Commit a0da87a8705dc3072aa663d9bd4faa2a107247e6
1 parent
125a348e
refactor(dept): 统一部门接口返回格式为标准Map结构
- 将DeptController.queryAllDeptList方法返回类型改为Map<String, Object>
- 使用HashMap构建标准的{code,data,msg}格式响应
- 移除SysDeptRespVO对象转换,直接映射为Map结构
- 修复parentDeptCode为空时返回空字符串的逻辑
refactor(road): 调整道路接口参数处理和返回格式
- 将RoadController.queryAllRoadList方法返回类型改为Map<String, Object>
- 添加deptCode参数为空值检查,避免转换异常
- 移除SysRoadRespVO对象转换,直接映射为Map结构
- 统一构建标准的{code,data,msg}格式响应
refactor(road): 优化道路查询条件构建逻辑
- 在RoadServiceImpl中添加查询条件的空值检查
- 避免对null值执行数据库查询条件拼接
- 修复like查询为likeRight以匹配原始意图
Showing
3 changed files
with
48 additions
and
22 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/road/RoadController.java
| ... | ... | @@ -126,19 +126,28 @@ public class RoadController { |
| 126 | 126 | @Operation(summary = "物联网查询道路") |
| 127 | 127 | @GetMapping("/queryAllRoadList") |
| 128 | 128 | @PermitAll |
| 129 | - public CommonResult<List<SysRoadRespVO>> queryAllRoadList(@RequestParam(required = false)String roadName,@RequestParam(required = false)String deptCode,@RequestParam(required = false)String companyCode) { | |
| 129 | + public Map<String, Object> queryAllRoadList(@RequestParam(required = false) String roadName, @RequestParam(required = false) String deptCode, @RequestParam(required = false) String companyCode) { | |
| 130 | 130 | RoadListReqVO reqVO = new RoadListReqVO(); |
| 131 | 131 | reqVO.setRoadName(roadName); |
| 132 | - reqVO.setCompanyId(Long.valueOf(deptCode)); | |
| 132 | + // 处理deptCode为空的情况 | |
| 133 | + if (deptCode != null && !deptCode.isEmpty()) { | |
| 134 | + reqVO.setCompanyId(Long.valueOf(deptCode)); | |
| 135 | + } | |
| 133 | 136 | reqVO.setBusiLine(companyCode); |
| 134 | 137 | List<RoadDO> roadList = roadService.getRoadList(reqVO); |
| 135 | - List<SysRoadRespVO> deptResps = roadList.stream().map(manager -> { | |
| 136 | - SysRoadRespVO sysDeptResp = new SysRoadRespVO(); | |
| 137 | - sysDeptResp.setRoadCode(manager.getId()+""); | |
| 138 | - sysDeptResp.setRoadName(manager.getRoadName()); | |
| 139 | - return sysDeptResp; | |
| 138 | + List<Map<String, Object>> roadResps = roadList.stream().map(manager -> { | |
| 139 | + Map<String, Object> roadMap = new HashMap<>(); | |
| 140 | + roadMap.put("roadCode", manager.getId() + ""); | |
| 141 | + roadMap.put("roadName", manager.getRoadName()); | |
| 142 | + return roadMap; | |
| 140 | 143 | }).collect(Collectors.toList()); |
| 141 | - return success(deptResps); | |
| 144 | + | |
| 145 | + // 构建返回格式 | |
| 146 | + Map<String, Object> result = new HashMap<>(); | |
| 147 | + result.put("msg", "操作成功"); | |
| 148 | + result.put("code", 200); | |
| 149 | + result.put("data", roadResps); | |
| 150 | + return result; | |
| 142 | 151 | } |
| 143 | 152 | |
| 144 | 153 | } | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/road/RoadServiceImpl.java
| ... | ... | @@ -159,10 +159,18 @@ public class RoadServiceImpl implements RoadService { |
| 159 | 159 | QueryWrapper<RoadDO> sql = new QueryWrapper<>(); |
| 160 | 160 | sql.select("id", "road_name", "level_id","company_id","dept_id"); |
| 161 | 161 | |
| 162 | - sql.lambda().eq(RoadDO::getCompanyId, reqVO.getCompanyId()) | |
| 163 | - .eq(RoadDO::getLevelId, reqVO.getLevelId()) | |
| 164 | - .eq(RoadDO::getBusiLine, reqVO.getBusiLine()) | |
| 165 | - .likeRight(StringUtils.isNotEmpty(reqVO.getRoadName()), RoadDO::getRoadName, reqVO.getRoadName()); | |
| 162 | + if (reqVO.getCompanyId() != null) { | |
| 163 | + sql.lambda().eq(RoadDO::getCompanyId, reqVO.getCompanyId()); | |
| 164 | + } | |
| 165 | + if (reqVO.getLevelId() != null) { | |
| 166 | + sql.lambda().eq(RoadDO::getLevelId, reqVO.getLevelId()); | |
| 167 | + } | |
| 168 | + if (reqVO.getBusiLine() != null) { | |
| 169 | + sql.lambda().eq(RoadDO::getBusiLine, reqVO.getBusiLine()); | |
| 170 | + } | |
| 171 | + if (StringUtils.isNotEmpty(reqVO.getRoadName())) { | |
| 172 | + sql.lambda().like(RoadDO::getRoadName, reqVO.getRoadName()); | |
| 173 | + } | |
| 166 | 174 | return roadMapper.selectList(sql); |
| 167 | 175 | } |
| 168 | 176 | ... | ... |
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/controller/admin/dept/DeptController.java
| ... | ... | @@ -18,6 +18,9 @@ import org.springframework.web.bind.annotation.*; |
| 18 | 18 | |
| 19 | 19 | import jakarta.annotation.Resource; |
| 20 | 20 | import jakarta.validation.Valid; |
| 21 | + | |
| 22 | +import java.util.HashMap; | |
| 23 | +import java.util.Map; | |
| 21 | 24 | import java.util.List; |
| 22 | 25 | import java.util.stream.Collectors; |
| 23 | 26 | |
| ... | ... | @@ -126,18 +129,24 @@ public class DeptController { |
| 126 | 129 | @Operation(summary = "查询所有组织") |
| 127 | 130 | @GetMapping("/queryAllDeptList") |
| 128 | 131 | @PermitAll |
| 129 | - public CommonResult<List<SysDeptRespVO>> queryAllDeptList(@RequestParam(required = false)String companyCode) { | |
| 132 | + public Map<String, Object> queryAllDeptList() { | |
| 130 | 133 | List<DeptDO> sysDepts = deptService.getSubDeptAllList(); |
| 131 | - List<SysDeptRespVO> deptResps = sysDepts.stream().map(sysDept -> { | |
| 132 | - SysDeptRespVO sysDeptResp = new SysDeptRespVO(); | |
| 133 | - sysDeptResp.setDeptCode(sysDept.getId()+""); | |
| 134 | - sysDeptResp.setDeptName(sysDept.getName()); | |
| 135 | - sysDeptResp.setParentDeptCode(sysDept.getParentId()+""); | |
| 136 | - sysDeptResp.setOrderNum(sysDept.getSort()); | |
| 137 | - sysDeptResp.setStatus(sysDept.getStatus().toString()); | |
| 138 | - return sysDeptResp; | |
| 134 | + List<Map<String, Object>> deptResps = sysDepts.stream().map(sysDept -> { | |
| 135 | + Map<String, Object> deptMap = new HashMap<>(); | |
| 136 | + deptMap.put("deptCode", sysDept.getId() + ""); | |
| 137 | + deptMap.put("deptName", sysDept.getName()); | |
| 138 | + // parentDeptCode为空时返回空字符串 | |
| 139 | + deptMap.put("parentDeptCode", sysDept.getParentId() == null || sysDept.getParentId() == 0 ? "" : sysDept.getParentId() + ""); | |
| 140 | + deptMap.put("orderNum", sysDept.getSort()); | |
| 141 | + return deptMap; | |
| 139 | 142 | }).collect(Collectors.toList()); |
| 140 | - return success(deptResps); | |
| 143 | + | |
| 144 | + // 构建返回格式 | |
| 145 | + Map<String, Object> result = new HashMap<>(); | |
| 146 | + result.put("msg", "操作成功"); | |
| 147 | + result.put("code", 200); | |
| 148 | + result.put("data", deptResps); | |
| 149 | + return result; | |
| 141 | 150 | } |
| 142 | 151 | |
| 143 | 152 | } | ... | ... |