def get_task_list(mid, create_user, category, department): db = Database() keys = ['id', 'name', 'moduleId', 'createUser', 'status', 'executor', 'createTime', 'description', 'category', 'department', 'mark', 'progress', 'planEndTime', 'multiUser'] sql, params = "select " + ','.join(keys) + ", IFNULL(uc, 0) userCount from task t left join \ (select taskId, count(*) uc from \ (select taskId, user from record_day where moduleId=%s group by taskId, user \ ) a group by taskId \ ) r on t.id=r.taskId \ left join \ (select taskId, max(updateTime) utm from record_day where moduleId=%s group by taskId \ ) b on t.id=r.taskId where t.moduleId=%s", [mid, mid, mid] if create_user != '': sql += " and createUser=%s" params.append(create_user) if category != '': sql += " and category=%s" params.append(category) if department != '': sql += " and department=%s" sql += " order by utm, status desc" data = db.read_all(sql, params) for line in data: line['planEndTime'] = str(line['planEndTime']) line['createTime'] = str(line['createTime']) return data
def get_module_list(pid, create_user, category, department): db = Database() keys = [ 'id', 'name', 'projectId', 'createUser', 'status', 'manager', 'createTime', 'description', 'category', 'department', 'mark' ] sql, params = "select " + ','.join( keys) + " from module where projectId=%s", [pid] if create_user != '': sql += " and createUser=%s" params.append(create_user) if category != '': sql += " and category=%s" params.append(category) if department != '': sql += " and department=%s" sql += " order by createTime desc" data = db.read_all(sql, params) for line in data: line['createTime'] = str(line['createTime']) return data
def _list_report_day(self, key="record", user=None, department=None): db = Database() table = "record_day" if key == "record" else "plan_day" params = [pre_days(), pre_days(-1)] sql = '''select user, workday, project, module, task, content, r.progress progress, r.category category, planEndTime from {} r left join task t on t.id=r.taskId where workday between %s and %s'''.format(table) if user: sql += " and user=%s" params.append(user) if department: sql += " and user in (select username from user where orgId=%s)" params.append(department) res = db.read_all(sql, params) '''按天归类''' dts = {} for d in res: day = str(d['workday'])[:10] if day not in dts: dts[day] = [] dts[day].append(d) '''End For''' return dts