Browse Source

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

linzhuo 8 years ago
parent
commit
6a597ceb25

+ 25 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/config/quartz/JobFactory.java

@ -0,0 +1,25 @@
package com.yihu.wlyy.config.quartz;
import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.stereotype.Component;
/**
 * Created by Administrator on 2016.10.12.
 * 為了讓quartz種可以使用Spring的注入
 */
@Component("jobFactory")
public class JobFactory extends AdaptableJobFactory {
    @Autowired
    private AutowireCapableBeanFactory capableBeanFactory;
    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
        // 调用父类的方法
        Object jobInstance = super.createJobInstance(bundle);
       // 进行注入
        capableBeanFactory.autowireBean(jobInstance);
        return jobInstance;
    }
}

+ 52 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/config/quartz/SchedulerConfig.java

@ -0,0 +1,52 @@
package com.yihu.wlyy.config.quartz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import javax.sql.DataSource;
import java.io.IOException;
import java.util.Properties;
/**
 * Created by chenweida on 2016/2/3.
 */
@Configuration
public class SchedulerConfig {
    @Autowired
    private ApplicationContext applicationContext;
    @Autowired
    private JobFactory jobFactory;
    @Autowired
    private DataSource dataSource;
    @Bean
    SchedulerFactoryBean schedulerFactoryBeanWlyy() throws IOException {
        SchedulerFactoryBean bean = new SchedulerFactoryBean();
        bean.setJobFactory(jobFactory);
        bean.setApplicationContext(this.applicationContext);
        bean.setOverwriteExistingJobs(true);
        bean.setStartupDelay(20);// 延时启动
        bean.setAutoStartup(true);
        bean.setDataSource(dataSource);
        bean.setQuartzProperties(quartzProperties());
        return bean;
    }
    /**
     * quartz配置文件
     * @return
     * @throws IOException
     */
    @Bean
    public Properties quartzProperties() throws IOException {
        PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
        propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
        propertiesFactoryBean.afterPropertiesSet();
        return propertiesFactoryBean.getObject();
    }
}

+ 65 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/job/RenewToSignJob.java

@ -0,0 +1,65 @@
package com.yihu.wlyy.job;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import java.util.Calendar;
/**
 * Created by lyr-pc on 2017/3/9.
 */
@Component
public class RenewToSignJob implements Job {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        try {
            System.out.println("RenewToSign start");
            Calendar cal = Calendar.getInstance();
            int year = cal.get(Calendar.YEAR)-1;
            int month = cal.get(Calendar.MONTH)+1;
            if(month <=7){
                //设置已过期
                String sql = "UPDATE wlyy_sign_family t SET t.status = -4 WHERE t.status>=0 AND t.sign_year='"+year+"' AND t.expenses_status='1'";
                //数据迁移
                String sql2 ="INSERT INTO wlyy_sign_family(" +
                        "code,lw_code,type,patient,openid,name,idcard,ssc," +
                        "mobile,emer_mobile,hospital,hospital_name,doctor," +
                        "doctor_name,begin,end,images,group_code,status,reason," +
                        "czrq,team_code,sign_type,apply_date,release_speak," +
                        "doctor_health_name,doctor_health,family_code,patient_apply_date," +
                        "expenses,expenses_status,sign_source,sign_doctor_code,sign_doctor_name," +
                        "sign_doctor_level,patient_apply_unsgin_date,apply_unsign_date,expenses_type," +
                        "sign_year,medical_insurance_num,agent_doctor_code,agent_doctor_name," +
                        "agent_doctor_level,admin_team_code,expenses_time) " +
                        "SELECT code,lw_code,type,patient,openid,name,idcard,ssc," +
                        "mobile,emer_mobile,hospital,hospital_name,doctor,doctor_name," +
                        "begin,end,images,group_code,status,reason,czrq,team_code," +
                        "sign_type,apply_date,release_speak,doctor_health_name," +
                        "doctor_health,family_code,patient_apply_date,expenses," +
                        "expenses_status,sign_source,sign_doctor_code,sign_doctor_name," +
                        "sign_doctor_level,patient_apply_unsgin_date,apply_unsign_date," +
                        "expenses_type,sign_year,medical_insurance_num,agent_doctor_code," +
                        "agent_doctor_name,agent_doctor_level,admin_team_code,expenses_time " +
                        "FROM wlyy_sign_family_renew t WHERE t.is_valid =0 AND t.status =1 AND t.sign_year='"+(year+1)+"' AND t.expenses_status='1'";
                //更改迁移状态
                String sql3 = "UPDATE wlyy_sign_family_renew t SET t.is_valid =1 WHERE t.is_valid =0 AND t.status =1 AND t.sign_year='"+(year+1)+"' AND t.expenses_status='1'";
                jdbcTemplate.execute(sql);
                jdbcTemplate.execute(sql2);
                jdbcTemplate.execute(sql3);
            }
            System.out.println("RenewToSign end");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("RenewToSign failed");
        }
    }
}

+ 1 - 4
patient-co-wlyy/src/main/java/com/yihu/wlyy/job/SignEndJob.java

@ -35,7 +35,7 @@ public class SignEndJob implements Job {
            int sucessT = jdbcTemplate.update(sqlT, start, end);
            int sucessTm = jdbcTemplate.update(sqlTm, start, end);
            int sucess = jdbcTemplate.update(sql, start, end);
            renewToSign();
            System.out.println("sign end job end");
        } catch (Exception e) {
            e.printStackTrace();
@ -43,7 +43,4 @@ public class SignEndJob implements Job {
        }
    }
    public void renewToSign(){
    }
}

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

@ -286,6 +286,9 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
    @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status >= 0")
    SignFamily findByPatient(String patient);
    @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status >= 0")
    List<SignFamily> findByPatients(String patient);
    @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 1 and a.status >= 0")
    SignFamily findBySanshiIdcard(String idcard);

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyRenewDao.java

@ -16,7 +16,7 @@ import java.util.List;
public interface SignFamilyRenewDao extends PagingAndSortingRepository<SignFamilyRenew, Long>, JpaSpecificationExecutor<SignFamilyRenew> {
    @Query("select a from SignFamilyRenew a where a.idcard = ?1 and a.type = 2 and a.status >= 0")
    SignFamilyRenew findByIdcard(String idcard);
    List<SignFamilyRenew> findByIdcard(String idcard);
    /**
     * 获取所有有效的签约信息(不包含-1 -2)

+ 9 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelInfoService.java

@ -202,6 +202,15 @@ public class SignPatientLabelInfoService extends BaseService {
            json.put("wechatFocusRemind", 1);
        }
        String timeKey = DateUtil.dateToStr(new Date(),"yyyyMMdd");
        String flag = redisTemplate.opsForValue().get("renew:"+timeKey+":"+patient);
        if(StringUtils.isNotBlank(flag)){
            json.put("isRemainRenew","1");
        }else{
            json.put("isRemainRenew","0");
        }
        return json;
    }

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

@ -99,6 +99,9 @@ public class FamilyContractService extends BaseService {
    MessageService messageService;
    @Autowired
    AdminTeamService adminTeamService;
    @Autowired
    SignPatientLabelDao labelDao;
    @Autowired
@ -2882,15 +2885,16 @@ public class FamilyContractService extends BaseService {
     * @param patient 居民code
     * @return
     */
    @Transactional
    public int signRenew(String doctor,String healthDoctor, String patient) throws Exception {
        Patient p = patientDao.findByCode(patient);
        if (p == null) {
            return -1;
        }
        SignFamilyRenew sc = signFamilyRenewDao.findByIdcard(p.getIdcard());
        List<SignFamilyRenew> sc = signFamilyRenewDao.findByIdcard(p.getIdcard());
        //判断身份证号是否已签约
        if (sc != null) {
        if (sc != null&&sc.size()>0) {
            return -2;
        }
@ -2900,25 +2904,96 @@ public class FamilyContractService extends BaseService {
        if (d == null) {
            return -3;
        }
        if (hd == null) {
            return -3;
        }
        SignFamilyRenew sf = new SignFamilyRenew();
        //判断是否有生效记录SQL
        String sql = "SELECT t.doctor,t.team_code teamCode,t.admin_team_code adminTeamCode FROM wlyy_sign_family t WHERE t.patient ='" + patient + "' AND t.status>=0 AND t.expenses_status='1'";
        List<Map<String,Object>> signs = jdbcTemplate.queryForList(sql);
        if(signs==null||signs.size()==0){
            return -4;
        }
        Map<String,Object> sign = signs.get(0);
        //判断续签医生是否一致
        if(doctor.equals((String)sign.get("doctor"))){
            //如果一致保存团队信息
            sf.setTeamCode((String)sign.get("teamCode"));
            sf.setAdminTeamId((Long)sign.get("adminTeamId"));
        }else {
            //如果不一致 查看医生团队
            String tcSql = "SELECT t.id FROM wlyy_admin_team t WHERE t.leader_code ='"+doctor+"'";
            List<Map<String ,Object>> ids = jdbcTemplate.queryForList(tcSql);
            if(ids!=null&&ids.size()>0){
                Integer id =  (Integer)ids.get(0).get("id");
                Long lid = id.longValue();
                sf.setAdminTeamId(lid);
            }else{
                //未找到团队信息
                return -5;
            }
            //新建咨询团队组
            DoctorTeam team = new DoctorTeam();
            String code = getCode();
            team.setCode(code);
            team.setCzrq(new Date());
            team.setDel("1");
            team.setSignType("2");
            //判断是否有健康管理师
            if(hd!=null&&StringUtils.isNotBlank(hd.getName())){
                team.setName(d.getName()+","+hd.getName()+","+p.getName());
                //新建健康管理师
                DoctorTeamMember hdmb = new DoctorTeamMember();
                hdmb.setName(hd.getName());
                hdmb.setMemberCode(healthDoctor);
                hdmb.setCode(getCode());
                hdmb.setDel("1");
                hdmb.setCzrq(new Date());
                hdmb.setTeam(code);
                hdmb.setType(hd.getLevel());
                hdmb.setSignType("2");
                doctorTeamDoctor.save(hdmb);
            }else{
                team.setName(d.getName()+","+p.getName());
            }
            //新建医生成员
            DoctorTeamMember dmb = new DoctorTeamMember();
            dmb.setName(d.getName());
            dmb.setMemberCode(doctor);
            dmb.setCode(getCode());
            dmb.setDel("1");
            dmb.setCzrq(new Date());
            dmb.setTeam(code);
            dmb.setType(d.getLevel());
            dmb.setSignType("2");
            //新建病人
            DoctorTeamMember pmb = new DoctorTeamMember();
            pmb.setName(p.getName());
            pmb.setMemberCode(patient);
            pmb.setCode(getCode());
            pmb.setDel("1");
            pmb.setCzrq(new Date());
            pmb.setTeam(code);
            pmb.setType(5);
            pmb.setSignType("2");
            doctorTeamDoctor.save(dmb);
            doctorTeamDoctor.save(pmb);
            doctorTeamDao.save(team);
            //关联新团队
            sf.setTeamCode(code);
        }
        sf.setCode(getCode());
        sf.setCzrq(new Date());
        sf.setPatientApplyDate(new Date());
        if(d!=null){
            sf.setDoctor(doctor);
            sf.setDoctorName(d.getName());
        }
        sf.setDoctor(doctor);
        sf.setDoctorName(d.getName());
        sf.setDoctorHealth(healthDoctor);
        sf.setDoctorHealthName(hd.getName());
        if(hd!=null){
            sf.setDoctorHealth(healthDoctor);
            sf.setDoctorHealthName(hd.getName());
        }
        sf.setMobile(p.getMobile());
        sf.setName(p.getName());
        sf.setIdcard(p.getIdcard());
@ -2933,8 +3008,12 @@ public class FamilyContractService extends BaseService {
        sf.setSignSource("2");//签约来源【1 社区签约 2 移动签约】
        //******************扣费接口**********************/
        sf.setExpensesStatus("0");   //扣费状态 【0未扣费 1已扣费 2已退费】
        Calendar cal = Calendar.getInstance();
        int year =cal.get(Calendar.YEAR);
        sf.setSignYear(year+"");
        sf.setIsValid(0);
        sf.setBegin(new Date());
        sf.setEnd(DateUtil.stringToDate(year+1+"-07-01 00:00:00","yyyy-MM-dd HH:mmm:ss"));
        SignFamilyRenew temp = signFamilyRenewDao.save(sf);
        if (temp != null) {

+ 141 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/SignWebService.java

@ -4,9 +4,12 @@ import java.util.*;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeamMember;
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.doctor.DoctorDao;
import com.yihu.wlyy.repository.doctor.DoctorTeamMemberDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.patient.SignFamilyRenewDao;
import com.yihu.wlyy.service.app.team.AdminTeamService;
@ -62,7 +65,8 @@ public class SignWebService extends BaseService {
    private WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    private SignFamilyRenewDao signFamilyRenewDao;
    @Autowired
    private DoctorDao doctorDao;
    /**
     * 根据医生代码及签约状态编码 获取该医生签约患者的信息列表
     *
@ -931,7 +935,7 @@ public class SignWebService extends BaseService {
     * @return
     */
    public JSONObject getRenewYearCount(String doctorCode){
        StringBuffer sql = new StringBuffer("SELECT t.sign_year,COUNT(1) count " +
        StringBuffer sql = new StringBuffer("SELECT t.sign_year labelCode,COUNT(1) amount " +
                "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();
@ -954,4 +958,139 @@ public class SignWebService extends BaseService {
        json.put("result",rs);
        return json;
    }
    /**
     * 统计
     * 咨询量、获取待预约、获取健康教育、获取健康指导
     * @param patient
     * @return
     */
    public JSONObject getSignCountInfoInYear(String patient){
        JSONObject rs = new JSONObject();
        List<SignFamily> signFamilys = signFamilyDao.findByPatients(patient);
        if(signFamilys==null||signFamilys.size()==0){
            throw new RuntimeException("找不到签约关系!");
        }
        SignFamily signFamily = signFamilys.get(0);
        String doctors_sql = "";
        if(StringUtils.isNotBlank(signFamily.getTeamCode())){
          doctors_sql = "SELECT t.member_code member,t.name FROM wlyy_doctor_team_member t WHERE t.team ='"+signFamily.getTeamCode()+"' AND t.type <>5";
        }else{
            throw new RuntimeException("找不到团队关系!");
        }
        List<Map<String,Object>> doctors = jdbcTemplate.queryForList(doctors_sql);
        String doctorCodeSql = "";
        if (doctors!=null&&doctors.size()>0){
            for(int i=0;i<doctors.size();i++){
                Map<String,Object> doctor = doctors.get(i);
                if(i==0){
                    doctorCodeSql = "'"+(String)doctor.get("member")+"'";
                }else{
                    doctorCodeSql +=",'"+(String)doctor.get("member")+"'";
                }
            }
        }
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        //咨询量
        String consult_sql = "SELECT COUNT(1) AS consultCount,d.name doctorName FROM wlyy_consult_team t,wlyy_doctor d WHERE t.doctor = d.code AND t.patient ='"+patient+"' " +
                "AND t.czrq <='"+year+"-07-01' AND t.czrq >='"+(year-1)+"-07-01' GROUP BY t.doctor DESC ";
        //获取待预约
        String reservation_sql = "SELECT COUNT(1) AS reservationCount FROM wlyy_patient_reservation  w " +
                " WHERE w.doctor in("+doctorCodeSql+") AND w.patient ='"+patient+"'" +
                " AND w.czrq <='"+year+"-07-01' AND w.czrq >='"+(year-1)+"-07-01'  ";
        //获取健康教育
        String article_sql = "SELECT COUNT(1) AS articleCount FROM wlyy_health_edu_article_patient  w,wlyy_health_edu_article w2 WHERE w.article = w2.code " +
                "AND  w.doctor IN("+doctorCodeSql+") AND w.patient ='"+patient+"' " +
                "AND w.czrq <='"+year+"-07-01' AND w.czrq >='"+(year-1)+"-07-01'  ";
        //获取健康指导
        String guidance_sql = "SELECT COUNT(1) AS guidanceCount  FROM wlyy_patient_health_guidance  w " +
                "WHERE w.doctor IN("+doctorCodeSql+") and w.patient ='"+patient+"' AND w.czrq <='"+year+"-07-01' AND w.czrq >='"+(year-1)+"-07-01'  ";
        //咨询量
        List<Map<String, Object>> consultResult = jdbcTemplate.queryForList(consult_sql);
        //待预约量
        List<Map<String, Object>> reservationResult = jdbcTemplate.queryForList(reservation_sql);
        //健康教育量
        List<Map<String, Object>> articleResult = jdbcTemplate.queryForList(article_sql);
        //健康指导量
        List<Map<String, Object>> guidanceResult = jdbcTemplate.queryForList(guidance_sql);
        Long consultTotal = 0L;
        if(consultResult!=null&&consultResult.size()>0){
            for(Map<String,Object> map :consultResult){
                Long c = (Long)map.get("consultCount");
                consultTotal+=c;
            }
        }
        rs.put("consultTotal",consultTotal);
        rs.put("consultResult",consultResult);
        rs.put("doctors",doctors);
        rs.put("reservationResult",reservationResult);
        rs.put("articleResult",articleResult);
        rs.put("guidanceResult",guidanceResult);
        return rs;
    }
    /**
     * 提醒用户续签约
     * @param access_token
     * @param patientCode
     * @param doctor
     * @return
     * @throws Exception
     */
    public int remainPatientRenew(String access_token,String patientCode,String doctor)throws Exception{
        Doctor d = doctorDao.findByCode(doctor);
        if(doctor==null){
            return -1;
        }
        //发送微信模板消息
        Patient p = patientService.findByCode(patientCode);
        JSONObject json = new JSONObject();
        json.put("keyword1", "续签家庭医生");
        json.put("keyword2", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
        json.put("remark","提醒医生 :"+d.getName()+"\n"
                +"我们将继续为您提供优质的健康服务。");
        String openid = p.getOpenid();
        String name = p.getName();
        if(StringUtils.isNotBlank(openid)){
            json.put("first",name+",您好!\n" +
                    "您的家庭医生签约将于7月31日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");
            PushMsgTask.getInstance().putWxMsg(access_token, 16, openid, name, json);
            patientSetReminFlag(patientCode);
            return 1;
        }else{
            //如果自己没有绑定,则发给家人
            JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patientCode);
            Patient member = (Patient)j.get("member");
            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);
                patientSetReminFlag(patientCode);
                return 1;
            }else{
                //发送短信
                String mobile = p.getMobile();
                if(StringUtils.isNotBlank(mobile)){
                    SMSService.sendMsg(mobile,name+"您好!您的家庭医生将于7月31日到期,为了继续给您提供健康服务,请关注“厦门i健康”公众号,回复“续签”,进行家庭医生线上续签。");
                    patientSetReminFlag(patientCode);
                    return 2;
                }
            }
        }
        return -1;
    }
    public void patientSetReminFlag(String patient){
        String dateKey = DateUtil.dateToStr(new Date(),"yyyyMMdd");
        redisTemplate.opsForValue().set("renew:"+dateKey+":"+patient,"1");
    }
}

+ 130 - 25
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java

@ -17,10 +17,12 @@ import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.security.TokenDao;
import com.yihu.wlyy.task.SignSsGetTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.EncodesUtil;
import com.yihu.wlyy.util.IdcardInfoExtractor;
import com.yihu.wlyy.util.SystemData;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@ -31,6 +33,8 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.utils.Clock;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@ -58,6 +62,8 @@ public class PatientService extends TokenService {
    JdbcTemplate jdbcTemplate;
    private Clock clock = Clock.DEFAULT;
    //可续签月份
    private int[] canRenewMonth = {4, 5, 6, 7};
    public void setClock(Clock clock) {
        this.clock = clock;
@ -214,7 +220,7 @@ public class PatientService extends TokenService {
                " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE idcard = ?";
        jdbcTemplate.update(sql, new Object[]{code, idcard, name, ssc, mobile, password, salt, imei, 1, ie.getBirthday()
                , ie.getGender(), clock.getCurrentDate(),clock.getCurrentDate(), 0, 0, 0, 0,idcard});
                , ie.getGender(), clock.getCurrentDate(), clock.getCurrentDate(), 0, 0, 0, 0, idcard});
        Patient temp = patientDao.findByIdcard(idcard);
        if (temp != null) {
@ -299,10 +305,11 @@ public class PatientService extends TokenService {
    /**
     * 判断是否续签
     *
     * @param patient
     * @return
     */
    public JSONObject checkCanRenew(String patient){
    public JSONObject checkCanRenew(String patient) {
        // 是否可以续签逻辑
        //A:wlyy_sign_family
        //B: wlyy_sign_family_renew
@ -311,60 +318,158 @@ public class PatientService extends TokenService {
        JSONObject rs = new JSONObject();
        //判断是否签约
        List<SignFamily> signs =  jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family t WHERE t.status >=0 AND t.expenses_status ='1' AND  t.patient ='"+patient+"'  AND NOW() >= t.begin AND NOW() <= t.end",SignFamily.class);
        if(signs!=null){
        List<SignFamily> signs = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family t WHERE t.status >=0 AND t.expenses_status ='1' AND  t.patient ='" + patient + "'  AND NOW() >= t.begin AND NOW() <= t.end", SignFamily.class);
        if (signs != null) {
            //当前年度已经签约
            rs.put("issign","1");
        }else{
            rs.put("issign", "1");
        } else {
            //当前年度未签约
            rs.put("issign","0");
            rs.put("issign", "0");
        }
        //A表有已签约,但还没有扣费的记录的,不允许续签
        List<SignFamily>  signFamilys1 = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family t WHERE t.status >=0 AND t.expenses_status <>'1' AND t.patient ='"+patient+"'",SignFamily.class);
        if(signFamilys1!=null){
            rs.put("isrenew","0");
        List<SignFamily> signFamilys1 = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family t WHERE t.status >=0 AND t.expenses_status <>'1' AND t.patient ='" + patient + "'", SignFamily.class);
        if (signFamilys1 != null) {
            rs.put("isrenew", "0");
            return rs;
        }
        //A表有已签约,且已扣费,当前日期超过了7月1日,且当前日期在合约的有效期范围内,不允许续签
        Calendar calendar =Calendar.getInstance();
        String year = calendar.get(Calendar.YEAR)+"";
        List<SignFamily>  signFamilys2 = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family t WHERE t.status >=0 AND t.expenses_status ='1' AND  t.patient ='"+patient+"' AND CURDATE()>'"+year+"-07-01' NOW() >= t.begin and NOW() <= t.end",SignFamily.class);
        if(signFamilys2!=null){
            rs.put("isrenew","0");
        Calendar calendar = Calendar.getInstance();
        String year = calendar.get(Calendar.YEAR) + "";
        List<SignFamily> signFamilys2 = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family t WHERE t.status >=0 AND t.expenses_status ='1' AND  t.patient ='" + patient + "' AND CURDATE()>'" + year + "-07-01' NOW() >= t.begin and NOW() <= t.end", SignFamily.class);
        if (signFamilys2 != null) {
            rs.put("isrenew", "0");
            return rs;
        }
        //B表:已签约且未生效,不允许续签
        List<SignFamilyRenew> signFamilyRenews = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family_renew t WHERE t.status>=0 AND  t.is_valid = 0 AND t.patient ='"+patient+"'",SignFamilyRenew.class);
        if(signFamilyRenews!=null){
            rs.put("isrenew","0");
        List<SignFamilyRenew> signFamilyRenews = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family_renew t WHERE t.status>=0 AND  t.is_valid = 0 AND t.patient ='" + patient + "'", SignFamilyRenew.class);
        if (signFamilyRenews != null) {
            rs.put("isrenew", "0");
            return rs;
        }
        //都未有记录则允许续签
        rs.put("isrenew","1");
        rs.put("isrenew", "1");
        return rs;
    }
    /**
     * 判断是否可以续签
     * @param patient
     * @return
     */
    public JSONObject checkCanSignRenew(String patient) {
        JSONObject rs = new JSONObject();
        //得到当前年度,和当前月份,年度
        Calendar cal = Calendar.getInstance();
        int month = cal.get(Calendar.MONTH) + 1;
        int year = cal.get(Calendar.YEAR);
        //判断是否在续签允许的范围内
        boolean flag = false;
        for (int i = 0; i < canRenewMonth.length; i++) {
            if (month == canRenewMonth[i]) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            rs.put("mes", "当前时间段不允许续签");
            rs.put("code", "-1");
            return rs;
        }
        //判断是否有生效记录SQL
        String sql = "SELECT t.id,t.sign_year signYear FROM wlyy_sign_family t WHERE t.patient ='" + patient + "' AND t.status>=0 AND t.expenses_status='1'";
        //用于判断续签表是否有记录QL,有记录则不允许续签
        String sqlRenew = "SELECT t.id,t.sign_year signYear FROM wlyy_sign_family_renew t WHERE t.patient ='" + patient + "' AND t.status>=0 ";
        //判读是否有当前年度的记录SQL
        String signSql = "SELECT t.id,t.sign_year signYear FROM wlyy_sign_family t WHERE t.patient ='" + patient + "' AND t.status>=0 AND t.expenses_status='1' AND t.sign_year ='" + year + "'";
        //判读是否有旧的已到期记录SQL
        String oldSignSql = "SELECT t.id,t.sign_year signYear FROM wlyy_sign_family t WHERE t.patient ='" + patient + "' AND t.status=-4 AND  t.expenses_status='1' AND t.sign_year ='" + (year - 1) + "'";
        //判断时间是否在6月30之前
        if (month < 7) {
            //判断是否有签约记录
            List<SignFamily> signFamilys1 = jdbcTemplate.queryForList(sql, SignFamily.class);
            if (signFamilys1 != null && signFamilys1.size() > 0) {
                //如果有记录则判断其年份是否为当前年份,如果为当前年份,不允许续签
                SignFamily sign = signFamilys1.get(0);
                if (StringUtils.isNotBlank(sign.getSignYear())) {
                    int y = Integer.parseInt(sign.getSignYear());
                    if (y == year) {
                        rs.put("mes", "当前年度已经签约");
                        rs.put("code", "-2");
                        return rs;
                        //如果不等于当前年份,则判断续签表是否有数据
                    } else {
                        return checkRenewData(sqlRenew,rs);
                    }
                } else {
                    rs.put("mes", "签约记录为脏数据");
                    rs.put("code", "0");
                    return rs;
                }
            } else {
                //没有签约记录,不允许续签,提示前往签约
                rs.put("mes", "没有签约记录,请前往签约");
                rs.put("code", "-4");
                return rs;
            }
        } else {
            //如果在签约七月份之后判断是否已经生效,判断是否有旧数据
            List<SignFamily> signFamilys1 = jdbcTemplate.queryForList(signSql, SignFamily.class);
            if (signFamilys1 != null && signFamilys1.size() > 0) {
                rs.put("mes", "当前年度已经签约");
                rs.put("code", "-2");
                return rs;
            }
            List<SignFamily> signFamilys2 = jdbcTemplate.queryForList(oldSignSql, SignFamily.class);
            if (signFamilys1 != null && signFamilys1.size() > 0) {
                rs.put("mes", ",可以续签(已到期)");
                rs.put("code", "2");
                return rs;
            } else {
                rs.put("mes", "没有签约记录,请前往签约");
                rs.put("code", "-4");
                return rs;
            }
        }
    }
    public JSONObject checkRenewData(String sqlRenew,JSONObject rs){
        List<SignFamilyRenew> renews = jdbcTemplate.queryForList(sqlRenew, SignFamilyRenew.class);
        //如果续签表没有数据,则可以续签,有数据提示已经续签
        if (renews != null && renews.size() > 0) {
            rs.put("mes", "已经提交续签");
            rs.put("code", "-3");
            return rs;
        } else {
            rs.put("mes", ",可以续签(未到期)");
            rs.put("code", "1");
            return rs;
        }
    }
    /**
     * 根据居民ID查询签约CODE
     *
     * @param patient
     * @return
     */
    public String getSignCodeByPatient(String patient){
    public String getSignCodeByPatient(String patient) {
        if(StringUtils.isBlank(patient)){
        if (StringUtils.isBlank(patient)) {
            return "";
        }
        try{
            List<SignFamily> signFamilies = jdbcTemplate.queryForList("SELECT * FROM wlyy_sign_family WHERE t.patient = '"+patient+"' AND t.status >=0 AND t.expenses_status ='1' ",SignFamily.class);
            if(signFamilies!=null && signFamilies.size()>0){
        try {
            List<SignFamily> signFamilies = jdbcTemplate.queryForList("SELECT * FROM wlyy_sign_family WHERE t.patient = '" + patient + "' AND t.status >=0 AND t.expenses_status ='1' ", SignFamily.class);
            if (signFamilies != null && signFamilies.size() > 0) {
                return signFamilies.get(0).getCode();
            }
        }catch (Exception e){
        } catch (Exception e) {
            return "";
        }
        return "";
    }
}

+ 20 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/DateUtil.java

@ -1,6 +1,7 @@
package com.yihu.wlyy.util;
import java.sql.Time;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@ -735,4 +736,23 @@ public class DateUtil {
//
		System.out.println(getNextYear(new Date(), -65));
	}
	/**
	 *  字符串转时间
	 * @param str 时间字符串
	 * @param eg 格式
	 * @return
	 */
	public static Date stringToDate(String str, String eg) {
		DateFormat format = new SimpleDateFormat(eg);
		Date date = null;
		if (str != null && !"".equals(str)) {
			try {
				date = format.parse(str);
			} catch (Exception e) {
				return null;
			}
		}
		return date;
	}
}

+ 15 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/util/ManagerUtilController.java

@ -1,6 +1,7 @@
package com.yihu.wlyy.web.common.util;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.job.RenewToSignJob;
import com.yihu.wlyy.job.SignEndJob;
import com.yihu.wlyy.job.consult.EvaluateScoreJob;
import com.yihu.wlyy.job.consult.FamousConsultTimesJob;
@ -291,4 +292,18 @@ public class ManagerUtilController extends BaseController {
            return error(-1, "启动失败");
        }
    }
    @RequestMapping(value = "/start_renew_to_sign_job")
    @ResponseBody
    public String startRenewToSignJob() {
        try {
            if (!quartzHelper.isExistJob("renew_to_sign_job")) {
                quartzHelper.startNow(RenewToSignJob.class, "renew_to_sign_job", new HashMap<String, Object>());
                return write(200, "启动成功");
            } else {
                return write(200, "任务已存在");
            }
        } catch (Exception e) {
            return error(-1, "启动失败");
        }
    }
}

+ 16 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelInfoController.java

@ -2,6 +2,7 @@ package com.yihu.wlyy.web.doctor.patient;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelInfo;
import com.yihu.wlyy.service.app.label.SignPatientLabelInfoService;
import com.yihu.wlyy.service.app.sign.SignWebService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -25,6 +26,8 @@ public class SignPatientLabelInfoController extends BaseController {
    @Autowired
    SignPatientLabelInfoService labelInfoService;
    @Autowired
    SignWebService signWebService;
    /**
     * 根据姓名,地址,身份证号搜索团队内居民
@ -147,6 +150,12 @@ public class SignPatientLabelInfoController extends BaseController {
            }
            page = page - 1;
            if(labelType.equals("9")){
                JSONObject jsonObject = signWebService.getOverDuePatients(labelCode,getUID(),page,pagesize);
                return write(200, "查询成功", "data", jsonObject);
            }
            JSONArray result = labelInfoService.getPatientByLabel(getUID(), labelCode, labelType, teamCode, page, pagesize);
            return write(200, "查询成功", "data", result);
@ -235,6 +244,13 @@ public class SignPatientLabelInfoController extends BaseController {
                teamCode = 0L;
            }
            //计算年度数目
            if(labelType.equals("9")){
                JSONObject r= signWebService.getRenewYearCount(getUID());
                return write(200, "查询成功", "data", r);
            }
            JSONArray result = labelInfoService.getPatientAmountByLabelType(getUID(), labelType, teamCode);
            return write(200, "查询成功", "data", result);

+ 38 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorSignController.java

@ -488,11 +488,47 @@ public class DoctorSignController extends WeixinBaseController {
    @ApiOperation(value = "获取年度分组")
    public String getRenewYearCount(){
        try{
            //JSONObject rs =signWebService.getRenewYearCount(getUID());
            JSONObject rs =signWebService.getRenewYearCount("64de930c-5b15-11e6-8344-fa163e8aee56");
            JSONObject rs =signWebService.getRenewYearCount(getUID());
            //JSONObject rs =signWebService.getRenewYearCount("64de930c-5b15-11e6-8344-fa163e8aee56");
            return write(200, "操作成功!", "data", rs);
        }catch (Exception e){
            return error(-1, "请求失败");
        }
    }
    /**
     *
     *统计
     * 咨询量、获取待预约、获取健康教育、获取健康指导
     * @return
     */
    @RequestMapping("/getSignCountInfoInYear")
    @ApiOperation(value = "统计咨询量、获取待预约、获取健康教育、获取健康指导")
    public String getSignCountInfoInYear(@RequestParam(required = true)String patient){
        try{
            JSONObject rs =signWebService.getSignCountInfoInYear(patient);
            //JSONObject rs =signWebService.getRenewYearCount("64de930c-5b15-11e6-8344-fa163e8aee56");
            return write(200, "操作成功!", "data", rs);
        }catch (Exception e){
            return error(-1, "请求失败");
        }
    }
    @RequestMapping("/remainPatientRenew")
    @ApiOperation(value = "提醒居民续签")
    public String remainPatientRenew(@RequestParam(required = true)String patient){
        try{
            int rs =signWebService.remainPatientRenew(getAccessToken(),patient,getUID());
            if(rs==-1){
                return error(-1, "提醒失败");
            }else if(rs ==1){
                return write(200, "微信提醒成功!", "data", rs);
            }else if(rs ==2){
                return write(200, "短信提醒成功!", "data", rs);
            }
            return error(-1, "提醒失败");
        }catch (Exception e){
            return error(-1, "请求失败");
        }
    }
}

+ 5 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/sign/FamilyContractController.java

@ -487,6 +487,10 @@ public class FamilyContractController extends BaseController {
                return error(-1, "用户已存在签约");
            } else if (result == -3) {
                return error(-1, "医生信息查询失败");
            } else if (result == -4) {
                return error(-1, "未找到有效签约记录");
            } else if (result == -5) {
                return error(-1, "未找到有效团队记录");
            } else {
                return write(200, "签约申请成功");
            }
@ -654,7 +658,7 @@ public class FamilyContractController extends BaseController {
    @ResponseBody
    public String checkCanRenew(@RequestParam(required = true) String patient){
        try {
            JSONObject result = patientService.checkCanRenew(patient);
            JSONObject result = patientService.checkCanSignRenew(patient);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            return error(-1, "查询失败");

+ 5 - 5
patient-co-wlyy/src/main/resources/applicationContext.xml

@ -106,11 +106,11 @@
	<bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper" />
    <!--quartz任务调度器名称,调度器只能加载与名称相同的任务-->
	<bean id="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" scope="singleton">
		<property name="dataSource" ref="dataSource"/>
		<property name="configLocation" value="classpath:/quartz.properties" />
		<property name="autoStartup" value="true"/>
	</bean>
	<!--<bean id="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" scope="singleton">-->
		<!--<property name="dataSource" ref="dataSource"/>-->
		<!--<property name="configLocation" value="classpath:/quartz.properties" />-->
		<!--<property name="autoStartup" value="true"/>-->
	<!--</bean>-->
	<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
		<property name="maxIdle" value="${redis.maxIdle}"/>