diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java index c0a47974f..6dfb57aec 100644 --- a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java @@ -5,6 +5,7 @@ import cn.iocoder.mall.admin.api.bo.DataDictBO; import cn.iocoder.mall.admin.api.dto.DataDictAddDTO; import cn.iocoder.mall.admin.api.dto.DataDictUpdateDTO; +import java.util.Collection; import java.util.List; public interface DataDictService { @@ -17,5 +18,25 @@ public interface DataDictService { CommonResult deleteDataDict(Integer adminId, Integer dataDictId); + /** + * 获取字典值 - 单个 + * + * 注意: dictValue:Object 为了方便调用,会自动转换为 dictValue:String + * + * @param dictKey + * @param dictValue + * @return + */ CommonResult getDataDict(String dictKey, Object dictValue); + + /** + * 获取字典值 - 多个 + * + * 注意:dictValueList:? 为了方便调用,会自动转换为 Set:String + * + * @param dictKey + * @param dictValueList + * @return + */ + CommonResult> getDataDictList(String dictKey, Collection dictValueList); } diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java index 2468358db..381634363 100644 --- a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java @@ -4,6 +4,7 @@ import cn.iocoder.mall.admin.dataobject.DataDictDO; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; +import java.util.Collection; import java.util.List; @Repository @@ -11,8 +12,16 @@ public interface DataDictMapper { DataDictDO selectById(@Param("id") Integer id); - DataDictDO selectByEnumValueAndValue(@Param("enumValue") String enumValue, - @Param("value") String value); + DataDictDO selectByEnumValueAndValue( + @Param("enumValue") String enumValue, + @Param("value") String value + ); + + List selectByEnumValueAndValues( + @Param("enumValue") String enumValue, + @Param("values") Collection values + ); + List selectList(); diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java index 663d7fc75..f15e1dde4 100644 --- a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java @@ -14,8 +14,11 @@ import cn.iocoder.mall.admin.dataobject.DataDictDO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * 数据字典 Service @@ -93,4 +96,12 @@ public class DataDictServiceImpl implements DataDictService { DataDictBO dataDictBO = DataDictConvert.INSTANCE.convert(dataDictDO); return CommonResult.success(dataDictBO); } + + @Override + public CommonResult> getDataDictList(String dictKey, Collection dictValueList) { + Set convertDictValueList = dictValueList.stream().map(o -> String.valueOf(o)).collect(Collectors.toSet()); + List dataDictDOList = dataDictMapper.selectByEnumValueAndValues(dictKey, convertDictValueList); + List dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList); + return CommonResult.success(dataDictBOList); + } } \ No newline at end of file diff --git a/admin/admin-service-impl/src/main/resources/mapper/DataDictMapper.xml b/admin/admin-service-impl/src/main/resources/mapper/DataDictMapper.xml index 5aad44a5d..d272e102b 100644 --- a/admin/admin-service-impl/src/main/resources/mapper/DataDictMapper.xml +++ b/admin/admin-service-impl/src/main/resources/mapper/DataDictMapper.xml @@ -17,6 +17,19 @@ LIMIT 1 + + +