|
@ -8,11 +8,15 @@ import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.entity.patient.SignFamily;
|
|
|
import com.yihu.wlyy.entity.patient.SignFamilyRenew;
|
|
|
import com.yihu.wlyy.repository.patient.SignFamilyDao;
|
|
|
import com.yihu.wlyy.repository.patient.SignFamilyRenewDao;
|
|
|
import com.yihu.wlyy.service.app.team.AdminTeamService;
|
|
|
import com.yihu.wlyy.service.common.SMSService;
|
|
|
import com.yihu.wlyy.service.common.account.DoctorService;
|
|
|
import com.yihu.wlyy.service.common.account.PatientService;
|
|
|
import com.yihu.wlyy.service.system.SystemDictService;
|
|
|
import com.yihu.wlyy.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONException;
|
|
@ -54,6 +58,10 @@ public class SignWebService extends BaseService {
|
|
|
private AdminTeamService adminTeamService;
|
|
|
@Autowired
|
|
|
private SystemDictService systemDictService;
|
|
|
@Autowired
|
|
|
private WeiXinOpenIdUtils weiXinOpenIdUtils;
|
|
|
@Autowired
|
|
|
private SignFamilyRenewDao signFamilyRenewDao;
|
|
|
|
|
|
/**
|
|
|
* 根据医生代码及签约状态编码 获取该医生签约患者的信息列表
|
|
@ -360,9 +368,10 @@ public class SignWebService extends BaseService {
|
|
|
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
//加入续签表数据
|
|
|
List<SignFamilyRenew> renews = jdbcTemplate.queryForList(
|
|
|
"SELECT * FROM wlyy_sign_family_renew t " +
|
|
|
"WHERE t.patient = '"+patient+"' AND t.status <> -1 and t.status <> -2",SignFamilyRenew.class);
|
|
|
// List<SignFamilyRenew> renews = jdbcTemplate.queryForList(
|
|
|
// "SELECT * FROM wlyy_sign_family_renew t " +
|
|
|
// "WHERE t.patient = '"+patient+"' AND t.status <> -1 and t.status <> -2",SignFamilyRenew.class);
|
|
|
List<SignFamilyRenew> renews = signFamilyRenewDao.findAllActiveSignByPatient(patient);
|
|
|
|
|
|
for(SignFamilyRenew renew: renews){
|
|
|
AdminTeam adminTeam = null;
|
|
@ -706,4 +715,243 @@ public class SignWebService extends BaseService {
|
|
|
return resultObject;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据医生代码及签约状态编码 获取该医生续签患者的信息列表
|
|
|
*
|
|
|
* @param doctor
|
|
|
* @param status
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Map<String, Object>> getSignRenewWebByDoctor(String doctor, int status, int page, int pageSize) {
|
|
|
// 查询语句
|
|
|
String sql = "select " +
|
|
|
" a.code " +
|
|
|
" ,a.doctor " +
|
|
|
" ,b.code as patient" +
|
|
|
" ,b.idcard " +
|
|
|
" ,b.name " +
|
|
|
" ,b.province_name as provinceName" +
|
|
|
" ,b.city_name as cityName" +
|
|
|
" ,b.town_name as townName" +
|
|
|
" ,b.address " +
|
|
|
" ,b.photo " +
|
|
|
" ,a.status " +
|
|
|
" ,a.id " +
|
|
|
(status == 1 ? " ,a.patient_apply_date as applyDate " : " ,a.expenses_time as applyDate ") +
|
|
|
" ,a.reason " +
|
|
|
" ,b.street_name as streetName" +
|
|
|
" ,b.sex" +
|
|
|
" ,b.openid" +
|
|
|
" from " +
|
|
|
" ( select code,patient,doctor,status,id,apply_date,patient_apply_date,expenses_time,reason,begin from wlyy_sign_family_renew where (doctor = ? or doctor_health = ?) and status = ? and type = 2" +
|
|
|
" order by begin desc ) a " +
|
|
|
" ,wlyy_patient b " +
|
|
|
" where a.patient = b.code order by a.begin desc limit " + page * pageSize + "," + pageSize;
|
|
|
|
|
|
// 未缴费查询语句
|
|
|
String sqlExpenses = "select " +
|
|
|
" a.code " +
|
|
|
" ,a.doctor " +
|
|
|
" ,b.code as patient" +
|
|
|
" ,b.name " +
|
|
|
" ,b.idcard " +
|
|
|
" ,b.province_name as provinceName" +
|
|
|
" ,b.city_name as cityName" +
|
|
|
" ,b.town_name as townName" +
|
|
|
" ,b.address " +
|
|
|
" ,b.photo " +
|
|
|
" ,a.status " +
|
|
|
" ,a.id " +
|
|
|
" ,a.apply_date as applyDate " +
|
|
|
" ,a.reason " +
|
|
|
" ,b.street_name as streetName" +
|
|
|
" ,b.sex" +
|
|
|
" ,b.openid" +
|
|
|
" from " +
|
|
|
" ( select code,patient,doctor,status,id,apply_date,reason,begin,expenses_status,LENGTH(trim(ifnull(expenses_status,''))) len from wlyy_sign_family_renew where (doctor = ? or doctor_health = ?) and status > ? and type = 2 order by begin desc ) a " +
|
|
|
" ,wlyy_patient b " +
|
|
|
" where a.patient = b.code and (a.expenses_status = '0' or a.len < 1) order by a.begin desc limit " + page * pageSize + "," + pageSize;
|
|
|
|
|
|
|
|
|
//1:待签约 2, 待缴费 3 已签约
|
|
|
Page<Object> list = null;
|
|
|
List<Map<String, Object>> patients = null;
|
|
|
switch (status) {
|
|
|
case 1:// 待处理
|
|
|
patients = jdbcTemplate.queryForList(sql, new Object[]{doctor, doctor, 0});
|
|
|
break;
|
|
|
case 2:// 待缴费
|
|
|
patients = jdbcTemplate.queryForList(sqlExpenses, new Object[]{doctor, doctor, 1});
|
|
|
break;
|
|
|
case 3:// 已签约
|
|
|
patients = jdbcTemplate.queryForList(sql, new Object[]{doctor, doctor, 1});
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return patients;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量提醒用户
|
|
|
* @param access_token
|
|
|
* @param doctor
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public int sendRenewToPatients(String access_token,String doctor) throws Exception{
|
|
|
String sql = "SELECT p.name,p.openid,t.doctor_name doctorName,p.code,p.mobile FROM wlyy_sign_family t ,wlyy_patient p " +
|
|
|
"WHERE t.patient = p.code AND t.doctor = ? AND t.status >=0 AND t.expenses_status ='1' AND " +
|
|
|
"NOT EXISTS" +
|
|
|
"(SELECT 1 FROM wlyy_sign_family_renew a WHERE a.patient =t.patient) ";
|
|
|
|
|
|
List<Map<String,Object>> signFamilies = jdbcTemplate.queryForList(sql,new Object[]{doctor});
|
|
|
|
|
|
if(signFamilies!=null&&signFamilies.size()>0){
|
|
|
for(Map<String,Object> signFamily : signFamilies){
|
|
|
String openid = (String)signFamily.get("openid");
|
|
|
String name = (String)signFamily.get("name");
|
|
|
String doctorName =(String)signFamily.get("doctorName");
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
|
|
json.put("keyword1", "续签家庭医生");
|
|
|
json.put("keyword2", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
|
|
|
json.put("remark","提醒医生 :"+doctorName+"\n"
|
|
|
+"我们将继续为您提供优质的健康服务。");
|
|
|
if(StringUtils.isNotBlank(openid)){
|
|
|
json.put("first",name+",您好!\n" +
|
|
|
"您的家庭医生签约将于7月31日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");
|
|
|
PushMsgTask.getInstance().putWxMsg(access_token, 16, openid, name, json);
|
|
|
return 1;
|
|
|
}else{
|
|
|
//如果自己没有绑定,则发给家人
|
|
|
String code = (String)signFamily.get("code");
|
|
|
JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(code);
|
|
|
Patient member = (Patient)j.get("member");
|
|
|
Patient p = patientService.findByCode(code);
|
|
|
if(StringUtils.isNotBlank(member.getOpenid())){
|
|
|
json.put("first",weiXinOpenIdUtils.getTitleMes(p,(int)j.get("relation"),member.getName())+"\n"+
|
|
|
name+",您好!\n" +
|
|
|
"您的家庭医生签约将于7月31日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");
|
|
|
PushMsgTask.getInstance().putWxMsg(access_token, 16, member.getOpenid(), member.getName(), json);
|
|
|
return 1;
|
|
|
}else{
|
|
|
//发送短信
|
|
|
String mobile = (String)signFamily.get("mobile");
|
|
|
if(StringUtils.isNotBlank(mobile)){
|
|
|
SMSService.sendMsg(mobile,name+"您好!您的家庭医生将于7月31日到期,为了继续给您提供健康服务,请关注“厦门i健康”公众号,回复“续签”,进行家庭医生线上续签。");
|
|
|
return 2;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 同意或拒绝签约签约
|
|
|
* @param access_token
|
|
|
* @param dotorCode
|
|
|
* @param state 1成功 0拒绝
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public int agreeRenew(String access_token,String dotorCode,String patientCode,String state) throws Exception{
|
|
|
List<SignFamilyRenew> renews = signFamilyRenewDao.findByDoctorAndPatient(dotorCode,patientCode);
|
|
|
|
|
|
if(renews==null||renews.size()==0){
|
|
|
renews = signFamilyRenewDao.findByDoctorHealthAndPatient(dotorCode,patientCode);
|
|
|
}
|
|
|
|
|
|
if(renews!=null&&renews.size()>0){
|
|
|
for(SignFamilyRenew renew : renews){
|
|
|
if(StringUtils.isNotBlank(state)){
|
|
|
if ("0".equals(state)){
|
|
|
renew.setStatus(-2);
|
|
|
}else if("1".equals(state)){
|
|
|
renew.setStatus(1);
|
|
|
}
|
|
|
}
|
|
|
renew.setStatus(1);
|
|
|
signFamilyRenewDao.save(renew);
|
|
|
|
|
|
//发送微信模板消息
|
|
|
JSONObject data = new JSONObject();
|
|
|
data.put("doctorName",renew.getDoctorName());
|
|
|
data.put("date",DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
|
|
|
data.put("content","家庭医生续签");
|
|
|
|
|
|
Patient patient = patientService.findByCode(renew.getPatient());
|
|
|
if(patient!=null && StringUtils.isNotBlank(patient.getOpenid())){
|
|
|
|
|
|
if ("0".equals(state)){
|
|
|
data.put("first",renew.getName()+",您好!\n"+
|
|
|
"您的家庭医生续签申请已被拒绝");
|
|
|
data.put("remark","您可在到期后选择其他医生进行签约。");
|
|
|
PushMsgTask.getInstance().putWxMsg(access_token, 2, patient.getOpenid(), patient.getName(), data);
|
|
|
}else if("1".equals(state)){
|
|
|
data.put("first",renew.getName()+",您好!\n"+
|
|
|
"您的家庭医生续签申请已通过");
|
|
|
data.put("remark","待自动扣费成功后,家庭医生将续签成功。");
|
|
|
PushMsgTask.getInstance().putWxMsg(access_token, 1, patient.getOpenid(), patient.getName(), data);
|
|
|
}
|
|
|
}else{
|
|
|
//如果自己没有绑定,则发给家人
|
|
|
JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient.getCode());
|
|
|
Patient member = (Patient)j.get("member");
|
|
|
if(StringUtils.isNotBlank(member.getOpenid())){
|
|
|
|
|
|
if ("0".equals(state)){
|
|
|
data.put("first",weiXinOpenIdUtils.getTitleMes(patient,(int)j.get("relation"),member.getName())+"\n"+
|
|
|
patient.getName()+",您好!\n" +
|
|
|
"您的家庭医生续签申请已被拒绝");
|
|
|
data.put("remark","您可在到期后选择其他医生进行签约。");
|
|
|
PushMsgTask.getInstance().putWxMsg(access_token, 2, member.getOpenid(), member.getName(), data);
|
|
|
}else if("1".equals(state)){
|
|
|
data.put("first",weiXinOpenIdUtils.getTitleMes(patient,(int)j.get("relation"),member.getName())+"\n"+
|
|
|
patient.getName()+",您好!\n" +
|
|
|
"您的家庭医生续签申请已通过");
|
|
|
data.put("remark","待自动扣费成功后,家庭医生将续签成功。");
|
|
|
PushMsgTask.getInstance().putWxMsg(access_token, 1, member.getOpenid(), member.getName(), data);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取年度列表
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getRenewYearCount(String doctorCode){
|
|
|
StringBuffer sql = new StringBuffer("SELECT t.sign_year,COUNT(1) count " +
|
|
|
"FROM wlyy_sign_family t WHERE t.doctor ='"+doctorCode+"' AND t.end <=NOW() AND t.status=-4 AND sign_year IS NOT NULL GROUP BY t.sign_year DESC");
|
|
|
List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql.toString());
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("result",rs);
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取用户信息
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getOverDuePatients(String year,String doctorCode,Integer page,Integer pageSize){
|
|
|
StringBuffer sql = new StringBuffer("SELECT IFNULL(year( from_days( datediff( now(), p.birthday))),'未知') age," +
|
|
|
"p.code,p.idcard,p.name,p.mobile,p.openid,p.phone,p.photo," +
|
|
|
"p.ssc,t.sign_type,p.sex,t.emer_mobile,t.expenses_time,t.expenses_status " +
|
|
|
"FROM wlyy_sign_family t ,wlyy_patient p " +
|
|
|
"WHERE t.patient = p.code AND t.doctor ='"+doctorCode+"' AND t.sign_year ='"+year+"' LIMIT "+page*pageSize+","+pageSize+";");
|
|
|
List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql.toString());
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("result",rs);
|
|
|
return json;
|
|
|
}
|
|
|
}
|