Browse Source

新增买家批量上传物料后台功能开发

hejq 7 years ago
parent
commit
d02f5c82bd

+ 17 - 1
src/main/java/com/uas/platform/b2c/core/support/view/JxlsExcelView.java

@@ -14,7 +14,7 @@ import org.springframework.web.servlet.view.document.AbstractExcelView;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.net.URLEncoder;
+import java.net.*;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Locale;
@@ -33,10 +33,26 @@ public class JxlsExcelView extends AbstractExcelView {
 	 */
 	public final static int MAX_SIZE = 50000;
 
+    /**
+     * 文件名
+     */
 	private String fileName;
 
+	/**
+	 * 导入.xls格式文件
+	 */
 	private static final String EXTENSION = ".xls";
 
+	/**
+	 *  .xls 表格
+	 */
+	public static final String EXCEL_XLS = "xls";
+
+	/**
+	 * .xlsx 表格
+	 */
+	public static final String EXCEL_XLSX = "xlsx";
+
 	public JxlsExcelView(String tplPath, String fileName) {
 		super();
 		setUrl(tplPath);

+ 55 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/ReleaseProductByBatchService.java

@@ -1,7 +1,9 @@
 package com.uas.platform.b2c.prod.commodity.service;
 
 import com.uas.platform.b2c.prod.commodity.model.ReleaseProductByBatch;
+import com.uas.platform.b2c.prod.store.model.StoreIn;
 import com.uas.platform.core.model.PageInfo;
+import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.data.domain.Page;
 import org.springframework.ui.ModelMap;
@@ -115,4 +117,57 @@ public interface ReleaseProductByBatchService {
      * 每天零层删除所有的信息
      */
     void deleteAllInfo();
+
+    /**
+     * 判断店铺信息
+     *
+     * @param selfSale 自营还是寄售
+     * @return StoreIn
+     * @see StoreIn
+     */
+    StoreIn getStoreInfo(Boolean selfSale);
+
+    /**
+     *	验证该模板是否是商城模板
+     * @param headerRow 首行
+     * @param colNum	总列
+     * @param currency	币别
+     * @param isPcb 是否pcb模块
+     * @param isAPerson 是否为个人用户
+     */
+    void validateTemplate(Row headerRow, int colNum, String currency, boolean isAPerson, boolean isPcb);
+
+    /**
+     * 验证是否是模板的数据
+     * @param row excel的row对象
+     * @param rowNum 行号
+     * @return true false
+     */
+    boolean validateExcelData(Row row, int rowNum);
+
+    /**
+     * 初始化product信息,将excel内容转换为product字段值
+     * @param row 行对象
+     * @param aProduct 验证单行数据
+     * @param rowNum 行数
+     * @param isPcb 是否pcb模块
+     * @param isAPerson 是否是个人用户
+     * @return 为空的个数
+     */
+    int convertValueToProduct(Row row, ReleaseProductByBatch aProduct, int rowNum, boolean isAPerson, boolean isPcb);
+
+    /**
+     *  1:比较品牌、型号、自定义标签是否重复,2:比较六要素是否重复
+     * @param releaseProductByBatchs 批量上传商品建立临时表存储相关信息
+     */
+    void checkReleaseProductByBatch(List<ReleaseProductByBatch> releaseProductByBatchs);
+
+    /**
+     * 统计批量上传数据相关
+     *
+     * @param modelMap ModelMap
+     * @param strCount
+     * @param batch
+     */
+    void checkReleaseCount(ModelMap modelMap, String strCount, String batch);
 }

+ 115 - 54
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ReleaseProductByBatchServiceImpl.java

@@ -10,10 +10,32 @@ import com.uas.platform.b2c.core.support.SystemSession;
 import com.uas.platform.b2c.core.utils.NumberUtil;
 import com.uas.platform.b2c.core.utils.RegexConstant;
 import com.uas.platform.b2c.core.utils.StringUtilB2C;
-import com.uas.platform.b2c.prod.commodity.constant.*;
-import com.uas.platform.b2c.prod.commodity.dao.*;
-import com.uas.platform.b2c.prod.commodity.model.*;
-import com.uas.platform.b2c.prod.commodity.service.*;
+import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
+import com.uas.platform.b2c.prod.commodity.constant.ErrorInfoConstant;
+import com.uas.platform.b2c.prod.commodity.constant.ModifyConstant;
+import com.uas.platform.b2c.prod.commodity.constant.ShortConstant;
+import com.uas.platform.b2c.prod.commodity.constant.StringConstant;
+import com.uas.platform.b2c.prod.commodity.constant.UploadConstant;
+import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
+import com.uas.platform.b2c.prod.commodity.dao.PCBDao;
+import com.uas.platform.b2c.prod.commodity.dao.PcbPropertyvalueDao;
+import com.uas.platform.b2c.prod.commodity.dao.ProductDao;
+import com.uas.platform.b2c.prod.commodity.dao.ProductPersonDao;
+import com.uas.platform.b2c.prod.commodity.dao.ReleaseProductByBatchDao;
+import com.uas.platform.b2c.prod.commodity.model.Goods;
+import com.uas.platform.b2c.prod.commodity.model.GoodsHistory;
+import com.uas.platform.b2c.prod.commodity.model.GoodsQtyPrice;
+import com.uas.platform.b2c.prod.commodity.model.PCB;
+import com.uas.platform.b2c.prod.commodity.model.PCBPropertyValue;
+import com.uas.platform.b2c.prod.commodity.model.Product;
+import com.uas.platform.b2c.prod.commodity.model.ProductPerson;
+import com.uas.platform.b2c.prod.commodity.model.ProductPrivate;
+import com.uas.platform.b2c.prod.commodity.model.ReleaseProductByBatch;
+import com.uas.platform.b2c.prod.commodity.service.GoodsHistoryService;
+import com.uas.platform.b2c.prod.commodity.service.GoodsService;
+import com.uas.platform.b2c.prod.commodity.service.ProductPrivateService;
+import com.uas.platform.b2c.prod.commodity.service.ProductService;
+import com.uas.platform.b2c.prod.commodity.service.ReleaseProductByBatchService;
 import com.uas.platform.b2c.prod.commodity.util.GoodsUtil;
 import com.uas.platform.b2c.prod.commodity.util.SheetUtil;
 import com.uas.platform.b2c.prod.product.brand.dao.BrandInfoDao;
@@ -41,7 +63,11 @@ import org.apache.commons.collections.map.HashedMap;
 import org.apache.log4j.Logger;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFDateUtil;
-import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.DateUtil;
+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.beans.factory.annotation.Value;
 import org.springframework.dao.DataAccessException;
@@ -68,7 +94,16 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.regex.Matcher;
@@ -76,6 +111,11 @@ import java.util.regex.Pattern;
 
 import static com.uas.platform.b2c.core.utils.NumberUtil.fractionNumCeil;
 
+/**
+ * 批量上传物料
+ *
+ * @author hejq
+ */
 @Service
 public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchService {
 
@@ -109,9 +149,6 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	@Autowired
 	private RestTemplate restTemplate;
 
-	@Autowired
-	private ProductPrivateDao productPrivateDao;
-
     @Autowired
     private ProductPersonDao productPersonDao;
 
@@ -127,9 +164,6 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	@Autowired
 	private PcbPropertyvalueDao pcbPropertyvalueDao;
 
-	@Autowired
-	private V_ProductPrivateDao v_productPrivateDao;
-
 	@Autowired
 	private  ProductService productService;
 
@@ -266,27 +300,8 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		}
 		Long enUU = SystemSession.getUser().getEnterprise().getUu();
 		if (!isAPerson) {
-			//1:比较品牌、型号、自定义标签是否重复,2:比较六要素是否重复
-			for(int i = releaseProductByBatchs.size() - 1; i > -1; i--) {
-				ReleaseProductByBatch releaseProductByBatch = releaseProductByBatchs.get(i);
-				for(int j = i - 1; j > -1; j--) {
-					ReleaseProductByBatch byBatch = releaseProductByBatchs.get(j);
-					if(releaseProductByBatch.compareSameProductTagInfo(byBatch)) {
-						releaseProductByBatch.setTag("");
-						releaseProductByBatch.setTagstr("");
-						if (releaseProductByBatch.compareSameProductSixEle(byBatch)) {
-							releaseProductByBatch.addErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
-							releaseProductByBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
-							releaseProductByBatch.setReleaseCode(ReleaseStatus.had_exists.value());
-                            if (!StringUtilB2C.isEmpty(releaseProductByBatch.getErrmsg())) {
-                                if (releaseProductByBatch.getErrmsg().substring(0, 1).equals(",")) {
-                                    releaseProductByBatch.setErrmsg(releaseProductByBatch.getErrmsg().substring(1));
-                                }
-                            }
-						}
-					}
-				}
-			}
+            //1:比较品牌、型号、自定义标签是否重复,2:比较六要素是否重复
+            checkReleaseProductByBatch(releaseProductByBatchs);
 		}
 		commonDao.save(releaseProductByBatchs, ReleaseProductByBatch.class);
         releaseProductByBatchDao.callReleaseExistValidProcedure(batch, isAPerson, enUU);
@@ -325,34 +340,76 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 				}
 			});
 		}
-		Integer filter = 0, failure = 0, success = 0;
 		if (!StringUtilB2C.isEmpty(strCount)) {
-			String[] split = strCount.split(SplitChar.HYPHEN);
-            if (split.length == 3) {
-                filter = Integer.valueOf(split[0]);
-                failure = Integer.valueOf(split[1]);
-                success = Integer.valueOf(split[2]);
-            } else {
-                //上面的代码只能在正式上获取到返回值,为了在测试上执行,增加获取结果的代码
-                Long userUU = SystemSession.getUser().getUserUU();
-                filter = releaseProductByBatchDao.getCountOfImportFail(userUU, batch, failCode);
-                failure = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.failure.value());
-                success = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.success.value());
-            }
+		    // 统计上传数据相关
+			checkReleaseCount(modelMap, strCount, batch);
 		}
 		if (!isAPerson && !isPcb) {
 			String publish = publishByBatch(batch, isPcb);
 			modelMap.put("publish", publish);
 		}
 		modelMap.put("total", total);
-		modelMap.put("success", success);
-		modelMap.put("failure", failure);
-		modelMap.put("filter", filter);
 		modelMap.put("batch", batch);
 		return modelMap;
 	}
 
-	@Override
+    /**
+     * 统计上传数据相关
+     *
+     * @param modelMap ModelMap
+     * @param strCount
+     * @param batch
+     */
+    @Override
+    public void checkReleaseCount(ModelMap modelMap, String strCount, String batch) {
+        Integer filter, failure, success;
+        String[] split = strCount.split(SplitChar.HYPHEN);
+        if (split.length == 3) {
+            filter = Integer.valueOf(split[0]);
+            failure = Integer.valueOf(split[1]);
+            success = Integer.valueOf(split[2]);
+        } else {
+            //上面的代码只能在正式上获取到返回值,为了在测试上执行,增加获取结果的代码
+            Long userUU = SystemSession.getUser().getUserUU();
+            filter = releaseProductByBatchDao.getCountOfImportFail(userUU, batch, failCode);
+            failure = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.failure.value());
+            success = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.success.value());
+        }
+        modelMap.put("success", success);
+        modelMap.put("failure", failure);
+        modelMap.put("filter", filter);
+    }
+
+
+    /**
+     *  1:比较品牌、型号、自定义标签是否重复,2:比较六要素是否重复
+     * @param releaseProductByBatchs 批量上传商品建立临时表存储相关信息
+     */
+    @Override
+    public void checkReleaseProductByBatch(List<ReleaseProductByBatch> releaseProductByBatchs) {
+        for (int i = releaseProductByBatchs.size() - 1; i > -1; i--) {
+            ReleaseProductByBatch releaseProductByBatch = releaseProductByBatchs.get(i);
+            for (int j = i - 1; j > -1; j--) {
+                ReleaseProductByBatch byBatch = releaseProductByBatchs.get(j);
+                if (releaseProductByBatch.compareSameProductTagInfo(byBatch)) {
+                    releaseProductByBatch.setTag("");
+                    releaseProductByBatch.setTagstr("");
+                    if (releaseProductByBatch.compareSameProductSixEle(byBatch)) {
+                        releaseProductByBatch.addErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
+                        releaseProductByBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
+                        releaseProductByBatch.setReleaseCode(ReleaseStatus.had_exists.value());
+                        if (!StringUtilB2C.isEmpty(releaseProductByBatch.getErrmsg())) {
+                            if (releaseProductByBatch.getErrmsg().substring(0, 1).equals(",")) {
+                                releaseProductByBatch.setErrmsg(releaseProductByBatch.getErrmsg().substring(1));
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
 	public ModelMap modifyByWorkbook(Workbook workbook) {
 		ModelMap modelMap = new ModelMap();
 		StoreIn self = getStoreIn(true);
@@ -788,7 +845,8 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 * @param currency	币别
 	 * @param isPcb 是否pcb模块
 	 */
-	private void validateTemplate(Row headerRow, int colNum, String currency, boolean isAPerson, boolean isPcb) {
+	@Override
+	public void validateTemplate(Row headerRow, int colNum, String currency, boolean isAPerson, boolean isPcb) {
 		if (isAPerson) {
 			if (colNum == UploadConstant.MAX_TOTAL_COLUMN_PERSON) {
 				Cell errorCell = headerRow.getCell(UploadConstant.MAX_TOTAL_COLUMN_PERSON - 1);
@@ -848,7 +906,8 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 * @param rowNum 行号
 	 * @return
 	 */
-	private boolean validateExcelData(Row row, int rowNum) {
+	@Override
+	public boolean validateExcelData(Row row, int rowNum) {
 		Object codeValue = readWorkBookCell(row.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
 				rowNum, UploadConstant.PRODUCT_CODE);
 		if ("只能填数字、英文、英文特殊符号".equals(StringUtilB2C.getStr(codeValue)) || "SJ-S-112DMH(举例)".equals(StringUtilB2C.getStr(codeValue)))
@@ -936,7 +995,8 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 * @param selfSale
 	 * @return
 	 */
-	private StoreIn getStoreInfo(Boolean selfSale) {
+	@Override
+	public StoreIn getStoreInfo(Boolean selfSale) {
 		StoreIn storeIn = null;
 		if(selfSale) {
 			storeIn = storeInService.findByEnUU(SystemSession.getUser().getEnterprise().getUu());
@@ -1054,7 +1114,8 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 * @param rowNum 行数
 	 * @param isPcb 是否pcb模块
 	 */
-	private int convertValueToProduct(Row row, ReleaseProductByBatch aProduct, int rowNum, boolean isAPerson, boolean isPcb) {
+	@Override
+	public int convertValueToProduct(Row row, ReleaseProductByBatch aProduct, int rowNum, boolean isAPerson, boolean isPcb) {
 		// 统计为空的个数
 		int result = 0;
 		aProduct.setNum(rowNum - 2);

+ 74 - 0
src/main/java/com/uas/platform/b2c/trade/order/controller/PurchaseProductController.java

@@ -0,0 +1,74 @@
+package com.uas.platform.b2c.trade.order.controller;
+
+import com.uas.platform.b2c.common.base.model.FileUpload;
+import com.uas.platform.b2c.core.support.log.UsageBufferedLogger;
+import com.uas.platform.b2c.core.support.view.JxlsExcelView;
+import com.uas.platform.b2c.trade.order.service.PurchaseProductService;
+import com.uas.platform.b2c.trade.support.ResultMap;
+import com.uas.platform.core.exception.IllegalOperatorException;
+import com.uas.platform.core.logging.BufferedLoggerManager;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.*;
+
+/**
+ * 买家中心物料相关
+ *
+ * @author hejq
+ * @date 2018-09-18 9:30
+ * @version 1.0
+ */
+@RequestMapping("/trade/purchaseProduct")
+@RestController("trade.PurchaseProductController")
+public class PurchaseProductController {
+
+    /**
+     * 系统操作日志
+     */
+    private static final UsageBufferedLogger LOGGER = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
+
+    @Autowired
+    private PurchaseProductService purchaseProductService;
+
+    /**
+     * 通过excel批量导入个人物料
+     *
+     * @param uploadItem the upload item 上传的文件
+     * @param selfSale   the self sale 自营还是寄售
+     * @param currency 币别
+     * @param ignoreImport 是覆盖导入,还是忽略导入 1是忽略导入,0是覆盖导入
+     * @return ResultMap
+     * @see ResultMap
+     */
+    @RequestMapping(value = "/personal/release/excel", method = RequestMethod.POST)
+    public ResultMap releasePersonalProductByExcel(FileUpload uploadItem, @RequestParam("selfSale") Boolean selfSale, String currency, Integer ignoreImport) {
+        String fileName = uploadItem.getFile().getOriginalFilename();
+        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
+        InputStream inputStream;
+        Workbook workbook;
+        try {
+            inputStream = uploadItem.getFile().getInputStream();
+            // 根据表格格式分开处理
+            if (JxlsExcelView.EXCEL_XLS.equals(suffix)) {
+                workbook = new HSSFWorkbook(inputStream);
+            } else if (JxlsExcelView.EXCEL_XLSX.equals(suffix)) {
+                workbook = new XSSFWorkbook(inputStream);
+            } else {
+                return ResultMap.error(new IllegalOperatorException("文件格式不正确!请上传.xls或.xlsx格式的文件"));
+            }
+            ResultMap resultMap = purchaseProductService.releasePersonalProductByExcel(workbook, selfSale, currency, ignoreImport);
+            LOGGER.log("买家物料", "通过Excel批量上传个人物料");
+            return resultMap;
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return ResultMap.success();
+    }
+}

+ 25 - 0
src/main/java/com/uas/platform/b2c/trade/order/service/PurchaseProductService.java

@@ -0,0 +1,25 @@
+package com.uas.platform.b2c.trade.order.service;
+
+import com.uas.platform.b2c.trade.support.ResultMap;
+import org.apache.poi.ss.usermodel.Workbook;
+
+/**
+ * 买家中心物料相关
+ *
+ * @author hejq
+ * @date 2018-09-18 10:09
+ */
+public interface PurchaseProductService {
+
+    /**
+     * 通过excel批量导入个人物料
+     *
+     * @param workbook Workbook 对象
+     * @param selfSale   the self sale 自营还是寄售
+     * @param currency 币别
+     * @param ignoreImport 是覆盖导入,还是忽略导入 1是忽略导入,0是覆盖导入
+     * @return ResultMap
+     * @see ResultMap
+     */
+    ResultMap releasePersonalProductByExcel(Workbook workbook, Boolean selfSale, String currency, Integer ignoreImport);
+}

+ 162 - 0
src/main/java/com/uas/platform/b2c/trade/order/service/impl/PurchaseProductServiceImpl.java

@@ -0,0 +1,162 @@
+package com.uas.platform.b2c.trade.order.service.impl;
+
+import com.uas.platform.b2c.common.base.dao.CommonDao;
+import com.uas.platform.b2c.core.constant.ReleaseStatus;
+import com.uas.platform.b2c.core.support.SystemSession;
+import com.uas.platform.b2c.core.utils.StringUtilB2C;
+import com.uas.platform.b2c.prod.commodity.constant.UploadConstant;
+import com.uas.platform.b2c.prod.commodity.dao.ReleaseProductByBatchDao;
+import com.uas.platform.b2c.prod.commodity.model.ReleaseProductByBatch;
+import com.uas.platform.b2c.prod.commodity.service.ReleaseProductByBatchService;
+import com.uas.platform.b2c.prod.commodity.util.SheetUtil;
+import com.uas.platform.b2c.prod.product.common.service.CreateNumberService;
+import com.uas.platform.b2c.trade.order.service.PurchaseProductService;
+import com.uas.platform.b2c.trade.support.ResultMap;
+import com.uas.platform.core.exception.IllegalOperatorException;
+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.dao.DataAccessException;
+import org.springframework.jdbc.core.StatementCallback;
+import org.springframework.stereotype.Service;
+import org.springframework.ui.ModelMap;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 买家中心物料相关
+ *
+ * @author hejq
+ * @date 2018-09-18 10:09
+ */
+@Service
+public class PurchaseProductServiceImpl implements PurchaseProductService {
+
+    @Autowired
+    private ReleaseProductByBatchService releaseProductByBatchService;
+
+    @Autowired
+    private CreateNumberService createNumberService;
+
+    @Autowired
+    private CommonDao commonDao;
+
+    @Autowired
+    private ReleaseProductByBatchDao releaseProductByBatchDao;
+
+    private final static List<Integer> failCode = Arrays.asList(ReleaseStatus.lack_info.value(),
+            ReleaseStatus.had_exists.value());
+
+    /**
+     * 通过excel批量导入个人物料
+     *
+     * @param workbook     Workbook 对象
+     * @param selfSale     the self sale 自营还是寄售
+     * @param currency     币别
+     * @param ignoreImport 是覆盖导入,还是忽略导入 1是忽略导入,0是覆盖导入
+     * @return ResultMap
+     * @see ResultMap
+     */
+    @Override
+    public ResultMap releasePersonalProductByExcel(Workbook workbook, Boolean selfSale, String currency, Integer ignoreImport) {
+        // 先判断表格式
+        Sheet sheet = workbook.getSheetAt(0);
+        if (sheet.getRow(0) == null) {
+            return ResultMap.error(new IllegalOperatorException("表格模板不正确!请重新下载最新模板"));
+        }
+        int rowNum = SheetUtil.getSheetLastNum(sheet, UploadConstant.MAX_TOTAL_COLUMN);
+        // 除去表头格式,最多上传2000条数据
+        int maxExcelNumber = 2002;
+        // 用户填写数据计数
+        int minExcelNumber = 2;
+        // 先判断表格内容
+        if (rowNum > maxExcelNumber) {
+            return ResultMap.error(new IllegalOperatorException("您上传的信息超过2000条,请拆分成2000以下再上传"));
+        }
+        if (rowNum < minExcelNumber) {
+            return ResultMap.error(new IllegalOperatorException("请填写上传信息"));
+        }
+        List<ReleaseProductByBatch> releaseProductByBatchArrayList = new ArrayList<>(rowNum);
+        String batch = createNumberService.getTimeNumber("product$goods", 8, rowNum);
+        Row headerRow = sheet.getRow(0);
+        int total = 0;
+        int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
+        // 为空的个数
+        int blankNum;
+        // 非个人用户
+        boolean isAPerson = false;
+        // 非Pcb商品
+        boolean isPcb = false;
+        if (null != headerRow) {
+            // 验证模板是否为商城模板
+            releaseProductByBatchService.validateTemplate(headerRow, colNum, currency, isAPerson, isPcb);
+            for (int r = minExcelNumber; r <= rowNum; r++) {
+                Row row = sheet.getRow(r);
+                // 英文品牌名称
+                if (row != null) {
+                    // 防止用户直接用模板进行上传
+                    if (!releaseProductByBatchService.validateExcelData(row, r)) {
+                        continue;
+                    }
+                    ReleaseProductByBatch releaseProductByBatch = new ReleaseProductByBatch();
+                    // 将excel内容对应到ReleaseProductByBatch的字段当中
+                    blankNum = releaseProductByBatchService.convertValueToProduct(row, releaseProductByBatch, r, isAPerson, isPcb);
+                    if (blankNum != 4) {
+                        total++;
+                        releaseProductByBatchArrayList.add(releaseProductByBatch);
+                    }
+                }
+            }
+        }
+        Long enUU = SystemSession.getUser().getEnterprise().getUu();
+        //1:比较品牌、型号、自定义标签是否重复,2:比较六要素是否重复
+        releaseProductByBatchService.checkReleaseProductByBatch(releaseProductByBatchArrayList);
+        // 保存临时表信息
+        commonDao.save(releaseProductByBatchArrayList, ReleaseProductByBatch.class);
+        // 验证数据信息是否重复
+        releaseProductByBatchDao.callReleaseExistValidProcedure(batch, isAPerson, enUU);
+        final Object[] obj = new Object[]{enUU, batch};
+        String sql = "/*#mycat:db_type=master*/ set @enuu = %s; set @batch = '%s'; call PRODUCT_RELEASE_VALID_V5(@enuu, @batch, @out); select @out";
+        final String updateSql = String.format(sql, obj);
+        ModelMap modelMap = new ModelMap();
+        // 处理上传数据
+        assignmentProductInfo(updateSql, modelMap, batch);
+        modelMap.put("total", total);
+        modelMap.put("batch", batch);
+        return ResultMap.success(modelMap);
+    }
+
+    /**
+     * 处理验证后的数据
+     *
+     * @param updateSql 产品发布验证匹配 调用存储过程 PRODUCT_RELEASE_VALID_V5
+     * @param modelMap ModelMap
+     * @param batch
+     */
+    private void assignmentProductInfo(String updateSql, ModelMap modelMap, String batch) {
+        String finalStrCount = "0";
+        String strCount = commonDao.getJdbcTemplate().execute(new StatementCallback<String>() {
+
+            @Override
+            public String doInStatement(Statement stmt) throws SQLException, DataAccessException {
+                stmt.executeQuery(updateSql);
+                ResultSet rs = stmt.getResultSet();
+                if (null != rs) {
+                    rs.next();
+                    return rs.getString(1);
+                }
+                return finalStrCount;
+            }
+        });
+        if (!StringUtilB2C.isEmpty(strCount)) {
+            // 获取批量上传的相关数据统计
+            releaseProductByBatchService.checkReleaseCount(modelMap, strCount, batch);
+        }
+    }
+}

+ 6 - 1
src/main/java/com/uas/platform/b2c/trade/support/CodeType.java

@@ -73,7 +73,12 @@ public enum CodeType {
 	/**
 	 * 信息未修改
 	 */
-	INFO_NO_MODIFY(15, "INFO_NO_MODIFY");
+	INFO_NO_MODIFY(15, "INFO_NO_MODIFY"),
+
+	/**
+	 * 操作失败
+	 */
+	ERROR(16, "ERROR");
 
 	private int code;
 

+ 21 - 0
src/main/java/com/uas/platform/b2c/trade/support/ResultMap.java

@@ -107,4 +107,25 @@ public class ResultMap {
 		result.data = data;
 		return result;
 	}
+
+    /**
+     * 操作成功返回结果
+     *
+     * @return ResultMap
+     * @see ResultMap
+     */
+    public static ResultMap success() {
+        return new ResultMap(CodeType.OK.code(), null);
+    }
+
+	/**
+	 * 失败返回结果
+	 *
+	 * @param e 异常信息
+	 * @return ResultMap
+     * @see ResultMap
+	 */
+	public static ResultMap error(Exception e) {
+		return new ResultMap(CodeType.ERROR.code(), e.getMessage());
+	}
 }