Example #1
0
def handler(update: Update, context: CallbackContext) -> None:
    """Handle button reply"""
    query = update.callback_query
    data = query.data

    if data['timepicker_action'] == 'ok':
        # Set jobs
        chat_id = update.callback_query.message.chat.id
        utils.set_jobs(chat_id, context.user_data, context.job_queue)
        # Get frequency and time text for reply
        utils.send_info(update, context, isnew=True)
        # Delete old time query
        query.delete_message()
        return

    if not 'timepicker_target' in data:
        return

    # Handle minutes
    if data["timepicker_target"] == 'min':
        # Get offset based on increase or decrease
        offset = 15
        if data["timepicker_action"] == 'inc':
            pass
        elif data["timepicker_action"] == 'dec':
            offset = -offset
        else:
            offset = 0

        # Add offset
        context.user_data['time_minute'] += offset

        # Handle rollovers
        while (context.user_data['time_minute'] > 59):
            context.user_data['time_minute'] -= 60
            context.user_data['time_hour'] += 1

        while (context.user_data['time_minute'] < 0):
            context.user_data['time_minute'] += 60
            context.user_data['time_hour'] -= 1

    # Handle hours
    if data["timepicker_target"] == 'hour':
        # Get offset based on increase or decrease
        offset = 1
        if data["timepicker_action"] == 'inc':
            pass
        elif data["timepicker_action"] == 'dec':
            offset = -offset
        else:
            offset = 0
        # Add offset
        context.user_data['time_hour'] += offset
    
    # Deal with hour rollovers (can also be caused by minutes)
    while (context.user_data['time_hour'] > 23):
        context.user_data['time_hour'] -= 24

    while (context.user_data['time_hour'] < 0):
        context.user_data['time_hour'] += 24

    # Update KB
    reply_markup = InlineKeyboardMarkup(get_kb(context.user_data['time_hour'], context.user_data['time_minute']))
    query.edit_message_reply_markup(reply_markup=reply_markup)
Example #2
0
def handle_info(update: Update, context: CallbackContext) -> None:
    utils.send_info(update, context)
    update.message.delete()
                            # 遗漏事宜:需要在信息中保留业务的流水号,以便当领导授权优先办理时,可以撤回该风险
                            #
                            flg,current_nodes_info,yw_sn = utils.comp_date(cur_mysql,summary_id)
                            if flg:

                                user_name = utils.get_user_name(cur_mysql,current_nodes_info)
                                #utils.send_message(cur_mysql,current_nodes_info,("【数据铁笼风险提示】:%s,你在办理《%s》%s前,仍有未办理业务!") % (user_name,m_subject,post_name))
                                utils.send_alarm(cur_mysql,current_nodes_info,summary_id,line_id,yw_sn,"【数据铁笼风险提示】:%s,在办理《%s》<%s>%s前,仍有未办理业务!" % (user_name,m_subject,yw_sn,post_name))

                                # 向上级汇报
                                members = utils.get_leader(cur_mysql,line_id,sn,0)
                                members += utils.get_leader(cur_mysql,line_id,sn,1)
                                for member in members:
                                    #leader_name = utils.get_user_name(cur_mysql,member)
                                    #send_alarm(cur_mysql1,member,"【数据铁笼提示】:%s,好:%s在办的《%s》%s已超期,请知悉。" % (leader_name,user_name,subject,post_name))            # 负数表示超出的天数
                                    utils.send_info(cur_mysql,member,"【数据铁笼风险通报】:%s在办理《%s》%s前,仍有未办理业务,请知悉。" % (user_name,m_subject,post_name))

                        if (m_sn=="None") or (m_sn==None):
                            m_sn = o_sn
                        elif int(o_sn) <= int(m_sn):
                            # 第一种情况:主管领导签字同意后,由科员办结
                            # 第二种情况:处长签字同意后,由科员现场踏勘,有可能是处长去

                            if utils.is_wait(cur_oracle,cur_mysql,summary_id):
                                # 针对劳动派遣的补正情况,领导同意后,回到“初审”节点
                                if int(m_line_id)==2 and int(m_sn)==4:
                                    # 针对“劳务派遣”,并分管领导已同意“补正”时
                                    # 状态应该回到“初审”节点
                                    o_sn = '1'
                            else:
                                # 如果不需要“补正”,则流程往下走
def do_rec(cur, cur_mysql, in_sql):
    line_id = None
    while 1:
        subject = ''
        start_date = '2000-01-01 00:00:00'
        one = cur.fetchone()
        if one != None:
            sql = in_sql
            #print(':\n-------------------------------%s' % type(one))
            cnt = len(one)
            #print one
            for i in range(cnt):
                #print i,one[i]
                if i != 0:
                    if i == 12:
                        form_appid = one[12]
                        if form_appid == None:
                            #print(">>>form_appid=%s" % str(form_appid))
                            line_id = None
                        else:
                            # 注意:针对优先办理等特权情况,无法用此方法获取line_id,因为这些form可针对所有业务
                            line_id = utils.get_lineid_by_formid(
                                cur_mysql, form_appid)
                            #print(">>>line_id=%s<<<" % line_id)
                    sql += ','
                else:
                    summary_id = one[0]
                if i == 3:
                    # 新增记录,设定法定期限为8天
                    sql += '8'
                elif i == 13:
                    # for VOUCH
                    sql += '0'
                else:
                    sql += '"' + str(one[i]) + '"'
                    if i == 2:
                        subject = str(one[i])
                    if i == 8:
                        start_member = str(one[i])
                    if i == 6:
                        start_date = str(one[i])

        else:
            break

        # 设定岗位期限为8天
        sql += ",8,"
        if utils.is_include(cur_mysql, 'col_summary', summary_id) == 0:

            print("++++")
            # 2015-12-19: 新加入的summary没有优先办理特权
            if line_id != None:
                if "分管领导指派优先办理" in subject:
                    sql += "0,5,0)"
                else:
                    # 设置新增的申请单在 业务线的第一个(sn=0)岗位上
                    sql += "%s,1,0)" % line_id
            else:
                sql += "0,1,0)"
            print sql
            # 保存记录
            cur_mysql.execute(sql)
            # 添加流水号
            yw_sn = utils.get_sn(cur_mysql, summary_id)
            print(">>>流水号:%s<<<" % yw_sn)
            if yw_sn != None:
                sql = 'update col_summary set yw_sn="%s" where id="%s"' % (
                    yw_sn, summary_id)
                #print sql
                cur_mysql.execute(sql)
            else:
                yw_sn = ""

            #--------------------------------------------------
            # !!!若这是一个“特权”事件,则需执行其特权行为 !!!
            #
            utils.set_summary_pri(cur_mysql, summary_id, yw_sn, start_member)

            # for resent_time,用于放置 受理时间
            if (("人力资源服务许可" in subject) or ("劳务派遣" in subject) or
                ("自动发起" in subject)) and (line_id is not None):

                # 获取业务节点(受理)期限(天)
                nday = utils.get_post_deadline(cur_mysql, line_id, 1)
                if nday is not None:
                    sql = 'update col_summary set cnt="%s" where id="%s"' % (
                        nday, summary_id)
                    #print sql
                    cur_mysql.execute(sql)

                # 获取该申请的受理时间
                acc_time = utils.get_summary_feild_value(
                    cur_mysql, summary_id, "受理时间")
                #print(">>>受理时间:%s" % val )
                if acc_time is not None:
                    sql = 'update col_summary set resent_time="%s" where id="%s"' % (
                        acc_time, summary_id)
                    #print sql
                    cur_mysql.execute(sql)
                else:
                    # 若无受理时间,则认为是当前时间
                    acc_time = time.strftime("%Y-%m-%d %H:%M:%S",
                                             time.localtime(time.time()))
                    sql = 'update col_summary set resent_time="%s" where id="%s"' % (
                        acc_time, summary_id)
                    #print sql
                    cur_mysql.execute(sql)

                # 通过业务线line_id,检查申请是否带齐必要的附件
                # 如果未带齐,则发出“风险”警告
                #
                #print(">>>1<<<")
                # 2015-12-27 针对“补正”系统会自动发起新的summary记录,此时,不用判断附件情况
                #
                if ("(自动发起)" not in subject) and (not utils.chk_file(
                        cur_mysql, summary_id, line_id)):
                    #print(">>>Here!<<<")

                    user_name = utils.get_user_name(cur_mysql, start_member)

                    utils.send_alarm(cur_mysql,start_member,summary_id,line_id,yw_sn,"【数据铁笼风险提示】:%s,在受理《%s》<%s>时,提交材料存在缺失项,请知悉。" \
                        % (user_name,subject,yw_sn))

                    # 向上级汇报
                    members = utils.get_leader(cur_mysql, line_id, 0, 0)
                    members += utils.get_leader(cur_mysql, line_id, 0, 1)
                    for member in members:
                        leader_name = utils.get_user_name(cur_mysql, member)
                        #send_alarm(cur_mysql1,member,"【数据铁笼提示】:%s,好:%s在办的《%s》%s已超期,请知悉。" % (leader_name,user_name,subject,post_name))            # 负数表示超出的天数
                        utils.send_info(cur_mysql,member,"【数据铁笼风险通报】%s,好:%s在受理《%s》时,提交材料存在缺失项,请知悉。" \
                            % (leader_name,user_name,subject))

                # 检查提交时间start_date与“受理时间”acc_time之间的间隔是否超过一天?
                # 若超过,则报风险
                now_d = datetime.datetime.now()
                if acc_time == "None" or acc_time == None or acc_time == "NONE":
                    acc_time = now_d.strftime("%Y-%m-%d %H:%M:%S")
                acc_d = datetime.datetime.strptime(acc_time,
                                                   "%Y-%m-%d %H:%M:%S")

                # 时间戳(分钟计)
                now_ts = int(time.mktime(now_d.timetuple())) / 60
                acc_ts = int(time.mktime(acc_d.timetuple())) / 60

                # 记录 某人 在 该业务线节点上 处理申报所占用时间 now_ts - last_ts
                min_cnt = utils.cal_workdays(
                    cur_mysql, acc_time, now_d.strftime('%Y-%m-%d %H:%M:%S'))

                if "(自动发起)" in subject:
                    sql = 'insert into kpi_001(member,summary_id,line_id,sn,dtime,start_date) values("%s","%s",%s,%s,%d,"%s")' \
                                % (start_member,summary_id,line_id,1,min_cnt,acc_time)
                else:
                    sql = 'insert into kpi_001(member,summary_id,line_id,sn,dtime,start_date) values("%s","%s",%s,%s,%d,"%s")' \
                                % (start_member,summary_id,line_id,0,min_cnt,acc_time)

                #sql = 'insert into kpi_001(member,summary_id,line_id,sn,dtime,start_date) values("%s","%s",%s,%s,%d,"%s")' \
                #            % (start_member,summary_id,line_id,0,now_ts-acc_ts,acc_time)
                cur_mysql.execute(sql)

                # 添加 业务日志
                utils.yw_log(cur_mysql, summary_id, start_member, 0, acc_time,
                             now_d.strftime('%Y-%m-%d %H:%M:%S'), min_cnt)

                #if (now_ts>acc_ts) and ((now_ts-acc_ts)>(24*60)):
                # 工作耗时超过7.5小时
                if min_cnt >= 450:

                    # 提交日期 超过 受理日期 一天以上
                    # 风险提示

                    user_name = utils.get_user_name(cur_mysql, start_member)

                    utils.send_alarm(cur_mysql,start_member,summary_id,line_id,yw_sn,"【数据铁笼风险提示】:%s,在受理《%s》<%s>时超出一天期限,请知悉。" \
                        % (user_name,subject,yw_sn))

                    # 向上级汇报
                    members = utils.get_leader(cur_mysql, line_id, 0, 0)
                    members += utils.get_leader(cur_mysql, line_id, 0, 1)
                    for member in members:
                        leader_name = utils.get_user_name(cur_mysql, member)
                        utils.send_info(cur_mysql,member,"【数据铁笼风险通报】%s,好:%s在受理《%s》时,超出岗位工作期限,请知悉。" \
                            % (leader_name,user_name,subject))

                    # 需要根据此情况调整 deadline 的值
                    n = 8 - (now_ts - acc_ts) / (24 * 60)
                    sql = 'update col_summary set deadline=%d where id="%s"' % (
                        n, summary_id)
                    cur_mysql.execute(sql)

                # 设置第一个时间点
                # 把finish_date用于记录本节点的完成时间
                #
                now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                sql = 'update col_summary set finish_date="%s" where id="%s"' % (
                    now, summary_id)
                cur_mysql.execute(sql)
                                utils.send_alarm(
                                    cur_mysql, current_nodes_info, summary_id,
                                    line_id, yw_sn,
                                    "【数据铁笼风险提示】:%s,在办理《%s》<%s>%s前,仍有未办理业务!" %
                                    (user_name, m_subject, yw_sn, post_name))

                                # 向上级汇报
                                members = utils.get_leader(
                                    cur_mysql, line_id, sn, 0)
                                members += utils.get_leader(
                                    cur_mysql, line_id, sn, 1)
                                for member in members:
                                    #leader_name = utils.get_user_name(cur_mysql,member)
                                    #send_alarm(cur_mysql1,member,"【数据铁笼提示】:%s,好:%s在办的《%s》%s已超期,请知悉。" % (leader_name,user_name,subject,post_name))            # 负数表示超出的天数
                                    utils.send_info(
                                        cur_mysql, member,
                                        "【数据铁笼风险通报】:%s在办理《%s》%s前,仍有未办理业务,请知悉。"
                                        % (user_name, m_subject, post_name))

                        if (m_sn == "None") or (m_sn == None):
                            m_sn = o_sn
                        elif int(o_sn) <= int(m_sn):
                            # 第一种情况:主管领导签字同意后,由科员办结
                            # 第二种情况:处长签字同意后,由科员现场踏勘,有可能是处长去

                            if utils.is_wait(cur_oracle, cur_mysql,
                                             summary_id):
                                # 针对劳动派遣的补正情况,领导同意后,回到“初审”节点
                                if int(m_line_id) == 2 and int(m_sn) == 4:
                                    # 针对“劳务派遣”,并分管领导已同意“补正”时
                                    # 状态应该回到“初审”节点
                                    o_sn = '1'
def do_rec(cur, cur_mysql, in_sql):
    line_id = None
    while 1:
        subject = ""
        start_date = "2000-01-01 00:00:00"
        one = cur.fetchone()
        if one != None:
            sql = in_sql
            # print(':\n-------------------------------%s' % type(one))
            cnt = len(one)
            # print one
            for i in range(cnt):
                # print i,one[i]
                if i != 0:
                    if i == 12:
                        form_appid = one[12]
                        if form_appid == None:
                            # print(">>>form_appid=%s" % str(form_appid))
                            line_id = None
                        else:
                            # 注意:针对优先办理等特权情况,无法用此方法获取line_id,因为这些form可针对所有业务
                            line_id = utils.get_lineid_by_formid(cur_mysql, form_appid)
                            # print(">>>line_id=%s<<<" % line_id)
                    sql += ","
                else:
                    summary_id = one[0]
                if i == 3:
                    # 新增记录,设定法定期限为8天
                    sql += "8"
                elif i == 13:
                    # for VOUCH
                    sql += "0"
                else:
                    sql += '"' + str(one[i]) + '"'
                    if i == 2:
                        subject = str(one[i])
                    if i == 8:
                        start_member = str(one[i])
                    if i == 6:
                        start_date = str(one[i])

        else:
            break

        # 设定岗位期限为8天
        sql += ",8,"
        if utils.is_include(cur_mysql, "col_summary", summary_id) == 0:

            print ("++++")
            # 2015-12-19: 新加入的summary没有优先办理特权
            if line_id != None:
                if "分管领导指派优先办理" in subject:
                    sql += "0,5,0)"
                else:
                    # 设置新增的申请单在 业务线的第一个(sn=0)岗位上
                    sql += "%s,1,0)" % line_id
            else:
                sql += "0,1,0)"
            print sql
            # 保存记录
            cur_mysql.execute(sql)
            # 添加流水号
            yw_sn = utils.get_sn(cur_mysql, summary_id)
            print (">>>流水号:%s<<<" % yw_sn)
            if yw_sn != None:
                sql = 'update col_summary set yw_sn="%s" where id="%s"' % (yw_sn, summary_id)
                # print sql
                cur_mysql.execute(sql)
            else:
                yw_sn = ""

            # --------------------------------------------------
            # !!!若这是一个“特权”事件,则需执行其特权行为 !!!
            #
            utils.set_summary_pri(cur_mysql, summary_id, yw_sn, start_member)

            # for resent_time,用于放置 受理时间
            if (("人力资源服务许可" in subject) or ("劳务派遣" in subject) or ("自动发起" in subject)) and (line_id is not None):

                # 获取业务节点(受理)期限(天)
                nday = utils.get_post_deadline(cur_mysql, line_id, 1)
                if nday is not None:
                    sql = 'update col_summary set cnt="%s" where id="%s"' % (nday, summary_id)
                    # print sql
                    cur_mysql.execute(sql)

                # 获取该申请的受理时间
                acc_time = utils.get_summary_feild_value(cur_mysql, summary_id, "受理时间")
                # print(">>>受理时间:%s" % val )
                if acc_time is not None:
                    sql = 'update col_summary set resent_time="%s" where id="%s"' % (acc_time, summary_id)
                    # print sql
                    cur_mysql.execute(sql)
                else:
                    # 若无受理时间,则认为是当前时间
                    acc_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
                    sql = 'update col_summary set resent_time="%s" where id="%s"' % (acc_time, summary_id)
                    # print sql
                    cur_mysql.execute(sql)

                # 通过业务线line_id,检查申请是否带齐必要的附件
                # 如果未带齐,则发出“风险”警告
                #
                # print(">>>1<<<")
                # 2015-12-27 针对“补正”系统会自动发起新的summary记录,此时,不用判断附件情况
                #
                if ("(自动发起)" not in subject) and (not utils.chk_file(cur_mysql, summary_id, line_id)):
                    # print(">>>Here!<<<")

                    user_name = utils.get_user_name(cur_mysql, start_member)

                    utils.send_alarm(
                        cur_mysql,
                        start_member,
                        summary_id,
                        line_id,
                        yw_sn,
                        "【数据铁笼风险提示】:%s,在受理《%s》<%s>时,提交材料存在缺失项,请知悉。" % (user_name, subject, yw_sn),
                    )

                    # 向上级汇报
                    members = utils.get_leader(cur_mysql, line_id, 0, 0)
                    members += utils.get_leader(cur_mysql, line_id, 0, 1)
                    for member in members:
                        leader_name = utils.get_user_name(cur_mysql, member)
                        # send_alarm(cur_mysql1,member,"【数据铁笼提示】:%s,好:%s在办的《%s》%s已超期,请知悉。" % (leader_name,user_name,subject,post_name))            # 负数表示超出的天数
                        utils.send_info(
                            cur_mysql,
                            member,
                            "【数据铁笼风险通报】%s,好:%s在受理《%s》时,提交材料存在缺失项,请知悉。" % (leader_name, user_name, subject),
                        )

                # 检查提交时间start_date与“受理时间”acc_time之间的间隔是否超过一天?
                # 若超过,则报风险
                now_d = datetime.datetime.now()
                if acc_time == "None" or acc_time == None or acc_time == "NONE":
                    acc_time = now_d.strftime("%Y-%m-%d %H:%M:%S")
                acc_d = datetime.datetime.strptime(acc_time, "%Y-%m-%d %H:%M:%S")

                # 时间戳(分钟计)
                now_ts = int(time.mktime(now_d.timetuple())) / 60
                acc_ts = int(time.mktime(acc_d.timetuple())) / 60

                # 记录 某人 在 该业务线节点上 处理申报所占用时间 now_ts - last_ts
                min_cnt = utils.cal_workdays(cur_mysql, acc_time, now_d.strftime("%Y-%m-%d %H:%M:%S"))

                if "(自动发起)" in subject:
                    sql = (
                        'insert into kpi_001(member,summary_id,line_id,sn,dtime,start_date) values("%s","%s",%s,%s,%d,"%s")'
                        % (start_member, summary_id, line_id, 1, min_cnt, acc_time)
                    )
                else:
                    sql = (
                        'insert into kpi_001(member,summary_id,line_id,sn,dtime,start_date) values("%s","%s",%s,%s,%d,"%s")'
                        % (start_member, summary_id, line_id, 0, min_cnt, acc_time)
                    )

                # sql = 'insert into kpi_001(member,summary_id,line_id,sn,dtime,start_date) values("%s","%s",%s,%s,%d,"%s")' \
                #            % (start_member,summary_id,line_id,0,now_ts-acc_ts,acc_time)
                cur_mysql.execute(sql)

                # 添加 业务日志
                utils.yw_log(
                    cur_mysql, summary_id, start_member, 0, acc_time, now_d.strftime("%Y-%m-%d %H:%M:%S"), min_cnt
                )

                # if (now_ts>acc_ts) and ((now_ts-acc_ts)>(24*60)):
                # 工作耗时超过7.5小时
                if min_cnt >= 450:

                    # 提交日期 超过 受理日期 一天以上
                    # 风险提示

                    user_name = utils.get_user_name(cur_mysql, start_member)

                    utils.send_alarm(
                        cur_mysql,
                        start_member,
                        summary_id,
                        line_id,
                        yw_sn,
                        "【数据铁笼风险提示】:%s,在受理《%s》<%s>时超出一天期限,请知悉。" % (user_name, subject, yw_sn),
                    )

                    # 向上级汇报
                    members = utils.get_leader(cur_mysql, line_id, 0, 0)
                    members += utils.get_leader(cur_mysql, line_id, 0, 1)
                    for member in members:
                        leader_name = utils.get_user_name(cur_mysql, member)
                        utils.send_info(
                            cur_mysql,
                            member,
                            "【数据铁笼风险通报】%s,好:%s在受理《%s》时,超出岗位工作期限,请知悉。" % (leader_name, user_name, subject),
                        )

                    # 需要根据此情况调整 deadline 的值
                    n = 8 - (now_ts - acc_ts) / (24 * 60)
                    sql = 'update col_summary set deadline=%d where id="%s"' % (n, summary_id)
                    cur_mysql.execute(sql)

                # 设置第一个时间点
                # 把finish_date用于记录本节点的完成时间
                #
                now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                sql = 'update col_summary set finish_date="%s" where id="%s"' % (now, summary_id)
                cur_mysql.execute(sql)