Browse Source

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

lyr 8 years ago
parent
commit
ef4806b334

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

@ -197,11 +197,6 @@
            <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>

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

@ -1,6 +1,5 @@
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;
@ -12,7 +11,10 @@ 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.task.RemindExpensesTask;
import com.yihu.wlyy.task.RemindFocusWechatTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
@ -53,13 +55,13 @@ public class PatientRemindService extends BaseService {
    JdbcTemplate jdbcTemplate;
    @Autowired
    ConsultService consultService;
    /**
     * 缴费提醒
     *
     * @param doctor 医生
     * @throws Exception
     */
    @Async
    public void remindPatientExpensesAll(String doctor) throws Exception {
        try {
            Doctor doc = doctorDao.findByCode(doctor);
@ -89,38 +91,53 @@ public class PatientRemindService extends BaseService {
     * @param hos
     */
    public void RemindAll(Doctor doc, Hospital hos) throws Exception {
            boolean flag = true;
            int page = 0;
            int start = 0;
            String sql = "select p.* " +
                    "     from " +
                    "        wlyy_sign_family f join wlyy_patient p on f.patient = p.code " +
                    "     where " +
                    "        (f.doctor = ? or f.doctor_health = ?) " +
                    "        and f.status > 0 " +
                    "        and f.type = 2 " +
                    "        and (f.expenses_status = '0' or LENGTH(trim(ifnull(f.expenses_status,''))) < 1) " +
                    "     limit ?,3000";
            while (flag) {
                List<Patient> result = jdbcTemplate.query(sql, new Object[]{doc.getCode(), doc.getCode(), start}, new BeanPropertyRowMapper(Patient.class));
                if (result != null && result.size() > 0) {
                    for (Patient p : result) {
                        if (p != null) {
                            Boolean epTime = redisTemplate.opsForSet().isMember("expenses:remind:set", p.getCode());
                            if (epTime) {
                                continue;
                            }
                            remindPatientExpenses(p, doc, hos, true);
        Calendar today = Calendar.getInstance();
        today.set(Calendar.HOUR, 23);
        today.set(Calendar.MINUTE, 59);
        today.set(Calendar.SECOND, 59);
        today.set(Calendar.MILLISECOND, 59);
        boolean flag = true;
        int page = 0;
        int start = 0;
        String sql = "select p.* " +
                "     from " +
                "        wlyy_sign_family f join wlyy_patient p on f.patient = p.code " +
                "     where " +
                "        (f.doctor = ? or f.doctor_health = ?) " +
                "        and f.status > 0 " +
                "        and f.type = 2 " +
                "        and (f.expenses_status = '0' or LENGTH(trim(ifnull(f.expenses_status,''))) < 1) " +
                "     limit ?,3000";
        List<Patient> patients = new ArrayList<>();
        List<String> redisPatients = new ArrayList<>();
        Set<String> exists = redisTemplate.opsForSet().members("expenses:remind:set");
        while (flag) {
            List<Patient> result = jdbcTemplate.query(sql, new Object[]{doc.getCode(), doc.getCode(), start}, new BeanPropertyRowMapper(Patient.class));
            if (result != null && result.size() > 0) {
                patients.addAll(result);
                for (Patient p : result) {
                    if (p != null) {
                        if (exists != null && exists.contains(p.getCode())) {
                            continue;
                        }
                        redisPatients.add(p.getCode());
                    }
                    page = page + 1;
                    start = page * 3000;
                } else {
                    flag = false;
                }
                page = page + 1;
                start = page * 3000;
            } else {
                flag = false;
            }
        }
        if (patients.size() > 0) {
            RemindExpensesTask task = new RemindExpensesTask(patients, doc, hos);
            new Thread(task).run();
            redisTemplate.opsForSet().add("expenses:remind:set", redisPatients.toArray(new String[]{}));
            redisTemplate.expireAt("expenses:remind:set", today.getTime());
        }
    }
    /**
@ -148,7 +165,7 @@ public class PatientRemindService extends BaseService {
                throw new Exception("patient info can not find");
            }
            return remindPatientExpenses(p, doc, hos, false);
            return remindPatientExpenses(p, doc, hos);
        } catch (Exception e) {
            e.printStackTrace();
            JSONObject reObj = new JSONObject();
@ -166,14 +183,13 @@ public class PatientRemindService extends BaseService {
     * @param hos 医院
     * @return
     */
    public JSONObject remindPatientExpenses(Patient p, Doctor doc, Hospital hos, boolean ignore) throws Exception {
    public JSONObject remindPatientExpenses(Patient p, Doctor doc, Hospital hos) throws Exception {
        try {
            Calendar today = Calendar.getInstance();
            today.set(Calendar.HOUR,23);
            today.set(Calendar.MINUTE,59);
            today.set(Calendar.SECOND,59);
            today.set(Calendar.MILLISECOND,59);
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            today.set(Calendar.HOUR, 23);
            today.set(Calendar.MINUTE, 59);
            today.set(Calendar.SECOND, 59);
            today.set(Calendar.MILLISECOND, 59);
            JSONObject reObj = new JSONObject();
            String mDesc = "";
            boolean mFlag = false;
@ -209,16 +225,12 @@ public class PatientRemindService extends BaseService {
                wFlag = true;
            }
            //发送IM
            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());
            }
            consultService.sendMucMessageBySingnType(doc.getCode(), doc.getName(), p.getCode(), doc.getName() + "医生提醒您:为完成家庭医生签约," +
                    "尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费", "1", "医生:" + doc.getName() + "给患者:" + p.getName() + "发送了缴费提醒!");
            if (wFlag || mFlag) {
                reObj.put("status", 200);
                redisTemplate.opsForSet().add("expenses:remind:set",p.getCode());
                redisTemplate.opsForSet().add("expenses:remind:set", p.getCode());
                redisTemplate.expireAt("expenses:remind:set", today.getTime());
                if (wFlag && mFlag) {
                    reObj.put("msg", "提醒成功");
@ -253,7 +265,6 @@ public class PatientRemindService extends BaseService {
        }
    }
    /**
     * 提醒患者关注微信
     *
@ -293,9 +304,13 @@ public class PatientRemindService extends BaseService {
     *
     * @param doctor
     */
    @Async
    public void remindPatientWechatFocusAll(String doctor) throws Exception {
        try {
            Calendar today = Calendar.getInstance();
            today.set(Calendar.HOUR, 23);
            today.set(Calendar.MINUTE, 59);
            today.set(Calendar.SECOND, 59);
            today.set(Calendar.MILLISECOND, 59);
            int page = 0;
            int start = 0;
            boolean flag = true;
@ -311,17 +326,19 @@ public class PatientRemindService extends BaseService {
                    "        and f.status > 0 " +
                    "        and f.expenses_status = '1' " +
                    "        and LENGTH(trim(ifnull(p.openid,''))) < 1 limit ?,3000";
            List<Map<String, Object>> patients = new ArrayList<>();
            List<String> redisPatients = new ArrayList<>();
            Set<String> exist = redisTemplate.opsForSet().members("wechat:focus:remind:set");
            while (flag) {
                List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{doctor, doctor, start});
                if (result != null && result.size() > 0) {
                    patients.addAll(result);
                    for (Map<String, Object> map : result) {
                        boolean epTime = redisTemplate.opsForSet().isMember("wechat:focus:remind:set", map.get("code").toString());
                        if (epTime) {
                        if (exist != null && exist.contains(map.get("code").toString())) {
                            continue;
                        }
                        remindWechatFocus(map, doc);
                        redisPatients.add(map.get("code").toString());
                    }
                    page = page + 1;
                    start = page * 3000;
@ -330,6 +347,13 @@ public class PatientRemindService extends BaseService {
                }
            }
            if (patients.size() > 0) {
                RemindFocusWechatTask task = new RemindFocusWechatTask(patients, doc);
                new Thread(task).run();
                redisTemplate.opsForSet().add("wechat:focus:remind:set", redisPatients.toArray(new String[]{}));
                redisTemplate.expireAt("wechat:focus:remind:set", today.getTime());
            }
            redisTemplate.opsForValue().set("wechat:focus:remind:doctor:" + doctor, "0");
            redisTemplate.expire("wechat:focus:remind:doctor:" + doctor, 10, TimeUnit.MINUTES);
        } catch (Exception e) {
@ -339,7 +363,6 @@ public class PatientRemindService extends BaseService {
        }
    }
    /**
     * 微信关注提醒
     *
@ -349,13 +372,12 @@ public class PatientRemindService extends BaseService {
     */
    public JSONObject remindWechatFocus(Map<String, Object> p, Doctor doctor) {
        Calendar today = Calendar.getInstance();
        today.set(Calendar.HOUR,23);
        today.set(Calendar.MINUTE,59);
        today.set(Calendar.SECOND,59);
        today.set(Calendar.MILLISECOND,59);
        today.set(Calendar.HOUR, 23);
        today.set(Calendar.MINUTE, 59);
        today.set(Calendar.SECOND, 59);
        today.set(Calendar.MILLISECOND, 59);
        JSONObject result = new JSONObject();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        redisTemplate.opsForSet().add("wechat:focus:remind:set",p.get("code").toString());
        redisTemplate.opsForSet().add("wechat:focus:remind:set", p.get("code").toString());
        redisTemplate.expireAt("wechat:focus:remind:set", today.getTime());
        if (p.get("mobile") == null || StringUtils.isEmpty(p.get("mobile").toString())) {

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/SMSService.java

@ -139,7 +139,7 @@ public class SMSService extends BaseService {
     * @param content
     * @return
     */
    public JSONObject sendMsg(String mobile, String content) {
    public static JSONObject sendMsg(String mobile, String content) {
        // 调用总部发送信息的接口
        String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(content, mobile), "GBK");
        JSONObject json = toJson(result);

+ 74 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/task/RemindExpensesTask.java

@ -0,0 +1,74 @@
package com.yihu.wlyy.task;
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.service.app.consult.ConsultService;
import com.yihu.wlyy.service.common.SMSService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import javax.print.Doc;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
 * 缴费提醒任务
 * <p>
 * Created by lyr-pc on 2017/1/16.
 */
public class RemindExpensesTask implements Runnable {
    List<Patient> patients;
    Doctor doctor;
    Hospital hospital;
    @Autowired
    WeiXinAccessTokenUtils tokenUtils;
    @Autowired
    ConsultService consultService;
    public RemindExpensesTask(List<Patient> patients, Doctor doctor, Hospital hospital) {
        this.patients = patients;
        this.doctor = doctor;
        this.hospital = hospital;
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
    }
    @Override
    public void run() {
        for (Patient p : patients) {
            try {
                if (StringUtils.isNotEmpty(p.getMobile())) {
                    JSONObject result = SMSService.sendMsg(p.getMobile(), doctor.getName() + "医生提醒您:为完成家庭医生签约," +
                            "尽早为您提供家庭医生服务,请尽快到" + hospital.getName() + "(地址:" + hospital.getAddress() + ")缴费");
                }
                if (StringUtils.isNotEmpty(p.getOpenid())) {
                    // 微信提醒
                    JSONObject json = new JSONObject();
                    json.put("first", "缴费提醒");
                    json.put("toUser", p.getCode());
                    json.put("name", p.getName());
                    json.put("doctor", doctor.getCode());
                    json.put("doctorName", doctor.getName());
                    json.put("date", DateUtil.dateToStrShort(new Date()));
                    json.put("content", p.getName() + ",您好!为完成家庭医生签约,尽早为您提供家庭医生服务,请尽快到" + hospital.getName() + "(地址:" + hospital.getAddress() + ")缴费");
                    json.put("remark", "");
                    // 添加到发送队列
                    PushMsgTask.getInstance().putWxMsg(tokenUtils.getAccessToken(), 8, p.getOpenid(), p.getName(), json);
                }
                //发送IM
                consultService.sendMucMessageBySingnType(doctor.getCode(), doctor.getName(), p.getCode(), doctor.getName() + "医生提醒您:为完成家庭医生签约," +
                        "尽早为您提供家庭医生服务,请尽快到" + doctor.getName() + "(地址:" + hospital.getAddress() + ")缴费", "1", "医生:" + hospital.getName() + "给患者:" + p.getName() + "发送了缴费提醒!");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

+ 50 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/task/RemindFocusWechatTask.java

@ -0,0 +1,50 @@
package com.yihu.wlyy.task;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.service.common.SMSService;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
/**
 * 居民微信关注提醒
 * <p>
 * Created by lyr-pc on 2017/1/16.
 */
public class RemindFocusWechatTask implements Runnable {
    List<Map<String, Object>> patients;
    Doctor doctor;
    /**
     * 构造函数
     *
     * @param patients 居民列表
     */
    public RemindFocusWechatTask(List<Map<String, Object>> patients, Doctor doctor) {
        this.patients = patients;
        this.doctor = doctor;
    }
    @Override
    public void run() {
        for (Map<String, Object> p : patients) {
            try {
                if (p.get("mobile") == null || StringUtils.isEmpty(p.get("mobile").toString())) {
                    continue;
                }
                String msg = "尊敬的" + p.get("name").toString() + "," + doctor.getName() + "医生提醒您:" +
                        "为更好地为您提供健康服务,请您关注并登录\"厦门i健康\"微信公众号,与医生进行互动。";
                JSONObject smsResult = SMSService.sendMsg(p.get("mobile").toString(), msg);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}