修改导入excel生成卡片新接口
This commit is contained in:
@@ -138,7 +138,7 @@ public class LpkGiftCardRest {
|
|||||||
@RequestParam(value = "endDate") String endDate,
|
@RequestParam(value = "endDate") String endDate,
|
||||||
@RequestParam(value = "file") MultipartFile file,
|
@RequestParam(value = "file") MultipartFile file,
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
HttpServletResponse response) throws IOException, ParseException {
|
HttpServletResponse response) throws IOException {
|
||||||
return lpkGiftCardService.getExcelInfo2(startDate,endDate,file,request,response);
|
return lpkGiftCardService.getExcelInfo2(startDate,endDate,file,request,response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -609,8 +609,8 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
|||||||
System.out.println(sunday.compareTo(endD));
|
System.out.println(sunday.compareTo(endD));
|
||||||
} while (sunday.compareTo(endD) < 1);
|
} while (sunday.compareTo(endD) < 1);
|
||||||
String nextYear = DateUtil.offsetMonth(new Date(), 12).toString();
|
String nextYear = DateUtil.offsetMonth(new Date(), 12).toString();
|
||||||
int y=DateUtil.year(DateUtil.parse(nextYear));
|
int y = DateUtil.year(DateUtil.parse(nextYear));
|
||||||
weekMap.add(String.valueOf(y)+"-01-01");
|
weekMap.add(String.valueOf(y) + "-01-01");
|
||||||
Object[] array = weekMap.stream().sorted().toArray();
|
Object[] array = weekMap.stream().sorted().toArray();
|
||||||
return rb.success().setData(array);
|
return rb.success().setData(array);
|
||||||
}
|
}
|
||||||
@@ -1037,7 +1037,6 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
|||||||
if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
|
if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
|
||||||
return rb.fail().setMsg("上传文件不正确");
|
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;
|
boolean isExcel2003 = true;
|
||||||
if (fileName.matches("^.+\\.(?i)(xlsx)$")) {
|
if (fileName.matches("^.+\\.(?i)(xlsx)$")) {
|
||||||
isExcel2003 = false;
|
isExcel2003 = false;
|
||||||
@@ -1050,7 +1049,7 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
|||||||
wb = new XSSFWorkbook(is);
|
wb = new XSSFWorkbook(is);
|
||||||
}
|
}
|
||||||
Sheet sheet = wb.getSheetAt(0);
|
Sheet sheet = wb.getSheetAt(0);
|
||||||
ReturnMsg returnMsg = getSheetVal2(sheet, resultCell);
|
ReturnMsg returnMsg = getSheetVal2(sheet);
|
||||||
Set<String> setMsg = returnMsg.getSetMsg();
|
Set<String> setMsg = returnMsg.getSetMsg();
|
||||||
StringBuffer sbMsg = new StringBuffer();
|
StringBuffer sbMsg = new StringBuffer();
|
||||||
if (null != setMsg && setMsg.size() > 0) {
|
if (null != setMsg && setMsg.size() > 0) {
|
||||||
@@ -1064,11 +1063,14 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
|||||||
}
|
}
|
||||||
List<ReturnExcelInfo> importReturn = returnMsg.getInfos();
|
List<ReturnExcelInfo> importReturn = returnMsg.getInfos();
|
||||||
importReturn.removeAll(Collections.singleton(null));
|
importReturn.removeAll(Collections.singleton(null));
|
||||||
|
String startNo = "";
|
||||||
|
String endNo = "";
|
||||||
if (!importReturn.isEmpty()) {
|
if (!importReturn.isEmpty()) {
|
||||||
for (ReturnExcelInfo info : importReturn) {
|
for (int i = 0; i < importReturn.size(); i++) {
|
||||||
|
ReturnExcelInfo info = importReturn.get(i);
|
||||||
//生成礼包
|
//生成礼包
|
||||||
LpkGiftCardDto dtoCard = new LpkGiftCardDto();
|
LpkGiftCardDto dtoCard = new LpkGiftCardDto();
|
||||||
dtoCard.setCardArea("88");
|
dtoCard.setCardArea("70");
|
||||||
dtoCard.setNum("1");
|
dtoCard.setNum("1");
|
||||||
String cardSid = getCardByExcel(dtoCard);
|
String cardSid = getCardByExcel(dtoCard);
|
||||||
LpkGiftCard lpkGiftCard = fetchBySid(cardSid);
|
LpkGiftCard lpkGiftCard = fetchBySid(cardSid);
|
||||||
@@ -1076,6 +1078,12 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
|||||||
if (null != lpkGiftCard) {
|
if (null != lpkGiftCard) {
|
||||||
if (StringUtils.isNotBlank(lpkGiftCard.getSerialNumber())) {
|
if (StringUtils.isNotBlank(lpkGiftCard.getSerialNumber())) {
|
||||||
cardNo = lpkGiftCard.getSerialNumber();
|
cardNo = lpkGiftCard.getSerialNumber();
|
||||||
|
if (i == 0) {
|
||||||
|
startNo = cardNo;
|
||||||
|
}
|
||||||
|
if (i == importReturn.size() - 1) {
|
||||||
|
endNo = cardNo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LpkGiftBagDto dtoBag = new LpkGiftBagDto();
|
LpkGiftBagDto dtoBag = new LpkGiftBagDto();
|
||||||
@@ -1098,22 +1106,6 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
|||||||
giftBagGoods.setGoodsNumber(detail.getGoodNum());
|
giftBagGoods.setGoodsNumber(detail.getGoodNum());
|
||||||
}
|
}
|
||||||
goods.add(giftBagGoods);
|
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());
|
LpkCardBuildRecord cardBuildRecord = lpkCardBuildRecordService.fetchBySid(lpkGiftCard.getRecordSid());
|
||||||
cardBuildRecord.setGiftbagSid(bagSid);
|
cardBuildRecord.setGiftbagSid(bagSid);
|
||||||
lpkCardBuildRecordService.updateById(cardBuildRecord);
|
lpkCardBuildRecordService.updateById(cardBuildRecord);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return rb.success().setMsg("本次导入:"+importReturn.size()+"条数据,生成卡券共计"+importReturn.size()+"张;卡券序列号:"+startNo+"-"+endNo);
|
||||||
}
|
}
|
||||||
return rb.success().setMsg("导入成功");
|
return rb.success().setMsg("导入成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReturnMsg getSheetVal2(Sheet sheet, int[] resultCell) {
|
private ReturnMsg getSheetVal2(Sheet sheet) {
|
||||||
ReturnMsg returnMsg = new ReturnMsg();
|
ReturnMsg returnMsg = new ReturnMsg();
|
||||||
List<ReturnExcelInfo> voList = new ArrayList<>();
|
List<ReturnExcelInfo> voList = new ArrayList<>();
|
||||||
int[] resultIndex = new int[resultCell.length];
|
|
||||||
Set<String> setMsg = new HashSet<>();
|
Set<String> setMsg = new HashSet<>();
|
||||||
Row row1 = sheet.getRow(1);
|
Row row1 = sheet.getRow(0);
|
||||||
int startNo = 0;
|
Map<Integer, String> mapGoods = new HashMap<>();
|
||||||
int endNo = 0;
|
|
||||||
for (int i = 0; i < row1.getPhysicalNumberOfCells(); i++) {
|
for (int i = 0; i < row1.getPhysicalNumberOfCells(); i++) {
|
||||||
String trim = new String();
|
String trim = new String();
|
||||||
try {
|
try {
|
||||||
trim = getCellVal(row1.getCell(i)).toString().trim();
|
trim = getCellVal(row1.getCell(i)).toString().trim();
|
||||||
String temp = getCellVal(row1.getCell(i)).toString().trim();
|
String temp = getCellVal(row1.getCell(i)).toString().trim();
|
||||||
if (StringUtils.isNotBlank(temp)) {
|
if (StringUtils.isNotBlank(temp)) {
|
||||||
if (temp.equals("菜品")) {
|
LpkGoods lpkGoods = lpkGoodsService.getGoodsByName(temp);
|
||||||
startNo = i;
|
if (null == lpkGoods) {
|
||||||
}
|
setMsg.add("导入模板的菜品名称与系统中不匹配");
|
||||||
if (temp.equals("菜窖重量合计(斤)")) {
|
returnMsg.setSetMsg(setMsg);
|
||||||
endNo = i - 1;
|
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Row row2 = sheet.getRow(2);
|
for (int r = 1; r <= sheet.getLastRowNum(); r++) {
|
||||||
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++) {
|
|
||||||
ReturnExcelInfo info = new ReturnExcelInfo();
|
ReturnExcelInfo info = new ReturnExcelInfo();
|
||||||
List<ReturnExcelInfoDetails> importVoList = new ArrayList<>();
|
List<ReturnExcelInfoDetails> importVoList = new ArrayList<>();
|
||||||
Row row = sheet.getRow(r);
|
Row row = sheet.getRow(r);
|
||||||
if (row == null) {
|
if (row == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String name = new String();
|
for (int i = 1; i <= mapGoods.size(); i++) {
|
||||||
String phone = new String();
|
|
||||||
for (int i = 4; i <= endNo; i++) {
|
|
||||||
String trim = new String();
|
String trim = new String();
|
||||||
try {
|
try {
|
||||||
trim = getCellVal(row.getCell(i)).toString().trim();
|
trim = getCellVal(row.getCell(i)).toString().trim();
|
||||||
String temp = 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 (StringUtils.isNotBlank(temp)) {
|
||||||
if (i > 5 && i <= endNo) {
|
|
||||||
ReturnExcelInfoDetails details = new ReturnExcelInfoDetails();
|
ReturnExcelInfoDetails details = new ReturnExcelInfoDetails();
|
||||||
details.setGoodNum(temp);
|
details.setGoodNum(temp);
|
||||||
String goodsName = mapGoods.get(i);
|
String goodsName = mapGoods.get(i);
|
||||||
details.setGoodName(goodsName);
|
details.setGoodName(goodsName);
|
||||||
|
if (!temp.equals("0") && !temp.equals("0.0") && !temp.equals("0.00")) {
|
||||||
importVoList.add(details);
|
importVoList.add(details);
|
||||||
|
}
|
||||||
if (!isNum(temp)) {
|
if (!isNum(temp)) {
|
||||||
setMsg.add("菜品数量必须为整数");
|
setMsg.add(r + "行菜品数量必须为整数");
|
||||||
} else {
|
} else {
|
||||||
if (temp.contains(".")) {
|
if (temp.contains(".")) {
|
||||||
String num = temp.substring(temp.indexOf(".") + 1);
|
String num = temp.substring(temp.indexOf(".") + 1);
|
||||||
if (Integer.parseInt(num) != 0) {
|
if (Integer.parseInt(num) != 0) {
|
||||||
setMsg.add("菜品数量必须为整数");
|
setMsg.add(r + "行菜品数量必须为整数");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info.setInfoDetails(importVoList);
|
info.setInfoDetails(importVoList);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!importVoList.isEmpty()) {
|
if (!importVoList.isEmpty()) {
|
||||||
voList.add(info);
|
voList.add(info);
|
||||||
}
|
} else {
|
||||||
}
|
setMsg.add(r + "行为空行");
|
||||||
if (voList != null && voList.size() > 0) {
|
|
||||||
for (ReturnExcelInfo returnExcelInfoDetails : voList) {
|
|
||||||
if (StringUtils.isBlank(returnExcelInfoDetails.getName())) {
|
|
||||||
setMsg.add("客户姓名不能为空");
|
|
||||||
}
|
|
||||||
if (StringUtils.isBlank(returnExcelInfoDetails.getPhone())) {
|
|
||||||
setMsg.add("客户电话不能为空");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
returnMsg.setSetMsg(setMsg);
|
returnMsg.setSetMsg(setMsg);
|
||||||
|
|||||||
Reference in New Issue
Block a user