单位树形结构
This commit is contained in:
parent
5ab57900c4
commit
dd1146bf2e
|
|
@ -43,11 +43,12 @@ public interface SysUnitMapper {
|
|||
List<SysUnit> findByParentId(@Param("parentId") String parentId);
|
||||
|
||||
/*部门列表*/
|
||||
List<SysUnit> findUnit();
|
||||
List<SysUnit> findUnit(@Param("parentUnitId") String parentUnitId);
|
||||
|
||||
/*部门列表*/
|
||||
List<SysUnit> findByName(@Param("condition") String condition,
|
||||
@Param("parentId") String parentId);
|
||||
@Param("parentId") String parentId,
|
||||
@Param("parentUnitId") String parentUnitId);
|
||||
|
||||
/*修改部门*/
|
||||
Integer changeUnit(@Param("record") SysUnit record);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,12 @@ public class SysUnit implements Serializable {
|
|||
@ApiModelProperty("父级部门id")
|
||||
private String superiorunitid;
|
||||
|
||||
@ApiModelProperty("父级地址")
|
||||
private String parentPath;
|
||||
|
||||
@ApiModelProperty("父级名称")
|
||||
private String parentName;
|
||||
|
||||
@ApiModelProperty("父级部门名")
|
||||
private String superName;
|
||||
|
||||
|
|
@ -90,6 +96,22 @@ public class SysUnit implements Serializable {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public String getParentPath() {
|
||||
return parentPath;
|
||||
}
|
||||
|
||||
public void setParentPath(String parentPath) {
|
||||
this.parentPath = parentPath;
|
||||
}
|
||||
|
||||
public String getParentName() {
|
||||
return parentName;
|
||||
}
|
||||
|
||||
public void setParentName(String parentName) {
|
||||
this.parentName = parentName;
|
||||
}
|
||||
|
||||
public Integer getUserNum() {
|
||||
return userNum;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
<id column="SysUnitId" jdbcType="CHAR" property="sysunitid" />
|
||||
<result column="OrgCode" jdbcType="VARCHAR" property="orgcode" />
|
||||
<result column="SuperiorUnitId" jdbcType="CHAR" property="superiorunitid" />
|
||||
<result column="parent_path" jdbcType="CHAR" property="parentPath" />
|
||||
<result column="parent_name" jdbcType="CHAR" property="parentName" />
|
||||
<result column="UnitCode" jdbcType="VARCHAR" property="unitcode" />
|
||||
<result column="UnitName" jdbcType="VARCHAR" property="unitname" />
|
||||
<result column="PinYin" jdbcType="VARCHAR" property="pinyin" />
|
||||
|
|
@ -84,7 +86,11 @@
|
|||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
SysUnitId, OrgCode, SuperiorUnitId, UnitCode, UnitName, PinYin, UnitType, UnitAddress,
|
||||
SysUnitId, OrgCode,
|
||||
parent_path,
|
||||
parent_name,
|
||||
SuperiorUnitId,
|
||||
UnitCode, UnitName, PinYin, UnitType, UnitAddress,
|
||||
SimpleName, Principal, MobileTel, BaseInfo, Telephone, UnitLocation, Latitude, Longitude,
|
||||
Comments, CreatedOn, CreatedBy, ModifiedOn, ModifiedBy, SysEnterpriseId
|
||||
</sql>
|
||||
|
|
@ -127,7 +133,10 @@
|
|||
</if>
|
||||
</delete>
|
||||
<insert id="insert" parameterType="com.rzyc.model.user.SysUnit">
|
||||
insert into SysUnit (SysUnitId, OrgCode, SuperiorUnitId,
|
||||
insert into SysUnit (SysUnitId, OrgCode,
|
||||
SuperiorUnitId,
|
||||
parent_path,
|
||||
parent_name,
|
||||
UnitCode, UnitName, PinYin,
|
||||
UnitType, UnitAddress, SimpleName,
|
||||
Principal, MobileTel, BaseInfo,
|
||||
|
|
@ -135,7 +144,10 @@
|
|||
Longitude, Comments, CreatedOn,
|
||||
CreatedBy, ModifiedOn, ModifiedBy,
|
||||
SysEnterpriseId)
|
||||
values (#{sysunitid,jdbcType=CHAR}, #{orgcode,jdbcType=VARCHAR}, #{superiorunitid,jdbcType=CHAR},
|
||||
values (#{sysunitid,jdbcType=CHAR}, #{orgcode,jdbcType=VARCHAR},
|
||||
#{superiorunitid,jdbcType=CHAR},
|
||||
#{parentPath,jdbcType=CHAR},
|
||||
#{parentName,jdbcType=CHAR},
|
||||
#{unitcode,jdbcType=VARCHAR}, #{unitname,jdbcType=VARCHAR}, #{pinyin,jdbcType=VARCHAR},
|
||||
#{unittype,jdbcType=VARCHAR}, #{unitaddress,jdbcType=VARCHAR}, #{simplename,jdbcType=VARCHAR},
|
||||
#{principal,jdbcType=VARCHAR}, #{mobiletel,jdbcType=VARCHAR}, #{baseinfo,jdbcType=VARCHAR},
|
||||
|
|
@ -517,6 +529,10 @@
|
|||
<!--部门列表-->
|
||||
<select id="findUnit" resultMap="BaseResultMap">
|
||||
SELECT * FROM SysUnit su
|
||||
where 1 = 1
|
||||
<if test="null != parentUnitId and '' != parentUnitId">
|
||||
and FIND_IN_SET(#{parentUnitId},su.parent_path)
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!--部门列表-->
|
||||
|
|
@ -543,6 +559,9 @@
|
|||
<if test="null != parentId and '' != parentId">
|
||||
AND su.SuperiorUnitId = #{parentId}
|
||||
</if>
|
||||
<if test="null != parentUnitId and '' != parentUnitId">
|
||||
and FIND_IN_SET(#{parentUnitId},su.parent_path)
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!--修改部门-->
|
||||
|
|
@ -551,6 +570,8 @@
|
|||
set
|
||||
OrgCode = #{record.orgcode,jdbcType=VARCHAR},
|
||||
SuperiorUnitId = #{record.superiorunitid,jdbcType=CHAR},
|
||||
parent_path = #{record.parentPath,jdbcType=CHAR},
|
||||
parent_name = #{record.parentName,jdbcType=CHAR},
|
||||
UnitCode = #{record.unitcode,jdbcType=VARCHAR},
|
||||
UnitName = #{record.unitname,jdbcType=VARCHAR},
|
||||
PinYin = #{record.pinyin,jdbcType=VARCHAR},
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ public class PcCompanyController extends BaseController{
|
|||
sysEnterprises.get(0).setOrgName(orgName);
|
||||
|
||||
|
||||
List<SysUnit> units = sysUnitMapper.findUnit();
|
||||
List<SysUnit> units = sysUnitMapper.findUnit("");
|
||||
String sysUnitId = sysEnterprises.get(0).getSysUnitId();
|
||||
String managerDept = sysEnterprises.get(0).getManagerDept();
|
||||
String [] arr=sysUnitId.split(",");
|
||||
|
|
|
|||
|
|
@ -762,7 +762,11 @@ public class PcPersonalController extends com.rzyc.controller.BaseController {
|
|||
@ResponseBody
|
||||
public MultiResult<SysUnit> unitTree()throws Exception{
|
||||
MultiResult<SysUnit> result = new MultiResult<>();
|
||||
List<SysUnit> units = sysUnitMapper.findUnit();
|
||||
|
||||
String userId = getUserId();
|
||||
String parentUnitId = getSuperUnitId(userId);
|
||||
|
||||
List<SysUnit> units = sysUnitMapper.findUnit(parentUnitId);
|
||||
if(units.size() > 0){
|
||||
JSONArray unitJson = handleUnitTree(units);
|
||||
List<SysUnit> sysUnits = JSONArray.parseArray(JSONArray.toJSONString(unitJson),SysUnit.class);
|
||||
|
|
@ -1300,15 +1304,38 @@ public class PcPersonalController extends com.rzyc.controller.BaseController {
|
|||
@ResponseBody
|
||||
public SingleResult<Pager<SysUnit>> unitPage(@Valid UnitPageDto unitPageDto)throws Exception{
|
||||
SingleResult<Pager<SysUnit>> result = new SingleResult<>();
|
||||
|
||||
String userId = getUserId();
|
||||
String parentUnitId = getSuperUnitId(userId);
|
||||
String condition = TypeConversion.getCondition(unitPageDto.getCondition());
|
||||
PageHelper.startPage(unitPageDto.getPage(), unitPageDto.getPageSize());
|
||||
Page<SysUnit> page = (Page<SysUnit>)sysUnitMapper.findByName(condition,unitPageDto.getUnitId());
|
||||
Page<SysUnit> page = (Page<SysUnit>)sysUnitMapper.findByName(condition,unitPageDto.getUnitId(),parentUnitId);
|
||||
Pager<SysUnit> pager = new Pager<>();
|
||||
getDatePage(pager,page);
|
||||
result.setData(pager);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户部门id
|
||||
* @version v1.0
|
||||
* @author dong
|
||||
* @date 2022/12/8 15:00
|
||||
*/
|
||||
private String getSuperUnitId(String userId)throws Exception{
|
||||
String parentUnitId = "";
|
||||
if(StringUtils.isBlank(userId)){
|
||||
userId = getUserId();
|
||||
}
|
||||
if(StringUtils.isNotBlank(userId)){
|
||||
SysUser sysUser = sysUserMapper.findById(userId);
|
||||
if(null != sysUser){
|
||||
parentUnitId = sysUser.getSysunitorentid();
|
||||
}
|
||||
}
|
||||
return parentUnitId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改新增部门
|
||||
* @return
|
||||
|
|
@ -1333,15 +1360,36 @@ public class PcPersonalController extends com.rzyc.controller.BaseController {
|
|||
//查重
|
||||
SysUnit unit = sysUnitMapper.selectByPrimaryKey(sysUnit.getSysunitid());
|
||||
if(null != unit){
|
||||
getUnitPath(sysUnit.getSuperiorunitid(),sysUnit);
|
||||
sysUnitMapper.changeUnit(sysUnit);
|
||||
}else{
|
||||
//新增
|
||||
getUnitPath(sysUnit.getSuperiorunitid(),sysUnit);
|
||||
sysUnitMapper.insert(sysUnit);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @version v1.0
|
||||
* @author dong
|
||||
* @date 2022/12/8 13:52
|
||||
*/
|
||||
public void getUnitPath(String parentId,SysUnit sysUnit)throws Exception{
|
||||
sysUnit.setParentPath(sysUnit.getSysunitid());
|
||||
sysUnit.setParentName(sysUnit.getUnitname());
|
||||
if(StringUtils.isNotBlank(parentId)){
|
||||
SysUnit unit = sysUnitMapper.selectByPrimaryKey(parentId);
|
||||
if(null != unit){
|
||||
sysUnit.setParentPath(unit.getParentPath()+","+sysUnit.getSysunitid());
|
||||
sysUnit.setParentName(unit.getParentName()+","+sysUnit.getUnitname());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 角色分页
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ public class PcCompanyController extends com.rzyc.controller.BaseController {
|
|||
sysEnterprises.get(0).setOrgName(orgName);
|
||||
|
||||
|
||||
List<SysUnit> units = sysUnitMapper.findUnit();
|
||||
List<SysUnit> units = sysUnitMapper.findUnit("");
|
||||
String sysUnitId = sysEnterprises.get(0).getSysUnitId();
|
||||
String managerDept = sysEnterprises.get(0).getManagerDept();
|
||||
String [] arr=sysUnitId.split(",");
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user