2024-01-16 18:36:09 +08:00

172 lines
8.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.zhgd.xmgl.task;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhgd.xmgl.modules.basicdata.service.INoticeService;
import com.zhgd.xmgl.modules.project.entity.ProjectExternalSystemService;
import com.zhgd.xmgl.modules.project.mapper.ProjectExternalSystemServiceMapper;
import com.zhgd.xmgl.modules.project.service.IProjectUfaceConfigService;
import com.zhgd.xmgl.modules.worker.entity.WorkerBlacklist;
import com.zhgd.xmgl.modules.worker.entity.WorkerCertificate;
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
import com.zhgd.xmgl.modules.worker.mapper.WorkerBlacklistMapper;
import com.zhgd.xmgl.modules.worker.mapper.WorkerCertificateMapper;
import com.zhgd.xmgl.modules.worker.mapper.WorkerInfoMapper;
import com.zhgd.xmgl.modules.worker.service.IWorkerCertificateService;
import com.zhgd.xmgl.util.ElecardUtil;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
/**
* @program: wisdomSite
* @description: 劳务人员定时任务
* @author: Mr.Peng
* @create: 2021-09-10 17:31
**/
@Slf4j
@Component
@RestController
public class WorkerTask {
@Autowired
private ProjectExternalSystemServiceMapper projectExternalSystemServiceMapper;
@Autowired
private WorkerInfoMapper workerInfoMapper;
@Autowired
private INoticeService noticeService;
@Autowired
private IProjectUfaceConfigService projectUfaceConfigService;
@Autowired
private IWorkerCertificateService workerCertificateService;
@Autowired
private WorkerCertificateMapper workerCertificateMapper;
@Autowired
private WorkerBlacklistMapper workerBlacklistMapper;
/**
* 定时修改用户码状态
*/
@SchedulerLock(name = "updateWorkerCode", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5)
@Scheduled(cron = "0 0 1 * * ?")
public void updateWorkerCode() {
log.info("------------------------------健康码同步开始-----------------------------------------");
try {
List<ProjectExternalSystemService> list = projectExternalSystemServiceMapper.getChangtongCodeSystemList();
if(list!=null&&list.size()>0){
for (ProjectExternalSystemService projectExternalSystemService:list){
getWorkerCodeState(projectExternalSystemService);
}
}
}catch (Exception e){
e.printStackTrace();
}
log.info("------------------------------健康码同步结束-----------------------------------------");
}
public void getWorkerCodeState(ProjectExternalSystemService projectExternalSystemService){
try{
List<WorkerInfo> list= workerInfoMapper.selectAllWorkerInfoList(projectExternalSystemService.getProjectSn());
if(list!=null&&list.size()>0){
String token= ElecardUtil.getToken(projectExternalSystemService.getSystemUrl(),projectExternalSystemService.getAppId(),projectExternalSystemService.getAppSecert(),
projectExternalSystemService.getPublicKey(),projectExternalSystemService.getPrivateKey());
if(StringUtils.isNotEmpty(token)){
int redNum=0;
int orangeNum=0;
StringBuilder redWorkerName=new StringBuilder();
StringBuilder orangeWorkerName=new StringBuilder();
for (WorkerInfo workerInfo:list){
log.info("---------------"+workerInfo.getWorkerName());
String enterStatus=ElecardUtil.getCardInfo(projectExternalSystemService.getSystemUrl(),projectExternalSystemService.getAppId(),projectExternalSystemService.getAppSecert(),
projectExternalSystemService.getPublicKey(),projectExternalSystemService.getPrivateKey(),token,workerInfo.getIdCard());
//0 :绿色, 1:黄色 ,2:红色
//红黄码需设备取消授权不允许通行
if(StringUtils.isNotEmpty(enterStatus)){
if("2".equals(enterStatus)){
redNum++;
if(redWorkerName.length()>0){
redWorkerName.append("");
}
redWorkerName.append(workerInfo.getWorkerName());
//码状态0无码1红2黄3绿
workerInfo.setCodeState(1);
workerInfo.setUfaceDevId("0");
projectUfaceConfigService.deleteWorkerInfo(workerInfo);
}else if("1".equals(enterStatus)){
orangeNum++;
if(orangeWorkerName.length()>0){
orangeWorkerName.append("");
}
orangeWorkerName.append(workerInfo.getWorkerName());
workerInfo.setCodeState(2);
workerInfo.setUfaceDevId("0");
projectUfaceConfigService.deleteWorkerInfo(workerInfo);
}else{
workerInfo.setCodeState(3);
}
workerInfoMapper.updateById(workerInfo);
}
}
if(redNum>0||orangeNum>0){
//String title="今日昌通码核验黄码"+orangeNum+"人,红码"+redNum+"人";
StringBuilder title=new StringBuilder();
title.append("今日昌通码核验黄码").append(orangeNum).append("人,");
if(orangeWorkerName.length()>0){
title.append("分别为:").append(orangeWorkerName.toString()).append("");
}
title.append("红码").append(redNum).append("");
if(redWorkerName.length()>0){
title.append("分别为:").append(redWorkerName.toString()).append("");
}
StringBuilder title2=new StringBuilder();
if(orangeWorkerName.length()>0){
title2.append("黄码人员:").append(orangeWorkerName.toString()).append("");
}
if(redWorkerName.length()>0){
title2.append("红码人员:").append(redWorkerName.toString()).append("");
}
title2.append("已销权");
noticeService.sendProjectNoicte(projectExternalSystemService.getProjectSn(), "红黄码核验", title.toString(), "17");
noticeService.sendProjectNoicte(projectExternalSystemService.getProjectSn(), "红黄码销权", title2.toString(), "17");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 劳务人员,截止日期到期的话,就自动填充原因,就是证件到期到黑名单中
*/
@SchedulerLock(name = "addWorkerBlacklist", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5)
@Scheduled(cron = "0 0 1 * * ?")
@GetMapping("xmgl/task/addWorkerBlacklist")
public void addWorkerBlacklist() {
List<WorkerInfo> list = workerCertificateMapper.selectExpiredNotInBlackWorkerList();
for (WorkerInfo workerInfo : list) {
WorkerBlacklist black = new WorkerBlacklist();
black.setProjectSn(workerInfo.getProjectSn());
black.setWorkerId(workerInfo.getId());
black.setWorkerName(workerInfo.getWorkerName());
black.setIdCard(workerInfo.getIdCard());
black.setAddReason("证件已到期");
black.setReason("证件已到期");
black.setAddTime(DateUtil.now());
black.setCreateTime(new Date());
black.setType(1);
workerBlacklistMapper.insert(black);
}
}
}