Commit a117e471 by wuchao

回访计划

parent af871952
package com.scpyun.platform.jilinsscgsdp.service.impl;
import com.scpyun.base.core.annotation.Api;
import com.scpyun.base.core.annotation.ApiOperation;
import com.scpyun.base.db.service.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.scheduling.annotation.Scheduled;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Author liu
* @Date 2025/9/26 15:38
* @PackageName:com.scpyun.platform.jilinsscgsdp.service.impl
* @ClassName: KeyPersonVisitServiceImpl
* @Description: TODO
* @Version 1.0
*/
//@Api("重度人员回访计划定时任务")
//@Service("keyPersonVisitRecordScheduledTask")
@Component
@Slf4j
public class KeyPersonVisitRecordScheduledTaskServiceImpl {
@Autowired
CommonService commonService;
private final String SUCCESS = "success";
private String namespace = "com.scpyun.platform.standard.jilinsscgsdp.keyPersonVisitRecordScheduledTaskDao.";
/**
* 每天00:10生成回访“待办”记录
*/
// @Scheduled(cron = "0 30 0 * * ?")
@Scheduled(cron = "0/20 * * * * ?")
// @ApiOperation(value = "生成",desc = "生成")
public void generateDailyVisitTodos() {
log.info("定时任务 - 开始生成回访计划");
List<Map<String, Object>> activePlans = commonService.findList(namespace + "selectActiveVisitPlans", new HashMap<>());
if (activePlans == null || activePlans.isEmpty()) {
return;
}
LocalDate today = LocalDate.now();
for (Map<String, Object> plan : activePlans) {
String planId = String.valueOf(plan.get("id"));
String planName = String.valueOf(plan.get("plan_name"));
String planType = String.valueOf(plan.get("plan_type"));
String ratingDictType = String.valueOf(plan.get("rating_dict_type"));
String ratingType = String.valueOf(plan.get("rating_type"));
int startDay = Integer.parseInt(String.valueOf(plan.get("visit_start_day")));
int endDay = Integer.parseInt(String.valueOf(plan.get("visit_end_day")));
int overdueDays = 0;
Object overdueObj = plan.get("overdue_warning_day");
if (overdueObj != null) {
try { overdueDays = Integer.parseInt(String.valueOf(overdueObj)); } catch (Exception ignored) {}
if (overdueDays < 0) { overdueDays = 0; }
}
Map<String, Object> personQuery = new HashMap<>();
personQuery.put("rating_dict_type", ratingDictType);
personQuery.put("rating_type", ratingType);
List<Map<String, Object>> persons;
if ("6".equals(ratingDictType)) {
persons = commonService.findList(namespace + "selectPersonsForMinorByPlan", personQuery);
} else {
persons = commonService.findList(namespace + "selectPersonsForKeyPersonByPlan", personQuery);
}
if (persons == null || persons.isEmpty()) {
continue;
}
for (Map<String, Object> person : persons) {
String personId = String.valueOf(person.get("person_id"));
Map<String, Object> param = new HashMap<>();
param.put("person_id", personId);
// 标记可能已过期的“待办”记录
Map<String, Object> latestBefore = commonService.getObject(namespace + "selectLatestRecordByPerson", param);
if (latestBefore != null) {
commonService.update(namespace + "markOverdueIfExpired", latestBefore);
}
// 重新获取最新记录
Map<String, Object> latest = commonService.getObject(namespace + "selectLatestRecordByPerson", param);
// 4.3 无任何回访记录:直接新增
if (latest == null) {
LocalDate planStart = today;
LocalDate planEnd = today.plusDays(Math.max(0, endDay - startDay));
Map<String, Object> insert = new HashMap<>();
insert.put("person_id", personId);
insert.put("key_person_visit_id", planId);
insert.put("plan_name", planName);
insert.put("plan_type", planType);
insert.put("rating_dict_type", ratingDictType);
insert.put("rating_type", ratingType);
insert.put("plan_start_data", planStart.toString());
insert.put("plan_end_data", planEnd.toString());
if (overdueDays > 0) {
LocalDate overdueDate = planEnd.minusDays(overdueDays);
insert.put("overdue_date", overdueDate.toString());
}
commonService.insert(namespace + "insertVisitRecord", insert);
continue;
}
String statusStr = String.valueOf(latest.get("do_status"));
int status = -1;
try { status = Integer.parseInt(statusStr); } catch (Exception ignored) {}
// 4.2 一个“待办”限制:如仍为“待办”,则不生成;
if (status == 0) {
continue;
}
// 4.4 最新为“已办(1)”或“超期未办(2)”:达到起始天数生成新“待办”
Object planEndObj = latest.get("plan_end_date");
LocalDate baseDate = planEndObj != null ? LocalDate.parse(String.valueOf(planEndObj)) : today;
long daysSinceBase = ChronoUnit.DAYS.between(baseDate, today);
if (daysSinceBase >= startDay) {
LocalDate planStart = baseDate.plusDays(startDay);
LocalDate planEnd = baseDate.plusDays(endDay);
Map<String, Object> insert = new HashMap<>();
insert.put("person_id", personId);
insert.put("key_person_visit_id", planId);
insert.put("plan_name", planName);
insert.put("plan_type", planType);
insert.put("rating_dict_type", ratingDictType);
insert.put("rating_type", ratingType);
insert.put("plan_start_data", planStart.toString());
insert.put("plan_end_data", planEnd.toString());
if (overdueDays > 0) {
LocalDate overdueDate = planEnd.minusDays(overdueDays);
insert.put("overdue_date", overdueDate.toString());
}
commonService.insert(namespace + "insertVisitRecord", insert);
}
}
}
log.info("定时任务 - 回访计划生成结束");
}
/**
* 每天00:10:将所有“待办”中超过临期日期(overdue_date)的记录标记为已临期(is_overdue=1)
* 示例:overdue_date=2025-05-05,则在2025-05-06触发任务后置为1
*/
// @Scheduled(cron = "0 10 0 * * ?")
@Scheduled(cron = "0/20 * * * * ?")
// @ApiOperation(value = "标记临期", desc = "超过 overdue_date 将 is_overdue 置为 1")
public void markOverdueByOverdueDate() {
log.info("定时任务 - 更新回访计划临期状态");
commonService.update(namespace + "markOverdueByOverdueDate", new HashMap<>());
log.info("定时任务 - 回访计划临期状态结束");
}
}
...@@ -62,6 +62,16 @@ public class KeyPersonVisitServiceImpl { ...@@ -62,6 +62,16 @@ public class KeyPersonVisitServiceImpl {
} catch (Exception ex) { } catch (Exception ex) {
throw new CustomException("临期预警天需为正整数"); throw new CustomException("临期预警天需为正整数");
} }
// 必填:部门类型
Object officeTypeObj = map.get("sys_type_office_value");
if (officeTypeObj == null || String.valueOf(officeTypeObj).trim().length() == 0) {
throw new CustomException("请选择部门类型");
}
// 如果保存时状态为启用,需要先停用同一部门、同一类别、同一风险等级的其他启用记录
Object statusObj = map.get("status");
if ("1".equals(String.valueOf(statusObj))) {
commonService.update(namespace + "disableOtherActives", map);
}
// 区分新增与修改:有id则更新,无id则新增 // 区分新增与修改:有id则更新,无id则新增
Object idObj = map.get("id"); Object idObj = map.get("id");
if (idObj == null || String.valueOf(idObj).trim().length() == 0) { if (idObj == null || String.valueOf(idObj).trim().length() == 0) {
......
...@@ -60,11 +60,16 @@ public class MurderManagementServiceImpl { ...@@ -60,11 +60,16 @@ public class MurderManagementServiceImpl {
private static final Logger log = LoggerFactory.getLogger(MurderManagementServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(MurderManagementServiceImpl.class);
@ApiOperation(value = "查询登录人信息", desc = "") @ApiOperation(value = "查询登录人信息", desc = "")
public Map<String,Object> getLoginUserAreaInfo(Page<Map<String,Object>> map) { public Map<String,Object> getLoginUserAreaInfo(Page<Map<String,Object>> map) {
// Map<String, Object> user = (Map<String, Object>) map.getParams().get("_user"); Map<String, Object> user = (Map<String, Object>) map.getParams().get("_user");
// return commonService.getObject(nameSpace + "getLoginUserAreaInfo", user.get("company_id")); String company_id = user.get("company_id").toString();
String areaId = map.getParams().get("area_id").toString(); if (company_id.length() == 12) {
return commonService.getObject(nameSpace + "getLoginUserAreaInfo", company_id);
} else {
Map<String, String> areaMap = DataScopeUtil.getPosition(user);
String areaId = areaMap.get("area_id").toString();
return commonService.getObject(nameSpace + "getLoginUserAreaInfo",areaId); return commonService.getObject(nameSpace + "getLoginUserAreaInfo",areaId);
} }
}
@ApiOperation(value = "重点人员列表查询", desc = "") @ApiOperation(value = "重点人员列表查询", desc = "")
......
...@@ -58,11 +58,16 @@ public class keyPersonMinorServiceImpl { ...@@ -58,11 +58,16 @@ public class keyPersonMinorServiceImpl {
private static final Logger log = LoggerFactory.getLogger(keyPersonMinorServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(keyPersonMinorServiceImpl.class);
@ApiOperation(value = "查询登录人信息", desc = "") @ApiOperation(value = "查询登录人信息", desc = "")
public Map<String,Object> getLoginUserAreaInfo(Page<Map<String,Object>> map) { public Map<String,Object> getLoginUserAreaInfo(Page<Map<String,Object>> map) {
// Map<String, Object> user = (Map<String, Object>) map.getParams().get("_user"); Map<String, Object> user = (Map<String, Object>) map.getParams().get("_user");
// return commonService.getObject(nameSpace + "getLoginUserAreaInfo", user.get("company_id")); String company_id = user.get("company_id").toString();
String areaId = map.getParams().get("area_id").toString(); if (company_id.length() == 12) {
return commonService.getObject(nameSpace + "getLoginUserAreaInfo", company_id);
} else {
Map<String, String> areaMap = DataScopeUtil.getPosition(user);
String areaId = areaMap.get("area_id").toString();
return commonService.getObject(nameSpace + "getLoginUserAreaInfo",areaId); return commonService.getObject(nameSpace + "getLoginUserAreaInfo",areaId);
} }
}
@ApiOperation(value = "重点人员列表查询", desc = "") @ApiOperation(value = "重点人员列表查询", desc = "")
......
...@@ -8,7 +8,7 @@ import org.springframework.stereotype.Component; ...@@ -8,7 +8,7 @@ import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.stream.Collectors;
@Component @Component
public class DataScopeUtil { public class DataScopeUtil {
...@@ -18,6 +18,38 @@ public class DataScopeUtil { ...@@ -18,6 +18,38 @@ public class DataScopeUtil {
private static CommonService commonService; private static CommonService commonService;
private static String namespace = "com.scpyun.platform.standard.jilinsscgsdp.KeyPersonPower."; private static String namespace = "com.scpyun.platform.standard.jilinsscgsdp.KeyPersonPower.";
/**
* 获取当前登录人机构类型
* @param _user
* @return
*/
public static Map<String, Object> getOfficeType(Object _user) {
Map<String, Object> params = new HashMap<>();
Map<String, Object> result = new HashMap<>();
JSONObject user = JSONObject.parseObject(JSONObject.toJSONString(_user));
String company_id = user.getString("company_id");
String companyName = user.getString("company_name");
if (company_id.length() == 12) {
result.put("office_value", "-9999");
result.put("office_label", "综治中心");
} else {
params.put("type", "sys_type_office");
List<Map<String, Object>> officeTypeList = commonService.findList(namespace + "selectDicByType", params);
officeTypeList = officeTypeList.stream().filter(c->companyName.contains(c.get("label").toString())).collect(Collectors.toList());
if (officeTypeList.size() ==0) {
result.put("office_value", "-9998");
result.put("office_label", "未获取到类型");
} else {
result.put("office_value", officeTypeList.get(0).get("value"));
result.put("office_label", officeTypeList.get(0).get("label"));
}
}
return result;
}
/** /**
* 获取按钮权限 * 获取按钮权限
* @param _user * @param _user
...@@ -67,8 +99,8 @@ public class DataScopeUtil { ...@@ -67,8 +99,8 @@ public class DataScopeUtil {
* area_id: 区域id * area_id: 区域id
*/ */
public static Map<String, String> getPosition(Object _user) { public static Map<String, String> getPosition(Object _user) {
Map queryMap = new HashMap(); Map<String, Object> queryMap = new HashMap<>();
Map resultMap = new HashMap(); Map<String, String> resultMap = new HashMap<>();
JSONObject user = JSONObject.parseObject(JSONObject.toJSONString(_user)); JSONObject user = JSONObject.parseObject(JSONObject.toJSONString(_user));
String company_id = user.getString("company_id"); String company_id = user.getString("company_id");
...@@ -80,7 +112,7 @@ public class DataScopeUtil { ...@@ -80,7 +112,7 @@ public class DataScopeUtil {
Map<String, Object> result = commonService.getObject(namespace + "selectOfficeById", queryMap); Map<String, Object> result = commonService.getObject(namespace + "selectOfficeById", queryMap);
resultMap.put("grade", company_grade); resultMap.put("grade", company_grade);
resultMap.put("area_id", result.get("area_id")); resultMap.put("area_id", result.get("area_id") != null ? result.get("area_id").toString() : "");
return resultMap; return resultMap;
} }
...@@ -91,7 +123,7 @@ public class DataScopeUtil { ...@@ -91,7 +123,7 @@ public class DataScopeUtil {
* @return true:是 false:否 * @return true:是 false:否
*/ */
public static Boolean isChanChun(Object _user) { public static Boolean isChanChun(Object _user) {
Map queryMap = new HashMap(); Map<String, Object> queryMap = new HashMap<>();
JSONObject user = JSONObject.parseObject(JSONObject.toJSONString(_user)); JSONObject user = JSONObject.parseObject(JSONObject.toJSONString(_user));
String company_id = user.getString("company_id"); String company_id = user.getString("company_id");
if (company_id.length() == 12 && company_id.startsWith("2201")) { if (company_id.length() == 12 && company_id.startsWith("2201")) {
...@@ -112,7 +144,7 @@ public class DataScopeUtil { ...@@ -112,7 +144,7 @@ public class DataScopeUtil {
public static Map<String, Object> resetUser(Map<String, Object> map) { public static Map<String, Object> resetUser(Map<String, Object> map) {
Object _user = map.get("_user"); Object _user = map.get("_user");
Map queryMap = new HashMap(); Map<String, Object> queryMap = new HashMap<>();
JSONObject user = JSONObject.parseObject(JSONObject.toJSONString(_user)); JSONObject user = JSONObject.parseObject(JSONObject.toJSONString(_user));
String company_id = user.getString("company_id"); String company_id = user.getString("company_id");
if (company_id.length() == 12) { if (company_id.length() == 12) {
...@@ -123,7 +155,6 @@ public class DataScopeUtil { ...@@ -123,7 +155,6 @@ public class DataScopeUtil {
queryMap.put("id", company_id); queryMap.put("id", company_id);
Map<String, Object> result = commonService.getObject(namespace + "selectOfficeById", queryMap); Map<String, Object> result = commonService.getObject(namespace + "selectOfficeById", queryMap);
String id = result.get("id").toString();
String area_id = result.get("area_id").toString(); String area_id = result.get("area_id").toString();
user.put("area_id", area_id); user.put("area_id", area_id);
map.put("_user", user); map.put("_user", user);
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
select select
value, value,
label label
from sys_dict where type = #{type} from sys_dict where type = #{type} and del_flag = '0'
</select> </select>
<select id="selectOfficeById" parameterType="map" resultType="map"> <select id="selectOfficeById" parameterType="map" resultType="map">
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
INSERT INTO jl_key_person_visit( INSERT INTO jl_key_person_visit(
id, id,
rating_dict_type, rating_dict_type,
sys_type_office_value,
sys_type_office_label,
plan_name, plan_name,
plan_type, plan_type,
rating_type, rating_type,
...@@ -17,6 +19,8 @@ ...@@ -17,6 +19,8 @@
) VALUES ( ) VALUES (
UUID(), UUID(),
#{rating_dict_type}, #{rating_dict_type},
#{sys_type_office_value},
#{sys_type_office_label},
#{plan_name}, #{plan_name},
#{plan_type}, #{plan_type},
#{rating_type}, #{rating_type},
...@@ -33,6 +37,8 @@ ...@@ -33,6 +37,8 @@
UPDATE jl_key_person_visit UPDATE jl_key_person_visit
SET SET
rating_dict_type = #{rating_dict_type}, rating_dict_type = #{rating_dict_type},
sys_type_office_value = #{sys_type_office_value},
sys_type_office_label = #{sys_type_office_label},
plan_name = #{plan_name}, plan_name = #{plan_name},
plan_type = #{plan_type}, plan_type = #{plan_type},
rating_type = #{rating_type}, rating_type = #{rating_type},
...@@ -164,6 +170,8 @@ ...@@ -164,6 +170,8 @@
SELECT SELECT
id, id,
rating_dict_type, rating_dict_type,
sys_type_office_value,
sys_type_office_label,
plan_name, plan_name,
plan_type, plan_type,
rating_type, rating_type,
...@@ -183,6 +191,9 @@ ...@@ -183,6 +191,9 @@
<if test="params.rating_type != null and params.rating_type != ''"> <if test="params.rating_type != null and params.rating_type != ''">
AND rating_type = #{params.rating_type} AND rating_type = #{params.rating_type}
</if> </if>
<if test="params.sys_type_office_value != null and params.sys_type_office_value != ''">
AND sys_type_office_value = #{params.sys_type_office_value}
</if>
<if test="params.status != null and params.status != ''"> <if test="params.status != null and params.status != ''">
AND status = #{params.status} AND status = #{params.status}
</if> </if>
...@@ -204,10 +215,25 @@ ...@@ -204,10 +215,25 @@
SET status = '2', update_by = #{_user.id}, update_time = NOW() SET status = '2', update_by = #{_user.id}, update_time = NOW()
WHERE rating_dict_type = #{rating_dict_type} WHERE rating_dict_type = #{rating_dict_type}
AND rating_type = #{rating_type} AND rating_type = #{rating_type}
AND id &lt;> #{id} AND IFNULL(sys_type_office_value, '') = IFNULL(#{sys_type_office_value}, '')
AND status = '1' AND status = '1'
<if test="id != null and id != ''">
AND id &lt;> #{id}
</if>
</update> </update>
<!-- 检查唯一性:同一部门、同一类别、同一风险等级是否已存在 -->
<select id="checkUniqueVisitPlan" parameterType="map" resultType="int">
SELECT COUNT(1)
FROM jl_key_person_visit
WHERE rating_dict_type = #{rating_dict_type}
AND rating_type = #{rating_type}
AND IFNULL(sys_type_office_value, '') = IFNULL(#{sys_type_office_value}, '')
<if test="id != null and id != ''">
AND id &lt;> #{id}
</if>
</select>
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//oos.juyouhx.com//DTD Mapper 3.0//EN" "http://oss.juyouhx.com/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.scpyun.platform.standard.jilinsscgsdp.keyPersonVisitRecordScheduledTaskDao" name="重点人员回访计划">
<!-- 计划:启用中 -->
<select id="selectActiveVisitPlans" parameterType="map" resultType="map">
SELECT id,
plan_name,
plan_type,
rating_dict_type,
rating_type,
visit_start_day,
visit_end_day,
overdue_warning_day
FROM jl_key_person_visit
WHERE status = '1'
</select>
<!-- 人员筛选:重点人员(非未成年人),且有最新评分等级 -->
<select id="selectPersonsForKeyPersonByPlan" parameterType="map" resultType="map">
SELECT kp.id AS person_id
FROM jl_key_person kp
INNER JOIN jl_key_person_rating_summary s
ON s.key_person_id = kp.id
WHERE kp.sys_type = #{rating_dict_type}
AND s.rating_type = #{rating_type}
AND s.is_history = '1'
GROUP BY kp.id
</select>
<!-- 人员筛选:重点未成年人,且有最新评分等级 -->
<select id="selectPersonsForMinorByPlan" parameterType="map" resultType="map">
SELECT km.id AS person_id
FROM jl_key_person_minor km
INNER JOIN jl_key_person_rating_summary s
ON s.key_person_id = km.id
WHERE s.rating_type = #{rating_type}
AND s.is_history = '1'
GROUP BY km.id
</select>
<!-- 限制:一个人仅允许一条待办 -->
<select id="selectPendingCountByPerson" parameterType="map" resultType="int">
SELECT COUNT(1)
FROM jl_key_person_visit_record
WHERE key_person_id = #{person_id}
AND do_status = '0'
</select>
<!-- 最新一条回访记录(含计划起止、办理状态) -->
<select id="selectLatestRecordByPerson" parameterType="map" resultType="map">
SELECT id,
key_person_id,
key_person_visit_id,
do_status,
plan_start_data,
plan_end_data AS plan_end_date,
DATE(create_time) AS create_date
FROM jl_key_person_visit_record
WHERE key_person_id = #{person_id}
ORDER BY create_time DESC
LIMIT 1
</select>
<!-- 若超出计划结束日期且仍为待办,则标记为超期未办(不可处理本次回访) -->
<update id="markOverdueIfExpired" parameterType="map">
UPDATE jl_key_person_visit_record
SET do_status = '2',is_history = '0'
WHERE id = #{id}
AND do_status = '0'
AND DATE(NOW()) &gt; plan_end_data
</update>
<!-- 插入新的待办记录 -->
<insert id="insertVisitRecord" parameterType="map">
INSERT INTO jl_key_person_visit_record (
id,
key_person_id,
key_person_visit_id,
rating_dict_type,
plan_name,
plan_type,
rating_type,
plan_start_data,
plan_end_data,
overdue_date,
do_status,
is_overdue,
is_history,
create_time
) VALUES (
UUID(),
#{person_id},
#{key_person_visit_id},
#{rating_dict_type},
#{plan_name},
#{plan_type},
#{rating_type},
#{plan_start_data},
#{plan_end_data},
#{overdue_date},
'0',
'0',
'1',
NOW()
)
</insert>
<!-- 超过临期日期的“待办”置为 is_overdue=1(仅待办) -->
<update id="markOverdueByOverdueDate" parameterType="map">
UPDATE jl_key_person_visit_record
SET is_overdue = '1'
WHERE do_status = '0'
AND overdue_date IS NOT NULL
AND now() > overdue_date
AND (is_overdue IS NULL OR is_overdue = '0')
</update>
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论