Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master' into master

yangyj 1 жил өмнө
parent
commit
794e401aae

+ 2 - 1
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/entity/MiddleMeterApply.java

@@ -135,5 +135,6 @@ public class MiddleMeterApply extends BaseEntity {
     @ApiModelProperty(value = "是否关联质检资料1是0否")
     private Integer isLinkData;
 
-
+    @ApiModelProperty(value = "是否自动计量生成1(自动批量计量生成)0(手动新增)")
+    private Integer isAutoBuild;
 }

+ 3 - 0
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/vo/MeterTreeContractVO.java

@@ -21,4 +21,7 @@ public class MeterTreeContractVO extends MeterTreeContract {
     @ApiModelProperty(value = "桩号类型名称")
     private String stakeTypeName;
 
+    @ApiModelProperty(value = "是否已经计量:0否1是")
+    private Integer isMeter;
+
 }

+ 4 - 0
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/vo/MeterTreeLinkWbsTreeVO.java

@@ -31,4 +31,8 @@ public class MeterTreeLinkWbsTreeVO {
 
     @ApiModelProperty(value = "wbs树pkeyId,字符串拼接")
     private String wbsTreeIds;
+
+    @ApiModelProperty(value = "wbs树pKeyId")
+    private String wbsTreeId2;
+
 }

+ 11 - 2
blade-service/blade-meter/src/main/java/org/springblade/meter/controller/MeterTreeController.java

@@ -55,6 +55,7 @@ public class MeterTreeController extends BladeController {
     private final IInventoryFormMeterService inventoryFormMeterService;
     private final DataSourceTransactionManager transactionManager;
     private final IMeterTreeLinkWbsTreeService meterTreeLinkWbsTreeService;
+    private final IMiddleMeterApplyService middleMeterApplyService;
 
     @GetMapping("/template/detail")
     @ApiOperationSupport(order = 1)
@@ -629,9 +630,8 @@ public class MeterTreeController extends BladeController {
             boolean b1 = false;
             boolean b2 = false;
             try {
-//                b1 = meterTreeContractService.updateById(dto);
                 b1 = meterTreeContractService.contractUpdate(dto);
-                b2 = inventoryFormMeterService.updateInfo(dto.getDecompositionList(), dto.getId(),dto.getUpPayRatio());
+                b2 = inventoryFormMeterService.updateInfo(dto);
                 transactionManager.commit(status);
             }catch (Exception e){
                 transactionManager.rollback(status);
@@ -701,6 +701,15 @@ public class MeterTreeController extends BladeController {
                     .eq(MeterTreeContract::getContractId, basicInfo.getContractId())
                     .eq(MeterTreeContract::getParentId, basicInfo.getId()));
             if (count == 0) {
+                //设置是否被计量
+                int total = Math.toIntExact(middleMeterApplyService.count(new LambdaQueryWrapper<MiddleMeterApply>()
+                        .eq(MiddleMeterApply::getContractId, basicInfo.getContractId())
+                        .eq(MiddleMeterApply::getContractUnitId, id)));
+                if (total == 0){
+                    vo.setIsMeter(0);
+                }else {
+                    vo.setIsMeter(1);
+                }
                 //设置清单
                 List<ContractFromVO> contrFormAllByContrId = contractInventoryFormService.getNodeResolveForm(basicInfo.getContractId(), basicInfo.getId());
                 vo.setDecompositionList(contrFormAllByContrId);

+ 2 - 0
blade-service/blade-meter/src/main/java/org/springblade/meter/mapper/MeterTreeContractMapper.java

@@ -42,4 +42,6 @@ public interface MeterTreeContractMapper extends BaseMapper<MeterTreeContract> {
     List<MeterTreeLinkWbsTreeVO> getAllLinkByContractId(@Param("contractId") Long contractId, @Param("ids") List<Long> meterIds);
 
     List<NodePartVO> getAllWbsNode(@Param("projectId") Long projectId,@Param("contractId") Long contractId);
+
+    List<MiddleMeterApply> getMiddleMeter(@Param("contractId") Long contractId, @Param("ids") List<Long> meterIds);
 }

+ 11 - 2
blade-service/blade-meter/src/main/java/org/springblade/meter/mapper/MeterTreeContractMapper.xml

@@ -53,6 +53,7 @@
                if((select count(1) from s_meter_tree_contract mtc2 where mtc2.project_id = #{projectId}
                     and mtc2.contract_id = #{contractId} and is_deleted = 0 and mtc2.parent_id = mtc1.id) = 0,'false','true') as hasChild
         from s_meter_tree_contract mtc1 where project_id = #{projectId} and contract_id = #{contractId} and is_deleted = 0
+        ORDER BY -mtc1.sort desc,mtc1.create_time
     </select>
     <select id="getWBSTree" resultType="org.springblade.meter.vo.MeterFullTreeVO">
         select p_key_id,id, if(full_name is null,node_name,full_name) as node_name,parent_id,
@@ -66,14 +67,13 @@
         select contract_name from m_contract_info where id = #{contractId}
     </select>
     <select id="getAllLinkByContractId" resultType="org.springblade.meter.vo.MeterTreeLinkWbsTreeVO">
-        select meter_tree_id,GROUP_CONCAT(wbs_tree_id) as wbsTreeIds
+        select meter_tree_id,wbs_tree_id,wbs_tree_id as wbsTreeId2
         from s_meter_tree_link_wbs_tree smtlwt1
         where contract_id = #{contractId}  and is_deleted = 0
         and meter_tree_id in
         <foreach item="id" collection="ids" open="(" close=")" separator=",">
             #{id}
         </foreach>
-        group by meter_tree_id
     </select>
     <select id="getAllWbsNode" resultType="org.springblade.meter.vo.NodePartVO">
         select p_key_id,id,parent_id,node_type,
@@ -81,6 +81,15 @@
         from m_wbs_tree_contract where project_id = #{projectId} and contract_id = #{contractId} and type = 1 and is_deleted = 0
         group by id
     </select>
+    <select id="getMiddleMeter" resultType="org.springblade.meter.entity.MiddleMeterApply">
+        select id ,contract_unit_id
+        from s_middle_meter_apply
+        where contract_id = #{contractId}  and is_deleted = 0
+        and contract_unit_id in
+        <foreach item="id" collection="ids" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
+    </select>
 
 
 </mapper>

+ 3 - 0
blade-service/blade-meter/src/main/java/org/springblade/meter/mapper/MiddleMeterApplyMapper.java

@@ -19,6 +19,7 @@ package org.springblade.meter.mapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.apache.ibatis.annotations.Param;
 import org.springblade.business.entity.InformationQuery;
+import org.springblade.business.entity.Task;
 import org.springblade.manager.entity.ContractInfo;
 import org.springblade.manager.entity.WbsTreeContract;
 import org.springblade.meter.dto.WbsNodeDTO;
@@ -108,5 +109,7 @@ public interface MiddleMeterApplyMapper extends BaseMapper<MiddleMeterApply> {
 
     List<InventoryFormMeterVO> getAllFormMeter(@Param("contractId")Long contractId,@Param("ids") List<Long> meterIds);
 
+    Task getTaskInfo(@Param("contractId")Long contractId,@Param("id") Long id);
 
+    Integer getWbsLinkFileTotal(@Param("contractId")Long contractId,@Param("id") Long id);
 }

+ 7 - 2
blade-service/blade-meter/src/main/java/org/springblade/meter/mapper/MiddleMeterApplyMapper.xml

@@ -335,7 +335,7 @@
                (select GROUP_CONCAT(ifm.contract_form_id) from s_inventory_form_meter ifm
                     where ifm.contract_id = #{contractId} and smtc.id = ifm.contract_meter_id and ifm.is_deleted = 0) as linkForm,
                (select GROUP_CONCAT(mma.id) from s_middle_meter_apply mma
-                    where mma.contract_id = #{contractId} and smtc.id = mma.contract_unit_id and mma.is_deleted = 0) as linkMiddle
+                    where mma.contract_id = #{contractId} and mma.contract_period_id = #{periodId} and smtc.id = mma.contract_unit_id and mma.is_deleted = 0) as linkMiddle
         from s_meter_tree_contract smtc where contract_id = #{contractId} and is_auto_meter = 1 and is_deleted = 0
     </select>
     <select id="getAllLinkWbsInfo" resultType="org.springblade.meter.vo.MeterLinkWbsInfoVO">
@@ -371,7 +371,12 @@
             #{id}
         </foreach>
     </select>
-
+    <select id="getTaskInfo" resultType="org.springblade.business.entity.Task">
+        select * from u_task WHERE contract_id = #{contractId} and  form_data_id = id and is_deleted = 0
+    </select>
+    <select id="getWbsLinkFileTotal" resultType="java.lang.Integer">
+        select count(1) from s_attachment_form where contract_id = #{contractId} and master_id = #{id} and select_id is not null and is_deleted = 0
+    </select>
 
 
 </mapper>

+ 2 - 1
blade-service/blade-meter/src/main/java/org/springblade/meter/service/IInventoryFormMeterService.java

@@ -17,6 +17,7 @@
 package org.springblade.meter.service;
 
 import org.springblade.core.tool.api.R;
+import org.springblade.meter.dto.MeterTreeContractDTO;
 import org.springblade.meter.entity.InventoryFormMeter;
 import org.springblade.core.mp.base.BaseService;
 import org.springblade.meter.vo.ContractFromVO;
@@ -42,7 +43,7 @@ public interface IInventoryFormMeterService extends BaseService<InventoryFormMet
     R inventoryFormMeterService(String meterId, String formIds);
 
     // 修改信息
-    boolean updateInfo(List<ContractFromVO> dataInfo, Long meterId, BigDecimal upPayRatio);
+    boolean updateInfo(MeterTreeContractDTO dto);
 
     /**
      * 删除 同合计量 清单

+ 9 - 1
blade-service/blade-meter/src/main/java/org/springblade/meter/service/impl/InventoryFormMeterServiceImpl.java

@@ -26,6 +26,7 @@ import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.ObjectUtil;
 import org.springblade.manager.entity.WbsTree;
+import org.springblade.meter.dto.MeterTreeContractDTO;
 import org.springblade.meter.entity.*;
 import org.springblade.meter.mapper.InventoryFormMeterMapper;
 import org.springblade.meter.service.IChangeTokenInventoryService;
@@ -87,7 +88,11 @@ public class InventoryFormMeterServiceImpl extends BaseServiceImpl<InventoryForm
     }
 
     @Override
-    public boolean updateInfo(List<ContractFromVO> dataInfo,Long meterId, BigDecimal upPayRatio) {
+    public boolean updateInfo(MeterTreeContractDTO dto) {
+        List<ContractFromVO> dataInfo = dto.getDecompositionList();
+        Long meterId = dto.getId();
+        BigDecimal upPayRatio = dto.getUpPayRatio();
+        Integer isAutoMeter = dto.getIsAutoMeter();
         //统计施工图金额和变更后施工图金额
         BigDecimal b1 = BigDecimal.ZERO;
         BigDecimal b2 = BigDecimal.ZERO;
@@ -113,6 +118,9 @@ public class InventoryFormMeterServiceImpl extends BaseServiceImpl<InventoryForm
             //统计
             vo.setBuildPictureMoney(vo.getCurrentPrice().multiply(vo.getBuildPictureTotal()));
             vo.setChangeBuildPictureMoney(vo.getCurrentPrice().multiply(vo.getChangeBuildPictureTotal()));
+            if (isAutoMeter == 1){
+                vo.setUpPayRatio(null);
+            }
 //            vo.setUpPayMoney(vo.getChangeBuildPictureMoney().multiply(vo.getUpPayRatio().divide(new BigDecimal(100))));
             b1 = b1.add(vo.getBuildPictureMoney());
             b2 = b2.add(vo.getChangeBuildPictureMoney());

+ 27 - 5
blade-service/blade-meter/src/main/java/org/springblade/meter/service/impl/MeterTreeContractServiceImpl.java

@@ -1792,24 +1792,24 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
                     .eq(MeterTreeContract::getContractId,dto.getContractId())
                     .ne(MeterTreeContract::getId, dto.getId()));
             if (count > 0){
-                throw new ServiceException("修改失败,当前工程编号已经存在");
+                throw new ServiceException("当前工程编号已经存在");
             }
         }
         //校验如果为混泥土节点
         if (dto.getIsConcreteNode() == 1){
             if ( (dto.getSevenRatio() == null || dto.getTwentyEightRatio() == null)) {
-                throw new ServiceException("修改失败,混泥土节点必须填写强度比例");
+                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范围内");
+                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("修改失败,请检查支付比例是否在规定范围");
+            throw new ServiceException("请检查支付比例是否在规定范围");
         }
         //如果计算式有值,就同步去修改所有中间计量申请的
         if (StringUtils.isNotBlank(dto.getCalculateFormula())){
@@ -1870,6 +1870,12 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
         List<MeterTreeLinkWbsTree> list = new ArrayList<>();
         //转换为id集合
         List<Long> meterIds = Func.toLongList(dto.getMeterIds());
+        //校验节点是否已经计量过,已经计量过的节点不允许再关联
+        List<MiddleMeterApply> applyList = baseMapper.getMiddleMeter(dto.getContractId(),meterIds);
+        if (applyList.size() > 0){
+            MeterTreeContract treeContract = this.getById(applyList.get(0).getContractUnitId());
+            throw new ServiceException("节点("+treeContract.getNodeName()+")已经被计量过,不能再关联WBS节点,请修改后再关联");
+        }
         List<Long> wbsIds = Func.toLongList(dto.getWbsIds());
         //根据合同段查询出WBS树所有树节点,用于生成分项部位
         List<NodePartVO> wbsNodes = baseMapper.getAllWbsNode(dto.getProjectId(),dto.getContractId());
@@ -1917,7 +1923,13 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
         Map<Long, String> map = new HashMap<>();
         if (linkList.size() > 0){
             isLinkInfo = false;
-            map = linkList.stream().collect(Collectors.toMap(l -> l.getMeterTreeId(), l -> l.getWbsTreeIds()));
+            map = linkList.stream().collect(Collectors.groupingBy(
+                    MeterTreeLinkWbsTreeVO::getMeterTreeId,
+                    Collectors.mapping(
+                            MeterTreeLinkWbsTreeVO::getWbsTreeId2,
+                            Collectors.joining(",")
+                    )
+            ));
         }
         //循环
         for (Long meterId : meterIds) {
@@ -1943,6 +1955,16 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
         if (StringUtils.isBlank(map.get("ids"))){
             throw new ServiceException("请选择数据后再提交");
         }
+        if (StringUtils.isBlank(map.get("nodeId"))){
+            throw new ServiceException("未传入节点id");
+        }
+        List<Long> meterIds = Func.toLongList(map.get("nodeId"));
+        MeterTreeContract treeContract = this.getById(meterIds.get(0));
+        //校验节点是否已经计量过,已经计量过的节点不允许再关联
+        List<MiddleMeterApply> applyList = baseMapper.getMiddleMeter(treeContract.getContractId(),meterIds);
+        if (applyList.size() > 0){
+            throw new ServiceException("节点("+treeContract.getNodeName()+")已经被计量过,不能取消关联");
+        }
         meterTreeLinkWbsTreeService.removeBatchByIds(Func.toLongList(map.get("ids")));
     }
 

+ 97 - 10
blade-service/blade-meter/src/main/java/org/springblade/meter/service/impl/MiddleMeterApplyServiceImpl.java

@@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.models.auth.In;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.StringUtils;
 import org.springblade.business.entity.InformationQuery;
@@ -131,11 +132,46 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
         if (StringUtils.isBlank(ids) || nodeId == null){
             return vos;
         }
-        //获取清单和分解信息
+        //获取所以清单和分解信息
         List<Long> longs = Func.toLongList(ids);
         vos = baseMapper.getResolveFormInfo(contractId,nodeId,longs);
-        vos = vos.stream().filter(l-> !l.getAllMeterTotal().equals(l.getChangeTotal()) && l.getChangeTotal().compareTo(BigDecimal.ZERO) != 0)
-                            .collect(Collectors.toList());
+        if (vos.size() == 0){
+            return vos;
+        }
+        //获取节点信息
+        MeterTreeContract treeContract = meterTreeContractService.getById(nodeId);
+        //如果是自动计量节点,则直接使用后管设置的支付比例
+        if (treeContract.getIsAutoMeter() == 1){
+            MeterContractInfo one = meterContractInfoService.getOne(new LambdaQueryWrapper<MeterContractInfo>()
+                    .eq(MeterContractInfo::getContractId, treeContract.getContractId()));
+            if (one == null || one.getMiddlePayRatio() == null){
+                throw new ServiceException("合同段未配置支付比例,新增自动计量节点的计量单,必须先设置支付比例");
+            }
+            vos.stream().forEach(l->l.setUpPayRatio(one.getMiddlePayRatio()));
+
+        }
+        //过滤没有计量数量的清单
+        vos = vos.stream().filter(l->{
+            //变更后数量不能为0
+            if (l.getChangeTotal().compareTo(BigDecimal.ZERO) == 0){
+                return false;
+            }
+            //有比例,则判断 当前已计量数量 是否大于等于 比例*变更后数量
+            if (l.getUpPayRatio() != null){
+                if (l.getAllMeterTotal().compareTo(l.getChangeTotal().multiply(l.getUpPayRatio()).divide(new BigDecimal(100))) >= 0){
+                    return false;
+                }else {
+                    return true;
+                }
+            }else {
+                //没有比例,直接判断已计量数量是否大于等于变更后数量
+                if (l.getAllMeterTotal().compareTo(l.getChangeTotal()) >= 0){
+                    return false;
+                }else {
+                    return true;
+                }
+            }
+        }).collect(Collectors.toList());
         for (MeterInventoryVO vo : vos) {
             //如果合同计量单元填写了比例,则默认分解清单的比例为0
             if (vo.getUpPayRatio() != null) {
@@ -145,7 +181,7 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
             vo.setOtherMeterTotal(vo.getAllMeterTotal().subtract(vo.getCurrentMeterTotal()));
             vo.setOtherPayRatio(vo.getOtherMeterTotal().divide(vo.getChangeTotal(), 4, RoundingMode.DOWN).multiply(new BigDecimal(100)).setScale(2));
             //设置施工图数量是否大于合同数量
-            vo.setIsBuildThanContract(vo.getChangeTotal().compareTo(vo.getContractChangeAllTotal()) == 1?1:0);
+            vo.setIsBuildThanContract(vo.getChangeTotal().compareTo(vo.getContractChangeAllTotal()) == 1 ? 1 : 0);
         }
         return vos;
     }
@@ -265,6 +301,19 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
              throw new ServiceException("请添加需要计量的清单");
          }
         this.save(apply);
+         if (StringUtils.isNotBlank(apply.getCalculateFormula())) {
+             //如果存在计算式,每次同步修改所有期的当前节点计算式
+             this.update(new LambdaUpdateWrapper<MiddleMeterApply>()
+                    .eq(MiddleMeterApply::getContractId,dto.getContractId())
+                    .eq(MiddleMeterApply::getContractUnitId,dto.getContractUnitId())
+                    .set(MiddleMeterApply::getCalculateFormula,dto.getCalculateFormula()));
+             //再同步修改合同计量单元当前节点的计算式
+             meterTreeContractService.update(new LambdaUpdateWrapper<MeterTreeContract>()
+                    .eq(MeterTreeContract::getId,dto.getContractUnitId())
+                    .set(MeterTreeContract::getCalculateFormula,dto.getCalculateFormula()));
+
+         }
+
 
     }
 
@@ -343,14 +392,16 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
             throw new ServiceException("修改失败,不能删除所有计量清单");
         }
         //删除附件
+        int total = baseMapper.getWbsLinkFileTotal(dto.getContractId(),dto.getId());
         attachmentFormService.deleteByMasterId(dto.getId());
         //先保存附件,因为要判断是否关联
         Integer isLinkData = 0;
+        Integer linkTotal = 0;
         List<AttachmentForm> fileList = dto.getFileList();
         if (fileList != null && fileList.size() != 0) {
             for (AttachmentForm file : fileList) {
-                if (isLinkData == 0  && file.getSelectId() != null){
-                    isLinkData = 1;
+                if (file.getSelectId() != null){
+                    linkTotal++;
                 }
                 file.setProjectId(dto.getProjectId());
                 file.setContractId(dto.getContractId());
@@ -358,10 +409,21 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
             }
             attachmentFormService.saveBatch(fileList);
         }
+        if (linkTotal > 0){
+            isLinkData = 1;
+        }
+        //获取计量单信息,判断是否为自动生成
+        MiddleMeterApply meterApply = this.getById(dto.getId());
+        //为自动生成,则获取附件的selectId逗号拼接,判断是否全部存在于当前附件
+        if (meterApply.getIsAutoBuild() == 1){
+            if (linkTotal != total){
+                throw new ServiceException("修改失败:不允许删除关联WBS节点的附件");
+            }
+        }
         //校验当前计量期是否已经上报
         ContractMeterPeriod period = contractMeterPeriodService.getById(dto.getContractPeriodId());
         if (period.getApproveStatus() != 0){
-            throw new ServiceException("修改失败,当前计量期已经上报或审批");
+            throw new ServiceException("修改失败当前计量期已经上报或审批");
         }
         //保存中间计量申请,设置计量金额为0,如果存在计量清单,则统计计量清单总金额
         MiddleMeterApply apply = new MiddleMeterApply();
@@ -438,6 +500,18 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
             inventoryFormApplyService.saveBatch(formApplies);
         }
         this.updateById(apply);
+        if (StringUtils.isNotBlank(apply.getCalculateFormula())) {
+            //如果存在计算式,每次同步修改所有期的当前节点计算式
+            this.update(new LambdaUpdateWrapper<MiddleMeterApply>()
+                    .eq(MiddleMeterApply::getContractId,dto.getContractId())
+                    .eq(MiddleMeterApply::getContractUnitId,dto.getContractUnitId())
+                    .set(MiddleMeterApply::getCalculateFormula,dto.getCalculateFormula()));
+            //再同步修改合同计量单元当前节点的计算式
+            meterTreeContractService.update(new LambdaUpdateWrapper<MeterTreeContract>()
+                    .eq(MeterTreeContract::getId,dto.getContractUnitId())
+                    .set(MeterTreeContract::getCalculateFormula,dto.getCalculateFormula()));
+
+        }
 
     }
 
@@ -718,8 +792,10 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
         }
         List<String> list = vos.stream().map(l -> l.getId()+"").collect(Collectors.toList());
         String join = String.join(",", list);
+        //获取符合条件的分解清单
         voList = this.addResolveForm(apply.getContractId(), apply.getContractUnitId(), join);
         if (voList.size() > 1){
+            //按照合同计量单元部位排序
             Map<String, MeterInventoryVO> map = voList.stream().collect(Collectors.toMap(MeterInventoryVO::getFormNumber, l -> l));
             List<String> list2 = inventoryFormService.getAllFormNumberBySort(apply.getContractId());
             for (String s : map.keySet()) {
@@ -885,6 +961,16 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
         if (apply == null){
             throw new ServiceException("未找到中间计量申请信息");
         }
+        //查询查询当前计量期信息
+        ContractMeterPeriod period = contractMeterPeriodService.getById(apply.getContractPeriodId());
+        if (period == null){
+            throw new ServiceException("未找到当前计量期信息");
+        }
+        //获取任务信息
+        Task task = baseMapper.getTaskInfo(apply.getContractId(),period.getId());
+        if (task == null){
+            throw new ServiceException("未找到任务信息");
+        }
         //根据文件id,查询出queryInfo数据
         if (StringUtils.isBlank(fileIds)){
             throw new ServiceException("请选择关联资料");
@@ -1073,8 +1159,8 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
                 }
                 //末尾拼接所有WBS节点,所有计量节点
                 str.append(vo2.getLinkWbs()+",");
-                str2.append(vo2.getId());
-                str3.append(vo2.getLinkForm());
+                str2.append(vo2.getId()+",");
+                str3.append(vo2.getLinkForm()+",");
 
             }
             if (voList.size() == 0 || StringUtils.isBlank(str.toString()) || StringUtils.isBlank(str2.toString()) || StringUtils.isBlank(str3.toString())){
@@ -1111,7 +1197,7 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
             //查询出当前计量期所有未删除的计量单,如果不为空,则过滤出最大后缀
             List<MiddleMeterApply> applyList = this.list(new LambdaQueryWrapper<MiddleMeterApply>()
                     .eq(MiddleMeterApply::getContractId, contractId)
-                    .eq(MiddleMeterApply::getContractPeriodId, period));
+                    .eq(MiddleMeterApply::getContractPeriodId, periodId));
             //获取当前计量期所有已经计量的数量(),用于生成计量单编号
             if (applyList.size() == 0){
                 count = 1;
@@ -1212,6 +1298,7 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
                 apply.setMeterMoney(total);
                 apply.setCalculateFormula(vo2.getCalculateFormula());
                 apply.setIsLinkData(1);
+                apply.setIsAutoBuild(1);
                 //添加到计量单集合
                 middleMeterApplyAdd.add(apply);
                 count++;