EngineeringController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 CenterdataTKeyProjects centerdataTKeyProjects) {
  46. log.info("centerdataTKeyProjects:{}",centerdataTKeyProjects);
  47. if (StringUtils.isNotEmpty(SecurityUtils.getToken())) {
  48. log.info("SecurityUtils.getToken()",SecurityUtils.getToken());
  49. R<?> result = remoteDataBaseService.projects(centerdataTKeyProjects);
  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 CenterdataTKeyProjectsPictures centerdataTKeyProjectsPictures) {
  62. System.out.println(centerdataTKeyProjectsPictures);
  63. R<String> appUrl = remoteConfigService.remotegetConfigKey("appUrl");
  64. List<String> pictureList = new ArrayList<>();
  65. for (String picture : centerdataTKeyProjectsPictures.getSchedulePictures()) {
  66. pictureList.add(appUrl.getData().toString() + picture);
  67. }
  68. centerdataTKeyProjectsPictures.setSchedulePictures(pictureList);
  69. // TODO: 2024/1/16 0016 待修改
  70. JSONObject jsonObject = new JSONObject();
  71. jsonObject.put("", centerdataTKeyProjectsPictures);
  72. try {
  73. RestUtil.post(url, jsonObject);
  74. } catch (Exception e) {
  75. log.info("重点工程报错");
  76. }
  77. return R.ok("接收成功");
  78. }
  79. /**
  80. * 重点区域
  81. * @param
  82. * @return
  83. */
  84. // @PostMapping("/pushAreaData")
  85. // @ResponseBody
  86. // public R<?> pushAreaData(@RequestBody DataExchangeEntity dataExchangeEntity) {
  87. // log.info("dataExchangeEntity:{}",dataExchangeEntity);
  88. // List<String> pictureList = new ArrayList<>();
  89. // if (StringUtils.isNotEmpty(SecurityUtils.getToken()) && !CollectionUtils.isEmpty(dataExchangeEntity.getEventPicture())) {
  90. // for (String picture : dataExchangeEntity.getEventPicture()) {
  91. // if (!"image".equals(FilePrefixUtils.getUrlSuffix(picture))) {
  92. // log.error("事件图片必须为图片格式---{}", dataExchangeEntity);
  93. // return R.fail("事件图片必须为图片格式");
  94. // } else {
  95. // MultipartFile multipartFile = FilePrefixUtils.urlToMultipartFile(picture, System.currentTimeMillis() + ".jpg");
  96. // SysFile sysFile = SpringUtils.getBean(RemoteFileService.class).upload(multipartFile).getData();
  97. // pictureList.add(sysFile.getUrl());
  98. // }
  99. // }
  100. // dataExchangeEntity.setPictureUrlList(pictureList);
  101. // R<?> result = remoteDataBaseService.insert3rdSystemEvent(dataExchangeEntity);
  102. // if (result.getCode() == 200) {
  103. // return R.ok("推送成功");
  104. // } else {
  105. // return R.fail(result.getMsg());
  106. // }
  107. // } else {
  108. // return R.fail("推送失败");
  109. // }
  110. // }
  111. //
  112. //
  113. // @PostMapping("/receiveAreaData")
  114. // @ResponseBody
  115. // public R<?> receiveAreaData(@RequestBody DataExchangeEntity dataExchangeEntity) {
  116. // System.out.println(dataExchangeEntity);
  117. // R<String> appUrl = remoteConfigService.remotegetConfigKey("appUrl");
  118. // List<String> pictureList = new ArrayList<>();
  119. // for (String picture : dataExchangeEntity.getEventPicture()) {
  120. // pictureList.add(appUrl.getData().toString() + picture);
  121. // }
  122. // dataExchangeEntity.setEventPicture(pictureList);
  123. // // TODO: 2024/1/9 0009 待修改
  124. // JSONObject jsonObject = new JSONObject();
  125. // jsonObject.put("", dataExchangeEntity);
  126. // try {
  127. // RestUtil.post(url, jsonObject);
  128. // } catch (Exception e) {
  129. // log.info("远程调用119报错");
  130. // }
  131. // return R.ok("接收成功");
  132. // }
  133. }