class UAVDeviceAdd(Resource): def __init__(self): self.dao = DeviceDAO() self.userDao = UserDAO() def post(self): if (request.data != ""): data = json.loads(request.data) token = data['token'] device_json = data['device'] device_dict = json.loads(json.dumps(device_json)) device_obj = Device() device_obj.device_id = int(device_dict[0]['device_id']) device_obj.device_ver = device_dict[0]['device_ver'] device_obj.device_type = device_dict[0]['device_type'] device_obj.uad_code = device_dict[0]['uad_code'] device_obj.device_fact = device_dict[0]['device_fact'] device_obj.device_date = device_dict[0]['device_date'] device_obj.user_team = device_dict[0]['user_team'] device_obj.uad_camera = device_dict[0]['uad_camera'] device_obj.uav_yuntai = device_dict[0]['uav_yuntai'] device_obj.uad_rcontrol = device_dict[0]['uad_rcontrol'] device_obj.device_status = '在库' device_obj.device_use_number = 0 user = self.userDao.verify_token(token, '') if (not user): return make_response(jsonify({'error': 'Unauthorized access'}), 401) rs = self.dao.add_device(user, device_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) def get(self): return self.post()
class UAVDeviceManagerSearch(Resource): def __init__(self): self.dao = DeviceDAO() self.userDao = UserDAO() def get(self, id): 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) else: device_id = id return self.dao.query_condition(user, device_id, None, None, None, None, 1, 1) else: return make_response(jsonify({'error': 'Unauthorized access'}), 401) def put(self, id): 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) device = Device() device_data = request.data['device'] args = parser.parse_args() device.device_id = id device.device_ver = device_data['device_ver'] device.device_type = device_data['device_type'] device.uad_code = device_data['uad_code'] device.device_fact = device_data['device_fact'] device.device_date = device_data['device_date'] device.user_team = device_data['user_team'] device.uad_camera = device_data['uad_camera'] device.uav_yuntai = device_data['uav_yuntai'] device.uad_rcontrol = device_data['uad_rcontrol'] device.device_status = device_data['device_status'] rs = dao.modify_device(user, device) if rs == -1: return make_response(jsonify({'error': 'Unauthorized modify'}), 401) else: return make_response( jsonify({'success': 'modify device success'}), 200) else: return make_response(jsonify({'error': 'Unauthorized access'}), 401) def post(self, id): args = parser.parse_args() token = args.get('token') user = self.userDao.verify_token(token, '') if (not user): return make_response(jsonify({'error': 'Unauthorized access'}), 401) else: device = Device() if (request.data != ""): data = json.loads(request.data) if not data.has_key('device'): return make_response( jsonify({'error': 'Data Format Rrror'}), 401) device_data = request.data['device'] device.device_id = device_data['device_id'] device.device_ver = device_data['device_ver'] device.device_type = device_data['device_type'] device.uad_code = device_data['uad_code'] device.device_fact = device_data['device_fact'] device.device_date = device_data['device_date'] device.user_team = device_data['user_team'] device.uad_camera = device_data['uad_camera'] device.uav_yuntai = device_data['uav_yuntai'] device.uad_rcontrol = device_data['uad_rcontrol'] device.device_status = device_data['device_status'] rs = self.dao.add_device(user, device) if rs == 1: return make_response( jsonify({'success': 'add device success'}), 200) else: return make_response( jsonify({'error': 'Unauthorized add data'}), 401) else: return make_response(jsonify({'error': 'Data Format Rrror'}), 401)
class UAVDeviceAdd(Resource): def __init__(self): self.dao = DeviceDAO() self.userDao = UserDAO() def post(self): if (request.data != ""): data = json.loads(request.data) token = data['token'] device_json = data['device'] device_dict = json.loads(json.dumps(device_json)) device_obj = Device() device_obj.device_id = int(device_dict[0]['device_id']) device_obj.device_ver = device_dict[0]['device_ver'] device_obj.device_type = device_dict[0]['device_type'] device_obj.uad_code = device_dict[0]['uad_code'] device_obj.device_fact = device_dict[0]['device_fact'] device_obj.device_date = datetime.strptime( device_dict[0]['device_date'], '%Y-%m-%d').date() device_obj.user_team = device_dict[0]['user_team'] device_obj.uad_camera = device_dict[0]['uad_camera'] device_obj.uav_yuntai = device_dict[0]['uav_yuntai'] device_obj.uad_rcontrol = device_dict[0]['uad_rcontrol'] device_obj.device_use_dpartment = device_dict[0]['use_department'] device_obj.device_status = '在库' device_obj.device_use_number = 0 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.add_device(user, device_obj) if rs == 1: return make_response(jsonify({'success': '添加设备成功'}), 200) elif rs == 2011101: return make_response( jsonify({ 'existed': '设备已经存在', 'errorcode': rs }), 401) else: return make_response( jsonify({ 'failed': '无权限添加设备', 'errorcode': rs }), 401) else: return make_response( jsonify({ 'error': '输入参数有误', 'errorcode': 10000000 }), 401) def get(self): return self.post()