Browse Source

中山向医生推送消息

wangjun 4 years ago
parent
commit
63bbd6f607

+ 37 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/service/SystemMessageService.java

@ -10,8 +10,10 @@ import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.utils.YkyySMSService;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
@ -21,6 +23,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author zmk
@ -43,6 +47,8 @@ public class SystemMessageService extends BaseJpaService<SystemMessageDO,SystemM
    private YkyySMSService ykyySMSService;
    @Value("${wechat.id}")
    private String wechatId;
    @Autowired
    private HibenateUtils hibenateUtils;
    /**
@ -149,6 +155,37 @@ public class SystemMessageService extends BaseJpaService<SystemMessageDO,SystemM
        return msg;
    }
    /*private MixEnvelop findOutPatientMessage(String reciver ,Integer page ,Integer pageSize){
        String sql = "select b.id as \"id\"," +
                " b.content as \"content\"," +
                "b.saas_id as \"saasId\"," +
                "b.is_read as \"isRead\"," +
                "b.type as \"type\"," +
                "b.sender as \"sender\"," +
                "b.sender_name as \"senderName\"," +
                "b.receiver as \"receiver\"," +
                "b.receiver_name as \"receiverName\"," +
                "b.relation_type as \"relationType\"," +
                "b.relation_code as \"relationCode\"," +
                "b.relation_name as \"relationName\"," +
                "b.status as \"status\"," +
                "b.del as \"del\"," +
                "b.create_user as \"createUser\"," +
                "b.create_user_name as \"createUserName\"," +
                "b.create_time as \"createTime\"," +
                "b.update_user as \"updateUser\"," +
                "b.update_user_name as \"updateUserName\"," +
                "b.update_time as \"updateTime\" " +
                " from wlyy_outpatient t left join base_user_message b " +
                " on t.id = b.relation_code " +
                " where b.del=1 ";
        if (StringUtils.isNoneBlank(reciver)){
            sql+=" and b.reciver = '"+reciver+"'";
        }
        sql+=" and t.status = '0' order by b.create_time asc ";
        String sqlAppend = sql+" and t.status != '0' order by b.create_time desc";
        List<Map<String,Object>> listfront = hi
    }*/
}

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

@ -89,5 +89,8 @@ public interface OutpatientDao extends PagingAndSortingRepository<WlyyOutpatient
    @Query("from WlyyOutpatientDO a where a.consumer = ?1 and a.status=1 and a.payStatus =1 order by a.createTime desc")
    List<WlyyOutpatientDO> findWlyyOutpatientDO(String patient);
    @Query("from WlyyOutpatientDO a where a.status=0 and a.payStatus =1 order by a.createTime desc")
    List<WlyyOutpatientDO> findDoctorRemindMessage();
}

+ 1 - 1
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -3706,7 +3706,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        return rs.size();
    }
    @Transactional(readOnly = true)
    public Map<String, Object> findDoctorInfo(String doctor, String withWork,String patient) {
        BaseDoctorDO doctorDO = baseDoctorDao.findById(doctor);
        Map<String, Object> rs = new HashedMap();

+ 4 - 2
business/base-service/src/mqConfig/mqdata/BS15018.json

@ -7,7 +7,8 @@
		"OP_DATE": "2011-09-27 15:35:57",
		"CARD_TYPE": "2",
		"CARD_TYPE_NAME": "社保卡",
		"social_no": "350211198411053024"
		"social_no": "350211198411053024",
			"name":"白海灵"
		},
	{
		"PAT_NO": "P5616242-0",
@ -16,6 +17,7 @@
		"OP_DATE": "2014-07-25 08:46:40",
		"CARD_TYPE": "2",
		"CARD_TYPE_NAME": "社保卡",
		"social_no": "350211198411053024"
		"social_no": "350211198411053024",
		"name":"白海灵"
	}]
}

+ 3 - 0
common/common-entity/sql记录

@ -196,3 +196,6 @@ alter table base_patient add `archive_status` tinyint(1) DEFAULT NULL COMMENT '
alter table base_patient add `medicare_number` varchar(50) DEFAULT NULL COMMENT '医疗保险号';
alter table base_patient add `ssc` varchar(50) DEFAULT NULL COMMENT '社保卡号';
alter table base_patient add `archive_type` tinyint(1) DEFAULT NULL COMMENT '档案类型 1老人 2新生儿';
-- 2021-04-09 中山消息推送
alter table wlyy_outpatient ADD last_remind_time timestamp ;
alter table wlyy_outpatient ADD remind_doctor  varchar(50) ;

+ 25 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/hospital/prescription/WlyyOutpatientDO.java

@ -279,6 +279,31 @@ public class WlyyOutpatientDO extends UuidIdentityEntity {
     * 云信房间号
     */
    private String channelId;
    /**
     * 是否提醒过医生
     */
    private String remindDoctor;
    /**
     * 上次提醒时间
     */
    private Date lastRemindTime;
    @Column(name = "last_remind_time")
    public Date getLastRemindTime() {
        return lastRemindTime;
    }
    public void setLastRemindTime(Date lastRemindTime) {
        this.lastRemindTime = lastRemindTime;
    }
    @Column(name = "remind_doctor")
    public String getRemindDoctor() {
        return remindDoctor;
    }
    public void setRemindDoctor(String remindDoctor) {
        this.remindDoctor = remindDoctor;
    }
    @Column(name = "charge_type")
    public String getChargeType() {
        return chargeType;

+ 3 - 2
svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/BaseDoctorService.java

@ -346,7 +346,8 @@ public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
        List<Map<String,Object>> list=null;
        if ("xm_ykyy_wx".equalsIgnoreCase(wechatId)){
        list = hibenateUtils.createSQLQuery(sql,page,size);
       /* if ("xm_ykyy_wx".equalsIgnoreCase(wechatId)){
            if (flag){
                sql+=" LIMIT  " + (page - 1) * size + "," + size + "";
@ -379,7 +380,7 @@ public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
            sql+=" LIMIT  " + (page - 1) * size + "," + size + "";
            Logger.getAnonymousLogger().info("finalCountSql="+sql);
            list = jdbcTemplate.queryForList(sql);
        }
        }*/
        String countSql = " select " +

+ 2 - 2
svr/svr-base/src/main/java/com/yihu/jw/base/service/user/UserService.java

@ -252,10 +252,10 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
                " g.street_code AS streetCode, " +
                " g.street_name AS streetName, " +
                " g.name, " +
                " address " +
                " g.address " +
                " FROM " +
                " base_org g " +
                " JOIN base_org_user u ON g.`code` = u.org_code " +
                " JOIN base_org_user u ON g.code = u.org_code " +
                " WHERE  " +
                " u.user_id = '" + id + "'";
        List<Map<String, Object>> org = jdbcTemplate.queryForList(sql);

+ 153 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/service/channel/RemindDoctorService.java

@ -0,0 +1,153 @@
package com.yihu.jw.service.channel;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
import com.yihu.jw.hospital.prescription.service.PrescriptionService;
import com.yihu.jw.util.RemindDoctorJob;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.YkyySMSService;
import com.yihu.jw.wechat.enterprise.EnterpriseService;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Service
public class RemindDoctorService {
    private static final Logger logger = LoggerFactory.getLogger(RemindDoctorService.class);
    @Autowired
    private SystemMessageDao systemMessageDao;
    @Autowired
    private OutpatientDao outpatientDao;
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private EnterpriseService enterpriseService;
    @Value("${wechat.id}")
    private String wechatId;
    @Autowired
    private PrescriptionService prescriptionService;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    public void sendSystemMessage() {
        try {
            List<WlyyOutpatientDO> list = outpatientDao.findDoctorRemindMessage();
            WlyyHospitalSysDictDO wlyyHospitalSysDictDO = wlyyHospitalSysDictDao.findById("isCirculation");//是否重复提醒
            List<WlyyHospitalSysDictDO> dictDOS =wlyyHospitalSysDictDao.findByDictNameAndDictCode("RECEPTION_REMINDER","time");
            Long doctorRemindTime =0l;
            if (dictDOS!=null&&dictDOS.size()>0){
                doctorRemindTime = Long.parseLong(dictDOS.get(0).getDictValue());
            }
            String baseUrl = prescriptionService.findDomainUrlInDict();
            String msg = "";
            String sex = "";
            String age="";
            String date = "";
            String title = "";
            for (WlyyOutpatientDO wlyyOutpatientDO : list) {
                Long lastRemindTime=wlyyOutpatientDO.getLastRemindTime()==null?wlyyOutpatientDO.getCreateTime().getTime():wlyyOutpatientDO.getLastRemindTime().getTime();
                Long nowTime = new Date().getTime();
                if (StringUtils.isNoneBlank(wlyyOutpatientDO.getDoctor())&&!StringUtils.isNoneBlank(wlyyOutpatientDO.getRemindDoctor())&&(nowTime-lastRemindTime)>doctorRemindTime*1000*60) {
                    logger.info("条件满足开始发送提醒"+wlyyOutpatientDO.getId());
                    sex= IdCardUtil.getSexForIdcard(wlyyOutpatientDO.getIdcard());
                    age = IdCardUtil.getAgeForIdcard(wlyyOutpatientDO.getIdcard())+"";
                    Long createTime = wlyyOutpatientDO.getCreateTime().getTime();
                    Long minusts = TimeUnit.MILLISECONDS.toMinutes(nowTime - createTime);
                    SystemMessageDO systemMessageDO = new SystemMessageDO();
                    if ("2".equals(wlyyOutpatientDO.getOutpatientType())) {
                        systemMessageDO.setTitle("协同门诊消息提醒");
                        systemMessageDO.setType("3");
                    } else if ("3".equals(wlyyOutpatientDO.getOutpatientType())) {//专家咨询
                        //1.图文 2.视频 3家医
                        if ("1".equals(wlyyOutpatientDO.getType())) {
                            systemMessageDO.setTitle("图文咨询消息提醒");
                            systemMessageDO.setType("18");
                            title = "图文咨询消息提醒";
                            msg = wlyyOutpatientDO.getPatientName()+"("+sex+" "+age+"岁)向您发起了图文咨询,已等待"+minusts+"分钟。点击接诊";
                        } else if ("3".equals(wlyyOutpatientDO.getType())) {
                            systemMessageDO.setTitle("家医咨询消息提醒");
                            systemMessageDO.setType("15");
                        } else {
                            systemMessageDO.setTitle("视频咨询消息提醒");
                            systemMessageDO.setType("17");
                            title = "视频咨询消息提醒";
                            date = DateUtil.dateToStrLong(wlyyOutpatientDO.getRegisterDate());
                            msg = wlyyOutpatientDO.getPatientName()+"("+sex+" "+age+"岁)预约了"+date+"的视频咨询,点击查看";
                        }
                    } else if ("1".equals(wlyyOutpatientDO.getOutpatientType())) {//在线复诊
                        //1.图文 2.视频
                        if ("1".equals(wlyyOutpatientDO.getType())) {
                            systemMessageDO.setTitle("图文复诊消息提醒");
                            systemMessageDO.setType("1");
                            title = "图文复诊消息提醒";
                            msg = wlyyOutpatientDO.getPatientName()+"("+sex+" "+age+"岁)向您发起了图文复诊,已等待"+minusts+"分钟。点击接诊";
                        } else {
                            systemMessageDO.setTitle("视频复诊消息提醒");
                            systemMessageDO.setType("2");
                            title = "视频复诊消息提醒";
                            date = DateUtil.dateToStrLong(wlyyOutpatientDO.getRegisterDate());
                            msg = wlyyOutpatientDO.getPatientName()+"("+sex+" "+age+"岁)预约了"+date+"的视频复诊,点击查看";
                        }
                    }
                    JSONObject data = new JSONObject();
                    data.put("name", wlyyOutpatientDO.getPatientName());
                    data.put("age", IdCardUtil.getAgeForIdcard(wlyyOutpatientDO.getIdcard()));
                    data.put("gender", IdCardUtil.getSexForIdcard_new(wlyyOutpatientDO.getIdcard()));
                    data.put("question", wlyyOutpatientDO.getDescription());
                    data.put("msg", systemMessageDO.getTitle());
                    data.put("waitTime",minusts);
                    systemMessageDO.setData(data.toString());
                    systemMessageDO.setReceiver(wlyyOutpatientDO.getDoctor());
                    systemMessageDO.setReceiverName(wlyyOutpatientDO.getDoctorName());
                    systemMessageDO.setRelationCode(wlyyOutpatientDO.getId());
                    systemMessageDO.setSender(wlyyOutpatientDO.getPatient());
                    systemMessageDO.setSenderName(wlyyOutpatientDO.getPatientName());
                    systemMessageDO.setRelationCode(wlyyOutpatientDO.getId());
                    systemMessageDO.setIsRead("0");
                    systemMessageDO.setDel("1");
                    systemMessageDO.setCreateTime(new Date());
                    systemMessageDao.save(systemMessageDO);
                    //系统消息结束===开始发送企业模板消息
                    if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                        String url=baseUrl+"/hlwyy/ims-app-web/#/onlineChat/detail?_rs_title="+wlyyOutpatientDO.getDescription()+"&type=3&id="+wlyyOutpatientDO.getId();
                        enterpriseService.sendTWMesByDoctor("zsyy",wlyyOutpatientDO.getDoctor(),title,msg,url);
                    }else if(wechatId.equalsIgnoreCase("xm_ykyy_wx")){
                        String url=baseUrl+"/ims-app-web/#/onlineChat/detail?_rs_title="+wlyyOutpatientDO.getDescription()+"&type=3&id="+wlyyOutpatientDO.getId();
                        enterpriseService.sendTWMesByDoctor("xm_ykyy_wx",wlyyOutpatientDO.getDoctor(),title,msg,url);
                    }else if (wechatId.equalsIgnoreCase("xm_xzzx_wx")){
                        String url=baseUrl+"/hlwyy/ims-app-web/#/onlineChat/detail?_rs_title="+wlyyOutpatientDO.getDescription()+"&type=3&id="+wlyyOutpatientDO.getId();
                        enterpriseService.sendTWMesByDoctor("xm_xzzx_wx",wlyyOutpatientDO.getDoctor(),title,msg,url);
                    }
                    if (wlyyHospitalSysDictDO!=null){
                        if ("1".equalsIgnoreCase(wlyyHospitalSysDictDO.getDictValue())){
                            wlyyOutpatientDO.setRemindDoctor("1");
                        }
                    }
                    wlyyOutpatientDO.setLastRemindTime(new Date());
                    outpatientDao.save(wlyyOutpatientDO);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

+ 77 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/util/RemindDoctorJob.java

@ -0,0 +1,77 @@
package com.yihu.jw.util;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.service.channel.PrescriptionStatusUpdateService;
import com.yihu.jw.service.channel.RemindDoctorService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
@Lazy(false)
@Component
@EnableScheduling
public class RemindDoctorJob implements SchedulingConfigurer {
    private static final Logger logger = LoggerFactory.getLogger(RemindDoctorJob.class);
    private static String cron = "0 */1 * * * ?";//"0 0 0 * * ?";0 */5 * * * ?
    public RemindDoctorJob(){
        cron="0 */1 * * * ?";
        System.out.println("初始化时的corn"+cron);
    }
    @Autowired
    private RemindDoctorService remindDoctorService;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    public String change(String corIn) {
        if (StringUtils.isNotBlank(corIn)) {
            cron = corIn;
        }
        return cron;
    }
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.addTriggerTask(new Runnable() {
            @Override
            public void run() {
                try {
                    List<WlyyHospitalSysDictDO> dictDOS =wlyyHospitalSysDictDao.findByDictNameAndDictCode("RECEPTION_REMINDER","OPEN");
                    if (dictDOS!=null&&dictDOS.size()>0){
                        if ("1".equalsIgnoreCase(dictDOS.get(0).getDictValue())){//配置中的value值如果为1则表示开启发送提醒功能
                            logger.info("配置开始发送提醒========remindDoctor========");
                            remindDoctorService.sendSystemMessage();
                        }else {
                            logger.info("配置发送提醒关闭");
                        }
                    }else {
                        logger.info("若无配置则发送提醒关闭");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    logger.error("END===ERROE===remindDoctor,message:"+e.getMessage());
                }
            }
        }, new Trigger() {
            @Override
            public Date nextExecutionTime(TriggerContext triggerContext) {
                // 任务触发,可修改任务的执行周期
                CronTrigger trigger = new CronTrigger(cron);
                System.out.println("remindDoctor,可修改任务的执行周期"+cron);
                Date nextExec = trigger.nextExecutionTime(triggerContext);
                return nextExec;
            }
        });
    }
}

+ 9 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/web/quota/JobController.java

@ -15,6 +15,7 @@ import com.yihu.jw.job.ykyy.YkyyDataUploadJob;
import com.yihu.jw.repository.job.QuartzJobConfigDao;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.service.channel.PrescriptionStatusUpdateService;
import com.yihu.jw.service.channel.RemindDoctorService;
import com.yihu.jw.service.quota.JobService;
import com.yihu.jw.util.AutoTimeOutRemind;
import com.yihu.jw.util.OverdueJob;
@ -78,6 +79,8 @@ public class JobController extends BaseController {
    private YkyyPrescriptionService ykyyPrescriptionService;
    @Autowired
    private PrescriptionStatusUpdateService prescriptionStatusUpdateService;
    @Autowired
    private RemindDoctorService remindDoctorService;
    @Autowired
    public JobController(JobService jobService, QuartzHelper quartzHelper) {
@ -729,5 +732,11 @@ public class JobController extends BaseController {
                                @RequestParam(value = "endTime", required = false)String endTime, Integer status, Integer page , Integer pageSize){
        return success(ykyyPrescriptionService.saveVideoFileList(startTime,endTime,status,page,pageSize));
    }
    @RequestMapping(value = "/testRemindDoctor", method = RequestMethod.GET)
    @ApiOperation("测试发送消息")
    public String testRemindDoctor(){
        remindDoctorService.sendSystemMessage();
        return success("发送成功");
    }
}

+ 1 - 1
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/patient/PatientNoLoginEndPoint.java

@ -247,7 +247,7 @@ public class PatientNoLoginEndPoint extends EnvelopRestEndpoint {
    ) throws Exception{
        logger.info("findDoctorByHospitalAndDiseaseAndDept start:"+ DateUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm:ss:SSS"));
        return prescriptionService.findDoctorByHospitalAndDiseaseAndDept(iswork,patientid,
        return prescriptionService.findDoctorByHospitalAndDiseaseAndDept2(iswork,patientid,
                orgCode,dept,
                diseaseKey,doctorNameKey,
                jobTitleNameKey,outpatientType,