소스 검색

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

demon 8 년 전
부모
커밋
449087a35b

+ 53 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/patient/PatientFamilyMember.java

@ -0,0 +1,53 @@
package com.yihu.wlyy.entity.patient;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * 家庭成员表
 *
 * Created by lyr on 2016/10/17.
 */
@Entity
@Table(name = "wlyy_patient_family_member")
public class PatientFamilyMember extends IdEntity {
    // 居民cdoe
    private String patient;
    // 家庭成员
    private String familyMember;
    // 家庭关系
    private Integer familyRelation;
    // 操作日期
    private Date czrq;
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public String getFamilyMember() {
        return familyMember;
    }
    public void setFamilyMember(String familyMember) {
        this.familyMember = familyMember;
    }
    public Integer getFamilyRelation() {
        return familyRelation;
    }
    public void setFamilyRelation(Integer familyRelation) {
        this.familyRelation = familyRelation;
    }
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 34 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientFamilyMemberDao.java

@ -0,0 +1,34 @@
package com.yihu.wlyy.repository.patient;
import com.yihu.wlyy.entity.patient.PatientFamilyMember;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * 家庭成员
 *
 * Created by lyr on 2016/10/17.
 */
public interface PatientFamilyMemberDao extends PagingAndSortingRepository<PatientFamilyMember, Long>,
        JpaSpecificationExecutor<PatientFamilyMember> {
    /**
     * 查询居民的某个成员
     *
     * @param patient 居民
     * @param member 成员
     * @return
     */
    PatientFamilyMember findByPatientAndFamilyMember(String patient,String member);
    /**
     * 查找某个居民的家庭成员
     *
     * @param patient 居民
     * @return
     */
    List<PatientFamilyMember> findByPatient(String patient);
}

+ 3 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java

@ -302,4 +302,7 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
	@Query("select a from SignFamily a where a.type = ?1 and a.signSource = ?2 and a.status > 0 and a.id >= ?3 and a.id <= ?4 order by a.id")
	Page<SignFamily> findByTypeAndSignSourceAndId(Integer type,String signSource,Long start,Long end,Pageable pageable);
	@Query("select a from SignFamily a where a.patient = ?1 and a.status > 0")
	List<SignFamily> findAllSignByPatient(String patient);
}

+ 8 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/DoctorInfoService.java

@ -720,11 +720,17 @@ public class DoctorInfoService extends BaseService {
            return -1;
        }
        Doctor docMobile = doctorDao.findByMobile(mobile);
        if (docMobile != null) {
            return -2;
        }
        // 验证码验证
        int smsCheck = smsService.check(mobile, type == 1 ? 7 : 8, captcha);
        int smsCheck = smsService.check(mobile, type == 1 ? 8 : 9, captcha);
        // 验证失败,不允许变更
        if (smsCheck != 1) {
            return -2;
            return -3;
        }
        doc.setMobile(mobile);

+ 8 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/PatientInfoService.java

@ -76,11 +76,17 @@ public class PatientInfoService extends BaseService {
			return -1;
		}
		Patient pMobile = patientDao.findByMobile(mobile);
		if (pMobile == null) {
			return -2;
		}
		// 验证码验证
		int smsCheck = smsService.check(mobile, type == 1 ? 7 : 8, captcha);
		int smsCheck = smsService.check(mobile, type == 1 ? 8 : 9, captcha);
		// 验证失败,不允许变更
		if (smsCheck != 1) {
			return -2;
			return -3;
		}
		p.setMobile(mobile);

+ 287 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyMemberService.java

@ -0,0 +1,287 @@
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 org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * 家庭成员服务
 * <p>
 * Created by lyr on 2016/10/17.
 */
@Service
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 captcha 验证码
     * @return
     */
    public int addMember(String patient, String member, String captcha, 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, captcha) != 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 -3;
        }
        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 JSONObject isRegister(String idcard) {
        JSONObject result = new JSONObject();
        Patient p = patientDao.findByIdcard(idcard);
        if (p == null) {
            result.put("isRegister",0);
        } else {
            result.put("isRegister",1);
            result.put("patient",p);
        }
        return result;
    }
    /**
     * 获取居民的家庭成员
     *
     * @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 if (patient.getSex() == 2) {
                    relationTrans = 6;
                } else {
                    relationTrans = 0;
                }
                break;
            case 3:
                relationTrans = 4;
                break;
            case 4:
                relationTrans = 3;
                break;
            case 5:
            case 6:
                if (patient.getSex() == 1) {
                    relationTrans = 1;
                } else if (patient.getSex() == 1) {
                    relationTrans = 2;
                } else {
                    relationTrans = 0;
                }
                break;
        }
        return relationTrans;
    }
}

+ 10 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -1534,4 +1534,14 @@ public class FamilyContractService extends BaseService {
        return signFamilyDao.findNoHealthSignFamilyHealth(doctor, pageRequest);
    }
    /**
     * 查询居民的所有签约
     *
     * @param patient
     * @return
     */
    public List<SignFamily> findAllSignByPatient(String patient) {
        return signFamilyDao.findAllSignByPatient(patient);
    }
}

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

@ -33,7 +33,8 @@ public class SMSService extends BaseService {
     * 发送短信验证码接口
     *
     * @param mobile 手机号
     * @param type   消息类型:1微信端注册,2微信端找回密码,3医生端找回密码,4患者登录,5医生登录,6用户变更手机号验证 7用户新手机号验证 8绑定手机号
     * @param type   消息类型:1微信端注册,2微信端找回密码,3医生端找回密码,4患者登录,5医生登录,7用户变更手机号验证 8用户新手机号验证 9绑定手机号
     *               10 家庭成员添加验证
     * @return
     * @throws Exception
     */
@ -83,15 +84,18 @@ public class SMSService extends BaseService {
        } else if (type == 4 || type == 5) {
            // 登录
            sms.setContent("您的登录验证码为:" + captcha);
        } else if (type == 6) {
        } else if (type == 7) {
            // 手机号变更验证
            sms.setContent("【厦门市民健康系统】您的更换手机号验证码为:" + captcha);
        } else if (type == 7) {
        } else if (type == 8) {
            // 新手机号绑定验证
            sms.setContent("【厦门市民健康系统】您的新手机号验证码为:" + captcha);
        } else if (type == 8) {
        } else if (type == 9) {
            // 新手机号绑定验证
            sms.setContent("【厦门市民健康系统】您绑定手机号的验证码为:" + captcha);
        } else if (type == 10) {
            // 新手机号绑定验证
            sms.setContent("【厦门市民健康系统】XXX欲添加您为家人,验证码为:" + captcha + "。如您同意,可告知其验证码;如其非您的家人,请忽略本短信。");
        } else {
            // 其他验证码
            sms.setContent("验证码:" + captcha);
@ -99,7 +103,7 @@ public class SMSService extends BaseService {
        sms.setCaptcha(captcha);
        Date date = new Date();
        // 延后5分钟
        sms.setDeadline(DateUtil.getNextMin(date, 5));
        sms.setDeadline(DateUtil.getNextMin(date, type == 10 ? 30 : 5));
        sms.setCzrq(date);
        sms.setMobile(mobile);
        sms.setIp(ip);
@ -124,7 +128,7 @@ public class SMSService extends BaseService {
     * 验证码校验
     *
     * @param mobile  手机号
     * @param type    type 消息类型:1微信端注册,2微信端找回密码,3医生端找回密码,4患者登录,5医生登录 6用户变更手机号 7用户新手机号验证 8用户绑定手机号
     * @param type    type 消息类型:1微信端注册,2微信端找回密码,3医生端找回密码,4患者登录,5医生登录 7用户变更手机号 8用户新手机号验证 9用户绑定手机号
     * @param captcha 验证码
     * @return -1验证码过期,-1验证码错误,0验证码无效,1验证通过
     */

+ 3 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/sms/SMSController.java

@ -32,14 +32,15 @@ public class SMSController extends BaseController {
	/**
	 * 发送短信验证码接口
	 * @param mobile 手机号
	 * @param type 消息类型:1微信端注册,2微信端找回密码,3医生端找回密码,4患者登录,5医生登录 .6患者签约验证
	 * @param type 消息类型:1微信端注册,2微信端找回密码,3医生端找回密码,4患者登录,5医生登录 .6患者签约验证 7用户变更手机号验证 8用户新手机号验证 9绑定手机号
	 *             10 家庭成员添加验证
	 * @return
	 */
	@RequestMapping(value = "captcha", method = RequestMethod.POST)
	@ResponseBody
	public String send(String mobile, int type, @RequestParam(required = false) String captchaToken) {
		try {
			if (type != 1 && type != 2 && type != 3 && type != 4 && type != 5&& type != 6) {
			if (type > 10 || type < 1) {
				return error(-1, "无效的请求!");
			}
			if (StringUtils.isEmpty(mobile)) {

+ 12 - 10
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/account/DoctorController.java

@ -1459,7 +1459,7 @@ public class DoctorController extends BaseController {
     *
     * @param mobile  新手机号
     * @param captcha 验证码
     * @param type 1:变更手机号  2:绑定手机号
     * @param type    1:变更手机号  2:绑定手机号
     * @return
     */
    @RequestMapping(value = "/mobile_update", method = RequestMethod.POST)
@ -1480,8 +1480,9 @@ public class DoctorController extends BaseController {
            if (result == -1) {
                return error(-1, "医生信息查找失败");
            }
            if (result == -2) {
            } else if (result == -2) {
                return error(-1, "手机已注册");
            } else if (result == -3) {
                return error(-1, "验证码错误");
            } else if (result == 1) {
                return write(200, "手机号更新成功");
@ -1496,20 +1497,21 @@ public class DoctorController extends BaseController {
    /**
     * 修改密码
     *
     * @param newPassword1 新密码1
     * @param newPassword2 新密码2
     * @param oldPassword 旧密码
     * @param doctorCode 医生code
     * @param oldPassword  旧密码
     * @param doctorCode   医生code
     * @return
     */
    @RequestMapping(value = "/updatePassword", method = RequestMethod.POST )
    @RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
    @ResponseBody
    public String updatePassword(String newPassword1,
                                           String newPassword2,
                                           String oldPassword,
                                           String doctorCode) {
                                 String newPassword2,
                                 String oldPassword,
                                 String doctorCode) {
        try {
            doctorInfoService.updatePassword(newPassword1, newPassword2, oldPassword,doctorCode);
            doctorInfoService.updatePassword(newPassword1, newPassword2, oldPassword, doctorCode);
            return write(200, "更新成功");
        } catch (Exception e) {
            e.printStackTrace();

+ 3 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/account/PatientController.java

@ -667,8 +667,9 @@ public class PatientController extends WeixinBaseController {
            if (result == -1) {
                return error(-1, "居民信息查找失败");
            }
            if (result == -2) {
            } else if(result == -2) {
                return error(-1, "手机号已注册");
            } else if (result == -3) {
                return error(-1, "验证码错误");
            } else if (result == 1) {
                return write(200, "手机号更新成功");

+ 172 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/family/FamilyMemberController.java

@ -0,0 +1,172 @@
package com.yihu.wlyy.web.patient.family;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonAnyFormatVisitor;
import com.yihu.wlyy.service.app.family.FamilyMemberService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
 * 家庭关系成员控制器
 * <p>
 * Created by lyr-pc on 2016/10/18.
 */
@RestController
@RequestMapping(value = "/patient/family")
@Api(description = "家庭成员")
public class FamilyMemberController extends BaseController {
    @Autowired
    FamilyMemberService familyMemberService;
    /**
     * 添加成员
     *
     * @param member   成员code
     * @param captcha  验证码
     * @param relation 关系
     * @return
     */
    @RequestMapping(value = "/member_add", method = RequestMethod.POST)
    @ApiOperation(value = "添加成员")
    public String addFamilyMember(String member, String captcha, int relation) {
        try {
            if (StringUtils.isEmpty(member)) {
                return error(-1, "添加成员不能为空");
            }
            if (StringUtils.isEmpty(captcha)) {
                return error(-1, "验证码不能为空");
            }
            if (relation < 0 || relation > 6) {
                return error(-1, "家庭关系无效");
            }
            int result = familyMemberService.addMember(getUID(), member, captcha, relation);
            if (result == -1) {
                return error(-1, "居民信息查询失败");
            } else if (result == -2) {
                return error(-1, "该成员未注册");
            } else if (result == -3) {
                return error(-1, "验证码无效");
            } else if (result == -4) {
                return error(-1, "该家庭成员已存在");
            } else {
                return write(200, "添加成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "添加失败");
        }
    }
    /**
     * 更新家庭关系
     *
     * @param member   成员code
     * @param relation 家庭关系
     * @return
     */
    @RequestMapping(value = "/relation_update", method = RequestMethod.POST)
    @ApiOperation(value = "家庭成员关系修改")
    public String modifyFamilyRelation(String member, int relation) {
        try {
            if (StringUtils.isEmpty(member)) {
                return error(-1, "添加成员不能为空");
            }
            if (relation < 0 || relation > 6) {
                return error(-1, "家庭关系无效");
            }
            int result = familyMemberService.modifyFamilyRelation(getUID(), member, relation);
            if (result == -1) {
                return error(-1, "居民信息查询失败");
            } else if (result == -2) {
                return error(-1, "该成员未注册");
            } else if (result == -3) {
                return error(-1, "与该成员的关系不存在");
            } else {
                return write(200, "更新成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "更新失败");
        }
    }
    /**
     * 删除成员
     *
     * @param member
     * @return
     */
    @RequestMapping(value = "/member_delete", method = RequestMethod.POST)
    @ApiOperation(value = "家庭成员删除")
    public String deleteMember(String member) {
        try {
            if (StringUtils.isEmpty(member)) {
                return error(-1, "成员不能为空");
            }
            int result = familyMemberService.deleteMember(getUID(), member);
            if (result == -1) {
                return error(-1, "与该成员的关系不存在");
            } else {
                return write(200, "删除成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "删除失败");
        }
    }
    /**
     * 家庭成员查询
     *
     * @return
     */
    @RequestMapping(value = "/members", method = RequestMethod.GET)
    @ApiOperation(value = "家庭成员查询")
    public String getPatientFamilyMembers() {
        try {
            JSONArray result = familyMemberService.getPatientFamilyMembers(getUID());
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    /**
     * 根据身份证号查询居民是否注册
     *
     * @param idcard 身份证号
     * @return
     */
    @RequestMapping(value = "/is_register", method = RequestMethod.GET)
    @ApiOperation(value = "家庭成员查询")
    public String isRegister(String idcard) {
        try {
            if (StringUtils.isEmpty(idcard)) {
                return error(-1, "身份证号不能为空");
            }
            JSONObject result = familyMemberService.isRegister(idcard);
            return write(-1, "查询成功", "data", result);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
}