feat: 当前标准引用的标准有新版标准的时候发消息

This commit is contained in:
2024-08-05 14:32:46 +08:00
parent c5e953065f
commit f7d2594aa4
4 changed files with 91 additions and 12 deletions
@@ -825,7 +825,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
// 同步es数据库
lawsHomeSearchService.updateEsData(module, id, LawsHomeSearchCommon.LAWS_ES_ADD);
return ResultCommon.OK;
return id;
}
private void processPartName(Map<String, Object> parameterMap, String standardId) {
@@ -14,6 +14,7 @@ import com.jero.modules.laws.common.service.ILawsCommonService;
import com.jero.modules.laws.enterprise.entity.EnterpriseStandardRmrEvaluateDetail;
import com.jero.modules.laws.enterprise.service.EnterpriseStandardReviewMeetingRecordService;
import com.jero.modules.laws.standard.service.ILawsNodeRelationService;
import com.jero.modules.laws.standard.service.ILawsReplacedStandardService;
import com.jero.modules.personal.service.ILawsStandardCollectionService;
import com.jero.modules.split.service.ISarFileSplitInfoService;
import com.jero.modules.tag.entity.LawsTag;
@@ -30,6 +31,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
/**
* @Author: liao
@@ -58,6 +60,9 @@ public class LawsEnterpriseController {
@Resource
private ISarFileCompareInfoService compareInfoService;
@Resource
private ILawsReplacedStandardService replacedStandardService;
private static final String MODULE_VALUE = TableNameEnum.ENTERPRISE_STANDARDS.getValue();
@AutoLog(value = "企业法规标准-分页列表查询")
@@ -96,7 +101,9 @@ public class LawsEnterpriseController {
@RequiresPermissions("enterpriseStandard:add")
public Result<String> commonAdd(@RequestBody @ApiParam("标签管理") Map<String,Object> parameterMap) {
parameterMap.put(FieldCommon.MODULE, MODULE_VALUE);
return Result.OK(lawsCommonService.commonAdd(parameterMap));
String id = lawsCommonService.commonAdd(parameterMap);
CompletableFuture.runAsync(() -> replacedStandardService.newVersionESSendMsg(id));
return Result.OK();
}
@AutoLog(value = "企业法规标准-编辑数据")
@@ -58,4 +58,9 @@ public interface ILawsReplacedStandardService extends IService<LawsReplacedStand
*/
void clearRepeatData();
/**
* 清理重复数据
*/
void newVersionESSendMsg(String standardId);
}
@@ -1,22 +1,26 @@
package com.jero.modules.laws.standard.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jero.modules.laws.common.service.ILawsCommonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.api.SendMessageAPI;
import com.jero.common.api.dto.message.SendMessageDTO;
import com.jero.common.exception.JeroBootException;
import com.jero.modules.laws.common.constant.MessageTemplateCodeCommon;
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
import com.jero.modules.laws.standard.entity.LawsReplacedStandard;
import com.jero.modules.laws.standard.mapper.LawsReplacedStandardMapper;
import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
import com.jero.modules.laws.standard.service.ILawsReplacedStandardService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jero.common.exception.JeroBootException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -26,16 +30,20 @@ import java.util.stream.Collectors;
* @Date: 2023-09-19
* @Version: V1.0
*/
@Slf4j
@Service
@Transactional(rollbackFor = JeroBootException.class)
public class LawsReplacedStandardServiceImpl extends ServiceImpl<LawsReplacedStandardMapper, LawsReplacedStandard> implements ILawsReplacedStandardService {
@Autowired
private ILawsCommonService lawsCommonService;
@Resource
private LawsReplacedStandardMapper replacedStandardMapper;
@Resource
private ILawsEnterpriseStandardService esService;
@Resource
private SendMessageAPI sendMessageAPI;
/**
* @Author: liao
* @Date: 2023/9/19 11:06
@@ -131,4 +139,63 @@ public class LawsReplacedStandardServiceImpl extends ServiceImpl<LawsReplacedSta
public void clearRepeatData() {
replacedStandardMapper.clearRepeatData();
}
@Override
public void newVersionESSendMsg(String standardId) {
LawsEnterpriseStandard es = esService.getById(standardId);
if (es == null) {
log.error("企业标准不存在,id" + standardId);
return;
}
// 找到所有当前标准的老版本标准
LambdaQueryWrapper<LawsEnterpriseStandard> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(LawsEnterpriseStandard::getStandardNumberTemp, es.getStandardNumberTemp());
queryWrapper.eq(LawsEnterpriseStandard::getStandardCode, es.getStandardCode());
queryWrapper.eq(LawsEnterpriseStandard::getNameCode, es.getNameCode());
queryWrapper.eq(LawsEnterpriseStandard::getCategoryCode, es.getCategoryCode());
queryWrapper.ne(LawsEnterpriseStandard::getYearNumber, es.getYearNumber());
List<LawsEnterpriseStandard> oldVersionStandard = esService.list(queryWrapper);
if (CollUtil.isEmpty(oldVersionStandard)) {
log.info("企业标准没有老版本,id" + standardId);
return;
}
// 找到年代号最大的那个
LawsEnterpriseStandard maxYearNumberStandard = oldVersionStandard.stream()
.max(Comparator.comparing(LawsEnterpriseStandard::getYearNumber)).get();
// 找到所有引用这些标准的标准
LambdaQueryWrapper<LawsReplacedStandard> replacedStandardWrapper = new LambdaQueryWrapper<>();
replacedStandardWrapper.eq(LawsReplacedStandard::getType, "2");
replacedStandardWrapper.like(LawsReplacedStandard::getReplaced, maxYearNumberStandard.getStandardNumber());
List<LawsReplacedStandard> replacedStandardList = list(replacedStandardWrapper);
if (CollUtil.isEmpty(replacedStandardList)) {
log.info("企业标准没有被引用,id" + standardId);
return;
}
LambdaQueryWrapper<LawsEnterpriseStandard> esWrapper = new LambdaQueryWrapper<>();
esWrapper.in(LawsEnterpriseStandard::getStandardNumber, replacedStandardList.stream()
.map(LawsReplacedStandard::getReplacedBy).collect(Collectors.toSet()));
List<LawsEnterpriseStandard> replacedStandard = esService.list(esWrapper);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
// 发消息
for (LawsEnterpriseStandard standard : replacedStandard) {
SendMessageDTO sendMessageDTO = new SendMessageDTO();
sendMessageDTO.setTemplateCode(MessageTemplateCodeCommon.IMPLEMENTATION_DATE_NEW_STANDARD);
Map<String, String> sendMap = new HashMap<>();
sendMap.put("standardNumber", standard.getStandardNumber());
sendMap.put("standardName", standard.getStandardName());
sendMap.put("implementationDate", simpleDateFormat.format(standard.getImplementationDate()));
Set<String> userIdList = new HashSet<>();
// 拼接发送人员
userIdList.add(standard.getMainDraftingUser());
// 去除最后一个分号
if (CollUtil.isEmpty(userIdList)) {
continue;
}
sendMessageDTO.setToUserId(String.join(",", userIdList));
sendMessageDTO.setMap(sendMap);
sendMessageAPI.sendMessage(sendMessageDTO);
}
}
}