|
|
@@ -5,148 +5,87 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.ydtech.modules.admin.dao.SysDeptMapper;
|
|
|
-import com.ydtech.modules.admin.model.vo.TreeSysDeptVO;
|
|
|
import com.ydtech.core.page.PageRequest;
|
|
|
import com.ydtech.core.page.PageResult;
|
|
|
+import com.ydtech.exception.SystemException;
|
|
|
+import com.ydtech.modules.admin.dao.SysDeptMapper;
|
|
|
import com.ydtech.modules.admin.model.SysDept;
|
|
|
+import com.ydtech.modules.admin.model.vo.TreeSysDeptVO;
|
|
|
import com.ydtech.modules.admin.service.SysDeptService;
|
|
|
+import com.ydtech.modules.protocol.utils.AssertionUtils;
|
|
|
import com.ydtech.utils.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@Service
|
|
|
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
implements SysDeptService {
|
|
|
- @Override
|
|
|
- public List<SysDept> findTree(SysDept sysDept) {
|
|
|
- LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper();
|
|
|
- lqw.eq(SysDept::getDelFlag, 0);
|
|
|
- if (null != sysDept) {
|
|
|
- lqw.like(StringUtils.isNotEmpty(sysDept.getName()), SysDept::getName, sysDept.getName());
|
|
|
-// lqw.like(StringUtils.isNotEmpty(sysDept.getParentId()), SysDept::getParentId, sysDept.getParentId());
|
|
|
-// lqw.like(StringUtils.isNotEmpty(sysDept.getParentId()), SysDept::getParentId, sysDept.getParentId());
|
|
|
- lqw.like(StringUtils.isNotEmpty(sysDept.getId()), SysDept::getId, sysDept.getId());
|
|
|
- }
|
|
|
-// lqw.like(SysDept::getId,"99140109M13D01");
|
|
|
-
|
|
|
- List<SysDept> list = new ArrayList<>();
|
|
|
- List<SysDept> allList = list(lqw);
|
|
|
-
|
|
|
|
|
|
- list.addAll(allList.stream().filter(s -> s.getParentId().equalsIgnoreCase("0")).collect(Collectors.toList()));
|
|
|
+ @Override
|
|
|
+ public List<SysDept> findTree(String deptId) {
|
|
|
+ SysDept sysDept = getById(deptId);
|
|
|
|
|
|
-// allList.stream().forEach(r -> {
|
|
|
-// if (StringUtils.isNullOrEmpty(r.getParentId()) || r.getParentId().equalsIgnoreCase("0")) {
|
|
|
-// if (!exists(list, r)) {
|
|
|
-// list.add(r);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// });
|
|
|
+ LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
|
|
|
+ lqw.eq(SysDept::getDelFlag, 0);
|
|
|
+ lqw.likeRight(SysDept::getId, deptId);
|
|
|
+ List<SysDept> sysDeptList = list(lqw);
|
|
|
+ Map<String, List<SysDept>> map = sysDeptList.stream().collect(Collectors.groupingBy(SysDept::getParentId));
|
|
|
+ sysDeptList.forEach(i -> i.setChildren(map.getOrDefault(i.getId(), new ArrayList<>())));
|
|
|
+ return map.get(sysDept.getParentId());
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void addDept(SysDept sysDept) {
|
|
|
+ SysDept dept = getById(sysDept.getId());
|
|
|
+ AssertionUtils.isEmpty(dept, "机构编号为:" + dept.getId() + " " + dept.getName() + "已被占用");
|
|
|
+ boolean b = save(sysDept);
|
|
|
+ AssertionUtils.isSucceed(b, "删除失败");
|
|
|
+ }
|
|
|
|
|
|
- //指定部门
|
|
|
- if (list.size() < 1) {
|
|
|
- list.addAll(allList.stream().filter(s -> s.getId().equalsIgnoreCase(sysDept.getId())).collect(Collectors.toList()));
|
|
|
-// allList.stream().forEach(r -> {
|
|
|
-// list.add(r);
|
|
|
-// });
|
|
|
+ @Override
|
|
|
+ public void deleteDept(String deptId) {
|
|
|
+ SysDept sysDept = getById(deptId);
|
|
|
+ List<SysDept> list = lambdaQuery().eq(SysDept::getParentId, sysDept.getId()).list();
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ boolean b = removeById(deptId);
|
|
|
+ AssertionUtils.isSucceed(b, "删除失败");
|
|
|
+ } else {
|
|
|
+ throw new SystemException(sysDept.getName() + "下还有其他隶属机构");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- findChildren(list, allList);
|
|
|
- return list;
|
|
|
}
|
|
|
-//public class SysDeptServiceImpl extends SysDeptDaoImpl
|
|
|
-// implements SysDeptService {
|
|
|
-
|
|
|
-
|
|
|
- // @Override
|
|
|
-// public int add(SysDept record) {
|
|
|
-// return insertSelective(record);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public int edit(SysDept record) {
|
|
|
-// return updateSelective(record);
|
|
|
-// }
|
|
|
-//
|
|
|
+
|
|
|
@Override
|
|
|
public PageResult findSubDepts(PageRequest pageRequest) {
|
|
|
-
|
|
|
-
|
|
|
String id = pageRequest.getColumnFilterValue(pageRequest, "id");
|
|
|
|
|
|
- Page p = PageRequest.buildPageRequest(pageRequest);
|
|
|
- LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper();
|
|
|
+ Page<SysDept> p = PageRequest.buildPageRequest(pageRequest);
|
|
|
+ LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
|
|
|
lqw.eq(StringUtils.isNotEmpty(id), SysDept::getParentId, id);
|
|
|
-
|
|
|
IPage<SysDept> pResult = page(p, lqw);
|
|
|
-
|
|
|
//传入查询条件
|
|
|
PageResult pageResult = PageResult.buildPageResult(pResult);
|
|
|
return pageResult;
|
|
|
|
|
|
}
|
|
|
|
|
|
- //
|
|
|
-//
|
|
|
-// public SysDept findById(Long id) {
|
|
|
-// return selectByPk("" + id);
|
|
|
-// }
|
|
|
-//
|
|
|
-//// public PageResult findPage(PageRequest pageRequest) {
|
|
|
-//// return MybatisPageHelper.findPage(pageRequest, sysDeptMapper);
|
|
|
-//// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public List<SysDept> findTree() {
|
|
|
-// List<SysDept> sysDepts = new ArrayList<>();
|
|
|
-// List<SysDept> depts = selectAll();
|
|
|
-// for (SysDept dept : depts) {
|
|
|
-// if (StringUtils.isNullOrEmpty(dept.getParentId()) || dept.getParentId().equals("0") ) {
|
|
|
-// dept.setLevel(0);
|
|
|
-// sysDepts.add(dept);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// findChildren(sysDepts, depts);
|
|
|
-// return sysDepts;
|
|
|
-// }
|
|
|
-//
|
|
|
-// private void findChildren(List<SysDept> sysDepts, List<SysDept> depts) {
|
|
|
-// for (SysDept sysDept : sysDepts) {
|
|
|
-// List<SysDept> children = new ArrayList<>();
|
|
|
-// for (SysDept dept : depts) {
|
|
|
-// if (sysDept.getId() != null && sysDept.getId().equals(dept.getParentId())) {
|
|
|
-//// dept.setParentName(dept.getName());
|
|
|
-// dept.setParentName(dept.getParentName());
|
|
|
-// dept.setLevel(sysDept.getLevel() + 1);
|
|
|
-// children.add(dept);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// sysDept.setChildren(children);
|
|
|
-// findChildren(children, depts);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// //----------------------------------------------------------
|
|
|
-//
|
|
|
+
|
|
|
//查找自已有权限的部门树
|
|
|
public List<TreeSysDeptVO> selectListTreeSysDeptVO(String id) {
|
|
|
- if (id == null) id = "";
|
|
|
+ if (id == null) {
|
|
|
+ id = "";
|
|
|
+ }
|
|
|
LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
|
|
|
+
|
|
|
lqw.like(StringUtils.isNotEmpty(id), SysDept::getId, id);
|
|
|
List<SysDept> deptList = list(lqw);
|
|
|
- List<TreeSysDeptVO> recordList = new ArrayList<TreeSysDeptVO>();
|
|
|
+ List<TreeSysDeptVO> recordList = new ArrayList<>();
|
|
|
|
|
|
- deptList.stream().forEach(a -> {
|
|
|
+ deptList.forEach(a -> {
|
|
|
TreeSysDeptVO model = new TreeSysDeptVO();
|
|
|
model.setId(a.getId());
|
|
|
model.setName(a.getName());
|
|
|
@@ -161,55 +100,11 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
|
|
|
return recordList;
|
|
|
}
|
|
|
-// public List<TreeSysDeptVO> selectListTreeSysDeptVO(String id) {
|
|
|
-// if (id == null) id = "";
|
|
|
-//
|
|
|
-// String sql = "select t1.id, t1.name, t1.parent_id, t1.dept_code, t1.province, t1.city, t1.area, t1.comlevel from sys_dept t1 where id like ? order by order_num ";
|
|
|
-//
|
|
|
-// JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
|
|
-//
|
|
|
-// List<TreeSysDeptVO> recordList = new ArrayList<TreeSysDeptVO>();
|
|
|
-//
|
|
|
-// jdbcTemplate.query(sql, new Object[]{id + "%"},
|
|
|
-// new RowCallbackHandler() {
|
|
|
-// @Override
|
|
|
-// public void processRow(ResultSet resultSet) throws SQLException {
|
|
|
-// TreeSysDeptVO model = new TreeSysDeptVO();
|
|
|
-// model.setId(resultSet.getString("id"));
|
|
|
-// model.setName(resultSet.getString("name"));
|
|
|
-// model.setParentId(resultSet.getString("parent_id"));
|
|
|
-// model.setDeptCode(resultSet.getString("dept_code"));
|
|
|
-// model.setProvince(resultSet.getString("province"));
|
|
|
-// model.setCity(resultSet.getString("city"));
|
|
|
-// model.setArea(resultSet.getString("area"));
|
|
|
-// model.setComlevel(resultSet.getString("comlevel"));
|
|
|
-// recordList.add(model);
|
|
|
-// }
|
|
|
-// });
|
|
|
-//
|
|
|
-// return recordList;
|
|
|
-// }
|
|
|
-
|
|
|
- // public String findMaxDeptId(String deptId) {
|
|
|
-// if (deptId == null) return "";
|
|
|
-// String result = "00";
|
|
|
-//
|
|
|
-// String sql = "SELECT IFNULL(MAX(id),0) maxid FROM sys_dept t1 WHERE t1.id LIKE ? ";
|
|
|
-//
|
|
|
-// JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
|
|
-// String maxId = jdbcTemplate.queryForObject(sql, new Object[]{deptId + "D%"}, String.class);
|
|
|
-//
|
|
|
-// if (!maxId.equalsIgnoreCase("0") && !maxId.equalsIgnoreCase(deptId)) {
|
|
|
-// result = maxId.substring(deptId.length() + 1);
|
|
|
-// }
|
|
|
-//
|
|
|
-// return result;
|
|
|
-// }
|
|
|
+
|
|
|
+
|
|
|
public String findMaxDeptId(String deptId) {
|
|
|
if (deptId == null) return "";
|
|
|
String result = "00";
|
|
|
-
|
|
|
-
|
|
|
QueryWrapper<SysDept> qw = new QueryWrapper<>();
|
|
|
qw.like(StringUtils.isNotEmpty(deptId), "id", deptId + "D%");
|
|
|
|
|
|
@@ -225,13 +120,12 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
|
|
|
public String findMaxHouseId(String deptId) {
|
|
|
|
|
|
- if (deptId == null) return "";
|
|
|
+ if (deptId == null) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
String result = "00";
|
|
|
-
|
|
|
-
|
|
|
QueryWrapper<SysDept> qw = new QueryWrapper<>();
|
|
|
qw.like(StringUtils.isNotEmpty(deptId), "id", deptId + "M%");
|
|
|
-
|
|
|
qw.select("IFNULL(MAX(id),0) maxid");
|
|
|
Map<String, Object> m = getMap(qw);
|
|
|
String maxId = m.get("maxid").toString();
|
|
|
@@ -241,34 +135,21 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
|
|
|
return result;
|
|
|
|
|
|
-
|
|
|
-// if (deptId == null) return "";
|
|
|
-// String result = "00";
|
|
|
-//
|
|
|
-// String sql = "SELECT IFNULL(MAX(id),0) maxid FROM sys_dept t1 WHERE t1.id LIKE ? ";
|
|
|
-//
|
|
|
-// JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
|
|
-// String maxId = jdbcTemplate.queryForObject(sql, new Object[]{deptId + "M%"}, String.class);
|
|
|
-//
|
|
|
-// if (!maxId.equalsIgnoreCase("0") && !maxId.equalsIgnoreCase(deptId)) {
|
|
|
-// result = maxId.substring(deptId.length() + 1);
|
|
|
-// }
|
|
|
-//
|
|
|
-// return result;
|
|
|
}
|
|
|
|
|
|
//
|
|
|
@Override
|
|
|
public List<TreeSysDeptVO> selectListWhere(String where, Object[] paramValues) {
|
|
|
|
|
|
- String sql = "select t1.id, t1.name, t1.parent_id, t1.dept_code, t1.province, t1.city, t1.area, t1.comlevel from sys_dept t1 where del_flag='0' " + where;
|
|
|
+ String sql = "select t1.id, t1.name, t1.parent_id, t1.dept_code, t1.province, t1.city, t1.area, t1.comlevel from sys_dept t1 " +
|
|
|
+ "where del_flag='0' " + where;
|
|
|
QueryWrapper<SysDept> qw = new QueryWrapper<>();
|
|
|
qw.select(sql);
|
|
|
List<SysDept> sysDeptList = list(qw);
|
|
|
|
|
|
List<TreeSysDeptVO> recordList = new ArrayList<TreeSysDeptVO>();
|
|
|
|
|
|
- sysDeptList.stream().forEach(a -> {
|
|
|
+ sysDeptList.forEach(a -> {
|
|
|
TreeSysDeptVO model = new TreeSysDeptVO();
|
|
|
model.setId(a.getId());
|
|
|
model.setName(a.getName());
|
|
|
@@ -284,35 +165,6 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
return recordList;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private boolean exists(List<SysDept> insSysDeptList, SysDept insSysDept) {
|
|
|
- AtomicBoolean exist = new AtomicBoolean(false);
|
|
|
- insSysDeptList.stream().forEach(a -> {
|
|
|
- if (a.getId().equals(insSysDept.getId())) {
|
|
|
- exist.set(true);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return exist.get();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void findChildren(List<SysDept> list, List<SysDept> allList) {
|
|
|
- for (SysDept l : list) {
|
|
|
- List<SysDept> children = new ArrayList<>();
|
|
|
- for (SysDept sysDept : allList) {
|
|
|
-
|
|
|
- if (l.getId() != null && l.getId().equals(sysDept.getParentId())) {
|
|
|
- if (!exists(children, sysDept)) {
|
|
|
- children.add(sysDept);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- l.setChildren(children);
|
|
|
-// children.sort((o1, o2) -> o1.getOrderNum().compareTo(o2.getOrderNum()));
|
|
|
- findChildren(children, allList);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
|