ApplyController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package com.huimv.manage.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.huimv.manage.service.IApplyService;
  4. import com.huimv.manage.util.Const;
  5. import com.huimv.manage.util.Result;
  6. import com.huimv.manage.webservice.Soap;
  7. import com.huimv.manage.webservice.task.ProduceMissionTask;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.beans.factory.annotation.Value;
  11. import org.springframework.web.bind.annotation.*;
  12. import java.io.UnsupportedEncodingException;
  13. /**
  14. * @Project : huimv.shiwan
  15. * @Package : com.huimv.biosafety.uface.controller
  16. * @Description : TODO
  17. * @Version : 1.0
  18. * @Author : ZhuoNing
  19. * @Create : 2020-12-25
  20. **/
  21. @CrossOrigin
  22. @RestController
  23. @Slf4j
  24. @RequestMapping(value = "/eartag/apply")
  25. public class ApplyController {
  26. @Value("${webservice.url}")
  27. private String webServiceUrl;
  28. @Value("${webservice.producerId}")
  29. private String producerId;
  30. @Autowired
  31. private IApplyService applyService;
  32. @Autowired
  33. private Soap soap;
  34. @Autowired
  35. private ProduceMissionTask produceMissionTask;
  36. /**
  37. * @Method : listTask
  38. * @Description :
  39. * @Params : []
  40. * @Return : java.lang.String
  41. *
  42. * @Author : ZhuoNing
  43. * @Date : 2021/10/27
  44. * @Time : 20:28
  45. */
  46. @RequestMapping(value = "/listApply",method = RequestMethod.GET)
  47. // public Result listApply(@RequestParam(value = "accessToken",required=false) String accessToken,
  48. // @RequestParam(value = "applyId",required=false) int applyId,
  49. // @RequestParam(value = "startDate",required=false) String startDate,
  50. // @RequestParam(value = "endDate",required=false) String endDate,
  51. // @RequestParam(value = "returnState",required=false) int returnState,
  52. // @RequestParam(value = "deliverState",required=false) int deliverState,
  53. // @RequestParam(value = "pageSize",required=true) int pageSize)
  54. public Result listApply()
  55. {
  56. return applyService.listApply();
  57. }
  58. /**
  59. * @Method : getNewTask
  60. * @Description :
  61. * @Params : []
  62. * @Return : java.lang.String
  63. *
  64. * @Author : ZhuoNing
  65. * @Date : 2021/10/27
  66. * @Time : 20:29
  67. */
  68. @RequestMapping(value = "/getNewApply",method = RequestMethod.GET)
  69. public Result getNewTask() throws UnsupportedEncodingException {
  70. log.info("producerId>>"+producerId);
  71. log.info("webServiceUrl>>"+webServiceUrl);
  72. // 从远程接口下载新任务号数据
  73. JSONArray downloadApplyJa = produceMissionTask.parseReturnNewMissionXML(soap.callSoap(produceMissionTask.getNewMissionXML(producerId),webServiceUrl));
  74. // test
  75. // JSONArray downloadApplyJa = newProduceMission.parseApplyXML(newProduceMission.getNewMessionResult_test());
  76. if(downloadApplyJa == null){
  77. return new Result(Const.CODE_APPLY_PARSE,Const.APPLY_PARSE_ERROR,false);
  78. }
  79. // 过滤已经入库的任务号
  80. JSONArray newApplyJa = applyService.filterExistApply(downloadApplyJa);
  81. if(newApplyJa.size() > 0){
  82. // test
  83. // System.out.println("获取任务号:"+newApplyJa.size());
  84. // for(int a=0;a<newApplyJa.size();a++){
  85. // JSONObject applyJo = newApplyJa.getJSONObject(a);
  86. // System.out.println(applyJo);
  87. // }
  88. // 保存新任务(号)
  89. return applyService.saveNewMission(newApplyJa);
  90. }else{
  91. return new Result(Const.CODE_APPLY_NO_NEW, Const.APPLY_NO_NEW,false);
  92. }
  93. }
  94. /**
  95. * @Method : setReturnDownloadState
  96. * @Description : 设置返回任务已下载
  97. * @Params : [applyId]
  98. * @Return : com.huimv.manage.util.Result
  99. *
  100. * @Author : ZhuoNing
  101. * @Date : 2021/10/29
  102. * @Time : 11:08
  103. */
  104. @RequestMapping(value = "/setReturnDownloadState",method = RequestMethod.POST)
  105. public Result setReturnDownloadState(@RequestParam(value = "applyId") int applyId) throws UnsupportedEncodingException {
  106. // Step1.构造请求字串
  107. // Step2.发送请求传
  108. // Step3.请求结果入库
  109. String stateBln = produceMissionTask.parseReturnSetMissionHasDownStateXML(soap.callSoap(produceMissionTask.getSetMissionHasDownloadXML(applyId),webServiceUrl));
  110. if(stateBln.trim().equalsIgnoreCase("true")){
  111. // 修改状态
  112. return applyService.setMissionHasDownloadState(applyId,1);
  113. }else{
  114. return new Result(Const.CODE_UPDATE_STATE_FAIL,Const.UPDATE_STATE_FAIL,false);
  115. }
  116. }
  117. }