def taskForEveryone(): ''' 寻找每个人的推送任务并返回信息 (需要测试) ''' Clazz = leancloud.Object.extend('Clazz') Accout = leancloud.Object.extend('ClazzAccount') User = leancloud.Object.extend('User') Task = leancloud.Object.extend('Post') clazzQuery = Clazz.query userQuery = User.query accout1 = Accout.query accout2 = Accout.query taskQuery = Task.query clazzQuery.select('objectId', 'startDate', 'endDate', 'name') clazzList = clazzQuery.find() userList = [] userTask = [] nowDate = datetime.datetime.utcnow().replace(tzinfo=utc) for each in clazzList: startDate = each.get('startDate') endDate = each.get('endDate') if startDate <= nowDate and endDate >= nowDate: # 对正在进行的班级进行人员统计 clazz_folder = Clazz.create_without_data(each.id) query1 = accout1.equal_to('clazz', clazz_folder).equal_to('status', 'WAITENTER') query2 = accout2.equal_to('clazz', clazz_folder).equal_to('status', 'PROCESSING') query = leancloud.Query.or_(query1, query2) query.select('user') def call_back(lst): for item in lst: userList.append(item) map_query(query, 1000, call_back) # 对正在进行的班级进行任务统计 timeCount = datediff(startDate.strftime("%Y-%m-%d"), nowDate.strftime("%Y-%m-%d")) timeCount = timeCount + 1 tasks = taskQuery.equal_to('clazz', clazz_folder).equal_to('dayNumber', timeCount).find() for userItem in userList: for taskItem in tasks: dic = {} user = userQuery.get(userItem.get('user').id) dic['userId'] = user.id dic['openId'] = user.get('openId') dic['userName'] = user.get('name') dic['task'] = taskItem.id dic['dayNum'] = timeCount dic['clazzName'] = each.get('name') userTask.append(dic) return userTask
def taskByClazzId(clazzId): ''' 通过clazzId处理课程推送任务信息 ''' # 实例化对象,创建query Clazz = leancloud.Object.extend('Clazz') Accout = leancloud.Object.extend('ClazzAccount') Task = leancloud.Object.extend('Post') User = leancloud.Object.extend('_User') clazzQuery,accout1,userQuery,accout2,taskQuery = Clazz.query, Accout.query, User.query, Accout.query, Task.query clazzQuery.select('objectId', 'startDate', 'endDate', 'name') clazz = clazzQuery.get(clazzId) userList, userTask = [], [] nowDate = datetime.datetime.utcnow().replace(tzinfo=utc) startDate = clazz.get('startDate') endDate = clazz.get('endDate') if startDate <= nowDate and endDate >= nowDate: # 对正在进行的班级进行人员统计 clazz_folder = Clazz.create_without_data(clazz.id) query1 = accout1.equal_to('clazz', clazz_folder).equal_to('status', 'WAITENTER') query2 = accout2.equal_to('clazz', clazz_folder).equal_to('status', 'PROCESSING') query = leancloud.Query.or_(query1, query2) query.select('user') def call_back(lst): for item in lst: userList.append(item) map_query(query, 1000, call_back) # 对正在进行的班级进行任务统计 timeCount = datediff(startDate.strftime("%Y-%m-%d"), nowDate.strftime("%Y-%m-%d")) timeCount = timeCount + 1 tasks = taskQuery.equal_to('clazz', clazz_folder).equal_to('dayNumber', timeCount).find() for userItem in userList: for taskItem in tasks: dic = {} user = userQuery.get(userItem.get('user').id) dic['userId'] = user.id dic['openId'] = user.get('openId') dic['userName'] = user.get('name') dic['task'] = taskItem.id dic['dayNum'] = timeCount dic['clazzName'] = clazz.get('name') if variable.taskUrl == '': variable.taskUrl = taskItem.get('redirectUrl') userTask.append(dic) return userTask