Kaynağa Gözat

消息查询接口修改

lyr 8 yıl önce
ebeveyn
işleme
fa8ab4fdc1

+ 25 - 4
src/main/java/com/yihu/wlyy/repository/consult/ConsultTeamDao.java

@ -8,6 +8,7 @@ package com.yihu.wlyy.repository.consult;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.jaxb.PageAdapter;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
@ -132,6 +133,10 @@ public interface ConsultTeamDao extends PagingAndSortingRepository<ConsultTeam,
	@Query("SELECT SUM(a.doctorRead) FROM ConsultTeam a, ConsultTeamDoctor b WHERE a.consult = b.consult AND b.to = ?1 AND a.del = '1' AND a.status = 0")
	int amountAllDoctorUnread(String doctor);
	// 查询医生所有未读的消息总数
	@Query("SELECT a.name,b.czrq FROM ConsultTeam a, ConsultTeamDoctor b WHERE a.consult = b.consult AND b.to = ?1 AND a.del = '1' AND a.status = 0 order by b.czrq desc")
	Page<Object> AllDoctorUnreadLast(String doctor,Pageable pageRequest);
	// 查询带未读数量的所有健康咨询列表
	@Query("SELECT a FROM ConsultTeam a, ConsultTeamDoctor b WHERE a.consult = b.consult AND b.to = ?1 AND a.status = 0 and a.type< 3")
	Page<ConsultTeam> findListByUnreadDoctor(String doctor, Pageable pageRequest);
@ -174,19 +179,35 @@ public interface ConsultTeamDao extends PagingAndSortingRepository<ConsultTeam,
	ConsultTeam findByParientCodeAndSignTypeAndDoctor(String patientCode, String doctor, int s);
	//名医咨询 -全部 带symptoms 未处理、未回复
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.symptoms like ?3 and (a.doctorRead < 1 or b.reply != 1) and a.del = '1' and b.del = '1'")
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.symptoms like ?3 and a.status = 0 and (a.doctorRead > 0 or b.reply != 1) and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorUnReplyReadList(String uid, long id,String title, Pageable pageRequest);
	//名医咨询 -全部 带symptoms 处理、未回复
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.symptoms like ?2 and (a.doctorRead < 1 or b.reply != 1) and a.del = '1' and b.del = '1'")
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.symptoms like ?2 and a.status = 0 and (a.doctorRead > 0 or b.reply != 1) and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorUnReplyReadList(String uid,String title, Pageable pageRequest);
	//名医咨询 -全部 处理、未回复
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and (a.doctorRead < 1 or b.reply != 1) and a.del = '1' and b.del = '1'")
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.status = 0 and (a.doctorRead > 0 or b.reply != 1) and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorUnReplyReadNoTitleList(String uid, long id, Pageable pageRequest);
	//名医咨询 -全部
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and (a.doctorRead < 1 or b.reply != 1) and a.del = '1' and b.del = '1'")
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.status = 0 and (a.doctorRead > 0 or b.reply != 1) and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorUnReplyReadNoTitleList(String uid, Pageable pageRequest);
	//名医咨询 -全部 带symptoms 进行中
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.symptoms like ?3 and a.status = 0 and b.reply = 1 and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorIngList(String uid, long id,String title, Pageable pageRequest);
	//名医咨询 -全部 带symptoms 进行中
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.symptoms like ?2 and a.status = 0 and  b.reply = 1 and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorIngList(String uid,String title, Pageable pageRequest);
	//名医咨询 -全部 进行中
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.status = 0 and  b.reply = 1 and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorIngNoTitleList(String uid, long id, Pageable pageRequest);
	//名医咨询 -全部 进行中
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.status = 0 and b.reply = 1 and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorIngNoTitleList(String uid, Pageable pageRequest);
}

+ 9 - 0
src/main/java/com/yihu/wlyy/repository/message/MessageDao.java

@ -6,6 +6,9 @@
package com.yihu.wlyy.repository.message;
import com.yihu.wlyy.entity.message.Message;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
@ -16,9 +19,15 @@ public interface MessageDao extends PagingAndSortingRepository<Message, Long>, J
    @Query("select count(a) from Message a where a.type =1 and a.read= 1 and a.receiver=?1 ")
    int amountUnreadByReceiver(String doctor);
    @Query("select a from Message a where a.type =1 and a.read= 1 and a.receiver=?1 order by a.czrq desc")
    Page<Message> amountUnreadLastByReceiver(String doctor, Pageable pageRequest);
    @Query("select count(a) from Message a where (a.type =2 or a.type =3) and a.read= 1 and a.receiver=?1 ")
    int amountUnreadHealthByReceiver(String doctor);
    @Query("select a from Message a where (a.type =2 or a.type =3) and a.read= 1 and a.receiver=?1 order by a.czrq desc")
    Page<Message> amountUnreadHealthLastByReceiver(String doctor,Pageable pageRequest);
    @Modifying
    @Query("update Message a set a.read = 0,a.over='0' where a.id = ?1")
    int read(long msgid);

+ 21 - 1
src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java

@ -120,7 +120,7 @@ public class ConsultTeamService extends ConsultService {
                return findByDoctorType5(uid, id, pagesize, title);
            case 6:
                //6 名医咨询 进行中
                return findByDoctorType6(uid, 0, id, pagesize, title);
                return findByDoctorTypeSix(uid, id, pagesize, title);
            case 7:
                //7 名医咨询 已结束
                return findByDoctorType6(uid, 1, id, pagesize, title);
@ -130,6 +130,26 @@ public class ConsultTeamService extends ConsultService {
        return null;
    }
    private Page<ConsultTeam> findByDoctorTypeSix(String uid,long id,int pagesize,String title){
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        if (StringUtils.isNoneEmpty(title)) {
            title = "%" + title + "%";
            if (id > 0) {
                return consultTeamDao.findFamousDoctorIngList(uid, id, title, pageRequest);
            } else {
                return consultTeamDao.findFamousDoctorIngList(uid, title, pageRequest);
            }
        } else {
            if (id > 0) {
                return consultTeamDao.findFamousDoctorIngNoTitleList(uid, id, pageRequest);
            } else {
                return consultTeamDao.findFamousDoctorIngNoTitleList(uid, pageRequest);
            }
        }
    }
    private Page<ConsultTeam> findByDoctorType8(String uid,long id,int pagesize,String title){
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息

+ 77 - 0
src/main/java/com/yihu/wlyy/service/app/message/MessageService.java

@ -1,5 +1,6 @@
package com.yihu.wlyy.service.app.message;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ -7,6 +8,7 @@ import javax.transaction.Transactional;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.repository.message.MessageDao;
import com.yihu.wlyy.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -61,6 +63,81 @@ public class MessageService extends BaseService {
		return json;
	}
	/**
	 * 查询医生未读消息和最后消息
	 *
	 * @param doctor
	 * @return
	 */
	public JSONObject findDoctorAllMessage(String doctor){
		// 三师咨询未读消息总数
		int consult = 0;
		JSONObject consultJson =  new JSONObject();
		try {
			consult = consultTeamDao.amountAllDoctorUnread(doctor);
		} catch (Exception e) {
		}
		consultJson.put("amount",consult);
		if(consult > 0){
			PageRequest pageRequest = new PageRequest(0,1);
			Page<Object> msgs = consultTeamDao.AllDoctorUnreadLast(doctor,pageRequest);
			if(msgs != null && msgs.getSize() > 0){
				for(Object msg : msgs){
					Object[] msgArray = (Object[])msg;
					JSONObject msgJson = new JSONObject();
					msgJson.put("msg",msgArray[0].toString() + "向您发来一个咨询");
					msgJson.put("msgTime",msgArray[1] != null? DateUtil.dateToStr((Date) msgArray[1],DateUtil.YYYY_MM_DD):"");
					consultJson.put("lastMessage",msgJson);
				}
			}
		}
		// 签约未读消息总数
		int sign = messageDao.amountUnreadByReceiver(doctor);
		JSONObject signJson =  new JSONObject();
		signJson.put("amount",sign);
		if(sign > 0){
			PageRequest pageRequest = new PageRequest(0,1);
			Page<Message> msgs = messageDao.amountUnreadLastByReceiver(doctor,pageRequest);
			if(msgs != null && msgs.getSize() > 0){
				for(Message msg : msgs){
					JSONObject msgJson = new JSONObject();
					msgJson.put("msg",msg.getSenderName() + "申请与您签约家庭医生");
					msgJson.put("msgTime",msg.getCzrq() != null? DateUtil.dateToStr((Date) msg.getCzrq(),DateUtil.YYYY_MM_DD):"");
					signJson.put("lastMessage",msgJson);
				}
			}
		}
		// 体征指标未读消息总数
		int healthIndex = messageDao.amountUnreadHealthByReceiver(doctor);
		JSONObject indexJson =  new JSONObject();
		indexJson.put("amount",healthIndex);
		if(sign > 0){
			PageRequest pageRequest = new PageRequest(0,1);
			Page<Message> msgs = messageDao.amountUnreadHealthLastByReceiver(doctor,pageRequest);
			if(msgs != null && msgs.getSize() > 0){
				for(Message msg : msgs){
					JSONObject msgJson = new JSONObject();
					msgJson.put("msg",msg.getContent());
					msgJson.put("msgTime",msg.getCzrq() != null? DateUtil.dateToStr((Date) msg.getCzrq(),DateUtil.YYYY_MM_DD):"");
					indexJson.put("lastMessage",msgJson);
				}
			}
		}
		JSONObject json = new JSONObject();
		json.put("consult", consultJson);
		json.put("sign", signJson);
		json.put("healthIndex", indexJson);
		return json;
	}
	/**
	 * 查询健康咨询列表
	 * @param doctor 医生标识

+ 60 - 0
src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java

@ -4,6 +4,8 @@ import java.util.List;
import java.util.Map;
import com.yihu.wlyy.service.app.health.PatientHealthGuidanceService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.common.account.DoctorService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
@ -45,6 +47,10 @@ public class DoctorConsultController extends WeixinBaseController {
	private DoctorInfoService doctorInfoService;
	@Autowired
	private PatientHealthGuidanceService patientHealthGuidanceService;
	@Autowired
	private DoctorService doctorService;
	@Autowired
	private DoctorWorkTimeService doctorWorkTimeService;
	/**
	 * 三师咨询列表查询
@ -106,6 +112,60 @@ public class DoctorConsultController extends WeixinBaseController {
		}
	}
	/**
	 * 名医列表
	 * @return
	 */
	@RequestMapping(value = "famousDoctorList")
	@ResponseBody
	public String famousDoctorList(
			@RequestParam(required = false) String name,
			int page,
			int pagesize) {
		try {
			JSONArray array = new JSONArray();
			Page<Doctor>list = doctorService.famousDoctorList(name, page, pagesize);
			if (list != null) {
				for (Doctor doctor : list) {
					if (doctor == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					json.put("id", doctor.getId());
					// 医生标识
					json.put("code", doctor.getCode());
					// 医生性别
					json.put("sex", doctor.getSex());
					// 医生姓名
					json.put("name", doctor.getName());
					// 所在医院名称
					json.put("hospital", doctor.getHospital());
					// 所在医院名称
					json.put("hospital_name", doctor.getHosptialName());
					// 科室名称
					json.put("dept_name", (doctor.getDeptName() == null ||
							StringUtils.isEmpty(doctor.getDeptName().toString())) ? " " : doctor.getDeptName());
					// 职称名称
					json.put("job_name", (doctor.getJobName() == null ||
							StringUtils.isEmpty(doctor.getJobName().toString())) ? " " : doctor.getJobName());
					// 头像
					json.put("photo", doctor.getPhoto());
					// 简介
					json.put("introduce", doctor.getIntroduce());
					// 专长
					json.put("expertise", doctor.getExpertise());
					// 剩余咨询次数
					json.put("num", doctorWorkTimeService.getDoctorConsultTimesRemain(doctor.getCode()));
					array.put(json);
				}
			}
			return write(200, "获取医院医生列表成功!", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取医院医生列表失败!");
		}
	}
	/**
	 * 获取咨询全科医生签约量
	 *

+ 20 - 0
src/main/java/com/yihu/wlyy/web/doctor/message/DoctorMessageController.java

@ -44,6 +44,26 @@ public class DoctorMessageController extends BaseController {
		}
	}
	/**
	 * 医生消息总数统计接口
	 * @return
	 */
	@RequestMapping(value = "messages")
	@ResponseBody
	public String messages() {
		try {
			JSONObject json = messageService.findDoctorAllMessage("6c0cfe5065e011e69f7c005056850d66");
			if (json == null) {
				return error(-1, "获取消息总数失败!");
			} else {
				return write(200, "获取消息总数成功!", "data", json);
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "获取消息总数失败!");
		}
	}
	/**
	 * 健康咨询消息列表查询接口
	 * @param id