升級后出現
系統管理里的用戶管理出現下面問題
2023-08-17 09:44:38.902 [http-nio-8080-exec-4] [1;31mERROR[0;39m [36mo.jeecg.common.exception.JeecgBootExceptionHandler:69[0;39m - java.lang.String cannot be cast to java.lang.Long
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
?? ?at org.jeecg.common.aspect.DictAspect.parseDictText(DictAspect.java:139)
?? ?at org.jeecg.common.aspect.DictAspect.doAround(DictAspect.java:62)
?? ?at sun.reflect.GeneratedMethodAccessor150.invoke(Unknown Source)
?? ?at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
?? ?at java.lang.reflect.Method.invoke(Method.java:498)
?? ?at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634)
?? ?at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624)
?? ?at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72)
?? ?at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
?? ?at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
?? ?at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
?? ?at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
?? ?at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
?? ?at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
?? ?at org.jeecg.modules.system.controller.SysUserController$$EnhancerBySpringCGLIB$$604f6775.queryPageList(<generated>)
數據字典出現下面問題
2023-08-17 09:50:23.491 [http-nio-8080-exec-2] [1;31mERROR[0;39m [36mo.jeecg.common.exception.JeecgBootExceptionHandler:69[0;39m - java.lang.String cannot be cast to java.lang.Long
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
?? ?at org.jeecg.common.aspect.DictAspect.parseDictText(DictAspect.java:139)
?? ?at org.jeecg.common.aspect.DictAspect.doAround(DictAspect.java:62)
?? ?at sun.reflect.GeneratedMethodAccessor150.invoke(Unknown Source)
?? ?at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
?? ?at java.lang.reflect.Method.invoke(Method.java:498)
?? ?at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634)
?? ?at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624)
?? ?at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72)
?? ?at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
?? ?at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
?? ?at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
?? ?at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
?? ?at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
?? ?at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
?? ?at org.jeecg.modules.system.controller.SysDictItemController$$EnhancerBySpringCGLIB$$824a46d6.queryPageList(<generated>)
?? ?at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
?? ?at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
?? ?at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
?? ?at java.lang.reflect.Method.invoke(Method.java:498)
上面兩個問題主要都是DictAspect.parseDictText出現問題,具體看就是這個函數里面的一個日期轉換到string出問題,目前不需要了,可以注釋掉了,注釋掉后正常,代碼如下:
private void parseDictText(Object result) {if (result instanceof Result) {if (((Result) result).getResult() instanceof IPage) {List<JSONObject> items = new ArrayList<>();//step.1 篩選出加了 Dict 注解的字段列表List<Field> dictFieldList = new ArrayList<>();// 字典數據列表, key = 字典code,value=數據列表Map<String, List<String>> dataListMap = new HashMap<>();for (Object record : ((IPage) ((Result) result).getResult()).getRecords()) {ObjectMapper mapper = new ObjectMapper();String json="{}";try {//解決@JsonFormat注解解析不了的問題詳見SysAnnouncement類的@JsonFormat//json = mapper.writeValueAsString(record); //改用objectMapper,解決java8 LocalDateTime JSON解析問題json = objectMapper.writeValueAsString(record);} catch (JsonProcessingException e) {log.error("json解析失敗"+e.getMessage(),e);}JSONObject item = JSONObject.parseObject(json);//update-begin--Author:scott -- Date:20190603 ----for:解決繼承實體字段無法翻譯問題------//for (Field field : record.getClass().getDeclaredFields()) {// 遍歷所有字段,把字典Code取出來,放到 map 里for (Field field : oConvertUtils.getAllFields(record)) {String value = item.getString(field.getName());if (oConvertUtils.isEmpty(value)) {continue;}//update-end--Author:scott -- Date:20190603 ----for:解決繼承實體字段無法翻譯問題------if (field.getAnnotation(Dict.class) != null) {if (!dictFieldList.contains(field)) {dictFieldList.add(field);}String code = field.getAnnotation(Dict.class).dicCode();String text = field.getAnnotation(Dict.class).dicText();String table = field.getAnnotation(Dict.class).dictTable();List<String> dataList;String dictCode = code;if (!StringUtils.isEmpty(table)) {dictCode = String.format("%s,%s,%s", table, text, code);}dataList = dataListMap.computeIfAbsent(dictCode, k -> new ArrayList<>());this.listAddAllDeduplicate(dataList, Arrays.asList(value.split(",")));}//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()))));}*/}items.add(item);}//step.2 調用翻譯方法,一次性翻譯Map<String, List<DictModel>> translText = this.translateAllDict(dataListMap);//step.3 將翻譯結果填充到返回結果里for (JSONObject record : items) {for (Field field : dictFieldList) {String code = field.getAnnotation(Dict.class).dicCode();String text = field.getAnnotation(Dict.class).dicText();String table = field.getAnnotation(Dict.class).dictTable();String fieldDictCode = code;if (!StringUtils.isEmpty(table)) {fieldDictCode = String.format("%s,%s,%s", table, text, code);}String value = record.getString(field.getName());if (oConvertUtils.isNotEmpty(value)) {List<DictModel> dictModels = translText.get(fieldDictCode);if(dictModels==null || dictModels.size()==0){continue;}String textValue = this.translDictText(dictModels, value);log.debug(" 字典Val : " + textValue);log.debug(" __翻譯字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + ": " + textValue);// TODO-sun 測試輸出,待刪log.debug(" ---- dictCode: " + fieldDictCode);log.debug(" ---- value: " + value);log.debug(" ----- text: " + textValue);log.debug(" ---- dictModels: " + JSON.toJSONString(dictModels));record.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);}}}((IPage) ((Result) result).getResult()).setRecords(items);}}