|
@ -2,26 +2,27 @@ package com.yihu.wlyy.service.app.family;
|
|
|
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.entity.patient.PatientFamilyMember;
|
|
|
import com.yihu.wlyy.entity.patient.PatientFamilyTemp;
|
|
|
import com.yihu.wlyy.entity.patient.SignFamily;
|
|
|
import com.yihu.wlyy.entity.patient.invitation.PatientInvitationLog;
|
|
|
import com.yihu.wlyy.entity.security.AccessToken;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientFamilyMemberDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientFamilyTempDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientInvitationLogDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.service.app.sign.FamilyContractService;
|
|
|
import com.yihu.wlyy.service.common.SMSService;
|
|
|
import com.yihu.wlyy.service.common.account.AccessTokenService;
|
|
|
import com.yihu.wlyy.util.HttpUtil;
|
|
|
import com.yihu.wlyy.util.IdCardUtil;
|
|
|
import com.yihu.wlyy.util.MD5;
|
|
|
import com.yihu.wlyy.util.SystemConf;
|
|
|
import com.yihu.wlyy.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.util.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.Date;
|
|
@ -48,6 +49,8 @@ public class FamilyMemberService extends BaseService {
|
|
|
FamilyContractService contractService;
|
|
|
@Autowired
|
|
|
private AccessTokenService accessTokenService;
|
|
|
@Autowired
|
|
|
private PatientFamilyTempDao patientFamilyTempDao;
|
|
|
|
|
|
@Autowired
|
|
|
JdbcTemplate jdbcTemplate;
|
|
@ -498,11 +501,10 @@ public class FamilyMemberService extends BaseService {
|
|
|
/**
|
|
|
* 验证添加的家庭成员
|
|
|
*
|
|
|
* @param code 用于查询openId
|
|
|
* @param menber 预绑定成员
|
|
|
* @return 0未绑定微信,1仅绑定微信,2仅绑定手机,3手机微信都绑定
|
|
|
*/
|
|
|
public JSONObject checkFamilyMember(String code, String menber,String sus) throws Exception {
|
|
|
public JSONObject checkFamilyMember(String menber) throws Exception {
|
|
|
|
|
|
JSONObject r = new JSONObject();
|
|
|
|
|
@ -511,43 +513,46 @@ public class FamilyMemberService extends BaseService {
|
|
|
|
|
|
//1.判断微信过滤
|
|
|
//判断是否绑定微信,如果版绑定了微信,将状态改变为 1
|
|
|
if(sus.equals("1")){
|
|
|
result = 1;
|
|
|
}
|
|
|
|
|
|
Patient p = patientDao.findByCode(menber);
|
|
|
|
|
|
if (StringUtils.isNotBlank(p.getOpenid())) {
|
|
|
String sus = getIsSus(p.getOpenid());
|
|
|
if(StringUtils.isNotBlank(sus)){
|
|
|
if ("1".equals(sus)) {
|
|
|
result = 1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//2.判断手机过滤
|
|
|
//判断是否绑定了手机
|
|
|
Patient p = patientDao.findByCode(menber);
|
|
|
if(StringUtils.isNoneBlank(p.getMobile())){
|
|
|
|
|
|
if (StringUtils.isNoneBlank(p.getMobile())) {
|
|
|
//如果用户绑定了微信,将状态更改为4
|
|
|
if(result == 1){
|
|
|
if (result == 1) {
|
|
|
result = 3;
|
|
|
//如果用户未绑定微信,将状态更改为2
|
|
|
}else if(result == 0){
|
|
|
result = 2 ;
|
|
|
//如果用户未绑定微信,将状态更改为2
|
|
|
} else if (result == 0) {
|
|
|
result = 2;
|
|
|
}
|
|
|
}
|
|
|
//返回过滤后的状态
|
|
|
r.put("state",result);
|
|
|
if(result==0){
|
|
|
r.put("mes","未绑定微信和手机");
|
|
|
}else if(result==1){
|
|
|
r.put("mes","仅绑定微信");
|
|
|
}else if(result==2){
|
|
|
r.put("mes","仅绑定手机");
|
|
|
}else if(result==3){
|
|
|
r.put("mes","手机和微信皆绑定");
|
|
|
r.put("state", result);
|
|
|
if (result == 0) {
|
|
|
r.put("mes", "未绑定微信和手机");
|
|
|
} else if (result == 1) {
|
|
|
r.put("mes", "仅绑定微信");
|
|
|
} else if (result == 2) {
|
|
|
r.put("mes", "仅绑定手机");
|
|
|
} else if (result == 3) {
|
|
|
r.put("mes", "手机和微信皆绑定");
|
|
|
}
|
|
|
|
|
|
return r;
|
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取微信的access_token
|
|
|
*
|
|
@ -584,18 +589,230 @@ public class FamilyMemberService extends BaseService {
|
|
|
|
|
|
/**
|
|
|
* 查询所有待处理列表
|
|
|
*
|
|
|
* @param code
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getFamilyMesList(String code){
|
|
|
public JSONObject getFamilyMesList(String code) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(getFamilyMesListSql(code));
|
|
|
result.put("mes",list);
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(getFamilyMesListSql(code));
|
|
|
result.put("mes", list);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public String getFamilyMesListSql(String code){
|
|
|
StringBuffer sql = new StringBuffer("SELECT t.*,p.idcard,p.mobile FROM wlyy_patient_family_temp t,wlyy_patient p WHERE t.patient = p.code AND t.dealer ="+code);
|
|
|
public String getFamilyMesListSql(String code) {
|
|
|
StringBuffer sql = new StringBuffer("SELECT t.*,p.idcard,p.mobile FROM wlyy_patient_family_temp t,wlyy_patient p WHERE t.patient = p.code AND t.dealer ='" + code+"'");
|
|
|
return sql.toString();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过用户名密码添加
|
|
|
*
|
|
|
* @param patient
|
|
|
* @param member
|
|
|
* @param password
|
|
|
* @param relation
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Transactional
|
|
|
public int addMemberByPw(String patient, String member, String password, int relation) throws Exception {
|
|
|
|
|
|
if (patient.equals(member)) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
Patient p = patientDao.findByCode(patient);
|
|
|
Patient m = patientDao.findByCode(member);
|
|
|
|
|
|
if (p == null) {
|
|
|
return -1;
|
|
|
}
|
|
|
// 添加的成员是否注册判断
|
|
|
if (m == null) {
|
|
|
return -2;
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isNotEmpty(password)) {
|
|
|
String loginPassword = MD5.GetMD5Code(password + m.getSalt());
|
|
|
if (!loginPassword.equals(m.getPassword())) {
|
|
|
return -3;
|
|
|
}
|
|
|
}
|
|
|
return addMemberFamily(p, m, patient, member, relation);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过微信模板添加
|
|
|
*
|
|
|
* @param id
|
|
|
* @param state
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Transactional
|
|
|
public int addMenberByWXTemp(Long id, String state) throws Exception {
|
|
|
if (StringUtils.isNotBlank(state)) {
|
|
|
//同意添加
|
|
|
if ("1".equals(state)) {
|
|
|
PatientFamilyTemp temp = patientFamilyTempDao.findOne(id);
|
|
|
|
|
|
if (temp.getPatient().equals(temp.getFamilyMember())) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
Patient p = patientDao.findByCode(temp.getPatient());
|
|
|
Patient m = patientDao.findByCode(temp.getFamilyMember());
|
|
|
if (p == null) {
|
|
|
return -1;
|
|
|
}
|
|
|
// 添加的成员是否注册判断
|
|
|
if (m == null) {
|
|
|
return -2;
|
|
|
}
|
|
|
return addMemberFamily(p, m, temp.getPatient(), temp.getFamilyMember(), temp.getFamilyRelation());
|
|
|
//不同意添加
|
|
|
} else if ("2".equals(state)) {
|
|
|
PatientFamilyTemp temp = patientFamilyTempDao.findOne(id);
|
|
|
temp.setState("2");
|
|
|
patientFamilyTempDao.save(temp);
|
|
|
return 2;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
public int addMemberByCaptcha(String patient, String member, String captcha, int relation) throws Exception {
|
|
|
|
|
|
if (patient.equals(member)) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
Patient p = patientDao.findByCode(patient);
|
|
|
Patient m = patientDao.findByCode(member);
|
|
|
if (p == null) {
|
|
|
return -1;
|
|
|
}
|
|
|
// 添加的成员是否注册判断
|
|
|
if (m == null) {
|
|
|
return -2;
|
|
|
}
|
|
|
|
|
|
// 验证码验证
|
|
|
if (StringUtils.isNotEmpty(captcha)) {
|
|
|
int checkStatus = smsService.check(m.getMobile(), 10, captcha);
|
|
|
if (checkStatus == -2) {
|
|
|
return -6; // 验证码过期
|
|
|
} else if (checkStatus == -1) {
|
|
|
return -3; // 验证码错误
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return addMemberFamily(p, m, patient, member, relation);
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
public int addMemberFamily(Patient p, Patient m, String patient, String member, int relation) throws Exception {
|
|
|
|
|
|
if (relation < 5) {
|
|
|
List<PatientFamilyMember> familyMembers = memberDao.findByPatientAndFamilyRelation(patient, relation);
|
|
|
|
|
|
if (familyMembers != null && familyMembers.size() > 0) {
|
|
|
return -5;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 添加自己与对方的关系
|
|
|
PatientFamilyMember fm = memberDao.findByPatientAndFamilyMember(patient, member);
|
|
|
// 家庭关系已存在时,不重复添加
|
|
|
if (fm != null) {
|
|
|
return -4;
|
|
|
} else {
|
|
|
fm = new PatientFamilyMember();
|
|
|
fm.setPatient(patient);
|
|
|
fm.setFamilyMember(member);
|
|
|
}
|
|
|
fm.setFamilyRelation(relation);
|
|
|
fm.setCzrq(new Date());
|
|
|
|
|
|
// 添加对方与自己的关系
|
|
|
PatientFamilyMember fmt = memberDao.findByPatientAndFamilyMember(member, patient);
|
|
|
// 不存在则创建
|
|
|
if (fmt == null) {
|
|
|
fmt = new PatientFamilyMember();
|
|
|
fmt.setPatient(member);
|
|
|
fmt.setFamilyMember(patient);
|
|
|
}
|
|
|
|
|
|
// 对方与自己的关系转s
|
|
|
//int relationTrans = familyRelationTrans(p, relation);
|
|
|
int relationTrans = familyRelationTrans(p, relation);
|
|
|
fmt.setFamilyRelation(relationTrans);
|
|
|
fmt.setCzrq(new Date());
|
|
|
|
|
|
memberDao.save(fm);
|
|
|
memberDao.save(fmt);
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
public int sendWXTemp(String patient, String member, String access_token, int relation) {
|
|
|
|
|
|
Patient p = patientDao.findByCode(patient);
|
|
|
Patient m = patientDao.findByCode(member);
|
|
|
|
|
|
if (p == null) {
|
|
|
return -1;
|
|
|
}
|
|
|
// 添加的成员是否注册判断
|
|
|
if (m == null) {
|
|
|
return -2;
|
|
|
}
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("frist", m.getName() + ",您好!" + p.getName() + "向您发起添加家人申请,添加成功后,对方可使用您的账号,为您处理各类健康服务。");
|
|
|
json.put("keyword1", "添加家人申请");
|
|
|
json.put("keyword2", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
|
|
|
json.put("keyword3", p.getName());
|
|
|
json.put("keyword4", relations.get(relation));
|
|
|
json.put("remark", "点击立即处理。");
|
|
|
json.put("member", member);
|
|
|
//此消息为定向推送,无需家人代收
|
|
|
PushMsgTask.getInstance().putWxMsg(access_token, 12, m.getOpenid(), p.getName(), json);
|
|
|
|
|
|
PatientFamilyTemp temp = new PatientFamilyTemp();
|
|
|
temp.setState("0");
|
|
|
temp.setCzrq(new Date());
|
|
|
temp.setDealer(member);
|
|
|
temp.setPatient(patient);
|
|
|
temp.setPatientName(p.getName());
|
|
|
temp.setFamilyMember(member);
|
|
|
temp.setFamilyRelation(relation);
|
|
|
//保存消息列表
|
|
|
patientFamilyTempDao.save(temp);
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取subscribe
|
|
|
*
|
|
|
* @param openid
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public String getIsSus(String openid) throws Exception {
|
|
|
String userInfo_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + getAccessToken() + "&openid=" + openid + "&lang=zh_CN";
|
|
|
String params = "";
|
|
|
String result = HttpUtil.sendGet(userInfo_url, params);
|
|
|
JSONObject json = new JSONObject(result);
|
|
|
if (json.has("subscribe")) {
|
|
|
return json.get("subscribe").toString();
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|