项目管理接口相关逻辑补充,部门添加型行政区划树状层级业务等

This commit is contained in:
mi9688
2024-10-30 17:55:57 +08:00
parent decd964994
commit 502a785d3b
9 changed files with 455 additions and 93 deletions

View File

@ -1,5 +1,8 @@
package com.fastbee.system.service.impl;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONException;
import cn.hutool.json.JSONUtil;
import com.fastbee.common.annotation.DataScope;
import com.fastbee.common.constant.UserConstants;
import com.fastbee.common.core.domain.TreeSelect;
@ -9,6 +12,7 @@ import com.fastbee.common.core.domain.entity.SysUser;
import com.fastbee.common.core.domain.model.LoginUser;
import com.fastbee.common.core.text.Convert;
import com.fastbee.common.exception.ServiceException;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.common.utils.SecurityUtils;
import com.fastbee.common.utils.StringUtils;
import com.fastbee.common.utils.spring.SpringUtils;
@ -245,10 +249,87 @@ public class SysDeptServiceImpl implements ISysDeptService
{
throw new ServiceException("部门停用,不允许新增");
}
//设置祖级别列表
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
//处理机构所管理行政区划信息
parseAdministrativeDivisionInfo(dept);
dept.setCreateTime(DateUtils.getNowDate());
return deptMapper.insertDept(dept);
}
/**
* 解析项目行政区划信息
* @param sysDept 部门
*/
private void parseAdministrativeDivisionInfo(SysDept sysDept) {
//项目行政区域处理
//拆解项目行政区域代码信息
if(org.apache.commons.lang3.StringUtils.isBlank(sysDept.getAdministrativeAreaCode())){
throw new ServiceException("项目行政区域代码不能为空!");
}
//判断行政区域代码json格式
if(isNotValidJsonArray(sysDept.getAdministrativeAreaCode())){
throw new ServiceException("项目行政区域代码多选列表非json数组");
}
//项目省代码列表
List<String> provincialCodeList =new ArrayList<>();
//项目市代码列表
List<String> cityCodeList =new ArrayList<>();
//项目县代码列表
List<String> countyCodeList =new ArrayList<>();
//项目镇代码列表
List<String> townCodeList =new ArrayList<>();
//项目村代码列表
List<String> villageCodeList =new ArrayList<>();
JSONArray administrativeAreaList = JSONUtil.parseArray(sysDept.getAdministrativeAreaCode());
administrativeAreaList.forEach(item->{
if(isNotValidJsonArray(item.toString())){
throw new ServiceException("项目行政区域代码多选列表的元素非json数组");
}
//单个行政区划代码列表
JSONArray administrativeArea = JSONUtil.parseArray(item);
//拆解出每个行政区划代码里面的镇或村
// if(administrativeArea.size()!=5){
// throw new ServiceException("项目行政区域代码多选列表的元素长度必须为5到达村级别");
// }
//保存项目省代码列表
provincialCodeList.add(administrativeArea.get(0).toString());
//保存项目市代码列表
cityCodeList.add(administrativeArea.get(1).toString());
//保存项目县代码列表
countyCodeList.add(administrativeArea.get(2).toString());
//保存项目镇代码列表
if(administrativeArea.size()>=4){
//保存项目镇代码列表
townCodeList.add(administrativeArea.get(3).toString());
}
if(administrativeArea.size()>=5){
//保存项目村代码列表
villageCodeList.add(administrativeArea.get(4).toString());
}
});
//设置项目省、市、县、镇、村行政区划代码列表
sysDept.setProvinceCode(JSONUtil.toJsonStr(provincialCodeList));
sysDept.setCityCode(JSONUtil.toJsonStr(cityCodeList));
sysDept.setCountyCode(JSONUtil.toJsonStr(countyCodeList));
sysDept.setTownCode(JSONUtil.toJsonStr(townCodeList));
sysDept.setVillageCode(JSONUtil.toJsonStr(villageCodeList));
}
/**
* 验证json对象是否是数组
*/
public boolean isNotValidJsonArray(String jsonStr) {
try {
JSONUtil.parseArray(jsonStr);
} catch (JSONException e) {
return true;
}
return false;
}
/**
* 修改保存部门信息
*
@ -261,17 +342,26 @@ public class SysDeptServiceImpl implements ISysDeptService
})
@Override
public int updateDept(SysDept dept)
{
{ //查询当前修改部门的父部门
SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
//查询当前修改部门修改前的旧数据
SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))
{
//更新部门的祖级列表
String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
String oldAncestors = oldDept.getAncestors();
dept.setAncestors(newAncestors);
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
}
//处理机构所管理行政区划信息
parseAdministrativeDivisionInfo(dept);
//更新部门信息
dept.setUpdateTime(DateUtils.getNowDate());
int result = deptMapper.updateDept(dept);
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
&& !StringUtils.equals("0", dept.getAncestors()))
{
@ -283,7 +373,6 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 修改该部门的父级部门状态
*
* @param dept 当前部门
*/
private void updateParentDeptStatusNormal(SysDept dept)

View File

@ -102,9 +102,9 @@ public class SysDistrictServiceImpl implements ISysDistrictService
* @param mapOutlineUrl 地图轮廓json文件访问uel
*/
private void verifySaveJsonData(SysDistrict sysDistrict, String mapOutlineUrl) {
//行政区划轮廓json文件url必须是绝对完整
//行政区划轮廓json文件url是绝对url代表新上传过
if(!(mapOutlineUrl.contains("http://") || mapOutlineUrl.contains("https://"))){
throw new ServiceException("行政区划轮廓json文件url不正确");
return ;
}
//上传行政区划轮廓进行数据处理
String jsonData = HttpUtil.get(mapOutlineUrl);
@ -135,7 +135,7 @@ public class SysDistrictServiceImpl implements ISysDistrictService
if(StringUtils.isBlank(mapOutlineUrl)){
return sysDistrictMapper.updateSysDistrict(sysDistrict);
}
//判断行政区划轮廓json文件路url是否是完整url还是相对url
//判断行政区划轮廓json文件路url是否是完整url还是相对url,如果是相对url则代表并未修改绝对url代表修改过
verifySaveJsonData(sysDistrict, mapOutlineUrl);
return sysDistrictMapper.updateSysDistrict(sysDistrict);

View File

@ -61,7 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.dept_type, d.dept_user_id,
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.dept_type, d.dept_user_id,d.administrative_area_code,
(select dept_name from sys_dept where dept_id = d.parent_id) parent_name
from sys_dept d
where d.dept_id = #{deptId}
@ -121,54 +121,137 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</select>
<insert id="insertDept" parameterType="SysDept" useGeneratedKeys="true" keyProperty="deptId">
insert into sys_dept(
<if test="deptId != null and deptId != 0">dept_id,</if>
<if test="deptUserId != null and deptUserId != 0">dept_user_id,</if>
<if test="parentId != null and parentId != 0">parent_id,</if>
<if test="deptName != null and deptName != ''">dept_name,</if>
<if test="ancestors != null and ancestors != ''">ancestors,</if>
<if test="orderNum != null">order_num,</if>
<if test="leader != null and leader != ''">leader,</if>
<if test="phone != null and phone != ''">phone,</if>
<if test="email != null and email != ''">email,</if>
<if test="status != null">status,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="deptType != null and deptType != ''">dept_type,</if>
create_time
)values(
<if test="deptId != null and deptId != 0">#{deptId},</if>
<if test="deptUserId != null and deptUserId != 0">#{deptUserId},</if>
<if test="parentId != null and parentId != 0">#{parentId},</if>
<if test="deptName != null and deptName != ''">#{deptName},</if>
<if test="ancestors != null and ancestors != ''">#{ancestors},</if>
<if test="orderNum != null">#{orderNum},</if>
<if test="leader != null and leader != ''">#{leader},</if>
<if test="phone != null and phone != ''">#{phone},</if>
<if test="email != null and email != ''">#{email},</if>
<if test="status != null">#{status},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="deptType != null and deptType != ''">#{deptType},</if>
sysdate()
)
<!-- <insert id="insertDept" parameterType="SysDept" useGeneratedKeys="true" keyProperty="deptId">-->
<!-- insert into sys_dept(-->
<!-- <if test="deptId != null and deptId != 0">dept_id,</if>-->
<!-- <if test="deptUserId != null and deptUserId != 0">dept_user_id,</if>-->
<!-- <if test="parentId != null and parentId != 0">parent_id,</if>-->
<!-- <if test="deptName != null and deptName != ''">dept_name,</if>-->
<!-- <if test="ancestors != null and ancestors != ''">ancestors,</if>-->
<!-- <if test="orderNum != null">order_num,</if>-->
<!-- <if test="leader != null and leader != ''">leader,</if>-->
<!-- <if test="phone != null and phone != ''">phone,</if>-->
<!-- <if test="email != null and email != ''">email,</if>-->
<!-- <if test="status != null">status,</if>-->
<!-- <if test="createBy != null and createBy != ''">create_by,</if>-->
<!-- <if test="deptType != null and deptType != ''">dept_type,</if>-->
<!-- create_time-->
<!-- )values(-->
<!-- <if test="deptId != null and deptId != 0">#{deptId},</if>-->
<!-- <if test="deptUserId != null and deptUserId != 0">#{deptUserId},</if>-->
<!-- <if test="parentId != null and parentId != 0">#{parentId},</if>-->
<!-- <if test="deptName != null and deptName != ''">#{deptName},</if>-->
<!-- <if test="ancestors != null and ancestors != ''">#{ancestors},</if>-->
<!-- <if test="orderNum != null">#{orderNum},</if>-->
<!-- <if test="leader != null and leader != ''">#{leader},</if>-->
<!-- <if test="phone != null and phone != ''">#{phone},</if>-->
<!-- <if test="email != null and email != ''">#{email},</if>-->
<!-- <if test="status != null">#{status},</if>-->
<!-- <if test="createBy != null and createBy != ''">#{createBy},</if>-->
<!-- <if test="deptType != null and deptType != ''">#{deptType},</if>-->
<!-- sysdate()-->
<!-- )-->
<!-- </insert>-->
<insert id="insertDept" parameterType="SysDept" useGeneratedKeys="true" keyProperty="deptId">
insert into sys_dept
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deptUserId != null">dept_user_id,</if>
<if test="parentId != null">parent_id,</if>
<if test="ancestors != null and ancestors != ''">ancestors,</if>
<if test="deptName != null">dept_name,</if>
<if test="orderNum != null">order_num,</if>
<if test="leader != null and leader != ''">leader,</if>
<if test="phone != null">phone,</if>
<if test="status != null">status,</if>
<if test="delFlag != null">del_flag,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="email != null">email,</if>
<if test="deptType != null">dept_type,</if>
<if test="administrativeArea != null">administrative_area,</if>
<if test="administrativeAreaCode != null">administrative_area_code,</if>
<if test="provinceCode != null">province_code,</if>
<if test="cityCode != null">city_code,</if>
<if test="countyCode != null">county_code,</if>
<if test="townCode != null">town_code,</if>
<if test="villageCode != null">village_code,</if>
<if test="projectId != null">project_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deptUserId != null">#{deptUserId},</if>
<if test="parentId != null">#{parentId},</if>
<if test="ancestors != null and ancestors != ''">#{ancestors},</if>
<if test="deptName != null">#{deptName},</if>
<if test="orderNum != null">#{orderNum},</if>
<if test="leader != null and leader != ''">#{leader},</if>
<if test="phone != null">#{phone},</if>
<if test="status != null">#{status},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="email != null">#{email},</if>
<if test="deptType != null">#{deptType},</if>
<if test="administrativeArea != null">#{administrativeArea},</if>
<if test="administrativeAreaCode != null">#{administrativeAreaCode},</if>
<if test="provinceCode != null">#{provinceCode},</if>
<if test="cityCode != null">#{cityCode},</if>
<if test="countyCode != null">#{countyCode},</if>
<if test="townCode != null">#{townCode},</if>
<if test="villageCode != null">#{villageCode},</if>
<if test="projectId != null">#{projectId},</if>
</trim>
</insert>
<!-- <update id="updateDept" parameterType="SysDept">-->
<!-- update sys_dept-->
<!-- <set>-->
<!-- <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>-->
<!-- <if test="deptUserId != null and deptUserId != 0">dept_user_id = #{deptUserId},</if>-->
<!-- <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>-->
<!-- <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>-->
<!-- <if test="orderNum != null">order_num = #{orderNum},</if>-->
<!-- <if test="leader != null">leader = #{leader},</if>-->
<!-- <if test="phone != null">phone = #{phone},</if>-->
<!-- <if test="email != null">email = #{email},</if>-->
<!-- <if test="status != null and status != ''">status = #{status},</if>-->
<!-- <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>-->
<!-- update_time = sysdate()-->
<!-- </set>-->
<!-- where dept_id = #{deptId}-->
<!-- </update>-->
<update id="updateDept" parameterType="SysDept">
update sys_dept
<set>
<if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
<if test="deptUserId != null and deptUserId != 0">dept_user_id = #{deptUserId},</if>
<if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
<if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
<if test="orderNum != null">order_num = #{orderNum},</if>
<if test="leader != null">leader = #{leader},</if>
<if test="phone != null">phone = #{phone},</if>
<if test="email != null">email = #{email},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
where dept_id = #{deptId}
update sys_dept
<trim prefix="SET" suffixOverrides=",">
<if test="deptUserId != null">dept_user_id = #{deptUserId},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
<if test="deptName != null">dept_name = #{deptName},</if>
<if test="orderNum != null">order_num = #{orderNum},</if>
<if test="leader != null and leader != ''">leader = #{leader},</if>
<if test="phone != null">phone = #{phone},</if>
<if test="status != null">status = #{status},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="email != null">email = #{email},</if>
<if test="deptType != null">dept_type = #{deptType},</if>
<if test="administrativeArea != null">administrative_area = #{administrativeArea},</if>
<if test="administrativeAreaCode != null">administrative_area_code = #{administrativeAreaCode},</if>
<if test="provinceCode != null">province_code = #{provinceCode},</if>
<if test="cityCode != null">city_code = #{cityCode},</if>
<if test="countyCode != null">county_code = #{countyCode},</if>
<if test="townCode != null">town_code = #{townCode},</if>
<if test="villageCode != null">village_code = #{villageCode},</if>
<if test="projectId != null">project_id = #{projectId},</if>
</trim>
where dept_id = #{deptId}
</update>
<update id="updateDeptChildren" parameterType="java.util.List">