package com.gkhy.safePlatform.specialWork.service.impl;
|
|
import cn.hutool.core.util.IdUtil;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.gkhy.safePlatform.account.rpc.apimodel.AccountUserService;
|
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserInfoRPCRespDTO;
|
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
|
import com.gkhy.safePlatform.commons.enums.E;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.commons.exception.AusinessException;
|
import com.gkhy.safePlatform.commons.exception.BusinessException;
|
import com.gkhy.safePlatform.commons.query.PageQuery;
|
import com.gkhy.safePlatform.commons.vo.ResultVO;
|
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
|
import com.gkhy.safePlatform.emergency.rpc.api.EmergencyRpcAPi;
|
import com.gkhy.safePlatform.emergency.rpc.api.model.dto.resp.*;
|
import com.gkhy.safePlatform.equipment.rpc.api.EquipmentRpcAPi;
|
import com.gkhy.safePlatform.equipment.rpc.api.model.dto.req.MaterialReceiveRecordsRPCReq;
|
import com.gkhy.safePlatform.equipment.rpc.api.model.dto.resp.MaterialReceiveRecordsRPCRespDto;
|
import com.gkhy.safePlatform.equipment.rpc.api.model.dto.resp.SafeMaterialBsClassifyRPCRespDto;
|
import com.gkhy.safePlatform.equipment.rpc.api.model.dto.resp.SafeMaterialClassifyRPCRespDto;
|
import com.gkhy.safePlatform.equipment.rpc.api.model.dto.resp.SafeMaterialClassifyStockRPCRespDto;
|
import com.gkhy.safePlatform.specialWork.entity.MaterialAllocationBaseInfo;
|
import com.gkhy.safePlatform.specialWork.entity.MaterialDetailInfo;
|
import com.gkhy.safePlatform.specialWork.enums.*;
|
import com.gkhy.safePlatform.specialWork.model.dto.req.*;
|
import com.gkhy.safePlatform.specialWork.model.dto.resp.*;
|
import com.gkhy.safePlatform.specialWork.model.query.MaterialAllocationBaseQuery;
|
import com.gkhy.safePlatform.specialWork.service.MaterialAllocationBaseService;
|
import com.gkhy.safePlatform.specialWork.service.baseService.MaterialAllocationBaseInfoService;
|
import com.gkhy.safePlatform.specialWork.service.baseService.MaterialDetailInfoService;
|
import net.sf.jsqlparser.expression.StringValue;
|
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.list.PredicatedList;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.rocketmq.client.stat.ConsumerStatsManager;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
import java.util.stream.Stream;
|
|
@Service("MaterialAllocationBaseService")
|
public class MaterialAllocationBaseServiceImpl implements MaterialAllocationBaseService {
|
@DubboReference(check = false)
|
private EmergencyRpcAPi emergencyRpcAPi;
|
@DubboReference(check = false)
|
private EquipmentRpcAPi equipmentRpcAPi;
|
@DubboReference(check = false)
|
private AccountUserService accountUserService;
|
@Autowired
|
private MaterialAllocationBaseInfoService materialAllocationBaseInfoService;
|
|
@Autowired
|
private MaterialDetailInfoService materialDetailInfoService;
|
|
/**
|
* 新增
|
* @param currentUser
|
* @param addReqDTO
|
* @return
|
*/
|
@Transactional
|
@Override
|
public ResultVO save(ContextCacheUser currentUser, MaterialAllocationBaseAddReqDTO addReqDTO) {
|
|
if(null == WorkTypeEnum.parse(addReqDTO.getWorkType())){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"作业类型不合法!");
|
}
|
if(null != addReqDTO.getWorkLevel()){
|
if(null == WorkLevelEnum.parse(addReqDTO.getWorkLevel())){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"作业级别不合法!");
|
}
|
}
|
List<SafeMaterialBsClassifyRPCRespDto> classifyRPCRespDtoList = new ArrayList<>();
|
|
//验证数据
|
List<MaterialDetailAddReqDTO> materialDetailList = addReqDTO.getMaterialDetailList();
|
if(!CollectionUtils.isEmpty(materialDetailList)){
|
List<Long> smallClassifyIdList = materialDetailList
|
.stream().map(MaterialDetailAddReqDTO::getSmallClassifyId)
|
.collect(Collectors.toList());
|
classifyRPCRespDtoList = this.getTraceabilityClassifyList(smallClassifyIdList);
|
|
for (MaterialDetailAddReqDTO materialDetail : materialDetailList) {
|
|
if(null == materialDetail.getStandVal()){
|
throw new AusinessException(E.DATA_PARAM_NULL,"标准值不能为空!");
|
}
|
if(null == materialDetail.getConfigurationLevel()){
|
throw new AusinessException(E.DATA_PARAM_NULL,"配置级别不能为空!");
|
}
|
if(null == ConfigurationLevelEnum.parse(materialDetail.getConfigurationLevel())){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"配置级别不合法!");
|
}
|
if(null == materialDetail.getSmallClassifyId()){
|
throw new AusinessException(E.DATA_PARAM_NULL,"物资种类id不能为空!");
|
}
|
if(null != materialDetail.getConsumable()){
|
if(null == ConsumableEnum.getByCode(materialDetail.getConsumable())){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"是否是耗材数据校验不合法!");
|
}else{
|
if(ConsumableEnum.YES.getCode().equals(materialDetail.getConsumable())){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"耗材物资暂不支持物资配置!");
|
}
|
}
|
}
|
List<SafeMaterialBsClassifyRPCRespDto> selectList = classifyRPCRespDtoList
|
.stream()
|
.filter(classify -> classify.getSmallClassifyId().equals(materialDetail.getSmallClassifyId()))
|
.collect(Collectors.toList());
|
if(selectList.size() == 0){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"物资种类不存在");
|
}
|
|
}
|
}
|
|
//配置物资表数据
|
MaterialAllocationBaseInfo materialAllocationBaseInfo = new MaterialAllocationBaseInfo();
|
BeanUtils.copyProperties(addReqDTO,materialAllocationBaseInfo);
|
materialAllocationBaseInfo.setId(IdUtil.getSnowflake(0,0).nextId());
|
materialAllocationBaseInfo.setCreateUid(currentUser.getUid());
|
materialAllocationBaseInfo.setCreateUname(currentUser.getUsername());
|
|
List<MaterialDetailInfo> materialDetailInfoList = new ArrayList<>();
|
if(!CollectionUtils.isEmpty(materialDetailList)){
|
for (MaterialDetailAddReqDTO materialDetail : materialDetailList) {
|
//物资详表数据
|
MaterialDetailInfo materialDetailInfo = new MaterialDetailInfo();
|
BeanUtils.copyProperties(materialDetail,materialDetailInfo);
|
materialDetailInfo.setId(IdUtil.getSnowflake(0,0).nextId());
|
materialDetailInfo.setCreateUid(currentUser.getUid());
|
materialDetailInfo.setCreateUname(currentUser.getUsername());
|
materialDetailInfo.setGmtCreate(LocalDateTime.now());
|
materialDetailInfo.setMaBaseId(materialAllocationBaseInfo.getId());
|
materialDetailInfo.setStatus(MaterialDetailStatusEnum.VALID.getCode());
|
List<SafeMaterialBsClassifyRPCRespDto> selectList = classifyRPCRespDtoList
|
.stream()
|
.filter(classify -> classify.getSmallClassifyId().equals(materialDetail.getSmallClassifyId()))
|
.collect(Collectors.toList());
|
if(selectList.size()>0){
|
materialDetailInfo.setBigClassifyId(selectList.get(0).getBigClassifyId());
|
materialDetailInfo.setBigClassifyName(selectList.get(0).getBigClassifyName());
|
materialDetailInfo.setMaterialName(selectList.get(0).getSmallClassifyName());
|
}
|
materialDetailInfoList.add(materialDetailInfo);
|
|
}
|
}
|
|
//插入配置表数据
|
materialAllocationBaseInfoService.saveOne(materialAllocationBaseInfo);
|
//插入物资详表数据
|
if(materialDetailInfoList.size()>0){
|
materialDetailInfoService.saveBatch(materialDetailInfoList);
|
}
|
return new ResultVO<>(ResultCodes.OK);
|
}
|
|
|
|
@Transactional
|
@Override
|
public ResultVO update(ContextCacheUser currentUser, MaterialAllocationBaseModReqDTO modReqDTO) {
|
|
if(null == WorkTypeEnum.parse(modReqDTO.getWorkType())){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"作业类型不合法!");
|
}
|
if(null != modReqDTO.getWorkLevel()){
|
if(null == WorkLevelEnum.parse(modReqDTO.getWorkLevel())){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"作业级别不合法!");
|
}
|
}
|
|
//配置物资表数据
|
MaterialAllocationBaseInfo materialAllocationBaseInfo = new MaterialAllocationBaseInfo();
|
BeanUtils.copyProperties(modReqDTO,materialAllocationBaseInfo);
|
materialAllocationBaseInfo.setModifiedUid(currentUser.getUid());
|
materialAllocationBaseInfo.setModifiedUname(currentUser.getUsername());
|
|
List<MaterialDetailModReqDTO> materialDetailList = modReqDTO.getMaterialDetailList();
|
List<SafeMaterialBsClassifyRPCRespDto> classifyRPCRespDtoList = new ArrayList<>();
|
//验证
|
if(!CollectionUtils.isEmpty(materialDetailList)){
|
List<Long> smallClassifyIdList = materialDetailList
|
.stream().map(MaterialDetailModReqDTO::getSmallClassifyId)
|
.collect(Collectors.toList());
|
classifyRPCRespDtoList = this.getTraceabilityClassifyList(smallClassifyIdList);
|
|
for (MaterialDetailModReqDTO materialDetail : materialDetailList) {
|
|
if (null == materialDetail.getStandVal()) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "标准值不能为空!");
|
}
|
if (null == materialDetail.getConfigurationLevel()) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "配置级别不能为空!");
|
}
|
if (null == ConfigurationLevelEnum.parse(materialDetail.getConfigurationLevel())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "配置级别不合法!");
|
}
|
if (null == materialDetail.getSmallClassifyId()) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "物资种类id不能为空!");
|
}
|
List<SafeMaterialBsClassifyRPCRespDto> selectList = classifyRPCRespDtoList
|
.stream()
|
.filter(classify -> classify.getSmallClassifyId().equals(materialDetail.getSmallClassifyId()))
|
.collect(Collectors.toList());
|
if (selectList.size() == 0) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "物资种类不存在");
|
}
|
}
|
}
|
|
//获取原有物资配置表关联数据
|
List<MaterialDetailInfo> listByMaBaseId = materialDetailInfoService.listByMaBaseId(modReqDTO.getId());
|
|
//过滤出要删除的数据 做解绑操作
|
List<MaterialDetailInfo> deleteOldStepList = listByMaBaseId.stream().parallel().filter(a ->
|
materialDetailList.stream().noneMatch(b ->
|
a.getId().equals(b.getId())))
|
.collect(Collectors.toList());
|
List<Long> deleteOldStepIdList = deleteOldStepList.stream().map(md -> md.getId()).collect(Collectors.toList());
|
if(deleteOldStepIdList != null && deleteOldStepIdList.size()>0){
|
//批量删除
|
materialDetailInfoService.batchUpdateStatus(deleteOldStepIdList);
|
}
|
|
List<MaterialDetailInfo> mdSaveList = new ArrayList<>();
|
List<MaterialDetailInfo> mdUpdateList = new ArrayList<>();
|
if(!CollectionUtils.isEmpty(materialDetailList)){
|
for (MaterialDetailModReqDTO materialDetail : materialDetailList) {
|
//物资详表数据
|
MaterialDetailInfo materialDetailInfo = new MaterialDetailInfo();
|
BeanUtils.copyProperties(materialDetail,materialDetailInfo);
|
List<SafeMaterialBsClassifyRPCRespDto> selectList = classifyRPCRespDtoList
|
.stream()
|
.filter(classify -> classify.getSmallClassifyId().equals(materialDetail.getSmallClassifyId()))
|
.collect(Collectors.toList());
|
if(selectList.size()>0){
|
materialDetailInfo.setBigClassifyId(selectList.get(0).getBigClassifyId());
|
materialDetailInfo.setBigClassifyName(selectList.get(0).getBigClassifyName());
|
materialDetailInfo.setMaterialName(selectList.get(0).getSmallClassifyName());
|
}
|
if(null == materialDetail.getId()){//主键不存在
|
//生成主键
|
materialDetailInfo.setId(IdUtil.getSnowflake(0,0).nextId());
|
materialDetailInfo.setCreateUid(currentUser.getUid());
|
materialDetailInfo.setCreateUname(currentUser.getUsername());
|
materialDetailInfo.setMaBaseId(materialAllocationBaseInfo.getId());
|
materialDetailInfo.setStatus(MaterialDetailStatusEnum.VALID.getCode());
|
mdSaveList.add(materialDetailInfo);
|
}else{//主键存在
|
materialDetailInfo.setModifiedUname(currentUser.getUsername());
|
materialDetailInfo.setModifiedUid(currentUser.getUid());
|
mdUpdateList.add(materialDetailInfo);
|
}
|
|
}
|
}
|
//更新配置表数据
|
materialAllocationBaseInfoService.updateOne(materialAllocationBaseInfo);
|
//插入物资详表数据
|
if(mdSaveList.size()>0){
|
materialDetailInfoService.saveBatch(mdSaveList);
|
}
|
//更新物资详细表
|
if(mdUpdateList.size()>0){
|
materialDetailInfoService.updateBatch(mdUpdateList);
|
}
|
return new ResultVO<>(ResultCodes.OK);
|
}
|
|
@Override
|
public ResultVO delete(ContextCacheUser currentUser, Long id) {
|
if(null == id){
|
throw new AusinessException(E.DATA_PARAM_NULL,"主键不能为空!");
|
}
|
//逻辑删除物资配置表数据
|
materialAllocationBaseInfoService.updateStatus(id);
|
//根据配置物资id删除
|
materialDetailInfoService.updateStatusByMaBaseId(id);
|
return new ResultVO(ResultCodes.OK);
|
}
|
|
@Override
|
public ResultVO deleteBatch(ContextCacheUser currentUser, DeleteForm deleteForm) {
|
List<Long> ids = deleteForm.getIds();
|
//批量删除-配置数据
|
materialAllocationBaseInfoService.batchUpdateStatus(ids);
|
//批量删除-物资详细数据
|
materialDetailInfoService.batchUpdateStatusByMaBaseIds(ids);
|
return new ResultVO<>(ResultCodes.OK);
|
}
|
|
@Override
|
public SearchResultVO<List<MaterialAllcationBasePageRespDTO>> listByPage(ContextCacheUser currentUser, PageQuery<MaterialAllocationBaseQuery> pageQuery) {
|
Page<MaterialAllocationBaseInfo> page = new Page(pageQuery.getPageIndex(), pageQuery.getPageSize());
|
//获取物资配置分页数据
|
List<MaterialAllocationBaseInfo> materialAllocationBaseList = materialAllocationBaseInfoService.listByPage(page, pageQuery.getSearchParams());
|
List<MaterialDetailInfo> materialDetailList = new ArrayList<>();
|
if(materialAllocationBaseList.size()>0){
|
List<Long> idList = materialAllocationBaseList.stream().map(mab -> mab.getId()).collect(Collectors.toList());
|
//根据物资配置ids获取物资数据
|
materialDetailList = materialDetailInfoService.listByMaBaseIds(idList);
|
}
|
List<MaterialAllcationBasePageRespDTO> mabRespDTOList = new ArrayList<>();
|
if(!CollectionUtils.isEmpty(materialAllocationBaseList)){
|
for (MaterialAllocationBaseInfo materialAllocationBaseInfo:materialAllocationBaseList) {
|
List<ConfigurationLevelRespDTO> clList = new ArrayList<>();
|
MaterialAllcationBasePageRespDTO mabPageRespDTO = new MaterialAllcationBasePageRespDTO();
|
BeanUtils.copyProperties(materialAllocationBaseInfo, mabPageRespDTO);
|
List<MaterialDetailInfo> selectList = materialDetailList
|
.stream()
|
.filter(md -> md.getMaBaseId().equals(materialAllocationBaseInfo.getId()))
|
.collect(Collectors.toList());
|
for (ConfigurationLevelEnum configurationLevelEnum : ConfigurationLevelEnum.values()) {
|
ConfigurationLevelRespDTO configurationLevelRespDTO = new ConfigurationLevelRespDTO();
|
configurationLevelRespDTO.setConfigurationLevel(configurationLevelEnum.getCode());
|
configurationLevelRespDTO.setConfigurationLevelName(configurationLevelEnum.getValue());
|
List<MaterialDetailInfo> collect = selectList
|
.stream()
|
.filter(sl -> sl.getConfigurationLevel().equals(configurationLevelEnum.getCode()))
|
.collect(Collectors.toList());
|
//物资转换
|
List<MaterialDetailRespDTO> mdRespDTOList = new ArrayList<>();
|
for (MaterialDetailInfo materialDetailInfo:collect) {
|
MaterialDetailRespDTO materialDetailRespDTO = new MaterialDetailRespDTO();
|
BeanUtils.copyProperties(materialDetailInfo,materialDetailRespDTO);
|
if(null != materialDetailInfo.getConsumable()){
|
materialDetailRespDTO.setConsumableName(ConsumableEnum.getByCode(materialDetailInfo.getConsumable()).getValue());
|
}
|
mdRespDTOList.add(materialDetailRespDTO);
|
}
|
configurationLevelRespDTO.setMdList(mdRespDTOList);
|
clList.add(configurationLevelRespDTO);
|
}
|
mabPageRespDTO.setClList(clList);
|
mabRespDTOList.add(mabPageRespDTO);
|
}
|
}
|
|
return new SearchResultVO<>(true,
|
page.getCurrent(),
|
page.getSize(),
|
page.getPages(),
|
page.getTotal(),
|
mabRespDTOList,
|
ResultCodes.OK);
|
}
|
|
@Override
|
public ResultVO<List<MaterialAllcationBasePageRespDTO>> list(ContextCacheUser currentUser, MaterialAllocationBaseQuery query) {
|
|
//获取物资配置分页数据
|
List<MaterialAllocationBaseInfo> materialAllocationBaseList = materialAllocationBaseInfoService.listAll(query);
|
//获取物资数据
|
List<MaterialDetailInfo> materialDetailList = materialDetailInfoService.listAll();
|
|
List<MaterialAllcationBasePageRespDTO> mabRespDTO = new ArrayList<>();
|
for (MaterialAllocationBaseInfo materialAllocationBaseInfo:materialAllocationBaseList) {
|
List<ConfigurationLevelRespDTO> clList = new ArrayList<>();
|
MaterialAllcationBasePageRespDTO mabPageRespDTO = new MaterialAllcationBasePageRespDTO();
|
BeanUtils.copyProperties(materialAllocationBaseInfo, mabPageRespDTO);
|
List<MaterialDetailInfo> selectList = materialDetailList
|
.stream()
|
.filter(md -> md.getMaBaseId().equals(materialAllocationBaseInfo.getId()))
|
.collect(Collectors.toList());
|
for (ConfigurationLevelEnum clEnum : ConfigurationLevelEnum.values()) {
|
ConfigurationLevelRespDTO clRespDTO = new ConfigurationLevelRespDTO();
|
clRespDTO.setConfigurationLevel(clEnum.getCode());
|
clRespDTO.setConfigurationLevelName(clEnum.getValue());
|
List<MaterialDetailInfo> collect = selectList
|
.stream()
|
.filter(md -> md.getConfigurationLevel().equals(clEnum.getCode()))
|
.collect(Collectors.toList());
|
//物资转换
|
List<MaterialDetailRespDTO> mdRespDTOList = new ArrayList<>();
|
for (MaterialDetailInfo materialDetailInfo:collect) {
|
MaterialDetailRespDTO materialDetailRespDTO = new MaterialDetailRespDTO();
|
BeanUtils.copyProperties(materialDetailInfo,materialDetailRespDTO);
|
mdRespDTOList.add(materialDetailRespDTO);
|
}
|
clRespDTO.setMdList(mdRespDTOList);
|
clList.add(clRespDTO);
|
}
|
mabPageRespDTO.setClList(clList);
|
mabRespDTO.add(mabPageRespDTO);
|
}
|
return new ResultVO<>(ResultCodes.OK,mabRespDTO);
|
}
|
|
@Override
|
public ResultVO<List<MaterialAllocationBaseRespDTO>> queryByWorkTypeOrLevel(ContextCacheUser currentUser, MaterialAllocationBaseQuery query) {
|
if(null == query.getWorkType()){
|
throw new AusinessException(E.DATA_PARAM_NULL,"作业类型不可为空!");
|
}
|
//获取基础配置数据
|
List<MaterialAllocationBaseInfo> materialAllocationBaseList = materialAllocationBaseInfoService.listAll(query);
|
/* List<MaterialDetailInfo> materialDetailList = new ArrayList<>();
|
List<SafeMaterialClassifyStockRPCRespDto> materialStockList = new ArrayList<>();
|
if(!CollectionUtils.isEmpty(materialAllocationBaseList)){
|
//获取配置下物资
|
List<Long> ids = materialAllocationBaseList.stream().map(MaterialAllocationBaseInfo::getId).collect(Collectors.toList());
|
materialDetailList= materialDetailInfoService.listByMaBaseIds(ids);
|
}
|
if(!CollectionUtils.isEmpty(materialDetailList)){
|
//获取物资库存
|
List<Long> smallClassifyIds = materialDetailList.stream().map(MaterialDetailInfo::getSmallClassifyId).collect(Collectors.toList());
|
materialStockList = this.getMaterialStock(smallClassifyIds);
|
}*/
|
List<MaterialAllocationBaseRespDTO> respDTOList = new ArrayList<>();
|
//循环配置
|
for (MaterialAllocationBaseInfo allocationBaseInfo:materialAllocationBaseList) {
|
MaterialAllocationBaseRespDTO allocationBaseRespDTO = new MaterialAllocationBaseRespDTO();
|
BeanUtils.copyProperties(allocationBaseInfo,allocationBaseRespDTO);
|
/* //过滤该配置下的物资
|
List<MaterialDetailInfo> selectMaterialList = materialDetailList
|
.stream()
|
.filter(md -> md.getMaBaseId().equals(allocationBaseInfo.getId()))
|
.collect(Collectors.toList());
|
List<MaterialClassifyRespDTO> classifyRespDTOList = new ArrayList<>();
|
for(MaterialDetailInfo materialDetailInfo:selectMaterialList){
|
MaterialClassifyRespDTO materialClassifyRespDTO = new MaterialClassifyRespDTO();
|
materialClassifyRespDTO.setMaterialId(materialDetailInfo.getId());
|
materialClassifyRespDTO.setMaterialName(materialDetailInfo.getMaterialName());
|
materialClassifyRespDTO.setConfigurationLevelName(ConfigurationLevelEnum.parse(materialDetailInfo.getConfigurationLevel()).getValue());
|
materialClassifyRespDTO.setStandVal(materialDetailInfo.getStandVal());
|
//过滤出该种物资各个仓库的存量
|
List<SafeMaterialClassifyStockRPCRespDto> collect = materialStockList
|
.stream()
|
.filter(ms -> ms.getSmallClassifyId().equals(materialDetailInfo.getSmallClassifyId()))
|
.collect(Collectors.toList());
|
List<MaterialStockRespDTO> stockRespDTOList = new ArrayList<>();
|
for(SafeMaterialClassifyStockRPCRespDto stockRPCRespDto:collect){
|
MaterialStockRespDTO materialStockRespDTO = new MaterialStockRespDTO();
|
materialStockRespDTO.setDepId(stockRPCRespDto.getDepId());
|
materialStockRespDTO.setStockCount(stockRPCRespDto.getStockCount());
|
materialStockRespDTO.setDepName(stockRPCRespDto.getDepName());
|
stockRespDTOList.add(materialStockRespDTO);
|
}
|
materialClassifyRespDTO.setMsList(stockRespDTOList);
|
classifyRespDTOList.add(materialClassifyRespDTO);
|
}
|
allocationBaseRespDTO.setMcList(classifyRespDTOList);*/
|
respDTOList.add(allocationBaseRespDTO);
|
}
|
return new ResultVO<>(ResultCodes.OK,respDTOList);
|
}
|
|
|
/**
|
* 应急物资
|
* @param currentUser
|
* @return
|
*/
|
@Override
|
public ResultVO emergencyMaterial(ContextCacheUser currentUser) {
|
try{
|
List<EmergencySuppliesTypeRPCResp> list = (List<EmergencySuppliesTypeRPCResp>)emergencyRpcAPi.emergencySuppliesList(currentUser).getData();
|
return new ResultVO(ResultCodes.OK,list);
|
}catch (Exception e){
|
throw new BusinessException(ResultCodes.RPC_ACCESS_EXCEPTION);
|
}
|
}
|
|
@Override
|
public List<SafeMaterialClassifyRPCRespDto> materialClassify() {
|
ResultVO<List<SafeMaterialClassifyRPCRespDto>> result = equipmentRpcAPi.getMaterialClassifyList();
|
List<SafeMaterialClassifyRPCRespDto> classifyRPCRespDtoList = new ArrayList<>();
|
if(result.getCode().equals(ResultCodes.OK.getCode())){
|
if(null != result.getData()){
|
classifyRPCRespDtoList = (List<SafeMaterialClassifyRPCRespDto>) result.getData();
|
}else{
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
}else{
|
throw new BusinessException(result.getCode(),result.getMsg());
|
}
|
|
return classifyRPCRespDtoList;
|
}
|
|
@Override
|
public List<MaterialReceiveRecordsRespDTO> materialReceive(MaterialReceiveReqDTO receiveReq) {
|
|
//获取领取人员信息
|
List<UserInfoRPCRespDTO> userInfoRPCRespDTOList = listAccountUsers(receiveReq.getReceiveUids());
|
//物资配置清单
|
List<MaterialDetailInfo> materialDetailInfoList = materialDetailInfoService.listByMaBaseId(receiveReq.getMaBaseId());
|
if(CollectionUtils.isEmpty(materialDetailInfoList)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"未查询到该物资配置清单!");
|
}
|
List<Long> smallClassifyIdList = materialDetailInfoList.stream().map(MaterialDetailInfo::getSmallClassifyId).collect(Collectors.toList());
|
//根据人员获取未归还相关领取物资 人员,小类别,
|
MaterialReceiveRecordsRPCReq materialReceiveRecordsRPCReq = new MaterialReceiveRecordsRPCReq();
|
materialReceiveRecordsRPCReq.setReceiveUids(receiveReq.getReceiveUids());
|
materialReceiveRecordsRPCReq.setSmallClassifyIds(smallClassifyIdList);
|
List<MaterialReceiveRecordsRPCRespDto> list = new ArrayList<>();
|
ResultVO<List<MaterialReceiveRecordsRPCRespDto>> result = equipmentRpcAPi.getMaterialReceiveRecords(materialReceiveRecordsRPCReq);
|
if(result.getCode().equals(ResultCodes.OK.getCode())){
|
if(null != result.getData()){
|
list = (List<MaterialReceiveRecordsRPCRespDto>) result.getData();
|
}
|
}else {
|
throw new BusinessException(result.getCode(), result.getMsg());
|
}
|
List<MaterialReceiveRecordsRespDTO> respDTOList = new ArrayList<>();
|
for(MaterialDetailInfo materialDetailInfo:materialDetailInfoList){
|
MaterialReceiveRecordsRespDTO receiveRecordsRespDTO = new MaterialReceiveRecordsRespDTO();
|
receiveRecordsRespDTO.setMaBaseId(materialDetailInfo.getMaBaseId());
|
receiveRecordsRespDTO.setMdId(materialDetailInfo.getId());
|
receiveRecordsRespDTO.setMaterialName(materialDetailInfo.getMaterialName());
|
receiveRecordsRespDTO.setBigClassifyId(materialDetailInfo.getBigClassifyId());
|
receiveRecordsRespDTO.setBigClassifyName(materialDetailInfo.getBigClassifyName());
|
receiveRecordsRespDTO.setSmallClassifyId(materialDetailInfo.getSmallClassifyId());
|
receiveRecordsRespDTO.setConsumable(materialDetailInfo.getConsumable());
|
if(null != materialDetailInfo.getConsumable()){
|
receiveRecordsRespDTO.setConsumableName(ConsumableEnum.getByCode(materialDetailInfo.getConsumable()).getValue());
|
}
|
receiveRecordsRespDTO.setConfigurationLevel(materialDetailInfo.getConfigurationLevel());
|
receiveRecordsRespDTO.setConfigurationLevelName(ConfigurationLevelEnum.parse(materialDetailInfo.getConfigurationLevel()).getValue());
|
receiveRecordsRespDTO.setStandVal(materialDetailInfo.getStandVal());
|
StringBuffer userNames = new StringBuffer();
|
StringBuffer userUids = new StringBuffer();
|
if(!CollectionUtils.isEmpty(list)){
|
List<MaterialReceiveRecordsRPCRespDto> selectReceiveList = list.stream().filter(item -> item.getSmallClassifyId().equals(materialDetailInfo.getSmallClassifyId())).collect(Collectors.toList());
|
receiveRecordsRespDTO.setReceiveCount(selectReceiveList.size());
|
for(UserInfoRPCRespDTO user:userInfoRPCRespDTOList){
|
List<MaterialReceiveRecordsRPCRespDto> collect = selectReceiveList.stream().filter(item -> item.getReceiveUid().equals(user.getUid())).collect(Collectors.toList());
|
userNames.append(user.getUsername()).append("(").append(String.valueOf(collect.size())).append("),");
|
userUids.append(user.getUid().toString()).append(",");
|
}
|
|
}else{
|
for(UserInfoRPCRespDTO user:userInfoRPCRespDTOList){
|
userNames.append(user.getUsername()).append("(0)");
|
userUids.append(user.getUid().toString()).append(",");
|
}
|
receiveRecordsRespDTO.setReceiveCount(0);
|
}
|
receiveRecordsRespDTO.setReceiveUnames(userNames.substring(0,userNames.length()));
|
receiveRecordsRespDTO.setReceiveUids(userUids.substring(0,userUids.length()));
|
respDTOList.add(receiveRecordsRespDTO);
|
}
|
return respDTOList;
|
}
|
@Override
|
public List<MaterialReceiveRecordsRPCRespDto> materialDetailReceiveRecords(MaterialReceiveReqDTO receiveReq) {
|
|
//物资配置清单
|
List<MaterialDetailInfo> materialDetailInfoList = materialDetailInfoService.listByMaBaseId(receiveReq.getMaBaseId());
|
if(CollectionUtils.isEmpty(materialDetailInfoList)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"未查询到该物资配置清单!");
|
}
|
List<Long> smallClassifyIdList = materialDetailInfoList.stream().map(MaterialDetailInfo::getSmallClassifyId).collect(Collectors.toList());
|
//根据人员获取未归还相关领取物资 人员,小类别,
|
MaterialReceiveRecordsRPCReq materialReceiveRecordsRPCReq = new MaterialReceiveRecordsRPCReq();
|
materialReceiveRecordsRPCReq.setReceiveUids(receiveReq.getReceiveUids());
|
materialReceiveRecordsRPCReq.setSmallClassifyIds(smallClassifyIdList);
|
List<MaterialReceiveRecordsRPCRespDto> list = new ArrayList<>();
|
ResultVO<List<MaterialReceiveRecordsRPCRespDto>> result = equipmentRpcAPi.getMaterialReceiveRecords(materialReceiveRecordsRPCReq);
|
if(result.getCode().equals(ResultCodes.OK.getCode())){
|
if(null != result.getData()){
|
list = (List<MaterialReceiveRecordsRPCRespDto>) result.getData();
|
}
|
}else {
|
throw new BusinessException(result.getCode(), result.getMsg());
|
}
|
return list;
|
}
|
|
private List<SafeMaterialClassifyRPCRespDto> getClassifyListByIds(List<Long> ids){
|
List<SafeMaterialClassifyRPCRespDto> list = new ArrayList<>();
|
ResultVO<List<SafeMaterialClassifyRPCRespDto>> result = equipmentRpcAPi.getClassifyListByIds(ids);
|
if(result.getCode().equals(ResultCodes.OK.getCode())){
|
if(null == result.getData()){
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL.getCode(),"物资种类不存在!");
|
}else{
|
list = (List<SafeMaterialClassifyRPCRespDto>) result.getData();
|
}
|
}else {
|
throw new BusinessException(result.getCode(), result.getMsg());
|
}
|
return list;
|
}
|
private List<SafeMaterialBsClassifyRPCRespDto> getTraceabilityClassifyList(List<Long> ids){
|
List<SafeMaterialBsClassifyRPCRespDto> list = new ArrayList<>();
|
ResultVO<List<SafeMaterialBsClassifyRPCRespDto>> result = equipmentRpcAPi.getTraceabilityClassifyList(ids);
|
if(result.getCode().equals(ResultCodes.OK.getCode())){
|
if(null == result.getData()){
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL.getCode(),"物资种类不存在!");
|
}else{
|
list = (List<SafeMaterialBsClassifyRPCRespDto>) result.getData();
|
}
|
}else {
|
throw new BusinessException(result.getCode(), result.getMsg());
|
}
|
return list;
|
}
|
private List<SafeMaterialClassifyStockRPCRespDto> getMaterialStock(List<Long> smallClassifyIds){
|
List<SafeMaterialClassifyStockRPCRespDto> list = new ArrayList<>();
|
ResultVO<List<SafeMaterialClassifyStockRPCRespDto>> result = equipmentRpcAPi.getSmallClassifyStockByIds(smallClassifyIds);
|
if(result.getCode().equals(ResultCodes.OK.getCode())){
|
if(null == result.getData()){
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL.getCode(),"物资种类不存在!");
|
}else{
|
list = (List<SafeMaterialClassifyStockRPCRespDto>) result.getData();
|
}
|
}else {
|
throw new BusinessException(result.getCode(), result.getMsg());
|
}
|
return list;
|
}
|
//调用RPC 获取去人员
|
private List<UserInfoRPCRespDTO> listAccountUsers(List<Long> userIds){
|
List<UserInfoRPCRespDTO> userInfoRPCRespDTOList = new ArrayList<>();
|
ResultVO<List<UserInfoRPCRespDTO>> listResultVO = accountUserService.listUserInfoByUids(userIds);
|
if (listResultVO != null && listResultVO.getCode().equals(ResultCodes.OK.getCode())) {
|
if (listResultVO.getData() != null) {
|
userInfoRPCRespDTOList = (List<UserInfoRPCRespDTO>) listResultVO.getData();
|
}else{
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"领取人员不存在");
|
}
|
} else {
|
throw new BusinessException(ResultCodes.RPC_ACCESS_EXCEPTION);
|
}
|
return userInfoRPCRespDTOList;
|
}
|
}
|