Browse Source

Merge branch 'dev' of huangzhanpeng/wlyy_management into dev

chenweida 8 years ago
parent
commit
5cc0a9d1a2

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/message/HealthMessageJob.java

@ -101,7 +101,7 @@ public class HealthMessageJob implements Job {
                message.setSender("system");
                message.setCzrq(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(yesterday+" 23:59:00"));
                message.setState(1);
                String title="新增系统消息";
                String title="新增待分配居民";
                message.setTitle(title);
                SimpleDateFormat dateFormat1=new SimpleDateFormat("yyyy-MM-dd");
                SimpleDateFormat dateFormat2=new SimpleDateFormat("MM月dd日");

+ 5 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/job/FollowupPlanJob.java

@ -1,12 +1,15 @@
package com.yihu.wlyy.job;
import com.yihu.wlyy.service.app.followup.FollowUpService;
import com.yihu.wlyy.util.DateUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import java.util.Date;
/**
 * Created by hzp on 2017.1.4.
@ -20,7 +23,8 @@ public class FollowupPlanJob implements Job {
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        System.out.print("follow plan message sending...");
        String date = DateUtil.dateToStrShort(new Date());
        //发送随访计划消息
        followUpService.sendMessage();
        followUpService.sendMessage(date);
    }
}

+ 0 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/followup/FollowUpDao.java

@ -28,6 +28,4 @@ public interface FollowUpDao extends PagingAndSortingRepository<Followup, Long>,
    @Query(value = "select a.* from wlyy_followup a where a.doctor_code in ?1 and a.patient_code = ?2 and a.followup_class=?3 and a.status ='1' order by a.followup_date DESC limit 1",nativeQuery = true)
    Followup findLastFollowup(String[] doctors,String patientCode,String followClass) throws Exception;
    @Query(value = "select doctor_code,count(1) count from wlyy_followup where status not in ('0','1') and followup_plan_date>=?1 and followup_plan_date<=?2 group by doctor_code",nativeQuery = true)
    List<Map<String,String>> getFollowupToday(String start,String end) throws Exception;
}

+ 17 - 13
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/message/MessageDao.java

@ -18,34 +18,38 @@ import java.util.List;
public interface MessageDao extends PagingAndSortingRepository<Message, Long>, JpaSpecificationExecutor<Message> {
    @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 count(1) from Message a where a.type =1 and a.read= 1 and a.receiver=?1 ")
    Integer 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 and a.read= 1 and a.receiver=?1 ")
    int amountUnreadHealthByReceiver(String doctor);
    @Query("select count(1) from Message a where a.type =2 and a.read= 1 and a.receiver=?1 ")
    Integer amountUnreadHealthByReceiver(String doctor);
    @Query("select a from Message a where (a.type =2 ) and a.read= 1 and a.receiver=?1 order by a.czrq desc")
    Page<Message> amountUnreadHealthLastByReceiver(String doctor,Pageable pageRequest);
    @Query("select a from Message a where a.type =2 and a.read= 1 and a.receiver=?1 order by a.czrq desc")
    List<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);
    @Query("SELECT a FROM Message a WHERE a.sender=?1 AND a.receiver = ?2 and a.signStatus = ?3 and a.read=1")
    Message findByParams(String sender, String receiver, String signStatus);
    @Query("SELECT a FROM Message a WHERE a.sender=?1 AND a.receiver = ?2 and a.signStatus = ?3 ")
    Message findAllByParams(String sender, String receiver, String signStatus);
    Message findUnreadSign(String sender, String receiver, String signStatus);
    @Query(" from Message a where a.read = 1 and over ='1' and a.sender = ?1 and a.receiver=?2 and a.signStatus='1'")
    Message findByPatient(String patient,String doctor);
    @Query("select count(a) from Message a where a.read = 0 and a.over ='0'  and a.receiver=?1 and a.type=?2 ")
    int findMessageNum(String doctor, Integer type);
    @Query("select a from Message a where a.read= 1 and a.receiver = ?1 and a.sender=?2 and a.tzType=?3")
    List<Message> getHealthIndexMessageByPatient(String doctor,String patient,String type,Pageable pageRequest);
    @Query("select a from Message a where a.read= 1 and a.receiver = ?1 and a.type not in (1,2) order by a.czrq desc")
    List<Message> getSystemMessage(String doctor);
    @Query("select count(a) from Message a where a.read = 0 and a.over ='0'  and a.receiver=?1 and a.type=?2 ")
    int findMessageNum(String doctor, Integer type);
}

+ 16 - 9
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/followup/FollowUpService.java

@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import com.yihu.wlyy.repository.followup.FollowUpDao;
@ -69,6 +70,9 @@ public class FollowUpService extends BaseService {
	@Autowired
	private MessageDao messageDao;
	@Autowired
	private JdbcTemplate jdbcTemplate;
	/**
	 * 转译随访信息
     */
@ -570,37 +574,40 @@ public class FollowUpService extends BaseService {
	 * 每日发送随访计划提醒消息
     */
	@Transactional
	public void sendMessage()
	public void sendMessage(String date)
	{
	    try{
			String date = DateUtil.dateToStrShort(new Date());
			String start = date +" 00:00:00";
			String end = date +" 23:59:59";
			String sql = "select doctor_code,count(1) count from wlyy_followup where status not in ('0','1') and followup_plan_date>='"+start+"' and followup_plan_date<='"+end+"' group by doctor_code";
			//获取所有未执行随访计划
			List<Map<String,String>> followupToday = followupDao.getFollowupToday(start,end);
			List<Map<String,Object>> followupToday = jdbcTemplate.queryForList(sql);
			if(followupToday!=null)
			{
				List<Message> list = new ArrayList<>();
				for(Map<String,String> map:followupToday)
				for(Map<String,Object> map:followupToday)
				{
					String doctor = map.get("doctor_code");
					String count = map.get("count");
					String doctor = String.valueOf(map.get("doctor_code"));
					String count = String.valueOf(map.get("count"));
					// 添加签约消息
					String title = "随访计划提醒";
					String content = "您今日有" +count+"个随访计划待处理";
					Message message = new Message();
					message.setCode(getCode());
					message.setCzrq(new Date());
					message.setContent("您有一条新的家庭签约申请!");
					message.setContent(content);
					message.setRead(1);//设置未读
					message.setReceiver(doctor);//设置接受医生的code
					message.setSender("system");//设置发送的用户
					message.setTitle("随访计划提醒");
					message.setTitle(title);
					message.setType(4);//随访计划提醒
					message.setReadonly(1);//是否只读消息
					list.add(message);
					// 推送消息给医生
					PushMsgTask.getInstance().put(doctor,"4","随访计划提醒","您今日有" +count+"个随访计划待处理","");
					PushMsgTask.getInstance().put(doctor,"4",title,content,"");
				}
				messageDao.save(list);

+ 7 - 10
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java

@ -383,11 +383,12 @@ public class PatientHealthIndexService extends BaseService {
            // 餐后
            if (index % 2 == 0) {
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueBefore, minValueBefore)) {
                    msgContent += patient.getName() + "饭后血糖超标,血糖值" + value1 + ",参考范围:" + minValueAfter + " ~ " + maxValueAfter + ";\n";
                    msgContent += patient.getName() + "血糖异常("+value1+"mmol/L),请处理";
                }
            } else { //餐前
            }
            else { //餐前
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueAfter, minValueAfter)) {
                    msgContent += patient.getName() + "饭前血糖超标,血糖值" + value1 + ",参考范围:" + minValueBefore + " ~ " + maxValueBefore + ";\n";
                    msgContent += patient.getName() + "血糖异常("+value1+"mmol/L),请处理";
                }
            }
        }
@ -415,13 +416,9 @@ public class PatientHealthIndexService extends BaseService {
                    minValueSZY = standard.getMinValue2();
                }
            }
            // 收缩压校验
            if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY)) {
                msgContent += "血压超标,收缩压" + value1 + ",参考范围:" + minValueSSY + " ~ " + maxValueSSY + ";\n";
            }
            // 舒张压
            if (!checkHealthIndex(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)) {
                msgContent += "血压超标,舒张压" + value2 + ",参考范围:" + minValueSZY + " ~ " + maxValueSZY + ";\n";
            // 收缩压/舒张压校验
            if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY)||!checkHealthIndex(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)) {
                msgContent = patient.getName() +"血压异常(舒张压 "+value2+"mmHg、收缩压 "+value1+"mmHg),请处理";
            }
        }

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

@ -52,6 +52,15 @@ public class MessageService extends BaseService {
    @Autowired
    private PatientDao patientDao;
    /**
     * IM消息数量
     */
    private String getImMsgAmount(String doctor){
        String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
                + "/api/v1/chats/msg/amount?user_id="+doctor;
        return HttpClientUtil.get(url, "UTF-8");
    }
    /**
     * 汇总查询医生的消息总数
     *
@ -78,11 +87,8 @@ public class MessageService extends BaseService {
    /**
     * 查询医生未读消息和最后消息
     *
     * @param doctor
     * @return
     */
    public JSONObject findDoctorAllMessage(String doctor) {
    public JSONObject findDoctorAllMessage(String doctor) throws Exception {
        // 签约未读消息总数
        int sign = messageDao.amountUnreadByReceiver(doctor);
@ -95,54 +101,66 @@ public class MessageService extends BaseService {
            if (msgs != null && msgs.getSize() > 0) {
                for (Message msg : msgs) {
                    JSONObject msgJson = new JSONObject();
                    msgJson.put("title", msg.getTitle());
                    msgJson.put("type", msg.getType());
                    if (msg.getSignStatus().equals("4")) {
                        msgJson.put("msg", msg.getSenderName() + "申请与您解除家庭签约");
                    } else {
                        msgJson.put("msg", msg.getSenderName() + "申请与您签约家庭医生");
                    }
                    msgJson.put("msgTime", msg.getCzrq() != null ? DateUtil.dateToStr(msg.getCzrq(), DateUtil.YYYY_MM_DD) : "");
                    msgJson.put("msgTime", DateUtil.dateToStrLong(msg.getCzrq()));
                    signJson.put("lastMessage", msgJson);
                }
            }
        }
        // 体征指标未读消息总数
        int healthIndex = messageDao.amountUnreadHealthByReceiver(doctor);
        Integer healthIndex = messageDao.amountUnreadHealthByReceiver(doctor);
        JSONObject indexJson = new JSONObject();
        indexJson.put("amount", healthIndex);
        if (sign > 0) {
        if (healthIndex > 0) {
            PageRequest pageRequest = new PageRequest(0, 1);
            Page<Message> msgs = messageDao.amountUnreadHealthLastByReceiver(doctor, pageRequest);
            List<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(msg.getCzrq(), DateUtil.YYYY_MM_DD) : "");
                    indexJson.put("lastMessage", msgJson);
                }
            if (msgs != null && msgs.size() > 0) {
                JSONObject msgJson = new JSONObject();
                msgJson.put("title", msgs.get(0).getTitle());
                msgJson.put("type", msgs.get(0).getType());
                msgJson.put("msg",  msgs.get(0).getContent());
                msgJson.put("msgTime",  DateUtil.dateToStrLong(msgs.get(0).getCzrq()));
                indexJson.put("lastMessage", msgJson);
            }
        }
        //获取系统消息总数
        int count= messageDao.findMessageNum(doctor,3);
        //获取系统消息
        List<Message> systemMessage = messageDao.getSystemMessage(doctor);
        JSONObject systemJson = new JSONObject();
        systemJson.put("amount", count);
        JSONObject json = new JSONObject();
        getImMsgAmount(json,doctor);//IM消息数量
        if(systemMessage!=null && systemMessage.size()>0)
        {
            systemJson.put("amount", systemMessage.size());
            JSONObject msgJson = new JSONObject();
            msgJson.put("title", systemMessage.get(0).getTitle());
            msgJson.put("type", systemMessage.get(0).getType());
            msgJson.put("msg", systemMessage.get(0).getContent());
            msgJson.put("msgTime", DateUtil.dateToStrLong(systemMessage.get(0).getCzrq()));
            systemJson.put("lastMessage", msgJson);
        }
        else{
            systemJson.put("amount", 0);
        }
        JSONObject json = new JSONObject();
        json.put("imMsgCount",getImMsgAmount(doctor));//IM消息数量
        json.put("sign", signJson);//签约数
        json.put("healthIndex", indexJson);//健康指标
        json.put("system", systemJson);//系统消息
        return json;
    }
    private void  getImMsgAmount(JSONObject obj,String doctor){
        String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
                + "/api/v1/chats/msg/amount?user_id="+doctor;
        String response = HttpClientUtil.get(url, "UTF-8");
        obj.put("imMsgCount",response);
    }
    /**
     * 查询健康咨询列表
     *
@ -208,14 +226,11 @@ public class MessageService extends BaseService {
    }
    /**
     * 根据参数查询指定的消息
     *
     * @return
     * 未读签约信息
     */
    public Message findMessage(String sender, String receiver, String signStatus) {
    public Message findUnreadSign(String sender, String receiver, String signStatus) {
        return messageDao.findByParams(sender, receiver, signStatus);
        return messageDao.findUnreadSign(sender, receiver, signStatus);
    }
    public Page<Message> find(String doctor, String type, long id, int pagesize) {

+ 16 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/followup/DoctorFollowUpController.java

@ -319,4 +319,20 @@ public class DoctorFollowUpController extends BaseController {
			return invalidUserException(e, -1, "复制上次随访失败!"+e.getMessage());
		}
	}
	/*************************************** 发送随访计划消息 ********************************************/
	@ApiOperation("发送随访计划消息")
	@RequestMapping(value = "/sendMessage", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public String sendMessage(@ApiParam(name="date",value="日期",defaultValue = "2017-01-05")
								  @RequestParam(value="date",required = true) String date)
	{
		try {
			followUpService.sendMessage(date);
			return write(200, "发送随访计划消息成功!");
		} catch (Exception e) {
			return invalidUserException(e, -1, "发送随访计划消息失败!"+e.getMessage());
		}
	}
}

+ 87 - 86
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/message/DoctorMessageController.java

@ -31,35 +31,29 @@ public class DoctorMessageController extends BaseController {
	@Autowired
	private MessageService messageService;
	/**
	 * 医生消息总数统计接口
	 * @return
	 */
	@RequestMapping(value = "amount")
	@RequestMapping(value = "messages")
	@ResponseBody
	public String amount() {
	@ApiOperation("查询医生未读消息和最后消息")
	public String messages() {
		try {
			JSONObject json = messageService.findDoctorAllMessageAmount(getUID());
			if (json == null) {
				return error(-1, "获取消息总数失败!");
			} else {
				return write(200, "获取消息总数成功!", "data", json);
			}
			JSONObject json = messageService.findDoctorAllMessage(getUID());
			return write(200, "获取消息总数成功!", "data", json);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取消息总数失败!");
			return error(-1, e.getMessage());
		}
	}
	/**
	 * 医生消息总数统计接口
	 * @return
	 */
	@RequestMapping(value = "messages")
	@RequestMapping(value = "amount")
	@ResponseBody
	public String messages() {
	public String amount() {
		try {
			JSONObject json = messageService.findDoctorAllMessage(getUID());
			JSONObject json = messageService.findDoctorAllMessageAmount(getUID());
			if (json == null) {
				return error(-1, "获取消息总数失败!");
			} else {
@ -114,53 +108,6 @@ public class DoctorMessageController extends BaseController {
		}
	}
	/**
	 * 体征指标消息查询接口
	 * @param id
	 * @param pagesize
	 * @param isRead 1未读,0已读
	 * @return
	 */
	@RequestMapping(value = "health")
	@ResponseBody
	public String health(long id, int pagesize, @RequestParam(required = false) String isRead) {
		try {
			JSONArray array = new JSONArray();
			Page<Message> list = messageService.findHealthListByDoctor(getUID(), id, pagesize, isRead);
			for (Message msg : list) {
				if (msg == null) {
					continue;
				}
				JSONObject json = new JSONObject();
				// 消息ID
				json.put("id", msg.getId());
				// 发送人标识
				json.put("sender", msg.getSender());
				// 发送人姓名
				json.put("senderName", msg.getSenderName());
				// 发送人头像
				json.put("senderPhoto", msg.getSenderPhoto());
				// 消息类型:1血糖,2血压
				json.put("type", msg.getTzType());
				// 是否已读:1未读,0已读
				json.put("read", msg.getRead());
				// 是否已读:
				json.put("sex", msg.getSex());
				// 当前值/收缩压,正数为高,负数为低
				json.put("value1", msg.getValue1());
				// 上次值/舒张压,正数为高,负数为低
				json.put("value2", msg.getValue2());
				// 发送时间
				json.put("czrq", DateUtil.dateToStrLong(msg.getCzrq()));
				array.put(json);
			}
			return write(200, "获取体征消息成功!", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取体征消息失败!");
		}
	}
	/**
	 * 更新体征消息为已读
	 * @param msgid
@ -168,6 +115,7 @@ public class DoctorMessageController extends BaseController {
	 */
	@RequestMapping(value = "read_health")
	@ResponseBody
	@ApiOperation("消息设置成已读")
	public String readHealth(long msgid) {
		try {
			messageService.readHealth(msgid);
@ -178,16 +126,16 @@ public class DoctorMessageController extends BaseController {
		}
	}
	/**
	 * 根据参数查询发送给我的消息
	 * @return
	 */
	@RequestMapping(value = "find")
	@ResponseBody
	public String find(String sender, String signStatus) {
	@ApiOperation("查询发送给我的消息")
	public String findMyMessage(String sender, String signStatus) {
		try {
			Message msg = messageService.findMessage(sender, getUID(), signStatus);
			Message msg = messageService.findUnreadSign(sender, getUID(), signStatus);
			JSONObject json = null;
			if (msg != null) {
				json = new JSONObject();
@ -206,11 +154,9 @@ public class DoctorMessageController extends BaseController {
			return error(-1, "获取消息失败!");
		}
	}
	/**
	 * @param type 消息类型  1.是家庭签约信息  2.体征消息  3分配健管师
	 * @param id  消息id
	 * @param pagesize  每頁顯示條數
	 * @return
	 * @param type 消息类型  1.是家庭签约信息  2.体征消息  3系统消息(分配健管师 + 随访计划消息 )
	 */
	@RequestMapping(value = "findMessage")
	@ResponseBody
@ -249,23 +195,7 @@ public class DoctorMessageController extends BaseController {
			return error(-1, "获取消息失败!");
		}
	}
	/**
	 * @param type 消息类型  1.是家庭签约信息  2.体征消息  3分配健管师
	 * @return
	 */
	@RequestMapping(value = "findMessageNum")
	@ResponseBody
	public String findMessageNum(Integer type) {
		try {
			JSONObject obj = messageService.findMessageNum(getUID(), type);
			return write(200, "获取消息成功!", "list", obj);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取消息失败!");
		}
	}
	@RequestMapping(value = "getHealthIndexMessage",method = RequestMethod.GET)
@ -300,4 +230,75 @@ public class DoctorMessageController extends BaseController {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
	/**
	 * @param type 消息类型  1.是家庭签约信息  2.体征消息  3分配健管师
	 */
	@RequestMapping(value = "findMessageNum")
	@ResponseBody
	@ApiOperation("获取未读消息数(1.2.8版本作废)")
	public String findMessageNum(@ApiParam(value="消息类型",defaultValue = "3")
								 @RequestParam Integer type) {
		try {
			JSONObject obj = messageService.findMessageNum(getUID(), type);
			return write(200, "获取消息成功!", "list", obj);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取消息失败!");
		}
	}
	/**
	 * 体征指标消息查询接口
	 * @param isRead 1未读,0已读
	 */
	@RequestMapping(value = "health")
	@ResponseBody
	@ApiOperation("体征指标消息查询接口(1.2.8版本作废)")
	public String health(long id, int pagesize, @RequestParam(required = false) String isRead) {
		try {
			JSONArray array = new JSONArray();
			Page<Message> list = messageService.findHealthListByDoctor(getUID(), id, pagesize, isRead);
			for (Message msg : list) {
				if (msg == null) {
					continue;
				}
				JSONObject json = new JSONObject();
				// 消息ID
				json.put("id", msg.getId());
				// 发送人标识
				json.put("sender", msg.getSender());
				// 发送人姓名
				json.put("senderName", msg.getSenderName());
				// 发送人头像
				json.put("senderPhoto", msg.getSenderPhoto());
				// 消息类型:1血糖,2血压
				json.put("type", msg.getTzType());
				// 是否已读:1未读,0已读
				json.put("read", msg.getRead());
				// 是否已读:
				json.put("sex", msg.getSex());
				// 当前值/收缩压,正数为高,负数为低
				json.put("value1", msg.getValue1());
				// 上次值/舒张压,正数为高,负数为低
				json.put("value2", msg.getValue2());
				// 发送时间
				json.put("czrq", DateUtil.dateToStrLong(msg.getCzrq()));
				array.put(json);
			}
			return write(200, "获取体征消息成功!", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取体征消息失败!");
		}
	}
}