zhangfeng
2022-11-25 f600f38c6c23a282b61ed4db1b2da094d695276f
equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java
@@ -1,12 +1,17 @@
package com.gkhy.safePlatform.equipment.service.impl;
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.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.SafeMaterialClassifyAddReq;
import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyModReq;
import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialClassifyDto;
@@ -200,5 +205,38 @@
        return safeMaterialClassifyInfoService.getTraceabilityClassifyList(smallClassifyIds);
    }
    @Override
    public SearchResultVO<List<SafeMaterialClassifyDto>> listByPage(PageQuery<MaterialClassifyQuery> pageQuery) {
        Page<SafeMaterialClassifyInfo> page = new Page<>(pageQuery.getPageIndex(),pageQuery.getPageSize());
        List<SafeMaterialClassifyInfo> classifyInfoList = safeMaterialClassifyInfoService.listByPage(page, pageQuery.getSearchParams());
        List<SafeMaterialClassifyInfo> childList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(classifyInfoList)) {
            List<Long> parentIdList = classifyInfoList.stream().map(SafeMaterialClassifyInfo::getId).collect(Collectors.toList());
            childList = safeMaterialClassifyInfoService.getListByParentIds(parentIdList);
        }
        List<SafeMaterialClassifyDto> respList = new ArrayList<>();
        for(SafeMaterialClassifyInfo classifyInfo:classifyInfoList){
            SafeMaterialClassifyDto classifyDto = new SafeMaterialClassifyDto();
            classifyDto.setId(classifyInfo.getId());
            classifyDto.setMaterialClassifyName(classifyInfo.getMaterialClassifyName());
            classifyDto.setParentId(classifyInfo.getParentId());
            //获取子级
            List<SafeMaterialClassifyInfo> selectList = childList.stream().filter(cl -> cl.getParentId().equals(classifyInfo.getId())).collect(Collectors.toList());
            List<SafeMaterialClassifyDto> childRespList = new ArrayList<>();
            if(selectList.size()>0){
                childRespList = BeanCopyUtils.copyBeanList(selectList,SafeMaterialClassifyDto.class);
            }
            classifyDto.setChildList(childRespList);
            respList.add(classifyDto);
        }
        return new SearchResultVO<>(true,
                page.getCurrent(),
                page.getSize(),
                page.getPages(),
                page.getTotal(),
                respList,
                ResultCodes.OK);
    }
}