行政区划树;闸阀增加附件

master
wany 2024-08-16 15:28:07 +08:00
parent a7a5d43d9f
commit 137ede4342
7 changed files with 159 additions and 6 deletions

View File

@ -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<AttGateValve> 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";
}
}

View File

@ -45,7 +45,7 @@ public class AttMeaWeirController {
@Operation(summary = "新增")
@PostMapping("/insert")
public R<AttMeaWeir> 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("当前行政区划不存在");

View File

@ -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<List<StAddvcdTreeVo>> tree(@Schema(description = "以根节点为基础,返回数据的深度,最低到组(自然村)") @RequestParam("level") String level) {
return R.ok(service.tree(level));
}
// @Operation(summary = "分页")
// @PostMapping("/page")
public R<List<StAddvcdD>> page() {

View File

@ -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<StAddvcdTreeVo> children;
}

View File

@ -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<StAddvcdD> {
@Select("""
<script>
select * from "public".st_addvcd_d where adcd = #{adcd}
</script>
""")
StAddvcdD selectByAdcd(@Param("adcd") String adcd);
}

View File

@ -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<FileAssociations> files;
}

View File

@ -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<StAddvcdDMapper, StAddvcdD>
{
public List<StAddvcdTreeVo> tree(String level) {
List<StAddvcdTreeVo> treeList = new ArrayList<>();
//根据adcd模糊查询得到所有的行政区划
List<StAddvcdD> list = this.baseMapper.selectList(new LambdaQueryWrapper<>());
List<StAddvcdTreeVo> 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<StAddvcdTreeVo> 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<StAddvcdTreeVo> 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<StAddvcdTreeVo> 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<StAddvcdTreeVo> 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<StAddvcdTreeVo> 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<StAddvcdTreeVo> 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;
}
}