From 3de10a15646e40c42dcd3ed9f0e66115885b2744 Mon Sep 17 00:00:00 2001 From: wxz Date: Mon, 7 Sep 2020 10:23:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=96=E9=83=A8=E5=BA=94=E7=94=A8=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=A2=9E=E5=8A=A0=E5=86=85=E9=83=A8=E5=AE=A2=E6=88=B7?= =?UTF-8?q?ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/dto/form/ExternalAppFormDTO.java | 9 ++++ .../dto/result/ExternalAppResultDTO.java | 4 ++ .../common-service-server/pom.xml | 6 +++ .../controller/ExternalAppController.java | 6 ++- .../com/epmet/entity/ExternalAppEntity.java | 2 + .../java/com/epmet/enu/CustomerTypeEnum.java | 41 +++++++++++++++++++ .../com/epmet/service/ExternalAppService.java | 4 +- .../service/impl/ExternalAppServiceImpl.java | 37 ++++++++++++++++- .../V0.0.4__add_extcustomer_source.sql | 1 + .../main/resources/mapper/ExternalAppDao.xml | 3 +- .../epmet/feign/OperCrmOpenFeignClient.java | 3 +- 11 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/enu/CustomerTypeEnum.java create mode 100644 epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.4__add_extcustomer_source.sql diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java index 00b99a500e..8a1b6713c0 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java @@ -20,6 +20,15 @@ public class ExternalAppFormDTO { @NotBlank(message = "缺少所属客户ID", groups = { AddExternalApp.class, UpdateExternalApp.class }) private String customerId; + /** + * 客户类型 + * external:外部 + * internal:内部 + */ + @NotBlank(message = "缺少客户类型", groups = { AddExternalApp.class, UpdateExternalApp.class }) + private String customerType; + + private Integer pageNo = 1; private Integer pageSize = 10; diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java index e4cf3fedb6..93fba80fa2 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java @@ -21,6 +21,10 @@ public class ExternalAppResultDTO { */ private String customerName; + private String customerType; + + private String customerTypeName; + /** * 秘钥 */ diff --git a/epmet-module/epmet-common-service/common-service-server/pom.xml b/epmet-module/epmet-common-service/common-service-server/pom.xml index 597eb77772..7e176a8857 100644 --- a/epmet-module/epmet-common-service/common-service-server/pom.xml +++ b/epmet-module/epmet-common-service/common-service-server/pom.xml @@ -64,6 +64,12 @@ jjwt 0.7.0 + + + com.epmet + oper-crm-client + 2.0.0 + diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java index 45bdb8bef6..b8e664e6c4 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java @@ -64,8 +64,9 @@ public class ExternalAppController { String appName = formDTO.getAppName(); String customerId = formDTO.getCustomerId(); + String customerType = formDTO.getCustomerType(); - ExternalAppResultDTO dto = externalAppService.add(appName, customerId); + ExternalAppResultDTO dto = externalAppService.add(appName, customerId, customerType); return new Result().ok(dto); } @@ -82,8 +83,9 @@ public class ExternalAppController { String appId = formDTO.getAppId(); String appName = formDTO.getAppName(); String customerId = formDTO.getCustomerId(); + String customerType = formDTO.getCustomerType(); - ExternalAppResultDTO dto = externalAppService.updateById(appId, appName, customerId); + ExternalAppResultDTO dto = externalAppService.updateById(appId, appName, customerId, customerType); return new Result().ok(dto); } diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/entity/ExternalAppEntity.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/entity/ExternalAppEntity.java index e4a4056108..421e9712f5 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/entity/ExternalAppEntity.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/entity/ExternalAppEntity.java @@ -48,4 +48,6 @@ public class ExternalAppEntity extends BaseEpmetEntity { */ private String customerId; + private String customerType; + } diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/enu/CustomerTypeEnum.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/enu/CustomerTypeEnum.java new file mode 100644 index 0000000000..c8554aeff2 --- /dev/null +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/enu/CustomerTypeEnum.java @@ -0,0 +1,41 @@ +package com.epmet.enu; + +import org.apache.commons.lang3.StringUtils; + +/** + * 客户类型枚举 + */ +public enum CustomerTypeEnum { + + INTERNAL("internal", "内部应用"), + EXTERNAL("external", "外部应用"), + UN_KNOW("unknow", "未知应用"); + + private String type; + private String name; + + CustomerTypeEnum(String type, String name) { + this.type = type; + this.name = name; + } + + public static String getName(String type) { + if (StringUtils.isBlank(type)) { + return null; + } + for (CustomerTypeEnum value : CustomerTypeEnum.values()) { + if (value.type.equals(type)) { + return value.name; + } + } + return UN_KNOW.name; + } + + public String getType() { + return type; + } + + public String getName() { + return name; + } +} diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java index 8f38fa2a83..a43019d388 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java @@ -27,9 +27,9 @@ import com.epmet.dto.result.ExternalAppResultDTO; * @since v1.0.0 2020-08-18 */ public interface ExternalAppService { - ExternalAppResultDTO add(String appName, String customerId); + ExternalAppResultDTO add(String appName, String customerId, String customerType); - ExternalAppResultDTO updateById(String appId, String appName, String customerId); + ExternalAppResultDTO updateById(String appId, String appName, String customerId, String customerType); PageData listPage(Integer pageNo, Integer pageSize, String customerId); diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java index dcfc930aad..b04ccc65c2 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java @@ -20,15 +20,21 @@ package com.epmet.service.impl; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.Result; import com.epmet.dao.ExternalAppDao; import com.epmet.dao.ExternalAppSecretDao; import com.epmet.dao.ExternalCustomerDao; +import com.epmet.dto.CustomerDTO; import com.epmet.dto.result.ExternalAppResultDTO; import com.epmet.entity.ExternalAppEntity; import com.epmet.entity.ExternalAppSecretEntity; +import com.epmet.enu.CustomerTypeEnum; +import com.epmet.feign.OperCrmOpenFeignClient; import com.epmet.service.ExternalAppService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -45,6 +51,8 @@ import java.util.UUID; @Service public class ExternalAppServiceImpl implements ExternalAppService { + private static Logger logger = LoggerFactory.getLogger(ExternalAppServiceImpl.class); + @Autowired private ExternalAppDao externalAppDao; @@ -54,9 +62,12 @@ public class ExternalAppServiceImpl implements ExternalAppService { @Autowired private ExternalCustomerDao externalCustomerDao; + @Autowired + private OperCrmOpenFeignClient operCrmOpenFeignClient; + @Transactional @Override - public ExternalAppResultDTO add(String appName, String customerId) { + public ExternalAppResultDTO add(String appName, String customerId, String customerType) { Integer count = externalAppDao.countByAppNameAndCustomerId(appName, customerId); if (count > 0) { throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_EXISTS.getCode(), @@ -72,6 +83,7 @@ public class ExternalAppServiceImpl implements ExternalAppService { ExternalAppEntity appEntity = new ExternalAppEntity(); appEntity.setAppName(appName); appEntity.setCustomerId(customerId); + appEntity.setCustomerType(customerType); externalAppDao.insert(appEntity); // 秘钥表插入 @@ -98,7 +110,7 @@ public class ExternalAppServiceImpl implements ExternalAppService { } @Override - public ExternalAppResultDTO updateById(String appId, String appName, String customerId) { + public ExternalAppResultDTO updateById(String appId, String appName, String customerId, String customerType) { ExternalAppEntity exists = externalAppDao.selectById(appId); if (exists == null) { throw new RenException(EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getCode(), @@ -113,6 +125,7 @@ public class ExternalAppServiceImpl implements ExternalAppService { exists.setAppName(appName); exists.setCustomerId(customerId); + exists.setCustomerType(customerType); externalAppDao.updateById(exists); ExternalAppResultDTO resultDTO = new ExternalAppResultDTO(); @@ -126,6 +139,26 @@ public class ExternalAppServiceImpl implements ExternalAppService { public PageData listPage(Integer pageNo, Integer pageSize, String customerId) { PageHelper.startPage(pageNo, pageSize); List list = externalAppDao.list(customerId); + for (ExternalAppResultDTO app : list) { + // 设置客户类型中文 + app.setCustomerTypeName(CustomerTypeEnum.getName(app.getCustomerType())); + + if (CustomerTypeEnum.INTERNAL.getType().equals(app.getCustomerType())) { + // 如果是内部客户,那么需要去oper_crm库查询客户信息 + CustomerDTO form = new CustomerDTO(); + form.setId(app.getCustomerId()); + Result customerInfoRst = operCrmOpenFeignClient.getCustomerInfo(form); + if (! customerInfoRst.success()) { + logger.error("common service->ExternalAppServiceImpl#listPage查询内部客户失败:{}", customerInfoRst.getInternalMsg()); + continue; + } + // 设置客户名称 + CustomerDTO customerInfo = customerInfoRst.getData(); + if (customerInfo != null) { + app.setCustomerName(customerInfo.getCustomerName()); + } + } + } PageInfo pageInfo = new PageInfo<>(list); return new PageData<>(list, pageInfo.getTotal()); } diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.4__add_extcustomer_source.sql b/epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.4__add_extcustomer_source.sql new file mode 100644 index 0000000000..397bbebd5d --- /dev/null +++ b/epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.4__add_extcustomer_source.sql @@ -0,0 +1 @@ +alter table external_app add column CUSTOMER_SOURCE varchar(20) not null after CUSTOMER_ID; \ No newline at end of file diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml b/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml index 588f735da7..b28e57914d 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml +++ b/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml @@ -33,10 +33,11 @@ ea.APP_NAME, ea.CUSTOMER_ID, ec.CUSTOMER_NAME , + ea.CUSTOMER_TYPE, eas.SECRET FROM external_app ea - INNER JOIN external_customer ec ON ( ea.CUSTOMER_ID = ec.ID ) + LEFT JOIN external_customer ec ON ( ea.CUSTOMER_ID = ec.ID ) LEFT JOIN external_app_secret eas ON (ea.ID = eas.APP_ID) ea.DEL_FLAG = 0 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 7b426012b4..b4ca88c64f 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 @@ -19,7 +19,8 @@ import java.util.List; * @author yinzuomei@elink-cn.com * @date 2020/6/4 13:25 */ -@FeignClient(name = ServiceConstant.OPER_CRM_SERVER, fallback = OperCrmOpenFeignClientFallback.class) +//@FeignClient(name = ServiceConstant.OPER_CRM_SERVER, fallback = OperCrmOpenFeignClientFallback.class) +@FeignClient(name = ServiceConstant.OPER_CRM_SERVER, fallback = OperCrmOpenFeignClientFallback.class, url = "118.190.150.119:48080/api") public interface OperCrmOpenFeignClient { /** * 获取客户信息