Browse Source

合同计量单元-增加比例校验

qianxb 1 year ago
parent
commit
6fdda392bc

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

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

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

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

+ 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("操作成功");
             }

+ 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());
             //修改,如果是已经被引用则跳过

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

@@ -201,7 +201,7 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
                 if (l.getCurrentMeterTotal() != null && l.getCurrentPrice() != null && l.getUpPayRatio() != 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))));
+                    formApply.setPayMoney(formApply.getCurrentMeterMoney().multiply(l.getUpPayRatio().divide(new BigDecimal(100))));
                 }else {
                     throw new ServiceException("单价和计量数量和支付比例不能为空");
                 }
@@ -350,7 +350,7 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
                 if (l.getCurrentMeterTotal() != null && l.getCurrentPrice() != null && l.getUpPayRatio() != 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))));
+                    formApply.setPayMoney(formApply.getCurrentMeterMoney().multiply(l.getUpPayRatio().divide(new BigDecimal(100))));
                 }else {
                     throw new ServiceException("单价和计量数量和支付比例不能为空");
                 }