Ejemplo n.º 1
0
def card_modify():
    args = utility.get_args(request)
    id = args.get('id', "")
    # card_type_id = args.get('card_type_id', "")
    # card_no = args.get('card_no', "")
    # password = args.get('password', "")
    remark = args.get('remark', "")
    is_enable = args.get('is_enable') == "1"

    card = None
    if admin_permission.can():
        card = Card.query.filter_by(id=id).first()
    else:
        card = db.session.query(Card).join(Card.admin).filter(
            or_(Admin.id == current_user.id,
                Admin.superior_id == current_user.id)).filter(
                    Card.id == id).first()
    if card is None:
        return "点卡不存在。"

    card.remark = remark
    card.is_enable = is_enable

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "修改点卡"
    operate_log.remark = "点卡:{},备注:{},启用:{}".format(card.card_no, card.remark,
                                                    card.is_enable)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "修改成功。"
Ejemplo n.º 2
0
def admin_insert():
    args = utility.get_args(request)
    user_name = args.get('user_name', "")
    password = args.get('password', "")
    software_names = request.form.getlist("software_names")  # dict会丢失数据
    role_name = args.get('role_name', "")

    if len(software_names) == 0:
        return "未授权软件。"

    softwares = db.session.query(Software).join(
        Software.admins).filter(Admin.id == current_user.id).filter(
            Software.name.in_(software_names)).all()
    if len(softwares) == 0:
        return "无权限添加"

    role = Role.query.filter_by(name=role_name).first()
    if role is None:
        return "身份不存在。"

    if not admin_permission.can():
        if role.id <= current_user.roles[0].id:
            return "无权限添加。"

    admin = Admin.query.filter_by(user_name=user_name).first()
    if admin != None:
        return "用户名已存在。"

    admin = Admin()
    admin.user_name = user_name
    admin.password = utility.get_md5(password)
    admin.superior_id = current_user.id
    admin.is_enable = True
    admin.update_time = func.now()
    admin.create_time = func.now()
    admin.roles.append(role)
    for software_name in software_names:
        software = Software.query.filter_by(name=software_name).first()
        if software is None:
            return "软件不存在。"
        admin.softwares.append(software)
    db.session.add(admin)

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "添加{}".format(role.description)
    operate_log.remark = "用户名:{},密码:{},授权软件:{}".format(
        user_name, password, "、".join(software_names))
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "添加成功!"
Ejemplo n.º 3
0
def operatelog_query():
    args = utility.get_args(request)
    draw = args.get('draw', "")  # 这个值作者会直接返回给前台
    start = args.get('start', "")  # 从多少开始
    length = args.get('length', "")  # 数据长度
    search = args.get('search[value]', "")  # 获取前台传过来的过滤条件
    order_column = args.get('order[0][column]', "")  # 哪一列排序,从0开始
    order_dir = args.get('order[0][dir]', "")  # asc desc 升序或者降序

    operatelogs = []
    recordsTotal = 0
    if admin_permission.can():
        operatelogs = db.session.query(OperateLog).join(
            OperateLog.admin).filter(
                func.CONCAT_WS(
                    ',', Admin.user_name, OperateLog.operate,
                    OperateLog.remark).like('%' + search + '%')).order_by(
                        text(str(int(order_column) + 1) + " " +
                             order_dir)).offset(start).limit(length).all()
        recordsTotal = db.session.query(func.count(OperateLog.id)).scalar()
    else:
        operatelogs = db.session.query(OperateLog).join(
            OperateLog.admin).filter(
                or_(Admin.id == current_user.id,
                    Admin.superior_id == current_user.id)).filter(
                        func.CONCAT_WS(',', Admin.user_name,
                                       OperateLog.operate, OperateLog.remark).
                        like('%' + search + '%')).order_by(
                            text(str(int(order_column) + 1) + " " +
                                 order_dir)).offset(start).limit(length).all()
        recordsTotal = db.session.query(func.count(OperateLog.id)).join(
            OperateLog.admin).filter(
                or_(Admin.id == current_user.id,
                    Admin.superior_id == current_user.id)).scalar()

    recordsFiltered = recordsTotal if search == "" else len(operatelogs)

    data = []
    for operatelog in operatelogs:
        item = [
            operatelog.id, operatelog.admin.user_name, operatelog.operate,
            operatelog.remark, operatelog.create_time
        ]
        data.append(item)

    result = {
        "draw": draw,
        "recordsTotal": recordsTotal,
        "recordsFiltered": recordsFiltered,
        "data": data
    }
    return utility.get_json(result)
Ejemplo n.º 4
0
def card_edit():
    args = utility.get_args(request)
    id = args.get('id', "")

    card = None
    if admin_permission.can():
        card = Card.query.filter_by(id=id).first()
    else:
        card = db.session.query(Card).join(Card.admin).filter(
            or_(Admin.id == current_user.id,
                Admin.superior_id == current_user.id)).filter(
                    Card.id == id).first()
    if card is None:
        return redirect(url_for('card'))

    return render_template('card_edit.html', card=card)
Ejemplo n.º 5
0
def admin_edit():
    args = utility.get_args(request)
    id = args.get('id', "")

    softwares = db.session.query(Software).join(
        Software.admins).filter(Admin.id == current_user.id).all()

    admin = None
    if admin_permission.can():
        admin = Admin.query.filter_by(id=id).first()
    else:
        admin = db.session.query(Admin).filter(
            Admin.superior_id == current_user.id).first()

    if admin is None:
        return redirect(url_for('admin'))

    return render_template('admin_edit.html', admin=admin, softwares=softwares)
Ejemplo n.º 6
0
def admin_modify():
    args = utility.get_args(request)
    id = args.get('id', "")
    user_name = args.get('user_name', "")
    software_names = request.form.getlist("software_names")  # dict会丢失数据
    role_name = args.get('role_name', "")
    is_enable = args.get('is_enable') == "1"

    if len(software_names) == 0:
        return "未授权软件。"

    admin = None
    if admin_permission.can():
        admin = Admin.query.filter_by(id=id).first()
    else:
        admin = db.session.query(Admin).filter(
            Admin.superior_id == current_user.id).first()

    if admin is None:
        return "管理员不存在。"

    admin.user_name = user_name
    admin.is_enable = is_enable
    admin.softwares = []
    for software_name in software_names:
        software = Software.query.filter_by(name=software_name).first()
        if software is None:
            return "软件不存在。"
        admin.softwares.append(software)

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "修改{}".format(admin.get_roles_names())
    operate_log.remark = "用户名:{},授权软件:{},启用:{}".format(
        user_name, "、".join(software_names), is_enable)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "修改成功。"
Ejemplo n.º 7
0
def card_set_enable_batch():
    args = utility.get_args(request)
    card_list = args.get('card_list', "")
    is_enable = args.get('is_enable') == "1"

    result = ""
    card_nos = card_list.strip().split("\n")
    for card_no in card_nos:
        result += card_no

        card = None
        if admin_permission.can():
            card = Card.query.filter(Card.card_no == card_no).first()
        else:
            card = db.session.query(Card).join(Card.admin).filter(
                or_(Admin.id == current_user.id,
                    Admin.superior_id == current_user.id)).filter(
                        Card.card_no == card_no).first()

        if card is None:
            result += "(点卡不存在)"
        else:
            if card.is_used:
                result += "(点卡已使用)"
            else:
                card.is_enable = is_enable
                result += "(修改成功)"
        result += "\n"

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "批量操作点卡"
    operate_log.remark = "数量:{},启用:{}".format(len(card_nos), is_enable)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return result
Ejemplo n.º 8
0
def card_query():
    args = utility.get_args(request)
    draw = args.get('draw', "")  # 这个值作者会直接返回给前台
    start = args.get('start', "")  # 从多少开始
    length = args.get('length', "")  # 数据长度
    search = args.get('search[value]', "")  # 获取前台传过来的过滤条件
    order_column = args.get('order[0][column]', "")  # 哪一列排序,从0开始
    order_dir = args.get('order[0][dir]', "")  # asc desc 升序或者降序
    order_name = args.get('columns[' + order_column + '][name]',
                          "")  # 需要html里定义name
    '''
    SELECT * FROM
    (SELECT cards.*, admins.user_name AS admin_name, my_card_types.card_type_name FROM `cards` LEFT JOIN `admins` ON cards.admin_id = admins.id
    LEFT JOIN (SELECT card_types.*,CONCAT(softwares.name, '(', CAST(card_types.day AS CHAR), '天卡)') AS card_type_name FROM card_types
    LEFT JOIN softwares ON card_types.software_id = softwares.id) AS my_card_types ON cards.type_id = my_card_types.id) AS t1
    WHERE CONCAT_WS(',',`card_no`,`remark`,`admin_name`,`card_type_name`)
    LIKE '%"..search.."%' "..order.." LIMIT "..start..", "..length
    '''

    # 点卡需要用户间彼此隔离
    cards = []
    recordsTotal = 0
    if admin_permission.can():
        cards = db.session.query(Card).join(Card.admin).join(
            Card.card_type).join(CardType.software).filter(
                func.CONCAT_WS(
                    ',', Card.card_no, Card.remark, Admin.user_name,
                    func.CONCAT(
                        Software.name, "(", CardType.day,
                        '天卡)')).like('%' + search + '%')).order_by(
                            text(order_name + " " +
                                 order_dir)).offset(start).limit(length).all()
        recordsTotal = db.session.query(func.count(Card.id)).scalar()
    else:
        cards = db.session.query(Card).join(Card.admin).join(
            Card.card_type).join(CardType.software).filter(
                or_(Admin.id == current_user.id,
                    Admin.superior_id == current_user.id)).filter(
                        func.CONCAT_WS(
                            ',', Card.card_no, Card.remark, Admin.user_name,
                            func.CONCAT(
                                Software.name, "(", CardType.day,
                                '天卡)')).like('%' + search + '%')).order_by(
                                    text(order_name + " " + order_dir)).offset(
                                        start).limit(length).all()
        recordsTotal = db.session.query(func.count(Card.id)).join(
            Card.admin).join(Card.card_type).join(CardType.software).filter(
                or_(Admin.id == current_user.id,
                    Admin.superior_id == current_user.id)).scalar()

    recordsFiltered = recordsTotal if search == "" else len(cards)

    data = []
    for card in cards:
        item = [
            card.id, card.admin.user_name,
            card.card_type.get_name(), card.card_no, card.password,
            card.remark, card.is_used, card.is_enable,
            card.create_time + timedelta(days=card.card_type.expired_day),
            card.update_time, card.create_time
        ]
        data.append(item)

    result = {
        "draw": draw,
        "recordsTotal": recordsTotal,
        "recordsFiltered": recordsFiltered,
        "data": data
    }
    return utility.get_json(result)
Ejemplo n.º 9
0
def admin_query():
    args = utility.get_args(request)
    draw = args.get('draw', "")  # 这个值作者会直接返回给前台
    start = args.get('start', "")  # 从多少开始
    length = args.get('length', "")  # 数据长度
    search = args.get('search[value]', "")  # 获取前台传过来的过滤条件
    order_column = args.get('order[0][column]', "")  # 哪一列排序,从0开始
    order_dir = args.get('order[0][dir]', "")  # asc desc 升序或者降序

    Superior = db.aliased(Admin)

    admins = []
    recordsTotal = 0
    if admin_permission.can():
        # Left join
        admins = db.session.query(Admin, Superior).join(
            Superior, Admin.superior,
            isouter=True).join(Admin.softwares).filter(
                func.CONCAT_WS(
                    ',', Admin.user_name, Superior.user_name,
                    Software.name).like('%' + search + '%')).order_by(
                        text(str(int(order_column) + 1) + " " +
                             order_dir)).offset(start).limit(length).all()

        recordsTotal = db.session.query(func.count(Admin.id)).scalar()
    else:
        # Left join
        admins = db.session.query(Admin, Superior).join(
            Superior, Admin.superior,
            isouter=True).join(Admin.softwares).filter(
                Admin.superior_id == current_user.id).filter(
                    func.CONCAT_WS(
                        ',', Admin.user_name, Superior.user_name,
                        Software.name).like('%' + search + '%')).order_by(
                            text(str(int(order_column) + 1) + " " +
                                 order_dir)).offset(start).limit(length).all()

        recordsTotal = db.session.query(func.count(
            Admin.id)).filter(Admin.superior_id == current_user.id).scalar()

    recordsFiltered = recordsTotal if search == "" else len(admins)

    data = []
    for admin, superior in admins:
        item = [
            admin.id, admin.user_name, admin.password,
            admin.get_roles_names(),
            admin.superior.user_name if admin.superior else "",
            admin.get_subordinates_names(),
            admin.get_softwares_names(), admin.is_enable, admin.update_time,
            admin.create_time
        ]
        data.append(item)

    result = {
        "draw": draw,
        "recordsTotal": recordsTotal,
        "recordsFiltered": recordsFiltered,
        "data": data
    }
    return utility.get_json(result)