|
@@ -16,11 +16,33 @@
|
|
|
*/
|
|
|
package org.springblade.meter.service.impl;
|
|
|
|
|
|
-import org.springblade.meter.entity.MiddleMeterApply;
|
|
|
+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.apache.commons.lang.StringUtils;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.meter.dto.MiddleMeterApplyDTO;
|
|
|
+import org.springblade.meter.entity.*;
|
|
|
import org.springblade.meter.mapper.MiddleMeterApplyMapper;
|
|
|
-import org.springblade.meter.service.IMiddleMeterApplyService;
|
|
|
+import org.springblade.meter.service.*;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.meter.vo.MeterInventoryDetailVO;
|
|
|
+import org.springblade.meter.vo.MeterInventoryVO;
|
|
|
+import org.springblade.meter.vo.MiddleMeterApplyVO;
|
|
|
+import org.springblade.meter.vo.ResolveInventoryVO;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 中间计量申请表 服务实现类
|
|
@@ -29,8 +51,255 @@ import org.springframework.stereotype.Service;
|
|
|
* @since 2023-11-29
|
|
|
*/
|
|
|
@Service
|
|
|
+@AllArgsConstructor
|
|
|
public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterApplyMapper, MiddleMeterApply> implements IMiddleMeterApplyService {
|
|
|
|
|
|
+ private final IInventoryFormMeterService formMeterService;
|
|
|
+
|
|
|
+ private final IChangeTokenFormService changeTokenFormService;
|
|
|
+
|
|
|
+ private final MeterTreeContractService meterTreeContractService;
|
|
|
+
|
|
|
+ private final IInventoryFormApplyService inventoryFormApplyService;
|
|
|
+
|
|
|
+ private final IAttachmentFormService attachmentFormService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加清单
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ResolveInventoryVO> addFormList(Long contractId, Long nodeId ,String ids) {
|
|
|
+ //获取当前节点下关联的清单,如果没有直接返回
|
|
|
+ List<ResolveInventoryVO> vos = new ArrayList<>();
|
|
|
+ List<Long> list = formMeterService.getNodeAllForm(nodeId);
|
|
|
+ if (list.size() == 0) {
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
+ //去除已经存在的清单,如果去除之后集合为空,则直接返回
|
|
|
+ if (StringUtils.isNotBlank(ids)) {
|
|
|
+ //查询出还未添加的清单
|
|
|
+ list = list.stream().filter(l -> !ids.contains(l.toString())).collect(Collectors.toList());
|
|
|
+ if (list.size() == 0) {
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vos = baseMapper.getFormList(contractId, nodeId, list);
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加分解清单
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<MeterInventoryVO> addResolveForm(Long contractId ,String ids) {
|
|
|
+ List<MeterInventoryVO> vos = new ArrayList<>();
|
|
|
+ if (StringUtils.isBlank(ids)){
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
+ //获取清单和分解信息
|
|
|
+ List<Long> longs = Func.toLongList(ids);
|
|
|
+ vos = baseMapper.getResolveFormInfo(contractId,longs);
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增 中间计量申请表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void add(MiddleMeterApplyDTO dto) {
|
|
|
+ //保存中间计量申请,设置计量金额为0,如果存在计量清单,则统计计量清单总金额
|
|
|
+ MiddleMeterApply apply = new MiddleMeterApply();
|
|
|
+ Long id = SnowFlakeUtil.getId();
|
|
|
+ dto.setId(id);
|
|
|
+ BeanUtils.copyProperties(dto,apply);
|
|
|
+ apply.setMeterMoney(null);
|
|
|
+ //保存计量清单
|
|
|
+ List<MeterInventoryVO> formList = dto.getFormList();
|
|
|
+ if (formList.size() != 0){
|
|
|
+ BigDecimal big = new BigDecimal(0);
|
|
|
+ //保存清单
|
|
|
+ List<InventoryFormApply> formApplies = formList.stream().map(l -> {
|
|
|
+ InventoryFormApply formApply = new InventoryFormApply();
|
|
|
+ formApply.setProjectId(dto.getProjectId());
|
|
|
+ formApply.setContractId(dto.getContractId());
|
|
|
+ formApply.setContractFormId(l.getId());
|
|
|
+ formApply.setMiddleMeterId(id);
|
|
|
+ formApply.setContractPeriodId(dto.getContractPeriodId());
|
|
|
+ if (l.getCurrentMeterTotal() != null && l.getCurrentPrice() != null) {
|
|
|
+ formApply.setCurrentMeterTotal(l.getCurrentMeterTotal());
|
|
|
+ formApply.setCurrentMeterMoney(l.getCurrentPrice().multiply(new BigDecimal(l.getCurrentMeterTotal())));
|
|
|
+ }else {
|
|
|
+ throw new ServiceException("计量金额和计量数量不能为空");
|
|
|
+ }
|
|
|
+ return formApply;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ for (InventoryFormApply formApply : formApplies) {
|
|
|
+ big = big.add(formApply.getCurrentMeterMoney());
|
|
|
+ }
|
|
|
+ apply.setMeterMoney(big);
|
|
|
+ inventoryFormApplyService.saveBatch(formApplies);
|
|
|
+ }
|
|
|
+ this.save(apply);
|
|
|
+ //保存附件
|
|
|
+ List<AttachmentForm> fileList = dto.getFileList();
|
|
|
+ if (fileList != null && fileList.size() != 0) {
|
|
|
+ for (AttachmentForm file : fileList) {
|
|
|
+ file.setMasterId(id);
|
|
|
+ }
|
|
|
+ attachmentFormService.saveBatch(fileList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前节点变更令
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String getNodeToken(Long nodeId) {
|
|
|
+ //判断是否存在变更令
|
|
|
+ ChangeTokenMeter nodeToken = baseMapper.getNodeToken(nodeId);
|
|
|
+ if (nodeToken == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //获取变更令
|
|
|
+ ChangeTokenForm tokenForm = changeTokenFormService.getById(nodeToken.getId());
|
|
|
+ return tokenForm.getChangeNumber();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前节点工程划分
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String getNodeDivide(Long nodeId) {
|
|
|
+ //获取当前节点
|
|
|
+ MeterTreeContract contract = meterTreeContractService.getById(nodeId);
|
|
|
+ //获取祖级节点
|
|
|
+ String ancestor = contract.getAncestor();
|
|
|
+ List<Long> ids = Func.toLongList(ancestor);
|
|
|
+ List<MeterTreeContract> list = baseMapper.getNodeDivide(contract.getContractId(), ids);
|
|
|
+ StringBuilder str = new StringBuilder();
|
|
|
+ for (MeterTreeContract c : list) {
|
|
|
+ str.append(c.getNodeName()+"-");
|
|
|
+ }
|
|
|
+ str.append(contract.getNodeName());
|
|
|
+ return str.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改 中间计量申请表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void update2(MiddleMeterApplyDTO dto) {
|
|
|
+ //保存中间计量申请,设置计量金额为0,如果存在计量清单,则统计计量清单总金额
|
|
|
+ MiddleMeterApply apply = new MiddleMeterApply();
|
|
|
+ BeanUtils.copyProperties(dto,apply);
|
|
|
+ apply.setMeterMoney(null);
|
|
|
+ //保存计量清单
|
|
|
+ List<MeterInventoryVO> formList = dto.getFormList();
|
|
|
+ if (formList.size() != 0){
|
|
|
+ BigDecimal big = new BigDecimal(0);
|
|
|
+ //删除当前节点本期清单
|
|
|
+ inventoryFormApplyService.remove(new LambdaQueryWrapper<InventoryFormApply>()
|
|
|
+ .eq(InventoryFormApply::getMiddleMeterId,dto.getId())
|
|
|
+ .eq(InventoryFormApply::getContractPeriodId,dto.getContractPeriodId()));
|
|
|
+ //保存清单
|
|
|
+ List<InventoryFormApply> formApplies = formList.stream().map(l -> {
|
|
|
+ InventoryFormApply formApply = new InventoryFormApply();
|
|
|
+ formApply.setProjectId(dto.getProjectId());
|
|
|
+ formApply.setContractId(dto.getContractId());
|
|
|
+ formApply.setContractFormId(l.getId());
|
|
|
+ formApply.setMiddleMeterId(dto.getId());
|
|
|
+ formApply.setContractPeriodId(dto.getContractPeriodId());
|
|
|
+ if (l.getCurrentMeterTotal() != null && l.getCurrentPrice() != null) {
|
|
|
+ formApply.setCurrentMeterTotal(l.getCurrentMeterTotal());
|
|
|
+ formApply.setCurrentMeterMoney(l.getCurrentPrice().multiply(new BigDecimal(l.getCurrentMeterTotal())));
|
|
|
+ }else {
|
|
|
+ throw new ServiceException("计量金额和计量数量不能为空");
|
|
|
+ }
|
|
|
+ return formApply;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ for (InventoryFormApply formApply : formApplies) {
|
|
|
+ big = big.add(formApply.getCurrentMeterMoney());
|
|
|
+ }
|
|
|
+ apply.setMeterMoney(big);
|
|
|
+ inventoryFormApplyService.saveBatch(formApplies);
|
|
|
+ }
|
|
|
+ this.updateById(apply);
|
|
|
+ //删除附件
|
|
|
+ attachmentFormService.deleteByMasterId(dto.getId());
|
|
|
+ //保存附件
|
|
|
+ List<AttachmentForm> fileList = dto.getFileList();
|
|
|
+ if (fileList != null && fileList.size() != 0) {
|
|
|
+ for (AttachmentForm file : fileList) {
|
|
|
+ file.setMasterId(dto.getId());
|
|
|
+ }
|
|
|
+ attachmentFormService.saveOrUpdateBatch(fileList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页 中间计量申请表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<MiddleMeterApplyVO> page2(MiddleMeterApply middleMeterApply, Query query) {
|
|
|
+ IPage<MiddleMeterApplyVO> iPage = new Page<>(query.getCurrent(),query.getSize());
|
|
|
+ iPage = baseMapper.page2(iPage,middleMeterApply);
|
|
|
+ return iPage;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 删除 中间计量申请表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void delete(List<Long> ids) {
|
|
|
+ for (Long id : ids) {
|
|
|
+ //删除中间计量申请信息
|
|
|
+ baseMapper.deleteById(id);
|
|
|
+ //删除中间表当前中间计量申请数据
|
|
|
+ inventoryFormApplyService.remove(new LambdaQueryWrapper<InventoryFormApply>()
|
|
|
+ .eq(InventoryFormApply::getMiddleMeterId,id));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 清单明细
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<MeterInventoryDetailVO> formDetail(MiddleMeterApply apply) {
|
|
|
+ List<MeterInventoryDetailVO> vos = new ArrayList<>();
|
|
|
+ //查询当前计量期所有的计量清单
|
|
|
+ List<MeterInventoryDetailVO> list = baseMapper.meterPeriodAllForm(apply);
|
|
|
+ if (list.size() == 0){
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
+ //按照清单id分组
|
|
|
+ Map<Long, List<MeterInventoryDetailVO>> map = list.stream().collect(Collectors.groupingBy(MeterInventoryDetailVO::getContractFormId));
|
|
|
+ //统计后插入结果集
|
|
|
+ for (Long aLong : map.keySet()) {
|
|
|
+ List<MeterInventoryDetailVO> voList = map.get(aLong);
|
|
|
+ MeterInventoryDetailVO vo = new MeterInventoryDetailVO();
|
|
|
+ MeterInventoryDetailVO vo1 = voList.get(0);
|
|
|
+ vo.setFormNumber(vo1.getFormNumber());
|
|
|
+ vo.setFormName(vo1.getFormName());
|
|
|
+ vo.setChangeTotal(vo1.getChangeTotal());
|
|
|
+ vo.setCurrentPrice(vo1.getCurrentPrice());
|
|
|
+ Integer total = 0;
|
|
|
+ BigDecimal money = new BigDecimal(0);
|
|
|
+ for (MeterInventoryDetailVO inventoryVO : voList) {
|
|
|
+ total += inventoryVO.getCurrentMeterTotal();
|
|
|
+ money = money.add(inventoryVO.getCurrentMeterMoney());
|
|
|
+ }
|
|
|
+ vo.setAllMeterTotal(total);
|
|
|
+ vo.setAllMeterMoney(money);
|
|
|
+ vo.setDetail(voList);
|
|
|
+ vos.add(vo);
|
|
|
+ }
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
}
|