Przeglądaj źródła

学院增删改查提交

pans 8 miesięcy temu
rodzic
commit
b8c527e558

+ 48 - 34
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/controller/CollegeController.java

@@ -12,6 +12,7 @@
  */
 package vip.xiaonuo.disk.controller;
 
+import cn.hutool.core.lang.tree.Tree;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import com.github.xiaoymin.knife4j.annotations.ApiSupport;
@@ -66,29 +67,42 @@ public class CollegeController {
     }
 
     /**
-     * 添加college
+     * 获取组织树
      *
-     * @author pans
-     * @date  2025/06/26 09:09
+     * @author xuyuxiang
+     * @date 2022/4/24 20:00
      */
     @ApiOperationSupport(order = 2)
-    @ApiOperation("添加college")
-    @CommonLog("添加college")
+    @ApiOperation("获取组织树")
+    @GetMapping("/disk/college/tree")
+    public CommonResult<List<Tree<String>>> tree() {
+        return CommonResult.data(collegeService.tree());
+    }
+
+    /**
+     * 添加组织
+     *
+     * @author xuyuxiang
+     * @date 2022/4/24 20:47
+     */
+    @ApiOperationSupport(order = 3)
+    @ApiOperation("添加组织")
+    @CommonLog("添加组织")
     @PostMapping("/disk/college/add")
-    public CommonResult<String> add(@RequestBody @Valid CollegeAddParam collegeAddParam) {
-        collegeService.add(collegeAddParam);
+    public CommonResult<String> add(@RequestBody @Valid CollegeAddParam sysOrgAddParam) {
+        collegeService.add(sysOrgAddParam);
         return CommonResult.ok();
     }
 
     /**
-     * 编辑college
+     * 编辑组织
      *
-     * @author pans
-     * @date  2025/06/26 09:09
+     * @author xuyuxiang
+     * @date 2022/4/24 20:47
      */
-    @ApiOperationSupport(order = 3)
-    @ApiOperation("编辑college")
-    @CommonLog("编辑college")
+    @ApiOperationSupport(order = 4)
+    @ApiOperation("编辑组织")
+    @CommonLog("编辑组织")
     @PostMapping("/disk/college/edit")
     public CommonResult<String> edit(@RequestBody @Valid CollegeEditParam collegeEditParam) {
         collegeService.edit(collegeEditParam);
@@ -96,49 +110,49 @@ public class CollegeController {
     }
 
     /**
-     * 删除college
+     * 删除组织
      *
-     * @author pans
-     * @date  2025/06/26 09:09
+     * @author xuyuxiang
+     * @date 2022/4/24 20:00
      */
-    @ApiOperationSupport(order = 4)
-    @ApiOperation("删除college")
-    @CommonLog("删除college")
+    @ApiOperationSupport(order = 5)
+    @ApiOperation("删除组织")
+    @CommonLog("删除组织")
     @PostMapping("/disk/college/delete")
     public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
-                                                   CommonValidList<CollegeIdParam> collegeIdParamList) {
+                                       CommonValidList<CollegeIdParam> collegeIdParamList) {
         collegeService.delete(collegeIdParamList);
         return CommonResult.ok();
     }
 
     /**
-     * 获取college详情
+     * 获取组织详情
      *
-     * @author pans
-     * @date  2025/06/26 09:09
+     * @author xuyuxiang
+     * @date 2022/4/24 20:00
      */
-    @ApiOperationSupport(order = 5)
-    @ApiOperation("获取college详情")
+    @ApiOperationSupport(order = 6)
+    @ApiOperation("获取组织详情")
     @GetMapping("/disk/college/detail")
     public CommonResult<College> detail(@Valid CollegeIdParam collegeIdParam) {
         return CommonResult.data(collegeService.detail(collegeIdParam));
     }
 
+    /* ====组织部分所需要用到的选择器==== */
 
     /**
-     * 获取college分页
+     * 获取组织树选择器
      *
-     * @author pans
-     * @date  2025/06/26 09:09
+     * @author xuyuxiang
+     * @date 2022/4/24 20:00
      */
-    @ApiOperationSupport(order = 1)
-    @ApiOperation("获取college分页")
-    @GetMapping("/disk/college/select")
-    public CommonResult<List<College>> select(CollegePageParam collegePageParam) {
-        return CommonResult.data(collegeService.select(collegePageParam));
+    @ApiOperationSupport(order = 7)
+    @ApiOperation("获取组织树选择器")
+    @GetMapping("/disk/college/orgTreeSelector")
+    public CommonResult<List<Tree<String>>> orgTreeSelector() {
+        return CommonResult.data(collegeService.orgTreeSelector());
     }
 
 
 
-
 }

+ 45 - 19
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/domain/College.java

@@ -12,11 +12,16 @@
  */
 package vip.xiaonuo.disk.domain;
 
-import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fhs.core.trans.anno.Trans;
+import com.fhs.core.trans.constant.TransType;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Getter;
 import lombok.Setter;
 import vip.xiaonuo.common.pojo.CommonEntity;
+import vip.xiaonuo.sys.modular.user.entity.SysUser;
 
 /**
  * college实体
@@ -28,27 +33,48 @@ import vip.xiaonuo.common.pojo.CommonEntity;
 @Setter
 @TableName("college")
 public class College extends CommonEntity {
+    /** id */
+    @ApiModelProperty(value = "id", position = 1)
+    private String id;
 
-    /** ID */
-    @ApiModelProperty(value = "ID", position = 1)
-    @TableId(type = IdType.AUTO)
-    private Integer id;
+    /** 租户id */
+    @ApiModelProperty(value = "租户id", position = 2)
+    private String tenantId;
 
-    /** 院系名称 */
-    @ApiModelProperty(value = "院系名称", position = 2)
-    private String collegeName;
+    /** 父id */
+    @ApiModelProperty(value = "父id", position = 3)
+    private String parentId;
 
-    /** 院系编码 */
-    @ApiModelProperty(value = "院系编码", position = 3)
-    private String collegeCode;
+    /** 主管id */
+    @ApiModelProperty(value = "主管id", position = 4)
+    @TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
+    @Trans(type = TransType.SIMPLE, target = SysUser.class, fields = "name", alias = "director", ref = "directorName")
+    private String directorId;
 
-    /** 组织id */
-    @ApiModelProperty(value = "组织id", position = 4)
-    private String orgId;
+    /** 名称 */
+    @ApiModelProperty(value = "名称", position = 5)
+    private String name;
+
+    /** 编码 */
+    @ApiModelProperty(value = "编码", position = 6)
+    private String code;
+
+    /** 分类 */
+    @ApiModelProperty(value = "分类", position = 7)
+    private String category;
+
+    /** 排序码 */
+    @ApiModelProperty(value = "排序码", position = 8)
+    private Integer sortCode;
+
+    /** 扩展信息 */
+    @ApiModelProperty(value = "扩展信息", position = 9)
+    @TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
+    private String extJson;
+
+    /** 是否是资源库特殊账号,0否1是 */
+    @ApiModelProperty(value = "是否是资源库特殊账号,0否1是")
+    @TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
+    private String isResourceaccount;
 
-    /** 删除标志 0未删除  1已删除 */
-    @ApiModelProperty(value = "删除标志 0未删除  1已删除", position = 5)
-    @TableLogic
-    @TableField(fill = FieldFill.INSERT)
-    private String deleteFlag;
 }

+ 13 - 2
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/enums/CollegeEnum.java

@@ -13,6 +13,7 @@
 package vip.xiaonuo.disk.enums;
 
 import lombok.Getter;
+import vip.xiaonuo.common.exception.CommonException;
 
 /**
  * college枚举
@@ -23,12 +24,22 @@ import lombok.Getter;
 @Getter
 public enum CollegeEnum {
 
-    /** 测试 */
-    TEST("TEST");
+    /** 公司 */
+    COMPANY("COMPANY"),
+
+    /** 部门 */
+    DEPT("DEPT");
 
     private final String value;
 
     CollegeEnum(String value) {
         this.value = value;
     }
+
+    public static void validate(String value) {
+        boolean flag = COMPANY.getValue().equals(value) || DEPT.getValue().equals(value);
+        if(!flag) {
+            throw new CommonException("不支持的组织分类:{}", value);
+        }
+    }
 }

+ 19 - 9
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/param/CollegeAddParam.java

@@ -16,6 +16,9 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Getter;
 import lombok.Setter;
 
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
 /**
  * college添加参数
  *
@@ -26,16 +29,23 @@ import lombok.Setter;
 @Setter
 public class CollegeAddParam {
 
-    /** 院系名称 */
-    @ApiModelProperty(value = "院系名称", position = 2)
-    private String collegeName;
+    /** 父id */
+    @ApiModelProperty(value = "父id", required = true, position = 1)
+    @NotBlank(message = "parentId不能为空")
+    private String parentId;
+
+    /** 名称 */
+    @ApiModelProperty(value = "名称", required = true, position = 2)
+    @NotBlank(message = "name不能为空")
+    private String name;
 
-    /** 院系编码 */
-    @ApiModelProperty(value = "院系编码", position = 3)
-    private String collegeCode;
+    /** 排序码 */
+    @ApiModelProperty(value = "排序码", required = true, position = 4)
+    @NotNull(message = "sortCode不能为空")
+    private Integer sortCode;
 
-    /** 组织id */
-    @ApiModelProperty(value = "组织id", position = 4)
-    private String orgId;
 
+    /** 扩展JSON */
+    @ApiModelProperty(value = "扩展JSON", position = 6)
+    private String extJson;
 }

+ 24 - 13
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/param/CollegeEditParam.java

@@ -16,6 +16,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Getter;
 import lombok.Setter;
 
+import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.NotNull;
 
 /**
@@ -28,21 +29,31 @@ import javax.validation.constraints.NotNull;
 @Setter
 public class CollegeEditParam {
 
-    /** ID */
-    @ApiModelProperty(value = "ID", required = true, position = 1)
-    @NotNull(message = "id不能为空")
-    private Integer id;
+    /** id */
+    @ApiModelProperty(value = "id", required = true, position = 1)
+    @NotBlank(message = "id不能为空")
+    private String id;
 
-    /** 院系名称 */
-    @ApiModelProperty(value = "院系名称", position = 2)
-    private String collegeName;
+    /** 父id */
+    @ApiModelProperty(value = "父id", required = true, position = 2)
+    @NotBlank(message = "parentId不能为空")
+    private String parentId;
 
-    /** 院系编码 */
-    @ApiModelProperty(value = "院系编码", position = 3)
-    private String collegeCode;
+    /** 名称 */
+    @ApiModelProperty(value = "名称", required = true, position = 3)
+    @NotBlank(message = "name不能为空")
+    private String name;
 
-    /** 组织id */
-    @ApiModelProperty(value = "组织id", position = 4)
-    private String orgId;
+
+
+    /** 排序码 */
+    @ApiModelProperty(value = "排序码", required = true, position = 5)
+    @NotNull(message = "sortCode不能为空")
+    private Integer sortCode;
+
+
+    /** 扩展JSON */
+    @ApiModelProperty(value = "扩展JSON", position = 7)
+    private String extJson;
 
 }

+ 3 - 3
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/param/CollegeIdParam.java

@@ -29,8 +29,8 @@ import javax.validation.constraints.NotNull;
 @Setter
 public class CollegeIdParam {
 
-    /** ID */
-    @ApiModelProperty(value = "ID", required = true)
+    /** id */
+    @ApiModelProperty(value = "id", required = true)
     @NotNull(message = "id不能为空")
-    private Integer id;
+    private String id;
 }

+ 26 - 0
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/param/CollegeOrgSelectorOrgListParam.java

@@ -0,0 +1,26 @@
+package vip.xiaonuo.disk.param;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class CollegeOrgSelectorOrgListParam {
+    /** 当前页 */
+    @ApiModelProperty(value = "当前页码")
+    private Integer current;
+
+    /** 每页条数 */
+    @ApiModelProperty(value = "每页条数")
+    private Integer size;
+
+    /** 父id */
+    @ApiModelProperty(value = "父id")
+    private String parentId;
+
+    /** 名称关键词 */
+    @ApiModelProperty(value = "名称关键词")
+    private String searchKey;
+
+}

+ 6 - 3
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/param/CollegePageParam.java

@@ -25,7 +25,6 @@ import lombok.Setter;
 @Getter
 @Setter
 public class CollegePageParam {
-
     /** 当前页 */
     @ApiModelProperty(value = "当前页码")
     private Integer current;
@@ -42,8 +41,12 @@ public class CollegePageParam {
     @ApiModelProperty(value = "排序方式,升序:ASCEND;降序:DESCEND")
     private String sortOrder;
 
-    /** 关键词 */
-    @ApiModelProperty(value = "关键词")
+    /** 父id */
+    @ApiModelProperty(value = "父id")
+    private String parentId;
+
+    /** 名称关键词 */
+    @ApiModelProperty(value = "名称关键词")
     private String searchKey;
 
 }

+ 108 - 21
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/service/CollegeService.java

@@ -12,13 +12,11 @@
  */
 package vip.xiaonuo.disk.service;
 
+import cn.hutool.core.lang.tree.Tree;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import vip.xiaonuo.disk.domain.College;
-import vip.xiaonuo.disk.param.CollegeAddParam;
-import vip.xiaonuo.disk.param.CollegeEditParam;
-import vip.xiaonuo.disk.param.CollegeIdParam;
-import vip.xiaonuo.disk.param.CollegePageParam;
+import vip.xiaonuo.disk.param.*;
 
 import java.util.List;
 
@@ -39,44 +37,133 @@ public interface CollegeService extends IService<College> {
     Page<College> page(CollegePageParam collegePageParam);
 
     /**
-     * 添加college
+     * 获取组织树
      *
-     * @author pans
-     * @date  2025/06/26 09:09
+     * @author xuyuxiang
+     * @date 2022/4/24 20:08
+     */
+    List<Tree<String>> tree();
+
+    /**
+     * 添加组织
+     *
+     * @author xuyuxiang
+     * @date 2022/4/24 20:48
      */
     void add(CollegeAddParam collegeAddParam);
 
     /**
-     * 编辑college
+     * 编辑组织
      *
-     * @author pans
-     * @date  2025/06/26 09:09
+     * @author xuyuxiang
+     * @date 2022/4/24 21:13
      */
     void edit(CollegeEditParam collegeEditParam);
 
     /**
-     * 删除college
+     * 删除组织
      *
-     * @author pans
-     * @date  2025/06/26 09:09
+     * @author xuyuxiang
+     * @date 2022/4/24 21:18
      */
     void delete(List<CollegeIdParam> collegeIdParamList);
 
     /**
-     * 获取college详情
+     * 获取组织详情
      *
-     * @author pans
-     * @date  2025/06/26 09:09
+     * @author xuyuxiang
+     * @date 2022/4/24 21:18
      */
     College detail(CollegeIdParam collegeIdParam);
 
     /**
-     * 获取college详情
+     * 获取组织详情
      *
-     * @author pans
-     * @date  2025/06/26 09:09
+     * @author xuyuxiang
+     * @date 2022/7/25 19:42
+     **/
+    College queryEntity(String id);
+
+    /**
+     * 获取所有组织
+     *
+     * @author xuyuxiang
+     * @date 2022/7/25 19:42
+     **/
+    List<College> getAllOrgList();
+
+    /**
+     * 根据组织全名称获取组织id,有则返回,无则创建
+     *
+     * @author xuyuxiang
+     * @date 2023/3/7 15:44
+     **/
+    String getOrgIdByOrgFullNameWithCreate(String orgFullName);
+
+    /**
+     * 根据id获取父子数据列表
+     *
+     * @author xuyuxiang
+     * @date 2022/8/15 14:55
+     **/
+    List<College> getParentAndChildListById(List<College> originDataList, String id, boolean includeSelf);
+
+    /**
+     * 根据id获取所有的子数据列表
+     *
+     * @author xuyuxiang
+     * @date 2022/8/15 14:55
+     **/
+    List<College> getChildListById(List<College> originDataList, String id, boolean includeSelf);
+
+    /**
+     * 根据id获取所有的父数据列表
+     *
+     * @author xuyuxiang
+     * @date 2022/8/15 14:55
+     **/
+    List<College> getParentListById(List<College> originDataList, String id, boolean includeSelf);
+
+    /**
+     * 根据id获取数据
+     *
+     * @author xuyuxiang
+     * @date 2022/8/15 14:55
+     **/
+    College getById(List<College> originDataList, String id);
+
+    /**
+     * 根据id获取父数据
+     *
+     * @author xuyuxiang
+     * @date 2022/8/15 14:55
+     **/
+    College getParentById(List<College> originDataList, String id);
+
+    /**
+     * 根据id获取子数据
+     *
+     * @author xuyuxiang
+     * @date 2022/8/15 14:55
+     **/
+    College getChildById(List<College> originDataList, String id);
+
+
+    /**
+     * 获取组织树选择器
+     *
+     * @author xuyuxiang
+     * @date 2022/4/24 20:08
+     */
+    List<Tree<String>> orgTreeSelector();
+
+    /**
+     * 获取组织列表选择器
+     *
+     * @author xuyuxiang
+     * @date 2022/7/22 13:34
      **/
-    College queryEntity(Integer id);
+    Page<College> orgListSelector(CollegeOrgSelectorOrgListParam collegeSelectorOrgListParam);
 
-    List<College> select(CollegePageParam collegePageParam);
+ 
 }

+ 222 - 19
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/service/impl/CollegeServiceImpl.java

@@ -14,8 +14,15 @@ package vip.xiaonuo.disk.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollStreamUtil;
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.core.lang.tree.TreeNode;
+import cn.hutool.core.lang.tree.TreeUtil;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -23,17 +30,18 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import vip.xiaonuo.common.enums.CommonSortOrderEnum;
+import vip.xiaonuo.common.enums.SysDataTypeEnum;
 import vip.xiaonuo.common.exception.CommonException;
+import vip.xiaonuo.common.listener.CommonDataChangeEventCenter;
 import vip.xiaonuo.common.page.CommonPageRequest;
 import vip.xiaonuo.disk.domain.College;
 import vip.xiaonuo.disk.mapper.CollegeMapper;
-import vip.xiaonuo.disk.param.CollegeAddParam;
-import vip.xiaonuo.disk.param.CollegeEditParam;
-import vip.xiaonuo.disk.param.CollegeIdParam;
-import vip.xiaonuo.disk.param.CollegePageParam;
+import vip.xiaonuo.disk.param.*;
 import vip.xiaonuo.disk.service.CollegeService;
 
+import java.util.Iterator;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * collegeService接口实现类
@@ -48,25 +56,51 @@ public class CollegeServiceImpl extends ServiceImpl<CollegeMapper, College> impl
     @Override
     public Page<College> page(CollegePageParam collegePageParam) {
         QueryWrapper<College> queryWrapper = new QueryWrapper<>();
-
+        // 查询部分字段
+        queryWrapper.lambda().select(College::getId, College::getParentId, College::getName,
+                College::getCategory, College::getSortCode, College::getIsResourceaccount);
+        if(ObjectUtil.isNotEmpty(collegePageParam.getParentId())) {
+            queryWrapper.lambda().eq(College::getParentId, collegePageParam.getParentId());
+        }
         if(ObjectUtil.isNotEmpty(collegePageParam.getSearchKey())) {
-            queryWrapper.lambda().like(College::getCollegeName, collegePageParam.getSearchKey());
+            queryWrapper.lambda().like(College::getName, collegePageParam.getSearchKey());
         }
         if(ObjectUtil.isAllNotEmpty(collegePageParam.getSortField(), collegePageParam.getSortOrder())) {
             CommonSortOrderEnum.validate(collegePageParam.getSortOrder());
             queryWrapper.orderBy(true, collegePageParam.getSortOrder().equals(CommonSortOrderEnum.ASC.getValue()),
                     StrUtil.toUnderlineCase(collegePageParam.getSortField()));
         } else {
-            queryWrapper.lambda().orderByAsc(College::getId);
+            queryWrapper.lambda().orderByAsc(College::getSortCode);
         }
         return this.page(CommonPageRequest.defaultPage(), queryWrapper);
     }
 
+    @Override
+    public List<Tree<String>> tree() {
+        List<College> collegeList = this.getAllOrgList();
+        List<TreeNode<String>> treeNodeList = collegeList.stream().map(college ->
+                        new TreeNode<>(college.getId(), college.getParentId(),
+                                college.getName(), college.getSortCode()).setExtra(JSONUtil.parseObj(college)))
+                .collect(Collectors.toList());
+        return TreeUtil.build(treeNodeList, "0");
+    }
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void add(CollegeAddParam collegeAddParam) {
+
         College college = BeanUtil.toBean(collegeAddParam, College.class);
+        // 重复名称
+        boolean repeatName = this.count(new LambdaQueryWrapper<College>().eq(College::getParentId, college.getParentId())
+                .eq(College::getName, college.getName())) > 0;
+        if(repeatName) {
+            throw new CommonException("存在重复的同级组织,名称为:{}", college.getName());
+        }
+        college.setCode(RandomUtil.randomString(10));
         this.save(college);
+
+        // 发布增加事件
+     //   CommonDataChangeEventCenter.doAddWithData(SysDataTypeEnum.ORG.getValue(), JSONUtil.createArray().put(college));
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -74,14 +108,40 @@ public class CollegeServiceImpl extends ServiceImpl<CollegeMapper, College> impl
     public void edit(CollegeEditParam collegeEditParam) {
         College college = this.queryEntity(collegeEditParam.getId());
         BeanUtil.copyProperties(collegeEditParam, college);
+        boolean repeatName = this.count(new LambdaQueryWrapper<College>().eq(College::getParentId, college.getParentId())
+                .eq(College::getName, college.getName()).ne(College::getId, college.getId())) > 0;
+        if(repeatName) {
+            throw new CommonException("存在重复的同级组织,名称为:{}", college.getName());
+        }
+        List<College> originDataList = this.getAllOrgList();
+        boolean errorLevel = this.getChildListById(originDataList, college.getId(), true).stream()
+                .map(College::getId).collect(Collectors.toList()).contains(college.getParentId());
+        if(errorLevel) {
+            throw new CommonException("不可选择上级组织:{}", this.getById(originDataList, college.getParentId()).getName());
+        }
         this.updateById(college);
+
+        // 发布更新事件
+        CommonDataChangeEventCenter.doUpdateWithData(SysDataTypeEnum.ORG.getValue(), JSONUtil.createArray().put(college));
     }
 
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void delete(List<CollegeIdParam> collegeIdParamList) {
-        // 执行删除
-        this.removeByIds(CollStreamUtil.toList(collegeIdParamList, CollegeIdParam::getId));
+        List<String> orgIdList = CollStreamUtil.toList(collegeIdParamList, CollegeIdParam::getId);
+        if(ObjectUtil.isNotEmpty(orgIdList)) {
+            List<College> allOrgList = this.getAllOrgList();
+            // 获取所有子组织
+            List<String> toDeleteOrgIdList = CollectionUtil.newArrayList();
+            orgIdList.forEach(orgId -> toDeleteOrgIdList.addAll(this.getChildListById(allOrgList, orgId, true).stream()
+                    .map(College::getId).collect(Collectors.toList())));
+
+            // 执行删除
+            this.removeByIds(toDeleteOrgIdList);
+
+            // 发布删除事件
+            //CommonDataChangeEventCenter.doDeleteWithDataId(SysDataTypeEnum.ORG.getValue(), toDeleteOrgIdList);
+        }
     }
 
     @Override
@@ -90,25 +150,168 @@ public class CollegeServiceImpl extends ServiceImpl<CollegeMapper, College> impl
     }
 
     @Override
-    public College queryEntity(Integer id) {
+    public College queryEntity(String id) {
         College college = this.getById(id);
         if(ObjectUtil.isEmpty(college)) {
-            throw new CommonException("college不存在,id值为:{}", id);
+            throw new CommonException("组织不存在,id值为:{}", id);
         }
         return college;
     }
 
     @Override
-    public List<College> select(CollegePageParam collegePageParam) {
-        QueryWrapper<College> queryWrapper = new QueryWrapper<>();
-        if(ObjectUtil.isAllNotEmpty(collegePageParam.getSortField(), collegePageParam.getSortOrder())) {
-            CommonSortOrderEnum.validate(collegePageParam.getSortOrder());
-            queryWrapper.orderBy(true, collegePageParam.getSortOrder().equals(CommonSortOrderEnum.ASC.getValue()),
-                    StrUtil.toUnderlineCase(collegePageParam.getSortField()));
+    public List<College> getAllOrgList() {
+        return this.list(new LambdaQueryWrapper<College>().orderByAsc(College::getSortCode));
+    }
+
+    @Override
+    public String getOrgIdByOrgFullNameWithCreate(String orgFullName) {
+        List<College> allOrgList = this.getAllOrgList();
+        List<Tree<String>> treeList = TreeUtil.build(allOrgList.stream().map(college ->
+                        new TreeNode<>(college.getId(), college.getParentId(), college.getName(), college.getSortCode()))
+                .collect(Collectors.toList()), "0");
+        return findOrgIdByOrgName("0", StrUtil.split(orgFullName, StrUtil.DASHED).iterator(), allOrgList, treeList);
+    }
+
+    public String findOrgIdByOrgName(String parentId, Iterator<String> iterator, List<College> allOrgList, List<Tree<String>> treeList) {
+        String orgName = iterator.next();
+        if(ObjectUtil.isNotEmpty(treeList)) {
+            List<Tree<String>> findList = treeList.stream().filter(tree -> tree.getName().equals(orgName)).collect(Collectors.toList());
+            if(ObjectUtil.isNotEmpty(findList)) {
+                if(iterator.hasNext()) {
+                    return findOrgIdByOrgName(findList.get(0).getId(), iterator, allOrgList, findList.get(0).getChildren());
+                } else {
+                    return findList.get(0).getId();
+                }
+            }
+        }
+        String orgId = this.doCreateOrg(parentId, orgName, allOrgList);
+        if(iterator.hasNext()) {
+            return findOrgIdByOrgName(orgId, iterator, allOrgList, CollectionUtil.newArrayList());
         } else {
-            queryWrapper.lambda().orderByAsc(College::getId);
+            return orgId;
         }
-        return collegeMapper.selectList(queryWrapper);
     }
 
+    /**
+     * 执行创建组织
+     *
+     * @author xuyuxiang
+     * @date 2023/3/8 9:38
+     **/
+    public String doCreateOrg(String parentId, String orgName, List<College> allOrgList) {
+        //创建该组织
+        College college = new College();
+        college.setName(orgName);
+        college.setCode(RandomUtil.randomString(10));
+        college.setParentId(parentId);
+        college.setSortCode(99);
+        this.save(college);
+        // 发布增加事件
+      //  CommonDataChangeEventCenter.doAddWithData(SysDataTypeEnum.ORG.getValue(), JSONUtil.createArray().put(college));
+        return college.getId();
+    }
+
+    /* ====组织部分所需要用到的选择器==== */
+
+    @Override
+    public List<Tree<String>> orgTreeSelector() {
+        List<College> collegeList = this.getAllOrgList();
+        List<TreeNode<String>> treeNodeList = collegeList.stream().map(college ->
+                        new TreeNode<>(college.getId(), college.getParentId(), college.getName(), college.getSortCode()))
+                .collect(Collectors.toList());
+        return TreeUtil.build(treeNodeList, "0");
+    }
+
+    @Override
+    public Page<College> orgListSelector(CollegeOrgSelectorOrgListParam collegeSelectorOrgListParam) {
+        LambdaQueryWrapper<College> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+        // 查询部分字段
+        lambdaQueryWrapper.select(College::getId, College::getParentId, College::getName,
+                College::getCategory, College::getSortCode);
+        if(ObjectUtil.isNotEmpty(collegeSelectorOrgListParam.getParentId())) {
+            lambdaQueryWrapper.eq(College::getParentId, collegeSelectorOrgListParam.getParentId());
+        }
+        if(ObjectUtil.isNotEmpty(collegeSelectorOrgListParam.getSearchKey())) {
+            lambdaQueryWrapper.like(College::getName, collegeSelectorOrgListParam.getSearchKey());
+        }
+        lambdaQueryWrapper.orderByAsc(College::getSortCode);
+        return this.page(CommonPageRequest.defaultPage(), lambdaQueryWrapper);
+    }
+
+
+
+    /* ====以下为各种递归方法==== */
+
+    @Override
+    public List<College> getParentAndChildListById(List<College> originDataList, String id, boolean includeSelf) {
+        List<College> parentListById = this.getParentListById(originDataList, id, false);
+        List<College> childListById = this.getChildListById(originDataList, id, true);
+        parentListById.addAll(childListById);
+        return parentListById;
+    }
+
+    @Override
+    public List<College> getChildListById(List<College> originDataList, String id, boolean includeSelf) {
+        List<College> resultList = CollectionUtil.newArrayList();
+        execRecursionFindChild(originDataList, id, resultList);
+        if(includeSelf) {
+            College self = this.getById(originDataList, id);
+            if(ObjectUtil.isNotEmpty(self)) {
+                resultList.add(self);
+            }
+        }
+        return resultList;
+    }
+
+    @Override
+    public List<College> getParentListById(List<College> originDataList, String id, boolean includeSelf) {
+        List<College> resultList = CollectionUtil.newArrayList();
+        execRecursionFindParent(originDataList, id, resultList);
+        if(includeSelf) {
+            College self = this.getById(originDataList, id);
+            if(ObjectUtil.isNotEmpty(self)) {
+                resultList.add(self);
+            }
+        }
+        return resultList;
+    }
+
+    public void execRecursionFindChild(List<College> originDataList, String id, List<College> resultList) {
+        originDataList.forEach(item -> {
+            if(item.getParentId().equals(id)) {
+                resultList.add(item);
+                execRecursionFindChild(originDataList, item.getId(), resultList);
+            }
+        });
+    }
+
+    public void execRecursionFindParent(List<College> originDataList, String id, List<College> resultList) {
+        originDataList.forEach(item -> {
+            if(item.getId().equals(id)) {
+                College parent = this.getById(originDataList, item.getParentId());
+                if(ObjectUtil.isNotEmpty(parent)) {
+                    resultList.add(parent);
+                }
+                execRecursionFindParent(originDataList, item.getParentId(), resultList);
+            }
+        });
+    }
+
+    @Override
+    public College getById(List<College> originDataList, String id) {
+        int index = CollStreamUtil.toList(originDataList, College::getId).indexOf(id);
+        return index == -1?null:originDataList.get(index);
+    }
+
+    @Override
+    public College getParentById(List<College> originDataList, String id) {
+        College self = this.getById(originDataList, id);
+        return ObjectUtil.isNotEmpty(self)?self:this.getById(originDataList, self.getParentId());
+    }
+
+    @Override
+    public College getChildById(List<College> originDataList, String id) {
+        int index = CollStreamUtil.toList(originDataList, College::getParentId).indexOf(id);
+        return index == -1?null:originDataList.get(index);
+    }
 }