|
@@ -16,15 +16,30 @@
|
|
|
*/
|
|
|
package org.springblade.meter.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+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.ContractMaterialValidityDTO;
|
|
|
import org.springblade.meter.entity.AttachmentForm;
|
|
|
+import org.springblade.meter.entity.ContractMaterialPrice;
|
|
|
import org.springblade.meter.entity.ContractMaterialValidity;
|
|
|
import org.springblade.meter.mapper.AttachmentFormMapper;
|
|
|
import org.springblade.meter.mapper.ContractMaterialValidityMapper;
|
|
|
import org.springblade.meter.service.IAttachmentFormService;
|
|
|
+import org.springblade.meter.service.IContractMaterialPriceService;
|
|
|
import org.springblade.meter.service.IContractMaterialValidityService;
|
|
|
+import org.springblade.meter.utils.ForestNodeMerger;
|
|
|
+import org.springblade.meter.vo.ContractMaterialVO3;
|
|
|
+import org.springblade.meter.vo.ContractMaterialValidityVO;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
|
/**
|
|
@@ -34,7 +49,95 @@ import java.util.Set;
|
|
|
* @since 2023-11-29
|
|
|
*/
|
|
|
@Service
|
|
|
+@AllArgsConstructor
|
|
|
public class ContractMaterialValidityServiceImpl extends BaseServiceImpl<ContractMaterialValidityMapper, ContractMaterialValidity> implements IContractMaterialValidityService {
|
|
|
|
|
|
+ private final IContractMaterialPriceService priceService;
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ContractMaterialValidityVO> list2(Long projectId,Long contractId) {
|
|
|
+ //获取合同下所有数据
|
|
|
+ List<ContractMaterialValidityVO> list = baseMapper.allNode(contractId);
|
|
|
+ //如果为空则直接创建目录,并且返回
|
|
|
+ if (list.size() == 0){
|
|
|
+ ContractMaterialValidity validity = new ContractMaterialValidity();
|
|
|
+ validity.setId(SnowFlakeUtil.getId());
|
|
|
+ validity.setParentId(0L);
|
|
|
+ validity.setNodeName("材料价格有效期");
|
|
|
+ validity.setProjectId(projectId);
|
|
|
+ validity.setContractId(contractId);
|
|
|
+ this.save(validity);
|
|
|
+ ContractMaterialValidityVO vo = new ContractMaterialValidityVO();
|
|
|
+ vo.setId(validity.getId());
|
|
|
+ vo.setParentId(0L);
|
|
|
+ vo.setNodeName(validity.getNodeName());
|
|
|
+ vo.setHasChildren(false);
|
|
|
+ list.add(vo);
|
|
|
+ }else {
|
|
|
+ //存在数据,直接转换为树
|
|
|
+ list = ForestNodeMerger.merge(list);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void add(ContractMaterialValidityDTO dto) {
|
|
|
+ //判断开始日期是否大于结束日期
|
|
|
+ if (dto.getStartDate().compareTo(dto.getEndDate()) > 0){
|
|
|
+ throw new ServiceException("开始日期不能大于结束日期");
|
|
|
+ }
|
|
|
+ //获取最新的一期结束时间
|
|
|
+ LocalDate end = baseMapper.getNewestEndDate(dto.getContractId());
|
|
|
+ //如果存在,则判断是否开始时间为结束时间后一天
|
|
|
+ if (end != null && end.plusDays(1).compareTo(dto.getStartDate()) != 0){
|
|
|
+ throw new ServiceException("开始日期必须为上一个结束日期后一天");
|
|
|
+ }
|
|
|
+ //获取根节点
|
|
|
+ ContractMaterialValidity rootNode = this.getOne(new LambdaQueryWrapper<ContractMaterialValidity>()
|
|
|
+ .eq(ContractMaterialValidity::getContractId, dto.getContractId())
|
|
|
+ .eq(ContractMaterialValidity::getParentId, 0));
|
|
|
+ if (rootNode == null){
|
|
|
+ throw new ServiceException("请选择节点");
|
|
|
+ }
|
|
|
+ //先生成价格有效期
|
|
|
+ ContractMaterialValidity validity = new ContractMaterialValidity();
|
|
|
+ validity.setId(SnowFlakeUtil.getId());
|
|
|
+ validity.setProjectId(dto.getProjectId());
|
|
|
+ validity.setContractId(dto.getContractId());
|
|
|
+ validity.setParentId(rootNode.getId());
|
|
|
+ validity.setStartDate(dto.getStartDate());
|
|
|
+ validity.setEndDate(dto.getEndDate());
|
|
|
+ validity.setNodeName(dto.getStartDate()+"至"+dto.getEndDate());
|
|
|
+ this.save(validity);
|
|
|
+ //生成实时价格
|
|
|
+ List<ContractMaterialPrice> priceList = getContractMaterialPrices(dto, validity);
|
|
|
+ priceService.saveBatch(priceList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ContractMaterialVO3> detail(Long id) {
|
|
|
+ if (id == null){
|
|
|
+ throw new ServiceException("请选择价格有效期");
|
|
|
+ }
|
|
|
+ List<ContractMaterialVO3> vo3s = baseMapper.detail(id);
|
|
|
+ return vo3s;
|
|
|
+ }
|
|
|
+
|
|
|
+ @NotNull
|
|
|
+ private static List<ContractMaterialPrice> getContractMaterialPrices(ContractMaterialValidityDTO dto, ContractMaterialValidity validity) {
|
|
|
+ List<ContractMaterialValidityDTO.Material> list = dto.getMaterials();
|
|
|
+ List<ContractMaterialPrice> priceList = new ArrayList<>();
|
|
|
+ for (ContractMaterialValidityDTO.Material material : list) {
|
|
|
+ ContractMaterialPrice price = new ContractMaterialPrice();
|
|
|
+ price.setProjectId(dto.getProjectId());
|
|
|
+ price.setContractId(dto.getContractId());
|
|
|
+ price.setContractMaterialId(material.getId());
|
|
|
+ price.setMaterialValidityId(validity.getId());
|
|
|
+ price.setCurrentPrice(material.getPrice());
|
|
|
+ priceList.add(price);
|
|
|
+ }
|
|
|
+ return priceList;
|
|
|
+ }
|
|
|
}
|