改造调用addWebhook为异步执行,并加入重试机制
This commit is contained in:
parent
508fa50eef
commit
c9dee61361
33
pom.xml
33
pom.xml
|
@ -45,22 +45,13 @@
|
|||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.5.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
|
@ -134,27 +125,29 @@
|
|||
<!-- <scope>test</scope>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- 重试相关依赖包 -->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
<groupId>org.springframework.retry</groupId>
|
||||
<artifactId>spring-retry</artifactId>
|
||||
<version>1.2.4.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>1.9.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -3,9 +3,13 @@ package com.gitlink.softbot;
|
|||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.retry.annotation.EnableRetry;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.gitlink.softbot.dao")
|
||||
@EnableAsync
|
||||
@EnableRetry
|
||||
public class SoftBotApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package com.gitlink.softbot.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
public class MyThreadPoolConfig {
|
||||
|
||||
private static final int CORE_POOL_SIZE = 10;
|
||||
|
||||
private static final int MAX_POOL_SIZE = 20;
|
||||
|
||||
private static final int QUEUE_CAPACITY = 200;
|
||||
|
||||
public static final String BEAN_EXECUTOR = "taskExecutor";
|
||||
|
||||
/** 线程池名前缀 */
|
||||
private static final String threadNamePrefix = "Async-Service-";
|
||||
|
||||
@Bean(BEAN_EXECUTOR)
|
||||
public Executor executor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(CORE_POOL_SIZE);
|
||||
executor.setMaxPoolSize(MAX_POOL_SIZE);
|
||||
// 设置队列容量
|
||||
executor.setQueueCapacity(QUEUE_CAPACITY);
|
||||
// 设置线程活跃时间(秒)
|
||||
executor.setKeepAliveSeconds(60);
|
||||
executor.setThreadNamePrefix(threadNamePrefix);
|
||||
// 设置拒绝策略
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.gitlink.softbot.controller.user;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.gitlink.softbot.global.exception.BotException;
|
||||
import com.gitlink.softbot.global.vo.Response;
|
||||
import com.gitlink.softbot.global.vo.Result;
|
||||
|
@ -156,7 +157,7 @@ public class UserController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("installMarketBot")
|
||||
public Result<?> installMarketBot(@RequestBody InstallMarketBotRequest installMarketBotRequest) throws BotException{
|
||||
public Result<?> installMarketBot(@RequestBody InstallMarketBotRequest installMarketBotRequest) throws BotException, JsonProcessingException {
|
||||
Result<?> result = new Result<>();
|
||||
userService.installMarketBot(installMarketBotRequest);
|
||||
return result.build(200).build("install bot success!");
|
||||
|
@ -180,7 +181,7 @@ public class UserController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("/updateInstallBot")
|
||||
public Result<?> updateInstallBot(@Valid @RequestBody UpdateInstallBotRequest updateInstallBotRequest) throws BotException{
|
||||
public Result<?> updateInstallBot(@Valid @RequestBody UpdateInstallBotRequest updateInstallBotRequest) throws Exception{
|
||||
Result<?> result = new Result<>();
|
||||
userService.updateInstallBot(updateInstallBotRequest);
|
||||
return result.build(200).build("update bot success!");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.gitlink.softbot.entity.db;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
|
@ -43,6 +44,9 @@ public class InstallBot {
|
|||
//仓库拥有者login(组织/个人)
|
||||
private String repoOwner;
|
||||
|
||||
@JsonIgnore
|
||||
private String webhookResponseMsg;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.gitlink.softbot.service.user;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.gitlink.softbot.global.exception.BotException;
|
||||
import com.gitlink.softbot.vo.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface IUserService {
|
||||
|
@ -25,11 +25,11 @@ public interface IUserService {
|
|||
//根据BotId返回Bot信息
|
||||
MarketBotVO getMarketBotById(Integer botId) throws BotException;
|
||||
//安装Bot
|
||||
void installMarketBot(InstallMarketBotRequest installMarketBotRequest) throws BotException;
|
||||
void installMarketBot(InstallMarketBotRequest installMarketBotRequest) throws BotException, JsonProcessingException;
|
||||
//安装Bot
|
||||
void unInstallMarketBot(UnInstallMarketBotRequest unInstallMarketBotRequest) throws BotException;
|
||||
//用户配置安装的Bot
|
||||
void updateInstallBot(UpdateInstallBotRequest updateInstallBotRequest) throws BotException;
|
||||
void updateInstallBot(UpdateInstallBotRequest updateInstallBotRequest) throws Exception;
|
||||
//删除安装的Bot
|
||||
void deleteInstallBot(DeleteInstallBotRequest deleteInstallBotRequest) throws BotException;
|
||||
//修改上市bot
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package com.gitlink.softbot.service.user.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.gitlink.softbot.dao.db.InstallMapper;
|
||||
import com.gitlink.softbot.entity.db.BotLimitEvent;
|
||||
import com.gitlink.softbot.entity.db.InstallBot;
|
||||
import com.gitlink.softbot.global.vo.Response;
|
||||
import com.gitlink.softbot.utils.GitLinkApi;
|
||||
import com.gitlink.softbot.utils.response.AddWebhookResponse;
|
||||
import com.gitlink.softbot.vo.Webhook;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.retry.annotation.Backoff;
|
||||
import org.springframework.retry.annotation.Recover;
|
||||
import org.springframework.retry.annotation.Retryable;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AsyncCallWebhookService {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private GitLinkApi api;
|
||||
|
||||
@Resource
|
||||
private InstallMapper installMapper;
|
||||
|
||||
@Async("taskExecutor")
|
||||
@Retryable(value = RuntimeException.class, maxAttempts = 3, backoff = @Backoff(delay = 2500,multiplier = 2))
|
||||
public void asyncAddWebhookAndRetry(Integer currentUserId, List<BotLimitEvent> botLimitEvents, InstallBot installBot) throws RuntimeException, JsonProcessingException {
|
||||
Webhook webhook = userService.getWebhook(botLimitEvents, installBot.getInstallerId());
|
||||
|
||||
//先获取webhookId构造webhook
|
||||
Object[] objects = new Object[]{installBot.getRepoOwner(), installBot.getStoreRepo()};
|
||||
Response response = api.addWebhook(currentUserId, objects, webhook);
|
||||
if (response.getCode().equals("error")) {
|
||||
log.info("installBotId: " + installBot.getId());
|
||||
installBot.setWebhookId(-1);
|
||||
installBot.setWebhookResponseMsg(response.getData().toString());
|
||||
installMapper.updateById(installBot);
|
||||
throw new RuntimeException("添加webhook异常");
|
||||
}
|
||||
if (response.getCode().equals("ok")) {
|
||||
//回写WebhookId
|
||||
AddWebhookResponse addWebhookResponse = JSON.parseObject(response.getData().toString(),AddWebhookResponse.class);
|
||||
installBot.setWebhookId(addWebhookResponse.getId());
|
||||
installMapper.updateById(installBot);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 最终重试失败处理
|
||||
*/
|
||||
@Recover
|
||||
public void recover(RuntimeException e){
|
||||
log.info("调用添加webhook请求,重试3次后依旧失败");
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@ import com.gitlink.softbot.service.user.AbstractUserBot;
|
|||
import com.gitlink.softbot.service.user.IUserService;
|
||||
import com.gitlink.softbot.utils.AuthOperate;
|
||||
import com.gitlink.softbot.utils.GitLinkApi;
|
||||
import com.gitlink.softbot.utils.response.AddWebhookResponse;
|
||||
import com.gitlink.softbot.vo.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -59,11 +58,11 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
@Autowired
|
||||
GitLinkApi api;
|
||||
|
||||
@Autowired
|
||||
private AsyncCallWebhookService asyncCallWebhookService;
|
||||
|
||||
/**
|
||||
* 获取个人注册bot信息
|
||||
* @param userId
|
||||
* @param botId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public GetRegisterBotResponse getRegisterBot(Integer userId,Integer botId) throws BotException{
|
||||
|
@ -89,7 +88,6 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
//增加用户登录名
|
||||
botOutputVO.setLogin(registerBot.getDeveloperLogin());
|
||||
BeanUtils.copyProperties(bot,botOutputVO);
|
||||
getRegisterBotResponse.setBotOutputVO(botOutputVO);
|
||||
getRegisterBotResponse.setLogin(registerBot.getDeveloperLogin());
|
||||
botOutputVO.setLimitAndEvents(limitVO);
|
||||
|
||||
|
@ -122,7 +120,7 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
checkInfo(botVO);
|
||||
TransactionStatus transactionStatus = null;
|
||||
DefaultTransactionDefinition transactionDefinition;
|
||||
Bot insertBot = null;
|
||||
Bot insertBot;
|
||||
try {
|
||||
// 有事务,则使用当前事务;否则开启新事务
|
||||
transactionDefinition = new DefaultTransactionDefinition();
|
||||
|
@ -706,8 +704,8 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class, noRollbackFor = RuntimeException.class)
|
||||
public void installMarketBot(InstallMarketBotRequest installMarketBotRequest) throws BotException {
|
||||
@Transactional(rollbackFor = BotException.class, noRollbackFor = RuntimeException.class)
|
||||
public void installMarketBot(InstallMarketBotRequest installMarketBotRequest) throws BotException, JsonProcessingException {
|
||||
|
||||
try {
|
||||
//1.校验有没有安装过此Bot
|
||||
|
@ -733,19 +731,7 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
for (InstallBot installBot : installBotList) {
|
||||
//插入表
|
||||
installMapper.insert(installBot);
|
||||
|
||||
Webhook webhook = getWebhook(botLimitEvents, installBot.getInstallerId());
|
||||
|
||||
//先获取webhookId构造webhook
|
||||
Object[] objects = new Object[]{installBot.getRepoOwner(), installBot.getStoreRepo()};
|
||||
Response response = api.addWebhook(installMarketBotRequest.getUserId(), objects, webhook);
|
||||
|
||||
checkException(response);
|
||||
AddWebhookResponse addWebhookResponse = JSON.parseObject(response.getData().toString(),AddWebhookResponse.class);
|
||||
|
||||
//回写WebhookId
|
||||
installBot.setWebhookId(addWebhookResponse.getId());
|
||||
installMapper.updateById(installBot);
|
||||
asyncCallWebhookService.asyncAddWebhookAndRetry(installMarketBotRequest.getUserId(), botLimitEvents, installBot);
|
||||
}
|
||||
|
||||
//2.对MarketBot表中install_num加1
|
||||
|
@ -766,7 +752,7 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
.eq("id",installMarketBotRequest.getBotId()));
|
||||
updateBot.setInstallNum(updateBot.getInstallNum()+1);
|
||||
botMapper.updateById(updateBot);
|
||||
}catch (Exception e){
|
||||
}catch (BotException e){
|
||||
throw new BotException("安装失败!");
|
||||
}
|
||||
|
||||
|
@ -775,7 +761,7 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void unInstallMarketBot(UnInstallMarketBotRequest unInstallMarketBotRequest) throws BotException {
|
||||
public void unInstallMarketBot(UnInstallMarketBotRequest unInstallMarketBotRequest){
|
||||
// 检查该仓库安装的bot
|
||||
List<InstallBot> installBots = installMapper.selectList(Wrappers.<InstallBot>lambdaQuery()
|
||||
.eq(InstallBot::getStoreId,unInstallMarketBotRequest.getStoreId())
|
||||
|
@ -795,9 +781,9 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
}
|
||||
}
|
||||
|
||||
private Webhook getWebhook(List<BotLimitEvent> limitEvents, Integer installerId){
|
||||
public Webhook getWebhook(List<BotLimitEvent> limitEvents, Integer installerId){
|
||||
|
||||
assert !Objects.isNull(limitEvents);
|
||||
assert !Objects.isNull(limitEvents);
|
||||
Webhook webhook = new Webhook();
|
||||
Object[] objects = new Object[limitEvents.size()];
|
||||
Integer event;
|
||||
|
@ -832,6 +818,7 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
webhook.setContent_type("json");
|
||||
String webhookUri = UriComponentsBuilder.fromUriString(bot.getWebhook()).queryParam("installer_id", installerId).build().toString();
|
||||
webhook.setUrl(webhookUri);
|
||||
webhook.setType("softbot");
|
||||
webhook.setHttp_method("POST");
|
||||
webhook.setBranch_filter("*");
|
||||
return webhook;
|
||||
|
@ -870,8 +857,8 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateInstallBot(UpdateInstallBotRequest updateInstallBotRequest) throws BotException{
|
||||
@Transactional(rollbackFor = Exception.class, noRollbackFor = RuntimeException.class)
|
||||
public void updateInstallBot(UpdateInstallBotRequest updateInstallBotRequest) throws Exception {
|
||||
|
||||
//1.先删除botId和userId对应的所有installBot
|
||||
List<InstallBot> installBotList = installMapper.selectList(Wrappers.<InstallBot>lambdaQuery()
|
||||
|
@ -902,19 +889,7 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
for (Integer store : storeList){
|
||||
InstallBot installBot = getInstallBot(updateInstallBotRequest,store);
|
||||
installMapper.insert(installBot);
|
||||
|
||||
Webhook webhook = getWebhook(botLimitEvents, installBot.getInstallerId());
|
||||
|
||||
Object[] objects = new Object[]{installBot.getRepoOwner(),installBot.getStoreRepo()};
|
||||
try {
|
||||
Response response = api.addWebhook(updateInstallBotRequest.getUserId(),objects,webhook);
|
||||
checkException(response);
|
||||
AddWebhookResponse addWebhookResponse = JSON.parseObject(response.getData().toString(),AddWebhookResponse.class);
|
||||
installBot.setWebhookId(addWebhookResponse.getId());
|
||||
installMapper.updateById(installBot);
|
||||
}catch (Exception e){
|
||||
throw new BotException("添加webhook失败");
|
||||
}
|
||||
asyncCallWebhookService.asyncAddWebhookAndRetry(updateInstallBotRequest.getUserId(), botLimitEvents, installBot);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -958,7 +933,7 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public GetInstallBotResponse getInstallBot(GetInstallBotRequest getInstallBotRequest) throws BotException{
|
||||
GetInstallBotResponse getInstallBotResponse = new GetInstallBotResponse();
|
||||
GetInstallBotResponse getInstallBotResponse = new GetInstallBotResponse();
|
||||
//1.到bot表中查看name
|
||||
Bot bot = botMapper.selectById(getInstallBotRequest.getBotId());
|
||||
|
||||
|
@ -1045,19 +1020,19 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
|
||||
@Override
|
||||
public GetTransferFromBotResponse getTransferBotState(GetTransferFromBotRequest getTransferFromBotRequest) {
|
||||
List<TransferBot> transferBots = transferBotMapper.selectList(Wrappers.<TransferBot>lambdaQuery()
|
||||
.eq(TransferBot::getBotId,getTransferFromBotRequest.getBotId())
|
||||
.eq(TransferBot::getTransferFromId,getTransferFromBotRequest.getUserId())
|
||||
.orderByDesc(TransferBot::getId));
|
||||
GetTransferFromBotResponse getTransferFromBotResponse = new GetTransferFromBotResponse();
|
||||
if(transferBots!=null && transferBots.size()>0){
|
||||
TransferBot transferBot = transferBots.get(0);
|
||||
getTransferFromBotResponse.setBotId(getTransferFromBotRequest.getBotId());
|
||||
getTransferFromBotResponse.setUserId(getTransferFromBotRequest.getUserId());
|
||||
getTransferFromBotResponse.setState(transferBot.getIsSuccess());
|
||||
getTransferFromBotResponse.setLogin(transferBot.getFromLogin());
|
||||
}
|
||||
return getTransferFromBotResponse;
|
||||
List<TransferBot> transferBots = transferBotMapper.selectList(Wrappers.<TransferBot>lambdaQuery()
|
||||
.eq(TransferBot::getBotId,getTransferFromBotRequest.getBotId())
|
||||
.eq(TransferBot::getTransferFromId,getTransferFromBotRequest.getUserId())
|
||||
.orderByDesc(TransferBot::getId));
|
||||
GetTransferFromBotResponse getTransferFromBotResponse = new GetTransferFromBotResponse();
|
||||
if(transferBots!=null && transferBots.size()>0){
|
||||
TransferBot transferBot = transferBots.get(0);
|
||||
getTransferFromBotResponse.setBotId(getTransferFromBotRequest.getBotId());
|
||||
getTransferFromBotResponse.setUserId(getTransferFromBotRequest.getUserId());
|
||||
getTransferFromBotResponse.setState(transferBot.getIsSuccess());
|
||||
getTransferFromBotResponse.setLogin(transferBot.getFromLogin());
|
||||
}
|
||||
return getTransferFromBotResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1096,12 +1071,12 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
}
|
||||
GetTransferToBotResponse getTransferToBotResponse = new GetTransferToBotResponse();
|
||||
List<GetTransferToBot> getTransferToBots = new ArrayList<>();
|
||||
if (!Objects.isNull(botList)){
|
||||
botList.forEach(bot -> {
|
||||
log.info("bot==:{}",bot);
|
||||
getTransferToBots.add(getTransferToBot(bot,transferBotMap.get(bot.getId())));
|
||||
});
|
||||
}
|
||||
if (!Objects.isNull(botList)){
|
||||
botList.forEach(bot -> {
|
||||
log.info("bot==:{}",bot);
|
||||
getTransferToBots.add(getTransferToBot(bot,transferBotMap.get(bot.getId())));
|
||||
});
|
||||
}
|
||||
getTransferToBotResponse.setUserId(getTransferToBotRequest.getUserId());
|
||||
getTransferToBotResponse.setLogin(getTransferToBotRequest.getLogin());
|
||||
getTransferToBotResponse.setBotList(getTransferToBots);
|
||||
|
@ -1124,58 +1099,58 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
// @Transactional(rollbackFor = Exception.class)
|
||||
public void receiveTransferBot(ReceiveTransferBotRequest receiveTransferBotRequest) throws BotException {
|
||||
//1.修改transfer_bot表
|
||||
List<TransferBot> transferBots = transferBotMapper.selectList(Wrappers.<TransferBot>lambdaQuery()
|
||||
.eq(TransferBot::getTransferFromId,receiveTransferBotRequest.getTransferFromId())
|
||||
.eq(TransferBot::getTransferToId,receiveTransferBotRequest.getTransferToId())
|
||||
.eq(TransferBot::getBotId,receiveTransferBotRequest.getBotId())
|
||||
.eq(TransferBot::getIsSuccess,2)
|
||||
.orderByDesc(TransferBot::getId));
|
||||
List<TransferBot> transferBots = transferBotMapper.selectList(Wrappers.<TransferBot>lambdaQuery()
|
||||
.eq(TransferBot::getTransferFromId,receiveTransferBotRequest.getTransferFromId())
|
||||
.eq(TransferBot::getTransferToId,receiveTransferBotRequest.getTransferToId())
|
||||
.eq(TransferBot::getBotId,receiveTransferBotRequest.getBotId())
|
||||
.eq(TransferBot::getIsSuccess,2)
|
||||
.orderByDesc(TransferBot::getId));
|
||||
|
||||
TransferBot transferBot = null;
|
||||
TransferBot transferBot = null;
|
||||
|
||||
if (transferBots!=null&&transferBots.size()>0){
|
||||
TransactionStatus transactionStatus = null;
|
||||
if (transferBots!=null&&transferBots.size()>0){
|
||||
TransactionStatus transactionStatus = null;
|
||||
|
||||
DefaultTransactionDefinition transactionDefinition;
|
||||
Bot bot = null;
|
||||
RegisterBot registerBot = null;
|
||||
try {
|
||||
// 有事务,则使用当前事务;否则开启新事务
|
||||
transactionDefinition = new DefaultTransactionDefinition();
|
||||
transactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
|
||||
transactionStatus = transactionManager.getTransaction(transactionDefinition);
|
||||
DefaultTransactionDefinition transactionDefinition;
|
||||
Bot bot = null;
|
||||
RegisterBot registerBot = null;
|
||||
try {
|
||||
// 有事务,则使用当前事务;否则开启新事务
|
||||
transactionDefinition = new DefaultTransactionDefinition();
|
||||
transactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
|
||||
transactionStatus = transactionManager.getTransaction(transactionDefinition);
|
||||
|
||||
transferBot = transferBots.get(0);
|
||||
//转让成功
|
||||
transferBot.setIsSuccess(1);
|
||||
transferBotMapper.updateById(transferBot);
|
||||
//2.将注册表中修改注册者为bot被转让人
|
||||
registerBot = registerMapper.selectOne(new QueryWrapper<RegisterBot>()
|
||||
.eq("bot_id",transferBot.getBotId()));
|
||||
registerBot.setDeveloperId(receiveTransferBotRequest.getTransferToId());
|
||||
registerBot.setDeveloperLogin(receiveTransferBotRequest.getTransferToLogin());
|
||||
registerMapper.updateById(registerBot);
|
||||
// 3.更改bot表中owner_id字段
|
||||
bot = botMapper.selectOne(new QueryWrapper<Bot>()
|
||||
.eq("id",receiveTransferBotRequest.getBotId()));
|
||||
bot.setOwnerId(receiveTransferBotRequest.getTransferToId());
|
||||
botMapper.updateById(bot);
|
||||
// 提交事务
|
||||
transactionManager.commit(transactionStatus);
|
||||
} catch (Exception e){
|
||||
if (transactionStatus != null) {
|
||||
transactionManager.rollback(transactionStatus);
|
||||
}
|
||||
throw new BotException("Bot注册失败:" + e);
|
||||
}
|
||||
// 4.bot表中更新client_secret和private_key字段
|
||||
if(registerBot!=null&&bot!=null){
|
||||
Response response0 = api.activeBotAuth(registerBot.getDeveloperId(), bot.getId(), AuthOperate.UPDATE_SECRET);
|
||||
checkException(response0);
|
||||
Response response1 = api.activeBotAuth(registerBot.getDeveloperId(), bot.getId(), AuthOperate.UPDATE_PRIVATE_KEY);
|
||||
checkException(response1);
|
||||
}
|
||||
}
|
||||
transferBot = transferBots.get(0);
|
||||
//转让成功
|
||||
transferBot.setIsSuccess(1);
|
||||
transferBotMapper.updateById(transferBot);
|
||||
//2.将注册表中修改注册者为bot被转让人
|
||||
registerBot = registerMapper.selectOne(new QueryWrapper<RegisterBot>()
|
||||
.eq("bot_id",transferBot.getBotId()));
|
||||
registerBot.setDeveloperId(receiveTransferBotRequest.getTransferToId());
|
||||
registerBot.setDeveloperLogin(receiveTransferBotRequest.getTransferToLogin());
|
||||
registerMapper.updateById(registerBot);
|
||||
// 3.更改bot表中owner_id字段
|
||||
bot = botMapper.selectOne(new QueryWrapper<Bot>()
|
||||
.eq("id",receiveTransferBotRequest.getBotId()));
|
||||
bot.setOwnerId(receiveTransferBotRequest.getTransferToId());
|
||||
botMapper.updateById(bot);
|
||||
// 提交事务
|
||||
transactionManager.commit(transactionStatus);
|
||||
} catch (Exception e){
|
||||
if (transactionStatus != null) {
|
||||
transactionManager.rollback(transactionStatus);
|
||||
}
|
||||
throw new BotException("Bot注册失败:" + e);
|
||||
}
|
||||
// 4.bot表中更新client_secret和private_key字段
|
||||
if(registerBot!=null&&bot!=null){
|
||||
Response response0 = api.activeBotAuth(registerBot.getDeveloperId(), bot.getId(), AuthOperate.UPDATE_SECRET);
|
||||
checkException(response0);
|
||||
Response response1 = api.activeBotAuth(registerBot.getDeveloperId(), bot.getId(), AuthOperate.UPDATE_PRIVATE_KEY);
|
||||
checkException(response1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1375,24 +1350,24 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateMarketBot(BotToMarketRequest botToMarketRequest) throws BotException{
|
||||
checkBotName(botToMarketRequest.getBotId(),botToMarketRequest.getMarketName());
|
||||
try {
|
||||
MarketBot marketBot = marketBotMapper.selectOne(Wrappers
|
||||
.<MarketBot>lambdaQuery().eq(MarketBot::getBotId,botToMarketRequest.getBotId()));
|
||||
if (marketBot!=null){
|
||||
MarketBot updateMarketBot = getDBMarketBot(botToMarketRequest);
|
||||
updateMarketBot.setId(marketBot.getId());
|
||||
marketBotMapper.updateById(updateMarketBot);
|
||||
//同步更新bot表信息
|
||||
Bot bot = botMapper.selectById(marketBot.getBotId());
|
||||
bot.setBotDes(updateMarketBot.getMarketIntro());
|
||||
bot.setLogo(updateMarketBot.getLogo());
|
||||
bot.setBotName(updateMarketBot.getMarketName());
|
||||
botMapper.updateById(bot);
|
||||
}
|
||||
try {
|
||||
MarketBot marketBot = marketBotMapper.selectOne(Wrappers
|
||||
.<MarketBot>lambdaQuery().eq(MarketBot::getBotId,botToMarketRequest.getBotId()));
|
||||
if (marketBot!=null){
|
||||
MarketBot updateMarketBot = getDBMarketBot(botToMarketRequest);
|
||||
updateMarketBot.setId(marketBot.getId());
|
||||
marketBotMapper.updateById(updateMarketBot);
|
||||
//同步更新bot表信息
|
||||
Bot bot = botMapper.selectById(marketBot.getBotId());
|
||||
bot.setBotDes(updateMarketBot.getMarketIntro());
|
||||
bot.setLogo(updateMarketBot.getLogo());
|
||||
bot.setBotName(updateMarketBot.getMarketName());
|
||||
botMapper.updateById(bot);
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
throw new BotException("更新失败!");
|
||||
}
|
||||
}catch (Exception e){
|
||||
throw new BotException("更新失败!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1404,15 +1379,15 @@ public class UserService extends AbstractUserBot implements IUserService {
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void downMarketBot(Integer botId) throws BotException{
|
||||
try {
|
||||
MarketBot marketBot = marketBotMapper.selectOne(Wrappers
|
||||
.<MarketBot>lambdaQuery()
|
||||
.eq(MarketBot::getBotId,botId));
|
||||
if (!Objects.isNull(marketBot)){
|
||||
marketBotMapper.deleteById(marketBot.getId());
|
||||
}
|
||||
}catch (Exception e){
|
||||
throw new BotException("下架bot失败");
|
||||
}
|
||||
try {
|
||||
MarketBot marketBot = marketBotMapper.selectOne(Wrappers
|
||||
.<MarketBot>lambdaQuery()
|
||||
.eq(MarketBot::getBotId,botId));
|
||||
if (!Objects.isNull(marketBot)){
|
||||
marketBotMapper.deleteById(marketBot.getId());
|
||||
}
|
||||
}catch (Exception e){
|
||||
throw new BotException("下架bot失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
-- ----------------------------
|
||||
-- 表install_bot中添加字段 webhook_response_msg:webhook请求返回信息
|
||||
-- ----------------------------
|
||||
ALTER TABLE `install_bot` ADD COLUMN `webhook_response_msg` TEXT DEFAULT NULL COMMENT 'webhook请求返回信息' AFTER `webhook_id`;
|
Loading…
Reference in New Issue