From d729d924aff31c769b90adc99d998d38cdf50ec0 Mon Sep 17 00:00:00 2001
From: liyanqi <15181887205@163.com>
Date: 星期五, 09 九月 2022 22:06:33 +0800
Subject: [PATCH] 修复一些问题

---
 ycl-common/src/main/java/com/ycl/service/depart/impl/SccgDepartServiceImpl.java |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 55 insertions(+), 1 deletions(-)

diff --git a/ycl-common/src/main/java/com/ycl/service/depart/impl/SccgDepartServiceImpl.java b/ycl-common/src/main/java/com/ycl/service/depart/impl/SccgDepartServiceImpl.java
index 7243c24..8b4e019 100644
--- a/ycl-common/src/main/java/com/ycl/service/depart/impl/SccgDepartServiceImpl.java
+++ b/ycl-common/src/main/java/com/ycl/service/depart/impl/SccgDepartServiceImpl.java
@@ -1,15 +1,25 @@
 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.BasePageDTO;
 import com.ycl.api.CommonResult;
+import com.ycl.dto.user.AdminDepartDTO;
 import com.ycl.entity.depart.SccgDepart;
+import com.ycl.entity.user.UmsAdminDepart;
 import com.ycl.enums.common.ResultCode;
 import com.ycl.exception.ApiException;
 import com.ycl.mapper.depart.SccgDepartMapper;
+import com.ycl.mapper.user.UmsAdminDepartMapper;
 import com.ycl.service.depart.SccgDepartService;
+import com.ycl.service.user.UmsAdminDepartService;
+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;
@@ -31,6 +41,10 @@
 public class SccgDepartServiceImpl extends ServiceImpl<SccgDepartMapper, SccgDepart> implements SccgDepartService {
     @Resource
     private SccgDepartMapper sccgDepartMapper;
+    @Resource
+    private UmsAdminDepartService umsAdminDepartService;
+    @Resource
+    private UmsAdminService umsAdminService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -63,16 +77,28 @@
             throw new ApiException(ResultCode.RECORD_ALREADY_EXISTS);
         }
         BeanUtils.copyProperties(updateDepartVO, sccgDepart);
+        List<Long> userIds = updateDepartVO.getUserIds();
+        if (CollUtil.isNotEmpty(userIds)) {
+            Long departId = updateDepartVO.getId();
+            userIds.forEach(e -> {
+                UmsAdminDepart adminDepart = new UmsAdminDepart();
+                adminDepart.setDepartId(departId);
+                adminDepart.setUserId(e);
+                umsAdminDepartService.save(adminDepart);
+            });
+        }
         if (sccgDepartMapper.updateById(sccgDepart) <= 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
@@ -96,7 +122,33 @@
 
     @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<UmsAdminDepart> 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
@@ -107,6 +159,7 @@
             throw new ApiException(ResultCode.RECORD_UPDATE_FAIL);
         }
     }
+
 
     /**
      * 鍒╃敤閫掑綊灏嗘渶鍚庝竴绾х┖闆嗗悎鍙樹负null锛屽墠绔仈绾ч�夋嫨鍣ㄦ渶鍚庢墠涓嶄細鍑虹幇 鏆傛棤鏁版嵁鐨刡ug
@@ -156,4 +209,5 @@
         SccgDepart sccgDepart = this.sccgDepartMapper.selectOne(queryWrapper);
         return sccgDepart;
     }
+
 }

--
Gitblit v1.8.0