Pārlūkot izejas kodu

中间计量申请,支付比例修改规则

qianxb 1 gadu atpakaļ
vecāks
revīzija
9858b587c8

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

@@ -109,7 +109,7 @@ public class InventoryFormApply extends BaseEntity {
     private Integer approveStatus;
 
     @ApiModelProperty(value = "最高支付比例")
-    private BigDecimal upPayRatio;
+    private BigDecimal payRatio;
 
     @ApiModelProperty(value = "支付金额")
     private BigDecimal PayMoney;

+ 3 - 0
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/entity/MiddleMeterApply.java

@@ -132,5 +132,8 @@ public class MiddleMeterApply extends BaseEntity {
     @ApiModelProperty(value = "审批状态,0未上报,1待审批,2已审批,3已废除")
     private Integer approveStatus;
 
+    @ApiModelProperty(value = "是否关联质检资料1是0否")
+    private Integer isLinkData;
+
 
 }

+ 5 - 2
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/vo/MeterInventoryVO.java

@@ -67,10 +67,13 @@ public class MeterInventoryVO {
     @ApiModelProperty(value = "最高支付比例")
     private BigDecimal upPayRatio;
 
+    @ApiModelProperty(value = "支付比例")
+    private BigDecimal payRatio;
+
     @ApiModelProperty(value = "最高支付金额")
     private BigDecimal upPayMoney;
 
-    @ApiModelProperty(value = "其他期支付金额")
-    private BigDecimal otherPayMoney;
+    @ApiModelProperty(value = "其他期支付比例")
+    private BigDecimal otherPayRatio;
 
 }

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

@@ -62,8 +62,8 @@
                0 as currentMeterTotal,0 as containChangeTotal,0 as currentMeterMoney,
                (IFNULL((select sum(current_meter_total) from s_inventory_form_apply where is_deleted = 0
                             and contract_meter_id = #{nodeId} and contract_form_id = cif.id),0)) as allMeterTotal,
-                (IFNULL((select sum(pay_money) from s_inventory_form_apply where is_deleted = 0
-                and contract_meter_id = #{nodeId} and contract_form_id = cif.id),0)) as otherPayMoney
+                (IFNULL((select sum(pay_ratio) from s_inventory_form_apply where is_deleted = 0
+                and contract_meter_id = #{nodeId} and contract_form_id = cif.id),0)) as otherPayRatio
         from s_contract_inventory_form  cif where contract_id = #{contractId} and is_deleted = 0 and is_form_node = 1
         AND id in
         <foreach collection="ids" item="id" open="(" separator="," close=")">
@@ -127,7 +127,7 @@
     </select>
     <select id="getForm" resultType="org.springblade.meter.vo.MeterInventoryVO">
         select ifa.id as taskDetailId,ifa.contract_form_id as id,ifa.form_number,ifa.form_name,ifa.current_price,ifa.build_picture_total as resolveTotal,
-               ifa.change_build_picture_total as changeTotal,ifa.up_pay_ratio as upPayRatio,
+               ifa.change_build_picture_total as changeTotal,ifa.pay_ratio as payRatio,
                ifa.current_meter_total as currentMeterTotal,0 as containChangeTotal,
                ifa.current_meter_money as currentMeterMoney,
                (select cif.change_total  from s_contract_inventory_form cif where cif.id = ifa.contract_form_id ) as contractChangeAllTotal,
@@ -137,10 +137,10 @@
                       and contract_meter_id = #{nodeId} and contract_form_id = ifa.contract_form_id and id != ifa.id),0)) as otherMeterTotal,
                (IFNULL((select sum(current_meter_total) from s_inventory_form_apply where is_deleted = 0
                       and contract_meter_id = #{nodeId} and contract_form_id = ifa.contract_form_id),0)) as allMeterTotal,
-               (IFNULL((select sum(pay_money) from s_inventory_form_apply where is_deleted = 0
-                      and contract_meter_id = #{nodeId} and contract_form_id = ifa.contract_form_id),0)) as otherPayMoney,
-               (select up_pay_money from s_inventory_form_meter ifm where ifm.is_deleted = 0
-                      and ifm.contract_meter_id = #{nodeId} and ifm.contract_form_id = ifa.contract_form_id) as upPayMoney
+               (IFNULL((select sum(pay_ratio) from s_inventory_form_apply where is_deleted = 0
+                      and contract_meter_id = #{nodeId} and contract_form_id = ifa.contract_form_id),0)) as otherPayRatio,
+               (select up_pay_ratio from s_inventory_form_meter where is_deleted = 0
+                      and contract_meter_id = #{nodeId} and contract_form_id = ifa.contract_form_id) as upPayRatio
         from s_inventory_form_apply ifa
         where ifa.contract_id = #{contractId} and ifa.is_deleted = 0
         AND ifa.middle_meter_id = #{id}

+ 69 - 30
blade-service/blade-meter/src/main/java/org/springblade/meter/service/impl/MiddleMeterApplyServiceImpl.java

@@ -124,7 +124,10 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
         //获取清单和分解信息
         List<Long> longs = Func.toLongList(ids);
         vos = baseMapper.getResolveFormInfo(contractId,nodeId,longs);
+        vos = vos.stream().filter(l-> !l.getAllMeterTotal().equals(l.getChangeTotal())).collect(Collectors.toList());
         for (MeterInventoryVO vo : vos) {
+            //默认分解清单的比例为0
+            vo.setPayRatio(new BigDecimal(0));
             //设置其他计量总数
             vo.setOtherMeterTotal(vo.getAllMeterTotal().subtract(vo.getCurrentMeterTotal()));
             //设置施工图数量是否大于合同数量
@@ -139,6 +142,21 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
     @Override
     @Transactional
     public void add(MiddleMeterApplyDTO dto) {
+        Long id = SnowFlakeUtil.getId();
+        //先保存附件,因为要判断是否关联
+        Integer isLinkData = 0;
+        List<AttachmentForm> fileList = dto.getFileList();
+        if (fileList != null && fileList.size() != 0) {
+            for (AttachmentForm file : fileList) {
+                if (isLinkData == 0  && file.getSelectId() != null){
+                    isLinkData = 1;
+                }
+                file.setProjectId(dto.getProjectId());
+                file.setContractId(dto.getContractId());
+                file.setMasterId(id);
+            }
+            attachmentFormService.saveBatch(fileList);
+        }
         //校验计量单元是否最底层节点
         Integer count = baseMapper.getNodeChild(dto.getContractId(),dto.getContractUnitId());
         if (count != 0){
@@ -157,10 +175,10 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
         dto.setMeterNumber(this.getMeterNumber(dto));
         //保存中间计量申请,设置计量金额为0,如果存在计量清单,则统计计量清单总金额
         MiddleMeterApply apply = new MiddleMeterApply();
-        Long id = SnowFlakeUtil.getId();
         dto.setId(id);
         BeanUtils.copyProperties(dto,apply);
         apply.setMeterMoney(null);
+        apply.setIsLinkData(isLinkData);
         //保存计量清单
         List<MeterInventoryVO> formList = dto.getFormList();
          if (formList.size() != 0){
@@ -198,14 +216,28 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
                 formApply.setCurrentPrice(l.getCurrentPrice());
                 formApply.setBuildPictureTotal(l.getResolveTotal());
                 formApply.setChangeBuildPictureTotal(l.getChangeTotal());
-                if (l.getCurrentMeterTotal() != null && l.getCurrentPrice() != null && l.getUpPayRatio() != null) {
+                if (l.getCurrentMeterTotal() != null && l.getCurrentPrice() != null) {
                     formApply.setCurrentMeterTotal(l.getCurrentMeterTotal());
                     formApply.setCurrentMeterMoney(l.getCurrentPrice().multiply(l.getCurrentMeterTotal()));
-                    formApply.setPayMoney(formApply.getCurrentMeterMoney().multiply(l.getUpPayRatio().divide(new BigDecimal(100))));
+
                 }else {
-                    throw new ServiceException("单价和计量数量和支付比例不能为空");
+                    throw new ServiceException("单价和计量数量不能为空");
                 }
-                formApply.setUpPayRatio(l.getUpPayRatio());
+                //校验比例是否在范围之内
+                if (l.getUpPayRatio() == null || l.getPayRatio() == null){
+                    throw new ServiceException("新增失败,支付比例不能为空");
+                }
+                if (apply.getIsLinkData() == 0) {
+                    if (l.getPayRatio().compareTo(BigDecimal.ZERO) < 0 || l.getPayRatio().add(l.getOtherPayRatio()).compareTo(l.getUpPayRatio()) > 0) {
+                        throw new ServiceException("新增失败,累计支付比例大于计量单元,计量单元比例:"+l.getUpPayRatio()+",其他期计量比例:"+l.getOtherPayRatio());
+                    }
+                }else {
+                    if (l.getPayRatio().compareTo(BigDecimal.ZERO) < 0 || l.getPayRatio().add(l.getOtherPayRatio()).compareTo(new BigDecimal(100)) > 0) {
+                        throw new ServiceException("新增失败,累计支付比例不能小于0大于100,其他期计量比例:"+l.getOtherPayRatio());
+                    }
+                }
+                formApply.setPayMoney(formApply.getCurrentMeterMoney().multiply(l.getUpPayRatio().divide(new BigDecimal(100))));
+                formApply.setPayRatio(l.getPayRatio());
                 return formApply;
             }).collect(Collectors.toList());
              for (InventoryFormApply formApply : formApplies) {
@@ -217,16 +249,6 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
              throw new ServiceException("请添加需要计量的清单");
          }
         this.save(apply);
-        //保存附件
-        List<AttachmentForm> fileList = dto.getFileList();
-        if (fileList != null && fileList.size() != 0) {
-            for (AttachmentForm file : fileList) {
-                file.setProjectId(dto.getProjectId());
-                file.setContractId(dto.getContractId());
-                file.setMasterId(id);
-            }
-            attachmentFormService.saveBatch(fileList);
-        }
 
     }
 
@@ -300,6 +322,22 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
     @Override
     @Transactional
     public void update2(MiddleMeterApplyDTO dto) {
+        //删除附件
+        attachmentFormService.deleteByMasterId(dto.getId());
+        //先保存附件,因为要判断是否关联
+        Integer isLinkData = 0;
+        List<AttachmentForm> fileList = dto.getFileList();
+        if (fileList != null && fileList.size() != 0) {
+            for (AttachmentForm file : fileList) {
+                if (isLinkData == 0  && file.getSelectId() != null){
+                    isLinkData = 1;
+                }
+                file.setProjectId(dto.getProjectId());
+                file.setContractId(dto.getContractId());
+                file.setMasterId(dto.getId());
+            }
+            attachmentFormService.saveBatch(fileList);
+        }
         //校验当前计量期是否已经上报
         ContractMeterPeriod period = contractMeterPeriodService.getById(dto.getContractPeriodId());
         if (period.getApproveStatus() != 0){
@@ -347,14 +385,27 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
                 formApply.setCurrentPrice(l.getCurrentPrice());
                 formApply.setBuildPictureTotal(l.getResolveTotal());
                 formApply.setChangeBuildPictureTotal(l.getChangeTotal());
-                if (l.getCurrentMeterTotal() != null && l.getCurrentPrice() != null && l.getUpPayRatio() != null) {
+                if (l.getCurrentMeterTotal() != null && l.getCurrentPrice() != null) {
                     formApply.setCurrentMeterTotal(l.getCurrentMeterTotal());
                     formApply.setCurrentMeterMoney(l.getCurrentPrice().multiply(l.getCurrentMeterTotal()));
-                    formApply.setPayMoney(formApply.getCurrentMeterMoney().multiply(l.getUpPayRatio().divide(new BigDecimal(100))));
                 }else {
                     throw new ServiceException("单价和计量数量和支付比例不能为空");
                 }
-                formApply.setUpPayRatio(l.getUpPayRatio());
+                //校验比例是否在范围之内
+                if (l.getUpPayRatio() == null || l.getPayRatio() == null){
+                    throw new ServiceException("新增失败,支付比例不能为空");
+                }
+                if (apply.getIsLinkData() == 0) {
+                    if (l.getPayRatio().compareTo(BigDecimal.ZERO) < 0 || l.getPayRatio().add(l.getOtherPayRatio()).compareTo(l.getUpPayRatio()) > 0) {
+                        throw new ServiceException("新增失败,累计支付比例大于计量单元,计量单元比例:"+l.getUpPayRatio()+",其他期计量比例:"+l.getOtherPayRatio());
+                    }
+                }else {
+                    if (l.getPayRatio().compareTo(BigDecimal.ZERO) < 0 || l.getPayRatio().add(l.getOtherPayRatio()).compareTo(new BigDecimal(100)) > 0) {
+                        throw new ServiceException("新增失败,累计支付比例不能小于0大于100,其他期计量比例:"+l.getOtherPayRatio());
+                    }
+                }
+                formApply.setPayMoney(formApply.getCurrentMeterMoney().multiply(l.getUpPayRatio().divide(new BigDecimal(100))));
+                formApply.setPayRatio(l.getPayRatio());
                 return formApply;
             }).collect(Collectors.toList());
             for (InventoryFormApply formApply : formApplies) {
@@ -364,18 +415,6 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
             inventoryFormApplyService.saveBatch(formApplies);
         }
         this.updateById(apply);
-        //删除附件
-        attachmentFormService.deleteByMasterId(dto.getId());
-        //保存附件
-        List<AttachmentForm> fileList = dto.getFileList();
-        if (fileList != null && fileList.size() != 0) {
-            for (AttachmentForm file : fileList) {
-                file.setProjectId(dto.getProjectId());
-                file.setContractId(dto.getContractId());
-                file.setMasterId(dto.getId());
-            }
-            attachmentFormService.saveOrUpdateBatch(fileList);
-        }
 
     }