|
|
@@ -3,6 +3,7 @@ package com.yw.contract.contract.service;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Random;
|
|
|
@@ -20,6 +21,8 @@ import com.kingdee.service.data.entity.SupplierListResRow;
|
|
|
import com.yw.contract.common.sync.jdy.JdyCommonHelper;
|
|
|
import com.yw.contract.common.sync.jdy.JdyPurOrderHelper;
|
|
|
import com.yw.contract.common.sync.mes.MesCommonHelper;
|
|
|
+import com.yw.contract.contract.dao.ContractEntryDao;
|
|
|
+import com.yw.contract.contract.dao.ContractMaterialDao;
|
|
|
import com.yw.contract.contract.dao.ContractPurchaseOrderDao;
|
|
|
import com.yw.contract.contract.model.ContractInfo;
|
|
|
import com.yw.contract.contract.model.ContractMaterial;
|
|
|
@@ -35,15 +38,115 @@ public class ContractPurchaseOrderServiceImpl implements ContractPurchaseOrderSe
|
|
|
|
|
|
@Autowired
|
|
|
ContractPurchaseOrderDao purchaseOrderDao;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ ContractMaterialDao contractMaterialDao;
|
|
|
+ @Autowired
|
|
|
+ ContractEntryDao contractEntryDao;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int addContractPurchaseOrder(ContractPurchaseOrder contractPurchaseOrder) throws Exception {
|
|
|
int orderStatus = contractPurchaseOrder.getOrderStatus();
|
|
|
- if(orderStatus == 1){
|
|
|
+ if(orderStatus == 1){
|
|
|
if(ObjectUtils.isEmpty(contractPurchaseOrder.getPurchaseOrderDetails())){
|
|
|
return -98;
|
|
|
+ }else{
|
|
|
+ if(StringUtils.isNotEmpty(contractPurchaseOrder.getContractNumber())){
|
|
|
+ Long contractId = contractPurchaseOrder.getContractId();
|
|
|
+ ContractInfo contractInfo = new ContractInfo();
|
|
|
+ contractInfo.setUniversalid(contractId);
|
|
|
+ Object object = this.getObject(contractInfo);
|
|
|
+ contractInfo = (ContractInfo)this.getObject(contractInfo);
|
|
|
+ if(StringUtils.isNotEmpty(contractInfo.getOrderNumber())){
|
|
|
+ return -97;
|
|
|
+ }
|
|
|
+ //如果有合同数据,取合同明细与已确认的订单的明细及当前订单的明细的物料和物料数量进行对比
|
|
|
+ List<ContractMaterial> contractMaterialList = contractMaterialDao.getContractMaterialListByContractId(contractId);
|
|
|
+ List<ContractPurchaseOrderDetail> purchaseOrderDetailList = contractPurchaseOrder.getPurchaseOrderDetails();
|
|
|
+
|
|
|
+ for (ContractMaterial material : contractMaterialList) {
|
|
|
+ String itemCode = material.getItemCode();
|
|
|
+ BigDecimal qtyMaterial = material.getQty();
|
|
|
+ boolean match = true;
|
|
|
+ for (ContractPurchaseOrderDetail detail : purchaseOrderDetailList) {
|
|
|
+ String materialCode = detail.getMaterialCode();
|
|
|
+ BigDecimal qtyDetail = detail.getQty();
|
|
|
+ if (!(materialCode.equals(itemCode) && qtyMaterial.compareTo(qtyDetail) == 0)) {
|
|
|
+ match = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!match) {
|
|
|
+ return -96;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if(StringUtils.isNotEmpty(contractPurchaseOrder.getPurchaseNumber())){
|
|
|
+ //如果没有合同数据,但有采购数据,则和采购数据进行对比
|
|
|
+ List<Object> orderList = new ArrayList<>();
|
|
|
+ Long purchaseId = contractPurchaseOrder.getPurchaseId();
|
|
|
+ String purchaseNumber = contractPurchaseOrder.getPurchaseNumber();
|
|
|
+ ContractPurchaseOrder orderA = new ContractPurchaseOrder();
|
|
|
+ orderA.setPurchaseNumber(purchaseNumber);
|
|
|
+ orderA.setOrderStatus(1);
|
|
|
+ List<Object> orderAList = this.getObjectList(orderA);
|
|
|
+ if(orderAList != null){
|
|
|
+ orderList.addAll(orderAList);
|
|
|
+ }
|
|
|
+ ContractPurchaseOrder orderB = new ContractPurchaseOrder();
|
|
|
+ orderB.setPurchaseNumber(purchaseNumber);
|
|
|
+ orderB.setOrderStatus(2);
|
|
|
+ List<Object> orderBList = this.getObjectList(orderB);
|
|
|
+ if(orderBList != null){
|
|
|
+ orderList.addAll(orderBList);
|
|
|
+ }
|
|
|
+ List<ContractPurchaseOrder> contractPurchaseOrderList = (List<ContractPurchaseOrder>) (List<?>) orderList;
|
|
|
+ List<Object> detailList = new ArrayList<>();
|
|
|
+ for(ContractPurchaseOrder contractPurchaseOrderI:contractPurchaseOrderList){
|
|
|
+ ContractPurchaseOrderDetail contractPurchaseOrderDetail = new ContractPurchaseOrderDetail();
|
|
|
+ contractPurchaseOrderDetail.setOrderId(contractPurchaseOrderI.getUniversalid());
|
|
|
+ List<Object> detailIList = this.getObjectList(contractPurchaseOrderDetail);
|
|
|
+ if(detailIList != null){
|
|
|
+ detailList.addAll(detailIList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ContractPurchaseOrderDetail> purchaseOrderDetailList = (List<ContractPurchaseOrderDetail>) (List<?>) detailList;
|
|
|
+ purchaseOrderDetailList.addAll(contractPurchaseOrder.getPurchaseOrderDetails());
|
|
|
+ //将所得到的采购订单物品详情数据和采购申请表的物品进行对比
|
|
|
+ ContractPurchaseDetail contractPurchaseDetail = new ContractPurchaseDetail();
|
|
|
+ contractPurchaseDetail.setContractPurchaseFormId(purchaseId);
|
|
|
+ List<Object> contractMaterials = this.getObjectList(contractPurchaseDetail);
|
|
|
+ List<ContractPurchaseDetail> contractPurchaseDetailList = new ArrayList<>();
|
|
|
+ contractPurchaseDetailList = (List<ContractPurchaseDetail>) (List<?>) contractMaterials;
|
|
|
+ // 获取当前订单的物料明细
|
|
|
+ List<ContractPurchaseOrderDetail> currentOrderDetails = contractPurchaseOrder.getPurchaseOrderDetails();
|
|
|
+
|
|
|
+ // 遍历当前订单的每种物料,进行数量校验
|
|
|
+ for (ContractPurchaseOrderDetail currentDetail : currentOrderDetails) {
|
|
|
+ String currentMaterialCode = currentDetail.getMaterialCode();
|
|
|
+
|
|
|
+ //在已有采购订单明细(purchaseOrderDetailList)中,汇总同一物料的总数量
|
|
|
+ BigDecimal totalOrderedQty = BigDecimal.ZERO;
|
|
|
+ for (ContractPurchaseOrderDetail existingDetail : purchaseOrderDetailList) {
|
|
|
+ if (existingDetail.getMaterialCode().equals(currentMaterialCode)) {
|
|
|
+ totalOrderedQty = totalOrderedQty.add(existingDetail.getQty());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //在采购申请表明细(contractPurchaseDetailList)中,查找该物料允许的最大数量
|
|
|
+ BigDecimal maxAllowedQty = BigDecimal.ZERO;
|
|
|
+ for (ContractPurchaseDetail purchaseDetail : contractPurchaseDetailList) {
|
|
|
+ if (purchaseDetail.getMaterialCode().equals(currentMaterialCode)) {
|
|
|
+ maxAllowedQty = purchaseDetail.getQty();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //比较:当前订单数量 + 已有订单总数量 不能超过申请表中的最大允许数量
|
|
|
+ if (totalOrderedQty.compareTo(maxAllowedQty) > 0) {
|
|
|
+ return -95; //物料采购数量超限
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
int num = purchaseOrderDao.addContractPurchaseOrder(contractPurchaseOrder);
|
|
|
@@ -58,6 +161,15 @@ public class ContractPurchaseOrderServiceImpl implements ContractPurchaseOrderSe
|
|
|
purchaseOrderDao.addObject(detail);
|
|
|
}
|
|
|
if(orderStatus == 1){
|
|
|
+ if(StringUtils.isNotEmpty(contractPurchaseOrder.getContractNumber())){
|
|
|
+ Long contractId = contractPurchaseOrder.getContractId();
|
|
|
+ ContractInfo contractInfo = new ContractInfo();
|
|
|
+ contractInfo.setUniversalid(contractId);
|
|
|
+ Object object = this.getObject(contractInfo);
|
|
|
+ contractInfo = (ContractInfo)this.getObject(contractInfo);
|
|
|
+ contractInfo.setOrderNumber(contractPurchaseOrder.getOrderNumber());
|
|
|
+ contractEntryDao.editContractEntry(contractInfo);
|
|
|
+ }
|
|
|
this.insertPurchaseOrder(contractPurchaseOrder.getUniversalid());
|
|
|
}
|
|
|
}
|
|
|
@@ -80,6 +192,103 @@ public class ContractPurchaseOrderServiceImpl implements ContractPurchaseOrderSe
|
|
|
if(orderStatus == 1){
|
|
|
if(ObjectUtils.isEmpty(contractPurchaseOrderDetailList)){
|
|
|
return -98;
|
|
|
+ }else{
|
|
|
+ if(StringUtils.isNotEmpty(contractPurchaseOrder.getContractNumber())){
|
|
|
+ Long contractId = contractPurchaseOrder.getContractId();
|
|
|
+ ContractInfo contractInfo = new ContractInfo();
|
|
|
+ contractInfo.setUniversalid(contractId);
|
|
|
+ Object object = this.getObject(contractInfo);
|
|
|
+ contractInfo = (ContractInfo)this.getObject(contractInfo);
|
|
|
+ if(StringUtils.isNotEmpty(contractInfo.getOrderNumber())){
|
|
|
+ return -97;
|
|
|
+ }
|
|
|
+ //如果有合同数据,取合同明细与已确认的订单的明细及当前订单的明细的物料和物料数量进行对比
|
|
|
+ List<ContractMaterial> contractMaterialList = contractMaterialDao.getContractMaterialListByContractId(contractId);
|
|
|
+ List<ContractPurchaseOrderDetail> purchaseOrderDetailList = contractPurchaseOrder.getPurchaseOrderDetails();
|
|
|
+
|
|
|
+ for (ContractMaterial material : contractMaterialList) {
|
|
|
+ String itemCode = material.getItemCode();
|
|
|
+ BigDecimal qtyMaterial = material.getQty();
|
|
|
+ boolean match = true;
|
|
|
+ for (ContractPurchaseOrderDetail detail : purchaseOrderDetailList) {
|
|
|
+ String materialCode = detail.getMaterialCode();
|
|
|
+ BigDecimal qtyDetail = detail.getQty();
|
|
|
+ if (!(materialCode.equals(itemCode) && qtyMaterial.compareTo(qtyDetail) == 0)) {
|
|
|
+ match = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!match) {
|
|
|
+ return -96;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if(StringUtils.isNotEmpty(contractPurchaseOrder.getPurchaseNumber())){
|
|
|
+ //如果没有合同数据,但有采购数据,则和采购数据进行对比
|
|
|
+ List<Object> orderList = new ArrayList<>();
|
|
|
+ Long purchaseId = contractPurchaseOrder.getPurchaseId();
|
|
|
+ String purchaseNumber = contractPurchaseOrder.getPurchaseNumber();
|
|
|
+ ContractPurchaseOrder orderA = new ContractPurchaseOrder();
|
|
|
+ orderA.setPurchaseNumber(purchaseNumber);
|
|
|
+ orderA.setOrderStatus(1);
|
|
|
+ List<Object> orderAList = this.getObjectList(orderA);
|
|
|
+ if(orderAList != null){
|
|
|
+ orderList.addAll(orderAList);
|
|
|
+ }
|
|
|
+ ContractPurchaseOrder orderB = new ContractPurchaseOrder();
|
|
|
+ orderB.setPurchaseNumber(purchaseNumber);
|
|
|
+ orderB.setOrderStatus(2);
|
|
|
+ List<Object> orderBList = this.getObjectList(orderB);
|
|
|
+ if(orderBList != null){
|
|
|
+ orderList.addAll(orderBList);
|
|
|
+ }
|
|
|
+ List<ContractPurchaseOrder> contractPurchaseOrderList = (List<ContractPurchaseOrder>) (List<?>) orderList;
|
|
|
+ List<Object> detailList = new ArrayList<>();
|
|
|
+ for(ContractPurchaseOrder contractPurchaseOrderI:contractPurchaseOrderList){
|
|
|
+ ContractPurchaseOrderDetail contractPurchaseOrderDetail = new ContractPurchaseOrderDetail();
|
|
|
+ contractPurchaseOrderDetail.setOrderId(contractPurchaseOrderI.getUniversalid());
|
|
|
+ List<Object> detailIList = this.getObjectList(contractPurchaseOrderDetail);
|
|
|
+ if(detailIList != null){
|
|
|
+ detailList.addAll(detailIList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ContractPurchaseOrderDetail> purchaseOrderDetailList = (List<ContractPurchaseOrderDetail>) (List<?>) detailList;
|
|
|
+ purchaseOrderDetailList.addAll(contractPurchaseOrder.getPurchaseOrderDetails());
|
|
|
+ //将所得到的采购订单物品详情数据和采购申请表的物品进行对比
|
|
|
+ ContractPurchaseDetail contractPurchaseDetail = new ContractPurchaseDetail();
|
|
|
+ contractPurchaseDetail.setContractPurchaseFormId(purchaseId);
|
|
|
+ List<Object> contractMaterials = this.getObjectList(contractPurchaseDetail);
|
|
|
+ List<ContractPurchaseDetail> contractPurchaseDetailList = new ArrayList<>();
|
|
|
+ contractPurchaseDetailList = (List<ContractPurchaseDetail>) (List<?>) contractMaterials;
|
|
|
+ // 获取当前订单的物料明细
|
|
|
+ List<ContractPurchaseOrderDetail> currentOrderDetails = contractPurchaseOrder.getPurchaseOrderDetails();
|
|
|
+
|
|
|
+ // 遍历当前订单的每种物料,进行数量校验
|
|
|
+ for (ContractPurchaseOrderDetail currentDetail : currentOrderDetails) {
|
|
|
+ String currentMaterialCode = currentDetail.getMaterialCode();
|
|
|
+
|
|
|
+ //在已有采购订单明细(purchaseOrderDetailList)中,汇总同一物料的总数量
|
|
|
+ BigDecimal totalOrderedQty = BigDecimal.ZERO;
|
|
|
+ for (ContractPurchaseOrderDetail existingDetail : purchaseOrderDetailList) {
|
|
|
+ if (existingDetail.getMaterialCode().equals(currentMaterialCode)) {
|
|
|
+ totalOrderedQty = totalOrderedQty.add(existingDetail.getQty());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //在采购申请表明细(contractPurchaseDetailList)中,查找该物料允许的最大数量
|
|
|
+ BigDecimal maxAllowedQty = BigDecimal.ZERO;
|
|
|
+ for (ContractPurchaseDetail purchaseDetail : contractPurchaseDetailList) {
|
|
|
+ if (purchaseDetail.getMaterialCode().equals(currentMaterialCode)) {
|
|
|
+ maxAllowedQty = purchaseDetail.getQty();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //比较:当前订单数量 + 已有订单总数量 不能超过申请表中的最大允许数量
|
|
|
+ if (totalOrderedQty.compareTo(maxAllowedQty) > 0) {
|
|
|
+ return -95; //物料采购数量超限
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
int num = purchaseOrderDao.editContractPurchaseOrder(contractPurchaseOrder,"universalid");
|
|
|
@@ -98,7 +307,16 @@ public class ContractPurchaseOrderServiceImpl implements ContractPurchaseOrderSe
|
|
|
detail.setUnitId(contractPurchaseOrder.getUnitId());
|
|
|
purchaseOrderDao.addObject(detail);
|
|
|
}
|
|
|
- if(orderStatus == 1){
|
|
|
+ if(orderStatus == 1){
|
|
|
+ if(StringUtils.isNotEmpty(contractPurchaseOrder.getContractNumber())){
|
|
|
+ Long contractId = contractPurchaseOrder.getContractId();
|
|
|
+ ContractInfo contractInfo = new ContractInfo();
|
|
|
+ contractInfo.setUniversalid(contractId);
|
|
|
+ Object object = this.getObject(contractInfo);
|
|
|
+ contractInfo = (ContractInfo)this.getObject(contractInfo);
|
|
|
+ contractInfo.setOrderNumber(contractPurchaseOrder.getOrderNumber());
|
|
|
+ contractEntryDao.editContractEntry(contractInfo);
|
|
|
+ }
|
|
|
this.insertPurchaseOrder(contractPurchaseOrder.getUniversalid());
|
|
|
}
|
|
|
}
|
|
|
@@ -310,6 +528,7 @@ public class ContractPurchaseOrderServiceImpl implements ContractPurchaseOrderSe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public int createPurchaseOrderFromContract(ContractPurchaseOrder contractPurchaseOrder, ContractInfo contractInfo)
|
|
|
throws Exception {
|
|
|
BigDecimal totalAmount = BigDecimal.ZERO;
|
|
|
@@ -339,7 +558,7 @@ public class ContractPurchaseOrderServiceImpl implements ContractPurchaseOrderSe
|
|
|
contractPurchaseOrder.setSupplierCode(contractInfo.getSupplierCode());
|
|
|
contractPurchaseOrder.setSupplierName(contractInfo.getSupplierName());
|
|
|
contractPurchaseOrder.setTotalAmount(totalAmount);
|
|
|
- contractPurchaseOrder.setOrderStatus(0);
|
|
|
+ contractPurchaseOrder.setOrderStatus(1);
|
|
|
contractPurchaseOrder.setSource(1);
|
|
|
contractPurchaseOrder.setSyncStatus(0);
|
|
|
contractPurchaseOrder.setCreateTime(new Date());
|
|
|
@@ -347,6 +566,10 @@ public class ContractPurchaseOrderServiceImpl implements ContractPurchaseOrderSe
|
|
|
contractPurchaseOrder.setPurchaseId(contractInfo.getPurchaseId());
|
|
|
contractPurchaseOrder.setPurchaseNumber(contractInfo.getPurchaseNumber());
|
|
|
int num = addContractPurchaseOrder(contractPurchaseOrder);
|
|
|
+ /*if(num > 0){
|
|
|
+ contractInfo.setOrderNumber(contractPurchaseOrder.getOrderNumber());
|
|
|
+ num = contractEntryDao.editContractEntry(contractInfo);
|
|
|
+ }*/
|
|
|
return num;
|
|
|
}
|
|
|
}
|