|
|
@ -17,8 +17,24 @@ |
|
|
|
|
|
|
|
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.dao.ExternalAppDao; |
|
|
|
import com.epmet.dao.ExternalAppSecretDao; |
|
|
|
import com.epmet.dao.ExternalCustomerDao; |
|
|
|
import com.epmet.dto.result.ExternalAppResultDTO; |
|
|
|
import com.epmet.entity.ExternalAppEntity; |
|
|
|
import com.epmet.entity.ExternalAppSecretEntity; |
|
|
|
import com.epmet.service.ExternalAppService; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
/** |
|
|
|
* 外部应用列表 |
|
|
@ -29,5 +45,89 @@ import org.springframework.stereotype.Service; |
|
|
|
@Service |
|
|
|
public class ExternalAppServiceImpl implements ExternalAppService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ExternalAppDao externalAppDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ExternalAppSecretDao externalAppSecretDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ExternalCustomerDao externalCustomerDao; |
|
|
|
|
|
|
|
@Transactional |
|
|
|
@Override |
|
|
|
public ExternalAppResultDTO add(String appName, String customerId) { |
|
|
|
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) { |
|
|
|
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); |
|
|
|
externalAppDao.insert(appEntity); |
|
|
|
|
|
|
|
// 秘钥表插入
|
|
|
|
ExternalAppSecretEntity secretEntity = new ExternalAppSecretEntity(); |
|
|
|
secretEntity.setAppId(appEntity.getId()); |
|
|
|
secretEntity.setSecret(genSecret()); |
|
|
|
externalAppSecretDao.insert(secretEntity); |
|
|
|
|
|
|
|
ExternalAppResultDTO dto = new ExternalAppResultDTO(); |
|
|
|
dto.setAppName(appName); |
|
|
|
dto.setCustomerId(customerId); |
|
|
|
dto.setAppId(appEntity.getId()); |
|
|
|
return dto; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 生成秘钥 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String genSecret() { |
|
|
|
String part1 = UUID.randomUUID().toString(); |
|
|
|
String part2 = UUID.randomUUID().toString(); |
|
|
|
return part1.concat(part2).replace("-", ""); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ExternalAppResultDTO updateById(String appId, String appName, String customerId) { |
|
|
|
ExternalAppEntity exists = externalAppDao.selectById(appId); |
|
|
|
if (exists == null) { |
|
|
|
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getCode(), |
|
|
|
EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
ExternalAppResultDTO byName = externalAppDao.getByNameAndCustomerId(appName, customerId); |
|
|
|
if (byName != null && !byName.getAppId().equals(appId)) { |
|
|
|
// 说明改了之后的名字跟当前客户内的其他应用重复
|
|
|
|
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_EXISTS.getCode(), "应用名称重复"); |
|
|
|
} |
|
|
|
|
|
|
|
exists.setAppName(appName); |
|
|
|
exists.setCustomerId(customerId); |
|
|
|
externalAppDao.updateById(exists); |
|
|
|
|
|
|
|
ExternalAppResultDTO resultDTO = new ExternalAppResultDTO(); |
|
|
|
resultDTO.setAppId(appId); |
|
|
|
resultDTO.setCustomerId(customerId); |
|
|
|
resultDTO.setAppName(appName); |
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<ExternalAppResultDTO> listPage(Integer pageNo, Integer pageSize, String customerId) { |
|
|
|
PageHelper.startPage(pageNo, pageSize); |
|
|
|
List<ExternalAppResultDTO> list = externalAppDao.list(customerId); |
|
|
|
PageInfo<ExternalAppResultDTO> pageInfo = new PageInfo<>(list); |
|
|
|
return new PageData<>(list, pageInfo.getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
} |