Exemplo n.º 1
0
def people_info():
    """用户填写信息互动显示"""
    req_dict = request.get_json()
    p_name = req_dict.get("p_name")
    p_project = req_dict.get("p_project")
    lingpai = req_dict.get("lingpai")
    addr = req_dict.get("work_addr", '')
    print("++++用户信息互动++++", req_dict)
    # 校验数据
    param_keys = ["p_name", "p_project", "lingpai", 'work_addr']
    param_dict = dict()
    for i in param_keys:
        param_dict.__setitem__(i, req_dict.get(i, ''))
    for key, value in param_dict.items():
        if not value:
            return jsonify(errno=RET.PARAMERR, errmsg="数据不完整,缺少%s" % key)
    redis_store.rpush(
        "itemreviews",
        json.dumps({
            "lingpai": lingpai,
            "p_name": p_name,
            "p_project": p_project,
            "show": "info"
        }))
    return jsonify(errno=RET.OK, errmsg="成功")
Exemplo n.º 2
0
def c_stop():
    """取消暂停"""
    req_dict = request.get_json()
    lingpai = req_dict.get("lingpai", '')
    user_id = req_dict.get("user_id", '')
    addr = req_dict.get("work_addr", '')
    print("++++取消暂停++++", req_dict)
    # 校验数据
    param_keys = ["lingpai", "user_id", 'work_addr']
    param_dict = dict()
    for i in param_keys:
        param_dict.__setitem__(i, req_dict.get(i, ''))
    for key, value in param_dict.items():
        if not value:
            return jsonify(errno=RET.PARAMERR, errmsg="数据不完整,缺少%s" % key)
    # 修改用户当前状态
    lingpai_obj = LingPai.query.filter_by(user_id=user_id).first()
    if not lingpai_obj:
        return jsonify(errno=RET.DBERR, errmsg="未登录")
    lingpai_obj.status = "空闲"
    db.session.add(lingpai_obj)
    db.session.commit()
    # 修改用户头顶屏幕显示
    redis_store.rpush('usershead',
                      json.dumps({
                          "lingpai": lingpai,
                          "show": "start"
                      }))
    # 修改用户对面屏幕显示
    redis_store.rpush('itemreviews',
                      json.dumps({
                          "lingpai": lingpai,
                          "show": "start"
                      }))
    return jsonify(errno=RET.OK, errmsg="成功")
Exemplo n.º 3
0
def review_click():
    """用户屏幕要素互动"""
    req_dict = request.get_json()
    itemreviews = req_dict.get("itemreviews", '')
    current_click = req_dict.get("current_click", '')
    reviewsclick = req_dict.get("reviewsclick", '')
    lingpai = req_dict.get("lingpai", '')
    user_id = req_dict.get("user_id", '')
    addr = req_dict.get("work_addr", '')
    print("++++屏幕要素互动++++", req_dict)
    # 校验数据
    param_keys = ["itemreviews", "lingpai", 'work_addr']
    param_dict = dict()
    for i in param_keys:
        param_dict.__setitem__(i, req_dict.get(i, ''))
    for key, value in param_dict.items():
        if not value:
            return jsonify(errno=RET.PARAMERR, errmsg="数据不完整,缺少%s" % key)
    redis_store.rpush(
        "itemreviews",
        json.dumps({
            "lingpai": lingpai,
            "itemreviews": itemreviews,
            "reviewsclick": reviewsclick,
            "current_click": current_click,
            "show": "true"
        }))
    return jsonify(errno=RET.OK, errmsg="成功")
Exemplo n.º 4
0
def logistical_details():
    if request.method == 'POST':
        prior_role = 'Generalist skills'
        redis_store.set(prior_role, skill_dump(request.form))
        redis_store.rpush(skills, prior_role)
    question = {
        'department': {
            'for': 'Department',
            'label': 'What department or agency is this role in?',
            'hint': "What's your organisation generally known as?"
        },
        'directorate': {
            'for': 'Directorate',
            'label': 'Which business area or directorate is this role in?',
            'hint': 'This should describe the team or business area in which the Fast Streamer will be working.'
        },
        'location': {
            'for': 'Location',
            'label': 'Please give an address for this role',
            'hint': 'Please include a postcode. This might not be where the Fast Streamer will spend'
                     'all their time, but it will help us decide whether they\'ll need to relocate'
        },
        'experience': {
            'heading': 'How much experience do you expect the Fast Streamer to already have to be effective in '
                       'this role?',
                       'name': 'post-length',
                       'values': {
                           '0 - 6 months': 1,
                           '12 - 18 months': 2,
                           '2 years': 3,
                           '3 years': 4
                       },
            'for': 'Experience required',
            'hint': 'Remember that this is the amount of general DDaT experience, rather than experience in '
                    'this area'
        },
        'ongoing': {
            'heading': 'Is this post a one-off, or ongoing?',
            'name': 'ongoing',
            'values': {
                'One-off': 'one-off',
                'Ongoing': 'ongoing'
            },
            'for': 'Ongoing or one-off?'
        },
        'start': {
            'for': 'Start month',
            'label': 'What month would you prefer the Fast Streamer start?',
            'hint': 'The start date will generally be 1st of the month, unless the Fast Streamer has already booked '
                    'some leave.'
        }

    }
    return render_template('submit/logistical-details.html', question=question)
Exemplo n.º 5
0
def recall():
    """重呼"""
    req_dict = request.get_json()
    water_num = req_dict.get("water_num", '')
    lingpai = req_dict.get("lingpai", '')
    user_id = req_dict.get("user_id", '')
    addr = req_dict.get("work_addr", '')
    print("++++重呼++++", req_dict)
    # 校验数据
    param_keys = ["water_num", "lingpai", "user_id", 'work_addr']
    param_dict = dict()
    for i in param_keys:
        param_dict.__setitem__(i, req_dict.get(i, ''))
    for key, value in param_dict.items():
        if not value:
            return jsonify(errno=RET.PARAMERR, errmsg="数据不完整,缺少%s" % key)
    number = Business.query.filter_by(water_num=water_num).first().number
    window = LingPai.query.filter_by(lingpai=lingpai).first().win
    redis_store.rpush(addr + "voice",
                      json.dumps({
                          "number": number,
                          "window": window
                      }))
    return jsonify(errno=RET.OK, errmsg="成功")
Exemplo n.º 6
0
def skills():
    r = RoleQuestion('Data Engineer', {
                            'Data analysis and synthesis': 'Data analysis and synthesis',
                            'Communicating between the technical and the non-technical'
                            : 'Communicating between the technical and the non-technical',
                            'Data development process': 'Data development process',
                            'Data integration design': 'Data integration design',
                            'Data modelling': 'Data modelling',
                            'Programming and build (data engineering)': 'Programming and build (data engineering)',
                            'Technical understanding (data engineering)': 'Technical understanding (data engineering)',
                            'Testing': 'Testing'
                        })
    r2 = RoleQuestion('Data Scientist', {
        'Applied maths, statistics and scientific practices': 1005,
        'Data engineering and manipulation': 1034,
        'Data science innovation': 1039,
        'Developing data science capability': 1043,
        'Domain expertise': 1047,
        'Programming and build (data science)': 1084,
        'Understanding analysis across the life cycle (data science)': 1126
    }

                            )
    r3 = RoleQuestion('Strategy and Policy', {
                            'Drafting': 'Drafting',
                            'Briefing': 'Briefing',
                            'Research': 'Research',
                            'Working with ministers': 'Working with ministers',
                            'Bills and legislation': 'Bills and legislation',
                            'Policy evaluation': 'Policy evaluation',
                            'Parliamentary questions/Freedom of Information requests'
                            : 'Parliamentary questions/Freedom of Information requests'
                         })
    r4 = RoleQuestion('Generalist skill areas', {
                            'Commercial awareness': 'Commercial awareness',
                            'Financial management': 'Financial management',
                            'People management': 'People management',
                            'Programme management': 'Programme management',
                            'Change management': 'Change management',
                            'Science/engineering policy facing': 'Science/engineering policy facing',
                            'International policy facing': 'International policy facing'

                        })
    families = {
        'data': [r, r2, r3, r4]
        }
    roles_in_family = families[redis_store.get('family')]
    seen_roles = int(redis_store.get('roles_seen'))
    if request.method == 'POST':  # user has clicked 'continue'
        prior_role = roles_in_family[seen_roles-1]
        redis_store.set(prior_role.name, skill_dump(request.form))
        redis_store.rpush('skills', prior_role.name)
    current_role = roles_in_family[seen_roles]
    redis_store.incr('roles_seen', 1)  # increment the number of roles seen
    name = current_role.name
    r = {
        'title': name,
        'skills': {
            'heading': 'Which of the following skills will this role develop?',
            'name': 'skills',
            'values': current_role.skills,
            'for': 'skills'
        },
        'description': {
                'label': 'How will the role deliver these skills?',
                'hint': "Please give a brief description of how this role will develop the Fast Streamers skills in the"
                        " areas you've indicated. If you've not ticked anything, there's no need to complete this box.",
                'for': 'skills-describe'
        },
        'skill_level': {
            'heading': 'What level of skill will the candidate gain?',
            'name': 'skill-level',
            'values': {
                'Awareness': 1,
                'Working': 2,
                'Practitioner': 3,
                'Expert': 4
            },
            'for': 'skill-level',
            'hint': "Across all the skills you've indicated, what level of ability do you expect the Fast Streamer to "
                    "have at the end of this post?"
        }
    }
    if seen_roles == len(roles_in_family) - 1:
        next_step = 'submit.logistical_details'
    else:
        next_step = 'submit.skills'
    return render_template('submit/skills.html', role=r, next_step=next_step)
Exemplo n.º 7
0
def deal_end():
    req_dict = request.get_json()
    lingpai = req_dict.get('lingpai', '')  # 大厅人员必须
    reviews = req_dict.get("reviews", '')  # 大厅人员非必须
    p_name = req_dict.get("p_name", '')  # 大厅人员必须
    p_project = req_dict.get("p_project", '')  # 大厅人员必须
    water_num = req_dict.get("water_num", '')
    subject = req_dict.get("subject", '')
    item = req_dict.get("item", '')
    deal_status = req_dict.get("deal_status", '')
    current_process = req_dict.get("current_process", '')
    description = req_dict.get("description", '')
    user_id = req_dict.get("user_id", '')
    addr = req_dict.get('work_addr', "")  # 地址
    print("++++处理++++", req_dict)
    # 校验数据
    param_keys = [
        "water_num", "deal_status", "current_process", "user_id", "work_addr",
        'subject', 'item'
    ]
    if current_process == "接件":
        param_keys.extend(["lingpai"])
    param_dict = dict()
    for i in param_keys:
        param_dict.__setitem__(i, req_dict.get(i, ''))
    for key, value in param_dict.items():
        if not value:
            return jsonify(errno=RET.PARAMERR, errmsg="数据不完整,缺少%s" % key)
    ## 修改用户当前状态
    #lingpai_obj = LingPai.query.filter_by(user_id=user_id).first()
    #if not lingpai_obj:
    #    return jsonify(errno=RET.DBERR,errmsg="未登录")
    #lingpai_obj.status="空闲"
    #db.session.add(lingpai_obj)
    #db.session.commit()
    # 修改当前叫号情况
    current_call_obj = CurrentCall.query.filter_by(water_num=water_num).first()
    if current_call_obj:
        current_call_obj.status = 1
        db.session.add(current_call_obj)
        db.session.commit()
    # 修改当前时间主题和事项,当前流程时限和已用时间
    business = Business.query.filter_by(water_num=water_num).first()
    if business:
        business.subject = subject
        business.item = item
        db.session.add(business)
        db.session.commit()
    else:
        return jsonify(errno=RET.DBERR, errmsg="没有此事件")
    # 检验要素是否属于当前事项
    item_obj = Item.query.filter_by(name=business.item).first()
    if reviews:
        review_id_list = list()
        for i in item_obj.steps.all():
            review_id_list.extend([j.id for j in i.reviews.all()])
        if reviews.split("-")[0] not in review_id_list:
            return jsonify(errno=RET.DATAERR, errmsg="要素与事项不符")
    try:
        current_subject = business.subject
        start_time = business.modify_time
        current_process = business.current_process
        next_process = None
        current_item = business.item
        people = People.query.filter_by(idno=business.idno).first()
        if deal_status == "N":
            business.current_user = user_id
            business.status = "不合格"
            business.in_deal = 0
            business.current_process = "发证"
            if current_process == "接件":
                business.current_process = "接件"  # 如果当前流程为接件则不流到发证处
                business.in_deal = 2
                business.p_name = p_name
                business.p_project = p_project
                business.reviews = reviews if reviews else ""
            if current_process == "发证":  # 如果发证处不合格则直接作废
                business.in_deal = 2
        elif deal_status == "Y":
            business.current_user = user_id
            business.status = "完成"
            business.in_deal = 0
            if current_process == "接件":
                next_process = business.process.split("-")[
                    business.process.split("-").index(current_process) + 1]
                business.current_process = next_process
                business.p_name = p_name
                business.p_project = p_project
                business.reviews = reviews if reviews else ""
            elif current_process == "科室负责人" and business.is_scene == 1:
                next_process = business.process.split("-")[
                    business.process.split("-").index(current_process) + 2]
                business.current_process = next_process
            elif current_process == "踏勘中心":
                next_process = business.process.split("-")[
                    business.process.split("-").index(current_process) - 1]
                business.current_process = next_process
                business.is_scene = 1
            elif current_process != "发证":
                next_process = business.process.split("-")[
                    business.process.split("-").index(current_process) + 1]
                business.current_process = next_process
            elif current_process == "发证":
                next_process = '发证'
                business.in_deal = 3
            item_obj = Item.query.filter_by(name=business.item).first()
            business.current_process_timeout = item_obj.steps.filter_by(
                name=next_process).first().timeout
            business.current_process_start_time = datetime.now()
        # 修改办理已花费时间,添加事件状态记录
        used_time_obj = datetime.now() - start_time
        if current_process == "踏勘中心":
            business.takan_used_time += used_time_obj.seconds / 3600 + used_time_obj.days * 24
        # 查询数据库,如果存在则修改,否则创建
        business_status = BusinessStatus.query.filter_by(
            water_num=water_num, current_process=current_process).first()
        if business_status:
            business_status.addr = addr
            business_status.user_id = user_id
            business_status.subject = current_subject
            business_status.item = current_item
            business_status.starts = start_time
            business_status.ends = datetime.now()
            business_status.result = deal_status
            business_status.description = description
        else:
            business_status = BusinessStatus(addr=addr,
                                             water_num=water_num,
                                             current_process=current_process,
                                             user_id=user_id,
                                             subject=current_subject,
                                             item=current_item,
                                             starts=start_time,
                                             ends=datetime.now(),
                                             result=deal_status,
                                             description=description)
        db.session.add_all([business, business_status])
        db.session.commit()
    except Exception as e:
        current_app.logger.error(e)
        db.session.rollback()
        return jsonify(errno=RET.DBERR, errmsg="数据库错误")
    # 是否发送短信
    mobile = people.mobile
    if current_process == "发证":
        pass
    elif next_process == "发证":
        try:
            result = current_app.config['MSG_SENDER'].send_with_param(
                86,
                mobile,
                current_app.config['TEMPLATE_LAST'],
                [3, datetime.now().strftime('%H:%M:%S')],
                sign=current_app.config['SMS_SIGN'],
                extend="",
                ext="")  # 签名参数未提供或者为空时,会使用默认签名发送短信
            pass
        except Exception as e:
            current_app.logger.error(e)
            return jsonify(errno=RET.THIRDERR, errmsg="第三方系统错误")
    elif deal_status == "N":
        if current_app.config["MSG"].get(current_process + "未通过") == "Y":
            print(current_process, "------------未通过")
            description_ret = description
            if description:
                description_obj = json.loads(description)
                description_ret = str(description_obj["checks"].append(
                    description_obj["msg"]))
            try:
                result = current_app.config['MSG_SENDER'].send_with_param(
                    86,
                    mobile,
                    current_app.config['TEMPLATE_UNPASS'], [
                        current_process, description_ret,
                        datetime.now().strftime('%H:%M:%S')
                    ],
                    sign=current_app.config['SMS_SIGN'],
                    extend="",
                    ext="")  # 签名参数未提供或者为空时,会使用默认签名发送短信
                pass
            except Exception as e:
                current_app.logger.error(e)
                return jsonify(errno=RET.THIRDERR, errmsg="第三方系统错误")
    elif deal_status == "Y":
        if current_app.config["MSG"].get(current_process + "通过") == "Y":
            print(current_process, "---------------通过")
            try:
                result = current_app.config['MSG_SENDER'].send_with_param(
                    86,
                    mobile,
                    current_app.config['TEMPLATE_PASS'], [
                        current_process, next_process,
                        datetime.now().strftime('%H:%M:%S')
                    ],
                    sign=current_app.config['SMS_SIGN'],
                    extend="",
                    ext="")  # 签名参数未提供或者为空时,会使用默认签名发送短信
                pass
            except Exception as e:
                current_app.logger.error(e)
                return jsonify(errno=RET.THIRDERR, errmsg="第三方系统错误")
    if current_process == "接件":
        try:
            # 修改用户头顶屏幕显示
            redis_store.rpush(
                'usershead',
                json.dumps({
                    "lingpai": lingpai,
                    "length": redis_store.llen(addr + business.subject),
                    "show": "false"
                }))
            # 修改用户对面屏幕显示
            redis_store.rpush(
                'itemreviews', json.dumps({
                    "lingpai": lingpai,
                    "show": "false"
                }))
        except Exception as e:
            current_app.logger.error(e)
            return jsonify(errno=RET.SERVERERR, errmsg="内部错误")
    return jsonify(errno=RET.OK, errmsg="成功")
Exemplo n.º 8
0
def get_number():
    """排号 涉及办事人员表添加取号记录,办事表查询和添加记录,队列"""
    # 获取数据
    req_dict = request.get_json()
    subject = req_dict.get('subject', "")  # 主题
    item = req_dict.get('item', "")  # 事项
    mobile = req_dict.get('mobile', "")  # 电话
    idno = req_dict.get('idno', "")  # 身份证
    addr = req_dict.get('work_addr', "")  # 地址
    print("++++取号++++", req_dict)
    # 校验数据
    param_keys = ["subject", "item", "mobile", "idno", "work_addr"]
    param_dict = dict()
    for i in param_keys:
        param_dict.__setitem__(i, req_dict.get(i, ''))
    for key, value in param_dict.items():
        if not value:
            return jsonify(errno=RET.PARAMERR, errmsg="数据不完整,缺少%s" % key)
    # 判断手机号格式
    if not re.match(r"1[34578]\d{9}", mobile):
        # 表示格式不对
        return jsonify(errno=RET.PARAMERR, errmsg="手机号格式错误")
    # 判断身份证号
    if not re.match(r"[1-9]\d{16}[0-9a-zA-Z]", idno):
        return jsonify(errno=RET.PARAMERR, errmsg="身份证格式错误")
    # 记录对应主题取号总量
    redis_store.incr(addr + subject + "total_number")
    totle = int(
        redis_store.get(addr + subject + "total_number").decode("utf-8"))
    print("取号总量-----------", totle)
    # 查询办事表检查当事人是否来过
    try:
        current_people = People.query.filter_by(idno=idno).first()
        current_addr = Addr.query.filter_by(name=addr).first()
        current_subject = Subject.query.filter_by(name=subject).first()
        current_item = Item.query.filter_by(name=item).first()
        current_location = Location.query.filter_by(subject=subject).first()
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg="数据库错误")

    # 生成流水号
    water_num = current_addr.seq + datetime.now().strftime(
        "%Y%m%d%H%M%S") + str(current_item.id).rjust(3, '0')
    # 生成号码
    number = current_subject.seq + str((0 + totle * 1) % 1000).rjust(3, '0')
    # 记录事件
    current_business = Business(water_num=water_num,
                                idno=idno,
                                addr=addr,
                                subject=subject,
                                item=item,
                                process=current_item.process,
                                current_process="接件",
                                in_deal=0,
                                is_scene=0,
                                number=number,
                                timeout=current_item.timeout,
                                takan_used_time=0,
                                wait_seconds=0,
                                move_times=0)
    age = datetime.now().year - int(idno[6:10])
    sex = int(idno[16:17]) % 2
    try:
        db.session.add(current_business)
        if not current_people:
            current_people = People(idno=idno, mobile=mobile)
            db.session.add(current_people)
        db.session.commit()
    except Exception as e:
        current_app.logger.error(e)
        db.session.rollback()
        return jsonify(errno=RET.DBERR, errmsg="数据库错误")

    # 添加队列
    try:
        # 发送短信
        length = redis_store.llen(addr + subject)
        location = current_location.location
        try:
            result = current_app.config['MSG_SENDER'].send_with_param(
                86,
                mobile,
                current_app.config['TEMPLATE_NUMBER'], [
                    number, length, location,
                    datetime.now().strftime('%H:%M:%S')
                ],
                sign=current_app.config['SMS_SIGN'],
                extend="",
                ext="")  # 签名参数未提供或者为空时,会使用默认签名发送短信
            pass
        except Exception as e:
            current_app.logger.error(e)
            return jsonify(errno=RET.THIRDERR, errmsg="第三方系统错误")
        # 添加排队队列
        redis_store.rpush(addr + subject, water_num)
        # 添加排队时间队列
        redis_store.rpush(addr + subject + "time",
                          datetime.now().strftime("%H%M%S"))
        # 添加用户头顶屏幕显示人数
        redis_store.rpush(
            'usershead',
            json.dumps({
                "subject": subject,
                "length": length,
                "show": "true"
            }))
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.SERVERERR, errmsg="内部错误")
    else:
        # 返回流水号,号码,位置,等待人数
        return jsonify(errno=RET.OK,
                       errmsg="成功",
                       data={
                           "water_num": water_num,
                           "number": number,
                           "location": location,
                           "wait": length
                       })
Exemplo n.º 9
0
def make_call():
    '''叫号'''
    req_dict = request.get_json()
    subject = req_dict.get('subject', '')
    lingpai = req_dict.get("lingpai", '')
    user_id = req_dict.get("user_id", '')
    addr = req_dict.get('work_addr', "")  # 地址
    print("++++叫号++++", req_dict)
    # 校验数据
    param_keys = ["subject", "lingpai", "user_id", "work_addr"]
    param_dict = dict()
    for i in param_keys:
        param_dict.__setitem__(i, req_dict.get(i, ''))
    for key, value in param_dict.items():
        if not value:
            return jsonify(errno=RET.PARAMERR, errmsg="数据不完整,缺少%s" % key)
    # 修改用户当前状态
    lingpai_obj = LingPai.query.filter_by(user_id=user_id).first()
    if not lingpai_obj:
        return jsonify(errno=RET.DBERR, errmsg="未登录")
    lingpai_obj.status = "办理中"
    db.session.add(lingpai_obj)
    db.session.commit()
    window = lingpai_obj.win
    # 获取当前主题等待人数
    current_wait_number = redis_store.llen(addr + subject)
    # 获取当前用户今日办件量
    current_day = datetime(datetime.now().year,
                           datetime.now().month,
                           datetime.now().day, 0, 0)
    current_user_call_number = len(
        Business.query.filter(
            and_(
                Business.create_time.between(current_day,
                                             current_day + timedelta(1)),
                Business.current_user == user_id)).all())
    # 通过比对数据库查看是否有中断事件,如果有则返回中断事件,否则返回队列事件
    # 首先比对数据库查看是否有中断事件
    broken_business = Business.query.filter_by(addr=addr,
                                               subject=subject,
                                               current_user=user_id,
                                               current_process="接件",
                                               in_deal=1).first()
    # 如果有中断事件,则返回中断事件和窗口
    if broken_business:
        # 比对数据库查看是否有上次未完成事件
        before_business = Business.query.filter(
            and_(Business.idno == broken_business.idno,
                 Business.item == broken_business.item,
                 Business.water_num != broken_business.water_num)).order_by(
                     Business.modify_time.desc()).all()
        current_p_comes = 0
        for i in before_business:
            if i.status == "完成":
                break
            current_p_comes += 1
        number = broken_business.number
        current_item = Item.query.filter_by(name=broken_business.item).first()
        people = People.query.filter_by(idno=broken_business.idno).first()
        # 记录当前叫号情况
        current_call_obj = CurrentCall.query.filter_by(
            water_num=broken_business.water_num).first()
        if current_call_obj:
            current_call_obj.win = window
        else:
            current_call_obj = CurrentCall(addr=addr,
                                           water_num=broken_business.water_num,
                                           number=broken_business.number,
                                           win=window,
                                           status=0)
        if current_call_obj:
            db.session.add(current_call_obj)
            db.session.commit()
        # 是否发送短信
        mobile = people.mobile
        try:
            result = current_app.config['MSG_SENDER'].send_with_param(
                86,
                mobile,
                current_app.config['TEMPLATE_CALL'],
                [number, window,
                 datetime.now().strftime('%H:%M:%S')],
                sign=current_app.config['SMS_SIGN'],
                extend="",
                ext="")  # 签名参数未提供或者为空时,会使用默认签名发送短
        except Exception as e:
            current_app.logger.error(e)
            return jsonify(errno=RET.THIRDERR, errmsg="第三方系统错误")
        # 添加语音队列
        redis_store.rpush(addr + "voice",
                          json.dumps({
                              "number": number,
                              "window": window
                          }))
        # 添加用户头顶屏幕队
        redis_store.rpush(
            'usershead',
            json.dumps({
                "number": number,
                "lingpai": lingpai,
                "length": redis_store.llen(addr + subject),
                "show": "true"
            }))
        # 添加用户对面屏幕队列
        step_reviews_list = list()
        for step in current_item.steps.all():
            review_list = [review.to_dict() for review in step.reviews.all()]
            for i in review_list:
                i.__setitem__("father_order", step.order)
                i.__setitem__("process", current_item.process)
            step_reviews_list.extend(review_list)
        print("+" * 100)
        redis_store.rpush(
            "itemreviews",
            json.dumps({
                "lingpai":
                lingpai,
                "itemreviews":
                step_reviews_list,
                "reviewsclick":
                before_business[0].reviews if before_business else "",
                "cometimes":
                len(before_business),
                "show":
                "true",
                "current_click":
                str(step_reviews_list[0]['id']),
                "business":
                add_time_step_to_business(broken_business)
            }))
        print("+" * 100)
        result = add_time_step_to_business(broken_business)
        result.__setitem__(
            "last_reviews",
            before_business[0].reviews if before_business else "")
        result.__setitem__("window", window)
        result.__setitem__("cometimes", current_p_comes)
        return jsonify(errno=RET.OK,
                       errmsg="成功",
                       data={
                           "business": result,
                           "wait": current_wait_number,
                           "called": current_user_call_number
                       })
    # 否则从队列中取第一个消息
    else:
        ret = redis_store.blpop(addr + subject, timeout=2)
        ret1 = redis_store.blpop(addr + subject + "time", timeout=2)
        if ret and ret1:
            water_num = ret[1].decode()
            print("water_num-----", water_num)
            # 查询所需信息
            business = Business.query.filter_by(water_num=water_num).first()
            current_item = Item.query.filter_by(name=business.item).first()
            business.current_user = user_id
            business.current_process_timeout = current_item.steps.filter_by(
                name=business.current_process).first().timeout
            business.wait_seconds = (datetime.now() -
                                     business.create_time).seconds
            business.in_deal = 1
            business.current_process_start_time = datetime.now()
            db.session.add(business)
            db.session.commit()
            # 比对数据库查看是否有上次未完成事件
            before_business = Business.query.filter(
                and_(Business.idno == business.idno,
                     Business.item == business.item,
                     Business.water_num != business.water_num)).order_by(
                         Business.modify_time.desc()).all()
            current_p_comes = 0
            for i in before_business:
                if i.status == "完成":
                    break
                current_p_comes += 1
            number = business.number
            people = People.query.filter_by(idno=business.idno).first()
            # 添加叫号情况
            current_call_obj = CurrentCall.query.filter_by(
                water_num=water_num).first()
            if current_call_obj:
                current_call_obj.win = window
            else:
                current_call_obj = CurrentCall(addr=addr,
                                               water_num=water_num,
                                               number=number,
                                               win=window,
                                               status=0)
            if current_call_obj:
                db.session.add(current_call_obj)
                db.session.commit()
            # 是否发送短信
            mobile = people.mobile
            try:
                result = current_app.config['MSG_SENDER'].send_with_param(
                    86,
                    mobile,
                    current_app.config['TEMPLATE_CALL'], [number, window],
                    sign=current_app.config['SMS_SIGN'],
                    extend="",
                    ext="")  # 签名参数未提供或者为空时,会使用默认签名发送短信
            except Exception as e:
                current_app.logger.error(e)
                return jsonify(errno=RET.THIRDERR, errmsg="第三方系统错误")
            # 添加语音队列
            redis_store.rpush(addr + "voice",
                              json.dumps({
                                  "number": number,
                                  "window": window
                              }))
            # 添加用户头顶屏幕队
            redis_store.rpush(
                'usershead',
                json.dumps({
                    "number": number,
                    "lingpai": lingpai,
                    "length": redis_store.llen(addr + subject),
                    "show": "true"
                }))
            # 添加用户对面屏幕队列
            step_reviews_list = list()
            for step in current_item.steps.all():
                review_list = [
                    review.to_dict() for review in step.reviews.all()
                ]
                for i in review_list:
                    i.__setitem__("father_order", step.order)
                    i.__setitem__("process", current_item.process)
                step_reviews_list.extend(review_list)
            print("-" * 100)
            redis_store.rpush(
                "itemreviews",
                json.dumps({
                    "lingpai":
                    lingpai,
                    "itemreviews":
                    step_reviews_list,
                    "reviewsclick":
                    before_business[0].reviews if before_business else "",
                    "cometimes":
                    len(before_business),
                    "show":
                    "true",
                    "current_click":
                    str(step_reviews_list[0]['id']),
                    "business":
                    add_time_step_to_business(business)
                }))
            print("-" * 100)
            result = add_time_step_to_business(business)
            result.__setitem__(
                "last_reviews",
                before_business[0].reviews if before_business else "")
            result.__setitem__("window", window)
            result.__setitem__("cometimes", current_p_comes)
            return jsonify(errno=RET.OK,
                           errmsg="成功",
                           data={
                               "business": result,
                               "wait": current_wait_number,
                               "called": current_user_call_number
                           })
        return jsonify(errno=RET.DATAERR, errmsg="没人了")
Exemplo n.º 10
0
def move():
    """转移"""
    req_dict = request.get_json()
    lingpai = req_dict.get('lingpai', '')
    subject = req_dict.get('subject', '')  # 主题
    item = req_dict.get('item', '')  # 事项
    water_num = req_dict.get('water_num', '')
    user_id = req_dict.get("user_id", '')
    addr = req_dict.get("work_addr", '')
    print("转移-------", req_dict)
    # 校验数据
    param_keys = [
        "lingpai", "subject", "item", "water_num", "user_id", 'work_addr'
    ]
    param_dict = dict()
    for i in param_keys:
        param_dict.__setitem__(i, req_dict.get(i, ''))
    for key, value in param_dict.items():
        if not value:
            return jsonify(errno=RET.PARAMERR, errmsg="数据不完整,缺少%s" % key)
    # 修改当前叫号情况
    current_call_obj = CurrentCall.query.filter_by(water_num=water_num).first()
    if current_call_obj:
        current_call_obj.status = 1
        db.session.add(current_call_obj)
        db.session.commit()
    # 修改用户当前状态
    lingpai_obj = LingPai.query.filter_by(user_id=user_id).first()
    if not lingpai_obj:
        return jsonify(errno=RET.DBERR, errmsg="未登录")
    lingpai_obj.status = "空闲"
    db.session.add(lingpai_obj)
    db.session.commit()
    # 修改数据
    try:
        business = Business.query.filter_by(water_num=water_num).first()
        old_subject = business.subject
        business.subject = subject
        business.item = item
        business.move_times += 1
        db.session.add(business)
        db.session.commit()
    except Exception as e:
        current_app.logger.error(e)
        db.session.rollback()
        return jsonify(errno=RET.DBERR, errmsg="数据库操作错误")
    # 根据排队时间将数据放入相应队列
    try:
        time_list = redis_store.lrange(addr + subject + "time", 0, -1)
        if time_list:
            for j in range(len(time_list)):
                if business.create_time.strftime(
                        '%H%M%S').encode() < time_list[j]:
                    redis_store.linsert(addr + subject, 'before',
                                        redis_store.lindex(addr + subject, j),
                                        water_num)
                    redis_store.linsert(
                        addr + subject + "time", 'before',
                        redis_store.lindex(addr + subject + "time", j),
                        business.create_time.strftime('%H%M%S'))
            else:
                print("enter else branch")
                redis_store.rpush(addr + subject, water_num)
                redis_store.rpush(addr + subject + "time",
                                  business.create_time.strftime('%H%M%S'))
        else:
            print("enter no branch")
            redis_store.lpush(addr + subject, water_num)
            redis_store.lpush(addr + subject + "time",
                              business.create_time.strftime('%H%M%S'))
        # 修改用户头顶屏幕显示
        redis_store.rpush(
            'usershead',
            json.dumps({
                "lingpai": lingpai,
                "length": redis_store.llen(addr + old_subject),
                "show": "false"
            }))
        # 修改用户对面屏幕显示
        redis_store.rpush('itemreviews',
                          json.dumps({
                              "lingpai": lingpai,
                              "show": "false"
                          }))
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.SERVERERR, errmsg="内部错误")
    return jsonify(errno=RET.OK, errmsg="成功")