|
|
@ -32,6 +32,7 @@ import com.yxt.yyth.api.lpkgiftbag.LpkGiftBagDto; |
|
|
|
import com.yxt.yyth.api.lpkgiftbaggoods.LpkGiftBagGoodsVo; |
|
|
|
import com.yxt.yyth.api.lpkgiftcard.*; |
|
|
|
import com.yxt.yyth.api.lpkgoods.LpkGoods; |
|
|
|
import com.yxt.yyth.api.lpkgoods.LpkGoodsDto; |
|
|
|
import com.yxt.yyth.api.lpkreserveorder.LpkReserveOrderCardVo; |
|
|
|
import com.yxt.yyth.api.lpkreserveorder.LpkReserveOrderVo; |
|
|
|
import com.yxt.yyth.api.lpkreserveordergoods.LpkReserveOrderGoods; |
|
|
@ -1085,6 +1086,218 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ResultBean getExcelInfo2(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("上传文件不正确"); |
|
|
|
} |
|
|
|
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; |
|
|
|
} |
|
|
|
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, resultCell); |
|
|
|
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)); |
|
|
|
if (!importReturn.isEmpty()) { |
|
|
|
for (ReturnExcelInfo info : importReturn) { |
|
|
|
//生成礼包
|
|
|
|
LpkGiftCardDto dtoCard = new LpkGiftCardDto(); |
|
|
|
dtoCard.setCardArea("88"); |
|
|
|
dtoCard.setNum("1"); |
|
|
|
String cardSid = getCardByExcel(dtoCard); |
|
|
|
LpkGiftCard lpkGiftCard = fetchBySid(cardSid); |
|
|
|
String cardNo = ""; |
|
|
|
if (null != lpkGiftCard) { |
|
|
|
if (StringUtils.isNotBlank(lpkGiftCard.getSerialNumber())) { |
|
|
|
cardNo = lpkGiftCard.getSerialNumber(); |
|
|
|
} |
|
|
|
} |
|
|
|
LpkGiftBagDto dtoBag = new LpkGiftBagDto(); |
|
|
|
dtoBag.setDateStart(startDate); |
|
|
|
dtoBag.setDateEnd(endDate); |
|
|
|
List<ReturnExcelInfoDetails> infoDetails = info.getInfoDetails(); |
|
|
|
List<GiftBagGoods> goods = new ArrayList<>(); |
|
|
|
if (!infoDetails.isEmpty()) { |
|
|
|
for (ReturnExcelInfoDetails detail : infoDetails) { |
|
|
|
GiftBagGoods giftBagGoods = new GiftBagGoods(); |
|
|
|
if (StringUtils.isNotBlank(detail.getGoodNum()) && StringUtils.isNotBlank(detail.getGoodName())) { |
|
|
|
LpkGoods lpkGoods = lpkGoodsService.getGoodsByName(detail.getGoodName()); |
|
|
|
if (null != lpkGoods) { |
|
|
|
giftBagGoods.setName(lpkGoods.getName()); |
|
|
|
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()); |
|
|
|
} |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
dtoBag.setGoods(goods); |
|
|
|
dtoBag.setName("家庭菜窖" + cardNo); |
|
|
|
String bagSid = lpkGiftBagService.saveGiftBag(dtoBag).getData(); |
|
|
|
if (StringUtils.isNotBlank(bagSid)) { |
|
|
|
lpkGiftCard.setGiftbagSid(bagSid); |
|
|
|
baseMapper.updateById(lpkGiftCard); |
|
|
|
LpkCardBuildRecord cardBuildRecord = lpkCardBuildRecordService.fetchBySid(lpkGiftCard.getRecordSid()); |
|
|
|
cardBuildRecord.setGiftbagSid(bagSid); |
|
|
|
lpkCardBuildRecordService.updateById(cardBuildRecord); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return rb.success().setMsg("导入成功"); |
|
|
|
} |
|
|
|
|
|
|
|
private ReturnMsg getSheetVal2(Sheet sheet, int[] resultCell) { |
|
|
|
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; |
|
|
|
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<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(); |
|
|
|
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++) { |
|
|
|
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); |
|
|
|
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("菜品数量必须为整数"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
info.setInfoDetails(importVoList); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
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("客户电话不能为空"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
returnMsg.setSetMsg(setMsg); |
|
|
|
returnMsg.setInfos(voList); |
|
|
|
return returnMsg; |
|
|
|
} |
|
|
|
// public static void main(String[] args) {
|
|
|
|
// LocalDate start = LocalDate.of(2021, Month.JANUARY, 1); // 设置起始日期为2021年1月1日
|
|
|
|
// LocalDate end = LocalDate.now(); // 设置结束日期为当前日期
|
|
|
|