|
@@ -13,6 +13,7 @@ import org.aspectj.lang.annotation.Pointcut;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.aspect.annotation.Dict;
|
|
import org.jeecg.common.aspect.annotation.Dict;
|
|
|
import org.jeecg.common.constant.CommonConstant;
|
|
import org.jeecg.common.constant.CommonConstant;
|
|
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.system.service.ISysDictService;
|
|
import org.jeecg.modules.system.service.ISysDictService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -39,6 +40,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
public class DictAspect {
|
|
public class DictAspect {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ISysDictService dictService;
|
|
private ISysDictService dictService;
|
|
|
|
|
+
|
|
|
// 定义切点Pointcut
|
|
// 定义切点Pointcut
|
|
|
@Pointcut("execution(public * org.jeecg.modules..*.*Controller.*(..))")
|
|
@Pointcut("execution(public * org.jeecg.modules..*.*Controller.*(..))")
|
|
|
public void excudeService() {
|
|
public void excudeService() {
|
|
@@ -46,14 +48,14 @@ public class DictAspect {
|
|
|
|
|
|
|
|
@Around("excudeService()")
|
|
@Around("excudeService()")
|
|
|
public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
|
|
public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
|
|
|
- long time1=System.currentTimeMillis();
|
|
|
|
|
|
|
+ long time1 = System.currentTimeMillis();
|
|
|
Object result = pjp.proceed();
|
|
Object result = pjp.proceed();
|
|
|
- long time2=System.currentTimeMillis();
|
|
|
|
|
- log.debug("获取JSON数据 耗时:"+(time2-time1)+"ms");
|
|
|
|
|
- long start=System.currentTimeMillis();
|
|
|
|
|
|
|
+ long time2 = System.currentTimeMillis();
|
|
|
|
|
+ log.debug("获取JSON数据 耗时:" + (time2 - time1) + "ms");
|
|
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
this.parseDictText(result);
|
|
this.parseDictText(result);
|
|
|
- long end=System.currentTimeMillis();
|
|
|
|
|
- log.debug("解析注入JSON数据 耗时"+(end-start)+"ms");
|
|
|
|
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
|
|
+ log.debug("解析注入JSON数据 耗时" + (end - start) + "ms");
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -63,20 +65,21 @@ public class DictAspect {
|
|
|
* 示例为SysUser 字段为sex 添加了注解@Dict(dicCode = "sex") 会在字典服务立马查出来对应的text 然后在请求list的时候将这个字典text,已字段名称加_dictText形式返回到前端
|
|
* 示例为SysUser 字段为sex 添加了注解@Dict(dicCode = "sex") 会在字典服务立马查出来对应的text 然后在请求list的时候将这个字典text,已字段名称加_dictText形式返回到前端
|
|
|
* 例输入当前返回值的就会多出一个sex_dictText字段
|
|
* 例输入当前返回值的就会多出一个sex_dictText字段
|
|
|
* {
|
|
* {
|
|
|
- * sex:1,
|
|
|
|
|
- * sex_dictText:"男"
|
|
|
|
|
|
|
+ * sex:1,
|
|
|
|
|
+ * sex_dictText:"男"
|
|
|
* }
|
|
* }
|
|
|
* 前端直接取值sext_dictText在table里面无需再进行前端的字典转换了
|
|
* 前端直接取值sext_dictText在table里面无需再进行前端的字典转换了
|
|
|
- * customRender:function (text) {
|
|
|
|
|
- * if(text==1){
|
|
|
|
|
- * return "男";
|
|
|
|
|
- * }else if(text==2){
|
|
|
|
|
- * return "女";
|
|
|
|
|
- * }else{
|
|
|
|
|
- * return text;
|
|
|
|
|
- * }
|
|
|
|
|
- * }
|
|
|
|
|
- * 目前vue是这么进行字典渲染到table上的多了就很麻烦了 这个直接在服务端渲染完成前端可以直接用
|
|
|
|
|
|
|
+ * customRender:function (text) {
|
|
|
|
|
+ * if(text==1){
|
|
|
|
|
+ * return "男";
|
|
|
|
|
+ * }else if(text==2){
|
|
|
|
|
+ * return "女";
|
|
|
|
|
+ * }else{
|
|
|
|
|
+ * return text;
|
|
|
|
|
+ * }
|
|
|
|
|
+ * }
|
|
|
|
|
+ * 目前vue是这么进行字典渲染到table上的多了就很麻烦了 这个直接在服务端渲染完成前端可以直接用
|
|
|
|
|
+ *
|
|
|
* @param result
|
|
* @param result
|
|
|
*/
|
|
*/
|
|
|
private void parseDictText(Object result) {
|
|
private void parseDictText(Object result) {
|
|
@@ -85,18 +88,18 @@ public class DictAspect {
|
|
|
List<JSONObject> items = new ArrayList<>();
|
|
List<JSONObject> items = new ArrayList<>();
|
|
|
for (Object record : ((IPage) ((Result) result).getResult()).getRecords()) {
|
|
for (Object record : ((IPage) ((Result) result).getResult()).getRecords()) {
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
- String json="{}";
|
|
|
|
|
|
|
+ String json = "{}";
|
|
|
try {
|
|
try {
|
|
|
//解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat
|
|
//解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat
|
|
|
- json = mapper.writeValueAsString(record);
|
|
|
|
|
|
|
+ json = mapper.writeValueAsString(record);
|
|
|
} catch (JsonProcessingException e) {
|
|
} catch (JsonProcessingException e) {
|
|
|
- log.error("json解析失败"+e.getMessage(),e);
|
|
|
|
|
|
|
+ log.error("json解析失败" + e.getMessage(), e);
|
|
|
}
|
|
}
|
|
|
JSONObject item = JSONObject.parseObject(json);
|
|
JSONObject item = JSONObject.parseObject(json);
|
|
|
//update-begin--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------
|
|
//update-begin--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------
|
|
|
//for (Field field : record.getClass().getDeclaredFields()) {
|
|
//for (Field field : record.getClass().getDeclaredFields()) {
|
|
|
for (Field field : oConvertUtils.getAllFields(record)) {
|
|
for (Field field : oConvertUtils.getAllFields(record)) {
|
|
|
- //update-end--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------
|
|
|
|
|
|
|
+ //update-end--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------
|
|
|
if (field.getAnnotation(Dict.class) != null) {
|
|
if (field.getAnnotation(Dict.class) != null) {
|
|
|
String code = field.getAnnotation(Dict.class).dicCode();
|
|
String code = field.getAnnotation(Dict.class).dicCode();
|
|
|
String text = field.getAnnotation(Dict.class).dicText();
|
|
String text = field.getAnnotation(Dict.class).dicText();
|
|
@@ -106,14 +109,13 @@ public class DictAspect {
|
|
|
//翻译字典值对应的txt
|
|
//翻译字典值对应的txt
|
|
|
String textValue = translateDictValue(code, text, table, key);
|
|
String textValue = translateDictValue(code, text, table, key);
|
|
|
|
|
|
|
|
- log.debug(" 字典Val : "+ textValue);
|
|
|
|
|
- log.debug(" __翻译字典字段__ "+field.getName() + CommonConstant.DICT_TEXT_SUFFIX+": "+ textValue);
|
|
|
|
|
|
|
+ log.debug(" 字典Val : " + textValue);
|
|
|
|
|
+ log.debug(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + ": " + textValue);
|
|
|
item.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);
|
|
item.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);
|
|
|
}
|
|
}
|
|
|
//date类型默认转换string格式化日期
|
|
//date类型默认转换string格式化日期
|
|
|
- if (field.getType().getName().equals("java.util.Date")&&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()))));
|
|
|
|
|
|
|
+ if (field.getType().getName().equals("java.util.Date") && field.getAnnotation(JsonFormat.class) == null && item.get(field.getName()) != null) {
|
|
|
|
|
+ item.put(field.getName(), DateUtils.datetimeFormat.get().format(new Date((Long) item.get(field.getName()))));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
items.add(item);
|
|
items.add(item);
|
|
@@ -125,7 +127,8 @@ public class DictAspect {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 翻译字典文本
|
|
|
|
|
|
|
+ * 翻译字典文本
|
|
|
|
|
+ *
|
|
|
* @param code
|
|
* @param code
|
|
|
* @param text
|
|
* @param text
|
|
|
* @param table
|
|
* @param table
|
|
@@ -133,20 +136,20 @@ public class DictAspect {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
private String translateDictValue(String code, String text, String table, String key) {
|
|
private String translateDictValue(String code, String text, String table, String key) {
|
|
|
- if(oConvertUtils.isEmpty(key)) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- StringBuffer textValue=new StringBuffer();
|
|
|
|
|
|
|
+ if (oConvertUtils.isEmpty(key)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ StringBuffer textValue = new StringBuffer();
|
|
|
String[] keys = key.split(",");
|
|
String[] keys = key.split(",");
|
|
|
for (String k : keys) {
|
|
for (String k : keys) {
|
|
|
String tmpValue = null;
|
|
String tmpValue = null;
|
|
|
- log.debug(" 字典 key : "+ k);
|
|
|
|
|
|
|
+ log.debug(" 字典 key : " + k);
|
|
|
if (k.trim().length() == 0) {
|
|
if (k.trim().length() == 0) {
|
|
|
continue; //跳过循环
|
|
continue; //跳过循环
|
|
|
}
|
|
}
|
|
|
- if (!StringUtils.isEmpty(table)){
|
|
|
|
|
- tmpValue= dictService.queryTableDictTextByKey(table,text,code,k.trim());
|
|
|
|
|
- }else {
|
|
|
|
|
|
|
+ if (!StringUtils.isEmpty(table)) {
|
|
|
|
|
+ tmpValue = dictService.queryTableDictTextByKey(table, text, code, k.trim());
|
|
|
|
|
+ } else {
|
|
|
tmpValue = dictService.queryDictTextByKey(code, k.trim());
|
|
tmpValue = dictService.queryDictTextByKey(code, k.trim());
|
|
|
}
|
|
}
|
|
|
|
|
|