@@ -0,0 +1,10 @@ | |||
package com.tuoheng.admin.constant; | |||
public interface SystemConstant { | |||
/** | |||
* 顶级部门pid,默认为0 | |||
*/ | |||
String ROOT_DEPT_PID = "0"; | |||
} |
@@ -93,11 +93,11 @@ public class UpdateDeptService { | |||
return JsonResult.error(EditDeptCodeEnum.DEPT_NAME_IS_NOT_NULL.getCode(), EditDeptCodeEnum.DEPT_NAME_IS_NOT_NULL.getMsg()); | |||
} | |||
if (oldEditDeptRequest.getId().equals(newEditDeptRequest.getId())) { | |||
if (!oldEditDeptRequest.getId().equals(newEditDeptRequest.getId())) { | |||
return JsonResult.error(EditDeptCodeEnum.DEPT_ID_IS_NOT_SAME.getCode(), EditDeptCodeEnum.DEPT_ID_IS_NOT_SAME.getMsg()); | |||
} | |||
if (oldEditDeptRequest.getPid().equals(newEditDeptRequest.getPid())) { | |||
if (!oldEditDeptRequest.getPid().equals(newEditDeptRequest.getPid())) { | |||
return JsonResult.error(EditDeptCodeEnum.DEPT_PID_IS_NOT_SAME.getCode(), EditDeptCodeEnum.DEPT_PID_IS_NOT_SAME.getMsg()); | |||
} | |||
@@ -121,21 +121,23 @@ public class UpdateDeptService { | |||
} | |||
} | |||
// 判断是否已存在该部门名称,同部门下,部门名称不能重复, | |||
// 注意要增加id不能与自己的相同的判断 | |||
Integer count = deptMapper.selectCount(new LambdaQueryWrapper<Dept>() | |||
.eq(Dept::getTenantId, tenantId) | |||
.eq(Dept::getPid, newEditDeptRequest.getPid()) | |||
.ne(Dept::getId, newEditDeptRequest.getId()) | |||
.eq(Dept::getName, newEditDeptRequest.getName()) | |||
.eq(Dept::getMark, 1)); | |||
if (!oldEditDeptRequest.getName().equals(newEditDeptRequest.getName())) { | |||
// 判断是否已存在该部门名称,同部门下,部门名称不能重复, | |||
// 注意要增加id不能与自己的相同的判断 | |||
Integer count = deptMapper.selectCount(new LambdaQueryWrapper<Dept>() | |||
.eq(Dept::getTenantId, tenantId) | |||
.eq(Dept::getPid, newEditDeptRequest.getPid()) | |||
.ne(Dept::getId, newEditDeptRequest.getId()) | |||
.eq(Dept::getName, newEditDeptRequest.getName()) | |||
.eq(Dept::getMark, 1)); | |||
// 系统中已存在 | |||
if (count > 0) { | |||
return JsonResult.error(EditDeptCodeEnum.DEPT_NAME_IS_ALREADY_EXIST.getCode(), EditDeptCodeEnum.DEPT_NAME_IS_ALREADY_EXIST.getMsg()); | |||
// 系统中已存在 | |||
if (count > 0) { | |||
return JsonResult.error(EditDeptCodeEnum.DEPT_NAME_IS_ALREADY_EXIST.getCode(), EditDeptCodeEnum.DEPT_NAME_IS_ALREADY_EXIST.getMsg()); | |||
} | |||
} | |||
// 新增部门,公路和路段信息不能为空 | |||
// 修改部门,公路和路段信息不能为空 | |||
if (CollectionUtils.isEmpty(newEditDeptRequest.getRoadSectionDtoList())) { | |||
return JsonResult.error(EditDeptCodeEnum.ROAD_IS_NULL.getCode(), EditDeptCodeEnum.ROAD_IS_NULL.getMsg()); | |||
} | |||
@@ -198,11 +200,15 @@ public class UpdateDeptService { | |||
// 差集:新增公路 | |||
Collection<String> addRoadIdList = org.apache.commons.collections4.CollectionUtils.subtract(newRoadIdList, oldRoadIdList); | |||
this.addRoadToDept(tenantId, newEditDeptRequest.getId(), addRoadIdList); | |||
if (!CollectionUtils.isEmpty(addRoadIdList)) { | |||
this.addRoadToDept(tenantId, newEditDeptRequest.getId(), addRoadIdList); | |||
} | |||
// 差集:删除公路 | |||
Collection<String> subRoadIdList = org.apache.commons.collections4.CollectionUtils.subtract(oldRoadIdList, newRoadIdList); | |||
this.removeRoadToDept(tenantId, newEditDeptRequest.getId(), subRoadIdList); | |||
if (!CollectionUtils.isEmpty(subRoadIdList)) { | |||
this.removeRoadToDept(tenantId, newEditDeptRequest.getId(), subRoadIdList); | |||
} | |||
} | |||
/** | |||
@@ -293,13 +299,18 @@ public class UpdateDeptService { | |||
// 差集:新增公路 | |||
Collection<String> addSectionIdList = org.apache.commons.collections4.CollectionUtils.subtract(newSectionIdList, oldSectionIdList); | |||
// 添加路段和部门数据 | |||
this.addSectionToDept(tenantId, newEditDeptRequest.getId(), addSectionIdList); | |||
if (!CollectionUtils.isEmpty(addSectionIdList)) { | |||
// 添加路段和部门数据 | |||
this.addSectionToDept(tenantId, newEditDeptRequest.getId(), addSectionIdList); | |||
} | |||
// 差集:删除公路 | |||
Collection<String> subSectionIdList = org.apache.commons.collections4.CollectionUtils.subtract(oldSectionIdList, newSectionIdList); | |||
// 删除路段和部门数据 | |||
this.removeSectionToDept(tenantId, newEditDeptRequest.getId(), subSectionIdList); | |||
if (!CollectionUtils.isEmpty(subSectionIdList)) { | |||
// 删除路段和部门数据 | |||
this.removeSectionToDept(tenantId, newEditDeptRequest.getId(), subSectionIdList); | |||
} | |||
} | |||
/** |
@@ -2,6 +2,7 @@ package com.tuoheng.admin.service.road.query; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.constant.SystemConstant; | |||
import com.tuoheng.admin.entity.Dept; | |||
import com.tuoheng.admin.entity.RoadDept; | |||
import com.tuoheng.admin.entity.RoadInformation; | |||
@@ -52,8 +53,18 @@ public class QueryRoadListByDeptIdService { | |||
return result; | |||
} | |||
// 获取该部门下公路列表 | |||
List<RoadInformation> roadInformationList = this.getRoadInformationList(tenantId, deptId); | |||
// 在校验中,判断部门是否存在时,若部门存在,直接将部门信息返回,减少数据库查询次数 | |||
Dept dept = (Dept) result.getData(); | |||
// 获取公路列表 | |||
List<RoadInformation> roadInformationList; | |||
if (SystemConstant.ROOT_DEPT_PID.equals(dept.getPid())) { | |||
// 顶级部门获取所有的公路列表 | |||
roadInformationList = this.getAllRoadInformationList(tenantId); | |||
} else { | |||
// 非顶级部门获取该部门下公路列表 | |||
roadInformationList = this.getRoadInformationListByDeptId(tenantId, deptId); | |||
} | |||
if (CollectionUtil.isEmpty(roadInformationList)) { | |||
log.info("根据部门Id查询公路列表业务:公路信息为空"); | |||
return JsonResult.error(QueryRoadListByDeptIdCodeEnum.ROAD_LIST_IS_NULL.getCode(), QueryRoadListByDeptIdCodeEnum.ROAD_LIST_IS_NULL.getMsg()); | |||
@@ -85,16 +96,32 @@ public class QueryRoadListByDeptIdService { | |||
} | |||
/** | |||
* 查询该部门下公路信息列表 | |||
* 如果是顶级部门,则查询所有公路列表 | |||
* | |||
* @param tenantId | |||
* @param id | |||
* @return | |||
*/ | |||
private List<RoadInformation> getRoadInformationList(String tenantId, String id) { | |||
private List<RoadInformation> getAllRoadInformationList(String tenantId) { | |||
List<RoadInformation> roadList = roadInformationMapper.selectList(new LambdaQueryWrapper<RoadInformation>() | |||
.eq(RoadInformation::getTenantId, tenantId) | |||
.eq(RoadInformation::getMark, 1)); | |||
if (CollectionUtil.isEmpty(roadList)) { | |||
return null; | |||
} | |||
return roadList; | |||
} | |||
/** | |||
* 如果是非顶级部门,则查询该部门下公路信息列表 | |||
* | |||
* @param tenantId | |||
* @param deptId | |||
* @return | |||
*/ | |||
private List<RoadInformation> getRoadInformationListByDeptId(String tenantId, String deptId) { | |||
List<RoadDept> roadDeptList = roadDeptMapper.selectList(new LambdaQueryWrapper<RoadDept>() | |||
.eq(RoadDept::getTenantId, tenantId) | |||
.eq(RoadDept::getDeptId, id)); | |||
.eq(RoadDept::getDeptId, deptId)); | |||
if (CollectionUtil.isEmpty(roadDeptList)) { | |||
return null; | |||
} |
@@ -27,10 +27,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<!-- 批量删除数据 --> | |||
<delete id="deleteBatchByMap" parameterType="hashmap"> | |||
delete from th_road_dept | |||
where tenant_id = #{tenantId} and dept_id = #{deptId} and road_id in | |||
<foreach collection="roadIdList" item="roadId" separator="," open="(" close=")"> | |||
#{roadId} | |||
</foreach> | |||
where tenant_id = #{tenantId} and dept_id = #{deptId} | |||
<if test="roadIdList != null and roadIdList.size() >0 "> | |||
and road_id in | |||
<foreach collection="roadIdList" item="roadId" separator="," open="(" close=")"> | |||
#{roadId} | |||
</foreach> | |||
</if> | |||
</delete> | |||
</mapper> |
@@ -26,10 +26,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<!-- 批量删除数据 --> | |||
<delete id="deleteBatchByMap" parameterType="hashmap"> | |||
delete from th_section_dept | |||
where tenant_id = #{tenantId} and dept_id = #{deptId} and section_id in | |||
<foreach collection="sectionIdList" item="sectionId" separator="," open="(" close=")"> | |||
#{sectionId} | |||
</foreach> | |||
where tenant_id = #{tenantId} and dept_id = #{deptId} | |||
<if test="sectionIdList != null and sectionIdList.size() >0 "> | |||
and section_id in | |||
<foreach collection="sectionIdList" item="sectionId" separator="," open="(" close=")"> | |||
#{sectionId} | |||
</foreach> | |||
</if> | |||
</delete> | |||
</mapper> |