Ver código fonte

获取全部字典

yzc 1 ano atrás
pai
commit
acf694350c

+ 10 - 4
hx-tenant/src/main/java/com/fjhx/tenant/controller/tenant/DictController.java

@@ -7,12 +7,10 @@ import com.fjhx.tenant.service.dict.DictTenantDataService;
 import com.ruoyi.common.annotation.TenantIgnore;
 import com.ruoyi.common.constant.BaseSourceConstant;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.Map;
 
 @DS(BaseSourceConstant.BASE)
 @TenantIgnore
@@ -31,4 +29,12 @@ public class DictController {
         return dictTenantDataService.getList(dto);
     }
 
+    /**
+     * 获取所有字典Map
+     */
+    @GetMapping("/allDictMap")
+    public Map<String, List<DictTenantDataVo>> getAllDictMap(DictTenantDataSelectDto dto) {
+        return dictTenantDataService.getAllDictMap(dto);
+    }
+
 }

+ 0 - 2
hx-tenant/src/main/java/com/fjhx/tenant/entity/dict/dto/DictTenantDataSelectDto.java

@@ -19,13 +19,11 @@ public class DictTenantDataSelectDto extends BaseSelectDto {
     /**
      * 字典编码
      */
-    @NotBlank(message = "字典编码不能为空")
     private String dictCode;
 
     /**
      * 租户id
      */
-    @NotBlank(message = "租户id不能为空")
     private String tenantId;
 
 }

+ 2 - 0
hx-tenant/src/main/java/com/fjhx/tenant/service/dict/DictTenantDataService.java

@@ -8,6 +8,7 @@ import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
 import com.fjhx.tenant.entity.dict.dto.DictTenantDataDto;
 
 import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -50,4 +51,5 @@ public interface DictTenantDataService extends BaseService<DictTenantData> {
      */
     List<DictTenantDataVo> getList(DictTenantDataSelectDto dto);
 
+    Map<String, List<DictTenantDataVo>> getAllDictMap(DictTenantDataSelectDto dto);
 }

+ 9 - 0
hx-tenant/src/main/java/com/fjhx/tenant/service/dict/impl/DictTenantDataServiceImpl.java

@@ -19,7 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 
 /**
@@ -149,4 +151,11 @@ public class DictTenantDataServiceImpl extends ServiceImpl<DictTenantDataMapper,
         return baseMapper.getList(dto);
     }
 
+    @Override
+    public Map<String, List<DictTenantDataVo>> getAllDictMap(DictTenantDataSelectDto dto) {
+        List<DictTenantDataVo> list = baseMapper.getList(dto);
+        Map<String, List<DictTenantDataVo>> allDictMap = list.stream().collect(Collectors.groupingBy(DictTenantData::getDictCode));
+        return allDictMap;
+    }
+
 }

+ 24 - 4
hx-tenant/src/main/resources/mapper/dict/DictTenantDataMapper.xml

@@ -13,28 +13,48 @@
     <sql id="list">
         select t.id,
                t.type,
+               t.dict_code,
                t.dict_key,
                t.dict_value,
                t.sort,
                t.tenant_id
-        from ((select t.id,
+        from (
+               (select t.id,
                       1 type,
+                      t.dict_code,
                       t.dict_key,
                       t.dict_value,
                       t.sort,
                       '000000' tenant_id
                from dict_common_data t
-               where t.dict_code = #{dto.dictCode})
+               <where>
+                   <if test="dto.dictCode != null and dto.dictCode != ''">
+                        t.dict_code = #{dto.dictCode}
+                   </if>
+               </where>
+               )
               union all
               (select t.id,
                       2 type,
+                      t.dict_code,
                       t.dict_key,
                       t.dict_value,
                       t.sort,
                       t.tenant_id
                from dict_tenant_data t
-               where t.dict_code = #{dto.dictCode}
-                 and t.tenant_id = #{dto.tenantId})) t
+                <where>
+                    <if test="dto.dictCode != null and dto.dictCode != ''">
+                        t.dict_code = #{dto.dictCode}
+                    </if>
+                    <if test="dto.dictCode != null and dto.dictCode != '' and dto.tenantId != null and dto.tenantId != ''">
+                        and
+                    </if>
+                    <if test="dto.tenantId != null and dto.tenantId != ''">
+                        t.tenant_id = #{dto.tenantId}
+                    </if>
+                </where>
+               )
+              ) t
         order by t.sort asc
     </sql>