|
@@ -16,20 +16,21 @@
|
|
|
*/
|
|
|
package org.springblade.meter.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
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.dto.ContractMaterialDTO2;
|
|
|
+import org.springblade.meter.entity.*;
|
|
|
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.springblade.meter.service.*;
|
|
|
+import org.springblade.meter.vo.ContractMaterialAdjustVO;
|
|
|
+import org.springblade.meter.vo.MaterialAdjustDetailVO;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -39,6 +40,7 @@ import java.math.RoundingMode;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 附件表 服务实现类
|
|
@@ -56,6 +58,8 @@ public class ContractMaterialAdjustServiceImpl extends BaseServiceImpl<ContractM
|
|
|
|
|
|
private final IAttachmentFormService attachmentFormService;
|
|
|
|
|
|
+ private final IInventoryFormMaterialService formMaterialService;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void add(ContractMaterialAdjustAddDTO dto) {
|
|
@@ -104,4 +108,103 @@ public class ContractMaterialAdjustServiceImpl extends BaseServiceImpl<ContractM
|
|
|
attachmentFormService.saveBatch(files);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ContractMaterialAdjustDetail> getMaterialDetail(ContractMaterialDTO2 dto) {
|
|
|
+ //1 获取所有材料关联的清单,如果没有则提示
|
|
|
+ List<InventoryFormMaterial> formMaterials = formMaterialService.list(new LambdaQueryWrapper<InventoryFormMaterial>()
|
|
|
+ .eq(InventoryFormMaterial::getContractMaterialId, dto.getContractMaterialId()));
|
|
|
+ if (formMaterials.size() == 0){
|
|
|
+ throw new ServiceException("当前材料并未关联清单");
|
|
|
+ }
|
|
|
+ List<Long> formIds = formMaterials.stream().map(l -> l.getContractFormId()).collect(Collectors.toList());
|
|
|
+ //2 获取当前计量期下,包含当前清单的所有计量单
|
|
|
+ List<ContractMaterialAdjustDetail> list = baseMapper.getMaterialDetail(dto,formIds);
|
|
|
+ for (ContractMaterialAdjustDetail detail : list) {
|
|
|
+ detail.setContractMaterialId(dto.getContractMaterialId());
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<ContractMaterialAdjustVO> page2(ContractMaterialDTO2 dto) {
|
|
|
+ if (dto.getContractId() == null || dto.getContractPeriodId() == null){
|
|
|
+ throw new ServiceException("请传入合同id和调差期id");
|
|
|
+ }
|
|
|
+ IPage<ContractMaterialAdjustVO> iPage = new Page<>(dto.getCurrent(),dto.getSize());
|
|
|
+ return baseMapper.page2(iPage,dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MaterialAdjustDetailVO detail(Long id) {
|
|
|
+ //获取材料调差单数据
|
|
|
+ MaterialAdjustDetailVO vo = baseMapper.detail(id);
|
|
|
+ //获取材料详情
|
|
|
+ List<ContractMaterialAdjustDetail> adjustDetailList = adjustDetailService.list(new LambdaQueryWrapper<ContractMaterialAdjustDetail>()
|
|
|
+ .eq(ContractMaterialAdjustDetail::getContractId, vo.getContractId())
|
|
|
+ .eq(ContractMaterialAdjustDetail::getMaterialAdjustId, id));
|
|
|
+ vo.setDetails(adjustDetailList);
|
|
|
+ //获取附件详情
|
|
|
+ List<AttachmentForm> files = attachmentFormService.list(new LambdaQueryWrapper<AttachmentForm>()
|
|
|
+ .eq(AttachmentForm::getContractId, vo.getContractId())
|
|
|
+ .eq(AttachmentForm::getMasterId, id));
|
|
|
+ vo.setFiles(files);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void update2(ContractMaterialAdjustAddDTO dto) {
|
|
|
+ //获取材料有效期
|
|
|
+ ContractMaterialValidity validity = validityService.getById(dto.getMaterialValidityId());
|
|
|
+ /*保存材料调差单*/
|
|
|
+ ContractMaterialAdjust adjust = new ContractMaterialAdjust();
|
|
|
+ BeanUtils.copyProperties(dto,adjust);
|
|
|
+ //计算调差金额,生成计算式
|
|
|
+ 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.updateById(adjust);
|
|
|
+
|
|
|
+ /*保存材料明细*/
|
|
|
+ //先删除再清空id
|
|
|
+ adjustDetailService.remove(new LambdaQueryWrapper<ContractMaterialAdjustDetail>()
|
|
|
+ .eq(ContractMaterialAdjustDetail::getMaterialAdjustId,adjust.getId()));
|
|
|
+ List<ContractMaterialAdjustDetail> details = dto.getDetails();
|
|
|
+ if (details.size() != 0){
|
|
|
+ for (ContractMaterialAdjustDetail detail : details) {
|
|
|
+ detail.setId(null);
|
|
|
+ detail.setMaterialAdjustId(adjust.getId());
|
|
|
+ }
|
|
|
+ adjustDetailService.saveBatch(details);
|
|
|
+ }
|
|
|
+ /*保存附件信息*/
|
|
|
+ //先删除再清空id
|
|
|
+ attachmentFormService.remove(new LambdaQueryWrapper<AttachmentForm>()
|
|
|
+ .eq(AttachmentForm::getMasterId,adjust.getId()));
|
|
|
+ List<AttachmentForm> files = dto.getFiles();
|
|
|
+ if (files.size() != 0){
|
|
|
+ for (AttachmentForm file : files) {
|
|
|
+ file.setId(null);
|
|
|
+ file.setMasterId(adjust.getId());
|
|
|
+ }
|
|
|
+ attachmentFormService.saveBatch(files);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|