EngineeringController.java 6.1 KB

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