• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

go实现员工管理系统

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.本系统分为三层分别为视图层,业务层,数据层代码如下

入口文件

 

 

package main

import (
    "fmt"
    "model"
    "service"
)

type customerView struct {
    key string
    loop bool
    customerservice  * service.CustomerService
}
//展示列表
func (cv * customerView) showList(){
    fmt.Println("--------------客户列表--------------");
    fmt.Println("编号\t姓名\t性别\t年龄\t电话\t邮箱");
    customersList:=cv.customerservice.List();
    for i:=0;i <len(customersList);i++ {
        info:=customersList[i].GetInfo();
        fmt.Println(info);
    }
    fmt.Println("--------------客户列表完成--------------");
}
//添加客户
func (cv * customerView) Add(){
    fmt.Println("--------------添加客户--------------");
    name:="";
    fmt.Println("请输入名字:");
    fmt.Scanln(&name);
    gener:="";
    fmt.Println("请输入性别:");
    fmt.Scanln(&gener);
    age:=0;
    fmt.Println("请输入年龄:");
    fmt.Scanln(&age);
    phone:="";
    fmt.Println("请输入电话:");
    fmt.Scanln(&phone);
    email:="";
    fmt.Println("请输入邮箱:");
    fmt.Scanln(&email);
    customer:=model.AddNewMember(name,gener,age,phone,email);
    bol:=cv.customerservice.AddData(customer);
    if bol {
        fmt.Println("--------------添加完成--------------");
    }
}
//删除客户
func (cv * customerView ) delUser(){
    fmt.Println("请输入要删除的员工ID:");
    id:=0;
    fmt.Scanln(&id);
    bol:=cv.customerservice.DelUser(id);
    if bol {
        fmt.Println("删除成功");
    }
}
//退出系统
func (cv * customerView) exitUser(){
    if  !cv.loop {
        fmt.Println("你退出了客户管理系统");
    }
}
//修改用户
func (cv * customerView ) updateUser(){
    fmt.Println("请输入修改用户ID:1");
    id:=0;
    UserSlice:=cv.customerservice.GetUserInfo(id);
    fmt.Scanf("姓名:%s",&UserSlice.Name);
    fmt.Println(UserSlice.Name);
}
//展示视图
func (cv * customerView) showView(){
    for {
        fmt.Println("--------------客户信息管理软件---------------");
        fmt.Println("              1 添加用户");
        fmt.Println("              2 修改用户");
        fmt.Println("              3 删除用户");
        fmt.Println("              4 用户列表");
        fmt.Println("              5 退出");
        fmt.Println("请选择(1-5):");
        fmt.Scanln(&cv.key);
        switch cv.key {
        case "1" :
            cv.Add();
        case "2":
            cv.updateUser();
        case "3":
            cv.delUser();
        case "4":
            cv.showList();
        case "5":
            cv.loop=false;
            cv.exitUser();
        default:
            fmt.Println("你输入的有误,请重新输入...");
        }
        if !cv.loop {
            break;
        }
    }
}
func main(){
    cv:=customerView{
        key: "",
        loop: true,
    };
    cv.customerservice = service.NewCustomerService();
    cv.showView();
}

 2.业务逻辑层

 

 

package service

import (
    "model"
)
type CustomerService struct {
    //声明一个切片用户保存用户
    customers []model.Customer
    //作为新客户id
    customer int
}
//初始化
func NewCustomerService() * CustomerService {
    CustomerService:=&CustomerService{};
    CustomerService.customer=1;
    customer:=model.NewMember(1,"lisi","女",20,"13001176883","[email protected]")
    CustomerService.customers=append(CustomerService.customers,customer);
    return CustomerService;
}
//返回切片类型
func ( customers CustomerService) List() []model.Customer {
    return customers.customers;
}
//添加数据
func (customers * CustomerService) AddData( customer model.Customer) bool  {
    customer.Id = len(customers.List())+1;
    customers.customers=append(customers.customers,customer);
    return true;
}
//删除一个用户
func (customers * CustomerService ) DelUser(index int) bool {
    index = index-1;
    customers.customers=append(customers.customers[:index],customers.customers[index+1:]...);
    return true;
}

func (customers * CustomerService ) GetUserInfo(id int) model.Customer {
    return customers.customers[id];
}

3.数据层

 

 

package model
import "fmt"
type Customer struct {
    Id int
    Name string
    Gender string
    Age int
    Phone string
    Email string
}
func NewMember (id int,name string,gender string,age int,phone string,email string)  Customer {
    return Customer{
        Id:id,
        Name: name,
        Gender: gender,
        Age: age,
        Phone: phone,
        Email: email,
    }
}
//添加新用户
func AddNewMember (name string,gender string,age int,phone string,email string) Customer {
    return Customer{
        Name: name,
        Gender: gender,
        Age: age,
        Phone: phone,
        Email: email,
    }
}
//获取用户信息
func (customer * Customer) GetInfo() string {
    info:=fmt.Sprintf("%v\t%v\t%v\t%v\t%v\t%v",customer.Id,customer.Name,customer.Gender,customer.Age,customer.Phone,customer.Email);
    return info;
}

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Go的异常处理defer,panic,recover发布时间:2022-07-10
下一篇:
golanggoget速度慢解决方法发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap