浏览代码

修改新增采购订单批量上传物料方法

hejq 8 年之前
父节点
当前提交
ea328f202c

+ 149 - 82
src/main/java/com/uas/platform/b2b/service/impl/PurcOrderServiceImpl.java

@@ -64,8 +64,8 @@ public class PurcOrderServiceImpl implements PurcOrderService {
 	public ModelMap relieve(Long id) {
 		ModelMap map = new ModelMap();
 		Vendor vendor = vendorDao.findOne(id);
-		vendor.setVendswitch((short) 0);
-		vendor = vendorDao.save(vendor);
+		vendor.setVendswitch(Constant.NO);
+		vendorDao.save(vendor);
 		map.put("success", "已取消供应商关系");
 		return map;
 	}
@@ -74,8 +74,8 @@ public class PurcOrderServiceImpl implements PurcOrderService {
 	public ModelMap activeVend(Long id) {
 		ModelMap map = new ModelMap();
 		Vendor vendor = vendorDao.findOne(id);
-		vendor.setVendswitch((short) 1);
-		vendor = vendorDao.save(vendor);
+		vendor.setVendswitch(Constant.YES);
+		vendorDao.save(vendor);
 		map.put("success", "已建立供应商关系");
 		return map;
 	}
@@ -84,7 +84,7 @@ public class PurcOrderServiceImpl implements PurcOrderService {
 	public ModelMap relieveServicer(Long id) {
 		ModelMap map = new ModelMap();
 		Vendor vendor = vendorDao.findOne(id);
-		vendor.setServicerswitch((short) 0);
+		vendor.setServicerswitch(Constant.NO);
 		vendorDao.save(vendor);
 		map.put("success", "已取消服务商关系");
 		return map;
@@ -94,7 +94,7 @@ public class PurcOrderServiceImpl implements PurcOrderService {
 	public ModelMap activeServicer(Long id) {
 		ModelMap map = new ModelMap();
 		Vendor vendor = vendorDao.findOne(id);
-		vendor.setServicerswitch((short) 1);
+		vendor.setServicerswitch(Constant.YES);
 		vendorDao.save(vendor);
 		map.put("success", "已建立服务商关系");
 		return map;
@@ -104,8 +104,8 @@ public class PurcOrderServiceImpl implements PurcOrderService {
 	public ModelMap disableCust(Long id) {
 		ModelMap map = new ModelMap();
 		Vendor vendor = vendorDao.findOne(id);
-		vendor.setCustswitch((short) 0);
-		vendor = vendorDao.save(vendor);
+		vendor.setCustswitch(Constant.NO);
+		vendorDao.save(vendor);
 		map.put("success", "已取消客户关系");
 		return map;
 	}
@@ -114,8 +114,8 @@ public class PurcOrderServiceImpl implements PurcOrderService {
 	public ModelMap activeCust(Long id) {
 		ModelMap map = new ModelMap();
 		Vendor vendor = vendorDao.findOne(id);
-		vendor.setCustswitch((short) 1);
-		vendor = vendorDao.save(vendor);
+		vendor.setCustswitch(Constant.YES);
+		vendorDao.save(vendor);
 		map.put("success", "已建立客户关系");
 		return map;
 	}
@@ -124,129 +124,196 @@ public class PurcOrderServiceImpl implements PurcOrderService {
 	public ModelMap releaseByWorkbook(Workbook workbook) throws Exception {
 		ModelMap modelMap = new ModelMap();
 		List<String> alters = new ArrayList<String>();
-		List<String> infos = new ArrayList<String>();
 		List<ProductInfo> productInfos = new ArrayList<ProductInfo>();
 		Sheet sheet = workbook.getSheetAt(0);
 		int rowNum = sheet.getLastRowNum();
 		Row headerRow = sheet.getRow(0);
 		int total = 0;
+		int success = 0;
 		if (headerRow != null) {
 			for (int r = 3; r <= rowNum; r++) {
-				Row row = sheet.getRow(r);
-				if (row != null && row.getCell(0) != null && row.getCell(0).getCellType() != Cell.CELL_TYPE_BLANK) {
+			    int line = r + 1;
+                Row row = sheet.getRow(r);
+				if (row != null) {
+				    int failure =  0;
 					total++;
 					Product product = new Product();
 					ProductInfo productInfo = new ProductInfo();
 
 					// 商品名称
-					if (row.getCell(0) != null) {
+					if (row.getCell(0) != null && row.getCell(0).getCellType() != Cell.CELL_TYPE_BLANK) {
 						row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
-						product.setTitle(row.getCell(0).getStringCellValue().trim());
+						try {
+							product.setTitle(row.getCell(0).getStringCellValue().trim());
+						} catch (Exception e) {
+                            alters.add("第" + line + "行第" + 1 + "列名称格式不正确");
+                            failure++;
+						}
+					} else {
+                        alters.add("第" + line + "行第" + 1 + "列名称未填写");
+                        failure++;
 					}
 
 					// 编号
 					if (row.getCell(1) != null) {
 						row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
-						String code = row.getCell(1).getStringCellValue().trim();
-						product.setCode(code);
+						try {
+							product.setCode(row.getCell(1).getStringCellValue().trim());
+						} catch (Exception e) {
+                            alters.add("第" + line + "行第" + 2 + "列编号格式不正确");
+                            failure++;
+						}
 					}
 
 					// 规格型号
-					if (row.getCell(2) != null) {
+					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());
+						try {
+							product.setSpec(row.getCell(2).getStringCellValue().trim());
+						} catch (Exception e) {
+                            alters.add("第" + line + "行第" + 3 + "规格型号格式不正确");
+                            failure++;
+						}
+					} else {
+                        alters.add("第" + line + "行第" + 3 + "列规格型号未填写");
+                        failure++;
 					}
 
 					// 原厂型号
 					if (row.getCell(3) != null) {
 						row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
-						product.setCmpCode(row.getCell(3).getStringCellValue().trim());
+						try {
+							product.setCmpCode(row.getCell(3).getStringCellValue().trim());
+						} catch (Exception e) {
+                            alters.add("第" + line + "行第" + 4 + "列原厂型号格式不正确");
+                            failure++;
+						}
 					}
 
 					// 数量
-					if (row.getCell(4) != null) {
+					if (row.getCell(4) != null && row.getCell(4).getCellType() != Cell.CELL_TYPE_BLANK) {
 						row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
-						productInfo.setAmount(Double.valueOf(row.getCell(4).getStringCellValue().trim()));
+						try {
+							productInfo.setAmount(Double.valueOf(row.getCell(4).getStringCellValue().trim()));
+						} catch (Exception e) {
+                            alters.add("第" + line + "行第" + 5 + "列数量不正确");
+                            failure++;
+						}
+					} else {
+                        alters.add("第" + r + "行第" + 5 + "列数量未填写");
+                        failure++;
 					}
+
 					// 含税单价
-					if (row.getCell(5) != null) {
+					if (row.getCell(5) != null && row.getCell(5).getCellType() != Cell.CELL_TYPE_BLANK) {
 						row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
-						productInfo.setRateprice(Double.valueOf(row.getCell(5).getStringCellValue().trim()));
+						try {
+							productInfo.setRateprice(Double.valueOf(row.getCell(5).getStringCellValue().trim()));
+						} catch (Exception e) {
+                            alters.add("第" + line + "行第" + 6 + "列含税单价不正确");
+                            failure++;
+						}
+					} else {
+                        alters.add("第" + line + "行第" + 6 + "列含税单价未填写");
+                        failure++;
 					}
+
 					// 税率
 					if (row.getCell(6) != null) {
 						row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
-						productInfo.setRate(Integer.valueOf(row.getCell(6).getStringCellValue().trim()));
+						try {
+							productInfo.setRate(Integer.valueOf(row.getCell(6).getStringCellValue().trim()));
+						} catch (Exception e) {
+                            alters.add("第" + line + "行第" + 7 + "列税率不正确");
+                            failure++;
+						}
 					}
+
 					// 交货日期
 					if (row.getCell(7) != null && row.getCell(7).getDateCellValue() != null) {
-						productInfo.setDate(row.getCell(7).getDateCellValue());
+						try {
+							productInfo.setDate(row.getCell(7).getDateCellValue());
+						} catch (Exception e) {
+                            alters.add("第" + line + "行第" + 8 + "列交货日期不正确");
+                            failure++;
+						}
 					}
+
 					// 备注
 					if (row.getCell(8) != null) {
 						row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
 						productInfo.setRemark(row.getCell(8).getStringCellValue());
 					}
-					product.setEnUU(SystemSession.getUser().getEnterprise().getUu());
-					product.setUserUU(SystemSession.getUser().getUserUU());
-					product.setSourceApp("B2B");
-					product.setIsSale((short) 1);
-					if (alters.size() > 0) {
-						modelMap.put("alters", alters);
-					}
-					if (infos.size() > 0) {
-						modelMap.put("infos", infos);
-					}
-					if (product.getTitle() != null) {
-						modelMap.put("total", total);
-						modelMap.put("success", total - alters.size());
-						//设置默认单位
-						product.setUnit("PCS");
-						//为了同步商城数据标准,标准字段也赋值
-						product.setPcmpcode(product.getCmpCode());
-						product.setPbranden(product.getPbranden() == null ? product.getBrand() : product.getPbranden());
-						// 新增数据时间
-						product.setErpDate(new Date());
-						product.setStandard(Constant.NO);
-						product.setIsPurchase(Constant.YES);
-						// 如果物料不存在,则进行存储
-						if(product.getCode() != null) {
-							List<Product> prods = productDao.findByEnUUAndCode(SystemSession.getUser().getEnterprise().getUu(), product.getCode());
-							if (CollectionUtils.isEmpty(prods)) {
-								Long prId = ProductUtils.updateOne(product);
-								product.setId(prId);
-							} else {
-								product = prods.get(0);
-							}
-						} else {// 物料编码不存在
-							List<Product> prods = productDao
-									.findByEnUUAndTitle(SystemSession.getUser().getEnterprise().getUu(), product.getTitle());
-							if (CollectionUtils.isEmpty(prods)) {
-								//生成随机编码
-								SimpleDateFormat sdf = new SimpleDateFormat("yymmddhhmm_sss");
-								product.setCode("prod" + sdf.format(new Date()));
-								Long prId = ProductUtils.updateOne(product);
-								product.setId(prId);
-							} else {
-								product = prods.get(0);
-							}
-						}
-						productInfo.setId(product.getId());
-						productInfo.setTitle(product.getTitle());
-						productInfo.setCode(product.getCode());
-						productInfo.setSpec(product.getSpec());
-						productInfo.setPrice(productInfo.getRateprice());
-						productInfo.setTotalprice(productInfo.getPrice() * productInfo.getAmount());
-						productInfos.add(productInfo);
-					}
+					if (failure == 0) {
+                        product.setEnUU(SystemSession.getUser().getEnterprise().getUu());
+                        product.setUserUU(SystemSession.getUser().getUserUU());
+                        product.setSourceApp("B2B");
+                        product.setIsSale(Constant.YES);
+                        if (product.getTitle() != null) {
+                            //设置默认单位
+                            product.setUnit("PCS");
+                            //为了同步商城数据标准,标准字段也赋值
+                            product.setPcmpcode(product.getCmpCode());
+                            product.setPbranden(product.getPbranden() == null ? product.getBrand() : product.getPbranden());
+                            // 新增数据时间
+                            product.setErpDate(new Date(System.currentTimeMillis()));
+                            product.setStandard(Constant.NO);
+                            product.setIsPurchase(Constant.YES);
+                            // 如果物料不存在,则进行存储
+                            if (product.getCode() != null) {
+                                List<Product> prods = productDao.findByEnUUAndCode(SystemSession.getUser().getEnterprise().getUu(), product.getCode());
+                                if (CollectionUtils.isEmpty(prods)) {
+                                    try {
+                                        Long prId = ProductUtils.updateOne(product);
+                                        product.setId(prId);
+                                        success++;
+                                    } catch (Exception e) {
+
+                                    }
+                                } else {
+                                    product = prods.get(0);
+                                }
+                            } else {// 物料编码不存在
+                                List<Product> prods = productDao
+                                        .findByEnUUAndTitle(SystemSession.getUser().getEnterprise().getUu(), product.getTitle());
+                                if (CollectionUtils.isEmpty(prods)) {
+                                    //生成随机编码
+                                    SimpleDateFormat sdf = new SimpleDateFormat("yymmddhhmm_sss");
+                                    product.setCode("prod" + sdf.format(new Date()));
+                                    try {
+                                        Long prId = ProductUtils.updateOne(product);
+                                        product.setId(prId);
+                                        success++;
+                                    } catch (Exception e) {
+
+                                    }
+                                } else {
+                                    product = prods.get(0);
+                                    success++;
+                                }
+                            }
+                            productInfo.setId(product.getId());
+                            productInfo.setTitle(product.getTitle());
+                            productInfo.setCode(product.getCode());
+                            productInfo.setSpec(product.getSpec());
+                            productInfo.setPrice(productInfo.getRateprice());
+                            productInfo.setTotalprice(productInfo.getPrice() * productInfo.getAmount());
+                            productInfos.add(productInfo);
+                        }
+                    }
 				}
 			}
-			if (!CollectionUtils.isEmpty(productInfos)) {
-				modelMap.put("products", productInfos);
-			}
+            if (alters.size() > 0) {
+                modelMap.put("alters", alters);
+            } else {
+                if (!CollectionUtils.isEmpty(productInfos)) {
+                    modelMap.put("products", productInfos);
+                }
+                modelMap.put("total", total);
+                modelMap.put("success", success);
+            }
 		}
 		return modelMap;
-
 	}
 
 	@Override

+ 3 - 0
src/main/webapp/resources/tpl/index/purc/modal/purc_uplodaByBatch.html

@@ -60,6 +60,9 @@
 		<p ng-if="result.total">
 			<span>总共上传{{result.total}}个,成功{{result.success}}个</span>
 		</p>
+		<p ng-if="alters" ng-repeat="a in alters">
+			<span ng-bind="a" class="text-inverse"></span>
+		</p>
 	</div>
 </div>
 <div class="modal-footer Deputy">