jihs 3 lat temu
rodzic
commit
88c37d759d

+ 2 - 0
jeecg-boot/jeecg-boot-base-common/src/main/java/org/jeecg/common/system/vo/DictModel.java

@@ -2,6 +2,7 @@ package org.jeecg.common.system.vo;
 
 import java.io.Serializable;
 
+import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 
 import lombok.Data;
@@ -12,6 +13,7 @@ import lombok.experimental.Accessors;
 @EqualsAndHashCode(callSuper = false)
 @Accessors(chain = true)
 @JsonIgnoreProperties(ignoreUnknown = true)
+@TableName(value = "dict_model")
 public class DictModel implements Serializable{
 	private static final long serialVersionUID = 1L;
 

+ 56 - 0
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysDictController.java

@@ -2,15 +2,19 @@ package org.jeecg.modules.system.controller;
 
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.constant.CacheConstant;
 import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.system.vo.DictModel;
 import org.jeecg.common.system.vo.LoginUser;
@@ -19,6 +23,7 @@ import org.jeecg.common.util.SqlInjectionUtil;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.system.entity.SysDict;
 import org.jeecg.modules.system.entity.SysDictItem;
+import org.jeecg.modules.system.entity.dto.DictModelDTO;
 import org.jeecg.modules.system.model.SysDictTree;
 import org.jeecg.modules.system.model.TreeSelectModel;
 import org.jeecg.modules.system.service.ISysDictItemService;
@@ -33,6 +38,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -515,4 +521,54 @@ public class SysDictController {
 		return result;
 	}
 
+
+	/**
+	 * 获取字典数据
+	 * @param dictCode 字典code
+	 * @param dictCode 表名,文本字段,code字段  | 举例:sys_user,realname,id
+	 * @return
+	 */
+	@RequestMapping(value = "/getDictItems/getDictList", method = RequestMethod.POST)
+	public Result<DictModelDTO> getDictList(@RequestBody List<String> dictCode) {
+		log.info(" dictCode : "+ dictCode);
+		Result<DictModelDTO> result = new Result<DictModelDTO>();
+		List<DictModel> ls = null;
+		try {
+			 if(CollectionUtils.isEmpty(dictCode)){
+				 result.error500("dictCode的值不能为空");
+				 return result;
+			 }
+			 List<SysDict> sysDictList = sysDictService.list(new LambdaQueryWrapper<SysDict>().in(SysDict::getDictCode, dictCode));
+			if(CollectionUtils.isEmpty(sysDictList)){
+				result.error500("没查到相关数据");
+				return result;
+			}
+			List<String> ids = sysDictList.stream().map(t -> t.getId()).collect(Collectors.toList());
+			Map<String, String> idMap = sysDictList.stream().collect(Collectors.toMap(t -> t.getId(), t-> t.getDictCode()));
+			Map<String, List<DictModel>> map = Maps.newHashMap();
+			for(String id : ids){
+				List<SysDictItem> sysDictItems = sysDictItemService.list(new LambdaQueryWrapper<SysDictItem>().eq(SysDictItem::getDictId, id));
+				List<DictModel> dictModels = new ArrayList<DictModel>();
+//				sysDictItem.parallelStream().reduce((a, b) -> new DictModel(a.getItemValue(), a.getItemText())).ifPresent(dictModels::add);
+				for(SysDictItem sysDictItem : sysDictItems){
+					dictModels.add(new DictModel(sysDictItem.getItemValue(), sysDictItem.getItemText()));
+				}
+				map.put(idMap.get(id), dictModels);
+
+			}
+
+			result.setSuccess(true);
+			result.setResult(new DictModelDTO(map));
+			log.info(result.toString());
+		} catch (Exception e) {
+			log.error(e.getMessage(),e);
+			result.error500(e.getMessage());
+			return result;
+		}
+
+		return result;
+	}
+
+
+
 }

+ 2 - 0
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/entity/SysDictItem.java

@@ -7,6 +7,7 @@ import java.util.Date;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 
+import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
@@ -24,6 +25,7 @@ import org.jeecgframework.poi.excel.annotation.Excel;
 @Data
 @EqualsAndHashCode(callSuper = false)
 @Accessors(chain = true)
+@TableName("sys_dict_item")
 public class SysDictItem implements Serializable {
 
     private static final long serialVersionUID = 1L;

+ 18 - 0
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/entity/dto/DictModelDTO.java

@@ -0,0 +1,18 @@
+package org.jeecg.modules.system.entity.dto;
+
+import lombok.Data;
+import org.jeecg.common.system.vo.DictModel;
+import java.util.List;
+import java.util.Map;
+
+@Data
+public class DictModelDTO {
+    Map<String, List<DictModel>> dicList;
+
+    public DictModelDTO() {
+    }
+
+    public DictModelDTO(Map<String, List<DictModel>> dicList) {
+        this.dicList = dicList;
+    }
+}