| <?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.FlowerMapper"> | 
|   | 
|     <select id="selectFlowerList" resultType="com.mzl.flower.dto.response.flower.FlowerListDTO"> | 
|         SELECT f.*, s.name supplierName, st.name supplierType, fc.name categoryStr | 
|             , (SELECT GROUP_CONCAT(DISTINCT(fz.id)) | 
|                 FROM t_flower_zone fz JOIN t_flower_zone_map fzm ON fz.id = fzm.zone_id | 
|                 WHERE fzm.flower_id = f.ID | 
|                 ORDER BY fz.id | 
|             ) AS zoneId | 
|             , (SELECT GROUP_CONCAT(DISTINCT(fz.name)) | 
|                 FROM t_flower_zone fz JOIN t_flower_zone_map fzm ON fz.id = fzm.zone_id | 
|                 WHERE fzm.flower_id = f.ID | 
|                 ORDER BY fz.id | 
|             ) AS  zoneName | 
|         FROM t_flower f | 
|         left join t_supplier_info s on s.id = f.supplier_id | 
|         left join t_supplier_type st on st.id = s.type_id | 
|         left join t_flower_category fc on fc.id = f.category | 
|         WHERE f.deleted = 0 | 
|         and f.status in ('PENDING','UP','REJECT','OFF','FORCE_OFF') | 
|         <if test="condition.name != null and condition.name != ''"> | 
|             AND f.name LIKE concat('%', #{condition.name},'%') | 
|         </if> | 
|         <if test="condition.supplierName != null and condition.supplierName != ''"> | 
|             AND s.name LIKE concat('%', #{condition.supplierName},'%') | 
|         </if> | 
|         <if test="condition.level != null and condition.level != ''"> | 
|             AND f.level = #{condition.level} | 
|         </if> | 
|         <if test="condition.tags != null and condition.tags != ''"> | 
|             AND f.tags LIKE concat('%', #{condition.tags},'%') | 
|         </if> | 
|         <if test="condition.recommend != null and condition.recommend"> | 
|             AND f.recommend = 1 | 
|         </if> | 
|         <if test="condition.recommend != null and !condition.recommend"> | 
|             AND (f.recommend = 0 or f.recommend is null) | 
|         </if> | 
|         <if test="condition.statusList != null and condition.statusList.size > 0"> | 
|             and f.status in | 
|             <foreach collection="condition.statusList" item="item" open="(" separator="," close=")"> | 
|                 #{item} | 
|             </foreach> | 
|         </if> | 
|         <if test="condition.category != null"> | 
|             AND (f.category = #{condition.category} | 
|                 or exists ( | 
|                     select 1 from t_flower_category fc where fc.id = f.category and fc.parent_id = #{condition.category} | 
|                 ) | 
|             ) | 
|         </if> | 
|         <if test="condition.zoneId != null"> | 
|             AND exists ( | 
|                 select 1 | 
|                 from t_flower_zone_map fz | 
|                 where fz.flower_id = f.id | 
|                 and fz.zone_id = #{condition.zoneId} | 
|             ) | 
|         </if> | 
|         <if test="condition.zoneName != null and condition.zoneName != ''"> | 
|             AND exists ( | 
|                 select 1 | 
|                 from t_flower_zone_map fz, t_flower_zone z | 
|                 where fz.flower_id = f.id | 
|                 and z.id = fz.zone_id | 
|                 and z.name LIKE concat('%', #{condition.zoneName},'%') | 
|             ) | 
|         </if> | 
|         ORDER BY f.create_time desc | 
|     </select> | 
|   | 
|     <select id="selectFlowerSupplierList" resultType="com.mzl.flower.dto.response.flower.FlowerSupplierListDTO"> | 
|         SELECT f.*, fc.name categoryStr | 
|         FROM t_flower f | 
|         left join t_flower_category fc on fc.id = f.category | 
|         WHERE f.deleted = #{deleted} | 
|         AND f.supplier_id = #{supplierId} | 
|         <if test="condition.name != null and condition.name != ''"> | 
|             AND f.name LIKE concat('%', #{condition.name},'%') | 
|         </if> | 
|         <if test="condition.level != null and condition.level != ''"> | 
|             AND f.level = #{condition.level} | 
|         </if> | 
|         <if test="condition.tags != null and condition.tags != ''"> | 
|             AND f.tags LIKE concat('%', #{condition.tags},'%') | 
|         </if> | 
|         <if test="condition.statusList != null and condition.statusList.size > 0"> | 
|             and f.status in | 
|             <foreach collection="condition.statusList" item="item" open="(" separator="," close=")"> | 
|                 #{item} | 
|             </foreach> | 
|         </if> | 
|         <if test="condition.category != null"> | 
|             AND (f.category = #{condition.category} | 
|                 or exists ( | 
|                     select 1 from t_flower_category fc where fc.id = f.category and fc.parent_id = #{condition.category} | 
|                 ) | 
|             ) | 
|         </if> | 
|   | 
|         ORDER BY f.create_time desc | 
|     </select> | 
|   | 
|     <select id="selectFlowerShowList" resultType="com.mzl.flower.dto.response.flower.FlowerShowListDTO"> | 
|         SELECT distinct f.*, s.name supplierName, st.name supplierType, fc.name categoryStr | 
|         , (select count(1) from t_collect_flower cf | 
|             where cf.flower_id = f.id | 
|             and cf.user_id = #{condition.userId} | 
|         ) collectCount | 
|         , (select sum(num) from t_cart c | 
|             where c.flower_id = f.id | 
|             and c.create_by = #{condition.userId} | 
|         ) shopnum, | 
|         fzp.rank as zoneRank | 
|         FROM t_flower f | 
|         left join t_supplier_info s on s.id = f.supplier_id | 
|         left join t_supplier_type st on st.id = s.type_id | 
|         left join t_flower_category fc on fc.id = f.category | 
|         left JOIN t_flower_zone_map fzp on fzp.flower_id = f.id | 
|         WHERE f.deleted = 0 | 
|         AND f.status = 'UP' | 
|         AND (fc.shown = 1 or fc.shown is null) | 
|         AND (f.shown = 1 or f.shown is null) | 
|         and (s.showed = 1 or s.showed is null) | 
|         and exists (select 1 from t_flower_category fcp where fcp.id = fc.parent_id and (fcp.shown = 1 or fcp.shown is null)) | 
|         <if test="condition.name != null and condition.name != ''"> | 
|             AND f.name LIKE concat('%', #{condition.name},'%') | 
|         </if> | 
|         <if test="condition.level != null and condition.level != ''"> | 
|             AND f.level = #{condition.level} | 
|         </if> | 
|         <if test="condition.tags != null and condition.tags != ''"> | 
|             AND f.tags LIKE concat('%', #{condition.tags},'%') | 
|         </if> | 
|         <if test="condition.categoryRoot != null"> | 
|             AND fc.parent_id = #{condition.categoryRoot} | 
|         </if> | 
|         <if test="condition.category != null"> | 
|             AND f.category = #{condition.category} | 
|         </if> | 
|         <if test="condition.supplierId != null"> | 
|             AND f.supplier_id = #{condition.supplierId} | 
|         </if> | 
|         <if test="condition.supplierName != null and condition.supplierName != ''"> | 
|             AND s.name LIKE concat('%', #{condition.supplierName},'%') | 
|         </if> | 
|         <if test="condition.recommend != null and condition.recommend"> | 
|             AND f.recommend = 1 | 
|         </if> | 
|         <if test="condition.zoneId != null"> | 
|             AND fzp.zone_id = #{condition.zoneId} | 
|         </if> | 
|   | 
|         <if test="condition.paramId != null and condition.params != null and condition.params.size > 0"> | 
|             AND exists ( | 
|                 select 1 from flower_param_${condition.paramId} pp | 
|                 where pp.id = f.id | 
|                 and | 
|                 <foreach collection="condition.params" item="p" open=" " separator=" and " close=""> | 
|                     field_${p.id} = #{p.value} | 
|                 </foreach> | 
|             ) | 
|         </if> | 
|   | 
|         <choose> | 
|             <when test="condition.column != null and condition.column != '' and (condition.recommend == null or condition.zoneId != null)"> | 
|                 <choose> | 
|                     <when test="'f.sales'.equals(condition.column) or 'f.stock'.equals(condition.column)"> | 
|                         order by ${condition.column} desc | 
|                     </when> | 
|                     <otherwise> | 
|                         order by ${condition.column}, f.price | 
|                     </otherwise> | 
|                 </choose> | 
|             </when> | 
|             <when test="(condition.column == null or condition.column == '') and condition.recommend != null and condition.recommend"> | 
|                 order by f.recommend_rank asc | 
|             </when> | 
|             <when test="(condition.column == null or condition.column == '') and condition.zoneId != null"> | 
|                 order by fzp.rank asc | 
|             </when> | 
|             <otherwise> | 
|                 order by f.price asc | 
|             </otherwise> | 
|         </choose> | 
|     </select> | 
|   | 
|     <select id="selectFlowerCartList" resultType="com.mzl.flower.dto.response.flower.FlowerCartListDTO"> | 
|         SELECT f.*, s.name supplierName, concat(fc.parent_name, '/', fc.name) categoryStr | 
|         , c.num, fc.param_id | 
|         , (CASE f.level | 
|             WHEN 'A' THEN fc.weight_a | 
|             WHEN 'B' THEN fc.weight_b | 
|             WHEN 'C' THEN fc.weight_c | 
|             WHEN 'D' THEN fc.weight_d | 
|             WHEN 'E' THEN fc.weight_e | 
|             WHEN 'O' THEN fc.weight_o | 
|         END | 
|         ) weight | 
|         FROM t_flower f | 
|         join t_cart c on c.flower_id = f.id and c.create_by = #{userId} | 
|         left join t_supplier_info s on s.id = f.supplier_id | 
|         left join t_flower_category fc on fc.id = f.category | 
|         WHERE f.deleted = 0 | 
|         and f.status = 'UP' | 
|         order by c.create_time desc | 
|     </select> | 
|   | 
|     <select id="selectFlowerOrderList" resultType="com.mzl.flower.dto.response.flower.FlowerCartListDTO"> | 
|         SELECT f.*, s.name supplierName, concat(fc.parent_name, '/', fc.name) categoryStr | 
|         , s.station_id stationId, fc.param_id | 
|         , (CASE f.level | 
|             WHEN 'A' THEN fc.weight_a | 
|             WHEN 'B' THEN fc.weight_b | 
|             WHEN 'C' THEN fc.weight_c | 
|             WHEN 'D' THEN fc.weight_d | 
|             WHEN 'E' THEN fc.weight_e | 
|             WHEN 'O' THEN fc.weight_o | 
|         END | 
|         ) weight | 
|         FROM t_flower f | 
|         left join t_supplier_info s on s.id = f.supplier_id | 
|         left join t_flower_category fc on fc.id = f.category | 
|         WHERE f.deleted = 0 | 
|         and f.id in | 
|         <foreach collection="ids" item="id" open="(" separator="," close=")"> | 
|             #{id} | 
|         </foreach> | 
|         order by f.create_time desc | 
|     </select> | 
|   | 
|   | 
|     <select id="myCollect" resultType="com.mzl.flower.dto.response.flower.FlowerShowListDTO"> | 
|         SELECT f.*, s.name supplierName, st.name supplierType, fc.name categoryStr | 
|         FROM t_collect_flower c | 
|         left join t_flower f on c.flower_id = f.id | 
|         left join t_supplier_info s on s.id = f.supplier_id | 
|         left join t_supplier_type st on st.id = s.type_id | 
|         left join t_flower_category fc on fc.id = f.category | 
|         WHERE f.deleted = 0 and c.deleted = 0 | 
| --         AND f.status = 'UP' | 
|         <if test="condition.name != null and condition.name != ''"> | 
|             AND f.name LIKE concat('%', #{condition.name},'%') | 
|         </if> | 
|         <if test="condition.level != null and condition.level != ''"> | 
|             AND f.level = #{condition.level} | 
|         </if> | 
|         <if test="condition.tags != null and condition.tags != ''"> | 
|             AND f.tags LIKE concat('%', #{condition.tags},'%') | 
|         </if> | 
|         <if test="condition.category != null"> | 
|             AND f.category = #{condition.category} | 
|         </if> | 
|   | 
|         <if test="condition.paramId != null and condition.params != null and condition.params.size > 0"> | 
|             AND exists ( | 
|             select 1 from flower_param_${condition.paramId} pp | 
|             where pp.id = f.id | 
|             and | 
|             <foreach collection="condition.params" item="p" open=" " separator=" and " close=""> | 
|                 field_${p.id} = #{p.value} | 
|             </foreach> | 
|             ) | 
|         </if> | 
|         <if test="condition.userId != null and condition.userId != ''"> | 
|             AND c.user_id = #{condition.userId} | 
|         </if> | 
|   | 
|         <if test="condition.column != null and condition.column != ''"> | 
|             order by ${condition.column} | 
|         </if> | 
|     </select> | 
|   | 
|     <select id="myBrowseHistory" resultType="com.mzl.flower.dto.response.flower.FlowerShowListDTO"> | 
|         SELECT f.*, s.name supplierName, st.name supplierType, fc.name categoryStr | 
|         FROM t_browse_his c | 
|         left join t_flower f on c.flower_id = f.id | 
|         left join t_supplier_info s on s.id = f.supplier_id | 
|         left join t_supplier_type st on st.id = s.type_id | 
|         left join t_flower_category fc on fc.id = f.category | 
|         WHERE f.deleted = 0 and c.deleted = 0 | 
|         <if test="condition.name != null and condition.name != ''"> | 
|             AND f.name LIKE concat('%', #{condition.name},'%') | 
|         </if> | 
|         <if test="condition.level != null and condition.level != ''"> | 
|             AND f.level = #{condition.level} | 
|         </if> | 
|         <if test="condition.tags != null and condition.tags != ''"> | 
|             AND f.tags LIKE concat('%', #{condition.tags},'%') | 
|         </if> | 
|         <if test="condition.category != null"> | 
|             AND f.category = #{condition.category} | 
|         </if> | 
|   | 
|         <if test="condition.paramId != null and condition.params != null and condition.params.size > 0"> | 
|             AND exists ( | 
|             select 1 from flower_param_${condition.paramId} pp | 
|             where pp.id = f.id | 
|             and | 
|             <foreach collection="condition.params" item="p" open=" " separator=" and " close=""> | 
|                 field_${p.id} = #{p.value} | 
|             </foreach> | 
|             ) | 
|         </if> | 
|         <if test="condition.userId != null and condition.userId != ''"> | 
|             AND c.user_id = #{condition.userId} | 
|         </if> | 
|   | 
|         <choose> | 
|             <when test="condition.column != null and condition.column != ''"> | 
|                 <choose> | 
|                     <when test="'f.sales'.equals(condition.column) or 'f.stock'.equals(condition.column)"> | 
|                         order by ${condition.column} desc | 
|                     </when> | 
|                     <otherwise> | 
|                         order by ${condition.column} asc | 
|                     </otherwise> | 
|                 </choose> | 
|             </when> | 
|             <otherwise> | 
|                 order by c.create_time desc | 
|             </otherwise> | 
|         </choose> | 
|     </select> | 
|   | 
|     <select id="searchInvalidCollect" resultType="java.lang.Long" parameterType="java.lang.String"> | 
|         SELECT c.id | 
|         FROM t_collect_flower c left join t_flower f on c.flower_id = f.id | 
|         WHERE f.deleted = 0 and c.deleted = 0 and f.status != 'UP' and c.user_id = #{userId} | 
|     </select> | 
|   | 
|     <update id="addFlowerStock"> | 
|         update t_flower set stock = stock + #{num} where id = #{id} | 
|     </update> | 
|   | 
|     <update id="updateFlowerSales"> | 
|         update t_flower set real_sales = ifnull(real_sales, 0) + #{num} where id = #{id} | 
|     </update> | 
|   | 
|     <select id="getUpFlowerStock" resultType="java.lang.Integer"> | 
|         SELECT sum(f.stock) | 
|         FROM t_flower f | 
|         join t_supplier_info s on s.id = f.supplier_id | 
|         join t_flower_category fc on fc.id = f.category | 
|         WHERE f.deleted = 0 | 
|         AND f.status = 'UP' | 
|         AND (fc.shown = 1 or fc.shown is null) | 
|         AND (f.shown = 1 or f.shown is null) | 
|         AND (s.showed = 1 or s.showed is null) | 
|         and exists (select 1 from t_flower_category fcp where fcp.id = fc.parent_id and (fcp.shown = 1 or fcp.shown is null)) | 
|     </select> | 
|     <select id="selectZoneFlowerList" resultType="com.mzl.flower.dto.response.flower.FlowerListDTO"> | 
|         SELECT f.*, s.name supplierName,fc.name categoryStr,fzp.zone_id as zoneId,fzp.rank as zoneRank | 
|         FROM t_flower f | 
|         left join t_supplier_info s on s.id = f.supplier_id | 
|         left join t_flower_category fc on fc.id = f.category | 
|         left JOIN t_flower_zone_map fzp on fzp.flower_id = f.id | 
|         WHERE f.deleted = 0 | 
|         and f.status in ('PENDING','UP','REJECT','OFF','FORCE_OFF') | 
|         <if test="condition.name != null and condition.name != ''"> | 
|             AND f.name LIKE concat('%', #{condition.name},'%') | 
|         </if> | 
|         <if test="condition.supplierName != null and condition.supplierName != ''"> | 
|             AND s.name LIKE concat('%', #{condition.supplierName},'%') | 
|         </if> | 
|         <if test="condition.level != null and condition.level != ''"> | 
|             AND f.level = #{condition.level} | 
|         </if> | 
|         <if test="condition.zoneId != null"> | 
|             AND fzp.zone_id = #{condition.zoneId} | 
|         </if> | 
|         ORDER BY fzp.rank asc | 
|     </select> | 
| </mapper> |