|
|
@@ -1,25 +1,32 @@
|
|
|
package com.uas.platform.b2b.erp.service.impl;
|
|
|
|
|
|
-import com.uas.platform.b2b.dao.*;
|
|
|
+import com.uas.platform.b2b.dao.EnterpriseDao;
|
|
|
+import com.uas.platform.b2b.dao.PurchaseForecastAllDao;
|
|
|
+import com.uas.platform.b2b.dao.UserDao;
|
|
|
+import com.uas.platform.b2b.dao.VendorDao;
|
|
|
import com.uas.platform.b2b.erp.model.PurchaseForecast;
|
|
|
import com.uas.platform.b2b.erp.service.PurchaseForecastService;
|
|
|
import com.uas.platform.b2b.erp.service.VendorService;
|
|
|
import com.uas.platform.b2b.model.*;
|
|
|
+import com.uas.platform.b2b.ps.ProductUtils;
|
|
|
+import com.uas.platform.b2b.support.CollectionUtil;
|
|
|
import com.uas.platform.b2b.support.SystemSession;
|
|
|
import com.uas.platform.core.model.Constant;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
+/**
|
|
|
+ * 采购预测
|
|
|
+ *
|
|
|
+ * @author hejq
|
|
|
+ * @date 2018-07-23 10:58
|
|
|
+ */
|
|
|
@Service
|
|
|
public class PurchaseForecastServiceImpl implements PurchaseForecastService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private ProductDao productDao;
|
|
|
@Autowired
|
|
|
private VendorDao vendorDao;
|
|
|
@Autowired
|
|
|
@@ -41,6 +48,9 @@ public class PurchaseForecastServiceImpl implements PurchaseForecastService {
|
|
|
public List<PurchaseForecastAllItem> convertPurchaseForecast(List<PurchaseForecast> purchaseForecasts) {
|
|
|
List<PurchaseForecastAllItem> items = new ArrayList<PurchaseForecastAllItem>();
|
|
|
long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ // 获取物料编号集合
|
|
|
+ Set<String> productCodes = CollectionUtil.getProductCodeCollection(purchaseForecasts);
|
|
|
+ Map<String, ProductInfo> products = ProductUtils.findByEnUUAndCodes(enUU, productCodes);
|
|
|
for (PurchaseForecast purchaseForecast : purchaseForecasts) {
|
|
|
// 先查看是否已存在
|
|
|
List<PurchaseForecastAll> forecasts = purchaseForecastDao.findByEnUUAndCode(enUU,
|
|
|
@@ -60,19 +70,20 @@ public class PurchaseForecastServiceImpl implements PurchaseForecastService {
|
|
|
// 对明细遍历
|
|
|
for (PurchaseForecastAllItem item : forecast.getForecastItems()) {
|
|
|
item.setOrder(forecast);
|
|
|
- if (item.getVendUU() != null) {// 明细中有供应商uu号
|
|
|
+ if (item.getVendUU() != null) {
|
|
|
List<Vendor> vendors = vendorDao.findByMyEnUUAndVendUU(enUU, item.getVendUU());
|
|
|
Vendor vendor = null;
|
|
|
if (vendors.size() == 0) {
|
|
|
vendor = addVendor(item);
|
|
|
if (null != vendor) {
|
|
|
- vendorService.addPartnerShipRecord(vendor, APPID); // 添加合作伙伴关系
|
|
|
+ // 添加合作伙伴关系
|
|
|
+ vendorService.addPartnerShipRecord(vendor, APPID);
|
|
|
}
|
|
|
} else {
|
|
|
vendor = vendors.get(0);
|
|
|
}
|
|
|
- List<Product> products = productDao.findByEnUUAndCode(enUU, item.getProduct().getCode());
|
|
|
- if (products.size() > 0 && vendor != null) {
|
|
|
+ ProductInfo product = products.get(item.getProductCode());
|
|
|
+ if (null != product && vendor != null) {
|
|
|
item.setVendUU(vendor.getVendEnUU());
|
|
|
if (item.getVendUserUU() != null && item.getVendUserUU() != 0) {
|
|
|
List<User> vendUsers = userDao.findByEnUUAndUserUU(vendor.getVendEnUU(),
|
|
|
@@ -87,9 +98,10 @@ public class PurchaseForecastServiceImpl implements PurchaseForecastService {
|
|
|
// 则设为平台中供应商列表中的供应商联系人UU
|
|
|
item.setVendUserUU(vendors.get(0).getVendUserUU());
|
|
|
}
|
|
|
- item.setProduct(products.get(0));
|
|
|
- item.setProductId(products.get(0).getId());
|
|
|
- item.setErpDate(new Date());
|
|
|
+
|
|
|
+ item.setProduct(product);
|
|
|
+ item.setProductId(product.getId());
|
|
|
+ item.setErpDate(new Date(System.currentTimeMillis()));
|
|
|
items.add(item);
|
|
|
}
|
|
|
}
|
|
|
@@ -103,62 +115,7 @@ public class PurchaseForecastServiceImpl implements PurchaseForecastService {
|
|
|
@Override
|
|
|
public List<PurchaseForecastAllItem> convertEDIPurchaseForecast(List<PurchaseForecast> purchaseForecasts, Long enUU) {
|
|
|
List<PurchaseForecastAllItem> items = new ArrayList<PurchaseForecastAllItem>();
|
|
|
- for (PurchaseForecast purchaseForecast : purchaseForecasts) {
|
|
|
- // 先查看是否已存在
|
|
|
- List<PurchaseForecastAll> forecasts = purchaseForecastDao.findByEnUUAndCode(enUU,
|
|
|
- purchaseForecast.getPf_code());
|
|
|
- if (forecasts.size() == 0) {
|
|
|
- PurchaseForecastAll forecast = purchaseForecast.convert();
|
|
|
- if (!CollectionUtils.isEmpty(forecast.getForecastItems())) {
|
|
|
- // 设置User
|
|
|
- if (forecast.getUserUU() != null) {
|
|
|
- List<User> users = userDao.findByEnUUAndUserUU(enUU, forecast.getUser().getUserUU());
|
|
|
- if (CollectionUtils.isEmpty(users)) {
|
|
|
- forecast.setUserUU(SystemSession.getUser().getUserUU());
|
|
|
- }
|
|
|
- } else {
|
|
|
- forecast.setUserUU(SystemSession.getUser().getUserUU());
|
|
|
- }
|
|
|
- // 对明细遍历
|
|
|
- for (PurchaseForecastAllItem item : forecast.getForecastItems()) {
|
|
|
- item.setOrder(forecast);
|
|
|
- if (item.getVendUU() != null) {// 明细中有供应商uu号
|
|
|
- List<Vendor> vendors = vendorDao.findByMyEnUUAndVendUU(enUU, item.getVendUU());
|
|
|
- Vendor vendor = null;
|
|
|
- if (vendors.size() == 0) {
|
|
|
- vendor = addVendor(item);
|
|
|
- if (null != vendor) {
|
|
|
- vendorService.addPartnerShipRecord(vendor, APPID); // 添加合作伙伴关系
|
|
|
- }
|
|
|
- } else {
|
|
|
- vendor = vendors.get(0);
|
|
|
- }
|
|
|
- List<Product> products = productDao.findByEnUUAndCode(enUU, item.getProduct().getCode());
|
|
|
- if (products.size() > 0 && vendor != null) {
|
|
|
- item.setVendUU(vendor.getVendEnUU());
|
|
|
- if (item.getVendUserUU() != null && item.getVendUserUU() != 0) {
|
|
|
- List<User> vendUsers = userDao.findByEnUUAndUserUU(vendor.getVendEnUU(),
|
|
|
- item.getVendUserUU());
|
|
|
- if (vendUsers.size() == 0) {
|
|
|
- // 平台中的供应商企业不存在供应商联系人uu的用户
|
|
|
- // 则设为平台中供应商列表中的供应商联系人UU
|
|
|
- item.setVendUserUU(vendors.get(0).getVendUserUU());
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 买方ERP中供应商资料没有设置供应商联系人uu
|
|
|
- // 则设为平台中供应商列表中的供应商联系人UU
|
|
|
- item.setVendUserUU(vendors.get(0).getVendUserUU());
|
|
|
- }
|
|
|
- item.setProduct(products.get(0));
|
|
|
- item.setProductId(products.get(0).getId());
|
|
|
- item.setErpDate(new Date());
|
|
|
- items.add(item);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // TODO 暂时不做
|
|
|
return items;
|
|
|
}
|
|
|
|