|
@ -0,0 +1,272 @@
|
|
|
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.SignFamily;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientFamilyMemberDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.service.app.sign.FamilyContractService;
|
|
|
import com.yihu.wlyy.service.common.SMSService;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 家庭成员服务
|
|
|
* <p>
|
|
|
* Created by lyr on 2016/10/17.
|
|
|
*/
|
|
|
public class FamilyMemberService extends BaseService {
|
|
|
@Autowired
|
|
|
PatientFamilyMemberDao memberDao;
|
|
|
@Autowired
|
|
|
PatientDao patientDao;
|
|
|
@Autowired
|
|
|
SMSService smsService;
|
|
|
@Autowired
|
|
|
FamilyContractService contractService;
|
|
|
@Autowired
|
|
|
JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
/**
|
|
|
* 添加家庭成员
|
|
|
*
|
|
|
* @param patient 患者
|
|
|
* @param member 成员
|
|
|
* @param catcha 验证码
|
|
|
* @return
|
|
|
*/
|
|
|
public int addMember(String patient, String member, String catcha, int relation) {
|
|
|
Patient p = patientDao.findByCode(patient);
|
|
|
Patient m = patientDao.findByCode(member);
|
|
|
|
|
|
if (p == null) {
|
|
|
return -1;
|
|
|
}
|
|
|
// 添加的成员是否注册判断
|
|
|
if (m == null) {
|
|
|
return -2;
|
|
|
}
|
|
|
// 验证码验证
|
|
|
if (smsService.check(m.getMobile(), 9, catcha) != 1) {
|
|
|
return -3;
|
|
|
}
|
|
|
// 添加自己与对方的关系
|
|
|
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(patient);
|
|
|
fmt.setFamilyMember(member);
|
|
|
}
|
|
|
|
|
|
// 对方与自己的关系转换
|
|
|
int relationTrans = familyRelationTrans(p, relation);
|
|
|
fmt.setFamilyRelation(relationTrans);
|
|
|
fmt.setCzrq(new Date());
|
|
|
|
|
|
memberDao.save(fm);
|
|
|
memberDao.save(fmt);
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改家庭成员关系
|
|
|
*
|
|
|
* @param patient 居民
|
|
|
* @param member 成员
|
|
|
* @param relation 关系
|
|
|
* @return
|
|
|
*/
|
|
|
public int modifyFamilyRelation(String patient, String member, int relation) {
|
|
|
Patient p = patientDao.findByCode(patient);
|
|
|
Patient m = patientDao.findByCode(member);
|
|
|
|
|
|
if (p == null) {
|
|
|
return -1;
|
|
|
}
|
|
|
// 成员是否注册判断
|
|
|
if (m == null) {
|
|
|
return -2;
|
|
|
}
|
|
|
|
|
|
// 自己与对方的关系
|
|
|
PatientFamilyMember fm = memberDao.findByPatientAndFamilyMember(patient, member);
|
|
|
if (fm == null) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
fm.setFamilyRelation(relation);
|
|
|
fm.setCzrq(new Date());
|
|
|
|
|
|
// 对方与自己的关系
|
|
|
PatientFamilyMember fmt = memberDao.findByPatientAndFamilyMember(member, patient);
|
|
|
|
|
|
// 不存在则创建
|
|
|
if (fmt == null) {
|
|
|
fmt = new PatientFamilyMember();
|
|
|
fmt.setPatient(patient);
|
|
|
fmt.setFamilyMember(member);
|
|
|
}
|
|
|
|
|
|
int relationTrans = familyRelationTrans(p, relation);
|
|
|
fmt.setFamilyRelation(relationTrans);
|
|
|
fmt.setCzrq(new Date());
|
|
|
|
|
|
memberDao.save(fm);
|
|
|
memberDao.save(fmt);
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除家庭成员
|
|
|
*
|
|
|
* @param patient 居民
|
|
|
* @param member 成员
|
|
|
* @return
|
|
|
*/
|
|
|
public int deleteMember(String patient, String member) {
|
|
|
// 自己与对方的关系
|
|
|
PatientFamilyMember fm = memberDao.findByPatientAndFamilyMember(patient, member);
|
|
|
if (fm == null) {
|
|
|
return -1;
|
|
|
}
|
|
|
// 对方与自己的关系
|
|
|
PatientFamilyMember fmt = memberDao.findByPatientAndFamilyMember(member, patient);
|
|
|
|
|
|
memberDao.delete(fm);
|
|
|
if (fmt != null) {
|
|
|
memberDao.delete(fmt);
|
|
|
}
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断成员是否注册
|
|
|
*
|
|
|
* @param idcard 身份证号
|
|
|
* @return
|
|
|
*/
|
|
|
public Patient isRegister(String idcard) {
|
|
|
Patient p = patientDao.findByIdcard(idcard);
|
|
|
return p;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取居民的家庭成员
|
|
|
*
|
|
|
* @param patient 居民
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONArray getPatientFamilyMembers(String patient) {
|
|
|
JSONArray resultArray = new JSONArray();
|
|
|
String sql = "select * " +
|
|
|
" from " +
|
|
|
" wlyy_patient_family_member t1, " +
|
|
|
" patient t2 " +
|
|
|
" where " +
|
|
|
" t2.code in (select family_member from wlyy_patient_family_member where patient = ? ) " +
|
|
|
" and t1.patient = ? " +
|
|
|
" and t1.patient = t2.code ";
|
|
|
|
|
|
List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{patient, patient});
|
|
|
|
|
|
if (result != null && result.size() > 0) {
|
|
|
for (Map<String, Object> map : result) {
|
|
|
JSONObject obj = new JSONObject();
|
|
|
List<SignFamily> signs = contractService.findAllSignByPatient(patient);
|
|
|
boolean ssSign = false;
|
|
|
boolean jtSign = false;
|
|
|
|
|
|
for (SignFamily sign : signs) {
|
|
|
if (sign.getType() == 1) {
|
|
|
ssSign = true;
|
|
|
} else {
|
|
|
jtSign = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
obj.put("code", map.get("code"));
|
|
|
obj.put("name", map.get("name"));
|
|
|
obj.put("idcard", map.get("idcard"));
|
|
|
obj.put("photo", map.get("photo"));
|
|
|
obj.put("mobile", map.get("mobile"));
|
|
|
obj.put("address", map.get("address"));
|
|
|
obj.put("familyRelation", map.get("family_relation"));
|
|
|
if (ssSign && jtSign) {
|
|
|
obj.put("signType", 3);
|
|
|
} else if (!ssSign && jtSign) {
|
|
|
obj.put("signType", 2);
|
|
|
} else if (ssSign && !jtSign) {
|
|
|
obj.put("signType", 1);
|
|
|
} else {
|
|
|
obj.put("signType", 0);
|
|
|
}
|
|
|
|
|
|
resultArray.put(obj);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return resultArray;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 家庭关系转换
|
|
|
*
|
|
|
* @param patient 居民
|
|
|
* @param relation 关系 1父亲 2母亲 3老公 4老婆 5儿子 6女儿 7其他
|
|
|
* @return
|
|
|
*/
|
|
|
public int familyRelationTrans(Patient patient, int relation) {
|
|
|
int relationTrans = 0;
|
|
|
|
|
|
switch (relation) {
|
|
|
case 1:
|
|
|
case 2:
|
|
|
if (patient.getSex() == 1) {
|
|
|
relationTrans = 5;
|
|
|
} else {
|
|
|
relationTrans = 6;
|
|
|
}
|
|
|
break;
|
|
|
case 3:
|
|
|
relation = 4;
|
|
|
break;
|
|
|
case 4:
|
|
|
relation = 3;
|
|
|
break;
|
|
|
case 5:
|
|
|
case 6:
|
|
|
if (patient.getSex() == 1) {
|
|
|
relationTrans = 1;
|
|
|
} else {
|
|
|
relationTrans = 2;
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return relationTrans;
|
|
|
}
|
|
|
}
|