diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/service/impl/MaterialLeaseInfoServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/service/impl/MaterialLeaseInfoServiceImpl.java index c9390bbf..9897dad9 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/service/impl/MaterialLeaseInfoServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/service/impl/MaterialLeaseInfoServiceImpl.java @@ -24,6 +24,8 @@ import com.bonus.material.basic.mapper.BmFileInfoMapper; import com.bonus.material.clz.domain.BmTeam; import com.bonus.material.clz.domain.vo.MaterialMaCodeVo; import com.bonus.material.clz.mapper.MaterialMachineMapper; +import com.bonus.material.common.domain.dto.SelectDto; +import com.bonus.material.common.domain.vo.AgreementVo; import com.bonus.material.common.mapper.SelectMapper; import com.bonus.material.ma.domain.Type; import com.bonus.material.ma.mapper.TypeMapper; @@ -334,9 +336,97 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService { } else { detail.setUseNum(BigDecimal.ZERO); } - // 根据AgreementId查询机具库存 - BigDecimal storageNum = materialLeaseInfoMapper.getStorageNum(info.getAgreementId(), detail.getTypeId()); - detail.setStorageNum(storageNum); + SelectDto selectDto = new SelectDto(); + selectDto.setProjectId(info.getProjectId().intValue()); + List list = mapper.getAgreementInfoBy(selectDto); + // 先查第四层类型 + List listL4 = new ArrayList<>(); + List listL5 = new ArrayList<>(); + List list7 = new ArrayList<>(); + BackApplyInfo backApplyInfo = new BackApplyInfo(); + if (!CollectionUtils.isEmpty(list)) { + for (AgreementVo agreementVo : list) { + backApplyInfo.setAgreementId(Long.valueOf(agreementVo.getAgreementId())); + listL4 = mapper.getUseTypeTreeL4(backApplyInfo); + if (!CollectionUtils.isEmpty(listL4)) { + listL4 = listL4.stream() + .filter(item -> StringUtils.isNotBlank(item.getMaterialName()) && StringUtils.isNotBlank(item.getTypeName())) + .collect(Collectors.toList()); + // 将listL5中typeId相同的数据进行num相加 + for (TypeTreeNode node : listL4) { + // 根据node中的typeId查询listL5中相同数据,如果在listL5中存在,则将num相加,反之将node添加到list5中 + TypeTreeNode node1 = listL5.stream() + .filter(item -> item.getTypeId() == (node.getTypeId())) + .findFirst() + .orElse(null); + if (node1 != null) { + node1.setNum(node1.getNum().add(node.getNum())); + } + if (node1 == null) { + listL5.add(node); + } + } + } + } + // 根据工程id去协议表中查询协议id + MaterialLeaseApplyInfo bean = new MaterialLeaseApplyInfo(); + bean.setProId(info.getProjectId()); + List listAgreement = materialLeaseInfoMapper.getAgreementIdByProId(bean); + if (!CollectionUtils.isEmpty(listAgreement)) { + for (BmAgreementInfo agreementInfo : listAgreement) { + bean.setAgreementId(agreementInfo.getAgreementId()); + List list6 = materialLeaseInfoMapper.getUseTypeTree(bean); + if (!CollectionUtils.isEmpty(list6)) { + for (TypeTreeNode node : list6) { + // 根据node中的typeId查询listL7中相同数据,如果在listL7中存在,则将num相加,反之将node添加到list7中 + TypeTreeNode node1 = list7.stream() + .filter(item -> item.getTypeId() == (node.getTypeId())) + .findFirst() + .orElse(null); + if (node1 != null) { + node1.setNum(node1.getNum().add(node.getNum())); + } + if (node1 == null) { + list7.add(node); + } + } + } + } + } + // 根据协议id去clz_slt_agreement_info材料站协议表中查询在用设备,进行数据筛选去除 + if (!CollectionUtils.isEmpty(listL5)) { + if (!CollectionUtils.isEmpty(list7)) { + // 将list5中typeId和list7中相同数据进行num相减,并剔除相减后为0的数据 + Map typeIdToNum = list7.stream() + .collect(Collectors.toMap( + TypeTreeNode::getTypeId, + TypeTreeNode::getNum, + BigDecimal::add + )); + Iterator iterator = listL5.iterator(); + while (iterator.hasNext()) { + TypeTreeNode node = iterator.next(); + Long typeId = node.getTypeId(); + // 获取要减去的值,默认值为BigDecimal.ZERO + BigDecimal subtractNum = typeIdToNum.getOrDefault(typeId, BigDecimal.ZERO); + // 计算新值,处理num为null的情况(若业务允许) + BigDecimal currentNum = Optional.ofNullable(node.getNum()) + .orElse(BigDecimal.ZERO); + BigDecimal newNum = currentNum.subtract(subtractNum); + if (newNum.compareTo(BigDecimal.ZERO) == 0) { + iterator.remove(); + } else { + node.setNum(newNum); + } + } + } + // 根据details中的typeId去list5中获取库存 + listL5.stream() + .filter(node -> detail.getTypeId().equals(node.getTypeId())) + .findFirst() + .ifPresent(node -> detail.setStorageNum(node.getNum())); + } + } // 获取编码详情 // 移出maCodeList集合中状态不为在库的数据 List maCodeVoList = materialLeaseInfoMapper.getCodeList(id, detail.getTypeId()); diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/mapper/SelectMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/mapper/SelectMapper.java index d5ff98ea..7516c1c9 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/mapper/SelectMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/mapper/SelectMapper.java @@ -234,4 +234,6 @@ public interface SelectMapper { * @return */ List getUserNameList(MaterialLeaseApplyInfo i8ProjectInfo); + + List getProjectListByClz(BmProject bmProject); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/service/impl/SelectServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/service/impl/SelectServiceImpl.java index 9b7751b5..8c15cb13 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/service/impl/SelectServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/service/impl/SelectServiceImpl.java @@ -88,13 +88,15 @@ public class SelectServiceImpl implements SelectService { */ @Override public AjaxResult getProjectList(BmProject bmProject) { + List bmProjects = new ArrayList<>(); if (bmProject.getIsApp() != null && bmProject.getIsApp()) { if (bmProject.getTeamId() != null) { - bmProject.setUnitId(bmProject.getTeamId()); + bmProjects = mapper.getProjectListByClz(bmProject); + } else { + bmProjects = mapper.getProjectListApp(bmProject); } - List list = mapper.getProjectListApp(bmProject); - list.removeIf(Objects::isNull); - return AjaxResult.success(list); + bmProjects.removeIf(Objects::isNull); + return AjaxResult.success(bmProjects); } // 获取登陆用户的组织ID diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialLeaseInfoMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialLeaseInfoMapper.xml index 49e8cadd..e8264c75 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialLeaseInfoMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialLeaseInfoMapper.xml @@ -82,17 +82,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" tta.agreement_id, bp.external_id, bp.imp_unit, - bt.bzz_idcard + bt.bzz_idcard, + bai.unit_id, + bai.project_id from clz_lease_apply_info lai left join tm_task tt on lai.task_id = tt.task_id left join tm_task_agreement tta ON tt.task_id = tta.task_id + left join bm_agreement_info bai ON tta.agreement_id = bai.agreement_id left join clz_lease_apply_details lad on lai.id = lad.parent_id left join bm_project bp on bp.pro_id = lai.project_id left join bm_unit bt on bt.unit_id = lai.team_id left join sys_dept sd on sd.dept_id = bp.imp_unit left join sys_dict_data sda on tt.task_status = sda.dict_value - and sda.dict_type = 'lease_task_status' + and sda.dict_type = 'clz_lease_apply_task_status' left join ma_type mt on lad.type_id = mt.type_id and mt.del_flag = '0' left join ma_type mt1 on mt.parent_id = mt1.type_id and mt1.del_flag = '0' diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml index bee983f0..b451cda6 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml @@ -190,7 +190,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" SELECT agreement_id AS agreementId, agreement_code AS agreementCode, is_slt AS isSlt - FROM bm_agreement_info + FROM clz_bm_agreement_info WHERE unit_id = #{unitId} AND project_id = #{projectId} AND status = '1' @@ -538,4 +538,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" WHERE post_id = '3de0eb390f3611efa1940242ac130004' AND depart_id = #{departId} +