diff --git a/src/main/java/com/yxt/yyth/biz/lpkgiftcard/LpkGiftCardRest.java b/src/main/java/com/yxt/yyth/biz/lpkgiftcard/LpkGiftCardRest.java index 7981adb..b067ae5 100644 --- a/src/main/java/com/yxt/yyth/biz/lpkgiftcard/LpkGiftCardRest.java +++ b/src/main/java/com/yxt/yyth/biz/lpkgiftcard/LpkGiftCardRest.java @@ -138,7 +138,7 @@ public class LpkGiftCardRest { @RequestParam(value = "endDate") String endDate, @RequestParam(value = "file") MultipartFile file, HttpServletRequest request, - HttpServletResponse response) throws IOException, ParseException { + HttpServletResponse response) throws IOException { return lpkGiftCardService.getExcelInfo2(startDate,endDate,file,request,response); } diff --git a/src/main/java/com/yxt/yyth/biz/lpkgiftcard/LpkGiftCardService.java b/src/main/java/com/yxt/yyth/biz/lpkgiftcard/LpkGiftCardService.java index 0188a24..d936cd2 100644 --- a/src/main/java/com/yxt/yyth/biz/lpkgiftcard/LpkGiftCardService.java +++ b/src/main/java/com/yxt/yyth/biz/lpkgiftcard/LpkGiftCardService.java @@ -609,8 +609,8 @@ public class LpkGiftCardService extends MybatisBaseService setMsg = returnMsg.getSetMsg(); StringBuffer sbMsg = new StringBuffer(); if (null != setMsg && setMsg.size() > 0) { @@ -1064,11 +1063,14 @@ public class LpkGiftCardService extends MybatisBaseService importReturn = returnMsg.getInfos(); importReturn.removeAll(Collections.singleton(null)); + String startNo = ""; + String endNo = ""; if (!importReturn.isEmpty()) { - for (ReturnExcelInfo info : importReturn) { + for (int i = 0; i < importReturn.size(); i++) { + ReturnExcelInfo info = importReturn.get(i); //生成礼包 LpkGiftCardDto dtoCard = new LpkGiftCardDto(); - dtoCard.setCardArea("88"); + dtoCard.setCardArea("70"); dtoCard.setNum("1"); String cardSid = getCardByExcel(dtoCard); LpkGiftCard lpkGiftCard = fetchBySid(cardSid); @@ -1076,6 +1078,12 @@ public class LpkGiftCardService extends MybatisBaseService voList = new ArrayList<>(); - int[] resultIndex = new int[resultCell.length]; Set setMsg = new HashSet<>(); - Row row1 = sheet.getRow(1); - int startNo = 0; - int endNo = 0; - for (int i = 0; i < row1.getPhysicalNumberOfCells(); i++) { - String trim = new String(); - try { - trim = getCellVal(row1.getCell(i)).toString().trim(); - String temp = getCellVal(row1.getCell(i)).toString().trim(); - if (StringUtils.isNotBlank(temp)) { - if (temp.equals("菜品")) { - startNo = i; - } - if (temp.equals("菜窖重量合计(斤)")) { - endNo = i - 1; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - Row row2 = sheet.getRow(2); - Map mapGoods = new HashMap<>(); - for (int i = startNo; i <= endNo; i++) { + Row row1 = sheet.getRow(0); + Map mapGoods = new HashMap<>(); + for (int i = 0; i < row1.getPhysicalNumberOfCells(); i++) { String trim = new String(); try { - trim = getCellVal(row2.getCell(i)).toString().trim(); - String temp = getCellVal(row2.getCell(i)).toString().trim(); + trim = getCellVal(row1.getCell(i)).toString().trim(); + String temp = getCellVal(row1.getCell(i)).toString().trim(); if (StringUtils.isNotBlank(temp)) { - String substring = temp.substring(0, temp.indexOf("(")); - mapGoods.put(i,substring); + LpkGoods lpkGoods = lpkGoodsService.getGoodsByName(temp); + if (null == lpkGoods) { + setMsg.add("导入模板的菜品名称与系统中不匹配"); + returnMsg.setSetMsg(setMsg); + returnMsg.setInfos(new ArrayList<>()); + return returnMsg; + } + mapGoods.put(i, temp); + } else { + setMsg.add("导入模板的菜品名称与系统中不匹配"); + returnMsg.setSetMsg(setMsg); + returnMsg.setInfos(new ArrayList<>()); + return returnMsg; } } catch (Exception e) { e.printStackTrace(); } } - for (int r = 3; r <= sheet.getLastRowNum(); r++) { + for (int r = 1; r <= sheet.getLastRowNum(); r++) { ReturnExcelInfo info = new ReturnExcelInfo(); List importVoList = new ArrayList<>(); Row row = sheet.getRow(r); if (row == null) { continue; } - String name = new String(); - String phone = new String(); - for (int i = 4; i <= endNo; i++) { + for (int i = 1; i <= mapGoods.size(); i++) { String trim = new String(); try { trim = getCellVal(row.getCell(i)).toString().trim(); String temp = getCellVal(row.getCell(i)).toString().trim(); - if (i == 4 ) { - info.setName(temp); - } - if (i == 5) { - info.setPhone(temp); - } if (StringUtils.isNotBlank(temp)) { - if (i > 5 && i <= endNo) { - ReturnExcelInfoDetails details = new ReturnExcelInfoDetails(); - details.setGoodNum(temp); - String goodsName = mapGoods.get(i); - details.setGoodName(goodsName); + ReturnExcelInfoDetails details = new ReturnExcelInfoDetails(); + details.setGoodNum(temp); + String goodsName = mapGoods.get(i); + details.setGoodName(goodsName); + if (!temp.equals("0") && !temp.equals("0.0") && !temp.equals("0.00")) { importVoList.add(details); - if (!isNum(temp)) { - setMsg.add("菜品数量必须为整数"); - } else { - if (temp.contains(".")) { - String num = temp.substring(temp.indexOf(".") + 1); - if (Integer.parseInt(num) != 0) { - setMsg.add("菜品数量必须为整数"); - } + } + if (!isNum(temp)) { + setMsg.add(r + "行菜品数量必须为整数"); + } else { + if (temp.contains(".")) { + String num = temp.substring(temp.indexOf(".") + 1); + if (Integer.parseInt(num) != 0) { + setMsg.add(r + "行菜品数量必须为整数"); } } - info.setInfoDetails(importVoList); } + info.setInfoDetails(importVoList); } } catch (Exception e) { e.printStackTrace(); + continue; } } if (!importVoList.isEmpty()) { voList.add(info); - } - } - if (voList != null && voList.size() > 0) { - for (ReturnExcelInfo returnExcelInfoDetails : voList) { - if (StringUtils.isBlank(returnExcelInfoDetails.getName())) { - setMsg.add("客户姓名不能为空"); - } - if (StringUtils.isBlank(returnExcelInfoDetails.getPhone())) { - setMsg.add("客户电话不能为空"); - } + } else { + setMsg.add(r + "行为空行"); } } returnMsg.setSetMsg(setMsg);