|
|
|
@ -1,14 +1,17 @@
|
|
|
|
|
package com.glxp.api.service.inv.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.glxp.api.common.enums.ResultEnum;
|
|
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
|
|
import com.glxp.api.common.util.ResultVOUtils;
|
|
|
|
|
import com.glxp.api.dao.basic.UdiRelevanceDao;
|
|
|
|
|
import com.glxp.api.dao.inv.InvProductDao;
|
|
|
|
|
import com.glxp.api.dao.inv.InvRemindMsgDao;
|
|
|
|
|
import com.glxp.api.entity.basic.UdiRelevanceEntity;
|
|
|
|
|
import com.glxp.api.entity.inv.InvProductEntity;
|
|
|
|
|
import com.glxp.api.entity.inv.InvRemindMsgEntity;
|
|
|
|
|
import com.glxp.api.entity.inv.InvRemindSetEntity;
|
|
|
|
@ -35,6 +38,8 @@ public class InvRemindMsgServiceImpl implements InvRemindMsgService {
|
|
|
|
|
private InvRemindMsgDao invRemindMsgDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private InvProductDao invProductDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private UdiRelevanceDao udiRelevanceDao;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<InvRemindMsgResponse> filterList(FilterInvRemindMsgRequest filterInvRemindMsgRequest) {
|
|
|
|
@ -70,77 +75,94 @@ public class InvRemindMsgServiceImpl implements InvRemindMsgService {
|
|
|
|
|
List<InvProductEntity> invDataList = new CopyOnWriteArrayList<>(invProductList);
|
|
|
|
|
|
|
|
|
|
invDataList.parallelStream().forEach(invProductEntity -> {
|
|
|
|
|
//初始化查询预警消息参数
|
|
|
|
|
FilterInvRemindMsgRequest invRemindMsgRequest = new FilterInvRemindMsgRequest();
|
|
|
|
|
invRemindMsgRequest.setRelId(invProductEntity.getRelIdFk().toString());
|
|
|
|
|
invRemindMsgRequest.setBatchNo(invProductEntity.getBatchNo());
|
|
|
|
|
invRemindMsgRequest.setDeptCode(invProductEntity.getDeptCode());
|
|
|
|
|
invRemindMsgRequest.setInvCode(invProductEntity.getInvCode());
|
|
|
|
|
invRemindMsgRequest.setInvSpaceCode(invProductEntity.getInvSpaceCode());
|
|
|
|
|
|
|
|
|
|
//根据预警设置,添加类型参数
|
|
|
|
|
if (invRemindSetEntity.getLowStock()) {
|
|
|
|
|
//开启低库存预警
|
|
|
|
|
invRemindMsgRequest.setType("1"); //库存不足预警
|
|
|
|
|
InvRemindMsgEntity msgEntity = getInvRemindMsgEntity(invRemindMsgRequest, invProductEntity);
|
|
|
|
|
//判断是否需要生成/刷新库存预警
|
|
|
|
|
if (msgEntity.getNextRemindTime().getTime() >= new Date().getTime() && invProductEntity.getReCount() < invRemindSetEntity.getLowStockNum()) {
|
|
|
|
|
//设置预警消息
|
|
|
|
|
msgEntity.setMsg(StrUtil.format("库存数量已不足:{},当前库存数量:{} ", invRemindSetEntity.getLowStockNum(), invProductEntity.getReCount()));
|
|
|
|
|
saveMsg(msgEntity);
|
|
|
|
|
//查询产品在耗材字典中设置的预警参数
|
|
|
|
|
UdiRelevanceEntity udiRelevanceEntity = udiRelevanceDao.selectRemindParams(invProductEntity.getRelIdFk());
|
|
|
|
|
if (null == udiRelevanceEntity) {
|
|
|
|
|
log.info("此库存产品在耗材字典中不存在,无法生成库存数量及近效期相关预警信息");
|
|
|
|
|
} else {
|
|
|
|
|
//初始化查询预警消息参数
|
|
|
|
|
FilterInvRemindMsgRequest invRemindMsgRequest = new FilterInvRemindMsgRequest();
|
|
|
|
|
invRemindMsgRequest.setRelId(invProductEntity.getRelIdFk().toString());
|
|
|
|
|
invRemindMsgRequest.setBatchNo(invProductEntity.getBatchNo());
|
|
|
|
|
invRemindMsgRequest.setDeptCode(invProductEntity.getDeptCode());
|
|
|
|
|
invRemindMsgRequest.setInvCode(invProductEntity.getInvCode());
|
|
|
|
|
invRemindMsgRequest.setInvSpaceCode(invProductEntity.getInvSpaceCode());
|
|
|
|
|
|
|
|
|
|
//根据预警设置,添加类型参数
|
|
|
|
|
if (invRemindSetEntity.getLowStock() && null != udiRelevanceEntity.getLowStockNum()) {
|
|
|
|
|
//开启低库存预警
|
|
|
|
|
invRemindMsgRequest.setType("1"); //库存不足预警
|
|
|
|
|
InvRemindMsgEntity msgEntity = getInvRemindMsgEntity(invRemindMsgRequest, invProductEntity);
|
|
|
|
|
//判断是否需要生成/刷新库存预警
|
|
|
|
|
if ((null == msgEntity.getNextRemindTime() || msgEntity.getNextRemindTime().getTime() <= new Date().getTime()) && udiRelevanceEntity.getLowStockNum() > invProductEntity.getReCount()) {
|
|
|
|
|
//设置预警消息
|
|
|
|
|
msgEntity.setMsg(StrUtil.format("库存数量已不足:{},当前库存数量:{} ", udiRelevanceEntity.getLowStockNum(), invProductEntity.getReCount()));
|
|
|
|
|
saveMsg(msgEntity);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
String logInfo = invRemindSetEntity.getLowStock() ? "产品 " + invProductEntity.getRelIdFk() + " 未设置低库存预警数量" : "产品 " + invProductEntity.getRelIdFk() + " 未开启低库存预警";
|
|
|
|
|
log.info(logInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (invRemindSetEntity.getLackStock()) {
|
|
|
|
|
//开启负库存预警
|
|
|
|
|
invRemindMsgRequest.setType("2");//库存负数预警
|
|
|
|
|
InvRemindMsgEntity msgEntity = getInvRemindMsgEntity(invRemindMsgRequest, invProductEntity);
|
|
|
|
|
//判断是否需要生成/刷新库存预警
|
|
|
|
|
if (msgEntity.getNextRemindTime().getTime() >= new Date().getTime() && invProductEntity.getReCount() < 0) {
|
|
|
|
|
//设置预警消息
|
|
|
|
|
msgEntity.setMsg(StrUtil.format("库存数量为负,当前库存数量:{}", invProductEntity.getReCount()));
|
|
|
|
|
saveMsg(msgEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (invRemindSetEntity.getOverStock()) {
|
|
|
|
|
//开启库存积压预警
|
|
|
|
|
invRemindMsgRequest.setType("3"); //库存积压预警
|
|
|
|
|
InvRemindMsgEntity msgEntity = getInvRemindMsgEntity(invRemindMsgRequest, invProductEntity);
|
|
|
|
|
//判断是否需要生成/刷新库存预警
|
|
|
|
|
if (msgEntity.getNextRemindTime().getTime() > new Date().getTime() && invProductEntity.getReCount() > invRemindSetEntity.getOverStockNum()) {
|
|
|
|
|
//设置预警消息
|
|
|
|
|
msgEntity.setMsg(StrUtil.format("库存积压,当前库存数量:{}", invProductEntity.getReCount()));
|
|
|
|
|
saveMsg(msgEntity);
|
|
|
|
|
if (invRemindSetEntity.getLackStock()) {
|
|
|
|
|
//开启负库存预警
|
|
|
|
|
invRemindMsgRequest.setType("2");//库存负数预警
|
|
|
|
|
InvRemindMsgEntity msgEntity = getInvRemindMsgEntity(invRemindMsgRequest, invProductEntity);
|
|
|
|
|
//判断是否需要生成/刷新库存预警
|
|
|
|
|
if ((null == msgEntity.getNextRemindTime() || msgEntity.getNextRemindTime().getTime() <= new Date().getTime()) && invProductEntity.getReCount() < 0) {
|
|
|
|
|
//设置预警消息
|
|
|
|
|
msgEntity.setMsg(StrUtil.format("库存数量为负,当前库存数量:{}", invProductEntity.getReCount()));
|
|
|
|
|
saveMsg(msgEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (invRemindSetEntity.getExpireDate()) {
|
|
|
|
|
//开启产品过期预警
|
|
|
|
|
invRemindMsgRequest.setType("4"); //库存过期预警
|
|
|
|
|
InvRemindMsgEntity msgEntity = getInvRemindMsgEntity(invRemindMsgRequest, invProductEntity);
|
|
|
|
|
//判断是否需要生成/刷新库存预警
|
|
|
|
|
if (msgEntity.getNextRemindTime().getTime() > new Date().getTime() && StrUtil.isNotBlank(invProductEntity.getExpireDate()) && DateUtil.compareExpire(invProductEntity.getExpireDate(), null)) {
|
|
|
|
|
//设置预警消息
|
|
|
|
|
msgEntity.setMsg(StrUtil.format("产品已过期,产品失效日期:{}", invProductEntity.getExpireDate()));
|
|
|
|
|
saveMsg(msgEntity);
|
|
|
|
|
if (invRemindSetEntity.getOverStock() && null != udiRelevanceEntity.getOverStockNum()) {
|
|
|
|
|
//开启库存积压预警
|
|
|
|
|
invRemindMsgRequest.setType("3"); //库存积压预警
|
|
|
|
|
InvRemindMsgEntity msgEntity = getInvRemindMsgEntity(invRemindMsgRequest, invProductEntity);
|
|
|
|
|
//判断是否需要生成/刷新库存预警
|
|
|
|
|
if ((null == msgEntity.getNextRemindTime() || msgEntity.getNextRemindTime().getTime() <= new Date().getTime()) && invProductEntity.getReCount() > udiRelevanceEntity.getOverStockNum()) {
|
|
|
|
|
//设置预警消息
|
|
|
|
|
msgEntity.setMsg(StrUtil.format("库存积压,当前库存数量:{}", invProductEntity.getReCount()));
|
|
|
|
|
saveMsg(msgEntity);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
String logInfo = invRemindSetEntity.getOverStock() ? "产品 " + invProductEntity.getRelIdFk() + " 未设置库存积压预警数量" : "产品 " + invProductEntity.getRelIdFk() + " 未开启库存积压预警";
|
|
|
|
|
log.info(logInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (invRemindSetEntity.getRecentDate()) {
|
|
|
|
|
//开启库存近效期预警
|
|
|
|
|
invRemindMsgRequest.setType("5"); //库存近效期预警
|
|
|
|
|
InvRemindMsgEntity msgEntity = getInvRemindMsgEntity(invRemindMsgRequest, invProductEntity);
|
|
|
|
|
//判断是否需要生成/刷新库存预警
|
|
|
|
|
if (msgEntity.getNextRemindTime().getTime() > new Date().getTime() && StrUtil.isNotBlank(invProductEntity.getExpireDate())) {
|
|
|
|
|
//计算产品记录失效的天数
|
|
|
|
|
long recentDay = Long.parseLong(DateUtil.getDate("yyMMdd")) - Long.parseLong(invProductEntity.getExpireDate());
|
|
|
|
|
if (invRemindSetEntity.getRecentDateDay() > recentDay) {
|
|
|
|
|
if (invRemindSetEntity.getExpireDate()) {
|
|
|
|
|
//开启产品过期预警
|
|
|
|
|
invRemindMsgRequest.setType("4"); //库存过期预警
|
|
|
|
|
InvRemindMsgEntity msgEntity = getInvRemindMsgEntity(invRemindMsgRequest, invProductEntity);
|
|
|
|
|
//判断是否需要生成/刷新库存预警
|
|
|
|
|
if ((null == msgEntity.getNextRemindTime() || msgEntity.getNextRemindTime().getTime() <= new Date().getTime()) && StrUtil.isNotBlank(invProductEntity.getExpireDate()) && DateUtil.compareExpire(invProductEntity.getExpireDate(), null)) {
|
|
|
|
|
//设置预警消息
|
|
|
|
|
msgEntity.setMsg(StrUtil.format("库存即将过期,产品失效日期:{}", invProductEntity.getExpireDate()));
|
|
|
|
|
msgEntity.setMsg(StrUtil.format("产品已过期,产品失效日期:{}", invProductEntity.getExpireDate()));
|
|
|
|
|
saveMsg(msgEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (invRemindSetEntity.getRecentDate() && null != udiRelevanceEntity.getRecentDateTime()) {
|
|
|
|
|
//开启库存近效期预警
|
|
|
|
|
invRemindMsgRequest.setType("5"); //库存近效期预警
|
|
|
|
|
InvRemindMsgEntity msgEntity = getInvRemindMsgEntity(invRemindMsgRequest, invProductEntity);
|
|
|
|
|
//判断是否需要生成/刷新库存预警
|
|
|
|
|
if ((null == msgEntity.getNextRemindTime() || msgEntity.getNextRemindTime().getTime() <= new Date().getTime()) && StrUtil.isNotBlank(invProductEntity.getExpireDate())) {
|
|
|
|
|
//当前时间 - 近效期预警时间 > 产品失效日期,则进行预警
|
|
|
|
|
DateTime dateTime = cn.hutool.core.date.DateUtil.offsetHour(new Date(), udiRelevanceEntity.getRecentDateTime());
|
|
|
|
|
|
|
|
|
|
if (Long.parseLong(dateTime.toString("yyMMdd")) > Long.parseLong(invProductEntity.getExpireDate())) {
|
|
|
|
|
//设置预警消息
|
|
|
|
|
msgEntity.setMsg(StrUtil.format("库存即将过期,产品失效日期:{}", invProductEntity.getExpireDate()));
|
|
|
|
|
saveMsg(msgEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
String logInfo = invRemindSetEntity.getRecentDate() ? "产品 " + invProductEntity.getRelIdFk() + " 未设置近效期预警时间" : "产品 " + invProductEntity.getRelIdFk() + " 未开启近效期预警";
|
|
|
|
|
log.info(logInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
@ -206,6 +228,7 @@ public class InvRemindMsgServiceImpl implements InvRemindMsgService {
|
|
|
|
|
msgEntity = new InvRemindMsgEntity();
|
|
|
|
|
msgEntity.setRelId(invProductEntity.getRelIdFk().toString()); //耗材字典产品ID
|
|
|
|
|
msgEntity.setBatchNo(invProductEntity.getBatchNo()); //批次号
|
|
|
|
|
msgEntity.setSupId(invProductEntity.getSupId()); //供应商ID
|
|
|
|
|
msgEntity.setDeptCode(invProductEntity.getDeptCode()); //部门编码
|
|
|
|
|
msgEntity.setInvCode(invProductEntity.getInvCode()); //仓库编码
|
|
|
|
|
msgEntity.setInvSpaceCode(invProductEntity.getInvSpaceCode()); //货位号
|
|
|
|
|