| <?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.mzl.flower.mapper.flower.FlowerCategoryMapper"> | 
|   | 
|     <select id="selectCategoryList" resultType="com.mzl.flower.dto.response.flower.FlowerCategoryTreeDTO"> | 
|         SELECT q.* | 
|         , (select count(1) from t_flower_category f where f.parent_id = q.id) childrenCount | 
|         FROM t_flower_category q | 
|         WHERE q.deleted = 0 | 
|         <if test="condition.name != null and condition.name != ''"> | 
|             AND (q.name LIKE concat('%', #{condition.name},'%') | 
|                 or exists ( | 
|                     select 1 from t_flower_category sq where sq.parent_id = q.id and sq.name LIKE concat('%', #{condition.name},'%') | 
|                 ) | 
|             ) | 
|         </if> | 
|         <choose> | 
|             <when test="condition.parentId != null"> | 
|                 AND q.parent_id = #{condition.parentId} | 
|             </when> | 
|             <otherwise> | 
|                 AND q.parent_id is null | 
|             </otherwise> | 
|         </choose> | 
|         <if test="condition.shown != null and condition.shown"> | 
|             AND (q.shown = 1 or q.shown is null) | 
|         </if> | 
|         <if test="condition.shown != null and !condition.shown"> | 
|             AND q.shown = 0 | 
|         </if> | 
|         ORDER BY q.sort_by, q.create_time Desc | 
|     </select> | 
|   | 
|     <select id="selectTreeList" resultType="com.mzl.flower.dto.response.flower.FlowerCategoryTreeDTO"> | 
|         SELECT q.* | 
|         , (select min(f.price) from t_flower f where f.category = q.id and f.status = 'UP' and f.deleted = 0) priceLow | 
|         , (select max(f.price) from t_flower f where f.category = q.id and f.status = 'UP' and f.deleted = 0) priceHigh | 
|         , (select sum(f.stock) from t_flower f where f.category = q.id and f.status = 'UP' and f.deleted = 0) stock | 
|         , (select count(1) from t_flower f where f.category = q.id and f.status = 'UP' and f.deleted = 0 and (f.shown = 1 or f.shown is null)) flowerCount | 
|         FROM t_flower_category q | 
|         WHERE q.deleted = 0 | 
|         <if test="condition.name != null and condition.name != ''"> | 
|             AND (q.name LIKE concat('%', #{condition.name},'%') | 
|                 or exists ( | 
|                     select 1 from t_flower_category sq where sq.parent_id = q.id and sq.name LIKE concat('%', #{condition.name},'%') | 
|                 ) | 
|             ) | 
|         </if> | 
|         <if test="condition.supplierId != null"> | 
|             AND exists( | 
|                 select 1 from t_flower f, t_flower_category fc | 
|                 where f.category = fc.id | 
|                 and (fc.id = q.id or fc.parent_id = q.id) | 
|                 and f.supplier_id = #{condition.supplierId} | 
|             ) | 
|         </if> | 
|         <if test="condition.parentId != null"> | 
|             AND q.parent_id = #{condition.parentId} | 
|         </if> | 
|         <if test="condition.shown != null and condition.shown"> | 
|             AND (q.shown = 1 or q.shown is null) | 
|         </if> | 
|         <if test="condition.shown != null and !condition.shown"> | 
|             AND q.shown = 0 | 
|         </if> | 
|         ORDER BY q.sort_by, q.create_time Desc | 
|     </select> | 
|   | 
|     <update id="clearParamByParamId"> | 
|         update t_flower_category set param_id = null where param_id = #{paramId} | 
|     </update> | 
|   | 
|     <update id="setParamById"> | 
|         update t_flower_category set param_id = #{paramId} where id in | 
|         <foreach collection="categoryIds" item="id" open="(" separator="," close=")"> | 
|             #{id} | 
|         </foreach> | 
|     </update> | 
|   | 
|     <select id="selectHomeCategoryDaily" resultType="com.mzl.flower.dto.response.flower.FlowerCategoryDailyDTO"> | 
|         SELECT q.id, q.name, d.ave_price, d.ave_price_difference, ave_price_difference_rate, d.day | 
|         FROM t_flower_category q | 
|         join t_flower_category_daily d on q.id = d.category_id | 
|         WHERE q.deleted = 0 | 
|         <if test="day != null"> | 
|             AND d.day = #{day} | 
|         </if> | 
|         <if test="partnerId != null"> | 
|             AND d.partner_id = #{partnerId} | 
|         </if> | 
|         ORDER BY d.day desc, d.ave_price desc | 
|     </select> | 
| </mapper> |