Merge remote-tracking branch 'origin/master'
正在显示
11 个修改的文件
包含
556 行增加
和
29 行删除
pkg/domain/staff_assess.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +//填写评估的类型 | ||
| 6 | +type StaffAssessType string | ||
| 7 | + | ||
| 8 | +const ( | ||
| 9 | + AssessSelf StaffAssessType = "self" //自评 | ||
| 10 | + AssessSuper StaffAssessType = "super" //上级评估 | ||
| 11 | + AssessInviteSameSuper StaffAssessType = "invite_same_super" //360 邀请评估-相同上级的同事 | ||
| 12 | + AssessInviteDiffSuper StaffAssessType = "invite_diff_super" //360 邀请评估-不同上级的同事 | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +//填写评估的状态 | ||
| 16 | +type StaffAssessStatus string | ||
| 17 | + | ||
| 18 | +const ( | ||
| 19 | + StaffAssessUnstart StaffAssessStatus = "unstart" //未开始 | ||
| 20 | + StaffAssessUncompleted StaffAssessStatus = "uncompleted" //未完成 | ||
| 21 | + StaffAssessCompleted StaffAssessStatus = "completed" //已完成 | ||
| 22 | +) | ||
| 23 | + | ||
| 24 | +// 记录用户需要的评估项 | ||
| 25 | +type StaffAssess struct { | ||
| 26 | + Id int `json:"id"` //id | ||
| 27 | + CompanyId int `json:"companyId"` //公司id | ||
| 28 | + EvaluationProjectId int `json:"evaluationProjectId"` //对应的项目id | ||
| 29 | + CycleId int64 `json:"cycleId"` //对应的周期id | ||
| 30 | + StaffAssessTaskId int `json:"staffAssessTaskId"` //执行评估的任务id | ||
| 31 | + TargetUser StaffDesc `json:"targetUser"` //被评估的目标用户 | ||
| 32 | + TargetDepartment []StaffDepartment `json:"targetDepartment"` //被评估的目标用户所在的部门 | ||
| 33 | + Executor StaffDesc `json:"executor"` //填写评估的用户 | ||
| 34 | + Types StaffAssessType `json:"types"` //填写评估对应的类型 | ||
| 35 | + LinkNodeId int `json:"linkNodeId"` //评估环节对应的id,用于调取评估模板 | ||
| 36 | + Status StaffAssessStatus `json:"status"` //评估的填写状态 | ||
| 37 | + BeginTime time.Time `json:"beginTime"` //开始时间 | ||
| 38 | + EndTime time.Time `json:"endTime"` //截止时间 | ||
| 39 | + CreatedAt time.Time `json:"createdAt"` //数据创建时间 | ||
| 40 | + UpdatedAt time.Time `json:"updatedAt"` //数据更新时间 | ||
| 41 | + DeletedAt *time.Time `json:"deletedAt"` //数据删除时间 | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +type StaffAssessRepository interface { | ||
| 45 | + Save(param *StaffAssess) (*StaffAssess, error) | ||
| 46 | + Remove(id int) error | ||
| 47 | + FindOne(queryOptions map[string]interface{}) (*StaffAssess, error) | ||
| 48 | + Find(queryOptions map[string]interface{}) (int, []*StaffAssess, error) | ||
| 49 | +} |
pkg/domain/staff_assess_content.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +//填写的评估内容 | ||
| 6 | +type StaffAssessContent struct { | ||
| 7 | + Id int `json:"id"` //id | ||
| 8 | + StaffAssessId int `json:"staffAssessId"` //用户需要的评估项id | ||
| 9 | + SortBy int `json:"sortBy"` //排序 | ||
| 10 | + Category string `json:"category"` //类别 | ||
| 11 | + Title string `json:"title"` //问题标题 | ||
| 12 | + Remark string `json:"remark"` //填写的反馈 | ||
| 13 | + Rate string `json:"rate"` //评估填写的值 | ||
| 14 | + ReteResult string `json:"reteResult"` //评估的结果 | ||
| 15 | + CreatedAt time.Time `json:"createdAt"` //数据创建时间 | ||
| 16 | + UpdatedAt time.Time `json:"updatedAt"` //数据更新时间 | ||
| 17 | + //TODO | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +type StaffAssessContentRepository interface { | ||
| 21 | + Save(param *StaffAssessContent) (*StaffAssessContent, error) | ||
| 22 | + Remove(id int) error | ||
| 23 | + FindOne(queryOptions map[string]interface{}) (*StaffAssessContent, error) | ||
| 24 | + Find(queryOptions map[string]interface{}) (int, []*StaffAssessContent, error) | ||
| 25 | +} |
pkg/domain/staff_assess_task.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +//评估任务重复执行的方式 | ||
| 6 | +type AssessTaskRepeatWay string | ||
| 7 | + | ||
| 8 | +const ( | ||
| 9 | + AssessTaskRepeatDay AssessTaskRepeatWay = "day" //按天重复 | ||
| 10 | + AssessTaskRepeatWeek AssessTaskRepeatWay = "week" //按周重复 | ||
| 11 | + AssessTaskRepeatMonth AssessTaskRepeatWay = "month" //按月 | ||
| 12 | + AssessTaskRepeatMonthDouble AssessTaskRepeatWay = "month_double" //按双月 | ||
| 13 | + AssessTaskRepeatQuarter AssessTaskRepeatWay = "quarter" //按季度 | ||
| 14 | + AssessTaskRepeatYearHalf AssessTaskRepeatWay = "year_half" //按半年 | ||
| 15 | + AssessTaskRepeatYear AssessTaskRepeatWay = "year" //按年 | ||
| 16 | +) | ||
| 17 | + | ||
| 18 | +// 执行评估的任务列表 | ||
| 19 | +type StaffAssessTask struct { | ||
| 20 | + Id int `json:"id"` | ||
| 21 | + CompanyId int `json:"companyId"` //公司id | ||
| 22 | + EvaluationProjectId int `json:"evaluationProjectId"` //项目id | ||
| 23 | + EvaluationProjectName string `json:"evaluationProjectName"` //项目名称 | ||
| 24 | + CycleId int64 `json:"cycleId"` //对应的周期id | ||
| 25 | + CycleName string `json:"cycleName"` //对应周期的名称 | ||
| 26 | + BeginTime time.Time `json:"beginTime"` //绩效考核开始时间 | ||
| 27 | + EndTime time.Time `json:"endTime"` //绩效考核截止时间 | ||
| 28 | + CreatedAt time.Time `json:"createdAt"` //数据创建时间 | ||
| 29 | + UpdatedAt time.Time `json:"updatedAt"` //数据更新时间 | ||
| 30 | + DeletedAt time.Time `json:"deletedAt"` //数据删除时间 | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +type StaffAssessTaskRepository interface { | ||
| 34 | + Save(param *StaffAssessTask) (*StaffAssessTask, error) | ||
| 35 | + Remove(id int) error | ||
| 36 | + FindOne(queryOptions map[string]interface{}) (*StaffAssessTask, error) | ||
| 37 | + Find(queryOptions map[string]interface{}) (int, []*StaffAssessTask, error) | ||
| 38 | +} |
pkg/domain/staff_desc.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +//员工基本信息描述 | ||
| 4 | +type StaffDesc struct { | ||
| 5 | + UserId int `json:"userId"` //用户id | ||
| 6 | + Account string `json:"account"` //用户的账号 | ||
| 7 | + UserName string `json:"userName"` //用户的名称 | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +//员工的部门 | ||
| 11 | +type StaffDepartment struct { | ||
| 12 | + DepartmentId int `json:"departmentId"` //部门id | ||
| 13 | + DepartmentName string `json:"departmentName"` //部门名称 | ||
| 14 | +} |
pkg/domain/staff_evaluation.go
已删除
100644 → 0
| 1 | -package domain | ||
| 2 | - | ||
| 3 | -import "time" | ||
| 4 | - | ||
| 5 | -type StaffEvaluationType string | ||
| 6 | - | ||
| 7 | -const ( | ||
| 8 | - EvaluationSelf StaffEvaluationType = "self" //自评 | ||
| 9 | - EvaluationSuper StaffEvaluationType = "super" //上级评估 | ||
| 10 | - EvaluationOverall StaffEvaluationType = "overall" //360评估 | ||
| 11 | -) | ||
| 12 | - | ||
| 13 | -// 需要填写评估的用户 | ||
| 14 | -type StaffEvaluation struct { | ||
| 15 | - Id int //id | ||
| 16 | - EvaluationProjectId int //对应的项目id | ||
| 17 | - CycleId int64 //对应的周期id | ||
| 18 | - TargetUserId int //被评估的目标用户 | ||
| 19 | - ExecutorId int //填写评估的用户 | ||
| 20 | - Types StaffEvaluationType //填写评估对应的类型 | ||
| 21 | - BeginTime time.Time //开始时间 | ||
| 22 | - EndTime time.Time //截止时间 | ||
| 23 | - CreatedAt time.Time //数据创建时间 | ||
| 24 | - UpdatedAt time.Time //数据更新时间 | ||
| 25 | -} | ||
| 26 | - | ||
| 27 | -//用户填写的评估 | ||
| 28 | -type StaffEvaluationContent struct { | ||
| 29 | -} |
pkg/infrastructure/pg/models/staff_assess.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "time" | ||
| 5 | + | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +// 记录用户需要的评估项 | ||
| 10 | +type StaffAssess struct { | ||
| 11 | + tableName struct{} `pg:"staff_assess" comment:"记录用户需要的评估项"` | ||
| 12 | + Id int `pg:",pk"` //id | ||
| 13 | + CompanyId int `comment:"公司id"` //公司id | ||
| 14 | + EvaluationProjectId int `comment:"对应的项目id"` //对应的项目id | ||
| 15 | + CycleId int64 `comment:"对应的周期id"` //对应的周期id | ||
| 16 | + TargetUser domain.StaffDesc `comment:"被评估的目标用户"` //被评估的目标用户 | ||
| 17 | + TargetDepartment []domain.StaffDepartment `comment:"被评估的用户所在的部门"` //被评估的用户所在的部门 | ||
| 18 | + Executor domain.StaffDesc `comment:"填写评估的用户"` //填写评估的用户 | ||
| 19 | + Types string `comment:"填写评估对应的类型"` //填写评估对应的类型 | ||
| 20 | + LinkNodeId int `comment:"评估环节id"` | ||
| 21 | + Status string `comment:"评估的填写状态"` //评估的填写状态 | ||
| 22 | + BeginTime time.Time `comment:"开始时间"` //开始时间 | ||
| 23 | + EndTime time.Time `comment:"截止时间"` //截止时间 | ||
| 24 | + CreatedAt time.Time `comment:"数据创建时间"` //数据创建时间 | ||
| 25 | + UpdatedAt time.Time `comment:"数据更新时间"` //数据更新时间 | ||
| 26 | + DeletedAt *time.Time `comment:"数据删除时间"` //数据删除时间 | ||
| 27 | +} |
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +//填写的评估内容 | ||
| 6 | +type StaffAssessContent struct { | ||
| 7 | + tableName struct{} `pg:"staff_assess_content" comment:"填写的评估项"` | ||
| 8 | + Id int `pg:",pk"` //id | ||
| 9 | + StaffAssessId int //用户需要的评估项id | ||
| 10 | + SortBy int //排序 | ||
| 11 | + Category string //类别 | ||
| 12 | + Title string //问题标题 | ||
| 13 | + Remark string //填写的反馈 | ||
| 14 | + Rate string //评估填写的值 | ||
| 15 | + ReteResult string //评估的结果 | ||
| 16 | + CreatedAt time.Time //数据创建时间 | ||
| 17 | + UpdatedAt time.Time //数据更新时间 | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +type StaffAssessContentRepository interface { | ||
| 21 | + Save(param *StaffAssessContent) (*StaffAssessContent, error) | ||
| 22 | + Remove(id int) error | ||
| 23 | + FindOne(queryOptions map[string]interface{}) (*StaffAssessContent, error) | ||
| 24 | + Find(queryOptions map[string]interface{}) (int, []*StaffAssessContent, error) | ||
| 25 | +} |
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +// 执行评估的任务列表 | ||
| 6 | +type StaffAssessTask struct { | ||
| 7 | + tableName struct{} `pg:"staff_assess_task" comment:"执行评估的任务列表"` | ||
| 8 | + Id int `pg:",pk"` | ||
| 9 | + CompanyId int `` //公司id | ||
| 10 | + EvaluationProjectId int `` //项目id | ||
| 11 | + EvaluationProjectName string `` //项目名称 | ||
| 12 | + CycleId int64 //对应的周期id | ||
| 13 | + CycleName string //对应周期的名称 | ||
| 14 | + BeginTime time.Time //开始时间 | ||
| 15 | + EndTime time.Time //截止时间 | ||
| 16 | + CreatedAt time.Time //数据创建时间 | ||
| 17 | + UpdatedAt time.Time //数据更新时间 | ||
| 18 | + DeletedAt time.Time //数据删除时间 | ||
| 19 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "errors" | ||
| 5 | + "fmt" | ||
| 6 | + "time" | ||
| 7 | + | ||
| 8 | + "github.com/go-pg/pg/v10" | ||
| 9 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +type StaffAssessContentRepository struct { | ||
| 15 | + transactionContext *pgTransaction.TransactionContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +var _ domain.StaffAssessContentRepository = (*StaffAssessContentRepository)(nil) | ||
| 19 | + | ||
| 20 | +func NewStaffEvaluationRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessContentRepository { | ||
| 21 | + return &StaffAssessContentRepository{transactionContext: transactionContext} | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +func (repo *StaffAssessContentRepository) TransformToDomain(d *models.StaffAssessContent) *domain.StaffAssessContent { | ||
| 25 | + return &domain.StaffAssessContent{} | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +func (repo *StaffAssessContentRepository) Save(d *domain.StaffAssessContent) (*domain.StaffAssessContent, error) { | ||
| 29 | + saveModel := models.StaffAssess{ | ||
| 30 | + Id: d.Id, | ||
| 31 | + } | ||
| 32 | + tx := repo.transactionContext.PgTx | ||
| 33 | + var err error | ||
| 34 | + if saveModel.Id == 0 { | ||
| 35 | + _, err = tx.Model(&saveModel).Insert() | ||
| 36 | + if err != nil { | ||
| 37 | + return nil, err | ||
| 38 | + } | ||
| 39 | + } else { | ||
| 40 | + _, err = tx.Model(&saveModel).WherePK().Update() | ||
| 41 | + if err != nil { | ||
| 42 | + return nil, err | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + d.Id = saveModel.Id | ||
| 46 | + return d, nil | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +func (repo *StaffAssessContentRepository) Remove(id int) error { | ||
| 50 | + tx := repo.transactionContext.PgTx | ||
| 51 | + nowTime := time.Now() | ||
| 52 | + _, err := tx.Model(&models.StaffAssessContent{}). | ||
| 53 | + Where("id=?", id). | ||
| 54 | + Set("deleted_at=?", nowTime). | ||
| 55 | + Update() | ||
| 56 | + return err | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +func (repo *StaffAssessContentRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssessContent, error) { | ||
| 60 | + tx := repo.transactionContext.PgTx | ||
| 61 | + m := new(models.StaffAssessContent) | ||
| 62 | + query := tx.Model(m) | ||
| 63 | + query.Where("deleted_at isnull") | ||
| 64 | + if id, ok := queryOptions["id"]; ok { | ||
| 65 | + query.Where("id=?", id) | ||
| 66 | + } | ||
| 67 | + if err := query.First(); err != nil { | ||
| 68 | + if errors.Is(err, pg.ErrNoRows) { | ||
| 69 | + return nil, fmt.Errorf("没有此资源") | ||
| 70 | + } else { | ||
| 71 | + return nil, err | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + u := repo.TransformToDomain(m) | ||
| 75 | + return u, nil | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +func (repo *StaffAssessContentRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssessContent, error) { | ||
| 79 | + tx := repo.transactionContext.PgTx | ||
| 80 | + var m []*models.StaffAssessContent | ||
| 81 | + query := tx.Model(&m). | ||
| 82 | + Where("deleted_at isnull").Limit(20) | ||
| 83 | + if companyId, ok := queryOptions["companyId"]; ok { | ||
| 84 | + query.Where("company_id = ?", companyId) | ||
| 85 | + } | ||
| 86 | + if v, ok := queryOptions["limit"].(int); ok { | ||
| 87 | + query.Limit(v) | ||
| 88 | + } | ||
| 89 | + if v, ok := queryOptions["offset"].(int); ok { | ||
| 90 | + query.Offset(v) | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + count, err := query.SelectAndCount() | ||
| 94 | + if err != nil { | ||
| 95 | + return 0, nil, err | ||
| 96 | + } | ||
| 97 | + var arrays []*domain.StaffAssessContent | ||
| 98 | + for _, v := range m { | ||
| 99 | + d := repo.TransformToDomain(v) | ||
| 100 | + arrays = append(arrays, d) | ||
| 101 | + } | ||
| 102 | + return count, arrays, nil | ||
| 103 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "errors" | ||
| 5 | + "fmt" | ||
| 6 | + "time" | ||
| 7 | + | ||
| 8 | + "github.com/go-pg/pg/v10" | ||
| 9 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +type StaffAssessRepository struct { | ||
| 15 | + transactionContext *pgTransaction.TransactionContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +var _ domain.StaffAssessRepository = (*StaffAssessRepository)(nil) | ||
| 19 | + | ||
| 20 | +func NewStaffAssessRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessRepository { | ||
| 21 | + return &StaffAssessRepository{transactionContext: transactionContext} | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +func (repo *StaffAssessRepository) TransformToDomain(d *models.StaffAssess) *domain.StaffAssess { | ||
| 25 | + return &domain.StaffAssess{ | ||
| 26 | + Id: d.Id, | ||
| 27 | + CompanyId: d.CompanyId, | ||
| 28 | + EvaluationProjectId: d.EvaluationProjectId, | ||
| 29 | + CycleId: d.CycleId, | ||
| 30 | + TargetUser: d.TargetUser, | ||
| 31 | + TargetDepartment: d.TargetDepartment, | ||
| 32 | + Executor: d.Executor, | ||
| 33 | + Types: domain.StaffAssessType(d.Types), | ||
| 34 | + Status: domain.StaffAssessStatus(d.Status), | ||
| 35 | + BeginTime: d.BeginTime, | ||
| 36 | + EndTime: d.EndTime, | ||
| 37 | + CreatedAt: d.EndTime, | ||
| 38 | + UpdatedAt: d.CreatedAt, | ||
| 39 | + DeletedAt: d.DeletedAt, | ||
| 40 | + } | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +func (repo *StaffAssessRepository) Save(d *domain.StaffAssess) (*domain.StaffAssess, error) { | ||
| 44 | + saveModel := models.StaffAssess{ | ||
| 45 | + Id: d.Id, | ||
| 46 | + CompanyId: d.CompanyId, | ||
| 47 | + EvaluationProjectId: d.EvaluationProjectId, | ||
| 48 | + CycleId: d.CycleId, | ||
| 49 | + TargetUser: d.TargetUser, | ||
| 50 | + TargetDepartment: d.TargetDepartment, | ||
| 51 | + Executor: d.Executor, | ||
| 52 | + Types: string(d.Types), | ||
| 53 | + Status: string(d.Status), | ||
| 54 | + BeginTime: d.BeginTime, | ||
| 55 | + EndTime: d.EndTime, | ||
| 56 | + CreatedAt: d.EndTime, | ||
| 57 | + UpdatedAt: d.CreatedAt, | ||
| 58 | + DeletedAt: d.DeletedAt, | ||
| 59 | + } | ||
| 60 | + tx := repo.transactionContext.PgTx | ||
| 61 | + var err error | ||
| 62 | + if saveModel.Id == 0 { | ||
| 63 | + _, err = tx.Model(&saveModel).Insert() | ||
| 64 | + if err != nil { | ||
| 65 | + return nil, err | ||
| 66 | + } | ||
| 67 | + } else { | ||
| 68 | + _, err = tx.Model(&saveModel).WherePK().Update() | ||
| 69 | + if err != nil { | ||
| 70 | + return nil, err | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + d.Id = saveModel.Id | ||
| 74 | + return d, nil | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +func (repo *StaffAssessRepository) Remove(id int) error { | ||
| 78 | + tx := repo.transactionContext.PgTx | ||
| 79 | + nowTime := time.Now() | ||
| 80 | + _, err := tx.Model(&models.StaffAssess{}). | ||
| 81 | + Where("id=?", id). | ||
| 82 | + Set("deleted_at=?", nowTime). | ||
| 83 | + Update() | ||
| 84 | + return err | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +func (repo *StaffAssessRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssess, error) { | ||
| 88 | + tx := repo.transactionContext.PgTx | ||
| 89 | + m := new(models.StaffAssess) | ||
| 90 | + query := tx.Model(m) | ||
| 91 | + query.Where("deleted_at isnull") | ||
| 92 | + if id, ok := queryOptions["id"]; ok { | ||
| 93 | + query.Where("id=?", id) | ||
| 94 | + } | ||
| 95 | + if err := query.First(); err != nil { | ||
| 96 | + if errors.Is(err, pg.ErrNoRows) { | ||
| 97 | + return nil, fmt.Errorf("没有此资源") | ||
| 98 | + } else { | ||
| 99 | + return nil, err | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + u := repo.TransformToDomain(m) | ||
| 103 | + return u, nil | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +func (repo *StaffAssessRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssess, error) { | ||
| 107 | + tx := repo.transactionContext.PgTx | ||
| 108 | + var m []*models.StaffAssess | ||
| 109 | + query := tx.Model(&m). | ||
| 110 | + Where("deleted_at isnull").Limit(20) | ||
| 111 | + if companyId, ok := queryOptions["companyId"]; ok { | ||
| 112 | + query.Where("company_id = ?", companyId) | ||
| 113 | + } | ||
| 114 | + if v, ok := queryOptions["limit"].(int); ok { | ||
| 115 | + query.Limit(v) | ||
| 116 | + } | ||
| 117 | + if v, ok := queryOptions["offset"].(int); ok { | ||
| 118 | + query.Offset(v) | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + count, err := query.SelectAndCount() | ||
| 122 | + if err != nil { | ||
| 123 | + return 0, nil, err | ||
| 124 | + } | ||
| 125 | + var arrays []*domain.StaffAssess | ||
| 126 | + for _, v := range m { | ||
| 127 | + d := repo.TransformToDomain(v) | ||
| 128 | + arrays = append(arrays, d) | ||
| 129 | + } | ||
| 130 | + return count, arrays, nil | ||
| 131 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "errors" | ||
| 5 | + "fmt" | ||
| 6 | + "time" | ||
| 7 | + | ||
| 8 | + "github.com/go-pg/pg/v10" | ||
| 9 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +type StaffAssessTaskRepository struct { | ||
| 15 | + transactionContext *pgTransaction.TransactionContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +var _ domain.StaffAssessTaskRepository = (*StaffAssessTaskRepository)(nil) | ||
| 19 | + | ||
| 20 | +func NewStaffAssessTaskRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessTaskRepository { | ||
| 21 | + return &StaffAssessTaskRepository{transactionContext: transactionContext} | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +func (repo *StaffAssessTaskRepository) TransformToDomain(d *models.StaffAssessTask) *domain.StaffAssessTask { | ||
| 25 | + return &domain.StaffAssessTask{ | ||
| 26 | + Id: d.Id, | ||
| 27 | + CompanyId: d.CompanyId, | ||
| 28 | + EvaluationProjectId: d.EvaluationProjectId, | ||
| 29 | + EvaluationProjectName: d.EvaluationProjectName, | ||
| 30 | + CycleId: d.CycleId, | ||
| 31 | + CycleName: d.CycleName, | ||
| 32 | + BeginTime: d.BeginTime, | ||
| 33 | + EndTime: d.EndTime, | ||
| 34 | + CreatedAt: d.EndTime, | ||
| 35 | + UpdatedAt: d.CreatedAt, | ||
| 36 | + DeletedAt: d.DeletedAt, | ||
| 37 | + } | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +func (repo *StaffAssessTaskRepository) Save(d *domain.StaffAssessTask) (*domain.StaffAssessTask, error) { | ||
| 41 | + saveModel := models.StaffAssessTask{ | ||
| 42 | + Id: d.Id, | ||
| 43 | + CompanyId: d.CompanyId, | ||
| 44 | + EvaluationProjectId: d.EvaluationProjectId, | ||
| 45 | + EvaluationProjectName: d.EvaluationProjectName, | ||
| 46 | + CycleId: d.CycleId, | ||
| 47 | + CycleName: d.CycleName, | ||
| 48 | + BeginTime: d.BeginTime, | ||
| 49 | + EndTime: d.EndTime, | ||
| 50 | + CreatedAt: d.EndTime, | ||
| 51 | + UpdatedAt: d.CreatedAt, | ||
| 52 | + DeletedAt: d.DeletedAt, | ||
| 53 | + } | ||
| 54 | + tx := repo.transactionContext.PgTx | ||
| 55 | + var err error | ||
| 56 | + if saveModel.Id == 0 { | ||
| 57 | + _, err = tx.Model(&saveModel).Insert() | ||
| 58 | + if err != nil { | ||
| 59 | + return nil, err | ||
| 60 | + } | ||
| 61 | + } else { | ||
| 62 | + _, err = tx.Model(&saveModel).WherePK().Update() | ||
| 63 | + if err != nil { | ||
| 64 | + return nil, err | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + d.Id = saveModel.Id | ||
| 68 | + return d, nil | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +func (repo *StaffAssessTaskRepository) Remove(id int) error { | ||
| 72 | + tx := repo.transactionContext.PgTx | ||
| 73 | + nowTime := time.Now() | ||
| 74 | + _, err := tx.Model(&models.StaffAssessTask{}). | ||
| 75 | + Where("id=?", id). | ||
| 76 | + Set("deleted_at=?", nowTime). | ||
| 77 | + Update() | ||
| 78 | + return err | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +func (repo *StaffAssessTaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.StaffAssessTask, error) { | ||
| 82 | + tx := repo.transactionContext.PgTx | ||
| 83 | + m := new(models.StaffAssessTask) | ||
| 84 | + query := tx.Model(m) | ||
| 85 | + query.Where("deleted_at isnull") | ||
| 86 | + if id, ok := queryOptions["id"]; ok { | ||
| 87 | + query.Where("id=?", id) | ||
| 88 | + } | ||
| 89 | + if err := query.First(); err != nil { | ||
| 90 | + if errors.Is(err, pg.ErrNoRows) { | ||
| 91 | + return nil, fmt.Errorf("没有此资源") | ||
| 92 | + } else { | ||
| 93 | + return nil, err | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + u := repo.TransformToDomain(m) | ||
| 97 | + return u, nil | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +func (repo *StaffAssessTaskRepository) Find(queryOptions map[string]interface{}) (int, []*domain.StaffAssessTask, error) { | ||
| 101 | + tx := repo.transactionContext.PgTx | ||
| 102 | + var m []*models.StaffAssessTask | ||
| 103 | + query := tx.Model(&m). | ||
| 104 | + Where("deleted_at isnull").Limit(20) | ||
| 105 | + if companyId, ok := queryOptions["companyId"]; ok { | ||
| 106 | + query.Where("company_id = ?", companyId) | ||
| 107 | + } | ||
| 108 | + if v, ok := queryOptions["limit"].(int); ok { | ||
| 109 | + query.Limit(v) | ||
| 110 | + } | ||
| 111 | + if v, ok := queryOptions["offset"].(int); ok { | ||
| 112 | + query.Offset(v) | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + count, err := query.SelectAndCount() | ||
| 116 | + if err != nil { | ||
| 117 | + return 0, nil, err | ||
| 118 | + } | ||
| 119 | + var arrays []*domain.StaffAssessTask | ||
| 120 | + for _, v := range m { | ||
| 121 | + d := repo.TransformToDomain(v) | ||
| 122 | + arrays = append(arrays, d) | ||
| 123 | + } | ||
| 124 | + return count, arrays, nil | ||
| 125 | +} |
-
请 注册 或 登录 后发表评论