From 0d4a1ee11eed68dcc27c77642dbcc277be888e61 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 16 Mar 2021 09:52:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90ApiService=E4=BD=93=E7=B3=BB?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=EF=BC=8C=E5=87=86=E5=A4=87=E6=8E=A5=E5=85=A5?= =?UTF-8?q?=E5=85=B7=E4=BD=93=E7=9A=84=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/tools/redis/RedisKeys.java | 9 +++ .../com/epmet/constant/ApiServiceActions.java | 11 ++++ .../epmet/dto/form/ProjectAssistFormDTO.java | 15 +++++ .../com/epmet/dto/form/TPFDemoFormDTO.java | 20 ++++++ .../java/com/epmet/apiservice/ApiService.java | 63 +++++++++++++++++++ .../epmet/apiservice/impl/DemoApiService.java | 31 +++++++++ .../impl/LuzhouGridPlatformApiService.java | 19 ++++++ .../LZGridPlatformProjectAssistResult.java | 4 ++ .../result/ProjectAssistResult.java | 8 +++ .../com/epmet/controller/BizController.java | 54 ++++++++++++++++ .../com/epmet/dao/ThirdplatformActionDao.java | 33 ++++++++++ .../dao/ThirdplatformCustomerRegisterDao.java | 36 +++++++++++ .../java/com/epmet/dao/ThirdplatformDao.java | 33 ++++++++++ .../entity/ThirdplatformActionEntity.java | 51 +++++++++++++++ .../ThirdplatformCustomerRegisterEntity.java | 51 +++++++++++++++ .../com/epmet/entity/ThirdplatformEntity.java | 61 ++++++++++++++++++ .../com/epmet/service/ApiServiceSelector.java | 46 ++++++++++++++ .../com/epmet/service/ProjectService.java | 15 +++++ .../service/impl/ProjectServiceImpl.java | 40 ++++++++++++ .../mapper/ThirdplatformActionDao.xml | 19 ++++++ .../ThirdplatformCustomerRegisterDao.xml | 36 +++++++++++ .../resources/mapper/ThirdplatformDao.xml | 21 +++++++ .../epmet/feign/OperCrmOpenFeignClient.java | 9 +++ .../OperCrmOpenFeignClientFallback.java | 5 ++ .../epmet/controller/CustomerController.java | 13 ++++ .../dao/CustomerThirdplatApiserviceDao.java | 10 +++ .../CustomerThirdplatApiServiceService.java | 9 +++ ...ustomerThirdplatApiServiceServiceImpl.java | 19 ++++++ .../mapper/CustomerThirdplatApiserviceDao.xml | 14 +++++ 29 files changed, 755 insertions(+) create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/constant/ApiServiceActions.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ProjectAssistFormDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/TPFDemoFormDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/ApiService.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/DemoApiService.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/LuzhouGridPlatformApiService.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/result/LZGridPlatformProjectAssistResult.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/result/ProjectAssistResult.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/BizController.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformActionDao.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformCustomerRegisterDao.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformDao.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ThirdplatformActionEntity.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ThirdplatformCustomerRegisterEntity.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ThirdplatformEntity.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ApiServiceSelector.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ProjectService.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ProjectServiceImpl.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformActionDao.xml create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformCustomerRegisterDao.xml create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformDao.xml diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index 098dd1c14d..220d621195 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -370,4 +370,13 @@ public class RedisKeys { public static String getCustomerApiServiceKey(String customerId) { return rootPrefix.concat("customer:thirdplat:apiservice:").concat(customerId); } + + /** + * 一个客户对应多个第三方平台,多个ApiService的key + * @param customerId + * @return + */ + public static String listCustomerApiServiceListKey(String customerId) { + return rootPrefix.concat("customer:thirdplat:apiservicelist:").concat(customerId); + } } diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/constant/ApiServiceActions.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/constant/ApiServiceActions.java new file mode 100644 index 0000000000..e754e8f31e --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/constant/ApiServiceActions.java @@ -0,0 +1,11 @@ +package com.epmet.constant; + +/** + * api service 常量列表 + */ +public interface ApiServiceActions { + + // 测试动作 + String DEMO_ACTION = "demoAction"; + +} diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ProjectAssistFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ProjectAssistFormDTO.java new file mode 100644 index 0000000000..543524f1b1 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ProjectAssistFormDTO.java @@ -0,0 +1,15 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class ProjectAssistFormDTO { + + private String customerId; + + @NotBlank(message = "平台ID不能为空") + private String platformId; + +} diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/TPFDemoFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/TPFDemoFormDTO.java new file mode 100644 index 0000000000..c790a4a529 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/TPFDemoFormDTO.java @@ -0,0 +1,20 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * 第三方平台-demo form dto + */ +@Data +public class TPFDemoFormDTO { + + private String demoString; + + @NotBlank(message = "客户ID不能为空") + private String customerId; + + @NotBlank(message = "平台ID不能为空") + private String platformId; +} 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 new file mode 100644 index 0000000000..da169d165a --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/ApiService.java @@ -0,0 +1,63 @@ +package com.epmet.apiservice; + +import com.epmet.apiservice.result.ProjectAssistResult; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.utils.SpringContextUtils; +import com.epmet.dao.ThirdplatformCustomerRegisterDao; +import com.epmet.dto.form.ProjectAssistFormDTO; +import com.epmet.dto.form.TPFDemoFormDTO; +import com.epmet.entity.ThirdplatformCustomerRegisterEntity; + +/** + * ApiService,对接第三方平台的抽象类 + * 每一个具体平台的ApiService都是该抽象类的子类,选择性实现抽象类中的某些方法,提供具体业务逻辑 + */ +public abstract class ApiService { + + /** + * @Description 判断该客户是否注册了该平台 + * @return true:已注册该平台,可以使用;false:未注册,无法使用 + * @author wxz + * @date 2021.03.15 11:09 + */ + public boolean isRegistered(String customerId, String platformId) { + ThirdplatformCustomerRegisterDao tpcRegDao = SpringContextUtils.getBean(ThirdplatformCustomerRegisterDao.class); + ThirdplatformCustomerRegisterEntity tpcReg = tpcRegDao.getByCustomerIdAndPlatformId(customerId, platformId); + if (tpcReg == null) { + return false; + } + return true; + } + + /** + * @Description 判断客户是否注册了指定的平台,如果没有注册,则抛出异常 + * @return + * @author wxz + * @date 2021.03.15 21:39 + */ + public void judgeRegistered(String customerId, String platformId) { + if (!isRegistered(customerId, platformId)) { + throw new RenException(String.format("客户:%s没有配置第三方平台:%s", customerId, platformId)); + } + } + + /** + * @Description demo示例方法 + * @return + * @author wxz + * @date 2021.03.15 10:46 + */ + public String demoAction(TPFDemoFormDTO tpfDemoFormDTO) { + return "do success !!"; + } + + /** + * @Description 项目协同处理 + * @return 项目协同处理的Result。具体的平台返回的结果最终都要转化为这个ProjectAssistResult返回 + * @author wxz + * @date 2021.03.16 09:28 + */ + public ProjectAssistResult projectAssist(ProjectAssistFormDTO formDTO) { + return null; + } +} 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 new file mode 100644 index 0000000000..6c1aca3917 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/DemoApiService.java @@ -0,0 +1,31 @@ +package com.epmet.apiservice.impl; + +import com.epmet.apiservice.ApiService; +import com.epmet.apiservice.result.ProjectAssistResult; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.constant.ApiServiceActions; +import com.epmet.dto.form.ProjectAssistFormDTO; +import com.epmet.dto.form.TPFDemoFormDTO; +import com.epmet.feign.OperCrmOpenFeignClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * demo api service + */ +@Component(value = "demoApiService") +public class DemoApiService extends ApiService { + + Logger logger = LoggerFactory.getLogger(DemoApiService.class); + + @Autowired + private OperCrmOpenFeignClient operCrmOpenFeignClient; + + @Override + public ProjectAssistResult projectAssist(ProjectAssistFormDTO formDTO) { + logger.info("DemoApiService发送项目协助到第三方平台成功"); + return null; + } +} 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 new file mode 100644 index 0000000000..4081bfad61 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/impl/LuzhouGridPlatformApiService.java @@ -0,0 +1,19 @@ +package com.epmet.apiservice.impl; + +import com.epmet.apiservice.ApiService; +import com.epmet.apiservice.result.ProjectAssistResult; +import com.epmet.dto.form.ProjectAssistFormDTO; +import org.springframework.stereotype.Component; + +/** + * 泸州网格化平台ApiService + */ +@Component("luzhouGridPlatformApiService") +public class LuzhouGridPlatformApiService extends ApiService { + + @Override + public ProjectAssistResult projectAssist(ProjectAssistFormDTO formDTO) { + System.out.println("泸州网格化平台项目协助发送成功"); + return null; + } +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/result/LZGridPlatformProjectAssistResult.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/result/LZGridPlatformProjectAssistResult.java new file mode 100644 index 0000000000..ef74410885 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/result/LZGridPlatformProjectAssistResult.java @@ -0,0 +1,4 @@ +package com.epmet.apiservice.result; + +public class LZGridPlatformProjectAssistResult { +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/result/ProjectAssistResult.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/result/ProjectAssistResult.java new file mode 100644 index 0000000000..2da96d1e17 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/apiservice/result/ProjectAssistResult.java @@ -0,0 +1,8 @@ +package com.epmet.apiservice.result; + +import lombok.Data; + +@Data +public class ProjectAssistResult { + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/BizController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/BizController.java new file mode 100644 index 0000000000..ed83a196bf --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/BizController.java @@ -0,0 +1,54 @@ +package com.epmet.controller; + +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dto.form.ProjectAssistFormDTO; +import com.epmet.dto.form.TPFDemoFormDTO; +import com.epmet.service.ProjectService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.lang.management.MemoryManagerMXBean; + +/** + * 对接第三方平台业务相关的controller + * 我们系统当中每一个需要发送到第三方平台的操作,只对应这里的一个方法,根据参数传入platformId,内部根据配置获取指定的APiService进行具体平台的调用 + * 每一个平台都有自己的ApiSerivce + */ +@RestController +@RequestMapping("biz") +public class BizController { + + @Autowired + private ProjectService projectService; + + /** + * @Description demo方法 + * @return + * @author wxz + * @date 2021.03.15 21:11 + */ + @PostMapping("demo-action") + public Result demoAction(@RequestBody TPFDemoFormDTO tpfDemoFormDTO) { + ValidatorUtils.validateEntity(tpfDemoFormDTO); + String r = projectService.demoAction(tpfDemoFormDTO); + return new Result().ok(r); + } + + /** + * @Description 发送项目协同处理方法 + * @return + * @author wxz + * @date 2021.03.15 21:13 + */ + @PostMapping("project-assist") + public Result projectAssist(@RequestBody ProjectAssistFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); + projectService.projectAssist(formDTO); + return new Result(); + } + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformActionDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformActionDao.java new file mode 100644 index 0000000000..9b309c15fc --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformActionDao.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.ThirdplatformActionEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-03-15 + */ +@Mapper +public interface ThirdplatformActionDao extends BaseDao { + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformCustomerRegisterDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformCustomerRegisterDao.java new file mode 100644 index 0000000000..e3a39cbbe2 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformCustomerRegisterDao.java @@ -0,0 +1,36 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.constant.ThirdPlatformConstant; +import com.epmet.entity.ThirdplatformCustomerRegisterEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-03-15 + */ +@Mapper +public interface ThirdplatformCustomerRegisterDao extends BaseDao { + + ThirdplatformCustomerRegisterEntity getByCustomerIdAndPlatformId(@Param("customerId") String customerId, @Param("platformId") String platformId); +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformDao.java new file mode 100644 index 0000000000..593d20923f --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformDao.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.ThirdplatformEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-03-15 + */ +@Mapper +public interface ThirdplatformDao extends BaseDao { + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ThirdplatformActionEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ThirdplatformActionEntity.java new file mode 100644 index 0000000000..88c7a8cd2f --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ThirdplatformActionEntity.java @@ -0,0 +1,51 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-03-15 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("thirdplatform_action") +public class ThirdplatformActionEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * + */ + private String platformId; + + /** + * + */ + private String actionKey; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ThirdplatformCustomerRegisterEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ThirdplatformCustomerRegisterEntity.java new file mode 100644 index 0000000000..b3b77fb626 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ThirdplatformCustomerRegisterEntity.java @@ -0,0 +1,51 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-03-15 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("thirdplatform_customer_register") +public class ThirdplatformCustomerRegisterEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * + */ + private String customerId; + + /** + * + */ + private String platformId; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ThirdplatformEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ThirdplatformEntity.java new file mode 100644 index 0000000000..4fede6dcdf --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ThirdplatformEntity.java @@ -0,0 +1,61 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-03-15 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("thirdplatform") +public class ThirdplatformEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 平台名称 + */ + private String platformName; + + /** + * 平台唯一KEY + */ + private String platformKey; + + /** + * + */ + private String platformSecret; + + /** + * apiservice + */ + private String apiService; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ApiServiceSelector.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ApiServiceSelector.java new file mode 100644 index 0000000000..6e45fc2122 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ApiServiceSelector.java @@ -0,0 +1,46 @@ +package com.epmet.service; + +import com.epmet.apiservice.ApiService; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.utils.SpringContextUtils; +import com.epmet.dao.ThirdplatformDao; +import com.epmet.entity.ThirdplatformEntity; + +/** + * ApiService选择器 + */ +public interface ApiServiceSelector { + + /** + * @Description 根据platformId查找platform对应的ApiService。如果找不到对应的api service,则返回null + * @return ApiService + * @author wxz + * @date 2021.03.15 20:59 + */ + default ApiService trySelectApiService(String platformId) { + ThirdplatformDao thirdplatformDao = SpringContextUtils.getBean(ThirdplatformDao.class); + ThirdplatformEntity thirdplatform = thirdplatformDao.selectById(platformId); + + if (thirdplatform == null) { + return null; + } + return (ApiService)SpringContextUtils.getBean(thirdplatform.getApiService()); + } + + /** + * @Description 根据platformId查找platform对应的ApiService。如果找不到对应的api service,则抛出RenException异常 + * @return ApiService + * @author wxz + * @date 2021.03.15 21:08 + */ + default ApiService selectApiService(String platformId) { + ThirdplatformDao thirdplatformDao = SpringContextUtils.getBean(ThirdplatformDao.class); + ThirdplatformEntity thirdplatform = thirdplatformDao.selectById(platformId); + + if (thirdplatform == null) { + throw new RenException(String.format("ID为%s的第三方平台不存在", platformId)); + } + return (ApiService)SpringContextUtils.getBean(thirdplatform.getApiService()); + } + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ProjectService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ProjectService.java new file mode 100644 index 0000000000..25d4f6de51 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ProjectService.java @@ -0,0 +1,15 @@ +package com.epmet.service; + +import com.epmet.dto.form.ProjectAssistFormDTO; +import com.epmet.dto.form.TPFDemoFormDTO; +import org.springframework.stereotype.Service; + +/** + * 该service用于封装project相关的代码 + */ +public interface ProjectService { + + String demoAction(TPFDemoFormDTO formDTO); + + void projectAssist(ProjectAssistFormDTO formDTO); +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ProjectServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ProjectServiceImpl.java new file mode 100644 index 0000000000..fb57663d72 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ProjectServiceImpl.java @@ -0,0 +1,40 @@ +package com.epmet.service.impl; + +import com.epmet.apiservice.ApiService; +import com.epmet.apiservice.result.ProjectAssistResult; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.dto.form.ProjectAssistFormDTO; +import com.epmet.dto.form.TPFDemoFormDTO; +import com.epmet.service.ApiServiceSelector; +import com.epmet.service.ProjectService; +import org.springframework.stereotype.Service; + +@Service +public class ProjectServiceImpl implements ProjectService, ApiServiceSelector { + + @Override + public String demoAction(TPFDemoFormDTO formDTO) { + String customerId = formDTO.getCustomerId(); + String platformId = formDTO.getPlatformId(); + + // 注意,此处会如果找不到对应的ApiService会抛出异常 + ApiService apiService = selectApiService(platformId); + apiService.judgeRegistered(customerId, platformId); + + return apiService.demoAction(formDTO); + } + + @Override + public void projectAssist(ProjectAssistFormDTO formDTO) { + String customerId = formDTO.getCustomerId(); + String platformId = formDTO.getPlatformId(); + + // 注意,此处会如果找不到对应的ApiService会抛出异常 + ApiService apiService = selectApiService(platformId); + apiService.judgeRegistered(customerId, platformId); + + System.out.println(apiService); + + ProjectAssistResult projectAssistResult = apiService.projectAssist(formDTO); + } +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformActionDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformActionDao.xml new file mode 100644 index 0000000000..03cf514cda --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformActionDao.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformCustomerRegisterDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformCustomerRegisterDao.xml new file mode 100644 index 0000000000..c8545d01ee --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformCustomerRegisterDao.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformDao.xml new file mode 100644 index 0000000000..0bc68d7af2 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformDao.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java index 0f4313dfad..f4dec72cac 100644 --- a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java +++ b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java @@ -122,4 +122,13 @@ public interface OperCrmOpenFeignClient { **/ @GetMapping("/oper/crm/customer/getallsubcustomerids/{customerId}") Result> getAllSubCustomerIds(@PathVariable("customerId") String customerId); + + /** + * @Description 根据客户id列出该客户所有的apiService + * @return + * @author wxz + * @date 2021.03.15 15:13 + */ + @PostMapping("list-apiservice-by-customerid") + Result> listApiServiceByCustomerId(@RequestBody ApiServiceFormDTO form); } diff --git a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/fallback/OperCrmOpenFeignClientFallback.java b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/fallback/OperCrmOpenFeignClientFallback.java index 5de09ce167..134ffcb242 100644 --- a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/fallback/OperCrmOpenFeignClientFallback.java +++ b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/fallback/OperCrmOpenFeignClientFallback.java @@ -95,4 +95,9 @@ public class OperCrmOpenFeignClientFallback implements OperCrmOpenFeignClient { public Result> getAllSubCustomerIds(String customerId) { return ModuleUtils.feignConError(ServiceConstant.OPER_CRM_SERVER, "getAllSubCustomerIds", customerId); } + + @Override + public Result> listApiServiceByCustomerId(ApiServiceFormDTO form) { + return ModuleUtils.feignConError(ServiceConstant.OPER_CRM_SERVER, "listApiServiceByCustomerId", form); + } } diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerController.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerController.java index c5330a9abd..461c06f3f6 100644 --- a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerController.java +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerController.java @@ -376,4 +376,17 @@ public class CustomerController { } return new Result<>(); } + + /** + * @Description 根据客户id列出该客户所有的apiService + * @return + * @author wxz + * @date 2021.03.15 15:13 + */ + @PostMapping("list-apiservice-by-customerid") + public Result> listApiServiceByCustomerId(@RequestBody ApiServiceFormDTO form) { + ValidatorUtils.validateEntity(form, ApiServiceFormDTO.GetByCustomerId.class); + String customerId = form.getCustomerId(); + return new Result>().ok(customerThirdplatApiServiceService.listByCustomerId(customerId)); + } } diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerThirdplatApiserviceDao.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerThirdplatApiserviceDao.java index 52f05556b1..a879264c54 100644 --- a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerThirdplatApiserviceDao.java +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerThirdplatApiserviceDao.java @@ -23,6 +23,8 @@ import com.epmet.entity.CustomerThirdplatApiserviceEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.List; + /** * 客户所属的第三方平台的apiService列表 * @@ -33,4 +35,12 @@ import org.apache.ibatis.annotations.Param; public interface CustomerThirdplatApiserviceDao extends BaseDao { ThirdplatApiserviceResultDTO getByCustomerId(@Param("customerId") String customerId); + + /** + * @Description 列出该客户所有的ApiService + * @return + * @author wxz + * @date 2021.03.15 15:07 + */ + List listByCustomerId(String customerId); } \ No newline at end of file diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerThirdplatApiServiceService.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerThirdplatApiServiceService.java index a1f9fa91e9..eb6adbe6ec 100644 --- a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerThirdplatApiServiceService.java +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerThirdplatApiServiceService.java @@ -3,6 +3,8 @@ package com.epmet.service; import com.epmet.dto.result.ThirdplatApiserviceResultDTO; import com.epmet.entity.CustomerThirdplatApiserviceEntity; +import java.util.List; + public interface CustomerThirdplatApiServiceService { /** @@ -13,4 +15,11 @@ public interface CustomerThirdplatApiServiceService { */ ThirdplatApiserviceResultDTO getByCustomerId(String customerId); + /** + * 根据客户id列出第三方平台列表 + * @param customerId + * @return + */ + List listByCustomerId(String customerId); + } diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerThirdplatApiServiceServiceImpl.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerThirdplatApiServiceServiceImpl.java index 9cfa19a820..9613f30f60 100644 --- a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerThirdplatApiServiceServiceImpl.java +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerThirdplatApiServiceServiceImpl.java @@ -8,9 +8,12 @@ import com.epmet.dto.result.ThirdplatApiserviceResultDTO; import com.epmet.entity.CustomerThirdplatApiserviceEntity; import com.epmet.service.CustomerThirdplatApiServiceService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import java.util.ArrayList; +import java.util.List; import java.util.Map; @Service @@ -22,6 +25,10 @@ public class CustomerThirdplatApiServiceServiceImpl implements CustomerThirdplat @Autowired private CustomerThirdplatApiserviceDao thirdplatApiserviceDao; + @Autowired + private RedisTemplate tpasRedisTemplate; + + @Override public ThirdplatApiserviceResultDTO getByCustomerId(String customerId) { ThirdplatApiserviceResultDTO apiService = null; @@ -39,4 +46,16 @@ public class CustomerThirdplatApiServiceServiceImpl implements CustomerThirdplat return apiService; } + + @Override + public List listByCustomerId(String customerId) { + List apiServices = tpasRedisTemplate.opsForList().range(RedisKeys.listCustomerApiServiceListKey(customerId), 0, -1); + if (!CollectionUtils.isEmpty(apiServices)) { + return apiServices; + } + + apiServices = thirdplatApiserviceDao.listByCustomerId(customerId); + tpasRedisTemplate.opsForList().rightPushAll(RedisKeys.listCustomerApiServiceListKey(customerId), apiServices); + return apiServices; + } } diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/resources/mapper/CustomerThirdplatApiserviceDao.xml b/epmet-module/oper-crm/oper-crm-server/src/main/resources/mapper/CustomerThirdplatApiserviceDao.xml index 8390e5647f..86f93189e2 100644 --- a/epmet-module/oper-crm/oper-crm-server/src/main/resources/mapper/CustomerThirdplatApiserviceDao.xml +++ b/epmet-module/oper-crm/oper-crm-server/src/main/resources/mapper/CustomerThirdplatApiserviceDao.xml @@ -29,5 +29,19 @@ where cta.CUSTOMER_ID = #{customerId} + + \ No newline at end of file