|
@@ -10,6 +10,7 @@ import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -72,6 +73,7 @@ import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
|
|
|
import com.fjhx.sale.entity.sale.vo.SaleQuotationVo;
|
|
|
import com.fjhx.sale.mapper.contract.ContractMapper;
|
|
|
import com.fjhx.sale.mapper.contract.ContractProductBomMapper;
|
|
|
+import com.fjhx.sale.mapper.purchase.EhsdPurchaseProductMapper;
|
|
|
import com.fjhx.sale.service.SaleService;
|
|
|
import com.fjhx.sale.service.claim.ClaimContractService;
|
|
|
import com.fjhx.sale.service.contract.*;
|
|
@@ -104,7 +106,6 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.common.utils.wrapper.SqlField;
|
|
|
import com.ruoyi.framework.config.ThreadPoolConfig;
|
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
|
-import com.ruoyi.system.service.ISysRoleService;
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
|
import com.ruoyi.system.utils.UserUtil;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
@@ -121,6 +122,7 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -231,7 +233,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
@Autowired
|
|
|
private CodingRuleService codingRuleService;
|
|
|
@Autowired
|
|
|
- private ISysRoleService roleService;
|
|
|
+ private EhsdPurchaseProductMapper ehsdPurchaseProductMapper;
|
|
|
|
|
|
|
|
|
* 合同和样品单 下拉分页
|
|
@@ -1419,6 +1421,14 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
|
|
|
@Override
|
|
|
public void saveOrEdit(ContractDto contract) {
|
|
|
+
|
|
|
+ if (ObjectUtil.equals(contract.getProcessingMethod(), 10)) {
|
|
|
+
|
|
|
+ contract.setWaitPurchaseStatus(1);
|
|
|
+ } else {
|
|
|
+ contract.setWaitPurchaseStatus(0);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(contract.getId())) {
|
|
|
Contract oldCo = this.getById(contract.getId());
|
|
@@ -1471,7 +1481,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
contractProductBom.setContractProductId(cp.getId());
|
|
|
contractProductBom.setProductId(cp.getProductId());
|
|
|
}
|
|
|
- contractProductBomService.editLinked(contractProductBomList, ContractProductBom::getContractProductId, cp.getId());
|
|
|
+ contractProductBomService.editLinked(contractProductBomList, ContractProductBom::getContractProductId, cp.getId());
|
|
|
|
|
|
|
|
|
for (ContractProductBom contractProductBom : contractProductBomList) {
|
|
@@ -3411,4 +3421,261 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ @DSTransactional
|
|
|
+ @Override
|
|
|
+ public void createWaitMaterial(Long contractId) {
|
|
|
+ Contract contract = contractService.getById(contractId);
|
|
|
+ Assert.notEmpty(contract, "查询不到合同信息,请检查!");
|
|
|
+ Contract oldContract = contractService.getById(contract.getOldContractId());
|
|
|
+
|
|
|
+
|
|
|
+ List<ContractProductVo> oldContractProductList0 = new ArrayList<>();
|
|
|
+ if (ObjectUtil.isNotEmpty(oldContract)) {
|
|
|
+ oldContractProductList0 = contractProductService.getList(IWrapper.<ContractProduct>getWrapper()
|
|
|
+ .eq("cp", ContractProduct::getContractId, oldContract.getId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ContractProductVo> newContractProductList0 = contractProductService.getList(IWrapper.<ContractProduct>getWrapper()
|
|
|
+ .eq("cp", ContractProduct::getContractId, contractId)
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ List<Long> productIds = oldContractProductList0.stream().map(ContractProductVo::getProductId).collect(Collectors.toList());
|
|
|
+ productIds.addAll(newContractProductList0.stream().map(ContractProductVo::getProductId).collect(Collectors.toList()));
|
|
|
+ List<Long> pCompanyIds = productInfoService.listObject(ProductInfo::getCompanyId, q -> q.in(ProductInfo::getId, productIds));
|
|
|
+
|
|
|
+
|
|
|
+ for (Long companyId : pCompanyIds) {
|
|
|
+
|
|
|
+ if (ObjectUtil.equals(contract.getWaitPurchaseStatus(), 1)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(oldContract) || ObjectUtil.notEqual(oldContract.getWaitPurchaseStatus(), 1)) {
|
|
|
+
|
|
|
+ createMaterialWaitPurchase(companyId, contractId);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ updateMaterialWaitPurchase(companyId, contractId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ contractService.update(q -> q.eq(Contract::getId, contract.getId()).set(Contract::getWaitPurchaseStatus, 1));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 创建合同产品 物料待采购信息
|
|
|
+ */
|
|
|
+ private void createMaterialWaitPurchase(Long companyId, Long contractId) {
|
|
|
+
|
|
|
+ List<ContractProductVo> contractProductList = contractProductService.getList(IWrapper.<ContractProduct>getWrapper()
|
|
|
+ .eq("cp", ContractProduct::getContractId, contractId)
|
|
|
+ .eq("pi.company_id", companyId)
|
|
|
+ );
|
|
|
+ Map<Long, ContractProduct> productMap = contractProductList.stream().collect(Collectors.toMap(ContractProduct::getId, Function.identity()));
|
|
|
+
|
|
|
+
|
|
|
+ List<Long> cpIds = contractProductList.stream().map(ContractProduct::getId).collect(Collectors.toList());
|
|
|
+ List<ContractProductBom> cpBList = contractProductBomService.list(q -> q
|
|
|
+ .in(ContractProductBom::getContractProductId, cpIds)
|
|
|
+ .ne(ContractProductBom::getType, 3)
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, AvailableStockBo> inOutBoMap = new ConcurrentHashMap<>();
|
|
|
+ for (ContractProductBom bom : cpBList) {
|
|
|
+ Long materialId = bom.getMaterialId();
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal multiply = bom.getQuantity();
|
|
|
+
|
|
|
+
|
|
|
+ AvailableStockBo inOutBo = inOutBoMap.get(materialId);
|
|
|
+ if (ObjectUtil.isEmpty(inOutBo)) {
|
|
|
+ inOutBo = new AvailableStockBo();
|
|
|
+ inOutBo.setProductId(materialId);
|
|
|
+ inOutBo.setQuantity(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ inOutBo.setQuantity(inOutBo.getQuantity().add(multiply));
|
|
|
+ inOutBoMap.put(materialId, inOutBo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<SubscribeDetail> subscribeDetailList = new ArrayList<>();
|
|
|
+
|
|
|
+ List<AvailableStockBo> collect = inOutBoMap.values().stream().collect(Collectors.toList());
|
|
|
+
|
|
|
+ productInfoService.editAvailableQuantity(collect, contractId, ProductAvailableRecordType.SALE_PASS, companyId);
|
|
|
+ for (AvailableStockBo inOutBo : collect) {
|
|
|
+ Long materialId = inOutBo.getProductId();
|
|
|
+ BigDecimal requiredQuantity = inOutBo.getQuantity();
|
|
|
+
|
|
|
+
|
|
|
+ if (requiredQuantity.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ SubscribeDetail subscribeDetail = new SubscribeDetail();
|
|
|
+ subscribeDetail.setProductId(materialId);
|
|
|
+ subscribeDetail.setCount(requiredQuantity);
|
|
|
+ subscribeDetail.setStatus(15);
|
|
|
+ subscribeDetail.setContractId(contractId);
|
|
|
+ subscribeDetail.setDataType(1);
|
|
|
+ subscribeDetail.setCompanyId(companyId);
|
|
|
+
|
|
|
+ subscribeDetailList.add(subscribeDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ subscribeDetailService.saveBatch(subscribeDetailList);
|
|
|
+ }
|
|
|
+
|
|
|
+ void updateMaterialWaitPurchase(Long companyId, Long newContractId) {
|
|
|
+ Contract newContract = contractService.getById(newContractId);
|
|
|
+ Long oldContractId = newContract.getOldContractId();
|
|
|
+
|
|
|
+
|
|
|
+ List<ContractProductVo> oldContractProductList = contractProductService.getList(IWrapper.<ContractProduct>getWrapper()
|
|
|
+ .eq("cp", ContractProduct::getContractId, oldContractId)
|
|
|
+
|
|
|
+ .eq("pi.company_id", companyId)
|
|
|
+ );
|
|
|
+ List<Long> oldCpIds = oldContractProductList.stream().map(ContractProduct::getId).collect(Collectors.toList());
|
|
|
+ List<ContractProductBomVo> oldProductBomListSum = contractProductBomService.getContractProductBomQuantitySum(IWrapper.getWrapper()
|
|
|
+ .eq("cpb.contract_id", oldContractId)
|
|
|
+ .in("cp.id", oldCpIds)
|
|
|
+ .ne("cpb.type", 3)
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ List<ContractProductVo> newContractProductList = contractProductService.getList(IWrapper.<ContractProduct>getWrapper()
|
|
|
+ .eq("cp", ContractProduct::getContractId, newContract)
|
|
|
+
|
|
|
+ .eq("pi.company_id", companyId)
|
|
|
+ );
|
|
|
+ List<Long> newCpIds = newContractProductList.stream().map(ContractProduct::getId).collect(Collectors.toList());
|
|
|
+ List<ContractProductBomVo> contractProductBomQuantitySum = contractProductBomService.getContractProductBomQuantitySum(IWrapper.getWrapper()
|
|
|
+ .eq("cpb.contract_id", newContractId)
|
|
|
+ .in("cp.id", newCpIds)
|
|
|
+ .ne("cpb.type", 3)
|
|
|
+ );
|
|
|
+ Map<Long, BigDecimal> newQuantityMap = contractProductBomQuantitySum.stream().collect(Collectors.toMap(ContractProductBom::getMaterialId, ContractProductBom::getQuantity));
|
|
|
+
|
|
|
+
|
|
|
+ List<AvailableStockBo> availableStockBoList = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ List<EhsdPurchaseProductVo> purchaseQuantitySumByContractId = ehsdPurchaseProductMapper.getPurchaseQuantitySumByContractId(newContractId, companyId);
|
|
|
+ Map<Long, BigDecimal> collect = purchaseQuantitySumByContractId.stream().collect(Collectors.toMap(EhsdPurchaseProduct::getProductId, EhsdPurchaseProduct::getQuantity));
|
|
|
+
|
|
|
+
|
|
|
+ for (ContractProductBomVo oldContractProductBom : oldProductBomListSum) {
|
|
|
+ Long materialId = oldContractProductBom.getMaterialId();
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal newQuantity = newQuantityMap.get(materialId);
|
|
|
+
|
|
|
+ BigDecimal purchaseQuantity = collect.getOrDefault(materialId, BigDecimal.ZERO);
|
|
|
+
|
|
|
+
|
|
|
+ SubscribeDetail subscribeDetail = subscribeDetailService.getOne(q -> q
|
|
|
+ .eq(SubscribeDetail::getContractId, newContractId)
|
|
|
+ .eq(SubscribeDetail::getProductId, materialId)
|
|
|
+ .eq(SubscribeDetail::getCompanyId, companyId)
|
|
|
+ );
|
|
|
+ BigDecimal demandPurchaseCount = BigDecimal.ZERO;
|
|
|
+ if (ObjectUtils.isNotEmpty(subscribeDetail)) {
|
|
|
+ demandPurchaseCount = subscribeDetail.getCount();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ AvailableStockBo availableStockBo = new AvailableStockBo();
|
|
|
+ availableStockBo.setProductId(materialId);
|
|
|
+ availableStockBo.setQuantity(oldContractProductBom.getQuantity());
|
|
|
+ availableStockBo.setNewQuantity(newQuantity);
|
|
|
+ availableStockBo.setInStockQuantity(purchaseQuantity);
|
|
|
+ availableStockBo.setDemandPurchaseCount(demandPurchaseCount);
|
|
|
+
|
|
|
+ availableStockBoList.add(availableStockBo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, BigDecimal> oldQuantityMap = oldProductBomListSum.stream().collect(Collectors.toMap(ContractProductBom::getMaterialId, ContractProductBom::getQuantity));
|
|
|
+ for (ContractProductBomVo newPurchaseProduct : contractProductBomQuantitySum) {
|
|
|
+ Long materialId = newPurchaseProduct.getMaterialId();
|
|
|
+
|
|
|
+ BigDecimal bigDecimal = oldQuantityMap.get(materialId);
|
|
|
+
|
|
|
+ if (ObjectUtils.isNotEmpty(bigDecimal)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ AvailableStockBo availableStockBo = new AvailableStockBo();
|
|
|
+ availableStockBo.setProductId(materialId);
|
|
|
+ availableStockBo.setQuantity(BigDecimal.ZERO);
|
|
|
+ availableStockBo.setNewQuantity(newPurchaseProduct.getQuantity());
|
|
|
+ availableStockBo.setInStockQuantity(BigDecimal.ZERO);
|
|
|
+ availableStockBo.setDemandPurchaseCount(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ availableStockBoList.add(availableStockBo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ productInfoService.editAvailableQuantity(availableStockBoList, newContractId, ProductAvailableRecordType.SALE_UPDATE, companyId);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (AvailableStockBo availableStockBo : availableStockBoList) {
|
|
|
+
|
|
|
+ Long materialId = availableStockBo.getProductId();
|
|
|
+ SubscribeDetail subscribeDetail = subscribeDetailService.getOne(q -> q.eq(SubscribeDetail::getContractId, newContractId)
|
|
|
+ .eq(SubscribeDetail::getProductId, materialId)
|
|
|
+ .eq(SubscribeDetail::getCompanyId, companyId)
|
|
|
+ );
|
|
|
+
|
|
|
+ BigDecimal requiredQuantity = availableStockBo.getNewQuantity();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (requiredQuantity.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (ObjectUtils.isEmpty(subscribeDetail)) {
|
|
|
+
|
|
|
+ subscribeDetail = new SubscribeDetail();
|
|
|
+ subscribeDetail.setProductId(materialId);
|
|
|
+ subscribeDetail.setCount(BigDecimal.ZERO);
|
|
|
+ subscribeDetail.setStatus(15);
|
|
|
+ subscribeDetail.setContractId(newContractId);
|
|
|
+ subscribeDetail.setDataType(1);
|
|
|
+ subscribeDetail.setCompanyId(companyId);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ subscribeDetail.setCount(requiredQuantity);
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal purchaseQuantity = availableStockBo.getInStockQuantity();
|
|
|
+ int status = purchaseQuantity.compareTo(requiredQuantity) >= 0 ? 20 : 30;
|
|
|
+ if (purchaseQuantity.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ status = 15;
|
|
|
+ }
|
|
|
+ subscribeDetail.setStatus(status);
|
|
|
+
|
|
|
+ subscribeDetailService.saveOrUpdate(subscribeDetail);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (ObjectUtils.isNotEmpty(subscribeDetail)) {
|
|
|
+ subscribeDetailService.removeById(subscribeDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|