六、ShopDao.xml

作者: 薛定谔的猫_1406 | 来源:发表于2018-04-10 20:34 被阅读0次
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.imooc.o2o.dao.ShopDao">
    <resultMap type="com.imooc.o2o.entity.Shop" id="shopMap">
        <id column="shop_id" property="shopId" />
        <result column="shop_name" property="shopName" />
        <result column="shop_desc" property="shopDesc" />
        <result column="shop_addr" property="shopAddr" />
        <result column="phone" property="phone" />
        <result column="shop_img" property="shopImg" />
        <result column="priority" property="priority" />
        <result column="create_time" property="createTime" />
        <result column="last_edit_time" property="lastEditTime" />
        <result column="enable_status" property="enableStatus" />
        <result column="advice" property="advice" />
        <association property="area" column="area_id"
            javaType="com.imooc.o2o.entity.Area">
            <id column="area_id" property="areaId" />
            <result column="area_name" property="areaName" />
        </association>
        <association property="shopCategory" column="shop_category_id"
            javaType="com.imooc.o2o.entity.ShopCategory">
            <id column="shop_category_id" property="shopCategoryId" />
            <result column="shop_category_name" property="shopCategoryName" />
        </association>
        <association property="owner" column="user_id"
            javaType="com.imooc.o2o.entity.PersonInfo">
            <id column="user_id" property="userId" />
            <result column="name" property="name" />
        </association>
    </resultMap>
    <select id="queryShopList" resultMap="shopMap">
        SELECT
        s.shop_id,
        s.shop_name,
        s.shop_desc,
        s.shop_addr,
        s.phone,
        s.shop_img,
        s.priority,
        s.create_time,
        s.last_edit_time,
        s.enable_status,
        s.advice,
        a.area_id,
        a.area_name,
        sc.shop_category_id,
        sc.shop_category_name
        FROM
        tb_shop s,
        tb_area a,
        tb_shop_category sc
        <where>
            <if
                test="shopCondition.shopCategory != null and 
            shopCondition.shopCategory.shopCategoryId != null">
                and s.shop_category_id =
                #{shopCondition.shopCategory.shopCategoryId}
            </if>
            <if
                test="shopCondition.shopCategory != null 
            and shopCondition.shopCategory.parent!=null 
            and shopCondition.shopCategory.parent.shopCategoryId !=null">
                and s.shop_category_id in (select shop_category_id from
                tb_shop_category
                WHERE parent_id =
                #{shopCondition.shopCategory.parent.shopCategoryId})
            </if>
            <if
                test="shopCondition.area != null and 
            shopCondition.area.areaId != null">
                and s.area_id =
                #{shopCondition.area.areaId}
            </if>
            <if test="shopCondition.shopName != null">
                and s.shop_name like '%${shopCondition.shopName}%'
            </if>
            <if test="shopCondition.enableStatus != null">
                and s.enable_status = #{shopCondition.enableStatus}
            </if>
            <if
                test="shopCondition.owner != null and shopCondition.owner.userId != null">
                and s.owner_id = #{shopCondition.owner.userId}
            </if>
            AND
            s.area_id=a.area_id
            AND
            s.shop_category_id = sc.shop_category_id
        </where>
        ORDER BY
        s.priority DESC
        LIMIT #{rowIndex},#{pageSize};
    </select>
    <select id="queryShopCount" resultType="int">
        SELECT
        count(1)
        FROM
        tb_shop s,
        tb_area a,
        tb_shop_category sc
        <where>
            <if
                test="shopCondition.shopCategory != null and 
            shopCondition.shopCategory.shopCategoryId != null">
                and s.shop_category_id =
                #{shopCondition.shopCategory.shopCategoryId}
            </if>
            <if
                test="shopCondition.shopCategory != null 
            and shopCondition.shopCategory.parent!=null 
            and shopCondition.shopCategory.parent.shopCategoryId !=null">
                and s.shop_category_id in (select shop_category_id from
                tb_shop_category
                WHERE parent_id =
                #{shopCondition.shopCategory.parent.shopCategoryId})
            </if>
            <if
                test="shopCondition.area != null and 
            shopCondition.area.areaId != null">
                and s.area_id =
                #{shopCondition.area.areaId}
            </if>
            <if test="shopCondition.shopName != null">
                and s.shop_name like '%${shopCondition.shopName}%'
            </if>
            <if test="shopCondition.enableStatus != null">
                and s.enable_status = #{shopCondition.enableStatus}
            </if>
            <if
                test="shopCondition.owner != null and shopCondition.owner.userId != null">
                and s.owner_id = #{shopCondition.owner.userId}
            </if>
            AND
            s.area_id=a.area_id
            AND
            s.shop_category_id = sc.shop_category_id
        </where>
    </select>
    <select id="queryByShopId" resultMap="shopMap" parameterType="Long">
        SELECT
        s.shop_id,
        s.shop_name,
        s.shop_desc,
        s.shop_addr,
        s.phone,
        s.shop_img,
        s.priority,
        s.create_time,
        s.last_edit_time,
        s.enable_status,
        s.advice,
        a.area_id,
        a.area_name,
        sc.shop_category_id,
        sc.shop_category_name
        FROM
        tb_shop s,
        tb_area a,
        tb_shop_category sc
        WHERE
        s.area_id=a.area_id
        AND
        s.shop_category_id = sc.shop_category_id
        AND
        s.shop_id = #{shopId}
    </select>
    <insert id="insertShop" useGeneratedKeys="true" keyColumn="shop_id"
        keyProperty="shopId">
        INSERT INTO
        tb_shop(owner_id, area_id, shop_category_id,
        shop_name, shop_desc, shop_addr,
        phone, shop_img, priority,
        create_time, last_edit_time, enable_status,
        advice)
        VALUES
        (#{owner.userId},#{area.areaId},#{shopCategory.shopCategoryId},#{shopName},
        #{shopDesc},#{shopAddr},#{phone},#{shopImg},#{priority},
        #{createTime},#{lastEditTime}, #{enableStatus},#{advice})
    </insert>
     
</mapper>

相关文章

  • 六、ShopDao.xml

  • 第6章 店铺编辑和列表功能

    店铺编辑 Dao层开发 ShopDao接口 在shopDao.xml中添加shopMap文件 在shopDao.x...

  • 【乡土】六  六

    四姐端着一大锅猪食,吃力地举过猪圈的围墙,回头骂六六,你就是个贾宝玉!六六一边吃着槽子糕,嘻皮笑脸地问,谁是贾宝玉...

  • 六月六

    晚上吃了山东印象的羊肉汤这次超多羊肉啊……晚上普拉提很给力,基本动作很重要,教练说没有做一个俯卧撑一个月想塑形不可...

  • 六妖六随笔

    今天是六月十六号,在读《影响力》读到兄弟会的一些东西时,突然想要写点什么,就叫它六妖六随笔吧。 兄弟会是美国大...

  • 六月六

    酷热的六月,村居一周,一大重要任务就是过六月六,那是晒家谱男性聚餐的大日子。 六点不到,太阳公公红着脸从东边山...

  • 六、面试总结(六)

    一、final,finally,finalize的区别?1.final : 1、修饰符(关键字) 如果一个类被声明...

  • 六月六

    路上的各种车子 比平常多出很多 从城市飞往乡间的荒野 地下的,凄清了很久 城市的故事对谁说起 纸钱在荒塚上炙烤 缭...

  • 六叔六婶

    一天,六叔六婶来电话,也没什么事,和平常一样,简单问了些我和孩子的情况就挂电话了。我和六叔六婶并没有多亲近,不过,...

  • 六叔六叔

    我最喜欢的就是六叔,他放着四爷爷传下来的窑头不做,一整天的捞鱼套兔子,他的细狗跟着他,在北坡栗子林里,在南沟沿着河...

网友评论

    本文标题:六、ShopDao.xml

    本文链接:https://www.haomeiwen.com/subject/jstohftx.html