瀏覽代碼

fix(fs-service): 修复订单查询不考虑删除状态问题

- 在所有订单相关查询中添加 is_del = 0 条件,以过滤掉已删除的订单
- 更新删除订单的逻辑,将 is_del 设置为 1 而不是直接删除
- 优化部分查询语句,提高可读性和性能
xw 1 月之前
父節點
當前提交
5035ac89f9

+ 8 - 8
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreOrderScrmMapper.java

@@ -81,7 +81,7 @@ public interface FsStoreOrderScrmMapper
             "left join fs_store_order_item_scrm oi on o.id = oi.order_id "+
             "left join fs_store_product_scrm fsp on fsp.product_id = oi.product_id"+
             "</if>" +
-            "where 1=1 " +
+            "where o.is_del = 0 " +
             "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
             "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
             "</if>" +
@@ -186,7 +186,7 @@ public interface FsStoreOrderScrmMapper
             "left join fs_store_order_item_scrm oi on o.id = oi.order_id "+
             "left join fs_store_product_scrm fsp on fsp.product_id = oi.product_id"+
             "</if>" +
-            "where 1=1  " +
+            "where o.is_del = 0  " +
             "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
             "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
             "</if>" +
@@ -289,7 +289,7 @@ public interface FsStoreOrderScrmMapper
             "left join fs_store_order_item_scrm oi on o.id = oi.order_id "+
             "left join fs_store_product_scrm fsp on fsp.product_id = oi.product_id"+
             "</if>" +
-            "where 1=1 " +
+            "where o.is_del = 0 " +
             "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
             "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
             "</if>" +
@@ -387,7 +387,7 @@ public interface FsStoreOrderScrmMapper
 
     @Select({"<script> " +
             "select f.phone as tuiNickName,o.*,u.phone,u.register_code,u.register_date,u.source, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber   from fs_store_order_scrm o left join fs_user u on o.user_id=u.user_id left join fs_user f on o.tui_user_id = f.user_id left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id  " +
-            "where 1=1 and o.tui_user_id is not null " +
+            "where o.is_del = 0 and o.tui_user_id is not null " +
             "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
             "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
             "</if>" +
@@ -646,7 +646,7 @@ public interface FsStoreOrderScrmMapper
             "select o.*,cts.name as scheduleName,u.nickname,u.phone,cc.push_code,cc.create_time as customer_create_time,cc.source,cc.customer_code, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber ,p.title as package_title ,CASE WHEN o.certificates IS NULL OR o.certificates = '' THEN 0 ELSE 1 END AS is_upload  " +
             " from fs_store_order_scrm o  left JOIN fs_store_product_package_scrm p on o.package_id=p.package_id left join fs_user u on o.user_id=u.user_id  " +
             " left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id left join crm_customer cc on cc.customer_id=o.customer_id left join company_tcm_schedule cts on cts.id = o.schedule_id " +
-            "where 1=1 " +
+            "where o.is_del = 0 " +
             "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
             "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
             "</if>" +
@@ -736,7 +736,7 @@ public interface FsStoreOrderScrmMapper
             "u.nickname,u.phone,cc.push_code,cc.create_time as customer_create_time,cc.source,cc.customer_code, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber ,p.title as package_title " +
             " from fs_store_order_scrm o  left JOIN fs_store_product_package_scrm p on o.package_id=p.package_id left join fs_user u on o.user_id=u.user_id  " +
             " left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id left join crm_customer cc on cc.customer_id=o.customer_id " +
-            "where 1=1 " +
+            "where o.is_del = 0 " +
             "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
             "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
             "</if>" +
@@ -814,7 +814,7 @@ public interface FsStoreOrderScrmMapper
             "select o.*,fp.pay_money as lastPayMoney,u.nickname,u.phone,cc.push_code,cc.create_time as customer_create_time,cc.source,cc.customer_code, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber ,p.title as package_title " +
             " from fs_store_order_scrm o  left JOIN fs_store_product_package_scrm p on o.package_id=p.package_id left join fs_user u on o.user_id=u.user_id  " +
             " left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id left join crm_customer cc on cc.customer_id=o.customer_id left join (select * from fs_store_payment_scrm where is_pay_remain != 0 and status != 0) fp on o.id = fp.order_id " +
-            "where 1=1 " +
+            "where o.is_del = 0 " +
             "<if test = 'maps.isPayRemain != null     '> " +
             "and o.is_pay_remain = #{maps.isPayRemain} " +
             "</if>" +
@@ -879,7 +879,7 @@ public interface FsStoreOrderScrmMapper
 
     @Select({"<script> " +
             "select o.*,u.nickname,u.phone,u.register_code,u.register_date,u.source, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber   from fs_store_order_scrm o left join fs_user u on o.user_id=u.user_id  left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id  " +
-            "where o.customer_id=#{maps.customerId} " +
+            "where o.is_del = 0 and o.customer_id=#{maps.customerId} " +
             "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
             "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
             "</if>" +

+ 24 - 12
fs-service/src/main/resources/mapper/hisStore/FsStoreOrderScrmMapper.xml

@@ -98,6 +98,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectFsStoreOrderList" parameterType="FsStoreOrderScrm" resultMap="FsStoreOrderResult">
         <include refid="selectFsStoreOrderVo"/>
         <where>
+            is_del = 0
             <if test="orderCode != null  and orderCode != ''"> and order_code = #{orderCode}</if>
             <if test="extendOrderId != null  and extendOrderId != ''"> and extend_order_id = #{extendOrderId}</if>
             <if test="userId != null "> and user_id = #{userId}</if>
@@ -157,7 +158,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectFsStoreOrderById" parameterType="Long" resultMap="FsStoreOrderResult">
         <include refid="selectFsStoreOrderVo"/>
-        where id = #{id}
+        where id = #{id} and is_del = 0
     </select>
 
     <insert id="insertFsStoreOrder" parameterType="FsStoreOrderScrm" useGeneratedKeys="true" keyProperty="id">
@@ -327,6 +328,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="customerId != null">#{customerId},</if>
             <if test="isPayRemain != null">#{isPayRemain},</if>
             <if test="deliverySendTime != null">#{deliverySendTime},</if>
+            <if test="scheduleId != null">#{scheduleId},</if>
             <if test="orderVisit != null">#{orderVisit},</if>
             <if test="serviceFee != null">#{serviceFee},</if>
             <if test="orderMedium != null">#{orderMedium},</if>
@@ -434,12 +436,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         delete from fs_store_order_scrm where id = #{id}
     </delete>
 
-    <delete id="deleteFsStoreOrderByIds" parameterType="String">
-        delete from fs_store_order_scrm where id in
+
+    <update id="deleteFsStoreOrderByIds" parameterType="java.util.List">
+        UPDATE fs_store_order_scrm
+        SET is_del = 1
+        WHERE id IN
         <foreach item="id" collection="array" open="(" separator="," close=")">
             #{id}
         </foreach>
-    </delete>
+    </update>
 
     <select id="selectFsStoreOrderCounts" resultType="com.alibaba.fastjson.JSONObject">
         SELECT  count(t.id ) AS orderCount,  t.type, sum(IFNULL(t.pay_price,0)) as payPrice
@@ -449,7 +454,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         FROM
         fs_store_order_scrm  AS o
         <where>
-            o.status  &gt; 0 and
+            o.status  &gt; 0 and o.is_del = 0 and
             (DATE_FORMAT(o.create_time,#{sqlDateFormat}) between #{beginTime} and #{finalTime})
             <if test="userIds != null and userIds.length>0">
                 AND o.company_user_id IN
@@ -473,6 +478,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         FROM
         fs_store_order_scrm  AS s
         WHERE
+        s.is_del = 0 and
         (DATE_FORMAT(s.create_time,#{sqlDateFormat}) between #{beginTime} and #{finalTime})
         AND s.status>0
         AND s.company_user_id IN
@@ -484,7 +490,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="selectFsStoreOrderStatisticsByUserId" resultType="com.fs.hisStore.domain.FsStoreOrderScrm">
-        select * from fs_store_order_scrm where user_id in
+        select * from fs_store_order_scrm where is_del = 0 and user_id in
         <foreach collection="ids"  item='item'  open='(' separator=',' close=')'>
             #{item}
         </foreach>
@@ -501,6 +507,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         FROM
         fs_store_order_scrm
         WHERE
+        is_del = 0 and
         <choose>
             <when test="map.orderStatus != null and map.orderStatus != ''">
                 status = #{map.orderStatus}
@@ -528,6 +535,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectFsStoreOrderCountByParam" resultType="int">
         select  count(id) from fs_store_order_scrm
         <where>
+            is_del = 0
             <if test="startTime != null and startTime != ''">AND date_format(create_time,'%y%m%d') &gt;= date_format(#{startTime},'%y%m%d')</if>
             <if test="endTime != null and endTime != ''">AND date_format(create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')</if>
             <if test="status != null"> and status = #{status}</if>
@@ -540,6 +548,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectFsStoreOrderByPayPriceCount" resultType="java.math.BigDecimal">
         select  sum(pay_price) from fs_store_order_scrm
         <where>
+            is_del = 0
             <if test="paid != null"> and paid = #{paid}</if>
             <if test="startTime != null and startTime != ''">AND date_format(create_time,'%y%m%d') &gt;= date_format(#{startTime},'%y%m%d')</if>
             <if test="endTime != null and endTime != ''">AND date_format(create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')</if>
@@ -548,7 +557,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
     <select id="selectFsStoreOrderTotalCount" resultType="java.lang.Long">
         select count(1) from fs_store_order_scrm
-        where 1=1
+        where is_del = 0
         <if test = "type != null and  type ==1  ">
             and  DATE_FORMAT(create_time, '%Y-%m-%d')  = DATE_FORMAT(NOW(), '%Y-%m-%d')
         </if>
@@ -820,6 +829,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         fs_store_order_scrm AS so
         LEFT JOIN company_user u ON so.company_user_id = u.user_id
         where
+        so.is_del = 0 and
         (DATE_FORMAT(so.create_time,#{sqlDateFormat}) between #{beginTime} and #{finalTime})
             <if test="userIds != null and userIds.length>0">AND so.company_user_id IN
                 <foreach item
@@ -834,7 +844,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ) o GROUP BY o.company_user_id
     </select>
     <select id="computePayMoney" resultMap="FsStoreOrderResult">
-        SELECT o.customer_id,o.pay_price FROM fs_store_order_scrm o WHERE `status` = 3
+        SELECT o.customer_id,o.pay_price FROM fs_store_order_scrm o WHERE o.is_del = 0 and `status` = 3
             and o.customer_id in
                 <foreach collection="customerIds" item="customerId" open="(" close=")" separator=",">
                     #{customerId}
@@ -842,7 +852,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         GROUP BY o.customer_id
     </select>
     <select id="selectLastByCustomerId" resultMap="FsStoreOrderResult">
-        SELECT o.* FROM fs_store_order_scrm o WHERE `status` = 3
+        SELECT o.* FROM fs_store_order_scrm o WHERE o.is_del = 0 and `status` = 3
         and o.customer_id = #{customerId}
         order by o.create_time desc limit 1
     </select>
@@ -864,7 +874,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN company_user u ON o.company_user_id = u.user_id
         where i.product_id = #{productId}
         and o.`status` = 3
-        and
+        and o.is_del = 0 and
         (DATE_FORMAT(o.create_time,#{sqlDateFormat}) between #{beginTime} and #{finalTime})
         <if test="userIds != null and userIds.length>0">AND o.company_user_id IN
             <foreach item="item" collection="userIds" open="(" separator="," close=")">
@@ -915,7 +925,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectStoreOrderScrmInId" resultType="com.fs.hisStore.domain.FsStoreOrderScrm">
         <include refid="selectFsStoreOrderVo"/>
-        where id IN <foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
+        where is_del = 0 and id IN <foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
             #{item}
     </foreach>
     </select>
@@ -932,7 +942,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         INNER JOIN fs_user fu ON os.user_id = fu.user_id
         INNER JOIN fs_store_order_item_scrm ois ON ois.order_id = os.id
         INNER JOIN fs_store_payment_scrm sps ON os.id=sps.order_id
-                                                  WHERE os.id IN <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
+                                                  WHERE os.is_del = 0 and os.id IN <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
         #{item}
     </foreach>
     AND  sps.`status` = 1
@@ -946,6 +956,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             fs_store_order_scrm sos
                 INNER JOIN fs_store_payment_scrm sps ON sos.id = sps.order_id
         WHERE
+            sos.is_del = 0 and
             sos.paid = 1
           AND sps.business_type = 2
           AND sos.`status` = 2
@@ -990,6 +1001,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ) fp
         ON o.id = fp.order_id
         WHERE
+        o.is_del = 0 and
         1 = 1
         <if test="maps.orderCode != null and maps.orderCode != ''">
             AND o.order_code LIKE CONCAT('%', #{maps.orderCode}, '%')