From 2bb74a9788cebce86bb386884a82bfe5b2a5a0fc Mon Sep 17 00:00:00 2001 From: WendyYang Date: Mon, 22 Apr 2024 17:07:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E9=97=A8=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/handler/GlobalExceptionHandler.java | 17 +++-- .../kqapi/zzsfw/manage/MatterManage.java | 84 +++++++++++----------- 2 files changed, 53 insertions(+), 48 deletions(-) diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/common/handler/GlobalExceptionHandler.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/common/handler/GlobalExceptionHandler.java index 3ff67e0..9387aef 100644 --- a/kq-vas-api/src/main/java/com/ningdatech/kqapi/common/handler/GlobalExceptionHandler.java +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/common/handler/GlobalExceptionHandler.java @@ -31,40 +31,49 @@ import java.util.stream.Collectors; @ResponseStatus(HttpStatus.BAD_REQUEST) public class GlobalExceptionHandler { + private static void printLog(Exception e) { + log.error("当前异常为:{}", e.getMessage(), e); + } + @ResponseBody @ExceptionHandler(value = NoHandlerFoundException.class) public ApiResponse noHandlerFoundException(NoHandlerFoundException e) { + printLog(e); return ApiResponse.ofStatus(Status.REQUEST_NOT_FOUND); } @ResponseBody @ExceptionHandler(value = {MethodArgumentNotValidException.class, BindException.class}) public ApiResponse bindException(BindException e) { + printLog(e); String msg = e.getAllErrors().stream() .map(DefaultMessageSourceResolvable::getDefaultMessage) .collect(Collectors.joining(",")); - return ApiResponse.of(Status.BAD_REQUEST.getCode(), msg, null); + return ApiResponse.of(Status.BAD_REQUEST.getCode(), msg); } @ResponseBody @ExceptionHandler(value = ConstraintViolationException.class) public ApiResponse constraintViolationException(ConstraintViolationException e) { + printLog(e); String msg = e.getConstraintViolations().stream() .map(ConstraintViolation::getMessage) .collect(Collectors.joining(",")); - return ApiResponse.of(Status.BAD_REQUEST.getCode(), msg, null); + return ApiResponse.of(Status.BAD_REQUEST.getCode(), msg); } @ResponseBody @ExceptionHandler(value = Exception.class) public ApiResponse handlerException(Exception e) { - return ApiResponse.of(Status.BAD_REQUEST.getCode(), e.getMessage(), null); + printLog(e); + return ApiResponse.of(Status.BAD_REQUEST.getCode(), e.getMessage()); } @ResponseBody @ExceptionHandler(value = BizException.class) public ApiResponse bizException(Exception e) { - return ApiResponse.of(Status.BAD_REQUEST.getCode(), e.getMessage(), null); + printLog(e); + return ApiResponse.of(Status.BAD_REQUEST.getCode(), e.getMessage()); } } diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/zzsfw/manage/MatterManage.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/zzsfw/manage/MatterManage.java index 3aca74c..99860eb 100644 --- a/kq-vas-api/src/main/java/com/ningdatech/kqapi/zzsfw/manage/MatterManage.java +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/zzsfw/manage/MatterManage.java @@ -5,14 +5,14 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ningdatech.kqapi.zzsfw.constants.ZzsfwMenuConstant; +import com.ningdatech.kqapi.zzsfw.enumeration.ItemTypeEnum; import com.ningdatech.kqapi.zzsfw.model.dto.KqZzsfwMattersDeduplicateDTO; import com.ningdatech.kqapi.zzsfw.model.dto.KqZzsfwMenuDTO; -import com.ningdatech.kqapi.zzsfw.model.entity.KqZzsfwMenu; import com.ningdatech.kqapi.zzsfw.model.entity.KqZzsfwMattersDeduplicate; +import com.ningdatech.kqapi.zzsfw.model.entity.KqZzsfwMenu; import com.ningdatech.kqapi.zzsfw.model.vo.MatterTopVO; import com.ningdatech.kqapi.zzsfw.model.vo.MattersVO; import com.ningdatech.kqapi.zzsfw.model.vo.TreeVO; -import com.ningdatech.kqapi.zzsfw.enumeration.ItemTypeEnum; import com.ningdatech.kqapi.zzsfw.service.IKqZzsfwMatterDeduplicateService; import com.ningdatech.kqapi.zzsfw.service.IKqZzsfwMenuService; import lombok.RequiredArgsConstructor; @@ -64,13 +64,13 @@ public class MatterManage { public List getMatters() { List matters = menuService.list(Wrappers.lambdaQuery(KqZzsfwMenu.class) .orderByAsc(KqZzsfwMenu::getSort)); - if(CollUtil.isEmpty(matters)){ + if (CollUtil.isEmpty(matters)) { return Collections.emptyList(); } //如果是政府类型的 就隐藏 没有链接的 List finalMatters = matters.stream().filter(m -> Objects.nonNull(m.getType()) && - (!m.getType().equals(ItemTypeEnum.GOV.getCode()) || Objects.nonNull(m.getWebapplyurl()))) + (!m.getType().equals(ItemTypeEnum.GOV.getCode()) || Objects.nonNull(m.getWebapplyurl()))) .collect(Collectors.toList()); Set zoneSet = new HashSet<>(); List res = finalMatters.stream().filter(m -> zoneSet.add(m.getZoneName())).map(m -> { @@ -85,12 +85,13 @@ public class MatterManage { /** * 查询社区 + * * @return */ public List getZones() { List matters = menuService.list(Wrappers.lambdaQuery(KqZzsfwMenu.class) .orderByAsc(KqZzsfwMenu::getSort)); - if(CollUtil.isEmpty(matters)){ + if (CollUtil.isEmpty(matters)) { return Collections.emptyList(); } @@ -109,9 +110,9 @@ public class MatterManage { public List getWindows(String zoneName) { List matters = menuService.list(Wrappers.lambdaQuery(KqZzsfwMenu.class) - .eq(StringUtils.isNotBlank(zoneName), KqZzsfwMenu::getZoneName,zoneName) + .eq(StringUtils.isNotBlank(zoneName), KqZzsfwMenu::getZoneName, zoneName) .orderByAsc(KqZzsfwMenu::getSort)); - if(CollUtil.isEmpty(matters)){ + if (CollUtil.isEmpty(matters)) { return Collections.emptyList(); } @@ -130,22 +131,20 @@ public class MatterManage { }).collect(Collectors.toList()); } - public List getDepartments(String zoneName,String windowName) { + public List getDepartments(String zoneName, String windowName) { List matters = menuService.list(Wrappers.lambdaQuery(KqZzsfwMenu.class) - .select(KqZzsfwMenu::getDepartment,KqZzsfwMenu::getType,KqZzsfwMenu::getWebapplyurl) - .eq(StringUtils.isNotBlank(windowName), KqZzsfwMenu::getWindow,windowName) - .eq(StringUtils.isNotBlank(zoneName), KqZzsfwMenu::getZoneName,zoneName) + .select(KqZzsfwMenu::getDepartment, KqZzsfwMenu::getType, KqZzsfwMenu::getWebapplyurl) + .eq(StringUtils.isNotBlank(windowName), KqZzsfwMenu::getWindow, windowName) + .eq(StringUtils.isNotBlank(zoneName), KqZzsfwMenu::getZoneName, zoneName) + .isNotNull(KqZzsfwMenu::getDepartment) .orderByAsc(KqZzsfwMenu::getSort)); - if(CollUtil.isEmpty(matters)){ + if (CollUtil.isEmpty(matters)) { return Collections.emptyList(); } - - List finalMatters = matters.stream().filter(m -> Objects.nonNull(m.getType()) && - (!m.getType().equals(ItemTypeEnum.GOV.getCode()) || Objects.nonNull(m.getWebapplyurl()))) - .collect(Collectors.toList()); - Set departMentSet = new HashSet<>(); - return finalMatters.stream().filter(m -> departMentSet.add(m.getDepartment())) + return matters.stream() + .filter(m -> m.getType() != null && (!ItemTypeEnum.GOV.eq(m.getType()) || m.getWebapplyurl() != null)) + .filter(m -> departMentSet.add(m.getDepartment())) .map(m -> { TreeVO department = new TreeVO(); department.setName(m.getDepartment()); @@ -156,33 +155,29 @@ public class MatterManage { public List matterList(String zoneName, String windowName, String department, Integer type) { List matters = menuService.list(Wrappers.lambdaQuery(KqZzsfwMenu.class) - .eq(StringUtils.isNotBlank(windowName), KqZzsfwMenu::getWindow,windowName) - .eq(StringUtils.isNotBlank(zoneName), KqZzsfwMenu::getZoneName,zoneName) - .eq(StringUtils.isNotBlank(department), KqZzsfwMenu::getDepartment,department) - .eq(Objects.nonNull(type), KqZzsfwMenu::getType,type) + .eq(StringUtils.isNotBlank(windowName), KqZzsfwMenu::getWindow, windowName) + .eq(StringUtils.isNotBlank(zoneName), KqZzsfwMenu::getZoneName, zoneName) + .eq(StringUtils.isNotBlank(department), KqZzsfwMenu::getDepartment, department) + .eq(Objects.nonNull(type), KqZzsfwMenu::getType, type) .orderByAsc(KqZzsfwMenu::getSort)); - if(CollUtil.isEmpty(matters)){ + if (CollUtil.isEmpty(matters)) { return Collections.emptyList(); } //如果是政府类型的 就隐藏 没有链接的 - List finalMatters = matters.stream().filter(m -> Objects.nonNull(m.getType()) && - (!m.getType().equals(ItemTypeEnum.GOV.getCode()) || Objects.nonNull(m.getWebapplyurl()))) - .collect(Collectors.toList()); - - return finalMatters.stream() + return matters.stream().filter(m -> Objects.nonNull(m.getType()) + && (!ItemTypeEnum.GOV.eq(m.getType()) || Objects.nonNull(m.getWebapplyurl()))) .map(m -> { MattersVO mattersVO = BeanUtil.copyProperties(m, MattersVO.class); mattersVO.setMatterName(m.getItemName()); mattersVO.setId(m.getId()); return mattersVO; - }) - .collect(Collectors.toList()); + }).collect(Collectors.toList()); } public MattersVO matter(Long id) { KqZzsfwMenu matter = menuService.getById(id); - if(Objects.isNull(matter)){ + if (Objects.isNull(matter)) { return null; } MattersVO mattersVO = BeanUtil.copyProperties(matter, MattersVO.class); @@ -194,11 +189,11 @@ public class MatterManage { private List generateWindows(KqZzsfwMenu menu, List matters) { Set windowSet = new HashSet<>(); return matters.stream().filter(m -> StringUtils.isNotBlank(m.getZoneName()) && m.getZoneName().equals(menu.getZoneName()) - && windowSet.add(m.getWindow())) + && windowSet.add(m.getWindow())) .map(m -> { TreeVO window = new TreeVO(); window.setName(m.getWindow()); - window.setChilren(generateDepartment(m,matters)); + window.setChilren(generateDepartment(m, matters)); window.setType(ZzsfwMenuConstant.MENU_TYPE_WINDOW); return window; }).collect(Collectors.toList()); @@ -206,12 +201,12 @@ public class MatterManage { private List generateDepartment(KqZzsfwMenu menu, List matters) { Set departmentSet = new HashSet<>(); - return matters.stream().filter( m -> StringUtils.isNotBlank(m.getWindow()) && m.getWindow().equals(menu.getWindow()) && + return matters.stream().filter(m -> StringUtils.isNotBlank(m.getWindow()) && m.getWindow().equals(menu.getWindow()) && m.getZoneName().equals(menu.getZoneName()) && departmentSet.add(m.getDepartment())) .map(m -> { TreeVO department = new TreeVO(); department.setName(m.getDepartment()); - department.setChilren(generateItemType(m,matters)); + department.setChilren(generateItemType(m, matters)); department.setType(ZzsfwMenuConstant.MENU_TYPE_DEPARTMENT); return department; }).collect(Collectors.toList()); @@ -224,9 +219,9 @@ public class MatterManage { .map(m -> { TreeVO menuType = new TreeVO(); ItemTypeEnum itemTypeEnum = ItemTypeEnum.match(m.getType()); - if(Objects.nonNull(itemTypeEnum)){ + if (Objects.nonNull(itemTypeEnum)) { menuType.setName(itemTypeEnum.getDesc()); - menuType.setChilren(generateMatters(m,matters)); + menuType.setChilren(generateMatters(m, matters)); menuType.setType(ZzsfwMenuConstant.MENU_ITEM_TYPE); return menuType; } @@ -270,27 +265,27 @@ public class MatterManage { } public String save(KqZzsfwMenuDTO dto) { - if(Objects.isNull(dto)){ + if (Objects.isNull(dto)) { return "保存失败 传入为空"; } KqZzsfwMenu entity = BeanUtil.copyProperties(dto, KqZzsfwMenu.class); - if(menuService.save(entity)){ + if (menuService.save(entity)) { return "保存成功 :" + entity; - }else{ + } else { return "保存失败"; } } public String saveDup(KqZzsfwMattersDeduplicateDTO dto) { - if(Objects.isNull(dto)){ + if (Objects.isNull(dto)) { return "保存失败 传入为空"; } KqZzsfwMattersDeduplicate entity = BeanUtil.copyProperties(dto, KqZzsfwMattersDeduplicate.class); - if(matterDeduplicateService.save(entity)){ + if (matterDeduplicateService.save(entity)) { return "保存成功 :" + entity; - }else{ + } else { return "保存失败"; } } @@ -390,13 +385,14 @@ public class MatterManage { /** * 4-10 数据问题 + * * @return */ public String update4_10() { //1.窗口后缀不是服务的 都加个服务 List list = menuService.list(); for (KqZzsfwMenu menu : list) { - if(StringUtils.isNotBlank(menu.getWindow()) && !menu.getWindow().endsWith("服务")){ + if (StringUtils.isNotBlank(menu.getWindow()) && !menu.getWindow().endsWith("服务")) { menu.setWindow(menu.getWindow() + "服务"); menuService.updateById(menu); }