| | |
| | | import cn.huge.base.common.utils.DateUtils; |
| | | import cn.huge.base.common.utils.IdUtils; |
| | | import cn.huge.module.client.api.impl.UtilsClientImpl; |
| | | import cn.huge.module.constant.BaseConsts; |
| | | import cn.huge.module.ctuser.dao.mapper.CtDeptMapper; |
| | | import cn.huge.module.ctuser.domain.po.CtDept; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | */ |
| | | public void saveCtDept(CtDept ctDept){ |
| | | try{ |
| | | Date nowDate = DateUtils.getMowDate(); |
| | | Date nowDate = DateUtils.getNowDate(); |
| | | // 判断是否新增 |
| | | if (IdUtils.checkNewId(ctDept.getId())){ |
| | | ctDept.setId(utilsClient.getNewTimeId()); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建某一级部门下树形结构 |
| | | * @param ctDeptList 所有部门集合 |
| | | * @param firstId 某一级组织编号 |
| | | * @return List |
| | | */ |
| | | public List<CtDept> createTree(List<CtDept> ctDeptList, String firstId) { |
| | | List<CtDept> firstMapList= new ArrayList<>(); |
| | | for (CtDept ctDept: ctDeptList ){ |
| | | for(CtDept deptParam: ctDeptList ) { |
| | | if (deptParam.getId().equals(ctDept.getParentId())) { |
| | | addToMBean(deptParam, ctDept); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | //取第一级节点 |
| | | for (CtDept dept: ctDeptList ){ |
| | | if (StringUtils.isNotEmpty(firstId)){ |
| | | if (firstId.equals(dept.getId())) { |
| | | firstMapList.add(dept); |
| | | } |
| | | }else{ |
| | | if (BaseConsts.ROOT.equals(dept.getParentId()) || StringUtils.isEmpty(dept.getParentId())) { |
| | | firstMapList.add(dept); |
| | | } |
| | | } |
| | | } |
| | | return firstMapList; |
| | | } |
| | | |
| | | /** |
| | | * 获取部门的子级部门 |
| | | * @param targetUnit 目标部门 |
| | | * @param currentUnit 子级部门 |
| | | */ |
| | | public void addToMBean(CtDept targetUnit, CtDept currentUnit){ |
| | | List<CtDept> childListObj = targetUnit.getChildren(); |
| | | List<CtDept> childList = null; |
| | | if(CollectionUtils.isEmpty(childListObj)) { |
| | | childList = new ArrayList(); |
| | | targetUnit.setChildren(childList); |
| | | }else{ |
| | | childList = childListObj; |
| | | } |
| | | childList.add(currentUnit); |
| | | } |
| | | } |