ConsultController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. package com.yihu.wlyy.web.patient.consult;
  2. import java.util.*;
  3. import com.yihu.wlyy.entity.consult.ConsultTeam;
  4. import com.yihu.wlyy.entity.consult.ConsultTeamLog;
  5. import com.yihu.wlyy.entity.doctor.profile.Doctor;
  6. import com.yihu.wlyy.entity.doctor.schedule.WlyyDoctorWorkTime;
  7. import com.yihu.wlyy.entity.doctor.schedule.WlyyDoctorWorkWeek;
  8. import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
  9. import io.swagger.annotations.Api;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.json.JSONArray;
  12. import org.json.JSONObject;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.data.domain.Page;
  15. import org.springframework.stereotype.Controller;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.ResponseBody;
  19. import com.yihu.wlyy.service.app.consult.ConsultTeamService;
  20. import com.yihu.wlyy.service.app.consult.DoctorCommentService;
  21. import com.yihu.wlyy.service.app.statistics.DoctorStatisticsService;
  22. import com.yihu.wlyy.service.app.talk.TalkGroupService;
  23. import com.yihu.wlyy.service.common.account.DoctorService;
  24. import com.yihu.wlyy.task.DoctorStatisticsTask;
  25. import com.yihu.wlyy.task.PushMsgTask;
  26. import com.yihu.wlyy.util.CommonUtil;
  27. import com.yihu.wlyy.util.DateUtil;
  28. import com.yihu.wlyy.util.MessageType;
  29. import com.yihu.wlyy.web.WeixinBaseController;
  30. /**
  31. * 患者端:三师咨询控制类
  32. * @author George
  33. *
  34. */
  35. @Controller
  36. @RequestMapping(value = "/patient/consult")
  37. @Api(description = "患者端-患者咨询")
  38. public class ConsultController extends WeixinBaseController {
  39. @Autowired
  40. private ConsultTeamService consultTeamService;
  41. @Autowired
  42. private DoctorCommentService doctorCommentService;
  43. @Autowired
  44. private DoctorStatisticsService doctorStatisticsService;
  45. @Autowired
  46. private DoctorService doctorService;
  47. @Autowired
  48. private TalkGroupService talkGroupService;
  49. @Autowired
  50. private DoctorWorkTimeService doctorWorkTimeService;
  51. /**
  52. * 患者咨询记录查询
  53. * @param title 咨询标题
  54. * @param id
  55. * @param pagesize 分页大小
  56. * @return
  57. */
  58. @RequestMapping(value = "records")
  59. @ResponseBody
  60. public String consultRecords(
  61. @RequestParam(required = false) String title,
  62. long id,
  63. int pagesize) {
  64. try {
  65. JSONArray array = new JSONArray();
  66. Page<Object> data = consultTeamService.findConsultRecordByPatient(getUID(), id, pagesize,title);
  67. if (data != null) {
  68. for (Object consult : data.getContent()) {
  69. if (consult == null) {
  70. continue;
  71. }
  72. Object[] result = (Object[])consult;
  73. JSONObject json = new JSONObject();
  74. json.put("id", result[0]);
  75. // 设置咨询类型:1三师咨询,2视频咨询,3图文咨询,4公共咨询,5病友圈
  76. json.put("type", result[1]);
  77. // 设置咨询标识
  78. json.put("code", result[2]);
  79. // 设置显示标题
  80. json.put("title", result[3]);
  81. // 设置主诉
  82. json.put("symptoms", result[4]);
  83. // 咨询状态
  84. json.put("status", result[6]);
  85. // 设置咨询日期
  86. json.put("czrq", DateUtil.dateToStrLong((Date)result[5]));
  87. array.put(json);
  88. }
  89. }
  90. return write(200, "查询成功!", "list", array);
  91. } catch (Exception e) {
  92. error(e);
  93. return error(-1, "查询失败!");
  94. }
  95. }
  96. /**
  97. * 获取医生的排班时间
  98. *
  99. * @param doctor
  100. * @param week
  101. * @return
  102. */
  103. @RequestMapping(value = "/doctor_worktime/week")
  104. @ResponseBody
  105. public String getDoctorWeekWorkTime(String doctor,String week){
  106. try{
  107. JSONObject result = doctorWorkTimeService.findDoctorWeekWorkTime(doctor,week);
  108. return write(200,"查询成功!","data",result);
  109. }catch (Exception e){
  110. e.printStackTrace();
  111. return error(-1,"查询失败!");
  112. }
  113. }
  114. /**
  115. * 获取医生某天的排班时间
  116. *
  117. * @param doctor
  118. * @return
  119. */
  120. @RequestMapping(value = "/doctor_worktime")
  121. @ResponseBody
  122. public String getDoctorWorkTime(String doctor){
  123. try{
  124. JSONObject result = doctorWorkTimeService.findDoctorWorkTime(doctor);
  125. return write(200,"查询成功!","data",result);
  126. }catch (Exception e){
  127. e.printStackTrace();
  128. return error(-1,"查询失败!");
  129. }
  130. }
  131. /**
  132. * 医生是否在工作
  133. *
  134. * @param doctor
  135. * @return
  136. */
  137. @RequestMapping(value = "is_doctor_working")
  138. @ResponseBody
  139. public String isDoctorAtWorking(String doctor){
  140. try{
  141. JSONObject result = doctorWorkTimeService.isDoctorWorking(doctor);
  142. return write(200,result.getString("msg"),"data",result.getString("status"));
  143. }catch (Exception e){
  144. e.printStackTrace();
  145. return error(-1,"查询失败");
  146. }
  147. }
  148. /**
  149. * 名医是否在工作
  150. *
  151. * @param doctor
  152. * @return
  153. */
  154. @RequestMapping(value = "is_famous_doctor_working")
  155. @ResponseBody
  156. public String isFamousDoctorAtWorking(String doctor){
  157. try{
  158. JSONObject result = doctorWorkTimeService.isFamousDoctorWorking(doctor);
  159. return write(200,result.getString("msg"),"data",result.getString("status"));
  160. }catch (Exception e){
  161. e.printStackTrace();
  162. return error(-1,"查询失败");
  163. }
  164. }
  165. /**
  166. * 名医咨询剩余次数查询
  167. *
  168. * @param doctor
  169. * @return
  170. */
  171. @RequestMapping(value = "/consult_times_remain")
  172. @ResponseBody
  173. public String famousDoctorTimesRemain(String doctor){
  174. try{
  175. int result = doctorWorkTimeService.getDoctorConsultTimesRemain(doctor);
  176. return write(200,"查询成功","data",result);
  177. }catch (Exception e){
  178. e.printStackTrace();
  179. return error(-1,"查询失败");
  180. }
  181. }
  182. /**
  183. * 获取未完成咨询
  184. *
  185. * @return
  186. */
  187. @RequestMapping(value = "/unfinished")
  188. @ResponseBody
  189. public String getUnFinishedConsult(){
  190. try{
  191. List<ConsultTeam> unfinishedConsult = consultTeamService.getUnfinishedConsult(getUID());
  192. JSONArray result = new JSONArray(unfinishedConsult);
  193. return write(200,"查询成功!","data",result);
  194. }catch (Exception e){
  195. e.printStackTrace();
  196. return error(-1,"查询失败!");
  197. }
  198. }
  199. /**
  200. * 三师咨询添加接口
  201. * @param type 咨询类型:1三师咨询,2家庭医生咨询
  202. * @param when 发病时间
  203. * @param symptoms 主要症状
  204. * @param images 图片URL地址,多图以逗号分隔
  205. * @param voice 语音URL地址
  206. * @return
  207. */
  208. @RequestMapping(value = "add")
  209. @ResponseBody
  210. public String add(@RequestParam(required = false) Integer type,
  211. String when,
  212. String symptoms,
  213. @RequestParam(required = false) String images,
  214. @RequestParam(required = false) String voice) {
  215. try {
  216. if (type == null) {
  217. type = 1;
  218. }
  219. if (type != 1 && type != 2) {
  220. return error(-1, "无效请求!");
  221. }
  222. if (consultTeamService.exist(getUID(),type)) {
  223. return error(-1, "还有咨询未结束,不允许再次提交咨询!");
  224. }
  225. if (StringUtils.isEmpty(images)) {
  226. images = fetchWxImages();
  227. }
  228. // 将临时图片拷贝到正式存储路径下
  229. if (StringUtils.isNotEmpty(images)) {
  230. images = CommonUtil.copyTempImage(images);
  231. }
  232. if (StringUtils.isEmpty(voice)) {
  233. voice = fetchWxVoices();
  234. }
  235. if (StringUtils.isNotEmpty(voice)) {
  236. voice = CommonUtil.copyTempVoice(voice);
  237. }
  238. ConsultTeam consult = new ConsultTeam();
  239. // 设置咨询类型:1三师咨询,2家庭医生咨询 6.名医咨询
  240. consult.setType(type);
  241. // 设置发病时间
  242. consult.setWhen(when);
  243. // 设置主要症状
  244. consult.setSymptoms(symptoms);
  245. // 设置咨询图片URL
  246. consult.setImages(images);
  247. // 设置咨询语音URL
  248. consult.setVoice(voice);
  249. // 保存到数据库
  250. int res = consultTeamService.addTeamConsult(consult, getUID());
  251. if (res == -1) {
  252. return error(-1, "家庭签约信息不存在或已过期,无法进行家庭医生咨询!");
  253. } else if (res == -2) {
  254. return error(-1, "家庭签约信息不存在或已过期,无法进行三师医生咨询!");
  255. }
  256. Doctor doctor = doctorService.findDoctorByCode(consult.getDoctor());
  257. //创建咨询讨论组
  258. talkGroupService.createConsultTalkGroup(consult.getDoctor(), doctor.getName(), doctor.getHospital(), doctor.getHosptialName(),
  259. consult.getPatient(), consult.getName(),consult.getConsult());
  260. // 添加到统计队列
  261. if (consult.getType() == 2) {
  262. DoctorStatisticsTask.getInstance(doctorStatisticsService).put(consult.getDoctor(), 1, 1, 0);
  263. }
  264. // 推送消息给医生
  265. PushMsgTask.getInstance().put(consult.getDoctor(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.D_CT_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.指定咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.您有新的指定咨询.name(), consult.getConsult());
  266. return success("提交成功");
  267. } catch (Exception ex) {
  268. error(ex);
  269. return invalidUserException(ex, -1, "提交失败!");
  270. }
  271. }
  272. /**
  273. * 名医咨询添加接口
  274. * @param when 发病时间
  275. * @param symptoms 主要症状
  276. * @param images 图片URL地址,多图以逗号分隔
  277. * @param voice 语音URL地址
  278. * @param doctorCode 名医的code
  279. * @return
  280. */
  281. @RequestMapping(value = "famousAdd")
  282. @ResponseBody
  283. public String famousAdd(
  284. @RequestParam(required = false)String when,
  285. String symptoms,
  286. @RequestParam(required = false) String doctorCode,
  287. @RequestParam(required = false) String images,
  288. @RequestParam(required = false) String voice) {
  289. try {
  290. //判断医生是否是在工作时间
  291. JSONObject jo=doctorWorkTimeService.isFamousDoctorWorking(doctorCode);
  292. if(!jo.get("status").equals("1")){
  293. return error(-1, jo.get("msg").toString());
  294. }
  295. //判断医生是否剩下咨询次数
  296. int result = doctorWorkTimeService.getDoctorConsultTimesRemain(doctorCode);
  297. if(result==0){
  298. return error(-1, "没有次数");
  299. }
  300. if (StringUtils.isEmpty(images)) {
  301. images = fetchWxImages();
  302. }
  303. // 将临时图片拷贝到正式存储路径下
  304. if (StringUtils.isNotEmpty(images)) {
  305. images = CommonUtil.copyTempImage(images);
  306. }
  307. if (StringUtils.isEmpty(voice)) {
  308. voice = fetchWxVoices();
  309. }
  310. if (StringUtils.isNotEmpty(voice)) {
  311. voice = CommonUtil.copyTempVoice(voice);
  312. }
  313. //判断是否已经存在还没有关闭的名医咨询
  314. if(consultTeamService.isExistFamousConsult(getUID())){
  315. return error(-1, "已经存在名医咨询!");
  316. }
  317. ConsultTeam consult = new ConsultTeam();
  318. // 设置咨询类型:1三师咨询,2家庭医生咨询 6.名医咨询
  319. consult.setType(6);
  320. // 设置发病时间
  321. consult.setWhen(when);
  322. // 设置主要症状
  323. consult.setSymptoms(symptoms);
  324. // 设置咨询图片URL
  325. consult.setImages(images);
  326. // 设置咨询语音URL
  327. consult.setVoice(voice);
  328. consult.setDoctor(doctorCode);//设置专科医生
  329. // 保存到数据库
  330. consultTeamService.addFamousTeamConsult(consult, getUID());
  331. //名医咨询次数减一
  332. doctorWorkTimeService.setDoctorCurrentConsultTimesRemain(doctorCode);
  333. // 推送消息给医生
  334. PushMsgTask.getInstance().put(consult.getDoctor(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM.D_CT_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM.名医咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM.您有新的名医咨询.name(), consult.getConsult());
  335. return success("提交成功");
  336. } catch (Exception ex) {
  337. error(ex);
  338. return invalidUserException(ex, -1, "提交失败!");
  339. }
  340. }
  341. /**
  342. * 名医列表
  343. * @return
  344. */
  345. @RequestMapping(value = "famousDoctorList")
  346. @ResponseBody
  347. public String famousDoctorList(
  348. @RequestParam(required = false) String name,
  349. int page,
  350. int pagesize) {
  351. try {
  352. JSONArray array = new JSONArray();
  353. Page<Doctor>list = doctorService.famousDoctorList(name, page, pagesize);
  354. if (list != null) {
  355. for (Doctor doctor : list) {
  356. if (doctor == null) {
  357. continue;
  358. }
  359. JSONObject json = new JSONObject();
  360. json.put("id", doctor.getId());
  361. // 医生标识
  362. json.put("code", doctor.getCode());
  363. // 医生性别
  364. json.put("sex", doctor.getSex());
  365. // 医生姓名
  366. json.put("name", doctor.getName());
  367. // 所在医院名称
  368. json.put("hospital", doctor.getHospital());
  369. // 所在医院名称
  370. json.put("hospital_name", doctor.getHosptialName());
  371. // 科室名称
  372. json.put("dept_name", (doctor.getDeptName() == null ||
  373. StringUtils.isEmpty(doctor.getDeptName().toString())) ? " " : doctor.getDeptName());
  374. // 职称名称
  375. json.put("job_name", (doctor.getJobName() == null ||
  376. StringUtils.isEmpty(doctor.getJobName().toString())) ? " " : doctor.getJobName());
  377. // 头像
  378. json.put("photo", doctor.getPhoto());
  379. // 简介
  380. json.put("introduce", doctor.getIntroduce());
  381. // 专长
  382. json.put("expertise", doctor.getExpertise());
  383. // 剩余咨询次数
  384. json.put("num", doctorWorkTimeService.getDoctorConsultTimesRemain(doctor.getCode()));
  385. array.put(json);
  386. }
  387. }
  388. return write(200, "获取医院医生列表成功!", "list", array);
  389. } catch (Exception e) {
  390. error(e);
  391. return error(-1, "获取医院医生列表失败!");
  392. }
  393. }
  394. @RequestMapping(value = "status")
  395. @ResponseBody
  396. public String status(String consult) {
  397. try {
  398. ConsultTeam ct = consultTeamService.findByCode(consult);
  399. if (ct == null) {
  400. return error(-1, "获取状态失败!");
  401. } else {
  402. return write(200, "获取状态成功!", "data", ct.getStatus());
  403. }
  404. } catch (Exception e) {
  405. error(e);
  406. return invalidUserException(e, -1, "获取状态失败!");
  407. }
  408. }
  409. /**
  410. * 查询患者三师咨询咨询列表
  411. * @param status 咨询状态(0未结束,1已结束,-1 已取消)
  412. * @param pagesize 页数
  413. * @return 查询结果
  414. */
  415. @RequestMapping(value = "list")
  416. @ResponseBody
  417. public String list(int status, long id, int pagesize) {
  418. try {
  419. Page<ConsultTeam> consults = consultTeamService.findByPatient(getUID(), status, id, pagesize);
  420. JSONArray jsonArray = new JSONArray();
  421. if (consults != null) {
  422. for (ConsultTeam consult : consults) {
  423. if (consult == null) {
  424. continue;
  425. }
  426. JSONObject json = new JSONObject();
  427. json.put("id", consult.getId());
  428. // 设置咨询标志
  429. json.put("code", consult.getConsult());
  430. // 设置咨询类型:0公共咨询,1指定医生,2三师咨询
  431. json.put("type", consult.getType());
  432. // 设置标题
  433. json.put("title", consult.getSymptoms());
  434. // 设置发病时间
  435. json.put("when", consult.getWhen());
  436. // 设置患者未读数量
  437. json.put("patientRead", consult.getPatientRead());
  438. // 设置状态
  439. json.put("status", consult.getStatus());
  440. // 设置患者评价标识
  441. json.put("comment", consult.getComment());
  442. // 设置咨询或回复时间
  443. json.put("time", DateUtil.dateToStr(consult.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
  444. jsonArray.put(json);
  445. }
  446. }
  447. return write(200, "查询成功", "list", jsonArray);
  448. } catch (Exception ex) {
  449. error(ex);
  450. return invalidUserException(ex, -1, "查询失败!");
  451. }
  452. }
  453. /**
  454. * 患者取消三师咨询
  455. * @param consult
  456. * @return
  457. */
  458. @RequestMapping(value = "cancel")
  459. @ResponseBody
  460. public String cancel(String consult) {
  461. try {
  462. int row = consultTeamService.cancel(consult);
  463. if (row > 0) {
  464. return success("咨询已取消!");
  465. } else {
  466. return error(-1, "咨询不能取消!");
  467. }
  468. } catch (Exception e) {
  469. error(e);
  470. return invalidUserException(e, -1, "操作失败!");
  471. }
  472. }
  473. /**
  474. * 修改状态为1的咨询记录为结束
  475. * @param code 咨询标识
  476. * @return
  477. */
  478. @RequestMapping(value = "finish")
  479. @ResponseBody
  480. public String finish(String code) {
  481. try {
  482. int row = consultTeamService.finish(code);
  483. if (row > 0) {
  484. return success("操作成功!");
  485. } else {
  486. return error(-1, "操作失败!");
  487. }
  488. } catch (Exception e) {
  489. error(e);
  490. return invalidUserException(e, -1, "操作失败!");
  491. }
  492. }
  493. /**
  494. * 三师咨询追问接口
  495. * @param consult 咨询标识
  496. * @param content 追问内容
  497. * @param type 追问内容类型:1文字,2图片,3语音
  498. * @return
  499. */
  500. @RequestMapping(value = "append")
  501. @ResponseBody
  502. public String append(String consult, String content, int type) {
  503. try {
  504. List<ConsultTeamLog> logs = new ArrayList<ConsultTeamLog>();
  505. if (type == 2) {
  506. // 图片消息
  507. if (StringUtils.isEmpty(content)) {
  508. content = fetchWxImages();
  509. }
  510. // 将临时图片拷贝到正式存储路径下
  511. if (StringUtils.isNotEmpty(content)) {
  512. content = CommonUtil.copyTempImage(content);
  513. }
  514. if (StringUtils.isEmpty(content)) {
  515. return error(-1, "图片上传失败!");
  516. }
  517. String[] images = content.split(",");
  518. for (String image : images) {
  519. ConsultTeamLog log = new ConsultTeamLog();
  520. log.setConsult(consult);
  521. log.setContent(image);
  522. log.setDel("1");
  523. log.setChatType(type);
  524. log.setType(2);
  525. logs.add(log);
  526. }
  527. } else {
  528. ConsultTeamLog log = new ConsultTeamLog();
  529. log.setConsult(consult);
  530. log.setContent(content);
  531. log.setDel("1");
  532. log.setChatType(type);
  533. log.setType(2);
  534. logs.add(log);
  535. }
  536. consultTeamService.reply(logs, getUID());
  537. return write(200, "追问成功!", "data", content);
  538. } catch (Exception e) {
  539. error(e);
  540. return invalidUserException(e, -1, "追问失败!");
  541. }
  542. }
  543. /**
  544. * 网络咨询咨询日志查询
  545. * @param consult 咨询标识
  546. * @param pagesize 每页显示数,默认为10
  547. * @return
  548. */
  549. @RequestMapping(value = "loglist")
  550. @ResponseBody
  551. public String loglist(String consult, long id, int pagesize) {
  552. try {
  553. ConsultTeam consultModel = consultTeamService.findByCode(consult);
  554. if (consultModel == null) {
  555. return error(-1, "咨询记录不存在!");
  556. }
  557. if (id <= 0) {
  558. // 更新患者未读数量为0
  559. consultTeamService.clearPatientRead(consult);
  560. }
  561. // 查询日志列表
  562. JSONArray jsonArray = new JSONArray();
  563. Page<ConsultTeamLog> list = consultTeamService.findLogByConsult(consult, id, pagesize);
  564. if (list != null) {
  565. for (ConsultTeamLog log : list) {
  566. if (consult == null) {
  567. continue;
  568. }
  569. JSONObject json = new JSONObject();
  570. json.put("id", log.getId());
  571. // 设置回复医生姓名
  572. json.put("doctorName", log.getDoctorName());
  573. // 设置回复内容
  574. json.put("content", log.getContent());
  575. // 设置咨询或回复时间
  576. json.put("time", DateUtil.dateToStr(log.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
  577. // 设置记录类型:1文字,2图片,3语音
  578. json.put("msgType", log.getChatType());
  579. // 设置类型:0患者问,1医生回复,2患者追问,3患者评价
  580. json.put("type", log.getType());
  581. jsonArray.put(json);
  582. }
  583. }
  584. // 返回结果
  585. return write(200, "查询成功", "list", jsonArray);
  586. } catch (Exception e) {
  587. error(e);
  588. return invalidUserException(e, -1, "查询失败!");
  589. }
  590. }
  591. /**
  592. * 查找单个咨询记录
  593. * @param consult 咨询标识
  594. * @param logId 记录标识
  595. *
  596. * @return
  597. */
  598. @RequestMapping(value = "oneLog")
  599. @ResponseBody
  600. public String oneLog(String consult,Long logId) {
  601. try {
  602. ConsultTeam consultModel = consultTeamService.findByCode(consult);
  603. if (consultModel == null) {
  604. return error(-1, "咨询记录不存在!");
  605. }
  606. // 查询日志列表
  607. JSONObject json = new JSONObject();
  608. ConsultTeamLog log = consultTeamService.oneLog(logId);
  609. if (log != null) {
  610. json.put("id", log.getId());
  611. // 设置回复医生姓名
  612. json.put("doctorName", log.getDoctorName());
  613. // 设置回复内容
  614. json.put("content", log.getContent());
  615. // 设置咨询或回复时间
  616. json.put("time", DateUtil.dateToStr(log.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
  617. // 设置记录类型:1文字,2图片,3语音
  618. json.put("msgType", log.getChatType());
  619. // 设置类型:0患者问,1医生回复,2患者追问,3患者评价
  620. json.put("type", log.getType());
  621. }
  622. // 返回结果
  623. return write(200, "查询成功", "consult", json);
  624. } catch (Exception e) {
  625. error(e);
  626. return invalidUserException(e, -1, "查询失败!");
  627. }
  628. }
  629. /**
  630. * 三师咨询评论
  631. * @param consult 咨询标识
  632. * @param content 评价内容
  633. * @param star 星级
  634. * @return 操作结果
  635. */
  636. @RequestMapping(value = "comment")
  637. @ResponseBody
  638. public String comment(String consult, String content, int star) {
  639. try {
  640. // 保存评价
  641. JSONArray array = doctorCommentService.consultComment(getUID(), consult, content, star, 2);
  642. // 添加到统计队列
  643. if (array != null) {
  644. DoctorStatisticsTask.getInstance(doctorStatisticsService).put(array);
  645. }
  646. // 添加评价记录
  647. ConsultTeamLog log = new ConsultTeamLog();
  648. log.setConsult(consult);
  649. log.setContent(content);
  650. log.setChatType(1);
  651. log.setDel("1");
  652. log.setType(3);
  653. log = consultTeamService.reply(log, getUID(), null, log.getType());
  654. return success("感谢您的评价!");
  655. } catch (Exception e) {
  656. error(e);
  657. return invalidUserException(e, -1, "评价失败!");
  658. }
  659. }
  660. }