Browse Source

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

chenweida 8 năm trước cách đây
mục cha
commit
2fd15a48ee

+ 28 - 3
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/check/CheckSignJob.java

@ -14,6 +14,7 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
@ -41,25 +42,49 @@ public class CheckSignJob implements Job{
        try{
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
            String timeKey=redisTemplate.opsForValue().get("quota:timeKey");
            long produceTime=  redisTemplate.getExpire("quota:16:4:350200:"+timeKey);
            long now =new Date().getTime();
            long nh = 1000*60*60;//一小时的毫秒数
            //如果当前时间扣掉生成时间大于2小时
            if((now-produceTime)/nh>2){
                sendEmail("实时统计失败,redis数据生成失败,redis数据生成时间時間:"+ DateUtil.dateToStrLong(new Date(produceTime))+",当前系统时间:"+ DateUtil.dateToStrLong(new Date()));
            }
            //判断当前时间是不是
            if(!redisTemplate.hasKey("quota:16:4:350200:"+timeKey)){
                //发送邮件给管理员
               sendEmail();
               sendEmail("实时统计失败,redis数据生成失败,redis数据为空時間:"+ DateUtil.dateToStrLong(new Date()));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    private void sendEmail() throws Exception {
    private void sendEmail(String text) throws Exception {
        SimpleMailMessage message=new SimpleMailMessage();
        message.setFrom(from);//发送者.
        message.setSubject("实时统计失败");//邮件主题.
        message.setText("实时统计失败,redis数据生成失败 時間:"+ DateUtil.dateToStrLong(new Date()));//邮件内容.
        message.setText(text);//邮件内容.
        String[] tos=to.split(",");
        message.setTo(tos);
        javaMailSender.send(message);
    }
    public void dateDiff(String startTime, String endTime, String format) throws Exception{
        //按照传入的格式生成一个simpledateformate对象
        SimpleDateFormat sd = new SimpleDateFormat(format);
        long nd = 1000*24*60*60;//一天的毫秒数
        long nh = 1000*60*60;//一小时的毫秒数
        long nm = 1000*60;//一分钟的毫秒数
        long ns = 1000;//一秒钟的毫秒数long diff;try {
        //获得两个时间的毫秒时间差异
        long diff = sd.parse(endTime).getTime() - sd.parse(startTime).getTime();
        long day = diff/nd;//计算差多少天
        long hour = diff%nd/nh;//计算差多少小时
        long min = diff%nd%nh/nm;//计算差多少分钟
        long sec = diff%nd%nh%nm/ns;//计算差多少秒//输出结果
        System.out.println("时间相差:"+day+"天"+hour+"小时"+min+"分钟"+sec+"秒。");
    }
}