禅道BUG修改。

This commit is contained in:
wangzhijiang
2024-03-06 15:33:58 +08:00
parent 001b40a0e6
commit 42373d931e
5 changed files with 503 additions and 466 deletions
@@ -42,466 +42,466 @@ import java.util.stream.Collectors;
@Component @Component
@Slf4j @Slf4j
public class DictAspect { public class DictAspect {
//
@Autowired // @Autowired
private CommonAPI commonAPI; // private CommonAPI commonAPI;
@Autowired // @Autowired
public RedisTemplate<String,Object> redisTemplate; // public RedisTemplate<String,Object> redisTemplate;
//
private static final String SYS_CACHE_DICT_S_S = "sys:cache:dict::%s:%s"; // private static final String SYS_CACHE_DICT_S_S = "sys:cache:dict::%s:%s";
//
// 定义切点Pointcut // // 定义切点Pointcut
@Pointcut("execution(public * com.jero.modules..*.*Controller.*(..))") // @Pointcut("execution(public * com.jero.modules..*.*Controller.*(..))")
public void excudeService() { // public void excudeService() {
// do other // // do other
} // }
@Pointcut("@annotation(com.jero.common.aspect.annotation.DictPoint)") // @Pointcut("@annotation(com.jero.common.aspect.annotation.DictPoint)")
public void dictPointCut() { // public void dictPointCut() {
} // }
//
@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(); // long time2=System.currentTimeMillis();
log.debug("获取JSON数据 耗时:"+(time2-time1)+"ms"); // log.debug("获取JSON数据 耗时:"+(time2-time1)+"ms");
long start=System.currentTimeMillis(); // long start=System.currentTimeMillis();
this.parseDictText(result); // this.parseDictText(result);
long end=System.currentTimeMillis(); // long end=System.currentTimeMillis();
log.debug("注入字典到JSON数据 耗时"+(end-start)+"ms"); // log.debug("注入字典到JSON数据 耗时"+(end-start)+"ms");
return result; // return result;
} // }
//
@Around("dictPointCut()") // @Around("dictPointCut()")
public Object arround(ProceedingJoinPoint point) throws Throwable { // public Object arround(ProceedingJoinPoint point) throws Throwable {
long time1 = System.currentTimeMillis(); // long time1 = System.currentTimeMillis();
Object result = point.proceed(); // Object result = point.proceed();
long time2 = System.currentTimeMillis(); // long time2 = System.currentTimeMillis();
log.debug("获取JSON数据 耗时:" + (time2 - time1) + "ms"); // log.debug("获取JSON数据 耗时:" + (time2 - time1) + "ms");
long start = System.currentTimeMillis(); // long start = System.currentTimeMillis();
this.parseMethodDictText(result); // this.parseMethodDictText(result);
long end = System.currentTimeMillis(); // long end = System.currentTimeMillis();
log.debug("解析注入JSON数据 耗时" + (end - start) + "ms"); // log.debug("解析注入JSON数据 耗时" + (end - start) + "ms");
return result; // return result;
} // }
//
/** // /**
* 本方法针对返回对象为Result 的IPage的分页列表数据进行动态字典注入 // * 本方法针对返回对象为Result 的IPage的分页列表数据进行动态字典注入
* 字典注入实现 通过对实体类添加注解@dict 来标识需要的字典内容,字典分为单字典code即可 table字典 code table text配合使用与原来jero的用法相同 // * 字典注入实现 通过对实体类添加注解@dict 来标识需要的字典内容,字典分为单字典code即可 table字典 code table text配合使用与原来jero的用法相同
* 示例为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:1,
* sex_dictText:"男" // * sex_dictText:"男"
* } // * }
* 前端直接取值sext_dictText在table里面无需再进行前端的字典转换了 // * 前端直接取值sext_dictText在table里面无需再进行前端的字典转换了
* customRender:function (text) { // * customRender:function (text) {
* if(text==1){ // * if(text==1){
* return "男"; // * return "男";
* }else if(text==2){ // * }else if(text==2){
* return "女"; // * return "女";
* }else{ // * }else{
* return text; // * return text;
* } // * }
* } // * }
* 目前vue是这么进行字典渲染到table上的多了就很麻烦了 这个直接在服务端渲染完成前端可以直接用 // * 目前vue是这么进行字典渲染到table上的多了就很麻烦了 这个直接在服务端渲染完成前端可以直接用
* @param result // * @param result
*/ // */
private void parseDictText(Object result) { // private void parseDictText(Object result) {
if (result instanceof Result && ((Result) result).getResult() instanceof IPage) { // if (result instanceof Result && ((Result) result).getResult() instanceof IPage) {
List<JSONObject> items = new ArrayList<>(); // List<JSONObject> items = new ArrayList<>();
//
//step.1 筛选出加了 Dict 注解的字段列表 // //step.1 筛选出加了 Dict 注解的字段列表
List<Field> dictFieldList = new ArrayList<>(); // List<Field> dictFieldList = new ArrayList<>();
// 字典数据列表, key = 字典code,value=数据列表 // // 字典数据列表, key = 字典code,value=数据列表
Map<String, List<String>> dataListMap = new HashMap<>(); // Map<String, List<String>> dataListMap = new HashMap<>();
//
addItems((Result) result, items, dictFieldList, dataListMap); // addItems((Result) result, items, dictFieldList, dataListMap);
//
//step.2 调用翻译方法,一次性翻译 // //step.2 调用翻译方法,一次性翻译
Map<String, List<DictModel>> translText = this.translateAllDict(dataListMap); // Map<String, List<DictModel>> translText = this.translateAllDict(dataListMap);
//
//step.3 将翻译结果填充到返回结果里 // //step.3 将翻译结果填充到返回结果里
putItems(items, dictFieldList, translText); // putItems(items, dictFieldList, translText);
//
((IPage) ((Result) result).getResult()).setRecords(items); // ((IPage) ((Result) result).getResult()).setRecords(items);
} // }
} // }
//
private void putItems(List<JSONObject> items, List<Field> dictFieldList, Map<String, List<DictModel>> translText) { // private void putItems(List<JSONObject> items, List<Field> dictFieldList, Map<String, List<DictModel>> translText) {
for (JSONObject obj : items) { // for (JSONObject obj : items) {
for (Field field : dictFieldList) { // for (Field field : dictFieldList) {
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();
String table = field.getAnnotation(Dict.class).dictTable(); // String table = field.getAnnotation(Dict.class).dictTable();
//
String fieldDictCode = code; // String fieldDictCode = code;
if (!StringUtils.isEmpty(table)) { // if (!StringUtils.isEmpty(table)) {
fieldDictCode = String.format("%s,%s,%s", table, text, code); // fieldDictCode = String.format("%s,%s,%s", table, text, code);
} // }
//
String value = obj.getString(field.getName()); // String value = obj.getString(field.getName());
if (oConvertUtils.isNotEmpty(value)) { // if (oConvertUtils.isNotEmpty(value)) {
List<DictModel> dictModels = translText.get(fieldDictCode); // List<DictModel> dictModels = translText.get(fieldDictCode);
if(dictModels==null || dictModels.isEmpty()){ // if(dictModels==null || dictModels.isEmpty()){
continue; // continue;
} // }
//
String textValue = this.translDictText(dictModels, value); // String textValue = this.translDictText(dictModels, value);
log.debug(" 字典Val : " + textValue); // log.debug(" 字典Val : " + textValue);
log.debug(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + " " + textValue); // log.debug(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + " " + textValue);
//
// TODO-sun 测试输出,待删 // // TODO-sun 测试输出,待删
log.debug(" ---- dictCode: " + fieldDictCode); // log.debug(" ---- dictCode: " + fieldDictCode);
log.debug(" ---- value: " + value); // log.debug(" ---- value: " + value);
log.debug(" ----- text: " + textValue); // log.debug(" ----- text: " + textValue);
log.debug(" ---- dictModels: " + JSON.toJSONString(dictModels)); // log.debug(" ---- dictModels: " + JSON.toJSONString(dictModels));
//
obj.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue); // obj.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);
} // }
} // }
} // }
} // }
//
private void addItems(Result<IPage<T>> result, List<JSONObject> items, List<Field> dictFieldList, Map<String, List<String>> dataListMap) { // private void addItems(Result<IPage<T>> result, List<JSONObject> items, List<Field> dictFieldList, Map<String, List<String>> dataListMap) {
for (Object obj : result.getResult().getRecords()) { // for (Object obj : 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(obj); // json = mapper.writeValueAsString(obj);
} catch (JsonProcessingException e) { // } catch (JsonProcessingException e) {
log.error("json解析失败"+e.getMessage(),e); // log.error("json解析失败"+e.getMessage(),e);
} // }
JSONObject item = JSON.parseObject(json,Feature.OrderedField); // JSONObject item = JSON.parseObject(json,Feature.OrderedField);
//update-begin--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------ // //update-begin--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------
// 遍历所有字段,把字典Code取出来,放到 map 里 // // 遍历所有字段,把字典Code取出来,放到 map 里
putItem(dictFieldList, dataListMap, obj, item); // putItem(dictFieldList, dataListMap, obj, item);
items.add(item); // items.add(item);
} // }
} // }
//
private void putItem(List<Field> dictFieldList, Map<String, List<String>> dataListMap, Object obj, JSONObject item) { // private void putItem(List<Field> dictFieldList, Map<String, List<String>> dataListMap, Object obj, JSONObject item) {
for (Field field : oConvertUtils.getAllFields(obj)) { // for (Field field : oConvertUtils.getAllFields(obj)) {
String value = item.getString(field.getName()); // String value = item.getString(field.getName());
if (oConvertUtils.isEmpty(value)) { // if (oConvertUtils.isEmpty(value)) {
continue; // continue;
} // }
//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) {
if (!dictFieldList.contains(field)) { // if (!dictFieldList.contains(field)) {
dictFieldList.add(field); // dictFieldList.add(field);
} // }
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();
String table = field.getAnnotation(Dict.class).dictTable(); // String table = field.getAnnotation(Dict.class).dictTable();
//
List<String> dataList; // List<String> dataList;
String dictCode = code; // String dictCode = code;
if (!StringUtils.isEmpty(table)) { // if (!StringUtils.isEmpty(table)) {
dictCode = String.format("%s,%s,%s", table, text, code); // dictCode = String.format("%s,%s,%s", table, text, code);
} // }
dataList = dataListMap.computeIfAbsent(dictCode, k -> new ArrayList<>()); // dataList = dataListMap.computeIfAbsent(dictCode, k -> new ArrayList<>());
this.listAddAllDeduplicate(dataList, Arrays.asList(value.split(","))); // this.listAddAllDeduplicate(dataList, Arrays.asList(value.split(",")));
} // }
//date类型默认转换string格式化日期 // //date类型默认转换string格式化日期
if (Date.class.isAssignableFrom(field.getType()) && field.getAnnotation(JsonFormat.class) == null && item.get(field.getName()) != null){ // if (Date.class.isAssignableFrom(field.getType()) && field.getAnnotation(JsonFormat.class) == null && item.get(field.getName()) != null){
SimpleDateFormat aDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // SimpleDateFormat aDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName())))); // item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName()))));
} // }
} // }
} // }
//
/** // /**
* list 去重添加 // * list 去重添加
*/ // */
private void listAddAllDeduplicate(List<String> dataList, List<String> addList) { // private void listAddAllDeduplicate(List<String> dataList, List<String> addList) {
// 筛选出dataList中没有的数据 // // 筛选出dataList中没有的数据
List<String> filterList = addList.stream().filter(i -> !dataList.contains(i)).collect(Collectors.toList()); // List<String> filterList = addList.stream().filter(i -> !dataList.contains(i)).collect(Collectors.toList());
dataList.addAll(filterList); // dataList.addAll(filterList);
} // }
//
/** // /**
* 一次性把所有的字典都翻译了 // * 一次性把所有的字典都翻译了
* 1. 所有的普通数据字典的所有数据只执行一次SQL // * 1. 所有的普通数据字典的所有数据只执行一次SQL
* 2. 表字典相同的所有数据只执行一次SQL // * 2. 表字典相同的所有数据只执行一次SQL
* @param dataListMap // * @param dataListMap
* @return // * @return
*/ // */
private Map<String, List<DictModel>> translateAllDict(Map<String, List<String>> dataListMap) { // private Map<String, List<DictModel>> translateAllDict(Map<String, List<String>> dataListMap) {
// 翻译后的字典文本,key=dictCode // // 翻译后的字典文本,key=dictCode
Map<String, List<DictModel>> translText = new HashMap<>(); // Map<String, List<DictModel>> translText = new HashMap<>();
// 需要翻译的数据(有些可以从redis缓存中获取,就不走数据库查询) // // 需要翻译的数据(有些可以从redis缓存中获取,就不走数据库查询)
List<String> needTranslData = new ArrayList<>(); // List<String> needTranslData = new ArrayList<>();
//step.1 先通过redis中获取缓存字典数据 // //step.1 先通过redis中获取缓存字典数据
for (Map.Entry<String, List<String>> entry : dataListMap.entrySet()) { // for (Map.Entry<String, List<String>> entry : dataListMap.entrySet()) {
String dictCode = entry.getKey(); // String dictCode = entry.getKey();
List<String> dataList = entry.getValue(); // List<String> dataList = entry.getValue();
if (dataList.isEmpty()) { // if (dataList.isEmpty()) {
continue; // continue;
} // }
// 表字典需要翻译的数据 // // 表字典需要翻译的数据
List<String> needTranslDataTable = new ArrayList<>(); // List<String> needTranslDataTable = new ArrayList<>();
addNeedTranslData(translText, needTranslData, dictCode, dataList, needTranslDataTable); // addNeedTranslData(translText, needTranslData, dictCode, dataList, needTranslDataTable);
//step.2 调用数据库翻译表字典 // //step.2 调用数据库翻译表字典
if (!needTranslDataTable.isEmpty()) { // if (!needTranslDataTable.isEmpty()) {
String[] arr = dictCode.split(","); // String[] arr = dictCode.split(",");
String table = arr[0]; // String table = arr[0];
String text = arr[1]; // String text = arr[1];
String code = arr[2]; // String code = arr[2];
String values = String.join(",", needTranslDataTable); // String values = String.join(",", needTranslDataTable);
log.info("translateDictFromTableByKeys.dictCode:" + dictCode); // log.info("translateDictFromTableByKeys.dictCode:" + dictCode);
log.info("translateDictFromTableByKeys.values:" + values); // log.info("translateDictFromTableByKeys.values:" + values);
List<DictModel> texts; // List<DictModel> texts;
if ("sys_user".equals(table)&&"realname".equals(text)&&"id".equals(code)){ // if ("sys_user".equals(table)&&"realname".equals(text)&&"id".equals(code)){
texts = commonAPI.translateUserRealNameFromTableByKeys(values); // texts = commonAPI.translateUserRealNameFromTableByKeys(values);
}else { // }else {
texts = commonAPI.translateDictFromTableByKeys(table, text, code, values); // texts = commonAPI.translateDictFromTableByKeys(table, text, code, values);
} // }
log.info("translateDictFromTableByKeys.result:" + texts); // log.info("translateDictFromTableByKeys.result:" + texts);
List<DictModel> list = translText.computeIfAbsent(dictCode, k -> new ArrayList<>()); // List<DictModel> list = translText.computeIfAbsent(dictCode, k -> new ArrayList<>());
list.addAll(texts); // list.addAll(texts);
setRedis(dictCode, texts); // setRedis(dictCode, texts);
//
} // }
} // }
//
//step.3 调用数据库进行翻译普通字典 // //step.3 调用数据库进行翻译普通字典
if (!needTranslData.isEmpty()) { // if (!needTranslData.isEmpty()) {
List<String> dictCodeList = Arrays.asList(dataListMap.keySet().toArray(new String[]{})); // List<String> dictCodeList = Arrays.asList(dataListMap.keySet().toArray(new String[]{}));
// 将不包含逗号的字典code筛选出来,因为带逗号的是表字典,而不是普通的数据字典 // // 将不包含逗号的字典code筛选出来,因为带逗号的是表字典,而不是普通的数据字典
List<String> filterDictCodes = dictCodeList.stream().filter(key -> !key.contains(",")).collect(Collectors.toList()); // List<String> filterDictCodes = dictCodeList.stream().filter(key -> !key.contains(",")).collect(Collectors.toList());
String dictCodes = String.join(",", filterDictCodes); // String dictCodes = String.join(",", filterDictCodes);
String values = String.join(",", needTranslData); // String values = String.join(",", needTranslData);
log.info("translateManyDict.dictCodes:" + dictCodes); // log.info("translateManyDict.dictCodes:" + dictCodes);
log.info("translateManyDict.values:" + values); // log.info("translateManyDict.values:" + values);
Map<String, List<DictModel>> manyDict = commonAPI.translateManyDict(dictCodes, values); // Map<String, List<DictModel>> manyDict = commonAPI.translateManyDict(dictCodes, values);
log.info("translateManyDict.result:" + manyDict); // log.info("translateManyDict.result:" + manyDict);
for (Map.Entry<String, List<DictModel>> entry : manyDict.entrySet()) { // for (Map.Entry<String, List<DictModel>> entry : manyDict.entrySet()) {
String dictCode = entry.getKey(); // String dictCode = entry.getKey();
List<DictModel> list = translText.computeIfAbsent(dictCode, k -> new ArrayList<>()); // List<DictModel> list = translText.computeIfAbsent(dictCode, k -> new ArrayList<>());
List<DictModel> newList = entry.getValue(); // List<DictModel> newList = entry.getValue();
list.addAll(newList); // list.addAll(newList);
//
// 做 redis 缓存 // // 做 redis 缓存
for (DictModel dict : newList) { // for (DictModel dict : newList) {
String redisKey = String.format(SYS_CACHE_DICT_S_S, dictCode, dict.getValue()); // String redisKey = String.format(SYS_CACHE_DICT_S_S, dictCode, dict.getValue());
try { // try {
redisTemplate.opsForValue().set(redisKey, dict.getText()); // redisTemplate.opsForValue().set(redisKey, dict.getText());
} catch (Exception e) { // } catch (Exception e) {
log.warn(e.getMessage(), e); // log.warn(e.getMessage(), e);
} // }
} // }
} // }
} // }
return translText; // return translText;
} // }
//
private void setRedis(String dictCode, List<DictModel> texts) { // private void setRedis(String dictCode, List<DictModel> texts) {
// 做 redis 缓存 // // 做 redis 缓存
for (DictModel dict : texts) { // for (DictModel dict : texts) {
String redisKey = String.format(CacheConstant.SYS_DICT_TABLE_CACHE_SIMPLE_KEY, dictCode, dict.getValue()); // String redisKey = String.format(CacheConstant.SYS_DICT_TABLE_CACHE_SIMPLE_KEY, dictCode, dict.getValue());
try { // try {
// 保留10分钟 // // 保留10分钟
redisTemplate.opsForValue().set(redisKey, dict.getText(), 600, TimeUnit.SECONDS); // redisTemplate.opsForValue().set(redisKey, dict.getText(), 600, TimeUnit.SECONDS);
} catch (Exception e) { // } catch (Exception e) {
log.warn(e.getMessage(), e); // log.warn(e.getMessage(), e);
} // }
} // }
} // }
//
private void addNeedTranslData(Map<String, List<DictModel>> translText, List<String> needTranslData, String dictCode, List<String> dataList, List<String> needTranslDataTable) { // private void addNeedTranslData(Map<String, List<DictModel>> translText, List<String> needTranslData, String dictCode, List<String> dataList, List<String> needTranslDataTable) {
for (String s : dataList) { // for (String s : dataList) {
String data = s.trim(); // String data = s.trim();
if (data.length() == 0) { // if (data.length() == 0) {
continue; //跳过循环 // continue; //跳过循环
} // }
if (dictCode.contains(",")) { // if (dictCode.contains(",")) {
String keyString = String.format(CacheConstant.SYS_DICT_TABLE_CACHE_SIMPLE_KEY, dictCode, data); // String keyString = String.format(CacheConstant.SYS_DICT_TABLE_CACHE_SIMPLE_KEY, dictCode, data);
if (Boolean.TRUE.equals(redisTemplate.hasKey(keyString))) { // if (Boolean.TRUE.equals(redisTemplate.hasKey(keyString))) {
addList(translText, dictCode, data, keyString); // addList(translText, dictCode, data, keyString);
} else if (!needTranslDataTable.contains(data)) { // } else if (!needTranslDataTable.contains(data)) {
// 去重添加 // // 去重添加
needTranslDataTable.add(data); // needTranslDataTable.add(data);
} // }
} else { // } else {
String keyString = String.format(SYS_CACHE_DICT_S_S, dictCode, data); // String keyString = String.format(SYS_CACHE_DICT_S_S, dictCode, data);
if (Boolean.TRUE.equals(redisTemplate.hasKey(keyString))) { // if (Boolean.TRUE.equals(redisTemplate.hasKey(keyString))) {
addList(translText, dictCode, data, keyString); // addList(translText, dictCode, data, keyString);
} else if (!needTranslData.contains(data)) { // } else if (!needTranslData.contains(data)) {
// 去重添加 // // 去重添加
needTranslData.add(data); // needTranslData.add(data);
} // }
} // }
//
} // }
} // }
//
private void addList(Map<String, List<DictModel>> translText, String dictCode, String data, String keyString) { // private void addList(Map<String, List<DictModel>> translText, String dictCode, String data, String keyString) {
try { // try {
String text = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString)); // String text = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString));
List<DictModel> list = translText.computeIfAbsent(dictCode, k -> new ArrayList<>()); // List<DictModel> list = translText.computeIfAbsent(dictCode, k -> new ArrayList<>());
list.add(new DictModel(data, text)); // list.add(new DictModel(data, text));
} catch (Exception e) { // } catch (Exception e) {
log.warn(e.getMessage()); // log.warn(e.getMessage());
} // }
} // }
//
/** // /**
* 字典值替换文本 // * 字典值替换文本
* // *
* @param dictModels // * @param dictModels
* @param values // * @param values
* @return // * @return
*/ // */
private String translDictText(List<DictModel> dictModels, String values) { // private String translDictText(List<DictModel> dictModels, String values) {
List<String> result = new ArrayList<>(); // List<String> result = new ArrayList<>();
//
// 允许多个逗号分隔,允许传数组对象 // // 允许多个逗号分隔,允许传数组对象
String[] splitVal = values.split(","); // String[] splitVal = values.split(",");
for (String val : splitVal) { // for (String val : splitVal) {
String dictText = ""; // String dictText = "";
for (DictModel dict : dictModels) { // for (DictModel dict : dictModels) {
if (val.equals(dict.getValue())) { // if (val.equals(dict.getValue())) {
dictText = dict.getText(); // dictText = dict.getText();
break; // break;
} // }
} // }
result.add(dictText); // result.add(dictText);
} // }
return String.join(",", result); // return String.join(",", result);
} // }
//
/** // /**
* 翻译字典文本 // * 翻译字典文本
* @param code // * @param code
* @param text // * @param text
* @param table // * @param table
* @param key // * @param key
* @deprecated 不推荐 // * @deprecated 不推荐
* @return // * @return
*/ // */
@Deprecated // @Deprecated
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)) { // if(oConvertUtils.isEmpty(key)) {
return null; // return null;
} // }
StringBuilder textValue = new StringBuilder(); // StringBuilder textValue = new StringBuilder();
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; //跳过循环
} // }
//update-begin--Author:scott -- Date:20210531 ----for !56 优化微服务应用下存在表字段需要字典翻译时加载缓慢问题----- // //update-begin--Author:scott -- Date:20210531 ----for !56 优化微服务应用下存在表字段需要字典翻译时加载缓慢问题-----
// tmpValue = getTmpValue(code, text, table, k, tmpValue); //// tmpValue = getTmpValue(code, text, table, k, tmpValue);
//update-end--Author:scott -- Date:20210531 ----for !56 优化微服务应用下存在表字段需要字典翻译时加载缓慢问题----- // //update-end--Author:scott -- Date:20210531 ----for !56 优化微服务应用下存在表字段需要字典翻译时加载缓慢问题-----
//
if (tmpValue != null) { // if (tmpValue != null) {
if (!"".equals(textValue.toString())) { // if (!"".equals(textValue.toString())) {
textValue.append(","); // textValue.append(",");
} // }
textValue.append(tmpValue); // textValue.append(tmpValue);
} // }
//
} // }
return textValue.toString(); // return textValue.toString();
} // }
//
private String getTmpValue(String code, String text, String table, String k, String tmpValue) { // private String getTmpValue(String code, String text, String table, String k, String tmpValue) {
if (!StringUtils.isEmpty(table)){ // if (!StringUtils.isEmpty(table)){
log.info("--DictAspect------dicTable="+ table+" ,dicText= "+text+" ,dicCode="+code); // 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()); // String keyString = String.format("sys:cache:dictTable::SimpleKey [%s,%s,%s,%s]",table,text,code,k.trim());
if (Boolean.TRUE.equals(redisTemplate.hasKey(keyString))){ // if (Boolean.TRUE.equals(redisTemplate.hasKey(keyString))){
try { // try {
tmpValue = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString)); // tmpValue = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString));
} catch (Exception e) { // } catch (Exception e) {
log.warn(e.getMessage()); // log.warn(e.getMessage());
} // }
}else { // }else {
//处理用户要翻译为姓名加工号 // //处理用户要翻译为姓名加工号
if ("sys_user".equals(table)&&"realname".equals(text)&&"id".equals(code)){ // if ("sys_user".equals(table)&&"realname".equals(text)&&"id".equals(code)){
tmpValue= commonAPI.translateUserRealNameFromTable(k.trim()); // tmpValue= commonAPI.translateUserRealNameFromTable(k.trim());
}else { // }else {
tmpValue= commonAPI.translateDictFromTable(table,text,code,k.trim()); // tmpValue= commonAPI.translateDictFromTable(table,text,code,k.trim());
} // }
} // }
}else { // }else {
String keyString = String.format(SYS_CACHE_DICT_S_S,code,k.trim()); // String keyString = String.format(SYS_CACHE_DICT_S_S,code,k.trim());
if (Boolean.TRUE.equals(redisTemplate.hasKey(keyString))){ // if (Boolean.TRUE.equals(redisTemplate.hasKey(keyString))){
try { // try {
tmpValue = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString)); // tmpValue = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString));
} catch (Exception e) { // } catch (Exception e) {
log.warn(e.getMessage()); // log.warn(e.getMessage());
} // }
}else { // }else {
tmpValue = commonAPI.translateDict(code, k.trim()); // tmpValue = commonAPI.translateDict(code, k.trim());
} // }
} // }
return tmpValue; // return tmpValue;
} // }
//
/** // /**
* @param result // * @param result
*/ // */
private void parseMethodDictText(Object result) { // private void parseMethodDictText(Object result) {
if (result instanceof Result) { // if (result instanceof Result) {
Object result1 = ((Result<Object>) result).getResult(); // Object result1 = ((Result<Object>) result).getResult();
String jsonStr = JSONUtil.toJsonStr(result1); // String jsonStr = JSONUtil.toJsonStr(result1);
if (JSONUtil.isTypeJSONObject(jsonStr)) { // if (JSONUtil.isTypeJSONObject(jsonStr)) {
JSONObject translate = translate(result1); // JSONObject translate = translate(result1);
((Result<Object>) result).setResult(translate); // ((Result<Object>) result).setResult(translate);
} else { // } else {
List<JSONObject> items = new ArrayList<>(); // List<JSONObject> items = new ArrayList<>();
for (Object o : (List<Object>) result1) { // for (Object o : (List<Object>) result1) {
JSONObject translate = translate(o); // JSONObject translate = translate(o);
items.add(translate); // items.add(translate);
} // }
((Result<Object>) result).setResult(items); // ((Result<Object>) result).setResult(items);
} // }
} // }
} // }
//
/** // /**
* @param record // * @param record
* @return // * @return
*/ // */
private JSONObject translate(Object record) { // private JSONObject translate(Object record) {
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, Feature.OrderedField); // JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
//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();
String table = field.getAnnotation(Dict.class).dictTable(); // String table = field.getAnnotation(Dict.class).dictTable();
String key = String.valueOf(item.get(field.getName())); // String key = String.valueOf(item.get(field.getName()));
//
//翻译字典值对应的txt // //翻译字典值对应的txt
String textValue = translateDictValue(code, text, table, key); // String textValue = translateDictValue(code, text, table, key);
//
log.debug(" 字典Val : " + textValue); // log.debug(" 字典Val : " + textValue);
log.debug(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + " " + 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) { // 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"); // SimpleDateFormat aDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName())))); // item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName()))));
} // }
} // }
return item; // return item;
} // }
//
} }
@@ -99,4 +99,8 @@ public class DocumentSplitInfo extends BaseEntity {
@TableField(exist = false) @TableField(exist = false)
@Dict(dicCode = "split_standard_source") @Dict(dicCode = "split_standard_source")
private String splitStandardSource; private String splitStandardSource;
// 文件状态展示字段
@TableField(exist = false)
private String fileTypeShow;
} }
@@ -149,7 +149,24 @@ public class DocumentSplitServiceImpl implements IDocumentSplitService {
public IPage<DocumentSplitInfo> queryByPage(DocumentSplitInfo documentSplitInfo, Integer pageNo, Integer pageSize) { public IPage<DocumentSplitInfo> queryByPage(DocumentSplitInfo documentSplitInfo, Integer pageNo, Integer pageSize) {
// 构建查询条件 // 构建查询条件
QueryWrapper<SarFileSplitInfoEO> queryWrapper = getSarFileSplitInfoEOQueryWrapper(documentSplitInfo); QueryWrapper<SarFileSplitInfoEO> queryWrapper = getSarFileSplitInfoEOQueryWrapper(documentSplitInfo);
return documentSplitMapper.queryByPage(new Page<>(pageNo, pageSize), queryWrapper); IPage<DocumentSplitInfo> documentSplitInfoIPage = documentSplitMapper.queryByPage(new Page<>(pageNo, pageSize), queryWrapper);
this.disposeData(documentSplitInfoIPage.getRecords());
return documentSplitInfoIPage;
}
private void disposeData(List<DocumentSplitInfo> datas) {
if (CollectionUtils.isNotEmpty(datas)) {
for (DocumentSplitInfo data : datas) {
if (StringUtils.isNotEmpty(data.getFileType())) {
if (StringUtils.equals(data.getFileType(), "1")) {
data.setFileTypeShow("发布稿");
} else if (StringUtils.equals(data.getFileType(), "2")) {
data.setFileTypeShow("正文");
}
}
}
}
} }
@Override @Override
@@ -298,8 +315,8 @@ public class DocumentSplitServiceImpl implements IDocumentSplitService {
public void add(SarFileSplitInfoEO sarFileSplitInfoEO) { public void add(SarFileSplitInfoEO sarFileSplitInfoEO) {
// // 企标权限校验 // // 企标权限校验
// enterpriseCheck(sarFileSplitInfoEO); // enterpriseCheck(sarFileSplitInfoEO);
// // 唯一校验 // 唯一校验
// uniqueCheck(sarFileSplitInfoEO); uniqueCheck(sarFileSplitInfoEO);
// 保存文本拆分数据 // 保存文本拆分数据
saveDocumentSplitInfo(sarFileSplitInfoEO); saveDocumentSplitInfo(sarFileSplitInfoEO);
//拆分 //拆分
@@ -36,7 +36,7 @@ public class SarFileSplitMenuEOController extends JeroController<SarFileSplitMen
@GetMapping("/getSplitMenusByInfoId") @GetMapping("/getSplitMenusByInfoId")
public Result<List<SarFileSplitMenuEO>> list(SarFileSplitMenuEOPage page) throws Exception { public Result<List<SarFileSplitMenuEO>> list(SarFileSplitMenuEOPage page) throws Exception {
page.setValidFlag("0"); page.setValidFlag("0");
page.setOrderBy("display_seq asc"); page.setOrderBy("display_seq,creation_time ASC");
List<SarFileSplitMenuEO> getList = sarFileSplitMenuEOService.queryByList(page); List<SarFileSplitMenuEO> getList = sarFileSplitMenuEOService.queryByList(page);
return Result.OK(getList); return Result.OK(getList);
} }
@@ -255,9 +255,25 @@ public class SarFileSplitMenuEOServiceImpl extends ServiceImpl<SarFileSplitMenuE
private List<SarFileSplitMenuEO> createChildList(SarFileSplitMenuEO testTree, List<SarFileSplitMenuEO> treeList) { private List<SarFileSplitMenuEO> createChildList(SarFileSplitMenuEO testTree, List<SarFileSplitMenuEO> treeList) {
return treeList.stream().filter(v -> testTree.getId().equals(v.getPId())) List<SarFileSplitMenuEO> results = treeList.stream().filter(v -> testTree.getId().equals(v.getPId()))
.peek(v -> v.setChildren(createChildList(v, treeList))) .peek(v -> v.setChildren(createChildList(v, treeList)))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(results)) {
Collections.sort(results, new Comparator<SarFileSplitMenuEO>() {
@Override
public int compare(SarFileSplitMenuEO o1, SarFileSplitMenuEO o2) {
if(o1.getDisplaySeq().compareTo(o2.getDisplaySeq())>0){
return 1;
}else if(o1.getDisplaySeq().compareTo(o2.getDisplaySeq())==0){
if(o1.getCreationTime().compareTo(o2.getCreationTime())<0){
return 1;
}
}
return -1;
}
});
}
return results;
} }
@Override @Override