diff --git a/src/main/java/com/biutag/supervision/mapper/GBaseAJJBXXMapper.java b/src/main/java/com/biutag/supervision/mapper/GBaseAJJBXXMapper.java new file mode 100644 index 0000000..fa6a29f --- /dev/null +++ b/src/main/java/com/biutag/supervision/mapper/GBaseAJJBXXMapper.java @@ -0,0 +1,12 @@ +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.GBaseAJJBXX; +import org.apache.ibatis.annotations.Mapper; + +@DS("slave2") +@Mapper +public interface GBaseAJJBXXMapper extends BaseMapper { + +} diff --git a/src/main/java/com/biutag/supervision/mapper/ModelClueDataMapper.java b/src/main/java/com/biutag/supervision/mapper/ModelClueDataMapper.java index 375a655..a4bb5b0 100644 --- a/src/main/java/com/biutag/supervision/mapper/ModelClueDataMapper.java +++ b/src/main/java/com/biutag/supervision/mapper/ModelClueDataMapper.java @@ -1,6 +1,5 @@ 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.ModelClue; import org.apache.ibatis.annotations.Select; @@ -8,7 +7,6 @@ import org.apache.ibatis.annotations.Select; import java.util.List; import java.util.Map; -@DS("slave2") public interface ModelClueDataMapper extends BaseMapper { @Select("${sql}") diff --git a/src/main/java/com/biutag/supervision/mapper/SupExternalDepartMapper.java b/src/main/java/com/biutag/supervision/mapper/SupExternalDepartMapper.java new file mode 100644 index 0000000..c2c7d80 --- /dev/null +++ b/src/main/java/com/biutag/supervision/mapper/SupExternalDepartMapper.java @@ -0,0 +1,7 @@ +package com.biutag.supervision.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.biutag.supervision.pojo.entity.SupExternalDepart; + +public interface SupExternalDepartMapper extends BaseMapper { +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/entity/GBaseAJJBXX.java b/src/main/java/com/biutag/supervision/pojo/entity/GBaseAJJBXX.java new file mode 100644 index 0000000..b1e372a --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/entity/GBaseAJJBXX.java @@ -0,0 +1,36 @@ +package com.biutag.supervision.pojo.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +@TableName("dwd_asj_zfba_ajjbxx") +public class GBaseAJJBXX { + + // 立案单位编码 + @TableField("LADWBMdm") + private String LADWBMdm; + + // 立案单位名称 + @TableField("LADWBMmc") + private String LADWBMmc; + + // 破案单位编码 + @TableField("PADWBMdm") + private String PADWBMdm; + + // 破案单位名称 + @TableField("PADWBMmc") + private String PADWBMmc; + + // 办案单位编码 + @TableField("BADWIDdm") + private String BADWIDdm; + + // 办案单位名称 + @TableField("BADWIDmc") + private String BADWIDmc; +} diff --git a/src/main/java/com/biutag/supervision/pojo/entity/GBaseCJD.java b/src/main/java/com/biutag/supervision/pojo/entity/GBaseCJD.java index ecc78b3..22e6c18 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/GBaseCJD.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/GBaseCJD.java @@ -1,11 +1,13 @@ package com.biutag.supervision.pojo.entity; import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Getter; import lombok.Setter; import java.util.Date; +@TableName("dwd_asj_zhtx_cjd") @Setter @Getter public class GBaseCJD { diff --git a/src/main/java/com/biutag/supervision/pojo/entity/GBaseJJD.java b/src/main/java/com/biutag/supervision/pojo/entity/GBaseJJD.java index 4ae05ed..1b20a6b 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/GBaseJJD.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/GBaseJJD.java @@ -1,11 +1,13 @@ package com.biutag.supervision.pojo.entity; import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Getter; import lombok.Setter; import java.util.Date; +@TableName("dwd_asj_zhtx_jjd") @Setter @Getter public class GBaseJJD { diff --git a/src/main/java/com/biutag/supervision/pojo/entity/ModelClue.java b/src/main/java/com/biutag/supervision/pojo/entity/ModelClue.java index 4c13b6b..8961003 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/ModelClue.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/ModelClue.java @@ -52,7 +52,16 @@ public class ModelClue { // 数据详情 JSON private String data; - @TableField(exist = false) + // 问题ID + @TableField("negative_id") + private String negativeId; + + // 状态:0-未处理 1-已处理 + @TableField("status") + private Integer status; + + // 外部主键 + @TableField("unique_key") private String uniqueKey; } \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/entity/SupExternalDepart.java b/src/main/java/com/biutag/supervision/pojo/entity/SupExternalDepart.java new file mode 100644 index 0000000..5b02af3 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/entity/SupExternalDepart.java @@ -0,0 +1,51 @@ +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 SupExternalDepart { + + // id + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + // 外部单位id + @TableField("external_id") + private String externalId; + + // 外部单位名称 + @TableField("external_name") + private String externalName; + + // 外部来源 + @TableField("source") + private String source; + + // 内部单位id + @TableField("internal_id") + private String internalId; + + // 内部单位名称 + @TableField("internal_name") + private String internalName; + + // 内部单位短名称 + @TableField("internal_short_name") + private String internalShortName; + + // 创建时间 + @TableField("create_time") + private LocalDateTime createTime; + + // 更新时间 + @TableField("update_time") + private LocalDateTime updateTime; + +} \ 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 90ee27a..37bd829 100644 --- a/src/main/java/com/biutag/supervision/service/BusinessDepartService.java +++ b/src/main/java/com/biutag/supervision/service/BusinessDepartService.java @@ -37,6 +37,8 @@ public class BusinessDepartService extends ServiceImpl page(BusinessQueryParam businessQueryParam) { // if (businessQueryParam.getDepartName()!=null && businessQueryParam.getDepartName().equals("开始导入今年所有的数据")) { // LocalDate start = LocalDate.parse("2024-05-23"); @@ -63,6 +65,11 @@ public class BusinessDepartService extends ServiceImpl queryWrapper = new QueryWrapper<>(); queryWrapper .like(StrUtil.isNotBlank(businessQueryParam.getDepartName()), "depart_name", businessQueryParam.getDepartName()) diff --git a/src/main/java/com/biutag/supervision/service/ModelClueService.java b/src/main/java/com/biutag/supervision/service/ModelClueService.java index 7a8f524..a281f76 100644 --- a/src/main/java/com/biutag/supervision/service/ModelClueService.java +++ b/src/main/java/com/biutag/supervision/service/ModelClueService.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.biutag.supervision.constants.enums.*; @@ -20,10 +21,6 @@ import org.springframework.transaction.annotation.Transactional; import java.text.SimpleDateFormat; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.*; @@ -52,6 +49,8 @@ public class ModelClueService extends ServiceImpl { public final SupDepartMapper supDepartMapper; + public final SupExternalDepartMapper supExternalDepartMapper; + public Page page(ModelClueQueryParam param) { if (Objects.nonNull(param.getModelIds()) && param.getModelIds().isEmpty()) { return new Page().setTotal(0).setRecords(new ArrayList<>()); @@ -168,10 +167,10 @@ public class ModelClueService extends ServiceImpl { for (ModelClue modelClue : modelClues) { modelClue.setModelId(modelId); modelClue.setCreateTime(LocalDateTime.now()); - SupDepart supDepart = supDepartMapper.selectOne(new LambdaQueryWrapper().eq(SupDepart::getCode, modelClue.getInvolveDepartId())); - if (supDepart != null && supDepart.getShortName() != null && !supDepart.getShortName().isEmpty()) { - modelClue.setInvolveDepartName(supDepart.getShortName()); - modelClue.setInvolveDepartId(supDepart.getId()); + SupExternalDepart supExternalDepart = supExternalDepartMapper.selectOne(new LambdaQueryWrapper().eq(SupExternalDepart::getExternalId, modelClue.getInvolveDepartId())); + if (supExternalDepart != null && supExternalDepart.getInternalShortName() != null && !supExternalDepart.getInternalShortName().isEmpty()) { + modelClue.setInvolveDepartName(supExternalDepart.getInternalShortName()); + modelClue.setInvolveDepartId(supExternalDepart.getInternalId()); } } modelClueMapper.insert(modelClues); @@ -182,16 +181,27 @@ public class ModelClueService extends ServiceImpl { } public List getModelClueBySql(String sql, Integer modelId) { + List oldUniqueKeys = this.listObjs(new LambdaQueryWrapper().select(ModelClue::getUniqueKey).eq(ModelClue::getStatus, 0), String::valueOf); List modelClues = modelClueDataMapper.selectDataByDynamicSql(sql); List uniqueKeys = modelClues.stream().map(ModelClue::getUniqueKey).filter(k -> k != null && !k.isEmpty()).toList(); - String newSql = generateNewSql(sql, uniqueKeys); + List changeStatusIds = oldUniqueKeys.stream().filter(item -> !uniqueKeys.contains(item)).toList(); + if (!changeStatusIds.isEmpty()) { + modelClueMapper.update(null, new LambdaUpdateWrapper().in(ModelClue::getUniqueKey, changeStatusIds).set(ModelClue::getStatus, 1)); + } + List needsInsertIds = uniqueKeys.stream().filter(item -> !oldUniqueKeys.contains(item)).toList(); + if (needsInsertIds.isEmpty()) { + return new ArrayList<>(); + } + List needsInsertModelClues = modelClues.stream().filter(item -> needsInsertIds.contains(item.getUniqueKey())).toList(); + String newSql = generateNewSql(sql, needsInsertIds); List> allData = modelClueDataMapper.selectByUniqueKeys(newSql); String originalFieldName = getKeyFieldName(sql); - for (ModelClue modelClue : modelClues) { + for (ModelClue modelClue : needsInsertModelClues) { for (Map data : allData) { String keyColumn = (String) data.get(originalFieldName); if (Objects.equals(keyColumn, modelClue.getUniqueKey())) { modelClue.setData(JSONObject.toJSONString(data)); + modelClue.setStatus(0); List modelNos = new ArrayList<>(List.of(1)); if (modelNos.contains(modelId)) { String thingDesc = modelClue.getThingDesc(); @@ -207,7 +217,7 @@ public class ModelClueService extends ServiceImpl { } } } - return modelClues; + return needsInsertModelClues; } private static String getDateString(Object param) { diff --git a/src/main/java/com/biutag/supervision/service/SupExternalDepartService.java b/src/main/java/com/biutag/supervision/service/SupExternalDepartService.java new file mode 100644 index 0000000..2a4e780 --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/SupExternalDepartService.java @@ -0,0 +1,120 @@ +package com.biutag.supervision.service; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.biutag.supervision.mapper.*; +import com.biutag.supervision.pojo.entity.*; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +@Slf4j +@RequiredArgsConstructor +@Service +public class SupExternalDepartService extends ServiceImpl { + + private final SupExternalDepartMapper supExternalDepartMapper; + + private final GBaseAJJBXXMapper gBaseAJJBXXMapper; + + private final SupDepartMapper supDepartMapper; + + private final GBaseJJDMapper gBaseJJDMapper; + + private final GBaseCJDMapper gBaseCJDMapper; + + public void insertPreData() { + List supExternalDeparts = new ArrayList<>(); + Set dms = new HashSet<>(); + selectAJJBXX(1, supExternalDeparts, dms); + selectAJJBXX(2, supExternalDeparts, dms); + selectAJJBXX(3, supExternalDeparts, dms); + selectJJDandCJD(dms, supExternalDeparts); + List supDeparts = supDepartMapper.selectList(new LambdaQueryWrapper().in(SupDepart::getCode, dms)); + for (SupExternalDepart supExternalDepart : supExternalDeparts) { + SupDepart supDepart = supDeparts.stream().filter(item -> item.getCode().equals(supExternalDepart.getExternalId())).findFirst().orElse(null); + if (supDepart != null) { + supExternalDepart.setInternalId(supDepart.getId()); + supExternalDepart.setInternalName(supDepart.getName()); + supExternalDepart.setInternalShortName(supDepart.getShortName()); + supExternalDepart.setCreateTime(LocalDateTime.now()); + } + } + supExternalDepartMapper.insert(supExternalDeparts); + } + + private void selectJJDandCJD(Set dms, List supExternalDeparts) { + List gBaseJJDS = gBaseJJDMapper.selectList(new QueryWrapper().select("DISTINCT gxdwdm, gxdwmc")); + if (!gBaseJJDS.isEmpty()) { + gBaseJJDS.forEach(item -> { + if (item != null && !dms.contains(item.getGxdwdm())) { + SupExternalDepart supExternalDepart = new SupExternalDepart(); + supExternalDepart.setExternalId(item.getGxdwdm() == null ? "" : item.getGxdwdm()); + supExternalDepart.setExternalName(item.getGxdwmc() == null ? "" : item.getGxdwmc()); + dms.add(item.getGxdwdm()); + supExternalDepart.setSource("情指行"); + supExternalDeparts.add(supExternalDepart); + } + }); + } + List gBaseCJDS = gBaseCJDMapper.selectList(new QueryWrapper().select("DISTINCT cjdxssdwdm, cjdxssdwmc")); + if (!gBaseCJDS.isEmpty()) { + gBaseCJDS.forEach(item -> { + if (item != null && !dms.contains(item.getCjdxssdwdm())) { + SupExternalDepart supExternalDepart = new SupExternalDepart(); + supExternalDepart.setExternalId(item.getCjdxssdwdm() == null ? "" : item.getCjdxssdwdm()); + supExternalDepart.setExternalName(item.getCjdxssdwmc() == null ? "" : item.getCjdxssdwmc()); + dms.add(item.getCjdxssdwdm()); + supExternalDepart.setSource("情指行"); + supExternalDeparts.add(supExternalDepart); + } + }); + } + } + + @DS("slave2") + private void selectAJJBXX(int type, List result, Set dms) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (type == 1) { + queryWrapper.select("DISTINCT LADWBMdm, LADWBMmc"); + } else if (type == 2) { + queryWrapper.select("DISTINCT PADWBMdm, PADWBMmc"); + } else if (type == 3) { + queryWrapper.select("DISTINCT BADWIDdm, BADWIDmc"); + } + List supExternalDeparts = gBaseAJJBXXMapper.selectList(queryWrapper); + if (!supExternalDeparts.isEmpty()) { + supExternalDeparts.forEach(item -> { + if (item != null) { + SupExternalDepart supExternalDepart = new SupExternalDepart(); + if (type == 1) { + supExternalDepart.setExternalId(item.getLADWBMdm() == null ? "" : item.getLADWBMdm()); + supExternalDepart.setExternalName(item.getLADWBMmc() == null ? "" : item.getLADWBMmc()); + } else if (type == 2 && !dms.contains(item.getPADWBMdm())) { + supExternalDepart.setExternalId(item.getPADWBMdm() == null ? "" : item.getPADWBMdm()); + supExternalDepart.setExternalName(item.getPADWBMmc() == null ? "" : item.getPADWBMmc()); + dms.add(item.getPADWBMdm()); + } else if (type == 3 && !dms.contains(item.getBADWIDdm())) { + supExternalDepart.setExternalId(item.getBADWIDdm() == null ? "" : item.getBADWIDdm()); + supExternalDepart.setExternalName(item.getBADWIDmc() == null ? "" : item.getBADWIDmc()); + dms.add(item.getBADWIDdm()); + } + supExternalDepart.setSource("情指行"); + result.add(supExternalDepart); + } + }); + } + if (dms.isEmpty() && type == 1) { + dms.addAll(result.stream().map(SupExternalDepart::getExternalId).collect(Collectors.toSet())); + } + } +}