|
|
@ -25,10 +25,12 @@ import com.yxt.common.core.result.ResultBean; |
|
|
|
import com.yxt.common.core.vo.PagerVo; |
|
|
|
import com.yxt.yyth.api.lpkcardbuildrecord.LpkCardBuildRecord; |
|
|
|
import com.yxt.yyth.api.lpkcardgrantrecord.LpkCardGrantRecordDto; |
|
|
|
import com.yxt.yyth.api.lpkcardqrcode.LpkCardQrcode; |
|
|
|
import com.yxt.yyth.api.lpkcardqrcode.LpkCardQrcodeDto; |
|
|
|
import com.yxt.yyth.api.lpkgiftbag.GiftBagGoods; |
|
|
|
import com.yxt.yyth.api.lpkgiftbag.LpkGiftBag; |
|
|
|
import com.yxt.yyth.api.lpkgiftbag.LpkGiftBagDto; |
|
|
|
import com.yxt.yyth.api.lpkgiftbaggoods.LpkGiftBagGoods; |
|
|
|
import com.yxt.yyth.api.lpkgiftbaggoods.LpkGiftBagGoodsVo; |
|
|
|
import com.yxt.yyth.api.lpkgiftcard.*; |
|
|
|
import com.yxt.yyth.api.lpkgoods.LpkGoods; |
|
|
@ -1056,13 +1058,14 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp |
|
|
|
importReturn.removeAll(Collections.singleton(null)); |
|
|
|
String startNo = ""; |
|
|
|
String endNo = ""; |
|
|
|
//生成卡包
|
|
|
|
if (!importReturn.isEmpty()) { |
|
|
|
for (int i = 0; i < importReturn.size(); i++) { |
|
|
|
ReturnExcelInfo info = importReturn.get(i); |
|
|
|
//生成礼包
|
|
|
|
LpkGiftCardDto dtoCard = new LpkGiftCardDto(); |
|
|
|
dtoCard.setCardArea("70"); |
|
|
|
dtoCard.setNum("1"); |
|
|
|
//生成卡片
|
|
|
|
String cardSid = getCardByExcel(dtoCard); |
|
|
|
LpkGiftCard lpkGiftCard = fetchBySid(cardSid); |
|
|
|
String cardNo = ""; |
|
|
@ -1112,11 +1115,185 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp |
|
|
|
lpkCardBuildRecordService.updateById(cardBuildRecord); |
|
|
|
} |
|
|
|
} |
|
|
|
return rb.success().setMsg("本次导入:"+importReturn.size()+"条数据,生成卡券共计"+importReturn.size()+"张;卡券序列号:"+startNo+"-"+endNo); |
|
|
|
return rb.success().setMsg("本次导入:" + importReturn.size() + "条数据,生成卡券共计" + importReturn.size() + "张;卡券序列号:" + startNo + "-" + endNo); |
|
|
|
} |
|
|
|
return rb.success().setMsg("导入成功"); |
|
|
|
} |
|
|
|
|
|
|
|
@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(","); |
|
|
|
} |
|
|
|
sbMsg.delete(sbMsg.length() - 1, sbMsg.length()); |
|
|
|
if (StringUtils.isNotBlank(sbMsg.toString())) { |
|
|
|
return rb.setMsg(sbMsg.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (i == 0) { |
|
|
|
startNo = String.valueOf(cardSerNum); |
|
|
|
} |
|
|
|
if (i == importReturn.size() - 1) { |
|
|
|
endNo = String.valueOf(cardSerNum); |
|
|
|
} |
|
|
|
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); |
|
|
|
} |
|
|
|
return rb.success().setMsg("本次导入:" + importReturn.size() + "条数据,生成卡券共计" + importReturn.size() + "张;卡券序列号:" + startNo + "-" + endNo); |
|
|
|
} |
|
|
|
return rb.success().setMsg("导入成功"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 二维码转base64 |
|
|
|
*/ |
|
|
|
public String genarateQRCodesToBase64ForExport(String uuid) { |
|
|
|
BufferedImage bufferedImage = QrCodeUtil.generate(uuid, 300, 300); |
|
|
|
byte[] bytes = ImgUtil.toBytes(bufferedImage, "JPG"); |
|
|
|
Base64Encoder base64Encoder = new Base64Encoder(); |
|
|
|
String a = base64Encoder.encode(bytes); |
|
|
|
a = a.trim(); |
|
|
|
a = a.replaceAll("\n", "").replaceAll("\r", ""); |
|
|
|
return a; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验导入结果 |
|
|
|
* |
|
|
|
* @param sheet |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private ReturnMsg getSheetVal2(Sheet sheet) { |
|
|
|
ReturnMsg returnMsg = new ReturnMsg(); |
|
|
|
List<ReturnExcelInfo> voList = new ArrayList<>(); |
|
|
@ -1168,12 +1345,12 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp |
|
|
|
importVoList.add(details); |
|
|
|
} |
|
|
|
if (!isNum(temp)) { |
|
|
|
setMsg.add(r + "行菜品数量必须为整数"); |
|
|
|
setMsg.add("第" + (r + 1) + "行菜品数量必须为大于0的整数"); |
|
|
|
} else { |
|
|
|
if (temp.contains(".")) { |
|
|
|
String num = temp.substring(temp.indexOf(".") + 1); |
|
|
|
if (Integer.parseInt(num) != 0) { |
|
|
|
setMsg.add(r + "行菜品数量必须为整数"); |
|
|
|
setMsg.add("第" + (r + 1) + "行菜品数量必须为大于0的整数"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1187,15 +1364,16 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp |
|
|
|
if (!importVoList.isEmpty()) { |
|
|
|
voList.add(info); |
|
|
|
} else { |
|
|
|
setMsg.add(r + "行为空行"); |
|
|
|
setMsg.add("第" + (r + 1) + "行为空行"); |
|
|
|
} |
|
|
|
} |
|
|
|
returnMsg.setSetMsg(setMsg); |
|
|
|
returnMsg.setInfos(voList); |
|
|
|
return returnMsg; |
|
|
|
} |
|
|
|
public ResultBean DownLoadTemplate(){ |
|
|
|
ResultBean rb=new ResultBean(); |
|
|
|
|
|
|
|
public ResultBean DownLoadTemplate() { |
|
|
|
ResultBean rb = new ResultBean(); |
|
|
|
return rb.success().setData(""); |
|
|
|
} |
|
|
|
// public static void main(String[] args) {
|
|
|
|