TIetaEditController.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.fdkankan.scene.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.fdkankan.common.constant.SceneInfoReqType;
  6. import com.fdkankan.common.exception.BusinessException;
  7. import com.fdkankan.common.util.ThreeDESUtil;
  8. import com.fdkankan.feign.TietaEntityClient;
  9. import com.fdkankan.scene.annotation.InitEditInfo;
  10. import com.fdkankan.scene.bean.ResultData;
  11. import com.fdkankan.scene.entity.SystemSecret;
  12. import com.fdkankan.scene.httpclient.CustomHttpClient;
  13. import com.fdkankan.scene.service.*;
  14. import com.fdkankan.scene.vo.*;
  15. import lombok.extern.log4j.Log4j2;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.beans.factory.annotation.Value;
  18. import org.springframework.validation.annotation.Validated;
  19. import org.springframework.web.bind.annotation.*;
  20. import org.springframework.web.multipart.MultipartFile;
  21. import javax.annotation.Resource;
  22. import java.io.IOException;
  23. import java.net.InetAddress;
  24. import java.util.*;
  25. import java.util.stream.Collectors;
  26. /**
  27. * 场景编辑管理
  28. */
  29. @RestController
  30. @RequestMapping("/service/scene/edit")
  31. public class TIetaEditController extends BaseController{
  32. @Resource
  33. private TietaEntityClient tietaEntityClient;
  34. @Autowired
  35. private SystemSecretService systemSecretService;
  36. @Value("${gateway.key:6#dPz>3F}")
  37. private String gatewayKey;
  38. @Value("${tieta.checkToken.syscode}")
  39. private String syscode;
  40. @Autowired
  41. private CustomHttpClient customHttpClient;
  42. @Value("${gateway.url}")
  43. private String gatewayUrl;
  44. @GetMapping("getStationResource")
  45. public ResultData getStationResource(String stationCode){
  46. List<SystemSecret> list = systemSecretService.list(new LambdaQueryWrapper<SystemSecret>().orderByDesc(SystemSecret::getUpdatedat));
  47. String APPID = syscode;
  48. String APPUUID = UUID.randomUUID().toString();
  49. String secret = ThreeDESUtil.decode(list.get(0).getAppsecret(), gatewayKey);
  50. String APPUUIDCRPT = ThreeDESUtil.encode(APPUUID, secret);
  51. String ACCESSIPADDR = InetAddress.getLoopbackAddress().getHostAddress();
  52. Map<String, String> headers = new HashMap<>();
  53. headers.put("APPID",APPID);
  54. headers.put("APPUUID",APPUUID);
  55. headers.put("APPUUIDCRPT",APPUUIDCRPT);
  56. headers.put("ACCESSIPADDR",ACCESSIPADDR);
  57. String url = gatewayUrl + "/CHINATOWER-RES-ENTITY-SERVICE/station/page/lower/resource/" + stationCode;
  58. JSONObject stationResource = customHttpClient.post(headers, url);
  59. // JSONObject stationResource = tietaEntityClient.getStationResource(headers, stationCode);
  60. Integer resultCode = stationResource.getInteger("resultCode");
  61. if(resultCode == null || resultCode != 0){
  62. throw new BusinessException(-1, String.format("资源平台返回失败,resultCode:%d, resultMsg:%s", resultCode, stationResource.getString("resultMsg")));
  63. }
  64. JSONArray jsonArray = stationResource.getJSONArray("data");
  65. List<Map<String, Object>> collect = jsonArray.stream().map(v -> {
  66. JSONObject resource = (JSONObject) v;
  67. Map<String, Object> map = new HashMap<>();
  68. map.put("ENTITY_ID", resource.get("ENTITY_ID"));
  69. map.put("ENTITY_NAME", resource.get("ENTITY_NAME"));
  70. map.put("RES_TYPE_ID", resource.get("RES_TYPE_ID"));
  71. map.put("ENTITY_STATE_ID_TEXT", resource.get("ENTITY_STATE_ID_TEXT"));
  72. return map;
  73. }).collect(Collectors.toList());
  74. return ResultData.ok(collect);
  75. }
  76. }