安全履职报警

This commit is contained in:
guoshengxiong 2024-06-06 14:59:53 +08:00
parent 7f8a821e1e
commit 4a8a00cfdc
10 changed files with 251 additions and 45 deletions

View File

@ -30,7 +30,8 @@
or (TIMESTAMPDIFF(HOUR, a.nad_time, now()) >= 168 and a.worker_classify = 1)) then '核酸已超时'
else '核酸未超时' end) as acid_status_name,
wt.type_name,
if(wap.id is not null,1,2) presence
if(wap.id is not null,1,2) presence,
su.user_id as noticeUserId
from worker_info a
LEFT JOIN team_info b ON a.team_id = b.id
LEFT JOIN department_info c ON a.department_id = c.id
@ -39,6 +40,7 @@
LEFT JOIN dictionaries_record e ON a.job_name = e.id
LEFT JOIN enterprise_info en ON en.id = a.enterprise_id
LEFT JOIN worker_attendance_presence wap ON wap.person_sn = a.person_sn
left join system_user su on su.worker_id = a.id
<if test="param.attendance == '1'.toString()">
join (select * from worker_attendance where
1=1
@ -48,6 +50,12 @@
and create_time>=current_date group by person_sn ) wa on wa.person_sn = a.person_sn
</if>
WHERE 1 = 1
<if test="param.userIdList != null and param.userIdList.size() != 0">
and su.user_id in
<foreach collection="param.userIdList" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="param.id != null and param.id != ''">
and a.id = #{param.id}
</if>

View File

@ -185,7 +185,7 @@ public class WorkerInfoServiceImpl extends ServiceImpl<WorkerInfoMapper, WorkerI
private EnterpriseInfoServiceImpl enterpriseInfoService;
/**
* 人员管理分页
* 人员管理分页
*
* @param map
* @return

View File

@ -123,7 +123,6 @@ public class XzSecurityQualityInspectionRecord implements Serializable {
*/
@Excel(name = "整改人", width = 15)
@ApiModelProperty(value = "整改人")
private Long changeId;
/**
* 整改时限
@ -136,21 +135,18 @@ public class XzSecurityQualityInspectionRecord implements Serializable {
*/
@Excel(name = "复查人", width = 15)
@ApiModelProperty(value = "复查人")
private Long reviewId;
/**
* 核验人
*/
@Excel(name = "核验人", width = 15)
@ApiModelProperty(value = "核验人")
private Long verifyManId;
/**
* 检查人id
*/
@Excel(name = "检查人id", width = 15)
@ApiModelProperty(value = "检查人id")
private Long inspectManId;
/**
* 检查时间
@ -262,5 +258,9 @@ public class XzSecurityQualityInspectionRecord implements Serializable {
@ApiModelProperty(value = "分项工程名称")
private String subentryName;
@TableField(exist = false)
@ApiModelProperty(value = "安全履职预警超时时间(分钟)")
private Integer safeWatchAlarmExceedMinute;
}

View File

@ -77,4 +77,11 @@ public interface XzSecurityQualityInspectionRecordMapper extends BaseMapper<XzSe
List<SectorOneVo> statsDangerType(@Param("param") Map<String, Object> paramMap);
/**
* 获取超时的整改记录
*
* @param projectSn
* @return
*/
List<XzSecurityQualityInspectionRecord> getWorkerSafeWatchTimeOutList(@Param("projectSn") String projectSn);
}

View File

@ -53,9 +53,6 @@
<if test="param.level != null and param.level != ''">
and t.level = #{param.level}
</if>
<if test="param.status != null and param.status != ''">
and t.status = #{param.status}
</if>
<if test="param.urgentLevel != null and param.urgentLevel != ''">
and t.urgent_level = #{param.urgentLevel}
</if>
@ -111,7 +108,7 @@
and t.status = #{param.status}
</if>
<if test="param.status == '7'.toString()">
and t.change_limit_time <![CDATA[<]]> current_date and t.status != 5
and t.change_limit_time <![CDATA[<]]> current_date and t.status != 5 and t.status != 6
</if>
<if test="param.search != null and param.search != ''">
and ( t.region_name like concat('%',
@ -279,7 +276,7 @@
and (t.status = 2 AND now() > t.change_limit_time)
</if>
<if test="param.isNotQualified == '1'.toString()">
and t.status != 5
and t.status != 5 and t.status !=6
</if>
<if test="param.enumType != null and param.enumType != ''">
and t.level = #{param.enumType}
@ -322,7 +319,7 @@
</if>
<if test="param.status == '7'.toString()">
and t.change_limit_time <![CDATA[<]]> current_date
and t.status != 5
and t.status != 5 and t.status != 6
</if>
<if test="param.urgentLevel != null and param.urgentLevel != ''">
and t.urgent_level = #{param.urgentLevel}
@ -694,4 +691,21 @@
)t2 on t1.year = t2.year and t1.month + 1 = t2.month or (t1.year + 1 = t2.year and t1.month = 12 and t2.month =
1)
</select>
<select id="getWorkerSafeWatchTimeOutList"
resultType="com.zhgd.xmgl.modules.xz.security.entity.XzSecurityQualityInspectionRecord">
SELECT r.*,
timestampdiff(MINUTE, ifnull(x.rectify_time, r.inspect_time), now()) as safeWatchAlarmExceedMinute
FROM xz_security_quality_inspection_record as r
left join (
select x.quality_id,
max(x.rectify_time) as rectify_time
from xz_security_quality_inspection_record as r
join xz_security_quality_rectify_record x on x.quality_id = r.id
group by x.quality_id
) as x on x.quality_id = r.id
WHERE now() > ifnull(x.rectify_time, r.inspect_time)
and r.project_sn = #{projectSn}
and r.status in (2,3,4)
</select>
</mapper>

View File

@ -77,7 +77,7 @@ public class XzWorkerSafeWatchAlarmController {
Page<XzWorkerSafeWatchAlarm> page = PageUtil.getPage(map);
queryWrapper.lambda().orderByDesc(XzWorkerSafeWatchAlarm::getAlarmTime);
IPage<XzWorkerSafeWatchAlarm> pageList = xzWorkerSafeWatchAlarmService.page(page, queryWrapper);
String [] typeName = {"人员日常考勤", "每个项目自检任务", "一个月内缺勤超过", "一个月内迟到超过", "同一企业同一隐患连续检查到(x)次"};
String[] typeName = {"人员日常考勤", "每个项目自检任务", "一个月内缺勤超过", "一个月内迟到超过", "同一企业同一隐患连续检查到(x)次", "一级安全隐患未整改超过(x)分钟", "一级安全隐患未复查超过(x)分钟", "一级安全隐患未核验超过(x)分钟", "二级安全隐患未整改超过(x)分钟", "二级安全隐患未复查超过(x)分钟", "二级安全隐患未核验超过(x)分钟", "三级安全隐患未整改超过(x)分钟", "三级安全隐患未复查超过(x)分钟", "三级安全隐患未核验超过(x)分钟", "四级安全隐患未整改超过(x)分钟", "四级安全隐患未复查超过(x)分钟", "四级安全隐患未核验超过(x)分钟"};
for (XzWorkerSafeWatchAlarm record : pageList.getRecords()) {
record.setType(typeName[Integer.parseInt(record.getType()) - 1]);
}

View File

@ -4,6 +4,7 @@ import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@ -85,4 +86,8 @@ public class XzWorkerSafeWatchAlarm implements Serializable {
*/
@ApiModelProperty(value = "项目sn")
private String projectSn;
@TableField(exist = false)
@ApiModelProperty(value = "用户ID")
private Long userId;
}

View File

@ -32,16 +32,16 @@ public class XzWorkerSafeWatchConfig implements Serializable {
@ApiModelProperty(value = "安全履职配置id")
private Long id;
/**
* 安全履职规则类型
* 安全履职规则类型6一级未整改7级未复查8一级未核验9二级未整改10二级未复查11二级未核验12三级未整改13三级未复查14三级未核验15四级未整改16四级未复查17四级未核验
*/
@Excel(name = "安全履职规则类型", width = 15)
@ApiModelProperty(value = "安全履职规则类型")
private String type;
/**
* 连续未履职(天数)
* 连续未履职(天数)(或时间或次数
*/
@Excel(name = "连续未履职(天数)", width = 15)
@ApiModelProperty(value = "连续未履职(天数)")
@Excel(name = "连续未履职(天数)(或时间或次数)", width = 15)
@ApiModelProperty(value = "连续未履职(天数)(或时间或次数)")
private Integer dayNum;
/**
* 项目sn

View File

@ -7,6 +7,7 @@ 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.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhgd.xmgl.modules.basicdata.entity.Notice;
@ -32,6 +33,7 @@ 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.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;
@ -48,9 +50,12 @@ 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 com.zhgd.xmgl.util.MapBuilder;
import com.zhgd.xmgl.util.NumberUtils;
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.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@ -58,6 +63,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@ -71,6 +77,8 @@ import java.util.stream.Collectors;
@RestController
@RequestMapping("xmgl/task")
public class WorkerTask {
@Autowired
WorkerInfoServiceImpl workerInfoService;
@Autowired
private ProjectExternalSystemServiceMapper projectExternalSystemServiceMapper;
@Autowired
@ -81,10 +89,8 @@ public class WorkerTask {
private SystemUserMapper systemUserMapper;
@Autowired
private SystemLogoConfigMapper systemLogoConfigMapper;
@Autowired
private IWorkerAttendancePresenceService workerAttendancePresenceService;
@Autowired
private INoticeService noticeService;
@Autowired
@ -95,28 +101,20 @@ public class WorkerTask {
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
@ -294,11 +292,15 @@ public class WorkerTask {
int day = DateUtil.dayOfMonth(new Date());
for (Project project : projects) {
if (project.getEnableWorkerSafeWatch() != null && project.getEnableWorkerSafeWatch() == 1) {
List<XzWorkerSafeWatchConfig> list = xzWorkerSafeWatchConfigService.list(Wrappers.<XzWorkerSafeWatchConfig>lambdaQuery()
.eq(XzWorkerSafeWatchConfig::getProjectSn, project.getProjectSn()));
workerSafeWatchAlarmForHidden(list, project);
if (true) {
continue;
}
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) {
@ -494,6 +496,180 @@ public class WorkerTask {
}
private void workerSafeWatchAlarmForHidden(List<XzWorkerSafeWatchConfig> list, Project project) {
//定制安全履职预警增加规则四级安全隐患预警规则分级对未整改未复查未核验超过多少时间进行循环通知
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;
}
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 (XzSecurityQualityInspectionRecord record : records) {
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;
}
Long alarmUserId = getAlarmWorkerId(record);
Integer safeWatchAlarmExceedMinute = record.getSafeWatchAlarmExceedMinute();
if (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)) {
for (String userId : noticeUserIds) {
//报警
Notice notice = new Notice();
notice.setType("35");
notice.setMsg(StrUtil.format("有一条{}{}安全隐患预警,设置的预警时间是{}分钟,现在已超时{}分钟", getLevelName(level), getStatusName(status), minute, safeWatchAlarmExceedMinute));
notice.setAccountId(Long.valueOf(userId));
notice.setTitle("安全隐患预警");
notice.setSendTime(now);
noticeList.add(notice);
}
}
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)) {
IPage<WorkerInfo> workerInfoList = workerInfoService.selectWorkerInfoList(new MapBuilder<String, Object>().put("userIdList", userIdSet).build());
List<WorkerInfo> workerInfoListRecords = workerInfoList.getRecords();
Map<Long, WorkerInfo> userIdMap = workerInfoListRecords.stream().collect(Collectors.toMap(WorkerInfo::getNoticeUserId, Function.identity(), (workerInfo, workerInfo2) -> workerInfo));
for (XzWorkerSafeWatchAlarm alarm : alarmList) {
WorkerInfo workerInfo = userIdMap.get(alarm.getUserId());
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 Long getAlarmWorkerId(XzSecurityQualityInspectionRecord record) {
if (record.getStatus() == 2) {
return record.getChangeId();
} else if (record.getStatus() == 3) {
return record.getReviewId();
} else {
return record.getVerifyManId();
}
}
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 "";
}
/**
* 添加通知
*
@ -558,20 +734,4 @@ public class WorkerTask {
}
}
/**
* 定制安全履职预警增加规则四级安全隐患预警规则分级对未整改未复查未核验超过多少时间进行循环通知
*/
@Scheduled(cron = "0 0/1 * * * ?")
@RequestMapping("/workerSafeWatchAlarmForHidden")
public void workerSafeWatchAlarmForHidden() {
//List<XzWorkerSafeWatchConfig> list = xzWorkerSafeWatchConfigService.list(Wrappers.<XzWorkerSafeWatchConfig>lambdaQuery()
// .eq(XzWorkerSafeWatchConfig::getProjectSn, project.getProjectSn()));
// xzSecurityQualityInspectionRecordMapper.getWorkerSafeWatchAlarmList();
//有一条四级未整改安全隐患预警设置超时的时间是4分钟
//SELECT * FROM xz_security_quality_inspection_record WHERE inspect_time = '2024-05-16 22:21:42';
//
//select timestampdiff(MINUTE,'2024-05-16 22:21:42','2024-05-16 22:57:45') % 5;
}
}

View File

@ -92,6 +92,18 @@ public class NumberUtils {
return b1 != null && b2 != null && b1.equals(b2);
}
/**
* 取余
*
* @return
*/
public static Integer mod(Integer b1, Integer b2) {
if (b1 == null || b2 == null) {
return null;
}
return b1 % b2;
}
/**
* description: 使用 String.format 格式化数字实现左侧补 0
*