package com.yihu.hos.standard.controller; import com.yihu.hos.config.JsonDateValueProcessor; import com.yihu.hos.core.constants.MicroServices; import com.yihu.hos.standard.model.standard.*; import com.yihu.hos.standard.service.standard.*; import com.yihu.hos.web.framework.model.standard.StandardVersion; import com.yihu.hos.web.framework.util.controller.BaseController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import net.sf.json.JSONArray; import net.sf.json.JsonConfig; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; import java.text.ParseException; import java.util.ArrayList; import java.util.Date; import java.util.List; @RestController("StdCenterEndPoint") @RequestMapping(value = MicroServices.ApiVersion.Version1_0+"/standardCenter") @Api(description = "获取标准列表相关接口") public class StdCenterEndPoint extends BaseController { @Autowired private STDVersionService stdVersionService; @Autowired private StdDatasetService stdDatasetService; @Autowired private StdMetadataService stdMetadataService; @Autowired private StdDictService stdDictService; @Autowired private StdDictEntryService stdDictEntryService; @Autowired private StdIndexService stdIndexService; @Autowired private StdRelationService stdRelationService; @Autowired private StandardService standardService; @Value("${org_code}") private String defaultOrgCode; @RequestMapping(value="/stdInfo/list",method = RequestMethod.GET) @ApiOperation(value = "获取版本列表", produces = "application/json", notes = "获取版本列表") public String getStdInfo(@ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "") @RequestParam(value = "filters", required = false) String filters) throws ParseException { List list = standardService.search(null, filters, null, null, null); JSONArray json = JSONArray.fromObject(list); return json.toString(); } @RequestMapping(value="/version/list",method = RequestMethod.GET) @ApiOperation(value = "获取版本号列表", produces = "application/json", notes = "获取版本号列表") public String getVersions(@ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "") @RequestParam(value = "filters", required = false) String filters) throws ParseException { List versions = stdVersionService.search(null, filters, null, null, null); JsonConfig config = new JsonConfig(); config.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor()); JSONArray json = JSONArray.fromObject(versions, config); return json.toString(); } @RequestMapping(value="/dataset/list",method = RequestMethod.GET) @ApiOperation(value = "获取数据集列表", produces = "application/json", notes = "获取数据集列表") public String getDatasetList(@ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "") @RequestParam(value = "filters", required = false) String filters, @ApiParam(name = "version", value = "版本", defaultValue = "") @RequestParam(value = "version") String version) throws IOException { List list = stdDatasetService.searchPage(StdDataSetModel.class, StandardVersion.DataSetTable,version, filters, null, null, null,true); JSONArray json = JSONArray.fromObject(list); return json.toString(); } @RequestMapping(value="/metadata/list",method = RequestMethod.GET) @ApiOperation(value = "获取数据元列表", produces = "application/json", notes = "获取数据元列表") public String getMetadataList(@ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "") @RequestParam(value = "filters", required = false) String filters, @ApiParam(name = "version", value = "版本", defaultValue = "") @RequestParam(value = "version") String version) throws IOException { List list = stdMetadataService.searchPage(StdMetaDataModel.class, StandardVersion.MetaDataTable,version, filters, null, null, null,true); JSONArray json = JSONArray.fromObject(list); return json.toString(); } @RequestMapping(value="/dict/list",method = RequestMethod.GET) @ApiOperation(value = "获取标准字典列表", produces = "application/json", notes = "获取标准字典列表") public String getDictList(@ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "") @RequestParam(value = "filters", required = false) String filters, @ApiParam(name = "version", value = "版本", defaultValue = "") @RequestParam(value = "version") String version) throws IOException { List list = stdDictService.searchPage(StdDictionaryModel.class, StandardVersion.DictTable,version, filters, null, null, null,true); JsonConfig config = new JsonConfig(); config.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor()); JSONArray json = JSONArray.fromObject(list, config); return json.toString(); } @RequestMapping(value="/dictItem/list",method = RequestMethod.GET) @ApiOperation(value = "获取标准字典项列表", produces = "application/json", notes = "获取标准字典项列表") public String getDictItemList(@ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "") @RequestParam(value = "filters", required = false) String filters, @ApiParam(name = "version", value = "版本", defaultValue = "") @RequestParam(value = "version") String version) throws IOException { List list = stdDictEntryService.searchPage(StdDictionaryEntryModel.class, StandardVersion.DictEntryTable,version, filters, null, null, null,true); JSONArray json = JSONArray.fromObject(list); return json.toString(); } @RequestMapping(value="/datasetIndex/list",method = RequestMethod.GET) @ApiOperation(value = "获取标准索引列表", produces = "application/json", notes = "获取标准索引列表") public String getDatasetIndexList(@ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "") @RequestParam(value = "filters", required = false) String filters, @ApiParam(name = "version", value = "版本", defaultValue = "") @RequestParam(value = "version") String version) throws IOException { List list = stdIndexService.searchPage(StdIndex.class, StandardVersion.StdIndexTable,version, filters, null, null, null,true); JSONArray json = JSONArray.fromObject(list); return json.toString(); } @RequestMapping(value="/relation/list",method = RequestMethod.GET) @ApiOperation(value = "获取版本号列表", produces = "application/json", notes = "获取版本号列表") public String getRelation(@ApiParam(name = "version", value = "版本", defaultValue = "") @RequestParam(value = "version") String version, @ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "") @RequestParam(value = "filters", required = false) String filters) throws IOException { List list = stdRelationService.searchPage(StdDatasetRelation.class, StandardVersion.StdRelationTable,version, filters, null, null, null,true); JSONArray json = JSONArray.fromObject(list); return json.toString(); } @RequestMapping(value="/lastDictItem/list",method = RequestMethod.GET) @ApiOperation(value = "根据字典code,获取健康之路最新的字典项", produces = "application/json", notes = "根据字典code,获取健康之路最新的字典项") public List getLastDictItem(@ApiParam(name = "code", value = "字典code", defaultValue = "") @RequestParam(value = "code") String code, @ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "") @RequestParam(value = "filters", required = false) String filters) throws IOException { List result = new ArrayList(); String ver = standardService.getLastStandByOrgCode(defaultOrgCode); if(StringUtils.isNotBlank(ver)){ List list = stdDictService.searchPage(StdDictionaryModel.class, StandardVersion.DictTable,ver, "code="+code, null, null, null,true); if(CollectionUtils.isNotEmpty(list)){ Long id = list.get(0).getId(); if(StringUtils.isBlank(filters)){ result = stdDictEntryService.searchPage(StdDictionaryEntryModel.class, StandardVersion.DictEntryTable,ver, "dictId="+id, null, null, null,true); }else{ result = stdDictEntryService.searchPage(StdDictionaryEntryModel.class, StandardVersion.DictEntryTable,ver, "dictId="+id+";"+filters, null, null, null,true); } } } return result; } }