mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
修复admin后台发布文档不生效问题;业务服务启动不用依赖网关
This commit is contained in:
@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -31,33 +32,38 @@ public class ApiRegisterServiceImpl implements ApiRegisterService {
|
||||
private ApiInfoMapper apiInfoMapper;
|
||||
|
||||
@Override
|
||||
public RegisterResult register(RegisterDTO registerDTO) {
|
||||
log.info("收到接口注册, registerDTO={}", registerDTO);
|
||||
|
||||
public RegisterResult register(Collection<RegisterDTO> registerDTOS) {
|
||||
try {
|
||||
ApiInfoDTO apiInfoDTO = CopyUtil.copyBean(registerDTO, ApiInfoDTO::new);
|
||||
apiInfoDTO.setStatus(StatusEnum.ENABLE.getValue());
|
||||
|
||||
ApiInfo apiInfo = apiInfoMapper.getByNameVersion(apiInfoDTO.getApiName(), apiInfoDTO.getApiVersion());
|
||||
if (apiInfo == null) {
|
||||
apiInfo = new ApiInfo();
|
||||
} else {
|
||||
check(apiInfo, registerDTO);
|
||||
for (RegisterDTO registerDTO : registerDTOS) {
|
||||
log.info("注册开放接口, registerDTO={}", registerDTO);
|
||||
this.doReg(registerDTO);
|
||||
}
|
||||
CopyUtil.copyPropertiesIgnoreNull(apiInfoDTO, apiInfo);
|
||||
apiInfo.setRegSource(REG_SOURCE_SYS);
|
||||
// 保存到数据库
|
||||
apiInfoMapper.saveOrUpdateIgnoreNull(apiInfo, data -> data.getId() != null);
|
||||
apiInfoDTO.setId(apiInfo.getId());
|
||||
// 保存到缓存
|
||||
apiManager.save(apiInfoDTO);
|
||||
return RegisterResult.success();
|
||||
} catch (Exception e) {
|
||||
log.error("接口注册失败, registerDTO={}", registerDTO, e);
|
||||
log.error("接口注册失败", e);
|
||||
return RegisterResult.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void doReg(RegisterDTO registerDTO) {
|
||||
ApiInfoDTO apiInfoDTO = CopyUtil.copyBean(registerDTO, ApiInfoDTO::new);
|
||||
apiInfoDTO.setStatus(StatusEnum.ENABLE.getValue());
|
||||
|
||||
ApiInfo apiInfo = apiInfoMapper.getByNameVersion(apiInfoDTO.getApiName(), apiInfoDTO.getApiVersion());
|
||||
if (apiInfo == null) {
|
||||
apiInfo = new ApiInfo();
|
||||
} else {
|
||||
check(apiInfo, registerDTO);
|
||||
}
|
||||
CopyUtil.copyPropertiesIgnoreNull(apiInfoDTO, apiInfo);
|
||||
apiInfo.setRegSource(REG_SOURCE_SYS);
|
||||
// 保存到数据库
|
||||
apiInfoMapper.saveOrUpdateIgnoreNull(apiInfo, data -> data.getId() != null);
|
||||
apiInfoDTO.setId(apiInfo.getId());
|
||||
// 保存到缓存
|
||||
apiManager.save(apiInfoDTO);
|
||||
}
|
||||
|
||||
private void check(ApiInfo apiInfo, RegisterDTO registerDTO) {
|
||||
if (!Objects.equals(apiInfo.getApplication(), registerDTO.getApplication())) {
|
||||
throw new RuntimeException("接口[" + registerDTO + "]已存在于[" + apiInfo.getApplication() + "]应用中.必须保证接口全局唯一");
|
||||
|
Reference in New Issue
Block a user