Переглянути джерело

个人产品库 初步搭建7 -完善控制模版上传的动作,还差加规格以及下载 错误excel

wangdy 8 роки тому
батько
коміт
723a2f8f89

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

@@ -109,4 +109,14 @@ public final class UploadConstant {
      * 用户可能直接用导入失败的表格进行导入
      */
     public static final int MAX_TOTAL_COLUMN = 17;
+
+    /**
+     * 个人导入表的最大列数
+     */
+    public static final int TOTAL_COLUMN_PERSON = 3;
+
+    /**
+     * 个人用户可能直接用导入失败的表格进行导入
+     */
+    public static final int MAX_TOTAL_COLUMN_PERSON = 4;
 }

+ 9 - 5
src/main/java/com/uas/platform/b2c/prod/commodity/controller/ReleaseProductByBatchController.java

@@ -1,6 +1,7 @@
 package com.uas.platform.b2c.prod.commodity.controller;
 
 import com.uas.platform.b2c.common.base.model.FileUpload;
+import com.uas.platform.b2c.core.constant.IntegerConstant;
 import com.uas.platform.b2c.core.support.log.UsageBufferedLogger;
 import com.uas.platform.b2c.core.support.view.JxlsExcelView;
 import com.uas.platform.b2c.core.utils.FastjsonUtils;
@@ -202,7 +203,7 @@ public class ReleaseProductByBatchController {
      * @return model map
      */
     @RequestMapping(value = "/release/excel", method = RequestMethod.POST)
-    public ModelMap releaseByExcel(FileUpload uploadItem, @RequestParam("selfSale") Boolean selfSale, String currency) {
+    public ModelMap releaseByExcel(FileUpload uploadItem, @RequestParam("selfSale") Boolean selfSale, String currency, Integer isPerson) {
         ModelMap map = new ModelMap();
         String fileName = uploadItem.getFile().getOriginalFilename();
         String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
@@ -217,7 +218,7 @@ public class ReleaseProductByBatchController {
             } else {
                 throw new IllegalOperatorException("文件格式不正确!请上传.xls或.xlsx格式的文件");
             }
-            map = releaseProductByBatchService.releaseByWorkbook(workbook, selfSale, currency);
+            map = releaseProductByBatchService.releaseByWorkbook(workbook, selfSale, currency, isPerson);
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -287,15 +288,18 @@ public class ReleaseProductByBatchController {
      * @return model and view
      */
     @RequestMapping(value = "/release/template", method = RequestMethod.GET)
-    public ModelAndView exportOrderses(String currency) {
+    public ModelAndView exportOrderses(String currency, Integer isPerson) {
         ModelAndView modelAndView = new ModelAndView();
+        logger.log("商品批次", "下载批量上架商品的Excel模板");
+        if (null != isPerson && isPerson.intValue() == IntegerConstant.YES_SHORT.intValue()) {
+            modelAndView.setView(new JxlsExcelView("classpath:jxls-tpl/trade/releasebyBatch-person", "个人产品导入模板-优软商城"));
+            return modelAndView;
+        }
         if (Currency.USD.equals(currency)) {
             modelAndView.setView(new JxlsExcelView("classpath:jxls-tpl/trade/releasebyBatch-usd", "产品导入模板-优软商城"));
         } else {
             modelAndView.setView(new JxlsExcelView("classpath:jxls-tpl/trade/releaseByBatch-rmb", "产品导入模板-优软商城"));
         }
-
-        logger.log("商品批次", "下载批量上架商品的Excel模板");
         return modelAndView;
     }
 }

+ 14 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/Product.java

@@ -320,6 +320,12 @@ public class Product {
 	@Column(name = "pr_batchcount")
 	private Integer batchCount;
 
+	/**
+	 * 器件规格
+	 */
+	@Column(name = "pr_specification")
+	private String specification;
+
 	public Product() {
 	}
 
@@ -727,4 +733,12 @@ public class Product {
 	public void setProductDetail(ProductDetail productDetail) {
 		this.productDetail = productDetail;
 	}
+
+	public String getSpecification() {
+		return specification;
+	}
+
+	public void setSpecification(String specification) {
+		this.specification = specification;
+	}
 }

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

@@ -667,12 +667,12 @@ public class ReleaseProductByBatch implements Serializable {
 	public int hashCode() {
 		int result = brandNameEn.hashCode();
 		result = 31 * result + code.hashCode();
-		result = 31 * result + minBuyQtyStr.hashCode();
-		result = 31 * result + productDate.hashCode();
-		result = 31 * result + minPackageStr.hashCode();
-		result = 31 * result + packaging.hashCode();
-		result = 31 * result + selfMaxDeliveryStr.hashCode();
-		result = 31 * result + selfMinDeliveryStr.hashCode();
+		result = 31 * result + (minBuyQtyStr == null ? 0 : minBuyQtyStr.hashCode());
+		result = 31 * result + (productDate == null ? 0 : productDate.hashCode());
+		result = 31 * result + (minPackageStr == null ? 0 : minPackageStr.hashCode());
+		result = 31 * result + (packaging == null ? 0 : packaging.hashCode());
+		result = 31 * result + (selfMaxDeliveryStr == null ? 0 : selfMaxDeliveryStr.hashCode());
+		result = 31 * result + (selfMinDeliveryStr == null ? 0 : selfMinDeliveryStr.hashCode());
 		return result;
 	}
 

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

@@ -32,7 +32,7 @@ public interface ReleaseProductByBatchService {
      * @param currency
      * @return model map
      */
-    public ModelMap releaseByWorkbook(Workbook workbook, Boolean selfSale, String currency);
+    public ModelMap releaseByWorkbook(Workbook workbook, Boolean selfSale, String currency, Integer isPerson);
 
     /**
      * 根据发布者UU获取一组产品的信息

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

@@ -111,14 +111,25 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 * @author hejq
 	 */
 	@Override
-	public ModelMap releaseByWorkbook(Workbook workbook, Boolean selfSale, String currency) {
+	public ModelMap releaseByWorkbook(Workbook workbook, Boolean selfSale, String currency, Integer isPerson) {
+		// 是否上传个人物料
+		boolean isAPerson = false;
+		if (null != isPerson && isPerson.intValue() == IntegerConstant.YES_SHORT.intValue()) {
+			isAPerson = true;
+		}
 		ModelMap modelMap = new ModelMap();
 		Set<ReleaseProductByBatch> releaseProductByBatchs = new HashSet<>();
 		// 获取第一个工作表
 		Sheet sheet = workbook.getSheetAt(0);
 		int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
-		if (colNum != UploadConstant.TOTAL_COLUMN && colNum != UploadConstant.MAX_TOTAL_COLUMN) {
-			throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
+		if (isAPerson) {
+			if (colNum != UploadConstant.TOTAL_COLUMN_PERSON && colNum != UploadConstant.MAX_TOTAL_COLUMN_PERSON) {
+				throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
+			}
+		} else {
+			if (colNum != UploadConstant.TOTAL_COLUMN && colNum != UploadConstant.MAX_TOTAL_COLUMN) {
+				throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
+			}
 		}
 		int rowNum = sheet.getLastRowNum();
 		if (rowNum > 2000) {
@@ -132,8 +143,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		int blankNum = 0;
 		if (headerRow != null) {
 			// 验证模板是否为商城模板
-			validateTemplate(headerRow, colNum, currency);
-
+			validateTemplate(headerRow, colNum, currency, isAPerson);
 			for (int r = 2; r <= rowNum; r++) {
 				Row row = sheet.getRow(r);
 				// 英文品牌名称
@@ -145,14 +155,16 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 					ReleaseProductByBatch releaseProductByBatch = new ReleaseProductByBatch();
 					// 初始化默认信息
 					setProductDefaultInfo(releaseProductByBatch, batch, currency, storeIn);
-
+// TODO 个人库验证
 					// 将excel内容对应到ReleaseProductByBatch的字段当中
-					blankNum = convertValueToProduct(row, releaseProductByBatch, r);
-
-					// 解析返回分段价格list
-					List<GoodsQtyPrice> qtyPriceList = initQtyPriceByExcel(row, releaseProductByBatch, r);
-					if (!CollectionUtils.isEmpty(qtyPriceList)) {
-						releaseProductByBatch.setPrices(qtyPriceList);
+					blankNum = convertValueToProduct(row, releaseProductByBatch, r, isAPerson);
+// TODO 个人库验证
+					if (!isAPerson) {
+						// 解析返回分段价格list
+						List<GoodsQtyPrice> qtyPriceList = initQtyPriceByExcel(row, releaseProductByBatch, r);
+						if (!CollectionUtils.isEmpty(qtyPriceList)) {
+							releaseProductByBatch.setPrices(qtyPriceList);
+						}
 					}
 
 					if (!StringUtils.isEmpty(releaseProductByBatch.getErrmsg())) {
@@ -213,36 +225,53 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 * @param colNum	总列
 	 * @param currency	币别
 	 */
-	private void validateTemplate(Row headerRow, int colNum, String currency) {
-		if (colNum == UploadConstant.MAX_TOTAL_COLUMN) {
-			Cell errorCell = headerRow.getCell(UploadConstant.MAX_TOTAL_COLUMN - 1);
-			Object errorCellObj = readWorkBookCell(errorCell, Cell.CELL_TYPE_STRING, 0, 0);
-			String errorHead = StringUtilB2C.replaceLineBreak(String.valueOf(errorCellObj));
-			if (StringUtils.isEmpty(errorHead) || !("错误提示".equals(errorHead))) {
-				throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
+	private void validateTemplate(Row headerRow, int colNum, String currency, boolean isAPerson) {
+		if (isAPerson) {
+			if (colNum == UploadConstant.MAX_TOTAL_COLUMN_PERSON) {
+				Cell errorCell = headerRow.getCell(UploadConstant.MAX_TOTAL_COLUMN_PERSON - 1);
+				Object errorCellObj = readWorkBookCell(errorCell, Cell.CELL_TYPE_STRING, 0, 0);
+				String errorHead = StringUtilB2C.replaceLineBreak(String.valueOf(errorCellObj));
+				if (StringUtils.isEmpty(errorHead) || !("错误提示".equals(errorHead))) {
+					throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
+				}
+			}
+			Object codeCellObj = readWorkBookCell(headerRow.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
+					0, UploadConstant.PRODUCT_CODE);
+			if (!"产品型号".equals(StringUtilB2C.getStr(codeCellObj))) {
+				throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
 			}
-		}
-		Object codeCellObj = readWorkBookCell(headerRow.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
-				0, UploadConstant.PRODUCT_CODE);
-		if (!"产品型号".equals(StringUtilB2C.getStr(codeCellObj))) {
-			throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
-		}
-		Object priceCellObj = readWorkBookCell(headerRow.getCell(UploadConstant.PRICE_START), Cell.CELL_TYPE_STRING,
-				0, UploadConstant.PRICE_START);
-		if (StringUtils.isEmpty(priceCellObj)) {
-			throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
 		} else {
-			String title = StringUtilB2C.replaceLineBreak(priceCellObj.toString());
-			if (Currency.USD.equals(currency)) {
-				if (!title.equals("USD单价1")) {
-					throw new IllegalOperatorException("您上传的文件表头与美金模板不符");
+			if (colNum == UploadConstant.MAX_TOTAL_COLUMN) {
+				Cell errorCell = headerRow.getCell(UploadConstant.MAX_TOTAL_COLUMN - 1);
+				Object errorCellObj = readWorkBookCell(errorCell, Cell.CELL_TYPE_STRING, 0, 0);
+				String errorHead = StringUtilB2C.replaceLineBreak(String.valueOf(errorCellObj));
+				if (StringUtils.isEmpty(errorHead) || !("错误提示".equals(errorHead))) {
+					throw new IllegalOperatorException("表格模板不正确!请重新下载最新模板");
 				}
+			}
+			Object codeCellObj = readWorkBookCell(headerRow.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
+					0, UploadConstant.PRODUCT_CODE);
+			if (!"产品型号".equals(StringUtilB2C.getStr(codeCellObj))) {
+				throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
+			}
+			Object priceCellObj = readWorkBookCell(headerRow.getCell(UploadConstant.PRICE_START), Cell.CELL_TYPE_STRING,
+					0, UploadConstant.PRICE_START);
+			if (StringUtils.isEmpty(priceCellObj)) {
+				throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
 			} else {
-				if (!title.equals("RMB单价1")) {
-					throw new IllegalOperatorException("您上传的文件表头与人民币模板不符");
+				String title = StringUtilB2C.replaceLineBreak(priceCellObj.toString());
+				if (Currency.USD.equals(currency)) {
+					if (!title.equals("USD单价1")) {
+						throw new IllegalOperatorException("您上传的文件表头与美金模板不符");
+					}
+				} else {
+					if (!title.equals("RMB单价1")) {
+						throw new IllegalOperatorException("您上传的文件表头与人民币模板不符");
+					}
 				}
 			}
 		}
+
 	}
 
 	/**
@@ -433,7 +462,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 * @param aProduct 验证单行数据
 	 * @param rowNum 行数
 	 */
-	private int convertValueToProduct(Row row, ReleaseProductByBatch aProduct, int rowNum) {
+	private int convertValueToProduct(Row row, ReleaseProductByBatch aProduct, int rowNum, boolean isAPerson) {
 		// 统计为空的个数
 		int result = 0;
 		Object codeValue = readWorkBookCell(row.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
@@ -450,49 +479,52 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		}
 		aProduct.setBrandEnByExcel(brandValue);
 
-		Object breakValue = readWorkBookCell(row.getCell(UploadConstant.BREAK_UP), Cell.CELL_TYPE_STRING,
-				rowNum, UploadConstant.BREAK_UP);
-		aProduct.setBreakUpByExcel(breakValue);
+		if (!isAPerson) {
+			Object breakValue = readWorkBookCell(row.getCell(UploadConstant.BREAK_UP), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.BREAK_UP);
+			aProduct.setBreakUpByExcel(breakValue);
 
-		Object reserveValue = readWorkBookCell(row.getCell(UploadConstant.RESERVE_NUMBER), Cell.CELL_TYPE_STRING,
-				rowNum, UploadConstant.RESERVE_NUMBER);
-		if (StringUtils.isEmpty(reserveValue)) {
-			result += 1;
-		}
-		aProduct.setReserveByExcel(reserveValue);
+			Object reserveValue = readWorkBookCell(row.getCell(UploadConstant.RESERVE_NUMBER), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.RESERVE_NUMBER);
+			if (StringUtils.isEmpty(reserveValue)) {
+				result += 1;
+			}
+			aProduct.setReserveByExcel(reserveValue);
+
+			Object produceValue = readWorkBookCell(row.getCell(UploadConstant.PRODUCE_DATE), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.PRODUCE_DATE);
+			aProduct.setProductDateByExcel(produceValue);
+
+			Object packageMethodValue = readWorkBookCell(row.getCell(UploadConstant.PACKAGE_METHOD), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.PACKAGE_METHOD);
+			aProduct.setPackagingByExcel(packageMethodValue);
+
+			Object minValue = readWorkBookCell(row.getCell(UploadConstant.MIN_DELIVERY), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.MIN_DELIVERY);
+			Object maxValue = readWorkBookCell(row.getCell(UploadConstant.MAX_DELIVERY), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.MAX_DELIVERY);
+			aProduct.setDeliveryByExcel(minValue, maxValue);
+			if (!StringUtils.isEmpty(minValue) || !StringUtils.isEmpty(maxValue)) {
+				setDeliveryTime(aProduct, minValue, maxValue);
+			}
 
-		Object produceValue = readWorkBookCell(row.getCell(UploadConstant.PRODUCE_DATE), Cell.CELL_TYPE_STRING,
-				rowNum, UploadConstant.PRODUCE_DATE);
-		aProduct.setProductDateByExcel(produceValue);
+			Object packageNumValue = readWorkBookCell(row.getCell(UploadConstant.PACKAGE_NUMBER), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.PACKAGE_NUMBER);
+			aProduct.setMinPackageByExcel(packageNumValue);
 
-		Object packageMethodValue = readWorkBookCell(row.getCell(UploadConstant.PACKAGE_METHOD), Cell.CELL_TYPE_STRING,
-				rowNum, UploadConstant.PACKAGE_METHOD);
-		aProduct.setPackagingByExcel(packageMethodValue);
+			Object buyQtyValue = readWorkBookCell(row.getCell(UploadConstant.BUY_MIN_QTY), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.BUY_MIN_QTY);
+			aProduct.setMinBuyQtyByExcel(buyQtyValue);
 
-		Object minValue = readWorkBookCell(row.getCell(UploadConstant.MIN_DELIVERY), Cell.CELL_TYPE_STRING,
-				rowNum, UploadConstant.MIN_DELIVERY);
-		Object maxValue = readWorkBookCell(row.getCell(UploadConstant.MAX_DELIVERY), Cell.CELL_TYPE_STRING,
-				rowNum, UploadConstant.MAX_DELIVERY);
-		aProduct.setDeliveryByExcel(minValue, maxValue);
-		if (!StringUtils.isEmpty(minValue) || !StringUtils.isEmpty(maxValue)) {
-			setDeliveryTime(aProduct, minValue, maxValue);
+			Object tagValue = readWorkBookCell(row.getCell(UploadConstant.CUSTOM_LABEL), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.CUSTOM_LABEL);
+			aProduct.setTagByExcel(tagValue);
+			// 自定义标签不为null,则检查是否重复
+			if (aProduct.getCode() != null && aProduct.getBrandNameEn() != null && aProduct.getTag() != null) {
+				resetTag(aProduct);
+			}
 		}
 
-        Object packageNumValue = readWorkBookCell(row.getCell(UploadConstant.PACKAGE_NUMBER), Cell.CELL_TYPE_STRING,
-                rowNum, UploadConstant.PACKAGE_NUMBER);
-		aProduct.setMinPackageByExcel(packageNumValue);
-
-        Object buyQtyValue = readWorkBookCell(row.getCell(UploadConstant.BUY_MIN_QTY), Cell.CELL_TYPE_STRING,
-                rowNum, UploadConstant.BUY_MIN_QTY);
-		aProduct.setMinBuyQtyByExcel(buyQtyValue);
-
-		Object tagValue = readWorkBookCell(row.getCell(UploadConstant.CUSTOM_LABEL), Cell.CELL_TYPE_STRING,
-				rowNum, UploadConstant.CUSTOM_LABEL);
-		aProduct.setTagByExcel(tagValue);
-		// 自定义标签不为null,则检查是否重复
-		if (aProduct.getCode() != null && aProduct.getBrandNameEn() != null && aProduct.getTag() != null) {
-			resetTag(aProduct);
-		}
 		return result;
 	}
 

BIN
src/main/resources/jxls-tpl/trade/releaseByBatch-person.xls


BIN
src/main/resources/jxls-tpl/trade/releaseByBatch-rmb.xls


+ 8 - 3
src/main/webapp/resources/js/vendor/controllers/forstore/vendor_upload_ctrl.js

@@ -201,11 +201,16 @@ define([ 'app/app' ], function(app) {
 				toaster.pop('info', '请选择需要上传的文件');
 				return;
 			}
+			if ($rootScope.$$productOn.tab === 'bathOnPerson') {
+				var param = {selfSale : $scope.batch.sellType == 'self', currency : $scope.batch.currency, isPerson : 1};
+			} else {
+                var param = {selfSale : $scope.batch.sellType == 'self', currency : $scope.batch.currency};
+			}
 			$upload.upload({
 				url: 'release/product/release/excel',
 				file: file,
 				method: 'POST',
-				params : {selfSale : $scope.batch.sellType == 'self', currency : $scope.batch.currency}
+				params : param
 			}).success(function(data) {
 				$scope.selectFile(' ');
 				$scope.batch.myFiles = [];
@@ -261,10 +266,10 @@ define([ 'app/app' ], function(app) {
 				});
 				modalInstance.result.then(function(response) {
 				}, function(res) {
-					window.location.href = $rootScope.rootPath + '/release/product/release/template?currency' + '=' + $scope.batch.currency;
+					window.location.href = $rootScope.rootPath + '/release/product/release/template?currency' + '=' + $scope.batch.currency + ($rootScope.$$productOn.tab == 'bathOnPerson' ? '&isPerson=1' : '');
 				});
 			} else {
-				window.location.href = $rootScope.rootPath + '/release/product/release/template?currency' + '=' + $scope.batch.currency;
+				window.location.href = $rootScope.rootPath + '/release/product/release/template?currency' + '=' + $scope.batch.currency + ($rootScope.$$productOn.tab == 'bathOnPerson' ? '&isPerson=1' : '');
 			}
 		};
 

+ 1 - 1
src/main/webapp/resources/view/vendor/forstore/vendor_material_person.html

@@ -1589,7 +1589,7 @@
 						</td>
 						<td class="edit">
 							<span name="delete-material" ng-show="!isBatch && !material.exPandOper && !material.addGoodsOper" ng-click="deleteMaterial(material)"><span>删除</span></span>
-							<span ng-show="!isBatch && !material.exPandOper && !material.addGoodsOper" ng-click="showShelfArea(material)"><span>添加产品</span></span>
+							<!--<span ng-show="!isBatch && !material.exPandOper && !material.addGoodsOper" ng-click="showShelfArea(material)"><span>添加产品</span></span>-->
 							<span ng-if="material.batchCount" ng-show="!isBatch && !material.exPandOper && !material.addGoodsOper" ng-click="expandGoods(material)"><span>展开<i class="fa fa-angle-down" style="margin-left:2px;"></i></span></span>
 							<!--收起-->
 							<span ng-show="!isBatch && material.exPandOper" ng-click="disExpandGoods(material)" class="packUp"><span>收起<i class="fa fa-angle-up" style="margin-left:2px;"></i></span></span>