package cn.iocoder.yudao.module.trade.service.foreign;
|
|
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
|
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.foreign.TradeForeignOrderDO;
|
import jakarta.annotation.Resource;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 外贸订单补件提醒 Service
|
*
|
* <p>当外贸订单按出货模式存在必填单据缺件时,向业务员发送站内信「补件提醒」。
|
* 采用 {@link Propagation#REQUIRES_NEW} 独立事务,保证即使外层「提交审批/完结」因缺件异常回滚,
|
* 提醒消息也已落库,不会被一起回滚。</p>
|
*
|
* @author mom
|
*/
|
@Service
|
@Slf4j
|
public class TradeForeignDocNotifyService {
|
|
/** 补件提醒站内信模板编号(见 trade_foreign_document_notify_init.sql) */
|
public static final String DOC_MISSING_TEMPLATE_CODE = "trade_foreign_doc_missing";
|
|
@Resource
|
private NotifyMessageSendApi notifyMessageSendApi;
|
|
/**
|
* 发送补件提醒站内信
|
*
|
* @param order 外贸订单
|
* @param missingDocNames 缺失的必填单据名称
|
* @param scene 触发场景(如「提交审批」「完结」)
|
*/
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
public void sendDocMissingNotify(TradeForeignOrderDO order, List<String> missingDocNames, String scene) {
|
if (order == null || order.getSaleUserId() == null || missingDocNames == null || missingDocNames.isEmpty()) {
|
return;
|
}
|
try {
|
Map<String, Object> params = new HashMap<>();
|
params.put("orderNo", order.getNo());
|
params.put("docs", String.join("、", missingDocNames));
|
params.put("scene", scene);
|
NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO();
|
reqDTO.setUserId(order.getSaleUserId());
|
reqDTO.setTemplateCode(DOC_MISSING_TEMPLATE_CODE);
|
reqDTO.setTemplateParams(params);
|
notifyMessageSendApi.sendSingleMessageToAdmin(reqDTO);
|
} catch (Exception e) {
|
// 提醒失败不影响主流程
|
log.warn("[sendDocMissingNotify][订单({}) 补件提醒发送失败]", order.getNo(), e);
|
}
|
}
|
|
}
|