Просмотр исходного кода

feat(base): 添加管网基础信息管理功能

- 新增 PipeNetworkBaseController 提供完整的CRUD接口
- 实现分页查询、单条查询、批量操作等功能
- 添加数据验证检查机制防止重复编码
- 集成 Swagger API 文档注解
- 实现事务管理和异常处理机制
林仔 1 месяц назад
Родитель
Сommit
eff0d80cc6

+ 107 - 0
pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/base/PipeNetworkBaseController.java

@@ -0,0 +1,107 @@
+package com.zksy.web.controller.base;
+
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.zksy.base.domain.PipeNetworkBase;
+import com.zksy.base.service.PipeNetworkBaseService;
+import com.zksy.common.annotation.Anonymous;
+import com.zksy.common.annotation.Log;
+import com.zksy.common.core.domain.AjaxResult;
+import com.zksy.common.enums.BusinessType;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@Slf4j
+@RestController
+@RequestMapping("/PipeNetworkBase")
+@Api(tags = "管网基础信息管理")
+public class PipeNetworkBaseController {
+
+    @Autowired
+    private PipeNetworkBaseService service;
+
+    @GetMapping("/getById/{id}")
+    @ApiOperation(value = "获取管网基础信息详情")
+    @Anonymous
+    public AjaxResult getById(@PathVariable String id) {
+        PipeNetworkBase entity = service.getById(id);
+        if (entity == null) {
+            return AjaxResult.error("该管网信息不存在");
+        }
+        return AjaxResult.success(entity);
+    }
+
+    @Anonymous
+    @GetMapping("/findByPage")
+    @ApiOperation(value = "管网基础信息分页查询")
+    public Page findByPage(
+            @ApiParam("页码") @RequestParam(defaultValue = "1") long pageNum,
+            @ApiParam("每页数量") @RequestParam(defaultValue = "10") long pageSize,
+            @ApiParam("设施编码") @RequestParam(required = false) String networkCode,
+            @ApiParam("设施名称") @RequestParam(required = false) String networkName,
+            @ApiParam("设施类型") @RequestParam(required = false) String networkType,
+            @ApiParam("状态") @RequestParam(required = false) String status) {
+        return service.findByPage(pageNum, pageSize, networkCode, networkName, networkType, status);
+    }
+
+    @Anonymous
+    @GetMapping("/getList")
+    @ApiOperation(value = "查询所有管网基础信息")
+    public AjaxResult getList() {
+        return AjaxResult.success(service.list());
+    }
+
+    @PostMapping("/save")
+    @ApiOperation(value = "新增管网基础信息")
+    @Log(title = "新增管网基础信息", businessType = BusinessType.INSERT)
+    public AjaxResult save(@RequestBody PipeNetworkBase entity) {
+        boolean saved = service.saveWithCheck(entity);
+        return saved ? AjaxResult.success("新增成功", saved)
+                : AjaxResult.error("新增失败", saved);
+    }
+
+    @PostMapping("/saveBatch")
+    @ApiOperation(value = "管网基础信息批量新增")
+    @Log(title = "批量新增管网基础信息", businessType = BusinessType.INSERT)
+    public AjaxResult saveBatch(@RequestBody List<PipeNetworkBase> entityList) {
+        if (CollectionUtils.isEmpty(entityList)) {
+            return AjaxResult.error("批量新增失败:列表不能为空");
+        }
+        boolean saved = service.saveBatchWithCheck(entityList);
+        return saved ? AjaxResult.success("新增成功", saved)
+                : AjaxResult.error("新增失败", saved);
+    }
+
+    @PutMapping("/updateById")
+    @ApiOperation(value = "管网基础信息修改")
+    @Log(title = "修改管网基础信息", businessType = BusinessType.UPDATE)
+    public AjaxResult updateById(@RequestBody PipeNetworkBase entity) {
+        boolean updated = service.updateWithCheck(entity);
+        return updated ? AjaxResult.success("修改成功", updated)
+                : AjaxResult.error("修改失败", updated);
+    }
+
+    @DeleteMapping("/deleteById")
+    @ApiOperation(value = "管网基础信息删除")
+    @Log(title = "删除管网基础信息", businessType = BusinessType.DELETE)
+    public AjaxResult deleteById(String id) {
+        boolean deleted = service.removeWithCheck(id);
+        return deleted ? AjaxResult.success("删除成功", deleted)
+                : AjaxResult.error("删除失败", deleted);
+    }
+
+    @DeleteMapping("/deleteBatchById")
+    @ApiOperation(value = "管网基础信息批量删除")
+    @Log(title = "管网基础信息批量删除", businessType = BusinessType.DELETE)
+    public AjaxResult deleteBatchById(@RequestParam List<String> ids) {
+        boolean deleted = service.removeBatchWithCheck(ids);
+        return deleted ? AjaxResult.success("删除成功", deleted)
+                : AjaxResult.error("删除失败", deleted);
+    }
+}

+ 9 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/mapper/PipeNetworkBaseMapper.java

@@ -0,0 +1,9 @@
+package com.zksy.base.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zksy.base.domain.PipeNetworkBase;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface PipeNetworkBaseMapper extends BaseMapper<PipeNetworkBase> {
+}

+ 24 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/PipeNetworkBaseService.java

@@ -0,0 +1,24 @@
+package com.zksy.base.service;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zksy.base.domain.PipeNetworkBase;
+
+import java.util.List;
+
+public interface PipeNetworkBaseService extends IService<PipeNetworkBase> {
+
+    Page<PipeNetworkBase> findByPage(long pageNum, long pageSize,
+                                      String networkCode, String networkName,
+                                      String networkType, String status);
+
+    boolean saveWithCheck(PipeNetworkBase entity);
+
+    boolean saveBatchWithCheck(List<PipeNetworkBase> entityList);
+
+    boolean updateWithCheck(PipeNetworkBase entity);
+
+    boolean removeWithCheck(String id);
+
+    boolean removeBatchWithCheck(List<String> ids);
+}

+ 134 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/PipeNetworkBaseServiceImpl.java

@@ -0,0 +1,134 @@
+package com.zksy.base.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zksy.base.domain.PipeNetworkBase;
+import com.zksy.base.mapper.PipeNetworkBaseMapper;
+import com.zksy.base.service.PipeNetworkBaseService;
+import com.zksy.common.exception.ServiceException;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Slf4j
+@Service
+public class PipeNetworkBaseServiceImpl extends ServiceImpl<PipeNetworkBaseMapper, PipeNetworkBase>
+        implements PipeNetworkBaseService {
+
+    @Override
+    public Page<PipeNetworkBase> findByPage(long pageNum, long pageSize,
+                                             String networkCode, String networkName,
+                                             String networkType, String status) {
+        Page<PipeNetworkBase> page = new Page<>(pageNum, pageSize);
+        LambdaQueryWrapper<PipeNetworkBase> queryWrapper = new LambdaQueryWrapper<>();
+        if (networkCode != null && !networkCode.isEmpty()) {
+            queryWrapper.like(PipeNetworkBase::getNetworkCode, networkCode);
+        }
+        if (networkName != null && !networkName.isEmpty()) {
+            queryWrapper.like(PipeNetworkBase::getNetworkName, networkName);
+        }
+        if (networkType != null && !networkType.isEmpty()) {
+            queryWrapper.eq(PipeNetworkBase::getNetworkType, networkType);
+        }
+        if (status != null && !status.isEmpty()) {
+            queryWrapper.eq(PipeNetworkBase::getStatus, status);
+        }
+        queryWrapper.orderByDesc(PipeNetworkBase::getCreateTime);
+        return this.page(page, queryWrapper);
+    }
+
+    @Override
+    public boolean saveWithCheck(PipeNetworkBase entity) {
+        LambdaQueryWrapper<PipeNetworkBase> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(PipeNetworkBase::getNetworkCode, entity.getNetworkCode());
+        long count = this.count(queryWrapper);
+        if (count > 0) {
+            throw new ServiceException("设施编码已存在,请更换:" + entity.getNetworkCode());
+        }
+        return this.save(entity);
+    }
+
+    @Override
+    public boolean saveBatchWithCheck(List<PipeNetworkBase> entityList) {
+        Set<String> codeSet = new HashSet<>();
+        for (PipeNetworkBase entity : entityList) {
+            String code = entity.getNetworkCode();
+            if (codeSet.contains(code)) {
+                throw new ServiceException("列表中存在重复编码:" + code);
+            }
+            codeSet.add(code);
+        }
+
+        for (PipeNetworkBase entity : entityList) {
+            LambdaQueryWrapper<PipeNetworkBase> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(PipeNetworkBase::getNetworkCode, entity.getNetworkCode());
+            if (this.count(wrapper) > 0) {
+                throw new ServiceException("设施编码已存在:" + entity.getNetworkCode());
+            }
+        }
+        return this.saveBatch(entityList);
+    }
+
+    @Override
+    @Transactional
+    public boolean updateWithCheck(PipeNetworkBase entity) {
+        String networkId = entity.getNetworkId();
+        if (this.getById(networkId) == null) {
+            throw new ServiceException("设施不存在,无法修改:" + networkId);
+        }
+
+        String newCode = entity.getNetworkCode();
+        if (newCode != null) {
+            LambdaQueryWrapper<PipeNetworkBase> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(PipeNetworkBase::getNetworkCode, newCode)
+                    .ne(PipeNetworkBase::getNetworkId, networkId);
+            if (this.count(wrapper) > 0) {
+                throw new ServiceException("设施编码已被使用:" + newCode);
+            }
+        }
+        return this.updateById(entity);
+    }
+
+    @Override
+    @Transactional
+    public boolean removeWithCheck(String networkId) {
+        PipeNetworkBase network = this.getById(networkId);
+        if (network == null) {
+            throw new ServiceException("设施不存在:" + networkId);
+        }
+        return this.baseMapper.deleteById(networkId) > 0;
+    }
+
+    @Override
+    @Transactional
+    public boolean removeBatchWithCheck(List<String> networkIds) {
+        if (CollectionUtils.isEmpty(networkIds)) {
+            throw new ServiceException("批量删除失败:设施ID列表不能为空");
+        }
+
+        List<PipeNetworkBase> existNetworks = this.listByIds(networkIds);
+        if (existNetworks.isEmpty()) {
+            throw new ServiceException("批量删除失败:所有设施ID均不存在");
+        }
+
+        List<String> existIds = existNetworks.stream()
+                .map(PipeNetworkBase::getNetworkId)
+                .collect(Collectors.toList());
+
+        List<String> invalidIds = networkIds.stream()
+                .filter(id -> !existIds.contains(id))
+                .collect(Collectors.toList());
+        if (!invalidIds.isEmpty()) {
+            log.warn("批量删除中存在无效设施ID:{}", invalidIds);
+        }
+
+        return this.removeByIds(existIds);
+    }
+}