Browse Source

Merge branch 'dev_externalappauth' into dev

master
wxz 5 years ago
parent
commit
8643e9f107
  1. 9
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java
  2. 4
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java
  3. 6
      epmet-module/epmet-common-service/common-service-server/pom.xml
  4. 6
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java
  5. 2
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/entity/ExternalAppEntity.java
  6. 41
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/enu/CustomerTypeEnum.java
  7. 4
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java
  8. 58
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java
  9. 1
      epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.4__add_extcustomer_type.sql
  10. 4
      epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml
  11. 2
      epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppSecretDao.xml
  12. 1
      epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java

9
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;

4
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;
/**
* 秘钥
*/

6
epmet-module/epmet-common-service/common-service-server/pom.xml

@ -64,6 +64,12 @@
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>oper-crm-client</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>

6
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java

@ -66,8 +66,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<ExternalAppResultDTO>().ok(dto);
}
@ -84,8 +85,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<ExternalAppResultDTO>().ok(dto);
}

2
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;
}

41
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;
}
}

4
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java

@ -29,9 +29,9 @@ import java.util.List;
* @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<ExternalAppResultDTO> listPage(Integer pageNo, Integer pageSize, String customerId);

58
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java

@ -20,15 +20,23 @@ 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.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
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 +53,8 @@ import java.util.UUID;
@Service
public class ExternalAppServiceImpl implements ExternalAppService {
private static Logger logger = LoggerFactory.getLogger(ExternalAppServiceImpl.class);
@Autowired
private ExternalAppDao externalAppDao;
@ -54,24 +64,42 @@ public class ExternalAppServiceImpl implements ExternalAppService {
@Autowired
private ExternalCustomerDao externalCustomerDao;
@Autowired
private OperCrmOpenFeignClient operCrmOpenFeignClient;
@Autowired
private RedisUtils redisUtils;
@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(),
EpmetErrorCode.OPER_EXTERNAL_APP_EXISTS.getMsg());
}
if (externalCustomerDao.selectById(customerId) == null) {
if (CustomerTypeEnum.EXTERNAL.getType().equals(customerType) && externalCustomerDao.selectById(customerId) == null) {
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getCode(),
EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getMsg());
}
if (CustomerTypeEnum.INTERNAL.getType().equals(customerType)) {
CustomerDTO form = new CustomerDTO();
form.setId(customerId);
Result<CustomerDTO> customerInfoRst = operCrmOpenFeignClient.getCustomerInfo(form);
if (customerInfoRst.success() && customerInfoRst.getData() == null) {
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getCode(),
EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getMsg());
}
}
// 应用表插入
ExternalAppEntity appEntity = new ExternalAppEntity();
appEntity.setAppName(appName);
appEntity.setCustomerId(customerId);
appEntity.setCustomerType(customerType);
externalAppDao.insert(appEntity);
// 秘钥表插入
@ -98,7 +126,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 +141,7 @@ public class ExternalAppServiceImpl implements ExternalAppService {
exists.setAppName(appName);
exists.setCustomerId(customerId);
exists.setCustomerType(customerType);
externalAppDao.updateById(exists);
ExternalAppResultDTO resultDTO = new ExternalAppResultDTO();
@ -126,6 +155,26 @@ public class ExternalAppServiceImpl implements ExternalAppService {
public PageData<ExternalAppResultDTO> listPage(Integer pageNo, Integer pageSize, String customerId) {
PageHelper.startPage(pageNo, pageSize);
List<ExternalAppResultDTO> 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<CustomerDTO> 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<ExternalAppResultDTO> pageInfo = new PageInfo<>(list);
return new PageData<>(list, pageInfo.getTotal());
}
@ -140,8 +189,11 @@ public class ExternalAppServiceImpl implements ExternalAppService {
public String resetSecret(String appId) {
String secret = genSecret();
if (externalAppSecretDao.updateSecret(appId, secret) > 0) {
// 删除外部应用的秘钥缓存,再次使用的时候将主动加载入缓存
redisUtils.delete(RedisKeys.getExternalAppSecretKey(appId));
return secret;
}
return null;
}

1
epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.4__add_extcustomer_type.sql

@ -0,0 +1 @@
alter table external_app add column CUSTOMER_TYPE varchar(20) not null after CUSTOMER_ID;

4
epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml

@ -7,6 +7,7 @@
<result property="id" column="ID"/>
<result property="appName" column="APP_NAME"/>
<result property="customerId" column="CUSTOMER_ID"/>
<result property="customerType" column="CUSTOMER_TYPE"/>
<result property="delFlag" column="DEL_FLAG"/>
<result property="revision" column="REVISION"/>
<result property="createdBy" column="CREATED_BY"/>
@ -33,10 +34,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)
<where>
ea.DEL_FLAG = 0

2
epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppSecretDao.xml

@ -19,7 +19,7 @@
<update id="updateSecret">
update external_app_secret
set SECRET=#{secret}
where ID = #{appId}
where APP_ID = #{appId}
</update>
<select id="getSecretsByAppId" resultType="com.epmet.entity.ExternalAppSecretEntity">

1
epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java

@ -22,6 +22,7 @@ import java.util.List;
* @date 2020/6/4 13:25
*/
@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 {
/**
* 获取客户信息

Loading…
Cancel
Save