OpenEndPoint.java 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.yihu.ehr.basic.fzopen.controller;
  2. import com.fasterxml.jackson.databind.ObjectMapper;
  3. import com.yihu.ehr.basic.fzopen.service.OpenService;
  4. import com.yihu.ehr.constants.ApiVersion;
  5. import com.yihu.ehr.constants.ServiceApi;
  6. import com.yihu.ehr.controller.EnvelopRestEndPoint;
  7. import com.yihu.ehr.util.rest.Envelop;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.annotations.ApiOperation;
  10. import io.swagger.annotations.ApiParam;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import java.util.Map;
  17. /**
  18. * 转发福州总部内网、开放平台接口
  19. *
  20. * @author 张进军
  21. * @date 2018/4/12 18:42
  22. */
  23. @RestController
  24. @RequestMapping(value = ApiVersion.Version1_0)
  25. @Api(description = "转发福州总部内网、开放平台接口", tags = {"转发福州总部内网、开放平台接口"})
  26. public class OpenEndPoint extends EnvelopRestEndPoint {
  27. @Autowired
  28. private ObjectMapper objectMapper;
  29. @Autowired
  30. private OpenService openService;
  31. @ApiOperation("转发福州总部开放平台接口")
  32. @RequestMapping(value = ServiceApi.Fz.OpenApi, method = RequestMethod.POST)
  33. public Envelop fzOpenApi(
  34. @ApiParam(name = "apiUrl", value = "", required = true)
  35. @RequestParam(value = "apiUrl") String apiUrl,
  36. @ApiParam(name = "paramsJson", value = "参数JSON字符串,timestamp 不用传,后台添加", required = true)
  37. @RequestParam(value = "paramsJson") String paramsJson) {
  38. Envelop envelop = new Envelop();
  39. envelop.setSuccessFlg(false);
  40. try {
  41. Map<String, Object> params = objectMapper.readValue(paramsJson, Map.class);
  42. Map<String, Object> result = objectMapper.readValue(openService.callFzOpenApi(apiUrl, params), Map.class);
  43. envelop.setObj(result);
  44. envelop.setSuccessFlg(true);
  45. } catch (Exception e) {
  46. e.printStackTrace();
  47. envelop.setErrorMsg(e.getMessage());
  48. }
  49. return envelop;
  50. }
  51. @ApiOperation("转发福州总部内网接口")
  52. @RequestMapping(value = ServiceApi.Fz.InnerApi, method = RequestMethod.POST)
  53. public Envelop fzInnerApi(
  54. @ApiParam(name = "api", value = "API 名称,格式为 a.b.c", required = true)
  55. @RequestParam(value = "api") String api,
  56. @ApiParam(name = "paramsJson", value = "参数JSON字符串", required = true)
  57. @RequestParam(value = "paramsJson") String paramsJson,
  58. @ApiParam(name = "apiVersion", value = "API 版本号,版本号为整型,从数字 1 开始递增", required = true)
  59. @RequestParam(value = "apiVersion") int apiVersion) {
  60. Envelop envelop = new Envelop();
  61. envelop.setSuccessFlg(false);
  62. try {
  63. Map<String, Object> params = objectMapper.readValue(paramsJson, Map.class);
  64. String result = openService.callFzInnerApi(api, params, apiVersion);
  65. envelop.setObj(result);
  66. envelop.setSuccessFlg(true);
  67. } catch (Exception e) {
  68. e.printStackTrace();
  69. envelop.setErrorMsg(e.getMessage());
  70. }
  71. return envelop;
  72. }
  73. }