|
@@ -24,12 +24,13 @@ import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
-
|
|
|
+@Service
|
|
|
public class QuestionSubmitServiceImpl extends ServiceImpl<QuestionSubmitMapper, QuestionSubmit>
|
|
|
implements QuestionSubmitService {
|
|
|
|
|
@@ -47,11 +48,11 @@ public class QuestionSubmitServiceImpl extends ServiceImpl<QuestionSubmitMapper,
|
|
|
* 提交题目
|
|
|
*
|
|
|
* @param questionSubmitAddRequest
|
|
|
- * @param loginUser
|
|
|
+ * @param loginUserId
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public long doQuestionSubmit(QuestionSubmitAddRequest questionSubmitAddRequest, User loginUser) {
|
|
|
+ public long doQuestionSubmit(QuestionSubmitAddRequest questionSubmitAddRequest, Long loginUserId) {
|
|
|
// 校验编程语言是否合法
|
|
|
String language = questionSubmitAddRequest.getLanguage();
|
|
|
QuestionSubmitLanguageEnum languageEnum = QuestionSubmitLanguageEnum.getEnumByValue(language);
|
|
@@ -65,10 +66,10 @@ public class QuestionSubmitServiceImpl extends ServiceImpl<QuestionSubmitMapper,
|
|
|
throw new BusinessException(ResultCode.NOT_FOUND_ERROR);
|
|
|
}
|
|
|
// 是否已提交题目
|
|
|
- long userId = loginUser.getId();
|
|
|
+
|
|
|
// 每个用户串行提交题目
|
|
|
QuestionSubmit questionSubmit = new QuestionSubmit();
|
|
|
- questionSubmit.setUserId(userId);
|
|
|
+ questionSubmit.setUserId(loginUserId);
|
|
|
questionSubmit.setQuestionId(questionId);
|
|
|
questionSubmit.setCode(questionSubmitAddRequest.getCode());
|
|
|
questionSubmit.setLanguage(language);
|
|
@@ -109,37 +110,36 @@ public class QuestionSubmitServiceImpl extends ServiceImpl<QuestionSubmitMapper,
|
|
|
|
|
|
// 拼接查询条件
|
|
|
queryWrapper.eq(StringUtils.isNotBlank(language), "language", language);
|
|
|
- queryWrapper.eq(ObjectUtils.isNotEmpty(userId), "userId", userId);
|
|
|
- queryWrapper.eq(ObjectUtils.isNotEmpty(questionId), "questionId", questionId);
|
|
|
+ queryWrapper.eq(ObjectUtils.isNotEmpty(userId), "user_id", userId);
|
|
|
+ queryWrapper.eq(ObjectUtils.isNotEmpty(questionId), "question_id", questionId);
|
|
|
queryWrapper.eq(QuestionSubmitStatusEnum.getEnumByValue(status) != null, "status", status);
|
|
|
- queryWrapper.eq("isDelete", false);
|
|
|
+ queryWrapper.eq("is_delete", 0);
|
|
|
queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
|
|
|
sortField);
|
|
|
return queryWrapper;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public QuestionSubmitVO getQuestionSubmitVO(QuestionSubmit questionSubmit, User loginUser) {
|
|
|
+ public QuestionSubmitVO getQuestionSubmitVO(QuestionSubmit questionSubmit, Long userId) {
|
|
|
QuestionSubmitVO questionSubmitVO = QuestionSubmitVO.objToVo(questionSubmit);
|
|
|
// 脱敏:仅本人和管理员能看见自己(提交 userId 和登录用户 id 不同)提交的代码
|
|
|
- long userId = loginUser.getId();
|
|
|
- // 处理脱敏
|
|
|
- //TODO && !userService.isAdmin(loginUser)
|
|
|
- if (userId != questionSubmit.getUserId() ) {
|
|
|
+
|
|
|
+ //TODO 处理脱敏 DONE
|
|
|
+ if (userId != questionSubmit.getUserId() && !userService.isAdmin(userId)) {
|
|
|
questionSubmitVO.setCode(null);
|
|
|
}
|
|
|
return questionSubmitVO;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Page<QuestionSubmitVO> getQuestionSubmitVOPage(Page<QuestionSubmit> questionSubmitPage, User loginUser) {
|
|
|
+ public Page<QuestionSubmitVO> getQuestionSubmitVOPage(Page<QuestionSubmit> questionSubmitPage, Long loginUserId) {
|
|
|
List<QuestionSubmit> questionSubmitList = questionSubmitPage.getRecords();
|
|
|
Page<QuestionSubmitVO> questionSubmitVOPage = new Page<>(questionSubmitPage.getCurrent(), questionSubmitPage.getSize(), questionSubmitPage.getTotal());
|
|
|
if (CollectionUtils.isEmpty(questionSubmitList)) {
|
|
|
return questionSubmitVOPage;
|
|
|
}
|
|
|
List<QuestionSubmitVO> questionSubmitVOList = questionSubmitList.stream()
|
|
|
- .map(questionSubmit -> getQuestionSubmitVO(questionSubmit, loginUser))
|
|
|
+ .map(questionSubmit -> getQuestionSubmitVO(questionSubmit, loginUserId))
|
|
|
.collect(Collectors.toList());
|
|
|
questionSubmitVOPage.setRecords(questionSubmitVOList);
|
|
|
return questionSubmitVOPage;
|