예제 #1
0
def adminData(current_project_id, starTime, endTime):
    '''
    管理员首页返回项目时间范围工时
    :param current_project_id:项目id
    :param starTime:起始时间
    :param endTime:结束时间
    :return:
    '''
    data = {}
    my_department = current_user.department
    my_company = current_user.get_company()
    departments = my_company.get_valid_departments()
    current_project = Project.query.filter(
        Project.id == current_project_id).first()
    if not current_project:
        for d in departments:
            for p in d.get_valid_projects():
                current_project = p
                break
    if starTime == None or starTime == "" or endTime == None or endTime == "":
        starTime = timeUtils.getTime("%Y-%m-") + "01"
        endTime = timeUtils.getTime("%Y-%m-") + timeUtils.getMonthLastDay(
            timeUtils.getTime("%Y"), timeUtils.getTime("%m"))
    data['dateList'] = timeUtils.getDateList(starTime, endTime)
    data['start_time'] = starTime
    data['end_time'] = endTime
    data['company'] = my_company
    data['departments'] = departments
    data['current_project'] = current_project
    return data
예제 #2
0
def updata(project_id,date,worktime):
    '''
    更新工时
    :param project_id: 项目id
    :param date: 日期
    :param worktime: 工时
    :return:
    '''
    now_time = timeUtils.getTime("%Y-%m-%d")
    work_hours = WorkHour.query.filter(WorkHour.project_id == project_id, WorkHour.user_id == current_user.id,
                                       WorkHour.date == date).first()
    if work_hours:
        work_hours.worktime = worktime
        work_hours.time = now_time
        work_hours.status = 1
    else:
        work_hours = WorkHour(user_id=current_user.id, project_id=project_id, worktime=worktime, time=now_time,
                              date=date)
        db.session.add(work_hours)
    try:
        db.session.commit()
        ret = STR_SUCCESS
    except Exception as e:
        systemlog.log_error(e)
        systemlog.log_error("提交工时出错")
        ret = "提交失败,请检查提交内容并重试"
    return ret
예제 #3
0
def indexData(current_project_id):
    '''
    普通用户首页数据(弃用)
    :param current_project_id:
    :return:
    '''
    data = {}
    my_department = current_user.department
    my_company = my_department.company
    my_projects = current_user.projects
    current_project = Project.query.filter(
        Project.id == current_project_id).first()
    if not current_project:
        for project in my_projects:
            if project.status == 0:
                current_project = project
                break
    current_work_hours = WorkHour.query.filter(
        WorkHour.user_id == current_user.id,
        WorkHour.time == timeUtils.getTime("%Y-%m-%d")).all()

    data['user'] = current_user
    data['company'] = my_company
    data['department'] = my_department
    data['projects'] = my_projects
    data['work_hours'] = current_work_hours
    data['current_project'] = current_project
    return data
예제 #4
0
def selectWorkHoursData(current_project_id, starTime, endTime):
    '''
    查询工时数据首页
    :param current_project_id: 需要查询的项目id
    :param starTime: 起始时间
    :param endTime: 结束时间
    :return:
    '''
    data = {}
    my_department = current_user.department
    my_company = current_user.get_company()
    my_projects = current_user.projects
    current_project = Project.query.filter(
        Project.id == current_project_id).first()
    if not current_project:  # 当前项目为空寻找第一个进行中项目为当前项目
        for project in my_projects:
            if project.status == 0:
                current_project = project
                break
    if starTime == None or starTime == "" or endTime == None or endTime == "":  # 时间区间为空设置当月时间为区间
        starTime = timeUtils.getTime("%Y-%m-") + "01"
        endTime = timeUtils.getTime("%Y-%m-") + timeUtils.getMonthLastDay(
            timeUtils.getTime("%Y"), timeUtils.getTime("%m"))
    # 根据条件查询工时
    work_hours = []
    if current_project:
        work_hours = WorkHour.query.filter(
            WorkHour.project_id == current_project.id,
            WorkHour.user_id == current_user.id).filter(
                WorkHour.date >= starTime, WorkHour.date <= endTime).all()
    data['date_list'] = timeUtils.getDateList(starTime, endTime)
    for item, index in zip(data['date_list'], range(0,
                                                    len(data['date_list']))):
        if item['date'] == timeUtils.getTime("%Y-%m-%d"):
            data['current_date'] = index + 1  #得到今天在在日期列表中的索引用于前端标黄
            break
    data['user'] = current_user
    data['company'] = my_company
    data['department'] = my_department
    data['projects'] = my_projects
    data['work_hours'] = work_hours
    data['current_project'] = current_project
    data['startime'] = starTime
    data['endtime'] = endTime
    return data
예제 #5
0
class Project(db.Model):
    __tablename__ = 't_project'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20))
    status = db.Column(db.Integer, default=0)
    regtime = db.Column(db.String(20), default=timeUtils.getTime('%Y-%m-%d'))
    department_id = db.Column(db.Integer, db.ForeignKey('t_department.id'))
    super_user_id = db.Column(db.Integer, db.ForeignKey('t_user.id'))
    users = db.relationship('User', secondary=project_user_table)

    #work_hours = db.relationship('WorkHour', backref=db.backref('project', order_by=id))
    def get_work_hours(self, start_time, end_time):
        return WorkHour.query.filter(WorkHour.project_id == self.id,
                                     WorkHour.date >= start_time,
                                     WorkHour.date <= end_time,
                                     WorkHour.status == 1).all()

    def get_valid_users(self):
        return [u for u in self.users if u.status > -1]
예제 #6
0
class User(UserMixin, db.Model):
    # 表的名字:
    __tablename__ = 't_user'
    # 表的结构:
    id = db.Column(db.Integer, primary_key=True)
    user = db.Column(db.String(20))
    pw = db.Column(db.String(20))
    status = db.Column(db.Integer, default=0)
    regtime = db.Column(db.String(20),
                        default=timeUtils.getTime('%Y-%m-%d %H:%M:%S'))
    department_id = db.Column(db.Integer, db.ForeignKey('t_department.id'))
    company_id = db.Column(db.Integer, db.ForeignKey('t_company.id'))
    projects = db.relationship('Project', secondary=project_user_table)
    super_projects = db.relationship("Project",
                                     backref=db.backref('super_user',
                                                        order_by=id))
    work_hours = db.relationship('WorkHour',
                                 backref=db.backref('user', order_by=id),
                                 lazy='dynamic')
    boms = db.relationship("ItemTableView",
                           backref=db.backref('user', order_by=id))

    # 登录认证的回调,写在user model中
    def get_work_hours(self, project_id):
        return WorkHour.query.filter(WorkHour.user_id == self.id,
                                     WorkHour.project_id == project_id,
                                     WorkHour.status == 1).all()

    def get_work_hours(self, project_id, start_time, end_time):
        return WorkHour.query.filter(WorkHour.user_id == self.id,
                                     WorkHour.project_id == project_id,
                                     WorkHour.date >= start_time,
                                     WorkHour.date <= end_time,
                                     WorkHour.status == 1).all()

    def get_company(self):
        return Company.query.get(int(self.company_id))
예제 #7
0
class Department(db.Model):
    # 表的名字:
    __tablename__ = 't_department'
    # 表的结构:
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20))
    status = db.Column(db.Integer,default=0)
    regtime = db.Column(db.String(20),default=timeUtils.getTime('%Y-%m-%d'))
    company_id = db.Column(db.Integer,db.ForeignKey('t_company.id'))
    users = db.relationship("User", backref=db.backref('department', order_by=id))
    projects = db.relationship("Project", backref=db.backref('department', order_by=id))
    def get_valid_projects(self):
        return Project.query.filter(Project.department_id == self.id,Project.status>-1).all()
    def get_not_project_user(self,project):
        users = project.users
        lists = []
        for user in self.users:
            if user not in users and user.status>-1:
                lists.append(user)
        return lists
    def get_finish_projects(self):
        return Project.query.filter(Project.department_id == self.id, Project.status == -1).all()
    def get_user_number(self):
        return len(self.users)
예제 #8
0
def makeExcel():
    '''
    下载工时报表
    :return:
    '''

    try:
        starTime = request.args.get('startime')
        endTime=request.args.get('endtime')
    except:
        pass
    if starTime == None or endTime == "":
        return render_template('alert.html', message="请输入日期范围!")
    dateList = timeUtils.getDateList(starTime,endTime,weekday = False)
    company = current_user.get_company()
    xlsx = excelUtils.make_work_hour_Ex(dateList, company, starTime,endTime)
    response = make_response(xlsx)
    file_name = quote("工时报表", 'utf-8')
    response.headers["Content-Disposition"] = "attachment; filename="+starTime+"&"+endTime+"-"+file_name+"("+timeUtils.getTime('%Y-%m-%d')+").xls"
    return response