Browse Source

买家批量上传个人物料后台功能开发

hejq 7 years ago
parent
commit
8414194d41

+ 21 - 11
src/main/java/com/uas/platform/b2c/common/account/model/UsageLog.java

@@ -6,9 +6,16 @@ import com.uas.platform.core.logging.BufferedLogable;
 import org.codehaus.jackson.annotate.JsonIgnore;
 import org.springframework.util.StringUtils;
 
-import javax.persistence.*;
-import java.io.Serializable;
-import java.util.Date;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Index;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import java.io.*;
 
 /**
  * 平台使用日志
@@ -237,7 +244,7 @@ public class UsageLog extends BufferedLogable implements Serializable {
 		this.detail = detail;
 		this.code = code;
 		this.key = key;
-		this.time = new Date().getTime();
+		this.time = System.currentTimeMillis();
 		if(SystemSession.getUser() != null) {
 			this.userUU = SystemSession.getUser().getUserUU();
 			this.enUU = SystemSession.getUser().getEnterprise() != null ? SystemSession.getUser().getEnterprise().getUu() : null;
@@ -253,7 +260,7 @@ public class UsageLog extends BufferedLogable implements Serializable {
 		this.detail = detail;
 		this.code = code;
 		this.key = key;
-		this.time = new Date().getTime();
+		this.time = System.currentTimeMillis();
 		if(SystemSession.getUser() != null) {
 			this.ip = SystemSession.getUser().getIp();
 		}
@@ -265,20 +272,23 @@ public class UsageLog extends BufferedLogable implements Serializable {
 		this.message = message;
 		this.code = code;
 		this.key = key;
-		this.time = new Date().getTime();
+		this.time = System.currentTimeMillis();
 		this.userUU = userUU;
 		this.ip = ip;
 	}
 
-	public void bufferedLog(String bufferedMessage) {
+	@Override
+    public void bufferedLog(String bufferedMessage) {
 		String[] strArray = bufferedMessage.split(separator);
 		if (strArray.length == 9) {
 			this.time = Long.parseLong(strArray[0]);
 			this.ip = strArray[1];
-			if (!"null".equals(strArray[2]))
-				this.enUU = Long.parseLong(strArray[2]);
-			if (!"null".equals(strArray[3]))
-				this.userUU = Long.parseLong(strArray[3]);
+			if (!"null".equals(strArray[2])) {
+                this.enUU = Long.parseLong(strArray[2]);
+            }
+			if (!"null".equals(strArray[3])) {
+                this.userUU = Long.parseLong(strArray[3]);
+            }
 			this.title = strArray[4];
 			this.message = strArray[5];
 			this.detail = StringUtils.hasText(strArray[6]) ? strArray[6] : null;

+ 20 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/constant/UploadConstant.java

@@ -180,4 +180,24 @@ public final class UploadConstant {
      * PCB一级类目id
      */
     public static final long PCB_PARENTID = 3825L;
+
+    /**
+     * 个人物料上传品牌标识
+     */
+    public static final String PRODUCT_BRAND_NAME = "英文/中文品牌名称";
+
+    /**
+     * 个人物料上传物料名称标识
+     */
+    public static final String PRODUCT_KIND_NAME = "物料名称";
+
+    /**
+     * 个人物料上传型号标识
+     */
+    public static final String PRODUCT_CMPCODE_NAME = "型号";
+
+    /**
+     * 个人物料上传规格标识
+     */
+    public static final String PRODUCT_SPEC_NAME = "规格(含参数、封装)";
 }

+ 7 - 24
src/main/java/com/uas/platform/b2c/prod/commodity/controller/ReleaseProductByBatchController.java

@@ -14,6 +14,7 @@ import com.uas.platform.b2c.prod.product.brand.service.BrandService;
 import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
 import com.uas.platform.b2c.prod.product.component.modal.Component;
 import com.uas.platform.b2c.trade.order.StringConstant.Currency;
+import com.uas.platform.b2c.trade.order.support.AjaxUtil;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.logging.BufferedLoggerManager;
 import com.uas.platform.core.model.PageInfo;
@@ -377,21 +378,12 @@ public class ReleaseProductByBatchController {
      */
     @RequestMapping(value = "/release/failure/xls", method = RequestMethod.GET)
     public ModelAndView exportOrderses(String batch, HttpServletRequest request, @RequestParam(defaultValue = "false") Boolean isAjax, String currency, Integer isPerson) {
-        ModelAndView modelAndView = new ModelAndView();
         HttpSession session = request.getSession();
-        Object loading = session.getAttribute("load-error-ing");
-        if (isAjax) {
-            MappingJackson2JsonView view = new MappingJackson2JsonView();
-            Map attributes = new HashMap();
-            if (loading == null || !Boolean.valueOf(loading.toString())) {
-                attributes.put("load", false);
-            } else if (Boolean.valueOf(loading.toString())) {
-                attributes.put("load", true);
-            }
-            view.setAttributesMap(attributes);
-            modelAndView.setView(view);
+        ModelAndView modelAndView = AjaxUtil.checkIsAjax(session, isAjax);
+        if (null != modelAndView) {
             return modelAndView;
         }
+        Object loading = session.getAttribute("load-error-ing");
         if (loading == null || !Boolean.valueOf(loading.toString())) {
             session.setAttribute("load-error-ing", true);
         }
@@ -442,21 +434,12 @@ public class ReleaseProductByBatchController {
      */
     @RequestMapping(value = "/modify/failure", method = RequestMethod.GET)
     public ModelAndView exportFailureData(String batch, HttpServletRequest request, @RequestParam(defaultValue = "false") Boolean isAjax) throws UnsupportedEncodingException {
-        ModelAndView modelAndView = new ModelAndView();
         HttpSession session = request.getSession();
-        Object loading = session.getAttribute("load-error-ing");
-        if (isAjax) {
-            MappingJackson2JsonView view = new MappingJackson2JsonView();
-            Map<String, Boolean> attributes = new HashMap<>();
-            if (loading == null || !Boolean.valueOf(loading.toString())) {
-                attributes.put("load", false);
-            } else if (Boolean.valueOf(loading.toString())) {
-                attributes.put("load", true);
-            }
-            view.setAttributesMap(attributes);
-            modelAndView.setView(view);
+        ModelAndView modelAndView = AjaxUtil.checkIsAjax(session, isAjax);
+        if (null != modelAndView) {
             return modelAndView;
         }
+        Object loading = session.getAttribute("load-error-ing");
         if (loading == null || !Boolean.valueOf(loading.toString())) {
             session.setAttribute("load-error-ing", true);
         }

+ 4 - 4
src/main/java/com/uas/platform/b2c/prod/commodity/model/ReleaseProductByBatch.java

@@ -230,7 +230,7 @@ public class ReleaseProductByBatch implements Serializable {
 	 * 上传时间
 	 */
 	@Column(name = "rel_createdate")
-	private Date createDate;
+	private Date createDate = new Date(System.currentTimeMillis());
 
 	/**
 	 * 产品最小包装量
@@ -510,13 +510,13 @@ public class ReleaseProductByBatch implements Serializable {
 	 * 店铺的id
 	 */
 	@Column(name = "rel_storeid")
-	private String storeid;
+	private String storeid = "";
 
 	/**
 	 * 店铺名称
 	 */
 	@Column(name = "rel_storename")
-	private String storeName;
+	private String storeName = "";
 
 	/**
 	 * 规格信息
@@ -534,7 +534,7 @@ public class ReleaseProductByBatch implements Serializable {
 	 * 物料id信息
 	 */
 	@Column(name = "rel_pronum", length = 100)
-	private String productNum;
+	private String productNum = "";
 
 	/**
 	 * 规格书信息

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

@@ -3,6 +3,7 @@ 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.Cell;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.data.domain.Page;
@@ -178,4 +179,16 @@ public interface ReleaseProductByBatchService {
      * @return 验证结果
      */
     String productReleaseValid(Long enUU, String batch);
+
+    /**
+     * 创建时间 :2016年12月11日 下午2:02:16
+     *
+     * @author yujia
+     * @param cell
+     * @param cellType
+     * @param n
+     * @param r
+     * @return Object
+     */
+    Object readWorkBookCell(Cell cell, int cellType, int r, int n);
 }

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

@@ -364,11 +364,11 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		if (CollectionUtils.isEmpty(releaseProductByBatchs)) {
 			return ;
 		}
-		for(int i = releaseProductByBatchs.size() - 1; i > -1; i--) {
+		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)) {
+				if (releaseProductByBatch.compareSameProductTagInfo(byBatch)) {
 					releaseProductByBatch.setTag("");
 					releaseProductByBatch.setTagstr("");
 					releaseProductByBatch.addErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
@@ -1475,7 +1475,8 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 * @throws @Description:
 	 *             传入单元格,类型,返回值
 	 */
-	private Object readWorkBookCell(Cell cell, int cellType, int r, int n) {
+ 	@Override
+	public Object readWorkBookCell(Cell cell, int cellType, int r, int n) {
 		Object obj = null;
 		try {
 			if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
@@ -1487,9 +1488,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 						throw new IllegalOperatorException("读取表格中"+ (r + 1)+"行"+ (n+1)+ "列的内容错误,需要文本格式的信息");
 					}
 					String str = cell.getStringCellValue().trim();
-//					Object data = getCellData(cell);
-//					String str = data == null ? "" : data.toString();
-					if(str.indexOf("\u00A0") > -1){
+					if (str.indexOf("\u00A0") > -1){
 						  str= str.replaceAll("\u00A0", "");
 					}
 					str = StringUtilB2C.replaceTabAndLineBreak(str);

+ 54 - 8
src/main/java/com/uas/platform/b2c/trade/order/controller/PurchaseProductController.java

@@ -1,9 +1,10 @@
 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.prod.commodity.service.ReleaseProductByBatchService;
 import com.uas.platform.b2c.trade.order.service.PurchaseProductService;
+import com.uas.platform.b2c.trade.order.support.AjaxUtil;
 import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.logging.BufferedLoggerManager;
@@ -15,7 +16,11 @@ 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 org.springframework.web.multipart.commons.CommonsMultipartFile;
+import org.springframework.web.servlet.ModelAndView;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
 import java.io.*;
 
 /**
@@ -37,25 +42,39 @@ public class PurchaseProductController {
     @Autowired
     private PurchaseProductService purchaseProductService;
 
+    @Autowired
+    private ReleaseProductByBatchService releaseProductByBatchService;
+
+    /**
+     * 获取批量发布商品的模板(大量)
+     *
+     * @return model and view
+     */
+    @RequestMapping(value = "/release/template", method = RequestMethod.GET)
+    public ModelAndView releasePersonalProductTemplate() {
+        LOGGER.log("买家物料", "下载Excel批量上传个人物料模板");
+        ModelAndView modelAndView = new ModelAndView();
+        modelAndView.setView(new JxlsExcelView("classpath:jxls-tpl/trade/releaseByBatch-person", "导入个人产品库-优软商城"));
+        return modelAndView;
+    }
+
     /**
      * 通过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();
+    public ResultMap releasePersonalProductByExcel(@RequestParam CommonsMultipartFile uploadItem, Integer ignoreImport) {
+        String fileName = uploadItem.getOriginalFilename();
         // 获取EXCEL后缀格式
         String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
         InputStream inputStream;
         Workbook workbook;
         try {
-            inputStream = uploadItem.getFile().getInputStream();
+            inputStream = uploadItem.getInputStream();
             // 根据表格格式分开处理
             if (JxlsExcelView.EXCEL_XLS.equals(suffix)) {
                 workbook = new HSSFWorkbook(inputStream);
@@ -64,11 +83,38 @@ public class PurchaseProductController {
             } else {
                 return ResultMap.error(new IllegalOperatorException("文件格式不正确!请上传.xls或.xlsx格式的文件"));
             }
-            ResultMap resultMap = purchaseProductService.releasePersonalProductByExcel(workbook, selfSale, currency, ignoreImport);
-            LOGGER.log("买家物料", "通过Excel批量上传个人物料");
+            ResultMap resultMap = purchaseProductService.releasePersonalProductByExcel(workbook, ignoreImport);
+            LOGGER.log("买家物料", "通过Excel批量上传个人物料-优软商城");
             return resultMap;
         } catch (IOException e) {
             return ResultMap.error(e);
         }
     }
+
+    /**
+     * 导出不合格的数据
+     *
+     * @param batch   the batch 批次号
+     * @param request the request 请求对象
+     * @param isAjax  the is ajax 是否是ajax 请求
+     * @return model and view
+     */
+    @RequestMapping(value = "/release/failure/xls", method = RequestMethod.GET)
+    public ModelAndView exportReleaseByBatchError(String batch, HttpServletRequest request, @RequestParam(defaultValue = "false") Boolean isAjax) {
+        HttpSession session = request.getSession();
+        ModelAndView modelAndView = AjaxUtil.checkIsAjax(session, isAjax);
+        if (null != modelAndView) {
+            return modelAndView;
+        }
+        Object loading = session.getAttribute("load-error-ing");
+        if (loading == null || !Boolean.valueOf(loading.toString())) {
+            session.setAttribute("load-error-ing", true);
+        }
+        modelAndView.addObject("data", releaseProductByBatchService.findFailureReleaseProductByBatch(batch));
+        String url = "classpath:jxls-tpl/trade/releaseByBatchError-person";
+        modelAndView.setView(new JxlsExcelView(url, "导出失败的个人物料-优软商城"));
+        LOGGER.log("买家物料", "以Excel形式导出失败的个人物料");
+        session.setAttribute("load-error-ing", false);
+        return modelAndView;
+    }
 }

+ 1 - 3
src/main/java/com/uas/platform/b2c/trade/order/service/PurchaseProductService.java

@@ -15,11 +15,9 @@ 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);
+    ResultMap releasePersonalProductByExcel(Workbook workbook, Integer ignoreImport);
 }

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

@@ -2,8 +2,10 @@ package com.uas.platform.b2c.trade.order.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+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.ErrorInfoConstant;
 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;
@@ -17,6 +19,7 @@ import com.uas.platform.core.util.HttpUtil;
 import com.uas.platform.core.util.serializer.FlexJsonUtils;
 import com.uas.ps.entity.Product;
 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;
@@ -73,14 +76,12 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
      * 通过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) {
+    public ResultMap releasePersonalProductByExcel(Workbook workbook, Integer ignoreImport) {
         // 先判断表格式
         Sheet sheet = workbook.getSheetAt(0);
         if (sheet.getRow(0) == null) {
@@ -102,18 +103,16 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
         Row headerRow = sheet.getRow(0);
         if (null != headerRow) {
             int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
-            // 非个人用户
-            boolean isAPerson = false;
-            // 非Pcb商品
-            boolean isPcb = false;
             // 验证模板是否为商城模板
-            releaseProductByBatchService.validateTemplate(headerRow, colNum, currency, isAPerson, isPcb);
+            validateTemplate(headerRow, colNum);
             // 去重后的数据
             List<ReleaseProductByBatch> uniqueBatchList = new ArrayList<>();
             // 为空的个数
             int blankNum;
             // 本次上传总数
             int total = 0;
+            // 批号
+            String batch = createNumberService.getTimeNumber("product$goods", 8, rowNum);
             for (int r = minExcelNumber; r <= rowNum; r++) {
                 Row row = sheet.getRow(r);
                 // 英文品牌名称
@@ -123,25 +122,23 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
                         continue;
                     }
                     ReleaseProductByBatch releaseProductByBatch = new ReleaseProductByBatch();
+                    // 初始化默认信息
+                    setProductDefaultInfo(releaseProductByBatch, batch);
                     // 将excel内容对应到ReleaseProductByBatch的字段当中
-                    blankNum = releaseProductByBatchService.convertValueToProduct(row, releaseProductByBatch, r, isAPerson, isPcb);
+                    blankNum = convertValueToProduct(row, releaseProductByBatch, r);
                     if (blankNum != 4) {
                         // 验证表格中数据是否重复,重复的取第一条数据
                         ReleaseProductByBatch uniquerProduct = validateRepeatInExcel(releaseProductByBatchArrayList, releaseProductByBatch);
                         if (null != uniquerProduct) {
                             uniqueBatchList.add(uniquerProduct);
                         }
-                        total++;
                         releaseProductByBatchArrayList.add(releaseProductByBatch);
+                        total++;
                     }
                 }
             }
-            //1:比较品牌、型号、自定义标签是否重复,2:比较六要素是否重复
-            releaseProductByBatchService.judgeSameReleaseProductByBatch(releaseProductByBatchArrayList);
             // 保存临时表信息
             releaseProductByBatchDao.save(releaseProductByBatchArrayList);
-            // 批号
-            String batch = createNumberService.getTimeNumber("product$goods", 8, rowNum);
             Long enUU = SystemSession.getUser().getEnterprise().getUu();
             // 验证数据信息是否重复
             releaseProductByBatchDao.callReleaseExistValidProcedure(batch, enUU);
@@ -149,9 +146,12 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
             // 处理上传数据
             assignmentProductInfo(enUU, modelMap, batch);
             // 验证成功后进行绑定处理
-            Integer assignNumber = assignBatch(uniqueBatchList);
-            modelMap.put("assignNumber", assignNumber);
-            modelMap.put("failure", total - assignNumber);
+            Integer assignNumber = 0;
+            if (!CollectionUtils.isEmpty(uniqueBatchList)) {
+                assignNumber = assignBatch(uniqueBatchList);
+            }
+            modelMap.put("assignSuccess", assignNumber);
+            modelMap.put("assignFailure", total - assignNumber);
             modelMap.put("total", total);
             modelMap.put("batch", batch);
             return ResultMap.success(modelMap);
@@ -159,6 +159,108 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
         return ResultMap.success();
     }
 
+    /**
+     * 初始化赋值
+     *
+     * @param aProduct 批量上传商品建立临时表存储相关信息
+     * @param batch 批号
+     */
+    private void setProductDefaultInfo(ReleaseProductByBatch aProduct, String batch) {
+        // 设置初始状态
+        aProduct.setReleaseCode(ReleaseStatus.success.value());
+        aProduct.setReleaseStatus(ReleaseStatus.success.getPhrase());
+        aProduct.setRelbatchid(batch);
+        aProduct.setUnit("PCS");
+        // 设置发布人信息
+        aProduct.setPublisherName(SystemSession.getUser().getUserName());
+        aProduct.setPublisherTel(SystemSession.getUser().getUserTel());
+        aProduct.setPublisherUu(SystemSession.getUser().getUserUU());
+    }
+
+    /**
+     * 初始化product信息,将excel内容转换为product字段值
+     *
+     * @param row 行对象
+     * @param aProduct 验证单行数据
+     * @param rowNum 行数
+     */
+    private int convertValueToProduct(Row row, ReleaseProductByBatch aProduct, int rowNum) {
+        // 统计为空的个数
+        int result = 0;
+        aProduct.setNum(rowNum - 2);
+        // 品牌
+        Object brandValue = releaseProductByBatchService.readWorkBookCell(row.getCell(UploadConstant.BRAND_ENGLISH), Cell.CELL_TYPE_STRING,
+                rowNum, UploadConstant.BRAND_ENGLISH);
+        if (StringUtils.isEmpty(brandValue)) {
+            result += 1;
+        }
+        aProduct.setBrandEnByExcel(brandValue);
+
+        // 类目
+        Object kindValue = releaseProductByBatchService.readWorkBookCell(row.getCell(UploadConstant.KIND), Cell.CELL_TYPE_STRING,
+                rowNum, UploadConstant.KIND);
+        if (StringUtils.isEmpty(kindValue)) {
+            result += 1;
+        }
+        aProduct.setKindByExcel(kindValue);
+
+        // 型号
+        Object codeValue = releaseProductByBatchService.readWorkBookCell(row.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
+                rowNum, UploadConstant.PRODUCT_CODE);
+        if (StringUtils.isEmpty(codeValue)) {
+            result += 1;
+        }
+        aProduct.setCodeByExcel(codeValue);
+
+        // 规格
+        Object specValue = releaseProductByBatchService.readWorkBookCell(row.getCell(UploadConstant.SPEC), Cell.CELL_TYPE_STRING,
+                rowNum, UploadConstant.SPEC);
+        aProduct.setSpecByExcel(specValue);
+        return result;
+    }
+
+    /**
+     * 个人物料上传模板校验
+     *
+     * @param headerRow 表头
+     * @param colNum 列数
+     */
+    private void validateTemplate(Row headerRow, int colNum) {
+        if (colNum == UploadConstant.MAX_TOTAL_COLUMN) {
+            Cell errorCell = headerRow.getCell(UploadConstant.MAX_TOTAL_COLUMN - 1);
+            Object errorCellObj = releaseProductByBatchService.readWorkBookCell(errorCell, Cell.CELL_TYPE_STRING, 0, 0);
+            String errorHead = StringUtilB2C.replaceLineBreak(String.valueOf(errorCellObj));
+            String errorMsg = "错误提示";
+            if (StringUtils.isEmpty(errorHead) || !(errorMsg.equals(errorHead))) {
+                throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
+            }
+        }
+        // 品牌
+        Object brandCellObj = releaseProductByBatchService.readWorkBookCell(headerRow.getCell(UploadConstant.BRAND_ENGLISH), Cell.CELL_TYPE_STRING,
+                0, UploadConstant.BRAND_ENGLISH);
+        if (!UploadConstant.PRODUCT_BRAND_NAME.equals(StringUtilB2C.getStr(brandCellObj))) {
+            throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
+        }
+        // 物料名称
+        Object titleCellObj = releaseProductByBatchService.readWorkBookCell(headerRow.getCell(UploadConstant.KIND), Cell.CELL_TYPE_STRING,
+                0, UploadConstant.KIND);
+        if (!UploadConstant.PRODUCT_KIND_NAME.equals(StringUtilB2C.getStr(titleCellObj))) {
+            throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
+        }
+        // 型号
+        Object codeCellObj = releaseProductByBatchService.readWorkBookCell(headerRow.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
+                0, UploadConstant.PRODUCT_CODE);
+        if (!UploadConstant.PRODUCT_CMPCODE_NAME.equals(StringUtilB2C.getStr(codeCellObj))) {
+            throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
+        }
+        // 规格
+        Object specCellObj = releaseProductByBatchService.readWorkBookCell(headerRow.getCell(UploadConstant.SPEC), Cell.CELL_TYPE_STRING,
+                0, UploadConstant.SPEC);
+        if (!UploadConstant.PRODUCT_SPEC_NAME.equals(StringUtilB2C.getStr(specCellObj))) {
+            throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
+        }
+    }
+
     /**
      * 将去重的数据批量绑定到个人物料库
      *
@@ -210,6 +312,16 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
             if (StringUtils.isEmpty(each.getErrmsg()) && !each.equals(aBatch)) {
                 return aBatch;
             }
+            if (aBatch.compareSameProductTagInfo(each)) {
+                aBatch.addErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
+                aBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
+                aBatch.setReleaseCode(ReleaseStatus.had_exists.value());
+                if (aBatch.getErrmsg().substring(0, 1).equals(",")) {
+                    aBatch.setErrmsg(aBatch.getErrmsg().substring(1));
+                }
+            } else {
+                return aBatch;
+            }
         }
         return null;
     }
@@ -228,6 +340,11 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
             product.setBrand(batch.getBrandNameEn() != null ? batch.getBrandNameEn() : batch.getBrandNameCn());
             product.setUserUU(SystemSession.getUser().getUserUU());
             product.setCode(batch.getCode());
+            // 没有编号设置编号
+            if (null == product.getCode()) {
+                String code = "B2CPR" + StringUtilB2C.getRandomNumber(6);
+                product.setCode(code);
+            }
             // 交期默认赋值为0
             Double leadTime = 0D;
             product.setLeadTime(leadTime);
@@ -236,6 +353,7 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
             product.setEnUU(SystemSession.getUser().getEnterprise().getUu());
             product.setKind(batch.getKindName());
             product.setUnit(batch.getUnit());
+            product.setTitle(batch.getKindName());
             productList.add(product);
         });
         return productList;

+ 42 - 0
src/main/java/com/uas/platform/b2c/trade/order/support/AjaxUtil.java

@@ -0,0 +1,42 @@
+package com.uas.platform.b2c.trade.order.support;
+
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
+
+import javax.servlet.http.HttpSession;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * ajax判断相关
+ *
+ * @author hejq
+ * @date 2018-09-19 14:54
+ */
+public class AjaxUtil {
+
+    /**
+     * 校验前端是否是ajax请求
+     *
+     * @param session HttpSession
+     * @param isAjax 是否是ajax请求
+     * @return ModelAndView or null
+     */
+    public static ModelAndView checkIsAjax(HttpSession session, Boolean isAjax) {
+        ModelAndView modelAndView = new ModelAndView();
+        if (isAjax) {
+            Object loading = session.getAttribute("load-error-ing");
+            MappingJackson2JsonView view = new MappingJackson2JsonView();
+            Map attributes = new HashMap();
+            if (loading == null || !Boolean.valueOf(loading.toString())) {
+                attributes.put("load", false);
+            } else if (Boolean.valueOf(loading.toString())) {
+                attributes.put("load", true);
+            }
+            view.setAttributesMap(attributes);
+            modelAndView.setView(view);
+            return modelAndView;
+        }
+        return null;
+    }
+}