diff --git a/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/constant/BusinessConstants.java b/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/constant/BusinessConstants.java index 2640c22..4534469 100644 --- a/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/constant/BusinessConstants.java +++ b/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/constant/BusinessConstants.java @@ -134,6 +134,11 @@ public class BusinessConstants { * 每页显示记录数 */ public static final String PAGE_SIZE = "pageSize"; + public static final String JPGE = "image/jpeg"; + public static final String PNG = "image/png"; + public static final String JPG = "image/jpg"; + + public final static Integer CELL_1 = 1; public final static Integer CELL_2 = 2; diff --git a/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/ImportExcelUtils.java b/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/ImportExcelUtils.java index 8f938b1..0a0a8d6 100644 --- a/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/ImportExcelUtils.java +++ b/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/ImportExcelUtils.java @@ -89,7 +89,7 @@ public class ImportExcelUtils { int colNum = sheet.getRow(1).getLastCellNum(); if (Objects.equals(className, BusinessConstants.PERSON_IMPORT_VO)) { return colNum == 9; - }else if(Objects.equals(className, BusinessConstants.Gt_IMPORT_VO)){ + } else if (Objects.equals(className, BusinessConstants.Gt_IMPORT_VO)) { return colNum == 4; } return false; @@ -113,7 +113,7 @@ public class ImportExcelUtils { if (row.getRowNum() < 2) { continue; } - }else if(Objects.equals(mClass.getSimpleName(), BusinessConstants.Gt_IMPORT_VO)){ + } else if (Objects.equals(mClass.getSimpleName(), BusinessConstants.Gt_IMPORT_VO)) { if (row.getRowNum() < 2) { continue; } @@ -131,9 +131,9 @@ public class ImportExcelUtils { JSONObject obj = new JSONObject(); obj.put("rowNo", row.getRowNum() + 1); if (Objects.equals(mClass.getSimpleName(), BusinessConstants.PERSON_IMPORT_VO)) { - setExcelToString(5, row); + setExcelToString(9, row); obj = setPersonObjData(row, obj, filename); - }else if (Objects.equals(mClass.getSimpleName(), BusinessConstants.Gt_IMPORT_VO)) { + } else if (Objects.equals(mClass.getSimpleName(), BusinessConstants.Gt_IMPORT_VO)) { setExcelToString(5, row); obj = setGtObjData(row, obj, filename); } @@ -244,22 +244,32 @@ public class ImportExcelUtils { if (part instanceof XSSFDrawing) { XSSFDrawing drawing = (XSSFDrawing) part; List shapes = drawing.getShapes(); - for (XSSFShape shape : shapes) { - XSSFPicture picture = (XSSFPicture) shape; - XSSFClientAnchor anchor = picture.getPreferredSize(); - CTMarker marker = anchor.getFrom(); - Row row = sheet.getRow(marker.getRow()); - if (row == null) { - continue; + try { + if (!(shape instanceof XSSFPicture)) { + throw new RuntimeException("模版中包含非图片(jpeg、jpg、png)的文件,请仔细检查"); + } + XSSFPicture picture = (XSSFPicture) shape; + boolean isImage = isXlsxImage(picture.getPictureData()); + if (!isImage) { + throw new RuntimeException("模版中包含非图片(jpeg、jpg、png)的文件,请仔细检查"); + } + XSSFClientAnchor anchor = picture.getPreferredSize(); + CTMarker marker = anchor.getFrom(); + Row row = sheet.getRow(marker.getRow()); + if (row == null) { + continue; + } + String keyName = null; + if (Objects.equals(className, BusinessConstants.PERSON_IMPORT_VO)) { + keyName = setKey(picture, row, BusinessConstants.PERSON_IMPORT_VO); + } else { + keyName = ""; + } + map.put(keyName, picture.getPictureData()); + } catch (Exception e) { + throw new RuntimeException("模版中包含非图片(jpeg、jpg、png)的文件,请仔细检查"); } - String keyName = null; - if (Objects.equals(className, BusinessConstants.PERSON_IMPORT_VO)) { - keyName = setKey(picture, row, BusinessConstants.PERSON_IMPORT_VO); - } else { - keyName = ""; - } - map.put(keyName, picture.getPictureData()); } } } @@ -281,6 +291,10 @@ public class ImportExcelUtils { for (HSSFShape shape : list) { if (shape instanceof HSSFPicture) { HSSFPicture picture = (HSSFPicture) shape; + boolean isImage = isXlsImage(picture.getPictureData()); + if (!isImage) { + throw new RuntimeException("模版中包含非图片(jpeg、jpg、png)的文件,请仔细检查"); + } int pictureIndex = ((HSSFPicture) shape).getPictureIndex(); if (pictureIndex != -1) { HSSFClientAnchor cAnchor = picture.getClientAnchor(); @@ -361,4 +375,42 @@ public class ImportExcelUtils { } } } + + /** + * Xls判断文件是否是png、jpg格式 + * + * @param pictureData + * @return boolean + * @author cwchen + * @date 2024/8/20 11:17 + */ + private static boolean isXlsImage(HSSFPictureData pictureData) { + String mimeType = pictureData.getMimeType(); + System.err.println(mimeType); + if (Objects.equals(mimeType, BusinessConstants.JPGE) || + Objects.equals(mimeType, BusinessConstants.JPG) || + Objects.equals(mimeType, BusinessConstants.PNG)) { + return true; + } + return false; + } + + /** + * Xlsx 判断文件是否是png、jpg格式 + * + * @param pictureData + * @return boolean + * @author cwchen + * @date 2024/8/20 11:29 + */ + private static boolean isXlsxImage(XSSFPictureData pictureData) { + String mimeType = pictureData.getMimeType(); + System.err.println(mimeType); + if (Objects.equals(mimeType, BusinessConstants.JPGE) || + Objects.equals(mimeType, BusinessConstants.JPG) || + Objects.equals(mimeType, BusinessConstants.PNG)) { + return true; + } + return false; + } } diff --git a/bonus-common/bonus-common-security/src/main/java/com/bonus/common/security/utils/SpringThreadPoolConfig.java b/bonus-common/bonus-common-security/src/main/java/com/bonus/common/security/utils/SpringThreadPoolConfig.java new file mode 100644 index 0000000..1a4284f --- /dev/null +++ b/bonus-common/bonus-common-security/src/main/java/com/bonus/common/security/utils/SpringThreadPoolConfig.java @@ -0,0 +1,65 @@ +package com.bonus.common.security.utils; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.concurrent.ThreadPoolExecutor; + +/** + * @author cw chen + * @description TODO + * @date 2022-08-22 14:42 + */ +@EnableAsync +@Configuration +public class SpringThreadPoolConfig { + /** + * 核心线程数(默认线程数) + */ + private int corePoolSize = 20; + + /** + * 最大线程数 + */ + private int maxPoolSize = 20; + + /** + * 允许线程空闲时间(单位:默认为秒) + */ + private int keepAliveTime = 10; + + /** + * 缓冲队列数 + */ + private int queueCapacity = 200; + + /** + * 线程池名前缀 + */ + private String threadNamePrefix = "custom-executor-"; + + @Bean("testTaskExecutor") + public ThreadPoolTaskExecutor taskExecutor1() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + //设置核心线程数 + executor.setCorePoolSize(corePoolSize); + //设置最大线程数 + executor.setMaxPoolSize(maxPoolSize); + //线程池所使用的缓冲队列 + executor.setQueueCapacity(queueCapacity); + //等待任务在关机时完成--表明等待所有线程执行完 + executor.setWaitForTasksToCompleteOnShutdown(true); + // 等待时间 (默认为0,此时立即停止),并没等待xx秒后强制停止 + executor.setKeepAliveSeconds(keepAliveTime); + // 线程名称前缀 + executor.setThreadNamePrefix(threadNamePrefix); + // 线程池对拒绝任务的处理策略 + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + // 初始化 + executor.initialize(); + return executor; + } + +} diff --git a/bonus-common/bonus-common-security/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/bonus-common/bonus-common-security/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 7a457ea..9b7fbe5 100644 --- a/bonus-common/bonus-common-security/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/bonus-common/bonus-common-security/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -4,4 +4,5 @@ com.bonus.common.security.service.TokenService com.bonus.common.security.aspect.PreAuthorizeAspect com.bonus.common.security.aspect.InnerAuthAspect com.bonus.common.security.handler.GlobalExceptionHandler -com.bonus.common.security.utils.ValidatorsUtils \ No newline at end of file +com.bonus.common.security.utils.ValidatorsUtils +com.bonus.common.security.utils.SpringThreadPoolConfig \ No newline at end of file diff --git a/bonus-modules/bonus-bracelet/src/main/java/com/bonus/bracelet/service/impl/PersonMgeServiceImpl.java b/bonus-modules/bonus-bracelet/src/main/java/com/bonus/bracelet/service/impl/PersonMgeServiceImpl.java index 57383a8..6f37528 100644 --- a/bonus-modules/bonus-bracelet/src/main/java/com/bonus/bracelet/service/impl/PersonMgeServiceImpl.java +++ b/bonus-modules/bonus-bracelet/src/main/java/com/bonus/bracelet/service/impl/PersonMgeServiceImpl.java @@ -36,6 +36,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; @@ -48,7 +49,10 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; import java.util.*; +import java.util.concurrent.Callable; +import java.util.concurrent.Future; import java.util.stream.Collectors; /** @@ -71,6 +75,9 @@ public class PersonMgeServiceImpl implements IPersonMgeService { @Resource(name = "ValidatorsUtils") private ValidatorsUtils validatorsUtils; + @Resource(name = "testTaskExecutor") + private ThreadPoolTaskExecutor testTaskExecutor; + @Resource private RemoteFileService remoteFileService; @@ -84,12 +91,11 @@ public class PersonMgeServiceImpl implements IPersonMgeService { public List getPersonLists(BraceletParamsDto dto) { dto.setSourceType(BusinessConstants.RESOURCE_TYPE_USER); List list = new ArrayList<>(); - int num = 0; try { list = mapper.getPersonLists(dto); for (PersonVo vo : list) { vo = handleData(vo); - num = mapper.getCertificateNum(vo.getId()); + int num = mapper.getCertificateNum(vo.getId()); vo.setCertificateNum(num); } } catch (Exception e) { @@ -515,6 +521,7 @@ public class PersonMgeServiceImpl implements IPersonMgeService { /** * 判断安全帽编号、马甲编号 是否重复 + * * @param list * @param value * @return boolean @@ -575,6 +582,26 @@ public class PersonMgeServiceImpl implements IPersonMgeService { return vo; } + /** + * 获取图片的base64 + * + * @param filePath + * @return String + * @author cwchen + * @date 2024/8/20 9:18 + */ + public String getImageBase64(String filePath) { + R result = remoteFileService.getImgBase64(filePath, SecurityConstants.INNER); + if (result != null && result.getCode() == HttpStatus.SUCCESS && result.getData() != null) { + String jsonString = JSON.toJSONString(result.getData()); + JSONObject item = JSON.parseObject(jsonString); + String base64 = item.getString("url"); + return base64; + } + return null; + } + + /** * 资源文件赋值 * diff --git a/bonus-modules/bonus-bracelet/src/main/resources/download/person_model.xlsx b/bonus-modules/bonus-bracelet/src/main/resources/download/person_model.xlsx index 088653c..c7c65e9 100644 Binary files a/bonus-modules/bonus-bracelet/src/main/resources/download/person_model.xlsx and b/bonus-modules/bonus-bracelet/src/main/resources/download/person_model.xlsx differ