Browse Source

fit: 模型任务分发实体

main
wxc 1 year ago
parent
commit
ae6ca8d886
  1. 31
      src/main/java/com/biutag/supervision/controller/sensitivePerception/ModelClueTaskController.java
  2. 27
      src/main/java/com/biutag/supervision/controller/system/PoliceController.java
  3. 8
      src/main/java/com/biutag/supervision/mapper/ModelClueTaskMapper.java
  4. 40
      src/main/java/com/biutag/supervision/pojo/entity/ModelClueTask.java
  5. 4
      src/main/java/com/biutag/supervision/pojo/entity/SupPolice.java
  6. 32
      src/main/java/com/biutag/supervision/pojo/model/ModelClueTaskModel.java
  7. 2
      src/main/java/com/biutag/supervision/pojo/model/PoliceModel.java
  8. 13
      src/main/java/com/biutag/supervision/service/ModelClueService.java
  9. 48
      src/main/java/com/biutag/supervision/service/ModelClueTaskService.java
  10. 22
      src/main/java/com/biutag/supervision/service/SupDepartService.java
  11. 8
      src/main/java/com/biutag/supervision/service/SupPoliceService.java
  12. 2
      src/main/resources/mapper/SupPoliceMapper.xml
  13. 2
      src/test/java/com/biutag/supervision/tools/GenCodeTests.java

31
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<ModelClueTaskModel>> page(ModelClueQueryParam param) {
return Result.success(modelClueTaskService.page(param));
}
}

27
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<Boolean> add(@RequestBody SupPolice police) {
SupPolice policeByEmpNo = policeService.getOne(new LambdaQueryWrapper<SupPolice>().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<SupPolice>().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<Boolean> update(@RequestBody SupPolice police) {
SupPolice policeByEmpNo = policeService.getOne(new LambdaQueryWrapper<SupPolice>().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<SupPolice>().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));
}

8
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<ModelClueTask> {
}

40
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;
}

4
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;

32
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;
}

2
src/main/java/com/biutag/supervision/pojo/model/PoliceModel.java

@ -104,4 +104,6 @@ public class PoliceModel {
// 警员角色
private String policeRole;
private String level;
}

13
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<ModelClueMapper, ModelClue> {
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<ModelClueMapper, ModelClue> {
return list(new LambdaQueryWrapper<ModelClue>().eq(ModelClue::getModelId, modelId).eq(ModelClue::getDistributionState, ModelDistributionStateEnum.UNDISTRIBUTED.getValue()));
}
@Transactional(rollbackFor = Exception.class)
public boolean distribution(Integer modelId) {
List<ModelClue> 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<ModelClueMapper, ModelClue> {
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;
}

48
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<ModelClueTaskMapper, ModelClueTask> {
private final ModelMapper modelMapper;
public Page<ModelClueTaskModel> page(ModelClueQueryParam param) {
LambdaQueryWrapper<ModelClueTask> queryWrapper = new LambdaQueryWrapper<ModelClueTask>()
.orderByDesc(ModelClueTask::getDistributionTime);
Page<ModelClueTask> page = page(Page.of(param.getCurrent(), param.getSize()), queryWrapper);
if (page.getRecords().isEmpty()) {
return new Page<ModelClueTaskModel>().setRecords(new ArrayList<>()).setTotal(0);
}
Set<Integer> modelIds = page.getRecords().stream().map(ModelClueTask::getModelId).collect(Collectors.toSet());
List<Model> models = modelMapper.selectBatchIds(modelIds);
List<ModelClueTaskModel> 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<ModelClueTaskModel>().setRecords(list).setTotal(page.getTotal());
}
}

22
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<SupDepartMapper, SupDepart> {
public List<DepartTree> buildTree(List<SupDepart> departs) {
Map<String, List<DepartTree>> childMap = new HashMap<>();
List<DepartTree> 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<String> authDepartIds = new ArrayList<>();
if (!firstAuth) {
List<SupDepart> 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<DepartTree> 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);
}
}

8
src/main/java/com/biutag/supervision/service/SupPoliceService.java

@ -76,4 +76,12 @@ public class SupPoliceService extends ServiceImpl<SupPoliceMapper, SupPolice> {
return exists(new LambdaQueryWrapper<SupPolice>().in(SupPolice::getOrgId, orgIds));
}
public Boolean ge(String empNo) {
return exists(new LambdaQueryWrapper<SupPolice>().in(SupPolice::getEmpNo, empNo));
}
public Boolean existsByIdCode(String idCode) {
return exists(new LambdaQueryWrapper<SupPolice>().in(SupPolice::getIdCode, idCode));
}
}

2
src/main/resources/mapper/SupPoliceMapper.xml

@ -7,7 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="queryPage" resultType="com.biutag.supervision.pojo.model.PoliceModel">
select p.id, p.name, p.emp_no, p.id_code, p.job, p.mobile, p.person_status, p.org_id, p.avatar_url, p.created_at, p.updated_at,
p.position, p.person_type, p.police_role, p.employment_date,
d.name depart_name, d.short_name depart_short_name, d1.short_name parent_depart_short_name
d.name depart_name, d.short_name depart_short_name, d1.short_name parent_depart_short_name, d.level
from sup_police p
left join sup_depart d on p.org_id = d.id
left join sup_depart d1 on d.pid = d1.id and d1.level = 2

2
src/test/java/com/biutag/supervision/tools/GenCodeTests.java

@ -25,7 +25,7 @@ public class GenCodeTests {
@Test
public void genEntity() throws TemplateException, IOException {
String tableName = "data_case_verif";
String tableName = "model_clue_task";
String tableSchema = "negative";
boolean genMapper = true;
boolean genService = true;

Loading…
Cancel
Save