|
@@ -5,8 +5,9 @@ import cn.iocoder.yudao.module.museums.controller.admin.specimeninfo.vo.Specimen
|
|
|
import cn.iocoder.yudao.module.museums.controller.admin.specimeninfo.vo.SpecimenInfoRespVO;
|
|
|
import cn.iocoder.yudao.module.museums.dal.dataobject.specimeninfo.SpecimenInfoDO;
|
|
|
import cn.iocoder.yudao.module.museums.dal.mysql.specimeninfo.SpecimenInfoMapper;
|
|
|
+import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
|
|
|
-import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
|
|
import com.mzt.logapi.context.LogRecordContext;
|
|
|
import com.mzt.logapi.service.impl.DiffParseFunction;
|
|
|
import com.mzt.logapi.starter.annotation.LogRecord;
|
|
@@ -25,6 +26,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.module.museums.dal.mysql.specimenoutbound.SpecimenOutboundMapper;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -34,6 +36,8 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
|
|
|
import static cn.iocoder.yudao.module.museums.enums.ErrorCodeConstants.*;
|
|
|
import static cn.iocoder.yudao.module.museums.enums.social.LogRecordConstants.*;
|
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 标本出库回库信息 Service 实现类
|
|
@@ -53,6 +57,9 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
@Resource
|
|
|
private AdminUserMapper adminUserMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private NotifyMessageSendApi notifySendApi;
|
|
|
+
|
|
|
//创建出库申请
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -84,6 +91,21 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
LogRecordContext.putVariable("specimenOutbound", specimenOutbound);
|
|
|
LogRecordContext.putVariable("validInfoIds", validInfoIds);
|
|
|
|
|
|
+ //发送站内信
|
|
|
+ String templateCode = "specimen_withdrawal_request_submitted";
|
|
|
+ Map<String, Object> templateParams = new HashMap<>();
|
|
|
+
|
|
|
+ // 定义格式化模板
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ // 转换 LocalDateTime 为字符串
|
|
|
+ String formattedDate = specimenOutbound.getCreateTime().format(formatter);
|
|
|
+ templateParams.put("createTime",formattedDate);
|
|
|
+ templateParams.put("operator",getLoginUserNickname());
|
|
|
+
|
|
|
+ notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
|
|
|
+ .setUserId(143L).setTemplateCode(templateCode).setTemplateParams(templateParams));
|
|
|
+
|
|
|
// 返回出库记录ID
|
|
|
return specimenOutbound.getId();
|
|
|
}
|
|
@@ -124,7 +146,7 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
specimenOutbound.setStatus(req.getStatus());
|
|
|
specimenOutbound.setProcessInstanceId(req.getProcessInstanceId());
|
|
|
specimenOutbound.setApprovalTime(req.getApprovalTime()); // 设置当前审批时间
|
|
|
-// specimenOutbound.setApproveUsers(getLoginUserId()); // 设置一审操作员
|
|
|
+ specimenOutbound.setApproveUsers(getLoginUserId()); // 设置一审操作员
|
|
|
}
|
|
|
|
|
|
// 二审逻辑
|
|
@@ -143,6 +165,48 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
LogRecordContext.putVariable("rejectionReasons", req.getRejectionReasons());
|
|
|
LogRecordContext.putVariable("processInstanceId", req.getProcessInstanceId());
|
|
|
|
|
|
+ // 发送站内信
|
|
|
+ String templateCode = "";
|
|
|
+ Map<String, Object> templateParams = new HashMap<>();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ // 获取出库申请的提交时间
|
|
|
+ String formattedDate = specimenOutbound.getCreateTime().format(formatter);
|
|
|
+ templateParams.put("createTime", formattedDate);
|
|
|
+
|
|
|
+ // 根据审批状态选择不同的模板
|
|
|
+ if (req.getStatus() == 1 || req.getStatus() == 2) {
|
|
|
+ if (req.getStatus() == 1) {
|
|
|
+ templateCode = "specimen_withdrawal_request_one_approved";
|
|
|
+ } else if (req.getStatus() == 2) {
|
|
|
+ templateCode = "specimen_withdrawal_request_rejected";
|
|
|
+ templateParams.put("processInstanceId", req.getProcessInstanceId());
|
|
|
+ }
|
|
|
+ } else if (req.getStatus() == 5 || req.getStatus() == 6) {
|
|
|
+ if (req.getStatus() == 5) {
|
|
|
+ templateCode = "specimen_withdrawal_request_two_approved";
|
|
|
+ } else if (req.getStatus() == 6) {
|
|
|
+ templateCode = "specimen_withdrawal_two_request_rejected";
|
|
|
+ templateParams.put("rejectionReasons", req.getRejectionReasons());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送通知
|
|
|
+ notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
|
|
|
+ .setUserId(Long.valueOf(specimenOutbound.getCreator()))
|
|
|
+ .setTemplateCode(templateCode)
|
|
|
+ .setTemplateParams(templateParams));
|
|
|
+
|
|
|
+ if (req.getStatus() == 1) {
|
|
|
+ templateCode = "specimen_withdrawal_request_two_submitted";
|
|
|
+ String operatorNickname = adminUserMapper.selectNicknameByUserId(Long.valueOf(specimenOutbound.getCreator()));
|
|
|
+ templateParams.put("operator", operatorNickname);
|
|
|
+ notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
|
|
|
+ .setUserId(142L)
|
|
|
+ .setTemplateCode(templateCode)
|
|
|
+ .setTemplateParams(templateParams));
|
|
|
+ }
|
|
|
+
|
|
|
// 更新数据库
|
|
|
specimenOutboundMapper.updateById(specimenOutbound);
|
|
|
}
|
|
@@ -165,6 +229,22 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
// 校验存在
|
|
|
validateSpecimenOutboundExists(updateReqVO.getId());
|
|
|
|
|
|
+ // 从数据库获取当前标本出库信息
|
|
|
+ SpecimenOutboundDO specimenOutbound = specimenOutboundMapper.selectById(updateReqVO.getId());
|
|
|
+ int currentStatus = specimenOutbound.getStatus();
|
|
|
+
|
|
|
+ // 校验状态
|
|
|
+ if (currentStatus == 0 || currentStatus == 2 || currentStatus == 6) {
|
|
|
+ // 根据当前状态更新
|
|
|
+ if (currentStatus == 2) {
|
|
|
+ updateReqVO.setStatus(0); // 编辑后将状态变为0
|
|
|
+ } else if (currentStatus == 6) {
|
|
|
+ updateReqVO.setStatus(1); // 编辑后将状态变为1
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw exception(INVALID_APPROVAL_STATUS);
|
|
|
+ }
|
|
|
+
|
|
|
List<String> validInfoIds = new ArrayList<>();
|
|
|
|
|
|
for (String number : updateReqVO.getNumber()) {
|
|
@@ -184,6 +264,30 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
updateObj.setInfoId(validInfoIds.toString());
|
|
|
specimenOutboundMapper.updateById(updateObj);
|
|
|
|
|
|
+ // 1. 准备参数
|
|
|
+ if(currentStatus == 2 || currentStatus == 6){
|
|
|
+ Long userId = null;
|
|
|
+ if(currentStatus == 2){
|
|
|
+ userId = 143L;
|
|
|
+ }else{
|
|
|
+ userId = 142L;
|
|
|
+ }
|
|
|
+ String templateCode = "";
|
|
|
+ Map<String, Object> templateParams = new HashMap<>();
|
|
|
+ String operatorNickname = adminUserMapper.selectNicknameByUserId(Long.valueOf(specimenOutbound.getCreator()));
|
|
|
+ templateParams.put("operator", operatorNickname);
|
|
|
+
|
|
|
+ // 获取出库申请的提交时间
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String formattedDate = specimenOutbound.getCreateTime().format(formatter);
|
|
|
+ templateParams.put("createTime", formattedDate);
|
|
|
+
|
|
|
+ // 2. 发送站内信
|
|
|
+ notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
|
|
|
+ .setUserId(userId).setTemplateCode(templateCode).setTemplateParams(templateParams));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// 记录日志上下文
|
|
|
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(specimenInfo, SpecimenOutboundSaveReqVO.class));
|
|
|
}
|
|
@@ -239,13 +343,18 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
specimenInfoMapper.updateCollectionStatus(Long.valueOf(infoId.trim()), 1); // 设为借出状态
|
|
|
}
|
|
|
|
|
|
+// System.out.println(existingSpecimen+"==================================================================");
|
|
|
+ // 记录日志上下文
|
|
|
+ String operatorNickname = adminUserMapper.selectNicknameByUserId(existingSpecimen.getOperator());
|
|
|
+ String twoOperatorNickname = adminUserMapper.selectNicknameByUserId(existingSpecimen.getTwoOperator());
|
|
|
+ LogRecordContext.putVariable("operatorNickname", operatorNickname);
|
|
|
+ LogRecordContext.putVariable("twoOperatorNickname", twoOperatorNickname);
|
|
|
return "标本ID:" + existingSpecimen.getInfoId() + "出库确认成功";
|
|
|
} else {
|
|
|
// 如果只确认了一个操作员,更新出库单的信息但不修改状态
|
|
|
specimenOutboundMapper.updateById(existingSpecimen);
|
|
|
return "标本编号:" + existingSpecimen.getNumber() + "等待第二个操作员确认";
|
|
|
}
|
|
|
- //TODO 日志还没做
|
|
|
}
|
|
|
|
|
|
|