任务过期预警和超期提醒功能实现

3 篇文章 0 订阅
2 篇文章 0 订阅

任务过期短信预警和超期短信提醒功能实现

预警
一、首先确定需要预警的任务类型,提前几天预警等信息
生效
生效时间在创建时间和修改时间后一段时间,免得创建预警信息时填写错误信息时没时间修改

 /**
     * 设置预警信息中创建时间和生效时间
     *
     * @param
     * @return
     */
    private Map<String, Date> setTime() {
        //设置创建或修改时间
        Map<String, Date> times = new HashMap<>();
        Date creatTime = new Date();
        times.put("creatTime", creatTime);
        //设置生效时间为一小时后
        Calendar cal = Calendar.getInstance();
        cal.setTime(creatTime);
        cal.add(Calendar.HOUR, 1);
        Date effectiveTime = cal.getTime();
        times.put("effectiveTime", effectiveTime);
        return times;
    }

二、创建相应的数据库表 early_table
三、编写表 early_table的实体类EarlyTable和增删改查接口
四、定义定时器 检索需要预警的工单

  /**
     * 定时触发:每隔10分钟检索生效的预警信息并根据预警的工单类型进行检查是否在n个工作日后超时
     */
    @Scheduled(cron = "0 */10 * * * ?")
    private void sendmsg() {
        log.info("预警筛选开始+++++++++++++++++++");
        EarlyTable earlyTable= new EarlyTable();
        earlyTable.setCreatTime(setTime().get("creatTime"));
        //检索所有生效的工单
        List<EarlyTable> infoList = noteWarnningMapper.getEatlyWarnInfoAll(earlyTable);
        log.info("预警筛选到个"+infoList.size()+"筛选信息+++++++++++++++++++");
        for (int i = 0; i < infoList.size(); i++) {
            screenFlow(infoList.get(i));
        }
    }

    /**
     * 根据预警信息检索临近超时的工单
     * @param noteEatlyWarningInfo
     */
    private void screenFlow(EarlyTable noteEatlyWarningInfo) {
        Map<String, Object> param = new HashMap<>();
        //预警时间:例 提前2工作日 swarnTime =2
        String swarnTime=noteEatlyWarningInfo.getWarningDate();
        //2 到2.006 是指工单要求结束时间距离现在时间10分钟(是为了检索工作日自建的一种时间查询方式,很麻烦 请用别的方法替代)
        String ewarnTime =swarnTime+".006";
        List<String> processchnameList = Arrays.asList(noteEatlyWarningInfo.getFlowType().split(","));
        //所属流程
        param.put("processchname", processchnameList);
        //工单类型
        param.put("flow_type", noteEatlyWarningInfo.getProcess());
        //时间范围
        param.put("swarnTime", swarnTime);
        param.put("ewarnTime", ewarnTime);
        log.info("预警筛选从"+swarnTime+"  到 "+ewarnTime+" 期间的工单");
        //检索需要预警的工单:要求完成时间到现在时间 N天零不超过10分钟(定时器是十分钟,超过会重复发预警消息)
        //检索 工单id 所在环节,环节状态,处理人,
        List<Map<String, Object>> noteInfo = noteWarnningMapper.screenFlow(param);
        //短信内容
        String msg ="";
        //userId集合
        List<String> assigneeIds = new ArrayList<>();
        //记录工单唯一标识:环节加flowid flow1为本条工单唯一标识   flow2 为上条工单唯一标识(处理人有多人时,批量处理)
        String flow1 ="";
        String flow2 ="";
        //短信接口参数对象
        BatchSmsMsg batchSmsMsg =new BatchSmsMsg();
        //预警短信模型
        NoteMsg noteMsg = noteWarnningMapper.getMsg("0");
        //预警工单发送人有省公司时
       
            for (int i = 0; i < noteInfo.size(); i++) {
                //判断工单是不是同上一个:获得本次工单的标识
                flow1 = (String) noteInfo.get(i).get("processchname") + (String) noteInfo.get(i).get("flowId");
                //若和上次工单标识不相同则发送短信,并清空id,把本次工单标识赋给flow2用于下个工单对比
                if (!flow1.equals(flow2) && assigneeIds.size() > 0) {
                    batchSmsMsg.setContent(msg);
                    batchSmsMsg.setUserIdList(assigneeIds);
                    userClient.batchSmsSend(batchSmsMsg);
                    assigneeIds.clear();
                }
                //获得短信内容
                msg = noteMsg.getTypemsg() + noteInfo.get(i).get("processchname")+"," + noteMsg.getTaskmsg() + noteInfo.get(i).get("taskchname")+","
                        + noteMsg.getTitlemsg() + noteInfo.get(i).get("flowTitle")+"," + noteMsg.getEatlymsg() + noteEatlyWarningInfo.getWarningDate() + noteMsg.getTailmsg();
                //处理人ID
                String assigneeId = (String) noteInfo.get(i).get("assigneeId");
               
                    assigneeIds.add(assigneeId);
                }
                //将本条唯一标识赋给flow2
                flow2 = flow1;
           
       }
                //最后一类工单的信息发送,最后的工单在遍历中没发送
                if(assigneeIds.size()>0) {
                    batchSmsMsg.setContent(msg);
                    batchSmsMsg.setUserIdList(assigneeIds);
                    userClient.batchSmsSend(batchSmsMsg);
                    assigneeIds.clear();
                }

        }

检索临近超时的sql:工单类型在范围内、所属流程、环节状态未完成、受理人是空或不是-1、要求完成时间距现在大于N工作日小于N+0.006工作日(10分钟)

<select id="screenFlow" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT  b.id,a.flow_id ,a.processchname,b.taskchname,a.flow_title,b.assignee_id,b.task_state,now() as now,to_number(to_char(extract(epoch FROM count_work_day(now()::timestamp without time zone,a.limit_time))/86400,'999999.999'),'999999.999') days
        FROM bpm_form_info AS a
        JOIN user_waitting_task AS b ON a.flow_id= b.flow_id
        WHERE a.processchname in
        <foreach collection="processchname" index="index" item="type" open="(" separator="," close=")">
            #{type}
        </foreach>
        AND a.flow_type =#{flow_type,jdbcType=VARCHAR}
        AND b.task_state !='2'
        AND (b.handler_id !='-1' or b.handler_id is null )
        <![CDATA[
        AND to_char(extract(epoch FROM count_work_day(now()::timestamp without time zone, a.limit_time))/86400,'999999.999') >=#{swarnTime,jdbcType=VARCHAR}
        AND to_char(extract(epoch FROM count_work_day(now()::timestamp without time zone, a.limit_time))/86400,'999999.999') <= #{ewarnTime,jdbcType=TIMESTAMP}
        ]]> order by a.flow_id
    </select>

超时
一、首先确定需要超时提醒的任务类型,几点提醒,多少天提醒一次等信息
二、建立数据库表
warnning_date :几点发送提醒短信
frequency:间隔多少天后再提醒一次
在这里插入图片描述
三、编写表 的实体类和增删改查接口
四、定义定时器 检索需要预警的工单

//每隔5分钟执行一次
 @Scheduled(cron = "0 */5 * * * ?")
    private void sendOvertimeMsg() {
        NoteOvertimeWarningInfo noteOvertimeWarningInfo = new NoteOvertimeWarningInfo();
        noteOvertimeWarningInfo.setCreatTime(setTime().get("creatTime"));
        //检索所有生效的工单
        List<NoteOvertimeWarningInfo> infoList = noteWarnningMapper.getOvertimeWarnInfoAll(noteOvertimeWarningInfo);
        log.info("超时筛选开始。共有"+infoList.size()+" 条筛选条件");
        for (int i = 0; i < infoList.size(); i++) {
            Calendar now = Calendar.getInstance();
            int hour = infoList.get(i).getWarningDate();
            //判断是否到发送超时提醒的时间(时),并验证(分)小于5 防止重复发送
            if(now.get(Calendar.HOUR_OF_DAY) == hour&&now.get(Calendar.MINUTE) <5){
                log.info("超时进行筛选 发送时间: " + infoList.get(i).getWarningDate()+" 现在时间: "+now);
            screenOvertimeFlow(infoList.get(i));
            }
        }
    }

    /**
     * 检索超时工单并进行提醒
     * @param noteOvertimeWarningInfo
     */
    private void screenOvertimeFlow(NoteOvertimeWarningInfo noteOvertimeWarningInfo) {
        Map<String, Object> param = new HashMap<>();
        param.put("now", new Date());
        List<String> processchnameList = Arrays.asList(noteOvertimeWarningInfo.getFlowType().split(","));
        param.put("processchname", processchnameList);
        param.put("flow_type", noteOvertimeWarningInfo.getProcess());
        //检索需要的工单
        List<Map<String, Object>> noteInfo = noteWarnningMapper.screenOvertimeFlow(param);
        //短信内容
        String msg = "";
        //userid集合
        List<String> assigneeIds = new ArrayList<>();
        //超时提醒的间隔天数
        int eatlyDate =noteOvertimeWarningInfo.getFrequency();
        //短信接口参数对象
        BatchSmsMsg batchSmsMsg =new BatchSmsMsg();
        //超时提醒短信模型
        NoteMsg noteMsg = noteWarnningMapper.getMsg("1");
        //记录工单唯一标识:环节加flowid flow1为本条工单唯一标识   flow2 为上条工单唯一标识
        String flow1 ="";
        String flow2 ="";
       
            for (int i = 0; i < noteInfo.size(); i++) {
                //获得本次工单的标识
                flow1=(String)noteInfo.get(i).get("processchname")+(String)noteInfo.get(i).get("flowId");
                //若和上次工单标识不相同则发送短信,并清空id,把本次工单标识赋给flow2用于下个工单对比
                if (!flow1.equals(flow2) && assigneeIds.size() > 0) {
                    batchSmsMsg.setContent(msg);
                    batchSmsMsg.setUserIdList(assigneeIds);
                    ResultBean a =userClient.batchSmsSend(batchSmsMsg);
                    assigneeIds.clear();
                }
                log.info("要求完成时间=  "+noteInfo.get(i).get("limitTime") + "  间隔日数:" +eatlyDate);
                //获取超时天数
                int overtimeDay =Integer.parseInt(noteInfo.get(i).get("days").toString().trim());
                //间隔天数为0(每天)或超时没超过一天或超时日数是间隔天数的倍数时发送超时提醒短信
                if(eatlyDate==0||overtimeDay==0||(overtimeDay%eatlyDate==0)) {
                     msg = noteMsg.getTypemsg()+ noteInfo.get(i).get("processchname")+"," + noteMsg.getTaskmsg() + noteInfo.get(i).get("taskchname")
                             +"," + noteMsg.getTitlemsg() + noteInfo.get(i).get("flowTitle") + noteMsg.getTailmsg();
                    //处理人ID
                    String assigneeId = (String) noteInfo.get(i).get("assigneeId");
                   
                        assigneeIds.add(assigneeId);
                    }
                    flow2=flow1;
                
            }
        }
        //最后一类工单的信息发送,最后的工单在遍历中没发送
        if(assigneeIds.size()>0) {
            batchSmsMsg.setContent(msg);
            batchSmsMsg.setUserIdList(assigneeIds);
            userClient.batchSmsSend(batchSmsMsg);
            assigneeIds.clear();
        }
    }

超时检索的sql:工单类型在范围内、所属流程、环节状态未完成、受理人是空或不是-1、要求完成时间小于现在时间

<select id="screenOvertimeFlow" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT DISTINCT a.flow_id ,a.processchname,b.taskchname,a.flow_title,b.assignee_id,b.task_state,a.limit_time,to_char(extract(day from now()-a.limit_time),'999') AS days
        FROM bpm_form_info AS a
        JOIN user_waitting_task AS b ON a.flow_id= b.flow_id
        WHERE a.processchname in
        <foreach collection="processchname" index="index" item="type" open="(" separator="," close=")">
            #{type}
        </foreach>
        AND a.flow_type =#{flow_type,jdbcType=VARCHAR}
        AND b.task_state !='2'
        AND (b.handler_id !='-1' or b.handler_id is null )
        <![CDATA[
        AND a.limit_time < #{now,jdbcType=TIMESTAMP}
        ]]> order by a.flow_id
    </select>
  • 4
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用定时任务和日期比较来实现jsp的过期预警功能。 具体实现步骤如下: 1. 在jsp页面中设置一个日期选择器,让用户选择过期日期。 2. 在后台代码中,获取用户选择的过期日期,并将其存储到数据库中。 3. 使用定时任务,每天定时查询数据库中所有过期日期,并计算与当前日期的差值,判断是否需要进行过期预警。 4. 如果需要进行过期预警,则可以通过邮件、短信等方式提醒用户。 以下是一个简单的示例代码: 在jsp页面中设置日期选择器: ``` <input type="date" name="expireDate"> ``` 在后台代码中,将用户选择的过期日期存储到数据库: ``` String expireDate = request.getParameter("expireDate"); // 将expireDate存储到数据库中 ``` 使用定时任务,每天查询数据库中所有过期日期,并判断是否需要进行过期预警: ``` // 获取当前日期 Date currentDate = new Date(); // 查询数据库中所有过期日期 List<Date> expireDates = // 从数据库中查询过期日期 for (Date expireDate : expireDates) { // 计算与当前日期的差值 long days = (expireDate.getTime() - currentDate.getTime()) / (1000 * 60 * 60 * 24); if (days <= 3) { // 如果差值小于等于3天,则进行过期预警 // 发送邮件、短信等提醒用户 } } ``` 需要注意的是,定时任务实现方式可能因为不同的框架而有所不同。以上示例代码仅供参考,实际实现时需要根据具体情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值