Browse Source

物料上传增加对kind的赋值

hejq 7 years ago
parent
commit
f24eda90b5

+ 5 - 11
src/main/java/com/uas/platform/b2b/controller/PurcProductController.java

@@ -155,24 +155,18 @@ public class PurcProductController {
 	 */
 	@RequestMapping(value = "/edit/release/excel", method = RequestMethod.POST)
 	public ModelMap releaseByExcel(FileUpload uploadItem) throws IOException,IllegalOperatorException {
-		ModelMap map = new ModelMap();
 		String fileName = uploadItem.getFile().getOriginalFilename();
 		String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
-		InputStream is = null;
-		Workbook workbook = null;
-//		try {
-		is = uploadItem.getFile().getInputStream();
-		if ("xls".equals(suffix)) {
+		Workbook workbook;
+		InputStream is = uploadItem.getFile().getInputStream();
+		if (JxlsExcelView.EXCEL_XLS.equals(suffix)) {
 			workbook = new HSSFWorkbook(is);
-		} else if ("xlsx".equals(suffix)) {
+		} else if (JxlsExcelView.EXCEL_XLSX.equals(suffix)) {
 			workbook = new XSSFWorkbook(is);
 		} else {
 			throw new IllegalOperatorException("文件格不正确,请上传.xls或.xlsx的文件");
 		}
-		map = purcProductService.releaseByWorkbook(workbook);
-//		} catch (Exception e) {
-//			e.printStackTrace();
-//		}
+		ModelMap map = purcProductService.releaseByWorkbook(workbook);
 		logger.log("商品批次", "[" + SystemSession.getUser().getUserName() + "]通过excel导入了物料,数量为" +  map.get("success"));
 		return map;
 	}

+ 8 - 2
src/main/java/com/uas/platform/b2b/service/impl/PurcProductServiceImpl.java

@@ -65,8 +65,10 @@ public class PurcProductServiceImpl implements PurcProductService {
         short isSale = Constant.NO;
         short isPurchase = Constant.YES;
         String importId = StringUtil.getRandomNumber(8);
+        // 物料信息开始的行数
+        int productNum = 3;
         if (headerRow != null) {
-            for (int r = 3; r <= rowNum; r++) {
+            for (int r = productNum; r <= rowNum; r++) {
                 Row row = sheet.getRow(r);
                 if (row != null && (row.getCell(1) != null && row.getCell(1).getCellType() != Cell.CELL_TYPE_BLANK
                         || row.getCell(2) != null && row.getCell(2).getCellType() != Cell.CELL_TYPE_BLANK
@@ -230,10 +232,14 @@ public class PurcProductServiceImpl implements PurcProductService {
             String importId = temps.get(0).getPr_import_id();
             // 已匹配+未匹配到的物料
             List<Product> products = productTempDao.getProducts(importId);
+            // 成功标志
+            final String TRUE_SIGN = "true";
+            // 成功返回值
+            final String SUCCESS_CODE = "success";
             try {
                 // 更新物料并插入个人物料
                 ModelMap map = ProductUtils.paginationUpdateAndAddToProductUser(products);
-                if ("true".equals(map.get("success"))) {
+                if (TRUE_SIGN.equals(map.get(SUCCESS_CODE))) {
                     modelMap.put("success", null != map.get("result") ? map.get("result") : 0);
                 } else {
                     modelMap.put("error", "物料添加出现异常(" + null != map.get("message") ? map.get("message") : "" + ")");