|
@@ -16,17 +16,34 @@
|
|
|
*/
|
|
|
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.apache.commons.lang.StringUtils;
|
|
|
+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.entity.ContractInventoryForm;
|
|
|
import org.springblade.meter.entity.ContractMaterial;
|
|
|
+import org.springblade.meter.entity.ContractMaterialAdjust;
|
|
|
+import org.springblade.meter.entity.ContractMaterialPrice;
|
|
|
import org.springblade.meter.mapper.ContractMaterialMapper;
|
|
|
+import org.springblade.meter.service.IContractMaterialAdjustService;
|
|
|
+import org.springblade.meter.service.IContractMaterialPriceService;
|
|
|
import org.springblade.meter.service.IContractMaterialService;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.meter.vo.ContractMaterialTreeVO;
|
|
|
import org.springblade.meter.vo.ContractMaterialVO;
|
|
|
+import org.springblade.meter.vo.ContractMaterialVO2;
|
|
|
+import org.springblade.meter.vo.SyncMaterialVO;
|
|
|
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.function.Consumer;
|
|
|
|
|
|
/**
|
|
|
* 合同材料表 服务实现类
|
|
@@ -35,8 +52,14 @@ import java.util.List;
|
|
|
* @since 2023-11-29
|
|
|
*/
|
|
|
@Service
|
|
|
+@AllArgsConstructor
|
|
|
public class ContractMaterialServiceImpl extends BaseServiceImpl<ContractMaterialMapper, ContractMaterial> implements IContractMaterialService {
|
|
|
|
|
|
+ private final IContractMaterialAdjustService adjustService;
|
|
|
+
|
|
|
+ private final IContractMaterialPriceService priceService;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 材料树 合同材料表
|
|
@@ -53,8 +76,8 @@ public class ContractMaterialServiceImpl extends BaseServiceImpl<ContractMateria
|
|
|
vo.setHasChild(false);
|
|
|
}else {
|
|
|
for (ContractMaterialVO materialVO : voList) {
|
|
|
- if (materialVO.getPrice() != null && materialVO.getAmount() != null){
|
|
|
- materialVO.setMeterMoney(materialVO.getPrice().multiply(materialVO.getAmount()));
|
|
|
+ if (materialVO.getPrice() != null){
|
|
|
+// materialVO.setMeterMoney(materialVO.getPrice().multiply(materialVO.getAmount()));
|
|
|
}
|
|
|
}
|
|
|
vo.setHasChild(true);
|
|
@@ -63,4 +86,106 @@ public class ContractMaterialServiceImpl extends BaseServiceImpl<ContractMateria
|
|
|
vos.add(vo);
|
|
|
return vos;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addOrUpdate(ContractMaterial contractMaterial) {
|
|
|
+ if (StringUtils.isBlank(contractMaterial.getMaterialNumber())){
|
|
|
+ throw new ServiceException("请填写材料编号");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(contractMaterial.getMaterialName())){
|
|
|
+ throw new ServiceException("请填写材料名称");
|
|
|
+ }
|
|
|
+ //校验是否存在当前材料编号和名称
|
|
|
+ LambdaQueryWrapper<ContractMaterial> wrapper1 = new LambdaQueryWrapper<>();
|
|
|
+ wrapper1.eq(ContractMaterial::getContractId,contractMaterial.getContractId());
|
|
|
+ wrapper1.eq(ContractMaterial::getMaterialNumber,contractMaterial.getMaterialNumber());
|
|
|
+ LambdaQueryWrapper<ContractMaterial> wrapper2 = new LambdaQueryWrapper<>();
|
|
|
+ wrapper2.eq(ContractMaterial::getContractId,contractMaterial.getContractId());
|
|
|
+ wrapper2.eq(ContractMaterial::getMaterialName,contractMaterial.getMaterialName());
|
|
|
+ if (contractMaterial.getId() != null){
|
|
|
+ //如果存在id,还要校验是否已经被调差
|
|
|
+ List<ContractMaterialAdjust> list = adjustService.list(new LambdaQueryWrapper<ContractMaterialAdjust>()
|
|
|
+ .eq(ContractMaterialAdjust::getContractId, contractMaterial.getContractId())
|
|
|
+ .eq(ContractMaterialAdjust::getContractMaterialId, contractMaterial.getId()));
|
|
|
+ if (list.size() > 0){
|
|
|
+ throw new ServiceException("当前材料已经被调差,不能被修改");
|
|
|
+ }
|
|
|
+ wrapper1.ne(ContractMaterial::getId,contractMaterial.getId());
|
|
|
+ wrapper2.ne(ContractMaterial::getId,contractMaterial.getId());
|
|
|
+ }
|
|
|
+ List<ContractMaterial> list1 = this.list(wrapper1);
|
|
|
+ if (list1.size() > 0){
|
|
|
+ throw new ServiceException("当前合同段已存在此材料编号");
|
|
|
+ }
|
|
|
+ List<ContractMaterial> list2 = this.list(wrapper2);
|
|
|
+ if (list2.size() > 0){
|
|
|
+ throw new ServiceException("当前合同段已存在此材料名称");
|
|
|
+ }
|
|
|
+ this.saveOrUpdate(contractMaterial);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<ContractMaterialVO2> page2(ContractMaterial material, Query query) {
|
|
|
+ IPage<ContractMaterialVO2> iPage = new Page<>(query.getCurrent(),query.getSize());
|
|
|
+ iPage = baseMapper.page2(iPage,material);
|
|
|
+ iPage.getRecords().stream().forEach(l->{
|
|
|
+ l.setIsSync(0);
|
|
|
+ l.setIsUpdateOrDelete(0);
|
|
|
+ if (l.getAdjustTotal() == 0){
|
|
|
+ l.setIsUpdateOrDelete(1);
|
|
|
+ if (l.getOtherTotal() > 0){
|
|
|
+ l.setIsSync(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return iPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncMaterial(Long id,Long selectId) {
|
|
|
+ //获取当前材料
|
|
|
+ ContractMaterial thisData = this.getById(id);
|
|
|
+ //获取选择的材料
|
|
|
+ ContractMaterial selectData = this.getById(selectId);
|
|
|
+ if (!thisData.getMaterialNumber().equals(selectData.getMaterialNumber())){
|
|
|
+ throw new ServiceException("数据错误,材料编号不同,请联系管理员");
|
|
|
+ }
|
|
|
+ thisData.setMaterialName(selectData.getMaterialName());
|
|
|
+ thisData.setSpecification(selectData.getSpecification());
|
|
|
+ thisData.setUnit(selectData.getUnit());
|
|
|
+ thisData.setPrice(selectData.getPrice());
|
|
|
+ thisData.setWastageRatio(selectData.getWastageRatio());
|
|
|
+ thisData.setQuotaRatio(selectData.getQuotaRatio());
|
|
|
+ thisData.setOwnerRatio(selectData.getOwnerRatio());
|
|
|
+ thisData.setDeductionRatio(selectData.getDeductionRatio());
|
|
|
+ this.updateById(thisData);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SyncMaterialVO> getSyncData(ContractMaterial material) {
|
|
|
+ return baseMapper.getSyncData(material);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void delete(String ids) {
|
|
|
+ if (StringUtils.isBlank(ids)){
|
|
|
+ throw new ServiceException("请先选择要删除的数据");
|
|
|
+ }
|
|
|
+ List<Long> list = Func.toLongList(ids);
|
|
|
+ //如果存在id,还要校验是否已经被调差
|
|
|
+ List<ContractMaterialAdjust> adjusts = adjustService.list(new LambdaQueryWrapper<ContractMaterialAdjust>()
|
|
|
+ .in(ContractMaterialAdjust::getContractMaterialId, list));
|
|
|
+ if (adjusts.size() > 0){
|
|
|
+ throw new ServiceException("材料已经被调差,不能被修改");
|
|
|
+ }
|
|
|
+ //删除实时价格
|
|
|
+ priceService.remove(new LambdaQueryWrapper<ContractMaterialPrice>()
|
|
|
+ .in(ContractMaterialPrice::getContractMaterialId,list));
|
|
|
+ //删除调差系数
|
|
|
+
|
|
|
+ //删除材料信息
|
|
|
+ this.removeBatchByIds(list);
|
|
|
+ }
|
|
|
}
|