|
@@ -14,18 +14,18 @@ import org.jeecg.common.api.CommonAPI;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.aspect.annotation.Dict;
|
|
|
import org.jeecg.common.constant.CommonConstant;
|
|
|
-import org.jeecg.modules.base.service.BaseCommonService;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 字典aop类
|
|
|
* @Author: dangzhenghui
|
|
@@ -36,20 +36,19 @@ import java.util.List;
|
|
|
@Component
|
|
|
@Slf4j
|
|
|
public class DictAspect {
|
|
|
-
|
|
|
@Autowired
|
|
|
private CommonAPI commonAPI;
|
|
|
- @Autowired
|
|
|
- public RedisTemplate redisTemplate;
|
|
|
|
|
|
- // 定义切点Pointcut
|
|
|
- @Pointcut("execution(public * org.jeecg.modules..*.*Controller.*(..))")
|
|
|
+ /**
|
|
|
+ * 定义切点Pointcut
|
|
|
+ */
|
|
|
+ @Pointcut("execution(public * org.jeecg.modules..*.*Controller.*(..))||execution(public * cn.com.ctop..*.*Controller.*(..))")
|
|
|
public void excudeService() {
|
|
|
}
|
|
|
|
|
|
@Around("excudeService()")
|
|
|
public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
|
|
|
- long time1=System.currentTimeMillis();
|
|
|
+ long time1 = System.currentTimeMillis();
|
|
|
Object result = pjp.proceed();
|
|
|
long time2=System.currentTimeMillis();
|
|
|
log.debug("获取JSON数据 耗时:"+(time2-time1)+"ms");
|
|
@@ -104,17 +103,24 @@ public class DictAspect {
|
|
|
String code = field.getAnnotation(Dict.class).dicCode();
|
|
|
String text = field.getAnnotation(Dict.class).dicText();
|
|
|
String table = field.getAnnotation(Dict.class).dictTable();
|
|
|
+ String extendsKey = field.getAnnotation(Dict.class).extendsKey();
|
|
|
+ if("".equals(extendsKey.trim())){
|
|
|
+ extendsKey = null;
|
|
|
+ }
|
|
|
+ String extendsValue = field.getAnnotation(Dict.class).extendsValue();
|
|
|
+ if("".equals(extendsValue.trim())){
|
|
|
+ extendsValue = null;
|
|
|
+ }
|
|
|
String key = String.valueOf(item.get(field.getName()));
|
|
|
-
|
|
|
//翻译字典值对应的txt
|
|
|
- String textValue = translateDictValue(code, text, table, key);
|
|
|
+ String textValue = translateDictValue(code, text, table, key,extendsKey,extendsValue);
|
|
|
|
|
|
log.debug(" 字典Val : "+ textValue);
|
|
|
log.debug(" __翻译字典字段__ "+field.getName() + CommonConstant.DICT_TEXT_SUFFIX+": "+ textValue);
|
|
|
item.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);
|
|
|
}
|
|
|
//date类型默认转换string格式化日期
|
|
|
- if (field.getType().getName().equals("java.util.Date")&&field.getAnnotation(JsonFormat.class)==null&&item.get(field.getName())!=null){
|
|
|
+ if ("java.util.Date".equals(field.getType().getName()) && field.getAnnotation(JsonFormat.class) == null && item.get(field.getName()) != null) {
|
|
|
SimpleDateFormat aDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName()))));
|
|
|
}
|
|
@@ -135,7 +141,7 @@ public class DictAspect {
|
|
|
* @param key
|
|
|
* @return
|
|
|
*/
|
|
|
- private String translateDictValue(String code, String text, String table, String key) {
|
|
|
+ private String translateDictValue(String code, String text, String table, String key,String extendsKey,String extendsValue) {
|
|
|
if(oConvertUtils.isEmpty(key)) {
|
|
|
return null;
|
|
|
}
|
|
@@ -147,32 +153,11 @@ public class DictAspect {
|
|
|
if (k.trim().length() == 0) {
|
|
|
continue; //跳过循环
|
|
|
}
|
|
|
- //update-begin--Author:scott -- Date:20210531 ----for: !56 优化微服务应用下存在表字段需要字典翻译时加载缓慢问题-----
|
|
|
if (!StringUtils.isEmpty(table)){
|
|
|
- log.info("--DictAspect------dicTable="+ table+" ,dicText= "+text+" ,dicCode="+code);
|
|
|
- String keyString = String.format("sys:cache:dictTable::SimpleKey [%s,%s,%s,%s]",table,text,code,k.trim());
|
|
|
- if (redisTemplate.hasKey(keyString)){
|
|
|
- try {
|
|
|
- tmpValue = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString));
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn(e.getMessage());
|
|
|
- }
|
|
|
- }else {
|
|
|
- tmpValue= commonAPI.translateDictFromTable(table,text,code,k.trim());
|
|
|
- }
|
|
|
+ tmpValue= commonAPI.translateDictFromTable(table,text,code,k.trim(),extendsKey,extendsValue);
|
|
|
}else {
|
|
|
- String keyString = String.format("sys:cache:dict::%s:%s",code,k.trim());
|
|
|
- if (redisTemplate.hasKey(keyString)){
|
|
|
- try {
|
|
|
- tmpValue = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString));
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn(e.getMessage());
|
|
|
- }
|
|
|
- }else {
|
|
|
- tmpValue = commonAPI.translateDict(code, k.trim());
|
|
|
- }
|
|
|
+ tmpValue = commonAPI.translateDict(code, k.trim(),extendsKey,extendsValue);
|
|
|
}
|
|
|
- //update-end--Author:scott -- Date:20210531 ----for: !56 优化微服务应用下存在表字段需要字典翻译时加载缓慢问题-----
|
|
|
|
|
|
if (tmpValue != null) {
|
|
|
if (!"".equals(textValue.toString())) {
|
|
@@ -184,5 +169,4 @@ public class DictAspect {
|
|
|
}
|
|
|
return textValue.toString();
|
|
|
}
|
|
|
-
|
|
|
}
|