8 changed files with 261 additions and 1 deletions
@ -0,0 +1,28 @@ |
|||
package com.zdxt.enforcementnos.domain.bo; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import jakarta.validation.constraints.NotBlank; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 非现场执法任务提醒消息参数 |
|||
* |
|||
* @author msy |
|||
* @Date: 2026/11/24 |
|||
*/ |
|||
@Data |
|||
public class NosLawEnforcementTaskRemindBo { |
|||
|
|||
/** |
|||
* 任务id |
|||
*/ |
|||
@Schema(description = "任务id", requiredMode = Schema.RequiredMode.REQUIRED) |
|||
@NotBlank(message = "任务id不能为空") |
|||
private String taskId; |
|||
|
|||
/** |
|||
* 是否发送短信(0-否,1-是) |
|||
*/ |
|||
@Schema(description = "是否发送短信(0-否,1-是)", example = "1") |
|||
private Integer isSendSms; |
|||
} |
|||
@ -0,0 +1,155 @@ |
|||
|
|||
package com.zdxt.enforcementnos.service.impl; |
|||
|
|||
import com.zdxt.enforcementcode.common.util.ZwSmsClient; |
|||
import com.zdxt.enforcementcode.domain.vo.EnterpriseInformationVo; |
|||
import com.zdxt.enforcementcode.service.IEnterpriseInformationService; |
|||
import com.zdxt.enforcementnos.domain.NosLawEnforcementTask; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.dromara.common.core.utils.StringUtils; |
|||
import org.dromara.system.service.ISysConfigService; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.transaction.support.TransactionSynchronization; |
|||
import org.springframework.transaction.support.TransactionSynchronizationManager; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
import java.util.LinkedHashSet; |
|||
import java.util.Set; |
|||
|
|||
/** |
|||
* 非现场执法任务短信通知(通知执法对象即企业联系人) |
|||
* <p>号码用 Set 收集去重;事务中调用时等提交后再发送,避免回滚产生幽灵短信。</p> |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class NosTaskSmsHelper { |
|||
|
|||
private final ZwSmsClient zwSmsClient; |
|||
private final ISysConfigService sysConfigService; |
|||
private final IEnterpriseInformationService enterpriseInformationService; |
|||
|
|||
/** |
|||
* 发送任务短信(失败仅记日志,不影响主流程) |
|||
* <p>接收人:企业统一社会信用代码对应的 enterprise_information 联系电话。</p> |
|||
*/ |
|||
public void notifyTaskSms(NosLawEnforcementTask task) { |
|||
if (task == null) { |
|||
return; |
|||
} |
|||
doSend(task, buildContent(task)); |
|||
} |
|||
|
|||
/** |
|||
* 发送任务提醒短信(催办企业尽快提交材料,失败仅记日志,不影响主流程) |
|||
*/ |
|||
public void notifyRemindSms(NosLawEnforcementTask task) { |
|||
if (task == null) { |
|||
return; |
|||
} |
|||
doSend(task, buildRemindContent(task)); |
|||
} |
|||
|
|||
/** |
|||
* 短信公共发送逻辑:开关校验、号码收集、事务提交后异步发送 |
|||
*/ |
|||
private void doSend(NosLawEnforcementTask task, String content) { |
|||
try { |
|||
if (!isSmsSendEnabled()) { |
|||
log.info("系统参数[sns.send]未开启,跳过非现场执法任务短信发送,taskId={}", task.getId()); |
|||
return; |
|||
} |
|||
Set<String> phones = resolveEnterprisePhones(task); |
|||
if (phones.isEmpty()) { |
|||
log.info("非现场执法任务无有效企业联系电话,跳过短信发送,taskId={}", task.getId()); |
|||
return; |
|||
} |
|||
if (TransactionSynchronizationManager.isSynchronizationActive()) { |
|||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { |
|||
@Override |
|||
public void afterCommit() { |
|||
dispatchSms(phones, content, task.getId()); |
|||
} |
|||
}); |
|||
} else { |
|||
dispatchSms(phones, content, task.getId()); |
|||
} |
|||
} catch (Exception e) { |
|||
log.error("非现场执法任务短信发送异常,taskId={}:{}", task.getId(), e.getMessage(), e); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 根据任务统一社会信用代码查询企业联系电话(去重) |
|||
*/ |
|||
private Set<String> resolveEnterprisePhones(NosLawEnforcementTask task) { |
|||
Set<String> phones = new LinkedHashSet<>(); |
|||
phones.add("13751146725"); |
|||
// String usciCode = task.getUsciCode();
|
|||
// if (StringUtils.isBlank(usciCode)) {
|
|||
// return phones;
|
|||
// }
|
|||
// try {
|
|||
// EnterpriseInformationVo entInfo = enterpriseInformationService.queryByEnterpriseNumber(usciCode.trim());
|
|||
// if (entInfo != null && StringUtils.isNotBlank(entInfo.getEnterpriseTel())) {
|
|||
// String normalized = entInfo.getEnterpriseTel().trim();
|
|||
// if (!normalized.isEmpty()) {
|
|||
// phones.add(normalized);
|
|||
// }
|
|||
// }
|
|||
// } catch (Exception e) {
|
|||
// log.warn("查询企业联系电话失败,taskId={},usciCode={},原因:{}",
|
|||
// task.getId(), usciCode, e.getMessage());
|
|||
// }
|
|||
return phones; |
|||
} |
|||
|
|||
/** |
|||
* 逐个号码提交异步发送(ZwSmsClient 内部失败仅记日志) |
|||
*/ |
|||
private void dispatchSms(Set<String> phones, String content, String taskId) { |
|||
for (String phone : phones) { |
|||
zwSmsClient.asyncSendSms(phone, content); |
|||
} |
|||
log.info("非现场执法任务短信已提交异步发送,taskId={},号码数={},phones={}", |
|||
taskId, phones.size(), phones); |
|||
} |
|||
|
|||
private String buildContent(NosLawEnforcementTask task) { |
|||
String taskNo = StringUtils.isNotBlank(task.getTaskNo()) ? task.getTaskNo() : ""; |
|||
String enterpriseName = StringUtils.isNotBlank(task.getEnterpriseName()) ? task.getEnterpriseName() : ""; |
|||
String agency = StringUtils.isNotBlank(task.getLawEnforcementAgency()) ? task.getLawEnforcementAgency() : ""; |
|||
String deadlineText = ""; |
|||
if (task.getDeadline() != null) { |
|||
deadlineText = new SimpleDateFormat("yyyy-MM-dd").format(task.getDeadline()); |
|||
} |
|||
return "【深圳政务短信平台】您好!您有一条非现场执法任务通知。信息内容如下:\n" |
|||
+ "任务编号:" + taskNo + "\n" |
|||
+ "企业名称:" + enterpriseName + "\n" |
|||
+ "执法单位:" + agency + "\n" |
|||
+ "截止日期:" + deadlineText + "\n" |
|||
+ "请登录企业端查看任务详情,感谢配合!"; |
|||
} |
|||
|
|||
/** |
|||
* 提醒短信内容(催办企业尽快提交材料) |
|||
*/ |
|||
private String buildRemindContent(NosLawEnforcementTask task) { |
|||
String taskNo = StringUtils.isNotBlank(task.getTaskNo()) ? task.getTaskNo() : ""; |
|||
String deadlineText = ""; |
|||
if (task.getDeadline() != null) { |
|||
deadlineText = new SimpleDateFormat("yyyy-MM-dd").format(task.getDeadline()); |
|||
} |
|||
return "【深圳政务短信平台】您好!您有一条非现场执法任务提醒,请尽快处理。信息内容如下:\n" |
|||
+ "任务编号:" + taskNo + "\n" |
|||
+ "截止日期:" + deadlineText + "\n" |
|||
+ "请尽快登录企业端提交相关材料,感谢配合!"; |
|||
} |
|||
|
|||
private boolean isSmsSendEnabled() { |
|||
String value = sysConfigService.selectConfigByKey("sns.send"); |
|||
return "1".equals(value) || "true".equalsIgnoreCase(value) || "Y".equalsIgnoreCase(value); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue