| <?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.matrix.system.shopXcx.dao.ShopProductAttributeDao"> | 
|   | 
|   | 
|   | 
|   | 
|     <!-- 定义ShopProductAttribute 的关联map --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopProductAttribute" id="ShopProductAttributeMap"> | 
|         <id property="attrId" column="attr_id" /> | 
|         <result property="createBy" column="create_by" /> | 
|         <result property="createTime" column="create_time" /> | 
|         <result property="updateBy" column="update_by" /> | 
|         <result property="updateTime" column="update_time" /> | 
|         <result property="parentId" column="parent_id" /> | 
|         <result property="attrName" column="attr_name" /> | 
|         <result property="attrUrl" column="attr_url" /> | 
|         <result property="attrCode" column="attr_code" /> | 
|         <result property="attrMark" column="attr_mark" /> | 
|         <result property="sort"    column="sort"/> | 
|         <result property="shopId"    column="shop_id"/> | 
|         <result property="companyId" column="company_id" /> | 
|     </resultMap> | 
|      | 
|      | 
|     <!-- 定义ShopProductAttribute 的复杂map  ,本map不添加其他的关联属性 --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopProductAttribute" id="ShopProductAttributeComplexMap"> | 
|         <id property="attrId" column="attr_id" /> | 
|         <result property="createBy" column="create_by" /> | 
|         <result property="createTime" column="create_time" /> | 
|         <result property="updateBy" column="update_by" /> | 
|         <result property="updateTime" column="update_time" /> | 
|         <result property="parentId" column="parent_id" /> | 
|         <result property="attrName" column="attr_name" /> | 
|         <result property="attrUrl" column="attr_url" /> | 
|         <result property="attrCode" column="attr_code" /> | 
|         <result property="attrMark" column="attr_mark" /> | 
|         <result property="sort"    column="sort"/> | 
|         <result property="companyId" column="company_id" /> | 
|         <collection property="child" column="{attrId=attr_id, shopId=shop_id}" select="selectByParentIds"/> | 
|     </resultMap> | 
|   | 
|     <!-- 根据id查询--> | 
|     <select id="selectByParentIds" resultMap="ShopProductAttributeComplexMap"> | 
|         select | 
|         <include refid="columns" ></include> | 
|         from shop_product_attribute | 
|         where  parent_id=#{attrId} and shop_id=#{shopId} | 
|     </select> | 
|   | 
|     <!-- 根据编码查询--> | 
|     <select id="selectByIdAsTree" resultMap="ShopProductAttributeComplexMap"> | 
|         select | 
|         <include refid="columns" ></include> | 
|         from shop_product_attribute | 
|             where  company_id=#{companyId} and   attr_code=#{attrCode} | 
|     </select> | 
|      | 
|     <!-- 字段sql --> | 
|     <sql id="columns"> | 
|         create_by, | 
|         create_time, | 
|         update_by, | 
|         update_time, | 
|             attr_id, | 
|             parent_id, | 
|             attr_name, | 
|             attr_url, | 
|             attr_code, | 
|             attr_mark, | 
|             sort, | 
|             shop_id, | 
|             company_id | 
|     </sql> | 
|      | 
|     <!-- 属性sql --> | 
|     <sql id="propertys"> | 
|         #{item.createBy}, | 
|         now(), | 
|         #{item.updateBy}, | 
|         now(), | 
|             #{item.attrId}, | 
|             #{item.parentId}, | 
|             #{item.attrName}, | 
|             #{item.attrUrl}, | 
|             #{item.attrCode}, | 
|             #{item.attrMark}, | 
|             #{item.sort}, | 
|             #{item.shopId}, | 
|             #{item.companyId} | 
|     </sql> | 
|      | 
|     <!-- where sql --> | 
|     <sql id="where_sql"> | 
|           | 
|          <if test="record!=null"> | 
|             <if test="(record.attrId!=null and record.attrId!='') or  (record.attrId!='' and record.attrId==0)  "> | 
|                 and attr_id  = #{record.attrId}  | 
|             </if> | 
|             <if test="(record.parentId!=null and record.parentId!='') or  (record.parentId!='' and record.parentId==0)  "> | 
|                 and parent_id  = #{record.parentId} | 
|             </if> | 
|             <if test="(record.attrName!=null and record.attrName!='') or  (record.attrName!='' and record.attrName==0)  "> | 
|                 and attr_name  = #{record.attrName}  | 
|             </if> | 
|             <if test="(record.attrUrl!=null and record.attrUrl!='') or  (record.attrUrl!='' and record.attrUrl==0)  "> | 
|                 and attr_url  = #{record.attrUrl}  | 
|             </if> | 
|             <if test="(record.attrCode!=null and record.attrCode!='') or  (record.attrCode!='' and record.attrCode==0)  "> | 
|                 and attr_code  = #{record.attrCode}  | 
|             </if> | 
|             <if test="(record.attrMark!=null and record.attrMark!='') or  (record.attrMark!='' and record.attrMark==0)  "> | 
|                 and attr_mark  = #{record.attrMark}  | 
|             </if> | 
|              <if test="(record.sort!=null and record.sort!='') or  (record.sort!='' and record.sort==0)  "> | 
|                  and sort  = #{record.sort} | 
|              </if> | 
|              <if test="(record.shopId!=null and record.shopId!='') or  (record.shopId!='' and record.shopId==0)  "> | 
|                  and (shop_id  = #{record.shopId}) | 
|              </if> | 
|   | 
|              <if test="record.companyId != null and record.companyId !='' "> | 
|                  and company_id = #{record.companyId} | 
|              </if> | 
|   | 
|          </if> | 
|           | 
|     </sql> | 
|      | 
|     <!--  插入方法   --> | 
|     <insert id="insert" parameterType="com.matrix.system.shopXcx.bean.ShopProductAttribute" | 
|         useGeneratedKeys="true" keyProperty="item.attrId"> | 
|         INSERT INTO shop_product_attribute ( | 
|              <include refid="columns"></include> | 
|         ) | 
|     VALUES ( | 
|          <include refid="propertys"></include> | 
|     ) | 
|     </insert> | 
|      | 
|      | 
|      | 
|     <!--  批量插入   --> | 
|     <insert id="batchInsert" parameterType="java.util.List"> | 
|         INSERT INTO shop_product_attribute ( | 
|         <include refid="columns"></include>     | 
|         ) | 
|     VALUES  | 
|     <foreach collection="list" item="item" index="index" separator=",">( | 
|         <include refid="propertys"></include>     | 
|     )</foreach> | 
|     </insert> | 
|      | 
|      | 
|      | 
|      | 
|      | 
|     <!--  根据Map更新 部分更新   --> | 
|     <update id="updateByMap" parameterType="java.util.HashMap" > | 
|         UPDATE shop_product_attribute | 
|         <set> | 
|             <if test="_parameter.containsKey('parentId')"> | 
|                     parent_id = #{parentId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('attrName')"> | 
|                     attr_name = #{attrName}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('attrUrl')"> | 
|                     attr_url = #{attrUrl}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('attrCode')"> | 
|                     attr_code = #{attrCode}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('attrMark')"> | 
|                     attr_mark = #{attrMark}, | 
|                 </if> | 
|             <if test="_parameter.containsKey('sort')"> | 
|                 sort = #{sort}, | 
|             </if> | 
|         </set> | 
|         WHERE attr_id=#{attrId}  | 
|     </update>  | 
|      | 
|      | 
|     <!--  根据对象更新 部分更新   --> | 
|     <update id="updateByModel" parameterType="Integer"> | 
|         UPDATE shop_product_attribute | 
|         <set> | 
|             <if test="record.parentId!=null or record.parentId==0"> | 
|                 parent_id  = #{record.parentId}, | 
|             </if> | 
|             <if test="record.attrName!=null and record.attrName!=''"> | 
|                 attr_name  = #{record.attrName},  | 
|             </if> | 
|             <if test="record.attrUrl!=null and record.attrUrl!=''"> | 
|                 attr_url  = #{record.attrUrl},  | 
|             </if> | 
|             <if test="record.attrCode!=null and record.attrCode!=''"> | 
|                 attr_code  = #{record.attrCode},  | 
|             </if> | 
|             <if test="record.attrMark!=null or record.attrMark!=''"> | 
|                 attr_mark  = #{record.attrMark},  | 
|             </if> | 
|                 sort  = #{record.sort}, | 
|         </set> | 
|         WHERE attr_id=#{record.attrId}  | 
|     </update> | 
|      | 
|     <!-- 批量删除 --> | 
|     <delete id="deleteByIds" parameterType="java.util.List"> | 
|         delete from shop_product_attribute where  attr_id in | 
|         <foreach collection="list" index="index" item="item" open="(" | 
|             separator="," close=")"> | 
|             #{item} | 
|         </foreach> | 
|     </delete> | 
|          | 
|     <!-- 根据id删除--> | 
|     <delete id="deleteById" parameterType="Integer"> | 
|         DELETE FROM shop_product_attribute | 
|         where  attr_id=#{attrId}  | 
|     </delete> | 
|      | 
|     <!-- 根据对象删除--> | 
|     <delete id="deleteByModel" parameterType="com.matrix.system.shopXcx.bean.ShopProductAttribute"> | 
|         DELETE FROM shop_product_attribute | 
|         <where> | 
|         <include refid="where_sql" ></include> | 
|         </where> | 
|     </delete> | 
|      | 
|      | 
|      | 
|     <!-- 分页查询 --> | 
|     <select id="selectInPage" resultMap="ShopProductAttributeMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_product_attribute | 
|         <where> | 
|           <include refid="where_sql"></include> | 
|          </where> | 
|         <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 --> | 
|             <if test="pageVo.sort !=null  and pageVo.order !=null"> | 
|                 order by | 
|                 ${pageVo.sort} ${pageVo.order} | 
|             </if> | 
|             <if test="pageVo.offset >=0  and pageVo.limit >0"> | 
|                 limit | 
|                 #{pageVo.offset},#{pageVo.limit} | 
|             </if> | 
|         </if> | 
|     </select> | 
|      | 
|     <!-- 查询总条数 --> | 
|     <select id="selectTotalRecord" parameterType="long"   resultType="java.lang.Integer"> | 
|     select count(*) | 
|     from shop_product_attribute | 
|         <where> | 
|            <include refid="where_sql"></include> | 
|         </where> | 
|     </select> | 
|   | 
|     <!-- 根据id查询--> | 
|     <select id="selectById" resultMap="ShopProductAttributeMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_product_attribute | 
|         where  attr_id=#{attrId}  | 
|     </select>     | 
|      | 
|      | 
|     <!-- 根据id 锁表查询--> | 
|     <select id="selectForUpdate" resultMap="ShopProductAttributeMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_product_attribute | 
|         where  attr_id=#{attr_id}  | 
|         for update | 
|     </select>     | 
|   | 
|     <!--根据id查询,是否有子节点 --> | 
|     <select id="selectForById"  resultType="java.lang.String"> | 
|          select group_concat(attr_id) from shop_product_attribute | 
|           where parent_id = #{parentId} | 
|     </select> | 
|   | 
|     <select id="selectByCode" resultMap="ShopProductAttributeMap"> | 
|         select | 
|         <include refid="columns" ></include> | 
|         from shop_product_attribute | 
|         where  attr_code=#{attrCode} and company_id=#{companyId} | 
|     </select> | 
|   | 
|     <!-- 根据对象查询--> | 
|     <select id="selectByModel" resultMap="ShopProductAttributeMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_product_attribute | 
|         <where> | 
|           <include refid="where_sql"></include> | 
|          </where> | 
|          order by sort asc | 
|     </select> | 
|   | 
|     <!--过滤顶级属性--> | 
|     <select id="selectSonAttribute" resultMap="ShopProductAttributeMap"> | 
|         select | 
|         <include refid="columns" ></include> | 
|         from shop_product_attribute | 
|         where | 
|         parent_id != #{parentId} | 
|     </select> | 
|   | 
|     <select id="selectByParentId" resultMap="ShopProductAttributeMap"> | 
|         select | 
|         <include refid="columns" ></include> | 
|         from shop_product_attribute | 
|         where parent_id = #{parentId} | 
|         order by sort | 
|     </select> | 
| </mapper> |