StdDictController.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package com.yihu.hos.standard.controller;
  2. import com.fasterxml.jackson.core.JsonProcessingException;
  3. import com.fasterxml.jackson.databind.ObjectMapper;
  4. import com.yihu.hos.core.datatype.StringUtil;
  5. import com.yihu.hos.standard.model.standard.StdDictionaryModel;
  6. import com.yihu.hos.standard.service.standard.StdDictService;
  7. import com.yihu.hos.web.framework.model.DetailModelResult;
  8. import com.yihu.hos.web.framework.model.DictionaryResult;
  9. import com.yihu.hos.web.framework.model.Result;
  10. import com.yihu.hos.web.framework.util.controller.BaseController;
  11. import io.swagger.annotations.ApiOperation;
  12. import io.swagger.annotations.ApiParam;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import javax.annotation.Resource;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. /**
  21. * Created by LLH on 2016/1/6.
  22. */
  23. @RestController("StdDictController")
  24. @RequestMapping("/standardCenter")
  25. //@Api(protocols = "https", value = "StdDictController", description = "标准字典管理", tags = {"标准字典"})
  26. public class StdDictController extends BaseController {
  27. @Resource(name = StdDictService.BEAN_ID)
  28. StdDictService stdDictService;
  29. /**
  30. * 查询字典列表信息(get)
  31. * @param stdVersion
  32. * @param condition
  33. * @param order
  34. * @param rows
  35. * @param page
  36. * @return
  37. * @throws Exception
  38. */
  39. @RequestMapping("/searchDictList")
  40. @ApiOperation(value = "获取字典列表", response = DetailModelResult.class, produces = "application/json", notes = "获取字典列表")
  41. public DetailModelResult getDictList(
  42. @ApiParam(name = "stdVersion", value = "标准版本号")
  43. @RequestParam(value = "stdVersion") String stdVersion,
  44. @ApiParam(name = "condition", value = "查询条件:编码或名称")
  45. @RequestParam(value = "condition", required = false) String condition,
  46. @ApiParam(name = "order", value = "Order param,Must be json.ascending:asc,descending:desc")
  47. @RequestParam(value = "order", required = false) String order,
  48. @ApiParam(name = "rows", value = "Limit the size of result set. Must be an integer")
  49. @RequestParam(value = "rows", required = false) Integer rows,
  50. @ApiParam(name = "page", value = "Start position of result set. Must be an integer")
  51. @RequestParam(value = "page", required = false) Integer page) {
  52. return stdDictService.getDetailModelList(stdVersion, condition, order, rows, page);
  53. }
  54. @RequestMapping("/getForDictId")
  55. @ApiOperation(value = "获取字典", response = Result.class, produces = "application/json", notes = "获取字典")
  56. public Result get(
  57. @ApiParam(name = "stdVersion", value = "stdVersion")
  58. @RequestParam(value = "stdVersion") String stdVersion,
  59. @ApiParam(name = "dictId", value = "字典ID")
  60. @RequestParam(value = "dictId") Integer dictId) {
  61. return stdDictService.get(stdVersion, dictId);
  62. }
  63. @RequestMapping("/delDict")
  64. @ApiOperation(value = "删除字典", response = Result.class, produces = "application/json", notes = "删除字典")
  65. public Result delete(
  66. @ApiParam(name = "stdVersion", value = "stdVersion")
  67. @RequestParam(value = "stdVersion") String stdVersion,
  68. @ApiParam(name = "dictId", value = "字典ID")
  69. @RequestParam(value = "dictId") Integer dictId) {
  70. return stdDictService.delete(stdVersion, dictId);
  71. }
  72. @RequestMapping("/updateDict")
  73. @ApiOperation(value = "修改字典", response = Result.class, produces = "application/json", notes = "修改字典")
  74. public Result modify(
  75. @ApiParam(name = "stdVersion", value = "stdVersion")
  76. @RequestParam(value = "stdVersion") String stdVersion,
  77. @ApiParam(name = "dict", value = "字典")
  78. @RequestParam(value = "dict") String dict) {
  79. return stdDictService.update(stdVersion, dict);
  80. }
  81. @RequestMapping("/addDict")
  82. @ApiOperation(value = "保存字典", response = Result.class, produces = "application/json", notes = "保存字典")
  83. public Result addDict(
  84. @ApiParam(name = "stdVersion", value = "stdVersion")
  85. @RequestParam(value = "stdVersion") String stdVersion,
  86. @ApiParam(name = "dict", value = "字典")
  87. @RequestParam(value = "dict") String dict) {
  88. return stdDictService.add(stdVersion, dict);
  89. }
  90. @RequestMapping(value="/getDictCodeValues")
  91. @ApiOperation(value = "获取字典下拉框信息", response = DetailModelResult.class, produces = "application/json", notes = "获取字典下拉框信息")
  92. public DetailModelResult getSelectList(
  93. @ApiParam(name = "stdVersion", value = "标准版本号")
  94. @RequestParam(value = "stdVersion") String stdVersion,
  95. @ApiParam(name = "q", value = "数据集名称或编码", required = false)
  96. @RequestParam(value = "q", required = false) String q,
  97. @ApiParam(name = "initVal", value = "初始化数据集名称或编码", required = false)
  98. @RequestParam(value = "initVal", required = false) String initVal,
  99. @ApiParam(name = "order", value = "Order param,Must be json.ascending:asc,descending:desc")
  100. @RequestParam(value = "order", required = false) String order,
  101. @ApiParam(name = "rows", value = "Limit the size of result set. Must be an integer")
  102. @RequestParam(value = "rows", required = false) Integer rows,
  103. @ApiParam(name = "page", value = "Start position of result set. Must be an integer")
  104. @RequestParam(value = "page", required = false) Integer page) {
  105. Map<String,String> condition = new HashMap<String,String>();
  106. if(!StringUtil.isEmpty(q)){
  107. condition.put("name", q);
  108. }
  109. else if(!StringUtil.isEmpty(initVal)){
  110. condition.put("initVal", initVal);//默认值
  111. }
  112. ObjectMapper mapper = new ObjectMapper();
  113. String conditionStr = null;
  114. try {
  115. conditionStr = mapper.writeValueAsString(condition);
  116. } catch (JsonProcessingException e) {
  117. e.printStackTrace();
  118. }
  119. List<StdDictionaryModel> dictList = stdDictService.getDictList(StdDictionaryModel.class, stdVersion, conditionStr, order, rows, 0);
  120. return stdDictService.getDictSelectList(dictList);
  121. }
  122. /**
  123. * 获取对应字典/参考字典列表
  124. * @param stdVersion
  125. * @return
  126. * @throws Exception
  127. */
  128. @RequestMapping("/getDicts")
  129. @ApiOperation(value = "获取字典列表", response = DictionaryResult.class, produces = "application/json", notes = "获取字典列表")
  130. public DictionaryResult getList(
  131. @ApiParam(name = "stdVersion", value = "stdVersion")
  132. @RequestParam(value = "stdVersion") String stdVersion,
  133. @ApiParam(name = "condition", value = "Must be Json")
  134. @RequestParam(value = "condition", required = false) String condition,
  135. @ApiParam(name = "order", value = "Must be Json")
  136. @RequestParam(value = "order", required = false) String order,
  137. @ApiParam(name = "rows", value = "Limit the size of result set. Must be an integer")
  138. @RequestParam(value = "rows", required = false) Integer rows,
  139. @ApiParam(name = "page", value = "Start position of result set. Must be an integer")
  140. @RequestParam(value = "page", required = false) Integer page) {
  141. return stdDictService.getDictionaryList(stdVersion, condition, order, rows, page);
  142. }
  143. }