Jelajahi Sumber

fix: 益兽园erp修复(商城走带scrm,非商城走不带scrm)

xdd 1 bulan lalu
induk
melakukan
035946ebaf

+ 110 - 0
fs-service/src/main/java/com/fs/erp/mapper/FsJstAftersalePushScrmMapper.java

@@ -0,0 +1,110 @@
+package com.fs.erp.mapper;
+
+import com.fs.erp.domain.FsJstAftersalePush;
+import org.apache.ibatis.annotations.*;
+
+import java.util.List;
+
+/**
+ * 订阅物流Mapper
+ */
+@Mapper
+public interface FsJstAftersalePushScrmMapper {
+
+    /**
+     * 根据ID查询
+     */
+    @Select("SELECT * FROM fs_jst_aftersale_push_scrm WHERE id = #{id}")
+    FsJstAftersalePush selectById(Long id);
+
+    /**
+     * 根据订单ID查询
+     */
+    @Select("SELECT * FROM fs_jst_aftersale_push_scrm WHERE order_id = #{orderId}")
+    FsJstAftersalePush selectByOrderId(String orderId);
+
+    /**
+     * 查询待处理的任务
+     */
+    @Select("SELECT * FROM fs_jst_aftersale_push_scrm WHERE task_status = #{status} AND retry_count < #{maxRetry} LIMIT #{limit}")
+    List<FsJstAftersalePush> selectByStatusAndRetry(Byte status, Integer maxRetry, Integer limit);
+
+    /**
+     * 插入记录
+     */
+    @Insert("INSERT INTO fs_jst_aftersale_push_scrm(order_id,after_sale_id, type, task_status, retry_count, last_execute_time, params) " +
+            "VALUES(#{orderId},#{afterSaleId}, #{type}, #{taskStatus}, #{retryCount}, #{lastExecuteTime}, #{params})")
+    @Options(useGeneratedKeys = true, keyProperty = "id")
+    int insert(FsJstAftersalePush push);
+
+    /**
+     * 更新记录
+     */
+    @Update("UPDATE fs_jst_aftersale_push_scrm SET params=#{params},task_status = #{taskStatus}, retry_count = #{retryCount}, " +
+            "last_execute_time = #{lastExecuteTime}, result = #{result}, error_message = #{errorMessage} " +
+            "WHERE id = #{id}")
+    int update(FsJstAftersalePush push);
+
+    /**
+     * 更新任务状态
+     */
+    @Update("UPDATE fs_jst_aftersale_push_scrm SET task_status = #{taskStatus}, " +
+            "last_execute_time = now() WHERE id = #{id}")
+    int updateStatus(@Param("id") Long id, @Param("taskStatus") Byte taskStatus);
+
+    @Select("WITH OrderWithNextTaskType AS (\n" +
+            "    SELECT \n" +
+            "        id,\n" +
+            "        order_id,\n" +
+            "        after_sale_id,\n" +
+            "        type,\n" +
+            "        task_status,\n" +
+            "        retry_count,\n" +
+            "        ROW_NUMBER() OVER(PARTITION BY order_id ORDER BY CAST(type AS UNSIGNED)) AS task_seq\n" +
+            "    FROM \n" +
+            "        fs_jst_aftersale_push_scrm\n" +
+            "),\n" +
+            "PendingTasks AS (\n" +
+            "    SELECT \n" +
+            "        o.id,\n" +
+            "        o.order_id,\n" +
+            "        o.after_sale_id,\n" +
+            "        o.type,\n" +
+            "        o.task_status,\n" +
+            "        o.retry_count,\n" +
+            "        o.task_seq,\n" +
+            "        (\n" +
+            "            SELECT MAX(p.task_status)  \n" +
+            "            FROM OrderWithNextTaskType p\n" +
+            "            WHERE p.order_id = o.order_id\n" +
+            "              AND p.task_seq = o.task_seq - 1\n" +
+            "        ) AS prev_task_status,\n" +
+            "        EXISTS (\n" +
+            "            SELECT 1\n" +
+            "            FROM OrderWithNextTaskType p\n" +
+            "            WHERE p.order_id = o.order_id\n" +
+            "              AND p.task_seq < o.task_seq\n" +
+            "              AND p.task_status != 1\n" +
+            "        ) AS has_pending_prev_task\n" +
+            "    FROM \n" +
+            "        OrderWithNextTaskType o\n" +
+            "    WHERE \n" +
+            "        o.task_status = 0 OR (o.task_status = 2 AND o.retry_count < 3)\n" +
+            ")\n" +
+            "SELECT \n" +
+            "    id,\n" +
+            "    order_id,\n" +
+            "    after_sale_id,\n" +
+            "    type,\n" +
+            "    task_status,\n" +
+            "    retry_count\n" +
+            "FROM \n" +
+            "    PendingTasks\n" +
+            "WHERE \n" +
+            "    (task_seq = 1 OR prev_task_status = 1)\n" +
+            "    AND has_pending_prev_task = 0\n" +
+            "ORDER BY\n" +
+            "    order_id,\n" +
+            "    task_seq;\n")
+    List<FsJstAftersalePush> queryPenddingData();
+}

+ 77 - 0
fs-service/src/main/java/com/fs/erp/mapper/FsJstCodPushScrmMapper.java

@@ -0,0 +1,77 @@
+package com.fs.erp.mapper;
+
+import com.fs.erp.domain.FsJstCodPush;
+import org.apache.ibatis.annotations.*;
+
+import java.util.List;
+
+@Mapper
+public interface FsJstCodPushScrmMapper {
+
+    /**
+     * 根据ID查询记录
+     */
+    @Select("SELECT * FROM fs_jst_cod_push_scrm WHERE id = #{id}")
+    FsJstCodPush selectById(@Param("id") Long id);
+
+    /**
+     * 根据订单ID查询记录
+     */
+    @Select("SELECT * FROM fs_jst_cod_push_scrm WHERE order_id = #{orderId}")
+    List<FsJstCodPush> selectByOrderId(@Param("orderId") String orderId);
+
+    /**
+     * 根据售后ID查询记录
+     */
+    @Select("SELECT * FROM fs_jst_cod_push_scrm WHERE after_sale_id = #{afterSaleId}")
+    List<FsJstCodPush> selectByAfterSaleId(@Param("afterSaleId") String afterSaleId);
+
+    /**
+     * 查询待处理的任务
+     */
+    @Select("SELECT * FROM fs_jst_cod_push_scrm WHERE task_status = 0 ORDER BY id ASC LIMIT #{limit}")
+    List<FsJstCodPush> selectPendingTasks(@Param("limit") int limit);
+
+
+    /**
+     * 查询待处理的数据
+     * @return List<FsJstCodPush>
+     */
+    @Select("SELECT * from fs_jst_cod_push_scrm where task_status = 0 OR (task_status = 2 AND retry_count < 3) ")
+    List<FsJstCodPush> queryPenddingData();
+    /**
+     * 插入新记录
+     */
+    @Insert("INSERT INTO fs_jst_cod_push_scrm(order_id, after_sale_id, type, task_status, params) " +
+            "VALUES(#{orderId}, #{afterSaleId}, #{type}, #{taskStatus}, #{params})")
+    @Options(useGeneratedKeys = true, keyProperty = "id")
+    int insert(FsJstCodPush record);
+
+    /**
+     * 更新任务状态
+     */
+    @Update("UPDATE fs_jst_cod_push_scrm SET task_status = #{taskStatus}, retry_count = #{retryCount}, " +
+            "last_execute_time = NOW(), result = #{result}, error_message = #{errorMessage} " +
+            "WHERE id = #{id}")
+    int updateTaskStatus(FsJstCodPush record);
+
+    /**
+     * 根据ID更新记录
+     */
+    @Update("<script>" +
+            "UPDATE fs_jst_cod_push_scrm " +
+            "<set>" +
+            "  <if test='orderId != null'>order_id = #{orderId},</if>" +
+            "  <if test='afterSaleId != null'>after_sale_id = #{afterSaleId},</if>" +
+            "  <if test='type != null'>type = #{type},</if>" +
+            "  <if test='taskStatus != null'>task_status = #{taskStatus},</if>" +
+            "  <if test='retryCount != null'>retry_count = #{retryCount},</if>" +
+            "  <if test='lastExecuteTime != null'>last_execute_time = #{lastExecuteTime},</if>" +
+            "  <if test='params != null'>params = #{params},</if>" +
+            "  <if test='result != null'>result = #{result},</if>" +
+            "  <if test='errorMessage != null'>error_message = #{errorMessage},</if>" +
+            "</set>" +
+            "WHERE id = #{id}" +
+            "</script>")
+    int updateById(FsJstCodPush record);
+}