1081 lines
64 KiB
Java
1081 lines
64 KiB
Java
package com.zhgd.xmgl.task;
|
||
|
||
import cn.hutool.core.collection.CollUtil;
|
||
import cn.hutool.core.convert.Convert;
|
||
import cn.hutool.core.date.BetweenFormatter;
|
||
import cn.hutool.core.date.DateTime;
|
||
import cn.hutool.core.date.DateUtil;
|
||
import cn.hutool.core.util.StrUtil;
|
||
import cn.hutool.http.HttpRequest;
|
||
import cn.xuyanwu.spring.file.storage.FileInfo;
|
||
import com.alibaba.fastjson.JSON;
|
||
import com.alibaba.fastjson.JSONArray;
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||
import com.google.common.collect.Lists;
|
||
import com.zhgd.xmgl.constant.Cts;
|
||
import com.zhgd.xmgl.modules.basicdata.entity.Notice;
|
||
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
|
||
import com.zhgd.xmgl.modules.basicdata.mapper.SystemLogoConfigMapper;
|
||
import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserMapper;
|
||
import com.zhgd.xmgl.modules.basicdata.service.INoticeService;
|
||
import com.zhgd.xmgl.modules.basicdata.service.ISystemUserService;
|
||
import com.zhgd.xmgl.modules.basicdata.service.UploadFileService;
|
||
import com.zhgd.xmgl.modules.dangerous.entity.HiddenDangerInspectRecord;
|
||
import com.zhgd.xmgl.modules.dangerous.service.IHiddenDangerInspectRecordService;
|
||
import com.zhgd.xmgl.modules.project.entity.Project;
|
||
import com.zhgd.xmgl.modules.project.entity.ProjectExternalSystemService;
|
||
import com.zhgd.xmgl.modules.project.entity.ProjectUfaceConfig;
|
||
import com.zhgd.xmgl.modules.project.mapper.ProjectExternalSystemServiceMapper;
|
||
import com.zhgd.xmgl.modules.project.mapper.ProjectMapper;
|
||
import com.zhgd.xmgl.modules.project.mapper.ProjectUfaceConfigMapper;
|
||
import com.zhgd.xmgl.modules.project.service.IProjectUfaceConfigService;
|
||
import com.zhgd.xmgl.modules.quality.entity.QualityRegion;
|
||
import com.zhgd.xmgl.modules.quality.service.IQualityRegionService;
|
||
import com.zhgd.xmgl.modules.worker.entity.*;
|
||
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.*;
|
||
import com.zhgd.xmgl.modules.worker.service.impl.WorkerInfoServiceImpl;
|
||
import com.zhgd.xmgl.modules.xz.entity.XzCertificateExpireAlarmRecord;
|
||
import com.zhgd.xmgl.modules.xz.entity.XzWorkerSafeWatchAlarm;
|
||
import com.zhgd.xmgl.modules.xz.entity.XzWorkerSafeWatchConfig;
|
||
import com.zhgd.xmgl.modules.xz.entity.XzWorkerSafeWatchManager;
|
||
import com.zhgd.xmgl.modules.xz.security.entity.XzSecurityInspectTaskItemRecord;
|
||
import com.zhgd.xmgl.modules.xz.security.entity.XzSecurityInspectTaskRecord;
|
||
import com.zhgd.xmgl.modules.xz.security.entity.XzSecurityQualityInspectionRecord;
|
||
import com.zhgd.xmgl.modules.xz.security.entity.vo.XzSecurityQualityInspectionRecordVo;
|
||
import com.zhgd.xmgl.modules.xz.security.enums.XzSecurityQualityInspectionRecordStatusEnum;
|
||
import com.zhgd.xmgl.modules.xz.security.mapper.XzSecurityInspectTaskItemRecordMapper;
|
||
import com.zhgd.xmgl.modules.xz.security.mapper.XzSecurityInspectTaskRecordMapper;
|
||
import com.zhgd.xmgl.modules.xz.security.mapper.XzSecurityQualityInspectionRecordMapper;
|
||
import com.zhgd.xmgl.modules.xz.security.service.IXzSecurityQualityInspectionRecordService;
|
||
import com.zhgd.xmgl.modules.xz.service.IXzHikvisionSyncService;
|
||
import com.zhgd.xmgl.modules.xz.service.IXzWorkerSafeWatchAlarmService;
|
||
import com.zhgd.xmgl.modules.xz.service.IXzWorkerSafeWatchConfigService;
|
||
import com.zhgd.xmgl.modules.xz.service.IXzWorkerSafeWatchManagerService;
|
||
import com.zhgd.xmgl.modules.xz.service.impl.XzCertificateExpireAlarmRecordServiceImpl;
|
||
import com.zhgd.xmgl.util.*;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import net.javacrumbs.shedlock.core.SchedulerLock;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.jetbrains.annotations.Nullable;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.beans.factory.annotation.Value;
|
||
import org.springframework.context.annotation.Lazy;
|
||
import org.springframework.scheduling.annotation.Scheduled;
|
||
import org.springframework.stereotype.Component;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RestController;
|
||
|
||
import javax.annotation.Resource;
|
||
import java.util.*;
|
||
import java.util.function.Function;
|
||
import java.util.stream.Collectors;
|
||
|
||
/**
|
||
* @program: wisdomSite
|
||
* @description: 劳务人员定时任务
|
||
* @author: Mr.Peng
|
||
* @create: 2021-09-10 17:31
|
||
**/
|
||
@Slf4j
|
||
@Component
|
||
@RestController
|
||
@RequestMapping("xmgl/task")
|
||
public class WorkerTask {
|
||
@Autowired
|
||
WorkerInfoServiceImpl workerInfoService;
|
||
@Autowired
|
||
IQualityRegionService qualityRegionService;
|
||
@Autowired
|
||
IRegionViolationService regionViolationService;
|
||
@Autowired
|
||
ISystemUserService systemUserService;
|
||
@Autowired
|
||
private ProjectExternalSystemServiceMapper projectExternalSystemServiceMapper;
|
||
@Autowired
|
||
private WorkerInfoMapper workerInfoMapper;
|
||
@Autowired
|
||
private ProjectMapper projectMapper;
|
||
@Autowired
|
||
private SystemUserMapper systemUserMapper;
|
||
@Autowired
|
||
private SystemLogoConfigMapper systemLogoConfigMapper;
|
||
@Autowired
|
||
private IWorkerAttendancePresenceService workerAttendancePresenceService;
|
||
@Autowired
|
||
private INoticeService noticeService;
|
||
@Autowired
|
||
private IProjectUfaceConfigService projectUfaceConfigService;
|
||
@Autowired
|
||
private IWorkerCertificateService workerCertificateService;
|
||
@Autowired
|
||
private WorkerCertificateMapper workerCertificateMapper;
|
||
@Autowired
|
||
private WorkerBlacklistMapper workerBlacklistMapper;
|
||
@Autowired
|
||
private XzCertificateExpireAlarmRecordServiceImpl xzCertificateExpireAlarmRecordService;
|
||
@Autowired
|
||
private IXzWorkerSafeWatchConfigService xzWorkerSafeWatchConfigService;
|
||
@Autowired
|
||
private IWorkerMonthAttendanceStatisticsService workerMonthAttendanceStatisticsService;
|
||
@Autowired
|
||
private XzSecurityQualityInspectionRecordMapper xzSecurityQualityInspectionRecordMapper;
|
||
@Autowired
|
||
private IWorkerAttendanceService workerAttendanceService;
|
||
@Autowired
|
||
private IXzWorkerSafeWatchAlarmService xzWorkerSafeWatchAlarmService;
|
||
@Autowired
|
||
private IXzWorkerSafeWatchManagerService xzWorkerSafeWatchManagerService;
|
||
@Autowired
|
||
private XzSecurityInspectTaskRecordMapper xzSecurityInspectTaskRecordMapper;
|
||
@Autowired
|
||
private XzSecurityInspectTaskItemRecordMapper xzSecurityInspectTaskItemRecordMapper;
|
||
@Autowired
|
||
private IHiddenDangerInspectRecordService hiddenDangerInspectRecordService;
|
||
@Autowired
|
||
private IXzSecurityQualityInspectionRecordService qualityInspectionRecordService;
|
||
@Resource
|
||
private UploadFileService uploadFileService;
|
||
@Lazy
|
||
@Resource
|
||
private IUfaceDevService ufaceDevService;
|
||
@Lazy
|
||
@Autowired
|
||
private IDangongWorkerFaceStatusService dangongWorkerFaceStatusService;
|
||
@Autowired
|
||
private IXzSecurityQualityInspectionRecordService xzSecurityQualityInspectionRecordService;
|
||
|
||
@Lazy
|
||
@Autowired
|
||
private IXzHikvisionSyncService xzHikvisionSyncService;
|
||
|
||
@Lazy
|
||
@Autowired
|
||
private ProjectUfaceConfigMapper projectUfaceConfigMapper;
|
||
|
||
@Value("${basePath}")
|
||
private String basePath;
|
||
@Lazy
|
||
@Autowired
|
||
private IWorkerExitConfigService workerExitConfigService;
|
||
@Lazy
|
||
@Autowired
|
||
private IWorkerBlacklistService workerBlacklistService;
|
||
|
||
/**
|
||
* 定时修改用户码状态
|
||
*/
|
||
@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();
|
||
Date now = new Date();
|
||
if (list != null && list.size() > 0) {
|
||
for (ProjectExternalSystemService projectExternalSystemService : list) {
|
||
getWorkerCodeState(projectExternalSystemService, now);
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
log.error("error:", e);
|
||
}
|
||
log.info("------------------------------健康码同步结束-----------------------------------------");
|
||
}
|
||
|
||
public void getWorkerCodeState(ProjectExternalSystemService projectExternalSystemService, Date now) {
|
||
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.sendProjectNotice(projectExternalSystemService.getProjectSn(), "红黄码核验", title.toString(), "17");
|
||
noticeService.sendProjectNotice(projectExternalSystemService.getProjectSn(), "红黄码销权", title2.toString(), "17");
|
||
}
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
log.error("error:", e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 劳务人员,截止日期到期的话(包括人员的合同信息、资格证书、保险信息),就自动填充原因,就是证件到期到黑名单中
|
||
*/
|
||
@SchedulerLock(name = "addWorkerBlacklist", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5)
|
||
@Scheduled(cron = "0 0 1 * * ?")
|
||
@RequestMapping("/addWorkerBlacklist")
|
||
public void addWorkerBlacklist() {
|
||
log.info("任务开始,劳务人员,截止日期到期的话(包括人员的合同信息、资格证书、保险信息),到黑名单");
|
||
//证书过期
|
||
List<WorkerInfo> list = workerCertificateMapper.selectExpiredCertificateNotInBlackWorkerList();
|
||
addWorkerBlacklist(list, "证件已到期", 1);
|
||
|
||
//合同过期
|
||
List<WorkerInfo> list1 = workerCertificateMapper.selectExpiredContractNotInBlackWorkerList();
|
||
addWorkerBlacklist(list1, "合同已到期", 2);
|
||
|
||
//保险过期
|
||
List<WorkerInfo> list2 = workerCertificateMapper.selectExpiredInsuranceNotInBlackWorkerList();
|
||
addWorkerBlacklist(list2, "保险已到期", 3);
|
||
}
|
||
|
||
private void addWorkerBlacklist(List<WorkerInfo> list, String addReason, int type) {
|
||
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(addReason);
|
||
black.setReason(addReason);
|
||
black.setAddTime(DateUtil.now());
|
||
black.setCreateTime(new Date());
|
||
black.setType(type);
|
||
workerBlacklistMapper.insert(black);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 对人员的资质证书到期进行预警,预警后发送消息提示项目管理员账号
|
||
* 系统设置:开启后将会在对企业下的各个项目开启人员证书到期预警提示,提前预警时间可以自行设置,监测内容包括人员的合同信息、资格证书、保险信息。
|
||
*/
|
||
@SchedulerLock(name = "alarmWorkerBlack", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5)
|
||
@Scheduled(cron = "0 0 1 * * ?")
|
||
@RequestMapping("/alarmWorkerBlack")
|
||
public void alarmWorkerBlack() {
|
||
log.info("任务开始,对人员的合同信息、资格证书、保险信息到期进行预警,预警后发送消息提示项目管理员账号");
|
||
//资格证书预警
|
||
List<WorkerInfo> list1 = workerCertificateMapper.getAlarmWorkerCertificateWithHeadquarter();
|
||
List<WorkerInfo> list2 = workerCertificateMapper.getAlarmWorkerCertificateNotHeadquarter();
|
||
addNotice(CollUtil.addAll(list1, list2), "人员的资质证书即将到期", "20");
|
||
|
||
//合同信息预警
|
||
List<WorkerInfo> list3 = workerCertificateMapper.getAlarmWorkerContractWithHeadquarter();
|
||
List<WorkerInfo> list4 = workerCertificateMapper.getAlarmWorkerContractNotHeadquarter();
|
||
addNotice(CollUtil.addAll(list3, list4), "人员的合同信息即将到期", "21");
|
||
|
||
//保险信息预警
|
||
List<WorkerInfo> list5 = workerCertificateMapper.getAlarmWorkerInsuranceWithHeadquarter();
|
||
List<WorkerInfo> list6 = workerCertificateMapper.getAlarmWorkerInsuranceNotHeadquarter();
|
||
addNotice(CollUtil.addAll(list5, list6), "人员的保险信息即将到期", "22");
|
||
}
|
||
|
||
/**
|
||
* 对人员未履职情况进行监测,及时反馈预警
|
||
*/
|
||
@Scheduled(cron = "0 0/1 * * * ?")
|
||
@RequestMapping("/workerSafeWatchAlarm")
|
||
public void workerSafeWatchAlarm() {
|
||
log.info("开始执行对人员未履职情况进行监测");
|
||
String[] typeName = {"人员日常考勤", "每个项目自检任务", "一个月内缺勤超过", "一个月内迟到超过"};
|
||
List<Project> projects = projectMapper.selectList(Wrappers.<Project>lambdaQuery().eq(Project::getStatus, 2));
|
||
for (Project project : projects) {
|
||
if (project.getEnableWorkerSafeWatch() != null && project.getEnableWorkerSafeWatch() == 1) {
|
||
List<SystemUser> projectLevelUsers = systemUserService.getSystemUsersBySn(new MapBuilder<String, Object>().put(Cts.SN, project.getProjectSn()).put(Cts.QUERY_TYPE, Cts.PROJECT_LEVEL).build());
|
||
List<XzWorkerSafeWatchConfig> list = xzWorkerSafeWatchConfigService.list(Wrappers.<XzWorkerSafeWatchConfig>lambdaQuery()
|
||
.eq(XzWorkerSafeWatchConfig::getProjectSn, project.getProjectSn()));
|
||
//安全履职预警增加规则
|
||
this.workerSafeWatchAlarmForHidden(list, project, projectLevelUsers);
|
||
if (StringUtils.isNotBlank(project.getWorkerSafeWatchTime()) &&
|
||
DateUtil.format(new Date(), "HH:mm").equals(
|
||
DateUtil.format(DateUtil.parseTime(project.getWorkerSafeWatchTime()), "HH:mm"))) {
|
||
List<XzWorkerSafeWatchAlarm> alarmList = new ArrayList<>();
|
||
List<Notice> noticeList = new ArrayList<>();
|
||
for (XzWorkerSafeWatchConfig xzWorkerSafeWatchConfig : list) {
|
||
String type = xzWorkerSafeWatchConfig.getType();
|
||
int dayNum = xzWorkerSafeWatchConfig.getDayNum();
|
||
Set<String> personSn = new HashSet<>();
|
||
//计算日常考勤规则
|
||
if ("1".equals(type)) {
|
||
dayNum = dayNum + 1;
|
||
DateTime dateTime = DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -dayNum));
|
||
Set<String> personSet = workerAttendanceService.list(Wrappers.<WorkerAttendance>lambdaQuery().between(WorkerAttendance::getCreateTime
|
||
, dateTime, new Date())).stream().map(w -> w.getPersonSn()).collect(Collectors.toSet());
|
||
Set<String> workerSet = workerInfoMapper.selectList(Wrappers.<WorkerInfo>lambdaQuery().eq(WorkerInfo::getInserviceType, 1)).stream().map(w -> w.getPersonSn()).collect(Collectors.toSet());
|
||
workerSet.removeAll(personSet);
|
||
personSn.addAll(workerSet);
|
||
}
|
||
if ("2".equals(type)) {
|
||
dayNum = dayNum + 1;
|
||
List<XzSecurityInspectTaskRecord> xzSecurityInspectTaskRecords = xzSecurityInspectTaskRecordMapper.selectList(Wrappers.<XzSecurityInspectTaskRecord>lambdaQuery()
|
||
.eq(XzSecurityInspectTaskRecord::getSn, project.getProjectSn())
|
||
.le(XzSecurityInspectTaskRecord::getEndTime, DateUtil.offsetDay(new Date(), -dayNum)));
|
||
if (xzSecurityInspectTaskRecords.size() > 0) {
|
||
List<XzSecurityInspectTaskItemRecord> itemList = xzSecurityInspectTaskItemRecordMapper.selectList(Wrappers.<XzSecurityInspectTaskItemRecord>lambdaQuery()
|
||
.in(XzSecurityInspectTaskItemRecord::getTaskId, xzSecurityInspectTaskRecords.stream().map(s -> s.getId()).collect(Collectors.toList())));
|
||
if (itemList != null && itemList.size() > 0) {
|
||
for (XzSecurityInspectTaskItemRecord data : itemList) {
|
||
XzSecurityInspectTaskRecord xzSecurityInspectTaskRecord = xzSecurityInspectTaskRecords.stream().filter(s -> s.getId().toString().equals(data.getTaskId().toString())).collect(Collectors.toList()).get(0);
|
||
SystemUser systemUser = systemUserMapper.selectById(xzSecurityInspectTaskRecord.getInspectUser());
|
||
WorkerInfo workerInfo = workerInfoMapper.selectById(systemUser.getWorkerId());
|
||
if (workerInfo != null) {
|
||
int count = 0;
|
||
if (xzSecurityInspectTaskRecord.getType() == 1) {
|
||
count = hiddenDangerInspectRecordService.count(Wrappers.<HiddenDangerInspectRecord>lambdaQuery()
|
||
.eq(HiddenDangerInspectRecord::getInspectHiddenDangerItemRecordId, data.getId()));
|
||
} else {
|
||
count = qualityInspectionRecordService.count(Wrappers.<XzSecurityQualityInspectionRecord>lambdaQuery()
|
||
.eq(XzSecurityQualityInspectionRecord::getItemId, data.getId()));
|
||
}
|
||
if (count == 0) {
|
||
personSn.add(workerInfo.getPersonSn());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if ("3".equals(type)) {
|
||
List<WorkerMonthAttendanceStatistics> list1 = workerMonthAttendanceStatisticsService.list(Wrappers.<WorkerMonthAttendanceStatistics>
|
||
lambdaQuery().eq(WorkerMonthAttendanceStatistics::getProjectSn, project.getProjectSn())
|
||
.eq(WorkerMonthAttendanceStatistics::getQueryTime, DateUtil.format(new Date(), "yyyy-MM")));
|
||
Integer number = 0;
|
||
for (WorkerMonthAttendanceStatistics workerMonthAttendanceStatistics : list1) {
|
||
JSONObject obj = JSONObject.parseObject(JSON.toJSONString(workerMonthAttendanceStatistics));
|
||
Iterator<String> iterator = obj.keySet().iterator();
|
||
while (iterator.hasNext()) {
|
||
String value = obj.getString(iterator.next());
|
||
if ("0".equals(value)) {
|
||
number++;
|
||
}
|
||
if (number > dayNum) {
|
||
personSn.add(workerMonthAttendanceStatistics.getPersonSn());
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if ("4".equals(type)) {
|
||
List<WorkerMonthAttendanceStatistics> list1 = workerMonthAttendanceStatisticsService.list(Wrappers.<WorkerMonthAttendanceStatistics>
|
||
lambdaQuery().eq(WorkerMonthAttendanceStatistics::getProjectSn, project.getProjectSn())
|
||
.eq(WorkerMonthAttendanceStatistics::getQueryTime, DateUtil.format(new Date(), "yyyy-MM")));
|
||
Integer number = 0;
|
||
for (WorkerMonthAttendanceStatistics workerMonthAttendanceStatistics : list1) {
|
||
JSONObject obj = JSONObject.parseObject(JSON.toJSONString(workerMonthAttendanceStatistics));
|
||
Iterator<String> iterator = obj.keySet().iterator();
|
||
while (iterator.hasNext()) {
|
||
String value = obj.getString(iterator.next());
|
||
if ("2".equals(value)) {
|
||
number++;
|
||
}
|
||
if (number > dayNum) {
|
||
personSn.add(workerMonthAttendanceStatistics.getPersonSn());
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if ("5".equals(type)) {
|
||
List<XzSecurityQualityInspectionRecordVo> xzSecurityQualityInspectionRecords = xzSecurityQualityInspectionRecordService.selectQualityInspectionRecordPage(new MapBuilder<String, Object>()
|
||
.put("recordType", 1)
|
||
.build()).getPage().getRecords();
|
||
xzSecurityQualityInspectionRecords.sort((o1, o2) -> o2.getCreateTime().compareTo(o1.getCreateTime()));
|
||
Set<String> ids = new HashSet<>();
|
||
for (XzSecurityQualityInspectionRecord xzSecurityQualityInspectionRecord : xzSecurityQualityInspectionRecords) {
|
||
for (String sn : StrUtil.split(xzSecurityQualityInspectionRecord.getEnterpriseSns(), ",")) {
|
||
String id = sn + "-" + xzSecurityQualityInspectionRecord.getDangerItemId();
|
||
ids.add(id);
|
||
}
|
||
}
|
||
for (String id : ids) {
|
||
String[] split = id.split("-");
|
||
List<XzSecurityQualityInspectionRecord> collect = xzSecurityQualityInspectionRecords.stream().filter(x -> Objects.nonNull(x.getEnterpriseSns()) && x.getEnterpriseSns().contains(split[0]) && x.getDangerItemId().toString().equals(split[1])).collect(Collectors.toList());
|
||
if (collect.size() >= dayNum) {
|
||
XzSecurityQualityInspectionRecord xzSecurityQualityInspectionRecord = collect.get(0);
|
||
SystemUser systemUser = systemUserMapper.selectById(xzSecurityQualityInspectionRecord.getChangeId());
|
||
Map<String, Object> requestParam = new HashMap<>(16);
|
||
requestParam.put("id", systemUser.getWorkerId());
|
||
requestParam.put("inserviceType", 1);
|
||
List<WorkerInfo> workerInfoList = workerInfoMapper.selectWorkerInfoList(new Page<>(-1, -1), requestParam);
|
||
if (workerInfoList.size() > 0) {
|
||
WorkerInfo workerInfo = workerInfoList.get(0);
|
||
XzWorkerSafeWatchAlarm xzWorkerSafeWatchAlarm = new XzWorkerSafeWatchAlarm();
|
||
xzWorkerSafeWatchAlarm.setWorkerId(workerInfo.getId());
|
||
xzWorkerSafeWatchAlarm.setWorkerName(workerInfo.getWorkerName());
|
||
String deptName = workerInfo.getDepartmentName() == null ? "" : workerInfo.getDepartmentName();
|
||
String teamName = workerInfo.getTeamName() == null ? "" : workerInfo.getTeamName();
|
||
xzWorkerSafeWatchAlarm.setDeptName(deptName + teamName);
|
||
xzWorkerSafeWatchAlarm.setEnterpriseName(workerInfo.getEnterpriseName());
|
||
xzWorkerSafeWatchAlarm.setAlarmTime(new Date());
|
||
xzWorkerSafeWatchAlarm.setType(type.toString());
|
||
xzWorkerSafeWatchAlarm.setProjectSn(xzSecurityQualityInspectionRecord.getProjectSn());
|
||
xzWorkerSafeWatchAlarm.setDayNum(dayNum);
|
||
xzWorkerSafeWatchAlarm.setEnterpriseId(workerInfo.getEnterpriseId());
|
||
alarmList.add(xzWorkerSafeWatchAlarm);
|
||
|
||
List<String> userIds = Arrays.asList(xzWorkerSafeWatchManagerService.list(Wrappers.<XzWorkerSafeWatchManager>lambdaQuery()
|
||
.eq(XzWorkerSafeWatchManager::getWatchConfigId, xzWorkerSafeWatchConfig.getId()))
|
||
.stream().map(l -> l.getUserId()).collect(Collectors.joining(",")).split(","));
|
||
for (String userId : userIds) {
|
||
if (StringUtils.isNotBlank(userId)) {
|
||
Notice notice = new Notice();
|
||
notice.setType("35");
|
||
notice.setMsg(StrUtil.format("事件:【{}】已连续被检查到【{}】{}次,请提醒责任人【{}】及时整改并加强对此风险的管控措施",
|
||
workerInfo.getEnterpriseName(), xzSecurityQualityInspectionRecord.getDangerItemContent(),
|
||
collect.size(), workerInfo.getWorkerName()));
|
||
notice.setTitle("人员安全履职预警提醒");
|
||
notice.setIsRead(0);
|
||
notice.setAccountId(Long.valueOf(userId));
|
||
notice.setSendTime(DateUtil.formatDateTime(new Date()));
|
||
noticeList.add(notice);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
if (personSn.size() > 0) {
|
||
Map<String, Object> requestParam = new HashMap<>(16);
|
||
requestParam.put("personSns", personSn);
|
||
requestParam.put("inserviceType", 1);
|
||
List<WorkerInfo> workerInfoList = workerInfoMapper.selectWorkerInfoList(new Page<>(-1, -1), requestParam);
|
||
for (WorkerInfo workerInfo : workerInfoList) {
|
||
if (workerInfo.getEnterpriseId() == null) {
|
||
continue;
|
||
}
|
||
XzWorkerSafeWatchAlarm xzWorkerSafeWatchAlarm = new XzWorkerSafeWatchAlarm();
|
||
xzWorkerSafeWatchAlarm.setWorkerId(workerInfo.getId());
|
||
xzWorkerSafeWatchAlarm.setWorkerName(workerInfo.getWorkerName());
|
||
String deptName = workerInfo.getDepartmentName() == null ? "" : workerInfo.getDepartmentName();
|
||
String teamName = workerInfo.getTeamName() == null ? "" : workerInfo.getTeamName();
|
||
xzWorkerSafeWatchAlarm.setDeptName(deptName + teamName);
|
||
xzWorkerSafeWatchAlarm.setEnterpriseName(workerInfo.getEnterpriseName());
|
||
xzWorkerSafeWatchAlarm.setAlarmTime(new Date());
|
||
xzWorkerSafeWatchAlarm.setType(type);
|
||
xzWorkerSafeWatchAlarm.setProjectSn(project.getProjectSn());
|
||
xzWorkerSafeWatchAlarm.setDayNum(dayNum);
|
||
xzWorkerSafeWatchAlarm.setEnterpriseId(workerInfo.getEnterpriseId());
|
||
alarmList.add(xzWorkerSafeWatchAlarm);
|
||
|
||
Long id = xzWorkerSafeWatchConfig.getId();
|
||
|
||
List<String> userIds = Arrays.asList(xzWorkerSafeWatchManagerService.list(Wrappers.<XzWorkerSafeWatchManager>lambdaQuery()
|
||
.eq(XzWorkerSafeWatchManager::getWatchConfigId, id))
|
||
.stream().map(l -> l.getUserId()).collect(Collectors.joining(",")).split(","));
|
||
userIds = userIds.stream().filter(s -> StringUtils.isNotBlank(s)).collect(Collectors.toList());
|
||
String msg = StrUtil.format("事件:{},人员名称:{},身份证号:{}",
|
||
typeName[Integer.parseInt(type) - 1] + dayNum + "天未履职", workerInfo.getWorkerName(), workerInfo.getIdCard());
|
||
for (String userId : userIds) {
|
||
Notice notice = new Notice();
|
||
notice.setType("35");
|
||
notice.setMsg(msg);
|
||
notice.setTitle("人员安全履职预警提醒");
|
||
notice.setIsRead(0);
|
||
notice.setAccountId(Long.valueOf(userId));
|
||
notice.setSendTime(DateUtil.formatDateTime(new Date()));
|
||
noticeList.add(notice);
|
||
}
|
||
if (CollUtil.isNotEmpty(userIds)) {
|
||
String frameUserNames = systemUserService.getFrameUserNames(StrUtil.join(",", userIds)) + msg;
|
||
for (SystemUser user : projectLevelUsers) {
|
||
Notice notice = new Notice();
|
||
notice.setType("35");
|
||
notice.setMsg(frameUserNames);
|
||
notice.setTitle("人员安全履职预警提醒");
|
||
notice.setIsRead(0);
|
||
notice.setAccountId(user.getUserId());
|
||
notice.setSendTime(DateUtil.formatDateTime(new Date()));
|
||
noticeList.add(notice);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
xzWorkerSafeWatchAlarmService.saveBatch(alarmList);
|
||
noticeService.saveBatch(noticeList);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
private void workerSafeWatchAlarmForHidden(List<XzWorkerSafeWatchConfig> list, Project project, List<SystemUser> projectLevelUsers) {
|
||
//(定制)安全履职预警增加规则,一、二、三、四级安全隐患预警规则,分级对未整改、未复查、未核验超过多少时间进行循环通知。
|
||
List<XzWorkerSafeWatchAlarm> alarmList = new ArrayList<>();
|
||
List<Notice> noticeList = new ArrayList<>();
|
||
Map<String, XzWorkerSafeWatchConfig> typeToConfigMap = list.stream().collect(Collectors.toMap(XzWorkerSafeWatchConfig::getType, Function.identity()));
|
||
List<XzSecurityQualityInspectionRecord> records = xzSecurityQualityInspectionRecordMapper.getWorkerSafeWatchTimeOutList(project.getProjectSn());
|
||
if (CollUtil.isEmpty(records)) {
|
||
return;
|
||
}
|
||
List<XzSecurityQualityInspectionRecordVo> recordVos = xzSecurityQualityInspectionRecordService.selectQualityInspectionRecordPage(new MapBuilder<String, Object>()
|
||
.put("recordIds", records.stream().map(XzSecurityQualityInspectionRecord::getId).collect(Collectors.toList()))
|
||
.build()).getPage().getRecords();
|
||
Map<Long, HashSet<String>> configIdToNoticeUserIdsMap = xzWorkerSafeWatchManagerService.list().stream().collect(Collectors.toMap(XzWorkerSafeWatchManager::getWatchConfigId, e -> {
|
||
return new HashSet<>(StrUtil.split(e.getUserId(), ","));
|
||
}, (e, e2) -> {
|
||
e.addAll(e2);
|
||
return e;
|
||
}));
|
||
for (XzSecurityQualityInspectionRecordVo record : recordVos) {
|
||
Integer level = record.getLevel();
|
||
Integer status = record.getStatus();
|
||
Integer minute = getMinute(level, status, typeToConfigMap);
|
||
if (minute == null) {
|
||
continue;
|
||
}
|
||
XzWorkerSafeWatchConfig config = getXzWorkerSafeWatchConfig(level, status, typeToConfigMap);
|
||
if (config == null) {
|
||
continue;
|
||
}
|
||
List<Long> alarmUserIds = getAlarmWorkerIds(record);
|
||
Integer safeWatchAlarmExceedMinute = record.getSafeWatchAlarmExceedMinute();
|
||
if (safeWatchAlarmExceedMinute != null && safeWatchAlarmExceedMinute >= minute) {
|
||
Integer mod = NumberUtils.mod(safeWatchAlarmExceedMinute, minute);
|
||
if (mod == 0) {
|
||
HashSet<String> noticeUserIds = configIdToNoticeUserIdsMap.get(config.getId());
|
||
String now = DateUtil.now();
|
||
if (CollUtil.isNotEmpty(noticeUserIds)) {
|
||
String msg = StrUtil.format("有一条{}{}安全隐患预警,设置的预警时间是{}分钟,现在已超时{}分钟", getLevelName(level), getStatusName(status), minute, safeWatchAlarmExceedMinute);
|
||
for (String userId : noticeUserIds) {
|
||
//报警
|
||
Notice notice = new Notice();
|
||
notice.setType("35");
|
||
notice.setMsg(msg);
|
||
notice.setAccountId(Long.valueOf(userId));
|
||
notice.setTitle("安全隐患预警");
|
||
notice.setSendTime(now);
|
||
noticeList.add(notice);
|
||
}
|
||
String frameUserNames = systemUserService.getFrameUserNames(StrUtil.join(",", noticeUserIds)) + msg;
|
||
for (SystemUser user : projectLevelUsers) {
|
||
Notice notice = new Notice();
|
||
notice.setType("35");
|
||
notice.setMsg(frameUserNames);
|
||
notice.setTitle("安全隐患预警");
|
||
notice.setAccountId(user.getUserId());
|
||
notice.setSendTime(now);
|
||
noticeList.add(notice);
|
||
}
|
||
}
|
||
for (Long alarmUserId : alarmUserIds) {
|
||
XzWorkerSafeWatchAlarm alarm = new XzWorkerSafeWatchAlarm();
|
||
alarm.setType(getSafeType(level, status));
|
||
alarm.setDayNum(safeWatchAlarmExceedMinute);
|
||
alarm.setAlarmTime(DateUtil.parse(now));
|
||
alarm.setUserId(alarmUserId);
|
||
alarm.setProjectSn(project.getProjectSn());
|
||
alarmList.add(alarm);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
Set<Long> userIdSet = alarmList.stream().map(XzWorkerSafeWatchAlarm::getUserId).collect(Collectors.toSet());
|
||
if (CollUtil.isNotEmpty(userIdSet)) {
|
||
List<SystemUser> users = systemUserService.list(new LambdaQueryWrapper<SystemUser>().in(SystemUser::getUserId, userIdSet));
|
||
Map<Long, List<SystemUser>> userIdMap = users.stream().collect(Collectors.groupingBy(SystemUser::getUserId));
|
||
Set<Long> workerIds = users.stream().map(SystemUser::getWorkerId).collect(Collectors.toSet());
|
||
List<WorkerInfo> workerInfoList = new ArrayList<>(workerInfoService.list(new LambdaQueryWrapper<WorkerInfo>().in(WorkerInfo::getId, workerIds)));
|
||
Map<Long, WorkerInfo> workerIdMap = workerInfoList.stream().collect(Collectors.toMap(WorkerInfo::getId, workerInfo -> workerInfo));
|
||
for (XzWorkerSafeWatchAlarm alarm : alarmList) {
|
||
List<SystemUser> userList = userIdMap.get(alarm.getUserId());
|
||
if (CollUtil.isNotEmpty(userList)) {
|
||
for (SystemUser su : userList) {
|
||
WorkerInfo workerInfo = workerIdMap.get(su.getWorkerId());
|
||
if (workerInfo != null) {
|
||
alarm.setWorkerId(workerInfo.getId());
|
||
alarm.setWorkerName(workerInfo.getWorkerName());
|
||
alarm.setEnterpriseId(workerInfo.getEnterpriseId());
|
||
alarm.setEnterpriseName(workerInfo.getEnterpriseName());
|
||
alarm.setDeptName(Objects.equals(workerInfo.getPersonType(), 1) ? workerInfo.getTeamName() : workerInfo.getDepartmentName());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (CollUtil.isNotEmpty(alarmList)) {
|
||
xzWorkerSafeWatchAlarmService.saveBatch(alarmList);
|
||
}
|
||
if (CollUtil.isNotEmpty(noticeList)) {
|
||
noticeService.saveBatch(noticeList);
|
||
}
|
||
}
|
||
|
||
private List<Long> getAlarmWorkerIds(XzSecurityQualityInspectionRecordVo record) {
|
||
List<Long> longlist = Lists.newArrayList();
|
||
if (Objects.equals(record.getStatus(), XzSecurityQualityInspectionRecordStatusEnum.NOT_RECTIFIED.getValue())) {
|
||
longlist.add(record.getChangeId());
|
||
} else if (Objects.equals(record.getStatus(), XzSecurityQualityInspectionRecordStatusEnum.NOT_REVIEWED.getValue())) {
|
||
longlist = StrUtil.split(record.getReviewIds(), ",").stream().map(Convert::toLong).collect(Collectors.toList());
|
||
} else {
|
||
longlist = StrUtil.split(record.getVerifyManIds(), ",").stream().map(Convert::toLong).collect(Collectors.toList());
|
||
}
|
||
return longlist;
|
||
}
|
||
|
||
private String getStatusName(Integer status) {
|
||
if (status == null) {
|
||
return "";
|
||
}
|
||
switch (status) {
|
||
case 2:
|
||
return "未整改";
|
||
case 3:
|
||
return "未复查";
|
||
case 4:
|
||
return "未核验";
|
||
default:
|
||
return "";
|
||
}
|
||
}
|
||
|
||
private String getLevelName(Integer level) {
|
||
if (level == null) {
|
||
return "";
|
||
}
|
||
switch (level) {
|
||
case 1:
|
||
return "一级";
|
||
case 2:
|
||
return "二级";
|
||
case 3:
|
||
return "三级";
|
||
case 4:
|
||
return "四级";
|
||
default:
|
||
return "";
|
||
}
|
||
}
|
||
|
||
private Integer getMinute(Integer level, Integer status, Map<String, XzWorkerSafeWatchConfig> typeMap) {
|
||
if (level == null || status == null) {
|
||
return Integer.MAX_VALUE;
|
||
}
|
||
//6一级未整改、7一级未复查、8一级未核验、9二级未整改、10二级未复查、11二级未核验、12三级未整改、13三级未复查、14三级未核验、15四级未整改、16四级未复查、17四级未核验
|
||
//1一级,2二级,3三级,4四级
|
||
//2待整改,3待复查,4待核验,5合格
|
||
XzWorkerSafeWatchConfig config = getXzWorkerSafeWatchConfig(level, status, typeMap);
|
||
if (config == null) {
|
||
return null;
|
||
}
|
||
return config.getDayNum();
|
||
}
|
||
|
||
@Nullable
|
||
private XzWorkerSafeWatchConfig getXzWorkerSafeWatchConfig(Integer level, Integer status, Map<String, XzWorkerSafeWatchConfig> typeMap) {
|
||
XzWorkerSafeWatchConfig config = null;
|
||
config = typeMap.get(getSafeType(level, status));
|
||
return config;
|
||
}
|
||
|
||
private String getSafeType(Integer level, Integer status) {
|
||
if (level == 1 && status == 2) {
|
||
return "6";
|
||
} else if (level == 1 && status == 3) {
|
||
return "7";
|
||
} else if (level == 1 && status == 4) {
|
||
return "8";
|
||
} else if (level == 2 && status == 2) {
|
||
return "9";
|
||
} else if (level == 2 && status == 3) {
|
||
return "10";
|
||
} else if (level == 2 && status == 4) {
|
||
return "11";
|
||
} else if (level == 3 && status == 2) {
|
||
return "12";
|
||
} else if (level == 3 && status == 3) {
|
||
return "13";
|
||
} else if (level == 3 && status == 4) {
|
||
return "14";
|
||
} else if (level == 4 && status == 2) {
|
||
return "15";
|
||
} else if (level == 4 && status == 3) {
|
||
return "16";
|
||
} else if (level == 4 && status == 4) {
|
||
return "17";
|
||
}
|
||
return "";
|
||
}
|
||
|
||
/**
|
||
* 添加通知
|
||
*
|
||
* @param list
|
||
* @param title 标题
|
||
* @param type
|
||
*/
|
||
private void addNotice(Collection<WorkerInfo> list, String title, String type) {
|
||
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) {
|
||
String certificateTypeName = workerInfo.getCertificateTypeName();
|
||
XzCertificateExpireAlarmRecord xzCertificateExpireAlarmRecord = new XzCertificateExpireAlarmRecord();
|
||
xzCertificateExpireAlarmRecord.setPersonTypeName(getPersonTypeName(workerInfo.getPersonType()));
|
||
xzCertificateExpireAlarmRecord.setEnterpriseName(workerInfo.getEnterpriseName());
|
||
xzCertificateExpireAlarmRecord.setTeamDepartmentName(StringUtils.isNotBlank(workerInfo.getDepartmentName()) ? workerInfo.getDepartmentName() : workerInfo.getTeamName());
|
||
xzCertificateExpireAlarmRecord.setWorkerName(workerInfo.getWorkerName());
|
||
xzCertificateExpireAlarmRecord.setCertificateTypeName(certificateTypeName);
|
||
xzCertificateExpireAlarmRecord.setCertificateEndDate(DateUtil.parseDate(workerInfo.getEffectTime()));
|
||
xzCertificateExpireAlarmRecord.setAlarmPromptTime(new Date());
|
||
xzCertificateExpireAlarmRecord.setProjectSn(workerInfo.getProjectSn());
|
||
xzCertificateExpireAlarmRecordService.add(xzCertificateExpireAlarmRecord);
|
||
if (CollUtil.isNotEmpty(systemUserList)) {
|
||
for (SystemUser systemUser : systemUserList) {
|
||
noticeService.addUserNotice(systemUser.getUserId(), title, workerInfo.getWorkerName() + "的" + certificateTypeName + "即将到期,请尽快更新!", type);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private String getPersonTypeName(Integer personType) {
|
||
if (personType == 1) {
|
||
return "劳务人员";
|
||
} else if (personType == 2) {
|
||
return "管理人员";
|
||
} else if (personType == 3) {
|
||
return "临时人员";
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
* 劳务在场零点清空功能
|
||
*/
|
||
@Scheduled(cron = "0 10 0 * * ?")
|
||
@SchedulerLock(name = "updateWorkerAttendanceZero", lockAtMostFor = 1000 * 60 * 30, lockAtLeastFor = 1000 * 60 * 3)
|
||
@RequestMapping("updateWorkerAttendanceZero")
|
||
public void updateWorkerAttendanceZero() {
|
||
List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>()
|
||
.eq(Project::getEnableWorkerAttendanceZero, 1));
|
||
for (Project project : projects) {
|
||
String projectSn = project.getProjectSn();
|
||
workerAttendancePresenceService.addNowAllWorkerAttendancePresence(projectSn);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 劳务安徽合武项目拉取考勤数据
|
||
*/
|
||
@Scheduled(cron = "0 0/1 * * * ?")
|
||
@SchedulerLock(name = "getWorkerAttendByHw", lockAtMostFor = 1000 * 55, lockAtLeastFor = 1000 * 55)
|
||
@RequestMapping("getWorkerAttendByHw")
|
||
public void getWorkerAttendByHw() {
|
||
List<WorkerInfo> workerInfoList = workerInfoMapper.selectList(Wrappers.<WorkerInfo>lambdaQuery().eq(WorkerInfo::getProjectSn, "51E111F3FDFB41D0AB67F812F1B80794"));
|
||
JSONObject pJo = new JSONObject();
|
||
pJo.put("tenantId", "1833147242533949441");
|
||
pJo.put("orgId", "1833149331474493441");
|
||
pJo.put("current", 1);
|
||
pJo.put("size", 1000);
|
||
pJo.put("startTime", System.currentTimeMillis() - 60000);
|
||
pJo.put("endTime", System.currentTimeMillis());
|
||
String result = HttpRequest.post("http://api.1357.cn/hz-labour/api/open/labour/findCardRecordByPage")
|
||
.header("appId", "6789018810540796316")
|
||
.header("appSecret", "91291360e88431ded65ba63687c16b516c23ca12")
|
||
.body(pJo.toJSONString())
|
||
.timeout(3000)
|
||
.execute().body();
|
||
if (result != null) {
|
||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||
if (jsonObject.getInteger("statusCode") == 200) {
|
||
JSONArray records = jsonObject.getJSONObject("data").getJSONArray("records");
|
||
for (int i = 0; i < records.size(); i++) {
|
||
JSONObject obj = records.getJSONObject(i);
|
||
String idCardNo = obj.getString("idCardNo");
|
||
List<WorkerInfo> collect = workerInfoList.stream().filter(w -> w.getIdCard().equals(idCardNo)).collect(Collectors.toList());
|
||
if (collect.size() > 0) {
|
||
AsyncTaskUtil.runAsync(() -> {
|
||
doAddWorkerAttend(obj, collect.get(0));
|
||
});
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void doAddWorkerAttend(JSONObject obj, WorkerInfo workerInfo) {
|
||
Map<String, Object> map = new HashMap<>();
|
||
String imagePath = obj.getString("imagePath");
|
||
String deviceNo = obj.getString("deviceNo");
|
||
String fileToBase64 = "data:image/jpeg;base64," + Base64Util.getFileToBase64(imagePath);
|
||
FileInfo fileInfo = uploadFileService.uploadFileBase64Image(fileToBase64);
|
||
String url = fileInfo.getUrl();
|
||
map.put("idCard", workerInfo.getIdCard());
|
||
map.put("projectCode", workerInfo.getProjectSn());
|
||
map.put("passTime", DateUtil.formatDateTime(new Date(obj.getLong("createTime"))));
|
||
map.put("direction", obj.getIntValue("inOrOut"));
|
||
map.put("passType", 2);
|
||
map.put("devCode", StringUtils.isNotBlank(deviceNo) ? deviceNo : "HW0225001");
|
||
map.put("faceUrl", url);
|
||
workerAttendanceService.saveExternalPassRecord(map);
|
||
}
|
||
|
||
// /**
|
||
// * MQTT同步下发人员信息
|
||
// */
|
||
// @Scheduled(cron = "0 0/15 * * * ?")
|
||
// @SchedulerLock(name = "mqttIssuedWorkerInfo", lockAtMostFor = 1000 * 55, lockAtLeastFor = 1000 * 55)
|
||
// @RequestMapping("mqttIssuedWorkerInfo")
|
||
// public void mqttIssuedWorkerInfo() {
|
||
// List<ProjectUfaceConfig> configList = projectUfaceConfigMapper.selectList(Wrappers.<ProjectUfaceConfig>lambdaQuery()
|
||
// .eq(ProjectUfaceConfig::getSupplierType, MQTT.getCode())
|
||
// .eq(ProjectUfaceConfig::getIssueDev, 1));
|
||
// for (ProjectUfaceConfig projectUfaceConfig : configList) {
|
||
// List<XzHikvisionSync> list = xzHikvisionSyncService.list(Wrappers.<XzHikvisionSync>lambdaQuery()
|
||
// .eq(XzHikvisionSync::getProjectSn, projectUfaceConfig.getProjectSn())
|
||
// .eq(XzHikvisionSync::getIsSuccess, 0)
|
||
// .eq(XzHikvisionSync::getType, 1)
|
||
// .eq(XzHikvisionSync::getBigType, 1));
|
||
// for (XzHikvisionSync sync : list) {
|
||
// WorkerInfo workerInfo = workerInfoMapper.selectById(sync.getWhoId());
|
||
// MqttFaceDevUtil.addOrUpdatePerson(workerInfo, sync.getDeviceSn());
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
/**
|
||
* 弹弓下发状态,把超过一个小时没有接受到异常状态的人员的图片,标志成正常状态
|
||
*/
|
||
@Scheduled(cron = "0 0/10 * * * ?")
|
||
@SchedulerLock(name = "updateDangongWorkerStatus", lockAtMostFor = 1000 * 55, lockAtLeastFor = 1000 * 55)
|
||
@RequestMapping("updateDangongWorkerStatus")
|
||
public void updateDangongWorkerStatus() {
|
||
List<ProjectUfaceConfig> configs = projectUfaceConfigService.list(new LambdaQueryWrapper<ProjectUfaceConfig>()
|
||
.eq(ProjectUfaceConfig::getSupplierType, 8));
|
||
if (CollUtil.isNotEmpty(configs)) {
|
||
List<String> sns = configs.stream().map(ProjectUfaceConfig::getProjectSn).collect(Collectors.toList());
|
||
// List<UfaceDev> ufaceDevs = ufaceDevService.list(new LambdaQueryWrapper<UfaceDev>()
|
||
// .in(UfaceDev::getProjectSn, sns));
|
||
// List<String> devSns = ufaceDevs.stream().map(UfaceDev::getDevSn).collect(Collectors.toList());
|
||
List<WorkerInfo> workerInfos = workerInfoService.list(new LambdaQueryWrapper<WorkerInfo>().in(WorkerInfo::getProjectSn, sns)
|
||
.or(eq -> eq.isNull(WorkerInfo::getSendSuccessStatus).or().ne(WorkerInfo::getSendSuccessStatus, 1)));
|
||
List<Long> workerIds = workerInfos.stream().map(WorkerInfo::getId).collect(Collectors.toList());
|
||
if (CollUtil.isEmpty(workerIds)) {
|
||
return;
|
||
}
|
||
dangongWorkerFaceStatusService.updateStatus(workerIds);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 中水北方区域人员滞留超过一天进行记录
|
||
*/
|
||
@Scheduled(cron = "0 0/2 * * * ?")
|
||
@SchedulerLock(name = "regionViolation", lockAtMostFor = 1000 * 55, lockAtLeastFor = 1000 * 55)
|
||
@RequestMapping("regionViolation")
|
||
public void regionViolation() {
|
||
List<RegionViolation> list = new ArrayList<>();
|
||
List<RegionViolation> violations = regionViolationService.list(Wrappers.<RegionViolation>lambdaQuery().isNull(RegionViolation::getOutTime));
|
||
List<Long> exist = violations.stream().map(v -> v.getWorkerId()).collect(Collectors.toList());
|
||
List<QualityRegion> regionList = qualityRegionService.list(Wrappers.<QualityRegion>lambdaQuery().eq(QualityRegion::getProjectSn, "554F52F52835441386247F5061D4F9DD"));
|
||
for (QualityRegion qualityRegion : regionList) {
|
||
Map<String, Object> map = new HashMap();
|
||
map.put("projectSn", "554F52F52835441386247F5061D4F9DD");
|
||
map.put("pageNo", 1);
|
||
map.put("pageSize", 1000);
|
||
map.put("presence", 1);
|
||
map.put("regionIdForUface", qualityRegion.getId());
|
||
List<WorkerInfo> workerInfoIList = workerInfoService.selectWorkerInfoList(map).getRecords();
|
||
for (WorkerInfo workerInfo : workerInfoIList) {
|
||
if (StringUtils.isNotBlank(workerInfo.getAlarmFlag())) {
|
||
if (!exist.contains(workerInfo.getId())) {
|
||
RegionViolation regionViolation = new RegionViolation();
|
||
regionViolation.setWorkerType(workerInfo.getPersonType());
|
||
regionViolation.setWorkerId(workerInfo.getId());
|
||
regionViolation.setEnterpriseName(workerInfo.getEnterpriseName());
|
||
String teamName = StringUtils.isNotEmpty(workerInfo.getTeamName()) ? workerInfo.getTeamName() : "";
|
||
String departmentName = StringUtils.isNotEmpty(workerInfo.getDepartmentName()) ? workerInfo.getDepartmentName() : "";
|
||
regionViolation.setTeamName(teamName + departmentName);
|
||
regionViolation.setWorkerName(workerInfo.getWorkerName());
|
||
regionViolation.setEnterTime(workerInfo.getAttendTime());
|
||
regionViolation.setProjectSn(workerInfo.getProjectSn());
|
||
regionViolation.setRegionId(qualityRegion.getId());
|
||
list.add(regionViolation);
|
||
}
|
||
}
|
||
}
|
||
List<Long> regionExist = violations.stream().filter(v -> v.getRegionId().toString().equals(qualityRegion.getId().toString()))
|
||
.map(v -> v.getWorkerId()).collect(Collectors.toList());
|
||
for (Long workerId : regionExist) {
|
||
if (!workerInfoIList.contains(workerId)) {
|
||
WorkerInfo workerInfo = workerInfoService.getById(workerId);
|
||
WorkerAttendance enter = workerAttendanceService.getOne(Wrappers.<WorkerAttendance>lambdaQuery()
|
||
.eq(WorkerAttendance::getPersonSn, workerInfo.getPersonSn())
|
||
.eq(WorkerAttendance::getPassType, 1)
|
||
.orderByDesc(WorkerAttendance::getCreateTime).last(" limit 1"));
|
||
WorkerAttendance out = workerAttendanceService.getOne(Wrappers.<WorkerAttendance>lambdaQuery()
|
||
.eq(WorkerAttendance::getPersonSn, workerInfo.getPersonSn())
|
||
.eq(WorkerAttendance::getPassType, 2)
|
||
.orderByDesc(WorkerAttendance::getCreateTime).last(" limit 1"));
|
||
if (out != null) {
|
||
UfaceDev one = ufaceDevService.getOne(Wrappers.<UfaceDev>lambdaQuery().eq(UfaceDev::getDevSn, out.getDevSn()));
|
||
LambdaUpdateWrapper<RegionViolation> wrapper = Wrappers.<RegionViolation>lambdaUpdate();
|
||
wrapper.eq(RegionViolation::getWorkerId, workerInfo.getId());
|
||
wrapper.isNull(RegionViolation::getOutTime);
|
||
wrapper.set(RegionViolation::getOutTime, out.getCreateTime());
|
||
wrapper.set(RegionViolation::getAddress, one.getDevName());
|
||
wrapper.set(RegionViolation::getDuration, DateUtil.formatBetween(DateUtil.parseDateTime(enter.getCreateTime()),
|
||
DateUtil.parseDateTime(out.getCreateTime()), BetweenFormatter.Level.SECOND));
|
||
regionViolationService.update(wrapper);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
regionViolationService.saveBatch(list);
|
||
}
|
||
|
||
/**
|
||
* 正赢 MQTT同步下发人员信息
|
||
*/
|
||
// @Scheduled(cron = "0 0/15 * * * ?")
|
||
// @SchedulerLock(name = "zyMqttIssuedWorkerInfo", lockAtMostFor = 1000 * 55, lockAtLeastFor = 1000 * 55)
|
||
// @RequestMapping("zyMqttIssuedWorkerInfo")
|
||
// public void zyMqttIssuedWorkerInfo() {
|
||
// List<ProjectUfaceConfig> configList = projectUfaceConfigMapper.selectList(Wrappers.<ProjectUfaceConfig>lambdaQuery()
|
||
// .eq(ProjectUfaceConfig::getSupplierType, ZYMQTT.getCode())
|
||
// .eq(ProjectUfaceConfig::getIssueDev, 1));
|
||
// for (ProjectUfaceConfig projectUfaceConfig : configList) {
|
||
// List<XzHikvisionSync> list = xzHikvisionSyncService.list(Wrappers.<XzHikvisionSync>lambdaQuery()
|
||
// .eq(XzHikvisionSync::getProjectSn, projectUfaceConfig.getProjectSn())
|
||
// .eq(XzHikvisionSync::getIsSuccess, 0)
|
||
// .eq(XzHikvisionSync::getType, 1)
|
||
// .eq(XzHikvisionSync::getBigType, 1));
|
||
// for (XzHikvisionSync sync : list) {
|
||
// WorkerInfo workerInfo = workerInfoMapper.selectById(sync.getWhoId());
|
||
// workerInfo.setFieldAcquisitionUrl(basePath + "/" + workerInfo.getFieldAcquisitionUrl());
|
||
// ZyMqttFaceDevUtil.addOrUpdatePerson(workerInfo, sync.getDeviceSn());
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
/**
|
||
* 更新人员自动退场
|
||
*/
|
||
@Scheduled(cron = "0 0 1 * * ?")
|
||
@SchedulerLock(name = "updateWorkerExit", lockAtMostFor = 1000 * 55, lockAtLeastFor = 1000 * 55)
|
||
@RequestMapping("updateWorkerExit")
|
||
public void updateWorkerExit() {
|
||
try {
|
||
Map<String, WorkerExitConfig> project2ConfigMap = workerExitConfigService.list(new LambdaQueryWrapper<WorkerExitConfig>()
|
||
.eq(WorkerExitConfig::getEnable, 1)).stream().collect(Collectors.toMap(WorkerExitConfig::getProjectSn, Function.identity(), (o1, o2) -> o1));
|
||
List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>());
|
||
for (Project project : projects) {
|
||
String projectSn = project.getProjectSn();
|
||
WorkerExitConfig config = project2ConfigMap.get(projectSn);
|
||
if (config != null) {
|
||
//退场人员列表
|
||
HashMap<String, Object> param = new MapBuilder<String, Object>()
|
||
.put("projectSn", projectSn)
|
||
.put("exitIfAbsenceDay", config.getExitIfAbsenceDay())
|
||
.build();
|
||
param.put("workerIdList", StrUtil.split(config.getWorkerIds(), ","));
|
||
param.put("departmentIdList", StrUtil.split(config.getDepartmentIds(), ","));
|
||
param.put("teamIdList", StrUtil.split(config.getTeamIds(), ","));
|
||
param.put("enterpriseIdList", StrUtil.split(config.getEnterpriseIds(), ","));
|
||
// if (StrUtil.isNotBlank(config.getWorkerIds())) {
|
||
// } else if (StrUtil.isNotBlank(config.getDepartmentIds()) || StrUtil.isNotBlank(config.getTeamIds())) {
|
||
// } else if (StrUtil.isNotBlank(config.getEnterpriseIds())) {
|
||
// }
|
||
List<WorkerInfo> exitWorkers = workerAttendanceService.getAutoExitWorkers(param);
|
||
if (CollUtil.isEmpty(exitWorkers)) {
|
||
continue;
|
||
}
|
||
try {
|
||
if (Objects.equals(config.getExitType(), 3)) {
|
||
for (WorkerInfo worker : exitWorkers) {
|
||
WorkerBlacklist workerBlacklist = new WorkerBlacklist();
|
||
workerBlacklist.setProjectSn(projectSn);
|
||
workerBlacklist.setWorkerId(worker.getId());
|
||
workerBlacklist.setWorkerName(worker.getWorkerName());
|
||
workerBlacklist.setIdCard(worker.getIdCard());
|
||
workerBlacklist.setAddReason("超过" + config.getExitIfAbsenceDay() + "天自动退场");
|
||
workerBlacklist.setReason(workerBlacklist.getAddReason());
|
||
workerBlacklist.setAddTime(DateUtil.now());
|
||
workerBlacklist.setCreateTime(new Date());
|
||
workerBlacklist.setIsExit(config.getEnableExitWhenBlack());
|
||
workerBlacklistService.addWorkerBlacklist(workerBlacklist);
|
||
}
|
||
} else if (Objects.equals(config.getExitType(), 2)) {
|
||
workerInfoService.updateWorkerExit(new MapBuilder<String, Object>()
|
||
.put("workerIdStr", exitWorkers.stream().map(w -> w.getId() + "").collect(Collectors.joining(",")))
|
||
.build());
|
||
} else if (Objects.equals(config.getExitType(), 1)) {
|
||
for (WorkerInfo worker : exitWorkers) {
|
||
worker.setUfaceDevId("");
|
||
worker.setUfaceDevGroupId("");
|
||
workerInfoService.editWorkerInfo(worker);
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
log.error("更新人员自动退场错误", e);
|
||
}
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
log.error("更新人员自动退场错误", e);
|
||
}
|
||
}
|
||
}
|