78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package models
|
|
|
|
type Employee struct {
|
|
Model
|
|
Username string `json:"username"`
|
|
Password string `json:"password"`
|
|
Department string `json:"department"`
|
|
Position string `json:"position"`
|
|
State int `json:"state"`
|
|
}
|
|
|
|
func CheckEmployee(username, password string) bool {
|
|
var employee Employee
|
|
db.Select("id").Where(Employee{Username: username, Password: password}).First(&employee)
|
|
|
|
if employee.ID > 0 {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func ExistEmployeeByID(id int) bool {
|
|
var employee Employee
|
|
db.Select("id").Where("id = ?", id).First(&employee)
|
|
|
|
if employee.ID > 0 {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func ExistEmployeeByUsername(username string) bool {
|
|
var employee Employee
|
|
db.Select("username").Where("username = ?", username).First(&employee)
|
|
if employee.ID > 0 {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func GetEmployeeTotal(maps interface{}) (count int) {
|
|
db.Model(&Employee{}).Where(maps).Count(&count)
|
|
|
|
return
|
|
}
|
|
|
|
func GetEmployees(pageNum int, pageSize int, maps interface{}) (employees []Employee) {
|
|
db.Where(maps).Offset(pageNum).Limit(pageSize).Find(&employees)
|
|
|
|
return
|
|
}
|
|
|
|
func GetEmployee(id int) (employee Employee) {
|
|
db.Where("id = ?", id).First(&employee)
|
|
return
|
|
}
|
|
|
|
func EditEmployee(id int, data interface{}) bool {
|
|
db.Model(&Employee{}).Where("id = ?", id).Updates(data)
|
|
return true
|
|
}
|
|
|
|
func AddArticle(data map[string]interface{}) bool {
|
|
db.Create(&Employee{
|
|
Username: data["username"].(string),
|
|
Password: data["password"].(string),
|
|
Department: data["department"].(string),
|
|
Position: data["position"].(string),
|
|
})
|
|
return true
|
|
}
|
|
|
|
func CleaanAllEmployee() bool {
|
|
db.Unscoped().Where("deleted_on != ?", 0).Delete(&Employee{})
|
|
|
|
return true
|
|
} |