| | |
| | | package cn.huge.module.ctuser.service; |
| | | |
| | | import cn.huge.base.common.dto.SelectTermDTO; |
| | | import cn.huge.base.common.exception.ServiceException; |
| | | import cn.huge.base.common.utils.DateUtils; |
| | | import cn.huge.base.common.utils.IdUtils; |
| | | import cn.huge.base.common.utils.ObjectUtils; |
| | | import cn.huge.base.common.utils.SelectTermUtils; |
| | | import cn.huge.module.client.api.impl.UtilsClientImpl; |
| | | import cn.huge.module.constant.BaseConsts; |
| | | import cn.huge.module.ctuser.dao.mapper.CtUnitMapper; |
| | | import cn.huge.module.ctuser.domain.po.CtDept; |
| | | import cn.huge.module.ctuser.domain.po.CtUnit; |
| | | import cn.huge.module.ctuser.domain.po.CtUser; |
| | | import cn.huge.module.ctuser.domain.po.CtUserole; |
| | | import cn.huge.module.ctuser.dto.CtUnitWeChatCountDTO; |
| | | import cn.huge.module.cust.constant.RoleBaseEnum; |
| | | import cn.huge.module.cust.dto.CtUserDTO; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | |
| | | ctUnitWeChatCountDTO.setTzUnitNum(tzUnitNum); |
| | | return ctUnitWeChatCountDTO; |
| | | } |
| | | |
| | | /** |
| | | * 按条件分页查询 |
| | | * |
| | | * @param userId 分页对象 |
| | | * @return Page |
| | | */ |
| | | public List<SelectTermDTO> unitChoose(String userId) { |
| | | // 获取当前登录用户 |
| | | CtUserDTO loginUser = ctUserService.clientGetUserAll(userId); |
| | | // 组织条件 |
| | | List<CtUnit> ctUnitList = mapper.listAllChild(loginUser.getUnitId()); |
| | | List<SelectTermDTO> unitSelectTerms = new ArrayList<>(); |
| | | |
| | | List<String> unitIdList= ctUnitList.stream().map(CtUnit::getId).collect(Collectors.toList()); |
| | | // 部门条件 |
| | | QueryWrapper<CtDept> ctDeptQueryWrapper = new QueryWrapper<>(); |
| | | ctDeptQueryWrapper.in("unit_id", unitIdList).select("id", "unit_id", "name", "parent_id"); |
| | | List<CtDept> ctDeptList = ctDeptService.list(ctDeptQueryWrapper); |
| | | List<String> deptIdList = ctDeptList.stream().map(CtDept::getId).collect(Collectors.toList()); |
| | | |
| | | for(CtUnit ctUnit: ctUnitList){ |
| | | SelectTermDTO unitSelectTerm = new SelectTermDTO(); |
| | | unitSelectTerm.setValue(ctUnit.getId()); |
| | | unitSelectTerm.setLabel(ctUnit.getUnitName()); |
| | | unitSelectTerm.setParentId(ctUnit.getParentId()); |
| | | unitSelectTerm.setCheckable(true); |
| | | List<SelectTermDTO> deptSelectTerms = new ArrayList<>(); |
| | | for(CtDept ctDept : ctDeptList){ |
| | | if(ctUnit.getId().equals(ctDept.getUnitId())){ |
| | | SelectTermDTO deptSelectTerm = new SelectTermDTO(); |
| | | deptSelectTerm.setValue(ctDept.getId()); |
| | | deptSelectTerm.setLabel(ctDept.getName()); |
| | | deptSelectTerm.setParentId(ctDept.getParentId()); |
| | | deptSelectTerm.setCheckable(true); |
| | | |
| | | deptSelectTerms.add(deptSelectTerm); |
| | | } |
| | | List<SelectTermDTO> depts = SelectTermUtils.createTreeByRoot(deptSelectTerms); |
| | | unitSelectTerm.setChildren(depts); |
| | | } |
| | | unitSelectTerms.add(unitSelectTerm); |
| | | } |
| | | return SelectTermUtils.createTreeByFirst(unitSelectTerms, loginUser.getUnitId()); |
| | | } |
| | | } |