Commit 22870a4a by wqc

一天提交5次

parent 68962b2c
package com.zq.user.controller.api; package com.zq.user.controller.api;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
import com.zq.common.vo.ResultVo; import com.zq.common.vo.ResultVo;
import com.zq.user.dao.AnswerRecDao;
import com.zq.user.dao.ReplyCountDao;
import com.zq.user.entity.AnswerRec; import com.zq.user.entity.AnswerRec;
import com.zq.user.entity.ReplyCount;
import com.zq.user.service.PrizeService; import com.zq.user.service.PrizeService;
import com.zq.user.service.QuestionService; import com.zq.user.service.QuestionService;
import com.zq.user.utils.LimitRequest;
import com.zq.user.vo.LotteryRecFindVo; import com.zq.user.vo.LotteryRecFindVo;
import com.zq.user.vo.QuestionFindVo; import com.zq.user.vo.QuestionFindVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -18,8 +12,6 @@ import io.swagger.annotations.ApiOperation; ...@@ -18,8 +12,6 @@ import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* @author wilmiam * @author wilmiam
* @since 2022/6/15 9:51 * @since 2022/6/15 9:51
...@@ -32,7 +24,6 @@ public class QuestionApi { ...@@ -32,7 +24,6 @@ public class QuestionApi {
private final PrizeService prizeService; private final PrizeService prizeService;
private final QuestionService questionService; private final QuestionService questionService;
private final ReplyCountDao replyCountDao;
@ApiOperation("获取题目列表") @ApiOperation("获取题目列表")
@PostMapping(value = "/getQuestionList") @PostMapping(value = "/getQuestionList")
...@@ -47,24 +38,6 @@ public class QuestionApi { ...@@ -47,24 +38,6 @@ public class QuestionApi {
AssertUtils.hasText(vo.getUserId(), "缺少用户ID"); AssertUtils.hasText(vo.getUserId(), "缺少用户ID");
AssertUtils.hasText(vo.getAnswerList(), "缺少答案"); AssertUtils.hasText(vo.getAnswerList(), "缺少答案");
ReplyCount replyCount2 = replyCountDao.selectOne(Wrappers.lambdaQuery(ReplyCount.builder().userId(vo.getUserId()).build()));
if (replyCount2==null) {
ReplyCount reply= new ReplyCount();
reply.setUserId(vo.getUserId());
reply.setReplyCount(vo.getReplyCount());
replyCountDao.insert(reply);
}
else{
Integer count = replyCount2.getReplyCount();
count+=count;
ReplyCount reply= new ReplyCount();
reply.setReplyCount(count);
replyCountDao.update(reply);
}
if (replyCount2.getReplyCount().intValue()>5){
return ResultVo.fail("今日已达5次题,请明日再答");
}
return ResultVo.success(questionService.answer(vo)); return ResultVo.success(questionService.answer(vo));
} }
......
...@@ -13,4 +13,5 @@ import org.springframework.stereotype.Repository; ...@@ -13,4 +13,5 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface AnswerRecDao extends BaseMapper<AnswerRec> { public interface AnswerRecDao extends BaseMapper<AnswerRec> {
int selectReplyCount(AnswerRec vo);
} }
package com.zq.user.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zq.user.entity.ReplyCount;
import org.springframework.stereotype.Repository;
@Repository
public interface ReplyCountDao extends BaseMapper<ReplyCount> {
void update(ReplyCount reply);
}
package com.zq.user.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName(value = "reply_count")
public class ReplyCount {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 答题次数
*/
@ApiModelProperty("答题次数")
private Integer replyCount;
/**
* 用户ID
*/
@ApiModelProperty("用户ID")
private String userId;
}
...@@ -193,16 +193,20 @@ public class QuestionService { ...@@ -193,16 +193,20 @@ public class QuestionService {
vo.setScore(score.setScale(2, RoundingMode.HALF_UP).floatValue()); vo.setScore(score.setScale(2, RoundingMode.HALF_UP).floatValue());
vo.setCreateTime(DateUtil.date()); vo.setCreateTime(DateUtil.date());
vo.setReplyCount(vo.getReplyCount());
int i = answerRecDao.selectReplyCount(vo);
if (i>=5){
return "今日已达5次题,请明日再来";
}else {
answerRecDao.insert(vo); answerRecDao.insert(vo);
Map<String, Object> returnData = new HashMap<>(); Map<String, Object> returnData = new HashMap<>();
returnData.put("wrongQuestionList", wrongQuestionList); returnData.put("wrongQuestionList", wrongQuestionList);
returnData.put("score", vo.getScore()); returnData.put("score", vo.getScore());
return returnData; return returnData;
} }
}
public List<AnswerRec> getAnswerRec(AnswerRec answerRec) { public List<AnswerRec> getAnswerRec(AnswerRec answerRec) {
if (answerRec.getUserId() != null) { if (answerRec.getUserId() != null) {
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zq.user.dao.AnswerRecDao">
<select id="selectReplyCount" resultType="java.lang.Integer">
SELECT COUNT(1) FROM t_answer_rec WHERE date_format(create_time,'yyyy-mm-dd') = date_format(NOW(),'yyyy-mm-dd')
AND user_id=#{userId}
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment