Comments (4)
package org.jeecg.modules.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.netty.util.internal.StringUtil;
import org.jeecg.modules.system.controller.FindsDepartsChildrenUtil;
import org.jeecg.common.util.YouBianCodeUtil;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.jeecg.modules.system.model.SysDepartTreeModel;
import org.jeecg.modules.system.service.ISysDepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
* <p>
* 部门表 服务实现类
* <p>
*
* @author Steve
* @Since 2019-01-22
*/
@Service
public class SysDepartServiceImpl<T> extends ServiceImpl<SysDepartMapper, SysDepart> implements ISysDepartService {
// 该集合用来存储部门下的所有数据
private List<SysDepart> globalList = new ArrayList<>();
/**
* queryTreeList 对应 queryTreeList 查询所有的部门数据,以树结构形式响应给前端
*/
@Override
public List<SysDepartTreeModel> queryTreeList() {
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
query.eq(SysDepart::getDelFlag, 0);
query.orderByAsc(SysDepart::getDepartOrder);
List<SysDepart> list = this.list(query);
globalList = list;
// 调用wrapTreeDataToTreeList方法生成树状数据
List<SysDepartTreeModel> listResult = FindsDepartsChildrenUtil.wrapTreeDataToTreeList(list);
return listResult;
}
/**
* saveDepartData 对应 add 保存用户在页面添加的新的部门对象数据
*/
@Override
@Transactional
public void saveDepartData(SysDepart sysDepart, String username) {
if (sysDepart != null && username != null) {
if (sysDepart.getParentId() == null) {
sysDepart.setParentId("");
}
String s = UUID.randomUUID().toString().replace("-", "");
sysDepart.setId(s);
// 先判断该对象有无父级ID,有则意味着不是最高级,否则意味着是最高级
// 获取父级ID
String parentId = sysDepart.getParentId();
String[] codeArray = generateOrgCode(parentId);
sysDepart.setOrgCode(codeArray[0]);
String orgType = codeArray[1];
sysDepart.setOrgType(String.valueOf(orgType));
sysDepart.setCreateTime(new Date());
sysDepart.setDelFlag("0");
this.save(sysDepart);
}
}
/**
* saveDepartData 的调用方法,生成部门编码和部门类型
*
* @param parentId
* @param parentId
* @return
*/
private String[] generateOrgCode(String parentId) {
//update-begin--Author:Steve Date:20190201 for:组织机构添加数据代码调整
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
LambdaQueryWrapper<SysDepart> query1 = new LambdaQueryWrapper<SysDepart>();
String[] strArray = new String[2];
// 创建一个List集合,存储查询返回的所有SysDepart对象
List<SysDepart> departList = new ArrayList<>();
// 定义新编码字符串
String newOrgCode = "";
// 定义旧编码字符串
String oldOrgCode = "";
// 定义部门类型
String orgType = "";
// 如果是最高级,则查询出同级的org_code, 调用工具类生成编码并返回
if (StringUtil.isNullOrEmpty(parentId)) {
// 线判断数据库中的表是否为空,空则直接返回初始编码
query1.eq(SysDepart::getParentId, "");
query1.orderByDesc(SysDepart::getOrgCode);
departList = this.list(query1);
if(departList == null || departList.size() == 0) {
strArray[0] = YouBianCodeUtil.getNextYouBianCode(null);
strArray[1] = "1";
return strArray;
}else {
SysDepart depart = departList.get(0);
oldOrgCode = depart.getOrgCode();
orgType = depart.getOrgType();
newOrgCode = YouBianCodeUtil.getNextYouBianCode(oldOrgCode);
}
} else { // 反之则查询出所有同级的部门,获取结果后有两种情况,有同级和没有同级
// 封装查询同级的条件
query.eq(SysDepart::getParentId, parentId);
// 降序排序
query.orderByDesc(SysDepart::getOrgCode);
// 查询出同级部门的集合
List<SysDepart> parentList = this.list(query);
// 查询出父级部门
SysDepart depart = this.getById(parentId);
// 获取父级部门的Code
String parentCode = depart.getOrgCode();
// 根据父级部门类型算出当前部门的类型
orgType = String.valueOf(Integer.valueOf(depart.getOrgType()) + 1);
// 处理同级部门为null的情况
if (parentList == null || parentList.size() == 0) {
// 直接生成当前的部门编码并返回
newOrgCode = YouBianCodeUtil.getSubYouBianCode(parentCode, null);
} else { //处理有同级部门的情况
// 获取同级部门的编码,利用工具类
String subCode = parentList.get(0).getOrgCode();
// 返回生成的当前部门编码
newOrgCode = YouBianCodeUtil.getSubYouBianCode(parentCode, subCode);
}
}
// 返回最终封装了部门编码和部门类型的数组
strArray[0] = newOrgCode;
strArray[1] = orgType;
return strArray;
//update-end--Author:Steve Date:20190201 for:组织机构添加数据代码调整
}
/**
* removeDepartDataById 对应 delete方法 根据ID删除相关部门数据
*
*/
/*
* @Override
*
* @Transactional public boolean removeDepartDataById(String id) {
* System.out.println("要删除的ID 为=============================>>>>>"+id); boolean
* flag = sysDepartService.removeById(id); return flag; }
*/
/**
* updateDepartDataById 对应 edit 根据部门主键来更新对应的部门数据
*/
@Override
@Transactional
public Boolean updateDepartDataById(SysDepart sysDepart, String username) {
if (sysDepart != null && username != null) {
sysDepart.setUpdateTime(new Date());
sysDepart.setUpdateBy(username);
this.updateById(sysDepart);
return true;
} else {
return false;
}
}
/**
* <p>
* 根据关键字搜索相关的部门数据
* </p>
*/
@Override
public List<SysDepartTreeModel> searhBy(String keyWord) {
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
query.like(SysDepart::getDepartName, keyWord);
List<SysDepart> departList = this.list(query);
List<SysDepartTreeModel> newList = new ArrayList<>();
if(departList.size() > 0 || this != null) {
for(SysDepart depart : departList) {
newList.add(new SysDepartTreeModel(depart));
}
return newList;
}
return null;
}
}
我修改成如下之后,项目可以启动,并且部门功能初步测试可用!
from jeecg-boot.
没看明白,问题出在那?
from jeecg-boot.
Bean with name 'sysDepartServiceImpl' has been injected into other beans
这个呀,我把这个类的
@Autowired
private ISysDepartService sysDepartService;
去掉了。换成了this之后就好了
from jeecg-boot.
非常感谢,明白了
from jeecg-boot.
Related Issues (20)
- 项目配置切换暗黑主题之后,无法自定义顶栏和菜单主题 HOT 1
- 使用appendSchemaByField后提交时验证报错 HOT 2
- 表格合计显示 HOT 1
- 前端上传组件,部署生产环境后,无法上传文件 HOT 19
- updateById 在启用了SASS并且是异步调用时取不到tenantId造成更新失败 HOT 1
- 【项目改写】是否有计划使用Angular技术栈改写一版当前项目 HOT 1
- 官网演示一对多示例,当编辑订单时,子表新增多行客户信息和机票信息,每次都只能保存一条记录。 HOT 1
- 地区选择器,杭州仍然是旧的划分,存在江干区下城区,没有钱塘区 HOT 3
- 添加 @vitejs/plugin-legacy 插件 打包报错 HOT 1
- windows环境下nginx配置经验交流
- 瀚高数据库Online表单开发导入数据库表功能 HOT 2
- 开启多租户模式后,登陆的用户使用一段时间后用户的租户ID就会变成0
- 打开Modal弹窗,控制台报错 HOT 2
- [期望需求] WebRTC的支持,或者实现示例和文档 HOT 1
- jeecg-boot前端部署到nginx后 登录首页报错404 无法获取到验证码 HOT 1
- nginx 别名部署前端项目报了这个 HOT 1
- online表单,能否修改自带按钮的名称,或者隐藏自带按钮 HOT 1
- 代码生成器不能导入其他数据库表 HOT 4
- popup_dict 设置问题?
- nacos启动失败 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jeecg-boot.