From 3d08d302d9f307e1fa8daaa16fd69346c967c2dd Mon Sep 17 00:00:00 2001 From: bynt Date: Tue, 14 Sep 2021 18:20:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A7=A3=E6=9E=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/constant/DefaultConstant.java | 6 ++- .../modules/constant/FileConstant.java | 16 ++++++ .../modules/sms/domain/SmsConfiguration.java | 4 ++ .../sms/service/dto/SmsConfigurationDto.java | 3 ++ .../impl/SmsConfigurationServiceImpl.java | 11 ++-- .../sms/vo/UploadAndSendMessageVo.java | 6 ++- .../impl/TbUploadFileNewServiceImpl.java | 52 +++++++++---------- .../uploadnew/task/SaveToFileNewTask.java | 34 ++++++------ .../uploadnew/task/SendMessageTask.java | 25 ++++----- .../modules/uploadnew/util/ExcelUtils.java | 12 ++--- .../uploadnew/util/ToolExcelUtils.java | 45 ++++++++++++++++ .../src/main/resources/config/application.yml | 2 +- 12 files changed, 138 insertions(+), 78 deletions(-) create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/util/ToolExcelUtils.java diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/constant/DefaultConstant.java b/eladmin-system/src/main/java/me/zhengjie/modules/constant/DefaultConstant.java index ed4876e..ee2259d 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/constant/DefaultConstant.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/constant/DefaultConstant.java @@ -40,9 +40,13 @@ public class DefaultConstant { public static final int TEN_NUMBER = 10; /** - * 10 + * 11 */ public static final int ELEVEN_NUMBER = 11; + /** + * 12 + */ + public static final int TWELVE_NUMBER = 12; /** diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/constant/FileConstant.java b/eladmin-system/src/main/java/me/zhengjie/modules/constant/FileConstant.java index a71e9b0..acb2742 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/constant/FileConstant.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/constant/FileConstant.java @@ -2,6 +2,7 @@ package me.zhengjie.modules.constant; /** + * @author * 文件相关 常量类 */ public class FileConstant { @@ -16,6 +17,21 @@ public class FileConstant { */ public static final String XLSX_FILE_SUB_NAME = "xlsx"; + /** + * 以 xls 结尾的文件 + */ + public static final String XLS_FILE_SUB_NAME = "xls"; + + /** + * 以 txt 结尾的文件 + */ + public static final String TXT_FILE_SUB_NAME = "txt"; + + /** + * 以 txt 结尾的文件 + */ + public static final String CSV_FILE_SUB_NAME = "csv"; + /** * 以 zip 结尾的文件 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/sms/domain/SmsConfiguration.java b/eladmin-system/src/main/java/me/zhengjie/modules/sms/domain/SmsConfiguration.java index d3ed32e..79db6bb 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/sms/domain/SmsConfiguration.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/sms/domain/SmsConfiguration.java @@ -73,6 +73,10 @@ public class SmsConfiguration implements Serializable { @ApiModelProperty(value = "更新时间") private Timestamp updateTime; + @Column(name = "middle_image") + @ApiModelProperty(value = "中间页图片") + private String middleImage; + public void copy(SmsConfiguration source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/sms/service/dto/SmsConfigurationDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/sms/service/dto/SmsConfigurationDto.java index 865487a..1867417 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/sms/service/dto/SmsConfigurationDto.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/sms/service/dto/SmsConfigurationDto.java @@ -53,6 +53,9 @@ public class SmsConfigurationDto implements Serializable { /** 背景图片 */ private String imageUrl; + /** 中间页图片 */ + private String middleImage; + /** 创建日期 */ private Timestamp createTime; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/sms/service/impl/SmsConfigurationServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/sms/service/impl/SmsConfigurationServiceImpl.java index 8bb1e59..feb7408 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/sms/service/impl/SmsConfigurationServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/sms/service/impl/SmsConfigurationServiceImpl.java @@ -25,6 +25,7 @@ import me.zhengjie.annotation.rest.RedisLock; import me.zhengjie.common.http.ResponseCode; import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.constant.DefaultConstant; +import me.zhengjie.modules.constant.FileConstant; import me.zhengjie.modules.sms.domain.SmsConfiguration; import me.zhengjie.modules.sms.repository.SmsConfigurationRepository; import me.zhengjie.modules.sms.service.SmsConfigurationService; @@ -144,13 +145,13 @@ public class SmsConfigurationServiceImpl implements SmsConfigurationService { String name = file.getOriginalFilename(); String taskName = messageVo.getTaskName(); if (name != null) { - int lastIndexOf = name.lastIndexOf(StrUtil.DOT); + int lastIndexOf = name.lastIndexOf(StrUtil.DOT) + DefaultConstant.ONE_NUMBER; // 校验文件格式 String nameStr = name.substring(lastIndexOf); - if (!((".xlsx".equals(nameStr) - || ".xls".equals(nameStr)) - || ".txt".equals(nameStr) - || ".csv".equals(nameStr))) { + if (!((FileConstant.XLSX_FILE_SUB_NAME.equals(nameStr) + || FileConstant.XLS_FILE_SUB_NAME.equals(nameStr)) + || FileConstant.TXT_FILE_SUB_NAME.equals(nameStr) + || FileConstant.CSV_FILE_SUB_NAME.equals(nameStr))) { throw new BadRequestException(ResponseCode.NO_FILE_FORMAT.getDesc()); } // 任务名称检验,为必填参数,且不能重复 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/sms/vo/UploadAndSendMessageVo.java b/eladmin-system/src/main/java/me/zhengjie/modules/sms/vo/UploadAndSendMessageVo.java index f90ad72..6d9bfad 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/sms/vo/UploadAndSendMessageVo.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/sms/vo/UploadAndSendMessageVo.java @@ -27,8 +27,10 @@ public class UploadAndSendMessageVo { @ApiModelProperty(value = "图片路径") private String picturePath; - - @ApiModelProperty(value = "跳转链接") private String linkAddress; + + @ApiModelProperty(value = "中间页链接") + private String middleImage; + } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/TbUploadFileNewServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/TbUploadFileNewServiceImpl.java index 294a785..7e38ded 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/TbUploadFileNewServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/TbUploadFileNewServiceImpl.java @@ -15,12 +15,15 @@ */ package me.zhengjie.modules.uploadnew.service.impl; -import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.system.OsInfo; import cn.hutool.system.SystemUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import me.zhengjie.common.http.ResponseCode; +import me.zhengjie.exception.BadRequestException; +import me.zhengjie.modules.constant.DefaultConstant; +import me.zhengjie.modules.constant.FileConstant; import me.zhengjie.modules.upload.consts.SysConst; import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew; import me.zhengjie.modules.uploadnew.repository.TbUploadFileNewRepository; @@ -28,8 +31,7 @@ import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService; import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto; import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewQueryCriteria; import me.zhengjie.modules.uploadnew.service.mapstruct.TbUploadFileNewMapper; -import me.zhengjie.modules.uploadnew.util.ExcelUtils; -import me.zhengjie.modules.uploadnew.util.TxtUtils; +import me.zhengjie.modules.uploadnew.util.ToolExcelUtils; import me.zhengjie.utils.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; @@ -41,6 +43,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Paths; import java.sql.Timestamp; import java.text.SimpleDateFormat; @@ -161,49 +164,47 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService { try { // 把文件保存到本地路径 file.transferTo(Paths.get(eachFilePath)); - baseStr = ""; } catch (IOException e) { log.error("============== [transferTo file fail, path is {} ] ==============", eachFilePath, e); } String name = file.getOriginalFilename(); int lastIndexOf = name.lastIndexOf("."); - String nameStr = name.substring(lastIndexOf); + String nameStr = name.substring(lastIndexOf + DefaultConstant.ONE_NUMBER); //记录文件格式 String fileFormat = ""; - List list = null; //根据文件类型进行解析 - try { - // FIXME: 2021/4/23 0023 - if (nameStr.equals(".xlsx") || nameStr.equals(".xls")) { + // modify the analytical data type by Enzo date 2021-9-14 + switch (nameStr) { + case FileConstant + .XLSX_FILE_SUB_NAME: + case FileConstant + .XLS_FILE_SUB_NAME: fileFormat = "excel文件"; - ExcelUtils excelUtils = new ExcelUtils(); - list = excelUtils.excelParseList(file.getInputStream()); - - } else if (nameStr.equals(".txt")) { + count = ToolExcelUtils.countSizeByUrl(eachFilePath); + break; + case FileConstant.TXT_FILE_SUB_NAME: fileFormat = "txt文件"; - list = FileUtil.readLines(eachFilePath, "UTF-8"); - } else if (nameStr.equals(".csv")) { + count = FileUtil.readLines(eachFilePath, StandardCharsets.UTF_8).size(); + break; + case FileConstant.CSV_FILE_SUB_NAME: fileFormat = "csv文件"; - list = TxtUtils.csvParseList(file.getInputStream()); - } - } catch (Exception e) { - e.printStackTrace(); + count = ToolExcelUtils.countSizeByUrl(eachFilePath); + break; + default: } - // 统计行数 - if (CollectionUtil.isNotEmpty(list)) { - count += list.size(); + if (count <= DefaultConstant.ZERO_NUMBER) { + log.error("============= file parsing exception name as {} =============",name); + throw new BadRequestException(ResponseCode.FILE_HANDLE_FAIL.getDesc()); } // 保存所有的临时存放路径 pathBuilder.append(eachFilePath); pathBuilder.append(FILE_PATH_SPLIT); - // 2. 更新上传记录为正在上传,解析了有多少条 TbUploadFileNew tbUploadFileNew = new TbUploadFileNew(); - tbUploadFileNew.setUploadFileTaskName(taskName); - tbUploadFileNew.setUploadTime(new Timestamp(new Date().getTime())); + tbUploadFileNew.setUploadTime(new Timestamp(System.currentTimeMillis())); String currentUsername; if (SysConst.sysDebug) { tbUploadFileNew.setOperation(TEST_USER_NAME);//fixme 这边测试环境补充一下需要的操作人 @@ -211,7 +212,6 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService { currentUsername = SecurityUtils.getCurrentUsername(); tbUploadFileNew.setOperation(currentUsername); } - /* update by enzo update file upload type date 2021-9-7*/ tbUploadFileNew.setUploadType(uploadType); tbUploadFileNew.setFileFormat(fileFormat); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SaveToFileNewTask.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SaveToFileNewTask.java index 07a5956..7fa33d9 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SaveToFileNewTask.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SaveToFileNewTask.java @@ -13,8 +13,10 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.google.common.collect.Lists; import com.jcraft.jsch.Session; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import me.zhengjie.exception.BadRequestException; +import me.zhengjie.modules.constant.FileConstant; import me.zhengjie.modules.upload.task.model.ResponseEncryptJsonContent; import me.zhengjie.modules.upload.task.model.SendEncryptJsonContent; import me.zhengjie.modules.upload.task.model.SendRemoteUpdateJsonContent; @@ -22,6 +24,7 @@ import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew; import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService; import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto; import me.zhengjie.modules.uploadnew.util.ExcelUtils; +import me.zhengjie.modules.uploadnew.util.ToolExcelUtils; import me.zhengjie.modules.uploadnew.util.TxtUtils; import me.zhengjie.utils.ConvertUtil; import me.zhengjie.utils.DateUtil; @@ -105,6 +108,7 @@ public class SaveToFileNewTask { Long endMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli(); log.info("====== [ task start end, task name is {},cost milliSecond is {} ] ======", "SendBigDataTask", ConvertUtil.secondToTime(endMilliSecond - satrtMilliSecond)); } + /** * 执行异步任务 * @@ -140,39 +144,30 @@ public class SaveToFileNewTask { * * @param filePath 进行操作的每一个文件的路径 */ + @SneakyThrows private boolean handleEachFileContent(String filePath, TbUploadFileNewDto tbUploadFileNewDto) { //根据文件类型进行解析 - List listT = null; - try { - if("excel文件".equals(tbUploadFileNewDto.getFileFormat())){ - ExcelUtils excelUtils = new ExcelUtils(); - listT = excelUtils.excelParseListByUrl(filePath); - }else if ("txt文件".equals(tbUploadFileNewDto.getFileFormat())){ - listT = TxtUtils.txtParseListVyUrl(filePath); - }else if ("csv文件".equals(tbUploadFileNewDto.getFileFormat())){ - listT = TxtUtils.csvParseListByUrl(filePath); - } - }catch (Exception e){ - log.error("SaveToFileTaskNew|batchSendToEncrypt ready send json is : {}", ""); - throw new BadRequestException("解析文件异常"); - } + List listT = tbUploadFileNewDto.getFileFormat().contains(FileConstant.TXT_FILE_SUB_NAME) ? + TxtUtils.txtParseListVyUrl(filePath) : + ToolExcelUtils.excelParseListByUrl(filePath); + Map> preEncryptNumMap = listT.stream() .collect(Collectors.groupingBy(String::length)); if (CollectionUtil.isNotEmpty(preEncryptNumMap)) { // 分批调用接口进行加密 List list = preEncryptNumMap.get(PRE_SEND_NUM_LENGTH); - if (CollectionUtil.isNotEmpty(list)){ + if (CollectionUtil.isNotEmpty(list)) { batchSendToEncrypt(filePath, list); } } // modify by q 把剩下不需要加密的内容也写到文件中 List list = preEncryptNumMap.get(SEND_NUM_LENGTH); - if (CollectionUtil.isNotEmpty(list)){ + if (CollectionUtil.isNotEmpty(list)) { writeToFile(list, filePath + TEMP_FILE_END_STR); } // 加入一个全局控制开关 - if (!booleanTag){ + if (!booleanTag) { return Boolean.FALSE; } @@ -183,7 +178,7 @@ public class SaveToFileNewTask { transFileToOtherServer(filePath + TEMP_FILE_END_STR); // 调用远程接口完成一条记录更新 - boolean sendUpdatePostReqTag = sendUpdatePostReq(filePath+ TEMP_FILE_END_STR, tbUploadFileNewDto); + boolean sendUpdatePostReqTag = sendUpdatePostReq(filePath + TEMP_FILE_END_STR, tbUploadFileNewDto); // fixme 这里要修改之前的平台给一个更新接口,然后这边可以用rpc调用,也可以用http,也可以考虑直接消息中间件进行解耦 if (delFileTag && sendUpdatePostReqTag) { return Boolean.TRUE; @@ -288,6 +283,7 @@ public class SaveToFileNewTask { } return Boolean.FALSE; } + private void writeToFile(List collect, String fullPath) { // 构建存储文件 try { @@ -330,7 +326,7 @@ public class SaveToFileNewTask { * @param path 单个存储在本地的路径地址 * @return 返回请求结果 */ - private boolean sendUpdatePostReq(String path,TbUploadFileNewDto tbUploadFileNewDto) { + private boolean sendUpdatePostReq(String path, TbUploadFileNewDto tbUploadFileNewDto) { // 构建发送参数 SendRemoteUpdateJsonContent sendRemoteUpdateJsonContent = new SendRemoteUpdateJsonContent(); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SendMessageTask.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SendMessageTask.java index f95a8bc..57d9cda 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SendMessageTask.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SendMessageTask.java @@ -5,10 +5,12 @@ import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import me.zhengjie.constant.SmsConstant; import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.constant.DefaultConstant; +import me.zhengjie.modules.constant.FileConstant; import me.zhengjie.modules.sms.domain.TbSendSms; import me.zhengjie.modules.sms.dto.ShortLinkUrlDto; import me.zhengjie.modules.sms.service.TbSendSmsService; @@ -18,6 +20,7 @@ import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew; import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService; import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto; import me.zhengjie.modules.uploadnew.util.ExcelUtils; +import me.zhengjie.modules.uploadnew.util.ToolExcelUtils; import me.zhengjie.modules.uploadnew.util.TxtUtils; import me.zhengjie.utils.ConvertUtil; import me.zhengjie.utils.FileUtil; @@ -28,6 +31,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.sql.Timestamp; import java.time.Instant; @@ -86,22 +90,13 @@ public class SendMessageTask { * @param filePath 进行操作的每一个文件的路径 * @param smsConfigurationDto */ - private boolean handleEachFileContent(String filePath, String fileFormat, SmsConfigurationDto smsConfigurationDto) { + @SneakyThrows + private boolean handleEachFileContent(String filePath, String fileFormat, SmsConfigurationDto smsConfigurationDto) { //根据文件类型进行解析 - List list = null; - try { - if ("excel文件".equals(fileFormat)) { - ExcelUtils excelUtils = new ExcelUtils(); - list = excelUtils.excelParseListByUrl(filePath); - } else if ("txt文件".equals(fileFormat)) { - list = TxtUtils.txtParseListVyUrl(filePath); - } else if ("csv文件".equals(fileFormat)) { - list = TxtUtils.csvParseListByUrl(filePath); - } - } catch (Exception e) { - log.error("SaveToFileTaskNew|batchSendToEncrypt ready send json is : {}", ""); - throw new BadRequestException("解析文件异常"); - } + List list = fileFormat.contains(FileConstant.TXT_FILE_SUB_NAME) ? + TxtUtils.txtParseListVyUrl(filePath) : + ToolExcelUtils.excelParseListByUrl(filePath); + if (!CollectionUtils.isEmpty(list)) { List stringList = list.stream().filter (phone -> phone.trim().getBytes(StandardCharsets.UTF_8).length == DefaultConstant.ELEVEN_NUMBER). diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/util/ExcelUtils.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/util/ExcelUtils.java index e42be8a..2f53916 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/util/ExcelUtils.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/util/ExcelUtils.java @@ -1,6 +1,7 @@ package me.zhengjie.modules.uploadnew.util; import lombok.extern.slf4j.Slf4j; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; @@ -60,8 +61,7 @@ public class ExcelUtils { */ public List excelParseListByUrl(String url) throws IOException { List list = new ArrayList<>(); - InputStream inputStream = new FileInputStream(new File(url)) ; - try { + InputStream inputStream = new FileInputStream(url) ; Workbook workbook = new XSSFWorkbook(inputStream); //获取第一张工作表 @@ -79,13 +79,7 @@ public class ExcelUtils { //关闭资源 workbook.close(); } - } catch (FileNotFoundException e) { - log.info("ExcelUtils | excelParseList ==========未找到文件"); - e.printStackTrace(); - } catch (IOException e) { - log.info("ExcelUtils | excelParseList ==========解析失败!!"); - e.printStackTrace(); - } + return list; } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/util/ToolExcelUtils.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/util/ToolExcelUtils.java new file mode 100644 index 0000000..7c2cb71 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/util/ToolExcelUtils.java @@ -0,0 +1,45 @@ +package me.zhengjie.modules.uploadnew.util; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.poi.excel.ExcelReader; +import cn.hutool.poi.excel.ExcelUtil; +import lombok.extern.slf4j.Slf4j; +import me.zhengjie.modules.constant.DefaultConstant; +import org.apache.commons.collections4.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Enzo + * @date : 2021/9/14 + */ +@Slf4j +public class ToolExcelUtils { + + private ToolExcelUtils() { + } + + public static List excelParseListByUrl(String fileUrl) { + List list = new ArrayList<>(); + ExcelReader reader = ExcelUtil.getReader(cn.hutool.core.io.FileUtil.file(fileUrl)); + if (CollectionUtils.isNotEmpty(reader.read())) { + for (List objects : reader.read()) { + String phone = objects.toString(); + if (phone.startsWith(StrUtil.BRACKET_START) && phone.endsWith(StrUtil.BRACKET_END)) { + list.add(phone.substring(DefaultConstant.ONE_NUMBER, DefaultConstant.TWELVE_NUMBER)); + } + } + } + return list; + } + + public static int countSizeByUrl(String fileUrl) { + ExcelReader reader = ExcelUtil.getReader(cn.hutool.core.io.FileUtil.file(fileUrl)); + if (CollectionUtils.isNotEmpty(reader.read())) { + return reader.read().size(); + } + return DefaultConstant.ZERO_NUMBER; + } + +} diff --git a/eladmin-system/src/main/resources/config/application.yml b/eladmin-system/src/main/resources/config/application.yml index db79fa1..ba202b3 100644 --- a/eladmin-system/src/main/resources/config/application.yml +++ b/eladmin-system/src/main/resources/config/application.yml @@ -6,7 +6,7 @@ spring: freemarker: check-template-location: false profiles: - active: prod + active: dev jackson: time-zone: GMT+8 data: