IMCategoryMapper.xml 10.5 KB
<?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.sibu.orderHelper.integral.web.dao.IMWebCategoryDao">
    <select id="listImCategory" resultMap="IMAddCategory" useCache="true" statementType="PREPARED" parameterType="map">
         SELECT
			g.im_category_id, g.name, g.image_url, g.sort_index,g.type_id,g.category_type,g.remark,g.create_dt,g.update_dt,g.delete_flag,g.child_category_id,g.create_member_id
		FROM
			im_category g
		WHERE
		  g.delete_flag = 1
		ORDER BY g.sort_index ASC,g.`create_dt` DESC
		limit ${pageNow}, ${pageSize}
    </select>

    <!-- 取出首页分类 -->
    <select id="listShowImCategory" resultMap="listShowIMCategory" useCache="true">
        SELECT
        g.im_category_id, g.name, g.image_url, g.sort_index, g.type_id, g.category_type
        FROM
        im_category g
        WHERE
        g.delete_flag = 1 and (g.child_category_id IS NULL or g.child_category_id = '')
        order by g.sort_index asc ,g.create_dt DESC
    </select>
    <resultMap type="IMAddCategoryBean" id="listShowIMCategory">
        <result column="im_category_id" property="imCategoryId" />
        <result column="name" property="name" />
        <result column="image_url" property="imageUrl" />
        <result column="sort_index" property="sortIndex" />
        <result column="type_id" property="typeId" />
        <result column="category_type" property="categoryType" />
        <result column="service_charge_rate" property="serviceChargeRate" />
    </resultMap>

    <select id="countImCategory" resultType="int">
        select count(1) from im_category where delete_flag = 1;
    </select>

    <select id="listParentImCategory" parameterType="String" resultMap="IMCategory" useCache="true">
        SELECT
        g.im_category_id, g.name, g.image_url, g.sort_index,g.category_type,g.type_id,g.remark,g.create_dt,g.update_dt,g.delete_flag,g.child_category_id,g.create_member_id
        FROM
        im_category g
        WHERE
        g.child_category_id IS NULL or g.child_category_id = '' and g.delete_flag = 1
        ORDER BY g.sort_index ASC,g.create_dt DESC
    </select>

    <select id="listChildrenImCategory" parameterType="String" resultMap="childCategory" useCache="true">
        SELECT
        g.im_category_id, g.name, g.image_url, g.sort_index,g.type_id,g.category_type,g.remark,g.create_dt,g.update_dt,g.delete_flag,g.child_category_id,g.create_member_id,
        child.im_category_id as c_im_category_id , child.name as c_name, child.image_url as c_image_url,
        child.sort_index as c_sort_index,child.type_id as c_type_id,child.category_type as c_category_type,
        child.remark as c_remark,child.create_dt as c_create_dt,child.update_dt as c_update_dt,
        child.delete_flag c_delete_flag,child.child_category_id as c_child_category_id,child.create_member_id as c_create_member_id
        FROM
        im_category g left join im_category child
        on g.im_category_id=child.child_category_id and child.delete_flag=1
        WHERE
        g.child_category_id = #{categoryId} and g.delete_flag = 1
        order by g.sort_index asc,g.create_dt DESC ,child.sort_index asc,child.create_dt DESC
    </select>

    <select id="getSecondCategory"  parameterType="String" resultMap="IMAddCategory">
        SELECT im_category_id,type_id,category_type,NAME,sort_index,remark,create_member_id,delete_flag,child_category_id
        FROM im_category  cate1 WHERE cate1.im_category_id=
        (SELECT  cate2.child_category_id  FROM im_category  cate2
        WHERE  cate2.im_category_id=#{categoryId})
    </select>

    <select id="get" resultMap="IMAddCategory" parameterType="String">
        SELECT
        im_category_id,type_id,category_type,name,image_url,sort_index,remark,create_member_id,
        create_dt,update_dt,delete_flag,child_category_id,service_charge_rate
        FROM
        im_category
        WHERE
        im_category_id=#{categoryId}
    </select>

    <select id="getFirstCategoryBeans" resultMap="IMAddCategory" parameterType="String">
        SELECT im_category_id,category_type,name FROM
        im_category
        WHERE  delete_flag=1 and  name=#{name}
    </select>
    <select id="getSecondCategoryBeans" resultMap="IMAddCategory" parameterType="map">
        SELECT im_category_id,category_type,name,child_category_id FROM
        im_category
        WHERE  delete_flag=1 and  name=#{name} AND child_category_id=#{firstCategoryId}
    </select>
    <select id="getCategoryBeans" resultMap="IMAddCategory" parameterType="map">
        SELECT im_category_id,category_type,name,child_category_id FROM
        im_category
        WHERE  delete_flag=1 and name=#{name}  AND child_category_id=#{secondCategoryId}
    </select>

    <insert id="add" parameterType="IMAddCategoryBean">
        insert into
        im_category(im_category_id,category_type,name,image_url,sort_index,remark,create_member_id,create_dt,update_dt,delete_flag,
        child_category_id,service_charge_rate)
        values(
        #{imCategoryId},
        #{categoryType},
        #{name},
        #{imageUrl},
        #{sortIndex},
        #{remark},
        #{createMemberId},
        now(),
        now(),
        1,
        #{childCategoryId},
        #{serviceChargeRate}
        )
    </insert>

    <update id="update" parameterType="IMAddCategoryBean">
        UPDATE im_category SET
        category_type=#{categoryType},
        name=#{name},
        image_url=#{imageUrl},
        sort_index=#{sortIndex},
        remark=#{remark},
        update_dt=now(),
        child_category_id=#{childCategoryId},
        service_charge_rate=#{serviceChargeRate}
        WHERE im_category_id=#{imCategoryId}
    </update>

    <update id="delete" parameterType="String" >
        UPDATE im_category SET delete_flag=0
        WHERE im_category_id=#{categoryId}
    </update>

    <resultMap type="IMCategoryBean" id="IMCategory">
        <result column="im_category_id" property="imCategoryId" />
        <result column="type_id" property="typeId" />
        <result column="category_type" property="categoryType" />
        <result column="name" property="name" />
        <result column="image_url" property="imageUrl" />
        <result column="sort_index" property="sortIndex" />
        <result column="remark" property="remark" />
        <result column="create_member_id" property="createMemberId" />
        <result column="create_dt" property="createDt" />
        <result column="update_dt" property="updateDt" />
        <result column="delete_flag" property="deleteFlag" />
        <result column="child_category_id" property="childCategoryId" />
    </resultMap>

    <resultMap type="com.sibu.orderHelper.integral.model.IMCategoryBean" id="IMAddCategory">
        <result column="im_category_id" property="imCategoryId" />
        <result column="type_id" property="typeId" />
        <result column="category_type" property="categoryType" />
        <result column="name" property="name" />
        <result column="image_url" property="imageUrl" />
        <result column="sort_index" property="sortIndex" />
        <result column="remark" property="remark" />
        <result column="create_member_id" property="createMemberId" />
        <result column="create_dt" property="createDt" />
        <result column="update_dt" property="updateDt" />
        <result column="delete_flag" property="deleteFlag" />
        <result column="child_category_id" property="childCategoryId" />
        <result column="service_charge_rate" property="serviceChargeRate" />
    </resultMap>
    <!-- 一对多包含三级分类 -->
    <resultMap type="IMAddCategoryBean" id="childCategory">
        <result column="im_category_id" property="imCategoryId" />
        <result column="type_id" property="typeId" />
        <result column="category_type" property="categoryType" />
        <result column="name" property="name" />
        <result column="image_url" property="imageUrl" />
        <result column="sort_index" property="sortIndex" />
        <result column="remark" property="remark" />
        <result column="create_member_id" property="createMemberId" />
        <result column="create_dt" property="createDt" />
        <result column="update_dt" property="updateDt" />
        <result column="delete_flag" property="deleteFlag" />
        <result column="child_category_id" property="childCategoryId" />
        <collection property="childs"  ofType="IMAddCategoryBean">
            <result column="c_im_category_id" property="imCategoryId" />
            <result column="c_type_id" property="typeId" />
            <result column="c_category_type" property="categoryType" />
            <result column="c_name" property="name" />
            <result column="c_image_url" property="imageUrl" />
            <result column="c_sort_index" property="sortIndex" />
            <result column="c_remark" property="remark" />
            <result column="c_create_member_id" property="createMemberId" />
            <result column="c_create_dt" property="createDt" />
            <result column="c_update_dt" property="updateDt" />
            <result column="c_delete_flag" property="deleteFlag" />
            <result column="c_child_category_id" property="childCategoryId" />
        </collection>
    </resultMap>

    <select id="checkCategoryName" resultMap="IMAddCategory" parameterType="map">
        SELECT im_category_id,category_type,name FROM im_category
        WHERE  delete_flag=1 and category_type=#{categoryType} and  name=#{name}
    </select>


    <select id="listParentCategoryBySysUser" parameterType="String" resultMap="IMCategory" useCache="true">
        SELECT
        g.im_category_id, g.name, g.image_url, g.sort_index,g.category_type,g.type_id,g.remark,g.create_dt,g.update_dt,g.delete_flag,g.child_category_id,g.create_member_id
        FROM
        im_category g
        WHERE
        g.child_category_id IS NULL or g.child_category_id = '' and g.delete_flag = 1  AND category_type = 1
        order by g.sort_index asc,g.create_dt DESC
    </select>

    <select id="listSellerCategory" parameterType="String" resultMap="IMCategory" useCache="true">
        SELECT
        g.im_category_id, g.name, g.image_url, g.sort_index,g.category_type,g.type_id,g.remark,g.create_dt,g.update_dt,g.delete_flag,g.child_category_id,g.create_member_id
        FROM
        im_category g
        WHERE g.child_category_id IS NULL or g.child_category_id = '' and g.delete_flag = 1
              and g.name=#{name}
        ORDER BY g.sort_index ASC,g.create_dt DESC
    </select>
</mapper>