Ejemplo n.º 1
0
class UAVBatteryModify(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            if (request.data != ""):
                data = json.loads(request.data)
                token = data['token']
                battery = data['battery']
                battery_dict = json.loads(json.dumps(battery))
                battery_obj = Battery()
                battery_obj.battery_id = battery_dict[0]['battery_id']
                battery_obj.battery_ver = battery_dict[0]['battery_ver']
                battery_obj.battery_type = battery_dict[0]['battery_type']
                battery_obj.battery_fact = battery_dict[0]['battery_fact']
                battery_obj.battery_date = battery_dict[0]['battery_date']
                battery_obj.user_team = battery_dict[0]['user_team']
                user = self.userDao.verify_token(token, '')
                if (not user):
                    return make_response(
                        jsonify({'error': 'Unauthorized access'}), 401)

                rs = self.dao.modify_battery(user, battery_obj)
                if rs == 1:
                    return make_response(
                        jsonify({'success': 'add device success'}), 200)
                else:
                    return make_response(
                        jsonify({'failed': 'add device failed'}), 401)
            else:
                return make_response(jsonify({'error': 'Unauthorized access'}),
                                     401)
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(jsonify({'error': 'Unauthorized access'}),
                                     401)

            rs = self.dao.modify_battery_status(user, battery_id, status)
            if rs == 1:
                return make_response(
                    jsonify({'success': 'modify device status success'}), 200)
            else:
                return make_response(
                    jsonify({'failed': 'modify device status failed'}), 401)
        else:
            return make_response(jsonify({'error': 'Unauthorized access'}),
                                 401)

    def get(self):
        return self.post()
Ejemplo n.º 2
0
class UAVBatteryStatistic(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self, battery_status):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(jsonify({'error': 'Unauthorized access'}),
                                     401)

            rs = self.dao.query_statistic(user, battery_status)
            if rs == -1:
                return make_response(jsonify({'error': 'Unauthorized access'}),
                                     401)
            else:
                return rs
        else:
            return make_response(jsonify({'error': 'Unauthorized access'}),
                                 401)

    def get(self, battery_status):
        return self.post(battery_status)
Ejemplo n.º 3
0
class UAVBatteryList(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(jsonify({'error': 'Unauthorized access'}),
                                     401)
            args = parser.parse_args()
            battery_status = args.get('battery_status')
            battery_type = args.get('battery_type')
            page_index = args.get('page_index')
            page_size = args.get('page_size')
            return self.dao.query_condition(user, None, None, battery_type,
                                            battery_status, page_index,
                                            page_size)
        else:
            return make_response(jsonify({'error': 'Unauthorized access'}),
                                 401)

    def get(self):
        return self.post()
Ejemplo n.º 4
0
class UAVBatteryStatus(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            battery_id = data['battery_id']
            status = data['status']
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(jsonify({'error': 'Unauthorized access'}),
                                     401)

            rs = self.dao.modify_battery_status(user, battery_id, status)
            if rs == 1:
                return make_response(
                    jsonify({'success': 'modify device status success'}), 200)
            else:
                return make_response(
                    jsonify({'failed': 'modify device status failed'}), 401)
        else:
            return make_response(jsonify({'error': 'Unauthorized access'}),
                                 401)

    def get(self):
        return self.post()
Ejemplo n.º 5
0
class UAVBatteryStatus(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            battery_id = data['battery_id']
            status = data['status']
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(
                    jsonify({
                        'error': '用户不存在或登录过期',
                        'errorcode': 10000000
                    }), 400)
            if user == 1010301:
                return make_response(
                    jsonify({
                        'error': '登录过期',
                        'errorcode': user
                    }), 400)
            if user == 1010302:
                return make_response(
                    jsonify({
                        'error': '用户验证错误',
                        'errorcode': user
                    }), 400)

            rs = self.dao.modify_battery_status(user, battery_id, status)
            if rs == 1:
                return make_response(jsonify({'success': '修改电池状态成功'}), 200)
            else:
                return make_response(
                    jsonify({
                        'error': '用户无权限修改电池状态',
                        'errorcode': rs
                    }), 401)
        else:
            return make_response(
                jsonify({
                    'error': '输入参数错误',
                    'errorcode': 10000000
                }), 401)

    def get(self):
        return self.post()
Ejemplo n.º 6
0
class UAVBatteryStatistic(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self, battery_status):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(
                    jsonify({
                        'error': '用户不存在或登录过期',
                        'errorcode': 10000000
                    }), 400)
            if user == 1010301:
                return make_response(
                    jsonify({
                        'error': '登录过期',
                        'errorcode': user
                    }), 400)
            if user == 1010302:
                return make_response(
                    jsonify({
                        'error': '用户验证错误',
                        'errorcode': user
                    }), 400)

            rs = self.dao.query_statistic(user, battery_status)
            if rs == None:
                return make_response(
                    jsonify({
                        'error': '获取统计信息失败',
                        'errorcode': 10000000
                    }), 401)
            else:
                return rs
        else:
            return make_response(
                jsonify({
                    'error': '输入参数错误',
                    'errorcode': 10000000
                }), 401)

    def get(self, battery_status):
        return self.post(battery_status)
Ejemplo n.º 7
0
class UAVBatteryList(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(
                    jsonify({
                        'error': '用户不存在或登录过期',
                        'errorcode': 10000000
                    }), 400)
            if user == 1010301:
                return make_response(
                    jsonify({
                        'error': '登录过期',
                        'errorcode': user
                    }), 400)
            if user == 1010302:
                return make_response(
                    jsonify({
                        'error': '用户验证错误',
                        'errorcode': user
                    }), 400)

            args = parser.parse_args()
            battery_status = args.get('battery_status')
            battery_type = args.get('battery_type')
            page_index = args.get('page_index')
            page_size = args.get('page_size')
            return self.dao.query_condition(user, None, None, battery_type,
                                            battery_status, page_index,
                                            page_size)
        else:
            return make_response(
                jsonify({
                    'error': '输入参数有误',
                    'errorcode': 10000000
                }), 401)

    def get(self):
        return self.post()
Ejemplo n.º 8
0
class UAVBatteryListPages(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            page_size = data['page_size']
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(jsonify({'error': 'Unauthorized access'}),
                                     401)
            return self.dao.query_pages(user, page_size)

    def get(self):
        return self.post()
Ejemplo n.º 9
0
class UAVBatteryGetID(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            battery_id = data['battery_id']
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(
                    jsonify({
                        'error': '用户不存在或登录过期',
                        'errorcode': 10000000
                    }), 400)
            if user == 1010301:
                return make_response(
                    jsonify({
                        'error': '登录过期',
                        'errorcode': user
                    }), 400)
            if user == 1010302:
                return make_response(
                    jsonify({
                        'error': '用户验证错误',
                        'errorcode': user
                    }), 400)

            return self.dao.query_condition(user, battery_id, None, None, None,
                                            1, 1)
        else:
            return make_response(
                jsonify({
                    'error': '输入数据有误',
                    'errorcode': 1000000
                }), 401)

    def get(self):
        return self.post()
Ejemplo n.º 10
0
 def __init__(self):
     self.dao = BatteryDAO()
     self.userDao = UserDAO()
Ejemplo n.º 11
0
class UAVBatteryModify(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            if (request.data != ""):
                data = json.loads(request.data)
                token = data['token']
                battery = data['battery']
                battery_dict = json.loads(json.dumps(battery))
                battery_obj = Battery()
                battery_obj.battery_id = battery_dict[0]['battery_id']
                battery_obj.battery_ver = battery_dict[0]['battery_ver']
                battery_obj.battery_type = battery_dict[0]['battery_type']
                battery_obj.battery_fact = battery_dict[0]['battery_fact']
                battery_obj.battery_date = datetime.strptime(
                    battery_dict[0]['battery_date'], '%Y-%m-%d').date()
                battery_obj.user_team = battery_dict[0]['user_team']
                battery_obj.battery_use_dpartment = battery_dict[0][
                    'use_department']
                user = self.userDao.verify_token(token, '')
                if (not user):
                    return make_response(
                        jsonify({
                            'error': '用户不存在或登录过期',
                            'errorcode': 10000000
                        }), 400)
                if user == 1010301:
                    return make_response(
                        jsonify({
                            'error': '登录过期',
                            'errorcode': user
                        }), 400)
                if user == 1010302:
                    return make_response(
                        jsonify({
                            'error': '用户验证错误',
                            'errorcode': user
                        }), 400)

                rs = self.dao.modify_battery(user, battery_obj)
                if rs == 1:
                    return make_response(jsonify({'success': '修改电池状态成功'}), 200)
                elif rs == 2021001:
                    return make_response(
                        jsonify({
                            'error': '待修改的电池不存在',
                            'errorcode': rs
                        }), 401)
            else:
                return make_response(
                    jsonify({
                        'error': '输入参数错误',
                        'errorcode': 10000000
                    }), 401)

    def get(self):
        return self.post()