From 4dff93c14ae3cd89693e207cd84cf0baec32aa60 Mon Sep 17 00:00:00 2001 From: lin <642018748@qq.com> Date: Tue, 11 Jul 2023 18:14:27 +0800 Subject: [PATCH] fix bug --- .../basic/TtMerchantPoiController.java | 227 ++++++------------ .../iformall/controller/mem/AsyncTask.java | 225 ++++++++--------- .../java/com/iformall/utils/Constant.java | 2 + 3 files changed, 173 insertions(+), 281 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtMerchantPoiController.java b/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtMerchantPoiController.java index dda785525..d8ed6a91c 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtMerchantPoiController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtMerchantPoiController.java @@ -1,5 +1,6 @@ package com.iformall.controller.basic; +import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils; import com.github.pagehelper.PageInfo; import com.iformall.annotation.SystemControllerLog; import com.iformall.annotation.TenantIgnore; @@ -156,82 +157,6 @@ public class TtMerchantPoiController extends DouyinBaseController { return ttMerchantPoiService.supplierQuery(getTenantInfo(),id); } -// @ApiOperation("获取商品可用的POI") -// @GetMapping("/findPoi") -// @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) -// @SystemControllerLog(description = "查询") -// public ResultData findPoi(Long couponChannelId) { -// logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::findPoi"); -// if(couponChannelId == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); -// } -// return ttMerchantPoiService.findPoi(getTenantInfo(),couponChannelId); -// } - -// @ApiOperation("商品同步") -// @PostMapping("spuSync") -// @SystemControllerLog(description = "商品同步") -// public ResultData spuSync(@RequestBody Map param) { -// logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::spuSync"); -// String couponChannelIdStr = param.get("couponChannelId"); -// Long couponChannelId = null; -// try{ -// couponChannelId = Long.parseLong(couponChannelIdStr); -// }catch(Exception e){ -// return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR); -// } -// if(couponChannelId == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); -// } -//// String merchantIdStr = param.get("merchantIds"); -//// List merchantIds = new ArrayList<>(); -//// try{ -//// List strings = Arrays.asList(merchantIdStr.split(",")); -//// merchantIds = strings.stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList()); -//// }catch(Exception e){ -//// return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR); -//// } -//// if(merchantIds == null || merchantIds.size() == 0){ -//// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); -//// } -// return ttMerchantPoiService.spuSync(getTenantInfo(),couponChannelId,null); -// } - -// @ApiOperation("商品同步查询") -// @GetMapping("spuGet") -// @SystemControllerLog(description = "商品同步查询") -// public ResultData spuGet(Long couponChannelId) { -// logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::spuGet"); -// if(couponChannelId == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); -// } -// return ttMerchantPoiService.spuGet(getTenantInfo(),couponChannelId); -// } -// -// @ApiOperation("商品状态同步") -// @PostMapping("spuStatusSync") -// @SystemControllerLog(description = "商品状态同步") -// public ResultData spuStatusSync(@RequestBody Map param) { -// logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::spuStatusSync"); -// Long couponChannelId = param.get("couponChannelId"); -// if(couponChannelId == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); -// } -// return ttMerchantPoiService.spuStatusSync(getTenantInfo(),couponChannelId); -// } -// -// @ApiOperation("商品库存同步") -// @PostMapping("spuStockSync") -// @SystemControllerLog(description = "商品库存同步") -// public ResultData spuStockSync(@RequestBody Map param) { -// logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::spuStockSync"); -// Long couponChannelId = param.get("couponChannelId"); -// if(couponChannelId == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); -// } -// return ttMerchantPoiService.spuStockSync(getTenantInfo(),couponChannelId); -// } - @TenantIgnore @RequestMapping("/exportTemplate") public void exportTemplate(HttpServletRequest request, HttpServletResponse response) { @@ -251,7 +176,6 @@ public class TtMerchantPoiController extends DouyinBaseController { @TenantIgnore @PostMapping(value = "/addLocationInfo", consumes = "multipart/*") - //@SystemControllerLog(description = "poi-来客模版补齐地理位置信息") public void addLocationInfo(@RequestParam("poiFile") MultipartFile mFile,HttpServletRequest request, HttpServletResponse response) { try { boolean isSaas = this.isGoodLifeSaas(); @@ -269,17 +193,39 @@ public class TtMerchantPoiController extends DouyinBaseController { private void addLocationInfo(TenantEntity tenantEntity,MultipartFile mFile,boolean isNew,String gaodeKey, HttpServletRequest request, HttpServletResponse response) throws Exception{ + File lFile = handlerImportFile(mFile,null,"poiAddLocation"); + if (isNew) { + asyncTask.exportExcelPoiDataAddLocationForNew(tenantEntity,gaodeKey,lFile,request,response); + }else { + } + } + + private File handlerImportFile(MultipartFile mFile,String importKey,String fileNamePre) { if (mFile.isEmpty()) { throw new MallinkException(Result.ERROR, "上传文件不能为空"); } - //得到当前用户ID - + + boolean isSetCacheLock = true; + if (StringUtils.isBlank(importKey)) { + isSetCacheLock = false; + } + + //查询当前用户得到的值是否为空,为空继续,不为空,返回模板正在导入 + if (isSetCacheLock) { + Boolean allCount = stringRedisTemplate.opsForHash().hasKey(importKey, "allCount"); + if (allCount) { + throw new MallinkException(Result.SUCCESS, "模板正在导入"); + } + + stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", 0 + ""); + } + String fpath = fmUploadDir; File targetFile = new File(fpath); if (!targetFile.exists()) { targetFile.mkdirs(); } - String fileName = "poiAddLocation" + Math.round(Math.random() * 100000000000L); + String fileName = fileNamePre + Math.round(Math.random() * 100000000000L); int dot = mFile.getOriginalFilename().lastIndexOf('.'); fileName = fileName + mFile.getOriginalFilename().substring(dot, mFile.getOriginalFilename().length()); @@ -297,32 +243,40 @@ public class TtMerchantPoiController extends DouyinBaseController { } fos.close(); fs.close(); + return lFile; } catch (Exception e) { - logger.error("poiAddLocation create tempFile error.",e); - throw new MallinkException(Result.ERROR,e.getMessage()); + if (isSetCacheLock) { + stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS); + stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1"); + } + logger.error("poi import error.",e); + throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { - logger.error("poiAddLocation create tempFile error.",e); - throw new MallinkException(Result.ERROR,e.getMessage()); + if (isSetCacheLock) { + stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS); + stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1"); + } + logger.error("poi import error.",e); + throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); } } if (fs != null) { try { fs.close(); } catch (IOException e) { - logger.error("poiAddLocation create tempFile error.",e); - throw new MallinkException(Result.ERROR,e.getMessage()); + if (isSetCacheLock) { + stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS); + stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1"); + } + logger.error("poi import error.",e); + throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); } } } - if (isNew) { - asyncTask.exportExcelPoiDataAddLocationForNew(tenantEntity,gaodeKey,lFile,request,response); - }else { - } - } @@ -345,72 +299,41 @@ public class TtMerchantPoiController extends DouyinBaseController { private void processImport(MultipartFile mFile,boolean isNew,HttpServletRequest request, HttpServletResponse response) throws Exception { logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::importPoi"); - if (mFile.isEmpty()) { - throw new MallinkException(Result.ERROR, "上传文件不能为空"); - } - //得到当前用户ID + //得到当前用户ID final MallUserInfo user = getUser(); String userId = "" + user.getId(); String importKey = Constant.importPoiPrev + userId; - - //查询当前用户得到的值是否为空,为空继续,不为空,返回模板正在导入 - Boolean allCount = stringRedisTemplate.opsForHash().hasKey(importKey, "allCount"); - if (allCount) { - throw new MallinkException(Result.SUCCESS, "模板正在导入"); - } - - stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", 0 + ""); - - String fpath = fmUploadDir; - File targetFile = new File(fpath); - if (!targetFile.exists()) { - targetFile.mkdirs(); + File lFile = handlerImportFile(mFile,importKey,"poi"); + if (isNew) { + asyncTask.importExcelPoiDataForNew(lFile, user, importKey,request,response); + }else { + asyncTask.importExcelPoiData(lFile, user, importKey,request,response); } - String fileName = "poi" + Math.round(Math.random() * 100000000000L); - int dot = mFile.getOriginalFilename().lastIndexOf('.'); - fileName = fileName + mFile.getOriginalFilename().substring(dot, mFile.getOriginalFilename().length()); - - File lFile = new File(fpath + File.separator + fileName); - FileOutputStream fos = null; - BufferedInputStream fs = null; - try { - fos = new FileOutputStream(lFile); - fs = (BufferedInputStream) mFile.getInputStream(); - byte[] buffer = new byte[1024]; - int len = 0; - while ((len = fs.read(buffer)) != -1) { - fos.write(buffer, 0, len); - } - fos.close(); - fs.close(); - } catch (Exception e) { - stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS); - stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1"); - logger.error("poi import error.",e); - throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); - } finally { - if (fos != null) { - try { - fos.close(); - } catch (IOException e) { - stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS); - stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1"); - logger.error("poi import error.",e); - throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); - } - } - if (fs != null) { - try { - fs.close(); - } catch (IOException e) { - stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS); - stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1"); - logger.error("poi import error.",e); - throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); - } - } - } + } + + @TenantIgnore + @PostMapping(value = "/importMerchantInitByPoi", consumes = "multipart/*") + @SystemControllerLog(description = "poi-初始化商户商户") + public void importMerchantInitByPoi(@RequestParam("file") MultipartFile mFile,HttpServletRequest request, HttpServletResponse response) { + try { + boolean isSaas = this.isGoodLifeSaas(); + if (!isSaas) { + throw new MallinkException(Result.ERROR,"当前版本不支持"); + }else { + importMerchantInit(mFile,true,request,response); + } + } catch (Exception e) { + logger.error("importMerchantInitByPoi error.",e); + throw new MallinkException(Result.ERROR,e.getMessage()); + } + } + + private void importMerchantInit(MultipartFile mFile,boolean isNew,HttpServletRequest request, HttpServletResponse response) throws Exception { + final MallUserInfo user = getUser(); + String userId = "" + user.getId(); + String importKey = Constant.importPoiMerchantPrev + userId; + File lFile = handlerImportFile(mFile,importKey,"poiMerchant"); if (isNew) { asyncTask.importExcelPoiDataForNew(lFile, user, importKey,request,response); }else { diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/mem/AsyncTask.java b/mallinkAdmin/src/main/java/com/iformall/controller/mem/AsyncTask.java index 9acbb41cd..13f829077 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/mem/AsyncTask.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/mem/AsyncTask.java @@ -188,22 +188,21 @@ public class AsyncTask { } @Async - public void importExcelPoiData(File file, MallUserInfo user, String importKey,HttpServletRequest request, HttpServletResponse response) { + public void importCardPriceData(File file, MallUserInfo user, String importKey) { ImportParams params = new ImportParams(); // 需要验证 - params.setImportFields(new String[]{"服务商POI_ID", "POI名称", "省份", "城市", "地址", "经度", "纬度", "高德ID(非必填)", - "已匹配POI_ID", "已匹配POI名称", "已匹配POI省份", "已匹配POI城市", "已匹配POI地址", "未匹配原因", "其他信息","POI导入结果"}); - IExcelDataHandler handler = new AsyncTask.PoiExcelHandler(); - handler.setNeedHandlerFields(new String[]{"服务商POI_ID","已匹配POI_ID"}); + params.setImportFields(new String[]{"*卡ID", "*面额(元)"}); + IExcelDataHandler handler = new AsyncTask.CardPriceExcelHandler(); + handler.setNeedHandlerFields(new String[]{"*卡ID","*面额(元)"}); params.setNeedVerify(true); - ExcelImportResult datalist = null; + ExcelImportResult datalist = null; try { - datalist = ExcelImportUtil.importExcelMore(file, MerchantPoiT.class, params); + datalist = ExcelImportUtil.importExcelMore(file, WxCardPriceTemplate.class, params); } catch (Exception e) { - logger.error(e.getMessage(),e); - stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); + set_redis_value(importKey, "1", "0", "0", "1", true); + logger.error(e.getMessage()); // 删除缓存文件 file.delete(); return; @@ -212,58 +211,110 @@ public class AsyncTask { file.delete(); if(datalist == null) { - logger.error("导入模板失败: 模板数据解析失败"); - stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); + logger.error("导入模板失败: 模板数据解析失败"); + set_redis_value(importKey, "1", "0", "0", "1", true); return; } - List successList = datalist.getList(); - + List successList = datalist.getList(); + List failList = datalist.getFailList(); + + logger.info("验证通过的数量: " + successList.size()); + logger.info("验证未通过的数量: " + failList.size()); + + int total = successList.size() + failList.size(); + int all_success = successList.size(); + int all_fail = failList.size(); + + //添加到redis里 + set_redis_value(importKey, "" + total, "" + all_success, "0", "" + all_fail, total == all_fail); + if(successList.size() > 0) { try { successList.parallelStream().forEach(poiBase -> { try { - ttMerchantPoiService.importOneMem(user, poiBase); + wxCouponPasswordService.importPrice(user,importKey, poiBase); } catch (UnknownSessionException ue) { logger.error("session :"+ue.getMessage()); } }); - stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); - ExportParams exportParams = new ExportParams(); - exportParams.setType(ExcelType.XSSF); - Workbook workBook = ExcelExportUtil.exportExcel(exportParams, MerchantPoiT.class, successList); - exportExcel(request, response, workBook, "POI导入-结果.xlsx"); } catch (Exception e) { - logger.error("导入模板失败:"+e.getMessage(),e); - stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); + set_redis_value(importKey, "1", "0", "0", "1", true); + e.printStackTrace(); + logger.error("导入模板失败:"+e.getMessage()); } } } - public void exportExcelPoiDataAddLocationForNew(TenantEntity tenantEntity,String gaodeKey,File file,HttpServletRequest request, HttpServletResponse response) throws Exception { - ImportParams params = new ImportParams(); + private ExcelImportResult handleImportFile(String importKey,File file,Class dataClazz,String[] importFields,String[] needFields,IExcelDataHandler handler) { + ImportParams params = new ImportParams(); // 需要验证 - String[] headers = new String[]{"门店名称", "门店ID", "城市", "详细地址","管理员手机号","富茂系统商户ID", "富茂系统商户名称","富茂系统省份", "富茂系统城市", "富茂系统地址","富茂系统经度", "富茂系统纬度","高德匹配备注","POI导入日志"}; - params.setImportFields(headers); - IExcelDataHandler handler = new AsyncTask.PoiNewExcelHandler(); - handler.setNeedHandlerFields(new String[]{"门店名称", "门店ID", "城市", "详细地址"}); + params.setImportFields(importFields); + handler.setNeedHandlerFields(needFields); params.setNeedVerify(true); - - ExcelImportResult datalist = null; - + ExcelImportResult datalist = null; try { - datalist = ExcelImportUtil.importExcelMore(file, MerchantPoiTNew.class, params); + datalist = ExcelImportUtil.importExcelMore(file, dataClazz, params); } catch (Exception e) { - logger.error("exportExcelPoiDataAddLocationForNew import error.",e); + logger.error(e.getMessage(),e); + if (StringUtils.isNotBlank(importKey)) { + stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); + } // 删除缓存文件 file.delete(); - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); + return null; } // 删除缓存文件 file.delete(); if(datalist == null) { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"解析模版失败,请检查模版格式"); + logger.error("导入模板失败: 模板数据解析失败"); + if (StringUtils.isNotBlank(importKey)) { + stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); + } + return null; + } + return datalist; + } + + @Async + public void importExcelPoiData(File file, MallUserInfo user, String importKey,HttpServletRequest request, HttpServletResponse response) { + String[] importFields = new String[]{"服务商POI_ID", "POI名称", "省份", "城市", "地址", "经度", "纬度", "高德ID(非必填)", + "已匹配POI_ID", "已匹配POI名称", "已匹配POI省份", "已匹配POI城市", "已匹配POI地址", "未匹配原因", "其他信息","POI导入结果"}; + String[] needFields = new String[]{"服务商POI_ID","已匹配POI_ID"}; + ExcelImportResult datalist = handleImportFile(importKey,file,MerchantPoiT.class,importFields,needFields,new AsyncTask.PoiExcelHandler()); + if (null == datalist) { + return; + } + List successList = datalist.getList(); + + if(successList.size() > 0) { + try { + successList.parallelStream().forEach(poiBase -> { + try { + ttMerchantPoiService.importOneMem(user, poiBase); + } catch (UnknownSessionException ue) { + logger.error("session :"+ue.getMessage()); + } + }); + stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); + exportExcel(request, response, successList,MerchantPoiT.class, "POI导入-结果.xlsx"); + } catch (Exception e) { + logger.error("导入模板失败:"+e.getMessage(),e); + stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); + } + } + } + + private static final String[] poiImportFields = new String[]{"门店名称", "门店ID", "城市", "详细地址","管理员手机号","富茂系统商户ID", "富茂系统商户名称","富茂系统省份", "富茂系统城市", "富茂系统地址","富茂系统经度", "富茂系统纬度","高德匹配备注","POI导入日志"}; + + public void exportExcelPoiDataAddLocationForNew(TenantEntity tenantEntity,String gaodeKey,File file,HttpServletRequest request, HttpServletResponse response) throws Exception { + ImportParams params = new ImportParams(); + // 需要验证 + String[] needFields = new String[]{"门店名称", "门店ID", "城市", "详细地址"}; + ExcelImportResult datalist = handleImportFile(null,file,MerchantPoiTNew.class,poiImportFields,needFields,new AsyncTask.PoiNewExcelHandler()); + if (null == datalist) { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"解析模版失败,请检查模版格式"); } List successList = datalist.getList(); @@ -327,24 +378,22 @@ public class AsyncTask { poiBase.setGaodeRemark("未匹配到信息"); } } - - } catch (UnknownSessionException ue) { logger.error("session :"+ue.getMessage()); poiBase.setGaodeRemark("查询高德API失败"); } }); - ExportParams exportParams = new ExportParams(); - exportParams.setType(ExcelType.XSSF); - Workbook workBook = ExcelExportUtil.exportExcel(exportParams, MerchantPoiTNew.class, successList); - exportExcel(request, response, workBook, "POI匹配模版-高德.xlsx"); + exportExcel(request, response, successList,MerchantPoiTNew.class, "POI匹配模版-高德.xlsx"); } catch (Exception e) { logger.error("更新地理信息失败:"+e.getMessage(),e); } } } - private static void exportExcel(HttpServletRequest request, HttpServletResponse response, Workbook wb, String fileName) throws Exception { + private static void exportExcel(HttpServletRequest request, HttpServletResponse response,List successList, Class dataClass, String fileName) throws Exception { + ExportParams exportParams = new ExportParams(); + exportParams.setType(ExcelType.XSSF); + Workbook workBook = ExcelExportUtil.exportExcel(exportParams, dataClass, successList); response.setContentType("application/octet-stream;charset=UTF-8"); //response.setHeader("Content-Type", "application/vnd.ms-excel");//xls response.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");//xlsx @@ -352,39 +401,18 @@ public class AsyncTask { response.addHeader("Pargam", "no-cache"); response.addHeader("Cache-Control", "no-cache"); OutputStream out = response.getOutputStream(); - wb.write(out); + workBook.write(out); out.flush(); out.close(); } @Async public void importExcelPoiDataForNew(File file, MallUserInfo user, String importKey,HttpServletRequest request, HttpServletResponse response) { - ImportParams params = new ImportParams(); // 需要验证 - String[] headers = new String[]{"门店名称", "门店ID", "城市", "详细地址","管理员手机号","富茂系统商户ID", "富茂系统商户名称","富茂系统省份", "富茂系统城市", "富茂系统地址","富茂系统经度", "富茂系统纬度","高德匹配备注","POI导入日志"}; - params.setImportFields(headers); - IExcelDataHandler handler = new AsyncTask.PoiNewExcelHandler(); - handler.setNeedHandlerFields(new String[]{"门店ID","富茂系统商户ID","富茂系统省份", "富茂系统城市", "富茂系统地址","富茂系统经度", "富茂系统纬度"}); - params.setNeedVerify(true); - - ExcelImportResult datalist = null; - - try { - datalist = ExcelImportUtil.importExcelMore(file, MerchantPoiTNew.class, params); - } catch (Exception e) { - logger.error("importExcelPoiDataForNew error.",e); - stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); - // 删除缓存文件 - file.delete(); - return; - } - // 删除缓存文件 - file.delete(); - - if(datalist == null) { - logger.error("导入模板失败: 模板数据解析失败"); - stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); - return; + String[] needFields = new String[]{"门店ID","富茂系统商户ID","富茂系统省份", "富茂系统城市", "富茂系统地址","富茂系统经度", "富茂系统纬度"}; + ExcelImportResult datalist = handleImportFile(null,file,MerchantPoiTNew.class,poiImportFields,needFields,new AsyncTask.PoiNewExcelHandler()); + if (null == datalist) { + return ; } List successList = datalist.getList(); @@ -398,11 +426,7 @@ public class AsyncTask { } }); stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); - ExportParams exportParams = new ExportParams(); - exportParams.setType(ExcelType.XSSF); - Workbook workBook = ExcelExportUtil.exportExcel(exportParams, MerchantPoiTNew.class, successList); - exportExcel(request, response, workBook, "POI导入-结果.xlsx"); - + exportExcel(request, response, successList,MerchantPoiTNew.class, "POI导入-结果.xlsx"); } catch (Exception e) { logger.error("导入模板失败:"+e.getMessage(),e); stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); @@ -410,62 +434,5 @@ public class AsyncTask { } } - @Async - public void importCardPriceData(File file, MallUserInfo user, String importKey) { - ImportParams params = new ImportParams(); - // 需要验证 - params.setImportFields(new String[]{"*卡ID", "*面额(元)"}); - IExcelDataHandler handler = new AsyncTask.CardPriceExcelHandler(); - handler.setNeedHandlerFields(new String[]{"*卡ID","*面额(元)"}); - params.setNeedVerify(true); - ExcelImportResult datalist = null; - - try { - datalist = ExcelImportUtil.importExcelMore(file, WxCardPriceTemplate.class, params); - } catch (Exception e) { - set_redis_value(importKey, "1", "0", "0", "1", true); - logger.error(e.getMessage()); - // 删除缓存文件 - file.delete(); - return; - } - // 删除缓存文件 - file.delete(); - - if(datalist == null) { - logger.error("导入模板失败: 模板数据解析失败"); - set_redis_value(importKey, "1", "0", "0", "1", true); - return; - } - - List successList = datalist.getList(); - List failList = datalist.getFailList(); - - logger.info("验证通过的数量: " + successList.size()); - logger.info("验证未通过的数量: " + failList.size()); - - int total = successList.size() + failList.size(); - int all_success = successList.size(); - int all_fail = failList.size(); - - //添加到redis里 - set_redis_value(importKey, "" + total, "" + all_success, "0", "" + all_fail, total == all_fail); - - if(successList.size() > 0) { - try { - successList.parallelStream().forEach(poiBase -> { - try { - wxCouponPasswordService.importPrice(user,importKey, poiBase); - } catch (UnknownSessionException ue) { - logger.error("session :"+ue.getMessage()); - } - }); - } catch (Exception e) { - set_redis_value(importKey, "1", "0", "0", "1", true); - e.printStackTrace(); - logger.error("导入模板失败:"+e.getMessage()); - } - } - } } diff --git a/mallinkService/src/main/java/com/iformall/utils/Constant.java b/mallinkService/src/main/java/com/iformall/utils/Constant.java index d39ca9b69..3fa9573d3 100644 --- a/mallinkService/src/main/java/com/iformall/utils/Constant.java +++ b/mallinkService/src/main/java/com/iformall/utils/Constant.java @@ -94,6 +94,8 @@ public class Constant { // 导入POI public static final String importPoiPrev = "importpoi:"; + + public static final String importPoiMerchantPrev = "importpoimerchant:"; //商品门店 public static final String coupon_merchants_key = "coupon:merchants:";