Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
bdc38574a5 | ||
|
fd431ae7fd | ||
|
4e400f4962 | ||
|
5831bace54 | ||
|
ff6624158b | ||
|
83a0c00349 | ||
|
0f37f4a96b | ||
|
e1103eba02 | ||
|
03ceb02918 |
4
pom.xml
4
pom.xml
@ -30,7 +30,7 @@
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.22</version>
|
||||
<version>5.8.23</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -40,7 +40,7 @@
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
||||
<version>1.7.3</version>
|
||||
<version>1.7.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.blueland.common.core.controller;
|
||||
|
||||
import com.blueland.common.core.domain.International;
|
||||
import com.blueland.common.core.utils.UserUtils;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import io.swagger.annotations.*;
|
||||
import com.blueland.common.core.result.AjaxResult;
|
||||
@ -112,25 +113,23 @@ public class InternationalController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键复制
|
||||
* 一键翻译
|
||||
*
|
||||
* @param targetLang 目标语言
|
||||
* @param sourceLang 源语言
|
||||
* @return {@link AjaxResult}<{@link Boolean}>
|
||||
*/
|
||||
@GetMapping("/copy")
|
||||
@ApiOperation(value = "一键复制", notes = "例如:数据库只有中文,要翻译成英文")
|
||||
@GetMapping("/translate")
|
||||
@ApiOperation(value = "一键翻译")
|
||||
@ApiImplicitParams(
|
||||
{
|
||||
@ApiImplicitParam(name = "tenantId", value = "租户id", dataType = "String", paramType = "query", required = false),
|
||||
@ApiImplicitParam(name = "targetLang", value = "目标语言", dataType = "String", paramType = "query", required = true),
|
||||
@ApiImplicitParam(name = "sourceLang", value = "源语言", dataType = "String", paramType = "query", required = true)
|
||||
}
|
||||
)
|
||||
public AjaxResult<Boolean> copy(@RequestParam("targetLang") String targetLang,
|
||||
@RequestParam("sourceLang") String sourceLang,
|
||||
@RequestParam(value = "tenantId", required = false) String tenantId) {
|
||||
return AjaxResult.operates(internationalService.copy(targetLang, sourceLang, tenantId));
|
||||
public AjaxResult<Boolean> translate(@RequestParam("targetLang") String targetLang,
|
||||
@RequestParam("sourceLang") String sourceLang) {
|
||||
return AjaxResult.operates(internationalService.translate(targetLang, sourceLang, UserUtils.getTenantId()));
|
||||
}
|
||||
|
||||
@GetMapping("/dowloadTemplate")
|
||||
@ -154,17 +153,24 @@ public class InternationalController {
|
||||
* @param sourceLang 源语言
|
||||
* @return {@link AjaxResult}<{@link Boolean}>
|
||||
*/
|
||||
@GetMapping("/tenantIdCopy")
|
||||
@ApiOperation(value = "一键复制(从其他租户复制)", notes = "例如:bio里面有en语言包,现在要复制到AHI里面")
|
||||
@GetMapping("/tenantIdTranslate")
|
||||
@ApiOperation(value = "一键翻译(从其他租户复制)", notes = "例如:bio里面有en语言包,现在要复制到AHI里面")
|
||||
@ApiImplicitParams(
|
||||
{
|
||||
@ApiImplicitParam(name = "tenantId", value = "租户id", dataType = "String", paramType = "query", required = true),
|
||||
@ApiImplicitParam(name = "sourceLang", value = "源语言", dataType = "String", paramType = "query", required = true)
|
||||
}
|
||||
)
|
||||
public AjaxResult<Boolean> tenantIdCopy(@RequestParam("sourceLang") String sourceLang,
|
||||
public AjaxResult<Boolean> tenantIdTranslate(@RequestParam("sourceLang") String sourceLang,
|
||||
String tenantId) {
|
||||
return AjaxResult.operates(internationalService.tenantIdCopy(sourceLang, tenantId));
|
||||
return AjaxResult.operates(internationalService.tenantIdTranslate(sourceLang, tenantId));
|
||||
}
|
||||
|
||||
@GetMapping("/init")
|
||||
@ApiOperation("初始化本租户的国际化数据")
|
||||
public AjaxResult init() {
|
||||
internationalService.init();
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
@ -43,16 +43,12 @@ public class BaseEntity {
|
||||
private Date updateTime;
|
||||
|
||||
@Column(ignore = true)
|
||||
@JSONField(serialize = false)
|
||||
@ApiModelProperty(value = "分页大小")
|
||||
@JsonIgnore
|
||||
private int pageSize;
|
||||
protected int pageSize;
|
||||
|
||||
@Column(ignore = true)
|
||||
@JSONField(serialize = false)
|
||||
@ApiModelProperty(value = "分页页码")
|
||||
@JsonIgnore
|
||||
private int pageNum;
|
||||
protected int pageNum;
|
||||
|
||||
@JsonIgnore
|
||||
public Page getPage() {
|
||||
|
@ -42,7 +42,7 @@ public class ExcelDicHandler implements IExcelDictHandler {
|
||||
dictMap.put("dictValue", "前端");
|
||||
list.add(dictMap);
|
||||
dictMap = new HashMap<>();
|
||||
dictMap.put("dictKey", "black");
|
||||
dictMap.put("dictKey", "back");
|
||||
dictMap.put("dictValue", "后端");
|
||||
list.add(dictMap);
|
||||
return list;
|
||||
@ -72,7 +72,7 @@ public class ExcelDicHandler implements IExcelDictHandler {
|
||||
if ("前端".equals(String.valueOf(value))) {
|
||||
return "front";
|
||||
}
|
||||
return "black";
|
||||
return "back";
|
||||
} else if (SysConstan.LANG.equals(dict)) {
|
||||
if ("中文".equals(String.valueOf(value))) {
|
||||
return "zh";
|
||||
|
@ -62,7 +62,7 @@ public interface InternationalService extends IService<International> {
|
||||
* @param tenantId
|
||||
* @return boolean
|
||||
*/
|
||||
boolean copy(String targetLang, String sourceLang, String tenantId);
|
||||
boolean translate(String targetLang, String sourceLang, String tenantId);
|
||||
|
||||
|
||||
/**
|
||||
@ -109,6 +109,7 @@ public interface InternationalService extends IService<International> {
|
||||
* @param tenantId 保持ID
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
Boolean tenantIdCopy(String sourceLang, String tenantId);
|
||||
Boolean tenantIdTranslate(String sourceLang, String tenantId);
|
||||
|
||||
void init();
|
||||
}
|
@ -34,6 +34,7 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.blueland.common.core.domain.table.InternationalTableDef.INTERNATIONAL;
|
||||
import static com.mybatisflex.core.query.QueryMethods.notExists;
|
||||
|
||||
/**
|
||||
* 国际化 服务层实现。
|
||||
@ -131,8 +132,8 @@ public class InternationalServiceImpl extends ServiceImpl<InternationalMapper, I
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean copy(String targetLang, String sourceLang, String tenantId) {
|
||||
List<International> sourceLangList = listByLang(sourceLang, tenantId, "");
|
||||
public boolean translate(String targetLang, String sourceLang, String tenantId) {
|
||||
List<International> sourceLangList = selectNotExist(targetLang, sourceLang, tenantId);
|
||||
|
||||
List<String> nameList = sourceLangList.stream()
|
||||
.map(International::getName)
|
||||
@ -147,7 +148,6 @@ public class InternationalServiceImpl extends ServiceImpl<InternationalMapper, I
|
||||
futures.add(future);
|
||||
}
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
||||
|
||||
List<International> targetLangList = sourceLangList.stream()
|
||||
.map(el -> {
|
||||
International international = new International();
|
||||
@ -159,7 +159,7 @@ public class InternationalServiceImpl extends ServiceImpl<InternationalMapper, I
|
||||
return international;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Assert.notEmpty(targetLangList, "根据租户和语言查询不到数据");
|
||||
boolean flag = saveBatch(targetLangList);
|
||||
if (flag) {
|
||||
RedisUtil.hashMultiSet(targetLang, targetLangList);
|
||||
@ -167,10 +167,26 @@ public class InternationalServiceImpl extends ServiceImpl<InternationalMapper, I
|
||||
return flag;
|
||||
}
|
||||
|
||||
private List<International> selectNotExist(String targetLang, String sourceLang, String tenantId) {
|
||||
QueryWrapper where = QueryWrapper.create()
|
||||
.select(INTERNATIONAL.CODE)
|
||||
.from(INTERNATIONAL)
|
||||
.where(INTERNATIONAL.LANG.eq(targetLang));
|
||||
|
||||
QueryWrapper wrapper = QueryWrapper.create()
|
||||
.from(INTERNATIONAL).as("t1")
|
||||
.where(INTERNATIONAL.LANG.eq(sourceLang))
|
||||
.and(INTERNATIONAL.CODE.notIn(where));
|
||||
|
||||
|
||||
return list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateInternational(International international) {
|
||||
boolean flag = updateById(international);
|
||||
if (flag) {
|
||||
international = getById(international.getId());
|
||||
RedisUtil.hashSet(international);
|
||||
}
|
||||
return flag;
|
||||
@ -212,6 +228,14 @@ public class InternationalServiceImpl extends ServiceImpl<InternationalMapper, I
|
||||
List<InternationalExport> importList;
|
||||
try {
|
||||
importList = ExcelImportUtil.importExcel(file.getInputStream(), InternationalExport.class, params);
|
||||
importList.stream()
|
||||
.collect(Collectors.groupingBy(el -> el.getCode() + el.getLang()))
|
||||
.values()
|
||||
.stream()
|
||||
.filter(el -> el.size() > 1)
|
||||
.forEach(el -> {
|
||||
Assert.isTrue(false, StrUtil.format("编码【{}】语言【{}】重复", el.get(0).getCode(), el.get(0).getLang()));
|
||||
});
|
||||
|
||||
// 校验数据完整性
|
||||
for (InternationalExport export : importList) {
|
||||
@ -232,7 +256,7 @@ public class InternationalServiceImpl extends ServiceImpl<InternationalMapper, I
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("导入失败");
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
List<International> list = BeanUtil.copyToList(importList, International.class);
|
||||
boolean flag = saveBatch(list);
|
||||
@ -258,7 +282,7 @@ public class InternationalServiceImpl extends ServiceImpl<InternationalMapper, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean tenantIdCopy(String sourceLang, String tenantId) {
|
||||
public Boolean tenantIdTranslate(String sourceLang, String tenantId) {
|
||||
List<International> list = listByLang(sourceLang, tenantId, "").stream()
|
||||
.map(el -> {
|
||||
el.setTenantId(UserUtils.getTenantId());
|
||||
@ -271,12 +295,32 @@ public class InternationalServiceImpl extends ServiceImpl<InternationalMapper, I
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
boolean flag = saveBatch(list);
|
||||
if(flag){
|
||||
if (flag) {
|
||||
RedisUtil.hashMultiSet(sourceLang, list);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据租户初始化
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
QueryWrapper wrapper = QueryWrapper.create()
|
||||
.where(INTERNATIONAL.TENANT_ID.eq(UserUtils.getTenantId()));
|
||||
List<International> list = list(wrapper);
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
list.stream()
|
||||
.collect(Collectors.groupingBy(International::getLang))
|
||||
.forEach((k, v) -> {
|
||||
RedisUtil.hashMultiSet(k, v);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Map<String, International> list(List<InternationalExport> list) {
|
||||
QueryWrapper wrapper = QueryWrapper.create();
|
||||
|
@ -9,6 +9,7 @@ import com.tencentcloudapi.tmt.v20180321.TmtClient;
|
||||
import com.tencentcloudapi.tmt.v20180321.models.TextTranslateBatchRequest;
|
||||
import com.tencentcloudapi.tmt.v20180321.models.TextTranslateBatchResponse;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -41,7 +42,8 @@ public class TranslateUtil {
|
||||
TextTranslateBatchResponse resp = client.TextTranslateBatch(req);
|
||||
String[] targetTextList = resp.getTargetTextList();
|
||||
for (int i = 0; i < targetTextList.length; i++) {
|
||||
infoMap.put(query.get(i), targetTextList[i]);
|
||||
String value = targetTextList[i].replace("[", "【").replace("]", "】");
|
||||
infoMap.put(query.get(i), value);
|
||||
}
|
||||
} catch (TencentCloudSDKException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@ -6,9 +6,6 @@ spring:
|
||||
username: crm
|
||||
password: crm@123
|
||||
url: jdbc:mysql://192.168.1.13:3308/crm_usm?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
|
||||
# redis:
|
||||
# host: localhost
|
||||
# port: 6379
|
||||
redis:
|
||||
database: 9
|
||||
host: 192.168.1.169
|
||||
@ -19,7 +16,7 @@ tm:
|
||||
|
||||
logging:
|
||||
level:
|
||||
net.rzdata.internation: debug
|
||||
com.blueland.common.core: debug
|
||||
mybatis-flex:
|
||||
type-aliases-package: com.blueland.common.core.domain
|
||||
|
||||
|
@ -13,9 +13,11 @@ spring:
|
||||
database: 9
|
||||
host: 192.168.1.169
|
||||
password: ''
|
||||
profiles:
|
||||
active: test
|
||||
tm:
|
||||
secretId: AKIDVotjKflbCYjgOr53xb093h6FApFQN5Yl
|
||||
secretKey: 1oMfqmSt52kDRYR4SaUAbmiOp1yf8MM7
|
||||
secretId: AKID4IXccMhHdjcJm0wqPjndHhspkbDbGeJz
|
||||
secretKey: aw3v5B3h8OPQO7j8JPGsFNHwMXTAcprf
|
||||
server:
|
||||
port: 8080
|
||||
servlet:
|
||||
@ -25,12 +27,9 @@ server:
|
||||
name: crm-internation
|
||||
logging:
|
||||
level:
|
||||
net.rzdata.internation: debug
|
||||
com.blueland.common.core: debug
|
||||
mybatis-flex:
|
||||
type-aliases-package: com.blueland.common.core.domain
|
||||
|
||||
|
||||
|
||||
knife4j:
|
||||
enable: true
|
||||
openapi:
|
||||
|
Loading…
x
Reference in New Issue
Block a user