ConfigController.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package com.example.controller;
  2. import com.example.controller.response.ErrorRes;
  3. import com.example.controller.response.NormalRes;
  4. import com.example.controller.response.Response;
  5. import com.example.controller.vo.ConfigVO;
  6. import com.example.entity.Config;
  7. import com.example.services.ConfigService;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.*;
  11. import java.util.List;
  12. /**
  13. * Created by twenbo on 2016/11/16. Changed by lucas on 2017/04/24.
  14. */
  15. @Slf4j
  16. @RestController
  17. @RequestMapping("/api/config")
  18. public class ConfigController {
  19. @Autowired
  20. private ConfigService configService;
  21. /**
  22. * @param configVO
  23. * @return
  24. */
  25. @PostMapping(value = "/add")
  26. public Response addConfig(@RequestBody ConfigVO configVO) {
  27. try {
  28. String rsl = configService.addConfig(configVO);
  29. return rsl != null ? new NormalRes(rsl) : new ErrorRes(40002, "Server error.");
  30. } catch (Exception e) {
  31. e.printStackTrace();
  32. return new ErrorRes();
  33. }
  34. }
  35. /**
  36. * @param userId
  37. * @return
  38. */
  39. @GetMapping(value = "/get/all")
  40. public Response getAllConfig(@RequestParam(value = "userId", required = false) String userId) {
  41. try {
  42. return new NormalRes(configService.getAllConfigs(Integer.parseInt(userId)));
  43. } catch (Exception e) {
  44. e.printStackTrace();
  45. return new ErrorRes();
  46. }
  47. }
  48. /**
  49. * @param userId
  50. * @return
  51. */
  52. @GetMapping(value = "/get/all_new")
  53. public Response getAllConfig_new(@RequestParam(value = "userId", required = false) String userId) {
  54. try {
  55. return new NormalRes(configService._getAllConfigsByUserId(Integer.parseInt(userId)));
  56. } catch (Exception e) {
  57. e.printStackTrace();
  58. return new ErrorRes();
  59. }
  60. }
  61. /**
  62. * @param configId
  63. * @return
  64. */
  65. @GetMapping(value = "/get/one/config")
  66. public Response getOneConfig(@RequestParam(value = "configId", required = false) String configId) {
  67. try {
  68. return new NormalRes(configService.getConfigInfoByConfigId(Integer.parseInt(configId)));
  69. } catch (Exception e) {
  70. e.printStackTrace();
  71. return new ErrorRes();
  72. }
  73. }
  74. /**
  75. * @param configId
  76. * @param confName
  77. * @param trainFeatureList
  78. * @return
  79. */
  80. @GetMapping(value = "/change")
  81. public Response changeConfig(@RequestParam(value = "configId", required = false) String configId,
  82. @RequestParam(value = "confName") String confName,
  83. @RequestParam(value = "trainFeatureList") List<String> trainFeatureList) {
  84. try {
  85. boolean rsl = configService.changeConfig(Integer.parseInt(configId), confName, trainFeatureList);
  86. return rsl ? new NormalRes() : new ErrorRes(40002, "Server error.");
  87. } catch (Exception e) {
  88. e.printStackTrace();
  89. return new ErrorRes();
  90. }
  91. }
  92. /**
  93. *
  94. * @param configId
  95. * @return
  96. */
  97. @GetMapping(value = "/delete")
  98. public Response deleteModelByConfigId(@RequestParam(value = "configId", required = false) String configId) {
  99. try {
  100. return new NormalRes(configService.deleteConfigById(Integer.parseInt(configId)));
  101. } catch (Exception e) {
  102. e.printStackTrace();
  103. return new ErrorRes();
  104. }
  105. }
  106. /**
  107. * @param fileId
  108. * @param fieldName
  109. * @return
  110. */
  111. @GetMapping(value = "/get/features")
  112. public Response getFeatureSelection(@RequestParam(value = "fileId", required = false) String fileId,
  113. @RequestParam(value = "fieldName", required = false) String fieldName) {
  114. try {
  115. return new NormalRes(configService.getSelectedFeature(Integer.parseInt(fileId), fieldName));
  116. } catch (Exception e) {
  117. e.printStackTrace();
  118. return new ErrorRes();
  119. }
  120. }
  121. }