使用easy trans实现导出
This commit is contained in:
parent
8d9c99b8cc
commit
0511718368
|
@ -290,6 +290,8 @@ INSERT INTO sys_dict_type (id, dict_type, dict_name, remark, sort, version, dele
|
|||
INSERT INTO sys_dict_type (id, dict_type, dict_name, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (6, 'success_fail', '状态', '操作状态:成功 | 失败', 0, 0, 0, 10000, now(), 10000, now());
|
||||
INSERT INTO sys_dict_type (id, dict_type, dict_name, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (7, 'login_operation', '操作信息', '登录管理', 0, 0, 0, 10000, now(), 10000, now());
|
||||
INSERT INTO sys_dict_type (id, dict_type, dict_name, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (8, 'params_type', '系统参数', '参数管理', 0, 0, 0, 10000, now(), 10000, now());
|
||||
INSERT INTO sys_dict_type (id, dict_type, dict_name, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (9, 'user_super_admin', '用户是否是超管','用户是否是超管', 0, 0, 0, 10000, now(), 10000, now());
|
||||
|
||||
|
||||
INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (1, 1, '停用', '0', '', 1, 0, 0, 10000, now(), 10000, now());
|
||||
INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (2, 1, '正常', '1', '', 0, 0, 0, 10000, now(), 10000, now());
|
||||
|
@ -313,5 +315,8 @@ INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sor
|
|||
INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (20, 7, '账号密码错误', '3', '', 3, 0, 0, 10000, now(), 10000, now());
|
||||
INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (21, 8, '否', '0', '', 1, 0, 0, 10000,now(), 10000, now());
|
||||
INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (22, 8, '是', '1', '', 0, 0, 0, 10000, now(), 10000, now());
|
||||
INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (23, 9, '是', '1', '', 1, 0, 0, 10000, now(), 10000, now());
|
||||
INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (24, 9, '否', '0', '', 0, 0, 0, 10000, now(), 10000, now());
|
||||
|
||||
|
||||
INSERT INTO sys_params (param_name, param_type, param_key, param_value, remark, version, deleted, creator, create_time, updater, update_time) VALUES ('用户登录-验证码开关', 1, 'LOGIN_CAPTCHA', 'false', '是否开启验证码(true:开启,false:关闭)', 0, 0, 10000, now(), 10000, now());
|
||||
|
|
|
@ -93,4 +93,13 @@ public class SysDictTypeController {
|
|||
return Result.ok(dictList);
|
||||
}
|
||||
|
||||
@GetMapping("refreshTransCache")
|
||||
@Operation(summary = "刷新字典翻译缓存数据")
|
||||
@PreAuthorize("hasAuthority('sys:dict:refreshTransCache')")
|
||||
public Result<String> refreshTransCache() {
|
||||
sysDictTypeService.refreshTransCache();
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -34,4 +34,9 @@ public interface SysDictTypeService extends BaseService<SysDictTypeEntity> {
|
|||
*/
|
||||
List<SysDictVO> getDictList();
|
||||
|
||||
/**
|
||||
* 刷新字典缓存
|
||||
*/
|
||||
void refreshTransCache();
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fhs.trans.service.impl.DictionaryTransService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.maku.framework.common.exception.ServerException;
|
||||
import net.maku.framework.common.page.PageResult;
|
||||
|
@ -20,11 +21,16 @@ import net.maku.system.query.SysDictTypeQuery;
|
|||
import net.maku.system.service.SysDictTypeService;
|
||||
import net.maku.system.vo.SysDictTypeVO;
|
||||
import net.maku.system.vo.SysDictVO;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 字典类型
|
||||
|
@ -33,9 +39,11 @@ import java.util.List;
|
|||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeDao, SysDictTypeEntity> implements SysDictTypeService {
|
||||
public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeDao, SysDictTypeEntity> implements SysDictTypeService, InitializingBean {
|
||||
private final SysDictDataDao sysDictDataDao;
|
||||
|
||||
private final DictionaryTransService dictionaryTransService;
|
||||
|
||||
@Override
|
||||
public PageResult<SysDictTypeVO> page(SysDictTypeQuery query) {
|
||||
IPage<SysDictTypeEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||
|
@ -121,4 +129,28 @@ public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeDao, SysD
|
|||
return dictList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
refreshTransCache();
|
||||
}
|
||||
|
||||
public void refreshTransCache() {
|
||||
// 异步不阻塞主线程,不会 增加启动用时
|
||||
CompletableFuture.supplyAsync(() -> {
|
||||
//获取所有的字典项数据
|
||||
List<SysDictDataEntity> dataList = sysDictDataDao.selectList(new LambdaQueryWrapper<>());
|
||||
//根据类型分组
|
||||
Map<Long, List<SysDictDataEntity>> dictTypeDataMap = dataList.stream().collect(Collectors
|
||||
.groupingBy(SysDictDataEntity::getDictTypeId));
|
||||
List<SysDictTypeEntity> dictTypeEntities = super.list();
|
||||
List<SysDictDataEntity> tempDataEntityList;
|
||||
for (SysDictTypeEntity dictTypeEntity : dictTypeEntities) {
|
||||
if (dictTypeDataMap.containsKey(dictTypeEntity.getId())) {
|
||||
dictionaryTransService.refreshCache(dictTypeEntity.getDictType(), dictTypeDataMap.get(dictTypeEntity.getId())
|
||||
.stream().collect(Collectors.toMap(SysDictDataEntity::getDictValue, SysDictDataEntity::getDictLabel)));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fhs.trans.service.impl.TransService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import net.maku.framework.common.page.PageResult;
|
||||
|
@ -32,6 +33,8 @@ import java.util.List;
|
|||
@AllArgsConstructor
|
||||
public class SysLogLoginServiceImpl extends BaseServiceImpl<SysLogLoginDao, SysLogLoginEntity> implements SysLogLoginService {
|
||||
|
||||
private final TransService transService;
|
||||
|
||||
@Override
|
||||
public PageResult<SysLogLoginVO> page(SysLogLoginQuery query) {
|
||||
IPage<SysLogLoginEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||
|
@ -73,7 +76,7 @@ public class SysLogLoginServiceImpl extends BaseServiceImpl<SysLogLoginDao, SysL
|
|||
public void export() {
|
||||
List<SysLogLoginEntity> list = list();
|
||||
List<SysLogLoginVO> sysLogLoginVOS = SysLogLoginConvert.INSTANCE.convertList(list);
|
||||
|
||||
transService.transBatch(sysLogLoginVOS);
|
||||
// 写到浏览器打开
|
||||
ExcelUtils.excelExport(SysLogLoginVO.class, "system_login_log_excel" + DateUtils.format(new Date()), null, sysLogLoginVOS);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.maku.system.service.impl;
|
|||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fhs.trans.service.impl.TransService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import net.maku.framework.common.constant.Constant;
|
||||
|
@ -41,6 +42,7 @@ import java.util.Map;
|
|||
public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {
|
||||
private final SysUserRoleService sysUserRoleService;
|
||||
private final SysUserPostService sysUserPostService;
|
||||
private final TransService transService;
|
||||
|
||||
@Override
|
||||
public PageResult<SysUserVO> page(SysUserQuery query) {
|
||||
|
@ -184,6 +186,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
|||
}
|
||||
|
||||
private void saveUser(List<SysUserExcelVO> result) {
|
||||
ExcelUtils.parseDict(result);
|
||||
List<SysUserEntity> sysUserEntities = SysUserConvert.INSTANCE.convertListEntity(result);
|
||||
sysUserEntities.forEach(user -> user.setPassword(password));
|
||||
saveBatch(sysUserEntities);
|
||||
|
@ -197,7 +200,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
|||
public void export() {
|
||||
List<SysUserEntity> list = list(Wrappers.lambdaQuery(SysUserEntity.class).eq(SysUserEntity::getSuperAdmin, SuperAdminEnum.NO.getValue()));
|
||||
List<SysUserExcelVO> userExcelVOS = SysUserConvert.INSTANCE.convert2List(list);
|
||||
|
||||
transService.transBatch(userExcelVOS);
|
||||
// 写到浏览器打开
|
||||
ExcelUtils.excelExport(SysUserExcelVO.class, "system_user_excel" + DateUtils.format(new Date()), null, userExcelVOS);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ import com.alibaba.excel.metadata.GlobalConfiguration;
|
|||
import com.alibaba.excel.metadata.data.WriteCellData;
|
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fhs.core.trans.anno.Trans;
|
||||
import com.fhs.core.trans.constant.TransType;
|
||||
import com.fhs.core.trans.vo.TransPojo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import net.maku.framework.common.excel.DateConverter;
|
||||
|
@ -22,7 +25,7 @@ import java.util.Date;
|
|||
*/
|
||||
@Data
|
||||
@Schema(description = "登录日志")
|
||||
public class SysLogLoginVO implements Serializable {
|
||||
public class SysLogLoginVO implements Serializable, TransPojo {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ExcelIgnore
|
||||
|
@ -45,48 +48,25 @@ public class SysLogLoginVO implements Serializable {
|
|||
@Schema(description = "User Agent")
|
||||
private String userAgent;
|
||||
|
||||
@ExcelProperty(value = "登录状态", converter = StatusConverter.class)
|
||||
@ExcelIgnore
|
||||
@Trans(type = TransType.DICTIONARY, key = "success_fail", ref = "statusLabel")
|
||||
@Schema(description = "登录状态 0:失败 1:成功")
|
||||
private Integer status;
|
||||
|
||||
@ExcelProperty(value = "操作信息", converter = OperationConverter.class)
|
||||
@ExcelProperty(value = "登录状态")
|
||||
private String statusLabel;
|
||||
|
||||
@ExcelIgnore
|
||||
@Trans(type = TransType.DICTIONARY, key = "login_operation", ref = "operationLabel")
|
||||
@Schema(description = "操作信息 0:登录成功 1:退出成功 2:验证码错误 3:账号密码错误")
|
||||
private Integer operation;
|
||||
|
||||
@ExcelProperty(value = "操作信息")
|
||||
private String operationLabel;
|
||||
|
||||
@ExcelProperty(value = "创建时间", converter = DateConverter.class)
|
||||
@Schema(description = "创建时间")
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date createTime;
|
||||
|
||||
|
||||
public static class StatusConverter implements Converter<Integer> {
|
||||
@Override
|
||||
public WriteCellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||
String dateValue = "";
|
||||
if (value == 0) {
|
||||
dateValue = "失败";
|
||||
} else if (value == 1) {
|
||||
dateValue = "成功";
|
||||
}
|
||||
return new WriteCellData<>(dateValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static class OperationConverter implements Converter<Integer> {
|
||||
@Override
|
||||
public WriteCellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||
String dateValue = "";
|
||||
if (value == 0) {
|
||||
dateValue = "登录成功";
|
||||
} else if (value == 1) {
|
||||
dateValue = "退出成功";
|
||||
} else if (value == 2) {
|
||||
dateValue = "验证码错误";
|
||||
} else if (value == 3) {
|
||||
dateValue = "账号密码错误";
|
||||
}
|
||||
return new WriteCellData<>(dateValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,15 @@
|
|||
package net.maku.system.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.converters.Converter;
|
||||
import com.alibaba.excel.metadata.GlobalConfiguration;
|
||||
import com.alibaba.excel.metadata.data.ReadCellData;
|
||||
import com.alibaba.excel.metadata.data.WriteCellData;
|
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||
import com.fhs.core.trans.anno.Trans;
|
||||
import com.fhs.core.trans.constant.TransType;
|
||||
import com.fhs.core.trans.vo.TransPojo;
|
||||
import lombok.Data;
|
||||
import net.maku.framework.common.excel.DateConverter;
|
||||
import net.maku.framework.common.utils.DateUtils;
|
||||
|
@ -22,18 +26,28 @@ import java.util.Date;
|
|||
* @author 阿沐 babamu@126.com
|
||||
*/
|
||||
@Data
|
||||
public class SysUserExcelVO implements Serializable {
|
||||
public class SysUserExcelVO implements Serializable, TransPojo {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 本属性对于导出无用,只是用于翻译
|
||||
*/
|
||||
@ExcelIgnore
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("用户名")
|
||||
private String username;
|
||||
|
||||
@ExcelProperty("姓名")
|
||||
private String realName;
|
||||
|
||||
@ExcelProperty(value = "性别", converter = GenderConverter.class)
|
||||
@ExcelIgnore
|
||||
@Trans(type = TransType.DICTIONARY, key = "user_gender", ref = "genderLabel")
|
||||
private Integer gender;
|
||||
|
||||
@ExcelProperty(value = "性别")
|
||||
private String genderLabel;
|
||||
|
||||
@ExcelProperty("邮箱")
|
||||
private String email;
|
||||
|
||||
|
@ -43,54 +57,21 @@ public class SysUserExcelVO implements Serializable {
|
|||
@ExcelProperty("机构ID")
|
||||
private Long orgId;
|
||||
|
||||
@ExcelProperty(value = "状态", converter = StatusConverter.class)
|
||||
@ExcelIgnore
|
||||
@Trans(type = TransType.DICTIONARY, key = "user_status", ref = "statusLabel")
|
||||
private Integer status;
|
||||
|
||||
@ExcelProperty(value = "超级管理员", converter = SuperConverter.class)
|
||||
@ExcelProperty(value = "状态")
|
||||
private String statusLabel;
|
||||
|
||||
@ExcelIgnore
|
||||
@Trans(type = TransType.DICTIONARY, key = "user_super_admin", ref = "superAdminLabel")
|
||||
private Integer superAdmin;
|
||||
|
||||
@ExcelProperty(value = "超级管理员")
|
||||
private String superAdminLabel;
|
||||
|
||||
@ExcelProperty(value = "创建时间", converter = DateConverter.class)
|
||||
private Date createTime;
|
||||
|
||||
public static class GenderConverter implements Converter<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||
String dateString = cellData.getStringValue();
|
||||
return UserGenderEnum.getValueByName(dateString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WriteCellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||
return new WriteCellData<>(UserGenderEnum.getNameByValue(value));
|
||||
}
|
||||
}
|
||||
|
||||
public static class StatusConverter implements Converter<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||
String dateString = cellData.getStringValue();
|
||||
return UserStatusEnum.getValueByName(dateString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WriteCellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||
return new WriteCellData<>(UserStatusEnum.getNameByValue(value));
|
||||
}
|
||||
}
|
||||
|
||||
public static class SuperConverter implements Converter<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||
String dateString = cellData.getStringValue();
|
||||
return SuperAdminEnum.getValueByName(dateString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WriteCellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||
return new WriteCellData<>(SuperAdminEnum.getNameByValue(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,5 +64,13 @@
|
|||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fhs-opensource</groupId>
|
||||
<artifactId>easy-trans-mybatis-plus-extend</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fhs-opensource</groupId>
|
||||
<artifactId>easy-trans-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -3,6 +3,14 @@ package net.maku.framework.common.utils;
|
|||
import cn.hutool.core.util.URLUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
import com.fhs.common.spring.SpringContextUtil;
|
||||
import com.fhs.common.utils.ConverterUtils;
|
||||
import com.fhs.core.trans.anno.Trans;
|
||||
import com.fhs.core.trans.constant.TransType;
|
||||
import com.fhs.core.trans.util.ReflectUtils;
|
||||
import com.fhs.core.trans.vo.TransPojo;
|
||||
import com.fhs.trans.service.impl.DictionaryTransService;
|
||||
import lombok.SneakyThrows;
|
||||
import net.maku.framework.common.excel.ExcelDataListener;
|
||||
import net.maku.framework.common.excel.ExcelFinishCallBack;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -12,7 +20,9 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Excel utils.
|
||||
|
@ -137,4 +147,51 @@ public class ExcelUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析字典数据到字段上
|
||||
* 比如 T中有 genderLabel字段 为男 需要给 gender 字段自动设置为0
|
||||
*
|
||||
* @param datas 需要被反向解析的数据
|
||||
* @param <T>
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static <T extends TransPojo> void parseDict(List<T> datas) {
|
||||
//没有数据就不需要初始化
|
||||
if (datas == null || datas.isEmpty() || datas.get(0) == null) {
|
||||
return;
|
||||
}
|
||||
Class clazz = datas.get(0).getClass();
|
||||
//拿到所有需要反向翻译的字段
|
||||
List<Field> fields = ReflectUtils.getAnnotationField(clazz, Trans.class);
|
||||
//过滤出字典翻译
|
||||
fields = fields.stream().filter(field -> {
|
||||
return TransType.DICTIONARY.equals(field.getAnnotation(Trans.class).type());
|
||||
}).collect(Collectors.toList());
|
||||
DictionaryTransService dictionaryTransService = SpringContextUtil.getBeanByClass(DictionaryTransService.class);
|
||||
for (T data : datas) {
|
||||
for (Field field : fields) {
|
||||
Trans trans = field.getAnnotation(Trans.class);
|
||||
//key不能为空并且ref不为空的才自动处理
|
||||
if (!StringUtils.isBlank(trans.key()) && !StringUtils.isBlank(trans.ref())) {
|
||||
Field ref = ReflectUtils.getDeclaredField(clazz, trans.ref());
|
||||
ref.setAccessible(true);
|
||||
//获取字典反向值
|
||||
String value = dictionaryTransService.getUnTransMap().get(trans.key() + "_" + ref.get(data));
|
||||
if (StringUtils.isBlank(value)) {
|
||||
continue;
|
||||
}
|
||||
//一般目标字段是int或者string字段 后面有添加单独抽离方法
|
||||
if(Integer.class.equals(field.getType())){
|
||||
field.setAccessible(true);
|
||||
field.set(data,ConverterUtils.toInteger(value));
|
||||
}else{
|
||||
field.setAccessible(true);
|
||||
field.set(data,ConverterUtils.toString(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,4 +61,13 @@ mybatis-plus:
|
|||
configuration-properties:
|
||||
prefix:
|
||||
blobType: BLOB
|
||||
boolValue: TRUE
|
||||
boolValue: TRUE
|
||||
|
||||
#easy trans 数据翻译组件
|
||||
easy-trans:
|
||||
#启用redis缓存 如果不用redis请设置为false
|
||||
is-enable-redis: false
|
||||
#启用全局翻译(拦截所有responseBody进行自动翻译),如果对于性能要求很高可关闭此配置
|
||||
is-enable-global: true
|
||||
#启用平铺模式
|
||||
is-enable-tile: true
|
11
pom.xml
11
pom.xml
|
@ -46,6 +46,7 @@
|
|||
<qcloud.cos.version>5.6.89</qcloud.cos.version>
|
||||
<huaweicloud.obs.version>3.22.3</huaweicloud.obs.version>
|
||||
<easyexcel.version>3.1.1</easyexcel.version>
|
||||
<easytrans.version>2.0.11</easytrans.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -155,6 +156,16 @@
|
|||
<artifactId>easyexcel</artifactId>
|
||||
<version>${easyexcel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fhs-opensource</groupId>
|
||||
<artifactId>easy-trans-spring-boot-starter</artifactId>
|
||||
<version>${easytrans.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fhs-opensource</groupId>
|
||||
<artifactId>easy-trans-mybatis-plus-extend</artifactId>
|
||||
<version>${easytrans.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user