From de08816b368eec8500cf92f7e18ec9d297e3c38d Mon Sep 17 00:00:00 2001 From: huangzj <826100833@qq.com> Date: Wed, 11 Jan 2023 10:48:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9F=A5=E8=AF=A2=E6=8C=A1?= =?UTF-8?q?=E5=A2=99=E9=83=A8=E9=97=A8=E7=9B=B4=E5=B1=9E=E4=B8=8B=E7=BA=A7?= =?UTF-8?q?=E9=83=A8=E9=97=A8(=E6=B2=A1=E6=9C=89=E4=B8=8B=E7=BA=A7?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E8=BF=94=E5=9B=9E=E5=BD=93=E5=89=8D=E9=83=A8?= =?UTF-8?q?=E9=97=A8)=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/njcn/user/api/DeptFeignClient.java | 14 +++++++- .../DeptFeignClientFallbackFactory.java | 6 ++++ .../njcn/user/controller/DeptController.java | 15 ++++++++ .../com/njcn/user/service/IDeptService.java | 10 ++++-- .../user/service/impl/DeptServiceImpl.java | 35 +++++++++++++++++-- 5 files changed, 75 insertions(+), 5 deletions(-) diff --git a/pqs-user/user-api/src/main/java/com/njcn/user/api/DeptFeignClient.java b/pqs-user/user-api/src/main/java/com/njcn/user/api/DeptFeignClient.java index 359ebbb4f..58ab46ad1 100644 --- a/pqs-user/user-api/src/main/java/com/njcn/user/api/DeptFeignClient.java +++ b/pqs-user/user-api/src/main/java/com/njcn/user/api/DeptFeignClient.java @@ -18,7 +18,9 @@ import java.util.List; * @date 2022/1/11 * 部门相关业务对外接口 */ -@FeignClient(value = ServerInfo.USER, path = "/dept", fallbackFactory = DeptFeignClientFallbackFactory.class) +@FeignClient(value = ServerInfo.USER, +// url = "http://127.0.0.1:10201", + path = "/dept", fallbackFactory = DeptFeignClientFallbackFactory.class) public interface DeptFeignClient { /** @@ -103,4 +105,14 @@ public interface DeptFeignClient { */ @GetMapping("/getRootDept") HttpResult getRootDept(); + + /** + * @Description: 获取当前部门的的下级子部门list,如果没子部门就是返回当前部门 + * @Param: [deptId] + * @return: com.njcn.common.pojo.response.HttpResult> + * @Author: clam + * @Date: 2023/1/10 + */ + @GetMapping("/getDepSonDetailIdByDeptId") + HttpResult> getDepSonDetailByDeptId(@RequestParam("deptId")String deptId) ; } diff --git a/pqs-user/user-api/src/main/java/com/njcn/user/api/fallback/DeptFeignClientFallbackFactory.java b/pqs-user/user-api/src/main/java/com/njcn/user/api/fallback/DeptFeignClientFallbackFactory.java index 11c48ade5..b0aa7fa8a 100644 --- a/pqs-user/user-api/src/main/java/com/njcn/user/api/fallback/DeptFeignClientFallbackFactory.java +++ b/pqs-user/user-api/src/main/java/com/njcn/user/api/fallback/DeptFeignClientFallbackFactory.java @@ -111,6 +111,12 @@ public class DeptFeignClientFallbackFactory implements FallbackFactory> getDepSonDetailByDeptId(String deptId) { + log.error("{}异常,降级处理,异常为:{}","查询前部门的的下级子部门list,(如果没子部门就是返回当前部门)",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } }; } } + diff --git a/pqs-user/user-boot/src/main/java/com/njcn/user/controller/DeptController.java b/pqs-user/user-boot/src/main/java/com/njcn/user/controller/DeptController.java index 7ced83303..b2c01fbb0 100644 --- a/pqs-user/user-boot/src/main/java/com/njcn/user/controller/DeptController.java +++ b/pqs-user/user-boot/src/main/java/com/njcn/user/controller/DeptController.java @@ -392,6 +392,21 @@ public class DeptController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe); } } + /** + * @Description: "获取当前部门的的下级子部门list,如果没子部门就是返回当前部门 + * @Param: [deptId] + * @return: com.njcn.common.pojo.response.HttpResult> + * @Author: clam + * @Date: 2023/1/10 + */ + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @GetMapping("/getDepSonDetailIdByDeptId") + @ApiOperation("获取当前部门的的下级子部门list,如果没子部门就是返回当前部门") + public HttpResult> getDepSonDetailByDeptId(@RequestParam("deptId")String deptId) { + String methodDescribe = getMethodDescribe("getDepSonDetailByDeptId"); + List deptList = deptService.getDepSonDetailByDeptId(deptId); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, deptList, methodDescribe); + } diff --git a/pqs-user/user-boot/src/main/java/com/njcn/user/service/IDeptService.java b/pqs-user/user-boot/src/main/java/com/njcn/user/service/IDeptService.java index 87d9d08e8..954a8d0d6 100644 --- a/pqs-user/user-boot/src/main/java/com/njcn/user/service/IDeptService.java +++ b/pqs-user/user-boot/src/main/java/com/njcn/user/service/IDeptService.java @@ -2,7 +2,6 @@ package com.njcn.user.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; -import com.njcn.common.pojo.response.HttpResult; import com.njcn.system.pojo.dto.AreaTreeDTO; import com.njcn.user.pojo.dto.DeptDTO; import com.njcn.user.pojo.param.DeptParam; @@ -11,7 +10,6 @@ import com.njcn.user.pojo.vo.DeptAllTreeVO; import com.njcn.user.pojo.vo.DeptTreeVO; import com.njcn.user.pojo.vo.DeptVO; import com.njcn.user.pojo.vo.PvTerminalTreeVO; -import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -200,4 +198,12 @@ public interface IDeptService extends IService { * @date 2023/1/6 */ Dept getRootDept(); + /** + * @Description: 获取当前部门的的下级子部门list,如果没子部门就是返回当前部门 + * @Param: [deptId] + * @return: java.util.List + * @Author: clam + * @Date: 2023/1/10 + */ + List getDepSonDetailByDeptId(String deptId); } diff --git a/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/DeptServiceImpl.java b/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/DeptServiceImpl.java index e1268cec1..62a6d8045 100644 --- a/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/DeptServiceImpl.java +++ b/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/DeptServiceImpl.java @@ -1,12 +1,12 @@ package com.njcn.user.service.impl; import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.common.pojo.enums.common.DataStateEnum; import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.response.HttpResult; @@ -27,13 +27,14 @@ import com.njcn.user.pojo.vo.DeptTreeVO; import com.njcn.user.pojo.vo.DeptVO; import com.njcn.user.pojo.vo.PvTerminalTreeVO; import com.njcn.user.service.IDeptService; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.web.factory.PageFactory; import com.njcn.web.utils.RequestUtil; import com.njcn.web.utils.WebUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.List; @@ -371,4 +372,34 @@ public class DeptServiceImpl extends ServiceImpl implements ID lambdaQueryWrapper.eq(Dept::getState,DataStateEnum.ENABLE.getCode()).eq(Dept::getPid,0); return this.getOne(lambdaQueryWrapper); } + + /** + * @param deptId + * @Description: "获取当前部门的的下级子部门list,如果没子部门就是返回当前部门 + * @Param: [deptId] + * @return: java.util.List + * @Author: clam + * @Date: 2023/1/10 + */ + @Override + public List getDepSonDetailByDeptId(String deptId) { + List result = new ArrayList<> (); + + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq (Dept::getPid, deptId). + eq (Dept::getState,DataStateEnum.ENABLE.getCode()); + result = this.baseMapper.selectList (lambdaQueryWrapper); + if(CollectionUtils.isEmpty (result)){ + LambdaQueryWrapper deptLambdaQueryWrapper = new LambdaQueryWrapper<>(); + deptLambdaQueryWrapper.eq (Dept::getId, deptId). + eq (Dept::getState,DataStateEnum.ENABLE.getCode()); + result = this.baseMapper.selectList (deptLambdaQueryWrapper); + } + List collect = result.stream ( ).map (temp -> { + DeptDTO deptDTO = new DeptDTO ( ); + BeanUtils.copyProperties (temp, deptDTO); + return deptDTO; + }).collect (Collectors.toList ( )); + return collect; + } }