diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/job/WaresStockBelowJob.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/job/WaresStockBelowJob.java new file mode 100644 index 00000000..bb4a8aa6 --- /dev/null +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/job/WaresStockBelowJob.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.job; + +import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; +import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; +import cn.iocoder.yudao.module.project.service.RepairWaresService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 配件库存低于几个(可以自己设置)需要做库存预警 + * + * @author 小李 + * @date 14:40 2024/11/30 + **/ +@Component +@TenantJob +@Slf4j +public class WaresStockBelowJob implements JobHandler { + + @Resource + private RepairWaresService waresService; + + @Override + public String execute(String param) throws Exception { + waresService.stockBelow(); + return null; + } +} diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/project/service/RepairWaresService.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/project/service/RepairWaresService.java index 053aabce..ea7c7f06 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/project/service/RepairWaresService.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/project/service/RepairWaresService.java @@ -94,4 +94,12 @@ public interface RepairWaresService extends IService<RepairWares> { * @date 14:42 2024/11/30 **/ void timeOver(); + + /** + * 配件库存低于几个(可以自己设置)需要做库存预警 + * + * @author 小李 + * @date 15:54 2024/11/30 + **/ + void stockBelow(); } \ No newline at end of file diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/project/service/impl/RepairWaresServiceImpl.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/project/service/impl/RepairWaresServiceImpl.java index 065cecdf..25596aa3 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/project/service/impl/RepairWaresServiceImpl.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/project/service/impl/RepairWaresServiceImpl.java @@ -248,19 +248,11 @@ public class RepairWaresServiceImpl extends ServiceImpl<RepairWaresMapper, Repai public void timeOver() { // 取配置 List<DictDataRespDTO> dataList = dictDataApi.getDictDataList(RepairDictConstants.REPAIR_WARES_NOTICE); - // 取仓管、维修管理员 - List<UserDTO> warehouse = roleApi.selectUserListByRoleCode(TenantContextHolder.getRequiredTenantId(), RepairRoleEnum.WAREHOUSE.getCode()); - List<UserDTO> admin = roleApi.selectUserListByRoleCode(TenantContextHolder.getRequiredTenantId(), RepairRoleEnum.ADMIN.getCode()); // 取出第一个 if (CollUtil.isEmpty(dataList)) { - // 如果为空就通知相关人员出现了问题 - if (CollUtil.isNotEmpty(warehouse)) { - warehouse.forEach(item -> workerService.sentMessage(item.getId(), "检查配件入库是否超时出现故障,请联系开发人员解决")); - } - if (CollUtil.isNotEmpty(admin)) { - admin.forEach(item -> workerService.sentMessage(item.getId(), "检查配件入库是否超时出现故障,请联系开发人员解决")); - } + noticeByFlag(true); + return; } DictDataRespDTO dictDataRespDTO = dataList.get(0); String day = dictDataRespDTO.getValue(); @@ -269,12 +261,12 @@ public class RepairWaresServiceImpl extends ServiceImpl<RepairWaresMapper, Repai List<RepairWares> repairWares = baseMapper.selectList(new LambdaQueryWrapper<RepairWares>().le(RepairWares::getUpdateTime, dateAgo)); if (CollUtil.isNotEmpty(repairWares)) { - // 构建对象 + // 构建对象 todo 表需要做适配 List<WarnMessageByRepair> warnMessages = repairWares.stream().map(item -> WarnMessageByRepair .builder() .title("配件超时未使用") - .content("名为:" + item.getName() + "的配件超过设定的未使用天数提醒,请及时处理相关事项!") + .content("名为:" + item.getName() + "的配件未使用天数超过设定的未使用天数提醒,请及时处理相关事项!") .warnTime(new Date()) .isRead("0") .build() @@ -283,4 +275,60 @@ public class RepairWaresServiceImpl extends ServiceImpl<RepairWaresMapper, Repai } } + /** + * 配件库存低于几个(可以自己设置)需要做库存预警 + * + * @author 小李 + * @date 15:54 2024/11/30 + **/ + @Override + public void stockBelow(){ + // 取配置 + List<DictDataRespDTO> dataList = dictDataApi.getDictDataList(RepairDictConstants.REPAIR_WARES_NOTICE); + + // 取出第二个 + if (CollUtil.isEmpty(dataList)) { + noticeByFlag(false); + return; + } + DictDataRespDTO dictDataRespDTO = dataList.get(1); + String count = dictDataRespDTO.getValue(); + List<RepairWares> repairWares = baseMapper.selectList(new LambdaQueryWrapper<RepairWares>().le(RepairWares::getStock, count)); + + if (CollUtil.isNotEmpty(repairWares)) { + // 构建对象 todo 表需要做适配 + List<WarnMessageByRepair> warnMessages = repairWares.stream().map(item -> + WarnMessageByRepair + .builder() + .title("配件库存不足") + .content("名为:" + item.getName() + "的配件库存低于设定的库存不足提醒,请及时处理相关事项!") + .warnTime(new Date()) + .isRead("0") + .build() + ).collect(Collectors.toList()); + warnMessageByRepairService.saveBatch(warnMessages); + } + } + + /** + * 上面两个方法公共的通知方法 + * + * @author 小李 + * @date 15:57 2024/11/30 + * @param flag 什么通知 + **/ + private void noticeByFlag(Boolean flag){ + // 取仓管、维修管理员 + List<UserDTO> warehouse = roleApi.selectUserListByRoleCode(TenantContextHolder.getRequiredTenantId(), RepairRoleEnum.WAREHOUSE.getCode()); + List<UserDTO> admin = roleApi.selectUserListByRoleCode(TenantContextHolder.getRequiredTenantId(), RepairRoleEnum.ADMIN.getCode()); + + String message = flag ? "检查配件入库是否超时出现故障,请联系开发人员解决" : "检查配件库存是否充足出现故障,请联系开发人员解决"; + // 如果为空就通知相关人员出现了问题 + if (CollUtil.isNotEmpty(warehouse)) { + warehouse.forEach(item -> workerService.sentMessage(item.getId(), message)); + } + if (CollUtil.isNotEmpty(admin)) { + admin.forEach(item -> workerService.sentMessage(item.getId(), message)); + } + } } \ No newline at end of file