Browse Source

代码修改

suqinyi 1 năm trước cách đây
mục cha
commit
73d3a22589

+ 7 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/PrescriptionDao.java

@ -16,6 +16,9 @@ import java.util.List;
 */
public interface PrescriptionDao extends PagingAndSortingRepository<WlyyPrescriptionDO, String>, JpaSpecificationExecutor<WlyyPrescriptionDO> {
    @Query("select a from WlyyPrescriptionDO a where a.patientCode = ?1 and a.status >= 0 ")
    List<WlyyPrescriptionDO> findByPatientCode(String patientCode);
@ -72,4 +75,8 @@ public interface PrescriptionDao extends PagingAndSortingRepository<WlyyPrescrip
    @Query("select a from WlyyPrescriptionDO a,WlyyDoorPrescriptionDO p where a.id=p.code and p.orderId = ?1 and p.isAfterDoor = ?2  order by a.createTime desc")
    List<WlyyPrescriptionDO> findByOrderIdAndIsAfterDoor(String id, Integer isAfterDoor);
//    @Query("from WlyyPrescriptionDO p where p.code=?1")
//    @Query("from WlyyPrescriptionDO p where p.code=?1")
//    WlyyPrescriptionDO findByCode(String code);
}

+ 3 - 0
business/base-service/src/main/java/com/yihu/jw/order/dao/ConsultOrderDao.java

@ -27,4 +27,7 @@ public interface ConsultOrderDao extends PagingAndSortingRepository<ConsultDo, S
//	// 查询患者咨询记录
//	@Query("select a.id,a.type,a.code,a.title,a.symptoms,a.czrq,b.status,b.doctor,b.team,b.evaluate,a.signCode  from ConsultDo a,ConsultTeamDo b where a.code = b.consult and a.patient = ?1 and a.del = '1' and a.type<>8 order by a.czrq desc")
//	Page<Object> findByPatient(String patient, Pageable pageRequest);
    ConsultDo queryByIdAndType(String id,Integer type);
}

+ 1 - 0
business/base-service/src/main/java/com/yihu/jw/order/dao/ConsultTeamOrderDao.java

@ -12,6 +12,7 @@ import java.util.Date;
 * @author huangwenjie
 */
public interface ConsultTeamOrderDao extends PagingAndSortingRepository<ConsultTeamDo, String>, JpaSpecificationExecutor<ConsultTeamDo> {
	// 根據consult查詢咨询记录
	ConsultTeamDo findByConsult(String consult);

+ 3 - 1
business/im-service/src/main/java/com/yihu/jw/im/util/ImUtil.java

@ -574,7 +574,6 @@ public class ImUtil {
            params.put("session_id", sessionId);
            params.put("session_type", sessionType);
            System.out.println("创建议题参数如下:" + "\n地址:" + imAddr + "\n参数:" + JSON.toJSONString(params));
            System.out.println("");
            String res = HttpClientUtil.postBody(imAddr, params);
            System.out.println("创建议题结果==>" + res);
            obj = JSON.parseObject(res);
@ -586,6 +585,9 @@ public class ImUtil {
        return obj;
    }
    /**
     * 判断会话是否存在
     */

+ 9 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/door/WlyyDoorPrescriptionDO.java

@ -22,6 +22,7 @@ import java.util.List;
@SequenceGenerator(name="id_generated", sequenceName="wlyy_door_prescription")
public class WlyyDoorPrescriptionDO extends IntegerIdentityEntity {
    private String consult;  //咨询id 1对1
    private String code ;//业务标识
//    private String number;//线上单号
    private String orderId;//工单id
@ -76,6 +77,14 @@ public class WlyyDoorPrescriptionDO extends IntegerIdentityEntity {
    private List<WlyyDoorPrescriptionDrugDO> recipeDetailList;
    public String getConsult() {
        return consult;
    }
    public void setConsult(String consult) {
        this.consult = consult;
    }
    @Transient
    public List<WlyyDoorPrescriptionDrugDO> getRecipeDetailList() {
        return recipeDetailList;

+ 12 - 12
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/controller/ConsultController.java

@ -1741,18 +1741,18 @@ public class ConsultController extends EnvelopRestEndpoint {
        }
    }
//    @RequestMapping(value = "queryByConsultCode", method = RequestMethod.GET)
//    @ApiOperation("根据咨询code查询关联业务项详情")
//    public String queryByConsultCode(@ApiParam(name = "code", value = "咨询code") @RequestParam(value = "code", required = true) String code,
//                                     @ApiParam(name = "type", value = "咨询类型") @RequestParam(value = "type", required = true) Integer type) {
//        try {
//            com.alibaba.fastjson.JSONObject detail = consultTeamService.queryByConsultCode(code, type);
//            return write(200, "查询成功", "data", detail.get("data"));
//        } catch (Exception e) {
//            error(e);
//            return error(-1, "查询失败");
//        }
//    }
    @RequestMapping(value = "queryByConsultCode", method = RequestMethod.GET)
    @ApiOperation("根据咨询code查询关联业务项详情")
    public String queryByConsultCode(@ApiParam(name = "code", value = "咨询code") @RequestParam(value = "code", required = true) String code,
                                     @ApiParam(name = "type", value = "咨询类型") @RequestParam(value = "type", required = true) Integer type) {
        try {
            com.alibaba.fastjson.JSONObject detail = consultTeamService.queryByConsultCode(code, type);
            return write(200, "查询成功", "data", detail.get("data"));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "updateMsg", method = RequestMethod.POST)
    @ApiOperation("修改会话消息内容")

+ 1669 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/controller/DoctorConsultController.java

@ -0,0 +1,1669 @@
package com.yihu.jw.hospital.module.consult.controller;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.service.BaseDoctorInfoService;
import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.hospital.message.service.SystemMessageService;
import com.yihu.jw.hospital.module.consult.service.ConsultTeamService;
import com.yihu.jw.hospital.module.followup.service.FollowUpService;
import com.yihu.jw.hospital.module.wx.dao.WechatTemplateConfigDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
import com.yihu.jw.hospital.task.PushMsgTask;
import com.yihu.jw.hospital.utils.CommonUtil;
import com.yihu.jw.hospital.utils.DoctorAssistantUtil;
import com.yihu.jw.im.dao.ConsultDao;
import com.yihu.jw.im.util.HttpClientUtil;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * 医生端:三师咨询控制类
 *
 * @author George
 */
@RestController
@RequestMapping(value = "/doctor/consult", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "三师咨询")
public class DoctorConsultController extends EnvelopRestEndpoint {
    @Value("${doctorAssistant.api}")
    private String doctorAssistant;
    @Value("${doctorAssistant.target_url}")
    private String targetUrl;
    @Autowired
    private ConsultTeamService consultTeamService;
    @Autowired
    private BasePatientService patientService;
    @Autowired
    private BaseDoctorInfoService doctorInfoService;
    @Autowired
    private CommonUtil CommonUtil;
    @Autowired
    private ImUtil imUtill;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private PrescriptionDao prescriptionDao;
    @Autowired
    private ConsultDao consultDao;
    @Autowired
    private FollowUpService followUpService;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private SystemMessageService messageService;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private DoctorAssistantUtil doctorAssistantUtil;
    //    @Autowired
//    private DoctorHelpDao doctorHelpDao;
//    @Autowired
//    private HospitalInviteSpecialistDao inviteSpecialistDao;
//    @Autowired
//    private PrescriptionDiagnosisService prescriptionDiagnosisService;
//    @Autowired
//    private DoctorWorkTimeService doctorWorkTimeService;
//    @Autowired
//    private TalkGroupService talkGroupService;
//    @Autowired
//    private HttpClientUtil httpClientUtil;
    @RequestMapping(value = "queryByConsultCode", method = RequestMethod.GET)
    @ApiOperation("根据咨询code查询关联业务项详情")
    public String queryByConsultCode(@ApiParam(name = "code", value = "咨询code") @RequestParam(value = "code", required = true) String code,
                                     @ApiParam(name = "type", value = "咨询类型") @RequestParam(value = "type", required = true) Integer type) {
        try {
            com.alibaba.fastjson.JSONObject detail = consultTeamService.queryByConsultCode(code, type);
            return write(200, "查询成功", "data", detail.get("data"));
        } catch (Exception e) {
            return e.getMessage();
        }
    }
    @ApiOperation("咨询是否结束")
    @RequestMapping(value = "/getConsultStatus", method = RequestMethod.GET)
    public String getConsultStatus(@RequestParam(required = true) String consult) {
        try {
            ConsultTeamDo consultTeam = consultTeamService.findByConsultCode(consult);
            return write(200, "查询成功", "data", consultTeam.getStatus());
        } catch (Exception e) {
            return e.getMessage();
        }
    }
    @ApiOperation("咨询是否结束")
    @RequestMapping(value = "/getConsultStatusByPrescription", method = RequestMethod.GET)
    public String getConsultStatusByPrescription(@ApiParam(name = "prescriptionCode", value = "续方code")
                                                 @RequestParam(value = "prescriptionCode", required = true) String prescriptionCode) {
        try {
            ConsultTeamDo consultTeam = consultTeamService.getConsultStatus(prescriptionCode);
            if (consultTeam != null) {
                return write(200, "查询成功", "data", consultTeam.getStatus());
            } else {
                return error(-1, "咨询不存在");
            }
        } catch (Exception e) {
            return e.getMessage();
        }
    }
//
//    /**
//     * 设置消息已读
//     *
//     * @param consult
//     * @return
//     */
//    @ApiOperation("设置消息已读")
//    @RequestMapping(value = "/readed", method = RequestMethod.POST)
//    public String readMessage(String consult) {
//        try {
//            int result = consultTeamService.readMessage(consult);
//            return write(200, "设置成功!");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//
//    @ApiOperation("医生发送topic消息")
//    @RequestMapping(value = "sendTopicIM", method = RequestMethod.POST)
//    public String sendTopicIM(@ApiParam(name = "consult", value = "咨询code")
//                              @RequestParam(value = "consult", required = true) String consult,
//                              @ApiParam(name = "sender_id", value = "发送者id")
//                              @RequestParam(value = "sender_id", required = true) String sender_id,
//                              @ApiParam(name = "sender_name", value = "发送者姓名")
//                              @RequestParam(value = "sender_name", required = true) String sender_name,
//                              @ApiParam(name = "content_type", value = "消息类型")
//                              @RequestParam(value = "content_type", required = true) String content_type,
//                              @ApiParam(name = "content", value = "消息内容")
//                              @RequestParam(value = "content", required = true) String content,
//                              @ApiParam(name = "sessionId", value = "会话id")
//                              @RequestParam(value = "sessionId", required = true) String sessionId) {
//        try {
//            imUtill.sendTopicIM(sender_id, sender_name, consult, content_type, content, null);
//            return success("发送成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return error(-1, "发送失败");
//    }
//
//    @ApiOperation("医生发送会话消息")
//    @RequestMapping(value = "sendImMsg", method = RequestMethod.POST)
//    public String sendImMsg(@ApiParam(name = "consult", value = "咨询code")
//                            @RequestParam(value = "consult", required = false) String consult,
//                            @ApiParam(name = "sender_id", value = "发送者id")
//                            @RequestParam(value = "sender_id", required = true) String sender_id,
//                            @ApiParam(name = "sender_name", value = "发送者姓名")
//                            @RequestParam(value = "sender_name", required = true) String sender_name,
//                            @ApiParam(name = "content_type", value = "消息类型")
//                            @RequestParam(value = "content_type", required = true) String content_type,
//                            @ApiParam(name = "business_type", value = "会话业务类型")
//                            @RequestParam(value = "business_type", required = true) String business_type,
//                            @ApiParam(name = "content", value = "消息内容")
//                            @RequestParam(value = "content", required = true) String content,
//                            @ApiParam(name = "sessionId", value = "会话id")
//                            @RequestParam(value = "sessionId", required = true) String sessionId) {
//        try {
//            imUtill.sendImMsg(sender_id, sender_name, sessionId, content_type, content_type, business_type);
//            return success("发送成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return error(-1, "发送失败");
//    }
//
//    @ApiOperation("医生主动发送im消息")
//    @RequestMapping(value = "doctorSendImMsg", method = RequestMethod.POST)
//    public String doctorSendImMsg(@ApiParam(name = "patient", value = "居民code")
//                                  @RequestParam(value = "patient", required = true) String patient,
//                                  @ApiParam(name = "doctor", value = "医生code")
//                                  @RequestParam(value = "doctor", required = true) String doctor,
//                                  @ApiParam(name = "doctorName", value = "医生姓名")
//                                  @RequestParam(value = "doctorName", required = true) String doctorName,
//                                  @ApiParam(name = "sessionId", value = "会话id")
//                                  @RequestParam(value = "sessionId", required = true) String sessionId,
//                                  @ApiParam(name = "content", value = "消息内容")
//                                  @RequestParam(value = "content", required = true) String content,
//                                  @ApiParam(name = "contentType", value = "消息类型")
//                                  @RequestParam(value = "contentType", required = true) String contentType) {
//        try {
//            consultTeamService.doctorSendImMsg(patient, doctor, doctorName, sessionId, content, contentType);
//            return success("发送成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return error(-1, "发送失败");
//        }
//    }
//
//    @ApiOperation("医生拒绝视频")
//    @RequestMapping(value = "refuseVideo", method = RequestMethod.POST)
//    public String refuseVideo(@ApiParam(name = "consult", value = "咨询code")
//                              @RequestParam(value = "consult", required = true) String consult,
//                              @ApiParam(name = "doctor", value = "医生code")
//                              @RequestParam(value = "doctor", required = true) String doctor) {
//        try {
//            Doctor d = doctorDao.findByCode(doctor);
//            d.setVideoStauts(0);
//            doctorDao.save(d);
//            imUtill.sendTopicIM(doctor, d.getName(), consult, "43", "医生在忙,建议提现预约视频通讯", null);
//            return success("拒绝成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//
//    }
//
//    @ApiOperation("医生接通视频")
//    @RequestMapping(value = "connectVideo", method = RequestMethod.POST)
//    public String connectVideo() {
//        try {
//            Doctor doctor = doctorDao.findByCode(getUID());
//            doctor.setVideoStauts(1);
//            doctorDao.save(doctor);
//            return success("接通成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//
//    }
//
//    @ApiOperation("医生挂断视频")
//    @RequestMapping(value = "handUpVideo", method = RequestMethod.POST)
//    public String handUpVideo(@ApiParam(name = "consult", value = "咨询code")
//                              @RequestParam(value = "consult", required = true) String consult,
//                              @ApiParam(name = "time", value = "视频接通时长")
//                              @RequestParam(value = "time", required = true) String time) {
//        try {
//            Doctor doctor = doctorDao.findByCode(getUID());
//            doctor.setVideoStauts(0);
//            doctorDao.save(doctor);
//            imUtill.sendTopicIM(doctor.getCode(), doctor.getName(), consult, "41", time, null);
//            return success("挂断成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//
//    }
//
//    /**
//     * 三师咨询列表查询
//     *
//     * @param type     咨询类型:0、全部,1、咨询我的,2、公共的, 3、参与过的,4、已结束的  5 名医咨询 全部
//     *                 6 名医咨询 进行中 7 名医咨询 已结束 8名医咨询 待处理 9咨询我的三师 + 家庭 + 名医   10查询我咨询的
//     * @param id
//     * @param pagesize 每页显示数,默认为10
//     * @return
//     */
//    @ApiOperation("三师咨询列表查询")
//    @RequestMapping(value = "list", method = RequestMethod.POST)
//    public String list(int type,
//                       int id,
//                       int pagesize,
//                       @RequestParam(required = false) String patient,
//                       @RequestParam(required = false) String title) {
//        try {
//            Page<ConsultTeamDo> list = consultTeamService.findByDoctor(getUID(), type, id, pagesize, patient, title);
//            JSONArray jsonArray = new JSONArray();
//            if (list != null) {
//                for (ConsultTeamDo consult : list) {
//                    if (consult == null) {
//                        continue;
//                    }
//
//                    if (StringUtils.isNotBlank(patient) && !StringUtils.equals(patient, consult.getPatient())) {
//                        continue;
//                    }
//
//                    JSONObject json = new JSONObject();
//                    json.put("id", consult.getId());
//                    // 设置咨询标识
//                    json.put("consult", consult.getConsult());
//                    // 设置患者标识
//                    json.put("patient", consult.getPatient());
//                    // 设置患者姓名
//                    json.put("name", consult.getName());
//                    // 设置醫生标识
//                    json.put("doctor", consult.getDoctor());
//                    Doctor doctor = doctorService.findDoctorByCode(consult.getDoctor());
//                    // 设置醫生标识
//                    json.put("doctorName", doctor.getName());
//                    // 设置医生photo
//                    json.put("doctorPhoto", doctor.getPhoto());
//                    // 设置医生sex
//                    json.put("doctorSex", doctor.getSex());
//                    if (consult.getType() == 7) {
//                        Doctor d = doctorInfoService.findDoctorByCode(consult.getPatient());
//                        // 设置患者头像
//                        json.put("photo", d.getPhoto());
//                        // 设置患者年龄
//                        json.put("age", IdCardUtil.getAgeForIdcard(d.getIdcard()));
//                        // 设置性别
//                        json.put("sex", d.getSex());
//                    } else {
//                        Patient p = patientService.findByCode(consult.getPatient());
//                        // 设置患者头像
//                        json.put("photo", p.getPhoto());
//                        // 设置患者年龄
//                        json.put("age", IdCardUtil.getAgeByIdcardOrBirthday(p.getIdcard(), p.getBirthday()));
//                        // 设置性别
//                        json.put("sex", p.getSex());
//                    }
//                    // 设置咨询标识
//                    json.put("title", consult.getSymptoms());
//                    // 设置评价内容
//                    json.put("comment", consult.getCommentContent());
//                    // 设置评价星级
//                    json.put("star", consult.getCommentStar());
//                    // 设置咨询类型:1三师咨询,2家庭医生咨询 6名医咨询
//                    json.put("type", consult.getType());
//                    // 设置咨询时间
//                    json.put("time", DateUtil.dateToStr(consult.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
//                    // 咨询状态
//                    json.put("status", consult.getStatus());
//                    // 未读消息
//                    json.put("doctorRead", consult.getDoctorRead());
//                    // 设置关联指导
//                    json.put("guidance", consult.getGuidance());
//                    json.put("startId", consult.getStartMsgId());
//                    json.put("endId", consult.getEndMsgId());
//                    List<WlyyTalkGroup> wlyyTalkGroups = talkGroupService.findAllConsultTalkGroup(consult.getConsult());
//                    if (wlyyTalkGroups != null && wlyyTalkGroups.size() > 0) {
//                        for (WlyyTalkGroup wlyyTalkGroup : wlyyTalkGroups) {
//                            json.put("group" + wlyyTalkGroup.getType(), wlyyTalkGroup.getCode());
//                            json.put("groupName" + wlyyTalkGroup.getType(), wlyyTalkGroup.getName());
//                        }
//                    }
//                    jsonArray.put(json);
//                }
//            }
//            return write(200, "查询成功", "list", list, jsonArray);
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
//
//
//    @RequestMapping(value = "list_by_team", method = RequestMethod.POST)
//    @ApiOperation(value = "居民咨询列表查询")
//    public String listByTeam(@RequestParam @ApiParam(value = "居民Code") String patient,
//                             @RequestParam @ApiParam(value = "团队Code") Long teamCode,
//                             @RequestParam @ApiParam(value = "第几页") int page,
//                             @RequestParam @ApiParam(value = "页大小") int pagesize) {
//        try {
//            if (StringUtils.isEmpty(patient)) {
//                return error(-1, "请输入需查询的居民");
//            }
//            if (teamCode == null || teamCode < 1) {
//                return error(-1, "请输入需查询的居民的团队");
//            }
//            page = page > 0 ? page - 1 : 0;
//            JSONArray jsonArray = consultTeamService.findByPatientAndTeam(patient, teamCode, page, pagesize);
//            return write(200, "查询成功", "data", jsonArray);
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
//
//    /**
//     * 获取三师家庭咨询
//     *
//     * @param status   0未处理或未回复 1已回复 2已结束
//     * @param id
//     * @param pagesize
//     * @param patient
//     * @return
//     */
//    @ApiOperation("获取三师家庭咨询")
//    @RequestMapping(value = "/list_by_status", method = RequestMethod.POST)
//    public String listByStatus(int status, int id, int pagesize,
//                               @RequestParam(required = false) String patient) {
//        try {
//            Page<ConsultTeamDo> list = consultTeamService.findConsultByDoctor(getUID(), status, id, pagesize);
//            JSONArray jsonArray = new JSONArray();
//            for (ConsultTeamDo consult : list) {
//                if (consult == null) {
//                    continue;
//                }
//
//                if (StringUtils.isNotBlank(patient) && !StringUtils.equals(patient, consult.getPatient())) {
//                    continue;
//                }
//
//                Patient p = patientService.findByCode(consult.getPatient());
//
//                JSONObject json = new JSONObject();
//                json.put("id", consult.getId());
//                // 设置咨询标识
//                json.put("consult", consult.getConsult());
//                // 设置患者标识
//                json.put("patient", consult.getPatient());
//                // 设置患者头像
//                json.put("photo", p.getPhoto());
//                // 设置咨询标识
//                json.put("title", consult.getSymptoms());
//                // 设置患者姓名
//                json.put("name", consult.getName());
//                // 设置患者年龄
//                json.put("age", IdCardUtil.getAgeByIdcardOrBirthday(p.getIdcard(), p.getBirthday()));
//                // 设置评价内容
//                json.put("comment", consult.getCommentContent());
//                // 设置评价星级
//                json.put("star", consult.getCommentStar());
//                // 设置咨询类型:1三师咨询,2家庭医生咨询 6名医咨询
//                json.put("type", consult.getType());
//                // 设置咨询时间
//                json.put("time", DateUtil.dateToStr(consult.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
//                // 咨询状态
//                json.put("status", consult.getStatus());
//                json.put("doctor", consult.getDoctor());
//                json.put("doctorName", consult.getDoctorName());
//                // 设置性别
//                json.put("sex", p.getSex());
//                // 未读消息
//                json.put("doctorRead", consult.getDoctorRead());
//                // 设置关联指导
//                json.put("guidance", consult.getGuidance());
//                json.put("startId", consult.getStartMsgId());
//                json.put("endId", consult.getEndMsgId());
//                List<WlyyTalkGroup> wlyyTalkGroups = talkGroupService.findAllConsultTalkGroup(consult.getConsult());
//                if (wlyyTalkGroups != null && wlyyTalkGroups.size() > 0) {
//                    for (WlyyTalkGroup wlyyTalkGroup : wlyyTalkGroups) {
//                        json.put("group" + wlyyTalkGroup.getType(), wlyyTalkGroup.getCode());
//                        json.put("groupName" + wlyyTalkGroup.getType(), wlyyTalkGroup.getName());
//                    }
//                }
//                jsonArray.put(json);
//            }
//            return write(200, "查询成功", "list", jsonArray);
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
//
//    @RequestMapping(value = "/hasTnvite", method = RequestMethod.POST)
//    public String hasTnvite(String groupCode) {
//        try {
//            JSONObject jo = new JSONObject();
//            List<WlyyTalkGroupMember> wlyyTalkGroupMembers = talkGroupService.findTalkGroupMembers(groupCode);
//            if (wlyyTalkGroupMembers.size() > 2) {
//                jo.put("hasTnvite", 1);//有邀请
//            } else {
//                jo.put("hasTnvite", 0);//没邀请
//            }
//            return write(200, "查询成功", "list", jo);
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
//
//    /**
//     * 名医列表
//     *
//     * @return
//     */
//    @ApiOperation("名医列表")
//    @RequestMapping(value = "famousDoctorList", method = RequestMethod.POST)
//    public String famousDoctorList(
//            @RequestParam(required = false) String name) {
//        try {
//            JSONArray array = new JSONArray();
//            List<Doctor> list = doctorService.getDoctorFamousDoctorList(name);
//            if (list != null) {
//                for (Doctor doctor : list) {
//                    if (doctor == null) {
//                        continue;
//                    }
//                    // 过滤掉自己
//                    if (doctor.getCode().equals(getUID())) {
//                        continue;
//                    }
//
//                    // 判断名医是否在工作
//                    JSONObject isWorking = doctorWorkTimeService.isDoctorWorking(doctor.getCode());
//
//                    if (isWorking == null || !isWorking.getString("status").equals("1")) {
//                        continue;
//                    }
//
//                    JSONObject json = new JSONObject();
//                    json.put("id", doctor.getId());
//                    // 医生标识
//                    json.put("code", doctor.getCode());
//                    // 医生性别
//                    json.put("sex", doctor.getSex());
//                    // 医生姓名
//                    json.put("name", doctor.getName());
//                    // 类别
//                    json.put("level", doctor.getLevel());
//                    // 所在医院名称
//                    json.put("hospital", doctor.getHospital());
//                    // 所在医院名称
//                    json.put("hospital_name", doctor.getHospitalName());
//                    // 科室名称
//                    json.put("dept_name", (doctor.getDeptName() == null ||
//                            StringUtils.isEmpty(doctor.getDeptName().toString())) ? " " : doctor.getDeptName());
//                    // 职称名称
//                    json.put("job_name", (doctor.getJobName() == null ||
//                            StringUtils.isEmpty(doctor.getJobName().toString())) ? " " : doctor.getJobName());
//                    // 头像
//                    json.put("photo", doctor.getPhoto());
//                    // 简介
//                    json.put("introduce", doctor.getIntroduce());
//                    // 专长
//                    json.put("expertise", doctor.getExpertise());
//                    array.put(json);
//                }
//            }
//            return write(200, "获取医院医生列表成功!", "list", array);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 获取咨询全科医生签约量
//     *
//     * @param consults
//     * @return
//     */
//    @ApiOperation("获取咨询全科医生签约量")
//    @RequestMapping(value = "/consult_sign", method = RequestMethod.POST)
//    public String consultSign(String consults) {
//        try {
//            List<Map<String, Object>> list = consultTeamService.getConsultSign(consults.split(","));
//            return write(200, "查询成功", "data", new JSONArray(list));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 结束三师咨询接口
//     *
//     * @param consult 三师咨询标识
//     * @return
//     */
//    @ApiOperation("结束三师咨询接口")
//    @RequestMapping(value = "finish", method = RequestMethod.POST)
//
//    public String finish(String consult) {
//        try {
//            int flag = consultTeamService.finish(consult, getUID(), 2);
//            if (flag > 0) {
//                return success("咨询已关闭");
//            } else if (flag == -2) {
//                return error(-1, "续方未审核,不能结束续方咨询!");
//            } else {
//                return error(-1, "关闭失败!");
//            }
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "关闭失败!");
//        }
//    }
//
//
//    /**
//     * 医生咨询咨询日志查询
//     *
//     * @param consult  咨询标识
//     * @param patient  患者标识
//     * @param pagesize 每页显示数,默认为10
//     * @return
//     */
//    @ApiOperation("医生咨询咨询日志查询")
//    @RequestMapping(value = "record", method = RequestMethod.POST)
//    public String record(String consult, String patient, long id, int pagesize) {
//        try {
//            Patient patientTemp = null;
//            if (id <= 0) {
//                // 只有第一页才会查询患者信息
//                patientTemp = patientService.findByCode(patient);
//                // 更新医生未读数量为0
//                consultTeamService.clearDoctorRead(consult);
//            }
//            // 查询日志列表
//            JSONArray jsonArray = new JSONArray();
//            Page<ConsultTeamDoLog> list = consultTeamService.findLogByConsult(consult, id, pagesize);
//            if (list != null) {
//                for (ConsultTeamDoLog log : list) {
//                    if (consult == null) {
//                        continue;
//                    }
//                    JSONObject json = new JSONObject();
//                    json.put("id", log.getId());
//                    // 设置回复内容
//                    json.put("content", log.getContent());
//                    // 设置回复医生姓名
//                    json.put("doctorName", log.getDoctorName());
//                    // 设置回复人头像
//                    json.put("photo", log.getPhoto());
//                    // 设置日志类型
//                    json.put("type", log.getType());
//                    // 设置记录类型
//                    json.put("chatType", log.getChatType());
//                    // 设置咨询或回复时间
//                    json.put("time", DateUtil.dateToStr(log.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
//                    jsonArray.put(json);
//                }
//            }
//            // 设置返回结果
//            JSONObject values = new JSONObject();
//            if (patientTemp != null) {
//                JSONObject patientJson = new JSONObject();
//                // 设置患者标识
//                patientJson.put("patient", patientTemp.getCode());
//                // 设置姓名
//                patientJson.put("name", patientTemp.getName());
//                // 设置头像
//                patientJson.put("photo", patientTemp.getPhoto());
//                values.put("patient", patientJson);
//            }
//            values.put("list", jsonArray);
//            // 返回结果
//            return write(200, "查询成功", "data", values);
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
//
//    /**
//     * 医生回复网络咨询
//     *
//     * @param patient 患者标识
//     * @param consult 咨询标识
//     * @param content 回复内容
//     * @param type    回复类型,1文字,2图片,3语音
//     * @return
//     */
//    @ApiOperation("医生回复网络咨询")
//    @RequestMapping(value = "reply", method = RequestMethod.POST)
//    public String reply(String patient, String consult, String content, int type) {
//        try {
//            // 查询医生基本信息
//            Doctor doctor = doctorInfoService.findDoctorByCode(getUID());
//            if (doctor == null) {
//                return error(-1, "回复失败!");
//            } else {
//                ConsultTeamDoLog log = new ConsultTeamDoLog();
//                // 设置咨询标识
//                log.setConsult(consult);
//                // 拷贝图片
//                if (StringUtils.isNotEmpty(content)) {
//                    if (type == 3) {
//                        // 语音
//                        content = CommonUtil.copyTempVoice(content);
//                    } else if (type == 2) {
//                        // 图片
//                        content = CommonUtil.copyTempImage(content);
//                    }
//                }
//                // 设置回复内容
//                log.setContent(content);
//                log.setDel("1");
//                // 设置回复医生标识
//                log.setDoctor(doctor.getCode());
//                // 设置医生姓名
//                log.setDoctorName(doctor.getName());
//                // 设置医生头像
//                log.setPhoto(doctor.getPhoto());
//                // 设置咨询类型为医生回复
//                log.setType(1);
//                // 设置记录类型
//                log.setChatType(type);
//                // 保存医生回复内容
//                log = consultTeamService.reply(log, patient, getUID(), log.getType());
//                if (log == null) {
//                    return error(-1, "回复失败!");
//                } else {
//                    // 推送消息给患者
//                    // 推送消息给微信端
//                    ConsultTeamDo ct = consultTeamService.findByCode(consult);
//                    Patient p = patientService.findByCode(patient);
//                    if (ct != null && p != null && StringUtils.isNotEmpty(p.getOpenid())) {
//                        JSONObject json = new JSONObject();
//                        json.put("first", p.getName() + ",您好!\n您的健康咨询有新的回复");
//                        json.put("toUser", p.getCode());
//                        String symp = ct.getSymptoms();
//                        json.put("consultcontent", StringUtils.isNotEmpty(symp) && symp.length() > 50 ? (symp.substring(0, 50) + "...") : content);
//                        String replycontent = content.length() > 50 ? content.substring(0, 50) + "..." : content;
//                        if (type == 2) {
//                            replycontent = "[图片]";
//                        } else if (type == 3) {
//                            replycontent = "[语音]";
//                        }
//                        json.put("consult", consult);
//                        json.put("replycontent", replycontent);
//                        json.put("doctorName", doctor.getName());
//                        json.put("remark", "医生已为您提供问诊方案");
//                        // PushMsgTask.getInstance().putWxMsg(getAccessToken(), 3, p.getOpenid(), p.getName(), json);
//                    }
//                    if (type == 2) {
//                        return write(200, "回复成功!", "data", content);
//                    }
//                    return success("回复成功!");
//                }
//            }
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "回复失败!");
//        }
//    }
//
//    /**
//     * 查询医生的总咨询次数和今日咨询次数
//     *
//     * @param doctorCode
//     * @return
//     */
//    @ApiOperation("查询医生的总咨询次数和今日咨询次数")
//    @RequestMapping(value = "getConsultCount", method = RequestMethod.POST)
//    public String getAllCount(@RequestParam(required = true) String doctorCode) {
//        try {
//            JSONObject json = new JSONObject();
//            Map<String, Long> counts = consultTeamService.getAllCount(doctorCode);
//
//            json.put("all", counts.get("all"));
//            json.put("today", counts.get("today"));
//            return json.toString();
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 查询患者的服务数目
//     *
//     * @return
//     */
//    @ApiOperation("查询患者的服务数目")
//    @RequestMapping(value = "getPatientServicNum", method = RequestMethod.POST)
//    public String getPatientServicNum(String patientCode) {
//        try {
//            JSONObject json = new JSONObject();
//            //统计咨询数目
//            Integer allSize1 = consultTeamService.findByDoctorSize(patientCode, getUID());
//            //查询健康指导
//            Integer allSize2 = patientHealthGuidanceService.findGuidanceByPatient(patientCode, getUID());
//            json.put("consult", allSize1);
//            json.put("guide", allSize2);
//            //json.put("today", counts.get("today"));
//            return json.toString();
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 根据医生code和和患者code判断是否有存在进行中的咨询
//     *
//     * @param patientCode 多个患者 逗号分隔
//     * @param doctor
//     * @return 只返回存在咨询的患者的code
//     */
//    @ApiOperation("根据医生code和和患者code判断是否有存在进行中的咨询")
//    @RequestMapping(value = "getConsultByPatientAndDoctor", method = RequestMethod.POST)
//    public String getConsultByPatientAndDoctor(String patientCode, String doctor) {
//        try {
//            JSONArray json = new JSONArray();
//            String[] patients = patientCode.split(",");
//            //查询医生未结束居民列表
//            List<String> list = consultTeamService.getConsultListByPatientAndDoctor(doctor);
//            for (int i = 0; i < patients.length; i++) {
//                if (list.contains(patients[i])) {
//                    json.put(patients[i]);
//                }
//            }
//            return json.toString();
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 名医咨询添加接口
//     *
//     * @param when       发病时间
//     * @param symptoms   主要症状
//     * @param images     图片URL地址,多图以逗号分隔
//     * @param voice      语音URL地址
//     * @param doctorCode 名医的code
//     * @return
//     */
//    @ApiOperation("名医咨询添加接口")
//    @RequestMapping(value = "famousAdd", method = RequestMethod.POST)
//
//    public String famousAdd(
//            @RequestParam(required = false) String when,
//            String symptoms,
//            @RequestParam(required = false) String doctorCode,
//            @RequestParam(required = false) String images,
//            @RequestParam(required = false) String voice) {
//        try {
//            //判断医生是否是在工作时间
//            JSONObject jo = doctorWorkTimeService.isFamousDoctorWorking(doctorCode);
//            if (!jo.get("status").equals("1")) {
//                return error(-1, jo.get("msg").toString());
//            }
//            if (StringUtils.isEmpty(images)) {
//                images = fetchWxImages();
//                // 将临时图片拷贝到正式存储路径下
//                if (StringUtils.isNotEmpty(images)) {
//                    images = CommonUtil.copyTempImage(images);
//                }
//            }
//
//            if (StringUtils.isNotEmpty(voice)) {
//                voice = fetchWxVoices();
//            }
//            if (StringUtils.isNotEmpty(voice)) {
//                voice = CommonUtil.copyTempVoice(voice);
//            }
//
//            ConsultTeamDo consult = new ConsultTeamDo();
//            // 设置咨询类型:1三师咨询,2家庭医生咨询 6.患者发起名医咨询 7医生发起的名医咨询
//            consult.setType(7);
//            // 设置发病时间
//            consult.setWhen(when);
//            // 设置主要症状
//            consult.setSymptoms(symptoms);
//            // 设置咨询图片URL
//            consult.setImages(images);
//            // 设置咨询语音URL
//            consult.setVoice(voice);
//            consult.setDoctor(doctorCode);//设置专科医生
//            // 保存到数据库
//            JSONObject result = consultTeamService.famousConsult(consult, getUID(), "2", null);
//            // 推送消息给医生
//            pushMsgTask.put(consult.getDoctor(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.D_CT_04.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.名医咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.您有新的名医咨询.name(), consult.getConsult());
//            if (StringUtils.isNotEmpty(images)) {
//                String[] arr = images.split(",");
//                for (String img : arr) {
//                    pushMsgTask.put(consult.getDoctor(), "2", MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.名医咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.您有新的名医咨询.name(), img);
//                }
//            }
//            return write(200, "创建成功!", "data", result);
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, "提交失败!");
//        }
//    }
//
//    /**
//     * 查询与某个医生是否存在未结束的咨询
//     *
//     * @param doctor 医生
//     * @return
//     */
//    @ApiOperation("查询与某个医生是否存在未结束的咨询")
//    @RequestMapping(value = "/is_consult_unfinished", method = RequestMethod.POST)
//    public String isExistsUnfinishedConsult(@RequestParam(required = false) String patient,
//                                            @RequestParam(required = false) String type,
//                                            @RequestParam(required = true) String doctor) {
//        try {
//            if ("1".equals(type)) {
//                //专科
//                List<ConsultHelp> helps = consultTeamService.findUnfinishedByPatientAndSpecialist(patient, doctor);
//                if (helps.size() > 0) {
//                    return write(200, "查询成功", "data", helps.get(0).getConsult());
//                } else {
//                    return write(200, "查询成功", "data", "");
//                }
//            }
//            List<ConsultTeamDo> consults = consultTeamService.getUnfinishedConsult(StringUtils.isEmpty(patient) ? getUID() : patient, doctor);
//
//            if (consults != null && consults.size() > 0) {
//                return write(200, "查询成功", "data", consults.get(0).getConsult());
//            } else {
//                return write(200, "查询成功", "data", "");
//            }
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//
//    /**
//     * 查询与某个医生是否存在未结束的咨询
//     *
//     * @param consult 咨询code
//     * @return
//     */
//    @ApiOperation("查询与某个医生是否存在未结束的咨询")
//    @RequestMapping(value = "/consultTeam", method = RequestMethod.POST)
//    public String consult(@RequestParam(required = false) String consult) {
//        try {
//            ConsultTeamDo consultTeam = consultTeamService.findByCode(consult);
//            return write(200, "查询成功", "data", consultTeam);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//
//    /**
//     * 三师咨询转接接口
//     *
//     * @param consult 图咨询标识
//     * @param doctor  转接对象标识 健康管理师转全科是 1个    全科转专科是多个  传多个doctor逗号分隔
//     * @param type    转接对象类型,1三师团队,2指定医生,3工作组团队
//     * @return
//     */
//    @ApiOperation("三师咨询转接接口")
//    @RequestMapping(value = "transfer", method = RequestMethod.POST)
//
//    public String transfer(
//            String consult,
//            String doctor,
//            @RequestParam(required = false) int type) {
//        try {
//            consultTeamService.transfers(getUID(), doctor, consult);
//            return success("转接成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 根据咨询code获取咨询的log
//     *
//     * @param consultCode
//     * @return
//     */
//    @ApiOperation("根据咨询code获取咨询的log")
//    @RequestMapping(value = "getConsultLog", method = RequestMethod.POST)
//    public String getConsultLog(
//            String consultCode) {
//        try {
//            List<ConsultTeamDoLog> consultTeamLogs = consultTeamService.getConsultLog(consultCode);
//            JSONArray ja = new JSONArray();
//            for (ConsultTeamDoLog log : consultTeamLogs) {
//                JSONObject json = new JSONObject();
//                json.put("id", log.getId());
//                // 设置回复内容
//                json.put("content", log.getContent());
//                // 设置回复医生姓名
//                json.put("doctorName", log.getDoctorName());
//                // 设置回复人头像
//                json.put("photo", log.getPhoto());
//                // 设置日志类型
//                json.put("type", log.getType());
//                // 设置记录类型
//                json.put("chatType", log.getChatType());
//                // 设置咨询或回复时间
//                json.put("time", DateUtil.dateToStr(log.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
//                ja.put(json);
//            }
//            return write(200, "查询成功", "data", ja);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 医生求助添加接口
//     *
//     * @param when       发病时间
//     * @param symptoms   主要症状
//     * @param groupCode  从哪个讨论组发起的求助
//     * @param images     图片URL地址,多图以逗号分隔
//     * @param voice      语音URL地址
//     * @param doctorCode 名医的code
//     * @return
//     */
//    @ApiOperation("医生求助添加接口")
//    @RequestMapping(value = "forHelpAdd", method = RequestMethod.POST)
//
//    public String forHelpAdd(
//            @RequestParam(required = false) String when,
//            String symptoms,
//            @RequestParam(required = false) String oldConsultCode,
//            @RequestParam(required = false) String groupCode,
//            @RequestParam(required = false) String doctorCode,
//            @RequestParam(required = false) String images,
//            @RequestParam(required = false) String voice) {
//        try {
//            if (StringUtils.isEmpty(images)) {
//                images = fetchWxImages();
//                // 将临时图片拷贝到正式存储路径下
//                if (StringUtils.isNotEmpty(images)) {
//                    images = CommonUtil.copyTempImage(images);
//                }
//            }
//
//            if (StringUtils.isEmpty(voice)) {
//                voice = fetchWxVoices();
//            }
//            if (StringUtils.isNotEmpty(voice)) {
//                voice = CommonUtil.copyTempVoice(voice);
//            }
//
//            ConsultTeamDo consult = new ConsultTeamDo();
//            // 设置咨询类型:1三师咨询,2家庭医生咨询 6.患者发起名医咨询 7医生发起的名医咨询 10医生发起的求助
//            consult.setType(10);
//            // 设置来源(从哪个讨论组发起的求助)
//            consult.setTeam(groupCode);
//            // 设置发病时间
//            consult.setWhen(when);
//            // 设置主要症状
//            consult.setSymptoms(symptoms);
//            // 设置咨询图片URL
//            consult.setImages(images);
//            // 设置咨询语音URL
//            consult.setVoice(voice);
//
//            consult.setDoctor(doctorCode);//设置专科医生
//            // 保存到数据库
//            if (consultTeamService.isCommonTeam(doctorCode, getUID())) {
//                consultTeamService.sendForHelpMsg(consult, getUID(), oldConsultCode);
//            } else {
//                consultTeamService.addForHelpTeamConsult(consult, getUID(), oldConsultCode);
//            }
//            return success("提交成功");
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, "提交失败!");
//        }
//    }
//
//    @RequestMapping(value = "hasUnfinished", method = RequestMethod.POST)
//    public String hasUnfinished(String doctorCode) {
//        try {
//            String curDoc = getUID();
//            JSONObject json = new JSONObject();
//            if (consultTeamService.isCommonTeam(doctorCode, curDoc)) {
//                json.put("isCommonTeam", 1);
//                return write(200, "查询成功", "data", json);
//            }
//            List<ConsultTeamDo> ls = consultTeamService.hasUnfinished(doctorCode, curDoc);
//            if (ls != null && ls.size() > 0) {
//                ConsultTeamDo ct = ls.get(0);
//                json.put("consult", ct.getConsult());
//                //是否是医生求助医生
//                if (ct.getType() == 10) {
//                    //取出原有咨询求助返回原咨询的患者
//                    ConsultTeamDo consultTeam = consultTeamService.findByConsultCode(ct.getTeam());
//                    Patient patient = patientService.findByCode(consultTeam.getPatient());
//                    json.put("zxGroupCode", consultTeam.getPatient() + "_" + consultTeam.getTeam() + "_" + consultTeam.getType());
//                    json.put("from", ct.getPatient());
//                    json.put("patient_name", patient.getName());
//                }
//            }
//            return write(200, "查询成功", "data", json);
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, "查询失败!");
//        }
//    }
//
//    /**
//     * 该咨询求助过的医生列表
//     *
//     * @param consult 关联的上一个咨询
//     * @return
//     */
//    @ApiOperation("该咨询求助过的医生列表")
//    @RequestMapping(value = "forHelpDocs", method = RequestMethod.POST)
//    public String forHelpDocs(String consult) {
//        try {
//            List<String> ls = consultTeamService.findByTeam(consult);
//            JSONObject json = new JSONObject();
//            if (ls != null) {
//                for (String o : ls) {
//                    json.put(o, 1);
//                }
//            }
//            return write(200, "查询成功", "data", json);
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, "查询失败!");
//        }
//    }
//
//    @RequestMapping(value = "getConsult")
//    public String getConsult(String consult) {
//        try {
//            ConsultTeamDo consultTeam = consultTeamService.findByConsultCode(consult);
//            return write(200, "查询成功", "data", consultTeam);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "/isConsultFinished", method = RequestMethod.POST)
//    public String isConsultFinished(@RequestParam String consult) {
//        try {
//            ConsultTeamDo ct = consultTeamService.findByConsultCode(consult);
//            return write(200, "查询咨询状态成功", "data", ct.getStatus());
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "seekHelp", method = RequestMethod.POST)
//
//    public String seekHelp(
//            @RequestParam(required = true) String symptoms,
//            @RequestParam(required = false) String oldConsultCode,
//            @RequestParam(required = false) String doctorCode,
//            @RequestParam(required = false) String images,
//            @RequestParam(required = true) Integer isSend) {
//        try {
//            if (StringUtils.isEmpty(images)) {
//                images = fetchWxImages();
//                // 将临时图片拷贝到正式存储路径下
//                if (StringUtils.isNotEmpty(images)) {
//                    images = CommonUtil.copyTempImage(images);
//                }
//            }
//            ConsultTeamDo consult = new ConsultTeamDo();
//            // 设置咨询类型:1三师咨询,2家庭医生咨询 6.患者发起名医咨询 7医生发起的名医咨询 10医生发起的求助
//            consult.setType(10);
//            // 设置主要症状
//            consult.setSymptoms(symptoms);
//            // 设置咨询图片URL
//            consult.setImages(images);
//
//            consult.setDoctor(doctorCode);//设置专科医生
//            // 保存到数据库
//            if (consultTeamService.isCommonTeam(doctorCode, getUID())) {
//                consultTeamService.addSeekHelpTeam(consult, getUID(), oldConsultCode, isSend);
//            } else {
//                consultTeamService.addSeekHelpOtherTeam(consult, getUID(), oldConsultCode, isSend);
//            }
//            return success("提交成功");
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, "提交失败!");
//        }
//    }
//
//
//    /**
//     * 结束咨询接口
//     *
//     * @param consult 咨询标识
//     * @return
//     */
//    @ApiOperation("结束咨询接口")
//    @RequestMapping(value = "finish_consult", method = {RequestMethod.GET, RequestMethod.POST})
//
//    public String finishConsult(@RequestParam(required = false) String consult) {
//        try {
//            int flag = consultTeamService.finishConsult(consult, getUID(), 2);
//            if (flag > 0) {
//                return success("咨询已关闭");
//            } else if (flag == -1) {
//                return error(-1, "该咨询已经关闭,不需重复关闭!");
//            } else if (flag == -2) {
//                return error(-1, "续方未审核,不能结束续方咨询!");
//            } else {
//                return error(-1, "关闭失败!");
//            }
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "关闭失败!");
//        }
//    }
//
//
//    /**
//     * 网络咨询咨询日志查询
//     *
//     * @param consult  咨询标识
//     * @param pagesize 每页显示数,默认为10
//     * @return
//     */
//    @ApiOperation("网络咨询咨询日志查询")
//    @RequestMapping(value = "loglist", method = RequestMethod.GET)
//    public String loglist(@RequestParam String consult, @RequestParam int page, @RequestParam int pagesize) {
//        try {
//            ConsultTeamDo consultModel = consultTeamService.findByCode(consult);
//            if (consultModel == null) {
//                return error(-1, "咨询记录不存在!");
//            }
//            JSONObject messageObj = imUtill.getTopicMessage(consultModel.getConsult(), consultModel.getStartMsgId(), consultModel.getEndMsgId(), page, pagesize, getUID());
//            return write(200, "查询成功", "list", messageObj);
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
//
//    /*********************************************续方咨询**************************************************************/
//
//    @RequestMapping(value = "prescriptionDetail", method = RequestMethod.GET)
//    @ApiOperation("获取续方信息")
//    public String prescriptionDetail(@ApiParam(name = "consult", value = "咨询code", defaultValue = "1")
//                                     @RequestParam(value = "consult", required = true) String consult) {
//        try {
//            JSONObject json = new JSONObject();
//
//            Consult consult1 = consultDao.findByCode(consult);
//            String prescriptionCode = consult1.getRelationCode();
//            Prescription prescription = prescriptionDao.findByCode(prescriptionCode);
//            json.put("status", prescription.getStatus());//状态 (-1 审核不通过 , 0 审核中, 10 审核通过/待支付 ,21支付失败  20 配药中/支付成功, 21 等待领药 ,30 配送中 ,100配送成功/已完成)
//            json.put("prescriptionDt", prescriptionDiagnosisService.getPrescriptionDiagnosis(prescriptionCode));//续方疾病类型
//            json.put("prescriptionInfo", prescriptionDiagnosisService.getPrescriptionInfo(prescriptionCode));//续方药品信息
//            json.put("followup", followUpService.getFollowupByPrescriptionCode(prescriptionCode));//续方关联的随访记录
//
//            //服务类型
//            List<SignFamilyServer> list = signFamilyServerDao.findBySignCodeAndType(consult1.getSignCode());
//            JSONArray jsonArray = new JSONArray();
//            if (list != null && list.size() > 0) {
//                for (SignFamilyServer server : list) {
//                    JSONObject jsonObject = new JSONObject();
//                    jsonObject.put("serverType", server.getServerType());
//                    jsonObject.put("serverTypeName", server.getServerTypeName());
//                    jsonArray.put(jsonObject);
//                }
//            }
//            json.put("signFamilyServer", jsonArray);
//            json.put("symptoms", consult1.getSymptoms());//咨询类型--- 1高血压,2糖尿病
//            json.put("jwCode", prescription.getJwCode());//基位处方code
//            json.put("code", prescription.getCode());//续方code
//            json.put("viewJiancha", prescription.getViewJiancha());//检查
//            json.put("viewTizhen", prescription.getViewTizhen());//体征
//            json.put("viewChufang", prescription.getViewChufang());//处方
//            json.put("viewXufang", prescription.getViewXufang());//续方
//            json.put("viewWenjuan", prescription.getViewWenjuan());//问卷
//            json.put("viewSuifang", prescription.getViewSuifang());//随访
//
//            return write(200, "查询成功!", "data", json);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "addPrescriptionBloodStatusConsult", method = RequestMethod.POST)
//
//    @ApiOperation("续方咨询-医生发送血糖血压快捷回复咨询")
//    public String addPrescriptionBloodStatusConsult(
//            @ApiParam(name = "prescriptionCode", value = "处方code", defaultValue = "")
//            @RequestParam(value = "prescriptionCode", required = true) String prescriptionCode,
//            @ApiParam(name = "type", value = "类型(1血压,2血糖)", defaultValue = "")
//            @RequestParam(value = "type", required = true) String type,
//            @ApiParam(name = "followupid", value = "随访记录ID", defaultValue = "")
//            @RequestParam(value = "followupid", required = true) String followupid) {
//        try {
//            consultTeamService.addPrescriptionBloodStatusConsult(prescriptionCode, type, followupid);
//            return write(200, "添加成功!");
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "addPrescriptionFollowupContentConsult", method = RequestMethod.POST)
//
//    @ApiOperation("续方咨询-医生发送问卷快捷回复咨询")
//    public String addPrescriptionFollowupContentConsult(
//            @ApiParam(name = "prescriptionCode", value = "处方code", defaultValue = "")
//            @RequestParam(value = "prescriptionCode", required = true) String prescriptionCode,
//            @ApiParam(name = "type", value = "类型(1症状,2体征及生活方式)", defaultValue = "")
//            @RequestParam(value = "type", required = true) String type,
//            @ApiParam(name = "followupid", value = "随访记录ID", defaultValue = "")
//            @RequestParam(value = "followupid", required = true) String followupid) {
//        try {
//            consultTeamService.addPrescriptionFollowupContentConsult(prescriptionCode, type, followupid);
//            return write(200, "添加成功!");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "getSessionId", method = RequestMethod.GET)
//    @ApiOperation("pcim-获取居民的sessionId")
//    public String getSessionId(@ApiParam(name = "patient", value = "居民code", defaultValue = "")
//                               @RequestParam(value = "patient", required = true) String patient) {
//        try {
//            com.alibaba.fastjson.JSONObject re = consultTeamService.getSessionId(patient);
//            return write(200, "获取成功!", "data", re);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "sendBusinessCard", method = RequestMethod.POST)
//    @ApiOperation("发送居民的名片")
//
//    public String sendBusinessCard(@ApiParam(name = "patient", value = "居民code", defaultValue = "")
//                                   @RequestParam(value = "patient", required = true) String patient,
//                                   @ApiParam(name = "sessionId", value = "会话id", defaultValue = "")
//                                   @RequestParam(value = "sessionId", required = true) String sessionId,
//                                   @ApiParam(name = "businessType", value = "businessType", defaultValue = "1")
//                                   @RequestParam(value = "businessType", required = true) String businessType) {
//        try {
//            String doctorCode = getUID();
//            Doctor doctor = doctorService.findDoctorByCode(doctorCode);
//
//            Patient p = patientService.findByCode(patient);
//            com.alibaba.fastjson.JSONObject content = new com.alibaba.fastjson.JSONObject();
//            content.put("name", p.getName());
//            content.put("patient", patient);
//            content.put("photo", p.getPhoto());
//            content.put("age", IdCardUtil.getAgeByIdcardOrBirthday(p.getIdcard(), p.getBirthday()));
//            content.put("sex", IdCardUtil.getSexForIdcard_new(p.getIdcard()));
//            SignFamily signFamily = signFamilyDao.findByPatient(patient);
//            if (signFamily != null) {
//                content.put("hospitalName", signFamily.getHospitalName());
//            }
//            imUtill.sendImMsg(doctorCode, doctor.getName(), sessionId, ImUtill.ContentType.personalCard.getValue(), content.toString(), businessType);
//            return success("发送成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "messageForward", method = RequestMethod.POST)
//    @ApiOperation("请求转发消息")
//    public String messageForward(@ApiParam(name = "senderId", value = "发送者id", defaultValue = "")
//                                 @RequestParam(value = "senderId", required = true) String senderId,
//                                 @ApiParam(name = "senderName", value = "发送者姓名", defaultValue = "")
//                                 @RequestParam(value = "senderName", required = true) String senderName,
//                                 @ApiParam(name = "sessionId", value = "会话id", defaultValue = "")
//                                 @RequestParam(value = "sessionId", required = true) String sessionId,
//                                 @ApiParam(name = "content", value = "会话内容", defaultValue = "")
//                                 @RequestParam(value = "content", required = true) String content,
//                                 @ApiParam(name = "title", value = "会话标题", defaultValue = "")
//                                 @RequestParam(value = "title", required = true) String title,
//                                 @ApiParam(name = "sessionType", value = "原会话的会话类型", defaultValue = "")
//                                 @RequestParam(value = "sessionType", required = true) String sessionType,
//                                 @ApiParam(name = "businessType", value = "businessType", defaultValue = "1")
//                                 @RequestParam(value = "businessType", required = true) String businessType) {
//        try {
//            String message = consultTeamService.getMessageById(sessionType, content, title);
//            imUtill.sendImMsg(senderId, senderName, sessionId, ImUtill.ContentType.messageForward.getValue(), message, businessType);
//            return success("发送成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "examinationDetail", method = RequestMethod.GET)
//    @ApiOperation("获取在线复诊信息")
//    public String examinationDetail(@ApiParam(name = "consult", value = "咨询code", defaultValue = "1")
//                                    @RequestParam(value = "consult", required = true) String consult) {
//        try {
//            JSONObject json = new JSONObject();
//
//            Consult consult1 = consultDao.findByCode(consult);
//            String examinationCode = consult1.getRelationCode();
//            Examination examination = examinationDao.findByCode(examinationCode);
//            json.put("status", examination.getStatus());//状态 (-1 审核不通过 , 0 审核中, 10 审核通过/待支付 ,21支付失败  20 配药中/支付成功, 21 等待领药 ,30 配送中 ,100配送成功/已完成)
//            json.put("examinationDt", examination.getAdjustReason());//续方疾病类型
//
//            json.put("symptoms", consult1.getSymptoms());//咨询类型--- 1高血压,2糖尿病
//            json.put("visitNo", examination.getVisitNo());//基位处方code
//            json.put("code", examination.getCode());//续方code
//
//            return write(200, "查询成功!", "data", json);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "updateConsultParticipant", method = RequestMethod.POST)
//    @ApiOperation("更新会话成员(新增或删除)")
//
//    public String updateConsultParticipant(@ApiParam(name = "sessionid", value = "会话ID", defaultValue = "1")
//                                           @RequestParam(value = "sessionid", required = true) String sessionid,
//                                           @ApiParam(name = "userid", value = "新增成员ID,多个以英文逗号隔开", defaultValue = "1")
//                                           @RequestParam(value = "userid", required = true) String userid,
//                                           @ApiParam(name = "olduserid", value = "删除的成员id")
//                                           @RequestParam(value = "olduserid", required = false) String olduserid) {
//        try {
//            imUtill.updateParticipant(sessionid, userid, olduserid);
//            return write(200, "操作成功!");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "inviteDoctor", method = RequestMethod.POST)
//    @ApiOperation("邀请医生回复居民问题")
//
//    public String inviteDoctor(@ApiParam(name = "sessionid", value = "会话ID")
//                               @RequestParam(value = "sessionid", required = true) String sessionid,
//                               @ApiParam(name = "doctor", value = "被邀请人")
//                               @RequestParam(value = "doctor", required = true) String doctor,
//                               @ApiParam(name = "topic", value = "咨询id")
//                               @RequestParam(value = "topic", required = true) String topic) {
//        try {
//            String uid = getUID();
//            imUtill.updateParticipant(sessionid, doctor, null);
//            //设置邀请消息
//            Doctor from = doctorDao.findByCode(uid);
//            Doctor d = doctorDao.findByCode(doctor);
//            String content = "已邀请" + d.getName() + "医生为您服务,请耐心等待";
//            imUtill.sendTopicIM(from.getCode(), from.getName(), topic, "1", content, null);
//            //发送邀请医生提醒消息
////            if(StringUtils.isNotEmpty(d.getOpenid())){
////                String first = from.getName()+"医生邀请您,为";
////                doctorAssistantUtil.sendWXTemplate(1,d.getOpenid(),d.getCid(),"咨询邀请回复","","");
////            }
//            return write(200, "操作成功!");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "askSpecialist", method = RequestMethod.POST)
//    @ApiOperation("邀请专科-回复居民咨询")
//
//    public String askSpecialist(@ApiParam(name = "sessionid", value = "会话ID")
//                                @RequestParam(value = "sessionid", required = true) String sessionid,
//                                @ApiParam(name = "doctor", value = "被邀请人")
//                                @RequestParam(value = "doctor", required = true) String doctor,
//                                @ApiParam(name = "topic", value = "咨询id")
//                                @RequestParam(value = "topic", required = true) String topic) {
//        try {
//            consultTeamService.askSpecialist(topic, sessionid, getUID(), doctor);
//            return write(200, "操作成功!");
//        } catch (ServiceException se) {
//            return error(-1, se.getMessage());
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 家庭医生发起康复咨询
//     *
//     * @param when              发病时间
//     * @param oldConsultCode    从哪个讨论组发起的求助
//     * @param specialDoctorCode 专科医生
//     * @param specialDoctorCode 全科医生
//     * @param images            图片URL地址,多图以逗号分隔
//     * @param voice             语音URL地址
//     * @param doctorCode        名医的code
//     * @return
//     */
//    @ApiOperation("医生求助添加接口")
//    @RequestMapping(value = "forSpecialAdd", method = RequestMethod.POST)
//
//    public String forSpecialAdd(
//            @RequestParam(required = false) String when,
//            @RequestParam(required = false) String oldConsultCode,
//            @RequestParam(required = false) String specialDoctorCode,
//            @RequestParam(required = false) String doctorCode,
//            @RequestParam(required = false) String patientCode,
//            @RequestParam(required = false) String images,
//            @RequestParam(required = false) String voice) {
//        try {
//            String symptoms = "";
//            if (StringUtils.isNoneBlank(oldConsultCode)) {
//                Consult consult = consultDao.findByCode(oldConsultCode);
//                symptoms = consult.getSymptoms();
//            }
//
//            if (StringUtils.isEmpty(images)) {
//                images = fetchWxImages();
//            }
//            // 将临时图片拷贝到正式存储路径下
//            if (StringUtils.isNotEmpty(images)) {
//                images = CommonUtil.copyTempImage(images);
//            }
//            if (StringUtils.isEmpty(voice)) {
//                voice = fetchWxVoices();
//            }
//            if (StringUtils.isNotEmpty(voice)) {
//                voice = CommonUtil.copyTempVoice(voice);
//            }
//            ConsultTeamDo consult = new ConsultTeamDo();
//            // 设置咨询类型:1三师咨询,2家庭医生咨询  6.名医咨询   18.康复咨询
//            consult.setType(18);
//            // 设置发病时间
//            consult.setWhen(when);
//            // 设置主要症状
//            consult.setSymptoms(symptoms);
//            // 设置咨询图片URL
//            consult.setImages(images);
//            // 设置咨询语音URL
//            consult.setVoice(voice);
//
//            consult.setIsAuthentication(0);
//            consult.setIsRefinement(0);
//            // 保存到数据库
//            int res = 0;
//            JSONArray dts = null;
//            synchronized (getRepUID().intern()) {//新增同步方法。设备保存写在service层但是不生效,写在controller层才生效
//                JSONObject re = consultTeamService.addTeamSpecialConsult(consult, patientCode, getUID(), specialDoctorCode, doctorCode);
//                res = re.getInt("status");
//                dts = re.has("doctor") ? re.getJSONArray("doctor") : null;
//            }
//            if (res == -1) {
//                return error(-1, "家庭签约信息不存在或已过期,无法进行家庭医生咨询!");
//            } else if (res == -2) {
//                return error(-1, "家庭签约信息不存在或已过期,无法进行三师医生咨询!");
//            } else if (res == -3) {
//                return error(-1, "还有咨询未结束,不允许再次提交咨询!");
//            }
//            Boolean flag = messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue());
//            if (flag) {
//                pushMsgTask.put(specialDoctorCode, 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());
//                Doctor doctor = doctorDao.findByCode(specialDoctorCode);
//                if (doctor != null && StringUtils.isNotEmpty(doctor.getOpenid())) {
//                    String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
//                    List<NameValuePair> params = new ArrayList<>();
//                    params.add(new BasicNameValuePair("type", "4"));
//                    params.add(new BasicNameValuePair("openId", doctor.getOpenid()));
//                    params.add(new BasicNameValuePair("url", targetUrl));
//                    params.add(new BasicNameValuePair("first", doctor.getName() + "医生您好,有患者向您发起咨询"));
//                    params.add(new BasicNameValuePair("remark", "【" + consult.getSymptoms() + "】\r\n请进入手机APP查看"));
//                    String sex = consult.getSex() == 1 ? "男" : "女";
//                    String keywords = consult.getName() + "," + sex;
//                    params.add(new BasicNameValuePair("keywords", keywords));
//
//                    httpClientUtil.post(url, params, "UTF-8");
//                }
//            }
////                }
////            }
//
//            BusinessLogs.info(BusinessLogs.BusinessType.consult, getRepUID(), getUID(), new JSONObject(consult));
//            return write(200, "提交成功", "data", consult);
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, "提交失败!");
//        }
//    }
//
//    @RequestMapping(value = "getKangFuConsultList", method = RequestMethod.GET)
//    @ApiOperation("获取续方咨询列表")
//    public String getKangFuConsultList(@ApiParam(name = "title", value = "咨询标题") @RequestParam(required = false) String title,
//                                       @ApiParam(name = "patient", value = "居民CODE") @RequestParam(required = false) String patient,
//                                       @ApiParam(name = "id", value = "第几页") @RequestParam(required = true) long id,
//                                       @ApiParam(name = "pagesize", value = "页面大小") @RequestParam(required = true) int pagesize) {
//        try {
//            JSONArray array = new JSONArray();
//            Page<Object> data = consultTeamService.findConsultRecordByType(patient, id, pagesize, 18, title);//18表示康复咨询
//            Patient patientobj = patientService.findByCode(patient);
//            if (data != null) {
//                for (Object consult : data.getContent()) {
//                    if (consult == null) {
//                        continue;
//                    }
//                    Object[] result = (Object[]) consult;
//                    JSONObject json = new JSONObject();
//                    json.put("id", result[0]);
//                    // 设置咨询类型:1三师咨询,2视频咨询,3图文咨询,4公共咨询,5病友圈,8 续方咨询  18康复咨询
//                    json.put("type", result[1]);
//                    // 设置咨询标识
//                    json.put("code", result[2]);
//                    // 设置显示标题
//                    json.put("title", result[3]);
//                    json.put("patientName", patientobj.getName());
//                    json.put("patientPhoto", patientobj.getPhoto());
//                    // 设置主诉
//                    json.put("symptoms", result[4]);
//                    // 咨询状态
//                    json.put("status", result[6]);
//                    // 设置咨询日期
//                    json.put("czrq", DateUtil.dateToStrLong((Date) result[5]));
//                    // 咨询状态
//                    json.put("doctorCode", result[7]);
//                    json.put("evaluate", result[8]);
//                    array.put(json);
//                }
//            }
//            return write(200, "查询成功!", "list", array);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "/getDoctorConsultSessions", method = RequestMethod.GET)
//    @ApiOperation("获取医生咨询列表,带专家咨询")
//    public String getDoctorConsultSessions(@ApiParam(name = "user_id", value = "会话医生code", required = true)
//                                           @RequestParam(value = "user_id", required = true) String user_id,
//                                           @ApiParam(name = "business_type", required = true)
//                                           @RequestParam(value = "business_type", required = true, defaultValue = "2") String business_type,
//                                           @ApiParam(name = "status", value = "0未结束,1已结束", required = true)
//                                           @RequestParam(value = "status", required = true) String status,
//                                           @ApiParam(name = "page", required = true)
//                                           @RequestParam(value = "page", required = true, defaultValue = "0") String page,
//                                           @ApiParam(name = "size", required = true)
//                                           @RequestParam(value = "size", required = true, defaultValue = "50") String size
//    ) {
//        try {
//            return write(200, "查询成功", "data", consultTeamService.getDoctorConsultSessions(user_id, business_type, status, page, size));
//        } catch (ServiceException se) {
//            return error(-1, se.getMessage());
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//
//    @RequestMapping(value = "/getIMkangFuConsultSessions", method = RequestMethod.GET)
//    @ApiOperation("获取医生康复咨询IM列表")
//    public String getIMkangFuConsultSessions(@ApiParam(name = "user_id", value = "会话医生code", required = true)
//                                             @RequestParam(value = "user_id", required = true) String user_id,
//                                             @ApiParam(name = "type", required = true)
//                                             @RequestParam(value = "type", required = true, defaultValue = "18") String type,
//                                             @ApiParam(name = "status", value = "0未结束,1已结束", required = false)
//                                             @RequestParam(value = "status", required = false) String status,
//                                             @ApiParam(name = "name", value = "居民姓名支持模糊", required = false)
//                                             @RequestParam(value = "name", required = false) String name,
//                                             @ApiParam(name = "page", required = true)
//                                             @RequestParam(value = "page", required = true, defaultValue = "0") String page,
//                                             @ApiParam(name = "size", required = true)
//                                             @RequestParam(value = "size", required = true, defaultValue = "50") String size
//    ) {
//        try {
//            return write(200, "查询成功", "data", consultTeamService.getIMkangFuConsultSessions(user_id, type, status, page, size, name));
//        } catch (ServiceException se) {
//            return error(-1, se.getMessage());
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "/getSpecialAndKangFuConsultUnreadInfo", method = RequestMethod.GET)
//    @ApiOperation("获取专家咨询、康复咨询是否存在未处理")
//    public String getSpecialAndKangFuConsultUnreadInfo(@ApiParam(name = "user_id", value = "医生code")
//                                                       @RequestParam(value = "user_id", required = true) String user_id
//    ) {
//        try {
//            return write(200, "查询成功", "data", consultTeamService.getSpecialAndKangFuConsultUnreadInfo(user_id));
//        } catch (ServiceException se) {
//            return error(-1, se.getMessage());
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
}

+ 52 - 43
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/service/ConsultTeamService.java

@ -6,7 +6,9 @@ import com.yihu.jw.entity.base.im.ConsultDo;
import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.im.ConsultTeamLogDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.door.WlyyDoorPrescriptionDO;
import com.yihu.jw.entity.door.WlyyDoorServiceOrderDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import com.yihu.jw.entity.wechat.WechatTemplateConfig;
import com.yihu.jw.hospital.HospitalDao;
import com.yihu.jw.hospital.module.door.dao.WlyyDoorServiceOrderDao;
@ -71,38 +73,38 @@ public class ConsultTeamService extends ConsultService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    private MessageDao messageDao;
    @Autowired
    private PrescriptionDao prescriptionDao;
    @Autowired
    private BasePatientDao patientDao;
    @Autowired
    private PrescriptionLogService prescriptionLogService;
    @Autowired
    private PrescriptionInfoDao prescriptionInfoDao;
    @Autowired
    private PrescriptionDiagnosisDao prescriptionDiagnosisDao;
//    @Autowired
//    private PrescriptionLogService prescriptionLogService;
//    @Autowired
//    private PrescriptionInfoDao prescriptionInfoDao;
//    @Autowired
//    private PrescriptionDiagnosisDao prescriptionDiagnosisDao;
    @Autowired
    private WeiXinAccessTokenUtils accessTokenUtils;
//    @Autowired
//    private WeiXinAccessTokenUtils accessTokenUtils;
    @Autowired
    private BasePatientService patientService;
    @Autowired
    private MessageService messageService;
//    @Autowired
//    private MessageService messageService;
//
//    @Autowired
//    private PrescriptionExpressageDao expressageDao;
//    @Autowired
//    private HospitalDao hospitalDao;
    @Autowired
    private PrescriptionExpressageDao expressageDao;
    @Autowired
    private HospitalDao hospitalDao;
    @Autowired
    private WlyyDoorServiceOrderDao wlyyDoorServiceOrderDao;
    @Autowired
@ -177,6 +179,10 @@ public class ConsultTeamService extends ConsultService {
//    private PresModeAdapter presModeAdapter;
//    @Autowired
//    private ZyDictService zyDictService;
//    @Autowired
//    private WeiXinOpenIdUtils weiXinOpenIdUtils;
//    @Autowired
//    private MessageDao messageDao;
    /**
@ -3057,13 +3063,14 @@ public class ConsultTeamService extends ConsultService {
    /**
     * 根据续方code获取咨询
     */
//    public ConsultTeamDo getConsultStatus(String prescriptionCode) {
//        Prescription prescription = prescriptionDao.findByCode(prescriptionCode);
    public ConsultTeamDo getConsultStatus(String prescriptionCode) {
        //先注释掉
//        WlyyPrescriptionDO prescription = prescriptionDao.findByCode(prescriptionCode);
//        if (prescription != null) {
//            return consultTeamDao.findByConsult(prescription.getConsult());
//        }
//        return null;
//    }
        return null;
    }
    /**
@ -3346,27 +3353,29 @@ public class ConsultTeamService extends ConsultService {
    /**
     * 根据咨询查关联业务记录
     */
//    public com.alibaba.fastjson.JSONObject queryByConsultCode(String code, Integer type) {
//        com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
//        if (StringUtils.isEmpty(code) || null == type) {
//            return null;
//        }
//        Consult consult = consultDao.queryByCodeAndType(code, type);
//
//        if (null == consult) {
//            result.put("data", "");
//            return result;
//        }
//
//        if (type == 11) {
//            WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findOne(consult.getRelationCode());
//            com.alibaba.fastjson.JSONObject patientInfo = wlyyDoorServiceOrderService.queryOrderCardInfo(orderDO);
//            result.put("data", patientInfo);
//        }
//
//        result.putIfAbsent("data", consult);
//        return result;
//    }
    public com.alibaba.fastjson.JSONObject queryByConsultCode(String code, Integer type) {
        com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
        if (StringUtils.isEmpty(code) || null == type) {
            return null;
        }
        //这是id
        ConsultDo consult = consultDao.queryByIdAndType(code, type);
        if (null == consult) {
            result.put("data", "");
            return result;
        }
        if (type == 11) {
            WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findOne(consult.getRelationCode());
            com.alibaba.fastjson.JSONObject patientInfo = wlyyDoorServiceOrderService.queryOrderCardInfo(orderDO);
            result.put("data", patientInfo);
        }
        result.putIfAbsent("data", consult);
        return result;
    }
    public org.json.JSONObject updateIMMsg(String sessionId, String sessionType, String msgId, String content) {
        org.json.JSONObject result = new org.json.JSONObject();
        if (StringUtils.isEmpty(sessionId) || StringUtils.isEmpty(sessionType) || StringUtils.isEmpty(msgId) || StringUtils.isEmpty(content)) {

+ 20 - 8
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/controller/DoorOrderController.java

@ -1,6 +1,7 @@
package com.yihu.jw.hospital.module.door.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.door.WlyyDoorConclusionDO;
import com.yihu.jw.entity.door.WlyyDoorServiceOrderDO;
@ -34,9 +35,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 * Created by wxw on 2019/3/15.
@ -840,7 +839,7 @@ public class DoorOrderController extends EnvelopRestEndpoint {
//    ) {
//        try {
//            List<JSONObject> array = new ArrayList<>();
//            WlyyDoorServiceOrderDO one = doorServiceOrderDao.findById(orderId).orElse(null);
//            WlyyDoorServiceOrderDO one = doorServiceOrderDao.findOne(orderId);
//            // 被服务的居民的次数(非代理居民)
//            Integer times = wlyyDoorServiceOrderService.countPatientDoorTimes(one.getPatient());
//            List<String> doctors = doorDoctorDao.findDoctors(orderId);
@ -1070,7 +1069,6 @@ public class DoorOrderController extends EnvelopRestEndpoint {
    @PostMapping(value = "createPrescription")
    @ResponseBody
    @ApiOperation("上门服务前手工开方接口")
    public Envelop createPrescription(@ApiParam(name = "orderId", value = "工单id", required = true) @RequestParam String orderId,
                                      @ApiParam(name = "prescriptionCode", value = "处方单号,多个用逗号隔开", required = true) @RequestParam String prescriptionCode,
@ -1196,12 +1194,26 @@ public class DoorOrderController extends EnvelopRestEndpoint {
//    }
    /**
     * 医生修改工单信息
     *
     * @param jsonData
     * @return
     */
    @PostMapping(value = "proxyUpdate")
    @ApiOperation(value = "上门服务-工单编辑")
    public Envelop proxyUpdate(@ApiParam(name = "jsonData", value = "Json数据", required = true) @RequestParam String jsonData) {
    public Envelop proxyUpdate(
            @ApiParam(name = "jsonData", value = "Json数据", required = true) @RequestParam String jsonData,
            @ApiParam(name = "loginUserCode", value = "Json数据", required = false) @RequestParam String loginUserCode
    ) {
        try {
            JSONObject result = wlyyDoorServiceOrderService.proxyUpdate(jsonData, getUID());
            String userCode;
            if (StringUtils.isBlank(getUID())) {
                userCode = loginUserCode;
            } else {
                userCode = getUID();
            }
            JSONObject result = wlyyDoorServiceOrderService.proxyUpdate(jsonData, userCode);
            if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
                return failed(result.getString(ResponseContant.resultMsg));
            }

+ 14 - 14
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/service/WlyyDoorPrescriptionService.java

@ -1,5 +1,6 @@
package com.yihu.jw.hospital.module.door.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
@ -15,6 +16,8 @@ import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
import com.yihu.jw.im.dao.ConsultDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.util.date.DateUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -23,10 +26,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.*;
/**
 * 上门服务开方相关业务
@ -83,16 +83,16 @@ public class WlyyDoorPrescriptionService {
//    /**
//     * 造长处方开方数据
//     *
//     * @param doctor
//     * @param patient
//     * @param visitDept
//     * @param visitTimeFrom
//     * @param visitTimeEnd
//     * @return
//     */
    /**
     * 造长处方开方数据
     *
     * @param doctor
     * @param patient
     * @param visitDept
     * @param visitTimeFrom
     * @param visitTimeEnd
     * @return
     */
//    public JSONArray getPrescription(String doctor, String patient, String visitDept, String visitTimeFrom, String visitTimeEnd) throws Exception {
//        JSONArray array = new JSONArray();
//        if (StringUtils.isEmpty(visitTimeFrom)) {

+ 43 - 36
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/service/WlyyDoorServiceOrderService.java

@ -2,7 +2,6 @@ package com.yihu.jw.hospital.module.door.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
@ -652,9 +651,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    /**
     * 创建上门服务工单
     *
     * @param jsonData
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public JSONObject create(String jsonData) throws Exception {
@ -871,12 +867,23 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            //发送 预约卡片信息(2101类型)
            JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
            orderInfoContent.put("re_msg_type", 0);//居民预约
            //发送消息
            int i = qucikSendIM(orderDO.getId(), "system", "智能助手", "2101", orderInfoContent.toJSONString());
            if (i != 1) {
                throw new Exception("上门服务工单消息发送失败");
            //模拟一,重试3次
            int tryCount = 3;
            int flagCount = 0;
            for (int i = 0; i < tryCount; i++) {
                //发送消息
                flagCount = qucikSendIM(orderDO.getId(), "system", "智能助手", "2101", orderInfoContent.toJSONString());
                if (flagCount == 1) {
                    break;
                }
            }
//            //模式2,睡眠1秒钟
//            Thread.sleep(1000);
//            flagCount = qucikSendIM(orderDO.getId(), "system", "智能助手", "2101", orderInfoContent.toJSONString());
            //后面这个要修改下,加个字段判断下是否转派
            if (StringUtils.isNoneBlank(orderDO.getDoctor())) {
                //服务医生修改,直接转派
@ -1040,9 +1047,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    /**
     * 回写最后一个回复内容的调度员到工单表
     *
     * @param dispatcher
     * @param orderId
     */
    @Transactional(rollbackFor = Exception.class)
    public JSONObject saveLastDispatcher(String orderId, String dispatcher, String dispatcherName) {
@ -1273,32 +1277,33 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            //生成二维码图片
            String contentJsonStr = orderDO.getNumber();
            InputStream ipt = QrcodeUtil.createQrcode(contentJsonStr, 300, "png");
            if (isneiwang) {
                // 圖片列表
                List<String> tempPaths = new ArrayList<String>();
                try {
                    ObjectNode imgNode = fastDFSUtil.upload(ipt, "png", "plan_service_qrcode" + System.currentTimeMillis());
                    JSONObject json = JSONObject.parseObject(imgNode.toString());
                    tempPaths.add(json.getString("fid"));
                    String urls = "";
                    for (String image : tempPaths) {
                        if (urls.length() == 0) {
                            urls = image;
                        } else {
                            urls += "," + image;
                        }
                    }
                    fileUrl = fastdfs_file_url + urls;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    fileUrl = fastdfs_file_url + PrescriptionQRCodetoNeiWang(ipt);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            //内网先注释
//            if (isneiwang) {
//                // 圖片列表
//                List<String> tempPaths = new ArrayList<String>();
//                try {
//                    ObjectNode imgNode = fastDFSUtil.upload(ipt, "png", "plan_service_qrcode" + System.currentTimeMillis());
//                    JSONObject json = JSONObject.parseObject(imgNode.toString());
//                    tempPaths.add(json.getString("fid"));
//                    String urls = "";
//                    for (String image : tempPaths) {
//                        if (urls.length() == 0) {
//                            urls = image;
//                        } else {
//                            urls += "," + image;
//                        }
//                    }
//                    fileUrl = fastdfs_file_url + urls;
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            } else {
            try {
                fileUrl = fastdfs_file_url + PrescriptionQRCodetoNeiWang(ipt);
            } catch (Exception e) {
                e.printStackTrace();
            }
//            }
            param.put("number", orderDO.getNumber());
            param.put("imageUrl", fileUrl);
            return fileUrl;
@ -2645,6 +2650,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            if (resObj.getIntValue("status") == -1) {
                String msg = "上门服务工单消息发送失败:" + resObj.getString("message");
                System.out.println(msg);
                return -1;
            }
        } catch (Exception e) {
            e.printStackTrace();
@ -3069,4 +3075,5 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
}