Browse Source

材料调差新增

qianxb 7 months ago
parent
commit
ae5542835a

+ 26 - 0
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/dto/ContractMaterialAdjustAddDTO.java

@@ -0,0 +1,26 @@
+package org.springblade.meter.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springblade.meter.entity.AttachmentForm;
+import org.springblade.meter.entity.ContractMaterialAdjust;
+import org.springblade.meter.entity.ContractMaterialAdjustDetail;
+
+import java.util.List;
+
+/**
+ * @Param
+ * @Author wangwl
+ * @Date 2024/4/24 10:54
+ **/
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ContractMaterialAdjustAddDTO extends ContractMaterialAdjust {
+
+    @ApiModelProperty(value = "材料明细集合")
+    private List<ContractMaterialAdjustDetail> details;
+
+    @ApiModelProperty(value = "附件集合")
+    private List<AttachmentForm> files;
+}

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

@@ -81,10 +81,10 @@ public class AttachmentForm extends BaseEntity {
     private Long selectId;
 
     @ApiModelProperty(value = "文件后缀")
-    private Long fileSuffix;
+    private String fileSuffix;
 
     @ApiModelProperty(value = "文件大小名称")
-    private Long fileSizeName;
+    private String fileSizeName;
 
 
 }

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

@@ -21,9 +21,12 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import org.springblade.core.mp.base.BaseEntity;
+import org.springframework.format.annotation.DateTimeFormat;
 
+import javax.validation.constraints.NotNull;
 import java.math.BigDecimal;
 import java.time.LocalDate;
+import java.time.YearMonth;
 
 /**
  * 合同材料表实体类
@@ -42,38 +45,53 @@ public class ContractMaterialAdjust extends BaseEntity {
      * 项目id
      */
     @ApiModelProperty(value = "项目id")
+    @NotNull(message = "请传入项目id!")
     private Long projectId;
     /**
      * 合同段id
      */
     @ApiModelProperty(value = "合同段id")
+    @NotNull(message = "请传入合同段id!")
     private Long contractId;
 
     @ApiModelProperty(value = "合同材料id")
+    @NotNull(message = "请传入合同材料id!")
     private Long contractMaterialId;
 
     @ApiModelProperty(value = "合同计量期id(调差期)")
+    @NotNull(message = "请传入调差期id!")
     private Long contractPeriodId;
 
     @ApiModelProperty(value = "调差月份")
-    private LocalDate adjustMonth;
+    @NotNull(message = "请填写调差月份!")
+    private String adjustMonth;
 
     @ApiModelProperty(value = "材料名称")
+    @NotNull(message = "请传入材料名称!")
     private String materialName;
 
     @ApiModelProperty(value = "材料基准价格")
+    @NotNull(message = "请传入材料基准价格!")
     private BigDecimal materialPrice;
 
+    @ApiModelProperty(value = "价格有效期id")
+    @NotNull(message = "请传入材料价格有效期id!")
+    private Long materialValidityId;
+
     @ApiModelProperty(value = "实时价格id")
+    @NotNull(message = "请传入材料实时价格id!")
     private Long currentPriceId;
 
     @ApiModelProperty(value = "实时价格")
+    @NotNull(message = "请传入材料实时价格!")
     private BigDecimal currentPrice;
 
     @ApiModelProperty(value = "价差幅度,百分比")
+    @NotNull(message = "请传入价差幅度!")
     private BigDecimal rangePriceRatio;
 
     @ApiModelProperty(value = "材料数量")
+    @NotNull(message = "请填写材料数量!")
     private BigDecimal materialTotal;
 
     @ApiModelProperty(value = "调差金额")

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

@@ -49,6 +49,9 @@ public class ContractMaterialAdjustDetail extends BaseEntity {
     @ApiModelProperty(value = "合同段id")
     private Long contractId;
 
+    @ApiModelProperty(value = "材料调差单id")
+    private Long materialAdjustId;
+
     @ApiModelProperty(value = "合同材料id")
     private Long contractMaterialId;
 
@@ -56,7 +59,7 @@ public class ContractMaterialAdjustDetail extends BaseEntity {
     private Long middleMeterId;
 
     @ApiModelProperty(value = "计量单编号")
-    private Long meterNumber;
+    private String meterNumber;
 
     @ApiModelProperty(value = "合同工程清单id")
     private Long contractFormId;

+ 12 - 0
blade-service/blade-meter/src/main/java/org/springblade/meter/controller/ContractMaterialAdjustController.java

@@ -27,8 +27,11 @@ import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
+import org.springblade.meter.dto.ContractMaterialAdjustAddDTO;
 import org.springblade.meter.entity.AttachmentForm;
+import org.springblade.meter.entity.ContractMaterial;
 import org.springblade.meter.service.IAttachmentFormService;
+import org.springblade.meter.service.IContractMaterialAdjustService;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
@@ -45,5 +48,14 @@ import javax.validation.Valid;
 @Api(value = "材料调差", tags = "材料调差接口")
 public class ContractMaterialAdjustController extends BladeController {
 
+    private final IContractMaterialAdjustService adjustService;
+
+    @PostMapping("/add")
+    @ApiOperationSupport(order = 1)
+    @ApiOperation(value = "新增", notes = "传入材料调差单")
+    public R submit(@Valid @RequestBody ContractMaterialAdjustAddDTO dto) {
+        adjustService.add(dto);
+        return R.success("新增成功");
+    }
 	
 }

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

@@ -17,6 +17,7 @@
 package org.springblade.meter.service;
 
 import org.springblade.core.mp.base.BaseService;
+import org.springblade.meter.dto.ContractMaterialAdjustAddDTO;
 import org.springblade.meter.entity.AttachmentForm;
 import org.springblade.meter.entity.ContractMaterialAdjust;
 
@@ -31,4 +32,5 @@ import java.util.Set;
 public interface IContractMaterialAdjustService extends BaseService<ContractMaterialAdjust> {
 
 
+    void add(ContractMaterialAdjustAddDTO dto);
 }

+ 67 - 0
blade-service/blade-meter/src/main/java/org/springblade/meter/service/impl/ContractMaterialAdjustServiceImpl.java

@@ -16,15 +16,28 @@
  */
 package org.springblade.meter.service.impl;
 
+import lombok.AllArgsConstructor;
+import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springblade.meter.dto.ContractMaterialAdjustAddDTO;
 import org.springblade.meter.entity.AttachmentForm;
 import org.springblade.meter.entity.ContractMaterialAdjust;
+import org.springblade.meter.entity.ContractMaterialAdjustDetail;
+import org.springblade.meter.entity.ContractMaterialValidity;
 import org.springblade.meter.mapper.AttachmentFormMapper;
 import org.springblade.meter.mapper.ContractMaterialAdjustMapper;
 import org.springblade.meter.service.IAttachmentFormService;
+import org.springblade.meter.service.IContractMaterialAdjustDetailService;
 import org.springblade.meter.service.IContractMaterialAdjustService;
+import org.springblade.meter.service.IContractMaterialValidityService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
 import java.util.Set;
 
 /**
@@ -34,7 +47,61 @@ import java.util.Set;
  * @since 2023-11-29
  */
 @Service
+@AllArgsConstructor
 public class ContractMaterialAdjustServiceImpl extends BaseServiceImpl<ContractMaterialAdjustMapper, ContractMaterialAdjust> implements IContractMaterialAdjustService {
 
+    private final IContractMaterialValidityService validityService;
 
+    private final IContractMaterialAdjustDetailService adjustDetailService;
+
+    private final IAttachmentFormService attachmentFormService;
+
+    @Override
+    @Transactional
+    public void add(ContractMaterialAdjustAddDTO dto) {
+        //获取材料有效期
+        ContractMaterialValidity validity = validityService.getById(dto.getMaterialValidityId());
+        /*保存材料调差单*/
+        ContractMaterialAdjust adjust = new ContractMaterialAdjust();
+        BeanUtils.copyProperties(dto,adjust);
+        adjust.setId(SnowFlakeUtil.getId());
+        //计算调差金额,生成计算式
+        StringBuilder str = new StringBuilder("调差价格依据于:"+dto.getMaterialName()+
+                "("+validity.getStartDate().format(DateTimeFormatter.ofPattern("yyyyMMdd"))+"至"+
+                validity.getEndDate().format(DateTimeFormatter.ofPattern("yyyyMMdd"))+")\n");
+        BigDecimal adjustMoney;
+        BigDecimal price = dto.getMaterialPrice();
+        BigDecimal currentPrice = dto.getCurrentPrice();
+        if (price.compareTo(currentPrice) == 1){
+            //市场价低于基准价
+            adjustMoney = dto.getMaterialTotal().multiply(currentPrice.subtract((price.multiply(new BigDecimal(1).add(dto.getRangePriceRatio().abs().divide(new BigDecimal(100))))))).multiply(new BigDecimal(1.09)).setScale(2, RoundingMode.DOWN);
+            str.append("调差公式(标准):调增金额=调差数量×[市场价-基准价×(1-风险幅度差%)]×(1+合同增值税税率)\n");
+            str.append("调差公式(计算):"+adjustMoney+"="+dto.getMaterialTotal()+"*["+currentPrice+"-"+price+"*(1+"+dto.getRangePriceRatio().abs()+"%)]*(1+9.0/100)");
+        }else {
+            //市场价高于基准价
+            adjustMoney = dto.getMaterialTotal().multiply(currentPrice.subtract((price.multiply(new BigDecimal(1).add(dto.getRangePriceRatio().divide(new BigDecimal(100))))))).multiply(new BigDecimal(1.09)).setScale(2, RoundingMode.DOWN);
+            str.append("调差公式(标准):调增金额=调差数量×[市场价-基准价×(1+风险幅度差%)]×(1+合同增值税税率)\n");
+            str.append("调差公式(计算):"+adjustMoney+"="+dto.getMaterialTotal()+"*["+currentPrice+"-"+price+"*(1-"+dto.getRangePriceRatio()+"%)]*(1+9.0/100)");
+        }
+        adjust.setAdjustMoney(adjustMoney);
+        adjust.setAdjustCalculation(str.toString());
+        this.save(adjust);
+
+        /*保存材料明细*/
+        List<ContractMaterialAdjustDetail> details = dto.getDetails();
+        if (details.size() != 0){
+            for (ContractMaterialAdjustDetail detail : details) {
+                detail.setMaterialAdjustId(adjust.getId());
+            }
+            adjustDetailService.saveBatch(details);
+        }
+        /*保存附件信息*/
+        List<AttachmentForm> files = dto.getFiles();
+        if (files.size() != 0){
+            for (AttachmentForm file : files) {
+                file.setMasterId(adjust.getId());
+            }
+            attachmentFormService.saveBatch(files);
+        }
+    }
 }