Commit 9d8a1b35124fc1ede1ea2cd503217775ed2dbe5c
1 parent
ec3fa013
feat:树小程序
Showing
6 changed files
with
372 additions
and
89 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/tree/TreeController.java
| @@ -118,20 +118,6 @@ public class TreeController { | @@ -118,20 +118,6 @@ public class TreeController { | ||
| 118 | BeanUtils.toBean(list, TreeRespVO.class)); | 118 | BeanUtils.toBean(list, TreeRespVO.class)); |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | - @GetMapping("/dept/list") | ||
| 122 | - @PreAuthorize("@ss.hasPermission('garden:tree:list')") | ||
| 123 | - public CommonResult<List<CompanyDeptRoadVO>> list(@RequestParam Long companyId,@RequestParam(required = false) String roadName) { | ||
| 124 | - LoginUser user = SecurityFrameworkUtils.getLoginUser(); | ||
| 125 | - if (null == user) { | ||
| 126 | - return null; | ||
| 127 | - } | ||
| 128 | - TreeVO tree = new TreeVO(); | ||
| 129 | - tree.setBelongCompanyId(companyId); | ||
| 130 | - tree.setRoadName(roadName); | ||
| 131 | - tree.setDeptId(null); | ||
| 132 | - return success(treeService.getCompanyDeptRoadTreeData(tree)); | ||
| 133 | - } | ||
| 134 | - | ||
| 135 | @GetMapping("/road/list") | 121 | @GetMapping("/road/list") |
| 136 | @PreAuthorize("@ss.hasPermission('garden:tree:list')") | 122 | @PreAuthorize("@ss.hasPermission('garden:tree:list')") |
| 137 | public CommonResult<PageResult<RoadTreeVO>> listTreesByRoad(@RequestParam(required = false) Long road) { | 123 | public CommonResult<PageResult<RoadTreeVO>> listTreesByRoad(@RequestParam(required = false) Long road) { |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/app/tree/AppTreeController.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.controller.app.tree; | ||
| 2 | + | ||
| 3 | +import com.fhs.core.trans.anno.TransMethodResult; | ||
| 4 | +import com.zteits.urbanops.framework.apilog.core.annotation.ApiAccessLog; | ||
| 5 | +import com.zteits.urbanops.framework.common.pojo.CommonResult; | ||
| 6 | +import com.zteits.urbanops.framework.common.pojo.PageParam; | ||
| 7 | +import com.zteits.urbanops.framework.common.pojo.PageResult; | ||
| 8 | +import com.zteits.urbanops.framework.common.util.object.BeanUtils; | ||
| 9 | +import com.zteits.urbanops.framework.dict.core.DictFrameworkUtils; | ||
| 10 | +import com.zteits.urbanops.framework.excel.core.util.ExcelUtils; | ||
| 11 | +import com.zteits.urbanops.framework.security.core.LoginUser; | ||
| 12 | +import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; | ||
| 13 | +import com.zteits.urbanops.module.garden.controller.admin.tree.vo.*; | ||
| 14 | +import com.zteits.urbanops.module.garden.dal.dataobject.tree.TreeDO; | ||
| 15 | +import com.zteits.urbanops.module.garden.service.tree.TreeService; | ||
| 16 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 17 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 18 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 19 | +import jakarta.annotation.Resource; | ||
| 20 | +import jakarta.servlet.http.HttpServletResponse; | ||
| 21 | +import jakarta.validation.Valid; | ||
| 22 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 23 | +import org.springframework.validation.annotation.Validated; | ||
| 24 | +import org.springframework.web.bind.annotation.*; | ||
| 25 | + | ||
| 26 | +import java.io.IOException; | ||
| 27 | +import java.time.LocalDateTime; | ||
| 28 | +import java.util.List; | ||
| 29 | + | ||
| 30 | +import static com.zteits.urbanops.framework.apilog.core.enums.OperateTypeEnum.EXPORT; | ||
| 31 | +import static com.zteits.urbanops.framework.common.pojo.CommonResult.success; | ||
| 32 | + | ||
| 33 | +@Tag(name = "App - 一树一档案") | ||
| 34 | +@RestController | ||
| 35 | +@RequestMapping({"/garden/tree","/business/tree"}) | ||
| 36 | +@Validated | ||
| 37 | +public class AppTreeController { | ||
| 38 | + | ||
| 39 | + @Resource | ||
| 40 | + private TreeService treeService; | ||
| 41 | + | ||
| 42 | + @PostMapping({"/create",""}) | ||
| 43 | + @Operation(summary = "创建一树一档案") | ||
| 44 | + public CommonResult<Long> createTree(@Valid @RequestBody TreeSaveReqVO createReqVO) { | ||
| 45 | + Long userId = SecurityFrameworkUtils.getLoginUserId(); | ||
| 46 | + Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId(); | ||
| 47 | + createReqVO.setCreateby(String.valueOf(userId)); | ||
| 48 | + createReqVO.setCreatetime(LocalDateTime.now()); | ||
| 49 | + createReqVO.setUpdateby(String.valueOf(userId)); | ||
| 50 | + createReqVO.setUpdatetime(LocalDateTime.now()); | ||
| 51 | + createReqVO.setDeptId(loginUserDeptId); | ||
| 52 | + return success(treeService.createTree(createReqVO)); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @PutMapping({"/update",""}) | ||
| 56 | + @Operation(summary = "更新一树一档案") | ||
| 57 | + public CommonResult<Boolean> updateTree(@Valid @RequestBody TreeSaveReqVO updateReqVO) { | ||
| 58 | + updateReqVO.setUpdateby(String.valueOf(SecurityFrameworkUtils.getLoginUserId())); | ||
| 59 | + updateReqVO.setUpdatetime(LocalDateTime.now()); | ||
| 60 | + treeService.updateTree(updateReqVO); | ||
| 61 | + return success(true); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @GetMapping("/get") | ||
| 65 | + @Operation(summary = "获得一树一档案") | ||
| 66 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||
| 67 | + @TransMethodResult | ||
| 68 | + public CommonResult<TreeRespVO> getTree(@RequestParam("id") Long id) { | ||
| 69 | + TreeDO tree = treeService.getTree(id); | ||
| 70 | + return success(BeanUtils.toBean(tree, TreeRespVO.class)); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + | ||
| 74 | + @GetMapping("/dept/list") | ||
| 75 | + @PreAuthorize("@ss.hasPermission('garden:tree:list')") | ||
| 76 | + public CommonResult<List<CompanyDeptRoadVO>> list(@RequestParam Long companyId,@RequestParam(required = false) String roadName) { | ||
| 77 | + LoginUser user = SecurityFrameworkUtils.getLoginUser(); | ||
| 78 | + if (null == user) { | ||
| 79 | + return null; | ||
| 80 | + } | ||
| 81 | + TreeVO tree = new TreeVO(); | ||
| 82 | + tree.setBelongCompanyId(companyId); | ||
| 83 | + tree.setRoadName(roadName); | ||
| 84 | + tree.setDeptId(null); | ||
| 85 | + return success(treeService.getCompanyDeptRoadTreeData(tree)); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @GetMapping("/road/list") | ||
| 89 | + @PreAuthorize("@ss.hasPermission('garden:tree:list')") | ||
| 90 | + public CommonResult<PageResult<RoadTreeVO>> listTreesByRoad(@RequestParam(required = false) Long road) { | ||
| 91 | + TreePageReqVO pageReqVO = new TreePageReqVO(); | ||
| 92 | + pageReqVO.setRoad(road); | ||
| 93 | + PageResult<RoadTreeVO> pageResult = treeService.getTreesByRoadId(pageReqVO); | ||
| 94 | + return success(pageResult); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + | ||
| 98 | + private void fillDictData(List<TreeDO> list) { | ||
| 99 | + for (TreeDO gardenTree : list) { | ||
| 100 | + String street = DictFrameworkUtils.parseDictDataLabel("street_belong", gardenTree.getStreet()); | ||
| 101 | + gardenTree.setStreet(street); | ||
| 102 | + | ||
| 103 | + String ownership = DictFrameworkUtils.parseDictDataLabel("tree_ownership", gardenTree.getOldtreeownership()); | ||
| 104 | + gardenTree.setOldtreeownership(ownership); | ||
| 105 | + | ||
| 106 | + String growthVigor = DictFrameworkUtils.parseDictDataLabel("growth_vigor", gardenTree.getGrowthvigor()); | ||
| 107 | + gardenTree.setGrowthvigor(growthVigor); | ||
| 108 | + String treeLevel = DictFrameworkUtils.parseDictDataLabel("tree_level", gardenTree.getTreelevel()); | ||
| 109 | + gardenTree.setTreelevel(treeLevel); | ||
| 110 | + String dataState = DictFrameworkUtils.parseDictDataLabel("data_state", gardenTree.getDatastate()); | ||
| 111 | + gardenTree.setDatastate(dataState); | ||
| 112 | + } | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | +} | ||
| 0 | \ No newline at end of file | 116 | \ No newline at end of file |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/app/treechangelog/AppTreeChangeLogController.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.controller.app.treechangelog; | ||
| 2 | + | ||
| 3 | +import com.fhs.core.trans.anno.TransMethodResult; | ||
| 4 | +import com.zteits.urbanops.framework.apilog.core.annotation.ApiAccessLog; | ||
| 5 | +import com.zteits.urbanops.framework.common.pojo.CommonResult; | ||
| 6 | +import com.zteits.urbanops.framework.common.pojo.PageParam; | ||
| 7 | +import com.zteits.urbanops.framework.common.pojo.PageResult; | ||
| 8 | +import com.zteits.urbanops.framework.common.util.object.BeanUtils; | ||
| 9 | +import com.zteits.urbanops.framework.excel.core.util.ExcelUtils; | ||
| 10 | +import com.zteits.urbanops.module.garden.controller.admin.treechangelog.vo.TreeChangeLogPageReqVO; | ||
| 11 | +import com.zteits.urbanops.module.garden.controller.admin.treechangelog.vo.TreeChangeLogRespVO; | ||
| 12 | +import com.zteits.urbanops.module.garden.controller.admin.treechangelog.vo.TreeChangeLogSaveReqVO; | ||
| 13 | +import com.zteits.urbanops.module.garden.dal.dataobject.treechangelog.TreeChangeLogDO; | ||
| 14 | +import com.zteits.urbanops.module.garden.service.treechangelog.TreeChangeLogService; | ||
| 15 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 16 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 17 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 18 | +import jakarta.annotation.Resource; | ||
| 19 | +import jakarta.servlet.http.HttpServletResponse; | ||
| 20 | +import jakarta.validation.Valid; | ||
| 21 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 22 | +import org.springframework.validation.annotation.Validated; | ||
| 23 | +import org.springframework.web.bind.annotation.*; | ||
| 24 | + | ||
| 25 | +import java.io.IOException; | ||
| 26 | +import java.util.List; | ||
| 27 | + | ||
| 28 | +import static com.zteits.urbanops.framework.apilog.core.enums.OperateTypeEnum.EXPORT; | ||
| 29 | +import static com.zteits.urbanops.framework.common.pojo.CommonResult.success; | ||
| 30 | + | ||
| 31 | +@Tag(name = "App - 一树一档案修改记录") | ||
| 32 | +@RestController | ||
| 33 | +@RequestMapping({"/garden/tree-change-log","/gardentree/logs"}) | ||
| 34 | +@Validated | ||
| 35 | +public class AppTreeChangeLogController { | ||
| 36 | + | ||
| 37 | + @Resource | ||
| 38 | + private TreeChangeLogService treeChangeLogService; | ||
| 39 | + | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + @GetMapping("/get") | ||
| 43 | + @Operation(summary = "获得一树一档案修改记录") | ||
| 44 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||
| 45 | + @PreAuthorize("@ss.hasPermission('garden:tree-change-log:query')") | ||
| 46 | + @TransMethodResult | ||
| 47 | + public CommonResult<TreeChangeLogRespVO> getTreeChangeLog(@RequestParam("id") Long id) { | ||
| 48 | + TreeChangeLogDO treeChangeLog = treeChangeLogService.getTreeChangeLog(id); | ||
| 49 | + return success(BeanUtils.toBean(treeChangeLog, TreeChangeLogRespVO.class)); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @GetMapping({"/page","/list"}) | ||
| 53 | + @Operation(summary = "查询一树一档案修改记录列表") | ||
| 54 | + public CommonResult<PageResult<TreeChangeLogRespVO>> getTreeChangeLogPage(@Valid TreeChangeLogPageReqVO pageReqVO) { | ||
| 55 | + PageResult<TreeChangeLogDO> pageResult = treeChangeLogService.getTreeChangeLogPage(pageReqVO); | ||
| 56 | + return success(BeanUtils.toBean(pageResult, TreeChangeLogRespVO.class)); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @GetMapping("/export-excel") | ||
| 60 | + @Operation(summary = "导出一树一档案修改记录 Excel") | ||
| 61 | + @PreAuthorize("@ss.hasPermission('garden:tree-change-log:export')") | ||
| 62 | + @ApiAccessLog(operateType = EXPORT) | ||
| 63 | + public void exportTreeChangeLogExcel(@Valid TreeChangeLogPageReqVO pageReqVO, | ||
| 64 | + HttpServletResponse response) throws IOException { | ||
| 65 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | ||
| 66 | + List<TreeChangeLogDO> list = treeChangeLogService.getTreeChangeLogPage(pageReqVO).getList(); | ||
| 67 | + // 导出 Excel | ||
| 68 | + ExcelUtils.write(response, "一树一档案修改记录.xls", "数据", TreeChangeLogRespVO.class, | ||
| 69 | + BeanUtils.toBean(list, TreeChangeLogRespVO.class)); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | +} | ||
| 0 | \ No newline at end of file | 73 | \ No newline at end of file |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/tree/TreeMapper.java
| @@ -7,9 +7,12 @@ import com.zteits.urbanops.framework.mybatis.core.query.LambdaQueryWrapperX; | @@ -7,9 +7,12 @@ import com.zteits.urbanops.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 7 | import com.zteits.urbanops.framework.mybatis.core.mapper.BaseMapperX; | 7 | import com.zteits.urbanops.framework.mybatis.core.mapper.BaseMapperX; |
| 8 | import com.zteits.urbanops.framework.mybatis.core.query.MPJLambdaWrapperX; | 8 | import com.zteits.urbanops.framework.mybatis.core.query.MPJLambdaWrapperX; |
| 9 | import com.zteits.urbanops.module.garden.dal.dataobject.tree.TreeDO; | 9 | import com.zteits.urbanops.module.garden.dal.dataobject.tree.TreeDO; |
| 10 | +import com.zteits.urbanops.module.garden.dal.dataobject.road.RoadDO; | ||
| 10 | import com.zteits.urbanops.module.system.dal.dataobject.dept.DeptDO; | 11 | import com.zteits.urbanops.module.system.dal.dataobject.dept.DeptDO; |
| 11 | import org.apache.ibatis.annotations.Mapper; | 12 | import org.apache.ibatis.annotations.Mapper; |
| 12 | import com.zteits.urbanops.module.garden.controller.admin.tree.vo.*; | 13 | import com.zteits.urbanops.module.garden.controller.admin.tree.vo.*; |
| 14 | +import com.baomidou.mybatisplus.extension.toolkit.Db; | ||
| 15 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
| 13 | 16 | ||
| 14 | /** | 17 | /** |
| 15 | * 一树一档案 Mapper | 18 | * 一树一档案 Mapper |
| @@ -71,4 +74,112 @@ public interface TreeMapper extends BaseMapperX<TreeDO> { | @@ -71,4 +74,112 @@ public interface TreeMapper extends BaseMapperX<TreeDO> { | ||
| 71 | } | 74 | } |
| 72 | 75 | ||
| 73 | List<CompanyDeptRoadVO> selectCompanyDeptRoadTreeData(TreeVO tree); | 76 | List<CompanyDeptRoadVO> selectCompanyDeptRoadTreeData(TreeVO tree); |
| 74 | -} | ||
| 75 | \ No newline at end of file | 77 | \ No newline at end of file |
| 78 | + | ||
| 79 | +// default List<CompanyDeptRoadVO> selectCompanyDeptRoadTreeData(TreeVO tree) { | ||
| 80 | +// List<DeptDO> companies = Db.lambdaQuery(DeptDO.class) | ||
| 81 | +// .eq(DeptDO::getStatus, 0) | ||
| 82 | +// .eq(DeptDO::getParentId, 100L) | ||
| 83 | +// .list(); | ||
| 84 | +// Long belongCompanyId = tree.getBelongCompanyId(); | ||
| 85 | +// if (belongCompanyId != null) { | ||
| 86 | +// companies.removeIf(c -> !Objects.equals(c.getId(), belongCompanyId)); | ||
| 87 | +// } | ||
| 88 | +// if (companies.isEmpty()) { | ||
| 89 | +// return Collections.emptyList(); | ||
| 90 | +// } | ||
| 91 | +// List<Long> companyIds = new ArrayList<>(); | ||
| 92 | +// for (DeptDO c : companies) { | ||
| 93 | +// companyIds.add(c.getId()); | ||
| 94 | +// } | ||
| 95 | +// Long deptIdFilter = tree.getDeptId(); | ||
| 96 | +// List<DeptDO> depts; | ||
| 97 | +// if (deptIdFilter != null) { | ||
| 98 | +// depts = Db.lambdaQuery(DeptDO.class) | ||
| 99 | +// .eq(DeptDO::getStatus, 0) | ||
| 100 | +// .eq(DeptDO::getId, deptIdFilter) | ||
| 101 | +// .list(); | ||
| 102 | +// depts.removeIf(d -> !companyIds.contains(d.getParentId())); | ||
| 103 | +// } else { | ||
| 104 | +// depts = Db.lambdaQuery(DeptDO.class) | ||
| 105 | +// .eq(DeptDO::getStatus, 0) | ||
| 106 | +// .in(DeptDO::getParentId, companyIds) | ||
| 107 | +// .list(); | ||
| 108 | +// } | ||
| 109 | +// List<Long> deptIds = new ArrayList<>(); | ||
| 110 | +// for (DeptDO d : depts) { | ||
| 111 | +// deptIds.add(d.getId()); | ||
| 112 | +// } | ||
| 113 | +// String roadNameFilter = tree.getRoadName(); | ||
| 114 | +// List<RoadDO> roads = deptIds.isEmpty() ? Collections.emptyList() | ||
| 115 | +// : Db.lambdaQuery(RoadDO.class) | ||
| 116 | +// .in(RoadDO::getDeptId, deptIds) | ||
| 117 | +// .like(roadNameFilter != null && !roadNameFilter.isEmpty(), RoadDO::getRoadName, roadNameFilter) | ||
| 118 | +// .list(); | ||
| 119 | +// List<Long> roadIds = new ArrayList<>(); | ||
| 120 | +// for (RoadDO r : roads) { | ||
| 121 | +// roadIds.add(r.getId()); | ||
| 122 | +// } | ||
| 123 | +// Map<Long, Integer> recordedCountMap = new HashMap<>(); | ||
| 124 | +// if (!roadIds.isEmpty()) { | ||
| 125 | +// List<Map<String, Object>> countMaps = selectMaps(new QueryWrapper<TreeDO>() | ||
| 126 | +// .select("road", "COUNT(id) AS cnt") | ||
| 127 | +// .in("road", roadIds) | ||
| 128 | +// .eq("deleted", 0) | ||
| 129 | +// .groupBy("road")); | ||
| 130 | +// for (Map<String, Object> m : countMaps) { | ||
| 131 | +// Object roadVal = m.get("road"); | ||
| 132 | +// Object cntVal = m.get("cnt"); | ||
| 133 | +// if (roadVal != null && cntVal != null) { | ||
| 134 | +// Long rid = ((Number) roadVal).longValue(); | ||
| 135 | +// Integer cnt = ((Number) cntVal).intValue(); | ||
| 136 | +// recordedCountMap.put(rid, cnt); | ||
| 137 | +// } | ||
| 138 | +// } | ||
| 139 | +// } | ||
| 140 | +// Map<Long, List<DeptDO>> deptsByCompany = new HashMap<>(); | ||
| 141 | +// for (DeptDO d : depts) { | ||
| 142 | +// List<DeptDO> list = deptsByCompany.computeIfAbsent(d.getParentId(), k -> new ArrayList<>()); | ||
| 143 | +// list.add(d); | ||
| 144 | +// } | ||
| 145 | +// Map<Long, List<RoadDO>> roadsByDept = new HashMap<>(); | ||
| 146 | +// for (RoadDO r : roads) { | ||
| 147 | +// List<RoadDO> list = roadsByDept.computeIfAbsent(r.getDeptId(), k -> new ArrayList<>()); | ||
| 148 | +// list.add(r); | ||
| 149 | +// } | ||
| 150 | +// List<CompanyDeptRoadVO> result = new ArrayList<>(); | ||
| 151 | +// for (DeptDO company : companies) { | ||
| 152 | +// CompanyDeptRoadVO companyVO = new CompanyDeptRoadVO(); | ||
| 153 | +// companyVO.setCompanyId(company.getId()); | ||
| 154 | +// companyVO.setCompanyName(company.getName()); | ||
| 155 | +// List<DeptDO> companyDepts = deptsByCompany.getOrDefault(company.getId(), Collections.emptyList()); | ||
| 156 | +// List<CompanyDeptRoadVO.DeptVO> deptVOs = new ArrayList<>(); | ||
| 157 | +// for (DeptDO dept : companyDepts) { | ||
| 158 | +// CompanyDeptRoadVO.DeptVO deptVO = new CompanyDeptRoadVO.DeptVO(); | ||
| 159 | +// deptVO.setDeptId(dept.getId()); | ||
| 160 | +// deptVO.setDeptName(dept.getName()); | ||
| 161 | +// List<RoadDO> deptRoads = roadsByDept.getOrDefault(dept.getId(), Collections.emptyList()); | ||
| 162 | +// List<CompanyDeptRoadVO.RoadVO> roadVOs = new ArrayList<>(); | ||
| 163 | +// for (RoadDO road : deptRoads) { | ||
| 164 | +// CompanyDeptRoadVO.RoadVO roadVO = new CompanyDeptRoadVO.RoadVO(); | ||
| 165 | +// roadVO.setRoadId(road.getId()); | ||
| 166 | +// roadVO.setRoadName(road.getRoadName()); | ||
| 167 | +// roadVO.setStartRemark(road.getStartingRemark()); | ||
| 168 | +// roadVO.setEndRemark(road.getEndRemark()); | ||
| 169 | +// Integer treeCount = road.getTreeArea() == null ? 0 : road.getTreeArea().intValue(); | ||
| 170 | +// roadVO.setTreeCount(treeCount); | ||
| 171 | +// Integer recordedCount = recordedCountMap.getOrDefault(road.getId(), 0); | ||
| 172 | +// roadVO.setRecordedCount(recordedCount); | ||
| 173 | +// roadVOs.add(roadVO); | ||
| 174 | +// } | ||
| 175 | +// roadVOs.sort(Comparator | ||
| 176 | +// .comparing(CompanyDeptRoadVO.RoadVO::getTreeCount, Comparator.nullsFirst(Comparator.naturalOrder())).reversed() | ||
| 177 | +// .thenComparing(CompanyDeptRoadVO.RoadVO::getRecordedCount, Comparator.nullsFirst(Comparator.naturalOrder())).reversed()); | ||
| 178 | +// deptVO.setRoads(roadVOs); | ||
| 179 | +// deptVOs.add(deptVO); | ||
| 180 | +// } | ||
| 181 | +// companyVO.setDepts(deptVOs); | ||
| 182 | +// result.add(companyVO); | ||
| 183 | +// } | ||
| 184 | +// return result; | ||
| 185 | +// } | ||
| 186 | +} |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/tree/TreeServiceImpl.java
| @@ -176,80 +176,80 @@ public class TreeServiceImpl implements TreeService { | @@ -176,80 +176,80 @@ public class TreeServiceImpl implements TreeService { | ||
| 176 | 176 | ||
| 177 | @Override | 177 | @Override |
| 178 | public List<CompanyDeptRoadVO> getCompanyDeptRoadTreeData(TreeVO tree) { | 178 | public List<CompanyDeptRoadVO> getCompanyDeptRoadTreeData(TreeVO tree) { |
| 179 | - List<DeptDO> sysDepts = deptMapper.selectList(); | 179 | +// List<DeptDO> sysDepts = deptMapper.selectList(); |
| 180 | 180 | ||
| 181 | List<CompanyDeptRoadVO> companyDeptRoadVOS = treeMapper.selectCompanyDeptRoadTreeData(tree); | 181 | List<CompanyDeptRoadVO> companyDeptRoadVOS = treeMapper.selectCompanyDeptRoadTreeData(tree); |
| 182 | 182 | ||
| 183 | 183 | ||
| 184 | - // 按公司分组所有部门 | ||
| 185 | - Map<Long, List<DeptDO>> companyDeptsMap = sysDepts.stream() | ||
| 186 | - .filter(d -> d.getParentId() != null) | ||
| 187 | - .collect(Collectors.groupingBy(DeptDO::getParentId)); | ||
| 188 | - | ||
| 189 | - // 过滤出叶子部门(没有子部门的部门) | ||
| 190 | - Map<Long, List<DeptDO>> companyLeafDeptsMap = new HashMap<>(); | ||
| 191 | - for (Map.Entry<Long, List<DeptDO>> entry : companyDeptsMap.entrySet()) { | ||
| 192 | - Long companyId = entry.getKey(); | ||
| 193 | - List<DeptDO> depts = entry.getValue(); | ||
| 194 | - | ||
| 195 | - // 构建部门ID到部门的映射 | ||
| 196 | - Map<Long, DeptDO> deptMap = depts.stream() | ||
| 197 | - .collect(Collectors.toMap(DeptDO::getId, d -> d)); | ||
| 198 | - | ||
| 199 | - // 找出叶子部门(其parentId不在deptMap中的部门,或者其parentId为0的部门) | ||
| 200 | - List<DeptDO> leafDepts = depts.stream() | ||
| 201 | - .filter(d -> d.getParentId() == 0 || !deptMap.containsKey(d.getParentId())) | ||
| 202 | - .collect(Collectors.toList()); | ||
| 203 | - | ||
| 204 | - companyLeafDeptsMap.put(companyId, leafDepts); | ||
| 205 | - } | ||
| 206 | - | ||
| 207 | - // 建立现有结果的映射: 公司ID -> CompanyDeptRoadVO | ||
| 208 | - Map<Long, CompanyDeptRoadVO> existingCompanyMap = companyDeptRoadVOS.stream() | ||
| 209 | - .collect(Collectors.toMap( | ||
| 210 | - CompanyDeptRoadVO::getCompanyId, | ||
| 211 | - vo -> vo, | ||
| 212 | - (existing, replacement) -> existing | ||
| 213 | - )); | ||
| 214 | - | ||
| 215 | - // 遍历所有公司,补充缺失的公司和部门 | ||
| 216 | - for (Map.Entry<Long, List<DeptDO>> entry : companyLeafDeptsMap.entrySet()) { | ||
| 217 | - Long companyId = entry.getKey(); | ||
| 218 | - List<DeptDO> depts = entry.getValue(); | ||
| 219 | - | ||
| 220 | - CompanyDeptRoadVO companyVO; | ||
| 221 | - if (!existingCompanyMap.containsKey(companyId)) { | ||
| 222 | - // 如果公司不存在,创建新的公司对象 | ||
| 223 | - companyVO = new CompanyDeptRoadVO(); | ||
| 224 | - companyVO.setCompanyId(companyId); | ||
| 225 | - companyVO.setCompanyName(DictFrameworkUtils.parseDictDataValue("belongCompanyId", companyId + "")); | ||
| 226 | - companyVO.setDepts(new ArrayList<>()); | ||
| 227 | - companyDeptRoadVOS.add(companyVO); | ||
| 228 | - } else { | ||
| 229 | - companyVO = existingCompanyMap.get(companyId); | ||
| 230 | - } | ||
| 231 | - | ||
| 232 | - // 建立该公司下已存在的部门映射: 部门ID -> DeptVO | ||
| 233 | - Map<Long, CompanyDeptRoadVO.DeptVO> existingDeptMap = companyVO.getDepts().stream() | ||
| 234 | - .collect(Collectors.toMap( | ||
| 235 | - deptVO -> Long.valueOf(deptVO.getDeptId()), | ||
| 236 | - deptVO -> deptVO, | ||
| 237 | - (existing, replacement) -> existing | ||
| 238 | - )); | ||
| 239 | - | ||
| 240 | - // 补充缺失的部门(仅叶子部门) | ||
| 241 | - for (DeptDO sysDept : depts) { | ||
| 242 | - Long deptId = sysDept.getId(); | ||
| 243 | - if (!existingDeptMap.containsKey(deptId)) { | ||
| 244 | - // 创建缺失的部门对象 | ||
| 245 | - CompanyDeptRoadVO.DeptVO missingDept = new CompanyDeptRoadVO.DeptVO(); | ||
| 246 | - missingDept.setDeptId(deptId); | ||
| 247 | - missingDept.setDeptName(sysDept.getName()); | ||
| 248 | - missingDept.setRoads(new ArrayList<>()); | ||
| 249 | - companyVO.getDepts().add(missingDept); | ||
| 250 | - } | ||
| 251 | - } | ||
| 252 | - } | 184 | +// // 按公司分组所有部门 |
| 185 | +// Map<Long, List<DeptDO>> companyDeptsMap = sysDepts.stream() | ||
| 186 | +// .filter(d -> d.getParentId() != null) | ||
| 187 | +// .collect(Collectors.groupingBy(DeptDO::getParentId)); | ||
| 188 | +// | ||
| 189 | +// // 过滤出叶子部门(没有子部门的部门) | ||
| 190 | +// Map<Long, List<DeptDO>> companyLeafDeptsMap = new HashMap<>(); | ||
| 191 | +// for (Map.Entry<Long, List<DeptDO>> entry : companyDeptsMap.entrySet()) { | ||
| 192 | +// Long companyId = entry.getKey(); | ||
| 193 | +// List<DeptDO> depts = entry.getValue(); | ||
| 194 | +// | ||
| 195 | +// // 构建部门ID到部门的映射 | ||
| 196 | +// Map<Long, DeptDO> deptMap = depts.stream() | ||
| 197 | +// .collect(Collectors.toMap(DeptDO::getId, d -> d)); | ||
| 198 | +// | ||
| 199 | +// // 找出叶子部门(其parentId不在deptMap中的部门,或者其parentId为0的部门) | ||
| 200 | +// List<DeptDO> leafDepts = depts.stream() | ||
| 201 | +// .filter(d -> d.getParentId() == 0 || !deptMap.containsKey(d.getParentId())) | ||
| 202 | +// .collect(Collectors.toList()); | ||
| 203 | +// | ||
| 204 | +// companyLeafDeptsMap.put(companyId, leafDepts); | ||
| 205 | +// } | ||
| 206 | +// | ||
| 207 | +// // 建立现有结果的映射: 公司ID -> CompanyDeptRoadVO | ||
| 208 | +// Map<Long, CompanyDeptRoadVO> existingCompanyMap = companyDeptRoadVOS.stream() | ||
| 209 | +// .collect(Collectors.toMap( | ||
| 210 | +// CompanyDeptRoadVO::getCompanyId, | ||
| 211 | +// vo -> vo, | ||
| 212 | +// (existing, replacement) -> existing | ||
| 213 | +// )); | ||
| 214 | +// | ||
| 215 | +// // 遍历所有公司,补充缺失的公司和部门 | ||
| 216 | +// for (Map.Entry<Long, List<DeptDO>> entry : companyLeafDeptsMap.entrySet()) { | ||
| 217 | +// Long companyId = entry.getKey(); | ||
| 218 | +// List<DeptDO> depts = entry.getValue(); | ||
| 219 | +// | ||
| 220 | +// CompanyDeptRoadVO companyVO; | ||
| 221 | +// if (!existingCompanyMap.containsKey(companyId)) { | ||
| 222 | +// // 如果公司不存在,创建新的公司对象 | ||
| 223 | +// companyVO = new CompanyDeptRoadVO(); | ||
| 224 | +// companyVO.setCompanyId(companyId); | ||
| 225 | +// companyVO.setCompanyName(DictFrameworkUtils.parseDictDataValue("belongCompanyId", companyId + "")); | ||
| 226 | +// companyVO.setDepts(new ArrayList<>()); | ||
| 227 | +// companyDeptRoadVOS.add(companyVO); | ||
| 228 | +// } else { | ||
| 229 | +// companyVO = existingCompanyMap.get(companyId); | ||
| 230 | +// } | ||
| 231 | +// | ||
| 232 | +// // 建立该公司下已存在的部门映射: 部门ID -> DeptVO | ||
| 233 | +// Map<Long, CompanyDeptRoadVO.DeptVO> existingDeptMap = companyVO.getDepts().stream() | ||
| 234 | +// .collect(Collectors.toMap( | ||
| 235 | +// deptVO -> Long.valueOf(deptVO.getDeptId()), | ||
| 236 | +// deptVO -> deptVO, | ||
| 237 | +// (existing, replacement) -> existing | ||
| 238 | +// )); | ||
| 239 | +// | ||
| 240 | +// // 补充缺失的部门(仅叶子部门) | ||
| 241 | +// for (DeptDO sysDept : depts) { | ||
| 242 | +// Long deptId = sysDept.getId(); | ||
| 243 | +// if (!existingDeptMap.containsKey(deptId)) { | ||
| 244 | +// // 创建缺失的部门对象 | ||
| 245 | +// CompanyDeptRoadVO.DeptVO missingDept = new CompanyDeptRoadVO.DeptVO(); | ||
| 246 | +// missingDept.setDeptId(deptId); | ||
| 247 | +// missingDept.setDeptName(sysDept.getName()); | ||
| 248 | +// missingDept.setRoads(new ArrayList<>()); | ||
| 249 | +// companyVO.getDepts().add(missingDept); | ||
| 250 | +// } | ||
| 251 | +// } | ||
| 252 | +// } | ||
| 253 | return companyDeptRoadVOS; | 253 | return companyDeptRoadVOS; |
| 254 | } | 254 | } |
| 255 | 255 |
urbanops-module-garden/src/main/resources/mapper/tree/TreeMapper.xml
| @@ -43,8 +43,7 @@ | @@ -43,8 +43,7 @@ | ||
| 43 | LEFT JOIN garden_road r ON d.id = r.dept_id | 43 | LEFT JOIN garden_road r ON d.id = r.dept_id |
| 44 | LEFT JOIN garden_tree t ON r.id = t.road AND t.deleted = 0 | 44 | LEFT JOIN garden_tree t ON r.id = t.road AND t.deleted = 0 |
| 45 | WHERE | 45 | WHERE |
| 46 | - c.status = 0 | ||
| 47 | - AND d.id NOT IN (SELECT DISTINCT parent_id FROM system_dept WHERE parent_id IS NOT NULL) | 46 | + c.status = 0 and c.parent_id = 100 |
| 48 | <if test="belongCompanyId != null"> | 47 | <if test="belongCompanyId != null"> |
| 49 | AND d.parent_id = #{belongCompanyId} | 48 | AND d.parent_id = #{belongCompanyId} |
| 50 | </if> | 49 | </if> |
| @@ -54,8 +53,8 @@ | @@ -54,8 +53,8 @@ | ||
| 54 | <if test="deptId != null"> | 53 | <if test="deptId != null"> |
| 55 | AND d.id = #{deptId} | 54 | AND d.id = #{deptId} |
| 56 | </if> | 55 | </if> |
| 57 | - GROUP BY c.id, d.id, | 56 | + GROUP BY c.id, c.name, d.id, d.name, |
| 58 | r.id, r.road_name, r.starting_remark, r.end_remark, r.tree_area | 57 | r.id, r.road_name, r.starting_remark, r.end_remark, r.tree_area |
| 59 | - ORDER BY treeCount DESC, recordedCount DESC; | 58 | + ORDER BY treeCount DESC, recordedCount DESC |
| 60 | </select> | 59 | </select> |
| 61 | </mapper> | 60 | </mapper> |
| 62 | \ No newline at end of file | 61 | \ No newline at end of file |