Python 图书馆志愿者值班管理系统:换班、调班、请假审批

作为图书馆管理者,您需要管理志愿者的值班情况,并处理换班、调班、请假等请求。本文将提供一个使用 Python 开发的简单值班管理系统,帮助您高效管理志愿者值班。

系统功能:

  • 值班表管理: 支持添加、删除、修改值班信息,并展示当前的值班表。
  • 换班请求: 志愿者可以请求与其他志愿者交换班次,管理员审核后进行操作。
  • 调班请求: 志愿者可以请求调整自身班次,管理员审核后进行操作。
  • 请假申请: 志愿者可以提交请假申请,管理员审核后进行操作。
  • 管理员审批: 管理员可以审核所有换班、调班、请假请求,并进行批准或拒绝操作。

代码示例:

import csv

class Volunteer:
    '志愿者类'
    def __init__(self, name, id):
        self.name = name
        self.id = id

class Shift:
    '班次类'
    def __init__(self, date, time, volunteer):
        self.date = date
        self.time = time
        self.volunteer = volunteer

class LibrarySchedule:
    '图书馆值班表类'
    def __init__(self):
        self.volunteers = []
        self.shifts = []
        self.load_volunteers()
        self.load_shifts()

    def load_volunteers(self):
        '加载志愿者信息'
        with open('volunteers.csv', 'r') as f:
            reader = csv.reader(f)
            for row in reader:
                volunteer = Volunteer(row[0], row[1])
                self.volunteers.append(volunteer)

    def load_shifts(self):
        '加载值班表信息'
        with open('shifts.csv', 'r') as f:
            reader = csv.reader(f)
            for row in reader:
                volunteer = self.find_volunteer(row[2])
                shift = Shift(row[0], row[1], volunteer)
                self.shifts.append(shift)

    def find_volunteer(self, id):
        '根据ID查找志愿者'
        for volunteer in self.volunteers:
            if volunteer.id == id:
                return volunteer
        return None

    def display_schedule(self):
        '展示值班表'
        print('{:<10}{:<10}{:<10}'.format('Date', 'Time', 'Volunteer'))
        for shift in self.shifts:
            print('{:<10}{:<10}{:<10}'.format(shift.date, shift.time, shift.volunteer.name))

    def request_swap_shift(self, volunteer1, volunteer2, date, time):
        '处理换班请求'
        shift1 = self.find_shift(volunteer1, date, time)
        shift2 = self.find_shift(volunteer2, date, time)
        if shift1 is None or shift2 is None:
            print('Error: One or both of the shifts do not exist')
            return
        if shift1.volunteer != volunteer1 or shift2.volunteer != volunteer2:
            print('Error: One or both of the shifts do not belong to the specified volunteers')
            return
        # 管理员审核操作,省略
        shift1.volunteer = volunteer2
        shift2.volunteer = volunteer1
        print('Shifts successfully swapped')

    def request_change_shift(self, volunteer, date, time):
        '处理调班请求'
        shift = self.find_shift(volunteer, date, time)
        if shift is None:
            print('Error: Shift does not exist')
            return
        new_volunteer_id = input('Enter the ID of the new volunteer: ')
        new_volunteer = self.find_volunteer(new_volunteer_id)
        if new_volunteer is None:
            print('Error: Volunteer does not exist')
            return
        # 管理员审核操作,省略
        shift.volunteer = new_volunteer
        print('Shift successfully changed')

    def request_leave(self, volunteer, date, time):
        '处理请假申请'
        shift = self.find_shift(volunteer, date, time)
        if shift is None:
            print('Error: Shift does not exist')
            return
        # 管理员审核操作,省略
        shift.volunteer = None
        print('Leave request submitted')

    def find_shift(self, volunteer, date, time):
        '根据志愿者、日期和时间查找班次'
        for shift in self.shifts:
            if shift.volunteer == volunteer and shift.date == date and shift.time == time:
                return shift
        return None

    def save_shifts(self):
        '保存值班表信息'
        with open('shifts.csv', 'w') as f:
            writer = csv.writer(f)
            for shift in self.shifts:
                writer.writerow([shift.date, shift.time, shift.volunteer.id])

schedule = LibrarySchedule()

while True:
    print('1. Display schedule')
    print('2. Request to swap shifts')
    print('3. Request to change shift')
    print('4. Request leave')
    print('5. Save schedule')
    print('6. Quit')
    choice = input('Enter your choice: ')

    if choice == '1':
        schedule.display_schedule()

    elif choice == '2':
        volunteer1_id = input('Enter the ID of the first volunteer: ')
        volunteer1 = schedule.find_volunteer(volunteer1_id)
        if volunteer1 is None:
            print('Error: Volunteer does not exist')
            continue
        volunteer2_id = input('Enter the ID of the second volunteer: ')
        volunteer2 = schedule.find_volunteer(volunteer2_id)
        if volunteer2 is None:
            print('Error: Volunteer does not exist')
            continue
        date = input('Enter the date of the shift (YYYY-MM-DD): ')
        time = input('Enter the time of the shift (HH:MM): ')
        schedule.request_swap_shift(volunteer1, volunteer2, date, time)

    elif choice == '3':
        volunteer_id = input('Enter your ID: ')
        volunteer = schedule.find_volunteer(volunteer_id)
        if volunteer is None:
            print('Error: Volunteer does not exist')
            continue
        date = input('Enter the date of the shift (YYYY-MM-DD): ')
        time = input('Enter the time of the shift (HH:MM): ')
        schedule.request_change_shift(volunteer, date, time)

    elif choice == '4':
        volunteer_id = input('Enter your ID: ')
        volunteer = schedule.find_volunteer(volunteer_id)
        if volunteer is None:
            print('Error: Volunteer does not exist')
            continue
        date = input('Enter the date of the shift (YYYY-MM-DD): ')
        time = input('Enter the time of the shift (HH:MM): ')
        schedule.request_leave(volunteer, date, time)

    elif choice == '5':
        schedule.save_shifts()

    elif choice == '6':
        break

    else:
        print('Error: Invalid choice')

使用方法:

  1. 创建 volunteers.csvshifts.csv 文件,分别存储志愿者信息和值班信息。
  2. 运行 Python 代码,选择相应功能进行操作。

注意: 代码中省略了管理员审核部分,您需要根据实际需求添加管理员身份验证和审核流程。

代码说明:

  • 代码使用了面向对象的编程方式,定义了 VolunteerShiftLibrarySchedule 类来表示志愿者、班次和值班表。
  • 代码使用了 CSV 文件来存储和读取数据,方便管理和维护。
  • 代码提供了清晰的接口和注释,便于理解和修改。

扩展功能:

  • 添加管理员用户管理功能。
  • 添加邮件或短信通知功能,提醒志愿者值班或审批结果。
  • 使用数据库来存储数据,提高系统性能和安全性。

希望本代码示例能帮助您快速构建图书馆志愿者值班管理系统。您可以在此基础上进一步完善功能,满足您的实际需求。


原文地址: https://www.cveoy.top/t/topic/npvv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录