File was renamed from ycl-common/src/main/java/com/ycl/service/depart/impl/SccgDepartServiceImpl.java |
| | |
| | | package com.ycl.service.depart.impl; |
| | | package com.ycl.service.platform.depart.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | |
| | | 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.SccgDepart; |
| | | import com.ycl.entity.user.UmsDepartManage; |
| | | import com.ycl.entity.platform.depart.UmsDepart; |
| | | import com.ycl.entity.platform.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.mapper.platform.depart.UmsDepartMapper; |
| | | import com.ycl.service.platform.depart.UmsDepartService; |
| | | import com.ycl.service.platform.user.UmsDepartManageService; |
| | | import com.ycl.service.platform.user.UmsAdminService; |
| | | import com.ycl.utils.common.PojoUtils; |
| | | import com.ycl.vo.depart.DepartVO; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | * @since 2022-09-07 |
| | | */ |
| | | @Service |
| | | public class SccgDepartServiceImpl extends ServiceImpl<SccgDepartMapper, SccgDepart> implements SccgDepartService { |
| | | public class UmsDepartServiceImpl extends ServiceImpl<UmsDepartMapper, UmsDepart> implements UmsDepartService { |
| | | @Resource |
| | | private SccgDepartMapper sccgDepartMapper; |
| | | private UmsDepartMapper sccgDepartMapper; |
| | | @Resource |
| | | private UmsDepartManageService umsAdminDepartService; |
| | | @Resource |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void create(DepartVO.AddDepartVO addDepartVO) { |
| | | SccgDepart sccgDepart = this.queryByName(addDepartVO.getDepartName()); |
| | | UmsDepart sccgDepart = this.queryByName(addDepartVO.getDepartName()); |
| | | if (null != sccgDepart) { |
| | | throw new ApiException(ResultCode.RECORD_ALREADY_EXISTS); |
| | | } |
| | | SccgDepart depart = new SccgDepart(); |
| | | UmsDepart depart = new UmsDepart(); |
| | | BeanUtils.copyProperties(addDepartVO, depart); |
| | | if (sccgDepartMapper.insert(depart) <= 0) { |
| | | throw new ApiException(ResultCode.RECORD_SAVE_FAIL); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public SccgDepart loadDepartById(long id) { |
| | | SccgDepart sccgDepart = sccgDepartMapper.selectById(id); |
| | | public UmsDepart loadDepartById(long id) { |
| | | UmsDepart sccgDepart = sccgDepartMapper.selectById(id); |
| | | if (null == sccgDepart) { |
| | | throw new ApiException(ResultCode.RECORD_NOT_EXISTS); |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(DepartVO.UpdateDepartVO updateDepartVO) { |
| | | SccgDepart sccgDepart = this.queryByName(updateDepartVO.getDepartName()); |
| | | UmsDepart sccgDepart = this.queryByName(updateDepartVO.getDepartName()); |
| | | if (null != sccgDepart && sccgDepart.getId() != updateDepartVO.getId()) { |
| | | throw new ApiException(ResultCode.RECORD_ALREADY_EXISTS); |
| | | } |
| | | SccgDepart depart = this.getById(updateDepartVO.getId()); |
| | | UmsDepart depart = this.getById(updateDepartVO.getId()); |
| | | BeanUtils.copyProperties(updateDepartVO, depart); |
| | | List<Long> userIds = updateDepartVO.getUserIds(); |
| | | if (CollUtil.isNotEmpty(userIds)) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<SccgDepart> tree() { |
| | | public List<UmsDepart> tree() { |
| | | // 1.查出所有网格 |
| | | List<SccgDepart> list = list(); |
| | | List<UmsDepart> list = list(); |
| | | |
| | | // 2.组装成父子的树型结构 |
| | | // 2.1、找到所有的一级网格:使用jdk8的stream流进行过滤 |
| | | List<SccgDepart> collect = list.stream().filter(griddingEntity -> { |
| | | List<UmsDepart> collect = list.stream().filter(griddingEntity -> { |
| | | //分类父id为0就表示该网格为 一级网格 |
| | | return griddingEntity.getParentId() == 0; |
| | | }).map(item -> { |
| | |
| | | item.setChildren(getChildrens(item, list)); |
| | | return item; |
| | | }).collect(Collectors.toList()); |
| | | List<SccgDepart> treeData = getTreeData(collect); |
| | | List<UmsDepart> treeData = getTreeData(collect); |
| | | return treeData; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<SccgDepart> pageDepart(DepartVO.PageDepartVO params) { |
| | | Page<SccgDepart> page = new Page<>(params.getCurrent(), params.getPageSize()); |
| | | LambdaQueryWrapper<SccgDepart> query = new LambdaQueryWrapper<>(); |
| | | public IPage<UmsDepart> pageDepart(DepartVO.PageDepartVO params) { |
| | | Page<UmsDepart> page = new Page<>(params.getCurrent(), params.getPageSize()); |
| | | LambdaQueryWrapper<UmsDepart> query = new LambdaQueryWrapper<>(); |
| | | if (StringUtils.isNotBlank(params.getDepartName())) { |
| | | query.like(SccgDepart::getDepartName, params.getDepartName()); |
| | | query.like(UmsDepart::getDepartName, params.getDepartName()); |
| | | } |
| | | if (PojoUtils.Vo.isUsefulSearchParam(params.getDepartType())) { |
| | | query.like(SccgDepart::getDepartType, params.getDepartType()); |
| | | query.like(UmsDepart::getDepartType, params.getDepartType()); |
| | | } |
| | | query.orderByDesc(SccgDepart::getCreateTime); |
| | | Page<SccgDepart> departPage = sccgDepartMapper.selectPage(page, query); |
| | | List<SccgDepart> records = departPage.getRecords(); |
| | | query.orderByDesc(UmsDepart::getCreateTime); |
| | | Page<UmsDepart> departPage = sccgDepartMapper.selectPage(page, query); |
| | | List<UmsDepart> records = departPage.getRecords(); |
| | | //负责人 |
| | | if (CollUtil.isNotEmpty(records)) { |
| | | for (SccgDepart record : records) { |
| | | for (UmsDepart record : records) { |
| | | List<UmsDepartManage> umsAdminDeparts = umsAdminDepartService.queryByDepartId(record.getId()); |
| | | if (CollUtil.isNotEmpty(umsAdminDeparts)) { |
| | | List<AdminDepartDTO.UserInfoDTO> userInfoDTOS = umsAdminDeparts.stream().map(a -> { |
| | |
| | | |
| | | @Override |
| | | public void updateStatus(DepartVO.StatusDepartVO params) { |
| | | SccgDepart sccgDepart = this.loadDepartById(params.getId()); |
| | | UmsDepart sccgDepart = this.loadDepartById(params.getId()); |
| | | BeanUtils.copyProperties(params, sccgDepart); |
| | | if (sccgDepartMapper.updateById(sccgDepart) <= 0) { |
| | | throw new ApiException(ResultCode.RECORD_UPDATE_FAIL); |
| | |
| | | * |
| | | * @return |
| | | */ |
| | | public List<SccgDepart> getTreeData(List<SccgDepart> griddingEntities) { |
| | | public List<UmsDepart> getTreeData(List<UmsDepart> griddingEntities) { |
| | | for (int i = 0; i < griddingEntities.size(); i++) { |
| | | //如果Children的size小于1就说明为空,设置为null |
| | | if (griddingEntities.get(i).getChildren().size() < 1) { |
| | |
| | | * @param all 所有网格 |
| | | * @return |
| | | */ |
| | | public List<SccgDepart> getChildrens(SccgDepart root, List<SccgDepart> all) { |
| | | List<SccgDepart> collect = all.stream().filter(griddingEntity -> { |
| | | public List<UmsDepart> getChildrens(UmsDepart root, List<UmsDepart> all) { |
| | | List<UmsDepart> collect = all.stream().filter(griddingEntity -> { |
| | | return griddingEntity.getParentId().equals(root.getId()); |
| | | }).map(item -> { |
| | | item.setChildren(getChildrens(item, all)); |
| | |
| | | * @param name |
| | | * @return |
| | | */ |
| | | private SccgDepart queryByName(String name) { |
| | | LambdaQueryWrapper<SccgDepart> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(SccgDepart::getDepartName, name); |
| | | SccgDepart sccgDepart = this.sccgDepartMapper.selectOne(queryWrapper); |
| | | private UmsDepart queryByName(String name) { |
| | | LambdaQueryWrapper<UmsDepart> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(UmsDepart::getDepartName, name); |
| | | UmsDepart sccgDepart = this.sccgDepartMapper.selectOne(queryWrapper); |
| | | return sccgDepart; |
| | | } |
| | | |