yeshijie 7 лет назад
Родитель
Сommit
99f668e04e

+ 1 - 1
common/common-entity/src/main/java/com/yihu/wlyy/entity/consult/Consult.java

@ -42,7 +42,7 @@ public class Consult extends IdEntity {
	private String del;
	// 结束时间
	private Date endTime;
	//签约表Code
	//签约表Code 废弃
	private String signCode;
	private String relationCode;//关联业务表的code

+ 1 - 1
common/common-entity/src/main/java/com/yihu/wlyy/entity/consult/ConsultTeam.java

@ -21,7 +21,7 @@ public class ConsultTeam extends IdEntity {
	private String consult;         // 咨询标识
	private String doctor;          // 医生标识
	private String team;            // 三师团队标识
	private Integer type;           //  1、三师咨询,2、家庭医生咨询,6、患者名医咨询 7医生名医咨询 8续方咨询
	private Integer type;           //  1、关注咨询,2、家庭医生咨询,6、患者名医咨询 7医生名医咨询 8续方咨询
	private String patient;         // 提问者标识
	private String name;            // 患者姓名
	private Integer sex;            // 患者性别

+ 1 - 1
common/common-entity/src/main/java/com/yihu/wlyy/entity/message/MessageNoticeSetting.java

@ -21,7 +21,7 @@ public class MessageNoticeSetting extends IdEntity{
    private String type;// '类型(1医生,2居民)'
    private Integer masterSwitch;// '总开关' (1开,0关)
    private Integer imSwitch;//'im消息开关'(1开,0关)
    private Integer familyTopicSwitch;// '健管师邀请后推送开关'(1开,0关)
    private Integer familyTopicSwitch;// '健管师邀请后推送开关'(1开,0关) 废弃字段
    private Integer signSwitch;// '签约消息开关'(1开,0关)
    private Integer healthSignSwitch;// '体征消息开关'(1开,0关)
    private Integer systemSwitch;// '系统消息开关'(1开,0关)

+ 2 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/consult/ConsultTeamDao.java

@ -30,8 +30,8 @@ public interface ConsultTeamDao extends PagingAndSortingRepository<ConsultTeam,
	List<ConsultTeam> findUnfinishedConsultType(String patient,String doctor);
	// 统计未完成的数量
	@Query("select count(1) from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.patient = ?1 and a.status = 0 and a.del = '1'and b.to=?2")
	int countByPatient(String patient,String doctor);
	@Query("select count(1) from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.patient = ?1 and a.status = 0 and a.del = '1'and b.to=?2 and a.type=?3 ")
	int countByPatient(String patient,String doctor,Integer type);
	// 被指定且未结束列表
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and b.to = ?1 and b.from is null")

+ 0 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultService.java

@ -72,10 +72,6 @@ public class ConsultService extends BaseService {
		consult.setSymptoms(symptoms);
		consult.setImages(images);
		consult.setType(type);
		SignFamily signFamily = signFamilyDao.findByPatient(patient);
		if(signFamily!=null){
			consult.setSignCode(signFamily.getCode());
		}
		return consultDao.save(consult);
	}

+ 58 - 232
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java

@ -1,6 +1,7 @@
package com.yihu.wlyy.service.app.consult;
import com.yihu.wlyy.adapter.PresModeAdapter;
import com.yihu.wlyy.entity.concern.ConcernDO;
import com.yihu.wlyy.entity.consult.Consult;
import com.yihu.wlyy.entity.consult.ConsultTeam;
import com.yihu.wlyy.entity.consult.ConsultTeamDoctor;
@ -8,18 +9,16 @@ import com.yihu.wlyy.entity.consult.ConsultTeamLog;
import com.yihu.wlyy.entity.device.PatientDevice;
import com.yihu.wlyy.entity.discussion.WlyyTalkGroup;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeam;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeamMember;
import com.yihu.wlyy.entity.education.HealthEduArticle;
import com.yihu.wlyy.entity.followup.Followup;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.entity.message.MessageNoticeSetting;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientFamilyMember;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.prescription.*;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.entity.zydict.ZyIvPhysicDict;
import com.yihu.wlyy.repository.concern.ConcernDao;
import com.yihu.wlyy.repository.consult.ConsultTeamDao;
import com.yihu.wlyy.repository.consult.ConsultTeamDoctorDao;
import com.yihu.wlyy.repository.consult.ConsultTeamLogDao;
@ -34,6 +33,7 @@ import com.yihu.wlyy.repository.patient.PatientFamilyMemberDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.prescription.*;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.app.concern.ConcernService;
import com.yihu.wlyy.service.app.health.HealthEduArticleService;
import com.yihu.wlyy.service.app.health.PatientHealthGuidanceService;
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
@ -130,7 +130,7 @@ public class ConsultTeamService extends ConsultService {
    @Autowired
    private PrescriptionDiagnosisDao prescriptionDiagnosisDao;
    @Autowired
    private ImUtill ImUtill;
    private ImUtill imUtill;
    @Autowired
    private HttpClientUtil HttpClientUtil;
    @Autowired
@ -177,6 +177,10 @@ public class ConsultTeamService extends ConsultService {
    private PushMsgTask pushMsgTask;
    @Autowired
    private PrescriptionExplainDao prescriptionExplainDao;
    @Autowired
    private ConcernService concernService;
    @Autowired
    private ConcernDao concernDao;
    @PostConstruct
    public void init() {
@ -203,29 +207,6 @@ public class ConsultTeamService extends ConsultService {
            json.put("msg","您还未签约,不能发起续方咨询");
            return json;
        }
        //点击后判断,如果用户当前存在可申请续方的处方记录,则进入续方申请流程,若不存在可续方记录,alert“当前没有可以申请续方的处方记录”
        // 智业接口没有返回列表,是单条 所以先不处理
//        int num = 0;
//        Patient p = patientDao.findByCode(patient);
//        String rp= jwPrescriptionService.getRecipeList(p.getSsc(),null,null,null);
//        com.alibaba.fastjson.JSONArray pres =presModeAdapter.modeToPrescription(rp);
//        Iterator iterator = pres.iterator();
//        while (iterator.hasNext()){
//            com.alibaba.fastjson.JSONObject r = ( com.alibaba.fastjson.JSONObject)iterator.next();
//            com.alibaba.fastjson.JSONArray des = r.getJSONArray("prescriptionDt");
//            for(int i=0 ;i<des.size();i++){
//                PrescriptionDiagnosis ds = des.getObject(i,PrescriptionDiagnosis.class);
//                if(gxy.equals(ds.getHealthProblem())||tnb.equals(ds.getHealthProblem())){
//                    //为糖尿病高血压
//                    num++;
//                    break;
//                }
//            }
//        }
//        if(num==0){
//            json.put("msg","当前没有可以申请续方的处方记录");
//            return json;
//        }
        //续方说明
        List<PrescriptionExplain> list = prescriptionExplainDao.findList();
@ -246,57 +227,13 @@ public class ConsultTeamService extends ConsultService {
    /**
     * 查询患者是否还有未结束的三师咨询
     * 查询患者与医生是否还有未结束的关注咨询
     *
     * @param patient
     * @return
     */
    public boolean exist(String patient, Integer type) throws Exception {
        DoctorTeamMember member = null;
        String memberCode=null;
        // 咨询三师
        if (type == 1) {
            // 查询三师签约信息
            SignFamily sc = signFamilyDao.findBySanshiPatientYes(patient);
            if (sc == null) {
                throw new Exception("不存在三师签约");
            }
            // 设置健康管理师,三师咨询默认给健康管理师处理
            //查找病人所在的团队
            DoctorTeam doctorTeam = doctorTeamDao.findBySanshiParientCode(patient);
            //得到团队的健康管理师
            member = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(), 3);
            if (member == null) {
                member = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(), 2);
            }
            memberCode= member.getCode();
        } else if (type == 2) {
            // 咨询家庭医生
            SignFamily sf = signFamilyDao.findByjiatingPatient(patient);
            if (sf == null) {
                throw new Exception("不存在家庭签约");
            }
            if (StringUtils.isEmpty(sf.getDoctorHealth())){
                memberCode = sf.getDoctor();
            }else {
                memberCode = sf.getDoctorHealth();
            }
            // 设置健康管理师,家庭医生咨询默认给健康管理师处理
            //查找病人所在的团队
//            DoctorTeam doctorTeam = doctorTeamDao.findByParientCode(patient);
//            //得到团队的健康管理师
//            member = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 3);
//
//            if (member == null) {
//                member = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 2);
//            }
        }
//        if (member == null) {
//            throw new Exception("找不到签约服务团队医生");
//        }
        int count = consultTeamDao.countByPatient(patient, memberCode);
    public boolean exist(String patient,Integer type, String doctor) throws Exception {
        int count = consultTeamDao.countByPatient(patient, doctor,type);
        return count > 0;
    }
@ -816,17 +753,26 @@ public class ConsultTeamService extends ConsultService {
    /**
     * 患者端
     * 添加三师咨询
     * 添加咨询
     *
     * @param ct      三师咨询对象
     * @param ct      咨询对象
     * @param patient 患者标识
     * @param doctorCode 咨询医生
     * @return
     * @throws Exception
     */
    public JSONObject addTeamConsult(ConsultTeam ct, String patient,String agent) throws Exception {
    public JSONObject addTeamConsult(ConsultTeam ct, String patient,String agent,String doctorCode) throws Exception {
        JSONObject re = new JSONObject();
        if (exist(patient, ct.getType())) {//判断是否有未结束的咨询移到同步方法中
            re.put("status",-3);
        //自动关注 咨询关注
        ConcernDO concernDO = concernDao.findByPatientAndDoctor(patient,doctorCode);
        if(concernDO==null){
            concernService.addConcern(patient,doctorCode,3);
            concernDO = concernDao.findByPatientAndDoctor(patient,doctorCode);
        }
        if (exist(patient, ct.getType(),doctorCode)) {
            re.put("status",-1);
            return re;
        }
@ -835,90 +781,8 @@ public class ConsultTeamService extends ConsultService {
        if(patient.equals(agent)){
            agent = null;
        }
        users.put(doctorCode, 0);
        // 咨询三师
        if (ct.getType() == 1) {
            // 查询三师签约信息
            SignFamily sc = signFamilyDao.findBySanshiPatientYes(patient);
            if (sc == null) {
                // 不存在三师签约
                re.put("status",-2);
                return re;
            }
            ct.setTeam(sc.getTeamCode());
            // 设置健康管理师,三师咨询默认给健康管理师处理
            //查找病人所在的团队
            DoctorTeam doctorTeam = doctorTeamDao.findBySanshiParientCode(patient);
            //得到团队的健康管理师
            DoctorTeamMember doctorTeamMemberHealthy = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(), 3);
            DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(), 2);
            if (doctorTeamMemberHealthy == null) {
                ct.setDoctor(doctorTeamMember.getMemberCode());
                users.put(doctorTeamMember.getMemberCode(), 0);
            } else {
                users.put(doctorTeamMemberHealthy.getMemberCode(), 0);
                if (doctorTeamMember != null) {
                    if (users.isNull(doctorTeamMember.getMemberCode())) {
                        users.put(doctorTeamMember.getMemberCode(), 1);
                    }
                }
                ct.setDoctor(doctorTeamMemberHealthy.getMemberCode());
            }
            // 设置家庭医生
            ct.setAdminTeamId(sc.getAdminTeamId());
        } else if (ct.getType() == 2) {
            // 咨询家庭医生
            SignFamily sf = signFamilyDao.findByjiatingPatient(patient);
            if (sf == null) {
                // 不存在家庭签约
                re.put("status",-1);
                return re;
            }
            ct.setTeam(sf.getTeamCode());
            // 设置健康管理师,家庭医生咨询默认给健康管理师处理
            //查找病人所在的团队
            //1.3.3.2 更改从签约记录判断团队成员,分配建管师
            if(StringUtils.isNotBlank(sf.getDoctorHealth())) {
                users.put(sf.getDoctorHealth(), 0);
                ct.setDoctor(sf.getDoctorHealth());
                if (StringUtils.isNotBlank(sf.getDoctor())) {
                    if (users.isNull(sf.getDoctor())) {
                        //全科需要判断是否开启健管师邀请后在接收消息
                        int isGetMessage = 1;
                        if(!messageService.getMessageNoticeSettingByMessageType(sf.getDoctor(),"1", MessageNoticeSetting.MessageTypeEnum.familyTopicSwitch.getValue())){
                            isGetMessage = 0;
                        }
                        users.put(sf.getDoctor(), isGetMessage);
                    }
                }
            } else {
                ct.setDoctor(sf.getDoctor());
                users.put(sf.getDoctor(), 0);
            }
//            DoctorTeam doctorTeam = doctorTeamDao.findByParientCode(patient);
//            //得到团队的健康管理师
//            DoctorTeamMember doctorTeamMemberHealthy = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 3);
//            DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 2);
//            if (doctorTeamMemberHealthy == null) {
//                ct.setDoctor(doctorTeamMember.getMemberCode());
//                users.put(doctorTeamMember.getMemberCode(), 0);
//            } else {
//                users.put(doctorTeamMemberHealthy.getMemberCode(), 0);
//                if (doctorTeamMember != null) {
//                    //全健同一个人导致会话成员状态问题处理
//                    if (users.isNull(doctorTeamMember.getMemberCode())) {
//                        users.put(doctorTeamMember.getMemberCode(), 1);
//                    }
//                }
//                ct.setDoctor(doctorTeamMemberHealthy.getMemberCode());
//            }
            // 设置家庭医生
            ct.setAdminTeamId(sf.getAdminTeamId());
        }
        // 设置患者信息
        ct.setPatient(patient);
        // 查询患者信息
@ -944,12 +808,13 @@ public class ConsultTeamService extends ConsultService {
        consult.setGuidance(ct.getGuidance());
        // 设置咨询标识
        ct.setConsult(consult.getCode());
        //设置服务团队
        ct.setTeam(concernDO.getTeamCode());
        //推送给IM去创建议题,取得成员消息
//        JSONObject messages = ImUtill.getCreateTopicMessage(patient, tempPatient.getName(), consult.getTitle(), "咨询问题:"+consult.getSymptoms(), consult.getImages());
        JSONObject messages = ImUtill.getCreateTopicMessage(patient, tempPatient.getName(), consult.getTitle(), consult.getSymptoms(), consult.getImages(),agent);
        users.put(patient, 0);//+ " "+(tempPatient.getSex()==1?"(男 ":"(女 ") + IdCardUtil.getAgeForIdcard(tempPatient.getIdcard())+")"
        JSONObject obj = ImUtill.createTopics(patient + "_" + ct.getTeam() + "_" + ct.getType(), consult.getCode(), tempPatient.getName(), users, messages, ImUtill.SESSION_TYPE_MUC);
        JSONObject messages = imUtill.getCreateTopicMessage(patient, tempPatient.getName(), consult.getTitle(), consult.getSymptoms(), consult.getImages(),agent);
        users.put(patient, 0);
        JSONObject obj = imUtill.createTopics(patient + "_" + ct.getTeam() + "_" + ct.getType(), consult.getCode(), tempPatient.getName(), users, messages, ImUtill.SESSION_TYPE_MUC);
        if (obj == null) {
            throw new RuntimeException("IM消息发送异常!");
        }
@ -979,7 +844,6 @@ public class ConsultTeamService extends ConsultService {
        // 添加咨询转发记录
        // 添加医生咨询日志
        String content = addLogs(ct);
        re.put("doctor",doctor);
        re.put("status",1);
        return re;
@ -1007,10 +871,7 @@ public class ConsultTeamService extends ConsultService {
                return -2;
            }
//            String checkPre = prescriptionInfoService.checkPre(patient,DateUtil.getStringDateShort()+" 00:00:00");
//            if("0".equals(checkPre)){//存在未结算的续方
//                return -3;
//            }
            ct.setAdminTeamId(signFamily.getAdminTeamId());
            Doctor doctor = doctorDao.findByAdminTeamId(signFamily.getAdminTeamId());
            doctorCode = doctor.getCode();
@ -1034,41 +895,6 @@ public class ConsultTeamService extends ConsultService {
            }
            //3、获取上次续方时间:与平安的“智慧医保的审方系统”对接,判断居民上次续方时间,点击跳转上次续方记录。(此功能需与第三方系统对接,如果本次版本无法实现,则消息中不显示此条信息)
            jsonObject.put("lastTime","");
    
//            //--增加问卷填写情况---huangwenjie--2017.11.01---已和产品确认,这块消息不在续方咨询消息中添加
//            List<PrescriptionFollowupContent> prescriptionFollowupContents =prescriptionFollowupContentDao.findByPrescriptionCode(prescription.getCode());
//            boolean zzFlag = false;//是否填写症状问卷
//            boolean tzssFlag = false;//是否填写体征和生活问卷
//            for (PrescriptionFollowupContent prescriptionFollowupContent: prescriptionFollowupContents) {
//                if(!zzFlag && "1".equals(prescriptionFollowupContent.getFollowupProject())){
//                    zzFlag = true;
//                }
//
//                if(!tzssFlag &&
//                        ("2".equals(prescriptionFollowupContent.getFollowupProject())
//                                || "4".equals(prescriptionFollowupContent.getFollowupProject()))
//                        ){
//                    zzFlag = true;
//                }
//
//                if(zzFlag && tzssFlag){
//                    break;
//                }
//            }
//            if(zzFlag){
//                jsonObject.put("zzMsg","居民已填写问卷");
//            }else{
//                jsonObject.put("zzMsg","居民未填写问卷");
//            }
//            if(tzssFlag){
//                jsonObject.put("tzssMsg","居民已填写问卷");
//            }else{
//                jsonObject.put("tzssMsg","居民未填写问卷");
//            }
//            jsonObject.put("zzFlag",zzFlag);
//            jsonObject.put("tzssFlag",tzssFlag);
            
            
            
            String content = jsonObject.toString();
@ -1119,11 +945,11 @@ public class ConsultTeamService extends ConsultService {
            ct.setConsult(consult.getCode());
            //推送给IM去创建议题,取得成员消息
            JSONObject messages = ImUtill.getCreateTopicMessage(patient, p.getName(), consult.getTitle(), content, consult.getImages(),agent);
            JSONObject messages = imUtill.getCreateTopicMessage(patient, p.getName(), consult.getTitle(), content, consult.getImages(),agent);
            //5、(im创建咨询) 续方咨询的sessionid为居民code+续方code+咨询类型
            String sessionId = patient + "_" + consult.getCode() + "_" + ct.getType();
            JSONObject obj = ImUtill.createTopics(sessionId, consult.getCode(), p.getName(), users, messages, ImUtill.SESSION_TYPE_PRESCRIPTION);
            JSONObject obj = imUtill.createTopics(sessionId, consult.getCode(), p.getName(), users, messages, ImUtill.SESSION_TYPE_PRESCRIPTION);
            if (obj == null) {
                throw new RuntimeException("IM消息发送异常!");
            }
@ -1886,8 +1712,8 @@ public class ConsultTeamService extends ConsultService {
        return consultTeamLogDao.findOne(logId);
    }
    public boolean isExistConsult(String uid, String doctor) {
        int consultTeam = consultTeamDao.countByPatient(uid, doctor);
    public boolean isExistConsult(String uid,Integer type, String doctor) {
        int consultTeam = consultTeamDao.countByPatient(uid, doctor,type);
        if (consultTeam > 0) {
            return true;
        } else {
@ -1919,7 +1745,7 @@ public class ConsultTeamService extends ConsultService {
            content = member.getName() + "("+relations.get(familyMember.getFamilyRelation())+")"+content;
        }
        ImUtill.sendIntoTopicIM(ct.getPatient(),ct.getPatient(),ct.getConsult(),content,agent,intoUserName);
        imUtill.sendIntoTopicIM(ct.getPatient(),ct.getPatient(),ct.getConsult(),content,agent,intoUserName);
        return 0;
    }
@ -2216,7 +2042,7 @@ public class ConsultTeamService extends ConsultService {
        participants.put(ct.getPatient(), 0);
        participants.put(ct.getDoctor(), 0);
        Doctor doctor = doctorService.findDoctorByCode(uid);
        JSONObject sessionJson = ImUtill.createSession(participants, ImUtill.SESSION_TYPE_P2P, doctor.getName() + "发起求助!", "");
        JSONObject sessionJson = imUtill.createSession(participants, ImUtill.SESSION_TYPE_P2P, doctor.getName() + "发起求助!", "");
        if (sessionJson.getInt("status") == -1) {
            throw new RuntimeException(sessionJson.getString("message"));
        }
@ -2225,13 +2051,13 @@ public class ConsultTeamService extends ConsultService {
            ct.setTeam(oldConsultCode);
            ConsultTeam oldConsult = consultTeamDao.findByConsult(oldConsultCode);
            if (oldConsult != null && isSend == 1) {
                ImUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"), "1", "居民问题:" + oldConsult.getSymptoms(), "1");
                imUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"), "1", "居民问题:" + oldConsult.getSymptoms(), "1");
                //推送给IM图片
                if (StringUtils.isNotEmpty(oldConsult.getImages())) {
                    String[] images = oldConsult.getImages().split(",");
                    for (String image : images) {
                        if (StringUtils.isNoneEmpty(image)) {
                            ImUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"), "2", image, "1");
                            imUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"), "2", image, "1");
                        }
                    }
                }
@ -2243,17 +2069,17 @@ public class ConsultTeamService extends ConsultService {
            qiuzuObj.put("old_consult_code", oldConsultCode);
            qiuzuObj.put("doctor", ct.getDoctor());
            qiuzuObj.put("doctor_name", doctorTemp.getName());
            ImUtill.sendTopicIM(doctor.getCode(), doctor.getName(), oldConsultCode, "5", qiuzuObj.toString(),null);
            imUtill.sendTopicIM(doctor.getCode(), doctor.getName(), oldConsultCode, "5", qiuzuObj.toString(),null);
        }
        ImUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"), "1", "咨询问题:" + ct.getSymptoms(), "1");
        imUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"), "1", "咨询问题:" + ct.getSymptoms(), "1");
        //推送给IM图片
        if (StringUtils.isNotEmpty(ct.getImages())) {
            String[] images = ct.getImages().split(",");
            for (String image : images) {
                if (StringUtils.isNoneEmpty(image)) {
                    ImUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"), "2", image, "1");
                    imUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"), "2", image, "1");
                }
            }
        }
@ -2300,12 +2126,12 @@ public class ConsultTeamService extends ConsultService {
        // 添加医生咨询日志
        String content = addLogs(ct);
        if (StringUtils.isBlank(oldConsultCode)) {
            JSONObject messages = ImUtill.getCreateTopicMessage(doctorTemp.getCode(), doctorTemp.getName(), consult.getTitle(), content, consult.getImages(),null);
            JSONObject messages = imUtill.getCreateTopicMessage(doctorTemp.getCode(), doctorTemp.getName(), consult.getTitle(), content, consult.getImages(),null);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put(ct.getPatient(), 0);
            jsonObject.put(ct.getDoctor(), 0);
            //设置消息ID
            JSONObject obj = ImUtill.createTopics(null, consult.getCode(), doctorTemp.getName(), jsonObject, messages, ImUtill.SESSION_TYPE_P2P);
            JSONObject obj = imUtill.createTopics(null, consult.getCode(), doctorTemp.getName(), jsonObject, messages, ImUtill.SESSION_TYPE_P2P);
            if (obj == null || obj.getInt("status") == -1) {
                throw new RuntimeException("im消息创建异常!" + obj == null ? "" : obj.getString("message"));
            }
@ -2316,28 +2142,28 @@ public class ConsultTeamService extends ConsultService {
            ConsultTeam consultTeam = consultTeamDao.findByConsult(oldConsultCode);
            ct.setTeam(oldConsultCode);
            if (oldConsult != null && isSend == 1) {
                JSONObject messages = ImUtill.getCreateTopicMessage(doctorTemp.getCode(), doctorTemp.getName(), consult.getTitle(), "居民问题:" + oldConsult.getSymptoms(), oldConsult.getImages(),null);
                JSONObject messages = imUtill.getCreateTopicMessage(doctorTemp.getCode(), doctorTemp.getName(), consult.getTitle(), "居民问题:" + oldConsult.getSymptoms(), oldConsult.getImages(),null);
                JSONObject jsonObject = new JSONObject();
                jsonObject.put(ct.getPatient(), 0);
                jsonObject.put(ct.getDoctor(), 0);
                JSONObject obj = ImUtill.createTopics(null, consult.getCode(), doctorTemp.getName(), jsonObject, messages, ImUtill.SESSION_TYPE_P2P);
                JSONObject obj = imUtill.createTopics(null, consult.getCode(), doctorTemp.getName(), jsonObject, messages, ImUtill.SESSION_TYPE_P2P);
                if (obj == null || obj.getInt("status") == -1) {
                    throw new RuntimeException("im消息创建异常!" + obj == null ? "" : obj.getString("message"));
                }
                ct.setStartMsgId(obj.get("start_msg_id").toString());
                Thread.sleep(100);//消息发送顺序问题处理
                ImUtill.sendTopicIM(doctorTemp.getCode(), doctorTemp.getName(), consult.getCode(), "6", content, null);
                imUtill.sendTopicIM(doctorTemp.getCode(), doctorTemp.getName(), consult.getCode(), "6", content, null);
                if (StringUtils.isNotBlank(consult.getImages())) {
                    String imgs[] = consult.getImages().split(",");
                    for (String url : imgs)
                        ImUtill.sendTopicIM(doctorTemp.getCode(), doctorTemp.getName(), consult.getCode(), "2", url, null);
                        imUtill.sendTopicIM(doctorTemp.getCode(), doctorTemp.getName(), consult.getCode(), "2", url, null);
                }
            } else if (oldConsult != null && isSend == 0) {
                JSONObject messages = ImUtill.getCreateTopicMessage(doctorTemp.getCode(), doctorTemp.getName(), consult.getTitle(), content, oldConsult.getImages(),null);
                JSONObject messages = imUtill.getCreateTopicMessage(doctorTemp.getCode(), doctorTemp.getName(), consult.getTitle(), content, oldConsult.getImages(),null);
                JSONObject jsonObject = new JSONObject();
                jsonObject.put(ct.getPatient(), 0);
                jsonObject.put(ct.getDoctor(), 0);
                JSONObject obj = ImUtill.createTopics(null, consult.getCode(), doctorTemp.getName(), jsonObject, messages, ImUtill.SESSION_TYPE_P2P);
                JSONObject obj = imUtill.createTopics(null, consult.getCode(), doctorTemp.getName(), jsonObject, messages, ImUtill.SESSION_TYPE_P2P);
                if (obj == null || obj.getInt("status") == -1) {
                    throw new RuntimeException("im消息创建异常!" + obj == null ? "" : obj.getString("message"));
                }
@ -2348,7 +2174,7 @@ public class ConsultTeamService extends ConsultService {
            qiuzuObj.put("old_consult_code", oldConsultCode);
            qiuzuObj.put("doctor", ct.getDoctor());
            qiuzuObj.put("doctor_name", doctor.getName());
            ImUtill.sendTopicIM(doctorTemp.getCode(), doctorTemp.getName(), oldConsultCode, "5", qiuzuObj.toString(), null);
            imUtill.sendTopicIM(doctorTemp.getCode(), doctorTemp.getName(), oldConsultCode, "5", qiuzuObj.toString(), null);
        }
        consultTeamDao.save(ct);  // 保存医生咨询信息
        consultTeamDoctorDao.save(cd);
@ -2389,7 +2215,7 @@ public class ConsultTeamService extends ConsultService {
            }
        }
        JSONObject obj = ImUtill.endTopics(consultTeam.getPatient(), endId, endName, consultTeam.getConsult());
        JSONObject obj = imUtill.endTopics(consultTeam.getPatient(), endId, endName, consultTeam.getConsult());
        if (obj == null) {
            throw new RuntimeException("IM消息结束异常!");
        }
@ -2584,9 +2410,9 @@ public class ConsultTeamService extends ConsultService {
        jsonObject.put(ct.getPatient(), 0);
        jsonObject.put(ct.getDoctor(), 0);
        JSONObject messages = ImUtill.getCreateTopicMessage(senderId, senderName, senderName + "发起咨询", content, ct.getImages(),agent);
        JSONObject messages = imUtill.getCreateTopicMessage(senderId, senderName, senderName + "发起咨询", content, ct.getImages(),agent);
        JSONObject obj = ImUtill.createTopics(null, consult.getCode(), consult.getSymptoms(), jsonObject, messages, ImUtill.SESSION_TYPE_P2P);
        JSONObject obj = imUtill.createTopics(null, consult.getCode(), consult.getSymptoms(), jsonObject, messages, ImUtill.SESSION_TYPE_P2P);
        if (obj == null) {
            throw new RuntimeException("im消息创建异常!");
        }
@ -2595,7 +2421,7 @@ public class ConsultTeamService extends ConsultService {
        }
        //设置消息ID
        ct.setStartMsgId(obj.getString("start_msg_id"));
        JSONObject object = ImUtill.getTopic(ct.getConsult());
        JSONObject object = imUtill.getTopic(ct.getConsult());
        JSONArray array = new JSONArray(object.get("data").toString());
        consultTeamDao.save(ct);  // 保存医生咨询信息
        consultTeamDoctorDao.save(cd);
@ -2605,7 +2431,7 @@ public class ConsultTeamService extends ConsultService {
            //获取会话ID。休眠1秒后继续获取相应信息
            // PS:可以通过前端请求两次去解决,由于离职,就不挖坑了,后来者可以改善、
            Thread.sleep(1000);
            object = ImUtill.getTopic(ct.getConsult());
            object = imUtill.getTopic(ct.getConsult());
            array = new JSONArray(object.get("data").toString());
        }
        return array.getJSONObject(0);
@ -2710,7 +2536,7 @@ public class ConsultTeamService extends ConsultService {
        contentobj.put("msgType",type);
        contentobj.put("isSendWxTemplate",true);//是否发送咨询回复的微信模板
        //医生发送Im消息
        ImUtill.sendTopicIM(prescription.getDoctor(), prescription.getDoctorName(), prescription.getConsult(), "17", contentobj.toString(), null);
        imUtill.sendTopicIM(prescription.getDoctor(), prescription.getDoctorName(), prescription.getConsult(), "17", contentobj.toString(), null);
//        contentobj.put("isSendWxTemplate",false);//是否发送咨询回复的微信模板
//        //居民发送Im消息
//        ImUtill.sendTopicIM(prescription.getPatient(), prescription.getPatientName(), prescription.getConsult(), "17", contentobj.toString(), null);

+ 2 - 45
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/scheduling/DoctorWorkTimeService.java

@ -4,7 +4,6 @@ import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.schedule.DoctorFamousConsultTimesRemain;
import com.yihu.wlyy.entity.doctor.schedule.WlyyDoctorWorkTime;
import com.yihu.wlyy.entity.doctor.schedule.WlyyDoctorWorkWeek;
import com.yihu.wlyy.entity.message.MessageNoticeSetting;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.doctor.DoctorWorkTimeDao;
import com.yihu.wlyy.repository.doctor.DoctorWorkWeekDao;
@ -13,13 +12,11 @@ import com.yihu.wlyy.repository.message.MessageNoticeSettingDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.message.MessageService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.eval.StringValueEval;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.print.Doc;
import javax.transaction.Transactional;
import java.text.SimpleDateFormat;
import java.util.*;
@ -737,7 +734,7 @@ public class DoctorWorkTimeService extends BaseService {
        }
    }
    public JSONObject isDoctorWorkingWhenConsult(String doctor,String doctorHealth) throws Exception {
    public JSONObject isDoctorWorkingWhenConsult(String doctor) throws Exception {
        JSONObject json = new JSONObject();
        Calendar calendar = Calendar.getInstance();
        int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
@ -745,47 +742,7 @@ public class DoctorWorkTimeService extends BaseService {
        if (week == 0) {
            week = 7;
        }
        //判断居民签约的全科医生是否关闭了"健康咨询在健管师邀请后参与"设置
        //MessageNoticeSetting messageNoticeSetting = messageNoticeSettingDao.findByUserAndType(doctor,"1");
        com.alibaba.fastjson.JSONObject re = messageService.getMessageNoticSetting(doctor,"1");
        if (re!=null){
            //健管师推荐开启,只判断健管师的时间
            if ("1".equals(re.getString("familyTopicSwitch"))){
                json = doctorWork(doctorHealth,week,calendar);
            }else {//健管师推荐关闭,则两个都要判断
                JSONObject doctorJson = doctorWork(doctor,week,calendar);
                JSONObject doctorHealthJson = doctorWork(doctorHealth,week,calendar);
                String doctorStatus = doctorJson.getString("status");
                String doctorHealthStatus = doctorHealthJson.getString("status");
                //两个都不接受咨询时,无法咨询
                if ("0".equals(doctorStatus) && "0".equals(doctorHealthStatus)){
                    json.put("status", "0");
                    json.put("msg", "医生不接受咨询");
                }
                //两个其中有一个可以咨询时都可以咨询
                if ("1".equals(doctorStatus) || "1".equals(doctorHealthStatus)){
                    json.put("status", "1");
                    json.put("msg", "医生当前接受咨询");
                }
                //如果全科和健管师都不在时间范围
                if ("2".equals(doctorStatus) && "2".equals(doctorHealthStatus)){
                    json.put("status","2");
                    json.put("msg","全科医生和健管师当前都不在工作时间");
                }
                //健管师在工作时间,全科不在
                if ("2".equals(doctorStatus) && "1".equals(doctorHealthStatus)){
                    json.put("status","3");
                    json.put("msg","全科医生当前不在工作时间");
                }
                //全科在工作时间,健管师不在
                if ("1".equals(doctorStatus) && "2".equals(doctorHealthStatus)){
                    json.put("status","4");
                    json.put("msg","健管师当前不在工作时间");
                }
            }
        }
        json = doctorWork(doctor,week,calendar);
        return json;
    }

+ 44 - 12
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/im/imController.java

@ -34,7 +34,7 @@ public class imController extends BaseController {
    @Autowired
    private ConsultDao consultDao;
    @Autowired
    private ImUtill ImUtill;
    private ImUtill imUtill;
    /**
     * 获取单个咨询
@ -46,7 +46,7 @@ public class imController extends BaseController {
    @ResponseBody
    public String getTopic(String consult) {
        try {
            return success(ImUtill.getTopic(consult).get("data").toString());
            return success(imUtill.getTopic(consult).get("data").toString());
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
@ -74,7 +74,7 @@ public class imController extends BaseController {
            if (StringUtils.isEmpty(doctor)) {
                doctor = getUID();
            }
            String consult = ImUtill.getTeamConsultByStatus(doctor,adminTeamCode, status, reply, page, pagesize);
            String consult = imUtill.getTeamConsultByStatus(doctor,adminTeamCode, status, reply, page, pagesize);
            JSONArray jsonArray = new JSONArray(consult);
            Iterator<Object> it = jsonArray.iterator();
            List list = new ArrayList();
@ -146,9 +146,9 @@ public class imController extends BaseController {
            }
            String consult = null;
            if(type==null){
                consult = ImUtill.getConsultByStatus(doctor, status, reply, page, pagesize);
                consult = imUtill.getConsultByStatus(doctor, status, reply, page, pagesize);
            }else {
                consult = ImUtill.getConsultByStatusAndType(doctor, status, reply,type,patientName,startTime,endTime, page, pagesize);
                consult = imUtill.getConsultByStatusAndType(doctor, status, reply,type,patientName,startTime,endTime, page, pagesize);
            }
            JSONArray jsonArray = new JSONArray(consult);
            Iterator<Object> it = jsonArray.iterator();
@ -220,7 +220,7 @@ public class imController extends BaseController {
            }
            String consult = null;
            consult = ImUtill.getConsultCountByStatusAndType(doctor, status, reply,type,patientName,startTime,endTime);
            consult = imUtill.getConsultCountByStatusAndType(doctor, status, reply,type,patientName,startTime,endTime);
            JSONObject json = new JSONObject(consult);
            return write(200, "查询成功", "total", json.getInt("count"));
        } catch (Exception e) {
@ -229,6 +229,38 @@ public class imController extends BaseController {
        }
    }
    /**
     * 获取医生统计数据
     * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
     *
     * @return
     */
    @RequestMapping(value = "/consult/getDoctorData", method = RequestMethod.GET)
    @ResponseBody
    public String getDoctorData() {
        try {
            String uid = getUID();
            JSONObject json = new JSONObject();
//                未回复
            String totalUnReply = imUtill.getConsultData(uid,null, 0, 0);
            int unReply = Integer.parseInt(totalUnReply);
//                已回复
            String totalReply = imUtill.getConsultData(uid,null, 0, 1);
            String totalReply1 = imUtill.getConsultData(uid,null, 10, null);
            int reply = Integer.parseInt(totalReply) + Integer.parseInt(totalReply1);
//                总咨询量
            String totalConsult = imUtill.getConsultData(uid, null,null, null);
            int consult = Integer.parseInt(totalConsult);
            json.put("totalUnReply", unReply);
            json.put("totalReply", reply);
            json.put("totalConsult", consult);
            return write(200, "查询成功", "data", json);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
    /**
     * 获取团队统计数据
     * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
@ -257,16 +289,16 @@ public class imController extends BaseController {
                map.put("doctor", doctor);
                map.put("type", doc.get("level") == null ? "" : doc.get("level").toString());
//                未回复
                String totalUnReply = ImUtill.getConsultData(doctor,adminTeamCode, 0, 0);
                String totalUnReply = imUtill.getConsultData(doctor,adminTeamCode, 0, 0);
                int unReply = Integer.parseInt(totalUnReply);
                map.put("totalUnReply", unReply);
//                已回复
                String totalReply = ImUtill.getConsultData(doctor,adminTeamCode, 0, 1);
                String totalReply1 = ImUtill.getConsultData(doctor,adminTeamCode, 10, null);
                String totalReply = imUtill.getConsultData(doctor,adminTeamCode, 0, 1);
                String totalReply1 = imUtill.getConsultData(doctor,adminTeamCode, 10, null);
                int reply = Integer.parseInt(totalReply) + Integer.parseInt(totalReply1);
                map.put("totalReply", reply);
//                总咨询量
                String totalConsult = ImUtill.getConsultData(doctor, adminTeamCode,null, null);
                String totalConsult = imUtill.getConsultData(doctor, adminTeamCode,null, null);
                int consult = Integer.parseInt(totalConsult);
                map.put("totalConsult", consult);
@ -325,12 +357,12 @@ public class imController extends BaseController {
            participants.put(getUID(), 0);
            Doctor d = doctorDao.findByCode(getUID());
            //创建医生会话讨论组
            JSONObject sessionObj = ImUtill.createSession(participants, ImUtill.SESSION_TYPE_P2P, d.getName() + "发来消息提醒", "");
            JSONObject sessionObj = imUtill.createSession(participants, ImUtill.SESSION_TYPE_P2P, d.getName() + "发来消息提醒", "");
            if (sessionObj.getInt("status") == -1) {
                throw new RuntimeException(sessionObj.getString("message"));
            }
            JSONObject session = sessionObj.getJSONObject("data");
            ImUtill.sendImMsg(getUID(), d.getName(), session.getString("id"), "1", content, "REMAIN");
            imUtill.sendImMsg(getUID(), d.getName(), session.getString("id"), "1", content, "REMAIN");
            return success("提醒成功!");
        } catch (Exception e) {
            error(e);

+ 7 - 7
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java

@ -268,13 +268,13 @@ public class DoctorConsultController extends WeixinBaseController {
                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());
                    }
                }
//                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);

+ 28 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/account/PatientController.java

@ -1,12 +1,14 @@
package com.yihu.wlyy.web.patient.account;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.concern.ConcernDO;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.SignFamilyServer;
import com.yihu.wlyy.entity.security.Token;
import com.yihu.wlyy.repository.concern.ConcernDao;
import com.yihu.wlyy.repository.patient.SignFamilyServerDao;
import com.yihu.wlyy.repository.security.TokenDao;
import com.yihu.wlyy.service.app.account.PatientInfoService;
@ -40,6 +42,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.yihu.wlyy.entity.patient.prescription.PrescriptionLog.PrescriptionLogType.sf;
/**
 * 患者帳戶信息的Controller.
 *
@ -76,6 +80,8 @@ public class PatientController extends WeixinBaseController {
    private WeiXinTagUtil weiXinTagUtil;
    @Autowired
    private RSAUtils rsaUtils;
    @Autowired
    private ConcernDao concernDao;
    /**
     * 患者基本信息查询接口
@ -730,6 +736,28 @@ public class PatientController extends WeixinBaseController {
        }
    }
    /**
     * 查询患者是否关注了医生
     *
     * @return
     */
    @RequestMapping(value = "is_concern")
    @ResponseBody
    @ApiOperation("查询患者是否关注了医生")
    public String is_concern(@ApiParam(name = "doctor", value = "医生编码", defaultValue = "350200")
                             @RequestParam(value = "doctor", required = true) String doctor) {
        try {
            ConcernDO concernDO = concernDao.findByPatientAndDoctor(getRepUID(),doctor);
            if (sf != null) {
                return write(200, "获取关注状态成功!", "data", concernDO.getStatus());
            }
            return write(200, "获取关注状态成功!", "data", -1);
        } catch (Exception e) {
            error(e);
            return error(-1, " !");
        }
    }
    /**
     * 查询患者身份证号
     *

+ 110 - 190
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java

@ -50,7 +50,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * 患者端:三师咨询控制类
@ -83,9 +82,9 @@ public class ConsultController extends WeixinBaseController {
    @Autowired
    private PrescriptionDiagnosisService prescriptionDiagnosisService;
    @Autowired
    private CommonUtil CommonUtil;
    private CommonUtil commonUtil;
    @Autowired
    private ImUtill ImUtill;
    private ImUtill imUtill;
    @Autowired
    private HttpUtil httpUtil;
    @Autowired
@ -228,17 +227,16 @@ public class ConsultController extends WeixinBaseController {
    }
    /**
     * 患者端在发起家庭医生咨询时检查全科医生和健管师是否在工作
     * 患者端在发起医生咨询时检查医生工作
     * @param doctor
     * @param healthDoctor
     * @return
     */
    @RequestMapping(value = "isDoctorWorkWhenconsult",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("全科医生和健管师是否在工作")
    public String isDoctorWorkWhenconsult(String doctor,String healthDoctor) {
    @ApiOperation("医生是否在工作")
    public String isDoctorWorkWhenconsult(String doctor) {
        try {
            JSONObject result = doctorWorkTimeService.isDoctorWorkingWhenConsult(doctor,healthDoctor);
            JSONObject result = doctorWorkTimeService.isDoctorWorkingWhenConsult(doctor);
            return write(200, result.getString("msg"), "data", result.getString("status"));
        } catch (Exception e) {
            error(e);
@ -331,27 +329,27 @@ public class ConsultController extends WeixinBaseController {
    /**
     * 三师咨询添加接口
     * 咨询添加接口
     *
     * @param type     咨询类型:1三师咨询,2家庭医生咨询
     * @param type     咨询类型:1关注咨询
     * @param when     发病时间
     * @param symptoms 主要症状
     * @param images   图片URL地址,多图以逗号分隔
     * @param voice    语音URL地址
     * @param doctor   咨询医生code
     * @return
     */
    @RequestMapping(value = "add")
    @ResponseBody
    @ApiOperation("三师咨询添加接口")
    @ApiOperation("咨询添加接口")
    public String add(@RequestParam(required = false) Integer type,
                      @RequestParam(required = false) String when,
                      @RequestParam String symptoms,
                      @RequestParam(required = true) String symptoms,
                      @RequestParam(required = false) String images,
                      @RequestParam(required = false) String voice,
                      @RequestParam(required = true) String doctor,
                      @RequestParam(required = false) Long guidance) {
        try {
            System.out.println("guidance1="+guidance);
            System.out.println("symptoms="+symptoms);
            if (type == null) {
                type = 1;
            }
@ -364,16 +362,16 @@ public class ConsultController extends WeixinBaseController {
            }
            // 将临时图片拷贝到正式存储路径下
            if (StringUtils.isNotEmpty(images)) {
                images = CommonUtil.copyTempImage(images);
                images = commonUtil.copyTempImage(images);
            }
            if (StringUtils.isEmpty(voice)) {
                voice = fetchWxVoices();
            }
            if (StringUtils.isNotEmpty(voice)) {
                voice = CommonUtil.copyTempVoice(voice);
                voice = commonUtil.copyTempVoice(voice);
            }
            ConsultTeam consult = new ConsultTeam();
            // 设置咨询类型:1三师咨询,2家庭医生咨询  6.名医咨询
            // 设置咨询类型:1 关注咨询
            consult.setType(type);
            // 设置发病时间
            consult.setWhen(when);
@ -388,85 +386,40 @@ public class ConsultController extends WeixinBaseController {
                consult.setGuidance(guidance);
            }
            System.out.println("guidance2="+guidance);
            // 保存到数据库
            int res = 0;
            JSONArray dts = null;
            synchronized (getRepUID().intern()){//新增同步方法。设备保存写在service层但是不生效,写在controller层才生效
                JSONObject re = consultTeamService.addTeamConsult(consult, getRepUID(),getUID());
            synchronized (getRepUID().intern()){
                JSONObject re = consultTeamService.addTeamConsult(consult, getRepUID(),getUID(),doctor);
                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, "还有咨询未结束,不允许再次提交咨询!");
            }
//            Doctor doctor = doctorService.findDoctorByCode(consult.getDoctor());
            //创建咨询讨论组
            // JSONObject jo= talkGroupService.createConsultTalkGroup(consult.getDoctor(), doctor.getName(), doctor.getHospital(), doctor.getHospitalName(),
            //        consult.getPatient(), consult.getName(), consult.getConsult());
            // consult.setGroupCode(jo.getString("groupCode"));
            //更新讨论组
            //consultTeamService.save(consult);
            // 添加到统计队列
            if (consult.getType() == 2) {
            if (consult.getType() == 1) {
                DoctorStatisticsTask.getInstance(doctorStatisticsService).put(consult.getDoctor(), 1, 1, 0);
            }
            // 推送消息给医生
            if(dts==null||dts.length()==0){
                if(messageService.getMessageNoticeSettingByMessageType(consult.getDoctor(),"1", MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue())){
                    pushMsgTask.put(consult.getDoctor(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.D_CT_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.指定咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.您有新的指定咨询.name(), consult.getConsult());
                    Doctor doctor = doctorDao.findByCode(consult.getDoctor());
                    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", "请进入手机APP查看"));
                        String sex = consult.getSex()==1? "男" : "女";
                        String keywords = consult.getName() + "," + sex;
                        params.add(new BasicNameValuePair("keywords", keywords));
                        httpClientUtil.post(url, params, "UTF-8");
                    }
                }
            }else {
                for (int i=0;i<dts.length();i++){
                    String doctorCode = dts.getString(i);
                    Boolean flag = true;
                    if(consult.getDoctor().equals(doctorCode)){
                        //健管
                        flag = messageService.getMessageNoticeSettingByMessageType(doctorCode,"1", MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue());
                    }else {
                        //全科
                        flag = !messageService.getMessageNoticeSettingByMessageType(doctorCode,"1", MessageNoticeSetting.MessageTypeEnum.familyTopicSwitch.getValue());
                    }
                    if(flag){
                        pushMsgTask.put(doctorCode, 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(doctorCode);
                        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", "请进入手机APP查看"));
                            String sex = consult.getSex()==1? "男" : "女";
                            String keywords = consult.getName() + "," + sex;
                            params.add(new BasicNameValuePair("keywords", keywords));
                            httpClientUtil.post(url, params, "UTF-8");
                        }
                    }
                }
            if(messageService.getMessageNoticeSettingByMessageType(consult.getDoctor(),"1", MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue())){
                pushMsgTask.put(consult.getDoctor(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.D_CT_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.指定咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.您有新的指定咨询.name(), consult.getConsult());
//                医生助手代码,暂时不做
//                Doctor d = doctorDao.findByCode(consult.getDoctor());
//                if (d!=null && StringUtils.isNotEmpty(d.getOpenid())){
//                    String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
//                    List<NameValuePair> params = new ArrayList<>();
//                    params.add(new BasicNameValuePair("type", "4"));
//                    params.add(new BasicNameValuePair("openId", d.getOpenid()));
//                    params.add(new BasicNameValuePair("url", targetUrl));
//                    params.add(new BasicNameValuePair("first", d.getName() + "医生您好,有患者向您发起咨询"));
//                    params.add(new BasicNameValuePair("remark", "请进入手机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));
@ -532,16 +485,16 @@ public class ConsultController extends WeixinBaseController {
            }
            // 将临时图片拷贝到正式存储路径下
            if (StringUtils.isNotEmpty(images)) {
                images = CommonUtil.copyTempImage(images);
                images = commonUtil.copyTempImage(images);
            }
            if (StringUtils.isEmpty(voice)) {
                voice = fetchWxVoices();
            }
            if (StringUtils.isNotEmpty(voice)) {
                voice = CommonUtil.copyTempVoice(voice);
                voice = commonUtil.copyTempVoice(voice);
            }
            //判断是否已经存在还没有关闭的咨询
            if (consultTeamService.isExistConsult(getRepUID(), doctorCode)) {
            if (consultTeamService.isExistConsult(getRepUID(),6, doctorCode)) {
                return error(-1, "还有咨询未结束,不允许再次提交咨询!");
            }
            ConsultTeam consult = new ConsultTeam();
@ -800,7 +753,7 @@ public class ConsultController extends WeixinBaseController {
                JSONObject obj = new JSONObject();
                // 将临时语音拷贝到正式存储路径下
                if (StringUtils.isNotEmpty(path)) {
                    content = CommonUtil.copyTempVoice(path);
                    content = commonUtil.copyTempVoice(path);
                    obj.put("path", content);
                    obj.put("times", times);
                    content = obj.toString();
@ -817,7 +770,7 @@ public class ConsultController extends WeixinBaseController {
                content = fetchWxImages();
                // 将临时图片拷贝到正式存储路径下
                if (StringUtils.isNotEmpty(content)) {
                    content = CommonUtil.copyTempImage(content);
                    content = commonUtil.copyTempImage(content);
                }
                if (StringUtils.isEmpty(content)) {
                    return error(-1, "图片上传失败!");
@ -843,15 +796,13 @@ public class ConsultController extends WeixinBaseController {
                arr = new String[]{content};
            }
//            Patient patient = patientDao.findByCode(getUID());
            Patient patient = patientDao.findByCode(getRepUID());
            int i = 0;
            List<String> failed = new ArrayList<>();
            String agent = getUID()==getRepUID()?null:getUID();
            for (ConsultTeamLog log : logs) {
//                String response = ImUtill.sendTopicIM(getUID(), patient.getName(), consult, String.valueOf(log.getType()), log.getContent());
                String response = ImUtill.sendTopicIM(getRepUID(), patient.getName(), consult, String.valueOf(log.getType()), log.getContent(),agent);
                String response = imUtill.sendTopicIM(getRepUID(), patient.getName(), consult, String.valueOf(log.getType()), log.getContent(),agent);
                if (StringUtils.isNotEmpty(response)) {
                    JSONObject resObj = new JSONObject(response);
@ -859,101 +810,70 @@ public class ConsultController extends WeixinBaseController {
                        return invalidUserException(new RuntimeException(resObj.getString("message")), -1, "追问失败!" + resObj.getString("message"));
                    }
                    failed.add(String.valueOf(resObj.get("data")));
                    try {
                         /*if(messageService.getMessageNoticeSettingByMessageType(consultModel.getDoctor(),"1",MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue())){
                            //            新增发送医生助手模板消息 v1.4.0 by wujunjie
                            Doctor doctor = doctorDao.findByCode(consultModel.getDoctor());
                            String doctorOpenID = doctor.getOpenid();
                            if (StringUtils.isNotEmpty(doctorOpenID)) {
                                String title = "";
                                Consult consultSingle = consultDao.findByCode(log.getConsult());
                                if (consultSingle!=null){
                                    Integer singleType = consultSingle .getType();
                                    if (singleType != null && singleType ==8 ){
                                        title = consultSingle.getTitle();
                                    }else if(singleType != null && singleType !=8 ){
                                        title = consultSingle.getSymptoms();
                                    }
                                    String repContent = parseContentType(type+"",content);
                                    String first = "居民" +patient.getName()+"的健康咨询有新的回复。";
                                    String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
                                    List<NameValuePair> params = new ArrayList<>();
                                    params.add(new BasicNameValuePair("type", "8"));
                                    params.add(new BasicNameValuePair("openId", doctorOpenID));
                                    params.add(new BasicNameValuePair("url", targetUrl));
                                    params.add(new BasicNameValuePair("first",  first));
                                    params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
                                    String keywords = title + "," + repContent +","+ doctor.getName();
                                    params.add(new BasicNameValuePair("keywords", keywords));
                                    httpClientUtil.post(url, params, "UTF-8");
                                }
                            }
                        }*/
                        String sql = "";
                        if (consultModel.getType() == 2){
                            //家庭咨询
                            sql = "SELECT t.participant_id FROM " + im +
                                    ".participants t where t.session_id = '" +
                                    patient.getCode() + "_" + consultModel.getTeam() + "_" + consultModel.getType() +
                                    "' and t.participant_role = 0";
                         }else if (consultModel.getType() == 8){
                            //续方咨询
                            sql = "SELECT t.participant_id FROM " + im +
                                    ".participants t where t.session_id = '" +
                                    patient.getCode() + "_" + consultModel.getConsult() + "_" + consultModel.getType() +
                                    "' and t.participant_role = 0";
                         }
                        List<Map<String, Object>> participants = jdbcTemplate.queryForList(sql);
                        for (Map<String, Object> participant : participants) {
//                          //有居民、健管、全科
                            String doctorCode = participant.get("participant_id").toString();
                            if (doctorCode.equals(patient.getCode())) {
                                continue;
                            }
                            //健管
                            Boolean flag = messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue());
                            //全科
//                            Boolean flag2 = !messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.familyTopicSwitch.getValue());
                            if (flag) {
                                //            新增发送医生助手模板消息 v1.4.0 by wujunjie
                                Doctor doctor = doctorDao.findByCode(doctorCode);
                                String doctorOpenID = doctor.getOpenid();
                                if (StringUtils.isNotEmpty(doctorOpenID)) {
                                    String title = "";
                                    Consult consultSingle = consultDao.findByCode(log.getConsult());
                                    if (consultSingle != null) {
                                        Integer singleType = consultSingle.getType();
                                        if (singleType != null && singleType == 8) {
                                            title = consultSingle.getTitle();
                                        } else if (singleType != null && singleType != 8) {
                                            title = consultSingle.getSymptoms();
                                        }
                                        String repContent = parseContentType(type + "", content);
                                        String first = "居民" + patient.getName() + "的健康咨询有新的回复。";
                                        String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
                                        List<NameValuePair> params = new ArrayList<>();
                                        params.add(new BasicNameValuePair("type", "8"));
                                        params.add(new BasicNameValuePair("openId", doctorOpenID));
                                        params.add(new BasicNameValuePair("url", targetUrl));
                                        params.add(new BasicNameValuePair("first", first));
                                        params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
                                        String keywords = title + "," + repContent + "," + doctor.getName();
                                        params.add(new BasicNameValuePair("keywords", keywords));
                                        httpClientUtil.post(url, params, "UTF-8");
                                        System.out.println("发送对象:"+doctorCode);
                                        System.out.println("发送对象名字:"+doctor.getName());
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
//                    try {
//                        String sql = "";
//                        if (consultModel.getType() == 2){
//                            //家庭咨询
//                            sql = "SELECT t.participant_id FROM " + im +
//                                    ".participants t where t.session_id = '" +
//                                    patient.getCode() + "_" + consultModel.getTeam() + "_" + consultModel.getType() +
//                                    "' and t.participant_role = 0";
//                         }else if (consultModel.getType() == 8){
//                            //续方咨询
//                            sql = "SELECT t.participant_id FROM " + im +
//                                    ".participants t where t.session_id = '" +
//                                    patient.getCode() + "_" + consultModel.getConsult() + "_" + consultModel.getType() +
//                                    "' and t.participant_role = 0";
//                         }
//
//                        List<Map<String, Object>> participants = jdbcTemplate.queryForList(sql);
//
//                        for (Map<String, Object> participant : participants) {
////                          //有居民、健管、全科
//                            String doctorCode = participant.get("participant_id").toString();
//                            if (doctorCode.equals(patient.getCode())) {
//                                continue;
//                            }
//                            //健管
//                            Boolean flag = messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue());
//                            //全科
////                            Boolean flag2 = !messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.familyTopicSwitch.getValue());
//                            if (flag) {
//                                //            新增发送医生助手模板消息 v1.4.0 by wujunjie
//                                Doctor doctor = doctorDao.findByCode(doctorCode);
//                                String doctorOpenID = doctor.getOpenid();
//                                if (StringUtils.isNotEmpty(doctorOpenID)) {
//                                    String title = "";
//                                    Consult consultSingle = consultDao.findByCode(log.getConsult());
//                                    if (consultSingle != null) {
//                                        Integer singleType = consultSingle.getType();
//                                        if (singleType != null && singleType == 8) {
//                                            title = consultSingle.getTitle();
//                                        } else if (singleType != null && singleType != 8) {
//                                            title = consultSingle.getSymptoms();
//                                        }
//                                        String repContent = parseContentType(type + "", content);
//                                        String first = "居民" + patient.getName() + "的健康咨询有新的回复。";
//                                        String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
//                                        List<NameValuePair> params = new ArrayList<>();
//                                        params.add(new BasicNameValuePair("type", "8"));
//                                        params.add(new BasicNameValuePair("openId", doctorOpenID));
//                                        params.add(new BasicNameValuePair("url", targetUrl));
//                                        params.add(new BasicNameValuePair("first", first));
//                                        params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
//                                        String keywords = title + "," + repContent + "," + doctor.getName();
//                                        params.add(new BasicNameValuePair("keywords", keywords));
//
//                                        httpClientUtil.post(url, params, "UTF-8");
//                                        System.out.println("发送对象:"+doctorCode);
//                                        System.out.println("发送对象名字:"+doctor.getName());
//                                    }
//                                }
//                            }
//                        }
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
                }
            }
@ -981,7 +901,7 @@ public class ConsultController extends WeixinBaseController {
            if (consultModel == null) {
                return error(-1, "咨询记录不存在!");
            }
            JSONObject messageObj = ImUtill.getTopicMessage(consultModel.getConsult(), consultModel.getStartMsgId(), consultModel.getEndMsgId(), page, pagesize, getRepUID());
            JSONObject messageObj = imUtill.getTopicMessage(consultModel.getConsult(), consultModel.getStartMsgId(), consultModel.getEndMsgId(), page, pagesize, getRepUID());
            //过滤续签
            consultTeamService.removeRenewPerson(messageObj,getRepUID());
@ -1004,7 +924,7 @@ public class ConsultController extends WeixinBaseController {
    @ApiOperation("网络咨询咨询日志查询")
    public String logs(@RequestParam String sessionId,@RequestParam(required = false) String startMsgId,@RequestParam(required = false) String endMsgId, @RequestParam int page, @RequestParam int pagesize) {
        try {
            JSONArray messageArray = ImUtill.getSessionMessage(sessionId, startMsgId, endMsgId, page, pagesize, getRepUID());
            JSONArray messageArray = imUtill.getSessionMessage(sessionId, startMsgId, endMsgId, page, pagesize, getRepUID());
            return write(200, "查询成功", "list", messageArray);
        } catch (Exception e) {
            error(e);
@ -1016,7 +936,7 @@ public class ConsultController extends WeixinBaseController {
    @ResponseBody
    public String participants(@RequestParam String sessionId) {
        try {
            JSONArray participants = ImUtill.getSessions(sessionId);
            JSONArray participants = imUtill.getSessions(sessionId);
            //过滤续签
            consultTeamService.removeRenewPerson(participants,getRepUID());
@ -1139,7 +1059,7 @@ public class ConsultController extends WeixinBaseController {
    @ResponseBody
    public String getTopic(String consult){
        try{
            return success(ImUtill.getTopic(consult).get("data").toString());
            return success(imUtill.getTopic(consult).get("data").toString());
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());