class UAVPartsList(Resource): def __init__(self): self.dao = PartsDao() 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() parts_status = args.get('parts_status') parts_type = args.get('parts_type') page_index = args.get('page_index') page_size = args.get('page_size') return self.dao.query_condition(user, None, None, parts_type, parts_status, page_index, page_size) else: return make_response(jsonify({'error': 'Unauthorized access'}), 401) def get(self): return self.post()
class UAVPartsStatus(Resource): def __init__(self): self.dao = PartsDao() self.userDao = UserDAO() def post(self): if (request.data != ""): data = json.loads(request.data) token = data['token'] parts_id = data['parts_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_parts_status(user, parts_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()
class UAVPartsStatistic(Resource): def __init__(self): self.dao = PartsDao() self.userDao = UserDAO() def post(self, parts_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, parts_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, parts_status): return self.post(parts_status)
class UAVPartsStatus(Resource): def __init__(self): self.dao = PartsDao() self.userDao = UserDAO() def post(self): if (request.data != ""): data = json.loads(request.data) token = data['token'] parts_id = data['parts_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_parts_status(user, parts_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()
class UAVPartsStatistic(Resource): def __init__(self): self.dao = PartsDao() self.userDao = UserDAO() def post(self, parts_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, parts_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, parts_status): return self.post(parts_status)
class UAVPartsList(Resource): def __init__(self): self.dao = PartsDao() 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() parts_status = args.get('parts_status') parts_type = args.get('parts_type') page_index = args.get('page_index') page_size = args.get('page_size') return self.dao.query_condition(user, None, None, parts_type, parts_status, page_index, page_size) else: return make_response( jsonify({ 'error': '输入参数有误', 'errorcode': 10000000 }), 401) def get(self): return self.post()
class UAVPartsListPages(Resource): def __init__(self): self.dao = PartsDao() 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) else: return make_response(jsonify({'error': 'Unauthorized access'}), 401) def get(self): return self.post()
class UAVPartsGetID(Resource): def __init__(self): self.dao = PartsDao() self.userDao = UserDAO() def post(self): if (request.data != ""): data = json.loads(request.data) token = data['token'] parts_id = data['parts_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, parts_id, None, None, None, 1, 1) else: return make_response( jsonify({ 'error': '输入参数有误', 'errorcode': 10000000 }), 401) def get(self): return self.post()
class UAVPartsAdd(Resource): def __init__(self): self.dao = PartsDao() self.userDao = UserDAO() def post(self): if (request.data != ""): data = json.loads(request.data) token = data['token'] parts = data['parts'] parts_dict = json.loads(json.dumps(parts)) parts_obj = Parts() parts_obj.parts_id = parts_dict[0]['parts_id'] parts_obj.parts_ver = parts_dict[0]['parts_ver'] parts_obj.parts_type = parts_dict[0]['parts_type'] parts_obj.parts_fact = parts_dict[0]['parts_fact'] parts_obj.parts_date = parts_dict[0]['parts_date'] parts_obj.user_team = parts_dict[0]['user_team'] parts_obj.parts_status = '在库' parts_obj.parts_use_number = 0 user = self.userDao.verify_token(token, '') if (not user): return make_response(jsonify({'error': 'Unauthorized access'}), 401) rs = self.dao.add_parts(user, parts_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()
def __init__(self): self.dao = PartsDao() self.userDao = UserDAO()
class UAVPartsModify(Resource): def __init__(self): self.dao = PartsDao() self.userDao = UserDAO() def post(self): if (request.data != ""): data = json.loads(request.data) token = data['token'] parts = data['parts'] parts_dict = json.loads(json.dumps(parts)) parts_obj = Parts() parts_obj.parts_id = parts_dict[0]['parts_id'] parts_obj.parts_ver = parts_dict[0]['parts_ver'] parts_obj.parts_type = parts_dict[0]['parts_type'] parts_obj.parts_fact = parts_dict[0]['parts_fact'] parts_obj.parts_date = datetime.strptime( parts_dict[0]['parts_date'], '%Y-%m-%d').date() parts_obj.user_team = parts_dict[0]['user_team'] parts_obj.parts_use_dpartment = parts_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_parts(user, parts_obj) if rs == 1: return make_response(jsonify({'success': '添加设备成功'}), 200) elif rs == 2030801: return make_response( jsonify({ 'failed': '待修改的设备不存在', 'errorcode': rs }), 401) elif rs == 2030802: return make_response( jsonify({ 'failed': '无权限添加设备', 'errorcode': rs }), 401) else: return make_response( jsonify({ 'error': '输入参数有误', 'errorcode': 10000000 }), 401) def get(self): return self.post()