法规清单 定时任务 发送消息。
This commit is contained in:
wangzhijiang
2022-04-19 19:38:59 +08:00
parent 0cdbe676ed
commit 2be7b38271
5 changed files with 190 additions and 36 deletions
@@ -310,10 +310,15 @@ public class ProjectLawsInventoryEO implements Serializable {
@ApiModelProperty(value = "任务确认-截止时间")
private Date taskAffirmDueDate;
/**任务确认-截止时间*/
@Excel(name = "任务确认-截止时间", width = 15, format = "yyyy-MM-dd")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
@ApiModelProperty(value = "任务确认-截止时间")
/**发送消息标识 三天*/
@ApiModelProperty(value = "发送消息标识 三天")
private String sendMsgFlag;
/**发送消息标识 结束当天*/
@ApiModelProperty(value = "发送消息标识 结束当天")
private String sendMsgCurrentFlag;
@TableField(exist = false)
@ApiModelProperty(value = "中英文切换标识")
private String cut;
}
@@ -0,0 +1,142 @@
package com.jero.modules.project.job;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jero.modules.project.entity.ProjectLawsInventoryEO;
import com.jero.modules.project.entity.ProjectLibraryBase;
import com.jero.modules.project.entity.ProjectNameInfoEO;
import com.jero.modules.project.enums.InventoryAffirmStatusEnum;
import com.jero.modules.project.enums.SendMsgFlagEnum;
import com.jero.modules.project.mapper.ProjectLawsInventoryEOMapper;
import com.jero.modules.project.mapper.ProjectLibraryBaseMapper;
import com.jero.modules.project.mapper.ProjectNameInfoEOMapper;
import com.jero.modules.project.service.IProjectLawsInventoryEOService;
import com.jero.modules.system.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* 清单确认定时器
*/
@Slf4j
public class InventoryAffirmJob implements Job {
@Autowired
private ProjectLawsInventoryEOMapper projectLawsInventoryEOMapper;
@Autowired
private ProjectLibraryBaseMapper projectLibraryBaseMapper;
@Autowired
private IProjectLawsInventoryEOService projectLawsInventoryEOService;
@Autowired
private ProjectNameInfoEOMapper projectNameInfoEOMapper;
/**
* 清单任务到达截止时间后,给用户发送消息
*/
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
//获取状态为待确认的数据
QueryWrapper<ProjectLawsInventoryEO> queryWrapperInventory = new QueryWrapper<>();
queryWrapperInventory.lambda().eq(ProjectLawsInventoryEO::getInventoryAffirmStatus, InventoryAffirmStatusEnum.LIST_TO_CONFIRM.getValue());
List<ProjectLawsInventoryEO> projectLawsInventoryEOList = projectLawsInventoryEOMapper.selectList(queryWrapperInventory);
if(CollectionUtils.isNotEmpty(projectLawsInventoryEOList)){
List<String> projectLibraryIdList = projectLawsInventoryEOList.stream().distinct()
.map(ProjectLawsInventoryEO::getProjectLibraryId).collect(Collectors.toList());
QueryWrapper<ProjectLibraryBase> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(ProjectLibraryBase::getId,projectLibraryIdList);
List<ProjectLibraryBase> projectLibraryBaseList = projectLibraryBaseMapper.selectList(queryWrapper);
if(CollectionUtils.isNotEmpty(projectLibraryBaseList)){
SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd");
Date currentDate = new Date();
//获取后三天前的时间
Calendar calendar=new GregorianCalendar();
calendar.setTime(new Date());
calendar.add(Calendar.DATE,3);
Date threeDays = calendar.getTime();
String threeDaysStr = sdf.format(threeDays);
String currentDateStr = sdf.format(currentDate);
for (ProjectLibraryBase projectLibraryBase : projectLibraryBaseList) {
QueryWrapper<ProjectNameInfoEO> projectNameInfoEOQueryWrapper = new QueryWrapper<>();
projectNameInfoEOQueryWrapper.lambda().eq(ProjectNameInfoEO::getId,projectLibraryBase.getProjectName());
ProjectNameInfoEO projectNameInfoEO = projectNameInfoEOMapper.selectOne(projectNameInfoEOQueryWrapper);
List<String> threeDaysUserIdList = new ArrayList<>();
List<String> currentDaysUserIdList = new ArrayList<>();
for (ProjectLawsInventoryEO projectLawsInventoryEO : projectLawsInventoryEOList) {
if(StringUtils.equals(projectLibraryBase.getId(),projectLawsInventoryEO.getProjectLibraryId())){
//如果清单确认结束日期是当前日期
if(StringUtils.equals(currentDateStr,sdf.format(projectLawsInventoryEO.getInventoryAffirmDueDate()))){
if(StringUtils.isEmpty(projectLawsInventoryEO.getSendMsgFlag())){
if(StringUtils.isNotEmpty(projectLawsInventoryEO.getRegulationOwnerId())){
currentDaysUserIdList.add(projectLawsInventoryEO.getRegulationOwnerId());
}if(StringUtils.isNotEmpty(projectLawsInventoryEO.getHomologationEngineerId())){
currentDaysUserIdList.add(projectLawsInventoryEO.getHomologationEngineerId());
}
projectLawsInventoryEO.setSendMsgFlag(SendMsgFlagEnum.FALSE.getValue());
projectLawsInventoryEOMapper.updateById(projectLawsInventoryEO);
}
}
//如果清单确认结束时间是当前系统时间后三天
if(StringUtils.equals(threeDaysStr,sdf.format(projectLawsInventoryEO.getInventoryAffirmDueDate()))){
if(StringUtils.isEmpty(projectLawsInventoryEO.getSendMsgCurrentFlag())){
if(StringUtils.isNotEmpty(projectLawsInventoryEO.getRegulationOwnerId())){
threeDaysUserIdList.add(projectLawsInventoryEO.getRegulationOwnerId());
}if(StringUtils.isNotEmpty(projectLawsInventoryEO.getHomologationEngineerId())){
threeDaysUserIdList.add(projectLawsInventoryEO.getHomologationEngineerId());
}
projectLawsInventoryEO.setSendMsgCurrentFlag(SendMsgFlagEnum.FALSE.getValue());
projectLawsInventoryEOMapper.updateById(projectLawsInventoryEO);
}
}
}
}
if(CollectionUtils.isNotEmpty(threeDaysUserIdList)){
threeDaysUserIdList = threeDaysUserIdList.stream().distinct().collect(Collectors.toList());
/*String msgContentCN = "您" + projectLibraryBase.getProjectName() + "(项目名称)法规清单的任务确认剩余处理时间还有3天,请及时查看处理";*/
String msgContentEN = "The remaining processing time for the regulation task confirmationof GB 7258 in"
+ projectNameInfoEO.getProjectName()
+ "(project name) is 3 days. Please check andhandle it in time.";
//发送消息
projectLawsInventoryEOService.sendMessage(msgContentEN,threeDaysUserIdList,projectLibraryBase.getId());
}
if(CollectionUtils.isNotEmpty(currentDaysUserIdList)){
currentDaysUserIdList = currentDaysUserIdList.stream().distinct().collect(Collectors.toList());
/*String msgContentCN = "您" + projectLibraryBase.getProjectName() + "(项目名称)法规清单的任务今天即将结束,请及时查看处理*/
String msgContentEN = "The the regulation task confirmation of GB 7258 in "
+ projectNameInfoEO.getProjectName()
+ "(projectname) is coming to an end today. Please check and deal with it intime";
//发送消息
projectLawsInventoryEOService.sendMessage(msgContentEN,currentDaysUserIdList,projectLibraryBase.getId());
}
}
}
}
}
}
@@ -70,6 +70,8 @@ public interface IProjectLawsInventoryEOService extends IService<ProjectLawsInve
*/
Result<?> updateStatusBatch(Map<String, Object> params);
void sendMessage(String msgContent, List<String> userIdList,String projectLibraryId);
/**
* 匹配相关人员
* @param params
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.jero.common.api.vo.Result;
import com.jero.common.constant.CommonConstant;
import com.jero.common.constant.WebsocketConst;
import com.jero.common.constant.enums.CutEnum;
import com.jero.common.constant.enums.MessageTypeEnum;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.query.QueryGenerator;
@@ -25,7 +26,6 @@ import com.jero.modules.project.mapper.ProjectLawsInventoryEOMapper;
import com.jero.modules.project.mapper.ProjectLibraryBaseMapper;
import com.jero.modules.project.mapper.ProjectRelatedPersonnelMapper;
import com.jero.modules.project.service.IProjectLawsInventoryEOService;
import com.jero.modules.project.service.IProjectRelatedPersonnelService;
import com.jero.modules.system.entity.SysAnnouncement;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.mapper.SysUserMapper;
@@ -195,7 +195,7 @@ public class ProjectLawsInventoryEOServiceImpl extends ServiceImpl<ProjectLawsIn
});
}
List<ProjectLawsInventoryEO> result = super.baseMapper.selectList(projectLawsInventoryEOQueryWrapper);
dataDispose(result,currentUser,isProjectRole);
dataDispose(result,currentUser,isProjectRole,projectLawsInventoryEO.getCut());
return result;
}
@@ -203,7 +203,7 @@ public class ProjectLawsInventoryEOServiceImpl extends ServiceImpl<ProjectLawsIn
* 数据处理
* @param list
*/
public void dataDispose(List<ProjectLawsInventoryEO> list,LoginUser currentUser,int isProjectRole){
public void dataDispose(List<ProjectLawsInventoryEO> list,LoginUser currentUser,int isProjectRole,String cut){
if(CollectionUtils.isNotEmpty(list)){
List<String> userIdList = new ArrayList<>();
List<String> deliverableList = new ArrayList<>();
@@ -252,19 +252,19 @@ public class ProjectLawsInventoryEOServiceImpl extends ServiceImpl<ProjectLawsIn
String homologationEngineerId = projectLawsInventoryEO.getHomologationEngineerId();
if(StringUtils.isNotEmpty(homologationEngineerId)){
String homologationEngineerName = sysUsers.stream().filter(e -> homologationEngineerId.equals(e.getId())).
map(SysUser::getRealname).collect(Collectors.joining(","));
map(SysUser::getUsername).collect(Collectors.joining(","));
projectLawsInventoryEO.setHomologationEngineerName(homologationEngineerName);
}
String regulationOwnerId = projectLawsInventoryEO.getRegulationOwnerId();
if(StringUtils.isNotEmpty(regulationOwnerId)){
String regulationOwnerName = sysUsers.stream().filter(e -> regulationOwnerId.equals(e.getId())).
map(SysUser::getRealname).collect(Collectors.joining(","));
map(SysUser::getUsername).collect(Collectors.joining(","));
projectLawsInventoryEO.setRegulationOwnerName(regulationOwnerName);
}
String engineeringInterfacePerson = projectLawsInventoryEO.getEngineeringInterfacePerson();
if(StringUtils.isNotEmpty(engineeringInterfacePerson)){
String engineeringInterfacePersonName = sysUsers.stream().filter(e -> engineeringInterfacePerson.equals(e.getId())).
map(SysUser::getRealname).collect(Collectors.joining(","));
map(SysUser::getUsername).collect(Collectors.joining(","));
projectLawsInventoryEO.setEngineeringInterfacePersonName(engineeringInterfacePersonName);
}
}
@@ -272,7 +272,12 @@ public class ProjectLawsInventoryEOServiceImpl extends ServiceImpl<ProjectLawsIn
//清单确认状态
String inventoryAffirmStatus = projectLawsInventoryEO.getInventoryAffirmStatus();
if(StringUtils.isNotEmpty(inventoryAffirmStatus)){
projectLawsInventoryEO.setInventoryAffirmStatusName(InventoryAffirmStatusEnum.getTextByValue(inventoryAffirmStatus));
if(StringUtils.equals(cut, CutEnum.CN.getValue())){
projectLawsInventoryEO.setInventoryAffirmStatusName(InventoryAffirmStatusEnum.getTextByValue(inventoryAffirmStatus));
}else {
projectLawsInventoryEO.setInventoryAffirmStatusName(inventoryAffirmStatus);
}
}
//任务确认状态
String taskAffirmStatus = projectLawsInventoryEO.getTaskAffirmStatus();
@@ -447,6 +452,7 @@ public class ProjectLawsInventoryEOServiceImpl extends ServiceImpl<ProjectLawsIn
List<ProjectLawsInventoryEO> projectLawsInventoryEOS = this.baseMapper.selectList(queryWrapper);
ProjectLibraryBase projectLibraryBase = projectLibraryBaseMapper.selectOne(new QueryWrapper<ProjectLibraryBase>()
.lambda().eq(ProjectLibraryBase::getId, projectLibraryId));
List<String> userIdList = new ArrayList<>();
for (ProjectLawsInventoryEO projectLawsInventoryEO : projectLawsInventoryEOS) {
//如果该数据的状态为 未发起或拒绝 可以发起清单确认
@@ -464,16 +470,26 @@ public class ProjectLawsInventoryEOServiceImpl extends ServiceImpl<ProjectLawsIn
updateWrapper.set(ProjectLawsInventoryEO::getHomologationEngineerSubmitStatus,null);
updateWrapper.eq(ProjectLawsInventoryEO::getId,projectLawsInventoryEO.getId());
super.update(projectLawsInventoryEO, updateWrapper);
//消息内容
// String msgContentCN = currentUser.getRealname() + "发起了 " + projectLibraryBase.getProjectName()
// + " (项目名称)法规的清单确认,截止时间为:" +inventoryAffirmDueDate+ " 请及时查看处理。";
String msgContentEN = currentUser.getRealname() + "发起了 " + projectLibraryBase.getProjectName()
+ " (项目名称)法规的清单确认,截止时间为:" +inventoryAffirmDueDate+ " 请及时查看处理。";
//发送消息
sendMessage(msgContentEN,projectLawsInventoryEO);
userIdList.add(projectLawsInventoryEO.getHomologationEngineerId());
userIdList.add(projectLawsInventoryEO.getRegulationOwnerId());
}
}
if(CollectionUtils.isNotEmpty(userIdList)){
userIdList = userIdList.stream().distinct().collect(Collectors.toList());
//消息内容
//String msgContentCN = currentUser.getUsername() + "发起了 " + projectLibraryBase.getProjectName()
//+ " (项目名称)法规的清单确认,截止时间为:" +inventoryAffirmDueDate+ " 请及时查看处理。";
String msgContentEN = currentUser.getUsername() + "initiated the regulation list confirmation of " + projectLibraryBase.getProjectName()
+ " (project name).The due date is" +inventoryAffirmDueDate+ ". Please check and deal with it in time.";
//XXX XXX XXXXXX
//发送消息
sendMessage(msgContentEN,userIdList,projectLibraryId);
}
result = "发起清单确认";
}else if(StringUtils.equals(operatorType,OperatorTypeEnum.SUBMIT_OR_REJECTED.getValue())){
//提交结果 0通过 1拒绝
@@ -536,26 +552,15 @@ public class ProjectLawsInventoryEOServiceImpl extends ServiceImpl<ProjectLawsIn
* @param msgContent
* @param projectLawsInventoryEO
*/
public void sendMessage(String msgContent,ProjectLawsInventoryEO projectLawsInventoryEO){
@Override
public void sendMessage(String msgContent, List<String> userIdList,String projectLibraryId){
String idTemp = projectLawsInventoryEO.getProjectLibraryId();
List<String> userIdList = new ArrayList<>();
String homologationEngineerId = projectLawsInventoryEO.getHomologationEngineerId();
String regulationOwnerId = projectLawsInventoryEO.getRegulationOwnerId();
if(StringUtils.isNotEmpty(homologationEngineerId)){
userIdList.add(homologationEngineerId);
}
if(StringUtils.isNotEmpty(regulationOwnerId)){
userIdList.add(regulationOwnerId);
}
userIdList = userIdList.stream().distinct().collect(Collectors.toList());
String idTemp = projectLibraryId;
List<SysUser> sysUsers = sysUserService.listByIds(userIdList);
List<String> thirdIdList = new ArrayList<>();
if(CollectionUtils.isNotEmpty(sysUsers)){
thirdIdList = sysUsers.stream().map(SysUser::getThirdId).collect(Collectors.toList());
}
//系统消息
@@ -286,7 +286,7 @@ public class ProjectRelatedPersonnelServiceImpl extends ServiceImpl<ProjectRelat
for (SysUser sysUser : sysUserList) {
if(StringUtils.equals(lawEngineer,sysUser.getId())){
Map<String,Object> map = new HashMap<>();
map.put("name",sysUser.getRealname());
map.put("name",sysUser.getUsername());
map.put("value",sysUser.getId());
lawEngineerList.add(map);
}
@@ -300,7 +300,7 @@ public class ProjectRelatedPersonnelServiceImpl extends ServiceImpl<ProjectRelat
for (SysUser sysUser : sysUserList) {
if(StringUtils.equals(certificationEngineer,sysUser.getId())){
Map<String,Object> map = new HashMap<>();
map.put("name",sysUser.getRealname());
map.put("name",sysUser.getUsername());
map.put("value",sysUser.getId());
certificationEngineerList.add(map);
}
@@ -313,7 +313,7 @@ public class ProjectRelatedPersonnelServiceImpl extends ServiceImpl<ProjectRelat
for (SysUser sysUser : sysUserList) {
if(StringUtils.equals(engineeringInterfacePerson,sysUser.getId())){
Map<String,Object> map = new HashMap<>();
map.put("name",sysUser.getRealname());
map.put("name",sysUser.getUsername());
map.put("value",sysUser.getId());
engineeringInterfacePersonList.add(map);
}