Sfoglia il codice sorgente

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

yangyj 1 anno fa
parent
commit
3c95229449

+ 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 Integer upPayRatio;
+    private BigDecimal payRatio;
 
     @ApiModelProperty(value = "支付金额")
     private BigDecimal PayMoney;

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

@@ -79,7 +79,7 @@ public class InventoryFormMeter extends BaseEntity {
     private BigDecimal changeBuildPictureMoney;
 
     @ApiModelProperty(value = "最高支付比例")
-    private Integer upPayRatio;
+    private BigDecimal upPayRatio;
 
     @ApiModelProperty(value = "最高支付金额")
     private BigDecimal upPayMoney;

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

@@ -93,6 +93,6 @@ public class MeterTreeContract extends BaseEntity {
     private Integer isLock;
 
     @ApiModelProperty(value = "最高支付比例")
-    private Integer upPayRatio;
+    private BigDecimal upPayRatio;
 
 }

+ 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;
+
 
 }

+ 1 - 1
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/vo/ContractFromVO.java

@@ -109,7 +109,7 @@ public class ContractFromVO {
     private Integer citeStatus;
 
     @ApiModelProperty(value = "最高支付比例")
-    private Integer upPayRatio;
+    private BigDecimal upPayRatio;
 
     @ApiModelProperty(value = "最高支付比例金额")
     private BigDecimal upPayMoney;

+ 6 - 3
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/vo/MeterInventoryVO.java

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

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

@@ -29,9 +29,15 @@ 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.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.support.DefaultTransactionDefinition;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -49,6 +55,7 @@ public class MeterTreeController extends BladeController {
     private final MeterTreeContractService meterTreeContractService;
     private final IContractInventoryFormService contractInventoryFormService;
     private final IInventoryFormMeterService inventoryFormMeterService;
+    private final DataSourceTransactionManager transactionManager;
 
     @GetMapping("/template/detail")
     @ApiOperationSupport(order = 1)
@@ -620,10 +627,25 @@ public class MeterTreeController extends BladeController {
             }
         }
         if (ObjectUtil.isNotEmpty(dto.getDecompositionList()) && dto.getDecompositionList().size() > 0) {
+            //校验比例是否在范围之内
+            if (dto.getUpPayRatio() == null || dto.getUpPayRatio().compareTo(BigDecimal.ZERO) < 0 || dto.getUpPayRatio().compareTo(new BigDecimal("100")) > 0){
+                throw new ServiceException("修改失败,请检查支付比例是否在规定范围");
+            }
             /*最底层节点修改*/
             dto.setUpdateStatus(1); //编辑
-            boolean b1 = meterTreeContractService.updateById(dto);
-            boolean b2 = inventoryFormMeterService.updateInfo(dto.getDecompositionList(), dto.getId());
+            //控制层手动管理事务,判断未引用清单比例是否超过合同计量单元
+            TransactionDefinition def = new DefaultTransactionDefinition();
+            TransactionStatus status = transactionManager.getTransaction(def);
+            boolean b1 = false;
+            boolean b2 = false;
+            try {
+                b1 = meterTreeContractService.updateById(dto);
+                b2 = inventoryFormMeterService.updateInfo(dto.getDecompositionList(), dto.getId(),dto.getUpPayRatio());
+                transactionManager.commit(status);
+            }catch (Exception e){
+                transactionManager.rollback(status);
+                return R.fail(e.getMessage());
+            }
             if (b1 && b2) {
                 return R.success("操作成功");
             }

+ 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}

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

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

+ 11 - 2
blade-service/blade-meter/src/main/java/org/springblade/meter/service/impl/InventoryFormMeterServiceImpl.java

@@ -93,7 +93,7 @@ public class InventoryFormMeterServiceImpl extends BaseServiceImpl<InventoryForm
     }
 
     @Override
-    public boolean updateInfo(List<ContractFromVO> dataInfo,Long meterId) {
+    public boolean updateInfo(List<ContractFromVO> dataInfo,Long meterId, BigDecimal upPayRatio) {
         //统计施工图金额和变更后施工图金额
         BigDecimal b1 = BigDecimal.ZERO;
         BigDecimal b2 = BigDecimal.ZERO;
@@ -108,10 +108,19 @@ public class InventoryFormMeterServiceImpl extends BaseServiceImpl<InventoryForm
             if (vo.getCiteStatus() == 0 && formIsChange(meterId,vo.getContractFormId())){
                 throw new ServiceException("清单["+vo.getFormName()+"]已经变更或计量,请刷新页面");
             }
+            //校验比例是否在范围之内
+            if (vo.getUpPayRatio() == null || vo.getUpPayRatio().compareTo(BigDecimal.ZERO) < 0 || vo.getUpPayRatio().compareTo(new BigDecimal("100")) > 0){
+                throw new ServiceException("修改失败,请检查支付比例是否在规定范围");
+            }
+            if (vo.getCiteStatus() == 0){
+               if (upPayRatio.compareTo(vo.getUpPayRatio()) == -1){
+                   throw new ServiceException("修改失败,未引用的清单支付比例大于合同计量单元");
+               }
+            }
             //统计
             vo.setBuildPictureMoney(vo.getCurrentPrice().multiply(vo.getBuildPictureTotal()));
             vo.setChangeBuildPictureMoney(vo.getCurrentPrice().multiply(vo.getChangeBuildPictureTotal()));
-            vo.setUpPayMoney(vo.getChangeBuildPictureMoney().multiply(new BigDecimal(vo.getUpPayRatio()).divide(new BigDecimal(100))));
+            vo.setUpPayMoney(vo.getChangeBuildPictureMoney().multiply(vo.getUpPayRatio().divide(new BigDecimal(100))));
             b1 = b1.add(vo.getBuildPictureMoney());
             b2 = b2.add(vo.getChangeBuildPictureMoney());
             //修改,如果是已经被引用则跳过

+ 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(new BigDecimal(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(new BigDecimal(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);
-        }
 
     }