diff --git a/internal/entities/company.go b/internal/entities/company.go index 38d5d40..4709170 100644 --- a/internal/entities/company.go +++ b/internal/entities/company.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"` } diff --git a/internal/entities/company_department.go b/internal/entities/company_department.go index 406cd41..bcfca31 100644 --- a/internal/entities/company_department.go +++ b/internal/entities/company_department.go @@ -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("缺少所属公司编号") } diff --git a/internal/entities/company_staff.go b/internal/entities/company_employee.go similarity index 92% rename from internal/entities/company_staff.go rename to internal/entities/company_employee.go index 3f4e9c1..dc34cc1 100644 --- a/internal/entities/company_staff.go +++ b/internal/entities/company_employee.go @@ -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"` } diff --git a/internal/entities/feature_category.go b/internal/entities/feature_category.go index 1f17a7b..ac3c341 100644 --- a/internal/entities/feature_category.go +++ b/internal/entities/feature_category.go @@ -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:栏目分类描述"` diff --git a/internal/entities/feature_content_chapter.go b/internal/entities/feature_content_chapter.go index a239c02..4bc6998 100644 --- a/internal/entities/feature_content_chapter.go +++ b/internal/entities/feature_content_chapter.go @@ -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:章回标题"` diff --git a/internal/entities/resource_category.go b/internal/entities/resource_category.go index a6680dc..565f306 100644 --- a/internal/entities/resource_category.go +++ b/internal/entities/resource_category.go @@ -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:状态"` diff --git a/internal/entities/system_menu.go b/internal/entities/system_menu.go index e4ed1b4..732fb81 100644 --- a/internal/entities/system_menu.go +++ b/internal/entities/system_menu.go @@ -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:排序"` diff --git a/internal/entities/system_permission.go b/internal/entities/system_permission.go index d429378..1e92019 100644 --- a/internal/entities/system_permission.go +++ b/internal/entities/system_permission.go @@ -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:权限标识"` diff --git a/internal/init.go b/internal/init.go index b50072c..1f824a9 100644 --- a/internal/init.go +++ b/internal/init.go @@ -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{}, diff --git a/internal/repositories/company_employee.go b/internal/repositories/company_employee.go new file mode 100644 index 0000000..f62fecf --- /dev/null +++ b/internal/repositories/company_employee.go @@ -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"), + } +} diff --git a/internal/repositories/company_staff.go b/internal/repositories/company_staff.go deleted file mode 100755 index 3ce524e..0000000 --- a/internal/repositories/company_staff.go +++ /dev/null @@ -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"), - } -} diff --git a/internal/services/company/controller/company_employee_controller.go b/internal/services/company/controller/company_employee_controller.go new file mode 100644 index 0000000..37bcd3d --- /dev/null +++ b/internal/services/company/controller/company_employee_controller.go @@ -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) +} diff --git a/internal/services/company/controller/company_staff_controller.go b/internal/services/company/controller/company_staff_controller.go deleted file mode 100644 index a5b6c55..0000000 --- a/internal/services/company/controller/company_staff_controller.go +++ /dev/null @@ -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) -} diff --git a/internal/services/company/request/company_staff_upsert_request.go b/internal/services/company/request/company_employee_upsert_request.go similarity index 84% rename from internal/services/company/request/company_staff_upsert_request.go rename to internal/services/company/request/company_employee_upsert_request.go index 42f4fb0..015f2fa 100644 --- a/internal/services/company/request/company_staff_upsert_request.go +++ b/internal/services/company/request/company_employee_upsert_request.go @@ -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, diff --git a/internal/services/company/service.go b/internal/services/company/service.go index c3fa350..72f3dfd 100644 --- a/internal/services/company/service.go +++ b/internal/services/company/service.go @@ -24,7 +24,7 @@ func (s *Service) Routes() []runtime.Routable { return []runtime.Routable{ &controller.CompanyController{}, &controller.CompanyDepartmentController{}, - &controller.CompanyStaffController{}, + &controller.CompanyEmployeeController{}, } } diff --git a/scripts/gen/gen.go b/scripts/gen/gen.go index ead4ae5..030875a 100644 --- a/scripts/gen/gen.go +++ b/scripts/gen/gen.go @@ -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": "栏目",