From 25840a9c204f634ceae7b9dd3cb029e46908780a Mon Sep 17 00:00:00 2001 From: sjh Date: Tue, 15 Oct 2024 14:20:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9F=BA=E7=A1=80=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=A8=A1=E5=9D=97=E6=95=B0=E6=8D=AE=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/biutag/supervision/job/Job.java | 22 ++++ .../supervision/mapper/BusinessLogMapper.java | 8 ++ .../supervision/mapper/GBaseCJDMapper.java | 15 +++ .../supervision/mapper/GBaseJJDMapper.java | 15 +++ .../mapper/StatisticsDepartMapper.java | 18 +++ .../mapper/StatisticsGroupMapper.java | 18 +++ .../pojo/entity/BusinessDepart.java | 3 +- .../supervision/pojo/entity/BusinessLog.java | 37 ++++++ .../pojo/entity/BusinessPolice.java | 5 +- .../supervision/pojo/entity/GBaseCJD.java | 34 ++++++ .../supervision/pojo/entity/GBaseJJD.java | 30 +++++ .../pojo/entity/StatisticsDepart.java | 47 ++++++++ .../pojo/entity/StatisticsGroup.java | 47 ++++++++ .../service/BusinessDepartService.java | 85 +++++++++++++- .../service/BusinessLogService.java | 11 ++ .../service/BusinessPoliceService.java | 110 +++++++++++++++++- .../service/StatisticsDepartService.java | 11 ++ .../service/StatisticsGroupService.java | 11 ++ src/main/resources/application-dev.yml | 5 + src/main/resources/application-prod.yml | 5 + src/main/resources/mapper/GBaseCJDMapper.xml | 13 +++ src/main/resources/mapper/GBaseJJDMapper.xml | 13 +++ 22 files changed, 558 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/biutag/supervision/mapper/BusinessLogMapper.java create mode 100644 src/main/java/com/biutag/supervision/mapper/GBaseCJDMapper.java create mode 100644 src/main/java/com/biutag/supervision/mapper/GBaseJJDMapper.java create mode 100644 src/main/java/com/biutag/supervision/mapper/StatisticsDepartMapper.java create mode 100644 src/main/java/com/biutag/supervision/mapper/StatisticsGroupMapper.java create mode 100644 src/main/java/com/biutag/supervision/pojo/entity/BusinessLog.java create mode 100644 src/main/java/com/biutag/supervision/pojo/entity/GBaseCJD.java create mode 100644 src/main/java/com/biutag/supervision/pojo/entity/GBaseJJD.java create mode 100644 src/main/java/com/biutag/supervision/pojo/entity/StatisticsDepart.java create mode 100644 src/main/java/com/biutag/supervision/pojo/entity/StatisticsGroup.java create mode 100644 src/main/java/com/biutag/supervision/service/BusinessLogService.java create mode 100644 src/main/java/com/biutag/supervision/service/StatisticsDepartService.java create mode 100644 src/main/java/com/biutag/supervision/service/StatisticsGroupService.java create mode 100644 src/main/resources/mapper/GBaseCJDMapper.xml create mode 100644 src/main/resources/mapper/GBaseJJDMapper.xml diff --git a/src/main/java/com/biutag/supervision/job/Job.java b/src/main/java/com/biutag/supervision/job/Job.java index 40fdc59..dd4716b 100644 --- a/src/main/java/com/biutag/supervision/job/Job.java +++ b/src/main/java/com/biutag/supervision/job/Job.java @@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.biutag.supervision.constants.enums.ProcessingStatusEnum; import com.biutag.supervision.pojo.entity.Negative; import com.biutag.supervision.pojo.entity.SupDepart; +import com.biutag.supervision.service.BusinessDepartService; +import com.biutag.supervision.service.BusinessPoliceService; import com.biutag.supervision.service.NegativeService; import com.biutag.supervision.service.SupDepartService; import com.biutag.supervision.util.TimeUtil; @@ -12,6 +14,10 @@ import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Date; import java.util.List; @RequiredArgsConstructor @@ -22,6 +28,10 @@ public class Job { private final SupDepartService departService; + private final BusinessPoliceService businessPoliceService; + + private final BusinessDepartService businessDepartService; + // 10分钟 // 更新流程状态 @Scheduled(fixedRate = 600000) @@ -69,4 +79,16 @@ public class Job { } }); } + + // 每日04:00更新基础数据 + @Scheduled(cron = "0 0 4 * * ?") + public void updateBaseData() { + List happenTime = new ArrayList<>(); + Date start = Date.from(LocalDateTime.now().minusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0).atZone(ZoneId.systemDefault()).toInstant()); + Date end = Date.from(LocalDateTime.now().minusDays(1).withHour(23).withMinute(59).withSecond(59).withNano(0).atZone(ZoneId.systemDefault()).toInstant()); + happenTime.add(start); + happenTime.add(end); + businessDepartService.generate(happenTime); + businessPoliceService.generate(happenTime); + } } diff --git a/src/main/java/com/biutag/supervision/mapper/BusinessLogMapper.java b/src/main/java/com/biutag/supervision/mapper/BusinessLogMapper.java new file mode 100644 index 0000000..ed4e0f9 --- /dev/null +++ b/src/main/java/com/biutag/supervision/mapper/BusinessLogMapper.java @@ -0,0 +1,8 @@ +package com.biutag.supervision.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.biutag.supervision.pojo.entity.BusinessLog; + +public interface BusinessLogMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/mapper/GBaseCJDMapper.java b/src/main/java/com/biutag/supervision/mapper/GBaseCJDMapper.java new file mode 100644 index 0000000..d4ae14b --- /dev/null +++ b/src/main/java/com/biutag/supervision/mapper/GBaseCJDMapper.java @@ -0,0 +1,15 @@ +package com.biutag.supervision.mapper; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.toolkit.Constants; +import com.biutag.supervision.pojo.entity.GBaseCJD; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface GBaseCJDMapper extends BaseMapper { + List selectCJDList(@Param(Constants.WRAPPER) QueryWrapper queryWrapper); +} diff --git a/src/main/java/com/biutag/supervision/mapper/GBaseJJDMapper.java b/src/main/java/com/biutag/supervision/mapper/GBaseJJDMapper.java new file mode 100644 index 0000000..2d1359d --- /dev/null +++ b/src/main/java/com/biutag/supervision/mapper/GBaseJJDMapper.java @@ -0,0 +1,15 @@ +package com.biutag.supervision.mapper; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.toolkit.Constants; +import com.biutag.supervision.pojo.entity.GBaseJJD; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface GBaseJJDMapper extends BaseMapper { + List selectJJDList(@Param(Constants.WRAPPER) QueryWrapper queryWrapper); +} diff --git a/src/main/java/com/biutag/supervision/mapper/StatisticsDepartMapper.java b/src/main/java/com/biutag/supervision/mapper/StatisticsDepartMapper.java new file mode 100644 index 0000000..a644031 --- /dev/null +++ b/src/main/java/com/biutag/supervision/mapper/StatisticsDepartMapper.java @@ -0,0 +1,18 @@ +package com.biutag.supervision.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.biutag.supervision.pojo.entity.StatisticsDepart; +import org.apache.ibatis.annotations.Select; + +import java.util.List; +import java.util.Map; + +public interface StatisticsDepartMapper extends BaseMapper { + @Select("") + List> getGroupIdsByDepartIds(List departIds); +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/mapper/StatisticsGroupMapper.java b/src/main/java/com/biutag/supervision/mapper/StatisticsGroupMapper.java new file mode 100644 index 0000000..f21f7f4 --- /dev/null +++ b/src/main/java/com/biutag/supervision/mapper/StatisticsGroupMapper.java @@ -0,0 +1,18 @@ +package com.biutag.supervision.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.biutag.supervision.pojo.entity.StatisticsGroup; +import org.apache.ibatis.annotations.Select; + +import java.util.List; +import java.util.Map; + +public interface StatisticsGroupMapper extends BaseMapper { + @Select("") + List> getNameByGroupIds(List groupIds); +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/entity/BusinessDepart.java b/src/main/java/com/biutag/supervision/pojo/entity/BusinessDepart.java index 899e66c..54c7e78 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/BusinessDepart.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/BusinessDepart.java @@ -1,5 +1,6 @@ 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 lombok.Getter; @@ -12,7 +13,7 @@ import java.time.LocalDateTime; public class BusinessDepart { // - @TableId(value = "id") + @TableId(value = "id", type = IdType.AUTO) private Integer id; // 日期(天) diff --git a/src/main/java/com/biutag/supervision/pojo/entity/BusinessLog.java b/src/main/java/com/biutag/supervision/pojo/entity/BusinessLog.java new file mode 100644 index 0000000..6faea4e --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/entity/BusinessLog.java @@ -0,0 +1,37 @@ +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 lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +import java.time.LocalDateTime; + +@Accessors(chain = true) +@Setter +@Getter +public class BusinessLog { + + // id + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + // 类型 + @TableField("type") + private String type; + + // 应更新数量 + @TableField("num") + private Integer num; + + // 实际更新数量 + @TableField("actual_num") + private Integer actualNum; + + // 创建时间 + @TableField("create_time") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/entity/BusinessPolice.java b/src/main/java/com/biutag/supervision/pojo/entity/BusinessPolice.java index a815209..9bd4bda 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/BusinessPolice.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/BusinessPolice.java @@ -1,5 +1,6 @@ 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 lombok.Getter; @@ -12,7 +13,7 @@ import java.time.LocalDateTime; public class BusinessPolice { // - @TableId(value = "id") + @TableId(value = "id", type = IdType.AUTO) private Integer id; // 日期(天) @@ -29,7 +30,7 @@ public class BusinessPolice { // 警号 @TableField("emp_no") - private Integer empNo; + private String empNo; // 警员所属单位ID @TableField("depart_id") diff --git a/src/main/java/com/biutag/supervision/pojo/entity/GBaseCJD.java b/src/main/java/com/biutag/supervision/pojo/entity/GBaseCJD.java new file mode 100644 index 0000000..713ec0c --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/entity/GBaseCJD.java @@ -0,0 +1,34 @@ +package com.biutag.supervision.pojo.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; + +@Setter +@Getter +public class GBaseCJD { + + private Integer clwbrxmTotal; + + // 处理完毕人姓名 + @TableField("clwbrxm") + private String clwbrxm; + + // 处警时间 + @TableField("cjsj") + private LocalDateTime cjsj; + + // 处理完毕人编号 + @TableField("clwbrbh") + private String clwbrbh; + + // 处警对象所属单位代码 + @TableField("cjdxssdwdm") + private String cjdxssdwdm; + + // 处警对象所属单位名称 + @TableField("cjdxssdwmc") + private String cjdxssdwmc; +} diff --git a/src/main/java/com/biutag/supervision/pojo/entity/GBaseJJD.java b/src/main/java/com/biutag/supervision/pojo/entity/GBaseJJD.java new file mode 100644 index 0000000..f632dd5 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/entity/GBaseJJD.java @@ -0,0 +1,30 @@ +package com.biutag.supervision.pojo.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; + +@Setter +@Getter +public class GBaseJJD { + + private Integer jjdbhTotal; + + // 接警单编号 + @TableField("jjdbh") + private String jjdbh; + + // 创建时间 + @TableField("cjsj") + private LocalDateTime cjsj; + + // 管辖单位代码 + @TableField("gxdwdm") + private String gxdwdm; + + // 管辖单位名称 + @TableField("gxdwmc") + private String gxdwmc; +} diff --git a/src/main/java/com/biutag/supervision/pojo/entity/StatisticsDepart.java b/src/main/java/com/biutag/supervision/pojo/entity/StatisticsDepart.java new file mode 100644 index 0000000..203ebc6 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/entity/StatisticsDepart.java @@ -0,0 +1,47 @@ +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 lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; + +@Setter +@Getter +public class StatisticsDepart { + + // + @TableId(value = "departId") + private String departId; + + // + @TableField("name") + private String name; + + // + @TableField("level") + private Integer level; + + // + @TableField("groupId") + private String groupId; + + // + @TableField("pid") + private String pid; + + // 总人数 + @TableField("total") + private Integer total; + + // 警察人数 + @TableField("policeNumber") + private Integer policeNumber; + + // 辅警人数 + @TableField("auxiliaryPoliceNumber") + private Integer auxiliaryPoliceNumber; + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/entity/StatisticsGroup.java b/src/main/java/com/biutag/supervision/pojo/entity/StatisticsGroup.java new file mode 100644 index 0000000..bcc2fa3 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/entity/StatisticsGroup.java @@ -0,0 +1,47 @@ +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 lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; + +@Setter +@Getter +public class StatisticsGroup { + + // + @TableId(value = "groupId") + private String groupId; + + // + @TableField("name") + private String name; + + // + @TableField("level") + private Integer level; + + // + @TableField("remark") + private String remark; + + // + @TableField("type") + private String type; + + // + @TableField("pid") + private String pid; + + // 特殊处理, 为1为派出所 + @TableField("flag") + private String flag; + + // + @TableField("sort") + private Integer sort; + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/service/BusinessDepartService.java b/src/main/java/com/biutag/supervision/service/BusinessDepartService.java index db63df0..f76e0e9 100644 --- a/src/main/java/com/biutag/supervision/service/BusinessDepartService.java +++ b/src/main/java/com/biutag/supervision/service/BusinessDepartService.java @@ -1,18 +1,50 @@ package com.biutag.supervision.service; import cn.hutool.core.util.StrUtil; +import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.biutag.supervision.mapper.*; import com.biutag.supervision.pojo.entity.BusinessDepart; -import com.biutag.supervision.mapper.BusinessDepartMapper; +import com.biutag.supervision.pojo.entity.BusinessLog; +import com.biutag.supervision.pojo.entity.GBaseJJD; import com.biutag.supervision.pojo.model.BusinessPoliceModel; import com.biutag.supervision.pojo.param.BusinessQueryParam; +import lombok.RequiredArgsConstructor; +import org.apache.ibatis.executor.BatchResult; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.stream.Collectors; + +@RequiredArgsConstructor @Service public class BusinessDepartService extends ServiceImpl { + + private final GBaseJJDMapper gBaseJJDMapper; + + private final StatisticsDepartMapper statisticsDepartMapper; + + private final StatisticsGroupMapper statisticsGroupMapper; + + private final BusinessLogMapper businessLogMapper; + public Page page(BusinessQueryParam businessQueryParam) { + if (businessQueryParam.getDepartName()!=null && businessQueryParam.getDepartName().equals("开始导入今年所有的数据")) { + List happenTime = new ArrayList<>(); + Date start = Date.from(LocalDateTime.parse("2024-01-01T00:00:00", DateTimeFormatter.ISO_DATE_TIME).atZone(ZoneId.systemDefault()).toInstant()); + Date end = Date.from(LocalDateTime.parse("2024-10-14T23:59:59", DateTimeFormatter.ISO_DATE_TIME).atZone(ZoneId.systemDefault()).toInstant()); + happenTime.add(start); + happenTime.add(end); + generate(happenTime); + } + if (businessQueryParam.getDepartName().equals("测试")) { + generate(businessQueryParam.getHappenTime()); + } QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper .like(StrUtil.isNotBlank(businessQueryParam.getDepartName()), "depart_name", businessQueryParam.getDepartName()) @@ -24,4 +56,55 @@ public class BusinessDepartService extends ServiceImpl happenTime) { + List businessDepartList = new ArrayList<>(); + List gBaseJJDSList = selectJJDList(happenTime); + List departIds = gBaseJJDSList.stream().map(GBaseJJD::getGxdwdm).toList(); + List> resultList = statisticsDepartMapper.getGroupIdsByDepartIds(departIds); + Map resultMap = resultList.stream().collect(Collectors.toMap(map -> (String) map.get("departId"), map -> (Long) map.get("groupId"))); + List groupIds = new ArrayList<>(); + for (GBaseJJD gBaseJJD : gBaseJJDSList) { + Long groupId = resultMap.get(gBaseJJD.getGxdwdm()); + groupIds.add(groupId); + BusinessDepart businessDepart = getBusinessDepart(gBaseJJD, groupId); + businessDepartList.add(businessDepart); + } + List> nameList = statisticsGroupMapper.getNameByGroupIds(groupIds); + Map names = nameList.stream().collect(Collectors.toMap(map -> (Long) map.get("groupId"), map -> (String) map.get("name"))); + for (BusinessDepart businessDepart : businessDepartList) { + businessDepart.setGroupName(names.get(businessDepart.getGroupId())); + businessDepart.setCreateTime(LocalDateTime.now()); + } + List insert = baseMapper.insert(businessDepartList); + int actualNum = (int) Arrays.stream(insert.get(0).getUpdateCounts()).parallel().filter(num -> num != 0).count(); + businessLogMapper.insert(new BusinessLog().setType("单位业务数据").setNum(gBaseJJDSList.size()).setActualNum(actualNum).setCreateTime(LocalDateTime.now())); + } + + private static BusinessDepart getBusinessDepart(GBaseJJD gBaseJJD, Long groupId) { + BusinessDepart businessDepart = new BusinessDepart(); + businessDepart.setDate(gBaseJJD.getCjsj()); + businessDepart.setDepartId(gBaseJJD.getGxdwdm()); + businessDepart.setDepartName(gBaseJJD.getGxdwmc()); + businessDepart.setGroupId(groupId); + businessDepart.setNumber(gBaseJJD.getJjdbhTotal()); + if (groupId != null) { + if (groupId == 10L) { + businessDepart.setBusinessType("1"); + businessDepart.setBusinessTypeName("110接处警"); + } else if (groupId == 11L) { + businessDepart.setBusinessType("2"); + businessDepart.setBusinessTypeName("122接处警"); + } + } + return businessDepart; + } + + @DS("slave2") + public List selectJJDList(List happenTime) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.between("cjsj", happenTime.get(0), happenTime.get(1)); + queryWrapper.groupBy("gxdwdm", "gxdwmc", "cjsj"); + return gBaseJJDMapper.selectJJDList(queryWrapper); + } } diff --git a/src/main/java/com/biutag/supervision/service/BusinessLogService.java b/src/main/java/com/biutag/supervision/service/BusinessLogService.java new file mode 100644 index 0000000..9cb14d9 --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/BusinessLogService.java @@ -0,0 +1,11 @@ +package com.biutag.supervision.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.biutag.supervision.pojo.entity.BusinessLog; +import com.biutag.supervision.mapper.BusinessLogMapper; +import org.springframework.stereotype.Service; + +@Service +public class BusinessLogService extends ServiceImpl { + +} diff --git a/src/main/java/com/biutag/supervision/service/BusinessPoliceService.java b/src/main/java/com/biutag/supervision/service/BusinessPoliceService.java index 214230a..6ad3bd9 100644 --- a/src/main/java/com/biutag/supervision/service/BusinessPoliceService.java +++ b/src/main/java/com/biutag/supervision/service/BusinessPoliceService.java @@ -1,18 +1,49 @@ package com.biutag.supervision.service; import cn.hutool.core.util.StrUtil; +import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.biutag.supervision.mapper.BusinessPoliceMapper; +import com.biutag.supervision.mapper.*; +import com.biutag.supervision.pojo.entity.BusinessLog; import com.biutag.supervision.pojo.entity.BusinessPolice; +import com.biutag.supervision.pojo.entity.GBaseCJD; import com.biutag.supervision.pojo.model.BusinessPoliceModel; import com.biutag.supervision.pojo.param.BusinessQueryParam; +import lombok.RequiredArgsConstructor; +import org.apache.ibatis.executor.BatchResult; import org.springframework.stereotype.Service; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.stream.Collectors; + +@RequiredArgsConstructor @Service public class BusinessPoliceService extends ServiceImpl { + + private final GBaseCJDMapper gBaseCJDMapper; + + private final StatisticsDepartMapper statisticsDepartMapper; + + private final StatisticsGroupMapper statisticsGroupMapper; + + private final BusinessLogMapper businessLogMapper; + public Page page(BusinessQueryParam businessQueryParam) { + if (businessQueryParam.getDepartName()!=null && businessQueryParam.getDepartName().equals("开始导入今年所有的数据")) { + List happenTime = new ArrayList<>(); + Date start = Date.from(LocalDateTime.parse("2024-01-01T00:00:00", DateTimeFormatter.ISO_DATE_TIME).atZone(ZoneId.systemDefault()).toInstant()); + Date end = Date.from(LocalDateTime.parse("2024-10-14T23:59:59", DateTimeFormatter.ISO_DATE_TIME).atZone(ZoneId.systemDefault()).toInstant()); + happenTime.add(start); + happenTime.add(end); + generate(happenTime); + } String empNo = ""; if (businessQueryParam.getEmpNo() != null && !businessQueryParam.getEmpNo().isEmpty()) { empNo = String.valueOf(Integer.parseInt(businessQueryParam.getEmpNo())); @@ -29,4 +60,81 @@ public class BusinessPoliceService extends ServiceImpl happenTime) { + List businessPoliceList = new ArrayList<>(); + List gBaseCJDSList = selectCJDList(happenTime); + List departIds = gBaseCJDSList.stream().map(GBaseCJD::getCjdxssdwdm).toList(); + List> resultList = statisticsDepartMapper.getGroupIdsByDepartIds(departIds); + Map resultMap = resultList.stream().collect(Collectors.toMap( + map -> (String) map.get("departId"), + map -> (Long) map.get("groupId") + )); + List groupIds = new ArrayList<>(); + for (GBaseCJD gBaseCJD : gBaseCJDSList) { + Long groupId = resultMap.get(gBaseCJD.getCjdxssdwdm()); + groupIds.add(groupId); + BusinessPolice businessPolice = getBusinessPolice(gBaseCJD, groupId); + businessPoliceList.add(businessPolice); + } + List> nameList = statisticsGroupMapper.getNameByGroupIds(groupIds); + Map names = nameList.stream().collect(Collectors.toMap( + map -> (Long) map.get("groupId"), + map -> (String) map.get("name") + )); + for (BusinessPolice businessPolice : businessPoliceList) { + businessPolice.setGroupName(names.get(businessPolice.getGroupId())); + businessPolice.setCreateTime(LocalDateTime.now()); + } + List insert = baseMapper.insert(businessPoliceList); + int actualNum = (int) Arrays.stream(insert.get(0).getUpdateCounts()).parallel().filter(num -> num != 0).count(); + businessLogMapper.insert(new BusinessLog().setType("个人业务数据").setNum(gBaseCJDSList.size()).setActualNum(actualNum).setCreateTime(LocalDateTime.now())); + } + + private static BusinessPolice getBusinessPolice(GBaseCJD gBaseCJD, Long groupId) { + BusinessPolice businessPolice = new BusinessPolice(); + businessPolice.setDate(gBaseCJD.getCjsj()); + businessPolice.setDepartId(gBaseCJD.getCjdxssdwdm()); + businessPolice.setDepartName(gBaseCJD.getCjdxssdwmc()); + businessPolice.setGroupId(groupId); + businessPolice.setNumber(gBaseCJD.getClwbrxmTotal()); + businessPolice.setPoliceName(gBaseCJD.getClwbrxm()); + businessPolice.setEmpNo(gBaseCJD.getClwbrbh()); + businessPolice.setPoliceIdCode(hashConcatenatedStrings(gBaseCJD.getClwbrxm(), gBaseCJD.getClwbrbh())); + if (groupId != null) { + if (groupId == 10L) { + businessPolice.setBusinessType("1"); + businessPolice.setBusinessTypeName("110接处警"); + } else if (groupId == 11L) { + businessPolice.setBusinessType("2"); + businessPolice.setBusinessTypeName("122接处警"); + } + } + return businessPolice; + } + + @DS("slave2") + public List selectCJDList(List happenTime) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.between("cjsj", happenTime.get(0), happenTime.get(1)); + queryWrapper.groupBy("clwbrxm", "clwbrbh", "cjdxssdwdm", "cjdxssdwmc", "cjsj"); + return gBaseCJDMapper.selectCJDList(queryWrapper); + } + + public static String hashConcatenatedStrings(String a, String b) { + try { + String concatenated = a + b; + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + byte[] hash = digest.digest(concatenated.getBytes()); + StringBuilder hexString = new StringBuilder(); + for (byte b1 : hash) { + String hex = Integer.toHexString(0xff & b1); + if(hex.length() == 1) hexString.append('0'); + hexString.append(hex); + } + return hexString.toString(); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("Error while hashing", e); + } + } } diff --git a/src/main/java/com/biutag/supervision/service/StatisticsDepartService.java b/src/main/java/com/biutag/supervision/service/StatisticsDepartService.java new file mode 100644 index 0000000..1911326 --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/StatisticsDepartService.java @@ -0,0 +1,11 @@ +package com.biutag.supervision.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.biutag.supervision.pojo.entity.StatisticsDepart; +import com.biutag.supervision.mapper.StatisticsDepartMapper; +import org.springframework.stereotype.Service; + +@Service +public class StatisticsDepartService extends ServiceImpl { + +} diff --git a/src/main/java/com/biutag/supervision/service/StatisticsGroupService.java b/src/main/java/com/biutag/supervision/service/StatisticsGroupService.java new file mode 100644 index 0000000..5012593 --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/StatisticsGroupService.java @@ -0,0 +1,11 @@ +package com.biutag.supervision.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.biutag.supervision.pojo.entity.StatisticsGroup; +import com.biutag.supervision.mapper.StatisticsGroupMapper; +import org.springframework.stereotype.Service; + +@Service +public class StatisticsGroupService extends ServiceImpl { + +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 75fde56..516f3d9 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -12,6 +12,11 @@ spring: url: jdbc:mysql://172.31.217.20:31868/open-platform?serverTimezone=GMT%2B8 username: root password: ip12341234 + slave2: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://172.31.217.20:31868/negative?serverTimezone=GMT%2B8 + username: root + password: ip12341234 data: redis: host: 172.31.217.20 diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 6a2c656..0d9c482 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -12,6 +12,11 @@ spring: url: jdbc:mysql://65.47.6.109:3306/open-platform?serverTimezone=GMT%2B8&useSSL=false username: root password: ip12341234 + slave2: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://65.47.16.209:5258/csga_dwd?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF8 + username: csga_wdpc + password: csga_wdpc@123 data: redis: host: 65.47.6.109 diff --git a/src/main/resources/mapper/GBaseCJDMapper.xml b/src/main/resources/mapper/GBaseCJDMapper.xml new file mode 100644 index 0000000..5fd55b6 --- /dev/null +++ b/src/main/resources/mapper/GBaseCJDMapper.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/GBaseJJDMapper.xml b/src/main/resources/mapper/GBaseJJDMapper.xml new file mode 100644 index 0000000..fb4e4c1 --- /dev/null +++ b/src/main/resources/mapper/GBaseJJDMapper.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file