@@ -81,4 +81,11 @@ public class DictController extends MyValidController { | |||
DictItemUpdateResponse response = dictItemManager.updateDictItem(req); | |||
return ApiResponse.of(response); | |||
} | |||
@ApiOperation(value = "2-4.字典项目获取所有") | |||
@PostMapping(value = "/itemGetAll") | |||
public ApiResponse<DictItemGetAllResponse> itemGetAll(@RequestBody @Valid DictItemGetAllRequest req) throws ManagerException { | |||
DictItemGetAllResponse response = dictItemManager.getAllDictItem(req); | |||
return ApiResponse.of(response); | |||
} | |||
} |
@@ -9,5 +9,5 @@ public interface DictItemManager { | |||
DictItemAddResponse createDictItem(DictItemAddRequest req) throws ManagerException; | |||
DictItemUpdateResponse updateDictItem(DictItemUpdateRequest req) throws ManagerException; | |||
DictItemDeleteResponse deleteDictItem(DictItemDeleteRequest req) throws ManagerException; | |||
DictItemGetAllResponse getAllDictItem(DictItemGetAllRequest typeId) throws ManagerException; | |||
} |
@@ -112,4 +112,22 @@ public class DictItemManagerImpl extends AbstractManager implements DictItemMana | |||
dictItemModel.setOrder(dictItem.getItemOrder()); | |||
return dictItemModel; | |||
} | |||
@Override | |||
public DictItemGetAllResponse getAllDictItem(DictItemGetAllRequest req) throws ManagerException { | |||
DictItemGetAllResponse res = new DictItemGetAllResponse(); | |||
Map<String, List<DictItemModel>> dictTypeModels = Maps.newHashMap(); | |||
List<DictType> dictTypes = dictTypeRepo.findAll(); | |||
for (DictType dictType : dictTypes) { | |||
List<DictItem> dictItemList = dictItemRepo.findByTypeId(dictType.getId()); | |||
if (dictItemList == null) | |||
throw new ManagerException("未查询到对应数据,请检查参数!"); | |||
List<DictItemModel> dictItemModels = | |||
dictItemList.stream().map(DictItemModel::fromDictItem).collect(Collectors.toList()); | |||
dictTypeModels.put(dictType.getCode(), dictItemModels); | |||
} | |||
res.setDictTypeAndItem(dictTypeModels); | |||
return res; | |||
} | |||
} |