def createDayDetail(self, team): if datetime.datetime.now().isocalendar()[2] in [6, 7]: pass else: day_detail_create_time = team["day_detail_create_time"] day_detail_create_flag = team["day_detail_create_flag"] if datetime.datetime.now().strftime('%H:%M') > day_detail_create_time: now_flag = get_year_week_day_str() if now_flag > day_detail_create_flag: users = connection.DayDetail.createByUserList(team['_id'], team['members'], team['name'], team['day_detail_summary_time']) team.update({"day_detail_create_flag": now_flag}) team.update({"day_detail_notify_flag": 0}) team['status'] = int(team['status']) team.save() _team = { "name": team['name'], "day_detail_summary_time":team['day_detail_summary_time'] } _value = { "team": _team } _queue = {"type":"createDay", "users":users, "value":_value} self.taskQueue.put(_queue)
def teamSummaryTask(self, team): year_week_day_str = get_year_week_day_str() now_hour_minute_str = get_hour_minute_str() team_task_summary_time = team['team_task_summary_time'] team_task_summary_flag = team['team_task_summary_flag'] if year_week_day_str == team_task_summary_flag: return else: if now_hour_minute_str < team_task_summary_time: return team.update({"team_task_summary_flag": year_week_day_str}) team['status'] = int(team['status']) team.save() emailList = [] userTaskList = [] now_date_str = [get_year_month_day_str_ch(), get_week_str()] i = 0 for m in team['members']: username = m['name'] useremail = m['email'] emailList.append(useremail) tasks_db = connection.Task.find({"teamID":team["_id"], "username":username, "useremail":useremail, "$or":[{"status":0} ,{"status":1}, {"status":3}]}) tasks = [] for t in tasks_db: task = {} task['username'] = username task['status'] = int(t['status']) task['name'] = t['name'] task['id'] = str(t['_id']) task['rfs'] = t['rfs'] task['pubusername'] = t['pubusername'] task['explain'] = t['explain'] task['remarks'] = t['remarks'] task['priority'] = t['priority'] task['done_100'] = t['done_100'] task['dead_line_time'] = [get_year_month_day_str_ch(t['dead_line_time']), get_hour_minute_str(t['dead_line_time'])] tasks.append(task) i += 1 userTaskList.append({"username": username, "tasks": tasks}) if i == 0: return data = { "userTaskList": userTaskList, "teamID": team['_id'], "teamname": team['name'], "now_date_str": now_date_str, "emails":emailList } _queue = {"type":"taskTeamSummary", "data":data} self.taskQueue.put(_queue)
def find_for_notify(self, teamID, member): year_week_day = get_year_week_day_str() return self.find_one({ "teamID":teamID, "username":member['name'], "useremail":member['email'], "year_week_day":year_week_day })
def get_summary_day(self, year_week_day=None): year_week_day = year_week_day or get_year_week_day_str() teamID = self['_id'] days = connection.DayDetail.find({"teamID":teamID, "year_week_day":year_week_day}) days_detail = [] for d in days: _day = {} username = d['username'] _day['username'] = username _day['status'] = d['status'] _day['submit_list'] = d['submit_list'] _day['rfs'] = d['rfs'] days_detail.append(_day) return days_detail
def summaryDayDetail(self, team): members = team['members'] day_detail_summary_time =team["day_detail_summary_time"] day_detail_summary_flag =team["day_detail_summary_flag"] now_time_str = datetime.datetime.now().strftime('%H:%M') if now_time_str >= day_detail_summary_time: now_flag = get_year_week_day_str() if now_flag > day_detail_summary_flag: team.update({"day_detail_summary_flag": now_flag}) team['status'] = int(team['status']) team.save() day_summary = team.get_summary_day(now_flag) users = team.get_users() _queue = {"type": "summaryDay", "users": users, "value": day_summary, "team": team['name'], "now_flag":now_flag} self.taskQueue.put(_queue)
def createByUserList(self, teamID, members, teamname, day_detail_summary_time): usersDayDetails = [] year_week_day = get_year_week_day_str() print day_detail_summary_time for m in members: if m['role'] not in [0, 3]: continue d = { "teamID": teamID, "teamname": teamname, "username": m["name"], "useremail": m["email"], "year_week_day": year_week_day } if connection.DayDetail.find_one(d): continue detail = [] dayDetail = self() dayDetail["status"] = 0 dayDetail["create_time"] = datetime.datetime.now() dayDetail["teamID"] = teamID dayDetail["teamname"] = teamname dayDetail["username"] = m["name"] dayDetail["useremail"] = m["email"] dayDetail["year_week_day"] = year_week_day dayDetail["submit_time"] = datetime.datetime.now() dayDetail["update_time"] = datetime.datetime.now() dayDetail["deadline_time"] = datetime.datetime.now() dayDetail["expend_time"] = 8 dayDetail.save() key = dayDetail['_id'] detail = [m["name"], m["email"], str(key)] usersDayDetails.append(detail) return usersDayDetails
def _checkDetailSummary(self, year_week_day, teamID): now_year_week_day = get_year_week_day_str() team = connection.Team.find_one({"_id":ObjectId(teamID)}) if team: now = datetime.datetime.now() _h = now.hour _m = now.minute if _h < 10: _h = "0" + str(_h) if _m < 10: _m = "0" + str(_m) now = str(_h) + ":" + str(_m) now = now_year_week_day + now team_day_detail_summary_time = team["day_detail_summary_time"] s_time = year_week_day + team_day_detail_summary_time if now > s_time: pass else: dayDetails = self.find({"teamID": teamID, "year_week_day":year_week_day}) for detail in dayDetails: if detail['status'] not in [2, 3]: return if now_year_week_day == year_week_day: team.update({"day_detail_summary_flag":year_week_day}) team.save() from db.cache import taskQueue day_summary = team.get_summary_day(year_week_day) users = team.get_users() _queue = {"type": "summaryDay", "users": users, "value": day_summary, "team": team['name'], "now_flag":year_week_day} taskQueue.put(_queue)