|  | @ -20,15 +20,23 @@ package com.epmet.service.impl; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.commons.tools.exception.EpmetErrorCode; |  |  | import com.epmet.commons.tools.exception.EpmetErrorCode; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.commons.tools.exception.RenException; |  |  | import com.epmet.commons.tools.exception.RenException; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.commons.tools.page.PageData; |  |  | 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.ExternalAppDao; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.dao.ExternalAppSecretDao; |  |  | import com.epmet.dao.ExternalAppSecretDao; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.dao.ExternalCustomerDao; |  |  | import com.epmet.dao.ExternalCustomerDao; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import com.epmet.dto.CustomerDTO; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.dto.result.ExternalAppResultDTO; |  |  | import com.epmet.dto.result.ExternalAppResultDTO; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.entity.ExternalAppEntity; |  |  | import com.epmet.entity.ExternalAppEntity; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.entity.ExternalAppSecretEntity; |  |  | import com.epmet.entity.ExternalAppSecretEntity; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import com.epmet.enu.CustomerTypeEnum; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import com.epmet.feign.OperCrmOpenFeignClient; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.service.ExternalAppService; |  |  | import com.epmet.service.ExternalAppService; | 
			
		
	
		
		
			
				
					|  |  | import com.github.pagehelper.PageHelper; |  |  | import com.github.pagehelper.PageHelper; | 
			
		
	
		
		
			
				
					|  |  | import com.github.pagehelper.PageInfo; |  |  | import com.github.pagehelper.PageInfo; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import org.slf4j.Logger; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import org.slf4j.LoggerFactory; | 
			
		
	
		
		
			
				
					|  |  | import org.springframework.beans.factory.annotation.Autowired; |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
			
		
	
		
		
			
				
					|  |  | import org.springframework.stereotype.Service; |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
		
			
				
					|  |  | import org.springframework.transaction.annotation.Transactional; |  |  | import org.springframework.transaction.annotation.Transactional; | 
			
		
	
	
		
		
			
				
					|  | @ -45,6 +53,8 @@ import java.util.UUID; | 
			
		
	
		
		
			
				
					|  |  | @Service |  |  | @Service | 
			
		
	
		
		
			
				
					|  |  | public class ExternalAppServiceImpl implements ExternalAppService { |  |  | public class ExternalAppServiceImpl implements ExternalAppService { | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     private static Logger logger = LoggerFactory.getLogger(ExternalAppServiceImpl.class); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     @Autowired |  |  |     @Autowired | 
			
		
	
		
		
			
				
					|  |  |     private ExternalAppDao externalAppDao; |  |  |     private ExternalAppDao externalAppDao; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | @ -54,24 +64,42 @@ public class ExternalAppServiceImpl implements ExternalAppService { | 
			
		
	
		
		
			
				
					|  |  |     @Autowired |  |  |     @Autowired | 
			
		
	
		
		
			
				
					|  |  |     private ExternalCustomerDao externalCustomerDao; |  |  |     private ExternalCustomerDao externalCustomerDao; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     @Autowired | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     private OperCrmOpenFeignClient operCrmOpenFeignClient; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     @Autowired | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     private RedisUtils redisUtils; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     @Transactional |  |  |     @Transactional | 
			
		
	
		
		
			
				
					|  |  |     @Override |  |  |     @Override | 
			
		
	
		
		
			
				
					
					|  |  |     public ExternalAppResultDTO add(String appName, String customerId) { |  |  |     public ExternalAppResultDTO add(String appName, String customerId, String customerType) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |         Integer count = externalAppDao.countByAppNameAndCustomerId(appName, customerId); |  |  |         Integer count = externalAppDao.countByAppNameAndCustomerId(appName, customerId); | 
			
		
	
		
		
			
				
					|  |  |         if (count > 0) { |  |  |         if (count > 0) { | 
			
		
	
		
		
			
				
					|  |  |             throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_EXISTS.getCode(), |  |  |             throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_EXISTS.getCode(), | 
			
		
	
		
		
			
				
					|  |  |                     EpmetErrorCode.OPER_EXTERNAL_APP_EXISTS.getMsg()); |  |  |                     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(), |  |  |             throw new RenException(EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getCode(), | 
			
		
	
		
		
			
				
					|  |  |                     EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getMsg()); |  |  |                     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(); |  |  |         ExternalAppEntity appEntity = new ExternalAppEntity(); | 
			
		
	
		
		
			
				
					|  |  |         appEntity.setAppName(appName); |  |  |         appEntity.setAppName(appName); | 
			
		
	
		
		
			
				
					|  |  |         appEntity.setCustomerId(customerId); |  |  |         appEntity.setCustomerId(customerId); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         appEntity.setCustomerType(customerType); | 
			
		
	
		
		
			
				
					|  |  |         externalAppDao.insert(appEntity); |  |  |         externalAppDao.insert(appEntity); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         // 秘钥表插入
 |  |  |         // 秘钥表插入
 | 
			
		
	
	
		
		
			
				
					|  | @ -98,7 +126,7 @@ public class ExternalAppServiceImpl implements ExternalAppService { | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     @Override |  |  |     @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); |  |  |         ExternalAppEntity exists = externalAppDao.selectById(appId); | 
			
		
	
		
		
			
				
					|  |  |         if (exists == null) { |  |  |         if (exists == null) { | 
			
		
	
		
		
			
				
					|  |  |             throw new RenException(EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getCode(), |  |  |             throw new RenException(EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getCode(), | 
			
		
	
	
		
		
			
				
					|  | @ -113,6 +141,7 @@ public class ExternalAppServiceImpl implements ExternalAppService { | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         exists.setAppName(appName); |  |  |         exists.setAppName(appName); | 
			
		
	
		
		
			
				
					|  |  |         exists.setCustomerId(customerId); |  |  |         exists.setCustomerId(customerId); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         exists.setCustomerType(customerType); | 
			
		
	
		
		
			
				
					|  |  |         externalAppDao.updateById(exists); |  |  |         externalAppDao.updateById(exists); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         ExternalAppResultDTO resultDTO = new ExternalAppResultDTO(); |  |  |         ExternalAppResultDTO resultDTO = new ExternalAppResultDTO(); | 
			
		
	
	
		
		
			
				
					|  | @ -126,6 +155,26 @@ public class ExternalAppServiceImpl implements ExternalAppService { | 
			
		
	
		
		
			
				
					|  |  |     public PageData<ExternalAppResultDTO> listPage(Integer pageNo, Integer pageSize, String customerId) { |  |  |     public PageData<ExternalAppResultDTO> listPage(Integer pageNo, Integer pageSize, String customerId) { | 
			
		
	
		
		
			
				
					|  |  |         PageHelper.startPage(pageNo, pageSize); |  |  |         PageHelper.startPage(pageNo, pageSize); | 
			
		
	
		
		
			
				
					|  |  |         List<ExternalAppResultDTO> list = externalAppDao.list(customerId); |  |  |         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); |  |  |         PageInfo<ExternalAppResultDTO> pageInfo = new PageInfo<>(list); | 
			
		
	
		
		
			
				
					|  |  |         return new PageData<>(list, pageInfo.getTotal()); |  |  |         return new PageData<>(list, pageInfo.getTotal()); | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
	
		
		
			
				
					|  | @ -140,8 +189,11 @@ public class ExternalAppServiceImpl implements ExternalAppService { | 
			
		
	
		
		
			
				
					|  |  |     public String resetSecret(String appId) { |  |  |     public String resetSecret(String appId) { | 
			
		
	
		
		
			
				
					|  |  |         String secret = genSecret(); |  |  |         String secret = genSecret(); | 
			
		
	
		
		
			
				
					|  |  |         if (externalAppSecretDao.updateSecret(appId, secret) > 0) { |  |  |         if (externalAppSecretDao.updateSecret(appId, secret) > 0) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             // 删除外部应用的秘钥缓存,再次使用的时候将主动加载入缓存
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             redisUtils.delete(RedisKeys.getExternalAppSecretKey(appId)); | 
			
		
	
		
		
			
				
					|  |  |             return secret; |  |  |             return secret; | 
			
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         return null; |  |  |         return null; | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | 
 |