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