diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/SaveOrUpdateCustSelPlatformFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/SaveOrUpdateCustSelPlatformFormDTO.java new file mode 100644 index 0000000000..5ba026cd80 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/SaveOrUpdateCustSelPlatformFormDTO.java @@ -0,0 +1,19 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.util.List; + +@Data +public class SaveOrUpdateCustSelPlatformFormDTO { + + @NotBlank(message = "客户id不能为空") + private String customerId; + + @NotBlank(message = "actionKey不能为空") + private String actionKey; + + private List platforms; + +} diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java index de647e726e..4a139daabd 100644 --- a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java @@ -2,6 +2,7 @@ package com.epmet.feign; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.form.SaveOrUpdateCustSelPlatformFormDTO; import com.epmet.dto.form.ThirdPlatformFormDTO; import com.epmet.dto.result.ThirdplatformResultDTO; import com.epmet.feign.fallback.ThirdOpenFeignClientFallback; @@ -22,7 +23,7 @@ public interface ThirdOpenFeignClient { * @date 2021.03.19 15:25 */ @PostMapping("/third/thirdplatform/customer/saveorupdate-selected-platforms") - Result saveOrUpdateSelectedPlatformsInfo(@RequestBody List input); + Result saveOrUpdateSelectedPlatformsInfo(@RequestBody SaveOrUpdateCustSelPlatformFormDTO input); /** * 根据客户id和动作,列出客户在指定动作下可用的第三方平台 diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/ThirdOpenFeignClientFallback.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/ThirdOpenFeignClientFallback.java index 9322354512..57a9c808c3 100644 --- a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/ThirdOpenFeignClientFallback.java +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/ThirdOpenFeignClientFallback.java @@ -3,6 +3,7 @@ package com.epmet.feign.fallback; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.form.SaveOrUpdateCustSelPlatformFormDTO; import com.epmet.dto.form.ThirdPlatformFormDTO; import com.epmet.dto.result.ThirdplatformResultDTO; import com.epmet.feign.ThirdOpenFeignClient; @@ -13,7 +14,7 @@ import java.util.List; @Component public class ThirdOpenFeignClientFallback implements ThirdOpenFeignClient { @Override - public Result saveOrUpdateSelectedPlatformsInfo(List input) { + public Result saveOrUpdateSelectedPlatformsInfo(SaveOrUpdateCustSelPlatformFormDTO input) { return ModuleUtils.feignConError(ServiceConstant.EPMET_THIRD_SERVER, "saveOrUpdateSelectedPlatformsInfo", input); } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/ApiService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/ApiService.java index 6debb8dac2..7aff23fd7a 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/ApiService.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/ApiService.java @@ -77,6 +77,7 @@ public abstract class ApiService { if (result.success()) { throw new RenException("请求第三方平台,获取AccessToken失败。"); } + judgeResultSuccess(result.getData()); return result.getData(); } @@ -114,42 +115,17 @@ public abstract class ApiService { if (result.success()) { throw new RenException("请求第三方平台,获取AccessToken失败。"); } + judgeResultSuccess(result.getData()); return result.getData(); } /** - * @Description 获取accessToken + * @Description 获取accessToken,由子类具体实现 * @return * @author wxz * @date 2021.03.16 13:45 */ - private String getAccessToken(String platformId) { - RedisTemplate 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 params = new HashMap<>(); - params.put("appKey", platformKey); - params.put("appSecret", platformSecret); - Result 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失败。"); - } - token = result.getData(); - rt.opsForValue().set(RedisKeys.getThirdPlatformAccessTokenKey(platformId), token); - } - return token; - } + public abstract String getAccessToken(String platformId); /** * @Description 判断客户是否注册了指定的平台,如果没有注册,则抛出异常 @@ -182,4 +158,12 @@ public abstract class ApiService { public ProjectAssistResult projectAssist(ProjectApplyAssistFormDTO formDTO) { return null; } + + /** + * @Description 判断第三方平台返回结果成功失败。如果失败,则抛出异常 + * @return + * @author wxz + * @date 2021.03.22 10:32 + */ + public abstract void judgeResultSuccess(String stringData); } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/DemoApiService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/DemoApiService.java index 94c3127d00..1a1e00cd4e 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/DemoApiService.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/DemoApiService.java @@ -20,9 +20,19 @@ public class DemoApiService extends ApiService { @Autowired private OperCrmOpenFeignClient operCrmOpenFeignClient; + @Override + public String getAccessToken(String platformId) { + return null; + } + @Override public ProjectAssistResult projectAssist(ProjectApplyAssistFormDTO formDTO) { logger.info("DemoApiService发送项目协助到第三方平台成功"); return null; } + + @Override + public void judgeResultSuccess(String stringData) { + + } } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/LuzhouGridPlatformApiService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/LuzhouGridPlatformApiService.java index d4c062bb09..026b40654d 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/LuzhouGridPlatformApiService.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/LuzhouGridPlatformApiService.java @@ -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 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 params = new HashMap<>(); + params.put("appKey", platformKey); + params.put("appSecret", platformSecret); + Result 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()); + } + } } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/result/LZGridPlatformBaseResult.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/result/LZGridPlatformBaseResult.java new file mode 100644 index 0000000000..c0f4ed190a --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/result/LZGridPlatformBaseResult.java @@ -0,0 +1,11 @@ +package com.epmet.apiservice.result; + +import lombok.Data; + +@Data +public class LZGridPlatformBaseResult { + private Boolean success; + private String code; + private R result; + // 有其他内容可直接写上 +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ThirdPlatformController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ThirdPlatformController.java index 9288625bee..f0bdb4d5ab 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ThirdPlatformController.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ThirdPlatformController.java @@ -2,6 +2,7 @@ package com.epmet.controller; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dto.form.SaveOrUpdateCustSelPlatformFormDTO; import com.epmet.dto.form.ThirdPlatformFormDTO; import com.epmet.dto.result.ThirdplatformResultDTO; import com.epmet.service.ThirdPlatformService; @@ -83,9 +84,9 @@ public class ThirdPlatformController { * @date 2021.03.19 15:25 */ @PostMapping("customer/saveorupdate-selected-platforms") - public Result saveOrUpdateSelectedPlatformsInfo(@RequestBody List input) { - input.stream().forEach(i -> ValidatorUtils.validateEntity(i, ThirdPlatformFormDTO.SaveOrUpdateSelectedPlatformInfo.class)); - thirdPlatformService.saveOrUpdateSelectedPlatformInfo(input); + public Result saveOrUpdateSelectedPlatformsInfo(@RequestBody SaveOrUpdateCustSelPlatformFormDTO input) { + ValidatorUtils.validateEntity(input); + thirdPlatformService.saveOrUpdateSelectedPlatformInfo(input.getCustomerId(), input.getActionKey(), input.getPlatforms()); return new Result(); } } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ThirdPlatformService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ThirdPlatformService.java index add4c63a2a..9a0042f6e7 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ThirdPlatformService.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ThirdPlatformService.java @@ -21,5 +21,5 @@ public interface ThirdPlatformService { void updateCustomizePlatformInfo(ThirdPlatformFormDTO input); - void saveOrUpdateSelectedPlatformInfo(List platforms); + void saveOrUpdateSelectedPlatformInfo(String customerId, String actionKey, List platforms); } \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ThirdPlatformServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ThirdPlatformServiceImpl.java index 39d3e33cae..7e92c34223 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ThirdPlatformServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ThirdPlatformServiceImpl.java @@ -70,26 +70,19 @@ public class ThirdPlatformServiceImpl implements ThirdPlatformService { @Transactional(rollbackFor = Exception.class) @Override - public void saveOrUpdateSelectedPlatformInfo(List platforms) { - if (CollectionUtils.isEmpty(platforms)) { - return; - } - + public void saveOrUpdateSelectedPlatformInfo(String customerId, String actionKey, List platforms) { // 1.物理删除客户-action所有对应关系 - int deletedCount = thirdplatformCustomerActionDao.deleteByCustomerIdAndActionKey(platforms.get(0).getCustomerId(), platforms.get(0).getActionKey()); + thirdplatformCustomerActionDao.deleteByCustomerIdAndActionKey(customerId, actionKey); platforms.stream().forEach(pt -> { - String customerId = pt.getCustomerId(); - String platformId = pt.getPlatformId(); - // 2.更新用户自定义的平台信息 - updateThirdPlatformCustomerRegInfo(pt); + updateThirdPlatformCustomerRegInfo(customerId, pt); // 3.重新建立customer-platform-action对应关系 ThirdplatformCustomerActionEntity tpcaEntity = new ThirdplatformCustomerActionEntity(); - tpcaEntity.setPlatformId(platformId); + tpcaEntity.setPlatformId(pt.getPlatformId()); tpcaEntity.setCustomerId(customerId); - tpcaEntity.setActionKey(pt.getActionKey()); + tpcaEntity.setActionKey(actionKey); thirdplatformCustomerActionDao.insert(tpcaEntity); }); @@ -101,10 +94,10 @@ public class ThirdPlatformServiceImpl implements ThirdPlatformService { * @author wxz * @date 2021.03.19 15:22 */ - private void updateThirdPlatformCustomerRegInfo(ThirdPlatformFormDTO platformFormDTO) { + private void updateThirdPlatformCustomerRegInfo(String customerId, ThirdPlatformFormDTO platformFormDTO) { LambdaQueryWrapper conditions = new QueryWrapper() .lambda() - .eq(ThirdplatformCustomerRegisterEntity::getCustomerId, platformFormDTO.getCustomerId()) + .eq(ThirdplatformCustomerRegisterEntity::getCustomerId, customerId) .eq(ThirdplatformCustomerRegisterEntity::getPlatformId, platformFormDTO.getPlatformId()); ThirdplatformCustomerRegisterEntity entity = new ThirdplatformCustomerRegisterEntity(); diff --git a/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/CustomerProjectParameterServiceImpl.java b/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/CustomerProjectParameterServiceImpl.java index 3595f23a94..6142562041 100644 --- a/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/CustomerProjectParameterServiceImpl.java +++ b/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/CustomerProjectParameterServiceImpl.java @@ -31,6 +31,7 @@ import com.epmet.constant.ThirdPlatformActions; import com.epmet.dao.CustomerProjectParameterDao; import com.epmet.dto.CustomerProjectParameterDTO; import com.epmet.dto.form.ParameterFormDTO; +import com.epmet.dto.form.SaveOrUpdateCustSelPlatformFormDTO; import com.epmet.dto.form.ThirdPlatformConfigFormDTO; import com.epmet.dto.form.ThirdPlatformFormDTO; import com.epmet.dto.result.ParameterResultDTO; @@ -327,7 +328,7 @@ public class CustomerProjectParameterServiceImpl extends BaseServiceImpl formDTOS = platformList.stream().map(p -> { + List platforms = platformList.stream().map(p -> { ThirdPlatformFormDTO thirdPlatformFormDTO = new ThirdPlatformFormDTO(); thirdPlatformFormDTO.setActionKey(ThirdPlatformActions.PROJECT_ASSIST); thirdPlatformFormDTO.setCustomerId(customerId); @@ -336,7 +337,12 @@ public class CustomerProjectParameterServiceImpl extends BaseServiceImpl