|
@@ -0,0 +1,57 @@
|
|
|
+package thyyxxk.wxservice_server.service;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
|
|
|
+import thyyxxk.wxservice_server.dao.CommentDao;
|
|
|
+import thyyxxk.wxservice_server.entity.PureCodeName;
|
|
|
+import thyyxxk.wxservice_server.entity.ResultVo;
|
|
|
+import thyyxxk.wxservice_server.entity.comment.request.CommentsInquiry;
|
|
|
+import thyyxxk.wxservice_server.entity.comment.response.CommentsResponse;
|
|
|
+import thyyxxk.wxservice_server.entity.comment.response.WechatPatientComment;
|
|
|
+import thyyxxk.wxservice_server.utils.ResultVoUtil;
|
|
|
+import thyyxxk.wxservice_server.utils.StringUtil;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class CommentService {
|
|
|
+ private final CommentDao dao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public CommentService(CommentDao dao) {
|
|
|
+ this.dao = dao;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<String> commitNewComment(WechatPatientComment comment) {
|
|
|
+ if (StringUtil.isBlank(comment.getCommentContent())) {
|
|
|
+ comment.setCommentContent("未填写评价内容。");
|
|
|
+ }
|
|
|
+ int times = Integer.parseInt(comment.getHisOrdNum().split("_")[1]);
|
|
|
+ comment.setTimes(times);
|
|
|
+ PureCodeName doctor = dao.selectDoctorCodeRsAndName(comment.getDoctorCode());
|
|
|
+ comment.setDoctorCodeRs(doctor.getCode());
|
|
|
+ comment.setDoctorName(doctor.getName());
|
|
|
+ int result = dao.insertNewComment(comment);
|
|
|
+ if (result == 1) {
|
|
|
+ return ResultVoUtil.success("评价成功。");
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "服务器异常,请稍后再试。");
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<CommentsResponse> fetchDoctorComments(CommentsInquiry inquiry) {
|
|
|
+ List<WechatPatientComment> list = dao.selectDoctorComments(inquiry);
|
|
|
+ CommentsResponse response = new CommentsResponse();
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ response.setFinished(true);
|
|
|
+ response.setMinId(-1);
|
|
|
+ response.setList(list);
|
|
|
+ return ResultVoUtil.success(response);
|
|
|
+ }
|
|
|
+ int latestMinId = list.get(list.size() - 1).getId();
|
|
|
+ response.setMinId(latestMinId);
|
|
|
+ response.setFinished(dao.moreCommentsExist(inquiry.getDoctorCode(), latestMinId) == 0);
|
|
|
+ response.setList(list);
|
|
|
+ return ResultVoUtil.success(response);
|
|
|
+ }
|
|
|
+}
|