|
|
@@ -1,15 +1,14 @@
|
|
|
package com.uas.platform.b2b.service.impl;
|
|
|
|
|
|
-import com.alibaba.dubbo.common.utils.CollectionUtils;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.uas.platform.b2b.core.util.DateUtils;
|
|
|
+import com.uas.platform.b2b.core.util.StringUtil;
|
|
|
import com.uas.platform.b2b.core.util.ThreadUtils;
|
|
|
import com.uas.platform.b2b.dao.ProductDao;
|
|
|
import com.uas.platform.b2b.dao.ProductStatusDao;
|
|
|
+import com.uas.platform.b2b.dao.ProductTempDao;
|
|
|
import com.uas.platform.b2b.dao.ProductUsersDao;
|
|
|
-import com.uas.platform.b2b.model.Product;
|
|
|
-import com.uas.platform.b2b.model.ProductStatus;
|
|
|
-import com.uas.platform.b2b.model.ProductUsers;
|
|
|
-import com.uas.platform.b2b.model.Role;
|
|
|
+import com.uas.platform.b2b.model.*;
|
|
|
import com.uas.platform.b2b.ps.ProductUtils;
|
|
|
import com.uas.platform.b2b.service.ProductUsersService;
|
|
|
import com.uas.platform.b2b.service.RoleService;
|
|
|
@@ -19,6 +18,7 @@ import com.uas.platform.core.logging.BufferedLoggerManager;
|
|
|
import com.uas.platform.core.model.Constant;
|
|
|
import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.search.b2b.model.SPage;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
@@ -29,6 +29,7 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
@@ -59,10 +60,8 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
@Autowired
|
|
|
private ProductStatusDao productStatusDao;
|
|
|
|
|
|
- /**
|
|
|
- * 物料单次请求数据量大小
|
|
|
- */
|
|
|
- private static final Double ONE_TIME_DATA_SIZE = 1000d;
|
|
|
+ @Autowired
|
|
|
+ private ProductTempDao productTempDao;
|
|
|
|
|
|
@Override
|
|
|
public SPage<ProductUsers> findProductInfoByPageInfo(PageInfo pageInfo) {
|
|
|
@@ -164,226 +163,230 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
|
|
|
@Override
|
|
|
public ModelMap releaseByWorkbook(Workbook workbook) throws Exception {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
ModelMap modelMap = new ModelMap();
|
|
|
- List<String> alters = new ArrayList<String>();
|
|
|
- List<String> existedProducts = new ArrayList<>();
|
|
|
- Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- Long useruu = SystemSession.getUser().getUserUU();
|
|
|
+ List<ProductTemp> temps = new ArrayList<>();
|
|
|
+ Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ Long userUU = SystemSession.getUser().getUserUU();
|
|
|
// 生成随机物料编码
|
|
|
- StringBuilder codeString = new StringBuilder();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmsssss");
|
|
|
- codeString.append("PR").append(sdf.format(new Date()));
|
|
|
+ String codePrefix = "PR" + DateUtils.format(new Date(), "yyMMddHHmmsssss") + StringUtil.getRandomNumber(3);
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
int rowNum = sheet.getLastRowNum();
|
|
|
Row headerRow = sheet.getRow(0);
|
|
|
int total = 0;
|
|
|
- // 上传成功的个人产品数量
|
|
|
- int successProductUser = 0;
|
|
|
+ short isSale = Constant.NO;
|
|
|
+ short isPurchase = Constant.NO;
|
|
|
+ List<Role> roles = roleService.findByEnUUAndUserUU(enUU, userUU);
|
|
|
+ if(!CollectionUtils.isEmpty(roles)) {
|
|
|
+ for(Role role : roles) {
|
|
|
+ if(role.getDesc().equals("业务员") || role.getDesc().equals("销售经理")) {
|
|
|
+ isSale = Constant.YES;
|
|
|
+ } else if(role.getDesc().equals("采购员")) {
|
|
|
+ isPurchase = Constant.YES;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String importId = StringUtil.getRandomNumber(8);
|
|
|
if (headerRow != null) {
|
|
|
- // 根据每次发送数据量,计算发送几次
|
|
|
- int times = (int) Math.ceil((rowNum - 2) / ONE_TIME_DATA_SIZE);
|
|
|
- int r = 3;
|
|
|
- for (int i = 1; i <= times; i++) {
|
|
|
- // 每批次都需要重置用来保存的list
|
|
|
- List<ProductUsers> productUsers = new ArrayList<ProductUsers>();
|
|
|
- List<Product> products = new ArrayList<>();
|
|
|
- int end = (int) (i * ONE_TIME_DATA_SIZE + 2);
|
|
|
- for (; r <= (rowNum <= end ? rowNum : end); r++) {
|
|
|
- Row row = sheet.getRow(r);
|
|
|
- if (row != null && row.getCell(1) != null && row.getCell(1).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
- total++;
|
|
|
- Product product = new Product();
|
|
|
- // 物料编号
|
|
|
- if (row.getCell(0) != null && row.getCell(0).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
- row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setCode(row.getCell(0).getStringCellValue().trim());
|
|
|
- } else {
|
|
|
- product.setCode(codeString.toString() + (r - 2));
|
|
|
- }
|
|
|
+ for (int r = 3; r <= rowNum; r++) {
|
|
|
+ Row row = sheet.getRow(r);
|
|
|
+ if (row != null) {
|
|
|
+ total++;
|
|
|
+ ProductTemp temp = new ProductTemp();
|
|
|
+ temp.setPr_import_id(importId);
|
|
|
+ temp.setPr_enuu(enUU);
|
|
|
+ temp.setPr_useruu(userUU);
|
|
|
+ temp.setPr_issale(isSale);
|
|
|
+ temp.setPr_ispurchase(isPurchase);
|
|
|
+ temp.setPr_sourceapp("B2B");
|
|
|
+ // 物料编号
|
|
|
+ if (row.getCell(0) != null) {
|
|
|
+ row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ temp.setPr_code(row.getCell(0).getStringCellValue().trim());
|
|
|
+ } else {
|
|
|
+ temp.setPr_code(codePrefix + StringUtils.leftPad(String.valueOf(r), 4, "0"));
|
|
|
+ }
|
|
|
|
|
|
- // 物料名称
|
|
|
- if (row.getCell(1) != null && row.getCell(1).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
- row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setTitle(row.getCell(1).getStringCellValue().trim());
|
|
|
- } else {
|
|
|
- modelMap.put("error", "第" + (r + 1) + "行物料名称未填写");
|
|
|
- return modelMap;
|
|
|
- }
|
|
|
+ // 物料名称
|
|
|
+ if (row.getCell(1) != null && row.getCell(1).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
+ row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ temp.setPr_title(row.getCell(1).getStringCellValue().trim());
|
|
|
+ } else {
|
|
|
+ modelMap.put("error", "第" + (r + 1) + "行物料名称未填写");
|
|
|
+ return modelMap;
|
|
|
+ }
|
|
|
|
|
|
- // 物料规格
|
|
|
- if (row.getCell(2) != null && row.getCell(2).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
- row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setSpec(row.getCell(2).getStringCellValue().trim());
|
|
|
- } else {
|
|
|
- modelMap.put("error", "第" + (r + 1) + "行物料规格未填写");
|
|
|
- return modelMap;
|
|
|
- }
|
|
|
+ // 物料规格
|
|
|
+ if (row.getCell(2) != null && row.getCell(2).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
+ row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ temp.setPr_spec(row.getCell(2).getStringCellValue().trim());
|
|
|
+ } else {
|
|
|
+ modelMap.put("error", "第" + (r + 1) + "行物料规格未填写");
|
|
|
+ return modelMap;
|
|
|
+ }
|
|
|
|
|
|
- // 原厂型号
|
|
|
- if (row.getCell(3) != null && row.getCell(3).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
- row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setCmpCode(row.getCell(3).getStringCellValue().trim());
|
|
|
- } else {
|
|
|
- modelMap.put("error", "第" + (r + 1) + "行物料型号未填写");
|
|
|
- return modelMap;
|
|
|
- }
|
|
|
+ // 原厂型号
|
|
|
+ if (row.getCell(3) != null && row.getCell(3).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
+ row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ temp.setPr_cmpcode(row.getCell(3).getStringCellValue().trim());
|
|
|
+ } else {
|
|
|
+ modelMap.put("error", "第" + (r + 1) + "行物料型号未填写");
|
|
|
+ return modelMap;
|
|
|
+ }
|
|
|
|
|
|
- // 品牌
|
|
|
- if (row.getCell(4) != null && row.getCell(4).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
- row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setBrand(row.getCell(4).getStringCellValue().trim());
|
|
|
- } else {
|
|
|
- modelMap.put("error", "第" + (r + 1) + "行品牌未填写");
|
|
|
- return modelMap;
|
|
|
- }
|
|
|
+ // 品牌
|
|
|
+ if (row.getCell(4) != null && row.getCell(4).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
+ row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ temp.setPr_brand(row.getCell(4).getStringCellValue().trim());
|
|
|
+ } else {
|
|
|
+ modelMap.put("error", "第" + (r + 1) + "行品牌未填写");
|
|
|
+ return modelMap;
|
|
|
+ }
|
|
|
|
|
|
- // 单位
|
|
|
- if (row.getCell(5) != null && row.getCell(5).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
- row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- if (null != row.getCell(5).getStringCellValue()
|
|
|
- && !row.getCell(5).getStringCellValue().trim().equals("")) {
|
|
|
- product.setUnit(row.getCell(5).getStringCellValue());
|
|
|
- }
|
|
|
- } else {
|
|
|
- modelMap.put("error", "第" + (r + 1) + "行单位未填写");
|
|
|
- return modelMap;
|
|
|
- }
|
|
|
- // 最小包装量
|
|
|
- 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.setMinPack(Double.valueOf(row.getCell(6).getStringCellValue()));
|
|
|
- }
|
|
|
+ // 单位
|
|
|
+ if (row.getCell(5) != null && row.getCell(5).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
+ row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ if (null != row.getCell(5).getStringCellValue()
|
|
|
+ && !row.getCell(5).getStringCellValue().trim().equals("")) {
|
|
|
+ temp.setPr_unit(row.getCell(5).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.setMinOrder(Double.valueOf(row.getCell(7).getStringCellValue()));
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ modelMap.put("error", "第" + (r + 1) + "行单位未填写");
|
|
|
+ return modelMap;
|
|
|
+ }
|
|
|
+ // 最小包装量
|
|
|
+ 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("")) {
|
|
|
+ temp.setPr_minpack(Double.valueOf(row.getCell(6).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.setLeadtime(Double.valueOf(row.getCell(8).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("")) {
|
|
|
+ temp.setPr_minorder(Double.valueOf(row.getCell(7).getStringCellValue()));
|
|
|
}
|
|
|
- // 交货提前期
|
|
|
- if (row.getCell(9) != null) {
|
|
|
- row.getCell(9).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- if (null != row.getCell(9).getStringCellValue().trim()
|
|
|
- && !row.getCell(9).getStringCellValue().trim().equals("")) {
|
|
|
- product.setLtinstock(Double.valueOf(row.getCell(9).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("")) {
|
|
|
+ temp.setPr_leadtime(Double.valueOf(row.getCell(8).getStringCellValue()));
|
|
|
}
|
|
|
- List<ProductUsers> existProds = productUsersDao.findByEnuuAndUseruuAndTitleAndCmpCodeAndBrand
|
|
|
- (enuu, useruu, product.getTitle(), product.getCmpCode(), product.getBrand());
|
|
|
- if(CollectionUtils.isEmpty(existProds)) {
|
|
|
- List<Product> prods = productDao.findByEnUUAndCode(enuu, product.getCode());
|
|
|
- if (CollectionUtils.isEmpty(prods)) {
|
|
|
- prods = productDao.findByTitleAndCmpCodeAndBrandAndEnUU(
|
|
|
- product.getTitle(), product.getCmpCode(), product.getBrand(), enuu);
|
|
|
- }
|
|
|
- if(CollectionUtils.isEmpty(prods)) {// 如果非标不存在再查询标准
|
|
|
- prods = productDao.findByTitleAndPcmpcodeAndPbrandAndEnUU(product.getTitle(), product.getCmpCode(), product.getBrand(), SystemSession.getUser().getEnterprise().getUu());
|
|
|
- }
|
|
|
- if (CollectionUtils.isEmpty(prods)) {
|
|
|
- // 如果物料不存在,先生成物料信息
|
|
|
- product.setEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- product.setUserUU(SystemSession.getUser().getUserUU());
|
|
|
- product.setSourceApp("B2B");
|
|
|
- product.setIsPubsale(Constant.NO);
|
|
|
- product.setIsShow(Constant.NO);
|
|
|
- product.setStandard(Constant.NO);
|
|
|
- product.setCreateTime(new Date());
|
|
|
- List<Role> roles = roleService.findByEnUUAndUserUU(enuu, useruu);
|
|
|
- if(!CollectionUtils.isEmpty(roles)) {
|
|
|
- for(Role role : roles) {
|
|
|
- if(role.getDesc().equals("业务员") || role.getDesc().equals("销售经理")) {
|
|
|
- product.setIsSale(Constant.YES);
|
|
|
- } else if(role.getDesc().equals("采购员")) {
|
|
|
- product.setIsPurchase(Constant.YES);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- products.add(product);
|
|
|
- } else {
|
|
|
- // 已存在,直接更新
|
|
|
- Product oldProd = prods.get(0);
|
|
|
- oldProd.setCode(product.getCode());
|
|
|
- oldProd.setCmpCode(product.getCmpCode());
|
|
|
- oldProd.setBrand(product.getBrand());
|
|
|
- oldProd.setTitle(product.getTitle());
|
|
|
- oldProd.setSpec(product.getSpec());
|
|
|
- oldProd.setUnit(product.getUnit());
|
|
|
- oldProd.setMinOrder(product.getMinOrder());
|
|
|
- oldProd.setMinPack(product.getMinPack());
|
|
|
- oldProd.setLeadtime(product.getLeadtime());
|
|
|
- oldProd.setLtinstock(product.getLtinstock());
|
|
|
- List<Role> roles = roleService.findByEnUUAndUserUU(enuu, useruu);
|
|
|
- if(!CollectionUtils.isEmpty(roles)) {
|
|
|
- for(Role role : roles) {
|
|
|
- if(role.getDesc().equals("业务员") || role.getDesc().equals("销售经理")) {
|
|
|
- oldProd.setIsSale(Constant.YES);
|
|
|
- } else if(role.getDesc().equals("采购员")) {
|
|
|
- oldProd.setIsPurchase(Constant.YES);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- products.add(oldProd);
|
|
|
- // 如果已存在,且被禁用,修改为可用
|
|
|
- List<ProductStatus> productStatuses = productStatusDao.findByPrIdAndB2bDisabled(oldProd.getId(), Constant.YES);
|
|
|
- if (!CollectionUtils.isEmpty(productStatuses)) {
|
|
|
- ProductStatus status = productStatuses.get(0);
|
|
|
- status.setB2bDisabled(Constant.NO);
|
|
|
- productStatusDao.save(status);
|
|
|
- }
|
|
|
- existedProducts.add(product.getTitle());
|
|
|
- }
|
|
|
-// productUsers.add(prod);
|
|
|
- } else {
|
|
|
- alters.add(existProds.get(0).getProduct().getTitle());
|
|
|
+ }
|
|
|
+ // 交货提前期
|
|
|
+ if (row.getCell(9) != null) {
|
|
|
+ row.getCell(9).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ if (null != row.getCell(9).getStringCellValue().trim()
|
|
|
+ && !row.getCell(9).getStringCellValue().trim().equals("")) {
|
|
|
+ temp.setPr_ltinstock(Double.valueOf(row.getCell(9).getStringCellValue()));
|
|
|
}
|
|
|
}
|
|
|
+ temps.add(temp);
|
|
|
}
|
|
|
- if (!CollectionUtils.isEmpty(products)) {
|
|
|
- try {
|
|
|
- List<Long> idList = ProductUtils.update(products);
|
|
|
- if (!CollectionUtils.isEmpty(idList)) {
|
|
|
- for (Long id: idList) {
|
|
|
- ProductUsers prodUser = productUsersDao.findByEnuuAndUseruuAndPrid(enuu, useruu, id);
|
|
|
- if (null == prodUser) {
|
|
|
- ProductUsers prod = new ProductUsers();
|
|
|
- prod.setDate(new Date());
|
|
|
- prod.setEnuu(enuu);
|
|
|
- prod.setPrid(id);
|
|
|
- prod.setUseruu(useruu);
|
|
|
- productUsers.add(prod);
|
|
|
- }
|
|
|
- }
|
|
|
- if (!CollectionUtils.isEmpty(productUsers)) {
|
|
|
- ProductUtils.updateProductUsersByBatch(productUsers);
|
|
|
- successProductUser = successProductUser + productUsers.size();
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ modelMap.put("total", total);
|
|
|
+ // 本地校验
|
|
|
+ checkTempProducts(temps, modelMap);
|
|
|
+ // 保存到公共库
|
|
|
+ saveToDataCenter(temps, modelMap);
|
|
|
+ System.out.println("总耗时:" + (System.currentTimeMillis() - start));
|
|
|
+ }
|
|
|
+ return modelMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验导入的物料
|
|
|
+ *
|
|
|
+ * @param temps
|
|
|
+ */
|
|
|
+ private void checkTempProducts(List<ProductTemp> temps, ModelMap modelMap) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ if (!CollectionUtils.isEmpty(temps)) {
|
|
|
+ String importId = temps.get(0).getPr_import_id();
|
|
|
+ // 放入数据库
|
|
|
+ productTempDao.save(temps);
|
|
|
+ // 匹配已存在物料
|
|
|
+ productTempDao.matchExists(importId);
|
|
|
+ // 已禁用物料自动解禁
|
|
|
+ productTempDao.toggleDisabled(importId);
|
|
|
+ // 返回在物料库已存在的物料名称
|
|
|
+ List<String> existed = productTempDao.getExistsTitle(importId);
|
|
|
+ if (!CollectionUtils.isEmpty(existed)) {
|
|
|
+ modelMap.put("existed", existed);
|
|
|
+ }
|
|
|
+ // 返回在个人物料库已存在的物料名称
|
|
|
+ List<String> userExisted = productTempDao.getUserExistsTitle(importId);
|
|
|
+ if (!CollectionUtils.isEmpty(userExisted)) {
|
|
|
+ modelMap.put("alters", userExisted);
|
|
|
+ }
|
|
|
+ System.out.println("校验:" + (System.currentTimeMillis() - start));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存到公共库
|
|
|
+ */
|
|
|
+ private void saveToDataCenter(List<ProductTemp> temps, ModelMap modelMap){
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ if (!CollectionUtils.isEmpty(temps)) {
|
|
|
+ String importId = temps.get(0).getPr_import_id();
|
|
|
+ // 匹配后结果
|
|
|
+ temps = productTempDao.findByImportId(importId);
|
|
|
+ // 未匹配到的物料
|
|
|
+ List<Product> products = productTempDao.getNotMatchedProducts(importId);
|
|
|
+ // 匹配的当前物料库相关数据
|
|
|
+ List<Product> exists = productTempDao.getMatchedProducts(importId);
|
|
|
+ if (!CollectionUtils.isEmpty(exists)) {
|
|
|
+ for (Product e : exists) {
|
|
|
+ for (ProductTemp t : temps) {
|
|
|
+ // 替换为新导入的数据
|
|
|
+ if (e.getId().equals(t.getPr_exist_id())) {
|
|
|
+ e.setCode(t.getPr_code());
|
|
|
+ e.setCmpCode(t.getPr_cmpcode());
|
|
|
+ e.setBrand(t.getPr_brand());
|
|
|
+ e.setTitle(t.getPr_title());
|
|
|
+ e.setSpec(t.getPr_spec());
|
|
|
+ e.setUnit(t.getPr_unit());
|
|
|
+ e.setMinOrder(t.getPr_minorder());
|
|
|
+ e.setMinPack(t.getPr_minpack());
|
|
|
+ e.setLeadtime(t.getPr_leadtime());
|
|
|
+ e.setLtinstock(t.getPr_ltinstock());
|
|
|
+ e.setIsSale(t.getPr_issale());
|
|
|
+ e.setIsPurchase(t.getPr_ispurchase());
|
|
|
+ products.add(e);
|
|
|
+ break;
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- modelMap.put("error", "物料添加失败");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- modelMap.put("total", total);
|
|
|
- modelMap.put("success", successProductUser);
|
|
|
- if(alters.size() > 0)
|
|
|
- modelMap.put("alters", alters);
|
|
|
- if (existedProducts.size() > 0) {
|
|
|
- modelMap.put("existed", existedProducts);
|
|
|
+ System.out.println("取匹配后结果:" + (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+ System.out.println(JSON.toJSONString(products.get(0)));
|
|
|
+ try {
|
|
|
+ // 更新物料
|
|
|
+ List<Long> idList = ProductUtils.paginationUpdate(products);
|
|
|
+ System.out.println("更新物料:" + (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+ if (!CollectionUtils.isEmpty(idList)) {
|
|
|
+ // 更新个人物料
|
|
|
+ List<ProductUsers> productUsersList = productTempDao.getNotMatchedProductUsers(importId,
|
|
|
+ temps.get(0).getPr_enuu(), temps.get(0).getPr_useruu(), idList);
|
|
|
+ if (!CollectionUtils.isEmpty(productUsersList)) {
|
|
|
+ ProductUtils.updateProductUsersByBatch(productUsersList);
|
|
|
+ modelMap.put("success", productUsersList.size());
|
|
|
+ System.out.println("更新个人物料:" + (System.currentTimeMillis() - start));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ modelMap.put("error", "物料添加失败(" + e.getMessage() + ")");
|
|
|
}
|
|
|
}
|
|
|
- return modelMap;
|
|
|
}
|
|
|
|
|
|
@Override
|