tplink项目、分组同步机构和区域

This commit is contained in:
曹磊 2025-03-27 14:13:00 +08:00
parent 20c9431e22
commit 5901c07376
20 changed files with 2443 additions and 54 deletions

View File

@ -0,0 +1,342 @@
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.*;
/**
* <p>
* 机构表 前端控制器
* <p>
*
* @Author: 曹磊 @Since 2025-03-25
*/
@RestController
@RequestMapping("/admin/institutionArea")
@Slf4j
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) {
Result<List<InstitutionAreaTreeModel>> result = new Result<>();
try {
List<InstitutionAreaTreeModel> list = service.queryTreeListByPid(parentId,ids, primaryKey);
result.setResult(list);
result.setSuccess(true);
} catch (Exception e) {
log.error(e.getMessage(),e);
result.setSuccess(false);
result.setMessage("查询失败");
}
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());
}
}
/**
* 添加新数据 添加用户新建的机构对象数据,并保存到数据库
*
* @param InstitutionArea
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result<InstitutionArea> add(@RequestBody InstitutionArea InstitutionArea, HttpServletRequest request) {
Result<InstitutionArea> result = new Result<InstitutionArea>();
String username = JwtUtil.getUserNameByToken(request);
try {
InstitutionArea.setCreateBy(username);
service.saveInstData(InstitutionArea, username);
result.success("添加成功!");
} catch (Exception e) {
log.error(e.getMessage(),e);
result.error500("操作失败");
}
return result;
}
/**
* 编辑数据 编辑机构的部分数据,并保存到数据库
*
* @param InstitutionArea
* @return
*/
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
public Result<InstitutionArea> edit(@RequestBody InstitutionArea InstitutionArea, HttpServletRequest request) {
String username = JwtUtil.getUserNameByToken(request);
InstitutionArea.setUpdateBy(username);
Result<InstitutionArea> result = new Result<InstitutionArea>();
InstitutionArea InstitutionAreaEntity = service.getById(InstitutionArea.getId());
if (InstitutionAreaEntity == null) {
result.error500("未找到对应实体");
} else {
boolean ok = service.updateInstDataById(InstitutionArea, username);
if (ok) {
result.success("修改成功!");
}
}
return result;
}
/**
* 通过id删除
* @param id
* @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("未找到对应实体");
}else {
service.deleteInst(id);
result.success("删除成功!");
}
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;
}
/**
* <p>
* 机构搜索功能方法,根据关键字模糊搜索相关机构
* </p>
*
* @param keyWord
* @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) {
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);
if (treeList == null || treeList.size() == 0) {
result.setSuccess(false);
result.setMessage("未查询匹配数据!");
return result;
}
result.setResult(treeList);
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

@ -0,0 +1,86 @@
package com.nu.modules.institution.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
/**
* <p>
* 机构区域表
* <p>
*
* @Author 曹磊
* @Since 2025-03-25
*/
@Data
@TableName("nu_admin_institution_area")
public class InstitutionArea implements Serializable {
private static final long serialVersionUID = 1L;
/**ID*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**父机构ID*/
private String parentId;
/**机构/部门名称*/
@Excel(name="机构/区域名称",width=15)
private String instName;
/**英文名*/
@Excel(name="英文名",width=15)
private String instNameEn;
/**缩写*/
private String instNameAbbr;
/**排序*/
@Excel(name="排序",width=15)
private Integer instOrder;
/**描述*/
@Excel(name="描述",width=15)
private String description;
/**机构类别 1=机构2=区域*/
@Excel(name="机构区域类别",width=15,dicCode="inst_category")
private String orgCategory;
/**机构类型 1一级部门 2子部门*/
private String orgType;
/**机构编码*/
@Excel(name="机构编码",width=15)
private String orgCode;
/**手机号*/
@Excel(name="手机号",width=15)
private String mobile;
/**地址*/
@Excel(name="地址",width=15)
private String address;
/**状态1启用0不启用*/
@Dict(dicCode = "depart_status")
private String status;
/**删除状态0正常1已删除*/
@Dict(dicCode = "del_flag")
private String delFlag;
/**创建人*/
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**更新人*/
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date updateTime;
/**租户ID*/
private Integer tenantId;
/**是否有叶子节点: 1是0否*/
private Integer izLeaf;
}

View File

@ -0,0 +1,124 @@
package com.nu.modules.institution.mapper;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nu.modules.institution.entity.InstitutionArea;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
* <p>
* 机构 Mapper 接口
* <p>
*
* @Author: 曹磊
* @Since 2025-03-25
*/
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查询下级区域
* @param parentId 父id
* @return List<InstitutionArea>
*/
List<InstitutionArea> queryTreeListByPid(@Param("parentId") String parentId);
/**
* 根据id下级区域数量
* @param parentId
* @return
*/
@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}")
InstitutionArea getInstById(@Param("id") String id);
@InterceptorIgnore(tenantLine = "true")
List<InstitutionArea> getMaxCodeInst(@Param("page") Page<InstitutionArea> page, @Param("parentId") String parentId);
/**
* 修改部门状态字段 是否子节点
* @param id 部门id
* @param leaf 叶子节点
* @return int
*/
@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

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<!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'
<choose>
<when test="parentId != null and parentId != ''">
AND parent_id = #{parentId,jdbcType=VARCHAR}
</when>
<otherwise>
AND parent_id is null or parent_id=''
</otherwise>
</choose>
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
WHERE
<choose>
<when test="parentId != null and parentId != ''">
parent_id = #{parentId}
</when>
<otherwise>
parent_id IS NULL OR parent_id=''
</otherwise>
</choose>
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

@ -0,0 +1,98 @@
package com.nu.modules.institution.model;
import com.nu.modules.institution.entity.InstitutionArea;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 机构表 封装树结构的机构的名称的实体类
* <p>
*
* @Author Steve
* @Since 2019-01-22
*
*/
public class InstitutionAreaIdModel implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
private String key;
/**
* 主键ID
*/
private String value;
/**
* 机构名称
*/
private String title;
List<InstitutionAreaIdModel> children = new ArrayList<>();
/**
* 将SysDepartTreeModel的部分数据放在该对象当中
* @param treeModel
* @return
*/
public InstitutionAreaIdModel convert(InstitutionAreaTreeModel treeModel) {
this.key = treeModel.getId();
this.value = treeModel.getId();
this.title = treeModel.getInstName();
return this;
}
/**
* 该方法为用户机构的实现类所使用
* @param inst
* @return
*/
public InstitutionAreaIdModel convertByUserDepart(InstitutionArea inst) {
this.key = inst.getId();
this.value = inst.getId();
this.title = inst.getInstName();
return this;
}
public List<InstitutionAreaIdModel> getChildren() {
return children;
}
public void setChildren(List<InstitutionAreaIdModel> children) {
this.children = children;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}

View File

@ -0,0 +1,357 @@
package com.nu.modules.institution.model;
import com.nu.modules.institution.entity.InstitutionArea;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* <p>
* 机构表 存储树结构数据的实体类
* <p>
*
* @Author 曹磊
* @Since 2025-03-25
*/
public class InstitutionAreaTreeModel implements Serializable{
private static final long serialVersionUID = 1L;
/** 对应InstitutionArea中的id字段,前端数据树中的key*/
private String key;
/** 对应InstitutionArea中的id字段,前端数据树中的value*/
private String value;
/** 对应inst_name字段,前端数据树中的title*/
private String title;
private boolean isLeaf;
// 以下所有字段均与InstitutionArea相同
private String id;
private String parentId;
private String instName;
private String instNameEn;
private String instNameAbbr;
private Integer instOrder;
private String description;
private String orgCategory;
private String orgType;
private String orgCode;
private String mobile;
private String address;
private String status;
private String delFlag;
private String createBy;
private Date createTime;
private String updateBy;
private Date updateTime;
//update-begin---author:wangshuai ---date:20200308 for[JTC-119]在部门管理菜单下设置部门负责人新增字段部门负责人ids
/**部门负责人ids*/
private String directorUserIds;
//update-end---author:wangshuai ---date:20200308 for[JTC-119]在部门管理菜单下设置部门负责人新增字段部门负责人ids
private List<InstitutionAreaTreeModel> children = new ArrayList<>();
/**
* 将InstitutionArea对象转换成InstitutionAreaTreeModel对象
* @param inst
*/
public InstitutionAreaTreeModel(InstitutionArea inst) {
this.key = inst.getId();
this.value = inst.getId();
this.title = inst.getInstName();
this.id = inst.getId();
this.parentId = inst.getParentId();
this.instName = inst.getInstName();
this.instNameEn = inst.getInstNameEn();
this.instNameAbbr = inst.getInstNameAbbr();
this.instOrder = inst.getInstOrder();
this.description = inst.getDescription();
this.orgCategory = inst.getOrgCategory();
this.orgType = inst.getOrgType();
this.orgCode = inst.getOrgCode();
this.mobile = inst.getMobile();
this.address = inst.getAddress();
this.status = inst.getStatus();
this.delFlag = inst.getDelFlag();
this.createBy = inst.getCreateBy();
this.createTime = inst.getCreateTime();
this.updateBy = inst.getUpdateBy();
this.updateTime = inst.getUpdateTime();
if(0 == inst.getIzLeaf()){
this.isLeaf = false;
}else{
this.isLeaf = true;
}
}
public boolean getIsLeaf() {
return isLeaf;
}
public void setIsLeaf(boolean isleaf) {
this.isLeaf = isleaf;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public List<InstitutionAreaTreeModel> getChildren() {
return children;
}
public void setChildren(List<InstitutionAreaTreeModel> children) {
if (children==null){
this.isLeaf=true;
}
this.children = children;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getInstName() {
return instName;
}
public void setInstName(String instName) {
this.instName = instName;
}
public String getOrgCategory() {
return orgCategory;
}
public void setOrgCategory(String orgCategory) {
this.orgCategory = orgCategory;
}
public String getOrgType() {
return orgType;
}
public void setOrgType(String orgType) {
this.orgType = orgType;
}
public String getOrgCode() {
return orgCode;
}
public void setOrgCode(String orgCode) {
this.orgCode = orgCode;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getInstNameEn() {
return instNameEn;
}
public void setInstNameEn(String instNameEn) {
this.instNameEn = instNameEn;
}
public String getInstNameAbbr() {
return instNameAbbr;
}
public void setInstNameAbbr(String instNameAbbr) {
this.instNameAbbr = instNameAbbr;
}
public Integer getInstOrder() {
return instOrder;
}
public void setInstOrder(Integer instOrder) {
this.instOrder = instOrder;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getDelFlag() {
return delFlag;
}
public void setDelFlag(String delFlag) {
this.delFlag = delFlag;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public InstitutionAreaTreeModel() { }
/**
* 重写equals方法
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
InstitutionAreaTreeModel model = (InstitutionAreaTreeModel) o;
return Objects.equals(id, model.id) &&
Objects.equals(parentId, model.parentId) &&
Objects.equals(instName, model.instName) &&
Objects.equals(instNameEn, model.instNameEn) &&
Objects.equals(instNameAbbr, model.instNameAbbr) &&
Objects.equals(instOrder, model.instOrder) &&
Objects.equals(description, model.description) &&
Objects.equals(orgCategory, model.orgCategory) &&
Objects.equals(orgType, model.orgType) &&
Objects.equals(orgCode, model.orgCode) &&
Objects.equals(mobile, model.mobile) &&
Objects.equals(address, model.address) &&
Objects.equals(status, model.status) &&
Objects.equals(delFlag, model.delFlag) &&
Objects.equals(createBy, model.createBy) &&
Objects.equals(createTime, model.createTime) &&
Objects.equals(updateBy, model.updateBy) &&
Objects.equals(updateTime, model.updateTime) &&
Objects.equals(children, model.children);
}
/**
* 重写hashCode方法
*/
@Override
public int hashCode() {
return Objects.hash(id, parentId, instName, instNameEn, instNameAbbr,
instOrder, description, orgCategory, orgType, orgCode, mobile, address,
status, delFlag, createBy, createTime, updateBy, updateTime,
children);
}
}

View File

@ -0,0 +1,168 @@
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 java.util.List;
/**
* <p>
* 机构表 服务实现类
* <p>
*
* @Author 曹磊
* @Since 2025-03-25
*/
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
* @param username 用户名
*/
void saveInstData(InstitutionArea InstitutionArea,String username);
/**
* 更新Inst数据
* @param InstitutionArea
* @param username 用户名
* @return
*/
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);
/**
* 根据部门id删除并删除其可能存在的子级部门
* @param id
* @return
*/
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);
/**
* 获取某个部门的所有父级部门的ID
*
* @param instId 根据instId查
* @return JSONObject
*/
JSONObject queryAllParentIdByInstId(String instId);
/**
* 获取某个部门的所有父级部门的ID
*
* @param orgCode 根据orgCode查
* @return JSONObject
*/
JSONObject queryAllParentIdByOrgCode(String orgCode);
/**
* 获取公司信息
* @param orgCode 部门编码
* @return
*/
InstitutionArea queryInstByOrgCode(String orgCode);
/**
* 获取下级部门
* @param pid
* @return
*/
List<InstitutionArea> queryInstByPid(String pid);
/**
* 删除部门
* @param id
*/
void deleteInst(String id);
/**
* 通讯录通过租户id查询部门数据
* @param parentId
* @param tenantId
* @param instName
* @return
*/
List<InstitutionAreaTreeModel> queryBookInstTreeSync(String parentId, Integer tenantId, String instName);
/**
* 根据id查询部门信息
* @param parentId
* @return
*/
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

@ -0,0 +1,575 @@
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;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
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.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;
/**
* <p>
* 机构表 服务实现类
* <p>
*
* @Author 曹磊
* @Since 2025-03-25
*/
@Service
public class InstitutionAreaServiceImpl extends ServiceImpl<InstitutionAreaMapper, InstitutionArea> implements IInstitutionAreaService {
/**
* queryTreeList 对应 queryTreeList 查询所有的机构数据,以树结构形式响应给前端
*/
@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));
}
//------------------------------------------------------------------------------------------------
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;
}
/**
* queryTreeList 根据机构id查询,前端回显调用
*/
@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(","));
}
//------------------------------------------------------------------------------------------------
//是否开启系统管理模块的多租户数据隔离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 保存用户在页面添加的新的机构对象数据
*/
@Override
@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机构编码规则生成器做成公用配置
JSONObject formData = new JSONObject();
formData.put("parentId",parentId);
String[] codeArray = OrgCodeRule.getOrgCode(formData);
//update-end--Author:baihailong Date:20191209 for机构编码规则生成器做成公用配置
institutionArea.setOrgCode(codeArray[0]);
String orgType = codeArray[1];
institutionArea.setOrgType(String.valueOf(orgType));
institutionArea.setCreateTime(new Date());
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");
} else {
institutionArea.setOrgCategory("2");
}
}
this.save(institutionArea);
}
}
/**
* updateInstDataById 对应 edit 根据机构主键来更新对应的机构数据
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateInstDataById(InstitutionArea institutionArea, String username) {
if (institutionArea != null && username != null) {
institutionArea.setUpdateTime(new Date());
institutionArea.setUpdateBy(username);
this.updateById(institutionArea);
return true;
} 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);
}
}
}
}
/**
* <p>
* 根据关键字搜索相关的机构数据
* </p>
*/
@Override
public List<InstitutionAreaTreeModel> searchByKeyWord(String keyWord,String myDeptSearch,String instIds) {
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;
}
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));
}
@Override
public void updateIzLeaf(String id, Integer izLeaf) {
baseMapper.setMainLeaf(id,izLeaf);
}
/**
* 设置父级节点是否存在叶子结点
* @param id
*/
private void setIzLeaf(String id) {
InstitutionArea inst = this.getInstById(id);
String parentId = inst.getParentId();
if(oConvertUtils.isNotEmpty(parentId)){
Long count = this.count(new QueryWrapper<InstitutionArea>().lambda().eq(InstitutionArea::getParentId, parentId));
if(count == 1){
//若父节点无其他子节点则该父节点是叶子节点
baseMapper.setMainLeaf(parentId, CommonConstant.IS_LEAF);
}
}
}
}

View File

@ -0,0 +1,180 @@
package com.nu.modules.institution.utils;
import io.netty.util.internal.StringUtil;
import org.jeecg.common.util.oConvertUtils;
/**
* 流水号生成规则(按默认规则递增数字从1-999开始递增数字到999递增字母;位数不够增加位数)
* A001
* A001A002
* @Author 曹磊
*
*/
public class FindOrgCodeUtil {
// 数字位数(默认生成3位的数字)
/**代表数字位数*/
private static final int NUM_LENGTH = 3;
public static final int ZHANWEI_LENGTH = 1+ NUM_LENGTH;
public static final char LETTER= 'Z';
/**
* 根据前一个code获取同级下一个code
* 例如:当前最大code为A001A004下一个code为A001A005
*
* @param code
* @return
*/
public static synchronized String getNextOrgCode(String code) {
String newcode = "";
if (oConvertUtils.isEmpty(code)) {
String zimu = "A";
String num = getStrNum(1);
newcode = zimu + num;
} else {
String beforeCode = code.substring(0, code.length() - 1- NUM_LENGTH);
String afterCode = code.substring(code.length() - 1 - NUM_LENGTH,code.length());
char afterCodeZimu = afterCode.substring(0, 1).charAt(0);
Integer afterCodeNum = Integer.parseInt(afterCode.substring(1));
String nextNum = "";
char nextZimu = 'A';
// 先判断数字等于999*则计数从1重新开始递增
if (afterCodeNum == getMaxNumByLength(NUM_LENGTH)) {
nextNum = getNextStrNum(0);
} else {
nextNum = getNextStrNum(afterCodeNum);
}
// 先判断数字等于999*则字母从A重新开始,递增
if(afterCodeNum == getMaxNumByLength(NUM_LENGTH)) {
nextZimu = getNextZiMu(afterCodeZimu);
}else{
nextZimu = afterCodeZimu;
}
// 例如Z99下一个code就是Z99A01
if (LETTER == afterCodeZimu && getMaxNumByLength(NUM_LENGTH) == afterCodeNum) {
newcode = code + (nextZimu + nextNum);
} else {
newcode = beforeCode + (nextZimu + nextNum);
}
}
return newcode;
}
/**
* 根据父亲code,获取下级的下一个code
*
* 例如父亲CODE:A001
* 当前CODE:A001B003
* 获取的code:A001B004
*
* @param parentCode 上级code
* @param localCode 同级code
* @return
*/
public static synchronized String getSubOrgCode(String parentCode,String localCode) {
if(localCode!=null && localCode!=""){
return getNextOrgCode(localCode);
}else{
parentCode = parentCode + "A"+ getNextStrNum(0);
}
return parentCode;
}
/**
* 将数字前面位数补零
*
* @param num
* @return
*/
private static String getNextStrNum(int num) {
return getStrNum(getNextNum(num));
}
/**
* 将数字前面位数补零
*
* @param num
* @return
*/
private static String getStrNum(int num) {
String s = String.format("%0" + NUM_LENGTH + "d", num);
return s;
}
/**
* 递增获取下个数字
*
* @param num
* @return
*/
private static int getNextNum(int num) {
num++;
return num;
}
/**
* 递增获取下个字母
*
* @param zimu
* @return
*/
private static char getNextZiMu(char zimu) {
if (zimu == LETTER) {
return 'A';
}
zimu++;
return zimu;
}
/**
* 根据数字位数获取最大值
* @param length
* @return
*/
private static int getMaxNumByLength(int length){
if(length==0){
return 0;
}
StringBuilder maxNum = new StringBuilder();
for (int i=0;i<length;i++){
maxNum.append("9");
}
return Integer.parseInt(maxNum.toString());
}
public static String[] cutOrgCode(String code){
if(code==null || StringUtil.isNullOrEmpty(code)){
return null;
}else{
//获取标准长度为numLength+1,截取的数量为code.length/numLength+1
int c = code.length()/(NUM_LENGTH +1);
String[] cutcode = new String[c];
for(int i =0 ; i <c;i++){
cutcode[i] = code.substring(0,(i+1)*(NUM_LENGTH +1));
}
return cutcode;
}
}
// public static void main(String[] args) {
// String s = getNextOrgCode("A001A002");
// System.out.println(s);
// char c1 = getNextZiMu('C');
// int n = getNextNum(8);
// String[] ss = cutOrgCode("C099A001B001");
// System.out.println(c1);
// System.out.println(n);
// for(int i=0;i<ss.length;i++){
// System.out.println(ss[i]);
// }
// }
}

View File

@ -0,0 +1,108 @@
package com.nu.modules.institution.utils;
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.util.oConvertUtils;
import java.util.ArrayList;
import java.util.List;
/**
* <P>
* 对应机构的表,处理并查找树级数据
* <P>
*
* @Author: 曹磊
* @Date: 2025-03-25
*/
public class FindsInstChildrenUtil {
/**
* queryTreeList的子方法 ====1=====
* 该方法是s将InstitutionArea类型的list集合转换成InstitutionAreaTreeModel类型的集合
*/
public static List<InstitutionAreaTreeModel> wrapTreeDataToTreeList(List<InstitutionArea> recordList) {
List<InstitutionAreaIdModel> idList = new ArrayList<InstitutionAreaIdModel>();
List<InstitutionAreaTreeModel> records = new ArrayList<>();
for (int i = 0; i < recordList.size(); i++) {
InstitutionArea inst = recordList.get(i);
records.add(new InstitutionAreaTreeModel(inst));
}
List<InstitutionAreaTreeModel> tree = findChildren(records, idList);
setEmptyChildrenAsNull(tree);
return tree;
}
/**
* 获取 InstitutionAreaIdModel
* @param recordList
* @return
*/
public static List<InstitutionAreaIdModel> wrapTreeDataToInstIdTreeList(List<InstitutionArea> recordList) {
List<InstitutionAreaIdModel> idList = new ArrayList<InstitutionAreaIdModel>();
List<InstitutionAreaTreeModel> records = new ArrayList<>();
for (int i = 0; i < recordList.size(); i++) {
InstitutionArea inst = recordList.get(i);
records.add(new InstitutionAreaTreeModel(inst));
}
findChildren(records, idList);
return idList;
}
/**
* queryTreeList的子方法 ====2=====
* 该方法是找到并封装顶级父类的节点到TreeList集合
*/
private static List<InstitutionAreaTreeModel> findChildren(List<InstitutionAreaTreeModel> recordList, List<InstitutionAreaIdModel> instIdList) {
List<InstitutionAreaTreeModel> treeList = new ArrayList<>();
for (int i = 0; i < recordList.size(); i++) {
InstitutionAreaTreeModel branch = recordList.get(i);
if (oConvertUtils.isEmpty(branch.getParentId())) {
treeList.add(branch);
InstitutionAreaIdModel InstitutionAreaIdModel = new InstitutionAreaIdModel().convert(branch);
instIdList.add(InstitutionAreaIdModel);
}
}
getGrandChildren(treeList,recordList,instIdList);
return treeList;
}
/**
* queryTreeList的子方法====3====
*该方法是找到顶级父类下的所有子节点集合并封装到TreeList集合
*/
private static void getGrandChildren(List<InstitutionAreaTreeModel> treeList,List<InstitutionAreaTreeModel> recordList,List<InstitutionAreaIdModel> idList) {
for (int i = 0; i < treeList.size(); i++) {
InstitutionAreaTreeModel model = treeList.get(i);
InstitutionAreaIdModel idModel = idList.get(i);
for (int i1 = 0; i1 < recordList.size(); i1++) {
InstitutionAreaTreeModel m = recordList.get(i1);
if (m.getParentId()!=null && m.getParentId().equals(model.getId())) {
model.getChildren().add(m);
InstitutionAreaIdModel dim = new InstitutionAreaIdModel().convert(m);
idModel.getChildren().add(dim);
}
}
getGrandChildren(treeList.get(i).getChildren(), recordList, idList.get(i).getChildren());
}
}
/**
* queryTreeList的子方法 ====4====
* 该方法是将子节点为空的List集合设置为Null值
*/
private static void setEmptyChildrenAsNull(List<InstitutionAreaTreeModel> treeList) {
for (int i = 0; i < treeList.size(); i++) {
InstitutionAreaTreeModel model = treeList.get(i);
if (model.getChildren().size() == 0) {
model.setChildren(null);
model.setIsLeaf(true);
}else{
setEmptyChildrenAsNull(model.getChildren());
model.setIsLeaf(false);
}
}
}
}

View File

@ -0,0 +1,78 @@
package com.nu.modules.institution.utils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nu.modules.institution.entity.InstitutionArea;
import com.nu.modules.institution.service.impl.InstitutionAreaServiceImpl;
import io.netty.util.internal.StringUtil;
import org.jeecg.common.util.SpringContextUtils;
import java.util.List;
/**
* @Author scott
* @Date 2019/12/9 11:33
* @Description: 机构编码生成规则
*/
public class OrgCodeRule{
public static String[] getOrgCode(JSONObject params) {
InstitutionAreaServiceImpl institutionAreaService = (InstitutionAreaServiceImpl) SpringContextUtils.getBean("institutionAreaServiceImpl");
String[] strArray = new String[2];
//定义机构类型
String orgType = "";
// 定义新编码字符串
String newOrgCode = "";
// 定义旧编码字符串
String oldOrgCode = "";
String parentId = null;
Object obj = params.get("parentId");
if (obj != null) {
parentId = obj.toString();
}
//如果是最高级,则查询出同级的org_code, 调用工具类生成编码并返回
if (StringUtil.isNullOrEmpty(parentId)) {
// 线判断数据库中的表是否为空,空则直接返回初始编码
//获取最大值code的机构信息
Page<InstitutionArea> page = new Page<>(1,1);
IPage<InstitutionArea> pageList = institutionAreaService.getMaxCodeInst(page,"");
List<InstitutionArea> records = pageList.getRecords();
if (null==records || records.size()==0) {
strArray[0] = FindOrgCodeUtil.getNextOrgCode(null);
strArray[1] = "1";
return strArray;
} else {
InstitutionArea depart = records.get(0);
oldOrgCode = depart.getOrgCode();
orgType = depart.getOrgType();
newOrgCode = FindOrgCodeUtil.getNextOrgCode(oldOrgCode);
}
} else {//反之则查询出所有同级的机构,获取结果后有两种情况,有同级和没有同级
//获取自己机构最大值orgCode机构信息
Page<InstitutionArea> page = new Page<>(1,1);
IPage<InstitutionArea> pageList = institutionAreaService.getMaxCodeInst(page,parentId);
List<InstitutionArea> records = pageList.getRecords();
// 查询出父级机构
InstitutionArea depart = institutionAreaService.getInstById(parentId);
// 获取父级机构的Code
String parentCode = depart.getOrgCode();
// 根据父级机构类型算出当前机构的类型
orgType = String.valueOf(Integer.valueOf(depart.getOrgType()) + 1);
// 处理同级机构为null的情况
if (null == records || records.size()==0) {
// 直接生成当前的机构编码并返回
newOrgCode = FindOrgCodeUtil.getSubOrgCode(parentCode, null);
} else { //处理有同级机构的情况
// 获取同级机构的编码,利用工具类
String subCode = records.get(0).getOrgCode();
// 返回生成的当前机构编码
newOrgCode = FindOrgCodeUtil.getSubOrgCode(parentCode, subCode);
}
}
// 返回最终封装了机构编码和机构类型的数组
strArray[0] = newOrgCode;
strArray[1] = orgType;
return strArray;
}
}

View File

@ -50,6 +50,7 @@ public enum ApiEnum {
IPC_SEARCH_VIDEO("/tums/playback/v3/searchVideo","搜索当天的录像数据V3"),
IPC_ADD_PLAYBACK_CHN("/tums/playback/v2/addPlaybackChn","添加回放通道V2"),
IPC_GET_MULTITRANS_URL("/tums/playback/v1/getMultitransUrl","获取nvmp设备双向通信URL"),
/** =================>暂时无用 **/
IPC_GET_RECORD_CFGS("/tums/record/v1/getRecordCfgs","获取录像配置"),
IPC_SET_RECORD_CFGS("/tums/record/v1/setRecordCfgs","设置录像计划"),
IPC_GET_BATCH_PROGRESS("/tums/record/v1/getBatchProgress","获取批量操作录像计划进度"),
@ -62,6 +63,7 @@ public enum ApiEnum {
IPC_MODIFY_TOUR("/tums/ptz/v1/modifyTour","修改高速球机的巡航点配置"),
IPC_EXECUTE_TOUR("/tums/ptz/v1/executeTour","操作高速球机的巡航点"),
IPC_DELETE_TOUR("/tums/ptz/v1/deleteTour","删除高速球机巡航点"),
/** <==================暂时无用 **/
IPC_UPLOAD_TO_SERVER("/tums/playback/v1/uploadToServer","回放视频转mp4上传"),
IPC_STOP_UPLOAD_TO_SERVER("/tums/preview/v1/stopUploadToServer","停止转存MP4上传任务"),
IPC_GET_UPLOAD_TO_SERVER_PROCESS("/tums/preview/v1/getUploadToServerProcess","获取转存MP4上传任务进度");

View File

@ -47,8 +47,8 @@ public class ProjectInfo implements Serializable {
/**机构ID*/
@Excel(name = "机构ID", width = 15)
@ApiModelProperty(value = "机构ID")
@Dict(dicCode = "id" , dictTable = "sys_depart" , dicText = "depart_name")
private String institutionalId;
@Dict(dicCode = "id" , dictTable = "nu_admin_institution_area" , dicText = "inst_name")
private String institutionId;
/**创建时间戳,单位秒*/
@ApiModelProperty(value = "创建时间戳,单位秒")
private String createTime;

View File

@ -7,7 +7,7 @@
select id,
project_id as projectId,
project_name as projectName,
institutional_id as institutionalId,
institution_id as institutionId,
create_time as createTime,
device_num as deviceNum,
message_num as messageNum,
@ -31,7 +31,7 @@
select id,
project_id as projectId,
project_name as projectName,
institutional_id as institutionalId,
institution_id as institutionId,
create_time as createTime,
device_num as deviceNum,
message_num as messageNum,
@ -60,7 +60,7 @@
select id,
project_id as projectId,
project_name as projectName,
institutional_id as institutionalId,
institution_id as institutionId,
create_time as createTime,
DATE_FORMAT(FROM_UNIXTIME(create_time),'%Y-%m-%d %H:%i:%s') as createTimeStr,
device_num as deviceNum,
@ -85,7 +85,7 @@
<insert id="add">
insert into nu_iot_tplink_project(project_id,
project_name,
institutional_id,
institution_id,
create_time,
device_num,
message_num,
@ -104,7 +104,7 @@
iz_leaf)
values (#{projectId},
#{projectName},
#{institutionalId},
#{institutionId},
#{createTime},
#{deviceNum},
#{messageNum},
@ -129,8 +129,8 @@
<if test="projectName != null and projectName != ''">
project_name = #{projectName},
</if>
<if test="institutionalId != null and institutionalId != ''">
institutional_id = #{institutionalId},
<if test="institutionId != null and institutionId != ''">
institution_id = #{institutionId},
</if>
<if test="createTime != null and createTime != ''">
create_time = #{createTime},
@ -179,7 +179,7 @@
update nu_iot_tplink_project
set project_id = #{projectId},
project_name = #{projectName},
institutional_id = #{institutionalId},
institution_id = #{institutionId},
create_time = #{createTime},
device_num = #{deviceNum},
message_num = #{messageNum},
@ -214,7 +214,7 @@
select id,
project_id as projectId,
project_name as projectName,
institutional_id as institutionalId,
institution_id as institutionId,
create_time as createTime,
DATE_FORMAT(FROM_UNIXTIME(create_time),'%Y-%m-%d %H:%i:%s') as createTimeStr,
device_num as deviceNum,

View File

@ -39,7 +39,7 @@ public class ProjectTreeModel implements Serializable{
private String projectName;
private String institutionalId;
private String institutionId;
private String createTimeStr;
@ -72,7 +72,7 @@ public class ProjectTreeModel implements Serializable{
this.id = "0";
this.projectId = projectInfo.getProjectId();
this.projectName = projectInfo.getProjectName();
this.institutionalId = projectInfo.getInstitutionalId();
this.institutionId = projectInfo.getInstitutionId();
this.createTimeStr = projectInfo.getCreateTimeStr();
this.deviceNum = projectInfo.getDeviceNum();
this.offlineNum = projectInfo.getOfflineNum();
@ -167,12 +167,12 @@ public class ProjectTreeModel implements Serializable{
this.projectName = projectName;
}
public String getInstitutionalId() {
return institutionalId;
public String getInstitutionId() {
return institutionId;
}
public void setInstitutionalId(String institutionalId) {
this.institutionalId = institutionalId;
public void setInstitutionId(String institutionId) {
this.institutionId = institutionId;
}
public String getCreateTimeStr() {
@ -254,7 +254,7 @@ public class ProjectTreeModel implements Serializable{
return Objects.equals(id, model.id) &&
Objects.equals(projectId, model.projectId) &&
Objects.equals(projectName, model.projectName) &&
Objects.equals(institutionalId, model.institutionalId) &&
Objects.equals(institutionId, model.institutionId) &&
Objects.equals(createTimeStr, model.createTimeStr) &&
Objects.equals(deviceNum, model.deviceNum) &&
Objects.equals(offlineNum, model.offlineNum) &&
@ -271,7 +271,7 @@ public class ProjectTreeModel implements Serializable{
*/
@Override
public int hashCode() {
return Objects.hash(id, projectId, projectName, institutionalId, createTimeStr, deviceNum ,offlineNum ,abnormalNum ,runningTimeStr ,status ,order, sort, children);
return Objects.hash(id, projectId, projectName, institutionId, createTimeStr, deviceNum ,offlineNum ,abnormalNum ,runningTimeStr ,status ,order, sort, children);
}
}

View File

@ -10,6 +10,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecgframework.poi.excel.annotation.Excel;
import java.io.Serializable;
@ -40,6 +41,15 @@ public class RegionInfo implements Serializable {
@Excel(name = "分组名称", width = 15)
@ApiModelProperty(value = "分组名称")
private String regionName;
/**机构ID*/
@Excel(name = "区域ID", width = 15)
@ApiModelProperty(value = "区域ID")
@Dict(dicCode = "id" , dictTable = "nu_admin_institution_area" , dicText = "inst_name")
private String areaId;
@Excel(name = "机构ID", width = 15)
@ApiModelProperty(value = "机构ID")
@Dict(dicCode = "id" , dictTable = "nu_admin_institution_area" , dicText = "inst_name")
private String institutionId;
/**分组层级*/
@Excel(name = "分组层级", width = 15)
@ApiModelProperty(value = "分组层级")

View File

@ -20,6 +20,8 @@ public interface RegionInfoMapper extends BaseMapper<RegionInfo> {
IPage<RegionInfo> findPage(Page<RegionInfo> page, @Param("params") RegionInfo regionInfo);
int add(Map<String, String> map);
int updateById(Map<String, String> map);
int updateByRegionId(Map<String, String> map);
int findChildrenCount(String regionId);
int deleteByRegionId(String regionId);
List<RegionInfo> queryTreeListByPid(String parentId,String projectId);
}

View File

@ -6,6 +6,7 @@
select a.id,
a.region_id as regionId,
a.region_name as regionName,
a.area_id as areaId,
a.region_level as regionLevel,
a.sort,
a.parent_id as parentId,
@ -28,6 +29,8 @@
select a.id,
a.region_id as regionId,
a.region_name as regionName,
(case a.region_level when '1' then b.institution_id else p.area_id end) as institutionId,
a.area_id as areaId,
a.region_level as regionLevel,
a.sort,
a.parent_id as parentId,
@ -56,6 +59,8 @@
select a.id,
a.region_id as regionId,
a.region_name as regionName,
(case a.region_level when '1' then b.institution_id else p.area_id end) as institutionId,
a.area_id as areaId,
a.region_level as regionLevel,
a.sort,
a.parent_id as parentId,
@ -82,62 +87,171 @@
<insert id="add">
insert into nu_iot_tplink_region(
region_id,
region_name,
area_id,
region_level,
sort,
parent_id,
project_id,
sys_type,
stream_way,
has_children,
<if test="hasChildren != null and hasChildren != ''">
has_children,
</if>
region_type,
update_time,
media_server_id,
backup_media_server_id,
bind_type,
iz_leaf
<if test="izLeaf != null and izLeaf != ''">
update_time,
</if>
<if test="izLeaf != null and izLeaf != ''">
media_server_id,
</if>
<if test="izLeaf != null and izLeaf != ''">
backup_media_server_id,
</if>
<if test="izLeaf != null and izLeaf != ''">
bind_type,
</if>
<if test="izLeaf != null">
iz_leaf,
</if>
region_id
)
values(
#{regionId},
#{regionName},
#{areaId},
#{regionLevel},
#{sort},
#{parentId},
#{projectId},
#{sysType},
#{streamWay},
#{hasChildren},
<if test="hasChildren != null and hasChildren != ''">
#{hasChildren},
</if>
#{regionType},
#{updateTime},
#{mediaServerId},
#{backupMediaServerId},
#{bindType},
#{izLeaf}
<if test="updateTime != null and updateTime != ''">
#{updateTime},
</if>
<if test="mediaServerId != null and mediaServerId != ''">
#{mediaServerId},
</if>
<if test="backupMediaServerId != null and backupMediaServerId != ''">
#{backupMediaServerId},
</if>
<if test="bindType != null and bindType != ''">
#{bindType},
</if>
<if test="izLeaf != null">
#{izLeaf},
</if>
#{regionId}
)
</insert>
<update id="updateById">
update nu_iot_tplink_region
set
region_id = #{regionId},
region_name = #{regionName},
region_level = #{regionLevel},
sort = #{sort},
parent_id = #{parentId},
project_id = #{projectId},
sys_type = #{sysType},
stream_way = #{streamWay},
has_children = #{hasChildren},
region_type = #{regionType},
update_time = #{updateTime},
media_server_id = #{mediaServerId},
backup_media_server_id = #{backupMediaServerId},
bind_type = #{bindType},
iz_leaf = #{izLeaf}
set region_name = #{regionName},
<if test="areaId != null and areaId != ''">
area_id = #{areaId},
</if>
<if test="regionLevel != null and regionLevel != ''">
region_level = #{regionLevel},
</if>
<if test="sort != null">
sort = #{sort},
</if>
<if test="parentId != null and parentId != ''">
parent_id = #{parentId},
</if>
<if test="projectId != null and projectId != ''">
project_id = #{projectId},
</if>
<if test="sysType != null and sysType != ''">
sys_type = #{sysType},
</if>
<if test="streamWay != null and streamWay != ''">
stream_way = #{streamWay},
</if>
<if test="hasChildren != null and hasChildren != ''">
has_children = #{hasChildren},
</if>
<if test="regionType != null and regionType != ''">
region_type = #{regionType},
</if>
<if test="updateTime != null and updateTime != ''">
update_time = #{updateTime},
</if>
<if test="mediaServerId != null and mediaServerId != ''">
media_server_id = #{mediaServerId},
</if>
<if test="backupMediaServerId != null and backupMediaServerId != ''">
backup_media_server_id = #{backupMediaServerId},
</if>
<if test="bindType != null and bindType != ''">
bind_type = #{bindType},
</if>
<if test="izLeaf != null">
iz_leaf = #{izLeaf},
</if>
region_id = #{regionId}
where id = #{id}
</update>
<update id="updateByRegionId">
update nu_iot_tplink_region
set
<if test="areaId != null and areaId != ''">
area_id = #{areaId},
</if>
<if test="regionLevel != null and regionLevel != ''">
region_level = #{regionLevel},
</if>
<if test="sort != null">
sort = #{sort},
</if>
<if test="parentId != null and parentId != ''">
parent_id = #{parentId},
</if>
<if test="projectId != null and projectId != ''">
project_id = #{projectId},
</if>
<if test="sysType != null and sysType != ''">
sys_type = #{sysType},
</if>
<if test="streamWay != null and streamWay != ''">
stream_way = #{streamWay},
</if>
<if test="hasChildren != null and hasChildren != ''">
has_children = #{hasChildren},
</if>
<if test="regionType != null and regionType != ''">
region_type = #{regionType},
</if>
<if test="updateTime != null and updateTime != ''">
update_time = #{updateTime},
</if>
<if test="mediaServerId != null and mediaServerId != ''">
media_server_id = #{mediaServerId},
</if>
<if test="backupMediaServerId != null and backupMediaServerId != ''">
backup_media_server_id = #{backupMediaServerId},
</if>
<if test="bindType != null and bindType != ''">
bind_type = #{bindType},
</if>
<if test="izLeaf != null">
iz_leaf = #{izLeaf},
</if>
region_name = #{regionName}
where region_id = #{regionId}
</update>
<select id="findChildrenCount" parameterType="com.nu.modules.tplink.region.entity.RegionInfo" resultType="java.lang.Integer">
select count(*) as cn
from nu_iot_tplink_region a
where a.parent_id = #{regionId}
</select>
<update id="deleteByRegionId">
delete from nu_iot_tplink_region where region_id = #{regionId}
</update>
@ -146,6 +260,8 @@
select a.id,
a.region_id as regionId,
a.region_name as regionName,
(case a.region_level when '1' then b.institution_id else p.area_id end) as institutionId,
a.area_id as areaId,
a.region_level as regionLevel,
a.sort,
a.parent_id as parentId,
@ -156,7 +272,7 @@
a.stream_way as streamWay,
a.has_children as hasChildren,
a.region_type as regionType,
a.update_time as updateTime,
DATE_FORMAT(FROM_UNIXTIME(a.update_time/1000),'%Y-%m-%d %H:%i:%s') as updateTime,
a.media_server_id as mediaServerId,
a.backup_media_server_id as backupMediaServerId,
a.bind_type as bindType,

View File

@ -38,6 +38,10 @@ public class RegionTreeModel implements Serializable{
private String regionName;
private String areaId;
private String institutionId;
private String regionLevel;
private String order;
@ -83,6 +87,8 @@ public class RegionTreeModel implements Serializable{
this.id = regionInfo.getRegionId();
this.regionId = regionInfo.getRegionId();
this.regionName = regionInfo.getRegionName();
this.areaId = regionInfo.getAreaId();
this.institutionId = regionInfo.getInstitutionId();
this.regionLevel = regionInfo.getRegionLevel();
this.order = regionInfo.getOrder();
this.sort = regionInfo.getSort();
@ -184,6 +190,22 @@ public class RegionTreeModel implements Serializable{
this.regionName = regionName;
}
public String getAreaId() {
return areaId;
}
public void setAreaId(String areaId) {
this.areaId = areaId;
}
public String getInstitutionId() {
return institutionId;
}
public void setInstitutionId(String institutionId) {
this.institutionId = institutionId;
}
public String getRegionLevel() {
return regionLevel;
}
@ -319,6 +341,8 @@ public class RegionTreeModel implements Serializable{
return Objects.equals(id, model.id) &&
Objects.equals(regionId, model.regionId) &&
Objects.equals(regionName, model.regionName) &&
Objects.equals(areaId, model.areaId) &&
Objects.equals(institutionId, model.institutionId) &&
Objects.equals(regionLevel, model.regionLevel) &&
Objects.equals(order, model.order) &&
Objects.equals(sort, model.sort) &&
@ -343,7 +367,7 @@ public class RegionTreeModel implements Serializable{
@Override
public int hashCode() {
return Objects.hash(id, regionId, regionName, regionLevel, order,
return Objects.hash(id, regionId, regionName, areaId, institutionId, regionLevel, order,
sort, parentId, parentName, projectId, projectName, sysType, streamWay, hasChildren,
regionType, updateTime, mediaServerId, backupMediaServerId, bindType,
children);

View File

@ -91,7 +91,6 @@ public class RegionInfoServiceImpl extends ServiceImpl<RegionInfoMapper, RegionI
map.put("id",String.valueOf(entity.getId()));
baseMapper.updateById(map);
}
String projectId = map.get("projectId");
if(projectId!=null&&!("").equals(projectId)){
Map<String, String> projectMap = new HashMap<>();
@ -217,6 +216,14 @@ public class RegionInfoServiceImpl extends ServiceImpl<RegionInfoMapper, RegionI
JSONObject jsonObject = new JSONObject(jsonResponse);
String errorCode = jsonObject.getStr("error_code");
if(errorCode.equals("0")){
JSONObject result = (JSONObject)jsonObject.get("result");
Map<String, String> map = new HashMap<>();
for (String key : result.keySet()) {
map.put(key, result.getStr(key));
}
map.put("sort", map.get("order"));
map.put("areaId", regionInfo.getAreaId());
baseMapper.add(map);
sync(regionInfo);
return Result.OK("分组添加成功!");
}else{
@ -239,7 +246,12 @@ public class RegionInfoServiceImpl extends ServiceImpl<RegionInfoMapper, RegionI
JSONObject jsonObject = new JSONObject(jsonResponse);
String errorCode = jsonObject.getStr("error_code");
if(errorCode.equals("0")){
sync(regionInfo);
Map<String, String> map = new HashMap<>();
map.put("regionId",regionInfo.getRegionId());
map.put("regionName",regionInfo.getRegionName());
map.put("areaId",regionInfo.getAreaId());
baseMapper.updateByRegionId(map);
this.sync(regionInfo);
return Result.OK("分组编辑成功!");
}else{
return Result.error(jsonObject.getStr("msg"));
@ -252,6 +264,10 @@ public class RegionInfoServiceImpl extends ServiceImpl<RegionInfoMapper, RegionI
*/
@Override
public Result<String> deleteRegion(RegionInfo regionInfo){
int childrenCount = baseMapper.findChildrenCount(regionInfo.getRegionId());
if(childrenCount>0){
return Result.error("此分组存在子分组,请将子分组全部删除后再来删除此分组!");
}
StringBuffer sb = new StringBuffer();
sb.append("{");
sb.append("\"regionId\"").append(":").append("\"").append(regionInfo.getRegionId()).append("\"");
@ -259,7 +275,7 @@ public class RegionInfoServiceImpl extends ServiceImpl<RegionInfoMapper, RegionI
String jsonResponse = tumsApi.deleteRegion(sb.toString());
JSONObject jsonObject = new JSONObject(jsonResponse);
String errorCode = jsonObject.getStr("error_code");
if(errorCode.equals("0")||errorCode.equals("-82401")){
if(errorCode.equals("0")||errorCode.equals("-82401")||errorCode.equals("-80205")){
baseMapper.deleteByRegionId(regionInfo.getRegionId());
return Result.OK("分组删除成功!");
}else{