作者 Your Name

员工填写绩效的数据模型

package domain
import "time"
//填写评估的类型
type StaffAssessType string
const (
AssessSelf StaffAssessType = "self" //自评
AssessSuper StaffAssessType = "super" //上级评估
AssessOverall StaffAssessType = "overall" //360评估
)
//填写评估的状态
type StaffAssessStatus string
const (
StaffAssessUnstart StaffAssessStatus = "unstart" //未开始
StaffAssessUncompleted StaffAssessStatus = "uncompleted" //未完成
StaffAssessCompleted StaffAssessStatus = "completed" //已完成
)
// 记录用户需要的评估项
type StaffAssess struct {
Id int `json:"id"` //id
CompanyId int `json:"companyId"` //公司id
EvaluationProjectId int `json:"evaluationProjectId"` //对应的项目id
CycleId int64 `json:"cycleId"` //对应的周期id
TargetUser StaffDesc `json:"targetUser"` //被评估的目标用户
TargetDepartment []StaffDepartment `json:"targetDepartment"` //被评估的目标用户所在的部门
Executor StaffDesc `json:"executor"` //填写评估的用户
Types StaffAssessType `json:"types"` //填写评估对应的类型
Status StaffAssessStatus `json:"status"` //评估的填写状态
BeginTime time.Time `json:"beginTime"` //开始时间
EndTime time.Time `json:"endTime"` //截止时间
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
DeletedAt *time.Time `json:"deletedAt"` //数据删除时间
}
type StaffAssessRepository interface {
Save(param *StaffAssess) (*StaffAssess, error)
Remove(id int) error
FindOne(queryOptions map[string]interface{}) (*StaffAssess, error)
Find(queryOptions map[string]interface{}) (int, []*StaffAssess, error)
}
... ...
package domain
import "time"
//填写的评估内容
type StaffAssessContent struct {
Id int //id
StaffAssessId int //用户需要的评估项id
SortBy int //排序
Category string //类别
Title string //问题标题
Remark string //填写的反馈
Rate string //评估填写的值
ReteResult string //评估的结果
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
}
type StaffAssessContentRepository interface {
Save(param *StaffAssessContent) (*StaffAssessContent, error)
Remove(id int) error
FindOne(queryOptions map[string]interface{}) (*StaffAssessContent, error)
Find(queryOptions map[string]interface{}) (int, []*StaffAssessContent, error)
}
... ...
package domain
import "time"
//评估任务重复执行的方式
type AssessTaskRepeatWay string
const (
AssessTaskRepeatDay AssessTaskRepeatWay = "day" //按天重复
AssessTaskRepeatWeek AssessTaskRepeatWay = "week" //按周重复
AssessTaskRepeatMonth AssessTaskRepeatWay = "month" //按月
AssessTaskRepeatMonthDouble AssessTaskRepeatWay = "month_double" //按双月
AssessTaskRepeatQuarter AssessTaskRepeatWay = "quarter" //按季度
AssessTaskRepeatYearHalf AssessTaskRepeatWay = "year_half" //按半年
AssessTaskRepeatYear AssessTaskRepeatWay = "year" //按年
)
// 执行评估的任务列表
type StaffAssessTask struct {
Id int `json:"id"`
CompanyId int `json:"companyId"` //公司id
EvaluationProjectId int `json:"evaluationProjectId"` //项目id
CycleId int64 `json:"cycleId"` //对应的周期id
Types StaffAssessType `json:"types"` //填写评估对应的类型
BeginTime time.Time `json:"beginTime"` //开始时间
EndTime time.Time `json:"endTime"` //截止时间
RepeatWay AssessTaskRepeatWay `json:"repeatWay"` //重复执行的方式
NextActiveTime int64 `json:"nextActveTime"` //下一次执行的任务的时间
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
DeletedAt time.Time `json:"deletedAt"` //数据删除时间
}
type StaffAssessTaskRepository interface {
Save(param *StaffAssessTask) (*StaffAssessTask, error)
Remove(id int) error
FindOne(queryOptions map[string]interface{}) (*StaffAssessTask, error)
Find(queryOptions map[string]interface{}) (int, []*StaffAssessTask, error)
}
//计算下一次执行任务的时间
func (task *StaffAssessTask) NewNextActveTime() {
if task.NextActiveTime == 0 {
task.NextActiveTime = task.BeginTime.Unix()
}
//Todo 根据重复执行的方式,计算下一次执行的时间点
}
... ...
package domain
//员工基本信息描述
type StaffDesc struct {
UserId int `json:"userId"` //用户id
Account string `json:"account"` //用户的账号
UserName string `json:"userName"` //用户的名称
}
//员工的部门
type StaffDepartment struct {
DepartmentId int `json:"departmentId"` //部门id
DepartmentName string `json:"departmentName"` //部门名称
}
... ...
package domain
import "time"
type StaffEvaluationType string
const (
EvaluationSelf StaffEvaluationType = "self" //自评
EvaluationSuper StaffEvaluationType = "super" //上级评估
EvaluationOverall StaffEvaluationType = "overall" //360评估
)
// 需要填写评估的用户
type StaffEvaluation struct {
Id int //id
EvaluationProjectId int //对应的项目id
CycleId int64 //对应的周期id
TargetUserId int //被评估的目标用户
ExecutorId int //填写评估的用户
Types StaffEvaluationType //填写评估对应的类型
BeginTime time.Time //开始时间
EndTime time.Time //截止时间
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
}
//用户填写的评估
type StaffEvaluationContent struct {
}
package models
import (
"time"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// 记录用户需要的评估项
type StaffAssess struct {
tableName struct{} `pg:"staff_assess" comment:"记录用户需要的评估项"`
Id int `pg:",pk"` //id
CompanyId int `comment:"公司id"` //公司id
EvaluationProjectId int `comment:"对应的项目id"` //对应的项目id
CycleId int64 `comment:"对应的周期id"` //对应的周期id
TargetUser domain.StaffDesc `comment:"被评估的目标用户"` //被评估的目标用户
TargetDepartment []domain.StaffDepartment `comment:"被评估的用户所在的部门"` //被评估的用户所在的部门
Executor domain.StaffDesc `comment:"填写评估的用户"` //填写评估的用户
Types string `comment:"填写评估对应的类型"` //填写评估对应的类型
Status string `comment:"评估的填写状态"` //评估的填写状态
BeginTime time.Time `comment:"开始时间"` //开始时间
EndTime time.Time `comment:"截止时间"` //截止时间
CreatedAt time.Time `comment:"数据创建时间"` //数据创建时间
UpdatedAt time.Time `comment:"数据更新时间"` //数据更新时间
DeletedAt *time.Time `comment:"数据删除时间"` //数据删除时间
}
... ...
package models
import "time"
//填写的评估内容
type StaffAssessContent struct {
tableName struct{} `pg:"staff_assess_content" comment:"填写的评估项"`
Id int `pg:",pk"` //id
StaffAssessId int //用户需要的评估项id
SortBy int //排序
Category string //类别
Title string //问题标题
Remark string //填写的反馈
Rate string //评估填写的值
ReteResult string //评估的结果
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
}
type StaffAssessContentRepository interface {
Save(param *StaffAssessContent) (*StaffAssessContent, error)
Remove(id int) error
FindOne(queryOptions map[string]interface{}) (*StaffAssessContent, error)
Find(queryOptions map[string]interface{}) (int, []*StaffAssessContent, error)
}
... ...
package models
import "time"
// 执行评估的任务列表
type StaffAssessTask struct {
tableName struct{} `pg:"staff_assess_task" comment:"执行评估的任务列表"`
Id int `pg:",pk"`
CompanyId int `` //公司id
EvaluationProjectId int //项目id
CycleId int64 //对应的周期id
Types string //填写评估对应的类型
BeginTime time.Time //开始时间
EndTime time.Time //截止时间
RepeatWay string //重复执行的方式
NextActiveTime int64 //下一次执行的任务的时间,时间戳(秒)
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
DeletedAt time.Time //数据删除时间
}
... ...
package repository
import (
"errors"
"fmt"
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
)
type StaffAssessContentRepository struct {
transactionContext *pgTransaction.TransactionContext
}
var _ domain.StaffAssessContentRepository = (*StaffAssessContentRepository)(nil)
func NewStaffEvaluationRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessContentRepository {
return &StaffAssessContentRepository{transactionContext: transactionContext}
}
func (repo *StaffAssessContentRepository) TransformToDomain(d *models.StaffAssessContent) *domain.StaffAssessContent {
return &domain.StaffAssessContent{}
}
func (repo *StaffAssessContentRepository) Save(d *domain.StaffAssessContent) (*domain.StaffAssessContent, error) {
saveModel := models.StaffAssess{
Id: d.Id,
}
tx := repo.transactionContext.PgTx
var err error
if saveModel.Id == 0 {
_, err = tx.Model(&saveModel).Insert()
if err != nil {
return nil, err
}
} else {
_, err = tx.Model(&saveModel).WherePK().Update()
if err != nil {
return nil, err
}
}
d.Id = saveModel.Id
return d, nil
}
func (repo *StaffAssessContentRepository) Remove(id int) error {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
_, err := tx.Model(&models.StaffAssessContent{}).
Where("id=?", id).
Set("deleted_at=?", nowTime).
Update()
return err
}
func (repo *StaffAssessContentRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssessContent, error) {
tx := repo.transactionContext.PgTx
m := new(models.StaffAssessContent)
query := tx.Model(m)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
u := repo.TransformToDomain(m)
return u, nil
}
func (repo *StaffAssessContentRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssessContent, error) {
tx := repo.transactionContext.PgTx
var m []*models.StaffAssessContent
query := tx.Model(&m).
Where("deleted_at isnull").Limit(20)
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var arrays []*domain.StaffAssessContent
for _, v := range m {
d := repo.TransformToDomain(v)
arrays = append(arrays, d)
}
return count, arrays, nil
}
... ...
package repository
import (
"errors"
"fmt"
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
)
type StaffAssessRepository struct {
transactionContext *pgTransaction.TransactionContext
}
var _ domain.StaffAssessRepository = (*StaffAssessRepository)(nil)
func NewStaffAssessRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessRepository {
return &StaffAssessRepository{transactionContext: transactionContext}
}
func (repo *StaffAssessRepository) TransformToDomain(d *models.StaffAssess) *domain.StaffAssess {
return &domain.StaffAssess{
Id: d.Id,
CompanyId: d.CompanyId,
EvaluationProjectId: d.EvaluationProjectId,
CycleId: d.CycleId,
TargetUser: d.TargetUser,
TargetDepartment: d.TargetDepartment,
Executor: d.Executor,
Types: domain.StaffAssessType(d.Types),
Status: domain.StaffAssessStatus(d.Status),
BeginTime: d.BeginTime,
EndTime: d.EndTime,
CreatedAt: d.EndTime,
UpdatedAt: d.CreatedAt,
DeletedAt: d.DeletedAt,
}
}
func (repo *StaffAssessRepository) Save(d *domain.StaffAssess) (*domain.StaffAssess, error) {
saveModel := models.StaffAssess{
Id: d.Id,
CompanyId: d.CompanyId,
EvaluationProjectId: d.EvaluationProjectId,
CycleId: d.CycleId,
TargetUser: d.TargetUser,
TargetDepartment: d.TargetDepartment,
Executor: d.Executor,
Types: string(d.Types),
Status: string(d.Status),
BeginTime: d.BeginTime,
EndTime: d.EndTime,
CreatedAt: d.EndTime,
UpdatedAt: d.CreatedAt,
DeletedAt: d.DeletedAt,
}
tx := repo.transactionContext.PgTx
var err error
if saveModel.Id == 0 {
_, err = tx.Model(&saveModel).Insert()
if err != nil {
return nil, err
}
} else {
_, err = tx.Model(&saveModel).WherePK().Update()
if err != nil {
return nil, err
}
}
d.Id = saveModel.Id
return d, nil
}
func (repo *StaffAssessRepository) Remove(id int) error {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
_, err := tx.Model(&models.StaffAssess{}).
Where("id=?", id).
Set("deleted_at=?", nowTime).
Update()
return err
}
func (repo *StaffAssessRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssess, error) {
tx := repo.transactionContext.PgTx
m := new(models.StaffAssess)
query := tx.Model(m)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
u := repo.TransformToDomain(m)
return u, nil
}
func (repo *StaffAssessRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssess, error) {
tx := repo.transactionContext.PgTx
var m []*models.StaffAssess
query := tx.Model(&m).
Where("deleted_at isnull").Limit(20)
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var arrays []*domain.StaffAssess
for _, v := range m {
d := repo.TransformToDomain(v)
arrays = append(arrays, d)
}
return count, arrays, nil
}
... ...
package repository
import (
"errors"
"fmt"
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
)
type StaffAssessTaskRepository struct {
transactionContext *pgTransaction.TransactionContext
}
var _ domain.StaffAssessTaskRepository = (*StaffAssessTaskRepository)(nil)
func NewStaffAssessTaskRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessTaskRepository {
return &StaffAssessTaskRepository{transactionContext: transactionContext}
}
func (repo *StaffAssessTaskRepository) TransformToDomain(d *models.StaffAssessTask) *domain.StaffAssessTask {
return &domain.StaffAssessTask{
Id: d.Id,
CompanyId: d.CompanyId,
EvaluationProjectId: d.EvaluationProjectId,
CycleId: d.CycleId,
Types: domain.StaffAssessType(d.Types),
BeginTime: d.BeginTime,
EndTime: d.EndTime,
RepeatWay: domain.AssessTaskRepeatWay(d.RepeatWay),
NextActiveTime: d.NextActiveTime,
CreatedAt: d.EndTime,
UpdatedAt: d.CreatedAt,
DeletedAt: d.DeletedAt,
}
}
func (repo *StaffAssessTaskRepository) Save(d *domain.StaffAssessTask) (*domain.StaffAssessTask, error) {
saveModel := models.StaffAssessTask{
Id: d.Id,
CompanyId: d.CompanyId,
EvaluationProjectId: d.EvaluationProjectId,
CycleId: d.CycleId,
Types: string(d.Types),
BeginTime: d.BeginTime,
EndTime: d.EndTime,
RepeatWay: string(d.RepeatWay),
NextActiveTime: d.NextActiveTime,
CreatedAt: d.EndTime,
UpdatedAt: d.CreatedAt,
DeletedAt: d.DeletedAt,
}
tx := repo.transactionContext.PgTx
var err error
if saveModel.Id == 0 {
_, err = tx.Model(&saveModel).Insert()
if err != nil {
return nil, err
}
} else {
_, err = tx.Model(&saveModel).WherePK().Update()
if err != nil {
return nil, err
}
}
d.Id = saveModel.Id
return d, nil
}
func (repo *StaffAssessTaskRepository) Remove(id int) error {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
_, err := tx.Model(&models.StaffAssessTask{}).
Where("id=?", id).
Set("deleted_at=?", nowTime).
Update()
return err
}
func (repo *StaffAssessTaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssessTask, error) {
tx := repo.transactionContext.PgTx
m := new(models.StaffAssessTask)
query := tx.Model(m)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
u := repo.TransformToDomain(m)
return u, nil
}
func (repo *StaffAssessTaskRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssessTask, error) {
tx := repo.transactionContext.PgTx
var m []*models.StaffAssessTask
query := tx.Model(&m).
Where("deleted_at isnull").Limit(20)
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var arrays []*domain.StaffAssessTask
for _, v := range m {
d := repo.TransformToDomain(v)
arrays = append(arrays, d)
}
return count, arrays, nil
}
... ...