|
|
@ -2,24 +2,68 @@ package com.epmet.apiservice.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.apiservice.ApiService; |
|
|
|
import com.epmet.apiservice.result.LZGridPlatformBaseResult; |
|
|
|
import com.epmet.apiservice.result.LZGridPlatformProjectAssistResult; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.redis.RedisKeys; |
|
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.utils.SpringContextUtils; |
|
|
|
import com.epmet.constant.ThirdPlatformActions; |
|
|
|
import com.epmet.dao.ThirdplatformActionDao; |
|
|
|
import com.epmet.dao.ThirdplatformDao; |
|
|
|
import com.epmet.dto.result.ProjectAssistResult; |
|
|
|
import com.epmet.dto.form.ProjectApplyAssistFormDTO; |
|
|
|
import com.epmet.entity.ThirdplatformActionEntity; |
|
|
|
import com.epmet.entity.ThirdplatformEntity; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
/** |
|
|
|
* 泸州网格化平台ApiService |
|
|
|
*/ |
|
|
|
@Component("luzhouGridPlatformApiService") |
|
|
|
public class LuzhouGridPlatformApiService extends ApiService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getAccessToken(String platformId) { |
|
|
|
RedisTemplate<String, String> rt = SpringContextUtils.getBean("redisTemplate", RedisTemplate.class); |
|
|
|
String token = rt.opsForValue().get(RedisKeys.getThirdPlatformAccessTokenKey(platformId)); |
|
|
|
if (StringUtils.isBlank(token)) { |
|
|
|
ThirdplatformEntity thirdplatform = SpringContextUtils.getBean(ThirdplatformDao.class).selectById(platformId); |
|
|
|
ThirdplatformActionEntity actionEntity = SpringContextUtils.getBean(ThirdplatformActionDao.class) |
|
|
|
.getByPlatformIdAndActionKey(platformId, ThirdPlatformActions.GET_ACCESS_TOKEN); |
|
|
|
|
|
|
|
String baseUrl = thirdplatform.getBaseUrl(); |
|
|
|
String platformKey = thirdplatform.getPlatformKey(); |
|
|
|
String platformSecret = thirdplatform.getPlatformSecret(); |
|
|
|
|
|
|
|
HashMap<String, Object> params = new HashMap<>(); |
|
|
|
params.put("appKey", platformKey); |
|
|
|
params.put("appSecret", platformSecret); |
|
|
|
Result<String> result = HttpClientManager.getInstance().sendGet(baseUrl.concat(actionEntity.getApiUrl()), params); |
|
|
|
if (result == null) { |
|
|
|
throw new RenException("请求第三方平台,获取AccessToken失败。result为null"); |
|
|
|
} |
|
|
|
if (!result.success()) { |
|
|
|
throw new RenException("请求第三方平台,获取AccessToken失败。"); |
|
|
|
} |
|
|
|
judgeResultSuccess(result.getData()); |
|
|
|
token = result.getData(); |
|
|
|
rt.opsForValue().set(RedisKeys.getThirdPlatformAccessTokenKey(platformId), token); |
|
|
|
} |
|
|
|
return token; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ProjectAssistResult projectAssist(ProjectApplyAssistFormDTO formDTO) { |
|
|
|
String platformId = formDTO.getPlatformId(); |
|
|
|
|
|
|
|
// 正式调用第三方平台
|
|
|
|
//String result = sendPostRequest(platformId, ThirdPlatformActions.PROJECT_ASSIST, "{}", null);
|
|
|
|
//String result1 = sendPostRequest(platformId, ThirdPlatformActions.PROJECT_ASSIST, "{}", null);
|
|
|
|
|
|
|
|
// 开发阶段临时写死
|
|
|
|
String result = "{\"eventId\":\"test-task-id\"}"; |
|
|
@ -36,4 +80,13 @@ public class LuzhouGridPlatformApiService extends ApiService { |
|
|
|
System.out.println("泸州网格化平台项目协助发送成功"); |
|
|
|
return projectAssistResult; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void judgeResultSuccess(String stringData) { |
|
|
|
//LZGridPlatformBaseResult;
|
|
|
|
LZGridPlatformBaseResult result = JSON.parseObject(stringData, LZGridPlatformBaseResult.class); |
|
|
|
if (!"200".equalsIgnoreCase(result.getCode())) { |
|
|
|
throw new RenException("泸州网格化平台:返回失败结果,错误码:" + result.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|