|
|
@ -1123,154 +1123,158 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public ResultBean getExcelInfo3(String startDate, String endDate, MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
String temp = request.getSession().getServletContext().getRealPath(File.separator) + "temp";// 临时目录
|
|
|
|
File tempFile = new File(temp); |
|
|
|
if (!tempFile.exists()) { |
|
|
|
tempFile.mkdirs(); |
|
|
|
} |
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) { |
|
|
|
return rb.fail().setMsg("上传文件不正确"); |
|
|
|
} |
|
|
|
boolean isExcel2003 = true; |
|
|
|
if (fileName.matches("^.+\\.(?i)(xlsx)$")) { |
|
|
|
isExcel2003 = false; |
|
|
|
} |
|
|
|
InputStream is = file.getInputStream(); |
|
|
|
Workbook wb = null; |
|
|
|
if (isExcel2003) { |
|
|
|
wb = new HSSFWorkbook(is); |
|
|
|
} else { |
|
|
|
wb = new XSSFWorkbook(is); |
|
|
|
} |
|
|
|
Sheet sheet = wb.getSheetAt(0); |
|
|
|
ReturnMsg returnMsg = getSheetVal2(sheet); |
|
|
|
Set<String> setMsg = returnMsg.getSetMsg(); |
|
|
|
StringBuffer sbMsg = new StringBuffer(); |
|
|
|
if (null != setMsg && setMsg.size() > 0) { |
|
|
|
for (String s : setMsg) { |
|
|
|
sbMsg.append(s).append(","); |
|
|
|
try { |
|
|
|
String temp = request.getSession().getServletContext().getRealPath(File.separator) + "temp";// 临时目录
|
|
|
|
File tempFile = new File(temp); |
|
|
|
if (!tempFile.exists()) { |
|
|
|
tempFile.mkdirs(); |
|
|
|
} |
|
|
|
sbMsg.delete(sbMsg.length() - 1, sbMsg.length()); |
|
|
|
if (StringUtils.isNotBlank(sbMsg.toString())) { |
|
|
|
return rb.setMsg(sbMsg.toString()); |
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) { |
|
|
|
return rb.fail().setMsg("上传文件不正确"); |
|
|
|
} |
|
|
|
} |
|
|
|
List<ReturnExcelInfo> importReturn = returnMsg.getInfos(); |
|
|
|
importReturn.removeAll(Collections.singleton(null)); |
|
|
|
String startNo = ""; |
|
|
|
String endNo = ""; |
|
|
|
List<LpkGiftCard> cards = new ArrayList<>(); //卡片
|
|
|
|
List<LpkGiftBagGoods> bagGoods = new ArrayList<>(); //卡片礼包关联
|
|
|
|
List<LpkGiftBag> bags = new ArrayList<>(); //礼包
|
|
|
|
List<LpkCardQrcode> codes = new ArrayList<>(); //二维码
|
|
|
|
List<LpkCardBuildRecord> records = new ArrayList<>(); //二维码
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
int cardSerNum = 0; |
|
|
|
//生成卡包
|
|
|
|
if (!importReturn.isEmpty()) { |
|
|
|
for (int i = 0; i < importReturn.size(); i++) { |
|
|
|
ReturnExcelInfo info = importReturn.get(i); |
|
|
|
LpkGiftCard card = new LpkGiftCard(); |
|
|
|
LpkGiftBag bag = new LpkGiftBag(); |
|
|
|
LpkCardQrcode code = new LpkCardQrcode(); |
|
|
|
LpkCardBuildRecord record = new LpkCardBuildRecord(); |
|
|
|
String serNum = baseMapper.selctMaxSerNumForExport(); |
|
|
|
card.setCreateTime(new DateTime());//卡片生成时间
|
|
|
|
bag.setCreateTime(new DateTime());//礼包生成时间
|
|
|
|
code.setCreateTime(new DateTime());//二维码生成时间
|
|
|
|
record.setCreateTime(new DateTime());//礼包记录生成时间
|
|
|
|
record.setBuildDate(new DateTime());//礼包记录生成时间
|
|
|
|
record.setGiftbagSid(bag.getSid()); |
|
|
|
record.setCountNumber("1"); |
|
|
|
if (StringUtils.isNotBlank(serNum)) { |
|
|
|
int serNumInt = Integer.parseInt(serNum); |
|
|
|
if (i == 0) { |
|
|
|
cardSerNum = serNumInt + 1; |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (cardSerNum == 0) { |
|
|
|
cardSerNum = 70000001; |
|
|
|
} |
|
|
|
boolean isExcel2003 = true; |
|
|
|
if (fileName.matches("^.+\\.(?i)(xlsx)$")) { |
|
|
|
isExcel2003 = false; |
|
|
|
} |
|
|
|
InputStream is = file.getInputStream(); |
|
|
|
Workbook wb = null; |
|
|
|
if (isExcel2003) { |
|
|
|
wb = new HSSFWorkbook(is); |
|
|
|
} else { |
|
|
|
wb = new XSSFWorkbook(is); |
|
|
|
} |
|
|
|
Sheet sheet = wb.getSheetAt(0); |
|
|
|
ReturnMsg returnMsg = getSheetVal2(sheet); |
|
|
|
Set<String> setMsg = returnMsg.getSetMsg(); |
|
|
|
StringBuffer sbMsg = new StringBuffer(); |
|
|
|
if (null != setMsg && setMsg.size() > 0) { |
|
|
|
for (String s : setMsg) { |
|
|
|
sbMsg.append(s).append(","); |
|
|
|
} |
|
|
|
card.setSerialNumber(String.valueOf(cardSerNum)); |
|
|
|
record.setStartNumber(String.valueOf(cardSerNum)); |
|
|
|
record.setEndNumber(String.valueOf(cardSerNum)); |
|
|
|
bag.setName("家庭菜窖" + cardSerNum); |
|
|
|
card.setGiftbagSid(bag.getSid()); //卡片赋值关联礼包sid
|
|
|
|
card.setRecordSid(record.getSid()); //卡片赋值关联生成卡记录sid
|
|
|
|
card.setState("1"); |
|
|
|
String uuid = UniqueIdGenerator.generateUniqueID(); |
|
|
|
int randomNumber = new Random().nextInt(900000) + 100000; |
|
|
|
card.setCodeKey(String.valueOf(randomNumber)); //6位密码
|
|
|
|
card.setCode(uuid); //20位提货码
|
|
|
|
//生成二维码转base64
|
|
|
|
String s = genarateQRCodesToBase64ForExport(card.getCode()); |
|
|
|
code.setCardSid(card.getSid()); |
|
|
|
code.setCreateTime(new DateTime()); |
|
|
|
code.setFile(s); |
|
|
|
//------礼包信息赋值-------------
|
|
|
|
try { |
|
|
|
bag.setDateStart(sdf.parse(startDate)); |
|
|
|
bag.setDateEnd(sdf.parse(endDate)); |
|
|
|
} catch (ParseException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
sbMsg.delete(sbMsg.length() - 1, sbMsg.length()); |
|
|
|
if (StringUtils.isNotBlank(sbMsg.toString())) { |
|
|
|
return rb.setMsg(sbMsg.toString()); |
|
|
|
} |
|
|
|
cards.add(card); |
|
|
|
bags.add(bag); |
|
|
|
codes.add(code); |
|
|
|
records.add(record); |
|
|
|
List<ReturnExcelInfoDetails> infoDetails = info.getInfoDetails(); |
|
|
|
if (!infoDetails.isEmpty()) { |
|
|
|
for (ReturnExcelInfoDetails detail : infoDetails) { |
|
|
|
LpkGiftBagGoods giftBagGoods = new LpkGiftBagGoods(); |
|
|
|
giftBagGoods.setCreateTime(new DateTime()); |
|
|
|
if (StringUtils.isNotBlank(detail.getGoodNum()) && StringUtils.isNotBlank(detail.getGoodName())) { |
|
|
|
LpkGoods lpkGoods = lpkGoodsService.getGoodsByName(detail.getGoodName()); |
|
|
|
if (null != lpkGoods) { |
|
|
|
giftBagGoods.setGoodsSid(lpkGoods.getSid()); |
|
|
|
if (detail.getGoodNum().contains(".")) { |
|
|
|
String num = detail.getGoodNum().substring(0, detail.getGoodNum().indexOf(".")); |
|
|
|
giftBagGoods.setGoodsNumber(num); |
|
|
|
} else { |
|
|
|
giftBagGoods.setGoodsNumber(detail.getGoodNum()); |
|
|
|
} |
|
|
|
List<ReturnExcelInfo> importReturn = returnMsg.getInfos(); |
|
|
|
importReturn.removeAll(Collections.singleton(null)); |
|
|
|
String startNo = ""; |
|
|
|
String endNo = ""; |
|
|
|
List<LpkGiftCard> cards = new ArrayList<>(); //卡片
|
|
|
|
List<LpkGiftBagGoods> bagGoods = new ArrayList<>(); //卡片礼包关联
|
|
|
|
List<LpkGiftBag> bags = new ArrayList<>(); //礼包
|
|
|
|
List<LpkCardQrcode> codes = new ArrayList<>(); //二维码
|
|
|
|
List<LpkCardBuildRecord> records = new ArrayList<>(); //二维码
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
int cardSerNum = 0; |
|
|
|
//生成卡包
|
|
|
|
if (!importReturn.isEmpty()) { |
|
|
|
for (int i = 0; i < importReturn.size(); i++) { |
|
|
|
ReturnExcelInfo info = importReturn.get(i); |
|
|
|
LpkGiftCard card = new LpkGiftCard(); |
|
|
|
LpkGiftBag bag = new LpkGiftBag(); |
|
|
|
LpkCardQrcode code = new LpkCardQrcode(); |
|
|
|
LpkCardBuildRecord record = new LpkCardBuildRecord(); |
|
|
|
String serNum = baseMapper.selctMaxSerNumForExport(); |
|
|
|
card.setCreateTime(new DateTime());//卡片生成时间
|
|
|
|
bag.setCreateTime(new DateTime());//礼包生成时间
|
|
|
|
code.setCreateTime(new DateTime());//二维码生成时间
|
|
|
|
record.setCreateTime(new DateTime());//礼包记录生成时间
|
|
|
|
record.setBuildDate(new DateTime());//礼包记录生成时间
|
|
|
|
record.setGiftbagSid(bag.getSid()); |
|
|
|
record.setCountNumber("1"); |
|
|
|
if (StringUtils.isNotBlank(serNum)) { |
|
|
|
int serNumInt = Integer.parseInt(serNum); |
|
|
|
if (i == 0) { |
|
|
|
cardSerNum = serNumInt + 1; |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (cardSerNum == 0) { |
|
|
|
cardSerNum = 70000001; |
|
|
|
} |
|
|
|
} |
|
|
|
card.setSerialNumber(String.valueOf(cardSerNum)); |
|
|
|
record.setStartNumber(String.valueOf(cardSerNum)); |
|
|
|
record.setEndNumber(String.valueOf(cardSerNum)); |
|
|
|
bag.setName("家庭菜窖" + cardSerNum); |
|
|
|
card.setGiftbagSid(bag.getSid()); //卡片赋值关联礼包sid
|
|
|
|
card.setRecordSid(record.getSid()); //卡片赋值关联生成卡记录sid
|
|
|
|
card.setState("1"); |
|
|
|
String uuid = UniqueIdGenerator.generateUniqueID(); |
|
|
|
int randomNumber = new Random().nextInt(900000) + 100000; |
|
|
|
card.setCodeKey(String.valueOf(randomNumber)); //6位密码
|
|
|
|
card.setCode(uuid); //20位提货码
|
|
|
|
//生成二维码转base64
|
|
|
|
String s = genarateQRCodesToBase64ForExport(card.getCode()); |
|
|
|
code.setCardSid(card.getSid()); |
|
|
|
code.setCreateTime(new DateTime()); |
|
|
|
code.setFile(s); |
|
|
|
//------礼包信息赋值-------------
|
|
|
|
try { |
|
|
|
bag.setDateStart(sdf.parse(startDate)); |
|
|
|
bag.setDateEnd(sdf.parse(endDate)); |
|
|
|
} catch (ParseException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
cards.add(card); |
|
|
|
bags.add(bag); |
|
|
|
codes.add(code); |
|
|
|
records.add(record); |
|
|
|
List<ReturnExcelInfoDetails> infoDetails = info.getInfoDetails(); |
|
|
|
if (!infoDetails.isEmpty()) { |
|
|
|
for (ReturnExcelInfoDetails detail : infoDetails) { |
|
|
|
LpkGiftBagGoods giftBagGoods = new LpkGiftBagGoods(); |
|
|
|
giftBagGoods.setCreateTime(new DateTime()); |
|
|
|
if (StringUtils.isNotBlank(detail.getGoodNum()) && StringUtils.isNotBlank(detail.getGoodName())) { |
|
|
|
LpkGoods lpkGoods = lpkGoodsService.getGoodsByName(detail.getGoodName()); |
|
|
|
if (null != lpkGoods) { |
|
|
|
giftBagGoods.setGoodsSid(lpkGoods.getSid()); |
|
|
|
if (detail.getGoodNum().contains(".")) { |
|
|
|
String num = detail.getGoodNum().substring(0, detail.getGoodNum().indexOf(".")); |
|
|
|
giftBagGoods.setGoodsNumber(num); |
|
|
|
} else { |
|
|
|
giftBagGoods.setGoodsNumber(detail.getGoodNum()); |
|
|
|
} |
|
|
|
} |
|
|
|
giftBagGoods.setGiftbagSid(bag.getSid()); |
|
|
|
bagGoods.add(giftBagGoods); |
|
|
|
} |
|
|
|
giftBagGoods.setGiftbagSid(bag.getSid()); |
|
|
|
bagGoods.add(giftBagGoods); |
|
|
|
} |
|
|
|
} |
|
|
|
if (i == 0) { |
|
|
|
startNo = String.valueOf(cardSerNum); |
|
|
|
} |
|
|
|
if (i == importReturn.size() - 1) { |
|
|
|
endNo = String.valueOf(cardSerNum); |
|
|
|
} |
|
|
|
cardSerNum = cardSerNum + 1; |
|
|
|
} |
|
|
|
if (i == 0) { |
|
|
|
startNo = String.valueOf(cardSerNum); |
|
|
|
//批量插入数据
|
|
|
|
//卡片
|
|
|
|
if (!cards.isEmpty()) { |
|
|
|
int i = baseMapper.saveCards(cards); |
|
|
|
} |
|
|
|
if (i == importReturn.size() - 1) { |
|
|
|
endNo = String.valueOf(cardSerNum); |
|
|
|
//卡记录
|
|
|
|
if (!records.isEmpty()) { |
|
|
|
int i = lpkCardBuildRecordService.saveRecords(records); |
|
|
|
} |
|
|
|
cardSerNum = cardSerNum + 1; |
|
|
|
} |
|
|
|
//批量插入数据
|
|
|
|
//卡片
|
|
|
|
if (!cards.isEmpty()) { |
|
|
|
int i = baseMapper.saveCards(cards); |
|
|
|
} |
|
|
|
//卡记录
|
|
|
|
if (!records.isEmpty()) { |
|
|
|
int i = lpkCardBuildRecordService.saveRecords(records); |
|
|
|
} |
|
|
|
//二维码
|
|
|
|
if (!codes.isEmpty()) { |
|
|
|
int i = lpkCardQrcodeService.saveCodes(codes); |
|
|
|
} |
|
|
|
//礼包
|
|
|
|
if (!bags.isEmpty()) { |
|
|
|
int i = lpkGiftBagService.saveBags(bags); |
|
|
|
} |
|
|
|
//礼包商品
|
|
|
|
if (!bagGoods.isEmpty()) { |
|
|
|
int i = LpkGiftBagGoodsService.saveBagGoods(bagGoods); |
|
|
|
//二维码
|
|
|
|
if (!codes.isEmpty()) { |
|
|
|
int i = lpkCardQrcodeService.saveCodes(codes); |
|
|
|
} |
|
|
|
//礼包
|
|
|
|
if (!bags.isEmpty()) { |
|
|
|
int i = lpkGiftBagService.saveBags(bags); |
|
|
|
} |
|
|
|
//礼包商品
|
|
|
|
if (!bagGoods.isEmpty()) { |
|
|
|
int i = LpkGiftBagGoodsService.saveBagGoods(bagGoods); |
|
|
|
} |
|
|
|
return rb.success().setMsg("本次导入:" + importReturn.size() + "条数据,生成卡券共计" + importReturn.size() + "张;卡券序列号:" + startNo + "-" + endNo); |
|
|
|
} |
|
|
|
return rb.success().setMsg("本次导入:" + importReturn.size() + "条数据,生成卡券共计" + importReturn.size() + "张;卡券序列号:" + startNo + "-" + endNo); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return rb.success().setMsg("导入成功"); |
|
|
|
} |
|
|
@ -1345,12 +1349,12 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp |
|
|
|
importVoList.add(details); |
|
|
|
} |
|
|
|
if (!isNum(temp)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行菜品数量必须为大于0的整数"); |
|
|
|
setMsg.add("第" + (r + 1) + "行菜品数量必须为大于等于0的整数"); |
|
|
|
} else { |
|
|
|
if (temp.contains(".")) { |
|
|
|
String num = temp.substring(temp.indexOf(".") + 1); |
|
|
|
if (Integer.parseInt(num) != 0) { |
|
|
|
setMsg.add("第" + (r + 1) + "行菜品数量必须为大于0的整数"); |
|
|
|
setMsg.add("第" + (r + 1) + "行菜品数量必须为大于等于0的整数"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|