From 137ede43422c698ab47503aa1e33a47ce7987ece Mon Sep 17 00:00:00 2001 From: wany <13995595726@qq.com> Date: Fri, 16 Aug 2024 15:28:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=8C=E6=94=BF=E5=8C=BA=E5=88=92=E6=A0=91?= =?UTF-8?q?=EF=BC=9B=E9=97=B8=E9=98=80=E5=A2=9E=E5=8A=A0=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AttGateValveController.java | 25 ++++- .../xyt/controller/AttMeaWeirController.java | 2 +- .../xyt/controller/StAddvcdDController.java | 10 ++ .../project/xyt/entity/vo/StAddvcdTreeVo.java | 22 +++++ .../project/xyt/mapper/StAddvcdDMapper.java | 9 ++ .../project/xyt/model/AttGateValve.java | 5 +- .../project/xyt/service/StAddvcdDService.java | 92 ++++++++++++++++++- 7 files changed, 159 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/gunshi/project/xyt/entity/vo/StAddvcdTreeVo.java diff --git a/src/main/java/com/gunshi/project/xyt/controller/AttGateValveController.java b/src/main/java/com/gunshi/project/xyt/controller/AttGateValveController.java index 97544e2..3ae2cd2 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/AttGateValveController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/AttGateValveController.java @@ -9,6 +9,7 @@ import com.gunshi.core.result.R; import com.gunshi.project.xyt.entity.so.GeneralDataPage; import com.gunshi.project.xyt.model.AttGateValve; import com.gunshi.project.xyt.service.AttGateValveService; +import com.gunshi.project.xyt.service.FileAssociationsService; import com.gunshi.project.xyt.validate.markers.Insert; import com.gunshi.project.xyt.validate.markers.Update; import io.swagger.v3.oas.annotations.Operation; @@ -31,18 +32,24 @@ import java.util.Objects; @Tag(name = "闸阀信息表") @RestController @RequestMapping(value="/attGateValve") -public class AttGateValveController { +public class AttGateValveController extends AbstractCommonFileController{ @Autowired private AttGateValveService service; + @Autowired + private FileAssociationsService fileService; + @Operation(summary = "新增") @PostMapping("/insert") public R insert(@Validated(Insert.class) @RequestBody AttGateValve dto) { - dto.setValveCode(String.valueOf(IdWorker.getId())); + dto.setValveCode(IdWorker.get32UUID()); dto.setCreateTime(new Date()); boolean result = service.save(dto); + if (result){ + fileService.saveFile(dto.getFiles(), getGroupId(), dto.getValveCode()); + } return R.ok(result ? dto : null); } @@ -53,6 +60,9 @@ public class AttGateValveController { throw new IllegalArgumentException("当前数据不存在"); } boolean result = service.updateById(dto); + if (result){ + fileService.saveFile(dto.getFiles(), getGroupId(), dto.getValveCode()); + } return R.ok(result ? dto : null); } @@ -62,7 +72,11 @@ public class AttGateValveController { if (Objects.isNull(service.getById(id))) { throw new IllegalArgumentException("当前数据不存在"); } - return R.ok(service.removeById(id)); + boolean data = service.removeById(id); + if (data){ + fileService.deleteFile(getGroupId(),id.toString()); + } + return R.ok(data); } @Operation(summary = "列表") @@ -92,4 +106,9 @@ public class AttGateValveController { return R.ok(service.getById(valveCode)); } + + @Override + public String getGroupId() { + return "attGateValve"; + } } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/controller/AttMeaWeirController.java b/src/main/java/com/gunshi/project/xyt/controller/AttMeaWeirController.java index 67d63e4..b3abf72 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/AttMeaWeirController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/AttMeaWeirController.java @@ -45,7 +45,7 @@ public class AttMeaWeirController { @Operation(summary = "新增") @PostMapping("/insert") public R insert(@Validated(Insert.class) @RequestBody AttMeaWeir dto) { - dto.setWeirCode(String.valueOf(IdWorker.getId())); + dto.setWeirCode(IdWorker.get32UUID()); dto.setCreateTime(new Date()); if (StringUtils.isNotBlank(dto.getAdcd()) && Objects.isNull(stAddvcdDService.getById(dto.getAdcd()))){ throw new IllegalArgumentException("当前行政区划不存在"); diff --git a/src/main/java/com/gunshi/project/xyt/controller/StAddvcdDController.java b/src/main/java/com/gunshi/project/xyt/controller/StAddvcdDController.java index fa4ff48..7d5651e 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/StAddvcdDController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/StAddvcdDController.java @@ -1,6 +1,8 @@ package com.gunshi.project.xyt.controller; +import com.gunshi.core.annotation.Get; import com.gunshi.core.result.R; +import com.gunshi.project.xyt.entity.vo.StAddvcdTreeVo; import com.gunshi.project.xyt.model.StAddvcdD; import com.gunshi.project.xyt.service.StAddvcdDService; import com.gunshi.project.xyt.validate.markers.Insert; @@ -54,6 +56,14 @@ public class StAddvcdDController { return R.ok(service.lambdaQuery().list()); } + /** + * 行政区划树 + */ + @Get(path = "/tree", summary = "行政区划树") + public R> tree(@Schema(description = "以根节点为基础,返回数据的深度,最低到组(自然村)") @RequestParam("level") String level) { + return R.ok(service.tree(level)); + } + // @Operation(summary = "分页") // @PostMapping("/page") public R> page() { diff --git a/src/main/java/com/gunshi/project/xyt/entity/vo/StAddvcdTreeVo.java b/src/main/java/com/gunshi/project/xyt/entity/vo/StAddvcdTreeVo.java new file mode 100644 index 0000000..3d70e5a --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/vo/StAddvcdTreeVo.java @@ -0,0 +1,22 @@ +package com.gunshi.project.xyt.entity.vo; + +import com.gunshi.project.xyt.model.StAddvcdD; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +/** + * Description: + * Created by wanyan on 2024/4/7 + * + * @author wanyan + * @version 1.0 + */ +@Data +public class StAddvcdTreeVo extends StAddvcdD { + + @Schema(description = "行政区划数组") + private List children; + +} diff --git a/src/main/java/com/gunshi/project/xyt/mapper/StAddvcdDMapper.java b/src/main/java/com/gunshi/project/xyt/mapper/StAddvcdDMapper.java index 9ca0821..b4a999d 100644 --- a/src/main/java/com/gunshi/project/xyt/mapper/StAddvcdDMapper.java +++ b/src/main/java/com/gunshi/project/xyt/mapper/StAddvcdDMapper.java @@ -3,6 +3,8 @@ package com.gunshi.project.xyt.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.gunshi.project.xyt.model.StAddvcdD; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; /** * 描述: 行政区划表 @@ -12,4 +14,11 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface StAddvcdDMapper extends BaseMapper { + @Select(""" + + """) + StAddvcdD selectByAdcd(@Param("adcd") String adcd); + } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/model/AttGateValve.java b/src/main/java/com/gunshi/project/xyt/model/AttGateValve.java index d018bfc..1943a41 100644 --- a/src/main/java/com/gunshi/project/xyt/model/AttGateValve.java +++ b/src/main/java/com/gunshi/project/xyt/model/AttGateValve.java @@ -15,6 +15,7 @@ import lombok.Data; import java.io.Serializable; import java.util.Date; +import java.util.List; /** * 描述: 闸阀信息表 @@ -170,5 +171,7 @@ public class AttGateValve implements Serializable { @Schema(description="是否可手动控制") private Boolean manualOperation; - + @TableField(exist = false) + @Schema(description = "文件集合") + private List files; } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/service/StAddvcdDService.java b/src/main/java/com/gunshi/project/xyt/service/StAddvcdDService.java index 640df24..6057966 100644 --- a/src/main/java/com/gunshi/project/xyt/service/StAddvcdDService.java +++ b/src/main/java/com/gunshi/project/xyt/service/StAddvcdDService.java @@ -1,13 +1,18 @@ package com.gunshi.project.xyt.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gunshi.project.xyt.entity.vo.StAddvcdTreeVo; import com.gunshi.project.xyt.mapper.StAddvcdDMapper; import com.gunshi.project.xyt.model.StAddvcdD; +import com.gunshi.project.xyt.util.MyBeanUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Date; +import java.util.ArrayList; +import java.util.List; /** * 描述: 行政区划表 @@ -20,6 +25,91 @@ import java.util.Date; public class StAddvcdDService extends ServiceImpl { + public List tree(String level) { + List treeList = new ArrayList<>(); + //根据adcd模糊查询得到所有的行政区划 + List list = this.baseMapper.selectList(new LambdaQueryWrapper<>()); + List totalList = MyBeanUtil.collectionCopy(list, StAddvcdTreeVo.class); + //根据adcd查询行政区划信息 + StAddvcdD stAddvcdD = this.baseMapper.selectByAdcd("421181000000000"); + StAddvcdTreeVo stAddvcdTreeVo = new StAddvcdTreeVo(); + BeanUtils.copyProperties(stAddvcdD, stAddvcdTreeVo); + if ("1".equals(level)) { + treeList.add(stAddvcdTreeVo); + //当下拉深度为2时 + } else if ("2".equals(level)) { + List towns = new ArrayList<>(); + //遍历所有的行政区划 + for (StAddvcdTreeVo total : totalList) { + //后6位都是0并且6到9位不是0时为乡镇 + if ("000000".equals(total.getAdcd().substring(9)) && !"000".equals(total.getAdcd().substring(6, 9))) { + towns.add(total); + } + } + stAddvcdTreeVo.setChildren(towns); + treeList.add(stAddvcdTreeVo); + //当下拉深度为3时 + }else if("3".equals(level)){ + List towns = new ArrayList<>(); + //遍历所有的行政区划 + for (StAddvcdTreeVo total : totalList) { + //后6位都是0并且6到9位不是0时为乡镇 + if ("000000".equals(total.getAdcd().substring(9)) && !"000".equals(total.getAdcd().substring(6, 9))) { + towns.add(total); + } + } + //遍历镇 + for (StAddvcdTreeVo town : towns) { + List administrativeVillageList = new ArrayList<>(); + //遍历所有的行政区划 + for (StAddvcdTreeVo total : totalList) { + //当行政区划前9位相同并且后3位都为0并且9到12不为0时为同一乡镇下的行政村 + if (town.getAdcd().substring(0, 9).equals(total.getAdcd().substring(0, 9)) && "000".equals(total.getAdcd().substring(12)) && !"000".equals(total.getAdcd().substring(9, 12))) { + administrativeVillageList.add(total); + } + } + town.setChildren(administrativeVillageList); + } + stAddvcdTreeVo.setChildren(towns); + treeList.add(stAddvcdTreeVo); + }else{ + List towns = new ArrayList<>(); + //遍历所有的行政区划 + for (StAddvcdTreeVo total : totalList) { + //后6位都是0并且6到9位不是0时为乡镇 + if ("000000".equals(total.getAdcd().substring(9)) && !"000".equals(total.getAdcd().substring(6, 9))) { + towns.add(total); + } + } + //遍历镇 + for (StAddvcdTreeVo town : towns) { + List administrativeVillageList = new ArrayList<>(); + //遍历所有的行政区划 + for (StAddvcdTreeVo total : totalList) { + //当行政区划前9位相同并且后3位都为0并且9到12不为0时为同一乡镇下的行政村 + if (town.getAdcd().substring(0, 9).equals(total.getAdcd().substring(0, 9)) && "000".equals(total.getAdcd().substring(12)) && !"000".equals(total.getAdcd().substring(9, 12))) { + administrativeVillageList.add(total); + } + } + //遍历行政村 + for (StAddvcdTreeVo administrativeVillage : administrativeVillageList) { + List naturalVillages = new ArrayList<>(); + //遍历所有的行政区划 + for (StAddvcdTreeVo total : totalList) { + //行政区划前12为相同并且后3位不为0时为同一行政村下的自然组 + if (total.getAdcd().substring(0, 12).equals(administrativeVillage.getAdcd().substring(0, 12)) && !"000".equals(total.getAdcd().substring(12))) { + naturalVillages.add(total); + } + } + administrativeVillage.setChildren(naturalVillages); + } + town.setChildren(administrativeVillageList); + } + stAddvcdTreeVo.setChildren(towns); + treeList.add(stAddvcdTreeVo); + } + return treeList; + } }