业务-----部门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层都一一 ...
随机推荐
- spring.factories
在Spring Boot中有一种非常解耦的扩展机制:Spring Factories.这种扩展机制实际上是仿照Java中的SPI扩展机制来实现的. Java SPI机制SPI的全名为Service P ...
- 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165318
2018-2019-2 <网络对抗技术>Exp0 Kali安装 Week1 20165318 下载地址 Kali官网,选择Kali Linux 64 bit VMware 安装步骤 以下步 ...
- cryptopunks的代码解释
1.imageHash就是将punk所有图像合在一起的那张图punks.png进行hash得到一个值,并将该值存储到链上,用处就是你可以通过将图像hash然后跟该值对比看图像对不对.这就是它的用处,在 ...
- Mysql主从同步(复制)(转)
文章转自:https://www.cnblogs.com/kylinlin/p/5258719.html 目录: mysql主从同步定义 主从同步机制 配置主从同步 配置主服务器 配置从服务器 使用主 ...
- nodeJS之crypto模块公钥加密及解密
nodeJS之crypto模块公钥加密及解密 NodeJS有以下4个与公钥加密相关的类.1. Cipher: 用于加密数据:2. Decipher: 用于解密数据:3. Sign: 用于生成签名:4. ...
- protobuf可变长编码的实现原理
protobuf中的整数,如int32.int64.uint32.uint64.sint32.sint64.bool和enum,采用可变长编码,即varints. 这样做的好处是,可以节省空间.根据整 ...
- Objective-C atomic属性不是线程安全的
atomic(原子的),顾名思义,原子操作应该是线程安全的,然而,真相并不是! @property (atomic, strong) NSMutableArray *arr; // 多线程操作arr并 ...
- windows7系统下配置开发环境 python2.7+pyqt4+pycharm
python2.7 链接:https://pan.baidu.com/s/1lPI9AF9GCaakLXsMZLd5mQ 提取码:5xt6 pip 链接:https://pan.baidu.com/s ...
- Ubuntu下禁止自动打开U盘等设备
打开终端 禁止自动挂载: $ gsettings set org.gnome.desktop.media-handling automount false 禁止自动挂载并打开 $ gsettings ...
- Redis 安装部署
1. 官网(https://redis.io/download)下载稳定版安装包 3.0.7或3.2或4.1; 2. 复制到部署服务器 /opt/redis4,解压 tar zxvf redis-4. ...