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