| | |
| | | package com.ycl.service.depart.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.ycl.dto.user.AdminDepartDTO; |
| | | import com.ycl.dto.UmsDepartDto; |
| | | import com.ycl.entity.depart.UmsDepart; |
| | | import com.ycl.entity.dict.DataDictionary; |
| | | import com.ycl.entity.user.UmsDepartManage; |
| | | import com.ycl.entity.user.UmsAdmin; |
| | | import com.ycl.enums.common.ResultCode; |
| | | import com.ycl.exception.ApiException; |
| | | import com.ycl.mapper.depart.UmsDepartMapper; |
| | | import com.ycl.mapper.dict.DataDictionaryMapper; |
| | | import com.ycl.service.depart.IDepartManagerService; |
| | | import com.ycl.service.depart.UmsDepartService; |
| | | import com.ycl.service.user.UmsAdminService; |
| | | import com.ycl.service.user.UmsDepartManageService; |
| | | import com.ycl.utils.common.PojoUtils; |
| | | import com.ycl.vo.depart.DepartVO; |
| | | import com.ycl.vo.depart.UmsDepartVO; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | IDepartManagerService iDepartManagerService; |
| | | @Resource |
| | | UmsDepartService umsDepartService; |
| | | @Resource |
| | | DataDictionaryMapper dataDictionaryMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(DepartVO.UpdateDepartVO updateDepartVO) { |
| | | UmsDepart sccgDepart = this.queryByName(updateDepartVO.getDepartName()); |
| | | if (null != sccgDepart && sccgDepart.getId() != updateDepartVO.getId()) { |
| | | if (null != sccgDepart && !sccgDepart.getId().equals(updateDepartVO.getId())) { |
| | | throw new ApiException(ResultCode.RECORD_ALREADY_EXISTS); |
| | | } |
| | | UmsDepart depart = this.getById(updateDepartVO.getId()); |
| | | UmsDepart depart = new UmsDepart(); |
| | | BeanUtils.copyProperties(updateDepartVO, depart); |
| | | List<Long> userIds = updateDepartVO.getUserIds(); |
| | | if (CollUtil.isNotEmpty(userIds)) { |
| | | Long departId = updateDepartVO.getId(); |
| | | List<UmsDepartManage> departList = umsAdminDepartService.queryByDepartId(departId); |
| | | if (CollUtil.isNotEmpty(departList)) { |
| | | umsAdminDepartService.deletedByDepartId(departId); |
| | | } |
| | | userIds.forEach(e -> { |
| | | UmsDepartManage adminDepart = new UmsDepartManage(); |
| | | adminDepart.setDepartId(departId); |
| | | adminDepart.setUserId(e); |
| | | umsAdminDepartService.save(adminDepart); |
| | | }); |
| | | } |
| | | if (sccgDepartMapper.updateById(depart) != 1) { |
| | | throw new ApiException(ResultCode.RECORD_UPDATE_FAIL); |
| | | umsDepartService.updateById(depart); |
| | | if (updateDepartVO.getDepartManagerList().size() > 0) { |
| | | iDepartManagerService.deleteByDepartId(depart.getId()); |
| | | updateDepartVO.getDepartManagerList() |
| | | .forEach(item -> { |
| | | item.setCreateTime(LocalDateTime.now()); |
| | | item.setDepartId(depart.getId()); |
| | | }); |
| | | iDepartManagerService.saveBatch(updateDepartVO.getDepartManagerList()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | // 2.组装成父子的树型结构 |
| | | // 2.1、找到所有的一级网格:使用jdk8的stream流进行过滤 |
| | | List<UmsDepart> collect = list.stream().filter(griddingEntity -> { |
| | | List<UmsDepart> collect = list.stream().filter(item -> |
| | | //分类父id为0就表示该网格为 一级网格 |
| | | return griddingEntity.getParentId() == 0; |
| | | }).map(item -> { |
| | | item.getParentId() == 0 |
| | | ).map(item -> { |
| | | // 找到子网格 set进children属性中 |
| | | item.setChildren(getChildrens(item, list)); |
| | | return item; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<UmsDepartDto> departExp() { |
| | | List<UmsDepart> umsDeparts = sccgDepartMapper.selectDepartList(); |
| | | List<UmsDepartDto> res = umsDeparts |
| | | .stream() |
| | | .map(item -> { |
| | | UmsDepartDto umsDepartDto = new UmsDepartDto(); |
| | | umsDepartDto.setId(item.getId()); |
| | | umsDepartDto.setDepartTypeName(item.getDepartName()); |
| | | String departType = sccgDepartMapper.getDepartType(item.getDepartType()); |
| | | umsDepartDto.setDepartType(departType); |
| | | UmsDepart umsDepartFather = sccgDepartMapper.selectOne(new LambdaQueryWrapper<UmsDepart>().eq(UmsDepart::getId, item.getParentId())); |
| | | if (Objects.isNull(umsDepartFather)){ |
| | | umsDepartDto.setParentDepartName(""); |
| | | }else { |
| | | umsDepartDto.setParentDepartName(umsDepartFather.getDepartName()); |
| | | } |
| | | umsDepartDto.setDepartDes(item.getDepartDes()); |
| | | return umsDepartDto; |
| | | }).collect(Collectors.toList()); |
| | | return res; |
| | | } |
| | | |
| | | @Override |
| | | public void updateStatus(DepartVO.StatusDepartVO params) { |
| | | UmsDepart sccgDepart = this.loadDepartById(params.getId()); |
| | | BeanUtils.copyProperties(params, sccgDepart); |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<UmsAdmin> selectSurplusUser() { |
| | | return sccgDepartMapper.selectSurplusUser(); |
| | | } |
| | | |
| | | @Override |
| | | public List<UmsAdmin> selectSurplusUserAndExistUser(Long id) { |
| | | return sccgDepartMapper.selectSurplusUserAndExistUser(id); |
| | | } |
| | | |
| | | /** |
| | | * 利用递归将最后一级空集合变为null,前端联级选择器最后才不会出现 暂无数据的bug |
| | |
| | | UmsDepart sccgDepart = this.sccgDepartMapper.selectOne(queryWrapper); |
| | | return sccgDepart; |
| | | } |
| | | |
| | | } |
| | | } |