Commit 4a9282d98770bad1e802a06afdb6af5c0cdb9c1d

Authored by 王明元
1 parent e2d74c35

2022年9月5日16:14:06 修复获取直播审计时候, 拥有最佳直播人员账号已经删除导致的后续问题

fw-dalaran-common/src/main/java/cn/fw/dalaran/common/utils/StringUtils.java
... ... @@ -548,4 +548,4 @@ public final class StringUtils {
548 548 System.out.println(repeat("?", 10, ","));
549 549 length("AAA中国()111222bb");
550 550 }
551   -}
552 551 \ No newline at end of file
  552 +}
... ...
fw-dalaran-dao/src/main/java/cn/fw/dalaran/dao/AccountDao.java
... ... @@ -36,4 +36,12 @@ public interface AccountDao extends BaseMapper<Account> {
36 36 * @return 对应账户
37 37 */
38 38 List<Account> getByUserAccountNo(String accountNo);
  39 +
  40 + /**
  41 + * 根据id获取账户(忽略逻辑删除)
  42 + *
  43 + * @param accountId 账户id
  44 + * @return 对应账户
  45 + */
  46 + Account getByIdIgnoreLogicDel(Long accountId);
39 47 }
... ...
fw-dalaran-dao/src/main/resources/mapper/AccountMapper.xml
... ... @@ -60,11 +60,21 @@
60 60 </update>
61 61  
62 62 <select id="getByUserId" resultType="cn.fw.dalaran.domain.db.Account">
63   - select * from account where user_id = #{userId}
  63 + select *
  64 + from account
  65 + where user_id = #{userId}
64 66 </select>
65 67  
66 68 <select id="getByUserAccountNo" resultType="cn.fw.dalaran.domain.db.Account">
67   - select * from account where account = #{accountNo}
  69 + select *
  70 + from account
  71 + where account = #{accountNo}
  72 + </select>
  73 +
  74 + <select id="getByIdIgnoreLogicDel" resultType="cn.fw.dalaran.domain.db.Account">
  75 + select *
  76 + from account
  77 + where id = #{accountId}
68 78 </select>
69 79  
70 80 </mapper>
... ...
fw-dalaran-domain/src/main/java/cn/fw/dalaran/domain/vo/LivePoolVO.java
... ... @@ -77,7 +77,7 @@ public class LivePoolVO {
77 77 */
78 78 private Integer liveDuration;
79 79 /**
80   - * 是否有效直播
  80 + * 是否有效直播(-2:被判空挂, -1:付费, 0:无效, 1:有效, 11:有效且最佳)
81 81 */
82 82 private Integer valid;
83 83 /**
... ... @@ -126,6 +126,23 @@ public class LivePoolVO {
126 126 private String account;
127 127  
128 128 /**
  129 + * 获取有效性描述
  130 + */
  131 + public String getValidStatusDesc() {
  132 + if (Objects.equals(this.valid, -2))
  133 + return "空挂";
  134 + if (Objects.equals(this.valid, -1))
  135 + return "付费";
  136 + if (Objects.equals(this.valid, 0))
  137 + return "无效";
  138 + if (Objects.equals(this.valid, 1))
  139 + return "有效";
  140 + if (Objects.equals(this.valid, 11))
  141 + return "最佳";
  142 + return "未知";
  143 + }
  144 +
  145 + /**
129 146 * 是否为最佳直播
130 147 */
131 148 public boolean getBestLive() {
... ...
fw-dalaran-server/src/main/java/cn/fw/dalaran/server/config/MyControllerAdvice.java
... ... @@ -2,6 +2,7 @@ package cn.fw.dalaran.server.config;
2 2  
3 3 import cn.fw.dalaran.common.exception.BusinessException;
4 4 import cn.fw.data.base.domain.common.Message;
  5 +import org.hibernate.validator.internal.engine.path.PathImpl;
5 6 import org.springframework.validation.BindException;
6 7 import org.springframework.validation.FieldError;
7 8 import org.springframework.validation.ObjectError;
... ... @@ -9,8 +10,11 @@ import org.springframework.web.bind.MethodArgumentNotValidException;
9 10 import org.springframework.web.bind.annotation.ExceptionHandler;
10 11 import org.springframework.web.bind.annotation.RestControllerAdvice;
11 12  
  13 +import javax.validation.ConstraintViolation;
  14 +import javax.validation.ConstraintViolationException;
12 15 import java.util.ArrayList;
13 16 import java.util.List;
  17 +import java.util.Set;
14 18  
15 19 /**
16 20 * @author wmy3969
... ... @@ -22,15 +26,7 @@ import java.util.List;
22 26 public class MyControllerAdvice {
23 27  
24 28 /**
25   - * BusinessException
26   - */
27   - @ExceptionHandler(value = {BusinessException.class})
28   - public Message<String> handleException(BusinessException e) {
29   - return Message.failure(50000, e.getMessage());
30   - }
31   -
32   - /**
33   - * 参数校验未通过异常处理
  29 + * 参数校验未通过异常处理(校验注解在实体类中)
34 30 */
35 31 @ExceptionHandler(value = {MethodArgumentNotValidException.class, BindException.class})
36 32 public Message<String> exception(Exception e) {
... ... @@ -52,7 +48,38 @@ public class MyControllerAdvice {
52 48 sb.append(",");
53 49 }
54 50 }
55   - return Message.failure(sb.toString());
  51 + return Message.failure(50500, sb.toString());
  52 + }
  53 +
  54 + /**
  55 + * 参数校验未通过异常处理(校验注解在方法参数列表上)
  56 + */
  57 + @ExceptionHandler(value = ConstraintViolationException.class)
  58 + public Message<String> exception(ConstraintViolationException e) {
  59 + Set<ConstraintViolation<?>> set = e.getConstraintViolations();
  60 + StringBuilder sb = new StringBuilder();
  61 + int size = set.size();
  62 + if (size > 0) {
  63 + ArrayList<ConstraintViolation<?>> list = new ArrayList<>(set);
  64 + for (int i = 0; i < size; i++) {
  65 + final ConstraintViolation<?> error = list.get(i);
  66 + sb.append("「");
  67 + sb.append(((PathImpl) error.getPropertyPath()).getLeafNode().getName());
  68 + sb.append("」");
  69 + sb.append(error.getMessageTemplate());
  70 + if (i < size - 1)
  71 + sb.append(",");
  72 + }
  73 + }
  74 + return Message.failure(50501, sb.toString());
  75 + }
  76 +
  77 + /**
  78 + * BusinessException
  79 + */
  80 + @ExceptionHandler(value = {BusinessException.class})
  81 + public Message<String> handleException(BusinessException e) {
  82 + return Message.failure(50502, e.getMessage());
56 83 }
57 84  
58 85 }
... ...
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/biz/OtherBizService.java
... ... @@ -6,6 +6,7 @@ import cn.fw.dalaran.common.utils.PublicUtil;
6 6 import cn.fw.dalaran.common.utils.StringUtils;
7 7 import cn.fw.dalaran.domain.db.*;
8 8 import cn.fw.dalaran.domain.enums.FileTypeEnum;
  9 +import cn.fw.dalaran.domain.enums.PlatformEnum;
9 10 import cn.fw.dalaran.domain.param.LiveCheckParams;
10 11 import cn.fw.dalaran.domain.vo.FileDesc;
11 12 import cn.fw.dalaran.domain.vo.LiveCheckVo;
... ... @@ -14,9 +15,14 @@ import cn.fw.dalaran.rpc.erp.dto.ShopMsg;
14 15 import cn.fw.dalaran.service.data.*;
15 16 import lombok.RequiredArgsConstructor;
16 17 import lombok.extern.slf4j.Slf4j;
  18 +import org.springframework.beans.factory.annotation.Autowired;
17 19 import org.springframework.beans.factory.annotation.Value;
  20 +import org.springframework.context.annotation.Lazy;
18 21 import org.springframework.scheduling.annotation.Async;
19 22 import org.springframework.stereotype.Service;
  23 +import org.springframework.transaction.PlatformTransactionManager;
  24 +import org.springframework.transaction.TransactionDefinition;
  25 +import org.springframework.transaction.annotation.Propagation;
20 26 import org.springframework.transaction.annotation.Transactional;
21 27 import org.springframework.util.CollectionUtils;
22 28  
... ... @@ -29,6 +35,7 @@ import java.text.SimpleDateFormat;
29 35 import java.util.*;
30 36 import java.util.concurrent.TimeUnit;
31 37 import java.util.concurrent.locks.LockSupport;
  38 +import java.util.concurrent.locks.ReentrantLock;
32 39 import java.util.stream.Collectors;
33 40  
34 41 /**
... ... @@ -51,6 +58,9 @@ public class OtherBizService {
51 58 private final TodoHistoryService todoHistoryService;
52 59 private final ThemeFileService themeFileService;
53 60  
  61 + private final PlatformTransactionManager platformTransactionManager;
  62 + private final TransactionDefinition transactionDefinition;
  63 +
54 64 /**
55 65 * 获取直播审计页面
56 66 *
... ... @@ -80,7 +90,12 @@ public class OtherBizService {
80 90 .list()
81 91 .stream()
82 92 .map(item -> {
83   - final Account account = accountService.getById(item.getAccountId());
  93 + Long accountId = item.getAccountId();
  94 + Account account;
  95 + if (Objects.isNull(account = accountService.getById(accountId)))
  96 + account = accountService.getByIdIgnoreLogicDel(accountId);
  97 + if (Objects.isNull(account))
  98 + return null;
84 99 return LiveCheckResult.builder()
85 100 .themeId(themeId)
86 101 .userId(account.getUserId())
... ... @@ -92,6 +107,7 @@ public class OtherBizService {
92 107 .status(-1)
93 108 .build();
94 109 })
  110 + .filter(Objects::nonNull)
95 111 .collect(Collectors.toList());
96 112 liveCheckResultService.saveBatch(waitCheckLives);
97 113 }
... ...
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/data/AccountService.java
... ... @@ -33,4 +33,12 @@ public interface AccountService extends IService&lt;Account&gt; {
33 33 * @return 对应账户
34 34 */
35 35 List<Account> getByUserAccountNo(String accountNo);
  36 +
  37 + /**
  38 + * 根据id获取账户(忽略逻辑删除)
  39 + *
  40 + * @param accountId 账户id
  41 + * @return 对应账户
  42 + */
  43 + Account getByIdIgnoreLogicDel(Long accountId);
36 44 }
... ...
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/data/impl/AccountServiceImpl.java
... ... @@ -52,4 +52,15 @@ public class AccountServiceImpl extends ServiceImpl&lt;AccountDao, Account&gt; impleme
52 52 return accountDao.getByUserAccountNo(accountNo);
53 53 }
54 54  
  55 + /**
  56 + * 根据id获取账户(忽略逻辑删除)
  57 + *
  58 + * @param accountId 账户id
  59 + * @return 对应账户
  60 + */
  61 + @Override
  62 + public Account getByIdIgnoreLogicDel(Long accountId) {
  63 + return accountDao.getByIdIgnoreLogicDel(accountId);
  64 + }
  65 +
55 66 }
... ...