机构管理

This commit is contained in:
曹磊 2025-03-27 18:03:38 +08:00
parent 5901c07376
commit a2fe049233
5 changed files with 81 additions and 893 deletions

View File

@ -1,41 +1,14 @@
package com.nu.modules.institution.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nu.modules.institution.entity.InstitutionArea;
import com.nu.modules.institution.model.InstitutionAreaIdModel;
import com.nu.modules.institution.model.InstitutionAreaTreeModel;
import com.nu.modules.institution.service.IInstitutionAreaService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.config.TenantContext;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.ImportExcelUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.mybatis.MybatisPlusSaasConfig;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
/**
@ -53,41 +26,17 @@ public class InstitutionAreaController {
@Autowired
private IInstitutionAreaService service;
/**
* 查询数据 查出所有机构,并以树结构数据格式响应给前端
*
* @return
*/
@RequestMapping(value = "/queryTreeList", method = RequestMethod.GET)
public Result<List<InstitutionAreaTreeModel>> queryTreeList(@RequestParam(name = "ids", required = false) String ids) {
Result<List<InstitutionAreaTreeModel>> result = new Result<>();
try {
if(oConvertUtils.isNotEmpty(ids)){
List<InstitutionAreaTreeModel> departList = service.queryTreeList(ids);
result.setResult(departList);
}else{
List<InstitutionAreaTreeModel> list = service.queryTreeList();
result.setResult(list);
}
result.setSuccess(true);
} catch (Exception e) {
log.error(e.getMessage(),e);
}
return result;
}
/**
* 异步查询机构list
* @param parentId 父节点 异步加载时传递
* @param ids 前端回显是传递
* @param primaryKey 主键字段id或者orgCode
* @return
*/
@RequestMapping(value = "/queryInstTreeSync", method = RequestMethod.GET)
public Result<List<InstitutionAreaTreeModel>> queryInstTreeSync(@RequestParam(name = "pid", required = false) String parentId,@RequestParam(name = "ids", required = false) String ids, @RequestParam(name = "primaryKey", required = false) String primaryKey) {
@RequestMapping(value = "/queryTreeSync", method = RequestMethod.GET)
public Result<List<InstitutionAreaTreeModel>> queryTreeSync(@RequestParam(name = "pid", required = false) String parentId, @RequestParam(name = "primaryKey", required = false) String primaryKey) {
Result<List<InstitutionAreaTreeModel>> result = new Result<>();
try {
List<InstitutionAreaTreeModel> list = service.queryTreeListByPid(parentId,ids, primaryKey);
List<InstitutionAreaTreeModel> list = service.queryTreeListByPid(parentId,primaryKey);
result.setResult(list);
result.setSuccess(true);
} catch (Exception e) {
@ -98,32 +47,6 @@ public class InstitutionAreaController {
return result;
}
/**
* 获取某个机构的所有父级机构的ID
*
* @param instId 根据instId查
* @param orgCode 根据orgCode查instId和orgCode必须有一个不为空
*/
@GetMapping("/queryAllParentId")
public Result queryParentIds(
@RequestParam(name = "instId", required = false) String instId,
@RequestParam(name = "orgCode", required = false) String orgCode) {
try {
JSONObject data;
if (oConvertUtils.isNotEmpty(instId)) {
data = service.queryAllParentIdByInstId(instId);
} else if (oConvertUtils.isNotEmpty(orgCode)) {
data = service.queryAllParentIdByOrgCode(orgCode);
} else {
return Result.error("departId 和 orgCode 不能都为空!");
}
return Result.OK(data);
} catch (Exception e) {
log.error(e.getMessage(), e);
return Result.error(e.getMessage());
}
}
/**
* 添加新数据 添加用户新建的机构对象数据,并保存到数据库
*
@ -169,58 +92,18 @@ public class InstitutionAreaController {
}
/**
* 通过id删除
* @param id
* 删除
* @param institutionArea
* @return
*/
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
public Result<InstitutionArea> delete(@RequestParam(name="id",required=true) String id) {
Result<InstitutionArea> result = new Result<InstitutionArea>();
InstitutionArea InstitutionArea = service.getById(id);
if(InstitutionArea==null) {
result.error500("未找到对应实体");
@PostMapping(value = "/delete")
public Result<String> delete(@RequestBody InstitutionArea institutionArea){
InstitutionArea entity = service.getById(institutionArea.getId());
if(entity==null) {
return Result.error("未找到对应实体");
}else {
service.deleteInst(id);
result.success("删除成功!");
return service.deleteInst(entity);
}
return result;
}
/**
* 批量删除 根据前端请求的多个ID,对数据库执行删除相关机构数据的操作
*
* @param ids
* @return
*/
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
public Result<InstitutionArea> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
Result<InstitutionArea> result = new Result<InstitutionArea>();
if (ids == null || "".equals(ids.trim())) {
result.error500("参数不识别!");
} else {
this.service.deleteBatchWithChildren(Arrays.asList(ids.split(",")));
result.success("删除成功!");
}
return result;
}
/**
* 查询数据 添加或编辑页面对该方法发起请求,以树结构形式加载所有机构的名称,方便用户的操作
*
* @return
*/
@RequestMapping(value = "/queryIdTree", method = RequestMethod.GET)
public Result<List<InstitutionAreaIdModel>> queryIdTree() {
Result<List<InstitutionAreaIdModel>> result = new Result<>();
try {
List<InstitutionAreaIdModel> list = service.queryInstIdTreeList();
result.setResult(list);
result.setSuccess(true);
} catch (Exception e) {
log.error(e.getMessage(),e);
}
return result;
}
/**
@ -232,15 +115,9 @@ public class InstitutionAreaController {
* @return
*/
@RequestMapping(value = "/searchBy", method = RequestMethod.GET)
public Result<List<InstitutionAreaTreeModel>> searchBy(@RequestParam(name = "keyWord", required = true) String keyWord, @RequestParam(name = "myInstSearch", required = false) String myInstSearch) {
public Result<List<InstitutionAreaTreeModel>> searchBy(@RequestParam(name = "keyWord", required = true) String keyWord) {
Result<List<InstitutionAreaTreeModel>> result = new Result<List<InstitutionAreaTreeModel>>();
//机构查询myDeptSearch为1时为我的机构查询登录用户为上级时查只查负责机构下数据
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String instIds = null;
if(oConvertUtils.isNotEmpty(user.getUserIdentity()) && user.getUserIdentity().equals( CommonConstant.USER_IDENTITY_2 )){
instIds = user.getDepartIds();
}
List<InstitutionAreaTreeModel> treeList = this.service.searchByKeyWord(keyWord,myInstSearch,instIds);
List<InstitutionAreaTreeModel> treeList = this.service.searchByKeyWord(keyWord);
if (treeList == null || treeList.size() == 0) {
result.setSuccess(false);
result.setMessage("未查询匹配数据!");
@ -250,93 +127,4 @@ public class InstitutionAreaController {
return result;
}
/**
* 查询所有机构信息
* @return
*/
@GetMapping("listAll")
public Result<List<InstitutionArea>> listAll(@RequestParam(name = "id", required = false) String id) {
Result<List<InstitutionArea>> result = new Result<>();
LambdaQueryWrapper<InstitutionArea> query = new LambdaQueryWrapper<InstitutionArea>();
query.orderByAsc(InstitutionArea::getOrgCode);
if(oConvertUtils.isNotEmpty(id)){
String[] arr = id.split(",");
query.in(InstitutionArea::getId,arr);
}
List<InstitutionArea> ls = this.service.list(query);
result.setSuccess(true);
result.setResult(ls);
return result;
}
/**
* 根据机构编码获取机构信息
*
* @param orgCode
* @return
*/
@GetMapping("/getInstName")
public Result<InstitutionArea> getInstName(@RequestParam(name = "orgCode") String orgCode) {
Result<InstitutionArea> result = new Result<>();
LambdaQueryWrapper<InstitutionArea> query = new LambdaQueryWrapper<>();
query.eq(InstitutionArea::getOrgCode, orgCode);
InstitutionArea InstitutionArea = service.getOne(query);
result.setSuccess(true);
result.setResult(InstitutionArea);
return result;
}
/**
* @功能根据id 批量查询
* @param instIds
* @return
*/
@RequestMapping(value = "/queryByIds", method = RequestMethod.GET)
public Result<Collection<InstitutionArea>> queryByIds(@RequestParam(name = "instIds") String instIds) {
Result<Collection<InstitutionArea>> result = new Result<>();
String[] ids = instIds.split(",");
Collection<String> idList = Arrays.asList(ids);
Collection<InstitutionArea> instList = service.listByIds(idList);
result.setSuccess(true);
result.setResult(instList);
return result;
}
/**
* 异步查询机构list
* @param parentId 父节点 异步加载时传递
* @return
*/
@RequestMapping(value = "/queryBookInstTreeSync", method = RequestMethod.GET)
public Result<List<InstitutionAreaTreeModel>> queryBookDepTreeSync(@RequestParam(name = "pid", required = false) String parentId,
@RequestParam(name = "tenantId") Integer tenantId,
@RequestParam(name = "instName",required = false) String instName) {
Result<List<InstitutionAreaTreeModel>> result = new Result<>();
try {
List<InstitutionAreaTreeModel> list = service.queryBookInstTreeSync(parentId, tenantId, instName);
result.setResult(list);
result.setSuccess(true);
} catch (Exception e) {
log.error(e.getMessage(),e);
}
return result;
}
/**
* 查询所有子区域信息
* @return
*/
@GetMapping("queryChildrenByParentId")
public Result<List<InstitutionArea>> queryChildrenByParentId(@RequestParam(name = "pid", required = false) String parentId) {
Result<List<InstitutionArea>> result = new Result<>();
LambdaQueryWrapper<InstitutionArea> query = new LambdaQueryWrapper<InstitutionArea>();
query.orderByAsc(InstitutionArea::getInstName);
query.eq(InstitutionArea::getParentId,parentId);
List<InstitutionArea> ls = this.service.list(query);
result.setSuccess(true);
result.setResult(ls);
return result;
}
}

View File

@ -20,35 +20,6 @@ import java.util.List;
*/
public interface InstitutionAreaMapper extends BaseMapper<InstitutionArea> {
/**
* 通过机构编码获取机构id
* @param orgCode 机构编码
* @return String
*/
@Select("select id from nu_admin_institution_area where org_code=#{orgCode}")
public String queryInstIdByOrgCode(@Param("orgCode") String orgCode);
/**
* 通过机构id 查询机构id,父id
* @param id 机构id
* @return
*/
@Select("select id,parent_id from nu_admin_institution_area where id=#{id}")
public InstitutionArea getParentInstId(@Param("id") String id);
/**
* 根据机构Id查询,当前和下级所有机构IDS
* @param id
* @return
*/
List<String> getSubInstIdsByInstId(@Param("id") String id);
/**
* 根据机构编码获取机构下所有IDS
* @param orgCodes
* @return
*/
List<String> getSubInstIdsByOrgCodes(@org.apache.ibatis.annotations.Param("orgCodes") String[] orgCodes);
/**
* 根据parent_id查询下级区域
@ -56,6 +27,7 @@ public interface InstitutionAreaMapper extends BaseMapper<InstitutionArea> {
* @return List<InstitutionArea>
*/
List<InstitutionArea> queryTreeListByPid(@Param("parentId") String parentId);
/**
* 根据id下级区域数量
* @param parentId
@ -63,28 +35,6 @@ public interface InstitutionAreaMapper extends BaseMapper<InstitutionArea> {
*/
@Select("SELECT count(*) FROM nu_admin_institution_area where del_flag ='0' AND parent_id = #{parentId,jdbcType=VARCHAR}")
Integer queryCountByPid(@Param("parentId")String parentId);
/**
* 根据OrgCod查询所属机构信息
* @param orgCode
* @return
*/
InstitutionArea queryInstByOrgCode(@Param("orgCode")String orgCode);
/**
* 根据id下级区域
* @param parentId
* @return
*/
@Select("SELECT * FROM nu_admin_institution_area where del_flag ='0' AND parent_id = #{parentId,jdbcType=VARCHAR}")
List<InstitutionArea> queryInstByPid(@Param("parentId")String parentId);
/**
* 通过父级id和租户id查询部门
* @param parentId
* @param tenantId
* @return
*/
@InterceptorIgnore(tenantLine = "true")
List<InstitutionArea> queryBookInstTreeSync(@Param("parentId") String parentId, @Param("tenantId") Integer tenantId, @Param("instName") String instName);
@InterceptorIgnore(tenantLine = "true")
@Select("SELECT * FROM nu_admin_institution_area where id = #{id,jdbcType=VARCHAR}")
@ -102,23 +52,4 @@ public interface InstitutionAreaMapper extends BaseMapper<InstitutionArea> {
@Update("UPDATE nu_admin_institution_area SET iz_leaf=#{leaf} WHERE id = #{id}")
int setMainLeaf(@Param("id") String id, @Param("leaf") Integer leaf);
/**
* 根据机构名称和租户id获取机构数据
* @param instName
* @param tenantId
* @return
*/
List<InstitutionArea> getInstByName(@Param("instName")String instName, @Param("tenantId")Integer tenantId,@Param("parentId") String parentId);
/**
* 根据机构名称和租户id获取分页机构数据
* @param page
* @param instName
* @param tenantId
* @param parentId
* @return
*/
List<InstitutionArea> getInstPageByName(@Param("page") Page<InstitutionArea> page, @Param("instName") String instName, @Param("tenantId") Integer tenantId, @Param("parentId") String parentId);
}

View File

@ -2,21 +2,6 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nu.modules.institution.mapper.InstitutionAreaMapper">
<!-- 根据部门Id查询,当前和下级所有部门IDS -->
<select id="getSubInstIdsByInstId" resultType="java.lang.String">
select id from nu_admin_institution_area
where del_flag = '0'
and org_code like concat((select org_code from nu_admin_institution_area where id=#{id}),'%')
</select>
<!--根据部门编码获取我的部门下所有部门ids -->
<select id="getSubInstIdsByOrgCodes" resultType="java.lang.String">
select id from nu_admin_institution_area where del_flag = '0' and
<foreach collection="orgCodes" item="item" index="index" open="(" separator="or" close=")">
org_code LIKE CONCAT(#{item},'%')
</foreach>
</select>
<!--根据parent_id查询下级区域-->
<select id="queryTreeListByPid" parameterType="Object" resultType="com.nu.modules.institution.entity.InstitutionArea">
SELECT * FROM nu_admin_institution_area where del_flag = '0'
@ -31,36 +16,6 @@
order by inst_order
</select>
<!-- 根据OrgCod查询机构信息 -->
<select id="queryInstByOrgCode" resultType="com.nu.modules.institution.entity.InstitutionArea">
select * from nu_admin_institution_area where del_flag = '0' and org_category='1' and org_code= #{orgCode,jdbcType=VARCHAR}
</select>
<!--通过父级id和租户id查询部门-->
<select id="queryBookInstTreeSync" resultType="com.nu.modules.institution.entity.InstitutionArea">
SELECT * FROM nu_admin_institution_area
WHERE
del_flag = '0'
<if test="tenantId != null">
AND tenant_id = #{tenantId}
</if>
<choose>
<when test="parentId != null and parentId != ''">
AND parent_id = #{parentId}
</when>
<otherwise>
<if test="instName == null or instName == ''">
AND (parent_id is null or parent_id='')
</if>
</otherwise>
</choose>
<if test="instName != null and instName != ''">
<bind name="bindName" value="'%'+instName+'%'"/>
AND inst_name LIKE #{bindName}
</if>
ORDER BY inst_order DESC
</select>
<!--获取机构orgCode最大值的机构信息-->
<select id="getMaxCodeInst" resultType="com.nu.modules.institution.entity.InstitutionArea">
SELECT * FROM nu_admin_institution_area
@ -76,28 +31,4 @@
ORDER BY org_code DESC
</select>
<!--根据机构名称和租户id获取机构数据-->
<select id="getInstByName" resultType="com.nu.modules.institution.entity.InstitutionArea">
SELECT id,inst_name,org_code,parent_id FROM nu_admin_institution_area
where inst_name = #{instName}
<if test="null != tenantId and 0 != tenantId">
and tenant_id = #{tenantId}
</if>
<if test="parentId != null and parentId != ''">
and parent_id = #{parentId}
</if>
order by create_time desc
</select>
<!--根据机构名称和租户id获取分页机构数据-->
<select id="getInstPageByName" resultType="com.nu.modules.institution.entity.InstitutionArea">
SELECT id,inst_name,org_code,parent_id FROM nu_admin_institution_area
where inst_name = #{instName}
and tenant_id = #{tenantId}
<if test="parentId != null and parentId != ''">
and parent_id = #{parentId}
</if>
ORDER BY create_time DESC
</select>
</mapper>

View File

@ -1,12 +1,11 @@
package com.nu.modules.institution.service;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.nu.modules.institution.entity.InstitutionArea;
import com.nu.modules.institution.model.InstitutionAreaIdModel;
import com.nu.modules.institution.model.InstitutionAreaTreeModel;
import org.jeecg.common.api.vo.Result;
import java.util.List;
@ -20,26 +19,6 @@ import java.util.List;
*/
public interface IInstitutionAreaService extends IService<InstitutionArea>{
/**
* 查询所有机构信息,并分节点进行显示
* @return
*/
List<InstitutionAreaTreeModel> queryTreeList();
/**
* 查询所有机构信息,并分节点进行显示
* @param ids 多个机构id
* @return
*/
List<InstitutionAreaTreeModel> queryTreeList(String ids);
/**
* 查询所有机构instId信息,并分节点进行显示
* @return
*/
public List<InstitutionAreaIdModel> queryInstIdTreeList();
/**
* 保存部门数据
* @param InstitutionArea
@ -55,21 +34,12 @@ public interface IInstitutionAreaService extends IService<InstitutionArea>{
*/
Boolean updateInstDataById(InstitutionArea InstitutionArea,String username);
/**
* 删除Inst数据
* @param id
* @return
*/
/* boolean removeInstDataById(String id); */
/**
* 根据关键字搜索相关的部门数据
* @param keyWord
* @param myInstSearch
* @param instIds 多个部门id
* @return
*/
List<InstitutionAreaTreeModel> searchByKeyWord(String keyWord,String myInstSearch,String instIds);
List<InstitutionAreaTreeModel> searchByKeyWord(String keyWord);
/**
* 根据部门id删除并删除其可能存在的子级部门
@ -78,71 +48,26 @@ public interface IInstitutionAreaService extends IService<InstitutionArea>{
*/
boolean delete(String id);
/**
* 根据部门id批量删除并删除其可能存在的子级部门
* @param ids 多个部门id
* @return
*/
void deleteBatchWithChildren(List<String> ids);
/**
* 根据部门Id查询,当前和下级所有部门IDS
* @param instId
* @return
*/
List<String> getSubInstIdsByInstId(String instId);
/**
* 获取我的部门下级所有部门
* @param parentId 父id
* @param ids 多个部门id
* @param primaryKey 主键字段id或者orgCode
* @return
*/
List<InstitutionAreaTreeModel> queryTreeListByPid(String parentId,String ids, String primaryKey);
List<InstitutionAreaTreeModel> queryTreeListByPid(String parentId,String primaryKey);
/**
* 获取某个部门的所有父级部门的ID
*
* @param instId 根据instId查
* @return JSONObject
*/
JSONObject queryAllParentIdByInstId(String instId);
/**
* 获取某个部门的所有父级部门的ID
*
* @param orgCode 根据orgCode查
* @return JSONObject
*/
JSONObject queryAllParentIdByOrgCode(String orgCode);
/**
* 获取公司信息
* @param orgCode 部门编码
* 根据id查询机构信息
* @param parentId
* @return
*/
InstitutionArea queryInstByOrgCode(String orgCode);
/**
* 获取下级部门
* @param pid
* @return
*/
List<InstitutionArea> queryInstByPid(String pid);
IPage<InstitutionArea> getMaxCodeInst(Page<InstitutionArea> page, String parentId);
/**
* 删除部门
* @param id
*/
void deleteInst(String id);
/**
* 通讯录通过租户id查询部门数据
* @param parentId
* @param tenantId
* @param instName
* @return
*/
List<InstitutionAreaTreeModel> queryBookInstTreeSync(String parentId, Integer tenantId, String instName);
Result<String> deleteInst(InstitutionArea institutionArea);
/**
* 根据id查询部门信息
@ -151,18 +76,5 @@ public interface IInstitutionAreaService extends IService<InstitutionArea>{
*/
InstitutionArea getInstById(String parentId);
/**
* 根据id查询部门信息
* @param parentId
* @return
*/
IPage<InstitutionArea> getMaxCodeInst(Page<InstitutionArea> page, String parentId);
/**
* 更新叶子节点
* @param id
* @param izLeaf
*/
void updateIzLeaf(String id, Integer izLeaf);
}

View File

@ -1,7 +1,5 @@
package com.nu.modules.institution.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -11,24 +9,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nu.modules.institution.entity.InstitutionArea;
import com.nu.modules.institution.mapper.InstitutionAreaMapper;
import com.nu.modules.institution.model.InstitutionAreaIdModel;
import com.nu.modules.institution.model.InstitutionAreaTreeModel;
import com.nu.modules.institution.service.IInstitutionAreaService;
import com.nu.modules.institution.utils.FindsInstChildrenUtil;
import com.nu.modules.institution.utils.OrgCodeRule;
import io.netty.util.internal.StringUtil;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.config.TenantContext;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.FillRuleConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.util.FillRuleUtil;
import org.jeecg.common.util.YouBianCodeUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.mybatis.MybatisPlusSaasConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.function.Consumer;
@ -44,68 +32,43 @@ import java.util.function.Consumer;
public class InstitutionAreaServiceImpl extends ServiceImpl<InstitutionAreaMapper, InstitutionArea> implements IInstitutionAreaService {
/**
* queryTreeList 对应 queryTreeList 查询所有的机构数据,以树结构形式响应给前端
* 根据parentId查询机构树
* @param parentId
* @param primaryKey 主键字段id或者orgCode
* @return
*/
@Override
public List<InstitutionAreaTreeModel> queryTreeList() {
LambdaQueryWrapper<InstitutionArea> query = new LambdaQueryWrapper<InstitutionArea>();
//------------------------------------------------------------------------------------------------
//是否开启系统管理模块的多租户数据隔离SAAS多租户模式
if(MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL){
query.eq(InstitutionArea::getTenantId, oConvertUtils.getInt(TenantContext.getTenant(), 0));
public List<InstitutionAreaTreeModel> queryTreeListByPid(String parentId,String primaryKey) {
Consumer<LambdaQueryWrapper<InstitutionArea>> square = i -> {
if(oConvertUtils.isEmpty(parentId)){
i.and(q->q.isNull(true,InstitutionArea::getParentId).or().eq(true,InstitutionArea::getParentId,""));
}else{
i.eq(true,InstitutionArea::getParentId,parentId);
}
//------------------------------------------------------------------------------------------------
query.eq(InstitutionArea::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
query.orderByAsc(InstitutionArea::getInstOrder);
List<InstitutionArea> list = this.list(query);
// 调用wrapTreeDataToTreeList方法生成树状数据
List<InstitutionAreaTreeModel> listResult = FindsInstChildrenUtil.wrapTreeDataToTreeList(list);
return listResult;
};
LambdaQueryWrapper<InstitutionArea> lqw=new LambdaQueryWrapper<>();
lqw.eq(true,InstitutionArea::getDelFlag,CommonConstant.DEL_FLAG_0.toString());
lqw.func(square);
lqw.orderByAsc(InstitutionArea::getInstOrder);
List<InstitutionArea> list = list(lqw);
List<InstitutionAreaTreeModel> records = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
InstitutionArea inst = list.get(i);
InstitutionAreaTreeModel treeModel = new InstitutionAreaTreeModel(inst);
records.add(treeModel);
}
return records;
}
/**
* queryTreeList 根据机构id查询,前端回显调用
* 根据id查询机构信息
* @param parentId
* @return
*/
@Override
public List<InstitutionAreaTreeModel> queryTreeList(String ids) {
List<InstitutionAreaTreeModel> listResult=new ArrayList<>();
LambdaQueryWrapper<InstitutionArea> query = new LambdaQueryWrapper<InstitutionArea>();
query.eq(InstitutionArea::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
if(oConvertUtils.isNotEmpty(ids)){
query.in(true,InstitutionArea::getId,ids.split(","));
public IPage<InstitutionArea> getMaxCodeInst(Page<InstitutionArea> page, String parentId) {
return page.setRecords(baseMapper.getMaxCodeInst(page,parentId));
}
//------------------------------------------------------------------------------------------------
//是否开启系统管理模块的多租户数据隔离SAAS多租户模式
if(MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL){
query.eq(InstitutionArea::getTenantId, oConvertUtils.getInt(TenantContext.getTenant(), 0));
}
//------------------------------------------------------------------------------------------------
query.orderByAsc(InstitutionArea::getInstOrder);
List<InstitutionArea> list= this.list(query);
for (InstitutionArea inst : list) {
listResult.add(new InstitutionAreaTreeModel(inst));
}
return listResult;
}
@Override
public List<InstitutionAreaIdModel> queryInstIdTreeList() {
LambdaQueryWrapper<InstitutionArea> query = new LambdaQueryWrapper<InstitutionArea>();
query.eq(InstitutionArea::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
//------------------------------------------------------------------------------------------------
//是否开启系统管理模块的多租户数据隔离SAAS多租户模式
if(MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL){
query.eq(InstitutionArea::getTenantId, oConvertUtils.getInt(TenantContext.getTenant(), 0));
}
//------------------------------------------------------------------------------------------------
query.orderByAsc(InstitutionArea::getInstOrder);
List<InstitutionArea> list = this.list(query);
// 调用wrapTreeDataToTreeList方法生成树状数据
List<InstitutionAreaIdModel> listResult = FindsInstChildrenUtil.wrapTreeDataToInstIdTreeList(list);
return listResult;
}
/**
* saveInstData 对应 add 保存用户在页面添加的新的机构对象数据
*/
@ -113,24 +76,23 @@ public class InstitutionAreaServiceImpl extends ServiceImpl<InstitutionAreaMappe
@Transactional(rollbackFor = Exception.class)
public void saveInstData(InstitutionArea institutionArea, String username) {
if (institutionArea != null && username != null) {
//update-begin---author:wangshuai ---date:20230216 for[QQYUN-4163]给机构表加个是否有子节点------------
//给机构表加个是否有子节点------------
if (oConvertUtils.isEmpty(institutionArea.getParentId())) {
institutionArea.setParentId("");
}else{
//将父机构的设成不是叶子结点
baseMapper.setMainLeaf(institutionArea.getParentId(),CommonConstant.NOT_LEAF);
}
//update-end---author:wangshuai ---date:20230216 for[QQYUN-4163]给机构表加个是否有子节点------------
//String s = UUID.randomUUID().toString().replace("-", "");
//给机构表加个是否有子节点------------
institutionArea.setId(IdWorker.getIdStr(institutionArea));
// 先判断该对象有无父级ID,有则意味着不是最高级,否则意味着是最高级
// 获取父级ID
String parentId = institutionArea.getParentId();
//update-begin--Author:baihailong Date:20191209 for机构编码规则生成器做成公用配置
//begin--机构编码规则生成器做成公用配置
JSONObject formData = new JSONObject();
formData.put("parentId",parentId);
String[] codeArray = OrgCodeRule.getOrgCode(formData);
//update-end--Author:baihailong Date:20191209 for机构编码规则生成器做成公用配置
//end--机构编码规则生成器做成公用配置
institutionArea.setOrgCode(codeArray[0]);
String orgType = codeArray[1];
institutionArea.setOrgType(String.valueOf(orgType));
@ -138,7 +100,6 @@ public class InstitutionAreaServiceImpl extends ServiceImpl<InstitutionAreaMappe
institutionArea.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
//新添加的机构是叶子节点
institutionArea.setIzLeaf(CommonConstant.IS_LEAF);
// QQYUN-7172数据库默认值兼容
if (oConvertUtils.isEmpty(institutionArea.getOrgCategory())) {
if (oConvertUtils.isEmpty(institutionArea.getParentId())) {
institutionArea.setOrgCategory("1");
@ -148,7 +109,6 @@ public class InstitutionAreaServiceImpl extends ServiceImpl<InstitutionAreaMappe
}
this.save(institutionArea);
}
}
/**
@ -165,56 +125,6 @@ public class InstitutionAreaServiceImpl extends ServiceImpl<InstitutionAreaMappe
} else {
return false;
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteBatchWithChildren(List<String> ids) {
//存放子级的id
List<String> idList = new ArrayList<String>();
//存放父级的id
List<String> parentIdList = new ArrayList<>();
for(String id: ids) {
idList.add(id);
//此步骤是为了删除子级
this.checkChildrenExists(id, idList);
//update-begin---author:wangshuai ---date:20230712 forQQYUN-5757批量删除机构时未正确置为叶子节点 ------------
InstitutionArea inst = this.getInstById(id);
if (oConvertUtils.isNotEmpty(inst.getParentId())) {
if (!parentIdList.contains(inst.getParentId())) {
parentIdList.add(inst.getParentId());
}
}
}
this.removeByIds(idList);
//再删除前需要获取父级id不然会一直为空
this.setParentInstIzLeaf(parentIdList);
}
@Override
public List<String> getSubInstIdsByInstId(String instId) {
return this.baseMapper.getSubInstIdsByInstId(instId);
}
/**
* 清空部门id
*
* @param parentIdList
*/
private void setParentInstIzLeaf(List<String> parentIdList) {
if (CollectionUtil.isNotEmpty(parentIdList)) {
for (String parentId : parentIdList) {
//查询父级id没有子级的时候跟新为叶子节点
LambdaQueryWrapper<InstitutionArea> query = new LambdaQueryWrapper<>();
query.eq(InstitutionArea::getParentId, parentId);
Long count = baseMapper.selectCount(query);
//当子级都不存在时设置当前部门为叶子节点
if (count == 0) {
baseMapper.setMainLeaf(parentId, CommonConstant.IS_LEAF);
}
}
}
}
/**
@ -223,37 +133,16 @@ public class InstitutionAreaServiceImpl extends ServiceImpl<InstitutionAreaMappe
* </p>
*/
@Override
public List<InstitutionAreaTreeModel> searchByKeyWord(String keyWord,String myDeptSearch,String instIds) {
public List<InstitutionAreaTreeModel> searchByKeyWord(String keyWord) {
LambdaQueryWrapper<InstitutionArea> query = new LambdaQueryWrapper<InstitutionArea>();
List<InstitutionAreaTreeModel> newList = new ArrayList<>();
//myDeptSearch不为空时为我的机构搜索只搜索所负责机构
if(!StringUtil.isNullOrEmpty(myDeptSearch)){
//instIds 为空普通用户或没有管理机构
if(StringUtil.isNullOrEmpty(instIds)){
return newList;
}
//根据机构id获取所负责机构
String[] codeArr = this.getMyDeptParentOrgCode(instIds);
//update-begin-author:taoyan date:20220104 for:/issues/3311 当用户属于两个机构的时候且这两个机构没有上下级关系我的机构-机构名称查询条件模糊搜索失效
if (codeArr != null && codeArr.length > 0) {
query.nested(i -> {
for (String s : codeArr) {
i.or().likeRight(InstitutionArea::getOrgCode, s);
}
});
}
//update-end-author:taoyan date:20220104 for:/issues/3311 当用户属于两个机构的时候且这两个机构没有上下级关系我的机构-机构名称查询条件模糊搜索失效
query.eq(InstitutionArea::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
}
query.like(InstitutionArea::getInstName, keyWord);
//update-begin--Author:huangzhilin Date:20140417 for[bugfree号]组织机构搜索回显优化--------------------
InstitutionAreaTreeModel model = new InstitutionAreaTreeModel();
List<InstitutionArea> instList = this.list(query);
if(instList.size() > 0) {
for(InstitutionArea inst : instList) {
model = new InstitutionAreaTreeModel(inst);
model.setChildren(null);
//update-end--Author:huangzhilin Date:20140417 for[bugfree号]组织机构搜索功回显优化----------------------
newList.add(model);
}
return newList;
@ -261,299 +150,26 @@ public class InstitutionAreaServiceImpl extends ServiceImpl<InstitutionAreaMappe
return null;
}
/**
* 根据机构id删除并且删除其可能存在的子级任何机构
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean delete(String id) {
List<String> idList = new ArrayList<>();
idList.add(id);
this.checkChildrenExists(id, idList);
//清空机构树内存
//FindsInstChildrenUtil.clearDepartIdModel();
boolean ok = this.removeByIds(idList);
return ok;
}
/**
* delete 方法调用
* @param id
* @param idList
*/
private void checkChildrenExists(String id, List<String> idList) {
LambdaQueryWrapper<InstitutionArea> query = new LambdaQueryWrapper<InstitutionArea>();
query.eq(InstitutionArea::getParentId,id);
List<InstitutionArea> departList = this.list(query);
if(departList != null && departList.size() > 0) {
for(InstitutionArea depart : departList) {
idList.add(depart.getId());
this.checkChildrenExists(depart.getId(), idList);
}
}
}
/**
* 根据用户所负责机构ids获取父级机构编码
* @param departIds
* @return
*/
private String[] getMyDeptParentOrgCode(String departIds){
//根据机构id查询所负责机构
LambdaQueryWrapper<InstitutionArea> query = new LambdaQueryWrapper<InstitutionArea>();
query.eq(InstitutionArea::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
if(oConvertUtils.isNotEmpty(departIds)){
query.in(InstitutionArea::getId, Arrays.asList(departIds.split(",")));
}
//------------------------------------------------------------------------------------------------
//是否开启系统管理模块的多租户数据隔离SAAS多租户模式
if(MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL){
query.eq(InstitutionArea::getTenantId, oConvertUtils.getInt(TenantContext.getTenant(), 0));
}
//------------------------------------------------------------------------------------------------
query.orderByAsc(InstitutionArea::getOrgCode);
List<InstitutionArea> list = this.list(query);
//查找根机构
if(list == null || list.size()==0){
return null;
}
String orgCode = this.getMyDeptParentNode(list);
String[] codeArr = orgCode.split(",");
return codeArr;
}
/**
* 获取负责机构父节点
* @param list
* @return
*/
private String getMyDeptParentNode(List<InstitutionArea> list){
Map<String,String> map = new HashMap(5);
//1.先将同一公司归类
for(InstitutionArea dept : list){
String code = dept.getOrgCode().substring(0,3);
if(map.containsKey(code)){
String mapCode = map.get(code)+","+dept.getOrgCode();
map.put(code,mapCode);
}else{
map.put(code,dept.getOrgCode());
}
}
StringBuffer parentOrgCode = new StringBuffer();
//2.获取同一公司的根节点
for(String str : map.values()){
String[] arrStr = str.split(",");
parentOrgCode.append(",").append(this.getMinLengthNode(arrStr));
}
return parentOrgCode.substring(1);
}
/**
* 获取同一公司中机构编码长度最小的机构
* @param str
* @return
*/
private String getMinLengthNode(String[] str){
int min =str[0].length();
StringBuilder orgCodeBuilder = new StringBuilder(str[0]);
for(int i =1;i<str.length;i++){
if(str[i].length()<=min){
min = str[i].length();
orgCodeBuilder.append(SymbolConstant.COMMA).append(str[i]);
}
}
return orgCodeBuilder.toString();
}
// /**
// * 获取机构树信息根据关键字
// * @param keyWord
// * @return
// */
// @Override
// public List<InstitutionAreaTreeModel> queryTreeByKeyWord(String keyWord) {
// LambdaQueryWrapper<InstitutionArea> query = new LambdaQueryWrapper<InstitutionArea>();
// query.eq(InstitutionArea::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
// query.orderByAsc(InstitutionArea::getInstOrder);
// List<InstitutionArea> list = this.list(query);
// // 调用wrapTreeDataToTreeList方法生成树状数据
// List<InstitutionAreaTreeModel> listResult = FindsInstChildrenUtil.wrapTreeDataToTreeList(list);
// List<InstitutionAreaTreeModel> treelist =new ArrayList<>();
// if(StringUtils.isNotBlank(keyWord)){
// this.getTreeByKeyWord(keyWord,listResult,treelist);
// }else{
// return listResult;
// }
// return treelist;
// }
/**
* 根据parentId查询机构树
* @param parentId
* @param ids 前端回显传递
* @param primaryKey 主键字段id或者orgCode
* @return
*/
@Override
public List<InstitutionAreaTreeModel> queryTreeListByPid(String parentId,String ids, String primaryKey) {
Consumer<LambdaQueryWrapper<InstitutionArea>> square = i -> {
if (oConvertUtils.isNotEmpty(ids)) {
if (CommonConstant.DEPART_KEY_ORG_CODE.equals(primaryKey)) {
i.in(InstitutionArea::getOrgCode, ids.split(SymbolConstant.COMMA));
} else {
i.in(InstitutionArea::getId, ids.split(SymbolConstant.COMMA));
}
} else {
if(oConvertUtils.isEmpty(parentId)){
i.and(q->q.isNull(true,InstitutionArea::getParentId).or().eq(true,InstitutionArea::getParentId,""));
}else{
i.eq(true,InstitutionArea::getParentId,parentId);
}
}
};
LambdaQueryWrapper<InstitutionArea> lqw=new LambdaQueryWrapper<>();
//------------------------------------------------------------------------------------------------
//是否开启系统管理模块的 SASS 控制
if(MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL){
lqw.eq(InstitutionArea::getTenantId, oConvertUtils.getInt(TenantContext.getTenant(), 0));
}
//------------------------------------------------------------------------------------------------
lqw.eq(true,InstitutionArea::getDelFlag,CommonConstant.DEL_FLAG_0.toString());
lqw.func(square);
//update-begin---author:wangshuai ---date:20220527 for[VUEN-1143]排序不对vue3和2应该都有问题应该按照升序排------------
lqw.orderByAsc(InstitutionArea::getInstOrder);
//update-end---author:wangshuai ---date:20220527 for[VUEN-1143]排序不对vue3和2应该都有问题应该按照升序排--------------
List<InstitutionArea> list = list(lqw);
//update-begin---author:wangshuai ---date:20220316 for[JTC-119]在机构管理菜单下设置机构负责人 创建用户的时候不需要处理
//update-end---author:wangshuai ---date:20220316 for[JTC-119]在机构管理菜单下设置机构负责人 创建用户的时候不需要处理
List<InstitutionAreaTreeModel> records = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
InstitutionArea depart = list.get(i);
InstitutionAreaTreeModel treeModel = new InstitutionAreaTreeModel(depart);
//TODO 异步树加载key拼接__+时间戳,以便于每次展开节点会刷新数据
//treeModel.setKey(treeModel.getKey()+"__"+System.currentTimeMillis());
records.add(treeModel);
}
return records;
}
@Override
public JSONObject queryAllParentIdByInstId(String instId) {
JSONObject result = new JSONObject();
for (String id : instId.split(SymbolConstant.COMMA)) {
JSONObject all = this.queryAllParentId("id", id);
result.put(id, all);
}
return result;
}
@Override
public JSONObject queryAllParentIdByOrgCode(String orgCode) {
JSONObject result = new JSONObject();
for (String code : orgCode.split(SymbolConstant.COMMA)) {
JSONObject all = this.queryAllParentId("org_code", code);
result.put(code, all);
}
return result;
}
/**
* 查询某个机构的所有父ID信息
*
* @param fieldName 字段名
* @param value
*/
private JSONObject queryAllParentId(String fieldName, String value) {
JSONObject data = new JSONObject();
// 父ID集合有序
data.put("parentIds", new JSONArray());
// 父ID的机构数据key是idvalue是数据
data.put("parentMap", new JSONObject());
this.queryAllParentIdRecursion(fieldName, value, data);
return data;
}
/**
* 递归调用查询父机构接口
*/
private void queryAllParentIdRecursion(String fieldName, String value, JSONObject data) {
QueryWrapper<InstitutionArea> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(fieldName, value);
InstitutionArea depart = super.getOne(queryWrapper);
if (depart != null) {
data.getJSONArray("parentIds").add(0, depart.getId());
data.getJSONObject("parentMap").put(depart.getId(), depart);
if (oConvertUtils.isNotEmpty(depart.getParentId())) {
this.queryAllParentIdRecursion("id", depart.getParentId(), data);
}
}
}
@Override
public InstitutionArea queryInstByOrgCode(String orgCode) {
int length = YouBianCodeUtil.ZHANWEI_LENGTH;
String compyOrgCode = orgCode.substring(0,length);
return this.baseMapper.queryInstByOrgCode(compyOrgCode);
}
/**
* 根据id查询下级机构
* @param pid
* @return
*/
@Override
public List<InstitutionArea> queryInstByPid(String pid) {
return this.baseMapper.queryInstByPid(pid);
}
/**
* 根据关键字筛选机构信息
* @param keyWord
* @return
*/
public void getTreeByKeyWord(String keyWord,List<InstitutionAreaTreeModel> allResult,List<InstitutionAreaTreeModel> newResult){
for (InstitutionAreaTreeModel model:allResult) {
if (model.getInstName().contains(keyWord)){
newResult.add(model);
continue;
}else if(model.getChildren()!=null){
getTreeByKeyWord(keyWord,model.getChildren(),newResult);
}
}
}
@Override
public void deleteInst(String id) {
//删除机构设置父级的叶子结点
this.setIzLeaf(id);
this.delete(id);
}
@Override
public List<InstitutionAreaTreeModel> queryBookInstTreeSync(String parentId, Integer tenantId, String instName) {
List<InstitutionArea> list = baseMapper.queryBookInstTreeSync(parentId,tenantId,instName);
List<InstitutionAreaTreeModel> records = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
InstitutionArea depart = list.get(i);
InstitutionAreaTreeModel treeModel = new InstitutionAreaTreeModel(depart);
records.add(treeModel);
}
return records;
}
@Override
public InstitutionArea getInstById(String id) {
return baseMapper.getInstById(id);
}
@Override
public IPage<InstitutionArea> getMaxCodeInst(Page<InstitutionArea> page, String parentId) {
return page.setRecords(baseMapper.getMaxCodeInst(page,parentId));
public Result<String> deleteInst(InstitutionArea institutionArea) {
//判断是否有字节点
int childrenCount = baseMapper.queryCountByPid(institutionArea.getId());
if(childrenCount>0){
if(institutionArea.getOrgCategory().equals("1")){
return Result.error("此机构存在子区域,请将子区域全部删除后再来删除此机构!");
}else{
return Result.error("此区域存在子区域,请将子区域全部删除后再来删除此区域!");
}
@Override
public void updateIzLeaf(String id, Integer izLeaf) {
baseMapper.setMainLeaf(id,izLeaf);
}
//删除机构设置父级的叶子结点
this.setIzLeaf(institutionArea.getId());
this.delete(institutionArea.getId());
return Result.OK("机构删除成功!");
}
/**
@ -572,4 +188,14 @@ public class InstitutionAreaServiceImpl extends ServiceImpl<InstitutionAreaMappe
}
}
/**
* 根据机构id删除并且删除其可能存在的子级任何机构
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean delete(String id) {
boolean ok = this.removeById(id);
return ok;
}
}