修改导入excel生成卡片新接口
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1037,7 +1037,6 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
||||
if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
|
||||
return rb.fail().setMsg("上传文件不正确");
|
||||
}
|
||||
int[] resultCell = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||
boolean isExcel2003 = true;
|
||||
if (fileName.matches("^.+\\.(?i)(xlsx)$")) {
|
||||
isExcel2003 = false;
|
||||
@@ -1050,7 +1049,7 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
||||
wb = new XSSFWorkbook(is);
|
||||
}
|
||||
Sheet sheet = wb.getSheetAt(0);
|
||||
ReturnMsg returnMsg = getSheetVal2(sheet, resultCell);
|
||||
ReturnMsg returnMsg = getSheetVal2(sheet);
|
||||
Set<String> setMsg = returnMsg.getSetMsg();
|
||||
StringBuffer sbMsg = new StringBuffer();
|
||||
if (null != setMsg && setMsg.size() > 0) {
|
||||
@@ -1064,11 +1063,14 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
||||
}
|
||||
List<ReturnExcelInfo> 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<LpkGiftCardMapper, Lp
|
||||
if (null != lpkGiftCard) {
|
||||
if (StringUtils.isNotBlank(lpkGiftCard.getSerialNumber())) {
|
||||
cardNo = lpkGiftCard.getSerialNumber();
|
||||
if (i == 0) {
|
||||
startNo = cardNo;
|
||||
}
|
||||
if (i == importReturn.size() - 1) {
|
||||
endNo = cardNo;
|
||||
}
|
||||
}
|
||||
}
|
||||
LpkGiftBagDto dtoBag = new LpkGiftBagDto();
|
||||
@@ -1098,22 +1106,6 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
||||
giftBagGoods.setGoodsNumber(detail.getGoodNum());
|
||||
}
|
||||
goods.add(giftBagGoods);
|
||||
} else {
|
||||
//没有新增商品
|
||||
LpkGoodsDto goodsDto = new LpkGoodsDto();
|
||||
goodsDto.setName(detail.getGoodName());
|
||||
String goodsSid = lpkGoodsService.saveGoods(goodsDto).getData();
|
||||
if (StringUtils.isNotBlank(goodsSid)) {
|
||||
giftBagGoods.setName(detail.getGoodName());
|
||||
giftBagGoods.setGoodsSid(goodsSid);
|
||||
if (detail.getGoodNum().contains(".")) {
|
||||
String num = detail.getGoodNum().substring(0, detail.getGoodNum().indexOf("."));
|
||||
giftBagGoods.setGoodsNumber(num);
|
||||
} else {
|
||||
giftBagGoods.setGoodsNumber(detail.getGoodNum());
|
||||
}
|
||||
goods.add(giftBagGoods);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1127,109 +1119,84 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
||||
LpkCardBuildRecord cardBuildRecord = lpkCardBuildRecordService.fetchBySid(lpkGiftCard.getRecordSid());
|
||||
cardBuildRecord.setGiftbagSid(bagSid);
|
||||
lpkCardBuildRecordService.updateById(cardBuildRecord);
|
||||
|
||||
}
|
||||
}
|
||||
return rb.success().setMsg("本次导入:"+importReturn.size()+"条数据,生成卡券共计"+importReturn.size()+"张;卡券序列号:"+startNo+"-"+endNo);
|
||||
}
|
||||
return rb.success().setMsg("导入成功");
|
||||
}
|
||||
|
||||
private ReturnMsg getSheetVal2(Sheet sheet, int[] resultCell) {
|
||||
private ReturnMsg getSheetVal2(Sheet sheet) {
|
||||
ReturnMsg returnMsg = new ReturnMsg();
|
||||
List<ReturnExcelInfo> voList = new ArrayList<>();
|
||||
int[] resultIndex = new int[resultCell.length];
|
||||
Set<String> setMsg = new HashSet<>();
|
||||
Row row1 = sheet.getRow(1);
|
||||
int startNo = 0;
|
||||
int endNo = 0;
|
||||
Row row1 = sheet.getRow(0);
|
||||
Map<Integer, String> mapGoods = new HashMap<>();
|
||||
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;
|
||||
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();
|
||||
}
|
||||
}
|
||||
Row row2 = sheet.getRow(2);
|
||||
Map<Integer,String> mapGoods = new HashMap<>();
|
||||
for (int i = startNo; i <= endNo; i++) {
|
||||
String trim = new String();
|
||||
try {
|
||||
trim = getCellVal(row2.getCell(i)).toString().trim();
|
||||
String temp = getCellVal(row2.getCell(i)).toString().trim();
|
||||
if (StringUtils.isNotBlank(temp)) {
|
||||
String substring = temp.substring(0, temp.indexOf("("));
|
||||
mapGoods.put(i,substring);
|
||||
}
|
||||
} 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<ReturnExcelInfoDetails> 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);
|
||||
if (!temp.equals("0") && !temp.equals("0.0") && !temp.equals("0.00")) {
|
||||
importVoList.add(details);
|
||||
}
|
||||
if (!isNum(temp)) {
|
||||
setMsg.add("菜品数量必须为整数");
|
||||
setMsg.add(r + "行菜品数量必须为整数");
|
||||
} else {
|
||||
if (temp.contains(".")) {
|
||||
String num = temp.substring(temp.indexOf(".") + 1);
|
||||
if (Integer.parseInt(num) != 0) {
|
||||
setMsg.add("菜品数量必须为整数");
|
||||
setMsg.add(r + "行菜品数量必须为整数");
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user