|
@@ -17,6 +17,7 @@
|
|
|
package org.springblade.meter.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.AllArgsConstructor;
|
|
@@ -33,10 +34,12 @@ import org.springblade.meter.service.*;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.meter.vo.*;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -69,9 +72,11 @@ public class ChangeTokenFormServiceImpl extends BaseServiceImpl<ChangeTokenFormM
|
|
|
private final IChangeTokenInventoryService changeTokenInventoryService;
|
|
|
|
|
|
//合同计量单元与清单中间表
|
|
|
-
|
|
|
private final IInventoryFormMeterService inventoryFormMeterService;
|
|
|
|
|
|
+ //合同计量单元
|
|
|
+ private final MeterTreeContractService meterTreeContractService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 一键生成零号变更 统计每个清单节点当前分解量,设置进清单的划分数量
|
|
@@ -141,6 +146,7 @@ public class ChangeTokenFormServiceImpl extends BaseServiceImpl<ChangeTokenFormM
|
|
|
meter.setContractMeterId(l.getId());
|
|
|
meter.setContractPicture(l.getContractPicture());
|
|
|
//设置部位基础信息,方便公式生成报表
|
|
|
+ meter.setBeforeContractPicture(l.getBeforeContractPicture());
|
|
|
meter.setNodeName(l.getNodeName());
|
|
|
meter.setNodeUrl(l.getNodeUrl());
|
|
|
meter.setChangeMoney(BigDecimal.ZERO);
|
|
@@ -184,8 +190,12 @@ public class ChangeTokenFormServiceImpl extends BaseServiceImpl<ChangeTokenFormM
|
|
|
InventoryFormMeter meter = inventoryFormMeterService.getOne(new LambdaQueryWrapper<InventoryFormMeter>()
|
|
|
.eq(InventoryFormMeter::getContractFormId, vo2.getId())
|
|
|
.eq(InventoryFormMeter::getContractMeterId, vo2.getContractMeterId()));
|
|
|
- if (meter == null || (meter.getBuildPictureTotal().add(vo2.getCurrentChangeTotal()).compareTo(BigDecimal.ZERO) == -1)){
|
|
|
+ if (meter == null){
|
|
|
throw new ServiceException(voMap.get(vo2.getContractMeterId()).getNodeName()+"部位下,未找到清单("+vo2.getFormName()+")的分解信息,不能负变更");
|
|
|
+ }else {
|
|
|
+ if (meter.getChangeBuildPictureTotal().add(vo2.getCurrentChangeTotal()).compareTo(BigDecimal.ZERO) == -1){
|
|
|
+ throw new ServiceException(voMap.get(vo2.getContractMeterId()).getNodeName()+"部位下,清单["+vo2.getFormName()+"]负变更超过施工图变更后数量,不能负变更");
|
|
|
+ }
|
|
|
}
|
|
|
}else if (vo2.getCurrentChangeTotal().compareTo(BigDecimal.ZERO) == 0){
|
|
|
throw new ServiceException(voMap.get(vo2.getContractMeterId()).getNodeName()+"部位下,清单("+vo2.getFormName()+")的变更数量为0,请确认后再提交");
|
|
@@ -203,6 +213,8 @@ public class ChangeTokenFormServiceImpl extends BaseServiceImpl<ChangeTokenFormM
|
|
|
inventoryList.add(inventory);
|
|
|
}
|
|
|
changeTokenInventoryService.saveBatch(inventoryList);
|
|
|
+ }else {
|
|
|
+ throw new ServiceException("请添加变更清单后再保存");
|
|
|
}
|
|
|
form.setChangeMoney(big);
|
|
|
this.save(form);
|
|
@@ -297,6 +309,11 @@ public class ChangeTokenFormServiceImpl extends BaseServiceImpl<ChangeTokenFormM
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void update2(ChangeTokenFormDTO dto) {
|
|
|
+ //获取当前变更令,判断上报状态
|
|
|
+ ChangeTokenForm tokenForm = this.getById(dto.getId());
|
|
|
+ if (tokenForm.getApproveStatus() != 0){
|
|
|
+ throw new ServiceException("当前变更令为上报或审批状态,不能修改");
|
|
|
+ }
|
|
|
//复制出基础数据
|
|
|
ChangeTokenForm form = new ChangeTokenForm();
|
|
|
BeanUtils.copyProperties(dto,form);
|
|
@@ -321,6 +338,7 @@ public class ChangeTokenFormServiceImpl extends BaseServiceImpl<ChangeTokenFormM
|
|
|
meter.setContractMeterId(l.getId());
|
|
|
meter.setContractPicture(l.getContractPicture());
|
|
|
//设置部位基础信息,方便公式生成报表
|
|
|
+ meter.setBeforeContractPicture(l.getBeforeContractPicture());
|
|
|
meter.setNodeName(l.getNodeName());
|
|
|
meter.setNodeUrl(l.getNodeUrl());
|
|
|
meter.setChangeMoney(BigDecimal.ZERO);
|
|
@@ -366,8 +384,12 @@ public class ChangeTokenFormServiceImpl extends BaseServiceImpl<ChangeTokenFormM
|
|
|
InventoryFormMeter meter = inventoryFormMeterService.getOne(new LambdaQueryWrapper<InventoryFormMeter>()
|
|
|
.eq(InventoryFormMeter::getContractFormId, vo2.getId())
|
|
|
.eq(InventoryFormMeter::getContractMeterId, vo2.getContractMeterId()));
|
|
|
- if (meter == null || (meter.getBuildPictureTotal().add(vo2.getCurrentChangeTotal()).compareTo(BigDecimal.ZERO) == -1)){
|
|
|
+ if (meter == null){
|
|
|
throw new ServiceException(voMap.get(vo2.getContractMeterId()).getNodeName()+"部位下,未找到清单["+vo2.getFormName()+"]的分解信息,不能负变更");
|
|
|
+ }else {
|
|
|
+ if (meter.getBuildPictureTotal().add(vo2.getCurrentChangeTotal()).compareTo(BigDecimal.ZERO) == -1){
|
|
|
+ throw new ServiceException(voMap.get(vo2.getContractMeterId()).getNodeName()+"部位下,清单["+vo2.getFormName()+"]负变更超过施工图变更后数量,不能负变更");
|
|
|
+ }
|
|
|
}
|
|
|
}else if (vo2.getCurrentChangeTotal().compareTo(BigDecimal.ZERO) == 0){
|
|
|
throw new ServiceException(voMap.get(vo2.getContractMeterId()).getNodeName()+"部位下,清单["+vo2.getFormName()+"]的变更数量为0,请确认后再提交");
|
|
@@ -385,6 +407,8 @@ public class ChangeTokenFormServiceImpl extends BaseServiceImpl<ChangeTokenFormM
|
|
|
inventoryList.add(inventory);
|
|
|
}
|
|
|
changeTokenInventoryService.saveBatch(inventoryList);
|
|
|
+ }else {
|
|
|
+ throw new ServiceException("请添加变更清单后再保存");
|
|
|
}
|
|
|
form.setChangeMoney(big);
|
|
|
this.updateById(form);
|
|
@@ -476,18 +500,164 @@ public class ChangeTokenFormServiceImpl extends BaseServiceImpl<ChangeTokenFormM
|
|
|
if (form.getCommandStatus() == 1){
|
|
|
throw new ServiceException("当前变更任务已经下达,请勿重复下达");
|
|
|
}
|
|
|
+ if (form.getApproveStatus() != 2){
|
|
|
+ throw new ServiceException("当前变更任务未审批通过,下达失败");
|
|
|
+ }
|
|
|
+ //为防止中途其他变更执行,获取节点和清单的最新数据进行重新计算再变更
|
|
|
//获取当前变更令的变更节点
|
|
|
-
|
|
|
+ List<ChangeNodeVO> allNode = baseMapper.getNodeList2(id, form.getContractId());
|
|
|
//获取当前变更令的所有变更清单
|
|
|
- //清单放入节点中
|
|
|
- //修改合同清单
|
|
|
- // 此条清单的变更后数量和变更后金额
|
|
|
+ List<ChangeFormVO2> allForm = baseMapper.getFormList2(id,form.getContractId());
|
|
|
+ //修改合同清单,此条清单的变更后数量和变更后金额,
|
|
|
+ // 所有清单按照清单id分组,
|
|
|
+ Map<Long, List<ChangeFormVO2>> map = allForm.stream().collect(Collectors.groupingBy(ChangeFormVO2::getId));
|
|
|
+ //获取所有清单的最新数据进行重新计算再变更
|
|
|
+ List<ContractInventoryForm> formList = contractInventoryFormService.listByIds(map.keySet());
|
|
|
+ Map<Long, ContractInventoryForm> formMap = formList.stream().collect(Collectors.toMap(l->l.getId(),l->l));
|
|
|
|
|
|
+ List<ChangeTokenInventory> list1 = new ArrayList<>();
|
|
|
+ List<ContractInventoryForm> list2 = new ArrayList<>();
|
|
|
+ for (Long aLong : map.keySet()) {
|
|
|
+ List<ChangeFormVO2> list = map.get(aLong);
|
|
|
+ BigDecimal total = BigDecimal.ZERO;
|
|
|
+ BigDecimal money = BigDecimal.ZERO;
|
|
|
+ for (ChangeFormVO2 vo2 : list) {
|
|
|
+ total = total.add(vo2.getCurrentChangeTotal());
|
|
|
+ money = money.add(vo2.getCurrentChangeMoney());
|
|
|
+ }
|
|
|
+ //获取清单汇总,并且插入到中间表
|
|
|
+ ContractInventoryForm form2 = formMap.get(aLong);
|
|
|
+ ChangeFormVO2 vo2 = list.get(0);
|
|
|
+ ChangeTokenInventory inventory = new ChangeTokenInventory();
|
|
|
+ inventory.setProjectId(form2.getProjectId());
|
|
|
+ inventory.setContractId(form2.getContractId());
|
|
|
+ inventory.setChangeTokenId(vo2.getChangeTokenId());
|
|
|
+ inventory.setContractFormId(vo2.getId());
|
|
|
+ inventory.setContractMeterId(vo2.getContractMeterId());
|
|
|
+ //设置汇总清单的数量
|
|
|
+ inventory.setChangeBeforeTotal(form2.getChangeTotal());
|
|
|
+ inventory.setChangeTotal(total);
|
|
|
+ inventory.setChangeAfterTotal(inventory.getChangeBeforeTotal().add(inventory.getChangeTotal()));
|
|
|
+ //设置汇总清单的金额
|
|
|
+ inventory.setChangeBeforeMoney(form2.getChangeMoney());
|
|
|
+ inventory.setChangeMoney(money);
|
|
|
+ inventory.setChangeAfterMoney(inventory.getChangeBeforeMoney().add(inventory.getChangeMoney()));
|
|
|
+ //设置清单3个基础信息,因为变更后不能改变
|
|
|
+ inventory.setFormNumber(vo2.getFormNumber());
|
|
|
+ inventory.setFormName(vo2.getFormName());
|
|
|
+ inventory.setCurrentPrice(vo2.getCurrentPrice());
|
|
|
+ inventory.setIsCollectForm(1);
|
|
|
+ list1.add(inventory);
|
|
|
+ // 修改清单数量与金额
|
|
|
+ ContractInventoryForm fo = new ContractInventoryForm();
|
|
|
+ fo.setId(aLong);
|
|
|
+ fo.setChangeTotal(inventory.getChangeAfterTotal());
|
|
|
+ fo.setChangeMoney(inventory.getChangeAfterMoney());
|
|
|
+ list2.add(fo);
|
|
|
+ }
|
|
|
+ //批量新增清单汇总到 变更令与计量单元中间表
|
|
|
+ changeTokenInventoryService.saveBatch(list1);
|
|
|
+ //批量修改合同工程清单,因为mybatis的修改是伪批量,所以手动拼接
|
|
|
+ baseMapper.batchUpdateForm(list2);
|
|
|
//修改清单与合同计量单元,当前节点下当前清单
|
|
|
- // 修改施工图数量和施工图变更后数量,施工图金额和施工图变更后金额,并且重新计算节点金额
|
|
|
- //修改清单与中间计量申请,当前节点下当前清单
|
|
|
- // 只修改业务日期在今天之后的,并且未上报的,修改分解数量与变更后数量
|
|
|
+ // 修改施工图数量和施工图变更后数量,施工图金额和施工图变更后金额
|
|
|
+ //变更令与清单中间表集合,用于批量修改
|
|
|
+ List<ChangeTokenInventory> list3 = new ArrayList<>();
|
|
|
+ //清单与合同计量单元中间表集合,用于批量修改
|
|
|
+ List<InventoryFormMeter> list4 = new ArrayList<>();
|
|
|
+ //清单与合同计量单元中间表集合,用于批量保存,因为变更不存在的清单,就是新增
|
|
|
+ List<InventoryFormMeter> list5 = new ArrayList<>();
|
|
|
+ //清单与中间计量申请中间表集合,用于批量修改
|
|
|
+ List<InventoryFormApply> list6 = new ArrayList<>();
|
|
|
+ for (ChangeFormVO2 vo2 : allForm) {
|
|
|
+ //判断是否存在分解信息,如果不存在新增
|
|
|
+ if (vo2.getNewestChangeTotal() == null){
|
|
|
+ InventoryFormMeter meter = new InventoryFormMeter();
|
|
|
+ meter.setProjectId(vo2.getProjectId());
|
|
|
+ meter.setContractId(vo2.getContractId());
|
|
|
+ meter.setContractFormId(vo2.getId());
|
|
|
+ meter.setBuildPictureTotal(BigDecimal.ZERO);
|
|
|
+ meter.setBuildPictureMoney(BigDecimal.ZERO);
|
|
|
+ meter.setContractMeterId(vo2.getContractMeterId());
|
|
|
+ meter.setChangeBuildPictureTotal(vo2.getChangeTotal());
|
|
|
+ meter.setChangeBuildPictureMoney(vo2.getChangeMoney());
|
|
|
+ list5.add(meter);
|
|
|
+ }else {
|
|
|
+ //判断施工图数量是否发生变化,发生变化代表新增之后下达之前,变更过,则修改中间表的变更前数量和变更前金额
|
|
|
+ if (!vo2.getNewestChangeTotal().equals(vo2.getContractTotal())) {
|
|
|
+ //为allForm设置最终的当前节点当前清单变更后数量,用于修改清单与中间计量申请
|
|
|
+ vo2.setChangeTotal(vo2.getNewestChangeTotal().add(vo2.getCurrentChangeTotal()));
|
|
|
+ vo2.setChangeMoney(vo2.getNewestChangeMoney().add(vo2.getCurrentChangeMoney()));
|
|
|
+ ChangeTokenInventory ct = new ChangeTokenInventory();
|
|
|
+ ct.setId(vo2.getMiddleId());
|
|
|
+ ct.setChangeBeforeTotal(vo2.getNewestChangeTotal());
|
|
|
+ ct.setChangeAfterTotal(vo2.getChangeTotal());
|
|
|
+ ct.setChangeBeforeMoney(vo2.getNewestChangeMoney());
|
|
|
+ ct.setChangeAfterMoney(vo2.getChangeMoney());
|
|
|
+ list3.add(ct);
|
|
|
+ }
|
|
|
+ InventoryFormMeter meter = new InventoryFormMeter();
|
|
|
+ meter.setContractFormId(vo2.getId());
|
|
|
+ meter.setContractMeterId(vo2.getContractMeterId());
|
|
|
+ meter.setChangeBuildPictureTotal(vo2.getChangeTotal());
|
|
|
+ meter.setChangeBuildPictureMoney(vo2.getChangeMoney());
|
|
|
+ list4.add(meter);
|
|
|
+ }
|
|
|
+ //修改清单与中间计量申请,当前节点下当前清单,只修改业务日期在今天之后的,并且未上报的,修改分解数量与变更后数量
|
|
|
+ String applyIds = vo2.getApplyIds();
|
|
|
+ if (StringUtils.isNotBlank(applyIds)){
|
|
|
+ //存在值,则代表需要修改
|
|
|
+ List<Long> ids = Func.toLongList(applyIds);
|
|
|
+ for (Long along : ids) {
|
|
|
+ InventoryFormApply apply = new InventoryFormApply();
|
|
|
+ apply.setId(along);
|
|
|
+ apply.setChangeBuildPictureTotal(vo2.getChangeTotal());
|
|
|
+ list6.add(apply);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (list3.size() > 0) {
|
|
|
+ baseMapper.batchUpdateTokenForm(list3);
|
|
|
+ }
|
|
|
+ if (list4.size() > 0) {
|
|
|
+ baseMapper.batchUpdateMeterForm(list4);
|
|
|
+ }
|
|
|
+ if (list5.size() > 0) {
|
|
|
+ inventoryFormMeterService.saveBatch(list5);
|
|
|
+ }
|
|
|
+ if (list6.size() > 0) {
|
|
|
+ baseMapper.batchUpdateApplyForm(list6);
|
|
|
+ }
|
|
|
+ this.update(new LambdaUpdateWrapper<ChangeTokenForm>()
|
|
|
+ .eq(ChangeTokenForm::getId,id)
|
|
|
+ .set(ChangeTokenForm::getCommandStatus,1)
|
|
|
+ .set(ChangeTokenForm::getCommandDate, LocalDate.now()));
|
|
|
+ //异步重新计算节点金额,和修改施工图号,此方法放到最后,待所有操作成功后再执行
|
|
|
+ meterTreeContractService.asyncCalculateNodeMoney(allNode);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void annulChange(Long id) {
|
|
|
+ //判断当前状态是否是已下达
|
|
|
+ ChangeTokenForm form = this.getById(id);
|
|
|
+ if (form.getCommandStatus() == 0){
|
|
|
+ throw new ServiceException("当前变更任务不是已下达状态,撤销失败");
|
|
|
+ }
|
|
|
+ if (form.getApproveStatus() != 2){
|
|
|
+ throw new ServiceException("当前变更任务未审批通过,撤销失败");
|
|
|
+ }
|
|
|
+ //判断是否有清单执行过二次变更,执行过则不能撤销
|
|
|
+ List<ChangeFormVO2> vo2 = baseMapper.getMultipleChange(id);
|
|
|
+ if (vo2.size() != 0){
|
|
|
+ vo2.stream().map(ChangeFormVO2::getFormName).collect(Collectors.joining(",","[","]"));
|
|
|
+ throw new ServiceException("当前变更之后又发生过变更,请先撤销上一次变更");
|
|
|
+ }
|
|
|
+ //判断是否修改过中间计量申请,修改过则不能撤销
|
|
|
+ vo2 = baseMapper.getUpdateMiddleForm(id);
|
|
|
|
|
|
|
|
|
+ this.update(new LambdaUpdateWrapper<ChangeTokenForm>()
|
|
|
+ .eq(ChangeTokenForm::getId,id)
|
|
|
+ .set(ChangeTokenForm::getCommandStatus,0));
|
|
|
}
|
|
|
}
|