package com.fdkankan.scene.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.fdkankan.common.constant.SceneInfoReqType; import com.fdkankan.common.exception.BusinessException; import com.fdkankan.common.util.ThreeDESUtil; import com.fdkankan.feign.TietaEntityClient; import com.fdkankan.scene.annotation.InitEditInfo; import com.fdkankan.scene.bean.ResultData; import com.fdkankan.scene.entity.SystemSecret; import com.fdkankan.scene.httpclient.CustomHttpClient; import com.fdkankan.scene.service.*; import com.fdkankan.scene.vo.*; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.IOException; import java.net.InetAddress; import java.util.*; import java.util.stream.Collectors; /** * 场景编辑管理 */ @RestController @RequestMapping("/service/scene/edit") public class TIetaEditController extends BaseController{ @Resource private TietaEntityClient tietaEntityClient; @Autowired private SystemSecretService systemSecretService; @Value("${gateway.key:6#dPz>3F}") private String gatewayKey; @Value("${tieta.checkToken.syscode}") private String syscode; @Autowired private CustomHttpClient customHttpClient; @Value("${gateway.url}") private String gatewayUrl; @GetMapping("getStationResource") public ResultData getStationResource(String stationCode){ List list = systemSecretService.list(new LambdaQueryWrapper().orderByDesc(SystemSecret::getUpdatedat)); String APPID = syscode; String APPUUID = UUID.randomUUID().toString(); String secret = ThreeDESUtil.decode(list.get(0).getAppsecret(), gatewayKey); String APPUUIDCRPT = ThreeDESUtil.encode(APPUUID, secret); String ACCESSIPADDR = InetAddress.getLoopbackAddress().getHostAddress(); Map headers = new HashMap<>(); headers.put("APPID",APPID); headers.put("APPUUID",APPUUID); headers.put("APPUUIDCRPT",APPUUIDCRPT); headers.put("ACCESSIPADDR",ACCESSIPADDR); String url = gatewayUrl + "/CHINATOWER-RES-ENTITY-SERVICE/station/page/lower/resource/" + stationCode; JSONObject stationResource = customHttpClient.post(headers, url); // JSONObject stationResource = tietaEntityClient.getStationResource(headers, stationCode); Integer resultCode = stationResource.getInteger("resultCode"); if(resultCode == null || resultCode != 0){ throw new BusinessException(-1, String.format("资源平台返回失败,resultCode:%d, resultMsg:%s", resultCode, stationResource.getString("resultMsg"))); } JSONArray jsonArray = stationResource.getJSONArray("data"); List> collect = jsonArray.stream().map(v -> { JSONObject resource = (JSONObject) v; Map map = new HashMap<>(); map.put("ENTITY_ID", resource.get("ENTITY_ID")); map.put("ENTITY_NAME", resource.get("ENTITY_NAME")); map.put("RES_TYPE_ID", resource.get("RES_TYPE_ID")); map.put("ENTITY_STATE_ID_TEXT", resource.get("ENTITY_STATE_ID_TEXT")); return map; }).collect(Collectors.toList()); return ResultData.ok(collect); } }