Пример #1
0
class ManagerReturn(Resource):
    def __init__(self):
        self.dao = ManagerDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            borrowList=data['return']
            user = self.userDao.verify_token(token, '')
            if (not user):
                 return make_response(jsonify({'error': 'Unauthorized access'}), 401)
            else:
                ret=[]
                for item in borrowList:
                    self.dao.manager_return(user,item['device_id'],item['return_date'],item['return_desc'])
                    uav_dao = DeviceDAO()
                    uav = uav_dao.query_index(int(item['uav_id']))
                    uavitem = {}
                    uavitem['device_type'] = uav['device_type']
                    uavitem['device_id'] = uav['device_id']
                    uavitem['user_team'] = uav['user_team']
                    uavitem['return_date'] = item['return_time']
                    uavitem['approve'] = item['approver']
                    ret.append(uavitem)
                return json.dumps(ret)
        else:
                return make_response(jsonify({'error': 'Unauthorized access'}), 401)
Пример #2
0
class ManagerReturnConfirm(Resource):
    def __init__(self):
        self.dao = ManagerDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            returnList=data['return']
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(jsonify({'error': '用户不存在或登录过期', 'errorcode': 10000000}), 400)
            elif user == 1010301:
                return make_response(jsonify({'error': '登录过期', 'errorcode': user}), 400)
            elif user == 1010302:
                return make_response(jsonify({'error': '用户验证错误', 'errorcode': user}), 400)
            else:
                ret=[]
                for item in returnList:
                    returntime = datetime.strptime(item['return_date'], '%Y-%m-%d').date()
                    deviceid   = item['id']
                    device_cond= item['condition']
                    rs=self.dao.manager_return(user,deviceid,returntime,device_cond)
                    if rs==2052101:
                        return make_response(jsonify({'error': '设备没有被借用','errorcode':rs}), 401)
                    if rs==2052102:
                        return make_response(jsonify({'error': '设备不存在或不是本班组设备','errorcode':rs}), 401)
                    if rs == 2052103:
                        return make_response(jsonify({'error': '设备无权限归还','errorcode':rs}), 401)

                return make_response(jsonify({'success': '设备归还成功','errorcode':rs}), 200)
        else:
            return make_response(jsonify({'error': '输入参数有误', 'errorcode': 10000000}), 401)