AdapterDictController.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package com.yihu.hos.standard.controller;
  2. import com.yihu.hos.standard.match.dictionary.DictItemStrategyExecute;
  3. import com.yihu.hos.standard.service.adapter.AdapterDictService;
  4. import com.yihu.hos.web.framework.model.ActionResult;
  5. import com.yihu.hos.web.framework.model.DetailModelResult;
  6. import com.yihu.hos.web.framework.model.Result;
  7. import com.yihu.hos.web.framework.util.controller.BaseController;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.annotations.ApiOperation;
  10. import io.swagger.annotations.ApiParam;
  11. import org.springframework.web.bind.annotation.*;
  12. import javax.annotation.Resource;
  13. /**
  14. * Created by LLH on 2016/1/6.
  15. */
  16. @RestController("AdapterDictController")
  17. @RequestMapping("/adapterCenter")
  18. @Api(protocols = "https", value = "AdapterDictController", description = "适配字典管理", tags = {"适配字典"})
  19. public class AdapterDictController extends BaseController {
  20. @Resource(name = AdapterDictService.BEAN_ID)
  21. private AdapterDictService dictService;
  22. /**
  23. * 查询字典列表信息(get)
  24. * @param adapterVersion
  25. * @param condition
  26. * @param order
  27. * @param rows
  28. * @param page
  29. * @return
  30. * @throws Exception
  31. */
  32. @RequestMapping(value = "/searchDictList")
  33. @ApiOperation(value = "获取字典列表", response = DetailModelResult.class, produces = "application/json", notes = "获取字典列表")
  34. public DetailModelResult searchDictList(
  35. @ApiParam(name = "adapterVersion", value = "适配标准版本号")
  36. @RequestParam(value = "adapterVersion") String adapterVersion,
  37. @ApiParam(name = "condition", value = "查询条件:编码或名称")
  38. @RequestParam(value = "condition", required = false) String condition,
  39. @ApiParam(name = "order", value = "Order param,Must be json.ascending:asc,descending:desc")
  40. @RequestParam(value = "order", required = false) String order,
  41. @ApiParam(name = "rows", value = "Limit the size of result set. Must be an integer")
  42. @RequestParam(value = "rows", required = false) Integer rows,
  43. @ApiParam(name = "page", value = "Start position of result set. Must be an integer")
  44. @RequestParam(value = "page", required = false) Integer page) {
  45. return dictService.getDetailResult(adapterVersion, condition, order, rows, page);
  46. }
  47. @RequestMapping(value = "/getForDictId")
  48. @ApiOperation(value = "获取字典", response = Result.class, produces = "application/json", notes = "获取字典")
  49. public Result get(
  50. @ApiParam(name = "adapterVersion", value = "标准版本号")
  51. @RequestParam(value = "adapterVersion") String adapterVersion,
  52. @ApiParam(name = "dictId", value = "字典ID")
  53. @RequestParam(value = "dictId") Integer dictId) {
  54. return dictService.get(adapterVersion, dictId);
  55. }
  56. @RequestMapping(value = "/delDict")
  57. @ApiOperation(value = "删除字典", produces = "application/json", notes = "删除字典")
  58. public void delDict(
  59. @ApiParam(name = "adapterVersion", value = "标准版本号")
  60. @RequestParam(value = "adapterVersion") String adapterVersion,
  61. @ApiParam(name = "dictId", value = "字典ID")
  62. @RequestParam(value = "dictId") Integer dictId) {
  63. dictService.delete(adapterVersion, dictId);
  64. }
  65. @RequestMapping(value = "/updateDict")
  66. @ApiOperation(value = "修改字典", response = Result.class, produces = "application/json", notes = "修改字典")
  67. public Result updateDict(
  68. @ApiParam(name = "adapterVersion", value = "标准版本号")
  69. @RequestParam(value = "adapterVersion") String adapterVersion,
  70. @ApiParam(name = "dict", value = "字典")
  71. @RequestParam(value = "dict") String dict) {
  72. return dictService.modify(adapterVersion, dict);
  73. }
  74. @RequestMapping(value = "/addDict")
  75. @ApiOperation(value = "保存字典", response = Result.class, produces = "application/json", notes = "保存字典")
  76. public Result addDict(
  77. @ApiParam(name = "adapterVersion", value = "标准版本号")
  78. @RequestParam(value = "adapterVersion") String adapterVersion,
  79. @ApiParam(name = "dict", value = "字典")
  80. @RequestParam(value = "dict") String dict) {
  81. return dictService.add(adapterVersion, dict);
  82. }
  83. @RequestMapping(value = "/isStrategyDic", method = RequestMethod.POST , produces = "application/json")
  84. @ResponseBody
  85. @ApiOperation(value = "是否智能匹配", response = Object.class, produces = "application/json", notes = "是否智能匹配")
  86. public Result isStrategy(
  87. @ApiParam(value = "匹配version", required = true) @RequestParam("version") String version
  88. ) throws Exception {
  89. ActionResult actionResult = new ActionResult();
  90. try {
  91. actionResult.setData("{\"isAdapt\":\"" + DictItemStrategyExecute.isAdapt(version) + "\"}");
  92. } catch (Exception e) {
  93. e.printStackTrace();
  94. return Result.error(e.getMessage());
  95. }
  96. return actionResult;
  97. }
  98. /**
  99. * 智能匹配
  100. *
  101. * @param version
  102. * @return
  103. * @throws Exception
  104. */
  105. @ResponseBody
  106. @RequestMapping(value = "/strategyDic", method = RequestMethod.POST)
  107. @ApiOperation(value = "智能匹配", response = Object.class, produces = "application/json", notes = "智能匹配")
  108. public Result strategyDic(
  109. @ApiParam(value = "匹配version", required = true) @RequestParam("version") String version,
  110. @ApiParam(value = "平台标准version", required = true) @RequestParam("std_version") String std_version,
  111. @ApiParam(value = "适配方案版本号", required = true) @RequestParam("adapter_std_version") String adapter_std_version
  112. ) throws Exception {
  113. ActionResult actionResult = new ActionResult();
  114. try {
  115. synchronized (DictItemStrategyExecute.class){
  116. if (!DictItemStrategyExecute.isAdapt(version)) {
  117. //判断之前是否已经有匹配有的话不进行匹配
  118. DictItemStrategyExecute.setVersionYes(version);
  119. }else{
  120. return actionResult;
  121. }
  122. }
  123. dictService.strategy(version,adapter_std_version);
  124. } catch (Exception e) {
  125. e.printStackTrace();
  126. return Result.error(e.getMessage());
  127. }
  128. return actionResult;
  129. }
  130. @RequestMapping(value = "/getStrategyDicSize", method = RequestMethod.POST)
  131. @ResponseBody
  132. @ApiOperation(value = "智能匹配进行", response = Object.class, produces = "application/json", notes = "智能匹配进行")
  133. public Result getStrategyDicSize(
  134. @ApiParam(value = "匹配version", required = true) @RequestParam("version") String version
  135. ) throws Exception {
  136. ActionResult actionResult = new ActionResult();
  137. try {
  138. actionResult.setData(DictItemStrategyExecute.getAllNumAndAdaptNum(version));
  139. } catch (Exception e) {
  140. e.printStackTrace();
  141. return Result.error(e.getMessage());
  142. }
  143. return actionResult;
  144. }
  145. @RequestMapping(value = "/endStrategyDic", method = RequestMethod.POST)
  146. @ResponseBody
  147. @ApiOperation(value = "智能匹配結束", response = Object.class, produces = "application/json", notes = "智能匹配結束")
  148. public Result endStrategyDic(
  149. @ApiParam(value = "匹配version", required = true) @RequestParam("version") String version
  150. ) throws Exception {
  151. ActionResult actionResult = new ActionResult();
  152. try {
  153. DictItemStrategyExecute.removeAdapt(version);
  154. } catch (Exception e) {
  155. e.printStackTrace();
  156. return Result.error(e.getMessage());
  157. }
  158. return actionResult;
  159. }
  160. }