예제 #1
0
def user_add():
    form = UserAddForm().validate_for_api()
    Role = QiInfoRole.query.filter_by(id=form.rid.data).first_or_404()
    role_code = Role.rcode

    if role_code == 'diremanager' and form.bid.data:
        raise ParameterException(msg='主管人员请不要填写部门')
    if (role_code != 'diremanager' and role_code != 'systemadmin') and form.bid.data is None:
        raise ParameterException(msg='请选择部门')
    if role_code == 'agentoperator' and form.agent_id.data is None:
        raise ParameterException(msg='坐席人员请填写工号')
    if role_code != 'agentoperator' and form.agent_id.data:
        raise ParameterException(msg='非坐席人员,请不要填写工号')
    user = QiInfoUser()

    with db_v1.auto_commit():
        form.populate_obj(user)
        user.insert_time = current_timestamp_sec()
        user.ac_type = 100
        user.ac_status = 100
        user.password = form.password.data
        user.is_deleted = 0
        user.create_time = current_timestamp_sec()
        db_v1.session.add(user)
    vm_keys_user = ('id', 'create_time')
    vm = {}
    for v_key in vm_keys_user:
        vm[v_key] = getattr(user, v_key, None)
    return CreateSuccess(msg='用户新增成功', data=vm)
예제 #2
0
def branch_add():
    form = BranchAddForm().validate_for_api()
    branch_name = form.branch_name.data
    superior_id = form.superior_id.data
    if QiInfoBranch.query.filter_by(branch_name=branch_name,
                                    superior_id=superior_id).first():
        superior_name = QiInfoBranch.query.filter_by(
            id=superior_id).first().branch_name
        raise ParameterException(msg=superior_name + '已有' + branch_name +
                                 ',如要新建,请重新命名 ')
    branch = QiInfoBranch()
    placeholder_num = current_app.config['BUSI_BRANCH_CODE_PLACEHOLDER_NUM']
    branch_code_list = QiInfoBranch.query.with_entities(
        QiInfoBranch.branch_code).filter_by(with_deleted=True).all()
    branch_cnt = max([
        int(proj_code[-placeholder_num:]) for proj_code, in branch_code_list
    ]) if len(branch_code_list) > 0 else 0
    branch_code = '{}{}'.format(current_app.config['BUSI_BRANCH_CODE_PREFIX'],
                                str(branch_cnt + 1).zfill(placeholder_num))
    with db_v1.auto_commit():
        form.populate_obj(branch)
        branch.insert_time = current_timestamp_sec()
        branch.is_deleted = 0
        branch.branch_code = branch_code
        branch.superior_id = form.superior_id.data
        branch.create_time = current_timestamp_sec()
        db_v1.session.add(branch)
    vm_keys_branch = ('id', 'create_time')
    vm = {}
    for v_key in vm_keys_branch:
        vm[v_key] = getattr(branch, v_key, None)
    vm['create_time'] = vm['create_time']
    return CreateSuccess(msg='部门新增成功', data=vm)
예제 #3
0
def user_change_pwd():
    uid = IDForm().validate_for_api().id.data
    form = PasswordEditForm().validate_for_api()
    account = QiInfoUser.query.filter_by(id=uid).first_or_404()
    identity = QiInfoUser.verify(account['account'], form.old_password.data)
    if form.new_password.data != form.confirm_password.data:
        raise ParameterException(msg='新旧密码不一样,请重新确认')
    if identity:
        with db_v1.auto_commit():
            user = QiInfoUser.query.filter_by(id=uid).first_or_404()
            user.password = form.new_password.data

    return Success(msg='修改密码成功')
예제 #4
0
def branch_del(bid):
    user = QiInfoUser.query.filter_by(bid=bid).all()
    if user:
        raise ParameterException(msg='该部门中有用户,无法删除部门,请修改该部门中的用户所属部门后,再进行删除')

    with db_v1.auto_commit():
        # branch = QiInfoBranch.query.filter_by(id==bid).first_or_404()
        branch = QiInfoBranch.query.filter_by(id=bid).first_or_404()
        branch.delete()
        sups = QiInfoBranch.query.filter_by(superior_id=bid).all()
        for sup in sups:
            sup.delete()
    return DeleteSuccess(msg='部门删除成功')
예제 #5
0
def to_db(call_id, paragraph_id, detail_rule_id, type_id, hit_location):
    with db_v1.auto_commit():
        # session = db_v1.db_session()
        model_info = QiResultsDetail()
        model_info.insert_time = int(time.time())
        model_info.is_deleted = 0
        model_info.call_id = call_id
        model_info.paragraph_id = paragraph_id
        model_info.detail_rule_id = detail_rule_id
        model_info.qc_time = datetime.datetime.now().strftime(
            "%Y-%m-%d %H-%M-%S")
        model_info.hit_status = 1
        model_info.type = type_id
        model_info.review_status = 0
        model_info.hit_location = hit_location
        db_v1.session.add(model_info)
    return True
예제 #6
0
def user_super_edit():
    uid = IDForm().validate_for_api().id.data
    form = UserEditForm().validate_for_api()
    account = QiInfoUser.query.filter_by(id=uid).first()

    Role = QiInfoRole.query.filter_by(id=form.rid.data).first_or_404()
    role_code = Role.rcode
    if form.account.data and form.account.data != account.account:
        raise ParameterException(msg='请不要修改用户账户')
    if QiInfoUser.query.filter(
            QiInfoUser.nickname == form.nickname.data,
            QiInfoUser.id != uid,
            QiInfoUser.is_deleted == 0).first():
        raise ParameterException(msg='该用户昵称已存在,请重新命名 ')
    if form.agent_id.data and role_code == 'agentoperator':
        if QiInfoUser.query.filter(
                QiInfoUser.agent_id == form.agent_id.data,
                QiInfoUser.id != uid,
                QiInfoUser.is_deleted == 0).first():
            raise ParameterException(msg='该坐席已存在,请重新命名 ')
    if role_code == 'diremanager' and form.bid.data:
        raise ParameterException(msg='主管人员请不要填写部门')
    if role_code != 'diremanager' and form.bid.data is None:
        raise ParameterException(msg='请选择部门')
    if role_code == 'agentoperator' and (form.agent_id.data is None or len(form.agent_id.data) == 0):
        raise ParameterException(msg='坐席人员请填写工号')
    if role_code != 'agentoperator' and form.agent_id.data:
        raise ParameterException(msg='非坐席人员,请不要填写工号')
    with db_v1.auto_commit():
        user = QiInfoUser.query.filter_by(id=uid).first_or_404()
        if form.nickname.data:
            user.nickname = form.nickname.data
        if form.password.data:
            user.password = form.password.data
        if form.telephone.data:
            user.telephone = form.telephone.data
        if form.rid.data:
            user.rid = form.rid.data
        if form.agent_id.data:
            user.agent_id = form.agent_id.data
        if form.bid.data:
            user.rid = form.bid.data
    return EditSuccess(msg='用户修改成功')
예제 #7
0
def qia_score(call_data, base_score):
    qc_time = datetime.datetime.now().strftime("%Y-%m-%d %H-%M-%S")
    tmp1 = db_v1.session.query(QiResultsDetail.call_id, func.sum(QiInfoMapRule.rule_score).label(
        "total_role_score")).filter(QiResultsDetail.call_id.in_(call_data), QiResultsDetail.hit_status == 1).join(
        QiInfoMapRule, QiResultsDetail.detail_rule_id == QiInfoMapRule.id).\
        group_by(QiResultsDetail.call_id).subquery()
    tmp2 = db_v1.session.query(QiResultsDetail.call_id, func.group_concat(
        distinct(func.concat(QiInfoMapRule.template_name, '-', QiInfoMapRule.rule_name)).op('SEPARATOR')(text('"|"'))).label(
        "hit_rules")).filter(QiResultsDetail.call_id.in_(call_data), QiResultsDetail.hit_status == 1).join(
        QiInfoMapRule, QiResultsDetail.detail_rule_id == QiInfoMapRule.id).group_by(QiResultsDetail.call_id).subquery()
    qc_datas = db_v1.session.query(QiInfoTraffic.call_id, (base_score + tmp1.c.total_role_score).label("qc_score"),
                                   tmp2.c.hit_rules).filter(QiInfoTraffic.call_id.in_(call_data)).outerjoin(
        tmp1, QiInfoTraffic.call_id == tmp1.c.call_id).outerjoin(tmp2, QiInfoTraffic.call_id == tmp2.c.call_id)

    # update_file_status = []
    # update_hit_status = []
    # update_unhit_status = []
    # for qc_data in qc_datas:
    #     update_file_status.append(qc_data.call_id)
    #     if not qc_data.hit_rules:
    #         update_hit_status.append(qc_data.call_id)
    #     else:
    #         update_unhit_status.append(qc_data.call_id)
    with db_v1.auto_commit():
        for qc_data in qc_datas:
            if qc_data.qc_score:
                model_info = QiScoreCall()
                model_info.insert_time = int(time.time())
                model_info.is_deleted = 0
                model_info.call_id = qc_data.call_id
                model_info.qc_time = qc_time
                model_info.hit_rules = qc_data.hit_rules
                model_info.qc_score = qc_data.qc_score
                db_v1.session.add(model_info)
                db_v1.session.query(QiInfoTraffic).filter(QiInfoTraffic.call_id == qc_data.call_id).update(
                    {"file_status": 3})
                if qc_data.hit_rules:
                    db_v1.session.query(QiInfoTraffic).filter(QiInfoTraffic.call_id == qc_data.call_id).update(
                     {"hit_status": 1})
                else:
                    db_v1.session.query(QiInfoTraffic).filter(QiInfoTraffic.call_id == qc_data.call_id).update(
                     {"hit_status": 2})
예제 #8
0
def update_hit_status(update_id, call_id):
    list_id = update_id.split(',')
    ud_id = []
    for i in list_id:
        ud_id.append(int(i))
    with db_v1.auto_commit():
        db_v1.session.query(QiResultsDetail).filter(
            QiResultsDetail.id.in_(ud_id)).update({
                "hit_status": 0,
                "review_status": 2
            })
        # 审核正确
        db_v1.session.query(QiResultsDetail).filter(
            and_(QiResultsDetail.call_id == call_id,
                 QiResultsDetail.review_status == 0,
                 QiResultsDetail.id.notin_(ud_id))).update(
                     {"review_status": 1}, synchronize_session=False)

        db_v1.session.query(QiInfoTraffic).filter(
            QiInfoTraffic.call_id == call_id).update({"review_status": 2})
예제 #9
0
def branch_edit():
    bid = IDForm().validate_for_api().id.data
    form = BranchEditForm().validate_for_api()

    branch_name = form.branch_name.data
    superior_id = form.superior_id.data
    if QiInfoBranch.query.filter(
            QiInfoBranch.branch_name == branch_name,
            QiInfoBranch.superior_id == superior_id,
            QiInfoBranch.id != bid,
    ).first():
        superior_name = QiInfoBranch.query.filter_by(
            id=superior_id).first().branch_name
        raise ParameterException(msg=superior_name + '已有' + branch_name +
                                 ',如要修改,请重新命名 ')

    with db_v1.auto_commit():
        branch = QiInfoBranch.query.filter_by(id=bid).first_or_404()
        if form.branch_name.data:
            branch.branch_name = form.branch_name.data
        if form.superior_id.data:
            branch.superior_id = form.superior_id.data
    return EditSuccess(msg='部门修改成功')
예제 #10
0
def user_super_del(uid):
    with db_v1.auto_commit():
        user = QiInfoUser.query.filter_by(id=uid).first_or_404()
        user.delete()
        db_v1.session.add(user)
    return DeleteSuccess(msg='用户删除成功')
예제 #11
0
def user_super_reset_pwd(uid):
    with db_v1.auto_commit():
        user = QiInfoUser.query.filter_by(id == uid).first_or_404()
        user.password = '******'
    return Success(msg='密码重设成功')