From c128ed33c2447e8daea89d70795098748bd5b2af Mon Sep 17 00:00:00 2001
From: zhangfeng <1603559716@qq.com>
Date: Fri, 06 Jan 2023 10:53:27 +0800
Subject: [PATCH] 补充查询单条领取记录接口
---
equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java | 244 ++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 212 insertions(+), 32 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 b71a9eb..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,25 +1,35 @@
package com.gkhy.safePlatform.equipment.service.impl;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+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.utils.StringUtils;
+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.req.SafeMaterialClassifyQuery;
import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialClassifyDto;
+import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialClassifyStockDto;
import com.gkhy.safePlatform.equipment.service.MaterialClassifyService;
import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialClassifyInfoService;
import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialInfoService;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
@Service("MaterialClassifyService")
public class MaterialClassifyServiceImpl implements MaterialClassifyService {
@@ -29,25 +39,66 @@
private SafeMaterialInfoService safeMaterialInfoService;
@Override
- public ResultVO<List<SafeMaterialClassifyDto>> list(SafeMaterialClassifyQuery query) {
- List<SafeMaterialClassifyInfo> list = safeMaterialClassifyInfoService.listByCondition(query);
- List<SafeMaterialClassifyDto> respList = new ArrayList<>();
- if(!CollectionUtils.isEmpty(list)){
- for(SafeMaterialClassifyInfo classifyInfo : list){
- SafeMaterialClassifyDto respDTO = new SafeMaterialClassifyDto();
- respDTO.setId(classifyInfo.getId());
- respDTO.setMaterialClassifyName(classifyInfo.getMaterialClassifyName());
- respList.add(respDTO);
+ public List<SafeMaterialClassifyDto> list() {
+ List<SafeMaterialClassifyInfo> list = safeMaterialClassifyInfoService.list();
+ //过滤出父级
+ List<SafeMaterialClassifyInfo> parentList = list
+ .stream()
+ .filter(item -> item.getParentId().equals(0l))
+ .collect(Collectors.toList());
+
+ List<SafeMaterialClassifyDto> respDTOList = new ArrayList<>();
+ //只有二级不采用递归
+ for (SafeMaterialClassifyInfo classifyInfo:parentList) {
+ SafeMaterialClassifyDto respDTO = new SafeMaterialClassifyDto();
+ respDTO.setId(classifyInfo.getId());
+ respDTO.setMaterialClassifyName(classifyInfo.getMaterialClassifyName());
+ respDTO.setParentId(classifyInfo.getParentId());
+ List<SafeMaterialClassifyInfo> childList = list
+ .stream()
+ .filter(item -> item.getParentId().equals(classifyInfo.getId()))
+ .collect(Collectors.toList());
+ List<SafeMaterialClassifyDto> childDTOList = new ArrayList<>();
+ for (SafeMaterialClassifyInfo child:childList){
+ 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);
}
+ respDTO.setChildList(childDTOList);
+ respDTOList.add(respDTO);
}
- return new ResultVO<>(ResultCodes.OK,respList);
+
+ return respDTOList;
}
@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);
@@ -63,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){
@@ -76,39 +138,157 @@
}
@Override
- public ResultVO delete(Long id) {
+ public ResultVO delete(ContextCacheUser currentUser,Long id) {
if(id == null){
throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
}
- ResultVO resultVO = null;
- //判断是否被绑定
- int count = safeMaterialInfoService.getCountByClassify(id);
- if(count > 0){
- throw new EquipmentException(ResultCodes.SERVER_DEL_ERROR,"该类型已被绑定,不可删除!");
- }else{
- //如果没有被绑定,逻辑删除
- SafeMaterialClassifyInfo classifyInfo = new SafeMaterialClassifyInfo();
- classifyInfo.setId(id);
- classifyInfo.setDelFlag(1);
- boolean flag = safeMaterialClassifyInfoService.updateById(classifyInfo);
- if (flag){
- resultVO = new ResultVO(ResultCodes.OK);
- }else {
- resultVO = new ResultVO(ResultCodes.SERVER_DEL_ERROR);
+ SafeMaterialClassifyInfo classify = safeMaterialClassifyInfoService.queryById(id);
+ if(null == classify){
+ throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST);
+ }
+ if(0 == classify.getParentId()){//一级
+ List<SafeMaterialClassifyInfo> childrenList = safeMaterialClassifyInfoService.getListByParentId(id);
+ if (childrenList.size()>0){
+ throw new EquipmentException(ResultCodes.SERVER_DEL_ERROR,"改类型存在小类,不可删除!");
+ }
+ }else {//二级
+ //判断是否被绑定
+ int count = safeMaterialInfoService.getCountBySmallClassifyId(id);
+ if(count > 0){
+ throw new EquipmentException(ResultCodes.SERVER_DEL_ERROR,"该类型已被绑定,不可删除!");
}
}
- return resultVO;
+ //如果没有被绑定,逻辑删除
+ SafeMaterialClassifyInfo classifyInfo = new SafeMaterialClassifyInfo();
+ classifyInfo.setId(id);
+ classifyInfo.setDelFlag(1);
+ safeMaterialClassifyInfoService.updateById(classifyInfo);
+
+ return new ResultVO(ResultCodes.OK);
}
@Override
- public ResultVO<SafeMaterialClassifyDto> queryById(Long id) {
+ public SafeMaterialClassifyDto queryById(ContextCacheUser currentUser,Long id) {
if(id == null){
throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
}
SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(id);
+ if(null == classifyInfo){
+ throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST);
+ }
+ List<SafeMaterialClassifyInfo> childList = new ArrayList<>();
+ if(0l == classifyInfo.getParentId()){
+ childList = safeMaterialClassifyInfoService.getListByParentId(id);
+ }
SafeMaterialClassifyDto respDTO = new SafeMaterialClassifyDto();
respDTO.setId(classifyInfo.getId());
respDTO.setMaterialClassifyName(classifyInfo.getMaterialClassifyName());
- return new ResultVO<>(ResultCodes.OK,respDTO);
+ 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);
+ return respDTO;
}
+
+ /**
+ * 根据小类id获取大小类相关信息
+ * @param smallClassifyId
+ * @return
+ */
+ public SafeMaterialClassifyDO getBigAndSmallClassifyInfo(Long smallClassifyId){
+ if(null == smallClassifyId){
+ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
+ }
+ SafeMaterialClassifyDO classifyDO = safeMaterialClassifyInfoService.getBigAndSmallClassify(smallClassifyId);
+ return classifyDO;
+ }
+ /**
+ * 根据小类ids获取小类相关信息
+ * @param ids
+ * @return
+ */
+ public List<SafeMaterialClassifyDto> getClassifyListByIds(List<Long> ids){
+ if(CollectionUtils.isEmpty(ids)){
+ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
+ }
+ List<SafeMaterialClassifyInfo> list = safeMaterialClassifyInfoService.getClassifyListByIds(ids);
+ List<SafeMaterialClassifyDto> classifyDtoList = new ArrayList<>();
+ for (SafeMaterialClassifyInfo classifyInfo:list){
+ SafeMaterialClassifyDto classifyDto = new SafeMaterialClassifyDto();
+ BeanUtils.copyProperties(classifyInfo,classifyDto);
+ classifyDtoList.add(classifyDto);
+ }
+ return classifyDtoList;
+ }
+
+ @Override
+ public List<SafeMaterialClassifyDO> getTraceabilityClassifyList(List<Long> smallClassifyIds) {
+ if(CollectionUtils.isEmpty(smallClassifyIds)){
+ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
+ }
+ 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