|
@@ -1,6 +1,7 @@
|
|
|
package org.springblade.meter.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -14,7 +15,10 @@ import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.meter.dto.LinkMeterTreeAndWbsTreeDTO;
|
|
|
+import org.springblade.meter.dto.MeterTreeContractDTO;
|
|
|
import org.springblade.meter.dto.MeterTreeContractSaveBatchDTO;
|
|
|
import org.springblade.meter.dto.MeterTreeContractSaveDTO;
|
|
|
import org.springblade.meter.entity.*;
|
|
@@ -22,15 +26,13 @@ import org.springblade.meter.mapper.ContractInventoryFormMapper;
|
|
|
import org.springblade.meter.mapper.InventoryFormMeterMapper;
|
|
|
import org.springblade.meter.mapper.MeterTreeContractMapper;
|
|
|
import org.springblade.meter.mapper.MeterTreeProjectMapper;
|
|
|
+import org.springblade.meter.service.IMeterTreeLinkWbsTreeService;
|
|
|
import org.springblade.meter.service.MeterTreeContractService;
|
|
|
-import org.springblade.meter.vo.ChangeNodeVO;
|
|
|
-import org.springblade.meter.vo.ContractFromVO;
|
|
|
-import org.springblade.meter.vo.InventoryFormMeterVO;
|
|
|
-import org.springblade.meter.vo.MeterTreeContractVO;
|
|
|
+import org.springblade.meter.utils.ForestNodeMerger;
|
|
|
+import org.springblade.meter.vo.*;
|
|
|
import org.springblade.system.entity.Dict;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -41,7 +43,6 @@ import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.util.stream.Stream;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
@@ -51,6 +52,7 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
|
|
|
private final MeterTreeProjectMapper meterTreeProjectMapper;
|
|
|
private final InventoryFormMeterMapper inventoryFormMeterMapper;
|
|
|
private final ContractInventoryFormMapper contractInventoryFormMapper;
|
|
|
+ private final IMeterTreeLinkWbsTreeService meterTreeLinkWbsTreeService;
|
|
|
|
|
|
@Override
|
|
|
public Integer selectMaxSort(Long parentId) {
|
|
@@ -1780,6 +1782,170 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
|
|
|
return R.success("成功导入:节点("+addNode+")个,"+"新增清单("+addForm+")条,"+"修改清单("+updateForm+")条.");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean contractUpdate(MeterTreeContractDTO dto) {
|
|
|
+ //先校验节点编号是否唯一
|
|
|
+ if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(dto.getNodeCode())){
|
|
|
+ long count = this.count(new LambdaUpdateWrapper<MeterTreeContract>()
|
|
|
+ .eq(MeterTreeContract::getNodeCode, dto.getNodeCode())
|
|
|
+ .eq(MeterTreeContract::getContractId,dto.getContractId())
|
|
|
+ .ne(MeterTreeContract::getId, dto.getId()));
|
|
|
+ if (count > 0){
|
|
|
+ throw new ServiceException("修改失败,当前工程编号已经存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //校验如果为混泥土节点
|
|
|
+ if (dto.getIsConcreteNode() == 1){
|
|
|
+ if ( (dto.getSevenRatio() == null || dto.getTwentyEightRatio() == null)) {
|
|
|
+ throw new ServiceException("修改失败,混泥土节点必须填写强度比例");
|
|
|
+ }
|
|
|
+ if ((dto.getSevenRatio().compareTo(BigDecimal.ZERO) < 0 || dto.getSevenRatio().compareTo(new BigDecimal("100")) > 0)
|
|
|
+ || (dto.getTwentyEightRatio().compareTo(BigDecimal.ZERO) < 0 || dto.getTwentyEightRatio().compareTo(new BigDecimal("100")) > 0)){
|
|
|
+ throw new ServiceException("修改失败,强度比例必须在0-100范围内");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //校验比例是否在范围之内
|
|
|
+ if (dto.getUpPayRatio() == null){
|
|
|
+ dto.setUpPayRatio(new BigDecimal(80));
|
|
|
+ }else if (dto.getUpPayRatio().compareTo(BigDecimal.ZERO) < 0 || dto.getUpPayRatio().compareTo(new BigDecimal("100")) > 0){
|
|
|
+ throw new ServiceException("修改失败,请检查支付比例是否在规定范围");
|
|
|
+ }
|
|
|
+ //如果计算式有值,就同步去修改所有中间计量申请的
|
|
|
+ if (StringUtils.isNotBlank(dto.getCalculateFormula())){
|
|
|
+ baseMapper.updateMiddleMeter(dto);
|
|
|
+ }
|
|
|
+ boolean b = this.updateById(dto);
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取计量和WBS全加载树
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public MeterTreeAndWbsTreeVO meterTreeAndWbsTree(Long projectId, Long contractId) {
|
|
|
+ MeterTreeAndWbsTreeVO vo = new MeterTreeAndWbsTreeVO();
|
|
|
+ //获取合同计量全加载树
|
|
|
+ List<MeterFullTreeVO> vos = baseMapper.getMeterTree(projectId,contractId);
|
|
|
+ List<MeterFullTreeVO> list = ForestNodeMerger.merge(vos);
|
|
|
+ vo.setMeterTree(list);
|
|
|
+ //获取WBS全加载树
|
|
|
+ List<MeterFullTreeVO> vos2 = baseMapper.getWBSTree(projectId,contractId);
|
|
|
+// List<MeterFullTreeVO> treeVOS = vos2.stream().collect(Collectors.toList());
|
|
|
+// //因为结构设计错误,id有重复,需要去重id,会丢失少许节点。如果后期需要完整节点,则先排除重复,再生成树,再把重复接在树上,再生成树。
|
|
|
+// List<MeterFullTreeVO> treeVOS = vos2.stream().collect(Collectors.toMap(MeterFullTreeVO::getId, l -> l, (st1, st2) -> st1))
|
|
|
+// .values().stream().collect(Collectors.toList());
|
|
|
+// //去除没有找到父信息的
|
|
|
+// treeVOS = treeVOS.stream().filter(l->l.getHasFather() || l.getParentId() == 0).collect(Collectors.toList());
|
|
|
+ List<MeterFullTreeVO> list2 = ForestNodeMerger.merge(vos2);
|
|
|
+ List<MeterFullTreeVO> list3 = new ArrayList<>();
|
|
|
+ //查询合同名称
|
|
|
+ String name = baseMapper.getContractName(projectId,contractId);
|
|
|
+ //会出现很多首节点,筛选出实际的
|
|
|
+ for (MeterFullTreeVO treeVO : list2) {
|
|
|
+ if (treeVO.getParentId() == 0){
|
|
|
+ treeVO.setNodeName(name);
|
|
|
+ list3.add(treeVO);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (list3.size() == 0){
|
|
|
+ throw new ServiceException("未找到WBS树首节点");
|
|
|
+ }
|
|
|
+ vo.setWbsTree(list3);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关联计量和WBS全加载树
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String LinkMeterTreeAndWbsTree(LinkMeterTreeAndWbsTreeDTO dto) {
|
|
|
+ //校验数据
|
|
|
+ if (StringUtils.isBlank(dto.getMeterIds()) || StringUtils.isBlank(dto.getWbsIds())){
|
|
|
+ throw new ServiceException("请选择节点");
|
|
|
+ };
|
|
|
+ List<MeterTreeLinkWbsTree> list = new ArrayList<>();
|
|
|
+ //转换为id集合
|
|
|
+ List<Long> meterIds = Func.toLongList(dto.getMeterIds());
|
|
|
+ List<Long> wbsIds = Func.toLongList(dto.getWbsIds());
|
|
|
+ //根据合同段查询出WBS树所有树节点,用于生成分项部位
|
|
|
+ List<NodePartVO> wbsNodes = baseMapper.getAllWbsNode(dto.getProjectId(),dto.getContractId());
|
|
|
+ //转换为map,key为Id
|
|
|
+ Map<Long, NodePartVO> voMap = wbsNodes.stream().collect(Collectors.toMap(l -> l.getId(), l -> l));
|
|
|
+ //转换为map,key为pKeyId
|
|
|
+ Map<Long, NodePartVO> voMap2 = wbsNodes.stream().collect(Collectors.toMap(l -> l.getPKeyId(), l -> l));
|
|
|
+ Map<Long,String> partMaps = new HashMap<>();
|
|
|
+ //循环节点,为每个节点设置部位信息
|
|
|
+ for (Long wbsId : wbsIds) {
|
|
|
+ //获取原节点信息
|
|
|
+ NodePartVO vo = voMap2.get(wbsId);
|
|
|
+ StringBuilder str = new StringBuilder(vo.getNodeName()+",");
|
|
|
+ //循环获取,直到<= 4为止,4为分项
|
|
|
+ while (vo.getNodeType() > 4){
|
|
|
+ //获取父级节点信息
|
|
|
+ NodePartVO partVO = voMap.get(vo.getParentId());
|
|
|
+ if (partVO == null){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ str.append(partVO.getNodeName()+",");
|
|
|
+ vo = partVO;
|
|
|
+ }
|
|
|
+ str.deleteCharAt(str.length()-1); // 删除最后一个分隔符
|
|
|
+ // 拆分字符串
|
|
|
+ String[] parts = str.toString().split(",");
|
|
|
+ // 排序字符串数组
|
|
|
+ List<String> list2 = Arrays.asList(parts);
|
|
|
+ Collections.reverse(list2);
|
|
|
+ // 重新拼接字符串
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (String s : list2) {
|
|
|
+ sb.append(s+"/");
|
|
|
+ }
|
|
|
+ if (sb.length() > 0) {
|
|
|
+ sb.deleteCharAt(sb.length()-1); // 添加最后一个元素但不加分隔符
|
|
|
+ }
|
|
|
+ //设置进map
|
|
|
+ partMaps.put(wbsId,sb.toString());
|
|
|
+
|
|
|
+ }
|
|
|
+ //查询出当前合同段当前选择的合同计量单元所有关联信息
|
|
|
+ List<MeterTreeLinkWbsTreeVO> linkList = baseMapper.getAllLinkByContractId(dto.getContractId(),meterIds);
|
|
|
+ Boolean isLinkInfo = true;
|
|
|
+ Map<Long, String> map = new HashMap<>();
|
|
|
+ if (linkList.size() > 0){
|
|
|
+ isLinkInfo = false;
|
|
|
+ map = linkList.stream().collect(Collectors.toMap(l -> l.getMeterTreeId(), l -> l.getWbsTreeIds()));
|
|
|
+ }
|
|
|
+ //循环
|
|
|
+ for (Long meterId : meterIds) {
|
|
|
+ for (Long wbsId : wbsIds) {
|
|
|
+ //如果不存在,则新增
|
|
|
+ if (isLinkInfo || StringUtils.isBlank(map.get(meterId)) || !map.get(meterId).contains(wbsId+"")){
|
|
|
+ MeterTreeLinkWbsTree tree = new MeterTreeLinkWbsTree();
|
|
|
+ tree.setProjectId(dto.getProjectId());
|
|
|
+ tree.setContractId(dto.getContractId());
|
|
|
+ tree.setMeterTreeId(meterId);
|
|
|
+ tree.setWbsTreeId(wbsId);
|
|
|
+ tree.setPart(partMaps.get(wbsId));
|
|
|
+ list.add(tree);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ meterTreeLinkWbsTreeService.saveBatch(list);
|
|
|
+ return "一共关联"+list.size()+"条数据";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteLinkWbsTree(Map<String, String> map) {
|
|
|
+ if (StringUtils.isBlank(map.get("ids"))){
|
|
|
+ throw new ServiceException("请选择数据后再提交");
|
|
|
+ }
|
|
|
+ meterTreeLinkWbsTreeService.removeBatchByIds(Func.toLongList(map.get("ids")));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通过清单信息和合同计量单元节点,施工图数量,返回组装好的中间表对象
|
|
|
*/
|