功能完善
parent
4a96df6661
commit
b51008f8ef
|
@ -2,17 +2,20 @@ package com.grail.doctor.publice.controller;
|
|||
|
||||
import com.grail.common.core.domain.Result;
|
||||
import com.grail.doctor.publice.service.CommentServlce;
|
||||
import com.grail.publice.domain.Comment;
|
||||
import com.grail.publice.domain.Gift;
|
||||
import com.grail.publice.domain.response.ResponseComment;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName : CommentController
|
||||
* @Description : 问诊好评
|
||||
|
@ -64,4 +67,40 @@ public class CommentController {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public CommentController(CommentServlce commentServlce){
|
||||
this.commentServlce = commentServlce;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户进行评价
|
||||
* @param comment
|
||||
* @return 是否评价成功结果
|
||||
*/
|
||||
@PostMapping("/addComment")
|
||||
public Result<String> addComment(@RequestBody Comment comment){
|
||||
comment.setCommentTime(new Date());
|
||||
commentServlce.addComment(comment);
|
||||
|
||||
return Result.success("评论成功");
|
||||
}
|
||||
@GetMapping("/exit")
|
||||
public Result<String> handleExit(@RequestParam Integer userId){
|
||||
//从数据中查询未评价的记录数
|
||||
int unfinishedCount = commentServlce.countUnfinishedComments(userId);
|
||||
|
||||
if (unfinishedCount > 0){
|
||||
//在7天后添加中评
|
||||
LocalDateTime delayedTime = LocalDateTime.now().plusDays(7);
|
||||
commentServlce.addDelayedComment(userId, delayedTime);
|
||||
return Result.success("已成功添加延迟评价任务");
|
||||
}else {
|
||||
//没有未评价的记录不需要添加延迟任务
|
||||
return Result.success("无需添加延迟任务评价");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.grail.doctor.publice.mapper;
|
||||
|
||||
import com.grail.publice.domain.Comment;
|
||||
import com.grail.publice.domain.Gift;
|
||||
import com.grail.publice.domain.response.ResponseComment;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
@ -17,4 +18,10 @@ public interface CommentMapper {
|
|||
List<ResponseComment> commentList();
|
||||
|
||||
List<Gift> giftList();
|
||||
|
||||
|
||||
|
||||
void addComment(Comment comment);
|
||||
|
||||
int countUnfinishedComments(Integer userId);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.grail.doctor.publice.service;
|
||||
|
||||
import com.grail.common.core.domain.Result;
|
||||
import com.grail.publice.domain.Comment;
|
||||
import com.grail.publice.domain.Gift;
|
||||
import com.grail.publice.domain.response.ResponseComment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -16,4 +18,12 @@ public interface CommentServlce {
|
|||
Result<List<ResponseComment>> commentList();
|
||||
|
||||
Result<List<Gift>> giftList();
|
||||
|
||||
void addComment(Comment comment);
|
||||
|
||||
int countUnfinishedComments(Integer userId);
|
||||
|
||||
void addDelayedComment(Integer userId, LocalDateTime delayedTime);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,12 +3,18 @@ package com.grail.doctor.publice.service.impl;
|
|||
import com.grail.common.core.domain.Result;
|
||||
import com.grail.doctor.publice.mapper.CommentMapper;
|
||||
import com.grail.doctor.publice.service.CommentServlce;
|
||||
import com.grail.publice.domain.Comment;
|
||||
import com.grail.publice.domain.Gift;
|
||||
import com.grail.publice.domain.response.ResponseComment;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* @ClassName : CommentServlceimpl
|
||||
|
@ -19,7 +25,12 @@ import java.util.List;
|
|||
@Service
|
||||
public class CommentServlceimpl implements CommentServlce {
|
||||
@Autowired
|
||||
private CommentMapper commentMapper;
|
||||
private CommentMapper commentMapper;//注入CommenMapper实例
|
||||
private final Timer timer;
|
||||
|
||||
public CommentServlceimpl() {
|
||||
this.timer = new Timer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<List<ResponseComment>> commentList() {
|
||||
|
@ -32,4 +43,53 @@ public class CommentServlceimpl implements CommentServlce {
|
|||
List<Gift> list = commentMapper.giftList();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void addComment(Comment comment) {
|
||||
//根据具体的持久框架,使用相应的方法将comment对象保存到数据库
|
||||
//这里我们假设使用MyBatista,调用commentMapper等方法
|
||||
commentMapper.addComment(comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countUnfinishedComments(Integer userId) {
|
||||
// 根据具体的持久化框架,使用相应的方法查询未评价的记录数
|
||||
// 这里我们假设使用MyBatis,调用commentMapper的方法
|
||||
return commentMapper.countUnfinishedComments(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDelayedComment(Integer userId, LocalDateTime delayedTime) {
|
||||
//计算延迟时间和当前时间之间的时间差
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
long delay = Duration.between(now, delayedTime).toMillis();
|
||||
|
||||
//创建一个 TimeTask 任务
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
//任务执行时,添加中评
|
||||
Comment comment = new Comment();
|
||||
comment.setCommentContent("满意");//自动给出中评
|
||||
comment.setCommentTime(new Date()); //默认添加当前时间
|
||||
comment.setUserId(userId); //默认给出评价的用户
|
||||
comment.setCommentSpeciality(3); //表示医生专业度中等评价
|
||||
comment.setCommentSatisfied(3); //表示医生满意度中等评价
|
||||
comment.setGiftId(null); //礼物默认添加为空
|
||||
}
|
||||
};
|
||||
//在指定的延迟时间后执行任务
|
||||
timer.schedule(task, delay);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
<?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.grail.doctor.publice.mapper.CommentMapper">
|
||||
<insert id="addComment">
|
||||
INSERT INTO t_comments(commentId, commentContent, commentTime, userId, commentSpeciality, commentSatisfied, gift_id)
|
||||
VALUES (#{commentId}, #{commentContent}, #{commentTime}, #{userId}, #{commentSpeciality}, #{commentSatisfied}, #{giftId})
|
||||
</insert>
|
||||
<select id="countUnfinishedComments" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*) FROM comment WHERE user_id = #{userId} AND comment_satisfied IS NULL
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
<select id="commentList" resultType="com.grail.publice.domain.response.ResponseComment">
|
||||
select t_comment.*,gift_name,user_name from t_comment left join
|
||||
|
@ -10,4 +20,5 @@
|
|||
<select id="giftList" resultType="com.grail.publice.domain.Gift">
|
||||
select * from t_gift
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue