feat(sis): 解压指定编码GBK

This commit is contained in:
zcxlsm 2025-07-31 20:47:18 +08:00
parent 9afeed3108
commit 6c57942886
2 changed files with 16 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package org.dromara.property.controller;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import cn.dev33.satoken.stp.StpUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*; import jakarta.validation.constraints.*;
@ -12,6 +13,7 @@ import org.dromara.property.domain.vo.ResidentPersonImportVo;
import org.dromara.property.listener.ResidentPersonImportListener; import org.dromara.property.listener.ResidentPersonImportListener;
import org.dromara.property.utils.UploadFaceUtil; import org.dromara.property.utils.UploadFaceUtil;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit; import org.dromara.common.idempotent.annotation.RepeatSubmit;
@ -34,7 +36,7 @@ import org.springframework.web.multipart.MultipartFile;
* 前端访问路由地址为:/property/person * 前端访问路由地址为:/property/person
* *
* @author mocheng * @author mocheng
* @date 2025-06-19 * @since 2025-06-19
*/ */
@Validated @Validated
@RequiredArgsConstructor @RequiredArgsConstructor
@ -128,6 +130,16 @@ public class ResidentPersonController extends BaseController {
return R.ok(result.getAnalysis()); return R.ok(result.getAnalysis());
} }
@Async
public void asyncImportExcel(String tokenValue, MultipartFile file, Boolean updateSupport, Long unitId) {
try {
StpUtil.setTokenValueToStorage(tokenValue);
ExcelResult<ResidentPersonImportVo> result = ExcelUtil.importExcel(file.getInputStream(), ResidentPersonImportVo.class, new ResidentPersonImportListener(updateSupport, unitId));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/** /**
* 获取导入模板 * 获取导入模板
*/ */
@ -139,7 +151,7 @@ public class ResidentPersonController extends BaseController {
/** /**
* 导入人脸数据 * 导入人脸数据
* *
* @param file 导入文件 * @param file 导入文件
* @param unitId 单位ID * @param unitId 单位ID
*/ */
@PostMapping(value = "/importFace", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "/importFace", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)

View File

@ -14,7 +14,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.nio.charset.StandardCharsets; import java.nio.charset.Charset;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
@ -58,7 +58,7 @@ public class UploadFaceUtil {
// 重置统计信息 // 重置统计信息
resetStats(); resetStats();
try (ZipInputStream zis = new ZipInputStream(zipFile.getInputStream(), StandardCharsets.UTF_8)) { try (ZipInputStream zis = new ZipInputStream(zipFile.getInputStream(), Charset.forName("GBK"))) {
ZipEntry entry; ZipEntry entry;
byte[] buffer = new byte[8192]; // 8KB缓冲区 byte[] buffer = new byte[8192]; // 8KB缓冲区
long totalExtractedSize = 0; long totalExtractedSize = 0;