yuhongqi пре 2 недеља
родитељ
комит
034b649699

+ 83 - 1
fs-ipad-task/src/main/java/com/fs/app/task/SendSmsMsg.java

@@ -7,6 +7,7 @@ import com.fs.common.core.domain.R;
 import com.fs.common.core.domain.entity.SysDictData;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.service.ISmsService;
+import com.fs.common.utils.spring.SpringUtils;
 import com.fs.company.domain.CompanySmsLogs;
 import com.fs.company.mapper.CompanySmsLogsMapper;
 import com.fs.course.service.IFsCourseWatchLogService;
@@ -116,6 +117,8 @@ public class SendSmsMsg {
     // 批量失败状态更新阈值
     private static final int BATCH_UPDATE_SIZE = 1000;
 
+    private static final String JINAN_LIANZHI_HEALTH = "济南联志健康";
+
     public SendSmsMsg(QwIpadServerMapper qwIpadServerMapper,
                       IQwSopSmsLogsService qwSopSmsLogsService,
                       @Lazy ISmsService smsService,
@@ -304,7 +307,9 @@ public class SendSmsMsg {
      */
     private SendResult processServerBatch(List<QwSopSmsLogs> batch, Map<Long, QwSopLogs> sopLogsMap, boolean sendByContactMobile) {
         int success = 0;
+        boolean updateSuccessStatus = isJinanLianzhiHealth();
         List<SendResultDetailDTO> failReasonsList = Collections.synchronizedList(new ArrayList<>());
+        List<QwSopSmsLogs> successRecords = Collections.synchronizedList(new ArrayList<>());
         List<Long> failedIds = Collections.synchronizedList(new ArrayList<>());
         // 批量获取手机号
         Map<Long, String> phoneMap = resolvePhones(batch, sendByContactMobile);
@@ -342,6 +347,9 @@ public class SendSmsMsg {
                 SendResultDetailDTO detail = sendSingleSms(logRecord, phoneMap, redisKey);
                 if (detail.isSuccess()) {
                     success++;
+                    if (updateSuccessStatus) {
+                        successRecords.add(logRecord);
+                    }
                 } else {
                     redisCache.deleteObject(redisKey);
                     failReasonsList.add(detail);
@@ -360,16 +368,27 @@ public class SendSmsMsg {
                 failReasonsList.clear();
                 failedIds.clear();
             }
+            if (updateSuccessStatus && successRecords.size() >= BATCH_UPDATE_SIZE) {
+                submitSuccessUpdate(new ArrayList<>(successRecords), sopLogsMap);
+                successRecords.clear();
+            }
         }
 
         // 提交剩余的失败记录
         if (!failReasonsList.isEmpty()) {
             submitFailedUpdate(failedIds, failReasonsList,sopLogsMap);
         }
+        if (updateSuccessStatus && !successRecords.isEmpty()) {
+            submitSuccessUpdate(successRecords, sopLogsMap);
+        }
 
         return new SendResult(success, failedIds.size(), failedIds);
     }
 
+    private boolean isJinanLianzhiHealth() {
+        return JINAN_LIANZHI_HEALTH.equals(SpringUtils.getProperty("cloud_host.company_name"));
+    }
+
     /**
      * 解析待发送记录的手机号(key 为 qw_sop_sms_logs.id)
      */
@@ -510,7 +529,7 @@ public class SendSmsMsg {
             );
 
             if (r != null && "200".equals(String.valueOf(r.get("code")))) {
-                return new SendResultDetailDTO(true, null, null);
+                return new SendResultDetailDTO(true, null, logRecord.getSopLogId());
             } else {
                 String msg = r != null && r.get("msg") != null ? r.get("msg").toString() : "未知错误";
                 log.warn("短信发送失败 id={}, phone={}, msg={}", logRecord.getId(), phone, msg);
@@ -522,6 +541,69 @@ public class SendSmsMsg {
         }
     }
 
+    /**
+     * 异步批量更新成功状态(济南联志健康:短信接口返回成功后立即标记为发送成功)
+     */
+    private void submitSuccessUpdate(List<QwSopSmsLogs> successRecords, Map<Long, QwSopLogs> sopLogsMap) {
+        if (successRecords == null || successRecords.isEmpty()) {
+            return;
+        }
+        statusExecutor.submit(() -> {
+            try {
+                List<Long> successIds = successRecords.stream()
+                        .map(QwSopSmsLogs::getId)
+                        .collect(Collectors.toList());
+                qwSopSmsLogsService.updateStatusByIds(successIds, "2");
+
+                List<QwSopLogs> updateList = successRecords.stream().map(record -> {
+                            QwSopLogs qwSopLogs = sopLogsMap.get(record.getSopLogId());
+                            if (qwSopLogs == null) {
+                                return null;
+                            }
+                            if (qwSopLogs.getSendStatus() == 5 || qwSopLogs.getReceivingStatus() == 4) {
+                                return null;
+                            }
+
+                            QwSopLogs update = new QwSopLogs();
+                            update.setSmsLogsId(record.getSopLogId());
+                            update.setSendStatus(1L);
+                            update.setReceivingStatus(1L);
+                            if (sopLogsMap.containsKey(record.getSopLogId())) {
+                                try {
+                                    String contentJson = sopLogsMap.get(record.getSopLogId()).getContentJson();
+                                    JSONObject jsonObject = JSONObject.parseObject(contentJson);
+                                    JSONArray settingArray = jsonObject.getJSONArray("setting");
+                                    if (settingArray != null && !settingArray.isEmpty()) {
+                                        Integer smsIndex = record.getSmsIndex();
+                                        if (smsIndex != null && smsIndex >= 0 && smsIndex < settingArray.size()) {
+                                            settingArray.getJSONObject(smsIndex).put("sendStatus", "1");
+                                        } else {
+                                            for (int i = 0; i < settingArray.size(); i++) {
+                                                settingArray.getJSONObject(i).put("sendStatus", "1");
+                                            }
+                                        }
+                                        update.setContentJson(jsonObject.toJSONString());
+                                    }
+                                } catch (Exception e) {
+                                    log.warn("解析ContentJson失败,sopLogId:{}", record.getSopLogId(), e);
+                                    update.setContentJson(sopLogsMap.get(record.getSopLogId()).getContentJson());
+                                }
+                            }
+                            return update;
+                        })
+                        .filter(Objects::nonNull)
+                        .collect(Collectors.toList());
+
+                if (!updateList.isEmpty()) {
+                    qwSopLogsMapper.batchUpdateSuccessQwSopLogsBySmsLogsId(updateList);
+                }
+                log.debug("批量更新成功状态完成,条数:{}", successIds.size());
+            } catch (Exception e) {
+                log.error("批量更新成功状态异常", e);
+            }
+        });
+    }
+
     /**
      * 异步批量更新失败状态
      */

+ 3 - 0
fs-service/src/main/java/com/fs/sop/mapper/QwSopLogsMapper.java

@@ -384,6 +384,9 @@ public interface QwSopLogsMapper extends BaseMapper<QwSopLogs> {
     @DataSource(DataSourceType.SOP)
     void batchUpdateQwSopLogsBySmsLogsId(@Param("list") List<QwSopLogs> list);
 
+    @DataSource(DataSourceType.SOP)
+    void batchUpdateSuccessQwSopLogsBySmsLogsId(@Param("list") List<QwSopLogs> list);
+
 
     @DataSource(DataSourceType.SOP)
     List<QwSopLogs> getQwSopInfoByUid(@Param("sopSmsLogIds") List<Long> sopSmsLogIds);

+ 29 - 0
fs-service/src/main/resources/mapper/sop/QwSopLogsMapper.xml

@@ -968,6 +968,35 @@
         </foreach>
     </update>
 
+    <update id="batchUpdateSuccessQwSopLogsBySmsLogsId" parameterType="list">
+        UPDATE qw_sop_logs
+        <set>
+            send_status = 1,
+            receiving_status = 1,
+            real_send_time = NOW(),
+            content_json = COALESCE(
+            CASE sms_logs_id
+            <foreach collection="list" item="item" separator=" ">
+                WHEN #{item.smsLogsId} THEN
+                <choose>
+                    <when test="item.contentJson != null and item.contentJson != ''">
+                        #{item.contentJson}
+                    </when>
+                    <otherwise>
+                        NULL
+                    </otherwise>
+                </choose>
+            </foreach>
+            END,
+            content_json
+            )
+        </set>
+        WHERE sms_logs_id IN
+        <foreach collection="list" item="item" open="(" separator="," close=")">
+            #{item.smsLogsId}
+        </foreach>
+    </update>
+
     <select id="getQwSopInfoByUid" resultType="com.fs.sop.domain.QwSopLogs">
         select id,send_status,receiving_status,expiration_time,send_time,external_id,send_type,sms_logs_id,content_json,qw_user_key from qw_sop_logs where sms_logs_id IN
         <foreach item="item" collection="sopSmsLogIds" separator="," open="(" close=")">