From b51008f8ef50e86d33abb01b10d50580555458f8 Mon Sep 17 00:00:00 2001 From: Yang Haoyu <2241399212@qq.com> Date: Wed, 25 Oct 2023 21:56:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../publice/controller/CommentController.java | 45 +++++++++++++- .../doctor/publice/mapper/CommentMapper.java | 7 +++ .../publice/service/CommentServlce.java | 10 +++ .../service/impl/CommentServlceimpl.java | 62 ++++++++++++++++++- .../main/resources/mapper/CommentMapper.xml | 11 ++++ 5 files changed, 131 insertions(+), 4 deletions(-) diff --git a/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/controller/CommentController.java b/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/controller/CommentController.java index 67bfa98..b0d0b42 100644 --- a/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/controller/CommentController.java +++ b/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/controller/CommentController.java @@ -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 addComment(@RequestBody Comment comment){ + comment.setCommentTime(new Date()); + commentServlce.addComment(comment); + + return Result.success("评论成功"); + } + @GetMapping("/exit") + public Result 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("无需添加延迟任务评价"); + } + } + + } diff --git a/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/mapper/CommentMapper.java b/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/mapper/CommentMapper.java index 8345d44..17b891a 100644 --- a/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/mapper/CommentMapper.java +++ b/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/mapper/CommentMapper.java @@ -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 commentList(); List giftList(); + + + + void addComment(Comment comment); + + int countUnfinishedComments(Integer userId); } diff --git a/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/service/CommentServlce.java b/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/service/CommentServlce.java index 92f584d..1700b6d 100644 --- a/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/service/CommentServlce.java +++ b/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/service/CommentServlce.java @@ -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> commentList(); Result> giftList(); + + void addComment(Comment comment); + + int countUnfinishedComments(Integer userId); + + void addDelayedComment(Integer userId, LocalDateTime delayedTime); + + } diff --git a/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/service/impl/CommentServlceimpl.java b/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/service/impl/CommentServlceimpl.java index 8eaf093..e293486 100644 --- a/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/service/impl/CommentServlceimpl.java +++ b/grail-doctor-public/grail-doctor-public-server/src/main/java/com/grail/doctor/publice/service/impl/CommentServlceimpl.java @@ -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> commentList() { @@ -32,4 +43,53 @@ public class CommentServlceimpl implements CommentServlce { List 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); + } + + + + + } diff --git a/grail-doctor-public/grail-doctor-public-server/src/main/resources/mapper/CommentMapper.xml b/grail-doctor-public/grail-doctor-public-server/src/main/resources/mapper/CommentMapper.xml index 285646b..c1c3753 100644 --- a/grail-doctor-public/grail-doctor-public-server/src/main/resources/mapper/CommentMapper.xml +++ b/grail-doctor-public/grail-doctor-public-server/src/main/resources/mapper/CommentMapper.xml @@ -1,6 +1,16 @@ + + INSERT INTO t_comments(commentId, commentContent, commentTime, userId, commentSpeciality, commentSatisfied, gift_id) + VALUES (#{commentId}, #{commentContent}, #{commentTime}, #{userId}, #{commentSpeciality}, #{commentSatisfied}, #{giftId}) + + + + + select * from t_gift +