国际化
parent
191d72f8ea
commit
485e592591
@ -0,0 +1,50 @@
|
||||
|
||||
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.controller.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.anji.plus.gaea.curd.dto.GaeaBaseDTO;
|
||||
import com.anji.plus.gaea.annotation.Formatter;
|
||||
import lombok.Data;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @description ui文字国际化处理 dto
|
||||
* @author 王斌
|
||||
* @date 2021-03-25 15:30:59.286
|
||||
**/
|
||||
@Data
|
||||
public class GaeaUiI18nDto extends GaeaBaseDTO implements Serializable {
|
||||
/** 语言标识 */
|
||||
@Formatter(dictCode = "LOCALE",targetField = "localeCn")
|
||||
private String locale;
|
||||
private String localeCn;
|
||||
|
||||
/** 行业标识 */
|
||||
@Formatter(dictCode = "SYS_CATA_TYPE",targetField = "cataTypeCn")
|
||||
private String cataType;
|
||||
private String cataTypeCn;
|
||||
|
||||
/** 所属系统 */
|
||||
private String system;
|
||||
|
||||
/** 所属菜单编号 */
|
||||
private String module;
|
||||
|
||||
/** 字段编码 */
|
||||
private String code;
|
||||
|
||||
/** 字段名称 */
|
||||
private String name;
|
||||
|
||||
/** 业务描述 */
|
||||
private String remark;
|
||||
private String refer;
|
||||
/** 启用状态 */
|
||||
@Formatter(dictCode = "ENABLE_FLAG",targetField = "enabledCn")
|
||||
private Integer enabled;
|
||||
private String enabledCn;
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/**/
|
||||
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.controller.param;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import com.anji.plus.gaea.annotation.Query;
|
||||
import com.anji.plus.gaea.constant.QueryEnum;
|
||||
import com.anji.plus.gaea.curd.params.PageParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @desc GaeaUiI18n ui文字国际化处理查询输入类
|
||||
* @author 王斌
|
||||
* @date 2021-03-25 15:30:59.286
|
||||
**/
|
||||
@Data
|
||||
public class GaeaUiI18nParam extends PageParam implements Serializable{
|
||||
|
||||
/** 精确查询 */
|
||||
@Query
|
||||
private String locale;
|
||||
|
||||
/** 精确查询 */
|
||||
@Query
|
||||
private String cataType;
|
||||
|
||||
/** 精确查询 */
|
||||
@Query
|
||||
private String system;
|
||||
|
||||
/** 模糊查询 */
|
||||
@Query(value = QueryEnum.LIKE)
|
||||
private String code;
|
||||
|
||||
/** 模糊查询 */
|
||||
@Query(value = QueryEnum.LIKE)
|
||||
private String name;
|
||||
|
||||
/** 模糊查询 */
|
||||
@Query(value = QueryEnum.LIKE)
|
||||
private String remark;
|
||||
|
||||
@Query(value = QueryEnum.EQ)
|
||||
private String refer;
|
||||
|
||||
@Query(value = QueryEnum.EQ)
|
||||
private String module;
|
||||
|
||||
/** 精确查询 */
|
||||
@Query
|
||||
private Integer enabled;
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
|
||||
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.dao.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
/**
|
||||
* @description ui文字国际化处理 entity
|
||||
* @author 王斌
|
||||
* @date 2021-03-25 15:30:59.286
|
||||
**/
|
||||
@TableName(value="gaea_ui_i18n")
|
||||
@Data
|
||||
public class GaeaUiI18n extends GaeaBaseEntity {
|
||||
@ApiModelProperty(value = "语言标识")
|
||||
private String locale;
|
||||
|
||||
@ApiModelProperty(value = "行业标识")
|
||||
private String cataType;
|
||||
|
||||
@ApiModelProperty(value = "所属系统")
|
||||
private String system;
|
||||
|
||||
@ApiModelProperty(value = "所属模块")
|
||||
private String module;
|
||||
|
||||
@ApiModelProperty(value = "字段编码")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty(value = "字段名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "业务描述")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "关联表名")
|
||||
private String refer;
|
||||
|
||||
@ApiModelProperty(value = "启用状态")
|
||||
private Integer enabled;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.service.impl;
|
||||
|
||||
import com.anjiplus.template.gaea.generator.domain.Column;
|
||||
|
||||
/**
|
||||
* @author WongBin
|
||||
* @date 2021/3/26
|
||||
*/
|
||||
public class ColumnDesc extends Column {
|
||||
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
|
||||
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import com.anji.plus.gaea.constant.BaseOperationEnum;
|
||||
import com.anji.plus.gaea.constant.Enabled;
|
||||
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
|
||||
|
||||
import com.anji.plus.gaea.exception.BusinessException;
|
||||
import com.anjiplus.template.gaea.generator.domain.Column;
|
||||
import com.anjiplus.template.gaea.generator.service.GeneratorService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.dao.entity.GaeaUiI18n;
|
||||
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.service.GaeaUiI18nService;
|
||||
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.dao.GaeaUiI18nMapper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @desc GaeaUiI18n ui文字国际化处理服务实现
|
||||
* @author 王斌
|
||||
* @date 2021-03-25 15:30:59.286
|
||||
**/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class GaeaUiI18nServiceImpl implements GaeaUiI18nService {
|
||||
|
||||
@Autowired
|
||||
private GaeaUiI18nMapper gaeaUiI18nMapper;
|
||||
|
||||
@Override
|
||||
public GaeaBaseMapper<GaeaUiI18n> getMapper() {
|
||||
return gaeaUiI18nMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GaeaUiI18n getDetail(Long id) {
|
||||
GaeaUiI18n gaeaUiI18n = this.selectOne(id);
|
||||
return gaeaUiI18n;
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
GeneratorService generatorService;
|
||||
|
||||
@Value("${spring.application.name}")
|
||||
private String applicationName;
|
||||
|
||||
@Override
|
||||
public void processBeforeOperation(GaeaUiI18n entity,
|
||||
BaseOperationEnum type) throws BusinessException {
|
||||
if(BaseOperationEnum.INSERT.equals(type)){
|
||||
entity.setSystem(applicationName);
|
||||
//entity.setCataType("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scan(String table) {
|
||||
assert table!=null;
|
||||
LambdaQueryWrapper<GaeaUiI18n> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(GaeaUiI18n::getRefer,table);
|
||||
if(gaeaUiI18nMapper.selectCount(wrapper) > 0){
|
||||
log.warn("{} exist,ignore",table);
|
||||
throw new BusinessException("6001",new String[]{"该表的字段已维护国际化配置"});
|
||||
}
|
||||
List<Column> columnDescList = generatorService.getColumns(table);
|
||||
//List<ColumnDesc> columnDescList = gaeaUiI18nMapper.queryColumns(table);
|
||||
if(!CollectionUtils.isEmpty(columnDescList)){
|
||||
List<GaeaUiI18n> list = columnDescList.stream().map(item->{
|
||||
if(item.getRemark()!=null && item.getRemark().length()>20){
|
||||
item.setRemark(item.getRemark().substring(0,20));
|
||||
}
|
||||
GaeaUiI18n it = new GaeaUiI18n();
|
||||
it.setCode(StrUtil.toCamelCase(item.getColumnName()));
|
||||
it.setName(item.getRemark());
|
||||
it.setLocale(getI18nLang());
|
||||
it.setSystem(applicationName);
|
||||
it.setRemark(item.getRemark());
|
||||
it.setEnabled(Enabled.YES.getValue());
|
||||
it.setRefer(item.getTableName());
|
||||
return it;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
int ret = gaeaUiI18nMapper.insertBatch(list);
|
||||
log.info("insert-batch-for:{},size:{}",table,ret);
|
||||
}
|
||||
}
|
||||
|
||||
private String getI18nLang(){
|
||||
return LocaleContextHolder.getLocale().getLanguage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUi18nTables() {
|
||||
return gaeaUiI18nMapper.queryTables("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getI18nFields(GaeaUiI18n q) {
|
||||
String table = q.getRefer();
|
||||
String tableAlias = "";
|
||||
// 提取表名称和别名
|
||||
if(q.getRefer().contains(":")) {
|
||||
table = q.getRefer().split(":")[0];
|
||||
tableAlias = Optional.ofNullable(q.getRefer().substring(table.length() + 1)).orElse("");
|
||||
q.setRefer(table);
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<GaeaUiI18n> qry = Wrappers.lambdaQuery();
|
||||
qry.eq(GaeaUiI18n::getLocale,q.getLocale())
|
||||
.and(t->t.eq(GaeaUiI18n::getEnabled,Enabled.YES.getValue()))
|
||||
// 所属行业
|
||||
.and(t->t.eq(GaeaUiI18n::getCataType,q.getCataType()).or().isNull(GaeaUiI18n::getCataType))
|
||||
// 同一个表 或同一个菜单
|
||||
.and(t->t.eq(GaeaUiI18n::getRefer,q.getRefer()).or().eq(GaeaUiI18n::getModule,q.getModule()))
|
||||
;
|
||||
List<GaeaUiI18n> list = gaeaUiI18nMapper.selectList(qry);
|
||||
|
||||
HashMap kv = new HashMap();
|
||||
// 表级别 字段默认设置
|
||||
list.stream().filter(i->i.getRefer()!=null && i.getCataType()==null).forEach(i->{
|
||||
kv.put(i.getCode(),i.getName());
|
||||
});
|
||||
// 表级别 字段行业属性,覆盖默认设置
|
||||
list.stream().filter(i->i.getRefer()!=null && i.getCataType()!=null).forEach(i->{
|
||||
kv.put(i.getCode(),i.getName());
|
||||
});
|
||||
|
||||
Map result = new HashMap();
|
||||
// 挂载在module根节点
|
||||
if(tableAlias.length()<1) {
|
||||
result.put(q.getModule(), kv);
|
||||
}else {
|
||||
// 作为module的子节点
|
||||
result.putIfAbsent(q.getModule(),new HashMap<>());
|
||||
((Map)result.get(q.getModule())).put(tableAlias,kv);
|
||||
}
|
||||
|
||||
// 设置模块级别的字段配置
|
||||
HashMap m = new HashMap();
|
||||
list.stream().filter(i->i.getRefer()==null && i.getModule().equals(q.getModule())).forEach(item->{
|
||||
m.put(item.getCode(),item.getName());
|
||||
});
|
||||
if(!m.isEmpty()) {
|
||||
((Map)result.get(q.getModule())).putAll(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue