From 888767c37b4c79d006f09701c0d4147f1b79919a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Mon, 15 Dec 2025 16:30:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(translate):=20=E6=96=B0=E5=A2=9E=E9=98=BF?= =?UTF-8?q?=E9=87=8C=E4=BA=91=E7=BF=BB=E8=AF=91=E5=B7=A5=E5=85=B7=E7=B1=BB?= =?UTF-8?q?=E5=8F=8A=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加阿里云机器翻译工具类AliyunTranslateUtil - 实现单文本和批量翻译功能 - 配置阿里云翻译相关参数 - 创建翻译控制器TranslateController - 支持自动检测源语言翻译 - 提供翻译结果封装响应结构 --- .../controller/CreditUserController.java | 31 ++++++++++++++----- .../credit/param/CreditUserImportParam.java | 6 ++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gxwebsoft/credit/controller/CreditUserController.java b/src/main/java/com/gxwebsoft/credit/controller/CreditUserController.java index a969aab..c718e6a 100644 --- a/src/main/java/com/gxwebsoft/credit/controller/CreditUserController.java +++ b/src/main/java/com/gxwebsoft/credit/controller/CreditUserController.java @@ -20,6 +20,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -141,21 +142,25 @@ public class CreditUserController extends BaseController { @Operation(summary = "批量导入赊账客户") @PostMapping("/import") public ApiResult> importBatch(@RequestParam("file") MultipartFile file) { - ImportParams importParams = new ImportParams(); - importParams.setTitleRows(1); - importParams.setHeadRows(1); List errorMessages = new ArrayList<>(); int successCount = 0; try { - List list = ExcelImportUtil.importExcel(file.getInputStream(), CreditUserImportParam.class, importParams); - - if (list == null || list.isEmpty()) { + List list = tryImport(file, 1, 1); + System.out.println("list = " + list); + if (CollectionUtils.isEmpty(list)) { + list = tryImport(file, 0, 1); // fallback:无标题行,只有表头 + } + if (CollectionUtils.isEmpty(list)) { + list = tryImport(file, 0, 2); // fallback:两行表头 + } + if (CollectionUtils.isEmpty(list)) { return fail("未读取到数据,请确认模板表头与示例格式一致", null); } User loginUser = getLoginUser(); Integer currentUserId = loginUser != null ? loginUser.getUserId() : null; + Integer currentTenantId = loginUser != null ? loginUser.getTenantId() : null; for (int i = 0; i < list.size(); i++) { CreditUserImportParam param = list.get(i); @@ -166,6 +171,9 @@ public class CreditUserController extends BaseController { if (item.getUserId() == null && currentUserId != null) { item.setUserId(currentUserId); } + if (item.getTenantId() == null && currentTenantId != null) { + item.setTenantId(currentTenantId); + } if (item.getStatus() == null) { item.setStatus(0); } @@ -178,7 +186,6 @@ public class CreditUserController extends BaseController { if (item.getDeleted() == null) { item.setDeleted(0); } - // 验证必填字段 if (item.getName() == null || item.getName().trim().isEmpty()) { errorMessages.add("第" + (i + 1) + "行:客户名称不能为空"); @@ -188,6 +195,7 @@ public class CreditUserController extends BaseController { errorMessages.add("第" + (i + 1) + "行:唯一标识不能为空"); continue; } + System.out.println("item = " + item); if (creditUserService.save(item)) { successCount++; @@ -255,6 +263,15 @@ public class CreditUserController extends BaseController { workbook.close(); } + private List tryImport(MultipartFile file, int titleRows, int headRows) throws Exception { + ImportParams importParams = new ImportParams(); + importParams.setTitleRows(titleRows); + importParams.setHeadRows(headRows); + importParams.setStartSheetIndex(0); + importParams.setSheetNum(1); + return ExcelImportUtil.importExcel(file.getInputStream(), CreditUserImportParam.class, importParams); + } + /** * 将CreditUserImportParam转换为CreditUser实体 */ diff --git a/src/main/java/com/gxwebsoft/credit/param/CreditUserImportParam.java b/src/main/java/com/gxwebsoft/credit/param/CreditUserImportParam.java index 706bf44..8acce7a 100644 --- a/src/main/java/com/gxwebsoft/credit/param/CreditUserImportParam.java +++ b/src/main/java/com/gxwebsoft/credit/param/CreditUserImportParam.java @@ -15,7 +15,7 @@ import java.io.Serializable; public class CreditUserImportParam implements Serializable { private static final long serialVersionUID = 1L; - @Excel(name = "客户名称") + @Excel(name = "项目名称") private String name; @Excel(name = "唯一标识") @@ -63,8 +63,8 @@ public class CreditUserImportParam implements Serializable { @Excel(name = "是否推荐", replace = {"否_0", "是_1"}) private Integer recommend; - @Excel(name = "到期时间", format = "yyyy-MM-dd HH:mm:ss") - private String expirationTime; +// @Excel(name = "到期时间", format = "yyyy-MM-dd HH:mm:ss") +// private String expirationTime; @Excel(name = "排序") private Integer sortNumber;