| | |
| | | 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.api.CommonResult; |
| | | import com.ycl.dto.user.AdminDepartDTO; |
| | | import com.ycl.entity.depart.SccgDepart; |
| | | import com.ycl.entity.user.UmsDepartManage; |
| | | import com.ycl.enums.common.ResultCode; |
| | | import com.ycl.exception.ApiException; |
| | | import com.ycl.mapper.depart.SccgDepartMapper; |
| | | import com.ycl.service.depart.SccgDepartService; |
| | | import com.ycl.service.user.UmsDepartManageService; |
| | | import com.ycl.service.user.UmsAdminService; |
| | | import com.ycl.utils.common.PojoUtils; |
| | | import com.ycl.vo.depart.DepartVO; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.xml.transform.Result; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | public class SccgDepartServiceImpl extends ServiceImpl<SccgDepartMapper, SccgDepart> implements SccgDepartService { |
| | | @Resource |
| | | private SccgDepartMapper sccgDepartMapper; |
| | | @Resource |
| | | private UmsDepartManageService umsAdminDepartService; |
| | | @Resource |
| | | private UmsAdminService umsAdminService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | if (null != sccgDepart && sccgDepart.getId() != updateDepartVO.getId()) { |
| | | throw new ApiException(ResultCode.RECORD_ALREADY_EXISTS); |
| | | } |
| | | BeanUtils.copyProperties(updateDepartVO, sccgDepart); |
| | | if (sccgDepartMapper.updateById(sccgDepart) <= 0) { |
| | | SccgDepart depart = this.getById(updateDepartVO.getId()); |
| | | 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) <= 0) { |
| | | throw new ApiException(ResultCode.RECORD_UPDATE_FAIL); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void delete(long id) { |
| | | if (sccgDepartMapper.deleteById(id) <= 0) { |
| | | throw new ApiException(ResultCode.RECORD_DELETE_FAIL); |
| | | } |
| | | umsAdminDepartService.deletedByDepartId(id); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public IPage<SccgDepart> pageDepart(DepartVO.PageDepartVO params) { |
| | | return null; |
| | | Page<SccgDepart> page = new Page<>(params.getCurrent(), params.getPageSize()); |
| | | LambdaQueryWrapper<SccgDepart> query = new LambdaQueryWrapper<>(); |
| | | if (StringUtils.isNotBlank(params.getDepartName())) { |
| | | query.like(SccgDepart::getDepartName, params.getDepartName()); |
| | | } |
| | | if (PojoUtils.Vo.isUsefulSearchParam(params.getDepartType())) { |
| | | query.like(SccgDepart::getDepartType, params.getDepartType()); |
| | | } |
| | | query.orderByDesc(SccgDepart::getCreateTime); |
| | | Page<SccgDepart> departPage = sccgDepartMapper.selectPage(page, query); |
| | | List<SccgDepart> records = departPage.getRecords(); |
| | | //负责人 |
| | | if (CollUtil.isNotEmpty(records)) { |
| | | for (SccgDepart record : records) { |
| | | List<UmsDepartManage> umsAdminDeparts = umsAdminDepartService.queryByDepartId(record.getId()); |
| | | if (CollUtil.isNotEmpty(umsAdminDeparts)) { |
| | | List<AdminDepartDTO.UserInfoDTO> userInfoDTOS = umsAdminDeparts.stream().map(a -> { |
| | | AdminDepartDTO.UserInfoDTO userInfoDTO = new AdminDepartDTO.UserInfoDTO(); |
| | | userInfoDTO.setUserId(a.getUserId()); |
| | | userInfoDTO.setUsername(umsAdminService.getById(a.getUserId()).getUsername()); |
| | | return userInfoDTO; |
| | | }).collect(Collectors.toList()); |
| | | record.setUserInfoDTOS(userInfoDTOS); |
| | | } |
| | | } |
| | | } |
| | | return departPage; |
| | | } |
| | | |
| | | @Override |
| | |
| | | throw new ApiException(ResultCode.RECORD_UPDATE_FAIL); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 利用递归将最后一级空集合变为null,前端联级选择器最后才不会出现 暂无数据的bug |
| | |
| | | SccgDepart sccgDepart = this.sccgDepartMapper.selectOne(queryWrapper); |
| | | return sccgDepart; |
| | | } |
| | | |
| | | } |