EngineeringController.java 6.9 KB

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