Browse Source

添加患者评价功能。

lighter 2 years ago
parent
commit
4e20e2db63

+ 35 - 0
src/main/java/thyyxxk/wxservice_server/controller/CommentController.java

@@ -0,0 +1,35 @@
+package thyyxxk.wxservice_server.controller;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+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.service.CommentService;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/comment")
+public class CommentController {
+    private final CommentService service;
+
+    @Autowired
+    public CommentController(CommentService service) {
+        this.service = service;
+    }
+
+    @PostMapping("/commitNewComment")
+    public ResultVo<String> commitNewComment(@RequestBody WechatPatientComment comment) {
+        return service.commitNewComment(comment);
+    }
+
+    @PostMapping("/fetchDoctorComments")
+    public ResultVo<CommentsResponse> fetchDoctorComments(@RequestBody CommentsInquiry inquiry) {
+        return service.fetchDoctorComments(inquiry);
+    }
+}

+ 29 - 0
src/main/java/thyyxxk/wxservice_server/dao/CommentDao.java

@@ -0,0 +1,29 @@
+package thyyxxk.wxservice_server.dao;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import thyyxxk.wxservice_server.entity.PureCodeName;
+import thyyxxk.wxservice_server.entity.comment.request.CommentsInquiry;
+import thyyxxk.wxservice_server.entity.comment.response.WechatPatientComment;
+
+import java.util.List;
+
+@Mapper
+public interface CommentDao {
+    @Select("select rtrim(code_rs) as code,rtrim(name) as name from a_employee_mi where code=#{code} ")
+    PureCodeName selectDoctorCodeRsAndName(String code);
+
+    @Insert("insert into t_wechat_patient_comment (doctor_code, doctor_code_rs, doctor_name, patient_id, times, " +
+            "patient_name, comment_level, comment_content) " +
+            "values (#{doctorCode},#{doctorCodeRs},#{doctorName},#{patientId},#{times}, " +
+            "#{patientName},#{commentLevel},#{commentContent})")
+    int insertNewComment(WechatPatientComment comment);
+
+    @Select("select top ${pageSize} *,commentTime=convert(varchar(10),comment_time,21) " +
+            "from t_wechat_patient_comment where doctor_code=#{doctorCode} and id<#{minId} order by id desc")
+    List<WechatPatientComment> selectDoctorComments(CommentsInquiry inquiry);
+
+    @Select("select count(1) from t_wechat_patient_comment where doctor_code=#{doctorCode} and id<#{minId}")
+    int moreCommentsExist(String doctorCode, int minId);
+}

+ 18 - 0
src/main/java/thyyxxk/wxservice_server/entity/comment/request/CommentsInquiry.java

@@ -0,0 +1,18 @@
+package thyyxxk.wxservice_server.entity.comment.request;
+
+import lombok.Data;
+
+@Data
+public class CommentsInquiry {
+    private String doctorCode;
+    private Integer pageSize;
+    private Integer minId;
+
+    public Integer getPageSize() {
+        return null == pageSize ? 3 : pageSize;
+    }
+
+    public Integer getMinId() {
+        return null == minId ? 99999999 : minId;
+    }
+}

+ 12 - 0
src/main/java/thyyxxk/wxservice_server/entity/comment/response/CommentsResponse.java

@@ -0,0 +1,12 @@
+package thyyxxk.wxservice_server.entity.comment.response;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class CommentsResponse {
+    private Integer minId;
+    private Boolean finished;
+    private List<WechatPatientComment> list;
+}

+ 33 - 0
src/main/java/thyyxxk/wxservice_server/entity/comment/response/WechatPatientComment.java

@@ -0,0 +1,33 @@
+package thyyxxk.wxservice_server.entity.comment.response;
+
+import lombok.Data;
+
+@Data
+public class WechatPatientComment {
+  private Integer id;
+  private String doctorCode;
+  private String doctorCodeRs;
+  private String doctorName;
+  private String patientId;
+  private Integer times;
+  private String patientName;
+  private String fuzzyName;
+  private String commentTime;
+  private Integer commentLevel;
+  private String commentContent;
+  private String hisOrdNum;
+
+  public String getFuzzyName() {
+    StringBuilder sb = new StringBuilder();
+    sb.append(patientName.charAt(0));
+    if (patientName.length() == 2) {
+      sb.append("*");
+      return sb.toString();
+    }
+    for (int i = 1; i < patientName.length() - 1; i++) {
+      sb.append("*");
+    }
+    sb.append(patientName.charAt(patientName.length() - 1));
+    return sb.toString();
+  }
+}

+ 57 - 0
src/main/java/thyyxxk/wxservice_server/service/CommentService.java

@@ -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);
+    }
+}

+ 4 - 3
src/main/resources/application.yml

@@ -9,8 +9,8 @@ spring:
     cache: false
   datasource:
     driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
-#    url: jdbc:sqlserver://172.16.32.179:1433;databaseName=thxyhisdb
-    url: jdbc:sqlserver://172.16.32.168:1433;databaseName=thxyhisdb
+    url: jdbc:sqlserver://172.16.32.179:1433;databaseName=thxyhisdb
+#    url: jdbc:sqlserver://172.16.32.168:1433;databaseName=thxyhisdb
     hikari:
       username: sa
       password:
@@ -34,7 +34,8 @@ mybatis:
 
 #hrgApiUrl: http://172.16.30.33:8089/thmz/api/v1
 #hrgApiUrl: http://172.16.30.33:8889/thmz/api/v1
-hrgApiUrl: http://172.16.32.160:81/thmz/api/v1
+#hrgApiUrl: http://172.16.32.160:81/thmz/api/v1
+hrgApiUrl: http://172.16.30.22:8089/thmz/api/v1
 
 inspectionUrl: http://172.16.32.178:622/pushservice.asmx?wsdl
 physicalCheck: http://172.16.32.183:8888/bdp/dataservice/api/