|
|
@@ -0,0 +1,135 @@
|
|
|
+package com.uas.platform.b2b.service.impl;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+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 com.uas.platform.b2b.dao.ProductDao;
|
|
|
+import com.uas.platform.b2b.model.Product;
|
|
|
+import com.uas.platform.b2b.service.PurcProductService;
|
|
|
+import com.uas.platform.b2b.support.SystemSession;
|
|
|
+import com.uas.platform.core.model.Constant;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class PurcProductServiceImpl implements PurcProductService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductDao productDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量导入物料资料
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap releaseByWorkbook(Workbook workbook) {
|
|
|
+ ModelMap modelMap = new ModelMap();
|
|
|
+ List<String> alters = new ArrayList<String>();
|
|
|
+ List<String> infos = new ArrayList<String>();
|
|
|
+ List<Product> products = new ArrayList<Product>();
|
|
|
+ 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.setTitle(row.getCell(0).getStringCellValue().trim());
|
|
|
+ }
|
|
|
+ // 物料编号
|
|
|
+ if (row.getCell(1) != null) {
|
|
|
+ row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ product.setCode(row.getCell(1).getStringCellValue().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 单位
|
|
|
+ if (row.getCell(2) != null) {
|
|
|
+ row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ product.setUnit(row.getCell(2).getStringCellValue().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 品牌
|
|
|
+ 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.setCmpCode(row.getCell(4).getStringCellValue().trim());
|
|
|
+ if (product.getCode() == null) {
|
|
|
+ product.setCode(product.getCmpCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最小包装量
|
|
|
+ if (row.getCell(5) != null) {
|
|
|
+ row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ product.setMinPack(Float.valueOf(row.getCell(5).getStringCellValue()));
|
|
|
+ }
|
|
|
+ // 最小订购量
|
|
|
+ if (row.getCell(6) != null) {
|
|
|
+ row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ product.setMinOrder(Float.valueOf(row.getCell(6).getStringCellValue()));
|
|
|
+ }
|
|
|
+ // 交货周期
|
|
|
+ if (row.getCell(7) != null) {
|
|
|
+ row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ product.setLeadtime(Float.valueOf(row.getCell(7).getStringCellValue()));
|
|
|
+ }
|
|
|
+ // 交货提前期
|
|
|
+ if (row.getCell(8) != null) {
|
|
|
+ row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ product.setLtinstock(Float.valueOf(row.getCell(8).getStringCellValue()));
|
|
|
+ }
|
|
|
+ List<Product> prods = productDao.findByEnUUAndCode(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
+ product.getCode());
|
|
|
+ if (CollectionUtils.isEmpty(prods)) {
|
|
|
+ product.setCode(product.getCode());
|
|
|
+ } else {
|
|
|
+ Product oldProd = prods.get(0);
|
|
|
+ if (!oldProd.getIsPurchase().equals(Constant.YES)) {
|
|
|
+ oldProd.setIsPurchase(Constant.YES);
|
|
|
+ productDao.save(oldProd);
|
|
|
+ }
|
|
|
+ alters.add(product.getCode());
|
|
|
+ product.setCode(null);
|
|
|
+ }
|
|
|
+ product.setEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ product.setUserUU(SystemSession.getUser().getUserUU());
|
|
|
+ product.setSourceApp("B2B");
|
|
|
+ product.setIsPurchase((short) 1);
|
|
|
+ if (alters.size() > 0) {
|
|
|
+ modelMap.put("alters", alters);
|
|
|
+ }
|
|
|
+ if (infos.size() > 0) {
|
|
|
+ modelMap.put("infos", infos);
|
|
|
+ }
|
|
|
+ if (product.getCode() != null) {
|
|
|
+ products.add(product);
|
|
|
+ }
|
|
|
+ modelMap.put("total", total);
|
|
|
+ modelMap.put("success", total - alters.size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(products)) {
|
|
|
+ productDao.save(products);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return modelMap;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|