Browse Source

修复:

1.客户保存选中的第三方列表为空的时候,不处理的bug
feature/evaluate
wxz 5 years ago
parent
commit
7f04bad985
  1. 19
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/SaveOrUpdateCustSelPlatformFormDTO.java
  2. 3
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java
  3. 3
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/ThirdOpenFeignClientFallback.java
  4. 40
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/ApiService.java
  5. 10
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/DemoApiService.java
  6. 55
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/LuzhouGridPlatformApiService.java
  7. 11
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/result/LZGridPlatformBaseResult.java
  8. 7
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ThirdPlatformController.java
  9. 2
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ThirdPlatformService.java
  10. 21
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ThirdPlatformServiceImpl.java
  11. 10
      epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/CustomerProjectParameterServiceImpl.java

19
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<ThirdPlatformFormDTO> platforms;
}

3
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<ThirdPlatformFormDTO> input);
Result saveOrUpdateSelectedPlatformsInfo(@RequestBody SaveOrUpdateCustSelPlatformFormDTO input);
/**
* 根据客户id和动作列出客户在指定动作下可用的第三方平台

3
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<ThirdPlatformFormDTO> input) {
public Result saveOrUpdateSelectedPlatformsInfo(SaveOrUpdateCustSelPlatformFormDTO input) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_THIRD_SERVER, "saveOrUpdateSelectedPlatformsInfo", input);
}

40
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<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失败。");
}
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);
}

10
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) {
}
}

55
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<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());
}
}
}

11
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<R> {
private Boolean success;
private String code;
private R result;
// 有其他内容可直接写上
}

7
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<ThirdPlatformFormDTO> 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();
}
}

2
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<ThirdPlatformFormDTO> platforms);
void saveOrUpdateSelectedPlatformInfo(String customerId, String actionKey, List<ThirdPlatformFormDTO> platforms);
}

21
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<ThirdPlatformFormDTO> platforms) {
if (CollectionUtils.isEmpty(platforms)) {
return;
}
public void saveOrUpdateSelectedPlatformInfo(String customerId, String actionKey, List<ThirdPlatformFormDTO> 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<ThirdplatformCustomerRegisterEntity> conditions = new QueryWrapper<ThirdplatformCustomerRegisterEntity>()
.lambda()
.eq(ThirdplatformCustomerRegisterEntity::getCustomerId, platformFormDTO.getCustomerId())
.eq(ThirdplatformCustomerRegisterEntity::getCustomerId, customerId)
.eq(ThirdplatformCustomerRegisterEntity::getPlatformId, platformFormDTO.getPlatformId());
ThirdplatformCustomerRegisterEntity entity = new ThirdplatformCustomerRegisterEntity();

10
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<Custome
// 1.本地执行配置更新
saveThirdPlatformSendProjectSwitch(customerId, sendProjectSwitch);
// 2.调用远程third服务,更新或新增客户-平台-等信息 ThirdPlatformFormDTO thirdPlatformFormDTO = new ThirdPlatformFormDTO();
List<ThirdPlatformFormDTO> formDTOS = platformList.stream().map(p -> {
List<ThirdPlatformFormDTO> 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<Custome
thirdPlatformFormDTO.setPlatformName(p.getPlatformName());
return thirdPlatformFormDTO;
}).collect(Collectors.toList());
Result result = thirdOpenFeignClient.saveOrUpdateSelectedPlatformsInfo(formDTOS);
SaveOrUpdateCustSelPlatformFormDTO form = new SaveOrUpdateCustSelPlatformFormDTO();
form.setPlatforms(platforms);
form.setCustomerId(customerId);
form.setActionKey(ThirdPlatformActions.PROJECT_ASSIST);
Result result = thirdOpenFeignClient.saveOrUpdateSelectedPlatformsInfo(form);
if (result == null || !result.success()) {
throw new RenException("调用Third服务,保存第三方平台列表失败");
}

Loading…
Cancel
Save