From ae6ca8d8865ff10156b5ece7369c314bc812ae24 Mon Sep 17 00:00:00 2001 From: wxc <191104855@qq.com> Date: Fri, 18 Oct 2024 09:26:12 +0800 Subject: [PATCH] =?UTF-8?q?fit:=20=E6=A8=A1=E5=9E=8B=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=88=86=E5=8F=91=E5=AE=9E=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ModelClueTaskController.java | 31 ++++++++++++ .../controller/system/PoliceController.java | 27 ++++++++++- .../mapper/ModelClueTaskMapper.java | 8 ++++ .../pojo/entity/ModelClueTask.java | 40 ++++++++++++++++ .../supervision/pojo/entity/SupPolice.java | 4 ++ .../pojo/model/ModelClueTaskModel.java | 32 +++++++++++++ .../supervision/pojo/model/PoliceModel.java | 2 + .../supervision/service/ModelClueService.java | 13 +++++ .../service/ModelClueTaskService.java | 48 +++++++++++++++++++ .../supervision/service/SupDepartService.java | 22 ++++++++- .../supervision/service/SupPoliceService.java | 8 ++++ src/main/resources/mapper/SupPoliceMapper.xml | 2 +- .../supervision/tools/GenCodeTests.java | 2 +- 13 files changed, 234 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/biutag/supervision/controller/sensitivePerception/ModelClueTaskController.java create mode 100644 src/main/java/com/biutag/supervision/mapper/ModelClueTaskMapper.java create mode 100644 src/main/java/com/biutag/supervision/pojo/entity/ModelClueTask.java create mode 100644 src/main/java/com/biutag/supervision/pojo/model/ModelClueTaskModel.java create mode 100644 src/main/java/com/biutag/supervision/service/ModelClueTaskService.java diff --git a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ModelClueTaskController.java b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ModelClueTaskController.java new file mode 100644 index 0000000..7f11f4e --- /dev/null +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ModelClueTaskController.java @@ -0,0 +1,31 @@ +package com.biutag.supervision.controller.sensitivePerception; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.biutag.supervision.pojo.Result; +import com.biutag.supervision.pojo.model.ModelClueModel; +import com.biutag.supervision.pojo.model.ModelClueTaskModel; +import com.biutag.supervision.pojo.param.ModelClueQueryParam; +import com.biutag.supervision.service.ModelClueService; +import com.biutag.supervision.service.ModelClueTaskService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author wxc + * @date 2024/10/16 + */ +@RequestMapping("model/clue/tasks") +@RequiredArgsConstructor +@RestController +public class ModelClueTaskController { + + private final ModelClueTaskService modelClueTaskService; + + @GetMapping + public Result> page(ModelClueQueryParam param) { + return Result.success(modelClueTaskService.page(param)); + } + +} diff --git a/src/main/java/com/biutag/supervision/controller/system/PoliceController.java b/src/main/java/com/biutag/supervision/controller/system/PoliceController.java index 5a6a7c2..6886f37 100644 --- a/src/main/java/com/biutag/supervision/controller/system/PoliceController.java +++ b/src/main/java/com/biutag/supervision/controller/system/PoliceController.java @@ -3,23 +3,26 @@ package com.biutag.supervision.controller.system; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.biutag.supervision.pojo.Result; import com.biutag.supervision.pojo.domain.PoliceAuth; import com.biutag.supervision.pojo.entity.NegDepartAuthority; import com.biutag.supervision.pojo.entity.NegSourceAuthority; +import com.biutag.supervision.pojo.entity.SupDepart; import com.biutag.supervision.pojo.entity.SupPolice; import com.biutag.supervision.pojo.model.PoliceModel; import com.biutag.supervision.pojo.param.PoliceQueryParam; import com.biutag.supervision.service.NegDepartAuthorityService; import com.biutag.supervision.service.NegSourceAuthorityService; +import com.biutag.supervision.service.SupDepartService; import com.biutag.supervision.service.SupPoliceService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; -import java.time.LocalDateTime; import java.util.Date; import java.util.List; +import java.util.Objects; @RequestMapping("police") @RequiredArgsConstructor @@ -28,6 +31,8 @@ public class PoliceController { private final SupPoliceService policeService; + private final SupDepartService departService; + private final NegDepartAuthorityService negDepartAuthorityService; private final NegSourceAuthorityService negSourceAuthorityService; @@ -39,6 +44,16 @@ public class PoliceController { @PostMapping public Result add(@RequestBody SupPolice police) { + SupPolice policeByEmpNo = policeService.getOne(new LambdaQueryWrapper().eq(SupPolice::getEmpNo, police.getEmpNo())); + if (Objects.nonNull(policeByEmpNo)) { + SupDepart depart = departService.getById(policeByEmpNo.getOrgId()); + throw new RuntimeException(String.format("该人员[%s]已存在于“%s”单位中,请联系二级机构或市局管理员以进行人员调整。", police.getEmpNo(), depart.getName())); + } + SupPolice one = policeService.getOne(new LambdaQueryWrapper().eq(SupPolice::getIdCode, police.getIdCode())); + if (Objects.nonNull(one)) { + SupDepart depart = departService.getById(one.getOrgId()); + throw new RuntimeException(String.format("该人员[%s]已存在于“%s”单位中,请联系二级机构或市局管理员以进行人员调整。", police.getIdCode(), depart.getName())); + } police.setId(IdUtil.getSnowflakeNextIdStr()); police.setUpdatedAt(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_FORMAT)); police.setCreatedAt(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_FORMAT)); @@ -47,6 +62,16 @@ public class PoliceController { @PutMapping public Result update(@RequestBody SupPolice police) { + SupPolice policeByEmpNo = policeService.getOne(new LambdaQueryWrapper().eq(SupPolice::getEmpNo, police.getEmpNo()).ne(SupPolice::getId, police.getId())); + if (Objects.nonNull(policeByEmpNo)) { + SupDepart depart = departService.getById(policeByEmpNo.getOrgId()); + throw new RuntimeException(String.format("该人员[%s]已存在于“%s”单位中,请联系二级机构或市局管理员以进行人员调整。", police.getEmpNo(), depart.getName())); + } + SupPolice one = policeService.getOne(new LambdaQueryWrapper().eq(SupPolice::getIdCode, police.getIdCode()).ne(SupPolice::getId, police.getId())); + if (Objects.nonNull(one)) { + SupDepart depart = departService.getById(one.getOrgId()); + throw new RuntimeException(String.format("该人员[%s]已存在于“%s”单位中,请联系二级机构或市局管理员以进行人员调整。", police.getIdCode(), depart.getName())); + } police.setUpdatedAt(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_FORMAT)); return Result.success(policeService.updateById(police)); } diff --git a/src/main/java/com/biutag/supervision/mapper/ModelClueTaskMapper.java b/src/main/java/com/biutag/supervision/mapper/ModelClueTaskMapper.java new file mode 100644 index 0000000..3274a9f --- /dev/null +++ b/src/main/java/com/biutag/supervision/mapper/ModelClueTaskMapper.java @@ -0,0 +1,8 @@ +package com.biutag.supervision.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.biutag.supervision.pojo.entity.ModelClueTask; + +public interface ModelClueTaskMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/entity/ModelClueTask.java b/src/main/java/com/biutag/supervision/pojo/entity/ModelClueTask.java new file mode 100644 index 0000000..b47227c --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/entity/ModelClueTask.java @@ -0,0 +1,40 @@ +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.fasterxml.jackson.annotation.JsonFormat; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; + +@Setter +@Getter +public class ModelClueTask { + + // + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + // 任务名称 + @TableField("task_name") + private String taskName; + + // 模型名称 + @TableField("model_id") + private Integer modelId; + + // 下发时间 + @TableField("distribution_time") + @JsonFormat(pattern = "YYYY-MM-dd HH:mm") + private LocalDateTime distributionTime; + + // 条数 + @TableField("size") + private Integer size; + + + private String distributionMethod; + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/entity/SupPolice.java b/src/main/java/com/biutag/supervision/pojo/entity/SupPolice.java index d2d8e7b..7950426 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/SupPolice.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/SupPolice.java @@ -3,6 +3,7 @@ package com.biutag.supervision.pojo.entity; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.fasterxml.jackson.annotation.JsonFormat; +import jakarta.validation.constraints.NotBlank; import lombok.Getter; import lombok.Setter; @@ -26,10 +27,12 @@ public class SupPolice { private String districtId; // 组织机构id + @NotBlank @TableField("org_id") private String orgId; // 警号 + @NotBlank @TableField("emp_no") private String empNo; @@ -74,6 +77,7 @@ public class SupPolice { private String email; // 身份证 + @NotBlank @TableField("id_code") private String idCode; diff --git a/src/main/java/com/biutag/supervision/pojo/model/ModelClueTaskModel.java b/src/main/java/com/biutag/supervision/pojo/model/ModelClueTaskModel.java new file mode 100644 index 0000000..1e3a427 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/model/ModelClueTaskModel.java @@ -0,0 +1,32 @@ +package com.biutag.supervision.pojo.model; + +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; + +/** + * @author wxc + * @date 2024/10/17 + */ +@Setter +@Getter +public class ModelClueTaskModel { + + private Integer id; + + // 任务名称 + private String taskName; + + // 模型名称 + private String modelName; + + // 下发时间 + private LocalDateTime distributionTime; + + // 条数 + private String size; + + private LocalDateTime createTime; + +} diff --git a/src/main/java/com/biutag/supervision/pojo/model/PoliceModel.java b/src/main/java/com/biutag/supervision/pojo/model/PoliceModel.java index a5529b7..26f13f8 100644 --- a/src/main/java/com/biutag/supervision/pojo/model/PoliceModel.java +++ b/src/main/java/com/biutag/supervision/pojo/model/PoliceModel.java @@ -104,4 +104,6 @@ public class PoliceModel { // 警员角色 private String policeRole; + private String level; + } diff --git a/src/main/java/com/biutag/supervision/service/ModelClueService.java b/src/main/java/com/biutag/supervision/service/ModelClueService.java index 0812582..c4523dd 100644 --- a/src/main/java/com/biutag/supervision/service/ModelClueService.java +++ b/src/main/java/com/biutag/supervision/service/ModelClueService.java @@ -11,11 +11,13 @@ import com.biutag.supervision.mapper.ModelMapper; import com.biutag.supervision.pojo.dto.NegativeDto; import com.biutag.supervision.pojo.entity.Model; import com.biutag.supervision.pojo.entity.ModelClue; +import com.biutag.supervision.pojo.entity.ModelClueTask; import com.biutag.supervision.pojo.entity.SupDepart; import com.biutag.supervision.pojo.model.ModelClueModel; import com.biutag.supervision.pojo.param.ModelClueQueryParam; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.ArrayList; @@ -30,6 +32,8 @@ public class ModelClueService extends ServiceImpl { private final ModelMapper modelMapper; + private final ModelClueTaskService modelClueTaskService; + private final NegativeService negativeService; public final SupDepartService departService; @@ -63,9 +67,11 @@ public class ModelClueService extends ServiceImpl { return list(new LambdaQueryWrapper().eq(ModelClue::getModelId, modelId).eq(ModelClue::getDistributionState, ModelDistributionStateEnum.UNDISTRIBUTED.getValue())); } + @Transactional(rollbackFor = Exception.class) public boolean distribution(Integer modelId) { List modelClues = listByUnDistributed(modelId); Model model = modelMapper.selectById(modelId); + LocalDateTime now = LocalDateTime.now(); modelClues.forEach(item -> { if (Objects.isNull(item.getInvolveDepartId())) { throw new RuntimeException("涉及单位不能为空..."); @@ -114,6 +120,13 @@ public class ModelClueService extends ServiceImpl { item.setUpdateTime(LocalDateTime.now()); updateById(item); }); + ModelClueTask modelClueTask = new ModelClueTask(); + modelClueTask.setModelId(modelId); + modelClueTask.setSize(modelClues.size()); + modelClueTask.setDistributionTime(now); + // 下发方式 + modelClueTask.setDistributionMethod(model.getDistributionMethod()); + modelClueTaskService.save(modelClueTask); return true; } diff --git a/src/main/java/com/biutag/supervision/service/ModelClueTaskService.java b/src/main/java/com/biutag/supervision/service/ModelClueTaskService.java new file mode 100644 index 0000000..d5e4119 --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/ModelClueTaskService.java @@ -0,0 +1,48 @@ +package com.biutag.supervision.service; + +import cn.hutool.core.bean.BeanUtil; +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.ModelClueTaskMapper; +import com.biutag.supervision.mapper.ModelMapper; +import com.biutag.supervision.pojo.entity.Model; +import com.biutag.supervision.pojo.entity.ModelClueTask; +import com.biutag.supervision.pojo.model.ModelClueTaskModel; +import com.biutag.supervision.pojo.param.ModelClueQueryParam; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +@RequiredArgsConstructor +@Service +public class ModelClueTaskService extends ServiceImpl { + + private final ModelMapper modelMapper; + + public Page page(ModelClueQueryParam param) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .orderByDesc(ModelClueTask::getDistributionTime); + + Page page = page(Page.of(param.getCurrent(), param.getSize()), queryWrapper); + if (page.getRecords().isEmpty()) { + return new Page().setRecords(new ArrayList<>()).setTotal(0); + } + Set modelIds = page.getRecords().stream().map(ModelClueTask::getModelId).collect(Collectors.toSet()); + List models = modelMapper.selectBatchIds(modelIds); + List list = page.getRecords().stream().map(item -> { + ModelClueTaskModel taskModel = new ModelClueTaskModel(); + BeanUtil.copyProperties(item, taskModel); + String modelName = models.stream().filter(model -> model.getId().equals(item.getModelId())).findFirst().map(Model::getModelName).orElse(""); + taskModel.setModelName(modelName); + return taskModel; + }).toList(); + return new Page().setRecords(list).setTotal(page.getTotal()); + } + +} diff --git a/src/main/java/com/biutag/supervision/service/SupDepartService.java b/src/main/java/com/biutag/supervision/service/SupDepartService.java index c833c0f..b8c5d84 100644 --- a/src/main/java/com/biutag/supervision/service/SupDepartService.java +++ b/src/main/java/com/biutag/supervision/service/SupDepartService.java @@ -4,10 +4,13 @@ import cn.hutool.core.util.StrUtil; 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.common.UserContextHolder; import com.biutag.supervision.constants.AppConstants; +import com.biutag.supervision.constants.enums.RoleCodeEnum; import com.biutag.supervision.constants.enums.StatusEnum; -import com.biutag.supervision.pojo.entity.SupDepart; import com.biutag.supervision.mapper.SupDepartMapper; +import com.biutag.supervision.pojo.entity.SupDepart; +import com.biutag.supervision.pojo.model.UserAuth; import com.biutag.supervision.pojo.param.DepartQueryParam; import com.biutag.supervision.pojo.param.DepartTreeListParam; import com.biutag.supervision.pojo.vo.DepartTree; @@ -109,13 +112,28 @@ public class SupDepartService extends ServiceImpl { public List buildTree(List departs) { Map> childMap = new HashMap<>(); List tree = new ArrayList<>(); + UserAuth user = UserContextHolder.getCurrentUser(); + // 权限 + if (!AppConstants.USER_TYPE_SUPER.equals(user.getUserType()) && (user.getRoleCodes().isEmpty() || user.getAuthDepartIds().isEmpty())) { + return tree; + } + // 市局权限 + boolean firstAuth = AppConstants.USER_TYPE_SUPER.equals(user.getUserType()) || user.getRoleCodes().contains(RoleCodeEnum.FIRST_ADMIN.getCode()); + List authDepartIds = new ArrayList<>(); + if (!firstAuth) { + List authDeparts = departs.stream().filter(item -> user.getAuthDepartIds().contains(item.getId())).toList(); + Integer maxLevel = authDeparts.stream().map(SupDepart::getLevel).max(Integer::compareTo).get(); + authDepartIds = authDeparts.stream().filter(item -> maxLevel.equals(item.getLevel())).map(SupDepart::getId).toList(); + } for (SupDepart depart : departs) { DepartTree node = new DepartTree(); BeanUtils.copyProperties(depart, node); node.setHasChildren(!depart.getLevel().equals(4) && departs.stream().anyMatch(item -> node.getId().equals(item.getPid()))); List children = childMap.computeIfAbsent(node.getPid(), k -> new ArrayList<>()); children.add(node); - if (AppConstants.ROOT_DEPART_ID.equals(node.getId())) { + if (firstAuth && AppConstants.ROOT_DEPART_ID.equals(node.getId())) { + tree.add(node); + } else if (authDepartIds.contains(node.getId())) { tree.add(node); } } diff --git a/src/main/java/com/biutag/supervision/service/SupPoliceService.java b/src/main/java/com/biutag/supervision/service/SupPoliceService.java index cb417e4..7c76285 100644 --- a/src/main/java/com/biutag/supervision/service/SupPoliceService.java +++ b/src/main/java/com/biutag/supervision/service/SupPoliceService.java @@ -76,4 +76,12 @@ public class SupPoliceService extends ServiceImpl { return exists(new LambdaQueryWrapper().in(SupPolice::getOrgId, orgIds)); } + public Boolean ge(String empNo) { + return exists(new LambdaQueryWrapper().in(SupPolice::getEmpNo, empNo)); + } + + public Boolean existsByIdCode(String idCode) { + return exists(new LambdaQueryWrapper().in(SupPolice::getIdCode, idCode)); + } + } diff --git a/src/main/resources/mapper/SupPoliceMapper.xml b/src/main/resources/mapper/SupPoliceMapper.xml index a7e9447..5ed31c5 100644 --- a/src/main/resources/mapper/SupPoliceMapper.xml +++ b/src/main/resources/mapper/SupPoliceMapper.xml @@ -7,7 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"