update 标准预警发送消息
This commit is contained in:
+3
-1
@@ -34,6 +34,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -57,7 +59,7 @@ public class LawsProblemLibraryServiceImpl extends ServiceImpl<LawsProblemLibrar
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private ISysDepartService sysDepartService;
|
||||
@Autowired
|
||||
@Resource
|
||||
private SendMessageAPI sendMessageAPI;
|
||||
|
||||
@Override
|
||||
|
||||
+57
-8
@@ -3,6 +3,9 @@ package com.jero.modules.laws.localTool.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.dto.message.SendMessageDTO;
|
||||
import com.jero.common.api.vo.SendMessageAPI;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.modules.laws.common.constant.MessageTemplateCodeCommon;
|
||||
import com.jero.modules.laws.common.util.DateUtil;
|
||||
import com.jero.modules.laws.localTool.entity.StandardEarlyWarning;
|
||||
@@ -17,12 +20,14 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -42,6 +47,8 @@ public class LawsStandardEarlyWarningServiceImpl implements ILawsStandardEarlyWa
|
||||
private ILawsStandardEarlyWarningService lawsStandardEarlyWarningService;
|
||||
@Resource
|
||||
private ISysUserDepartService userDepartService;
|
||||
@Resource
|
||||
private SendMessageAPI sendMessageAPI;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
@@ -106,7 +113,7 @@ public class LawsStandardEarlyWarningServiceImpl implements ILawsStandardEarlyWa
|
||||
.values()
|
||||
.stream()
|
||||
.collect(Collectors.toList());
|
||||
sendMsgList(MessageTemplateCodeCommon.NEW_MODEL_IMPLEMENTATION, distinctList);
|
||||
sendMsgList(MessageTemplateCodeCommon.NEW_MODEL_IMPLEMENTATION, distinctList, true);
|
||||
}
|
||||
// 在产车实施日期
|
||||
if (CollectionUtils.isNotEmpty(onList)) {
|
||||
@@ -118,7 +125,7 @@ public class LawsStandardEarlyWarningServiceImpl implements ILawsStandardEarlyWa
|
||||
.values()
|
||||
.stream()
|
||||
.collect(Collectors.toList());
|
||||
sendMsgList(MessageTemplateCodeCommon.ON_THE_PRODUCTION, distinctList);
|
||||
sendMsgList(MessageTemplateCodeCommon.ON_THE_PRODUCTION, distinctList, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +134,8 @@ public class LawsStandardEarlyWarningServiceImpl implements ILawsStandardEarlyWa
|
||||
* @Date: 2023/11/10 17:39
|
||||
* @Description: 发送消息
|
||||
**/
|
||||
private void sendMsgList(String templateCode, List<StandardEarlyWarning> distinctList) {
|
||||
private void sendMsgList(String templateCode, List<StandardEarlyWarning> distinctList, Boolean flag) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
distinctList.forEach(data -> {
|
||||
String departId = data.getResponsibleDepartment();
|
||||
LambdaQueryWrapper<SysUserDepart> queryWrapper = new LambdaQueryWrapper<>();
|
||||
@@ -136,9 +144,50 @@ public class LawsStandardEarlyWarningServiceImpl implements ILawsStandardEarlyWa
|
||||
if (CollectionUtils.isNotEmpty(userDepartList)) {
|
||||
// 每个部门需要发消息的用户id集合
|
||||
List<String> userIdList = userDepartList.stream().map(SysUserDepart::getUserId).collect(Collectors.toList());
|
||||
|
||||
String userIds = StringUtils.join(userIdList, ",");
|
||||
SendMessageDTO sendMessageDTO = new SendMessageDTO();
|
||||
sendMessageDTO.setTemplateCode(templateCode);
|
||||
sendMessageDTO.setToUserId(userIds);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("standardNumber", data.getStandardNumber());
|
||||
map.put("standardName", data.getStandardName());
|
||||
Date date;
|
||||
Date toDay = new Date();
|
||||
try {
|
||||
if (flag) { // 新车型实施日期
|
||||
date = dateFormat.parse(data.getNewModelImplementationDate());
|
||||
} else { // 在产车实施日期
|
||||
date = dateFormat.parse(data.getOnTheProductionDate());
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
throw new JeroBootException("时间格式转换错误");
|
||||
}
|
||||
long days = getBetweenDays(date, toDay);
|
||||
map.put("days", days + "");
|
||||
sendMessageDTO.setMap(map);
|
||||
sendMessageAPI.sendMessage(sendMessageDTO);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/11/10 18:46
|
||||
* @Description: 获取两个日期之间的天数
|
||||
**/
|
||||
private long getBetweenDays(Date startDate, Date endDate) {
|
||||
// 将 Date 转换为 Instant
|
||||
Instant startInstant = startDate.toInstant();
|
||||
Instant endInstant = endDate.toInstant();
|
||||
|
||||
// 将 Instant 转换为 LocalDate
|
||||
LocalDate startLocalDate = startInstant.atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
LocalDate endLocalDate = endInstant.atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
|
||||
// 使用 ChronoUnit 计算日期差
|
||||
long days = ChronoUnit.DAYS.between(startLocalDate, endLocalDate);
|
||||
return days;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user