2023-02-16 15:28:15 +08:00
|
|
|
|
package com.zhgd.xmgl.task;
|
|
|
|
|
|
|
2024-03-11 20:22:27 +08:00
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
2024-01-16 18:36:09 +08:00
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
2024-03-11 20:22:27 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserMapper;
|
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;
|
2024-03-11 20:22:27 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.project.mapper.ProjectMapper;
|
2023-02-16 15:28:15 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.project.service.IProjectUfaceConfigService;
|
2024-01-16 18:36:09 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.worker.entity.WorkerBlacklist;
|
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;
|
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;
|
2024-03-11 20:22:27 +08:00
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
2023-02-16 15:28:15 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @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;
|
2024-03-11 20:22:27 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private ProjectMapper projectMapper;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private SystemUserMapper systemUserMapper;
|
2023-02-16 15:28:15 +08:00
|
|
|
|
|
|
|
|
|
|
@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();
|
2024-03-11 20:22:27 +08:00
|
|
|
|
if (list != null && list.size() > 0) {
|
|
|
|
|
|
for (ProjectExternalSystemService projectExternalSystemService : list) {
|
2023-02-16 15:28:15 +08:00
|
|
|
|
getWorkerCodeState(projectExternalSystemService);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-11 20:22:27 +08:00
|
|
|
|
} catch (Exception e) {
|
2023-02-16 15:28:15 +08:00
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
log.info("------------------------------健康码同步结束-----------------------------------------");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-11 20:22:27 +08:00
|
|
|
|
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());
|
2023-02-16 15:28:15 +08:00
|
|
|
|
//0 :绿色, 1:黄色 ,2:红色
|
|
|
|
|
|
//红黄码需设备取消授权不允许通行
|
2024-03-11 20:22:27 +08:00
|
|
|
|
if (StringUtils.isNotEmpty(enterStatus)) {
|
|
|
|
|
|
if ("2".equals(enterStatus)) {
|
2023-02-16 15:28:15 +08:00
|
|
|
|
redNum++;
|
2024-03-11 20:22:27 +08:00
|
|
|
|
if (redWorkerName.length() > 0) {
|
2023-02-16 15:28:15 +08:00
|
|
|
|
redWorkerName.append("、");
|
|
|
|
|
|
}
|
|
|
|
|
|
redWorkerName.append(workerInfo.getWorkerName());
|
|
|
|
|
|
//码状态,0无码,1红,2黄,3绿
|
|
|
|
|
|
workerInfo.setCodeState(1);
|
|
|
|
|
|
workerInfo.setUfaceDevId("0");
|
|
|
|
|
|
projectUfaceConfigService.deleteWorkerInfo(workerInfo);
|
2024-03-11 20:22:27 +08:00
|
|
|
|
} else if ("1".equals(enterStatus)) {
|
2023-02-16 15:28:15 +08:00
|
|
|
|
orangeNum++;
|
2024-03-11 20:22:27 +08:00
|
|
|
|
if (orangeWorkerName.length() > 0) {
|
2023-02-16 15:28:15 +08:00
|
|
|
|
orangeWorkerName.append("、");
|
|
|
|
|
|
}
|
|
|
|
|
|
orangeWorkerName.append(workerInfo.getWorkerName());
|
|
|
|
|
|
workerInfo.setCodeState(2);
|
|
|
|
|
|
workerInfo.setUfaceDevId("0");
|
|
|
|
|
|
projectUfaceConfigService.deleteWorkerInfo(workerInfo);
|
2024-03-11 20:22:27 +08:00
|
|
|
|
} else {
|
2023-02-16 15:28:15 +08:00
|
|
|
|
workerInfo.setCodeState(3);
|
|
|
|
|
|
}
|
|
|
|
|
|
workerInfoMapper.updateById(workerInfo);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-11 20:22:27 +08:00
|
|
|
|
if (redNum > 0 || orangeNum > 0) {
|
2023-02-16 15:28:15 +08:00
|
|
|
|
//String title="今日昌通码核验黄码"+orangeNum+"人,红码"+redNum+"人";
|
2024-03-11 20:22:27 +08:00
|
|
|
|
StringBuilder title = new StringBuilder();
|
2023-02-16 15:28:15 +08:00
|
|
|
|
title.append("今日昌通码核验黄码").append(orangeNum).append("人,");
|
2024-03-11 20:22:27 +08:00
|
|
|
|
if (orangeWorkerName.length() > 0) {
|
2023-02-16 15:28:15 +08:00
|
|
|
|
title.append("分别为:").append(orangeWorkerName.toString()).append(",");
|
|
|
|
|
|
}
|
|
|
|
|
|
title.append("红码").append(redNum).append("人");
|
2024-03-11 20:22:27 +08:00
|
|
|
|
if (redWorkerName.length() > 0) {
|
2023-02-16 15:28:15 +08:00
|
|
|
|
title.append("分别为:").append(redWorkerName.toString()).append("。");
|
|
|
|
|
|
}
|
2024-03-11 20:22:27 +08:00
|
|
|
|
StringBuilder title2 = new StringBuilder();
|
|
|
|
|
|
if (orangeWorkerName.length() > 0) {
|
2023-02-16 15:28:15 +08:00
|
|
|
|
title2.append("黄码人员:").append(orangeWorkerName.toString()).append(",");
|
|
|
|
|
|
}
|
2024-03-11 20:22:27 +08:00
|
|
|
|
if (redWorkerName.length() > 0) {
|
2023-02-16 15:28:15 +08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-11 20:22:27 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 系统整改提前一个星期对人员的资质证书到期进行预警,预警后发送消息提示项目管理员账号
|
|
|
|
|
|
*/
|
|
|
|
|
|
@SchedulerLock(name = "alarmWorkerBlack", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5)
|
|
|
|
|
|
@Scheduled(cron = "0 0 1 * * ?")
|
|
|
|
|
|
@GetMapping("xmgl/task/alarmWorkerBlack")
|
|
|
|
|
|
public void alarmWorkerBlack() {
|
|
|
|
|
|
List<WorkerInfo> list = workerCertificateMapper.alarmWorkerBlack();
|
|
|
|
|
|
Map<String, List<WorkerInfo>> projectMap = list.stream().collect(Collectors.groupingBy(WorkerInfo::getProjectSn));
|
|
|
|
|
|
if (CollUtil.isNotEmpty(projectMap)) {
|
|
|
|
|
|
for (Map.Entry<String, List<WorkerInfo>> entry : projectMap.entrySet()) {
|
|
|
|
|
|
List<SystemUser> systemUserList = systemUserMapper.selectList(new LambdaQueryWrapper<SystemUser>()
|
|
|
|
|
|
.eq(SystemUser::getSn, entry.getKey()));
|
|
|
|
|
|
List<WorkerInfo> workerInfoList = entry.getValue();
|
|
|
|
|
|
if (CollUtil.isNotEmpty(workerInfoList)) {
|
|
|
|
|
|
for (WorkerInfo workerInfo : workerInfoList) {
|
|
|
|
|
|
if (CollUtil.isNotEmpty(systemUserList)) {
|
|
|
|
|
|
for (SystemUser systemUser : systemUserList) {
|
|
|
|
|
|
noticeService.addUserNotice(systemUser.getUserId(), workerInfo.getWorkerName() + "的" + workerInfo.getCertificateTypeName() + "即将到期,请尽快更新!", "人员的资质证书即将到期", "20");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-16 15:28:15 +08:00
|
|
|
|
}
|