From 53e7dce8d55487cbac64e4374ec9aa1b52a6c6ed Mon Sep 17 00:00:00 2001
From: SZH <szh_hello@163.com>
Date: Thu, 09 Mar 2023 21:16:43 +0800
Subject: [PATCH] 解决npe问题
---
equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java | 94 ++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 92 insertions(+), 2 deletions(-)
diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java
index c4a001d..d7ec1ce 100644
--- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java
+++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java
@@ -1,12 +1,20 @@
package com.gkhy.safePlatform.equipment.service.impl;
+import cn.hutool.core.util.IdUtil;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
+import com.gkhy.safePlatform.commons.query.PageQuery;
+import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import com.gkhy.safePlatform.commons.vo.ResultVO;
+import com.gkhy.safePlatform.commons.vo.SearchResultVO;
import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyDO;
import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyInfo;
+import com.gkhy.safePlatform.equipment.enums.ConsumableEnum;
import com.gkhy.safePlatform.equipment.enums.EquipmentResultCodes;
import com.gkhy.safePlatform.equipment.excepiton.EquipmentException;
+import com.gkhy.safePlatform.equipment.model.dto.req.MaterialClassifyQuery;
+import com.gkhy.safePlatform.equipment.model.dto.req.ParamForm;
import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyAddReq;
import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyModReq;
import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialClassifyDto;
@@ -38,6 +46,7 @@
.stream()
.filter(item -> item.getParentId().equals(0l))
.collect(Collectors.toList());
+
List<SafeMaterialClassifyDto> respDTOList = new ArrayList<>();
//只有二级不采用递归
for (SafeMaterialClassifyInfo classifyInfo:parentList) {
@@ -54,6 +63,10 @@
SafeMaterialClassifyDto childDTO = new SafeMaterialClassifyDto();
childDTO.setId(child.getId());
childDTO.setMaterialClassifyName(child.getMaterialClassifyName());
+ if(null != child.getConsumable()){
+ childDTO.setConsumableName(ConsumableEnum.getByCode(child.getConsumable()).getValue());
+ }
+ childDTO.setConsumable(child.getConsumable());
childDTO.setParentId(child.getParentId());
childDTOList.add(childDTO);
}
@@ -67,14 +80,25 @@
@Override
public ResultVO save(ContextCacheUser currentUser, SafeMaterialClassifyAddReq req) {
ResultVO resultVO = null;
+ if(null != req.getParentId()){
+ if(null == req.getConsumable()){
+ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"是否耗材未选择");
+ }
+ if(null == ConsumableEnum.getByCode(req.getConsumable())){
+ throw new EquipmentException(EquipmentResultCodes.DATA_ILLEGAL);
+ }
+ }
SafeMaterialClassifyInfo classifyInfo = new SafeMaterialClassifyInfo();
+ classifyInfo.setId(IdUtil.getSnowflake(0,0).nextId());
classifyInfo.setMaterialClassifyName(req.getMaterialClassifyName());
+ classifyInfo.setConsumable(req.getConsumable());
if(null != req.getParentId()){
classifyInfo.setParentId(req.getParentId());
}else{
classifyInfo.setParentId(0l);
}
+
boolean flag = safeMaterialClassifyInfoService.save(classifyInfo);
if (flag){
resultVO = new ResultVO(ResultCodes.OK);
@@ -90,8 +114,19 @@
if(req.getId() == null){
throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
}
+ SafeMaterialClassifyInfo safeMaterialClassifyInfo = safeMaterialClassifyInfoService.queryById(req.getId());
+ if(safeMaterialClassifyInfo.getParentId() != 0 ){
+ if(null == req.getConsumable()){
+ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"是否耗材未选择");
+ }
+ if(null == ConsumableEnum.getByCode(req.getConsumable())){
+ throw new EquipmentException(EquipmentResultCodes.DATA_ILLEGAL);
+ }
+ }
+
SafeMaterialClassifyInfo classifyInfo = new SafeMaterialClassifyInfo();
classifyInfo.setMaterialClassifyName(req.getMaterialClassifyName());
+ classifyInfo.setConsumable(req.getConsumable());
classifyInfo.setId(req.getId());
boolean flag = safeMaterialClassifyInfoService.updateById(classifyInfo);
if (flag){
@@ -103,7 +138,7 @@
}
@Override
- public ResultVO delete(Long id) {
+ public ResultVO delete(ContextCacheUser currentUser,Long id) {
if(id == null){
throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
}
@@ -133,7 +168,7 @@
}
@Override
- public SafeMaterialClassifyDto queryById(Long id) {
+ public SafeMaterialClassifyDto queryById(ContextCacheUser currentUser,Long id) {
if(id == null){
throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
}
@@ -149,12 +184,18 @@
respDTO.setId(classifyInfo.getId());
respDTO.setMaterialClassifyName(classifyInfo.getMaterialClassifyName());
respDTO.setParentId(classifyInfo.getParentId());
+ respDTO.setConsumable(classifyInfo.getConsumable());
+ respDTO.setConsumableName(ConsumableEnum.getByCode(classifyInfo.getConsumable()).getValue());
List<SafeMaterialClassifyDto> childDtoList = new ArrayList<>();
for (SafeMaterialClassifyInfo child:childList){
SafeMaterialClassifyDto childDto = new SafeMaterialClassifyDto();
childDto.setId(child.getId());
childDto.setMaterialClassifyName(child.getMaterialClassifyName());
childDto.setParentId(child.getParentId());
+ childDto.setConsumable(child.getConsumable());
+ if(null != child.getConsumable()){
+ childDto.setConsumableName(ConsumableEnum.getByCode(child.getConsumable()).getValue());
+ }
childDtoList.add(childDto);
}
respDTO.setChildList(childDtoList);
@@ -200,5 +241,54 @@
return safeMaterialClassifyInfoService.getTraceabilityClassifyList(smallClassifyIds);
}
+ @Override
+ public SearchResultVO<List<SafeMaterialClassifyDto>> listByPage(ContextCacheUser currentUser,PageQuery<MaterialClassifyQuery> pageQuery) {
+ Page<SafeMaterialClassifyInfo> page = new Page<>(pageQuery.getPageIndex(),pageQuery.getPageSize());
+ List<SafeMaterialClassifyInfo> parentList = safeMaterialClassifyInfoService.listByPage(page, pageQuery.getSearchParams());
+ List<SafeMaterialClassifyInfo> childList = new ArrayList<>();
+ if(!CollectionUtils.isEmpty(parentList)){
+ List<Long> parentIdList = parentList.stream().map(SafeMaterialClassifyInfo::getId).collect(Collectors.toList());
+ childList = safeMaterialClassifyInfoService.getListByParentIds(parentIdList);
+ }
+
+ List<SafeMaterialClassifyDto> respList = new ArrayList<>();
+ for(SafeMaterialClassifyInfo parentClassify:parentList){
+ SafeMaterialClassifyDto classifyDto = new SafeMaterialClassifyDto();
+ classifyDto.setId(parentClassify.getId());
+ classifyDto.setMaterialClassifyName(parentClassify.getMaterialClassifyName());
+ classifyDto.setParentId(parentClassify.getParentId());
+
+ //获取子级
+ List<SafeMaterialClassifyInfo> selectList = childList
+ .stream()
+ .filter(cl -> cl.getParentId().equals(parentClassify.getId()))
+ .collect(Collectors.toList());
+
+ List<SafeMaterialClassifyDto> childRespList = new ArrayList<>();
+ for(SafeMaterialClassifyInfo child:selectList){
+ SafeMaterialClassifyDto childClassify = new SafeMaterialClassifyDto();
+ childClassify.setId(child.getId());
+ childClassify.setMaterialClassifyName(child.getMaterialClassifyName());
+ childClassify.setParentId(child.getParentId());
+ childClassify.setConsumable(child.getConsumable());
+ if(null != child.getConsumable()){
+ childClassify.setConsumableName(ConsumableEnum.getByCode(child.getConsumable()).getValue());
+ }
+ childRespList.add(childClassify);
+ }
+ classifyDto.setChildList(childRespList);
+ respList.add(classifyDto);
+ }
+ return new SearchResultVO<>(true,
+ page.getCurrent(),
+ page.getSize(),
+ page.getPages(),
+ page.getTotal(),
+ respList,
+ ResultCodes.OK);
+ }
+
+
+
}
--
Gitblit v1.9.2