172 lines
8.6 KiB
Java
Raw Normal View History

2023-02-16 15:28:15 +08:00
package com.zhgd.xmgl.task;
2024-01-16 18:36:09 +08:00
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
2023-02-16 15:28:15 +08:00
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;
2024-01-16 18:36:09 +08:00
import com.zhgd.xmgl.modules.worker.entity.WorkerBlacklist;
import com.zhgd.xmgl.modules.worker.entity.WorkerCertificate;
2023-02-16 15:28:15 +08:00
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
2024-01-16 18:36:09 +08:00
import com.zhgd.xmgl.modules.worker.mapper.WorkerBlacklistMapper;
import com.zhgd.xmgl.modules.worker.mapper.WorkerCertificateMapper;
2023-02-16 15:28:15 +08:00
import com.zhgd.xmgl.modules.worker.mapper.WorkerInfoMapper;
2024-01-16 18:36:09 +08:00
import com.zhgd.xmgl.modules.worker.service.IWorkerCertificateService;
2023-02-16 15:28:15 +08:00
import com.zhgd.xmgl.util.ElecardUtil;
import lombok.extern.log4j.Log4j;
2024-01-16 18:36:09 +08:00
import lombok.extern.slf4j.Slf4j;
2023-02-16 15:28:15 +08:00
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;
2024-01-16 18:36:09 +08:00
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
2023-02-16 15:28:15 +08:00
2024-01-16 18:36:09 +08:00
import java.util.Date;
2023-02-16 15:28:15 +08:00
import java.util.List;
/**
* @program: wisdomSite
* @description: 劳务人员定时任务
* @author: Mr.Peng
* @create: 2021-09-10 17:31
**/
2024-01-16 18:36:09 +08:00
@Slf4j
2023-02-16 15:28:15 +08:00
@Component
2024-01-16 18:36:09 +08:00
@RestController
2023-02-16 15:28:15 +08:00
public class WorkerTask {
@Autowired
private ProjectExternalSystemServiceMapper projectExternalSystemServiceMapper;
@Autowired
private WorkerInfoMapper workerInfoMapper;
@Autowired
private INoticeService noticeService;
@Autowired
private IProjectUfaceConfigService projectUfaceConfigService;
2024-01-16 18:36:09 +08:00
@Autowired
private IWorkerCertificateService workerCertificateService;
@Autowired
private WorkerCertificateMapper workerCertificateMapper;
@Autowired
private WorkerBlacklistMapper workerBlacklistMapper;
2023-02-16 15:28:15 +08:00
/**
* 定时修改用户码状态
*/
2024-01-16 18:36:09 +08:00
@SchedulerLock(name = "updateWorkerCode", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5)
2023-02-16 15:28:15 +08:00
@Scheduled(cron = "0 0 1 * * ?")
2024-01-16 18:36:09 +08:00
public void updateWorkerCode() {
2023-02-16 15:28:15 +08:00
log.info("------------------------------健康码同步开始-----------------------------------------");
2024-01-16 18:36:09 +08:00
try {
List<ProjectExternalSystemService> list = projectExternalSystemServiceMapper.getChangtongCodeSystemList();
2023-02-16 15:28:15 +08:00
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("已销权");
2024-01-16 18:36:09 +08:00
noticeService.sendProjectNoicte(projectExternalSystemService.getProjectSn(), "红黄码核验", title.toString(), "17");
noticeService.sendProjectNoicte(projectExternalSystemService.getProjectSn(), "红黄码销权", title2.toString(), "17");
2023-02-16 15:28:15 +08:00
}
}
}
2024-01-16 18:36:09 +08:00
} catch (Exception e) {
2023-02-16 15:28:15 +08:00
e.printStackTrace();
}
}
2024-01-16 18:36:09 +08:00
/**
* 劳务人员截止日期到期的话就自动填充原因就是证件到期到黑名单中
*/
@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);
2023-02-16 15:28:15 +08:00
}
}
}