GhtController.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package com.goldenwater.slgc.controller.proxy;
  2. import org.springframework.web.bind.annotation.GetMapping;
  3. import org.springframework.web.bind.annotation.RequestMapping;
  4. import org.springframework.web.bind.annotation.RequestParam;
  5. import org.springframework.web.bind.annotation.RestController;
  6. import org.springframework.web.client.RestTemplate;
  7. import com.goldenwater.common.core.controller.BaseController;
  8. import com.goldenwater.common.core.domain.AjaxResult;
  9. import com.goldenwater.slgc.config.ApiProperties;
  10. import io.swagger.v3.oas.annotations.Operation;
  11. import io.swagger.v3.oas.annotations.tags.Tag;
  12. @Tag(name = "24. 工程概化图")
  13. @RestController
  14. @RequestMapping("/slgc/ght")
  15. public class GhtController extends BaseController {
  16. private final RestTemplate restTemplate;
  17. private final ApiProperties apiProperties;
  18. public GhtController(RestTemplate restTemplate, ApiProperties apiProperties) {
  19. this.restTemplate = restTemplate;
  20. this.apiProperties = apiProperties;
  21. }
  22. @Operation(summary = "24.01 查询概化图数据")
  23. @GetMapping("/list")
  24. public AjaxResult list(@RequestParam(defaultValue = "") String name) {
  25. try {
  26. String xml = restTemplate.getForObject(apiProperties.getYjzh() + "/SELECT_GCGHT?name=" + name, String.class);
  27. org.w3c.dom.Document doc = javax.xml.parsers.DocumentBuilderFactory.newInstance()
  28. .newDocumentBuilder().parse(new java.io.ByteArrayInputStream(xml.getBytes("UTF-8")));
  29. org.w3c.dom.NodeList nodes = (org.w3c.dom.NodeList)
  30. javax.xml.xpath.XPathFactory.newInstance().newXPath()
  31. .evaluate("//Table/string", doc, javax.xml.xpath.XPathConstants.NODESET);
  32. if (nodes.getLength() > 0) {
  33. String json = nodes.item(0).getTextContent().trim();
  34. com.alibaba.fastjson2.JSONArray arr = com.alibaba.fastjson2.JSONArray.parseArray(json);
  35. return success(arr != null ? arr : java.util.Collections.emptyList());
  36. }
  37. } catch (Exception ignored) {}
  38. return success(java.util.Collections.emptyList());
  39. }
  40. }