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