Browse Source

Merge branch 'develop' of http://192.168.11.14:51037/gitadmin/tuoheng_freeway into feature_v1.0

tags/v1.1.0^2
chengwang 1 year ago
parent
commit
8b3486a37e
3 changed files with 75 additions and 38 deletions
  1. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/ClientEnum.java
  2. +72
    -35
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/update/UpdateDeptService.java
  3. +2
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/menu/MenuServiceImpl.java

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/ClientEnum.java View File

@@ -14,7 +14,7 @@ import java.util.Map;
public enum ClientEnum {

ADMIN(1, "tuoheng-freeway-admin"),
API(2, "tuoheng-freeway-mp");
MP(2, "tuoheng-freeway-mp");

ClientEnum(int code, String description) {
this.code = code;

+ 72
- 35
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/update/UpdateDeptService.java View File

@@ -1,5 +1,6 @@
package com.tuoheng.admin.service.dept.update;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.constant.SystemConstant;
import com.tuoheng.admin.dto.RoadSectionDto;
@@ -16,7 +17,6 @@ import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;
@@ -139,7 +139,7 @@ public class UpdateDeptService {
}

// 修改部门,公路和路段信息不能为空
if (CollectionUtils.isEmpty(newEditDeptRequest.getRoadSectionDtoList())) {
if (CollectionUtil.isEmpty(newEditDeptRequest.getRoadSectionDtoList())) {
return JsonResult.error(EditDeptCodeEnum.ROAD_IS_NULL.getCode(), EditDeptCodeEnum.ROAD_IS_NULL.getMsg());
}

@@ -147,7 +147,7 @@ public class UpdateDeptService {
List<RoadSectionDto> roadSectionDtoList = newEditDeptRequest.getRoadSectionDtoList();
for (RoadSectionDto roadSectionDto : roadSectionDtoList) {
sectionList = roadSectionDto.getSectionList();
if (CollectionUtils.isEmpty(sectionList)) {
if (CollectionUtil.isEmpty(sectionList)) {
return JsonResult.error(EditDeptCodeEnum.SECTION_IS_NULL.getCode(), EditDeptCodeEnum.SECTION_IS_NULL.getMsg());
}
}
@@ -191,26 +191,50 @@ public class UpdateDeptService {
*/
private void roadHandle(String tenantId, EditDeptRequest oldEditDeptRequest, EditDeptRequest newEditDeptRequest) {
List<RoadSectionDto> oldRoadSectionList = oldEditDeptRequest.getRoadSectionDtoList();
List<String> oldRoadIdList = oldRoadSectionList.stream().map(o -> o.getRoad().getId()).collect(Collectors.toList());

List<String> oldRoadIdList = null;
if (CollectionUtil.isNotEmpty(oldRoadSectionList)) {
oldRoadIdList = oldRoadSectionList.stream().map(o -> o.getRoad().getId()).collect(Collectors.toList());
}
List<RoadSectionDto> newRoadSectionList = newEditDeptRequest.getRoadSectionDtoList();
List<String> newRoadIdList = newRoadSectionList.stream().map(o -> o.getRoad().getId()).collect(Collectors.toList());
List<String> newRoadIdList = null;
if (CollectionUtil.isNotEmpty(newRoadSectionList)) {
newRoadIdList = newRoadSectionList.stream().map(o -> o.getRoad().getId()).collect(Collectors.toList());
}

// 交集:存在公路, 不做处理
// Collection<String> union = org.apache.commons.collections4.CollectionUtils.union(oldRoadIdList, newRoadIdList);

// 差集:新增公路
Collection<String> addRoadIdList = org.apache.commons.collections4.CollectionUtils.subtract(newRoadIdList, oldRoadIdList);
if (!CollectionUtils.isEmpty(addRoadIdList)) {
Collection<String> addRoadIdList;
if (CollectionUtil.isNotEmpty(oldRoadIdList)) {
addRoadIdList = org.apache.commons.collections4.CollectionUtils.subtract(newRoadIdList, oldRoadIdList);
} else {
addRoadIdList = newRoadIdList;
}
if (CollectionUtil.isNotEmpty(addRoadIdList)) {
// 去重,防止前端提交了重复的数据
addRoadIdList= addRoadIdList.stream().distinct().collect(Collectors.toList());
this.addRoadToDept(tenantId, newEditDeptRequest.getId(), addRoadIdList);
}

// 差集:删除公路
Collection<String> subRoadIdList = org.apache.commons.collections4.CollectionUtils.subtract(oldRoadIdList, newRoadIdList);
if (!CollectionUtils.isEmpty(subRoadIdList)) {
this.removeRoadToDept(tenantId, newEditDeptRequest.getId(), subRoadIdList);
if (CollectionUtil.isNotEmpty(oldRoadIdList)) {
Collection<String> subRoadIdList = org.apache.commons.collections4.CollectionUtils.subtract(oldRoadIdList, newRoadIdList);
Map<String, Long> oldRoadIdMap = oldRoadIdList.stream().collect(Collectors.groupingBy(p -> p, Collectors.counting()));
Map<String, Long> subRoadIdMap = subRoadIdList.stream().collect(Collectors.groupingBy(p -> p, Collectors.counting()));
if (CollectionUtil.isNotEmpty(subRoadIdList)) {
List<String> deleteRoadIdList = new ArrayList<>();
for (String roadId : subRoadIdList) {
Long oldCount = oldRoadIdMap.get(roadId);
Long subCount = subRoadIdMap.get(roadId);
if (oldCount.equals(subCount)) {
deleteRoadIdList.add(roadId);
}
}
if (CollectionUtil.isNotEmpty(deleteRoadIdList)) {
this.removeRoadToDept(tenantId, newEditDeptRequest.getId(), subRoadIdList);
}
}
}
}

@@ -244,7 +268,7 @@ public class UpdateDeptService {
}
list.add(roadDept);
}
if (!CollectionUtils.isEmpty(list)) {
if (CollectionUtil.isNotEmpty(list)) {
roadDeptMapper.insertBatch(list);
}
}
@@ -268,12 +292,12 @@ public class UpdateDeptService {
deptList.add(parentDept);
queryChildDeptList(deptList, parentDept);

for (Dept dept : deptList) {
Map<String, Object> map = new HashMap<>();
map.put("tenantId", tenantId);
map.put("deptId", dept.getId());
map.put("roadIdList", roadIdList);
roadDeptMapper.deleteBatchByMap(map);
List<String> deptIdList = deptList.stream().map(p -> p.getId()).collect(Collectors.toList());;
for (String roadId : roadIdList) {
roadDeptMapper.delete(new LambdaQueryWrapper<RoadDept>()
.eq(RoadDept::getTenantId, tenantId)
.eq(RoadDept::getRoadId, roadId)
.in(RoadDept::getDeptId, deptIdList));
}
}

@@ -287,8 +311,10 @@ public class UpdateDeptService {
private void sectionhandle(String tenantId, EditDeptRequest oldEditDeptRequest, EditDeptRequest newEditDeptRequest) {
List<RoadSectionDto> oldRoadSectionList = oldEditDeptRequest.getRoadSectionDtoList();
List<Section> oldSectionList = new ArrayList<>();
for (RoadSectionDto roadSectionDto : oldRoadSectionList) {
oldSectionList.addAll(roadSectionDto.getSectionList());
if (CollectionUtil.isNotEmpty(oldRoadSectionList)) {
for (RoadSectionDto roadSectionDto : oldRoadSectionList) {
oldSectionList.addAll(roadSectionDto.getSectionList());
}
}

List<RoadSectionDto> newRoadSectionList = newEditDeptRequest.getRoadSectionDtoList();
@@ -296,14 +322,17 @@ public class UpdateDeptService {
for (RoadSectionDto roadSectionDto : newRoadSectionList) {
newSectionList.addAll(roadSectionDto.getSectionList());
}

List<String> oldSectionIdList = oldSectionList.stream().map(o -> o.getId()).collect(Collectors.toList());
List<String> newSectionIdList = newSectionList.stream().map(o -> o.getId()).collect(Collectors.toList());

// 差集:新增路段
Collection<String> addSectionIdList = org.apache.commons.collections4.CollectionUtils.subtract(newSectionIdList, oldSectionIdList);

if (!CollectionUtils.isEmpty(addSectionIdList)) {
Collection<String> addSectionIdList;
if (CollectionUtil.isNotEmpty(oldSectionList)) {
List<String> oldSectionIdList = oldSectionList.stream().map(o -> o.getId()).collect(Collectors.toList());
addSectionIdList = org.apache.commons.collections4.CollectionUtils.subtract(newSectionIdList, oldSectionIdList);
} else {
addSectionIdList = newSectionIdList;
}
if (CollectionUtil.isNotEmpty(addSectionIdList)) {
// 去重,防止前端提交了重复的数据
addSectionIdList= addSectionIdList.stream().distinct().collect(Collectors.toList());
// 添加路段和部门数据
@@ -311,10 +340,13 @@ public class UpdateDeptService {
}

// 差集:删除路段
Collection<String> subSectionIdList = org.apache.commons.collections4.CollectionUtils.subtract(oldSectionIdList, newSectionIdList);
if (!CollectionUtils.isEmpty(subSectionIdList)) {
// 删除路段和部门数据
this.removeSectionToDept(tenantId, newEditDeptRequest.getId(), subSectionIdList);
if (CollectionUtil.isNotEmpty(oldSectionList)) {
List<String> oldSectionIdList = oldSectionList.stream().map(o -> o.getId()).collect(Collectors.toList());
Collection<String> subSectionIdList = org.apache.commons.collections4.CollectionUtils.subtract(oldSectionIdList, newSectionIdList);
if (CollectionUtil.isNotEmpty(subSectionIdList)) {
// 删除路段和部门数据
this.removeSectionToDept(tenantId, newEditDeptRequest.getId(), subSectionIdList);
}
}
}

@@ -349,7 +381,7 @@ public class UpdateDeptService {
list.add(sectionDept);
}

if (!CollectionUtils.isEmpty(list)) {
if (CollectionUtil.isNotEmpty(list)) {
sectionDeptMapper.insertBatch(list);
}
}
@@ -363,11 +395,16 @@ public class UpdateDeptService {
* @return 结果
*/
private void removeSectionToDept(String tenantId, String deptId, Collection<String> sectionIdList) {
Map<String, Object> map = new HashMap<>();
map.put("tenantId", tenantId);
map.put("deptId", deptId);
map.put("sectionIdList", sectionIdList);
sectionDeptMapper.deleteBatchByMap(map);
List<String> deptIdList = deptMapper.selectAllChildListById(deptId);
if (CollectionUtil.isEmpty(deptIdList)) {
return;
}
for (String sectionId : sectionIdList) {
sectionDeptMapper.delete(new LambdaQueryWrapper<SectionDept>()
.eq(SectionDept::getTenantId, tenantId)
.eq(SectionDept::getSectionId, sectionId)
.in(SectionDept::getDeptId, deptIdList));
}
}

/**

+ 2
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/menu/MenuServiceImpl.java View File

@@ -64,8 +64,8 @@ public class MenuServiceImpl implements IMenuService{
queryWrapper.eq("client_id", ClientEnum.ADMIN.getDescription());
queryWrapper1.eq("client_id", ClientEnum.ADMIN.getDescription());
} else {
queryWrapper.eq("client_id", ClientEnum.API.getDescription());
queryWrapper1.eq("client_id", ClientEnum.API.getDescription());
queryWrapper.eq("client_id", ClientEnum.MP.getDescription());
queryWrapper1.eq("client_id", ClientEnum.MP.getDescription());
}
if (!StringUtils.isEmpty(menuQuery.getName())) {
queryWrapper1.like("name", menuQuery.getName());

Loading…
Cancel
Save