| | |
| | | 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.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.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.stream.Collectors; |
| | | |
| | |
| | | @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()); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @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; |
| | | } |
| | | |
| | | } |
| | | } |