完成定时任务和短信和消息通知

This commit is contained in:
shuo.wang
2024-05-11 13:42:37 +08:00
parent 3a7940bcb8
commit a37c20e840
8 changed files with 175 additions and 68 deletions

View File

@@ -30,6 +30,7 @@ import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -203,12 +204,8 @@ public class XxlJobHandler {
if (Objects.nonNull(approach)) {
Date date = CoolDateUtils.parseDate(approach.getActualBeginDate(), CoolDateUtils.DATE_FORMAT_DAY);
if (Objects.nonNull(date)) {
Instant instant = date.toInstant();
ZoneId zone = ZoneId.systemDefault();
LocalDate localDate = instant.atZone(zone).toLocalDate();
LocalDate datePlusFiveDays = localDate.plusDays(CommonConstants.FOUR); // 5天
LocalDate now = LocalDate.now();
if (datePlusFiveDays.equals(now)) {
Result result = getResult(date,CommonConstants.FOUR);
if (result.datePlusDays.equals(result.localDate)) {
//三方验收带预约
shopStageInfoDAO.updateShopStageInfo(shopId, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_120);
}
@@ -241,7 +238,6 @@ public class XxlJobHandler {
int pageNum = 1;
int pageSize = 50;
while (hasNext) {
//TODO
PageHelper.startPage(pageNum, pageSize);
//获取为带预约状态的
List<ShopStageInfoDO> shopIdListByStageStatus = shopStageInfoDAO.
@@ -252,27 +248,33 @@ public class XxlJobHandler {
}
List<Long> shopIds = shopIdListByStageStatus.stream().filter(o -> o.getShopId() != null).map(o -> o.getShopId()).collect(Collectors.toList());
List<AcceptanceInfoDO> acceptanceInfoDOS = acceptanceInfoDAO.selectByShopIds(shopIds);
int flag = CommonConstants.ZERO;
for (AcceptanceInfoDO acceptanceInfoDO : acceptanceInfoDOS) {
//进场时间
Date approach = acceptanceInfoDO.getActualEntryTime();
if (Objects.nonNull(approach)) {
Instant instant = approach.toInstant();
ZoneId zone = ZoneId.systemDefault();
LocalDate localDate = instant.atZone(zone).toLocalDate();
LocalDate datePlusFiveDays = localDate.plusDays(CommonConstants.FOUR); // 5天
if (datePlusFiveDays.equals(localDate)) {
//三方验收带预约
ShopInfoDO shopInfo = shopInfoDAO.getShopInfo(acceptanceInfoDO.getShopId());
EnterpriseUserDO userByRoleEnumAndRegionId = userAuthMappingService
.getUserByRoleEnumAndRegionId(UserRoleEnum.ENGINEER_DEP_SUPERVISOR, shopInfo.getRegionId());
LineInfoDO lineInfo = lineInfoDAO.getLineInfo(shopInfo.getLineId());
Map<String, String> messageMap = new HashMap<>();
messageMap.put("storeName", shopInfo.getShopName());
messageMap.put("partnerUsername", lineInfo.getUsername());
messageMap.put("partnerMobile", lineInfo.getMobile());
commonService.sendMessage(Arrays.asList(userByRoleEnumAndRegionId.getUserId()), MessageEnum.MESSAGE_24, messageMap);
while (flag < CommonConstants.TWO) {
try {
Date approach = acceptanceInfoDO.getActualEntryTime();
if (Objects.nonNull(approach)) {
Result result = getResult(approach,CommonConstants.FOUR);
if (result.datePlusDays.equals(result.localDate)) {
ShopInfoDO shopInfo = shopInfoDAO.getShopInfo(acceptanceInfoDO.getShopId());
EnterpriseUserDO userByRoleEnumAndRegionId = userAuthMappingService
.getUserByRoleEnumAndRegionId(UserRoleEnum.ENGINEER_DEP_SUPERVISOR, shopInfo.getRegionId());
LineInfoDO lineInfo = lineInfoDAO.getLineInfo(shopInfo.getLineId());
Map<String, String> messageMap = new HashMap<>();
messageMap.put("storeName", shopInfo.getShopName());
messageMap.put("partnerUsername", lineInfo.getUsername());
messageMap.put("partnerMobile", lineInfo.getMobile());
commonService.sendMessage(Arrays.asList(userByRoleEnumAndRegionId.getUserId()), MessageEnum.MESSAGE_24, messageMap);
}
}
break;
} catch (Exception e) {
log.error("------定时任务三方验收待预约钉钉通知失败,shopId:{}", acceptanceInfoDO.getShopId());
flag++;
}
}
flag = CommonConstants.ZERO;
}
hasNext = shopIdListByStageStatus.size() >= pageSize;
pageNum++;
@@ -280,10 +282,29 @@ public class XxlJobHandler {
}
private static @NotNull Result getResult(Date date,Integer days) {
Instant instant = date.toInstant();
ZoneId zone = ZoneId.systemDefault();
LocalDate localDate = instant.atZone(zone).toLocalDate();
LocalDate datePlusFiveDays = localDate.plusDays(days); // 5天
Result result = new Result(localDate, datePlusFiveDays);
return result;
}
private static class Result {
public final LocalDate localDate;
public final LocalDate datePlusDays;
public Result(LocalDate localDate, LocalDate datePlusDays) {
this.localDate = localDate;
this.datePlusDays = datePlusDays;
}
}
/**
* @Auther: wangshuo
* @Date: 2024/5/7
* @description:三方验收预约短信通知+7day
* @description:三方验收预约短信通知,进场时间+7天的1800发送短信到加盟商
*/
@XxlJob("threeAcceptanceMessage")
public void threeAcceptanceMessage() {
@@ -305,31 +326,67 @@ public class XxlJobHandler {
Map<Long, ShopStageInfoDO> lineIdMap = ShopStageInfoList.stream().filter(o -> o.getLineId() != null)
.collect(Collectors.toMap(ShopStageInfoDO::getLineId, Function.identity()));
List<AcceptanceInfoDO> acceptanceList = acceptanceInfoDAO.selectByShopIds(shopIds);
int flag = CommonConstants.ZERO;
for (AcceptanceInfoDO acceptanceInfoDO : acceptanceList) {
while (flag < CommonConstants.TWO) {
try {
Date approach = acceptanceInfoDO.getActualEntryTime();
if (Objects.nonNull(approach)) {
Result result = getResult(approach,CommonConstants.SIX);//7 day
if (result.datePlusDays.equals(result.localDate)) {
//三方验收带预约
ShopInfoDO shopInfo = shopInfoDAO.getShopInfo(acceptanceInfoDO.getShopId());
EnterpriseUserDO supervisor = userAuthMappingService
.getUserByRoleEnumAndRegionId(UserRoleEnum.ENGINEER_DEP_SUPERVISOR, shopInfo.getRegionId());
//获取撤场计划完成时间
List<ConstructionScheduleDTO> construction = decorationService.getConstruction(acceptanceInfoDO.getShopId());
Map<String, ConstructionScheduleDTO> map = construction.stream()
.filter(o -> StringUtils.isNoneBlank(o.getName()))
.collect(Collectors.toMap(ConstructionScheduleDTO::getName, dto -> dto));
ConstructionScheduleDTO withdrawal = map.get(CommonConstants.WITHDRAWAL);
//获取施工阶段计划完成时间
ConstructionScheduleDTO constructionInfo = decorationService.getConstructionInfo(acceptanceInfoDO.getShopId());
//获取计划验收时间
String palnAcceptanceTime = CoolDateUtils.DateFormat(acceptanceInfoDO.getPlanAcceptanceTime(), CoolDateUtils.DATE_FORMAT_SEC);
//区域监理name
String supervisorName = enterpriseUserDAO.getUserName(supervisor.getUserId());
//区域监理手机号
String mobile = supervisor.getMobile();
Map<String, String> messageMap = new HashMap<>();
if (Objects.nonNull(withdrawal) && withdrawal.getPlanEndDate() != null) {
messageMap.put("demolitionPlanTime", withdrawal.getPlanEndDate());
} else {
for (AcceptanceInfoDO acceptance : acceptanceList) {
Date approach = acceptance.getActualEntryTime();
if (Objects.nonNull(approach)) {
Instant instant = approach.toInstant();
ZoneId zone = ZoneId.systemDefault();
LocalDate localDate = instant.atZone(zone).toLocalDate();
LocalDate datePlusFiveDays = localDate.plusDays(CommonConstants.SIX); // 7天
if (datePlusFiveDays.equals(localDate)) {
ShopStageInfoDO stageInfoDO = lineIdMap.get(acceptance.getShopId());
if (Objects.nonNull(stageInfoDO)) {
Long lineId = stageInfoDO.getLineId();
LineInfoDO lineInfo = lineInfoDAO.getLineInfo(lineId);
Map<String, String> templateParam = new HashMap<>();
commonService.sendSms(lineInfo.getMobile(), SMSMsgEnum.THREE_ACCEPTANCE_WAIT, null);
if (Objects.nonNull(constructionInfo)) {
messageMap.put("demolitionPlanTime", constructionInfo.getPlanEndDate());
}
}
messageMap.put("palnAcceptanceTime", palnAcceptanceTime);
messageMap.put("supervisionName", supervisorName);
messageMap.put("supervisionMobile", mobile);
//加盟商手机号
ShopStageInfoDO stageInfoDO = lineIdMap.get(acceptanceInfoDO.getShopId());
Long lineId = stageInfoDO.getLineId();
LineInfoDO lineInfo = lineInfoDAO.getLineInfo(lineId);
commonService.sendSms(lineInfo.getMobile(), SMSMsgEnum.THREE_ACCEPTANCE_WAIT, messageMap);
}
}
break;
} catch (Exception e) {
log.error("定时任务三方验收预约短信通知失败 shopId:{}", acceptanceInfoDO.getShopId());
flag++;
}
}
flag = CommonConstants.ZERO;
}
hasNext = ShopStageInfoList.size() >= pageSize;
pageNum++;
}
XxlJobHelper.handleSuccess();
}
/**
* @Auther: wangshuo
* @Date: 2024/5/7
@@ -337,7 +394,7 @@ public class XxlJobHandler {
*/
@XxlJob("waitThreeAcceptanceMessage")
public void waitThreeAcceptanceMessage() {
log.info("------定时任务三方待验收通知-----");
log.info("------定时任务三方待验收钉钉通知-----");
boolean hasNext = true;
int pageNum = 1;
int pageSize = 50;
@@ -347,7 +404,7 @@ public class XxlJobHandler {
List<ShopStageInfoDO> ShopStageInfoList = shopStageInfoDAO.
getShopIdListByStageStatus(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_121.getShopSubStageStatus());
if (CollectionUtils.isEmpty(ShopStageInfoList)) {
log.info("------定时任务结束三方验收预约短信通知------");
log.info("------定时任务结束三方验收钉钉通知------");
return;
}
List<Long> shopIds = ShopStageInfoList.stream().filter(o -> o.getShopId() != null)
@@ -355,21 +412,26 @@ public class XxlJobHandler {
Map<Long, ShopStageInfoDO> lineIdMap = ShopStageInfoList.stream().filter(o -> o.getLineId() != null)
.collect(Collectors.toMap(ShopStageInfoDO::getLineId, Function.identity()));
List<AcceptanceInfoDO> acceptanceList = acceptanceInfoDAO.selectByShopIds(shopIds);
List<ShopInfoDO> shopListByIds = shopInfoDAO.getShopListByIds(shopIds);
Map<Long, ShopInfoDO> shopIdMap = shopListByIds.stream().filter(o -> o.getId() != null)
.collect(Collectors.toMap(ShopInfoDO::getId, Function.identity()));
for (AcceptanceInfoDO acceptance : acceptanceList) {
//进场时间
Date approach = acceptance.getActualEntryTime();
Long shopId = acceptance.getShopId();
if (Objects.nonNull(approach)) {
Instant instant = approach.toInstant();
ZoneId zone = ZoneId.systemDefault();
LocalDate localDate = instant.atZone(zone).toLocalDate();
LocalDate datePlusFiveDays = localDate.plusDays(CommonConstants.SIX); // 7天
if (datePlusFiveDays.equals(localDate)) {
ShopStageInfoDO stageInfoDO = lineIdMap.get(acceptance.getShopId());
if (Objects.nonNull(stageInfoDO)) {
Long lineId = stageInfoDO.getLineId();
LineInfoDO lineInfo = lineInfoDAO.getLineInfo(lineId);
commonService.sendSms(lineInfo.getMobile(), SMSMsgEnum.THREE_ACCEPTANCE_WAIT, null);
}
Result result = getResult(approach,CommonConstants.SIX);//7天
if (result.datePlusDays.equals(result.localDate)) {
ShopStageInfoDO stageInfoDO = lineIdMap.get(shopId);
ShopInfoDO shopInfoDO = shopIdMap.get(shopId);
Long lineId = stageInfoDO.getLineId();
LineInfoDO lineInfo = lineInfoDAO.getLineInfo(lineId);
Map<String, String> messageMap = new HashMap<>();
messageMap.put("storeName",shopInfoDO.getShopName());
messageMap.put("partnerUsername", lineInfo.getUsername());
messageMap.put("partnerMobile", lineInfo.getMobile());
commonService.sendMessage(Arrays.asList(shopInfoDO.getSupervisorUserId()), MessageEnum.MESSAGE_25, messageMap);
}
}
}