|
@@ -49,161 +49,161 @@ import java.util.stream.Collectors;
|
|
|
@AllArgsConstructor
|
|
|
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements SysDeptService {
|
|
|
|
|
|
- private final SysDeptRelationService sysDeptRelationService;
|
|
|
-
|
|
|
- private final SysDeptRelationMapper sysDeptRelationMapper;
|
|
|
-
|
|
|
- private final SysDeptMapper deptMapper;
|
|
|
-
|
|
|
- private final SysCsmUserRelationService sysCsmUserRelationService;
|
|
|
-
|
|
|
- private final SysDeptCsmMapper sysDeptCsmMapper;
|
|
|
-
|
|
|
- @Override
|
|
|
- public List convertToName() {
|
|
|
- return deptMapper.getDeptConvertToName();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List getChildDept(SysDept sysDept) {
|
|
|
- return deptMapper.getChildDept(sysDept);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List getParentDept(SysDept sysDept) {
|
|
|
- return deptMapper.getParentDept(sysDept);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public SysDept selectByDeptId(Integer deptId) {
|
|
|
- SysDept sysDept1 = new SysDept();
|
|
|
- sysDept1.setDeptId(deptId);
|
|
|
- return deptMapper.selectDistinctDeptId(sysDept1);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<SysDept> selectByName(String entname) {
|
|
|
- return deptMapper.selectByName(entname);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 添加信息部门
|
|
|
- *
|
|
|
- * @param dept 部门
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Integer saveDept(SysDept dept) {
|
|
|
- SysDept sysDept = new SysDept();
|
|
|
- BeanUtils.copyProperties(dept, sysDept);
|
|
|
- this.save(sysDept);
|
|
|
- sysDeptRelationService.insertDeptRelation(sysDept);
|
|
|
- return dept.getDeptId();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除部门
|
|
|
- *
|
|
|
- * @param id 部门 ID
|
|
|
- * @return 成功、失败
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean removeDeptById(Integer id) {
|
|
|
- // 级联删除部门
|
|
|
- List<Integer> idList = sysDeptRelationService
|
|
|
- .list(Wrappers.<SysDeptRelation>query().lambda().eq(SysDeptRelation::getAncestor, id)).stream()
|
|
|
- .map(SysDeptRelation::getDescendant).collect(Collectors.toList());
|
|
|
-
|
|
|
- if (CollUtil.isNotEmpty(idList)) {
|
|
|
- this.removeByIds(idList);
|
|
|
- }
|
|
|
-
|
|
|
- //删除组织机构
|
|
|
- sysDeptRelationService.deleteDeptById(id);
|
|
|
-
|
|
|
- // 删除部门级联关系
|
|
|
- sysDeptRelationService.deleteAllDeptRealtion(id);
|
|
|
- return Boolean.TRUE;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新部门
|
|
|
- *
|
|
|
- * @param sysDept 部门信息
|
|
|
- * @return 成功、失败
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean updateDeptById(SysDept sysDept) {
|
|
|
- // 更新部门状态
|
|
|
- this.updateById(sysDept);
|
|
|
- // 更新部门关系
|
|
|
- SysDeptRelation relation = new SysDeptRelation();
|
|
|
- relation.setAncestor(sysDept.getParentId());
|
|
|
- relation.setDescendant(sysDept.getDeptId());
|
|
|
- sysDeptRelationService.updateDeptRealtion(relation);
|
|
|
- return Boolean.TRUE;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<SysDept> listScope(SysDept sysDept) {
|
|
|
- QueryWrapper<SysDept> queryWrapper = Wrappers.query(sysDept);
|
|
|
-
|
|
|
- if (SecurityUtils.getRoles().contains(19)) {
|
|
|
- // CSM只能查看自己维护的企业下的数据, 以及下属维护的企业下的数据
|
|
|
- Integer userId = SecurityUtils.getUser().getId();
|
|
|
- // 递归查询下属关联的userId
|
|
|
- Set<Integer> allUserIds = sysCsmUserRelationService.recurseCsmLowerUserId(Collections.singleton(userId), new AtomicInteger(10));
|
|
|
- // 查询企业id
|
|
|
- List<SysDeptCsm> deptCsms = sysDeptCsmMapper.selectList(Wrappers.<SysDeptCsm>lambdaQuery()
|
|
|
- .in(SysDeptCsm::getUserId, allUserIds));
|
|
|
- if (CollUtil.isEmpty(deptCsms)) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
-
|
|
|
- Set<Integer> deptIds = deptCsms.stream().map(SysDeptCsm::getDeptId).collect(Collectors.toSet());
|
|
|
- queryWrapper.in("dept_id", deptIds);
|
|
|
- }
|
|
|
-
|
|
|
- return deptMapper.selectListByScope(queryWrapper, new DataScope());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<SysDept> selectDeptByName(SysDept sysDept) {
|
|
|
- List<SysDept> deptList = new ArrayList<>();
|
|
|
- if (SecurityUtils.getRoles().contains(1) || SecurityUtils.getRoles().contains(2)) {
|
|
|
- List<SysDept> sysDeptList = deptMapper.selectListByDept(sysDept);
|
|
|
- return sysDeptList;
|
|
|
- } else {
|
|
|
- sysDept.setDeptId(SecurityUtils.getUser().getDeptId());
|
|
|
- deptList = deptMapper.selectDeptByName(sysDept);
|
|
|
- }
|
|
|
- return deptList;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public SysDept selectDeptId(SysDept sysDept) {
|
|
|
- return deptMapper.selectById(sysDept.getDeptId());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public SysDept selectDeptById(SysDept sysDept) {
|
|
|
- return this.getById(sysDept.getDeptId());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询全部部门树
|
|
|
- *
|
|
|
- * @return 树
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<DeptTree> selectTreeAddUser(SysDept sysDept) {
|
|
|
- // 查询数据权限内部门
|
|
|
- List<Integer> roles = SecurityUtils.getRoles();
|
|
|
+ private final SysDeptRelationService sysDeptRelationService;
|
|
|
+
|
|
|
+ private final SysDeptRelationMapper sysDeptRelationMapper;
|
|
|
+
|
|
|
+ private final SysDeptMapper deptMapper;
|
|
|
+
|
|
|
+ private final SysCsmUserRelationService sysCsmUserRelationService;
|
|
|
+
|
|
|
+ private final SysDeptCsmMapper sysDeptCsmMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> convertToName() {
|
|
|
+ return deptMapper.getDeptConvertToName();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getChildDept(SysDept sysDept) {
|
|
|
+ return deptMapper.getChildDept(sysDept);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SysDept> getParentDept(SysDept sysDept) {
|
|
|
+ return deptMapper.getParentDept(sysDept);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SysDept selectByDeptId(Integer deptId) {
|
|
|
+ SysDept sysDept1 = new SysDept();
|
|
|
+ sysDept1.setDeptId(deptId);
|
|
|
+ return deptMapper.selectDistinctDeptId(sysDept1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SysDept> selectByName(String entname) {
|
|
|
+ return deptMapper.selectByName(entname);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加信息部门
|
|
|
+ *
|
|
|
+ * @param dept 部门
|
|
|
+ * @return 企业ID
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Integer saveDept(SysDept dept) {
|
|
|
+ SysDept sysDept = new SysDept();
|
|
|
+ BeanUtils.copyProperties(dept, sysDept);
|
|
|
+ this.save(sysDept);
|
|
|
+ sysDeptRelationService.insertDeptRelation(sysDept);
|
|
|
+ return dept.getDeptId();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除部门
|
|
|
+ *
|
|
|
+ * @param id 部门 ID
|
|
|
+ * @return 成功、失败
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean removeDeptById(Integer id) {
|
|
|
+ // 级联删除部门
|
|
|
+ List<Integer> idList = sysDeptRelationService
|
|
|
+ .list(Wrappers.<SysDeptRelation>query().lambda().eq(SysDeptRelation::getAncestor, id)).stream()
|
|
|
+ .map(SysDeptRelation::getDescendant).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(idList)) {
|
|
|
+ this.removeByIds(idList);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除组织机构
|
|
|
+ sysDeptRelationService.deleteDeptById(id);
|
|
|
+
|
|
|
+ // 删除部门级联关系
|
|
|
+ sysDeptRelationService.deleteAllDeptRelation(id);
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新部门
|
|
|
+ *
|
|
|
+ * @param sysDept 部门信息
|
|
|
+ * @return 成功、失败
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean updateDeptById(SysDept sysDept) {
|
|
|
+ // 更新部门状态
|
|
|
+ this.updateById(sysDept);
|
|
|
+ // 更新部门关系
|
|
|
+ SysDeptRelation relation = new SysDeptRelation();
|
|
|
+ relation.setAncestor(sysDept.getParentId());
|
|
|
+ relation.setDescendant(sysDept.getDeptId());
|
|
|
+ sysDeptRelationService.updateDeptRelation(relation);
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SysDept> listScope(SysDept sysDept) {
|
|
|
+ QueryWrapper<SysDept> queryWrapper = Wrappers.query(sysDept);
|
|
|
+
|
|
|
+ if (SecurityUtils.getRoles().contains(19)) {
|
|
|
+ // CSM只能查看自己维护的企业下的数据, 以及下属维护的企业下的数据
|
|
|
+ Integer userId = SecurityUtils.getUser().getId();
|
|
|
+ // 递归查询下属关联的userId
|
|
|
+ Set<Integer> allUserIds = sysCsmUserRelationService.recurseCsmLowerUserId(Collections.singleton(userId), new AtomicInteger(10));
|
|
|
+ // 查询企业id
|
|
|
+ List<SysDeptCsm> deptCsms = sysDeptCsmMapper.selectList(Wrappers.<SysDeptCsm>lambdaQuery()
|
|
|
+ .in(SysDeptCsm::getUserId, allUserIds));
|
|
|
+ if (CollUtil.isEmpty(deptCsms)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Integer> deptIds = deptCsms.stream().map(SysDeptCsm::getDeptId).collect(Collectors.toSet());
|
|
|
+ queryWrapper.in("dept_id", deptIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ return deptMapper.selectListByScope(queryWrapper, new DataScope());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SysDept> selectDeptByName(SysDept sysDept) {
|
|
|
+ List<SysDept> deptList = new ArrayList<>();
|
|
|
+ if (SecurityUtils.getRoles().contains(1) || SecurityUtils.getRoles().contains(2)) {
|
|
|
+ List<SysDept> sysDeptList = deptMapper.selectListByDept(sysDept);
|
|
|
+ return sysDeptList;
|
|
|
+ } else {
|
|
|
+ sysDept.setDeptId(SecurityUtils.getUser().getDeptId());
|
|
|
+ deptList = deptMapper.selectDeptByName(sysDept);
|
|
|
+ }
|
|
|
+ return deptList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SysDept selectDeptId(SysDept sysDept) {
|
|
|
+ return deptMapper.selectById(sysDept.getDeptId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SysDept selectDeptById(SysDept sysDept) {
|
|
|
+ return this.getById(sysDept.getDeptId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询全部部门树
|
|
|
+ *
|
|
|
+ * @return 树
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<DeptTree> selectTreeAddUser(SysDept sysDept) {
|
|
|
+ // 查询数据权限内部门
|
|
|
+ List<Integer> roles = SecurityUtils.getRoles();
|
|
|
// List<SysDept> deptList = new ArrayList<>();
|
|
|
// sysDept.setDeptId(SecurityUtils.getUser().getDeptId());
|
|
|
// List<SysDept> list1 = deptMapper.selectDeptByIds(sysDept);
|
|
@@ -220,73 +220,73 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
// deptList.addAll(list);
|
|
|
// }
|
|
|
// }
|
|
|
- List<SysDept> deptList = new ArrayList<>();
|
|
|
-
|
|
|
- if (roles.contains(1) || roles.contains(2)) {
|
|
|
- deptList = deptMapper.selectDeptList(sysDept);
|
|
|
- } else {
|
|
|
- SysDeptRelation sysDeptRelation = new SysDeptRelation();
|
|
|
- sysDeptRelation.setAncestor(SecurityUtils.getUser().getDeptId());
|
|
|
- List<SysDeptRelation> sysDeptRelationList = sysDeptRelationMapper.selectDeptRelationsList(sysDeptRelation);
|
|
|
- List<Integer> ids = sysDeptRelationList.stream().map(p -> p.getDescendant()).collect(Collectors.toList());
|
|
|
- for (Integer id : ids) {
|
|
|
- SysDept sysDept1 = new SysDept();
|
|
|
- sysDept1.setDeptId(id);
|
|
|
- SysDept sysDept2 = this.getById(sysDept1.getDeptId());
|
|
|
-
|
|
|
- if (null != sysDept2) {
|
|
|
- deptList.add(sysDept2);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 权限内部门
|
|
|
- final boolean[] isFisrt = {true};
|
|
|
- List<DeptTree> collect = deptList.stream().filter(dept -> dept.getDeptId().intValue() > 0)
|
|
|
- .sorted(Comparator.comparingInt(SysDept::getSort)).map(dept -> {
|
|
|
- DeptTree node = new DeptTree();
|
|
|
- node.setId(dept.getDeptId());
|
|
|
-
|
|
|
- if (isFisrt[0]) {
|
|
|
+ List<SysDept> deptList = new ArrayList<>();
|
|
|
+
|
|
|
+ if (roles.contains(1) || roles.contains(2)) {
|
|
|
+ deptList = deptMapper.selectDeptList(sysDept);
|
|
|
+ } else {
|
|
|
+ SysDeptRelation sysDeptRelation = new SysDeptRelation();
|
|
|
+ sysDeptRelation.setAncestor(SecurityUtils.getUser().getDeptId());
|
|
|
+ List<SysDeptRelation> sysDeptRelationList = sysDeptRelationMapper.selectDeptRelationsList(sysDeptRelation);
|
|
|
+ List<Integer> ids = sysDeptRelationList.stream().map(p -> p.getDescendant()).collect(Collectors.toList());
|
|
|
+ for (Integer id : ids) {
|
|
|
+ SysDept sysDept1 = new SysDept();
|
|
|
+ sysDept1.setDeptId(id);
|
|
|
+ SysDept sysDept2 = this.getById(sysDept1.getDeptId());
|
|
|
+
|
|
|
+ if (null != sysDept2) {
|
|
|
+ deptList.add(sysDept2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 权限内部门
|
|
|
+ final boolean[] isFisrt = {true};
|
|
|
+ List<DeptTree> collect = deptList.stream().filter(dept -> dept.getDeptId().intValue() > 0)
|
|
|
+ .sorted(Comparator.comparingInt(SysDept::getSort)).map(dept -> {
|
|
|
+ DeptTree node = new DeptTree();
|
|
|
+ node.setId(dept.getDeptId());
|
|
|
+
|
|
|
+ if (isFisrt[0]) {
|
|
|
// node.setParentId(dept.getAncestor());
|
|
|
- isFisrt[0] = false;
|
|
|
- } else {
|
|
|
+ isFisrt[0] = false;
|
|
|
+ } else {
|
|
|
// node.setParentId(dept.getAncestor());
|
|
|
- }
|
|
|
- node.setName(dept.getName());
|
|
|
+ }
|
|
|
+ node.setName(dept.getName());
|
|
|
|
|
|
- // 有权限不返回标识
|
|
|
+ // 有权限不返回标识
|
|
|
// if (deptList.contains(dept.getDeptId())) {
|
|
|
// node.setIsLock(Boolean.FALSE);
|
|
|
// }
|
|
|
- return node;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- return TreeUtil.build(collect, 0);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询全部部门树
|
|
|
- *
|
|
|
- * @return 树
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<DeptTree> selectTree(SysDept sysDept) {
|
|
|
- List<SysDept> deptList = deptMapper.selectDeptList(sysDept);
|
|
|
-
|
|
|
- List<DeptTree> collect = deptList.stream().filter(dept -> dept.getDeptId().intValue() > 0)
|
|
|
- .sorted(Comparator.comparingInt(SysDept::getSort)).map(dept -> {
|
|
|
- DeptTree node = new DeptTree();
|
|
|
- node.setId(dept.getDeptId());
|
|
|
+ return node;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return TreeUtil.build(collect, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询全部部门树
|
|
|
+ *
|
|
|
+ * @return 树
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<DeptTree> selectTree(SysDept sysDept) {
|
|
|
+ List<SysDept> deptList = deptMapper.selectDeptList(sysDept);
|
|
|
+
|
|
|
+ List<DeptTree> collect = deptList.stream().filter(dept -> dept.getDeptId().intValue() > 0)
|
|
|
+ .sorted(Comparator.comparingInt(SysDept::getSort)).map(dept -> {
|
|
|
+ DeptTree node = new DeptTree();
|
|
|
+ node.setId(dept.getDeptId());
|
|
|
// node.setParentId(dept.getParentId());
|
|
|
- node.setName(dept.getName());
|
|
|
+ node.setName(dept.getName());
|
|
|
|
|
|
- // 有权限不返回标识
|
|
|
- if (deptList.contains(dept.getDeptId())) {
|
|
|
- node.setIsLock(Boolean.FALSE);
|
|
|
- }
|
|
|
- return node;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- return TreeUtil.build(collect, 0);
|
|
|
+ // 有权限不返回标识
|
|
|
+ if (deptList.contains(dept.getDeptId())) {
|
|
|
+ node.setIsLock(Boolean.FALSE);
|
|
|
+ }
|
|
|
+ return node;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return TreeUtil.build(collect, 0);
|
|
|
|
|
|
|
|
|
// List<Integer> roles=SecurityUtils.getRoles();
|
|
@@ -436,115 +436,115 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
// }).collect(Collectors.toList());
|
|
|
// return TreeUtil.build(collect, 0);
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询所有关联服务企业
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<SysDept> getAllParentDept(SysDept sysDept) {
|
|
|
- List<SysDept> deptList = deptMapper.getAllParentDept(sysDept);
|
|
|
- //一个机构同时是一级cso和二级cso时,可以自己给自己发包
|
|
|
- Map<Integer, SysDept> partsMap = deptList.stream().collect(
|
|
|
- Collectors.toMap(SysDept::getLevel, Function.identity(), (dto1, dto2) -> dto1));
|
|
|
- //没有药企,有一级cso和二级cso时,这个时候不返回二级cso
|
|
|
- if ((!partsMap.containsKey(2)) && partsMap.containsKey(3) && partsMap.containsKey(4)) {
|
|
|
- deptList.remove(partsMap.get(4));
|
|
|
- }
|
|
|
- //二级CSO只展示上级一级CSO
|
|
|
- if (partsMap.containsKey(2) && partsMap.containsKey(3) && partsMap.containsKey(4)) {
|
|
|
- SysDept sysDept1 = this.getById(SecurityUtils.getUser().getDeptId());
|
|
|
- if (sysDept1.getLevel() == 4) {
|
|
|
- deptList.remove(partsMap.get(2));
|
|
|
- }
|
|
|
- }
|
|
|
- return deptList;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String selectEntCodeByLevelId(long levelId, int level) {
|
|
|
- return deptMapper.selectEntCodeByLevelId(levelId, level);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 分页查询药企和CSO代理商
|
|
|
- *
|
|
|
- * @param page 分页参数
|
|
|
- * @param deptName 部门名称
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Map<String, Object> listEntAndAgent(Page page, String deptName) {
|
|
|
- // 药企wrapper
|
|
|
- LambdaQueryWrapper<SysDept> entWrapper = Wrappers.lambdaQuery();
|
|
|
- entWrapper.eq(SysDept::getDelFlag, DelEnum.NOT_DEL.val());
|
|
|
- entWrapper.eq(SysDept::getLevel, DeptLevelEnum.ENT.getVal());
|
|
|
- if (StringUtils.isNotBlank(deptName)) {
|
|
|
- entWrapper.like(SysDept::getName, deptName);
|
|
|
- }
|
|
|
-
|
|
|
- // CSO wrapper
|
|
|
- LambdaQueryWrapper<SysDept> csoWrapper = Wrappers.lambdaQuery();
|
|
|
- csoWrapper.eq(SysDept::getDelFlag, DelEnum.NOT_DEL.val());
|
|
|
- csoWrapper.in(SysDept::getLevel, DeptLevelEnum.CSO_L1.getVal(), DeptLevelEnum.CSO_L2.getVal());
|
|
|
- if (StringUtils.isNotBlank(deptName)) {
|
|
|
- csoWrapper.like(SysDept::getName, deptName);
|
|
|
- }
|
|
|
-
|
|
|
- if (SecurityUtils.getRoles().contains(19)) {
|
|
|
- // CSM只能查看自己维护的企业下的用户, 以及下属维护的企业下的用户
|
|
|
- Integer userId = SecurityUtils.getUser().getId();
|
|
|
- // 递归查询下属关联的userId
|
|
|
- Set<Integer> allUserIds = sysCsmUserRelationService.recurseCsmLowerUserId(Collections.singleton(userId), new AtomicInteger(10));
|
|
|
- // 查询企业id
|
|
|
- List<SysDeptCsm> deptCsms = sysDeptCsmMapper.selectList(Wrappers.<SysDeptCsm>lambdaQuery()
|
|
|
- .in(SysDeptCsm::getUserId, allUserIds));
|
|
|
- if (CollUtil.isEmpty(deptCsms)) {
|
|
|
- return new HashMap<>();
|
|
|
- }
|
|
|
-
|
|
|
- Set<Integer> deptIds = deptCsms.stream().map(SysDeptCsm::getDeptId).collect(Collectors.toSet());
|
|
|
- entWrapper.in(SysDept::getDeptId, deptIds);
|
|
|
- csoWrapper.in(SysDept::getDeptId, deptIds);
|
|
|
- }
|
|
|
-
|
|
|
- Page<SysDept> entPage = this.page(page, entWrapper);
|
|
|
- List<Map<String, Object>> entMapList = entPage.getRecords().stream().map(sysDept -> {
|
|
|
- Map<String, Object> deptMap = MapUtil.newHashMap(2);
|
|
|
- deptMap.put("deptId", sysDept.getDeptId());
|
|
|
- deptMap.put("name", sysDept.getName());
|
|
|
- return deptMap;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- Page<Map<String, Object>> entHnqzPage = BeanUtil.copyProperties(entPage, Page.class);
|
|
|
- entHnqzPage.setRecords(entMapList);
|
|
|
-
|
|
|
- // CSO
|
|
|
- Page<SysDept> csoPage = this.page(page, csoWrapper);
|
|
|
- List<Map<String, Object>> csoMapList = csoPage.getRecords().stream().map(sysDept -> {
|
|
|
- Map<String, Object> deptMap = MapUtil.newHashMap(2);
|
|
|
- deptMap.put("deptId", sysDept.getDeptId());
|
|
|
- deptMap.put("name", sysDept.getName());
|
|
|
- return deptMap;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- Page<Map<String, Object>> csoHnqzPage = BeanUtil.copyProperties(entPage, Page.class);
|
|
|
- csoHnqzPage.setRecords(csoMapList);
|
|
|
-
|
|
|
- Map<String, Object> resultMap = MapUtil.newHashMap(2);
|
|
|
- resultMap.put("entPage", new HnqzPage<>(entHnqzPage));
|
|
|
- resultMap.put("csoPage", new HnqzPage<>(csoHnqzPage));
|
|
|
- return resultMap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取分页
|
|
|
- *
|
|
|
- * @param entName 企业名称
|
|
|
- * @param page 分页参数
|
|
|
- * @return 翻页结果
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Page<SysEnterpriseRelationVO> pageEntRels(Page<SysEnterpriseRelationVO> page, String entName) {
|
|
|
- return this.baseMapper.pageEntRels(page, entName);
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询所有关联服务企业
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<SysDept> getAllParentDept(SysDept sysDept) {
|
|
|
+ List<SysDept> deptList = deptMapper.getAllParentDept(sysDept);
|
|
|
+ //一个机构同时是一级cso和二级cso时,可以自己给自己发包
|
|
|
+ Map<Integer, SysDept> partsMap = deptList.stream().collect(
|
|
|
+ Collectors.toMap(SysDept::getLevel, Function.identity(), (dto1, dto2) -> dto1));
|
|
|
+ //没有药企,有一级cso和二级cso时,这个时候不返回二级cso
|
|
|
+ if ((!partsMap.containsKey(2)) && partsMap.containsKey(3) && partsMap.containsKey(4)) {
|
|
|
+ deptList.remove(partsMap.get(4));
|
|
|
+ }
|
|
|
+ //二级CSO只展示上级一级CSO
|
|
|
+ if (partsMap.containsKey(2) && partsMap.containsKey(3) && partsMap.containsKey(4)) {
|
|
|
+ SysDept sysDept1 = this.getById(SecurityUtils.getUser().getDeptId());
|
|
|
+ if (sysDept1.getLevel() == 4) {
|
|
|
+ deptList.remove(partsMap.get(2));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return deptList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String selectEntCodeByLevelId(long levelId, int level) {
|
|
|
+ return deptMapper.selectEntCodeByLevelId(levelId, level);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询药企和CSO代理商
|
|
|
+ *
|
|
|
+ * @param page 分页参数
|
|
|
+ * @param deptName 部门名称
|
|
|
+ * @return 分页集合
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> listEntAndAgent(Page<SysDept> page, String deptName) {
|
|
|
+ // 药企wrapper
|
|
|
+ LambdaQueryWrapper<SysDept> entWrapper = Wrappers.lambdaQuery();
|
|
|
+ entWrapper.eq(SysDept::getDelFlag, DelEnum.NOT_DEL.val());
|
|
|
+ entWrapper.eq(SysDept::getLevel, DeptLevelEnum.ENT.getVal());
|
|
|
+ if (StringUtils.isNotBlank(deptName)) {
|
|
|
+ entWrapper.like(SysDept::getName, deptName);
|
|
|
+ }
|
|
|
+
|
|
|
+ // CSO wrapper
|
|
|
+ LambdaQueryWrapper<SysDept> csoWrapper = Wrappers.lambdaQuery();
|
|
|
+ csoWrapper.eq(SysDept::getDelFlag, DelEnum.NOT_DEL.val());
|
|
|
+ csoWrapper.in(SysDept::getLevel, DeptLevelEnum.CSO_L1.getVal(), DeptLevelEnum.CSO_L2.getVal());
|
|
|
+ if (StringUtils.isNotBlank(deptName)) {
|
|
|
+ csoWrapper.like(SysDept::getName, deptName);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (SecurityUtils.getRoles().contains(19)) {
|
|
|
+ // CSM只能查看自己维护的企业下的用户, 以及下属维护的企业下的用户
|
|
|
+ Integer userId = SecurityUtils.getUser().getId();
|
|
|
+ // 递归查询下属关联的userId
|
|
|
+ Set<Integer> allUserIds = sysCsmUserRelationService.recurseCsmLowerUserId(Collections.singleton(userId), new AtomicInteger(10));
|
|
|
+ // 查询企业id
|
|
|
+ List<SysDeptCsm> deptCsms = sysDeptCsmMapper.selectList(Wrappers.<SysDeptCsm>lambdaQuery()
|
|
|
+ .in(SysDeptCsm::getUserId, allUserIds));
|
|
|
+ if (CollUtil.isEmpty(deptCsms)) {
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Integer> deptIds = deptCsms.stream().map(SysDeptCsm::getDeptId).collect(Collectors.toSet());
|
|
|
+ entWrapper.in(SysDept::getDeptId, deptIds);
|
|
|
+ csoWrapper.in(SysDept::getDeptId, deptIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<SysDept> entPage = this.page(page, entWrapper);
|
|
|
+ List<Map<String, Object>> entMapList = entPage.getRecords().stream().map(sysDept -> {
|
|
|
+ Map<String, Object> deptMap = MapUtil.newHashMap(2);
|
|
|
+ deptMap.put("deptId", sysDept.getDeptId());
|
|
|
+ deptMap.put("name", sysDept.getName());
|
|
|
+ return deptMap;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ Page<Map<String, Object>> entHnqzPage = BeanUtil.copyProperties(entPage, Page.class);
|
|
|
+ entHnqzPage.setRecords(entMapList);
|
|
|
+
|
|
|
+ // CSO
|
|
|
+ Page<SysDept> csoPage = this.page(page, csoWrapper);
|
|
|
+ List<Map<String, Object>> csoMapList = csoPage.getRecords().stream().map(sysDept -> {
|
|
|
+ Map<String, Object> deptMap = MapUtil.newHashMap(2);
|
|
|
+ deptMap.put("deptId", sysDept.getDeptId());
|
|
|
+ deptMap.put("name", sysDept.getName());
|
|
|
+ return deptMap;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ Page<Map<String, Object>> csoHnqzPage = BeanUtil.copyProperties(entPage, Page.class);
|
|
|
+ csoHnqzPage.setRecords(csoMapList);
|
|
|
+
|
|
|
+ Map<String, Object> resultMap = MapUtil.newHashMap(2);
|
|
|
+ resultMap.put("entPage", new HnqzPage<>(entHnqzPage));
|
|
|
+ resultMap.put("csoPage", new HnqzPage<>(csoHnqzPage));
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取分页
|
|
|
+ *
|
|
|
+ * @param entName 企业名称
|
|
|
+ * @param page 分页参数
|
|
|
+ * @return 翻页结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<SysEnterpriseRelationVO> pageEntRels(Page<SysEnterpriseRelationVO> page, String entName) {
|
|
|
+ return this.baseMapper.pageEntRels(page, entName);
|
|
|
+ }
|
|
|
}
|