|
|
@@ -3,17 +3,24 @@ package com.uas.ps.product.service.impl;
|
|
|
import com.uas.ps.entity.Product;
|
|
|
import com.uas.ps.entity.ProductUsers;
|
|
|
import com.uas.ps.entity.Status;
|
|
|
+import com.uas.ps.product.entity.Constant;
|
|
|
import com.uas.ps.product.entity.Prod;
|
|
|
import com.uas.ps.product.entity.ProductSaler;
|
|
|
import com.uas.ps.product.repository.ProductDao;
|
|
|
import com.uas.ps.product.repository.ProductMatchResultDao;
|
|
|
+import com.uas.ps.product.repository.ProductStoreStatusDao;
|
|
|
import com.uas.ps.product.repository.ProductUsersDao;
|
|
|
import com.uas.ps.product.service.ProductService;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
@@ -34,6 +41,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private ProductUsersDao productUsersDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProductStoreStatusDao productStoreStatusDao;
|
|
|
+
|
|
|
/**
|
|
|
* 保存物料
|
|
|
*
|
|
|
@@ -73,9 +83,47 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ModelMap match(Long enUU, Long userUU) {
|
|
|
+ public ModelMap match(Long enUU, Long userUU, String matchtype) {
|
|
|
ModelMap map = new ModelMap();
|
|
|
- // TODO
|
|
|
+ //TODO
|
|
|
+// boolean flag = true;
|
|
|
+// ProductStoreStatus status = productStoreStatusDao.findByEnuu(enUU);
|
|
|
+// if (status != null) {
|
|
|
+// if (status.getStatus().equals(Status.RUNNING.value())) {// 有人正在操作这张单据,不能进行操作
|
|
|
+// map.put("error", "当前有人正在进行匹配操作,无法进行匹配");
|
|
|
+// flag = false;
|
|
|
+// } else {
|
|
|
+// status.setStatus(Status.RUNNING.value());
|
|
|
+// status = productStoreStatusDao.save(status);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// ProductStoreStatus stroestatus = new ProductStoreStatus();
|
|
|
+// stroestatus.setDate(new Date());
|
|
|
+// stroestatus.setEnuu(enUU);
|
|
|
+// stroestatus.setUseruu(userUU);
|
|
|
+// stroestatus.setStatus(Status.RUNNING.value());
|
|
|
+// status = productStoreStatusDao.save(stroestatus);
|
|
|
+// }
|
|
|
+// String num = null;
|
|
|
+// if (flag) {
|
|
|
+// if (matchtype.equals("sale")) {
|
|
|
+// num = productDao.updateResultByEnuuForSale(enUU);
|
|
|
+//// logger.log("产品匹配", "一键匹配了产品信息", "大小" + num);
|
|
|
+// } else if (matchtype.equals("purc")) {
|
|
|
+// num = productDao.updateResultByEnuuForPurc(enUU);
|
|
|
+//// logger.log("物料匹配", "一键匹配了物料信息", "大小" + num);
|
|
|
+// } else if (matchtype.equals("all")) {
|
|
|
+// num = productDao.updateResultByEnuu(enUU);
|
|
|
+//// logger.log("物料匹配", "一键匹配了产品(物料)信息", "大小" + num);
|
|
|
+// }
|
|
|
+// if (null == num) {
|
|
|
+// map.put("size", 0);
|
|
|
+// } else {
|
|
|
+// map.put("size", num);
|
|
|
+// }
|
|
|
+// status.setStatus(Status.FINISH.value());
|
|
|
+// productStoreStatusDao.save(status);
|
|
|
+// }
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
@@ -174,4 +222,147 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量导入物料信息
|
|
|
+ *
|
|
|
+ * @param workbook excel解析的物料信息
|
|
|
+ * @param enUU 企业UU
|
|
|
+ * @param userUU 用户UU
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap releaseByWorkbook(Workbook workbook, Long enUU, Long userUU) {
|
|
|
+ ModelMap modelMap = new ModelMap();
|
|
|
+ List<String> alters = new ArrayList<>();
|
|
|
+ List<String> infos = new ArrayList<>();
|
|
|
+ List<Product> products = new ArrayList<>();
|
|
|
+ List<Product> productsInfo = new ArrayList<>();
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ Row headerRow = sheet.getRow(0);
|
|
|
+ int total = 0;
|
|
|
+ if (headerRow != null) {
|
|
|
+ for (int r = 3; r <= rowNum; r++) {
|
|
|
+ Row row = sheet.getRow(r);
|
|
|
+ if (row != null && row.getCell(0) != null && row.getCell(0).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
+ total++;
|
|
|
+ Product product = new Product();
|
|
|
+
|
|
|
+ // 物料编号
|
|
|
+ if (row.getCell(0) != null) {
|
|
|
+ row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ product.setCode(row.getCell(0).getStringCellValue().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 物料名称
|
|
|
+ if (row.getCell(1) != null) {
|
|
|
+ row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ product.setTitle(row.getCell(1).getStringCellValue().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 原厂型号
|
|
|
+ if (row.getCell(2) != null) {
|
|
|
+ row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ product.setCmpCode(row.getCell(2).getStringCellValue().trim());
|
|
|
+ if (product.getCode() == null) {
|
|
|
+ // 生成随机物料编码
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("mmsssss");
|
|
|
+ String code = enUU + sdf.format(new Date());
|
|
|
+ product.setCode(code);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 品牌
|
|
|
+ if (row.getCell(3) != null) {
|
|
|
+ row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ product.setBrand(row.getCell(3).getStringCellValue().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 单位
|
|
|
+ if (row.getCell(4) != null) {
|
|
|
+ row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ product.setUnit(row.getCell(4).getStringCellValue().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最小包装量
|
|
|
+ if (row.getCell(5) != null) {
|
|
|
+ row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ if (null != row.getCell(5).getStringCellValue()
|
|
|
+ && !row.getCell(5).getStringCellValue().trim().equals("")) {
|
|
|
+ product.setMinPack(Double.valueOf(row.getCell(5).getStringCellValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 最小订购量
|
|
|
+ if (row.getCell(6) != null) {
|
|
|
+ row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ if (null != row.getCell(6).getStringCellValue().trim()
|
|
|
+ && !row.getCell(6).getStringCellValue().trim().equals("")) {
|
|
|
+ product.setMinOrder(Double.valueOf(row.getCell(6).getStringCellValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 交货周期
|
|
|
+ if (row.getCell(7) != null) {
|
|
|
+ row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ if (null != row.getCell(7).getStringCellValue().trim()
|
|
|
+ && !row.getCell(7).getStringCellValue().trim().equals("")) {
|
|
|
+ product.setLeadTime(Double.valueOf(row.getCell(7).getStringCellValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 交货提前期
|
|
|
+ if (row.getCell(8) != null) {
|
|
|
+ row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ if (null != row.getCell(8).getStringCellValue().trim()
|
|
|
+ && !row.getCell(8).getStringCellValue().trim().equals("")) {
|
|
|
+ product.setLtinstock(Double.valueOf(row.getCell(8).getStringCellValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 判断是否存在
|
|
|
+ List<Product> prods = productDao.findByEnUUAndCode(enUU, product.getCode());
|
|
|
+ if (org.apache.commons.collections.CollectionUtils.isEmpty(prods)) {
|
|
|
+ } else {
|
|
|
+ Product oldProd = prods.get(0);
|
|
|
+ if (oldProd.getIsSale() == null) {
|
|
|
+ oldProd.setIsSale(Constant.YES);
|
|
|
+ productDao.save(oldProd);
|
|
|
+ }
|
|
|
+ alters.add(product.getCode());
|
|
|
+ product.setCode(null);
|
|
|
+ }
|
|
|
+ product.setEnUU(enUU);
|
|
|
+ product.setUserUU(userUU);
|
|
|
+ product.setSourceApp("B2B");
|
|
|
+ product.setIsPubsale(Constant.NO);
|
|
|
+ product.setIsShow(Constant.NO);
|
|
|
+ product.setIsSale(Constant.YES);
|
|
|
+ if (alters.size() > 0) {
|
|
|
+ modelMap.put("alters", alters);
|
|
|
+ }
|
|
|
+ if (infos.size() > 0) {
|
|
|
+ modelMap.put("infos", infos);
|
|
|
+ }
|
|
|
+ if (product.getCode() != null) {
|
|
|
+ products.add(product);
|
|
|
+ }
|
|
|
+ if (product.getStandard() == null) {
|
|
|
+ product.setStandard(Constant.NO);
|
|
|
+ }
|
|
|
+ product.setErpDate(new Date());
|
|
|
+ productsInfo.add(product);
|
|
|
+ modelMap.put("total", total);
|
|
|
+ modelMap.put("products", productsInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!org.apache.commons.collections.CollectionUtils.isEmpty(products)) {
|
|
|
+ try {
|
|
|
+ products = productDao.save(products);
|
|
|
+// saveUserOrders(products);
|
|
|
+ modelMap.put("success", products.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ modelMap.put("error", "存在编号相同的产品");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return modelMap;
|
|
|
+ }
|
|
|
}
|