EngineeringController.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package com.sooka.sponest.dataexchange.sendChange.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ruoyi.common.core.domain.R;
  4. import com.ruoyi.common.core.utils.file.FilePrefixUtils;
  5. import com.ruoyi.common.security.utils.SecurityUtils;
  6. import com.ruoyi.system.api.RemoteConfigService;
  7. import com.ruoyi.system.api.RemoteFileService;
  8. import com.ruoyi.system.api.domain.SysFile;
  9. import com.sooka.sponest.dataexchange.exchange.domian.DataExchangeEntity;
  10. import com.sooka.sponest.dataexchange.remoteapi.service.center.data.RemoteDataBaseService;
  11. import com.sooka.sponest.dataexchange.remoteapi.service.center.event.RemoteEventBaseService;
  12. import com.sooka.sponest.dataexchange.sendChange.domian.CenterdataTKeyProjects;
  13. import com.sooka.sponest.dataexchange.sendChange.domian.CenterdataTKeyProjectsPictures;
  14. import com.sooka.sponest.dataexchange.util.RestUtil;
  15. import com.sooka.sponest.dataexchange.util.spring.SpringUtils;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.apache.commons.lang3.StringUtils;
  18. import org.springframework.stereotype.Controller;
  19. import org.springframework.util.CollectionUtils;
  20. import org.springframework.web.bind.annotation.PostMapping;
  21. import org.springframework.web.bind.annotation.RequestBody;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import org.springframework.web.bind.annotation.ResponseBody;
  24. import org.springframework.web.multipart.MultipartFile;
  25. import javax.annotation.Resource;
  26. import java.util.ArrayList;
  27. import java.util.List;
  28. @Slf4j
  29. @Controller
  30. @RequestMapping("/sendChange")
  31. public class EngineeringController {
  32. @Resource
  33. private RemoteDataBaseService remoteDataBaseService;
  34. @Resource
  35. private RemoteConfigService remoteConfigService;
  36. // @Value("${}")
  37. private String url;
  38. /**
  39. * 重点工程
  40. * @param
  41. * @return
  42. */
  43. @PostMapping("/pushEngineeringData")
  44. @ResponseBody
  45. public R<?> pushEngineeringData(@RequestBody List<CenterdataTKeyProjects> list) {
  46. log.info("centerdataTKeyProjects:{}",list);
  47. if (StringUtils.isNotEmpty(SecurityUtils.getToken())) {
  48. log.info("SecurityUtils.getToken():{}",SecurityUtils.getToken());
  49. R<?> result = remoteDataBaseService.receivedMessage(list);
  50. if (result.getCode() == 200) {
  51. return R.ok("推送成功");
  52. } else {
  53. return R.fail(result.getMsg());
  54. }
  55. } else {
  56. return R.fail("推送失败");
  57. }
  58. }
  59. @PostMapping("/receiveEngineeringData")
  60. @ResponseBody
  61. public R<?> receiveEngineeringData(@RequestBody List<CenterdataTKeyProjectsPictures> list) {
  62. log.info("List<CenterdataTKeyProjectsPictures>:{}",list);
  63. R<String> appUrl = remoteConfigService.remotegetConfigKey("appUrl");
  64. List<CenterdataTKeyProjectsPictures> requestList = new ArrayList<>();
  65. for (CenterdataTKeyProjectsPictures var : list) {
  66. CenterdataTKeyProjectsPictures centerdataTKeyProjectsPictures = new CenterdataTKeyProjectsPictures();
  67. centerdataTKeyProjectsPictures.setProjectId(var.getProjectId());
  68. centerdataTKeyProjectsPictures.setSchedulePictures(appUrl.getData().toString() + var.getSchedulePictures());
  69. requestList.add(var);
  70. }
  71. // TODO: 2024/1/16 0016 待修改
  72. JSONObject jsonObject = new JSONObject();
  73. jsonObject.put("", requestList);
  74. try {
  75. RestUtil.post(url, jsonObject);
  76. } catch (Exception e) {
  77. log.info("重点工程报错");
  78. }
  79. return R.ok("接收成功");
  80. }
  81. /**
  82. * 重点区域
  83. * @param
  84. * @return
  85. */
  86. // @PostMapping("/pushAreaData")
  87. // @ResponseBody
  88. // public R<?> pushAreaData(@RequestBody DataExchangeEntity dataExchangeEntity) {
  89. // log.info("dataExchangeEntity:{}",dataExchangeEntity);
  90. // List<String> pictureList = new ArrayList<>();
  91. // if (StringUtils.isNotEmpty(SecurityUtils.getToken()) && !CollectionUtils.isEmpty(dataExchangeEntity.getEventPicture())) {
  92. // for (String picture : dataExchangeEntity.getEventPicture()) {
  93. // if (!"image".equals(FilePrefixUtils.getUrlSuffix(picture))) {
  94. // log.error("事件图片必须为图片格式---{}", dataExchangeEntity);
  95. // return R.fail("事件图片必须为图片格式");
  96. // } else {
  97. // MultipartFile multipartFile = FilePrefixUtils.urlToMultipartFile(picture, System.currentTimeMillis() + ".jpg");
  98. // SysFile sysFile = SpringUtils.getBean(RemoteFileService.class).upload(multipartFile).getData();
  99. // pictureList.add(sysFile.getUrl());
  100. // }
  101. // }
  102. // dataExchangeEntity.setPictureUrlList(pictureList);
  103. // R<?> result = remoteDataBaseService.insert3rdSystemEvent(dataExchangeEntity);
  104. // if (result.getCode() == 200) {
  105. // return R.ok("推送成功");
  106. // } else {
  107. // return R.fail(result.getMsg());
  108. // }
  109. // } else {
  110. // return R.fail("推送失败");
  111. // }
  112. // }
  113. //
  114. //
  115. // @PostMapping("/receiveAreaData")
  116. // @ResponseBody
  117. // public R<?> receiveAreaData(@RequestBody DataExchangeEntity dataExchangeEntity) {
  118. // System.out.println(dataExchangeEntity);
  119. // R<String> appUrl = remoteConfigService.remotegetConfigKey("appUrl");
  120. // List<String> pictureList = new ArrayList<>();
  121. // for (String picture : dataExchangeEntity.getEventPicture()) {
  122. // pictureList.add(appUrl.getData().toString() + picture);
  123. // }
  124. // dataExchangeEntity.setEventPicture(pictureList);
  125. // // TODO: 2024/1/9 0009 待修改
  126. // JSONObject jsonObject = new JSONObject();
  127. // jsonObject.put("", dataExchangeEntity);
  128. // try {
  129. // RestUtil.post(url, jsonObject);
  130. // } catch (Exception e) {
  131. // log.info("远程调用119报错");
  132. // }
  133. // return R.ok("接收成功");
  134. // }
  135. }