Переглянути джерело

Merge branch 'dev' of linzhuo/patient-co-management into dev

lyr 8 роки тому
батько
коміт
d635e18949
19 змінених файлів з 670 додано та 247 видалено
  1. 5 1
      patient-co-wlyy/pom.xml
  2. 6 6
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/consult/ConsultTeam.java
  3. 3 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java
  4. 27 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultService.java
  5. 262 34
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java
  6. 5 2
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyService.java
  7. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/message/MessageService.java
  8. 11 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java
  9. 6 6
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/PatientRemindService.java
  10. 6 2
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/guahao/GuahaoXMService.java
  11. 9 13
      patient-co-wlyy/src/main/java/com/yihu/wlyy/util/HttpUtil.java
  12. 171 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ImUtill.java
  13. 6 7
      patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SendP2PUtil.java
  14. 27 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SendPatientUtil.java
  15. 24 4
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/FileUploadController.java
  16. 65 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java
  17. 4 2
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java
  18. 19 3
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthGuidanceController.java
  19. 13 165
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java

+ 5 - 1
patient-co-wlyy/pom.xml

@ -197,7 +197,11 @@
            <version>${sitemesh.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>it.sauronsoftware.cron4j</groupId>
            <artifactId>cron4j</artifactId>
            <version>2.2.5</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>

+ 6 - 6
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/consult/ConsultTeam.java

@ -44,9 +44,9 @@ public class ConsultTeam extends IdEntity {
	private Long guidance;   //关联指导
	private String doctorName;//醫生名字
	//起始消息id
	private Integer startMsgId;
	private String startMsgId;
	//结束消息id
	private Integer endMsgId;
	private String endMsgId;
	// 结束人
	private String endOperator;
	// 结束人类型
@ -256,19 +256,19 @@ public class ConsultTeam extends IdEntity {
	}
	public Integer getStartMsgId() {
	public String getStartMsgId() {
		return startMsgId;
	}
	public void setStartMsgId(Integer startMsgId) {
	public void setStartMsgId(String startMsgId) {
		this.startMsgId = startMsgId;
	}
	public Integer getEndMsgId() {
	public String getEndMsgId() {
		return endMsgId;
	}
	public void setEndMsgId(Integer endMsgId) {
	public void setEndMsgId(String endMsgId) {
		this.endMsgId = endMsgId;
	}

+ 3 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java

@ -45,6 +45,9 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
    @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.type = 2 and a.status >= 0")
    SignFamily findByDoctorPatient(String doctor, String patient);
    @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and (a.type = 2 or a.type=1) and a.status >= 0")
    List<SignFamily> findSSandFamilyByDoctorPatient(String doctor, String patient);
    @Query("select a from SignFamily a where a.doctorHealth = ?1 and a.patient = ?2 and a.type = 2 and a.status >= 0 ")
    SignFamily findByDoctorHealthPatient(String doctor, String patient);

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

@ -1,7 +1,11 @@
package com.yihu.wlyy.service.app.consult;
import java.util.Date;
import java.util.List;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.util.SendPatientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@ -46,6 +50,9 @@ public class ConsultService extends BaseService {
	@Autowired
	public ConsultCommunicationReplyDao consultCommunicationReplyDao;
	@Autowired
	private SignFamilyDao signFamilyDao;
	/**
	 * 添加一条咨询记录
	 * @param patient 患者信息
@ -103,4 +110,24 @@ public class ConsultService extends BaseService {
	public Consult findOneConsult(String consult) {
		return consultDao.findByCode(consult);
	}
	public void sendMucMessageBySingnType(String doctor,String doctorName,String patient,String  content,String contentType,String title){
		//add by linz 增加签约关系查询,
		List<SignFamily> sfList = signFamilyDao.findSSandFamilyByDoctorPatient(doctor, doctorName);
		int type = 2;
		if(sfList!=null&&sfList.size()==1){
			//只存在一种签约关系
			type = sfList.get(0).getType();
		}else if(sfList!=null&&sfList.size()==2){
			//两种签约关系直接取家庭签约
			type = 2;
		}else{
			//没找到签约关系
			type=0;
		}
		if(type!=0){
			SendPatientUtil.sendToPatient(doctor,doctorName,patient, contentType, content,title,type+"");
		}
	}
}

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

@ -28,9 +28,7 @@ import com.yihu.wlyy.repository.doctor.DoctorTeamMemberDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.health.PatientHealthGuidanceService;
import com.yihu.wlyy.service.app.talk.TalkGroupService;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.HttpUtil;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.util.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
@ -53,7 +51,8 @@ import org.springside.modules.persistence.SearchFilter.Operator;
import org.springside.modules.utils.Clock;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.MessageType;
import javax.print.Doc;
/**
 * 網絡諮詢类.
@ -88,6 +87,8 @@ public class ConsultTeamService extends ConsultService {
    private PatientHealthGuidanceService guidanceService;
    @Autowired
    private TalkGroupService talkGroupService;
    @Autowired
    private com.yihu.wlyy.service.common.account.DoctorService doctorService;
    /**
     * 查询患者是否还有未结束的三师咨询
@ -658,6 +659,7 @@ public class ConsultTeamService extends ConsultService {
     * @throws Exception
     */
    public int addTeamConsult(ConsultTeam ct, String patient) throws Exception {
        JSONObject users = new JSONObject();
        // 咨询三师
        if (ct.getType() == 1) {
            // 查询三师签约信息
@ -671,13 +673,20 @@ public class ConsultTeamService extends ConsultService {
            //查找病人所在的团队
            DoctorTeam doctorTeam = doctorTeamDao.findBySanshiParientCode(patient);
            //得到团队的健康管理师
            DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(), 3);
            if (doctorTeamMember == null) {
                doctorTeamMember = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(), 2);
            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){
                    users.put(doctorTeamMember.getMemberCode(),1);
                }
                ct.setDoctor(doctorTeamMemberHealthy.getMemberCode());
            }
            // 设置家庭医生
            ct.setDoctor(doctorTeamMember.getMemberCode());
            ct.setAdminTeamId(sc.getAdminTeamId());
        } else if (ct.getType() == 2) {
            // 咨询家庭医生
@ -690,14 +699,19 @@ public class ConsultTeamService extends ConsultService {
            //查找病人所在的团队
            DoctorTeam doctorTeam = doctorTeamDao.findByParientCode(patient);
            //得到团队的健康管理师
            DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 3);
            if (doctorTeamMember == null) {
                doctorTeamMember = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 2);
            DoctorTeamMember doctorTeamMemberHealthy = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 3);
            DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 2);
            if (doctorTeamMemberHealthy == null) {
                ct.setDoctor(doctorTeamMember.getMemberCode());
                users.put(doctorTeamMemberHealthy.getMemberCode(),0);
            }else{
                users.put(doctorTeamMemberHealthy.getMemberCode(),0);
                if(doctorTeamMember!=null){
                    users.put(doctorTeamMember.getMemberCode(),1);
                }
                ct.setDoctor(doctorTeamMemberHealthy.getMemberCode());
            }
            ct.setTeam(sf.getTeamCode());
            // 设置家庭医生
            ct.setDoctor(doctorTeamMember.getMemberCode());
            ct.setAdminTeamId(sf.getAdminTeamId());
        }
        // 设置患者信息
@ -733,23 +747,14 @@ public class ConsultTeamService extends ConsultService {
        cd.setTo(ct.getDoctor());
        // 添加医生咨询日志
        String content = addLogs(ct);
        //推送给IM文字消息
        String returnJson = sendIM(ct.getPatient(), ct.getDoctor(), "6", content);
        JSONObject jo = new JSONObject(returnJson);
        if (jo.has("startId")) {
            //设置消息ID
            ct.setStartMsgId(jo.getInt("startId"));
            //推送给IM图片
            if (StringUtils.isNotEmpty(ct.getImages())) {
                String[] images = ct.getImages().split(",");
                for (String image : images) {
                    if (StringUtils.isNoneEmpty(image)) {
                        sendIM(ct.getPatient(), ct.getDoctor(), "2", image);
                    }
                }
            }
        //推送给IM去创建议题,取得成员消息
        JSONObject messages  = ImUtill.getCreateTopicMessage(patient,tempPatient.getName(),consult.getTitle(),consult.getSymptoms(),consult.getImages());
        users.put(patient,0);
        JSONObject obj  = ImUtill.createTopics(patient+"_consult_"+ct.getType(),consult.getCode(),"咨询问题:"+consult.getSymptoms(),users,messages,"1");
        if(obj==null){
            throw new RuntimeException("IM消息结束异常!");
        }
        ct.setStartMsgId(obj.get("start_msg_id").toString());
        consultTeamDao.save(ct);
        consultDao.save(consult);
        consultTeamDoctorDao.save(cd);
@ -949,7 +954,7 @@ public class ConsultTeamService extends ConsultService {
            throw new Exception("send consult finished IM message failed");
        } else {
            JSONObject jo = new JSONObject(returnJson);            //设置消息ID
            consultTeam.setEndMsgId(jo.getInt("startId"));
            consultTeam.setEndMsgId(jo.getInt("startId")+"");
            consultTeam.setEndOperator(endOperator);
            consultTeam.setEndType(endType);
        }
@ -1212,7 +1217,7 @@ public class ConsultTeamService extends ConsultService {
        ;
        JSONObject jo = new JSONObject(returnJson);
        //设置消息ID
        ct.setStartMsgId(jo.getInt("startId"));
        ct.setStartMsgId(jo.getInt("startId")+"");
        //推送给IM图片
        if (StringUtils.isNotEmpty(ct.getImages())) {
            String[] images = ct.getImages().split(",");
@ -1345,7 +1350,7 @@ public class ConsultTeamService extends ConsultService {
            sendIM(ct.getPatient(), ct.getDoctor(), "6", content);
        jo = new JSONObject(returnJson);
        //设置消息ID
        ct.setStartMsgId(jo.getInt("startId"));
        ct.setStartMsgId(jo.getInt("startId")+"");
        //推送给IM图片
        if (StringUtils.isNotEmpty(ct.getImages())) {
            String[] images = ct.getImages().split(",");
@ -1429,4 +1434,227 @@ public class ConsultTeamService extends ConsultService {
    public List findByTeam(String consult){
        return consultTeamDao.findByTeamAndType(consult, 10);
    }
    /**
     * 全科医生求助专科医生(同团队)
     * @param ct
     * @param uid
     * @param oldConsultCode
     */
    public void addSeekHelpTeam(ConsultTeam ct, String uid,String oldConsultCode){
        ct.setPatient(uid);
        //推送给IM文字消息
        JSONObject participants = new JSONObject();
        participants.put(ct.getPatient(),0);
        participants.put(ct.getDoctor(),0);
        Doctor doctor = doctorService.findDoctorByCode(uid);
        JSONObject sessionJson =  ImUtill.createSession(participants,"2",doctor.getName()+"发起求助!","");
        if(sessionJson.getInt("status")==-1){
            throw  new RuntimeException(sessionJson.getString("message"));
        }
        JSONObject session = sessionJson.getJSONObject("data");
        if(StringUtils.isNotEmpty(oldConsultCode)){
            ConsultTeam oldConsult =  consultTeamDao.findByConsult(oldConsultCode);
            if(oldConsult!=null){
                ImUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"),"1","居民问题:" +oldConsult.getSymptoms());
                //推送给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);
                        }
                    }
                }
            }
        }
        ImUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"),"1","咨询问题:"+ ct.getSymptoms());
        //推送给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);
                }
            }
        }
    }
    /**
     * 全科医生求助专科医生(不同团队)
     * @param ct
     * @param uid
     * @param oldConsultCode
     */
    public void addSeekHelpOtherTeam(ConsultTeam ct, String uid,String oldConsultCode) throws Exception{
        // 设置患者信息
        ct.setPatient(uid);
        Doctor doctorTemp = doctorDao.findByCode(uid);
        // 设置医生姓名
        ct.setName(doctorTemp.getName());
        // 设置医生生日
        ct.setBirthday(doctorTemp.getBirthday());
        //新增性别
        ct.setSex(doctorTemp.getSex());
        // 设置医生头像
        ct.setPhoto(doctorTemp.getPhoto());
        // 设置操作日期
        ct.setCzrq(new Date());
        ct.setDel("1");
        ct.setStatus(0);
        // 医生未读数量为1
        ct.setDoctorRead(1);
        // 患者未读数量为0
        ct.setPatientRead(0);
        // 添加咨询记录
        Consult consult = addConsult(ct.getPatient(), null, ct.getSymptoms(), ct.getImages(), ct.getType());
        // 设置咨询标识
        ct.setConsult(consult.getCode());
        // 添加咨询转发记录
        ConsultTeamDoctor cd = new ConsultTeamDoctor();
        cd.setConsult(consult.getCode());
        cd.setDel("1");
        cd.setCzrq(new Date());
        cd.setTo(ct.getDoctor());
        // 添加医生咨询日志
        String content = addLogs(ct);
        JSONObject messages  = ImUtill.getCreateTopicMessage(doctorTemp.getCode(),doctorTemp.getName(),consult.getTitle(),content,consult.getImages());
        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,"2");
        if(obj==null||obj.getInt("status")==-1){
            throw new RuntimeException("im消息创建异常!"+obj==null?"":obj.getString("message"));
        }
        ct.setStartMsgId(obj.get("start_msg_id").toString());
        //转发咨询问题
        if(StringUtils.isNotBlank(oldConsultCode)){
            Consult oldConsult = consultDao.findByCode(oldConsultCode);
            if(oldConsult!=null){
                ImUtill.sendImMsg(doctorTemp.getCode(),doctorTemp.getName(),String.valueOf(jsonObject.hashCode()),"6",content);
                if(StringUtils.isNotBlank(oldConsult.getImages())){
                    String imgs[] = oldConsult.getImages().split(",");
                    for(String url :imgs)
                        ImUtill.sendImMsg(doctorTemp.getCode(),doctorTemp.getName(),String.valueOf(jsonObject.hashCode()),"2",url);
                }
            }
        }
        consultTeamDao.save(ct);  // 保存医生咨询信息
        consultTeamDoctorDao.save(cd);
        consultDao.save(consult);
    }
    public int finishConsult(String consult, String endOperator, int endType){
        ConsultTeam consultTeam = consultTeamDao.findByConsult(consult);
        String endName = "";
        String endId = "";
        //推送给IM文字消息
        if (endType == 1) {
            Patient p = patientDao.findByCode(endOperator);
            endName = p.getName();
            endId = p.getCode();
        } else {
            Doctor d = doctorDao.findByCode(endOperator);
            endId = d.getCode();
            endName = d.getName();
        }
        JSONObject obj = ImUtill.endTopics(consultTeam.getPatient(),endId,endName,consultTeam.getConsult());
        if(obj==null){
            throw new RuntimeException("IM消息结束异常!");
        }
        if(obj.getInt("status")==-1){
            throw new RuntimeException(obj.getString("message"));
        }
        consultTeam.setType(endType);
        consultTeam.setEndMsgId(obj.getString("id"));
        return consultTeamDao.updateStatusByConsult(consult);
    }
    /**
     * 新增名医咨询
     * @param ct
     * @param uid
     * @param type 1患者 2医生
     * @throws Exception
     */
    public void famousConsult(ConsultTeam ct, String uid, String type) throws Exception {
        // 设置患者信息
        ct.setPatient(uid);
        String senderId="";
        String senderName="";
        if ("1".equals(type)) {
            // 查询患者信息
            Patient tempPatient = patientDao.findByCode(uid);
            // 设置患者姓名
            ct.setName(tempPatient.getName());
            // 设置患者生日
            ct.setBirthday(tempPatient.getBirthday());
            //新增性别
            ct.setSex(tempPatient.getSex());
            // 设置患者头像
            ct.setPhoto(tempPatient.getPhoto());
            senderId = tempPatient.getCode();
            senderName = tempPatient.getName();
        } else if ("2".equals(type)) {
            Doctor doctorTemp = doctorDao.findByCode(uid);
            // 设置医生姓名
            ct.setName(doctorTemp.getName());
            // 设置医生生日
            ct.setBirthday(doctorTemp.getBirthday());
            //新增性别
            ct.setSex(doctorTemp.getSex());
            // 设置医生头像
            ct.setPhoto(doctorTemp.getPhoto());
            senderId = doctorTemp.getCode();
            senderName = doctorTemp.getName();
        }
        // 设置操作日期
        ct.setCzrq(new Date());
        ct.setDel("1");
        ct.setStatus(0);
        // 医生未读数量为1
        ct.setDoctorRead(1);
        // 患者未读数量为0
        ct.setPatientRead(0);
        // 添加咨询记录
        Consult consult = addConsult(ct.getPatient(), null, ct.getSymptoms(), ct.getImages(), ct.getType());
        // 设置咨询标识
        ct.setConsult(consult.getCode());
        // 添加咨询转发记录
        ConsultTeamDoctor cd = new ConsultTeamDoctor();
        cd.setConsult(consult.getCode());
        cd.setDel("1");
        cd.setCzrq(new Date());
        cd.setTo(ct.getDoctor());
        // 添加医生咨询日志
        String content = addLogs(ct);
        //推送给IM文字消息
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(ct.getPatient(),0);
        jsonObject.put(ct.getDoctor(),0);
        JSONObject messages = ImUtill.getCreateTopicMessage(senderId,senderName,senderName+"发起咨询",content,ct.getImages());
        JSONObject obj = ImUtill.createTopics(null,consult.getCode(),consult.getSymptoms(),jsonObject,messages,"2");
        if(obj==null){
            throw new RuntimeException("im消息创建异常!");
        }
        if(obj.getInt("status")==-1){
            throw new RuntimeException(obj.getString("message"));
        }
        //设置消息ID
        ct.setStartMsgId(obj.getString("start_msg_id"));
        consultTeamDao.save(ct);  // 保存医生咨询信息
        consultTeamDoctorDao.save(cd);
        consultDao.save(consult);
    }
}

+ 5 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyService.java

@ -16,9 +16,9 @@ import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientInvitationLogDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.patient.SocialSecurityInfoDao;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.util.IdCardUtil;
import com.yihu.wlyy.util.MD5;
import com.yihu.wlyy.util.SendP2PUtil;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.wechat.util.WeiXinTempMsgSendUtils;
import org.json.JSONArray;
@ -55,6 +55,9 @@ public class FamilyService {
    private DoctorDao doctorDao;
    @Autowired
    private WeiXinTempMsgSendUtils weiXinTempMsgSendUtils;
    @Autowired
    private ConsultService consultService;
    @Value("#{sys.doctor_invitel_template}")
    private String templateId;
@ -335,7 +338,7 @@ public class FamilyService {
        }else{
            content = currentPatient.getName()+"先生,再次感谢您对我的信任。同时,我也衷心的希望能够拥有为您整个家庭提供问下服务的荣幸。在此诚意地邀请您为"+patient.getName()+"进行签约。";
        }
        SendP2PUtil.sendP2Pmsg(doctorCode,currentPatientCode,"1",content);
        consultService.sendMucMessageBySingnType(doctorCode,doctor.getName(),currentPatient.getCode(),content,"1","医生:"+doctor.getName()+"给患者:"+currentPatient.getName()+"发送了签约邀请!");
        return "1";
    }

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/message/MessageService.java

@ -63,7 +63,7 @@ public class MessageService extends BaseService {
     */
    private String getImMsgAmount(String doctor) {
        String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
                + "/api/v1/chats/msg/amount?user_id=" + doctor;
                + "/api/v2/sessions/unread_message_count?user_id=" + doctor;
        return HttpClientUtil.get(url, "UTF-8");
    }

+ 11 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -225,6 +225,17 @@ public class FamilyContractService extends BaseService {
        return doctorDao.findAll(spec, pageRequest);
    }
    /**
     * 根据医生和患者获取患者的签约状态
     * @param patient
     * @param doctor
     * @return
     */
    public List<SignFamily> getSign(String patient,String doctor){
        List<SignFamily> sfList = signFamilyDao.findSSandFamilyByDoctorPatient(patient, doctor);
        return sfList;
    }
    /**
     * 查询医生主页信息
     *

+ 6 - 6
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/PatientRemindService.java

@ -1,20 +1,19 @@
package com.yihu.wlyy.service.app.sign;
import com.yihu.wlyy.entity.consult.Consult;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.common.SMSService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.SendP2PUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import org.apache.commons.collections.FastHashMap;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -52,7 +51,8 @@ public class PatientRemindService extends BaseService {
    WeiXinAccessTokenUtils tokenUtils;
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    ConsultService consultService;
    /**
     * 缴费提醒
     *
@ -209,8 +209,8 @@ public class PatientRemindService extends BaseService {
                wFlag = true;
            }
            //发送IM
            SendP2PUtil.sendP2Pmsg(doc.getCode(), p.getCode(), "1", doc.getName() + "医生提醒您:为完成家庭医生签约," +
                    "尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费");
            consultService.sendMucMessageBySingnType(doc.getCode(),doc.getName(),p.getCode(),doc.getName() + "医生提醒您:为完成家庭医生签约," +
                  "尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费", "1","医生:"+doc.getName()+"给患者:"+p.getName()+"发送了缴费提醒!");
            if (ignore) {
                redisTemplate.opsForSet().add("expenses:remind:set",p.getCode());
                redisTemplate.expireAt("expenses:remind:set", today.getTime());

+ 6 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/guahao/GuahaoXMService.java

@ -7,11 +7,11 @@ import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
import com.yihu.wlyy.repository.patient.PatientReservationDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.jw.JwSmjkService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.SOAPUtil;
import com.yihu.wlyy.util.SendP2PUtil;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
@ -54,6 +54,9 @@ public class GuahaoXMService implements IGuahaoService {
    @Autowired
    SignFamilyDao signFamilyDao;
    @Autowired
    private ConsultService consultService;
    private ObjectMapper objectMapper = new ObjectMapper();
    /**
@ -109,7 +112,8 @@ public class GuahaoXMService implements IGuahaoService {
        }
        if (StringUtils.isNotBlank(dcode)) {
            reservation.setDoctor(dcode);//代理签约维护待签约人编码
            SendP2PUtil.sendP2Pmsg(dcode, patient, "1", "我已成功为您预约:" + startTime + "," + hospitalName + hosDeptName + doctorName + "医生的号源。您可直接前往医院就诊</br><a name='guahao' href='javascript:void(0)' data-id='" + code + "'>点击查看详情</a>");
            Patient p = patientService.findByCode(patient);
            consultService.sendMucMessageBySingnType(dcode,dname,patient,"我已成功为您预约:" + startTime + "," + hospitalName + hosDeptName + doctorName + "医生的号源。您可直接前往医院就诊</br><a name='guahao' href='javascript:void(0)' data-id='" + code + "'>点击查看详情</a>","1","医生:"+doctor.getName()+"给患者:"+p.getName()+"代理预约!");
        }
        // 保存预约记录
        patientReservationDao.save(reservation);

+ 9 - 13
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/HttpUtil.java

@ -132,20 +132,16 @@ public class HttpUtil {
	 * @param data 消息数据
	 */
	public static boolean pushMessage(String receiver, String msgType, String title, String msg, String data) {
//		JSONObject param = new JSONObject();
//		param.put("to_uid", receiver);
//		param.put("content", msg);
//		param.put("type", msgType);
//		param.put("title", title);
//		param.put("data", data);
		try{
			List<NameValuePair> params = new ArrayList<>();
			params.add(new BasicNameValuePair("to", receiver));
			params.add(new BasicNameValuePair("content", msg));
			params.add(new BasicNameValuePair("contentType", msgType));
			params.add(new BasicNameValuePair("title", title));
			params.add(new BasicNameValuePair("summary", data));
			String response = HttpClientUtil.post(SystemConf.getInstance().getMsgPushServer(), params, "UTF-8");
			JSONObject participants = new JSONObject();
			participants.put("system",0);
			participants.put(receiver,0);
			JSONObject sessionObj  = ImUtill.createSession(participants,"2","系统消息","");
			if(sessionObj.getInt("status")==-1){
				throw  new RuntimeException(sessionObj.getString("message"));
			}
			JSONObject session = sessionObj.getJSONObject("data");
			ImUtill.sendImMsg("system","系统",session.getString("id"),msgType, msg);
			return true;
		}catch (Exception e){
			e.printStackTrace();

+ 171 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ImUtill.java

@ -0,0 +1,171 @@
package com.yihu.wlyy.util;
import org.json.JSONArray;
import org.json.JSONObject;
/**
 * Created by 卓 on 2017/1/13.
 */
public class ImUtill {
    /**
     * 发送消息给IM
     *
     * @param from        来自
     * @param contentType 1文字 2图片消息
     * @param content     内容
     */
    public static String sendImMsg(String from,String fromName, String sessionId, String contentType, String content) {
        String imAddr = SystemConf.getInstance().getImListGet() + "/api/v2/sessions/"+sessionId+"/messages";
        JSONObject params = new JSONObject();
        params.put("sender_id", from);
        params.put("sender_name", fromName);
        params.put("content_type", contentType);
        params.put("content", content);
        params.put("session_id", sessionId);;
        String response = HttpClientUtil.postBody(imAddr, params);
        return response;
    }
    /**
     * 发送消息给IM
     *
     * @param from        来自
     * @param contentType 1文字 2图片消息
     * @param content     内容
     */
    public static String sendTopicIM(String from,String fromName, String topicId, String contentType, String content) {
        String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
                + ("api/v2/sessions/topic/"+topicId+"/messages");
        JSONObject params = new JSONObject();
        params.put("sender_id", from);
        params.put("sender_name", fromName);
        params.put("content_type", contentType);
        params.put("content", content);
        params.put("topic_id", topicId);;
        String response = HttpClientUtil.postBody(url, params);
        return response;
    }
    /**
     * 结束议题
     *
     * @param topicId  议题ID
     * @param endUser  结束人
     * @param endUserName 结束人名字
     * @param sessionId 会话ID
     */
    public static JSONObject endTopics(String sessionId,String endUser, String endUserName,String topicId) {
        String imAddr = SystemConf.getInstance().getImListGet() + "api/v2/sessions/"+sessionId+"/topics/"+topicId+"/ended";
        JSONObject params = new JSONObject();
        params.put("session_id", sessionId);
        params.put("end_user", endUser);
        params.put("end_user_name",endUserName);
        params.put("topic_id", topicId);
        String ret = HttpClientUtil.postBody(imAddr,params);
        JSONObject obj  = null;
        try{
            obj = new JSONObject(ret);
        }catch (Exception e){
            return null;
        }
        return obj;
    }
    /**
     * 议题邀请人员
     * @param user 结束人名字
     * @param sessionId 会话ID
     */
    public static void updateTopicUser(String sessionId,String user) {
        String imAddr = SystemConf.getInstance().getImListGet() + "api/v2/sessions/"+sessionId+"/participants/"+user;
        JSONObject params = new JSONObject();
        params.put("user", user+":"+0);
        HttpClientUtil.putBody(imAddr,params);
    }
    /**
     * 创建议题
     *
     * @param topicId  议题ID
     * @param topicName  议题名称
     * @param participants 成员
     */
    public static JSONObject createTopics(String sessionId, String topicId, String topicName, JSONObject participants, JSONObject messages, String sessionType) {
        String imAddr = SystemConf.getInstance().getImListGet() + "api/v2/sessions/"+topicId+"/topics";
        JSONObject params = new JSONObject();
        params.put("topic_id", topicId);
        params.put("topic_name", topicName);
        params.put("participants", participants.toString());
        params.put("messages", messages.toString());
        params.put("session_id", sessionId);
        params.put("session_type", sessionType);
        String ret = HttpClientUtil.postBody(imAddr,params);
        JSONObject obj  = null;
        try{
            obj = new JSONObject(ret);
        }catch (Exception e){
            return null;
        }
        return obj;
    }
    /**
     * 创建会话(system)
     *
     */
    public static JSONObject createSession(JSONObject participants,String sessionType,String sessionName,String sessionId) {
        String imAddr = SystemConf.getInstance().getImListGet() + "api/v2/sessions";
        JSONObject params = new JSONObject();
        params.put("participants", participants);
        params.put("session_name", sessionName);
        params.put("session_type", sessionType);
        params.put("session_id", sessionId);
        String ret = HttpClientUtil.postBody(imAddr,params);
        JSONObject obj  = null;
        try{
            obj = new JSONObject(ret);
        }catch (Exception e){
            return null;
        }
        return obj;
    }
    /**
     * 获取会话实例的消息对象
     * @param senderId
     * @param senderName
     * @param title
     * @param description
     * @param images
     * @return
     */
    public static JSONObject getCreateTopicMessage(String senderId,String senderName,String title,String description,String images){
        JSONObject messages = new JSONObject();
        messages.put("description",description);
        messages.put("title",title);
        messages.put("img",images);
        messages.put("sender_id",senderId);
        messages.put("sender_name",senderName);
        return messages;
    }
    public static JSONArray getTopicMessage(String topicId,String startMsgId,String endMsgId,int page,int pagesize,String uid){
        String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
                + "api/v2/sessions/topic/"+topicId+"/messages?topic_id="+topicId+"&end="+startMsgId
                +"&start="+(endMsgId==null?"":endMsgId)+"&page="+page+"&pagesize="+pagesize+"&user="+uid;
        try{
            String ret = HttpClientUtil.get(url, "UTF-8");
            JSONObject obj = new JSONObject(ret);
            if(obj.getInt("status")==-1){
                throw new RuntimeException(obj.getString("message"));
            }else{
                return  obj.getJSONArray("data");
            }
        }catch (Exception e){
            return null;
        }
    }
}

+ 6 - 7
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SendP2PUtil.java

@ -20,12 +20,11 @@ public class SendP2PUtil {
		params.add(new BasicNameValuePair("to", to));
		params.add(new BasicNameValuePair("content",  content));
		params.add(new BasicNameValuePair("contentType",contentType));
		//String response = HttpClientUtil.post(url, params, "UTF-8");
//		if (StringUtils.isEmpty(response)) {
//			return "-1";
//		}else{
//			return "200";
//		}
		return "200";
		String response = HttpClientUtil.post(url, params, "UTF-8");
		if (StringUtils.isEmpty(response)) {
			return "-1";
		}else{
			return "200";
		}
	}
}

+ 27 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SendPatientUtil.java

@ -0,0 +1,27 @@
package com.yihu.wlyy.util;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class SendPatientUtil {
	public static String sendToPatient(String from,String fromName,String to,String contentType,String content,String title,String type){
		JSONObject participants = new JSONObject();
		participants.put(from,0);
		participants.put(to,0);
		if(!"4".equals(contentType)){
			contentType = "0";
		}
		JSONObject sessionJson  = ImUtill.createSession(participants,"1",title,to+"_consult_"+type);
		if(sessionJson.getInt("status")==-1){
			throw  new RuntimeException(sessionJson.getString("message"));
		}
		JSONObject session = sessionJson.getJSONObject("data");
		return ImUtill.sendImMsg(from,fromName,session.getString("id"),contentType,content);
	}
}

+ 24 - 4
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/FileUploadController.java

@ -1,17 +1,22 @@
package com.yihu.wlyy.web.common;
import java.io.File;
import java.io.IOException;
import java.beans.Encoder;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.wlyy.util.fastdfs.FastDFSUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.io.FileUtils;
import org.json.JSONObject;
import org.springframework.http.MediaType;
@ -161,16 +166,31 @@ public class FileUploadController extends BaseController {
        List<String> tempPaths = new ArrayList<String>();
        try {
            String fastUrl = SystemConf.getInstance().getSystemProperties().getProperty("fastdfs_file_url");
            String type  = request.getParameter("type");
            MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
            Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
            String fileName = null;
            for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
                // 上传文件
                MultipartFile mf = entity.getValue();
                //byte audioData[] = mf.getBytes();
                //AudioFormat af = getAudioFormat();
                //ByteArrayInputStream bais = new ByteArrayInputStream(audioData);
                //AudioInputStream ais = new AudioInputStream(bais,af, audioData.length / af.getFrameSize());
                //File file = new File("temp.wav");
                //InputStream in = new FileInputStream(file);
                //AudioSystem.write(ais, AudioFileFormat.Type.WAVE,file);
                fileName = mf.getOriginalFilename();
                String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
                ObjectNode objectNode = fastDFSUtil.upload(mf.getInputStream(),fileExt,"");
                if("3".equals(type)){
                    fileExt ="wav";
                }
                ObjectNode objectNode = fastDFSUtil.upload(mf.getInputStream() ,fileExt,"");
                tempPaths.add(fastUrl + objectNode.get("groupName").toString().replaceAll("\"","")
                        + "/" + objectNode.get("remoteFileName").toString().replaceAll("\"",""));
            }

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

@ -683,7 +683,7 @@ public class DoctorConsultController extends WeixinBaseController {
            consult.setVoice(voice);
            consult.setDoctor(doctorCode);//设置专科医生
            // 保存到数据库
            consultTeamService.addFamousTeamConsult(consult, getUID(), "2");
            consultTeamService.famousConsult(consult, getUID(), "2");
            // 推送消息给医生
            PushMsgTask.getInstance().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)) {
@ -842,6 +842,7 @@ public class DoctorConsultController extends WeixinBaseController {
            consult.setImages(images);
            // 设置咨询语音URL
            consult.setVoice(voice);
            consult.setDoctor(doctorCode);//设置专科医生
            // 保存到数据库
            if(consultTeamService.isCommonTeam( doctorCode, getUID() ))
@ -935,4 +936,67 @@ public class DoctorConsultController extends WeixinBaseController {
            return error(-1, "查询咨询状态失败");
        }
    }
    @RequestMapping(value = "seekHelp")
    @ResponseBody
    public String seekHelp(
            @RequestParam(required = true) String symptoms,
            @RequestParam(required = false) String oldConsultCode,
            @RequestParam(required = false) String doctorCode,
            @RequestParam(required = false) String images){
        try {
                if (StringUtils.isEmpty(images)) {
                    images = fetchWxImages();
                    // 将临时图片拷贝到正式存储路径下
                    if (StringUtils.isNotEmpty(images)) {
                        images = CommonUtil.copyTempImage(images);
                    }
                }
                ConsultTeam consult = new ConsultTeam();
                // 设置咨询类型: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);
                }else{
                    consultTeamService.addSeekHelpOtherTeam(consult, getUID(), oldConsultCode);
                }
                return success("提交成功");
            } catch (Exception ex) {
                error(ex);
                return invalidUserException(ex, -1, "提交失败!");
            }
    }
    /**
     * 结束咨询接口
     * @param consult 咨询标识
     * @return
     */
    @RequestMapping(value = "finish_consult")
    @ResponseBody
    public String finishConsult(String consult) {
        try {
            int flag = consultTeamService.finishConsult(consult, getUID(), 2);
            if (flag > 0) {
                return success("咨询已关闭");
            } else {
                return error(-1, "关闭失败!");
            }
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "关闭失败!");
        }
    }
}

+ 4 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java

@ -6,10 +6,10 @@ import com.yihu.wlyy.entity.education.*;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.app.health.*;
import com.yihu.wlyy.service.app.label.SignPatientLabelInfoService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.util.SendP2PUtil;
import com.yihu.wlyy.web.WeixinBaseController;
import com.yihu.wlyy.web.doctor.message.DoctorMessageController;
import io.swagger.annotations.Api;
@ -73,6 +73,8 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
    @Autowired
    SignFamilyDao signFamilyDao;
    @Autowired
    ConsultService consultService;
    /**
     * 查询
     *
@ -381,7 +383,7 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
                    // 行政团队
                    heap.setAdminTeamCode(signFamily.getAdminTeamId());
                    list.add(heap);
                    SendP2PUtil.sendP2Pmsg(doctor.getCode(), p, "4", "{\"title\":\"" + temp.getTitle() + "\",\"id\":\"" + temp.getCode() + "\",\"img\":\"" + temp.getUrl() + "\",\"content\":\"为了您的健康,我给您发送了一篇文章,请咨询查阅,如有问题,可随时与我沟通\"}");
                    consultService.sendMucMessageBySingnType(doctor.getCode(),doctor.getName(), p, "{\"title\":\"" + temp.getTitle() + "\",\"id\":\"" + temp.getCode() + "\",\"img\":\"" + temp.getUrl() + "\",\"content\":\"为了您的健康,我给您发送了一篇文章,请咨询查阅,如有问题,可随时与我沟通\"}", "4","医生:"+doctor.getName()+"给患者:"+patientTemp.getName()+"发送了健康教育文章!");
                    if (StringUtils.isNotEmpty(patientTemp.getOpenid())) {
                        // 推送消息给微信端
                        JSONObject json = new JSONObject();

+ 19 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthGuidanceController.java

@ -1,6 +1,13 @@
package com.yihu.wlyy.web.doctor.health;
import com.yihu.wlyy.util.SendP2PUtil;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.app.sign.FamilyContractService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.common.account.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -33,6 +40,14 @@ public class DoctorHealthGuidanceController extends WeixinBaseController {
	@Autowired
	private PatientHealthGuidanceService patientHealthGuidanceService;
	@Autowired
	private DoctorService doctorService;
	@Autowired
	private PatientService patientService;
	@Autowired
	private ConsultService consultService;
	/**
	 * 获取某个健康指导
	 *
@ -68,7 +83,7 @@ public class DoctorHealthGuidanceController extends WeixinBaseController {
			guidance.setContent(content);
			guidance.setDoctor(getUID());
			guidance.setPatient(patient);
			Doctor doctor = doctorService.findDoctorByCode(getUID());
			if (StringUtils.isNotEmpty(images)) {
				images = CommonUtil.copyTempImage(images);
			}
@ -81,7 +96,8 @@ public class DoctorHealthGuidanceController extends WeixinBaseController {
			// 保存
			if (patientHealthGuidanceService.add(guidance, getAccessToken()) != null) {
				SendP2PUtil.sendP2Pmsg(getUID(), patient, "1",content);
				Patient p = patientService.findByCode(patient);
				consultService.sendMucMessageBySingnType(getUID(),doctor.getName(),patient,content,"1","医生:"+doctor.getName()+"给患者:"+p.getName()+"发送了健康指导!");
				return success("保存成功!");
			} else {
				return error(-1, "保存失败!");

+ 13 - 165
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java

@ -393,7 +393,7 @@ public class ConsultController extends WeixinBaseController {
            consult.setVoice(voice);
            consult.setDoctor(doctorCode);//设置专科医生
            // 保存到数据库
            consultTeamService.addFamousTeamConsult(consult, getUID(), "1");
            consultTeamService.famousConsult(consult, getUID(), "1");
            //名医咨询次数减一
            doctorWorkTimeService.setDoctorCurrentConsultTimesRemain(doctorCode);
            // 推送消息给医生
@ -568,7 +568,7 @@ public class ConsultController extends WeixinBaseController {
    @ResponseBody
    public String finish(@RequestParam(required = true) String code) {
        try {
            int row = consultTeamService.finish(code, getUID(), 1);
            int row = consultTeamService.finishConsult(code, getUID(), 1);
            if (row > 0) {
                return success("操作成功!");
            } else {
@ -614,7 +614,6 @@ public class ConsultController extends WeixinBaseController {
                    if (!StringUtils.isEmpty(images)) {
                        arr = images.split(",");
                    }
                    content = fetchWxImages();
                } else {
                    arr = content.split(",");
@ -648,37 +647,20 @@ public class ConsultController extends WeixinBaseController {
                arr = new String[]{content};
            }
            JSONObject group = talkGroupService.findConsultTalkGroup(consultModel.getConsult());
            Patient patient = patientDao.findByCode(getUID());
            int i = 0;
            List<String> failed = new ArrayList<>();
            for (ConsultTeamLog log : logs) {
                String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
                        + (group != null ? "api/v1/chats/gm" : "api/v1/chats/pm");
                List<NameValuePair> params = new ArrayList<>();
                if (group == null) {
                    params.add(new BasicNameValuePair("from", getUID()));
                    params.add(new BasicNameValuePair("to", consultModel.getDoctor()));
                    params.add(new BasicNameValuePair("content", log.getContent()));
                    params.add(new BasicNameValuePair("contentType", String.valueOf(log.getType())));
                } else {
                    params.add(new BasicNameValuePair("from", getUID()));
                    params.add(new BasicNameValuePair("at", ""));
                    params.add(new BasicNameValuePair("group", group.getString("code")));
                    params.add(new BasicNameValuePair("groupType", "2"));
                    params.add(new BasicNameValuePair("content", log.getContent()));
                    params.add(new BasicNameValuePair("contentType", String.valueOf(log.getType())));
                }
                String response = HttpClientUtil.post(url, params, "UTF-8");
                if (StringUtils.isEmpty(response)) {
                    failed.add(arr[i]);
                String response = ImUtill.sendTopicIM(getUID(),patient.getName(),consult,String.valueOf(log.getType()),log.getContent());
                if (StringUtils.isNotEmpty(response)) {
                    JSONObject resObj = new JSONObject(response);
                    if(resObj.getInt("status")==-1){
                        return invalidUserException(new RuntimeException(resObj.getString("message")), -1, "追问失败!"+resObj.getString("message"));
                    }
                    failed.add(response);
                }
            }
            return write(200, "追问成功!", "data", failed);
        } catch (Exception e) {
            error(e);
@ -696,148 +678,14 @@ public class ConsultController extends WeixinBaseController {
     */
    @RequestMapping(value = "loglist")
    @ResponseBody
    public String loglist(@RequestParam String consult, @RequestParam long id, @RequestParam int pagesize) {
    public String loglist(@RequestParam String consult, @RequestParam int page, @RequestParam int pagesize) {
        try {
            ConsultTeam consultModel = consultTeamService.findByCode(consult);
            if (consultModel == null) {
                return error(-1, "咨询记录不存在!");
            }
            Patient p = patientDao.findByCode(getUID());
            Map<String, Doctor> map = new HashMap<>();
            List<JSONObject> jsonArray = new ArrayList<>();
            JSONObject group = talkGroupService.findConsultTalkGroup(consultModel.getConsult());
            if (group != null) {
                String urlG = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
                        + "api/v1/chats/gm";
                String reG = HttpUtil.sendGet(urlG, "user_id=" + getUID() + "&group_id=" + group.getString("code"));
                JSONObject resultG = null;
                if (!org.springframework.util.StringUtils.isEmpty(reG)) {
                    resultG = new JSONObject(new String(reG.getBytes(), "utf-8"));
                }
                if (resultG != null && resultG.getInt("count") > 0) {
                    JSONArray list = resultG.getJSONArray("records");
                    for (int i = 0; i < list.length(); i++) {
                        JSONObject obj = list.getJSONObject(i);
                        if (obj.getInt("contentType") == 5 || obj.getInt("contentType") == 6) {
                            continue;
                        }
                        JSONObject json = new JSONObject();
                        json.put("id", obj.getInt("id"));
                        if (!obj.getString("from").equals(getUID())) {
                            Doctor doc = null;
                            if (map.containsKey(obj.getString("from"))) {
                                doc = map.get(obj.getString("from"));
                            } else {
                                doc = doctorService.findDoctorByCode(obj.getString("from"));
                            }
                            // 设置回复医生姓名
                            json.put("doctorName", doc.getName());
                            json.put("photo", doc.getPhoto());
                        } else {
                            // 设置回复医生姓名
                            json.put("doctorName", p.getName());
                            json.put("photo", p.getPhoto());
                        }
                        // 设置回复内容
                        json.put("content", obj.getString("content"));
                        // 设置咨询或回复时间
                        json.put("time", DateUtil.dateToStr(new Date(obj.getLong("timestamp")), DateUtil.YYYY_MM_DD_HH_MM_SS));
                        // 设置记录类型:1文字,2图片,3语音 4 文章
                        json.put("msgType", obj.getInt("contentType"));
                        // 设置类型:0患者问,1医生回复,2患者追问,3患者评价
                        if (!obj.getString("from").equals(getUID())) {
                            json.put("type", 1);
                        } else {
                            json.put("type", obj.getInt("contentType") == 6 ? 0 : 2);
                        }
                        jsonArray.add(json);
                    }
                }
            }
            JSONObject result = null;
            String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
                    + "api/v1/chats/pm";
            String re = HttpUtil.sendGet(url, "closed_interval=true&user_id=" + getUID() + "&peer_id=" + consultModel.getDoctor()
                    + "&message_end_id=" + consultModel.getStartMsgId() + (consultModel.getEndMsgId() != null ? ("&message_start_id=" + consultModel.getEndMsgId()) : ""));
            if (!org.springframework.util.StringUtils.isEmpty(re)) {
                result = new JSONObject(new String(re.getBytes(), "utf-8"));
            }
            if (result != null && result.getInt("count") > 0) {
                JSONArray list = result.getJSONArray("records");
                for (int i = 0; i < list.length(); i++) {
                    JSONObject obj = list.getJSONObject(i);
                    if (obj.getInt("contentType") == 5) {
                        continue;
                    }
                    JSONObject json = new JSONObject();
                    json.put("id", obj.getInt("id"));
                    if (!obj.getString("from").equals(getUID())) {
                        Doctor doc = null;
                        if (map.containsKey(obj.getString("from"))) {
                            doc = map.get(obj.getString("from"));
                        } else {
                            doc = doctorService.findDoctorByCode(obj.getString("from"));
                        }
                        // 设置回复医生姓名
                        json.put("doctorName", doc.getName());
                        json.put("photo", doc.getPhoto());
                    } else {
                        // 设置回复医生姓名
                        json.put("doctorName", p.getName());
                        json.put("photo", p.getPhoto());
                    }
                    // 设置回复内容
                    json.put("content", obj.getString("content"));
                    // 设置咨询或回复时间
                    json.put("time", DateUtil.dateToStr(new Date(obj.getLong("timestamp")), DateUtil.YYYY_MM_DD_HH_MM_SS));
                    // 设置记录类型:1文字,2图片,3语音
                    json.put("msgType", obj.getInt("contentType"));
                    // 设置类型:0患者问,1医生回复,2患者追问,3患者评价
                    if (!obj.getString("from").equals(getUID())) {
                        json.put("type", 1);
                    } else {
                        json.put("type", obj.getInt("contentType") == 6 ? 0 : 2);
                    }
                    jsonArray.add(json);
                }
            }
            jsonArray.sort(new Comparator<JSONObject>() {
                @Override
                public int compare(JSONObject o1, JSONObject o2) {
                    if (o1.getString("time").compareTo(o2.getString("time")) > 0) {
                        return -1;
                    } else if (o1.getString("time").compareTo(o2.getString("time")) < 0) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });
            // 返回结果
            return write(200, "查询成功", "list", new JSONArray(jsonArray));
           JSONArray array =  ImUtill.getTopicMessage(consultModel.getConsult(),consultModel.getStartMsgId(),consultModel.getEndMsgId(),page,pagesize,getUID());
            return write(200, "查询成功", "list", array);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");