1.迁移资质预警代码到自助平台

master
x_z 2 years ago
parent 9037b42fb6
commit de03676edf

@ -0,0 +1,71 @@
package com.glxp.api.controller.purchase;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageInfo;
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.req.purchase.FilterCertRemindMsgRequest;
import com.glxp.api.res.purchase.SupCertRemindMsgResponse;
import com.glxp.api.service.purchase.SupCertRemindMsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
*
*/
@Slf4j
@RestController
public class SupCertRemindMsgController {
@Resource
private SupCertRemindMsgService supCertRemindMsgService;
/**
*
*
* @param filterCertRemindMsgRequest
* @return
*/
@GetMapping("/sup/cert/remind/msg/filter")
public BaseResponse filterList(FilterCertRemindMsgRequest filterCertRemindMsgRequest) {
List<SupCertRemindMsgResponse> list = supCertRemindMsgService.filterList(filterCertRemindMsgRequest);
PageInfo<SupCertRemindMsgResponse> pageInfo = new PageInfo<>(list);
return ResultVOUtils.page(pageInfo);
}
/**
*
*
* @param id
* @param handleMsg
* @return
*/
@GetMapping("/sup/cert/remind/msg/confirmMsg")
public BaseResponse confirmMsg(Integer id, String handleMsg) {
if (null == id || StrUtil.isBlank(handleMsg)) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
return supCertRemindMsgService.confirmMsg(id, handleMsg);
}
/**
*
*
* @param id
* @param ignoreStatus
* @return
*/
@GetMapping("/sup/cert/remind/msg/ignoreMsg")
public BaseResponse ignoreMsg(Integer id, Integer ignoreStatus) {
if (null == id || null == ignoreStatus) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
return supCertRemindMsgService.ignoreMsg(id, ignoreStatus);
}
}

@ -1,6 +1,7 @@
package com.glxp.api.dao.purchase;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.glxp.api.entity.purchase.SupCertEntity;
import com.glxp.api.req.purchase.FilterSupCertRequest;
import com.glxp.api.req.purchase.purPlanPrintRequest;
@ -10,7 +11,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface SupCertDao {
public interface SupCertDao extends BaseMapper<SupCertEntity> {
List<SupCertEntity> filterCompanyCert(FilterSupCertRequest filterSupCertRequest);

@ -0,0 +1,35 @@
package com.glxp.api.dao.purchase;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.glxp.api.entity.purchase.SupCertRemindMsgEntity;
import com.glxp.api.req.purchase.FilterCertRemindMsgRequest;
import com.glxp.api.res.purchase.SupCertRemindMsgResponse;
import java.util.List;
public interface SupCertRemindMsgDao extends BaseMapper<SupCertRemindMsgEntity> {
/**
*
*
* @param filterCertRemindMsgRequest
* @return
*/
List<SupCertRemindMsgResponse> selectSupRemindMsgList(FilterCertRemindMsgRequest filterCertRemindMsgRequest);
/**
*
*
* @param filterCertRemindMsgRequest
* @return
*/
List<SupCertRemindMsgResponse> selectManufactureRemindMsgList(FilterCertRemindMsgRequest filterCertRemindMsgRequest);
/**
*
*
* @param filterCertRemindMsgRequest
* @return
*/
List<SupCertRemindMsgResponse> selectProductRemindMsgList(FilterCertRemindMsgRequest filterCertRemindMsgRequest);
}

@ -0,0 +1,102 @@
package com.glxp.api.entity.purchase;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
/**
*
*/
@Data
@TableName(value = "sup_cert_remind_msg")
public class SupCertRemindMsgEntity {
/**
* id
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* IDIDID
*/
@TableField(value = "idFk")
private String idFk;
/**
*
*/
@TableField(value = "code")
private String code;
/**
*
*/
@TableField(value = "vailDate")
private Date vailDate;
/**
*
*/
@TableField(value = "expireDate")
private Date expireDate;
/**
* 123
*/
@TableField(value = "`type`")
private Integer type;
/**
* 12
*/
@TableField(value = "`status`")
private Integer status;
/**
* 017215330
*/
@TableField(value = "ignoreStatus")
private Integer ignoreStatus;
/**
*
*/
@TableField(value = "msg")
private String msg;
/**
*
*/
@TableField(value = "handleMsg")
private String handleMsg;
/**
*
*/
@TableField(value = "nextRemindTime")
private Date nextRemindTime;
/**
*
*/
@TableField(value = "createTime")
private Date createTime;
/**
*
*/
@TableField(value = "updateTime")
private Date updateTime;
/**
*
*/
@TableField(value = "remark")
private String remark;
}

@ -0,0 +1,37 @@
package com.glxp.api.req.purchase;
import com.glxp.api.util.page.ListPageRequest;
import lombok.Data;
/**
*
*/
@Data
public class FilterCertRemindMsgRequest extends ListPageRequest {
/**
* ID
*/
private String supId;
/**
*
*/
private String name;
/**
* 123
*/
private Integer type;
/**
* 12
*/
private Integer status;
/**
* 017215330
*/
private Integer ignoreStatus;
}

@ -0,0 +1,96 @@
package com.glxp.api.res.purchase;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
* VO
*/
@Data
public class SupCertRemindMsgResponse {
/**
* id
*/
private Integer id;
/**
* IDIDID
*/
private String idFk;
/**
*
*/
private String code;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd")
private Date vailDate;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd")
private Date expireDate;
/**
* 123
*/
private Integer type;
/**
* 12
*/
private Integer status;
/**
* 017215330
*/
private Integer ignoreStatus;
/**
*
*/
private String msg;
/**
*
*/
private String handleMsg;
/**
*
*/
private Date nextRemindTime;
/**
*
*/
private Date createTime;
/**
*
*/
private Date updateTime;
/**
*
*/
private String remark;
/**
* //
*/
private String name;
/**
*
*/
private String certName;
}

@ -52,7 +52,20 @@ public class CustomerService {
public String getCustomerId() {
AuthAdmin authAdmin = getUserBean();
return authAdmin.getCustomerId()+"";
return authAdmin.getCustomerId() + "";
}
/**
*
*
* @return
*/
public boolean isHosUser() {
String customerId = getCustomerId();
if (customerId.equals("110")) {
return true;
}
return false;
}
}

@ -0,0 +1,45 @@
package com.glxp.api.service.purchase;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.req.purchase.FilterCertRemindMsgRequest;
import com.glxp.api.res.purchase.SupCertRemindMsgResponse;
import java.util.List;
/**
* Service
*/
public interface SupCertRemindMsgService {
/**
*
*
* @param filterCertRemindMsgRequest
* @return
*/
List<SupCertRemindMsgResponse> filterList(FilterCertRemindMsgRequest filterCertRemindMsgRequest);
/**
*
*
* @param id
* @param handleMsg
* @return
*/
BaseResponse confirmMsg(Integer id, String handleMsg);
/**
*
*
* @param id
* @param ignoreStatus
* @return
*/
BaseResponse ignoreMsg(Integer id, Integer ignoreStatus);
/**
*
*/
void createRemindMsg();
}

@ -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;
}
}

@ -0,0 +1,47 @@
package com.glxp.api.task;
import com.glxp.api.dao.schedule.ScheduledDao;
import com.glxp.api.entity.system.ScheduledEntity;
import com.glxp.api.req.system.ScheduledRequest;
import com.glxp.api.service.purchase.SupCertRemindMsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
*
*/
@Slf4j
@Component
public class SupCertRemindMsgTask implements SchedulingConfigurer {
@Resource
private ScheduledDao scheduledDao;
@Resource
private SupCertRemindMsgService supCertRemindMsgService;
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.addTriggerTask(this::process, triggerContext -> {
ScheduledRequest scheduledRequest = new ScheduledRequest();
scheduledRequest.setCronName("supCertRemindMsgTask");
ScheduledEntity scheduled = scheduledDao.findScheduled(scheduledRequest);
if (null == scheduled) {
log.error("资质预警预警定时任务未配置,请注意!");
return null;
}
String cron = scheduled.getCron();
return new CronTrigger(cron).nextExecutionTime(triggerContext);
});
}
private void process() {
log.info("开始扫描资质证书信息,生成资质预警消息");
supCertRemindMsgService.createRemindMsg();
log.info("资质证书预警信息生成结束");
}
}

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.glxp.api.dao.purchase.SupCertRemindMsgDao">
<select id="selectSupRemindMsgList" resultType="com.glxp.api.res.purchase.SupCertRemindMsgResponse">
select m.*,
c.companyName `name`,
(select `name` from sup_cert s where s.code = m.code and s.CustomerId = m.idFk) certName
from sup_cert_remind_msg m
left join sup_company c on m.idFk = c.customerId
<where>
<if test="supId != null and supId != ''">
AND m.idFk = #{supId}
</if>
<if test="name != null and name != ''">
AND c.companyName like concat('%', #{name}, '%')
</if>
<if test="status != null">
AND m.status = #{status}
</if>
<if test="ignoreStatus != null">
AND m.ignoreStatus = #{ignoreStatus}
</if>
<if test="type != null">
AND m.type = #{type}
</if>
</where>
order by m.updateTime desc
</select>
<select id="selectManufactureRemindMsgList" resultType="com.glxp.api.res.purchase.SupCertRemindMsgResponse">
select m.*,
c.companyName `name`,
(select `name` from sup_cert s where s.code = m.code and s.manufacturerIdFk = m.idFk) certName
from sup_cert_remind_msg m
left join sup_manufacturer c on m.idFk = c.customerId
<where>
<if test="supId != null and supId != ''">
AND c.customerId = #{supId}
</if>
<if test="name != null and name != ''">
AND c.companyName like concat('%', #{name}, '%')
</if>
<if test="status != null">
AND m.status = #{status}
</if>
<if test="ignoreStatus != null">
AND m.ignoreStatus = #{ignoreStatus}
</if>
<if test="type != null">
AND m.type = #{type}
</if>
</where>
order by m.updateTime desc
</select>
<select id="selectProductRemindMsgList" resultType="com.glxp.api.res.purchase.SupCertRemindMsgResponse">
select m.*,
c.recordProductName `name`,
(select `name` from sup_cert s where s.code = m.code and s.productIdFk = m.idFk) certName
from sup_cert_remind_msg m
left join sup_product c on m.idFk = c.productId
<where>
<if test="supId != null and supId != ''">
AND c.customerId = #{supId}
</if>
<if test="name != null and name != ''">
AND c.recordProductName like concat('%', #{name}, '%')
</if>
<if test="status != null">
AND m.status = #{status}
</if>
<if test="ignoreStatus != null">
AND m.ignoreStatus = #{ignoreStatus}
</if>
<if test="type != null">
AND m.type = #{type}
</if>
</where>
order by m.updateTime desc
</select>
</mapper>
Loading…
Cancel
Save