예제 #1
0
def repairs():
    """
    添加设备维修任务
    :return:
    """
    if request.method == 'GET':
        data = db_session.query(Repair).all()
        return json.dumps({
            'code': '10001',
            'message': '操作成功',
            'data': data
        },
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
    if request.method == 'POST':
        json_data = request.values
        data = Repair(EquipmentCode=json_data.get('EquipmentCode'),
                      No=get_no(json_data.get('ApplyTime')),
                      Worker=current_user.Name,
                      ApplyTime=json_data.get('ApplyTime'),
                      FaultExpound=json_data.get('FaultExpound'))
        equipment = db_session.query(Equipment).filter_by(
            EquipmentCode=json_data.get('EquipmentCode')).first()
        equipment.Status = '待接单'
        db_session.add_all([data, equipment])
        db_session.commit()
        db_session.close()
        return json.dumps({
            'code': '10000',
            'message': '操作成功'
        },
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
예제 #2
0
def get_index_equipment():
    try:
        query_type_data = db_session.query(
            Equipment.EquipmentType).filter_by().all()
        query_floor_data = db_session.query(
            Equipment.Floor).filter_by().order_by(Equipment.Floor.asc()).all()
        equipment_type = list(set(i[0] for i in query_type_data))
        equipment_floor = list(set(i[0] for i in query_floor_data))
        data = []
        for item_floor in equipment_floor:
            result = {"楼层": item_floor}
            for item_type in equipment_type:
                query_result = db_session.query(Equipment).filter_by(
                    Floor=item_floor, EquipmentType=item_type).all()
                result[item_type] = len(query_result)
            data.append(result)
        db_session.close()
        return json.dumps({
            'code': '200',
            'mes': '查询成功',
            'data': data
        },
                          ensure_ascii=False)
    except InvalidRequestError as e:
        print('/IndexEquipment', '1')
        db_session.rollback()
        print('/IndexEquipment', '2')
        re_path = request.path
        re_func = request.url_rule.endpoint.split('.')[1]
        re_method = request.method
        # root_path = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
        # file_path = os.path.join(root_path, 'logs\\logs.txt')
        ip = socket.gethostbyname(socket.gethostname())
        now_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        db_session.add(
            RunError(Time=now_time,
                     IP=ip,
                     Path=re_path,
                     Func=re_func,
                     Method=re_method,
                     Error=str(e)))
        db_session.commit()
        my_log(str(e))
        return json.dumps({'code': '200', 'mes': '事务回滚'}, ensure_ascii=False)
    except Exception as e:
        print(str(e))
        return json.dumps({
            'code': '200',
            'mes': '查询失败',
            'error': str(e)
        },
                          ensure_ascii=False)
예제 #3
0
def repair_tasks(p):
    """
    更新维修任务表的状态
    :param p: 更改工单状态
    :return:
    """
    if p == 'jiedan':
        json_data = request.values
        data = db_session.query(Repair).filter_by(
            No=json_data.get('No')).first()
        data.Status = '维修中'
        data.ReceiveWorker = current_user.Name
        data.ReceiveTime = json_data.get('Time')
        equipment = db_session.query(Equipment).filter_by(
            EquipmentCode=json_data.get('EquipmentCode')).first()
        equipment.Status = '维修中'
        db_session.add_all([data, equipment])
        db_session.commit()
        db_session.close()
        return json.dumps({
            'code': '10001',
            'message': '操作成功'
        },
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
    if p == 'over':
        json_data = request.values
        data = db_session.query(Repair).filter_by(
            No=json_data.get('No')).first()
        task_data = RepairTask(EquipmentCode=data.EquipmentCode,
                               No=data.No,
                               Status='维修完成',
                               Worker=data.Worker,
                               ReceiveWorker=data.ReceiveWorker,
                               Content=json_data.get('Content'),
                               ApplyTime=data.ApplyTime,
                               ReceiveTime=data.ReceiveTime,
                               EndTime=json_data.get('EndTime'))
        equipment = db_session.query(Equipment).filter_by(
            EquipmentCode=json_data.get('EquipmentCode')).first()
        equipment.Status = '运行中'
        db_session.add_all([task_data, equipment])
        db_session.delete(data)
        db_session.commit()
        db_session.close()
        return json.dumps({
            'code': '10001',
            'message': '操作成功'
        },
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
예제 #4
0
def repair_record(p):
    """维修记录"""
    # 每页多少条
    limit = int(request.values.get('limit'))
    # 当前页
    offset = int(request.values.get('offset'))
    total = db_session.query(RepairTask).filter_by(EquipmentCode=p).count()
    data = db_session.query(RepairTask).filter(
        RepairTask.EquipmentCode == p).order_by(
            RepairTask.ApplyTime.desc()).limit(limit).offset(
                (offset - 1) * limit)
    return json.dumps(
        {
            'code': '10001',
            'message': '操作成功',
            'data': {
                'rows': data.all(),
                'total': total
            }
        },
        cls=AlchemyEncoder,
        ensure_ascii=False)
예제 #5
0
def keep_record(p):
    """
    查看保养记录
    :param p: 设备号
    :return: 该设备的所有保养记录记录
    """
    try:
        # 当前页码
        page = int(request.values.get('offset'))
        # 每页多少条
        per_page = int(request.values.get('limit'))

        query_data = db_session.query(KeepRecord).order_by(
            KeepRecord.ApplyTime.desc()).all()
        # data_list = [item for item in query_data]
        result = []
        for data in query_data:
            if p in data.EquipmentCode:
                result.append(data)
        result_data = result[(page - 1) * per_page:page * per_page]
        return json.dumps(
            {
                'code': '10001',
                'message': '操作成功',
                'data': {
                    'rows': result_data,
                    'total': len(result)
                }
            },
            cls=AlchemyEncoder,
            ensure_ascii=False)
        # total = db_session.query(KeepRecord).filter_by(EquipmentCode=p).count()
        # data = db_session.query(KeepRecord).filter(KeepRecord.EquipmentCode == p).order_by(
        #     KeepRecord.ApplyTime.desc()).limit(per_page).offset((page - 1) * per_page)
        # return json.dumps({'code': '10001', 'message': '操作成功', 'data': {'rows': data.all(), 'total': total}},
        #                   cls=AlchemyEncoder, ensure_ascii=False)
    except Exception as e:
        logger.error(e)
        insertSyslog("error", "保养记录查询错误:" + str(e), current_user.Name)
        return json.dumps({
            'code': '20002',
            'message': str(e)
        },
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
예제 #6
0
def index():
    address = db_session.query(TagDetail).all()
    result = {}
    for tag in address:
        data = redis_coon.hget(REDIS_TABLENAME, tag.Address)

        if tag.Type == '电表' and data is not None:
            result[tag.Address] = data
        # elif tag.Type == '水表' and data is not None:
        #     db_session.add(
        #         WaterEnergy(WaterSum=str(data), AreaName=tag.AreaName, CollectionDate=datetime.now(),
        #                     Address=tag.Address))
        #     db_session.commit()
        #     # db_session.close()
        else:
            pass

    return json.dumps({'data': result}, cls=MyEncoder, ensure_ascii=False)
예제 #7
0
def get_keep_plan(p):
    """
    获取对应设备的保养计划
    :param p: 设备号
    :return: 该设备的所有记录
    """
    query_data = db_session.query(KeepPlan).order_by(
        KeepPlan.ApplyTime.desc()).all()
    result = []
    for data in query_data:
        if p in data.EquipmentCode:
            result.append(data)
    return json.dumps({
        'code': '10001',
        'message': '操作成功',
        'data': result
    },
                      cls=AlchemyEncoder,
                      ensure_ascii=False)
예제 #8
0
def keep_tasks():
    """保养任务表"""
    try:
        query_data = db_session.query(KeepPlan).filter_by(Status='待保养').all()
        if request.method == 'GET':
            # 每页多少条
            limit = int(request.values.get('limit', '5'))
            # 当前页
            offset = int(request.values.get('offset', '1'))
            for item in query_data:
                q = db_session.query(KeepTask).filter_by(No=item.No).first()
                if not q and get_time_stamp(item.WorkTime):
                    data = KeepTask(EquipmentCode=item.EquipmentCode,
                                    No=item.No,
                                    Worker=item.Worker,
                                    Status=item.Status,
                                    ApplyTime=item.ApplyTime,
                                    StartTime=item.StartTime,
                                    WorkTime=item.WorkTime,
                                    WeekTime=item.WeekTime,
                                    Type=item.Type)
                    db_session.add(data)
                    db_session.commit()
                # if item.Type == '单次':
                #     pass
                # db_session.delete(item)
                # db_session.commit()
            data = db_session.query(KeepTask).order_by(
                KeepTask.ApplyTime.desc()).limit(limit).offset(
                    (offset - 1) * limit)
            total = db_session.query(KeepTask).count()
            return json.dumps(
                {
                    'code': '10001',
                    'message': '操作成功',
                    'data': {
                        'rows': data.all(),
                        'total': total
                    }
                },
                cls=AlchemyEncoder,
                ensure_ascii=False)
        if request.method == 'POST':
            json_data = request.values
            no = json_data.get('No')
            end_time = json_data.get('EndTime')
            content = json_data.get('Content')
            item = db_session.query(KeepTask).filter_by(No=no).first()
            data = KeepRecord(EquipmentCode=item.EquipmentCode,
                              No=no,
                              Worker=item.Worker,
                              Status='已完成',
                              Type=item.Type,
                              KeepWorker=current_user.Name,
                              ApplyTime=item.ApplyTime,
                              StartTime=item.StartTime,
                              Describe=item.Describe,
                              Content=content,
                              WeekTime=item.WeekTime,
                              EndTime=end_time)
            db_session.delete(item)
            db_session.commit()
            keep_plan = db_session.query(KeepPlan).filter_by(No=no).first()
            if keep_plan and keep_plan.Type == '周期':
                keep_plan.WorkTime = add_date(keep_plan.WeekTime,
                                              keep_plan.WorkTime)
                db_session.add_all([data, keep_plan])
                db_session.commit()
                db_session.close()
                return json.dumps({
                    'code': '10001',
                    'message': '操作成功'
                },
                                  cls=AlchemyEncoder,
                                  ensure_ascii=False)
            else:
                db_session.delete(keep_plan)
                db_session.add(data)
                db_session.commit()
                db_session.close()
            return json.dumps({
                'code': '10001',
                'message': '操作成功'
            },
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
    except Exception as e:
        logger.error(e)
        insertSyslog("error", "保养任务表修改错误:" + str(e), current_user.Name)
        return json.dumps({
            'code': '20002',
            'message': str(e)
        },
                          cls=AlchemyEncoder,
                          ensure_ascii=False)