lxzn-boot-base-core/src/main/java/org/jeecg/common/aspect/DictAspect.java
@@ -94,6 +94,12 @@ private Object 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<>(5); //ååºç»æé List<Object> records=((IPage) ((Result) result).getResult()).getRecords(); //update-begin--Author:zyf -- Date:20220606 ----forï¼ãVUEN-1230ã 夿æ¯å¦å«æåå ¸æ³¨è§£,æ²¡ææ³¨è§£è¿å----- @@ -101,58 +107,6 @@ if(!hasDict){ return result; } List<JSONObject> dictText = getDictText(records); ((IPage) ((Result) result).getResult()).setRecords(dictText); } else { //ååºç»æé Object object= (Object) ((Result) result).getResult(); Class<?> aClass = ((Result) result).getResult().getClass(); if ("java.util.HashMap".equals(aClass.getName())){ //å°map转æ¢ä¸ºéåå¨è½¬æ¢ä¸ºmap Map<String, Object> mapset = new HashMap<>(); Map<String,Object> map= (Map<String,Object>) object; for (String s : map.keySet()) { Object a1 = map.get(s); List<Object> records=new ArrayList<>(); Class<?> aClass1 = a1.getClass(); if ("java.util.ArrayList".equals(aClass1.getName())){ records = (ArrayList)map.get(s); }else{ records = oConvertUtils.castList(a1, Object.class); } Boolean hasDict= checkHasDict(records); if(!hasDict){ return result; } List<JSONObject> dictText = getDictText(records); mapset.put(s,dictText); } ((Result) result).setResult(mapset); }else { List<Object> records = oConvertUtils.castList(object, Object.class); //update-begin--Author:zyf -- Date:20220606 ----forï¼ãVUEN-1230ã 夿æ¯å¦å«æåå ¸æ³¨è§£,æ²¡ææ³¨è§£è¿å----- Boolean hasDict= checkHasDict(records); if(!hasDict){ return result; } List<JSONObject> dictText = getDictText(records); ((Result) result).setResult(dictText); } } } return result; } /** ä¼ å ¥éå ç¿»è¯åå ¸å¼ **/ private List<JSONObject> getDictText(List<Object> records){ List<JSONObject> items = new ArrayList<>(); //step.1 çéåºå äº Dict 注解çåæ®µå表 List<Field> dictFieldList = new ArrayList<>(); // åå ¸æ°æ®åè¡¨ï¼ key = åå ¸codeï¼value=æ°æ®å表 Map<String, List<String>> dataListMap = new HashMap<>(5); log.debug(" __ è¿å ¥åå ¸ç¿»è¯åé¢ DictAspect ââ " ); //update-end--Author:zyf -- Date:20220606 ----forï¼ãVUEN-1230ã 夿æ¯å¦å«æåå ¸æ³¨è§£,æ²¡ææ³¨è§£è¿å----- @@ -242,7 +196,12 @@ } } } return items; ((IPage) ((Result) result).getResult()).setRecords(items); } } return result; } /** lxzn-boot-base-core/src/main/java/org/jeecg/common/aspect/annotation/DictExt.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,38 @@ package org.jeecg.common.aspect.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * åå ¸æ³¨è§£æ©å±ï¼æ¯æå¤å段å¹é */ @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface DictExt { /** * æ°æ®åå ¸è¡¨ * @return */ String dicTable() default ""; /** * æ°æ®Text * @return */ String dicText() default ""; /** * æ°æ®codeæ°ç» * @return */ String[] dicCode(); /** * æ°æ®åæ°æ°ç»ï¼åæ°è·codeæ°ç»ä¸ä¸å¯¹åº * @return */ String[] dicParams(); } lxzn-boot-base-core/src/main/java/org/jeecg/common/aspect/annotation/FieldQuery.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,37 @@ package org.jeecg.common.aspect.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * åå ¸æ³¨è§£ */ @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface FieldQuery{ /** * å ³èæ°æ®è¡¨ * @return */ String dicTable() default ""; /** * æ°æ®Text * @return */ String dicText() default ""; /** * æ°æ®codeæ°ç» * @return */ String[] dicCode(); /** * æ°æ®åæ°æ°ç»ï¼åæ°è·codeæ°ç»ä¸ä¸å¯¹åº * @return */ String[] dicParams(); } lxzn-module-dnc/src/main/java/org/jeecg/modules/activiti/controller/AssignFileStreamController.java
@@ -1,5 +1,6 @@ package org.jeecg.modules.activiti.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -52,11 +53,10 @@ @AutoLog(value = "DNCæµç¨æä½-è·åå½åç¨æ·çå¾ åå坿¾åçä»»å¡") @ApiOperation(value = "DNCæµç¨æä½-è·åå½åç¨æ·çå¾ åå坿¾åçä»»å¡", notes = "DNCæµç¨æä½-è·åå½åç¨æ·çå¾ åå坿¾åçä»»å¡") @GetMapping("/find/task/list") public QueryListResponseResult<ActTaskExt> getUndoTaskList() { List<ActTaskExt> list = assignFileStreamService.getUndoTaskList(); if(list == null) list = Collections.emptyList(); return new QueryListResponseResult<>(CommonCode.SUCCESS, list); public Result<?> getUndoTaskList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { IPage<ActTaskExt> actTaskExtIPage = assignFileStreamService.getUndoTaskList(pageNo,pageSize); return Result.ok(actTaskExtIPage); } @AutoLog(value = "DNCæµç¨æä½-æ¹éææ´¾å°è®¾å¤") lxzn-module-dnc/src/main/java/org/jeecg/modules/activiti/service/IAssignFileStreamService.java
@@ -1,5 +1,6 @@ package org.jeecg.modules.activiti.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.activiti.entity.AssignFileStream; @@ -38,7 +39,7 @@ * è·åå½åç¨æ·çå¾ åå坿¾åçä»»å¡ * @return */ List<ActTaskExt> getUndoTaskList(); IPage<ActTaskExt> getUndoTaskList(Integer pageNo, Integer pageSize); /** * å ³èç¨æ·è¡¨ è·åç¨æ·æµç§° lxzn-module-dnc/src/main/java/org/jeecg/modules/activiti/service/impl/AssignFileStreamServiceImpl.java
@@ -312,7 +312,7 @@ ExceptionCast.cast(CommonCode.INVALID_PARAM); if(!ValidateUtil.validateString(stream.getDeviceId())) ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); String userId = user.getId(); if(!ValidateUtil.validateString(userId)) ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST); @@ -512,7 +512,7 @@ } @Override public List<ActTaskExt> getUndoTaskList() { public IPage<ActTaskExt> getUndoTaskList(Integer pageNo,Integer pageSize) { LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); String userId = user.getId(); if(!ValidateUtil.validateString(userId)) @@ -537,7 +537,10 @@ ext.setAssignFileStream(streamDetail); extList.add(ext); }); return extList; //å°è£ Page IPage<ActTaskExt> page = new Page<>(pageNo,pageSize); page.setRecords(extList); return page; } @Override @@ -552,7 +555,7 @@ public boolean approveAssignFile(String taskId, String streamId, AssignFileStream stream) { if(!ValidateUtil.validateString(taskId) || !ValidateUtil.validateString(streamId) || stream == null) ExceptionCast.cast(CommonCode.INVALID_PARAM); LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); String userId = user.getId(); if(!ValidateUtil.validateString(userId)) ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST); lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/aspect/DncDictAspect.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,80 @@ package org.jeecg.modules.dnc.aspect; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.metadata.IPage; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.system.aspect.DicAspectService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.*; /** * @Description: Dncåå ¸aopç±» * @Version: 1.0 */ @Aspect @Component @Slf4j public class DncDictAspect { @Autowired private DicAspectService dicAspectService; // å®ä¹åç¹Pointcut @Pointcut("execution(public * org.jeecg.modules.dnc..*.*Controller.*(..))") public void excudeService() { } @Around("excudeService()") public Object doAround(ProceedingJoinPoint pjp) throws Throwable { long time1=System.currentTimeMillis(); Object result = pjp.proceed(); long time2=System.currentTimeMillis(); log.debug("è·åJSONæ°æ® èæ¶ï¼"+(time2-time1)+"ms"); long start=System.currentTimeMillis(); this.parseDictText(result); long end=System.currentTimeMillis(); log.debug("è§£ææ³¨å ¥JSONæ°æ® èæ¶"+(end-start)+"ms"); return result; } /** * æ¬æ¹æ³é对è¿å对象为Result çIPageçå页åè¡¨æ°æ®è¿è¡å¨æåå ¸æ³¨å ¥ * åå ¸æ³¨å ¥å®ç° éè¿å¯¹å®ä½ç±»æ·»å 注解@dict æ¥æ è¯éè¦çåå ¸å 容,åå ¸å为ååå ¸codeå³å¯ ï¼tableåå ¸ code table texté å使ç¨ä¸åæ¥jeecgçç¨æ³ç¸å * 示ä¾ä¸ºSysUser åæ®µä¸ºsex æ·»å äºæ³¨è§£@Dict(dicCode = "sex") ä¼å¨åå ¸æå¡ç«é©¬æ¥åºæ¥å¯¹åºçtext ç¶åå¨è¯·æ±listçæ¶åå°è¿ä¸ªåå ¸textï¼å·²å段åç§°å _dictTextå½¢å¼è¿åå°å端 * ä¾è¾å ¥å½åè¿åå¼çå°±ä¼å¤åºä¸ä¸ªsex_dictTextåæ®µ * { * sex:1, * sex_dictText:"ç·" * } * åç«¯ç´æ¥åå¼sext_dictTextå¨tableé颿 éåè¿è¡å端çåå ¸è½¬æ¢äº * customRender:function (text) { * if(text==1){ * return "ç·"; * }else if(text==2){ * return "女"; * }else{ * return text; * } * } * ç®åvueæ¯è¿ä¹è¿è¡åå ¸æ¸²æå°tableä¸çå¤äºå°±å¾éº»ç¦äº è¿ä¸ªç´æ¥å¨æå¡ç«¯æ¸²æå®æå端å¯ä»¥ç´æ¥ç¨ * @param result */ private void parseDictText(Object result) { if (result instanceof Result) { if (((Result) result).getResult() instanceof IPage) { List<JSONObject> items = dicAspectService.detailDict(((IPage) ((Result) result).getResult()).getRecords()); ((IPage) ((Result) result).getResult()).setRecords(items); } else if(((Result) result).getResult() instanceof List){ List<JSONObject> items = dicAspectService.detailDict(((List) ((Result) result).getResult())); ((Result) result).setResult(items); } } } } lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/aspect/DicAspectService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,311 @@ package org.jeecg.modules.system.aspect; import cn.hutool.core.util.ArrayUtil; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import cn.hutool.core.util.ReflectUtil; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.aspect.annotation.Dict; import org.jeecg.common.aspect.annotation.DictExt; import org.jeecg.common.aspect.annotation.DictList; import org.jeecg.common.aspect.annotation.FieldQuery; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.system.service.ISysDictService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import java.lang.reflect.Field; import java.text.SimpleDateFormat; import java.util.*; /** * åå ¸åæ®µç¿»è¯æå¡ * æ¯æåµå¥ç¿»è¯ * @since 2020/5/27 */ @Service @Slf4j public class DicAspectService { @Autowired private ISysDictService dictService; /** * æ¬æ¹æ³é对åè¡¨æ°æ®è¿è¡å¨æåå ¸æ³¨å ¥ * åå ¸æ³¨å ¥å®ç° éè¿å¯¹å®ä½ç±»æ·»å 注解@dict æ¥æ è¯éè¦çåå ¸å 容,åå ¸å为ååå ¸codeå³å¯ ï¼tableåå ¸ code table texté å使ç¨ä¸åæ¥jeecgçç¨æ³ç¸å * 示ä¾ä¸ºSysUser åæ®µä¸ºsex æ·»å äºæ³¨è§£@Dict(dicCode = "sex") ä¼å¨åå ¸æå¡ç«é©¬æ¥åºæ¥å¯¹åºçtext ç¶åå¨è¯·æ±listçæ¶åå°è¿ä¸ªåå ¸textï¼å·²å段åç§°å _dictTextå½¢å¼è¿åå°å端 * ä¾è¾å ¥å½åè¿åå¼çå°±ä¼å¤åºä¸ä¸ªsex_dictTextåæ®µ * { * sex:1, * sex_dictText:"ç·" * } * åç«¯ç´æ¥åå¼sext_dictTextå¨tableé颿 éåè¿è¡å端çåå ¸è½¬æ¢äº * customRender:function (text) { * if(text==1){ * return "ç·"; * }else if(text==2){ * return "女"; * }else{ * return text; * } * } * ç®åvueæ¯è¿ä¹è¿è¡åå ¸æ¸²æå°tableä¸çå¤äºå°±å¾éº»ç¦äº è¿ä¸ªç´æ¥å¨æå¡ç«¯æ¸²æå®æå端å¯ä»¥ç´æ¥ç¨ * @param records * @return */ public List<JSONObject> detailDict(List<Object> records){ List<JSONObject> items = new ArrayList<>(); FieldBatchQuery batchQuery = new FieldBatchQuery(); boolean hasDict = false; for (Object record : records) { JSONObject item = parseDictItem(record); Field[] fieldsArray = oConvertUtils.getAllFields(record); for (int i = 0; i < fieldsArray.length; i++) { Field field = fieldsArray[i]; if (field.getAnnotation(Dict.class) != null && records.size()<=500) { hasDict = true; String code = field.getAnnotation(Dict.class).dicCode(); String text = field.getAnnotation(Dict.class).dicText(); String table = field.getAnnotation(Dict.class).dictTable(); String key = String.valueOf(item.get(field.getName())); //ç¿»è¯åå ¸å¼å¯¹åºçtxt String textValue = translateDictValue(code, text, table, key); item.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue); } // åå ¸ç¿»è¯æ©å±åè½ï¼æ¯æåå ¸å¤å段å¹é else if(field.getAnnotation(DictExt.class) != null && records.size() <= 500){ hasDict = true; String[] code = field.getAnnotation(DictExt.class).dicCode(); String text = field.getAnnotation(DictExt.class).dicText(); String table = field.getAnnotation(DictExt.class).dicTable(); String[] params = field.getAnnotation(DictExt.class).dicParams(); String[] paramValues = this.getParamValues(item, params); String textValue = this.translateDictValue(code, text, table, paramValues); item.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue); item.put(field.getName(), ArrayUtil.join(paramValues, ",")); } else if(field.getAnnotation(FieldQuery.class) != null && records.size() <= 500){ FieldQuery ann = field.getAnnotation(FieldQuery.class); batchQuery.put(ann.dicTable(), ann.dicText(), ann.dicCode(), this.getParamValues(item, ann.dicParams())); } // 深度翻è¯listå ç´ else if(field.getAnnotation(DictList.class) != null){ Object fieldValue = ReflectUtil.getFieldValue(record, field); if(fieldValue == null){ // no-op } else if(null != fieldValue && fieldValue instanceof List){ try{ List<JSONObject> listDetail = this.detailDict((List)fieldValue); item.put(field.getName(), listDetail); }catch (Exception e){ log.error("åæ®µç¿»è¯é误ï¼index=" + i + ",fieldName=" + field.getName() + ",fieldValue=" + fieldValue + ",record=" + record); } }else{ log.error("深度åå ¸ç¿»è¯åªæ¯æListç±»åï¼å½åç±»å为" + fieldValue.getClass()); } } //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(records.size()>500 && hasDict){ log.error("ä½¿ç¨ @Dictæ³¨è§£è¶ è¿500æ¡è®°å½è¯·ä½¿ç¨å页æ¥è¯¢"); } items.add(item); } // æ¹éæ¥è¯¢å ³èæ°æ® if(batchQuery.size() > 0){ Map<String, List<Map>> batchResult = new HashMap<>(); batchQuery.forEach((queryKey, queryParam) -> { // æ¹éæ¥è¯¢ try { queryParam.setQueryResult(this.batchQueryFieldValue(queryParam.getQueryTable(), queryParam.getColumns(), queryParam.getParamName(), queryParam.getParamValues())); } catch (Exception e) { throw new RuntimeException(e); } }); for (int i = 0; i < records.size(); i++) { Object record = records.get(i); JSONObject item = items.get(i); try { this.fillItemValue(record, item, batchQuery); } catch (Exception e) { e.printStackTrace(); log.info("æ¹éæ¥è¯¢æ°æ®å¡«å åºé:{}", e.getMessage()); } } } return items; } /** * å表æ¹éæ¥è¯¢ * * @param queryTable * @param columns * @param paramName * @param paramValues * @return */ private List<Map> batchQueryFieldValue(String queryTable, String[] columns, String paramName, String[] paramValues) throws Exception { try{ return this.dictService.queryTableFieldByParams(queryTable, columns, paramName, paramValues); }catch (Exception e){ log.error("FieldQueryæ¥è¯¢é误", e); throw new Exception("FieldQueryæ¥è¯¢é误"); } } /** * å¡«å itemæ¹éæ¥è¯¢æ°æ® * @param record * @param item * @param batchQuery */ private void fillItemValue(Object record, JSONObject item, FieldBatchQuery batchQuery) throws Exception{ for (Field field : oConvertUtils.getAllFields(record)) { if(field.getAnnotation(FieldQuery.class) != null){ FieldQuery fieldQuery = field.getAnnotation(FieldQuery.class); String[] paramValues = this.getParamValues(item, fieldQuery.dicParams()); Object textValue = batchQuery.findResult(fieldQuery.dicTable(), fieldQuery.dicCode(), paramValues, fieldQuery.dicText()); item.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue); item.put(field.getName(), ArrayUtil.join(paramValues, ",")); } } } /** * è§£æåå ¸Item * @param record * @return */ private JSONObject parseDictItem(Object record) { ObjectMapper mapper = new ObjectMapper(); String json="{}"; try { //è§£å³@JsonFormat注解解æä¸äºçé®é¢è¯¦è§SysAnnouncementç±»ç@JsonFormat json = mapper.writeValueAsString(record); } catch (JsonProcessingException e) { log.error("jsonè§£æå¤±è´¥"+e.getMessage(),e); } return JSONObject.parseObject(json); } /** * è·ååæ°æ°å¼ * @param item * @param paramNames * @return */ private String[] getParamValues(JSONObject item, String[] paramNames) { // è·åå®é åæ° String[] values = new String[paramNames.length]; for (int i = 0; i < paramNames.length; i++) { String param = paramNames[i]; if(param.startsWith("$")){ values[i] = (String) item.get(param.substring(1)); }else{ values[i] = param; } if(values[i] == null) return null; if(values[i].indexOf("&&") > -1){ log.error(">>>åæ°["+values[i]+"]å å«éæ³å符','"); return null; } } return values; } /** * ç¿»è¯åå ¸ææ¬ * * @param code * @param text * @param table * @param paramValues * @return */ private String translateDictValue(String[] code, String text, String table, String[] paramValues) { if(paramValues == null || paramValues.length <=0 || oConvertUtils.isEmpty(table)){ return null; } try{ return this.dictService.queryTableDictByParams(table,text, ArrayUtil.join(code, "&&"), ArrayUtil.join(paramValues, "&&")); }catch (Exception e){ log.error("åå ¸ç¿»è¯å¼å¸¸table={},text={},code={},paramValues={}", table, text, ArrayUtil.join(code, "&&"),ArrayUtil.join(paramValues, "&&") ); throw e; } } /** * ç¿»è¯åå ¸ææ¬ * @param code * @param text * @param table * @param key * @return */ private String translateDictValue(String code, String text, String table, String key) { if(oConvertUtils.isEmpty(key)) { return null; } StringBuffer textValue=new StringBuffer(); String[] keys = key.split(","); for (String k : keys) { String tmpValue = null; if (k.trim().length() == 0) { continue; //è·³è¿å¾ªç¯ } if (!StringUtils.isEmpty(table)){ tmpValue= dictService.queryTableDictTextByKey(table,text,code,k.trim()); }else { tmpValue = dictService.queryDictTextByKey(code, k.trim()); } if (tmpValue != null) { if (!"".equals(textValue.toString())) { textValue.append(","); } textValue.append(tmpValue); } } return textValue.toString(); } } lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/aspect/FieldBatchQuery.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,135 @@ package org.jeecg.modules.system.aspect; import cn.hutool.core.util.ArrayUtil; import java.util.*; import java.util.function.BiConsumer; /** * æ¹éæ¥è¯¢å¨ */ public class FieldBatchQuery { // key=æ¥è¯¢è¦ç´ =table+paramNameï¼ value=æ¥è¯¢æ¡ä»¶ private Map<String, QueryParam> queryBatch = new HashMap<>(); /** * ä¾¿å©æ¥è¯¢è¦ç´ * @param action */ public void forEach(BiConsumer<? super String, ? super QueryParam> action) { this.queryBatch.forEach(action); } /** * æ¥è¯¢è¡¨æ°é * @return */ public int size() { return queryBatch.size(); } /** * æ¥æ¾æ¥è¯¢ç»æ * @param tableName * @param paramName * @param paramValue * @param column * @return */ public Object findResult(String tableName, String[] paramName, String[] paramValue, String column) { String queryKey = tableName + "()" + ArrayUtil.join(paramName, ","); if(!this.queryBatch.containsKey(queryKey)) return null; return this.queryBatch.get(queryKey).findResult(paramValue, column); } /** * ä¿åæ¥è¯¢æ¡ä»¶ * @param tableName æ¥è¯¢è¡¨å * @param textName æ¥è¯¢å段åç§° * @param paramName æ¥è¯¢åæ°åç§° * @param paramValue æ¥è¯¢åæ°å¼ */ public void put(String tableName, String textName, String[] paramName, String[] paramValue) { String queryKey = tableName + "()" + ArrayUtil.join(paramName, ","); QueryParam queryParams; if(this.queryBatch.containsKey(queryKey)){ queryParams = this.queryBatch.get(queryKey); }else{ queryParams = new QueryParam(tableName, paramName); this.queryBatch.put(queryKey, queryParams); } // æ·»å æ¥è¯¢ç»æcolumnåç§° queryParams.addTextName(textName); // æ·»å æ¥è¯¢åæ° queryParams.addParamValue(paramValue); } public static class QueryParam { private String queryTable; private Set<String> columns = new HashSet<>(); private Set<String> paramValueSet = new HashSet<>(); private String[] paramName; private List<Map> queryResult = new ArrayList<>(); private Map<String, Integer> resultIndex = new HashMap<>(); public QueryParam(String tableName, String[] column) { this.queryTable = tableName; this.paramName = column; } public void addTextName(String textName) { this.columns.add(textName); } public void addParamValue(String[] paramValue) { paramValueSet.add(ArrayUtil.join(paramValue, ",")); } public String getQueryTable() { return queryTable; } public String[] getColumns() { String[] ret = new String[this.columns.size()]; this.columns.toArray(ret); return ret; } public String getParamName() { return "concat(" + ArrayUtil.join(this.paramName, ",',',") + ")"; } public String[] getParamValues() { String[] ret = new String[this.paramValueSet.size()]; this.paramValueSet.toArray(ret); return ret; } public void setQueryResult(List<Map> queryResult) { this.queryResult = queryResult; } public Object findResult(String[] paramValue, String column) { if(paramValue == null) return null; String value = ArrayUtil.join(paramValue, ","); if(this.resultIndex.containsKey(value)){ return this.queryResult.get(this.resultIndex.get(value)).get(column); } for (int i = 0; i < this.queryResult.size(); i++) { Map<String, Object> map = queryResult.get(i); if(value.equals(map.get("paramValue"))){ this.resultIndex.put(value, i); return map.get(column); } } return null; } } } lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/mapper/SysDictMapper.java
@@ -25,7 +25,7 @@ * @since 2018-12-28 */ public interface SysDictMapper extends BaseMapper<SysDict> { /** * é夿£æ¥SQL * @param duplicateCheckVo @@ -152,13 +152,13 @@ * @return */ public List<DictModel> queryAllDepartBackDictModel(); /** * æ¥è¯¢ææç¨æ· ä½ä¸ºåå ¸ä¿¡æ¯ username -->value,realname -->text * @return */ public List<DictModel> queryAllUserBackDictModel(); // /** // * éè¿å ³é®åæ¥è¯¢åºåå ¸è¡¨ // * @param table @@ -263,4 +263,25 @@ */ @Deprecated List<DictModel> queryTableDictByKeysAndFilterSql(@Param("table") String table, @Param("text") String text, @Param("code") String code, @Param("filterSql") String filterSql, @Param("codeValues") List<String> codeValues); /** * 使ç¨åSqlæ¥è¯¢åå ¸æ°æ® * @param table * @param text * @param subSql * @return */ String queryTableDictTextBySubSql(@Param("table") String table, @Param("text") String text, @Param("subSql") String subSql); /** * å表æ¹éæ¥è¯¢ * @param queryTable * @param columns * @param paramName * @param paramValues * @return */ List<Map> queryTableFieldByParams(@Param("table") String queryTable, @Param("columns") String columns, @Param("paramName") String paramName, @Param("paramValues") String[] paramValues); } lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/mapper/xml/SysDictMapper.xml
@@ -36,7 +36,7 @@ <!-- éè¿åå ¸codeè·ååå ¸æ°æ® --> <select id="queryDictTextByKey" parameterType="String" resultType="String"> select s.item_text from sys_dict_item s select s.item_text from sys_dict_item s where s.dict_id = (select id from sys_dict where dict_code = #{code}) and s.item_value = #{key} </select> @@ -66,7 +66,7 @@ <select id="queryTableDictItemsByCode" parameterType="String" resultType="org.jeecg.common.system.vo.DictModel"> select ${text} as "text",${code} as "value" from ${table} </select> <!--éè¿æ¥è¯¢æå®tableç text code è·ååå ¸ï¼æå®æ¥è¯¢æ¡ä»¶ï¼--> <select id="queryTableDictItemsByCodeAndFilter" parameterType="String" resultType="org.jeecg.common.system.vo.DictModel"> select ${text} as "text",${code} as "value" from ${table} @@ -74,7 +74,7 @@ where ${filterSql} </if> </select> <!--éè¿æ¥è¯¢æå®tableç text code key è·ååå ¸å¼--> <select id="queryTableDictTextByKey" parameterType="String" resultType="String"> select ${text} as "text" from ${table} where ${code}= #{key} @@ -101,27 +101,27 @@ <select id="duplicateCheckCountSql" resultType="Long" parameterType="org.jeecg.modules.system.model.DuplicateCheckVo"> SELECT COUNT(*) FROM ${tableName} WHERE ${fieldName} = #{fieldVal} and id <> #{dataId} </select> <!-- é夿 ¡éª sqlè¯å¥ --> <select id="duplicateCheckCountSqlNoDataId" resultType="Long" parameterType="org.jeecg.modules.system.model.DuplicateCheckVo"> SELECT COUNT(*) FROM ${tableName} WHERE ${fieldName} = #{fieldVal} </select> <!-- æ¥è¯¢é¨é¨ä¿¡æ¯ ä½ä¸ºåå ¸æ°æ® --> <select id="queryAllDepartBackDictModel" resultType="org.jeecg.common.system.vo.DictModel"> select id as "value",depart_name as "text" from sys_depart where del_flag = '0' </select> <!-- æ¥è¯¢ç¨æ·ä¿¡æ¯ ä½ä¸ºåå ¸æ°æ® --> <select id="queryAllUserBackDictModel" resultType="org.jeecg.common.system.vo.DictModel"> select username as "value",realname as "text" from sys_user where del_flag = '0' </select> <!--éè¿æ¥è¯¢æå®tableç text code è·ååå ¸æ°æ®ï¼ä¸æ¯æå ³é®åæ¥è¯¢ <select id="queryTableDictItems" parameterType="String" resultType="org.jeecg.common.system.vo.DictModel"> select ${text} as "text",${code} as "value" from ${table} where ${text} like #{keyword} </select> --> <!-- æ ¹æ®è¡¨åãæ¾ç¤ºåæ®µåãåå¨å段åãç¶IDæ¥è¯¢æ --> <select id="queryTreeList" parameterType="Object" resultType="org.jeecg.modules.system.model.TreeSelectModel"> select ${text} as "title", @@ -213,7 +213,16 @@ and ${filterSql} </if> </select> <select id="queryTableDictTextBySubSql" resultType="java.lang.String"> select ${text} as "text" from ${table} where ${subSql} </select> <select id="queryTableFieldByParams" resultType="java.util.Map"> select ${columns},${paramName} as paramValue from ${table} where ${paramName} in <foreach item="key" collection="paramValues" open="(" separator="," close=")"> #{key} </foreach> </select> </mapper> lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/ISysDictService.java
@@ -255,4 +255,16 @@ */ List<DictModel> loadDict(String dictCode, String keyword, Integer pageSize); String queryTableDictByParams(String table, String text, String codes, String params); /** * å表æ¹éæ¥è¯¢ * @param queryTable * @param columns * @param paramName * @param paramValues * @return */ List<Map> queryTableFieldByParams(String queryTable, String[] columns, String paramName, String[] paramValues); } lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDictServiceImpl.java
@@ -1,5 +1,7 @@ package org.jeecg.modules.system.service.impl; import cn.hutool.core.lang.Validator; import cn.hutool.core.util.ArrayUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -153,7 +155,7 @@ log.debug("æ ç¼ådictTableListçæ¶åè°ç¨è¿éï¼"); return sysDictMapper.queryTableDictItemsByCodeAndFilter(table,text,code,filterSql); } /** * éè¿æ¥è¯¢æå®tableç text code è·ååå ¸å¼text * dictTableCacheéç¨redisç¼åæææ10åé @@ -282,7 +284,7 @@ public List<DictModel> queryAllUserBackDictModel() { return baseMapper.queryAllUserBackDictModel(); } // @Override // public List<DictModel> queryTableDictItems(String table, String text, String code, String keyword) { // return baseMapper.queryTableDictItems(table, text, code, "%"+keyword+"%"); @@ -475,4 +477,37 @@ } } @Override @Cacheable(value = CacheConstant.SYS_DICT_TABLE_CACHE) public String queryTableDictByParams(String table, String text, String codes, String params) { log.info("æ ç¼ådictTable queryTableDictByKeysçæ¶åè°ç¨è¿éï¼"); String[] codeArr = codes.split("&&"); String[] paramArr = params.split("&&"); String subSql = ""; for (int i = 0; i < codeArr.length; i++) { String column = codeArr[i]; // é»è®¤åæ°ä¸ºç©ºå符串 String param = paramArr.length > i ? paramArr[i] : ""; if(column == null || ! Validator.isGeneral(column)){ log.error("<<<鿳忮µ:" + column); return null; } if(null == param || (!"-1".equals(param) && ! Validator.isGeneralWithChinese(param.replaceAll(" ", "")))){ log.error("<<<鿳忰:" + param); return null; } if(i != 0) subSql += " and "; subSql += column+" = '"+param+"'"; } return sysDictMapper.queryTableDictTextBySubSql(table,text,subSql); } @Override public List<Map> queryTableFieldByParams(String queryTable, String[] columns, String paramName, String[] paramValues) { String column = ArrayUtil.join(columns, ","); return this.baseMapper.queryTableFieldByParams(queryTable, column, paramName, paramValues); } }