28 changed files with 1184 additions and 169 deletions
@ -0,0 +1,58 @@
|
||||
package com.biutag.supervision.controller.work; |
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.biutag.supervision.pojo.Result; |
||||
import com.biutag.supervision.pojo.entity.AlarmNotification; |
||||
import com.biutag.supervision.pojo.param.AlarmParam; |
||||
import com.biutag.supervision.service.AlarmNotificationService; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* @author kami on 2024-11-16 11:30:34 |
||||
* @version 0.0.1 |
||||
* @since 1.8 |
||||
*/ |
||||
@Slf4j |
||||
@RestController |
||||
@RequestMapping("/alarm/notification") |
||||
@AllArgsConstructor |
||||
public class AlarmNotificationController { |
||||
|
||||
private final AlarmNotificationService notificationService; |
||||
|
||||
/** |
||||
* 预警通知分页查询 |
||||
* @param param 请求参数 |
||||
* @return 预警通知分页数据 |
||||
*/ |
||||
@PostMapping("/pages") |
||||
public Result<Page<AlarmNotification>> pages(@RequestBody AlarmParam param) { |
||||
return Result.success(notificationService.pages(param)); |
||||
} |
||||
|
||||
/** |
||||
* 回复内容 |
||||
* @param data 数据 |
||||
* @return 响应 |
||||
*/ |
||||
@PostMapping("/reply") |
||||
public Result<Void> alarmNotificationReply(@RequestBody AlarmNotification data) { |
||||
AlarmNotification notification = new AlarmNotification(); |
||||
if(data.getId() == null) { |
||||
return Result.failed(5000, "未找到对用数据"); |
||||
} |
||||
notification.setId(data.getId()); |
||||
notification.setReplyResultContent(data.getReplyResultContent()); |
||||
notification.setReplyState(1); |
||||
boolean res = notificationService.updateById(notification); |
||||
if(!res) { |
||||
return Result.failed(5000, "修改失败"); |
||||
} |
||||
return Result.success(); |
||||
} |
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package com.biutag.supervision.mapper; |
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.supervision.pojo.entity.AlarmNotification; |
||||
|
||||
/** |
||||
* @author kami on 2024-11-16 11:05:28 |
||||
* @version 0.0.1 |
||||
* @since 1.8 |
||||
*/ |
||||
@DS("master") |
||||
public interface AlarmNotificationMapper extends BaseMapper<AlarmNotification> { |
||||
} |
||||
@ -0,0 +1,131 @@
|
||||
package com.biutag.supervision.pojo.entity; |
||||
|
||||
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 com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serial; |
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
|
||||
/** |
||||
* 预警通知 |
||||
* @author kami on 2024-11-16 10:51:18 |
||||
* @version 0.0.1 |
||||
* @since 1.8 |
||||
*/ |
||||
@Data |
||||
@TableName("`alarm_notification`") |
||||
public class AlarmNotification implements Serializable { |
||||
|
||||
@Serial |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 主键 |
||||
*/ |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private String id; |
||||
|
||||
/** |
||||
* 预警时间 |
||||
*/ |
||||
@TableField("`alarm_time`") |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") |
||||
LocalDateTime alarmTime; |
||||
|
||||
@TableField("`alarm_type_id`") |
||||
Long alarmTypeId; |
||||
/** |
||||
* 预警类型 |
||||
*/ |
||||
@TableField("`alarm_type`") |
||||
String alarmType; |
||||
|
||||
/** |
||||
* 被通知单位机构代码 |
||||
*/ |
||||
@TableField("`notification_depart_code`") |
||||
String notificationDepartCode; |
||||
|
||||
/** |
||||
* 被通知单位机构名称 |
||||
*/ |
||||
@TableField("`notification_depart_name`") |
||||
String notificationDepartName; |
||||
|
||||
/** |
||||
* 通知内容 |
||||
*/ |
||||
@TableField("`alarm_content`") |
||||
String alarmContent; |
||||
|
||||
/** |
||||
* 回复状态0未回复1已回复 |
||||
*/ |
||||
@TableField("`reply_state`") |
||||
Integer replyState; |
||||
|
||||
/** |
||||
* 回复情况内容 |
||||
*/ |
||||
@TableField("`reply_result_content`") |
||||
String replyResultContent; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
@TableField("`crt_time`") |
||||
LocalDateTime crtTime; |
||||
/** |
||||
* 创建用户 |
||||
*/ |
||||
@TableField("`crt_user`") |
||||
String crtUser; |
||||
/** |
||||
* 创建单位 |
||||
*/ |
||||
@TableField("`crt_depart_id`") |
||||
String crtDepartId; |
||||
/** |
||||
* 创建人名称 |
||||
*/ |
||||
@TableField("`crt_name`") |
||||
String crtName; |
||||
/** |
||||
* 创建ip |
||||
*/ |
||||
@TableField("`crt_host`") |
||||
String crtHost; |
||||
|
||||
/** |
||||
* 创建用户 |
||||
*/ |
||||
@TableField("`upd_user`") |
||||
String updUser; |
||||
/** |
||||
* 创建单位 |
||||
*/ |
||||
@TableField("`upd_depart_id`") |
||||
String updDepartId; |
||||
/** |
||||
* 创建人名称 |
||||
*/ |
||||
@TableField("`upd_name`") |
||||
String updName; |
||||
/** |
||||
* 创建ip |
||||
*/ |
||||
@TableField("`upd_host`") |
||||
String updHost; |
||||
|
||||
/** |
||||
* 修改时间 |
||||
*/ |
||||
@TableField("`upd_time`") |
||||
LocalDateTime updTime; |
||||
|
||||
} |
||||
@ -0,0 +1,62 @@
|
||||
package com.biutag.supervision.pojo.param; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; |
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import java.io.Serial; |
||||
import java.io.Serializable; |
||||
import java.time.LocalDate; |
||||
import java.time.LocalDateTime; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author kami on 2024-11-16 11:12:34 |
||||
* @version 0.0.1 |
||||
* @since 1.8 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
public class AlarmParam extends BasePage implements Serializable { |
||||
|
||||
@Serial |
||||
private static final long serialVersionUID = 1L; |
||||
/** |
||||
* 预警类型id |
||||
*/ |
||||
Long alarmTypeId; |
||||
/** |
||||
* 预警开始时间 |
||||
*/ |
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss") |
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class) |
||||
@JsonSerialize(using = LocalDateTimeSerializer.class) |
||||
LocalDateTime startTime; |
||||
|
||||
/** |
||||
* 预警开始时间 |
||||
*/ |
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss") |
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class) |
||||
@JsonSerialize(using = LocalDateTimeSerializer.class) |
||||
LocalDateTime endTime; |
||||
|
||||
/** |
||||
* 回复情况0-未回复 1-已回复 |
||||
*/ |
||||
Integer replyState; |
||||
/** |
||||
* 被通知单位机构编码 |
||||
*/ |
||||
String notificationDepartCode; |
||||
/** |
||||
* 回复情况 |
||||
*/ |
||||
String alarmContent; |
||||
|
||||
} |
||||
@ -0,0 +1,30 @@
|
||||
package com.biutag.supervision.pojo.vo; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @author kami on 2024-11-16 17:28:03 |
||||
* @version 0.0.1 |
||||
* @since 1.8 |
||||
*/ |
||||
@Data |
||||
@Builder |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
@NoArgsConstructor(force = true) |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public class BlamePerson implements Serializable { |
||||
|
||||
String blameIdCode; |
||||
|
||||
String blameName; |
||||
|
||||
Integer number; |
||||
} |
||||
@ -0,0 +1,35 @@
|
||||
package com.biutag.supervision.pojo.vo; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @author kami on 2024-11-16 15:06:25 |
||||
* @version 0.0.1 |
||||
* @since 1.8 |
||||
*/ |
||||
@Data |
||||
@Builder |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
@NoArgsConstructor(force = true) |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public class ProblemSourceStatisticsVo implements Serializable { |
||||
|
||||
Integer aTotal; |
||||
|
||||
Integer caseTotal; |
||||
|
||||
Integer negativeTotal; |
||||
|
||||
Integer peopleCount; |
||||
|
||||
Double avgPeople; |
||||
|
||||
} |
||||
@ -0,0 +1,31 @@
|
||||
package com.biutag.supervision.pojo.vo; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @author kami on 2024-11-16 15:06:25 |
||||
* @version 0.0.1 |
||||
* @since 1.8 |
||||
*/ |
||||
@Data |
||||
@Builder |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
@NoArgsConstructor(force = true) |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public class ProblemSourceVo implements Serializable { |
||||
|
||||
String name; |
||||
|
||||
String id; |
||||
|
||||
Integer number; |
||||
|
||||
} |
||||
@ -0,0 +1,42 @@
|
||||
package com.biutag.supervision.service; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.biutag.supervision.mapper.AlarmNotificationMapper; |
||||
import com.biutag.supervision.pojo.entity.AlarmNotification; |
||||
import com.biutag.supervision.pojo.entity.BaseUser; |
||||
import com.biutag.supervision.pojo.model.UserModel; |
||||
import com.biutag.supervision.pojo.param.AlarmParam; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
/** |
||||
* @author kami on 2024-11-16 11:07:43 |
||||
* @version 0.0.1 |
||||
* @since 1.8 |
||||
*/ |
||||
@Service |
||||
public class AlarmNotificationService extends ServiceImpl<AlarmNotificationMapper, AlarmNotification> { |
||||
|
||||
public Page<AlarmNotification> pages(AlarmParam param) { |
||||
LambdaQueryWrapper<AlarmNotification> query = new LambdaQueryWrapper<AlarmNotification>(); |
||||
if(param.getAlarmTypeId() != null && param.getAlarmTypeId() != -1) { |
||||
query.eq(AlarmNotification::getAlarmTypeId, param.getAlarmTypeId()); |
||||
} |
||||
if(param.getStartTime() != null) { |
||||
query.between(AlarmNotification::getAlarmTime, param.getStartTime(), param.getEndTime()); |
||||
} |
||||
if(param.getReplyState() != null && param.getReplyState() != -1) { |
||||
query.eq(AlarmNotification::getReplyState, param.getReplyState()); |
||||
} |
||||
if(param.getNotificationDepartCode() != null) { |
||||
query.eq(AlarmNotification::getNotificationDepartCode, param.getNotificationDepartCode()); |
||||
} |
||||
if(param.getAlarmContent() != null) { |
||||
query.like(AlarmNotification::getAlarmContent, param.getAlarmContent()); |
||||
} |
||||
return page(Page.of(param.getCurrent(), param.getSize()), query.orderByDesc(AlarmNotification::getAlarmTime)); |
||||
} |
||||
} |
||||
@ -0,0 +1,215 @@
|
||||
package com.biutag.supervision.service; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.biutag.supervision.mapper.*; |
||||
import com.biutag.supervision.pojo.entity.*; |
||||
import com.biutag.supervision.pojo.vo.BlamePerson; |
||||
import com.biutag.supervision.pojo.vo.ProblemSourceStatisticsVo; |
||||
import com.biutag.supervision.pojo.vo.ProblemSourceVo; |
||||
import com.biutag.supervision.util.CompletableUtils.CompletableFutureUtil; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.math.RoundingMode; |
||||
import java.time.LocalDateTime; |
||||
import java.time.format.DateTimeFormatter; |
||||
import java.util.*; |
||||
import java.util.concurrent.CompletableFuture; |
||||
import java.util.function.Function; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* 灵敏感知大屏 |
||||
* |
||||
* @author kami on 2024-11-16 15:04:16 |
||||
* @version 0.0.1 |
||||
* @since 1.8 |
||||
*/ |
||||
@Slf4j |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class ProblemSourceService { |
||||
|
||||
private final BusinessDepartMapper businessDepartMapper; |
||||
|
||||
private final NegativeMapper negativeMapper; |
||||
|
||||
private final NegativeBlameMapper blameMapper; |
||||
|
||||
/** |
||||
* 数量统计 |
||||
* |
||||
* @return 统计结构 |
||||
*/ |
||||
public ProblemSourceStatisticsVo totalStatistics() { |
||||
ProblemSourceStatisticsVo.ProblemSourceStatisticsVoBuilder build = ProblemSourceStatisticsVo.builder(); |
||||
CompletableFuture.allOf( |
||||
CompletableFutureUtil.runSyncObject(() -> build.aTotal(businessDepartMapper.problemSum(List.of(1, 2), "2024-01-01 00:00:00"))), |
||||
CompletableFutureUtil.runSyncObject(() -> build.caseTotal(businessDepartMapper.problemSum(List.of(4, 5, 6), "2024-01-01 00:00:00"))), |
||||
CompletableFutureUtil.runSyncObject(() -> build.negativeTotal(negativeMapper.selectCount(new LambdaQueryWrapper<Negative>().in(Negative::getCheckStatus, List.of(1, 2))).intValue())) |
||||
).join(); |
||||
List<NegativeBlame> list = blameMapper.selectList(new LambdaQueryWrapper<NegativeBlame>().select(NegativeBlame::getBlameIdCode)); |
||||
Long count = list.stream().map(NegativeBlame::getBlameIdCode).distinct().count(); |
||||
build.peopleCount(count.intValue()); |
||||
ProblemSourceStatisticsVo vo = build.build(); |
||||
vo.setAvgPeople(new BigDecimal(vo.getNegativeTotal().toString()).divide(new BigDecimal(vo.getPeopleCount().toString()), 2, RoundingMode.UP).doubleValue()); |
||||
return vo; |
||||
} |
||||
|
||||
private final SupDepartMapper supDepartMapper; |
||||
|
||||
/** |
||||
* @param type 类型 1- 风险值 2- 问题数 3-问题发生率 |
||||
* @param businessType |
||||
*/ |
||||
public void rankStatistics(Integer type, Integer businessType) { |
||||
List<SupDepart> departs = supDepartMapper.selectList(new LambdaQueryWrapper<SupDepart>() |
||||
.select(SupDepart::getId, SupDepart::getPid, SupDepart::getName, SupDepart::getLevel)); |
||||
Map<String, SupDepart> departMap = departs.stream().collect(Collectors.toMap(SupDepart::getId, Function.identity(), (oldValue, newValue) -> newValue)); |
||||
|
||||
List<Negative> negatives = negativeMapper.selectList(new LambdaQueryWrapper<Negative>() |
||||
.in(Negative::getCheckStatus, List.of(1, 2))); |
||||
|
||||
Map<String, Integer> mapLevel3 = new HashMap<>(); |
||||
Map<String, Integer> mapLevel2 = new HashMap<>(); |
||||
|
||||
for (Negative negative : negatives) { |
||||
SupDepart depart = departMap.get(negative.getInvolveDepartId()); |
||||
if (depart == null) { |
||||
continue; |
||||
} |
||||
if (depart.getLevel() == 3) { |
||||
Integer count = Optional.ofNullable(mapLevel3.get(negative.getInvolveDepartId())).orElse(0); |
||||
count++; |
||||
mapLevel3.put(negative.getInvolveDepartId(), count); |
||||
depart = departMap.get(depart.getPid()); |
||||
} |
||||
if (depart.getLevel() == 2) { |
||||
Integer count = Optional.ofNullable(mapLevel2.get(negative.getInvolveDepartId())).orElse(0); |
||||
count++; |
||||
mapLevel2.put(negative.getInvolveDepartId(), count); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private final StatisticsGroupMapper statisticsGroupMapper; |
||||
|
||||
private final StatisticsDepartMapper departMapper; |
||||
|
||||
public void statisticsGroupRank() { |
||||
StatisticsGroup group = statisticsGroupMapper.selectOne(new LambdaQueryWrapper<StatisticsGroup>() |
||||
.eq(StatisticsGroup::getName, "交警大队").last("limit 1")); |
||||
|
||||
List<StatisticsDepart> list = departMapper.selectList(new LambdaQueryWrapper<StatisticsDepart>() |
||||
.eq(StatisticsDepart::getLevel, 3) |
||||
.eq(StatisticsDepart::getGroupId, group.getGroupId())); |
||||
|
||||
Map<String, StatisticsDepart> departMap = list.stream().collect(Collectors.toMap(StatisticsDepart::getDepartId, Function.identity(), (oldValue, newValue) -> newValue)); |
||||
|
||||
List<Negative> negatives = negativeMapper.selectList(new LambdaQueryWrapper<Negative>() |
||||
.in(Negative::getCheckStatus, List.of(1, 2))); |
||||
Map<String, Integer> mapLevel3 = new HashMap<>(); |
||||
for (Negative negative : negatives) { |
||||
if (departMap.get(negative.getInvolveDepartId()) == null) { |
||||
continue; |
||||
} |
||||
Integer count = Optional.ofNullable(mapLevel3.get(negative.getInvolveDepartId())).orElse(0); |
||||
count++; |
||||
mapLevel3.put(negative.getInvolveDepartId(), count); |
||||
} |
||||
for (Map.Entry<String, Integer> entry : mapLevel3.entrySet()) { |
||||
log.info("机构:{} | {}", departMap.get(entry.getKey()).getName(), entry.getValue()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 派出所 |
||||
*/ |
||||
public void statisticsGroupRank2() { |
||||
StatisticsGroup group = statisticsGroupMapper.selectOne(new LambdaQueryWrapper<StatisticsGroup>() |
||||
.eq(StatisticsGroup::getName, "派出所").last("limit 1")); |
||||
|
||||
List<StatisticsDepart> list = departMapper.selectList(new LambdaQueryWrapper<StatisticsDepart>() |
||||
.eq(StatisticsDepart::getLevel, 3) |
||||
.eq(StatisticsDepart::getGroupId, group.getGroupId())); |
||||
|
||||
Map<String, StatisticsDepart> departMap = list.stream().collect(Collectors.toMap(StatisticsDepart::getDepartId, Function.identity(), (oldValue, newValue) -> newValue)); |
||||
|
||||
List<Negative> negatives = negativeMapper.selectList(new LambdaQueryWrapper<Negative>() |
||||
.in(Negative::getCheckStatus, List.of(1, 2))); |
||||
Map<String, Integer> mapLevel3 = new HashMap<>(); |
||||
for (Negative negative : negatives) { |
||||
if (departMap.get(negative.getInvolveDepartId()) == null) { |
||||
continue; |
||||
} |
||||
Integer count = Optional.ofNullable(mapLevel3.get(negative.getInvolveDepartId())).orElse(0); |
||||
count++; |
||||
mapLevel3.put(negative.getInvolveDepartId(), count); |
||||
} |
||||
for (Map.Entry<String, Integer> entry : mapLevel3.entrySet()) { |
||||
log.info("机构:{} | {}", departMap.get(entry.getKey()).getName(), entry.getValue()); |
||||
} |
||||
} |
||||
|
||||
// 分县
|
||||
public void statisticsGroupRank3() { |
||||
StatisticsGroup group = statisticsGroupMapper.selectOne(new LambdaQueryWrapper<StatisticsGroup>() |
||||
.eq(StatisticsGroup::getName, "派出所").last("limit 1")); |
||||
|
||||
List<StatisticsDepart> list = departMapper.selectList(new LambdaQueryWrapper<StatisticsDepart>() |
||||
.eq(StatisticsDepart::getLevel, 3) |
||||
.eq(StatisticsDepart::getGroupId, group.getGroupId())); |
||||
Map<String, StatisticsDepart> departMap = list.stream().collect(Collectors.toMap(StatisticsDepart::getDepartId, Function.identity(), (oldValue, newValue) -> newValue)); |
||||
|
||||
List<SupDepart> departs = supDepartMapper.selectList(new LambdaQueryWrapper<SupDepart>() |
||||
.eq(SupDepart::getLevel, 2) |
||||
.select(SupDepart::getId, SupDepart::getPid, SupDepart::getName, SupDepart::getLevel)); |
||||
Map<String, SupDepart> areaMap = departs.stream().collect(Collectors.toMap(SupDepart::getId, Function.identity(), (oldValue, newValue) -> newValue)); |
||||
|
||||
List<Negative> negatives = negativeMapper.selectList(new LambdaQueryWrapper<Negative>() |
||||
.in(Negative::getCheckStatus, List.of(1, 2))); |
||||
Map<String, Integer> mapLevel3 = new HashMap<>(); |
||||
for (Negative negative : negatives) { |
||||
StatisticsDepart depart = departMap.get(negative.getInvolveDepartId()); |
||||
if (depart == null) { |
||||
continue; |
||||
} |
||||
SupDepart area = areaMap.get(depart.getPid()); |
||||
if (area == null) { |
||||
continue; |
||||
} |
||||
Integer count = Optional.ofNullable(mapLevel3.get(area.getId())).orElse(0); |
||||
count++; |
||||
mapLevel3.put(negative.getInvolveDepartId(), count); |
||||
} |
||||
for (Map.Entry<String, Integer> entry : mapLevel3.entrySet()) { |
||||
log.info("机构:{} | {}", areaMap.get(entry.getKey()).getName(), entry.getValue()); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 民警、辅警 |
||||
*/ |
||||
public void personStatistics() { |
||||
List<BlamePerson> list = blameMapper.statisticsBlame(); |
||||
|
||||
List<BlamePerson> list2 = blameMapper.statisticsBlame2(); |
||||
|
||||
List<BlamePerson> list3 = blameMapper.statisticsBlame3(); |
||||
|
||||
|
||||
for (BlamePerson blamePerson : list) { |
||||
log.info("民警:{} | {}", blamePerson.getBlameName(), blamePerson.getNumber()); |
||||
} |
||||
for (BlamePerson blamePerson : list2) { |
||||
log.info("辅警:{} | {}", blamePerson.getBlameName(), blamePerson.getNumber()); |
||||
} |
||||
for (BlamePerson blamePerson : list3) { |
||||
log.info("领导:{} | {}", blamePerson.getBlameName(), blamePerson.getNumber()); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,13 @@
|
||||
package com.biutag.supervision.util.CompletableUtils; |
||||
|
||||
/** |
||||
* @author kami |
||||
* @version 1.0 |
||||
* @since 2021/11/22 17:37 |
||||
*/ |
||||
@FunctionalInterface |
||||
public interface CompletableFutureMine { |
||||
|
||||
void run(); |
||||
|
||||
} |
||||
@ -0,0 +1,13 @@
|
||||
package com.biutag.supervision.util.CompletableUtils; |
||||
|
||||
/** |
||||
* @author kami |
||||
* @version 1.0 |
||||
* @since 2021/11/22 17:37 |
||||
*/ |
||||
@FunctionalInterface |
||||
public interface CompletableFutureResult { |
||||
|
||||
Boolean run(); |
||||
|
||||
} |
||||
@ -0,0 +1,13 @@
|
||||
package com.biutag.supervision.util.CompletableUtils; |
||||
|
||||
/** |
||||
* @author kami |
||||
* @version 1.0 |
||||
* @since 2021/11/22 17:37 |
||||
*/ |
||||
@FunctionalInterface |
||||
public interface CompletableFutureType<T> { |
||||
|
||||
T run(); |
||||
|
||||
} |
||||
@ -0,0 +1,164 @@
|
||||
package com.biutag.supervision.util.CompletableUtils; |
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.slf4j.MDC; |
||||
|
||||
import java.util.Map; |
||||
import java.util.concurrent.CompletableFuture; |
||||
import java.util.concurrent.Executor; |
||||
import java.util.concurrent.Executors; |
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
/** |
||||
* @author kami |
||||
* @version 1.0 |
||||
* @since 2021/11/22 17:39 |
||||
*/ |
||||
@Slf4j |
||||
public class CompletableFutureUtil { |
||||
|
||||
private CompletableFutureUtil(){} |
||||
|
||||
public static final String TRACE_ID = "trace_id"; |
||||
|
||||
private static void run(CompletableFutureMine completableFutureMine, Map<String, String> previous) { |
||||
if (previous == null) { |
||||
MDC.clear(); |
||||
} else { |
||||
MDC.setContextMap(previous); |
||||
} |
||||
if (MDC.get(TRACE_ID) == null || MDC.get(TRACE_ID).isEmpty()) { |
||||
MDC.put(TRACE_ID, System.nanoTime() + ""); |
||||
} |
||||
completableFutureMine.run(); |
||||
MDC.clear(); |
||||
} |
||||
|
||||
private static Boolean runResult(CompletableFutureResult result, Map<String, String> previous) { |
||||
if (previous == null) { |
||||
MDC.clear(); |
||||
} else { |
||||
MDC.setContextMap(previous); |
||||
} |
||||
if (MDC.get(TRACE_ID) == null || MDC.get(TRACE_ID).isEmpty()) { |
||||
MDC.put(TRACE_ID, System.nanoTime() + ""); |
||||
} |
||||
Boolean rs = result.run(); |
||||
MDC.clear(); |
||||
return rs; |
||||
} |
||||
|
||||
public static void runSync(CompletableFutureMine completableFutureMine) { |
||||
Map<String, String> previous = MDC.getCopyOfContextMap(); |
||||
CompletableFuture.runAsync(() -> run(completableFutureMine, previous)).exceptionally(e -> { |
||||
log.error("",e); |
||||
MDC.clear(); |
||||
return null; |
||||
}); |
||||
} |
||||
|
||||
public static CompletableFuture runSyncObject(CompletableFutureMine completableFutureMine) { |
||||
Map<String, String> previous = MDC.getCopyOfContextMap(); |
||||
return CompletableFuture.runAsync(() -> { |
||||
if (previous == null) { |
||||
MDC.clear(); |
||||
} else { |
||||
MDC.setContextMap(previous); |
||||
} |
||||
if (MDC.get(TRACE_ID) == null || MDC.get(TRACE_ID).isEmpty()) { |
||||
MDC.put(TRACE_ID, System.nanoTime() + ""); |
||||
} |
||||
run(completableFutureMine, previous); |
||||
MDC.clear(); |
||||
}).exceptionally(e -> { |
||||
log.error("",e); |
||||
MDC.clear(); |
||||
return null; |
||||
}); |
||||
} |
||||
|
||||
public static void run(CompletableFutureMine completableFutureMine) { |
||||
Map<String, String> previous = MDC.getCopyOfContextMap(); |
||||
CompletableFuture.runAsync(() -> run(completableFutureMine, previous)).exceptionally(e -> { |
||||
log.error("",e); |
||||
MDC.clear(); |
||||
return null; |
||||
}).join(); |
||||
} |
||||
|
||||
public static void runSyncEach(CompletableFutureResult result, Long time) { |
||||
Map<String, String> previous = MDC.getCopyOfContextMap(); |
||||
CompletableFuture.runAsync(() -> { |
||||
Boolean goOn = true; |
||||
while (Boolean.TRUE.equals(goOn)) { |
||||
try { |
||||
TimeUnit.SECONDS.sleep(time); |
||||
} catch (InterruptedException e) { |
||||
log.error("",e); |
||||
Thread.currentThread().interrupt(); |
||||
} |
||||
goOn = runResult(result, previous); |
||||
} |
||||
}).exceptionally(e -> { |
||||
log.error("",e); |
||||
MDC.clear(); |
||||
return null; |
||||
}); |
||||
} |
||||
|
||||
public static void runSyncEach(CompletableFutureResult result, Executor ex, Long time) { |
||||
Map<String, String> previous = MDC.getCopyOfContextMap(); |
||||
CompletableFuture.runAsync(() -> { |
||||
Boolean goOn = true; |
||||
while (goOn) { |
||||
try { |
||||
TimeUnit.SECONDS.sleep(time); |
||||
} catch (InterruptedException e) { |
||||
log.error("",e); |
||||
Thread.currentThread().interrupt(); |
||||
} |
||||
goOn = runResult(result, previous); |
||||
} |
||||
}, ex).exceptionally(e -> { |
||||
log.error("",e); |
||||
MDC.clear(); |
||||
return null; |
||||
}); |
||||
} |
||||
|
||||
public static void runSync(CompletableFutureMine completableFutureMine, Executor ex) { |
||||
Map<String, String> previous = MDC.getCopyOfContextMap(); |
||||
CompletableFuture.runAsync(() -> run(completableFutureMine, previous), ex).exceptionally(e -> { |
||||
log.error("", e); |
||||
MDC.clear(); |
||||
return null; |
||||
}); |
||||
} |
||||
|
||||
public static void runSyncAssert(Boolean assets, CompletableFutureMine completableFutureMine) { |
||||
if(Boolean.TRUE.equals(assets)) { |
||||
CompletableFuture.runAsync(completableFutureMine::run).exceptionally(e -> { |
||||
log.error("",e); |
||||
return null; |
||||
}); |
||||
} |
||||
} |
||||
|
||||
public static <T> CompletableFuture<T> createRunner(CompletableFutureType<T> completableFutureType) { |
||||
Map<String, String> previous = MDC.getCopyOfContextMap(); |
||||
return CompletableFuture.supplyAsync(() -> { |
||||
if (previous == null) { |
||||
MDC.clear(); |
||||
} else { |
||||
MDC.setContextMap(previous); |
||||
} |
||||
if (MDC.get(TRACE_ID) == null || MDC.get(TRACE_ID).isEmpty()) { |
||||
MDC.put(TRACE_ID, System.nanoTime() + ""); |
||||
} |
||||
T t = completableFutureType.run(); |
||||
MDC.clear(); |
||||
return t; |
||||
}); |
||||
} |
||||
} |
||||
@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false"> |
||||
<contextName>logs</contextName> |
||||
<!-- 日志位置 --> |
||||
<property name="log.path" value="/work/log"/> |
||||
<!-- 日志保留时长 --> |
||||
<property name="log.maxHistory" value="7"/> |
||||
<!-- 控制台格式化及颜色 --> |
||||
<property name="log.colorPattern" |
||||
value="%magenta([%X{trace_id}][%d{yyyy-MM-dd'T'HH:mm:ss.SSS}]) %highlight(%-5level) %red(%thread) %green(%logger) %msg%n"/> |
||||
<property name="log.pattern" value="[%X{trace_id}][%d{yyyy-MM-dd'T'HH:mm:ss.SSS}] %-5level %thread %logger %msg%n"/> |
||||
|
||||
<!--输出到控制台--> |
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder> |
||||
<pattern>${log.colorPattern}</pattern> |
||||
<charset>UTF-8</charset> |
||||
</encoder> |
||||
</appender> |
||||
|
||||
<!--输出到文件--> |
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>${log.path}/info/info.%d{yyyy-MM-dd}.log</fileNamePattern> |
||||
<MaxHistory>${log.maxHistory}</MaxHistory> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern>${log.pattern}</pattern> |
||||
</encoder> |
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
<level>INFO</level> |
||||
<onMatch>ACCEPT</onMatch> |
||||
<onMismatch>DENY</onMismatch> |
||||
</filter> |
||||
</appender> |
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>${log.path}/error/error.%d{yyyy-MM-dd}.log</fileNamePattern> |
||||
<MaxHistory>${log.maxHistory}</MaxHistory> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern>${log.pattern}</pattern> |
||||
</encoder> |
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
<level>ERROR</level> |
||||
<onMatch>ACCEPT</onMatch> |
||||
<onMismatch>DENY</onMismatch> |
||||
</filter> |
||||
</appender> |
||||
|
||||
<logger name="com.biutag.supervision" level="INFO"/> |
||||
<!-- 日志类型为debug时,输出到控制台 --> |
||||
<root level="debug"> |
||||
<appender-ref ref="console"/> |
||||
</root> |
||||
<!-- 日志类型为info时,输出到配置好的文件 --> |
||||
<root level="info"> |
||||
<appender-ref ref="file_info"/> |
||||
<appender-ref ref="file_error"/> |
||||
</root> |
||||
</configuration> |
||||
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?> |
||||
<!DOCTYPE mapper |
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.biutag.supervision.mapper.AlarmNotificationMapper"> |
||||
|
||||
</mapper> |
||||
Loading…
Reference in new issue