499 lines
30 KiB
Java
499 lines
30 KiB
Java
package com.zhgd.xmgl.task;
|
||
|
||
import cn.hutool.core.collection.CollUtil;
|
||
import cn.hutool.core.date.DateTime;
|
||
import cn.hutool.core.date.DateUtil;
|
||
import cn.hutool.core.util.StrUtil;
|
||
import com.alibaba.fastjson.JSON;
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||
import com.zhgd.jeecg.common.mybatis.EntityMap;
|
||
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.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.mapper.ProjectExternalSystemServiceMapper;
|
||
import com.zhgd.xmgl.modules.project.mapper.ProjectMapper;
|
||
import com.zhgd.xmgl.modules.project.service.IProjectUfaceConfigService;
|
||
import com.zhgd.xmgl.modules.quality.entity.QualityInspectionRecord;
|
||
import com.zhgd.xmgl.modules.worker.entity.WorkerAttendance;
|
||
import com.zhgd.xmgl.modules.worker.entity.WorkerBlacklist;
|
||
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
||
import com.zhgd.xmgl.modules.worker.entity.WorkerMonthAttendanceStatistics;
|
||
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.IWorkerAttendancePresenceService;
|
||
import com.zhgd.xmgl.modules.worker.service.IWorkerAttendanceService;
|
||
import com.zhgd.xmgl.modules.worker.service.IWorkerCertificateService;
|
||
import com.zhgd.xmgl.modules.worker.service.IWorkerMonthAttendanceStatisticsService;
|
||
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.mapper.XzSecurityInspectTaskItemRecordMapper;
|
||
import com.zhgd.xmgl.modules.xz.security.mapper.XzSecurityInspectTaskRecordMapper;
|
||
import com.zhgd.xmgl.modules.xz.security.service.IXzSecurityQualityInspectionRecordService;
|
||
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.ElecardUtil;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import net.javacrumbs.shedlock.core.SchedulerLock;
|
||
import org.apache.commons.collections.MapUtils;
|
||
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.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RestController;
|
||
|
||
import java.util.*;
|
||
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
|
||
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 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;
|
||
|
||
/**
|
||
* 定时修改用户码状态
|
||
*/
|
||
@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.sendProjectNoicte(projectExternalSystemService.getProjectSn(), "红黄码核验", title.toString(), "17");
|
||
noticeService.sendProjectNoicte(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));
|
||
int day = DateUtil.dayOfMonth(new Date());
|
||
for (Project project : projects) {
|
||
if (project.getEnableWorkerSafeWatch() != null && project.getEnableWorkerSafeWatch() == 1) {
|
||
if (StringUtils.isNotBlank(project.getWorkerSafeWatchTime()) &&
|
||
DateUtil.format(new Date(), "HH:mm").equals(
|
||
DateUtil.format(DateUtil.parseTime(project.getWorkerSafeWatchTime()), "HH:mm"))) {
|
||
List<XzWorkerSafeWatchConfig> list = xzWorkerSafeWatchConfigService.list(Wrappers.<XzWorkerSafeWatchConfig>lambdaQuery()
|
||
.eq(XzWorkerSafeWatchConfig::getProjectSn, project.getProjectSn()));
|
||
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 (type.equals("1")) {
|
||
DateTime dateTime = DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -3));
|
||
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 (type.equals("2")) {
|
||
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());
|
||
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 (type.equals("3")) {
|
||
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 (value.equals("0")) {
|
||
number ++ ;
|
||
}
|
||
if (number > dayNum) {
|
||
personSn.add(workerMonthAttendanceStatistics.getPersonSn());
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (type.equals("4")) {
|
||
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 (value.equals("2")) {
|
||
number ++ ;
|
||
}
|
||
if (number > dayNum) {
|
||
personSn.add(workerMonthAttendanceStatistics.getPersonSn());
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (personSn.size() > 0) {
|
||
Map<String, Object> requestParam = new HashMap<>();
|
||
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(","));
|
||
for (String userId : userIds) {
|
||
if (StringUtils.isNotBlank(userId)) {
|
||
Notice notice = new Notice();
|
||
notice.setType("35");
|
||
notice.setMsg(StrUtil.format("事件:{},人员名称:{},身份证号:{}",
|
||
typeName[Integer.parseInt(type) - 1] + dayNum + "天未履职", workerInfo.getWorkerName(), workerInfo.getIdCard()));
|
||
notice.setTitle("人员安全履职预警提醒");
|
||
notice.setIsRead(0);
|
||
notice.setAccountId(Long.valueOf(userId));
|
||
notice.setSendTime(DateUtil.formatDateTime(new Date()));
|
||
noticeList.add(notice);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
xzWorkerSafeWatchAlarmService.saveBatch(alarmList);
|
||
noticeService.saveBatch(noticeList);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
/**
|
||
* 添加通知
|
||
*
|
||
* @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(), workerInfo.getWorkerName() + "的" + certificateTypeName + "即将到期,请尽快更新!", title, 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);
|
||
}
|
||
}
|
||
|
||
}
|