refactor: 修改员工单词 staff 为 employee

main
熊二 1 year ago
parent faded4e634
commit e18ec70269
  1. 4
      internal/entities/company.go
  2. 10
      internal/entities/company_department.go
  3. 6
      internal/entities/company_employee.go
  4. 2
      internal/entities/feature_category.go
  5. 2
      internal/entities/feature_content_chapter.go
  6. 2
      internal/entities/resource_category.go
  7. 2
      internal/entities/system_menu.go
  8. 2
      internal/entities/system_permission.go
  9. 6
      internal/init.go
  10. 18
      internal/repositories/company_employee.go
  11. 18
      internal/repositories/company_staff.go
  12. 16
      internal/services/company/controller/company_employee_controller.go
  13. 16
      internal/services/company/controller/company_staff_controller.go
  14. 10
      internal/services/company/request/company_employee_upsert_request.go
  15. 2
      internal/services/company/service.go
  16. 2
      scripts/gen/gen.go

@ -18,7 +18,7 @@ type Company struct {
UpdatedAt time.Time `json:"update_time" xml:"update_time" gorm:"<-:false;comment:更新时间"`
DeletedAt gorm.DeletedAt `json:"-" xml:"-" gorm:"comment:删除时间"`
Principal *CompanyStaff `json:"principal" xml:"principal"`
Staffs []*CompanyStaff `json:"staffs" xml:"staffs"`
Principal *CompanyEmployee `json:"principal" xml:"principal"`
Employees []*CompanyEmployee `json:"employees" xml:"employees"`
Departments []*CompanyDepartment `json:"departments" xml:"departments"`
}

@ -11,7 +11,7 @@ import (
// CompanyDepartment 公司部门表
type CompanyDepartment struct {
ID uint `json:"id" xml:"id" gorm:"primaryKey;not null;comment:部门编号"`
PID *uint `json:"pid" xml:"pid" gorm:"comment:上级部门编号"`
PID *uint `json:"pid" xml:"pid" gorm:"column:pid;comment:上级部门编号"`
CompanyID uint `json:"company_id" xml:"company_id" gorm:"comment:所属公司编号"`
PrincipalID *uint `json:"principal_id" xml:"principal_id" gorm:"comment:负责人编号(员工)"`
Name string `json:"name" xml:"name" gorm:"size:50;not null;comment:部门名称"`
@ -21,12 +21,12 @@ type CompanyDepartment struct {
UpdatedAt time.Time `json:"update_time" xml:"update_time" gorm:"<-:false;comment:更新时间"`
DeletedAt gorm.DeletedAt `json:"-" xml:"-" gorm:"comment:删除时间"`
Staffs []*CompanyStaff `json:"staffs" xml:"staffs" gorm:"many2many:company_staff_to_department_relations"`
Courses []*FeatureContent `json:"courses" xml:"courses" gorm:"many2many:company_course_to_department_relations"`
Children []*CompanyDepartment `json:"children" xml:"children" gorm:"foreignKey:PID"`
Employees []*CompanyEmployee `json:"employees" xml:"employees" gorm:"many2many:company_employee_to_department_relations"`
Courses []*FeatureContent `json:"courses" xml:"courses" gorm:"many2many:company_course_to_department_relations"`
Children []*CompanyDepartment `json:"children" xml:"children" gorm:"foreignKey:PID"`
}
func (c *CompanyDepartment) BeforeCreate(tx *gorm.DB) error {
func (c *CompanyDepartment) BeforeCreate(_ *gorm.DB) error {
if c.CompanyID == 0 {
return errors.New("缺少所属公司编号")
}

@ -6,8 +6,8 @@ import (
"time"
)
// CompanyStaff 公司员工表
type CompanyStaff struct {
// CompanyEmployee 公司员工表
type CompanyEmployee struct {
ID uint `json:"id" xml:"id" gorm:"primaryKey;not null;comment:员工编号"`
CompanyID uint `json:"company_id" xml:"company_id" gorm:"comment:所属公司编号"`
Name string `json:"name" xml:"name" gorm:"size:20;not null;comment:员工姓名"`
@ -22,5 +22,5 @@ type CompanyStaff struct {
UpdatedAt time.Time `json:"update_time" xml:"update_time" gorm:"<-:false;comment:更新时间"`
DeletedAt gorm.DeletedAt `json:"-" xml:"-" gorm:"comment:删除时间"`
Departments []*CompanyDepartment `json:"departments" xml:"departments" gorm:"many2many:company_staff_to_department_relations"`
Departments []*CompanyDepartment `json:"departments" xml:"departments" gorm:"many2many:company_employee_to_department_relations"`
}

@ -9,7 +9,7 @@ import (
// FeatureCategory 栏目分类表
type FeatureCategory struct {
ID uint `json:"id" xml:"id" gorm:"primaryKey;not null;comment:栏目分类编号"`
PID *uint `json:"pid" xml:"pid" gorm:"comment:上级分类编号"`
PID *uint `json:"pid" xml:"pid" gorm:"column:pid;comment:上级分类编号"`
FeatureID uint `json:"feature_id" xml:"feature_id" gorm:"index:,unique,composite:idx_title_with_feature;comment:所属栏目编号"`
Title string `json:"title" xml:"title" gorm:"size:25;not null;index:,unique,composite:idx_title_with_feature;comment:栏目分类标题"`
Description string `json:"description" xml:"description" gorm:"size:250;comment:栏目分类描述"`

@ -9,7 +9,7 @@ import (
// FeatureContentChapter 栏目内容章回表
type FeatureContentChapter struct {
ID uint `json:"id" xml:"id" gorm:"primaryKey;not null;comment:章回编号"`
PID *uint `json:"pid" xml:"pid" gorm:"comment:上级章回编号"`
PID *uint `json:"pid" xml:"pid" gorm:"column:pid;comment:上级章回编号"`
FeatureID uint `json:"feature_id" xml:"feature_id" gorm:"comment:所属栏目编号"`
ContentID uint `json:"content_id" xml:"content_id" gorm:"comment:所属内容编号"`
Title string `json:"title" xml:"title" gorm:"size:100;not null;comment:章回标题"`

@ -9,7 +9,7 @@ import (
// ResourceCategory 资源分类表
type ResourceCategory struct {
ID uint `json:"id" xml:"id" gorm:"primaryKey;not null;comment:资源分类编号"`
PID *uint `json:"pid" xml:"pid" gorm:"comment:上级分类编号"`
PID *uint `json:"pid" xml:"pid" gorm:"column:pid;comment:上级分类编号"`
Title string `json:"title" xml:"title" gorm:"size:25;not null;uniqueIndex;comment:资源分类名称"`
Sort int32 `json:"sort" xml:"sort" gorm:"default:0;comment:排序"`
Status bool `json:"status" xml:"status" gorm:"comment:状态"`

@ -9,7 +9,7 @@ import (
// SystemMenu 系统菜单表
type SystemMenu struct {
ID uint `json:"id" xml:"id" gorm:"primaryKey;not null;comment:菜单编号"`
PID *uint `json:"pid" xml:"pid" gorm:"comment:上级菜单编号"`
PID *uint `json:"pid" xml:"pid" gorm:"column:pid;comment:上级菜单编号"`
Title string `json:"title" xml:"title" gorm:"size:25;not null;comment:菜单标题"`
Icon string `json:"icon" xml:"icon" gorm:"comment:菜单图标"`
Sort int32 `json:"sort" xml:"sort" gorm:"default:0;comment:排序"`

@ -7,7 +7,7 @@ import (
type SystemPermission struct {
ID uint `json:"id" xml:"id" gorm:"primaryKey;not null;comment:权限编号"`
PID *uint `json:"pid" xml:"pid" gorm:"comment:上级权限编号"`
PID *uint `json:"pid" xml:"pid" gorm:"column:pid;comment:上级权限编号"`
Name string `json:"name" xml:"name" gorm:"size:25;not null;comment:权限名称"`
Type string `json:"type" xml:"type" gorm:"size:25;not null;index;comment:权限类型"`
Identifier string `json:"identifier" xml:"identifier" gorm:"size:25;not null;uniqueIndex;comment:权限标识"`

@ -32,17 +32,17 @@ func syncEntities() error {
return db.Sync(
&entities.Company{},
&entities.CompanyDepartment{},
&entities.CompanyStaff{},
&entities.Config{},
&entities.CompanyEmployee{},
&entities.ConfigGroup{},
&entities.Config{},
&entities.Feature{},
&entities.FeatureCategory{},
&entities.FeatureConfig{},
&entities.FeatureContent{},
&entities.FeatureContentChapter{},
&entities.FeatureContentDetail{},
&entities.Resource{},
&entities.ResourceCategory{},
&entities.Resource{},
&entities.SystemLog{},
&entities.SystemMenu{},
&entities.SystemPermission{},

@ -0,0 +1,18 @@
package repositories
import (
"gorm.io/gorm"
"sorbet/internal/entities"
"sorbet/pkg/db"
)
type CompanyEmployeeRepository struct {
*db.Repository[entities.CompanyEmployee]
}
// NewCompanyEmployeeRepository 创建公司员工仓库
func NewCompanyEmployeeRepository(orm *gorm.DB) *CompanyEmployeeRepository {
return &CompanyEmployeeRepository{
db.NewRepositoryWith[entities.CompanyEmployee](orm, "id"),
}
}

@ -1,18 +0,0 @@
package repositories
import (
"gorm.io/gorm"
"sorbet/internal/entities"
"sorbet/pkg/db"
)
type CompanyStaffRepository struct {
*db.Repository[entities.CompanyStaff]
}
// NewCompanyStaffRepository 创建公司员工仓库
func NewCompanyStaffRepository(orm *gorm.DB) *CompanyStaffRepository {
return &CompanyStaffRepository{
db.NewRepositoryWith[entities.CompanyStaff](orm, "id"),
}
}

@ -0,0 +1,16 @@
package controller
import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/company/request"
"sorbet/pkg/crud"
)
type CompanyEmployeeController struct {
crud.Controller[entities.CompanyEmployee, request.CompanyEmployeeUpsertRequest]
}
func (c *CompanyEmployeeController) InitRoutes(r *echo.Group) {
c.RegisterRoutes("/company/employees", r)
}

@ -1,16 +0,0 @@
package controller
import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/company/request"
"sorbet/pkg/crud"
)
type CompanyStaffController struct {
crud.Controller[entities.CompanyStaff, request.CompanyStaffUpsertRequest]
}
func (c *CompanyStaffController) InitRoutes(r *echo.Group) {
c.RegisterRoutes("/company/staffs", r)
}

@ -4,7 +4,7 @@ import (
"sorbet/internal/entities"
)
type CompanyStaffUpsertRequest struct {
type CompanyEmployeeUpsertRequest struct {
ID uint `json:"id" xml:"id" form:"id" path:"id"`
CompanyID uint `json:"company_id" xml:"company_id" form:"company_id"`
Name string `json:"name" xml:"name" form:"name"`
@ -16,11 +16,11 @@ type CompanyStaffUpsertRequest struct {
IsAdmin bool `json:"is_admin" xml:"is_admin" form:"is_admin"`
}
func (c *CompanyStaffUpsertRequest) GetID() any {
func (c *CompanyEmployeeUpsertRequest) GetID() any {
return c.ID
}
func (c *CompanyStaffUpsertRequest) ToMap() map[string]any {
func (c *CompanyEmployeeUpsertRequest) ToMap() map[string]any {
return map[string]any{
"id": c.ID,
"company_id": c.CompanyID,
@ -34,8 +34,8 @@ func (c *CompanyStaffUpsertRequest) ToMap() map[string]any {
}
}
func (c *CompanyStaffUpsertRequest) ToEntity() any {
return &entities.CompanyStaff{
func (c *CompanyEmployeeUpsertRequest) ToEntity() any {
return &entities.CompanyEmployee{
ID: c.ID,
CompanyID: c.CompanyID,
Name: c.Name,

@ -24,7 +24,7 @@ func (s *Service) Routes() []runtime.Routable {
return []runtime.Routable{
&controller.CompanyController{},
&controller.CompanyDepartmentController{},
&controller.CompanyStaffController{},
&controller.CompanyEmployeeController{},
}
}

@ -31,7 +31,7 @@ func New{{pascal}}Repository(orm *gorm.DB) *{{pascal}}Repository {
var labels = map[string]string{
"Company": "公司",
"CompanyDepartment": "公司部门",
"CompanyStaff": "公司员工",
"CompanyEmployee": "公司员工",
"Config": "配置",
"ConfigGroup": "配置组",
"Feature": "栏目",

Loading…
Cancel
Save