业务-----部门Service常用逻辑
1.org实体类
public class Org implements Serializable {
private static final long serialVersionUID = 1L;
private String title;
private Long parent;
private List<User> userList;
private List<Org> nodes;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Long getParent() {
return parent;
}
public void setParent(Long parent) {
this.parent = parent;
}
public List<Org> getNodes() {
if(nodes == null){
nodes = new ArrayList<Org>();
}
return nodes;
}
public void setNodes(List<Org> nodes) {
this.nodes = nodes;
}
public List<User> getUserList() {
if(userList == null){
userList = new ArrayList<User>();
}
return userList;
}
public void setUserList(List<User> userList) {
this.userList = userList;
}
@Override
public String toString() {
return "Org{" +
"createTime=" + createTime +
", title='" + title + '\'' +
", parent=" + parent +
", userList=" + userList +
", nodes=" + nodes +
'}';
}
}
2.查询该部门下的子部门
private List<Org> hasChilds(Long id){
List<Org> orgs = super.selectList(
new EntityWrapper<Org>().eq(Config.ABLE_CONFIG.ABLE_COLUMN,Config.ABLE_CONFIG.ABLE)
.eq("parent",id)
);
List<Org> orgList1 = new ArrayList<>();
for(Org org : orgs){
List<User> userList = userService.getByOrgId(org.getId());
org.setUserList(userList); //同时也查出了该部门下的所有人员
orgList1.add(org);
}
return orgList1;
}
3.查询该部门下的所有部门的id。---应用递归查询出所有的id,放到set集合中
public Set<Long> getAllChildIds(Long id,Set<Long> set) {
if(set == null){
set = new HashSet<>();
}
List<Org> orgList = hasChilds(id);
set.add(id);
for (int i = 0; i < orgList.size(); i++) {
set.add(orgList.get(i).getId());
getAllChildIds(orgList.get(i).getId(),set);
}
return set;
}
4.查询该部门下的所有部门部门---应用递归查询出该部门下的所有部门,放到Org实体类的List<Org> node属性中。(已经在实体类中定义过了)
public Org getAllChildOrgs(Long id) {
Org org = null;
if(id == 0){
org = new Org();
}else {
org = get(id);
}
List<Org> orgList = hasChilds(id);
for(Org org1 : orgList){
Org org2 = getAllChildOrgs(org1.getId());
org.getNodes().add(org2);
}
return org;
}
5.递归删除该部门下所有部门
//递归删除该部门下所有部门
public boolean del(Long id) {
if (id != null){
List<Org> hasResponses = hasChilds(id);
if (!CollectionUtils.isEmpty(hasResponses)){
for (Org orgRsp:hasResponses){
del(orgRsp.getId());
}
}
return delCurrent(id);
}else {
throw new ApplicationException(StatusCode.BAD_REQUEST.getCode(), StatusCode.BAD_REQUEST.getMessage());
}
}
//根据id删除对象
private boolean delCurrent(Long id){
Org org = new Org();
org.setId(id);
org.setIsDeleted(Config.ABLE_CONFIG.UNABLE);
org.setUpdateTime(new Date());
return super.updateById(org);
}
业务-----部门Service常用逻辑的更多相关文章
- 业务-----添加Service常用逻辑
1.参数不能为空 /** * 添加人员时判断是否字段全部传值 * @param request * @return */ private Boolean checkClientByCols(Clien ...
- 业务-----修改Service常用逻辑
注意:修改时唯一属性不能重复 //num==null 时,没有修改Num,不用考虑重复问题.//num!=null 时,修改了num.考虑重复问题 if(!StringUtils.isEmpty(re ...
- Flask基础(06)-->视图常用逻辑
Flask基础(06)-->视图常用逻辑 返回json 重定向:url_for 自定义状态码 返回json:在使用 Flask 写一个接口时候需要给客户端返回 JSON 数据,在 Flask 中 ...
- 业务型代码常用的SQL汇总(随时更新)
做了一年的业务代码开发,记录并分享一下自己平时在项目中遇到的比较好用的sql 1.查询表中是否某一字段下的数据有重复数据(以ID为例) SELECT id FROM 表名GROUP BY ID HAV ...
- MySQL根据业务场景归纳常用SQL语句
素材表数据:user[{"id":1,"name":"x"},{"id":2,"name":&quo ...
- 数据库及MYSQL基础(3)-JDBC
教学视频链接:https://edu.aliyun.com/course/1694?spm=5176.11400004.0.0.29254768sg2H5P 程序文件链接:https://pan.ba ...
- MSSQL - 逻辑主键、业务主键和复合主键
转载自:http://blog.csdn.net/sunrise918/article/details/5575054 这几天对逻辑主键.业务主键和复合主键进行了一些思考,也在网上搜索了一下相关的讨论 ...
- kubernetes进阶之七:Service
1.概述 Service也是Kubernetes里的最核心的资源对象之一,Kubernetes里的每个Service其实就是我们经常提起的微服务架构中的一个“微服务”,之前我们所说的Pod.RC等资源 ...
- SpringBoot 三层架构 Controller、Service、Dao作用和关系详解
首先创建一个springboot项目. model层 model层也叫pojo层或者entity层,个人比较喜欢pojo层. 一般数据库的一张表对应一个pojo层,并且表中所有字段都在pojo层都一一 ...
随机推荐
- Oracle导入程序Imp的使用详解
Oracle的导入实用程序(Import utility)允许从数据库提取数据,并且将数据写入操作系统文件.imp使用的基本格式:imp[username[/password[@service]]], ...
- swift class的虚函数表、扩展、@objc修饰、虚函数的派发方式研究
swift class的虚函数表.扩展.@objc修饰的研究 工具: swiftc -emit-sil BaseClass.swift | xcrun swift-demangle > Clas ...
- 深入分析escape()、encodeURI()、encodeURIComponent()的区别及示例
JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...
- Spring AOP 和 AspectJ
现如今有许多个可用的 AOP 库,使用这些库需要能够回答以下问题: 是否与现有的或新的应用程序兼容? 在哪里可以使用 AOP ? 如何迅速与应用程序集成? 性能开销是多少? 在本文中,我们将回答这些问 ...
- java.lang.NoClassDefFoundError: org/eclipse/core/resources/IContainer
启动eclipse报错:java.lang.NoClassDefFoundError: org/eclipse/core/resources/IContainer 解决办法: 删除以下文件.metad ...
- day20 Python 装饰器
装饰器:本质就是函数,为其他函数添加附加功能,一个原则是不修改函数的源代码,另外一个原则是不修改被修饰函数的调用功能 装饰器=高阶函数+函数嵌套+闭包 前戏 import time def cal(l ...
- Spark学习之JavaRdd
RDD 介绍 RDD,全称Resilient Distributed Datasets(弹性分布式数据集),是Spark最为核心的概念,是Spark对数据的抽象.RDD是分布式的元素集合,每个RDD只 ...
- csvwrite
https://ww2.mathworks.cn/help/matlab/ref/csvwrite.html
- NodeJS之path模块
NodeJS之path模块 常用的主要有如下工具函数: 1. path.basename(path[, ext]) 2. path.extname(path) 3. path.dirname(path ...
- <转>jmeter(十四)HTTP请求之content-type
本博客转载自:http://www.cnblogs.com/dinghanhua/p/5646435.html 个人感觉不错,对jmeter最常用的取样器http请求需要用到的信息头管理器做了很好的解 ...