|
@@ -7,6 +7,7 @@ import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.domain.entity.SysDictData;
|
|
import com.fs.common.core.domain.entity.SysDictData;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.service.ISmsService;
|
|
import com.fs.common.service.ISmsService;
|
|
|
|
|
+import com.fs.common.utils.spring.SpringUtils;
|
|
|
import com.fs.company.domain.CompanySmsLogs;
|
|
import com.fs.company.domain.CompanySmsLogs;
|
|
|
import com.fs.company.mapper.CompanySmsLogsMapper;
|
|
import com.fs.company.mapper.CompanySmsLogsMapper;
|
|
|
import com.fs.course.service.IFsCourseWatchLogService;
|
|
import com.fs.course.service.IFsCourseWatchLogService;
|
|
@@ -116,6 +117,8 @@ public class SendSmsMsg {
|
|
|
// 批量失败状态更新阈值
|
|
// 批量失败状态更新阈值
|
|
|
private static final int BATCH_UPDATE_SIZE = 1000;
|
|
private static final int BATCH_UPDATE_SIZE = 1000;
|
|
|
|
|
|
|
|
|
|
+ private static final String JINAN_LIANZHI_HEALTH = "济南联志健康";
|
|
|
|
|
+
|
|
|
public SendSmsMsg(QwIpadServerMapper qwIpadServerMapper,
|
|
public SendSmsMsg(QwIpadServerMapper qwIpadServerMapper,
|
|
|
IQwSopSmsLogsService qwSopSmsLogsService,
|
|
IQwSopSmsLogsService qwSopSmsLogsService,
|
|
|
@Lazy ISmsService smsService,
|
|
@Lazy ISmsService smsService,
|
|
@@ -304,7 +307,9 @@ public class SendSmsMsg {
|
|
|
*/
|
|
*/
|
|
|
private SendResult processServerBatch(List<QwSopSmsLogs> batch, Map<Long, QwSopLogs> sopLogsMap, boolean sendByContactMobile) {
|
|
private SendResult processServerBatch(List<QwSopSmsLogs> batch, Map<Long, QwSopLogs> sopLogsMap, boolean sendByContactMobile) {
|
|
|
int success = 0;
|
|
int success = 0;
|
|
|
|
|
+ boolean updateSuccessStatus = isJinanLianzhiHealth();
|
|
|
List<SendResultDetailDTO> failReasonsList = Collections.synchronizedList(new ArrayList<>());
|
|
List<SendResultDetailDTO> failReasonsList = Collections.synchronizedList(new ArrayList<>());
|
|
|
|
|
+ List<QwSopSmsLogs> successRecords = Collections.synchronizedList(new ArrayList<>());
|
|
|
List<Long> failedIds = Collections.synchronizedList(new ArrayList<>());
|
|
List<Long> failedIds = Collections.synchronizedList(new ArrayList<>());
|
|
|
// 批量获取手机号
|
|
// 批量获取手机号
|
|
|
Map<Long, String> phoneMap = resolvePhones(batch, sendByContactMobile);
|
|
Map<Long, String> phoneMap = resolvePhones(batch, sendByContactMobile);
|
|
@@ -342,6 +347,9 @@ public class SendSmsMsg {
|
|
|
SendResultDetailDTO detail = sendSingleSms(logRecord, phoneMap, redisKey);
|
|
SendResultDetailDTO detail = sendSingleSms(logRecord, phoneMap, redisKey);
|
|
|
if (detail.isSuccess()) {
|
|
if (detail.isSuccess()) {
|
|
|
success++;
|
|
success++;
|
|
|
|
|
+ if (updateSuccessStatus) {
|
|
|
|
|
+ successRecords.add(logRecord);
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
redisCache.deleteObject(redisKey);
|
|
redisCache.deleteObject(redisKey);
|
|
|
failReasonsList.add(detail);
|
|
failReasonsList.add(detail);
|
|
@@ -360,16 +368,27 @@ public class SendSmsMsg {
|
|
|
failReasonsList.clear();
|
|
failReasonsList.clear();
|
|
|
failedIds.clear();
|
|
failedIds.clear();
|
|
|
}
|
|
}
|
|
|
|
|
+ if (updateSuccessStatus && successRecords.size() >= BATCH_UPDATE_SIZE) {
|
|
|
|
|
+ submitSuccessUpdate(new ArrayList<>(successRecords), sopLogsMap);
|
|
|
|
|
+ successRecords.clear();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 提交剩余的失败记录
|
|
// 提交剩余的失败记录
|
|
|
if (!failReasonsList.isEmpty()) {
|
|
if (!failReasonsList.isEmpty()) {
|
|
|
submitFailedUpdate(failedIds, failReasonsList,sopLogsMap);
|
|
submitFailedUpdate(failedIds, failReasonsList,sopLogsMap);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (updateSuccessStatus && !successRecords.isEmpty()) {
|
|
|
|
|
+ submitSuccessUpdate(successRecords, sopLogsMap);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return new SendResult(success, failedIds.size(), failedIds);
|
|
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)
|
|
* 解析待发送记录的手机号(key 为 qw_sop_sms_logs.id)
|
|
|
*/
|
|
*/
|
|
@@ -510,7 +529,7 @@ public class SendSmsMsg {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
if (r != null && "200".equals(String.valueOf(r.get("code")))) {
|
|
if (r != null && "200".equals(String.valueOf(r.get("code")))) {
|
|
|
- return new SendResultDetailDTO(true, null, null);
|
|
|
|
|
|
|
+ return new SendResultDetailDTO(true, null, logRecord.getSopLogId());
|
|
|
} else {
|
|
} else {
|
|
|
String msg = r != null && r.get("msg") != null ? r.get("msg").toString() : "未知错误";
|
|
String msg = r != null && r.get("msg") != null ? r.get("msg").toString() : "未知错误";
|
|
|
log.warn("短信发送失败 id={}, phone={}, msg={}", logRecord.getId(), phone, msg);
|
|
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);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 异步批量更新失败状态
|
|
* 异步批量更新失败状态
|
|
|
*/
|
|
*/
|