fix (farm): 消息中心
- 自动推送农事计划 开始,结束消息 - 自动推送生产计划 逾期消息
This commit is contained in:
@@ -4,10 +4,11 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 种植中心-生产计划-生产计划新增/修改 Request VO")
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ProductionPlanSaveReqVO {
|
||||
|
||||
@Schema(description = "基础id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1050")
|
||||
|
||||
@@ -77,7 +77,8 @@ public class MessageCenterController {
|
||||
@Operation(summary = "获得消息中心分页")
|
||||
public CommonResult<PageResult<MessageCenterRespVO>> getMessageCenterPage(@Valid MessageCenterPageReqVO pageReqVO) {
|
||||
PageResult<MessageCenterDO> pageResult = messageCenterService.getMessageCenterPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, MessageCenterRespVO.class));
|
||||
PageResult<MessageCenterRespVO> res = BeanUtils.toBean(pageResult, MessageCenterRespVO.class);
|
||||
return success(res);
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
|
||||
@@ -29,7 +29,7 @@ public class MessageCenterPageReqVO extends PageParam {
|
||||
private Integer alarmStatus;
|
||||
|
||||
@Schema(description = "推送次数")
|
||||
private Integer number;
|
||||
private Integer pushCount;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@@ -39,6 +39,11 @@ public class MessageCenterPageReqVO extends PageParam {
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] readTime;
|
||||
|
||||
@Schema(description = "已读员工ID")
|
||||
private Long readUserId;
|
||||
@Schema(description = "已读员工姓名")
|
||||
private String readUserName;
|
||||
|
||||
@Schema(description = "基地id", example = "3475")
|
||||
private String baseId;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import cn.idev.excel.annotation.*;
|
||||
|
||||
@@ -38,16 +38,23 @@ public class MessageCenterRespVO {
|
||||
|
||||
@Schema(description = "推送次数")
|
||||
@ExcelProperty("推送次数")
|
||||
private Integer number;
|
||||
private Integer pushCount;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss")
|
||||
@Schema(description = "创建时间")
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "已读时间")
|
||||
@ExcelProperty("已读时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime readTime;
|
||||
|
||||
@Schema(description = "已读员工ID")
|
||||
private Long readUserId;
|
||||
@Schema(description = "已读员工姓名")
|
||||
private String readUserName;
|
||||
|
||||
@Schema(description = "基地id", example = "3475")
|
||||
@ExcelProperty("基地id")
|
||||
private String baseId;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class MessageCenterSaveReqVO {
|
||||
private Integer alarmStatus;
|
||||
|
||||
@Schema(description = "推送次数")
|
||||
private Integer number;
|
||||
private Integer pushCount;
|
||||
|
||||
@Schema(description = "已读时间")
|
||||
private LocalDateTime readTime;
|
||||
|
||||
@@ -51,11 +51,18 @@ public class MessageCenterDO extends BaseDO {
|
||||
/**
|
||||
* 推送次数
|
||||
*/
|
||||
private Integer number;
|
||||
private Integer pushCount;
|
||||
/**
|
||||
* 已读时间
|
||||
*/
|
||||
private LocalDateTime readTime;
|
||||
/**
|
||||
* 已读员工ID
|
||||
*/
|
||||
private Long readUserId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String readUserName;
|
||||
/**
|
||||
* 基地id
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,7 @@ public interface MessageCenterMapper extends BaseMapperX<MessageCenterDO> {
|
||||
.eqIfPresent(MessageCenterDO::getContent, reqVO.getContent())
|
||||
.eqIfPresent(MessageCenterDO::getReadStatus, reqVO.getReadStatus())
|
||||
.eqIfPresent(MessageCenterDO::getAlarmStatus, reqVO.getAlarmStatus())
|
||||
.eqIfPresent(MessageCenterDO::getNumber, reqVO.getNumber())
|
||||
.eqIfPresent(MessageCenterDO::getPushCount, reqVO.getPushCount())
|
||||
.betweenIfPresent(MessageCenterDO::getCreateTime, reqVO.getCreateTime())
|
||||
.betweenIfPresent(MessageCenterDO::getReadTime, reqVO.getReadTime())
|
||||
.eqIfPresent(MessageCenterDO::getBaseId, reqVO.getBaseId())
|
||||
|
||||
@@ -94,6 +94,11 @@ public class CommonConstants {
|
||||
public final static Integer INPUT_CATEGORY_1 = 1; // 模版类型
|
||||
public final static Integer INPUT_CATEGORY_2 = 2; // 引用类型
|
||||
|
||||
// 1=报警,2=预警,3=消息
|
||||
public final static Integer MESSAGE_TYPE_1 = 1;
|
||||
public final static Integer MESSAGE_TYPE_2 = 2;
|
||||
public final static Integer MESSAGE_TYPE_3 = 3;
|
||||
|
||||
public static Map<Integer, String> PLAN_MAP = new HashMap<>();
|
||||
public static Map<String, String> LIFE_CYCLE_MAP = new HashMap<>();
|
||||
public static Map<String, String> GRID_TYPE = new HashMap<>();
|
||||
|
||||
@@ -45,92 +45,9 @@ public class FarmingRecordJob implements JobHandler {
|
||||
@Override
|
||||
public String execute(String param) throws Exception {
|
||||
productionPlanManager.autoUpdateFarmRecordStatus();
|
||||
// List<FarmingRecordSaveReqVO> list = this.insertRecordHandler();
|
||||
// for (FarmingRecordSaveReqVO e : list) {
|
||||
// List<String> taskTime = e.getTaskTime();
|
||||
// if (taskTime.size() != 2) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// LocalDate today = LocalDate.now();
|
||||
// LocalDate startDate = LocalDate.parse(taskTime.get(0));
|
||||
// LocalDate endDate = LocalDate.parse(taskTime.get(1));
|
||||
// boolean isStartToday = startDate.isEqual(today);
|
||||
// boolean isEndToday = endDate.isEqual(today);
|
||||
//
|
||||
// if (isStartToday) {
|
||||
// // 开始日期在今天
|
||||
// e.setTaskStatus(FARMING_RECORD_STATUS_1);
|
||||
// farmingRecordService.createFarmingRecordForJob(e);
|
||||
// }
|
||||
// if (isEndToday) {
|
||||
// // 结束日期在今天
|
||||
// e.setTaskStatus(FARMING_RECORD_STATUS_2);
|
||||
// farmingRecordService.updateFarmingRecord(e);
|
||||
// }
|
||||
// }
|
||||
return "success";
|
||||
}
|
||||
|
||||
// private List<FarmingRecordSaveReqVO> insertRecordHandler() {
|
||||
// // 获取[进行中]状态的计划
|
||||
// List<ProductionPlanDO> plans = productionPlanService.getProductionPlans();
|
||||
// Map<String, ProductionPlanDO> planMap = plans.stream().filter(e -> Objects.equals(e.getPlanStatus(), PLAN_STATUS_2)).collect(Collectors.toMap(ProductionPlanDO::getSpeciesModelId, e -> e, (v1, v2) -> v1));
|
||||
// List<String> taskIdList = plans.stream().filter(e -> Objects.equals(e.getPlanStatus(), PLAN_STATUS_2)).map(ProductionPlanDO::getId).collect(Collectors.toList());
|
||||
//
|
||||
// // 获取引用模型集合 key: modelId;
|
||||
// Map<String, List<ModelFarmingOperationDO>> modelIdMap = modelManagementService.getRecordList(taskIdList);
|
||||
//
|
||||
// List<FarmingRecordSaveReqVO> farmingRecordSaveReqVOList = new ArrayList<>();
|
||||
// for (Map.Entry<String, List<ModelFarmingOperationDO>> en : modelIdMap.entrySet()) {
|
||||
// String modelId = en.getKey();
|
||||
// List<ModelFarmingOperationDO> operationList = en.getValue();
|
||||
//
|
||||
// for (ModelFarmingOperationDO e : operationList) {
|
||||
// farmingRecordSaveReqVOList.add(this.buildFarmingRecord(planMap.get(modelId), e));
|
||||
// }
|
||||
// }
|
||||
// return farmingRecordSaveReqVOList;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private FarmingRecordSaveReqVO buildFarmingRecord(ProductionPlanDO p, ModelFarmingOperationDO e) {
|
||||
// LocalDate productionStartDate = p.getProductionStartDate();
|
||||
// // 从第startingPeriod天开始
|
||||
// Integer startingPeriod = e.getStartingPeriod();
|
||||
// // 用时天数
|
||||
// Integer used = e.getUsed();
|
||||
// // 农事记录开始日期
|
||||
// LocalDate startDate = productionStartDate.plusDays(startingPeriod-1);
|
||||
// // 农事记录结束日期
|
||||
// LocalDate endDate = startDate.plusDays(used);
|
||||
//// String taskTime = startDate + "," + endDate;
|
||||
// List<String> taskTime = Arrays.asList(startDate.toString(), endDate.toString());
|
||||
//
|
||||
// FarmingRecordSaveReqVO saveObj = new FarmingRecordSaveReqVO();
|
||||
// saveObj.setTaskType(e.getFarmingId());
|
||||
// saveObj.setTaskName(e.getFarmingName());
|
||||
// saveObj.setTaskScope(p.getPlanNumber());
|
||||
// saveObj.setTaskTime(taskTime);
|
||||
// saveObj.setTaskStartDate(startDate);
|
||||
// saveObj.setTaskEndDate(endDate);
|
||||
// saveObj.setProductionPlanId(p.getId());
|
||||
// saveObj.setModelFarmingOperationId(e.getId());
|
||||
// saveObj.setExecutor("系统");
|
||||
// saveObj.setActualLaborCost(e.getUsed());
|
||||
// saveObj.setFeedbackNotes(e.getDescription());
|
||||
// saveObj.setFeedbackImageUrl("");
|
||||
// saveObj.setFeedbackImageUrlList(e.getSketchList());
|
||||
// saveObj.setBaseId(p.getBaseId());
|
||||
// saveObj.setBaseName(p.getBaseName());
|
||||
// saveObj.setPlotId(p.getPlotId());
|
||||
// saveObj.setPlotName(p.getPlotName());
|
||||
// saveObj.setTenantId(p.getTenantId());
|
||||
// saveObj.setModelFarmingOperationId(e.getId());
|
||||
// saveObj.setInputsIds(e.getInputsIds());
|
||||
// saveObj.setTaskStatus(FARMING_RECORD_STATUS_1);
|
||||
// return saveObj;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,20 +2,10 @@ package cn.iocoder.yudao.module.farm.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
||||
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.productionplan.ProductionPlanSaveReqVO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.productionplan.ProductionPlanDO;
|
||||
import cn.iocoder.yudao.module.farm.service.productionplan.ProductionPlanService;
|
||||
import cn.iocoder.yudao.module.farm.manager.perductionplan.ProductionPlanManager;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.module.farm.enums.CommonConstants.*;
|
||||
|
||||
/**
|
||||
* @description: 生产计划状态
|
||||
* 任务周期: 每天 00:00:00
|
||||
@@ -27,10 +17,10 @@ import static cn.iocoder.yudao.module.farm.enums.CommonConstants.*;
|
||||
@Slf4j
|
||||
public class ProductionPlanJob implements JobHandler {
|
||||
|
||||
private final ProductionPlanService productionPlanService;
|
||||
private final ProductionPlanManager productionPlanManager;
|
||||
|
||||
public ProductionPlanJob(ProductionPlanService productionPlanService) {
|
||||
this.productionPlanService = productionPlanService;
|
||||
public ProductionPlanJob(ProductionPlanManager productionPlanManager) {
|
||||
this.productionPlanManager = productionPlanManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,42 +31,9 @@ public class ProductionPlanJob implements JobHandler {
|
||||
*/
|
||||
@Override
|
||||
public String execute(String param) throws Exception {
|
||||
this.updatePlanStatus();
|
||||
productionPlanManager.autoUpdateProductionPlanStatus();
|
||||
return "success";
|
||||
}
|
||||
|
||||
private void updatePlanStatus() {
|
||||
// 当前日期
|
||||
LocalDate today = LocalDate.now(ZoneId.of("Asia/Shanghai"));
|
||||
List<ProductionPlanDO> plans = productionPlanService.getProductionPlans(null);
|
||||
|
||||
List<ProductionPlanSaveReqVO> uList = new ArrayList<>();
|
||||
for (ProductionPlanDO plan : plans) {
|
||||
String id = plan.getId();
|
||||
LocalDate productionStartDate = plan.getProductionStartDate();
|
||||
LocalDate productionEndDate = plan.getProductionEndDate();
|
||||
Integer planStatus = plan.getPlanStatus();
|
||||
|
||||
ProductionPlanSaveReqVO uDo = new ProductionPlanSaveReqVO();
|
||||
uDo.setId(id);
|
||||
|
||||
// 未完成 -> 逾期未开始
|
||||
if (!ObjectUtils.notEqual(planStatus,PLAN_STATUS_1)) {
|
||||
if (today.isAfter(productionStartDate)) {
|
||||
uDo.setPlanStatus(PLAN_STATUS_4);
|
||||
uDo.setPlanSubStatus(PLAN_STATUS_5);
|
||||
}
|
||||
}
|
||||
// 进行中 -> 逾期未结束
|
||||
if (!ObjectUtils.notEqual(planStatus,PLAN_STATUS_2)) {
|
||||
if (today.isAfter(productionEndDate)) {
|
||||
uDo.setPlanStatus(PLAN_STATUS_4);
|
||||
uDo.setPlanSubStatus(PLAN_STATUS_6);
|
||||
}
|
||||
}
|
||||
uList.add(uDo);
|
||||
}
|
||||
productionPlanService.updateBatchProductionPlan(uList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.farm.manager.perductionplan;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.FarmingRecordSaveReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.cropfarmingcenter.vo.productionplan.ProductionPlanSaveReqVO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.farmingrecord.FarmingRecordDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.modelfarmingoperation.ModelFarmingOperationDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.productionplan.ProductionPlanDO;
|
||||
@@ -13,12 +14,12 @@ import cn.iocoder.yudao.module.farm.service.productionplan.ProductionPlanService
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static cn.iocoder.yudao.module.farm.enums.CommonConstants.FARMING_RECORD_STATUS_1;
|
||||
import static cn.iocoder.yudao.module.farm.enums.CommonConstants.FARMING_RECORD_STATUS_2;
|
||||
import static cn.iocoder.yudao.module.farm.enums.CommonConstants.*;
|
||||
|
||||
/**
|
||||
* @description: 生产计划, 农事计划
|
||||
@@ -66,19 +67,92 @@ public class ProductionPlanManager {
|
||||
* 开始 -> 结束
|
||||
*/
|
||||
public void autoUpdateFarmRecordStatus() {
|
||||
|
||||
Map<Integer, List<FarmingRecordDO>> statusGroups = farmingRecordService.getFarmingRecordListByState();
|
||||
|
||||
this.isStartToday(statusGroups);
|
||||
this.isEndToday(statusGroups);
|
||||
processStartedRecords(statusGroups);
|
||||
processEndedRecords(statusGroups);
|
||||
}
|
||||
|
||||
public void autoUpdateProductionPlanStatus() {
|
||||
// 当前日期
|
||||
LocalDate today = LocalDate.now(ZoneId.of("Asia/Shanghai"));
|
||||
|
||||
// 获取生产计划并按状态分组
|
||||
Map<Integer, List<ProductionPlanDO>> statusGroups = productionPlanService.getProductionPlans(null)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(ProductionPlanDO::getPlanStatus));
|
||||
|
||||
// 处理逾期未开始和逾期未结束的计划
|
||||
List<ProductionPlanSaveReqVO> overdueStartPlans = processOverdueStartPlans(today, statusGroups);
|
||||
List<ProductionPlanSaveReqVO> overdueEndPlans = processOverdueEndPlans(today, statusGroups);
|
||||
|
||||
// 合并更新列表
|
||||
List<ProductionPlanSaveReqVO> allUpdates = Stream.concat(
|
||||
overdueStartPlans.stream(),
|
||||
overdueEndPlans.stream()
|
||||
).collect(Collectors.toList());
|
||||
|
||||
// 批量更新
|
||||
if (!allUpdates.isEmpty()) {
|
||||
productionPlanService.updateBatchProductionPlan(allUpdates);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ================私有方法===================
|
||||
// ================私有方法===================
|
||||
|
||||
/**
|
||||
* 处理逾期未开始的生产计划
|
||||
*/
|
||||
private List<ProductionPlanSaveReqVO> processOverdueStartPlans(LocalDate today,
|
||||
Map<Integer, List<ProductionPlanDO>> statusGroups) {
|
||||
return Optional.ofNullable(statusGroups.get(PLAN_STATUS_1))
|
||||
.orElse(Collections.emptyList())
|
||||
.stream()
|
||||
.filter(plan -> today.isAfter(plan.getProductionStartDate()))
|
||||
.map(plan -> {
|
||||
// 推送消息
|
||||
pushStartMessage(plan);
|
||||
// 构建更新对象
|
||||
return buildStatusUpdate(plan.getId(), PLAN_STATUS_4, PLAN_STATUS_5);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理逾期未结束的生产计划
|
||||
*/
|
||||
private List<ProductionPlanSaveReqVO> processOverdueEndPlans(LocalDate today,
|
||||
Map<Integer, List<ProductionPlanDO>> statusGroups) {
|
||||
return Optional.ofNullable(statusGroups.get(PLAN_STATUS_2))
|
||||
.orElse(Collections.emptyList())
|
||||
.stream()
|
||||
.filter(plan -> today.isAfter(plan.getProductionEndDate()))
|
||||
.map(plan -> {
|
||||
// 推送消息
|
||||
pushEndMessage(plan);
|
||||
// 构建更新对象
|
||||
return buildStatusUpdate(plan.getId(), PLAN_STATUS_4, PLAN_STATUS_6);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建状态更新对象
|
||||
*/
|
||||
private ProductionPlanSaveReqVO buildStatusUpdate(String id, Integer planStatus, Integer planSubStatus) {
|
||||
ProductionPlanSaveReqVO update = new ProductionPlanSaveReqVO();
|
||||
update.setId(id);
|
||||
update.setPlanStatus(planStatus);
|
||||
update.setPlanSubStatus(planSubStatus);
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将开始日期在今天之前的的记录 状态修改为: 开始
|
||||
*
|
||||
* @param statusGroups
|
||||
*/
|
||||
@Deprecated
|
||||
private void isStartToday(Map<Integer, List<FarmingRecordDO>> statusGroups) {
|
||||
List<FarmingRecordDO> notStartedList = statusGroups.get(CommonConstants.FARMING_RECORD_STATUS_0); // 未开始组
|
||||
LocalDate today = LocalDate.now();
|
||||
@@ -94,16 +168,17 @@ public class ProductionPlanManager {
|
||||
e.setTaskStatus(FARMING_RECORD_STATUS_1);
|
||||
farmingRecordService.updateFarmingRecord(BeanUtils.toBean(e, FarmingRecordSaveReqVO.class));
|
||||
|
||||
// TODO: 2025/11/11 推送系统消息
|
||||
|
||||
// 推送系统消息
|
||||
String title = "农事计划";
|
||||
String content = "农事计划 (" + e.getTaskScope() + ") [已开始]信息提醒.";
|
||||
messageCenterService.pushMessage(title, content, MESSAGE_TYPE_3);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将结束日期在今天之前的记录 状态修改为: 结束
|
||||
*
|
||||
* @param statusGroups
|
||||
*/
|
||||
@Deprecated
|
||||
private void isEndToday(Map<Integer, List<FarmingRecordDO>> statusGroups) {
|
||||
List<FarmingRecordDO> startedList = statusGroups.get(CommonConstants.FARMING_RECORD_STATUS_1); // 开始组
|
||||
LocalDate today = LocalDate.now();
|
||||
@@ -119,9 +194,111 @@ public class ProductionPlanManager {
|
||||
e.setTaskStatus(FARMING_RECORD_STATUS_2);
|
||||
farmingRecordService.updateFarmingRecord(BeanUtils.toBean(e, FarmingRecordSaveReqVO.class));
|
||||
|
||||
// TODO: 2025/11/11 推送系统消息
|
||||
|
||||
// 推送系统消息
|
||||
String title = "农事计划";
|
||||
String content = "农事计划 (" + e.getTaskScope() + ") [已结束]信息提醒.";
|
||||
messageCenterService.pushMessage(title, content, MESSAGE_TYPE_3);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理需要开始的任务:将开始日期在今天及之前的记录状态修改为"开始"
|
||||
*/
|
||||
private void processStartedRecords(Map<Integer, List<FarmingRecordDO>> statusGroups) {
|
||||
List<FarmingRecordDO> notStartedList = statusGroups.getOrDefault(
|
||||
CommonConstants.FARMING_RECORD_STATUS_0, Collections.emptyList());
|
||||
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
notStartedList.stream()
|
||||
.filter(record -> isDateBeforeOrEqual(record.getTaskStartDate(), today))
|
||||
.forEach(record -> updateRecordToStarted(record));
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理需要结束的任务:将结束日期在今天及之前的记录状态修改为"结束"
|
||||
*/
|
||||
private void processEndedRecords(Map<Integer, List<FarmingRecordDO>> statusGroups) {
|
||||
List<FarmingRecordDO> startedList = statusGroups.getOrDefault(
|
||||
CommonConstants.FARMING_RECORD_STATUS_1, Collections.emptyList());
|
||||
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
startedList.stream()
|
||||
.filter(record -> isDateBeforeOrEqual(record.getTaskEndDate(), today))
|
||||
.forEach(record -> updateRecordToEnded(record));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录为已开始状态
|
||||
*/
|
||||
private void updateRecordToStarted(FarmingRecordDO record) {
|
||||
// 更新状态
|
||||
record.setTaskStatus(FARMING_RECORD_STATUS_1);
|
||||
farmingRecordService.updateFarmingRecord(BeanUtils.toBean(record, FarmingRecordSaveReqVO.class));
|
||||
|
||||
// 推送系统消息
|
||||
pushStartMessage(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录为已结束状态
|
||||
*/
|
||||
private void updateRecordToEnded(FarmingRecordDO record) {
|
||||
// 更新状态
|
||||
record.setTaskStatus(FARMING_RECORD_STATUS_2);
|
||||
farmingRecordService.updateFarmingRecord(BeanUtils.toBean(record, FarmingRecordSaveReqVO.class));
|
||||
|
||||
// 推送系统消息
|
||||
pushEndMessage(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断日期是否在今天或之前
|
||||
*/
|
||||
private boolean isDateBeforeOrEqual(LocalDate date, LocalDate today) {
|
||||
return date.isBefore(today) || date.equals(today);
|
||||
}
|
||||
|
||||
|
||||
// ================消息推送===================
|
||||
// ================消息推送===================
|
||||
|
||||
/**
|
||||
* 推送开始消息 农事计划
|
||||
*/
|
||||
private void pushStartMessage(FarmingRecordDO record) {
|
||||
String title = "农事计划";
|
||||
String content = String.format("农事计划 (%s) [已开始]信息提醒.", record.getTaskScope());
|
||||
messageCenterService.pushMessage(title, content, MESSAGE_TYPE_3);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送结束消息 农事计划
|
||||
*/
|
||||
private void pushEndMessage(FarmingRecordDO record) {
|
||||
String title = "农事计划";
|
||||
String content = String.format("农事计划 (%s) [已结束]信息提醒.", record.getTaskScope());
|
||||
messageCenterService.pushMessage(title, content, MESSAGE_TYPE_3);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 推送开始消息 生产计划
|
||||
*/
|
||||
private void pushStartMessage(ProductionPlanDO plan) {
|
||||
String title = "生产计划";
|
||||
String content = String.format("生产计划 (%s) [逾期-未开始]信息提醒.", plan.getPlanNumber());
|
||||
messageCenterService.pushMessage(title, content, MESSAGE_TYPE_3);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送结束消息 生产计划
|
||||
*/
|
||||
private void pushEndMessage(ProductionPlanDO plan) {
|
||||
String title = "生产计划";
|
||||
String content = String.format("生产计划 (%s) [逾期-未结束]信息提醒.", plan.getPlanNumber());
|
||||
messageCenterService.pushMessage(title, content, MESSAGE_TYPE_3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -70,4 +70,11 @@ public interface MessageCenterService {
|
||||
*/
|
||||
MessageStatisticsRespVO getMessageStatistics(String startTime, String endTime);
|
||||
|
||||
/**
|
||||
* 消息推送
|
||||
* @param title
|
||||
* @param content
|
||||
* @param messageType
|
||||
*/
|
||||
void pushMessage(String title, String content, Integer messageType);
|
||||
}
|
||||
@@ -8,15 +8,19 @@ import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecen
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageCenterSaveReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.messagecenter.MessageCenterDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.personnelmanagement.SystemUserDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.mysql.messagecenter.MessageCenterMapper;
|
||||
import cn.iocoder.yudao.module.farm.dal.mysql.personnelmanagement.SystemUserMapper;
|
||||
import cn.iocoder.yudao.module.farm.enums.MessageTypeEnum;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
|
||||
@@ -31,6 +35,8 @@ import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.MESSAGE_CENT
|
||||
@Validated
|
||||
public class MessageCenterServiceImpl implements MessageCenterService {
|
||||
|
||||
@Resource
|
||||
private SystemUserMapper userMapper;
|
||||
@Resource
|
||||
private MessageCenterMapper messageCenterMapper;
|
||||
|
||||
@@ -40,6 +46,7 @@ public class MessageCenterServiceImpl implements MessageCenterService {
|
||||
// 插入
|
||||
MessageCenterDO messageCenter = BeanUtils.toBean(createReqVO, MessageCenterDO.class);
|
||||
messageCenter.setId(IdUtil.fastUUID());
|
||||
messageCenter.setReadUserId(user.getId());
|
||||
messageCenter.setTenantId(String.valueOf(user.getTenantId()));
|
||||
messageCenterMapper.insert(messageCenter);
|
||||
|
||||
@@ -53,6 +60,7 @@ public class MessageCenterServiceImpl implements MessageCenterService {
|
||||
validateMessageCenterExists(updateReqVO.getId());
|
||||
// 更新
|
||||
MessageCenterDO updateObj = BeanUtils.toBean(updateReqVO, MessageCenterDO.class);
|
||||
updateObj.setReadTime(LocalDateTime.now());
|
||||
messageCenterMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@@ -83,7 +91,16 @@ public class MessageCenterServiceImpl implements MessageCenterService {
|
||||
|
||||
@Override
|
||||
public PageResult<MessageCenterDO> getMessageCenterPage(MessageCenterPageReqVO pageReqVO) {
|
||||
return messageCenterMapper.selectPage(pageReqVO);
|
||||
|
||||
List<SystemUserDO> userList = userMapper.selectList(SystemUserDO::getTenantId, getLoginUser().getTenantId());
|
||||
Map<Long, String> userMap = userList.stream().collect(Collectors.toMap(SystemUserDO::getId, SystemUserDO::getNickname, (v1, v2) -> v1));
|
||||
|
||||
PageResult<MessageCenterDO> page = messageCenterMapper.selectPage(pageReqVO);
|
||||
Long total = page.getTotal();
|
||||
List<MessageCenterDO> list = page.getList();
|
||||
list.forEach(e -> e.setReadUserName(userMap.getOrDefault(e.getReadUserId(),"系统")));
|
||||
|
||||
return new PageResult<>(list,total);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,4 +133,17 @@ public class MessageCenterServiceImpl implements MessageCenterService {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushMessage(String title, String content, Integer messageType) {
|
||||
|
||||
MessageCenterSaveReqVO m = new MessageCenterSaveReqVO();
|
||||
m.setTitle(title);
|
||||
m.setContent(content);
|
||||
m.setMessageType(messageType);
|
||||
|
||||
m.setAlarmStatus(2);
|
||||
m.setPushCount(1);
|
||||
|
||||
this.createMessageCenter(m);
|
||||
}
|
||||
}
|
||||
@@ -276,7 +276,7 @@ public class FarmMessagePushServiceImpl implements FarmMessagePushService {
|
||||
wsMessage.setAlarmStatus(message.getAlarmStatus());
|
||||
wsMessage.setMessageTime(message.getCreateTime());
|
||||
wsMessage.setIsRead(message.getReadStatus() == 1);
|
||||
wsMessage.setPushCount(message.getNumber());
|
||||
wsMessage.setPushCount(message.getPushCount());
|
||||
|
||||
return wsMessage;
|
||||
}
|
||||
@@ -292,7 +292,7 @@ public class FarmMessagePushServiceImpl implements FarmMessagePushService {
|
||||
.content(content)
|
||||
.readStatus(0) // 未读
|
||||
.alarmStatus(AlarmStatusEnum.UNRESOLVED.getStatus()) // 未解除
|
||||
.number(0) // 推送次数
|
||||
.pushCount(0) // 推送次数
|
||||
.baseId(baseId)
|
||||
.plotId(plotId)
|
||||
.build();
|
||||
|
||||
@@ -125,6 +125,7 @@ public class ProductionPlanServiceImpl implements ProductionPlanService {
|
||||
@Override
|
||||
public List<ProductionPlanDO> getProductionPlans(String plotId) {
|
||||
LambdaQueryWrapperX<ProductionPlanDO> qw = new LambdaQueryWrapperX<>();
|
||||
qw.eqIfPresent(ProductionPlanDO::getDeleted, NO_CODE);
|
||||
qw.eqIfPresent(ProductionPlanDO::getPlotId, plotId);
|
||||
return productionPlanMapper.selectList(qw);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user