From a39cfa21b570ac30ed856f3f0a6ae9c1fc93b5d8 Mon Sep 17 00:00:00 2001 From: wanjia <553039491@qq.com> Date: Mon, 10 Apr 2023 16:11:55 +0800 Subject: [PATCH] =?UTF-8?q?getRegisterBot,getBotDetail=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=9A=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0issue=E6=9D=83=E9=99=90=E5=8F=8A=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softbot/entity/db/BotLimitEvent.java | 2 + .../service/market/impl/MarketService.java | 48 ++-------- .../service/user/impl/UserService.java | 89 ++++++++++--------- 3 files changed, 55 insertions(+), 84 deletions(-) diff --git a/src/main/java/com/gitlink/softbot/entity/db/BotLimitEvent.java b/src/main/java/com/gitlink/softbot/entity/db/BotLimitEvent.java index 9732d21..8e69406 100644 --- a/src/main/java/com/gitlink/softbot/entity/db/BotLimitEvent.java +++ b/src/main/java/com/gitlink/softbot/entity/db/BotLimitEvent.java @@ -29,6 +29,8 @@ public class BotLimitEvent { private Integer readWritePr; + private Integer readWriteIssue; + private Integer authCategory; private Integer event; diff --git a/src/main/java/com/gitlink/softbot/service/market/impl/MarketService.java b/src/main/java/com/gitlink/softbot/service/market/impl/MarketService.java index 59b628f..936516b 100644 --- a/src/main/java/com/gitlink/softbot/service/market/impl/MarketService.java +++ b/src/main/java/com/gitlink/softbot/service/market/impl/MarketService.java @@ -14,6 +14,7 @@ import com.gitlink.softbot.dao.db.BotLimitMapper; import com.gitlink.softbot.entity.db.*; import com.gitlink.softbot.global.exception.BotException; import com.gitlink.softbot.service.market.IMarketService; +import com.gitlink.softbot.service.user.impl.UserService; import com.gitlink.softbot.utils.GitLinkApi; import com.gitlink.softbot.vo.*; import lombok.extern.slf4j.Slf4j; @@ -53,6 +54,9 @@ public class MarketService implements IMarketService { @Autowired GitLinkApi api; + @Autowired + UserService userService; + @Override public MarketBotPagesVO getMarketBotByNameLike(String keyword,Integer pageIndex,Integer pageSize){ log.info("执行Bot通过上市名称模糊查询,keyword:{},pageIndex:{},pageSize:{}",keyword,pageIndex,pageSize); @@ -235,7 +239,7 @@ public class MarketService implements IMarketService { // 设置开发者名称 getBotDetailResponse.setDeveloperName(api.getUserNameByUid(registerBot.getDeveloperId().toString())); getBotDetailResponse.setDeveloperLogin(registerBot.getDeveloperLogin()); - getBotDetailResponse.setLimitAndEvents(getLimitFromLimitEvents(botLimitEvents)); + getBotDetailResponse.setLimitAndEvents(userService.getLimitFromLimitEvents(botLimitEvents)); return getBotDetailResponse; } @@ -293,46 +297,4 @@ public class MarketService implements IMarketService { marketBotPagesVO1.setPageSize(pageSize); return marketBotPagesVO1; } - - private LimitVO getLimitFromLimitEvents(List botLimitEvents){ - LimitVO limitVO = new LimitVO(); - //无权限情况下 - if (botLimitEvents.size()==1&&botLimitEvents.get(0).getEvent()==5){ - limitVO.setEventPr(""); - limitVO.setEventCode(""); - limitVO.setJurisDictionCode(2); - limitVO.setJurisDictionPr(2); - } - StringBuffer codeStr = new StringBuffer(); - StringBuffer prStr = new StringBuffer(); - - botLimitEvents.forEach(botLimitEvent -> { - if (botLimitEvent.getEvent()>=3){ - prStr.append(botLimitEvent.getEvent()); - prStr.append(","); - limitVO.setJurisDictionPr(botLimitEvent.getReadWritePr()); - }else { - codeStr.append(botLimitEvent.getEvent()); - codeStr.append(","); - limitVO.setJurisDictionCode(botLimitEvent.getReadWriteCode()); - } - }); - - if (codeStr.length()>1){ - codeStr.deleteCharAt(codeStr.length()-1); - }else { - limitVO.setJurisDictionCode(2); - } - if (prStr.length()>1){ - prStr.deleteCharAt(prStr.length()-1); - }else { - limitVO.setJurisDictionPr(2); - } - - limitVO.setEventPr(prStr.toString()); - limitVO.setEventCode(codeStr.toString()); - - log.info("limitVO:{}",limitVO); - return limitVO; - } } diff --git a/src/main/java/com/gitlink/softbot/service/user/impl/UserService.java b/src/main/java/com/gitlink/softbot/service/user/impl/UserService.java index 201a2ec..e33f83e 100644 --- a/src/main/java/com/gitlink/softbot/service/user/impl/UserService.java +++ b/src/main/java/com/gitlink/softbot/service/user/impl/UserService.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.fasterxml.jackson.core.JsonProcessingException; import com.gitlink.softbot.dao.db.*; import com.gitlink.softbot.entity.db.*; import com.gitlink.softbot.global.exception.BotException; @@ -415,46 +416,51 @@ public class UserService extends AbstractUserBot implements IUserService { botOutputVO.setIsPublic(bot.getIsPublic()); return botOutputVO; } - private LimitVO getLimitFromLimitEvents(List botLimitEvents){ + public LimitVO getLimitFromLimitEvents(List botLimitEvents){ LimitVO limitVO = new LimitVO(); //无权限情况下 if (botLimitEvents.size()==1&&botLimitEvents.get(0).getEvent()==5){ limitVO.setEventPr(""); limitVO.setEventCode(""); + limitVO.setEventIssue(""); limitVO.setJurisDictionCode(2); limitVO.setJurisDictionPr(2); + limitVO.setJurisDictionIssue(2); } - StringBuffer codeStr = new StringBuffer(); - StringBuffer prStr = new StringBuffer(); + StringJoiner codeStr = new StringJoiner(","); + StringJoiner prStr = new StringJoiner(","); + StringJoiner issueStr = new StringJoiner(","); - botLimitEvents.forEach(botLimitEvent -> { - if (botLimitEvent.getEvent()>=3){ - prStr.append(botLimitEvent.getEvent()); - prStr.append(","); - limitVO.setJurisDictionPr(botLimitEvent.getReadWritePr()); - }else { - codeStr.append(botLimitEvent.getEvent()); - codeStr.append(","); - limitVO.setJurisDictionCode(botLimitEvent.getReadWriteCode()); - } - }); + botLimitEvents.forEach(botLimitEvent -> { - if (codeStr.length()>1){ - codeStr.deleteCharAt(codeStr.length()-1); - }else { - limitVO.setJurisDictionCode(2); - } - if (prStr.length()>1){ - prStr.deleteCharAt(prStr.length()-1); - }else { - limitVO.setJurisDictionPr(2); - } + switch (botLimitEvent.getEvent()) { + case (0 | 1 | 2): + codeStr.add(botLimitEvent.getEvent().toString()); + limitVO.setJurisDictionCode(botLimitEvent.getReadWriteCode()); + case (3 | 4 | 6): + prStr.add(botLimitEvent.getEvent().toString()); + limitVO.setJurisDictionPr(botLimitEvent.getReadWritePr()); + case (7 | 8 | 9 | 10): + issueStr.add(botLimitEvent.getEvent().toString()); + limitVO.setJurisDictionIssue(botLimitEvent.getReadWriteIssue()); + } + }); - limitVO.setEventPr(prStr.toString()); - limitVO.setEventCode(codeStr.toString()); + if (codeStr.length()==0) { + limitVO.setJurisDictionCode(2); + } + if (prStr.length()==0) { + limitVO.setJurisDictionPr(2); + } + if (issueStr.length() == 0) { + limitVO.setJurisDictionIssue(2); + } - log.info("limitVO:{}",limitVO); - return limitVO; + limitVO.setEventPr(prStr.toString()); + limitVO.setEventCode(codeStr.toString()); + + log.info("limitVO:{}",limitVO); + return limitVO; } @Override public Bot shiftObject(BotInputVO botVO) { @@ -474,15 +480,16 @@ public class UserService extends AbstractUserBot implements IUserService { LimitVO limitVO = botInputVO.getLimitAndEvents(); List limitList = limitVOToLimit(limitVO); List botLimitEvents = new ArrayList<>(); - limitList.forEach(limit -> { - BotLimitEvent botLimitEvent = new BotLimitEvent(); - botLimitEvent.setBotId(bot.getId()); - botLimitEvent.setAuthCategory(limit.getAuthCategory()); - botLimitEvent.setReadWriteCode(limit.getReadWriteCode()); - botLimitEvent.setReadWritePr(limit.getReadWritePr()); - botLimitEvent.setEvent(limit.getEvent()); - botLimitEvents.add(botLimitEvent); - }); + limitList.forEach(limit -> { + BotLimitEvent botLimitEvent = new BotLimitEvent(); + botLimitEvent.setBotId(bot.getId()); + botLimitEvent.setAuthCategory(limit.getAuthCategory()); + botLimitEvent.setReadWriteCode(limit.getReadWriteCode()); + botLimitEvent.setReadWritePr(limit.getReadWritePr()); + botLimitEvent.setReadWriteIssue(limit.getReadWriteIssue()); + botLimitEvent.setEvent(limit.getEvent()); + botLimitEvents.add(botLimitEvent); + }); return botLimitEvents; } public RegisterBot shiftBotToRegisterBot(BotInputVO botInputVO,Bot bot){ @@ -567,7 +574,7 @@ public class UserService extends AbstractUserBot implements IUserService { @Transactional(rollbackFor = Exception.class) public void botToMarket(BotToMarketRequest botToMarketRequest) throws BotException{ log.info("Bot上市{}",botToMarketRequest); - //先校验是否公开,不是公开,则判断 + //先校验是否公开,不是公开,则判断 Bot bot = botMapper.selectById(botToMarketRequest.getBotId()); if (bot==null){ throw new BotException("该Bot不存在!"); @@ -651,9 +658,9 @@ public class UserService extends AbstractUserBot implements IUserService { System.out.println(registerBot.getBotId()); MarketBot marketBot = marketBotMapper.selectOne(new QueryWrapper() .eq("bot_id",registerBot.getBotId())); - if (Objects.isNull(marketBot)){ - return; - } + if (Objects.isNull(marketBot)){ + return; + } botList.add(getMarketBotsResponse.getMarketBot( marketBot ));