|
|
|
@ -0,0 +1,234 @@
|
|
|
|
|
package com.glxp.api.service.purchase.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
|
|
import com.glxp.api.common.util.ResultVOUtils;
|
|
|
|
|
import com.glxp.api.constant.ConstantStatus;
|
|
|
|
|
import com.glxp.api.dao.basic.UdiCompanyDao;
|
|
|
|
|
import com.glxp.api.dao.purchase.SupCertDao;
|
|
|
|
|
import com.glxp.api.dao.purchase.SupCertRemindMsgDao;
|
|
|
|
|
import com.glxp.api.entity.purchase.SupCertEntity;
|
|
|
|
|
import com.glxp.api.entity.purchase.SupCertRemindMsgEntity;
|
|
|
|
|
import com.glxp.api.req.purchase.FilterCertRemindMsgRequest;
|
|
|
|
|
import com.glxp.api.res.purchase.SupCertRemindMsgResponse;
|
|
|
|
|
import com.glxp.api.service.auth.CustomerService;
|
|
|
|
|
import com.glxp.api.service.purchase.SupCertRemindMsgService;
|
|
|
|
|
import com.glxp.api.util.DateUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public class SupCertRemindMsgImpl implements SupCertRemindMsgService {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private SupCertRemindMsgDao supCertRemindMsgDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private SupCertDao supCertDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private CustomerService customerService;
|
|
|
|
|
@Resource
|
|
|
|
|
private UdiCompanyDao udiCompanyDao;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SupCertRemindMsgResponse> filterList(FilterCertRemindMsgRequest filterCertRemindMsgRequest) {
|
|
|
|
|
if (null == filterCertRemindMsgRequest || null == filterCertRemindMsgRequest.getType()) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
if (null == filterCertRemindMsgRequest.getPage() && null != filterCertRemindMsgRequest.getLimit()) {
|
|
|
|
|
PageHelper.offsetPage((filterCertRemindMsgRequest.getPage() - 1) * filterCertRemindMsgRequest.getLimit(), filterCertRemindMsgRequest.getLimit());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<SupCertRemindMsgResponse> list = null;
|
|
|
|
|
//判断当前用户是否是供应商,供应商只能查看自己的资质信息
|
|
|
|
|
if (!customerService.isHosUser()) {
|
|
|
|
|
//添加供应商ID参数
|
|
|
|
|
filterCertRemindMsgRequest.setSupId(customerService.getCustomerId());
|
|
|
|
|
}
|
|
|
|
|
//根据类型查询预警信息
|
|
|
|
|
switch (filterCertRemindMsgRequest.getType()) {
|
|
|
|
|
case 1: //查询供应商资质预警信息
|
|
|
|
|
list = supCertRemindMsgDao.selectSupRemindMsgList(filterCertRemindMsgRequest);
|
|
|
|
|
break;
|
|
|
|
|
case 2: //查询生产企业资质预警信息
|
|
|
|
|
list = supCertRemindMsgDao.selectManufactureRemindMsgList(filterCertRemindMsgRequest);
|
|
|
|
|
break;
|
|
|
|
|
case 3: //查询产品资质预警信息
|
|
|
|
|
list = supCertRemindMsgDao.selectProductRemindMsgList(filterCertRemindMsgRequest);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse confirmMsg(Integer id, String handleMsg) {
|
|
|
|
|
SupCertRemindMsgEntity supCertRemindMsgEntity = supCertRemindMsgDao.selectById(id);
|
|
|
|
|
if (null == supCertRemindMsgEntity) {
|
|
|
|
|
return ResultVOUtils.error(500, "预警信息不存在");
|
|
|
|
|
}
|
|
|
|
|
supCertRemindMsgEntity.setHandleMsg(handleMsg);
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
supCertRemindMsgEntity.setUpdateTime(date);
|
|
|
|
|
supCertRemindMsgEntity.setNextRemindTime(date);
|
|
|
|
|
supCertRemindMsgEntity.setStatus(2); //已确认
|
|
|
|
|
supCertRemindMsgEntity.setIgnoreStatus(0); //忽略状态,不忽略
|
|
|
|
|
supCertRemindMsgDao.updateById(supCertRemindMsgEntity);
|
|
|
|
|
return ResultVOUtils.success("已确认");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse ignoreMsg(Integer id, Integer ignoreStatus) {
|
|
|
|
|
SupCertRemindMsgEntity msgEntity = supCertRemindMsgDao.selectById(id);
|
|
|
|
|
if (null == msgEntity) {
|
|
|
|
|
return ResultVOUtils.error(500, "预警信息不存在");
|
|
|
|
|
}
|
|
|
|
|
//根据忽略状态,更新忽略时间
|
|
|
|
|
Date updateTime = msgEntity.getUpdateTime();
|
|
|
|
|
switch (ignoreStatus) {
|
|
|
|
|
case 1: //忽略7天
|
|
|
|
|
msgEntity.setNextRemindTime(DateUtil.getAfterDay(updateTime, 7 * 24));
|
|
|
|
|
break;
|
|
|
|
|
case 2: //忽略15天
|
|
|
|
|
msgEntity.setNextRemindTime(DateUtil.getAfterDay(updateTime, 15 * 24));
|
|
|
|
|
break;
|
|
|
|
|
case 3: //忽略30天
|
|
|
|
|
msgEntity.setNextRemindTime(DateUtil.getAfterDay(updateTime, 30 * 24));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
msgEntity.setIgnoreStatus(ignoreStatus);
|
|
|
|
|
supCertRemindMsgDao.updateById(msgEntity);
|
|
|
|
|
return ResultVOUtils.success("已忽略预警");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void createRemindMsg() {
|
|
|
|
|
//资质预警类型集合
|
|
|
|
|
List<Integer> types = Arrays.asList(1, 2, 3);
|
|
|
|
|
for (Integer type : types) {
|
|
|
|
|
buildRemindMsg(buildQueryWrapper(type), type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造查询条件
|
|
|
|
|
*
|
|
|
|
|
* @param type
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private QueryWrapper<SupCertEntity> buildQueryWrapper(Integer type) {
|
|
|
|
|
QueryWrapper<SupCertEntity> wrapper = new QueryWrapper<>();
|
|
|
|
|
wrapper.eq("status", 0).eq("auditStatus", ConstantStatus.AUDIT_PASS).lt("expireDate", new Date()).eq("type", type);
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 1: //查询供应商ID
|
|
|
|
|
wrapper.select("CustomerId", "code", "vailDate", "expireDate");
|
|
|
|
|
break;
|
|
|
|
|
case 2: //查询生产企业ID
|
|
|
|
|
wrapper.select("manufacturerIdFk", "code", "vailDate", "expireDate");
|
|
|
|
|
break;
|
|
|
|
|
case 3: //查询产品ID
|
|
|
|
|
wrapper.select("productIdFk", "code", "vailDate", "expireDate");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return wrapper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造,保存预警信息
|
|
|
|
|
*
|
|
|
|
|
* @param supCertWrapper
|
|
|
|
|
* @param type
|
|
|
|
|
*/
|
|
|
|
|
private void buildRemindMsg(QueryWrapper<SupCertEntity> supCertWrapper, Integer type) {
|
|
|
|
|
List<SupCertEntity> supCertList = supCertDao.selectList(supCertWrapper);
|
|
|
|
|
List<SupCertEntity> list = new CopyOnWriteArrayList<>(supCertList);
|
|
|
|
|
list.parallelStream().forEach(supCertEntity -> {
|
|
|
|
|
//判断证书是否超出失效期
|
|
|
|
|
SupCertRemindMsgEntity msgEntity = getSupCertRemindMsg(supCertEntity, type);
|
|
|
|
|
if (null == msgEntity.getNextRemindTime() || msgEntity.getNextRemindTime().getTime() > new Date().getTime()) {
|
|
|
|
|
//生成,更新预警信息
|
|
|
|
|
saveMsg(msgEntity);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存/更新资质预警信息
|
|
|
|
|
*
|
|
|
|
|
* @param msgEntity
|
|
|
|
|
*/
|
|
|
|
|
private void saveMsg(SupCertRemindMsgEntity msgEntity) {
|
|
|
|
|
msgEntity.setStatus(1); //重置成为未确认信息
|
|
|
|
|
msgEntity.setIgnoreStatus(0); //忽略状态修改为不忽略
|
|
|
|
|
msgEntity.setHandleMsg(null); //处理方式重置为空
|
|
|
|
|
msgEntity.setUpdateTime(new Date());
|
|
|
|
|
msgEntity.setNextRemindTime(new Date());
|
|
|
|
|
|
|
|
|
|
if (null == msgEntity.getId()) {
|
|
|
|
|
log.info("新增资质预警:{}", JSONUtil.toJsonStr(msgEntity));
|
|
|
|
|
supCertRemindMsgDao.insert(msgEntity);
|
|
|
|
|
} else {
|
|
|
|
|
log.info("更新资质预警:{}", JSONUtil.toJsonStr(msgEntity));
|
|
|
|
|
supCertRemindMsgDao.insert(msgEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询/构造资质预警信息
|
|
|
|
|
*
|
|
|
|
|
* @param supCertEntity
|
|
|
|
|
* @param type
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private SupCertRemindMsgEntity getSupCertRemindMsg(SupCertEntity supCertEntity, Integer type) {
|
|
|
|
|
String idFk = null; //关联外键
|
|
|
|
|
String msg = null; //预警信息
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 1: //供应商
|
|
|
|
|
idFk = supCertEntity.getCustomerId();
|
|
|
|
|
msg = "供应商资质过期,过期时间:" + DateUtil.formatDate(supCertEntity.getExpireDate(), "yyyy-MM-dd");
|
|
|
|
|
break;
|
|
|
|
|
case 2: //生产企业
|
|
|
|
|
idFk = supCertEntity.getManufacturerIdFk();
|
|
|
|
|
msg = "生产企业资质过期,过期时间:" + DateUtil.formatDate(supCertEntity.getExpireDate(), "yyyy-MM-dd");
|
|
|
|
|
break;
|
|
|
|
|
case 3: //产品
|
|
|
|
|
idFk = supCertEntity.getProductIdFk();
|
|
|
|
|
msg = "产品资质过期,过期时间:" + DateUtil.formatDate(supCertEntity.getExpireDate(), "yyyy-MM-dd");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
SupCertRemindMsgEntity msgEntity = supCertRemindMsgDao.selectOne(new QueryWrapper<SupCertRemindMsgEntity>().eq("idFk", idFk).eq("type", type).eq("code", supCertEntity.getCode()));
|
|
|
|
|
if (null == msgEntity) {
|
|
|
|
|
//构造新的资质预警信息
|
|
|
|
|
msgEntity = new SupCertRemindMsgEntity();
|
|
|
|
|
msgEntity.setIdFk(idFk); //设置关联主键
|
|
|
|
|
msgEntity.setType(type); //类型
|
|
|
|
|
msgEntity.setCode(supCertEntity.getCode()); //证书编码
|
|
|
|
|
msgEntity.setCreateTime(new Date());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msgEntity.setVailDate(supCertEntity.getVailDate());
|
|
|
|
|
msgEntity.setExpireDate(supCertEntity.getExpireDate());
|
|
|
|
|
msgEntity.setMsg(msg);
|
|
|
|
|
return msgEntity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|