ConsultController.java 22 KB

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