StandardVersionController.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package com.yihu.hos.standard.controller;
  2. import com.yihu.hos.web.framework.model.ActionResult;
  3. import com.yihu.hos.web.framework.model.DictionaryResult;
  4. import com.yihu.hos.web.framework.model.Result;
  5. import com.yihu.hos.web.framework.util.controller.BaseController;
  6. import com.yihu.hos.standard.service.standard.StandardVersionService;
  7. import io.swagger.annotations.Api;
  8. import io.swagger.annotations.ApiOperation;
  9. import io.swagger.annotations.ApiParam;
  10. import org.springframework.web.bind.annotation.*;
  11. import org.springframework.web.multipart.MultipartFile;
  12. import javax.annotation.Resource;
  13. /**
  14. * Created by LLH on 2016/1/6.
  15. */
  16. @RestController("StandardVersionController")
  17. @RequestMapping("/standardCenter")
  18. @Api(protocols = "https", value = "StandardVersionController", description = "标准版本管理", tags = {"标准版本"})
  19. public class StandardVersionController extends BaseController {
  20. @Resource(name = StandardVersionService.BEAN_ID)
  21. private StandardVersionService standardVersionService;
  22. /**
  23. * 根据版本id获取标准版本信息(get)
  24. * @param versionId
  25. * @return
  26. * @throws Exception
  27. */
  28. @RequestMapping("/getForVersionId")
  29. @ApiOperation(value = "获取标准版本", response = Result.class, produces = "application/json", notes = "获取标准版本")
  30. public Result getForVersionId(
  31. @ApiParam(name = "versionId", value = "标准版本ID")
  32. @RequestParam(value = "versionId") Integer versionId) {
  33. return standardVersionService.get(versionId);
  34. }
  35. /**
  36. * 新增版本(post)
  37. * @param version
  38. * @return
  39. * @throws Exception
  40. */
  41. @RequestMapping("/addVersion")
  42. @ApiOperation(value = "保存标准版本", response = Result.class, produces = "application/json", notes = "保存标准版本")
  43. public Result addVersion(
  44. @ApiParam(name = "version", value = "标准版本信息")
  45. @RequestParam(value = "version") String version) throws Exception {
  46. return standardVersionService.add(version);
  47. }
  48. /**
  49. * 修改版本(put)
  50. * @param version
  51. * @return
  52. * @throws Exception
  53. */
  54. @RequestMapping("/updateVersion")
  55. @ApiOperation(value = "修改版本", response = Result.class, produces = "application/json", notes = "修改版本")
  56. public Result updateVersion(
  57. @ApiParam(name = "version", value = "标准版本")
  58. @RequestParam(value = "version") String version) throws Exception {
  59. return standardVersionService.update(version);
  60. }
  61. /**
  62. * 发布版本(post)
  63. * @param versionId
  64. * @param publisher
  65. * @return
  66. * @throws Exception
  67. */
  68. @RequestMapping("/publishVersion")
  69. @ApiOperation(value = "发布版本", response = Result.class, produces = "application/json", notes = "发布版本")
  70. public Result publish(
  71. @ApiParam(name = "versionId", value = "标准版本ID")
  72. @RequestParam(value = "versionId") Integer versionId,
  73. @ApiParam(name = "publisher", value = "发布者")
  74. @RequestParam(value = "publisher") String publisher) throws Exception {
  75. return standardVersionService.publish(versionId, publisher);
  76. }
  77. /**
  78. * 删除版本(put)
  79. * @param versionId
  80. * @return
  81. * @throws Exception
  82. */
  83. @RequestMapping("/deleteVersion")
  84. @ApiOperation(value = "删除版本", response = Result.class, produces = "application/json", notes = "删除版本")
  85. public Result delete(
  86. @ApiParam(name = "versionId", value = "标准版本ID")
  87. @RequestParam(value = "versionId") Integer versionId,
  88. @ApiParam(name = "version", value = "标准版本值")
  89. @RequestParam(value = "version") String version) throws Exception {
  90. return standardVersionService.delete(versionId,version);
  91. }
  92. /**
  93. * 获取基础版本名称列表
  94. * @param standardId
  95. * @return
  96. * @throws Exception
  97. */
  98. @RequestMapping("/getVersions")
  99. @ApiOperation(value = "获取标准版本列表", response = DictionaryResult.class, produces = "application/json", notes = "获取标准版本列表")
  100. public DictionaryResult getVersions(
  101. @ApiParam(name = "standardId", value = "标准ID")
  102. @RequestParam(value = "standardId") Integer standardId,
  103. @ApiParam(name = "condition", value = "Must be Json")
  104. @RequestParam(value = "condition", required = false) String condition,
  105. @ApiParam(name = "order", value = "Must be Json")
  106. @RequestParam(value = "order", required = false) String order,
  107. @ApiParam(name = "rows", value = "Limit the size of result set. Must be an integer")
  108. @RequestParam(value = "rows", required = false) Integer rows,
  109. @ApiParam(name = "page", value = "Start position of result set. Must be an integer")
  110. @RequestParam(value = "page", required = false) Integer page) {
  111. return standardVersionService.getDetailResultModelList(standardId, condition, order, rows, page);
  112. }
  113. /**
  114. * 根据类型文件上传保存对应的数据
  115. *
  116. * @param type
  117. * @param file
  118. * @return
  119. * @throws Exception
  120. */
  121. @ResponseBody
  122. @RequestMapping(value = "/importFile", method = RequestMethod.POST)
  123. @ApiOperation(value = "根据type导入数据接口", response = Object.class, produces = "application/json", notes = "导入数据接口")
  124. public Result importFile(@ApiParam(value = "类型(1:数据集 2:字典 3:机构数据 4:机构字典)", required = true) @RequestParam("type") String type,
  125. @ApiParam(value = "项目版本", required = true) @RequestParam("version") String version,
  126. @ApiParam(value = "项目版本", required = true) @RequestParam("standardId") Integer standardId,
  127. @ApiParam(value = "文件", required = true, allowMultiple = true) @RequestParam("file") MultipartFile file) throws Exception {
  128. ActionResult actionResult = new ActionResult();
  129. try {
  130. String id = "";
  131. //根據类别判断上传的文件1:数据集 2:字典
  132. if("1".equals(type)){
  133. version = standardVersionService.saveDatasetExcel(file, version,standardId);
  134. }else {
  135. version = standardVersionService.saveDictExcel(file, version,standardId);
  136. }
  137. //解析excel文件 保存
  138. actionResult.setData("{\"version\":\"" + version + "\"}");
  139. } catch (Exception e) {
  140. e.printStackTrace();
  141. return Result.error(e.getMessage());
  142. }
  143. return actionResult;
  144. }
  145. @ResponseBody
  146. @RequestMapping(value = "/isUpdateDatasetAndDict", method = RequestMethod.POST)
  147. @ApiOperation(value = "项目列表", response = Object.class, produces = "application/json", notes = "项目列表")
  148. public Result isUpdateDatasetAndDict(
  149. @RequestParam(required = true) String version) throws Exception {
  150. ActionResult actionResult = new ActionResult();
  151. try {
  152. actionResult.setData(standardVersionService.isUpdateDatasetAndDict(version));
  153. } catch (Exception e) {
  154. e.printStackTrace();
  155. return Result.error(e.getMessage());
  156. }
  157. return actionResult;
  158. }
  159. /**
  160. * 根据类型和主键删除数据
  161. *
  162. * @param type
  163. * @param id
  164. * @return
  165. * @throws Exception
  166. */
  167. @ResponseBody
  168. @RequestMapping(value = "/deleteByType", method = RequestMethod.POST)
  169. @ApiOperation(value = "文件上传成功后的删除", response = Object.class, produces = "application/json", notes = "文件上传成功后的删除")
  170. public Result deleteByType(
  171. @ApiParam(value = "类型(1:数据集 2:字典 )", required = true) @RequestParam("type") String type,
  172. @ApiParam(value = "主键(上传成功后返回的ID)", required = true) @RequestParam("version") String version) throws Exception {
  173. ActionResult actionResult = new ActionResult();
  174. try {
  175. //根據类别判断上传的文件1:数据集 2:字典 删除数据
  176. switch (type) {
  177. case "1": {
  178. standardVersionService.deleteDataset(version);
  179. break;
  180. }
  181. case "2": {
  182. standardVersionService.deleteDict(version);
  183. break;
  184. }
  185. }
  186. } catch (Exception e) {
  187. return Result.error(e.getMessage());
  188. }
  189. return actionResult;
  190. }
  191. }