feat(translate): 新增阿里云翻译工具类及接口
- 添加阿里云机器翻译工具类AliyunTranslateUtil - 实现单文本和批量翻译功能 - 配置阿里云翻译相关参数 - 创建翻译控制器TranslateController - 支持自动检测源语言翻译 - 提供翻译结果封装响应结构
This commit is contained in:
@@ -20,6 +20,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@@ -141,21 +142,25 @@ public class CreditUserController extends BaseController {
|
|||||||
@Operation(summary = "批量导入赊账客户")
|
@Operation(summary = "批量导入赊账客户")
|
||||||
@PostMapping("/import")
|
@PostMapping("/import")
|
||||||
public ApiResult<List<String>> importBatch(@RequestParam("file") MultipartFile file) {
|
public ApiResult<List<String>> importBatch(@RequestParam("file") MultipartFile file) {
|
||||||
ImportParams importParams = new ImportParams();
|
|
||||||
importParams.setTitleRows(1);
|
|
||||||
importParams.setHeadRows(1);
|
|
||||||
List<String> errorMessages = new ArrayList<>();
|
List<String> errorMessages = new ArrayList<>();
|
||||||
int successCount = 0;
|
int successCount = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<CreditUserImportParam> list = ExcelImportUtil.importExcel(file.getInputStream(), CreditUserImportParam.class, importParams);
|
List<CreditUserImportParam> list = tryImport(file, 1, 1);
|
||||||
|
System.out.println("list = " + list);
|
||||||
if (list == null || list.isEmpty()) {
|
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);
|
return fail("未读取到数据,请确认模板表头与示例格式一致", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
User loginUser = getLoginUser();
|
User loginUser = getLoginUser();
|
||||||
Integer currentUserId = loginUser != null ? loginUser.getUserId() : null;
|
Integer currentUserId = loginUser != null ? loginUser.getUserId() : null;
|
||||||
|
Integer currentTenantId = loginUser != null ? loginUser.getTenantId() : null;
|
||||||
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
CreditUserImportParam param = list.get(i);
|
CreditUserImportParam param = list.get(i);
|
||||||
@@ -166,6 +171,9 @@ public class CreditUserController extends BaseController {
|
|||||||
if (item.getUserId() == null && currentUserId != null) {
|
if (item.getUserId() == null && currentUserId != null) {
|
||||||
item.setUserId(currentUserId);
|
item.setUserId(currentUserId);
|
||||||
}
|
}
|
||||||
|
if (item.getTenantId() == null && currentTenantId != null) {
|
||||||
|
item.setTenantId(currentTenantId);
|
||||||
|
}
|
||||||
if (item.getStatus() == null) {
|
if (item.getStatus() == null) {
|
||||||
item.setStatus(0);
|
item.setStatus(0);
|
||||||
}
|
}
|
||||||
@@ -178,7 +186,6 @@ public class CreditUserController extends BaseController {
|
|||||||
if (item.getDeleted() == null) {
|
if (item.getDeleted() == null) {
|
||||||
item.setDeleted(0);
|
item.setDeleted(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证必填字段
|
// 验证必填字段
|
||||||
if (item.getName() == null || item.getName().trim().isEmpty()) {
|
if (item.getName() == null || item.getName().trim().isEmpty()) {
|
||||||
errorMessages.add("第" + (i + 1) + "行:客户名称不能为空");
|
errorMessages.add("第" + (i + 1) + "行:客户名称不能为空");
|
||||||
@@ -188,6 +195,7 @@ public class CreditUserController extends BaseController {
|
|||||||
errorMessages.add("第" + (i + 1) + "行:唯一标识不能为空");
|
errorMessages.add("第" + (i + 1) + "行:唯一标识不能为空");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
System.out.println("item = " + item);
|
||||||
|
|
||||||
if (creditUserService.save(item)) {
|
if (creditUserService.save(item)) {
|
||||||
successCount++;
|
successCount++;
|
||||||
@@ -255,6 +263,15 @@ public class CreditUserController extends BaseController {
|
|||||||
workbook.close();
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<CreditUserImportParam> 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实体
|
* 将CreditUserImportParam转换为CreditUser实体
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import java.io.Serializable;
|
|||||||
public class CreditUserImportParam implements Serializable {
|
public class CreditUserImportParam implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Excel(name = "客户名称")
|
@Excel(name = "项目名称")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Excel(name = "唯一标识")
|
@Excel(name = "唯一标识")
|
||||||
@@ -63,8 +63,8 @@ public class CreditUserImportParam implements Serializable {
|
|||||||
@Excel(name = "是否推荐", replace = {"否_0", "是_1"})
|
@Excel(name = "是否推荐", replace = {"否_0", "是_1"})
|
||||||
private Integer recommend;
|
private Integer recommend;
|
||||||
|
|
||||||
@Excel(name = "到期时间", format = "yyyy-MM-dd HH:mm:ss")
|
// @Excel(name = "到期时间", format = "yyyy-MM-dd HH:mm:ss")
|
||||||
private String expirationTime;
|
// private String expirationTime;
|
||||||
|
|
||||||
@Excel(name = "排序")
|
@Excel(name = "排序")
|
||||||
private Integer sortNumber;
|
private Integer sortNumber;
|
||||||
|
|||||||
Reference in New Issue
Block a user