作者 庄敏学
正在显示 76 个修改的文件 包含 2696 行增加623 行删除
... ... @@ -11,7 +11,7 @@ type CreateCycleCommand struct {
Name string `cname:"周期名称" json:"name" valid:"Required"`
TimeStart *time.Time `cname:"起始时间" json:"timeStart"`
TimeEnd *time.Time `cname:"截至时间" json:"timeEnd"`
KpiCycle int `cname:"考核周期(0日、1周、2月)" json:"kpiCycle" valid:"Required"`
KpiCycle int `cname:"考核周期" json:"kpiCycle" valid:"Required"`
TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
}
... ...
... ... @@ -15,3 +15,12 @@ func (in *QueryCycleCommand) Valid(validation *validation.Validation) {
return
}
}
type StatisticCycleProjectUserCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string"`
}
func (in *StatisticCycleProjectUserCommand) Valid(*validation.Validation) {
}
... ...
... ... @@ -30,6 +30,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复
count, err := cycleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
... ... @@ -48,6 +49,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "模板不存在, 请重新选择")
}
// 生成新周期数据
newCycle := &domain.EvaluationCycle{
Id: 0,
Name: in.Name,
... ... @@ -62,8 +64,41 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取所有模板中的规则对象数据
ruleIds := make([]int64, 0)
ruleMap := map[int64]*domain.EvaluationRule{}
for i := range templates {
v := templates[i]
for j := range v.LinkNodes {
node := v.LinkNodes[j]
for k := range node.NodeContents {
nodeContent := node.NodeContents[k]
ruleIds = append(ruleIds, nodeContent.RuleId)
}
}
}
_, rules, err := ruleRepository.Find(map[string]interface{}{"ids": ruleIds, "companyId": in.CompanyId})
for i := range rules {
ruleMap[rules[i].Id] = rules[i]
}
ctAdapter := &adapter.CycleTemplateAdapter{}
ctAdapter.EvaluationCycle = cycle
for i := range templates {
v := templates[i]
// 对评估模板中的评估规则进行数据赋值
for j := range v.LinkNodes {
node := v.LinkNodes[j]
for k := range node.NodeContents {
nodeContent := node.NodeContents[k]
if rule, ok := ruleMap[nodeContent.RuleId]; ok {
nodeContent.Rule = rule
}
}
}
// 插入周期中的模板数据
cycleTemplate := &domain.EvaluationCycleTemplate{
Id: 0,
Name: v.Name,
... ... @@ -74,12 +109,19 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 输出模板简单信息
ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
Id: cycleTemplate.Id,
Name: cycleTemplate.Name,
CreatedAt: cycleTemplate.CreatedAt,
})
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cycle, nil
return ctAdapter, nil
}
... ... @@ -166,10 +208,26 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_, cycleTemplates, err := cycleTemplateRepository.Find(map[string]interface{}{"cycleId": cycle.Id}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
ctAdapter := &adapter.CycleTemplateAdapter{}
ctAdapter.EvaluationCycle = cycle
for i := range cycleTemplates {
ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
Id: cycleTemplates[i].Id,
Name: cycleTemplates[i].Name,
CreatedAt: cycleTemplates[i].CreatedAt,
})
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cycle, nil
return ctAdapter, nil
}
func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{}, error) {
... ... @@ -249,10 +307,57 @@ func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface
transactionContext.RollbackTransaction()
}()
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
// FIXME 总数量是否使用Count获取一个总数量
count, cycles, err := cycleRepository.Find(tool_funs.SimpleStructToMap(in))
total, cycles, err := cycleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(total, cycles), nil
}
func (rs *EvaluationCycleService) StatisticCycleUser(in *command.StatisticCycleProjectUserCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(count, cycles), nil
userIds := make([]int64, 0)
userIdMap := map[int64]int64{}
for i := range projects {
project := projects[i]
for j := range project.Recipients {
userId, _ := strconv.ParseInt(project.Recipients[j], 10, 64)
userIdMap[userId] = userId
}
}
for _, v := range userIdMap {
userIds = append(userIds, v)
}
userTotal := 0
departmentTotal := 0
if len(userIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": userIds, "limit": len(userIds)})
departmentIdMap := map[int]int{}
for i := range users {
for _, v := range users[i].DepartmentId {
departmentIdMap[v] = v
}
}
userTotal = len(users)
departmentTotal = len(departmentIdMap)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{"userTotal": userTotal, "departmentTotal": departmentTotal}, nil
}
... ...
... ... @@ -2,25 +2,19 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type StateProjectCommand struct {
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
State int `cname:"项目状态" json:"state"`
type ActivateProjectCommand struct {
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
}
type CopyProjectCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
}
func (in *StateProjectCommand) Valid(validation *validation.Validation) {
switch in.State {
case domain.ProjectStateWaitConfig, domain.ProjectStateWaitActive, domain.ProjectStateEnable, domain.ProjectStateDisable:
default:
validation.SetError("state", "状态设置错误")
return
}
func (in *ActivateProjectCommand) Valid(validation *validation.Validation) {
}
func (in *CopyProjectCommand) Valid(*validation.Validation) {
... ...
... ... @@ -18,12 +18,3 @@ func (in *QueryProjectCommand) Valid(validation *validation.Validation) {
return
}
}
type StatisticCycleProjectUserCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string"`
}
func (in *StatisticCycleProjectUserCommand) Valid(*validation.Validation) {
}
... ...
... ... @@ -2,7 +2,7 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"time"
)
type UpdateProjectCommand struct {
... ... @@ -17,22 +17,25 @@ type UpdateProjectCommand struct {
}
type UpdateProjectTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string"`
Recipients []string `cname:"被评估人ID" json:"recipients"`
TimeStart *time.Time `cname:"自评起始时间" json:"timeStart" valid:"Required"`
TimeEnd *time.Time `cname:"自评截止时间" json:"timeEnd" valid:"Required"`
KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"`
KpiResultStart *time.Time `cname:"绩效结果开始查看时间" json:"kpiResultStart"`
Activate int `cname:"启动项目" json:"activate"`
}
type CheckRecipientCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string"`
Recipients []string `cname:"被评估人ID" json:"recipients"`
}
type UpdateProjectTemplateNodeCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string" valid:"Required"`
LinkNodes []*domain.LinkNode `cname:"评估流程" json:"linkNodes"`
Activate int `cname:"启动项目" json:"activate"`
}
func (in *UpdateProjectCommand) Valid(validation *validation.Validation) {
if len(in.Name) > 40 {
validation.SetError("name", "项目名称最大长度40个字符")
... ... @@ -46,10 +49,3 @@ func (in *UpdateProjectTemplateCommand) Valid(validation *validation.Validation)
return
}
}
func (in *UpdateProjectTemplateNodeCommand) Valid(validation *validation.Validation) {
if len(in.LinkNodes) == 0 {
validation.SetError("linkNodes", "请添加评估流程")
return
}
}
... ...
... ... @@ -55,10 +55,19 @@ func (rs *EvaluationProjectService) Create(in *command.CreateProjectCommand) (in
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
projectAdapter := &adapter.EvaluationProjectAdapter{}
projectAdapter.EvaluationProject = project
if len(project.PmpIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": project.PmpIds, "limit": len(project.PmpIds)})
projectAdapter.TransformPmpAdapter(users)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return project, nil
return projectAdapter, nil
}
... ... @@ -96,10 +105,19 @@ func (rs *EvaluationProjectService) Update(in *command.UpdateProjectCommand) (in
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
projectAdapter := &adapter.EvaluationProjectAdapter{}
projectAdapter.EvaluationProject = project
if len(project.PmpIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": project.PmpIds, "limit": len(project.PmpIds)})
projectAdapter.TransformPmpAdapter(users)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return project, nil
return projectAdapter, nil
}
func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemplateCommand) (interface{}, error) {
... ... @@ -145,48 +163,33 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
project.Recipients = in.Recipients
project.Template = cycleTemplate.Template
project, err = projectRepository.Insert(project)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return project, nil
}
func (rs *EvaluationProjectService) UpdateTemplateNode(in *command.UpdateProjectTemplateNodeCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// FIXME 启动时,需要激活定时任务
if in.Activate == 1 {
if len(in.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
project.State = domain.ProjectStateEnable
}
for i := range in.LinkNodes {
project.Template.LinkNodes[i].TimeStart = in.LinkNodes[i].TimeStart
project.Template.LinkNodes[i].TimeEnd = in.LinkNodes[i].TimeEnd
project.Template.LinkNodes[i].KpiCycle = in.LinkNodes[i].KpiCycle
project.Recipients = in.Recipients
project.Template = cycleTemplate.Template
for i := range project.Template.LinkNodes {
node := project.Template.LinkNodes[i]
node.KpiCycle = in.KpiCycle // 设置周期
if node.Type == domain.LinkNodeViewResult {
if in.KpiResultStart != nil {
node.TimeStart = in.KpiResultStart
}
} else {
node.TimeStart = in.TimeStart
node.TimeEnd = in.TimeEnd
}
}
project, err = projectRepository.Insert(project)
... ... @@ -268,8 +271,7 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
// FIXME 总数量是否使用Count获取一个总数量
count, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
total, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -288,10 +290,10 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter
pmpUsers = users
}
projectAdapters := adapter.TransformProjectListAdapter(projects, pmpUsers)
return tool_funs.SimpleWrapGridMap(count, projectAdapters), nil
return tool_funs.SimpleWrapGridMap(total, projectAdapters), nil
}
func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (interface{}, error) {
func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
... ... @@ -301,13 +303,20 @@ func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (inte
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
project.State = in.State
if project.Template == nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加评估模板")
}
if len(project.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
project.State = domain.TemplateStateEnable
project, err = projectRepository.Insert(project)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -333,6 +342,10 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf
}
// ID重置
project.Id = 0
project.Name = project.Name + " 副本"
project.CreatorId = in.CreatorId
project.Recipients = make([]string, 0) // 重置被评估人
// 如果拷贝已经启用的模板,默认先设置为待启用
if project.State == domain.ProjectStateEnable {
project.State = domain.ProjectStateWaitActive
... ... @@ -347,7 +360,7 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf
return project, nil
}
func (rs *EvaluationProjectService) StatisticCycleUser(in *command.StatisticCycleProjectUserCommand) (interface{}, error) {
func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
... ... @@ -355,42 +368,41 @@ func (rs *EvaluationProjectService) StatisticCycleUser(in *command.StatisticCycl
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "linkNodes")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
userIds := make([]int64, 0)
userIdMap := map[int64]int64{}
// 周期内的所有项目,员工不能重复被评估
rids := map[string]bool{}
for i := range projects {
project := projects[i]
for j := range project.Recipients {
userId, _ := strconv.ParseInt(project.Recipients[j], 10, 64)
userIdMap[userId] = userId
// 排除当前项目
if in.Id != projects[i].Id {
ids := projects[i].Recipients
for j := range ids {
rids[ids[j]] = true
}
}
}
for _, v := range userIdMap {
userIds = append(userIds, v)
}
userTotal := 0
departmentTotal := 0
if len(userIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": userIds, "limit": len(userIds)})
departmentIdMap := map[int]int{}
for i := range users {
for _, v := range users[i].DepartmentId {
departmentIdMap[v] = v
}
repeatNum := 0
for i := range in.Recipients {
id := in.Recipients[i]
if _, ok := rids[id]; ok {
repeatNum++
}
userTotal = len(users)
departmentTotal = len(departmentIdMap)
}
//if repeatNum > 0 {
// return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("有%d人已经在本周期其他项目内,需要将他们移除", repeatNum))
//}
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{"userTotal": userTotal, "departmentTotal": departmentTotal}, nil
return repeatNum, nil
}
... ...
... ... @@ -6,13 +6,13 @@ import (
)
type CreateRuleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Name string `cname:"规则名称" json:"name" valid:"Required"`
Remark string `cname:"规则备注" json:"remark"`
Type int `cname:"评估方式" json:"type"`
Rating *domain.Rating `cname:"评级" json:"rating"`
Score *domain.Score `cname:"评分" json:"score"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Name string `cname:"规则名称" json:"name" valid:"Required"`
Remark string `cname:"规则备注" json:"remark"`
Type int `cname:"评估方式" json:"type"`
Rating domain.Rating `cname:"评级" json:"rating"`
Score domain.Score `cname:"评分" json:"score"`
}
func (in *CreateRuleCommand) Valid(validation *validation.Validation) {
... ... @@ -26,20 +26,23 @@ func (in *CreateRuleCommand) Valid(validation *validation.Validation) {
}
if len(in.Name) > 40 {
validation.SetError("name", "角色名称最大长度40个字符")
validation.SetError("name", "名称最大长度40个字符")
return
}
if len(in.Remark) > 100 {
validation.SetError("remark", "备注不能超过100个字符")
return
}
if in.Type == domain.EvaluationTypeRating {
if nil == in.Rating || len(in.Rating.Levels) == 0 {
if len(in.Rating.Levels) == 0 {
validation.SetError("rating", "评级内容不能为空")
return
}
}
if in.Type == domain.EvaluationTypeScore {
if nil == in.Score {
validation.SetError("rating", "评分内容不能为空")
} else if in.Type == domain.EvaluationTypeScore {
if len(in.Score.Levels) == 0 {
validation.SetError("score", "评分内容不能为空")
return
}
}
... ...
... ... @@ -5,6 +5,8 @@ import "github.com/beego/beego/v2/core/validation"
type QueryRuleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
NameOrRemark string `cname:"规则名称或备注" json:"nameOrRemark"`
Type int `cname:"评估方式(0评级、1评分)" json:"type"`
CreatorId int64 `cname:"创建人ID" json:"creatorId,string"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
}
... ...
... ... @@ -6,14 +6,14 @@ import (
)
type UpdateRuleCommand struct {
Id int64 `cname:"规则ID" json:"id,string" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Name string `cname:"规则名称" json:"name" valid:"Required"`
Remark string `cname:"规则备注" json:"remark"`
Type int `cname:"评估方式" json:"type"`
Rating *domain.Rating `cname:"评级" json:"rating"`
Score *domain.Score `cname:"评分" json:"score"`
Id int64 `cname:"规则ID" json:"id,string" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Name string `cname:"规则名称" json:"name" valid:"Required"`
Remark string `cname:"规则备注" json:"remark"`
Type int `cname:"评估方式" json:"type"`
Rating domain.Rating `cname:"评级" json:"rating"`
Score domain.Score `cname:"评分" json:"score"`
}
func (in *UpdateRuleCommand) Valid(validation *validation.Validation) {
... ... @@ -27,20 +27,23 @@ func (in *UpdateRuleCommand) Valid(validation *validation.Validation) {
}
if len(in.Name) > 40 {
validation.SetError("name", "角色名称最大长度40个字符")
validation.SetError("name", "名称最大长度40个字符")
return
}
if len(in.Remark) > 100 {
validation.SetError("remark", "备注不能超过100个字符")
return
}
if in.Type == domain.EvaluationTypeRating {
if nil == in.Rating || len(in.Rating.Levels) == 0 {
if len(in.Rating.Levels) == 0 {
validation.SetError("rating", "评级内容不能为空")
return
}
}
if in.Type == domain.EvaluationTypeScore {
if nil == in.Score {
validation.SetError("rating", "评分内容不能为空")
} else if in.Type == domain.EvaluationTypeScore {
if len(in.Score.Levels) == 0 {
validation.SetError("score", "评分内容不能为空")
return
}
}
... ...
... ... @@ -7,6 +7,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_rule/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"sort"
)
type EvaluationRuleService struct {
... ... @@ -36,6 +37,13 @@ func (rs *EvaluationRuleService) Create(in *command.CreateRuleCommand) (interfac
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
}
if in.Type == domain.EvaluationTypeRating { // 按等级量化值排序
sort.SliceStable(in.Rating.Levels, func(i, j int) bool {
return in.Rating.Levels[i].QuantizedValue < in.Rating.Levels[j].QuantizedValue
})
}
newRule := &domain.EvaluationRule{
Id: 0,
Name: in.Name,
... ... @@ -82,6 +90,12 @@ func (rs *EvaluationRuleService) Update(in *command.UpdateRuleCommand) (interfac
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if in.Type == domain.EvaluationTypeRating { // 按等级量化值排序
sort.SliceStable(in.Rating.Levels, func(i, j int) bool {
return in.Rating.Levels[i].QuantizedValue < in.Rating.Levels[j].QuantizedValue
})
}
rule.Name = in.Name
rule.Remark = in.Remark
rule.Type = in.Type
... ... @@ -143,22 +157,22 @@ func (rs *EvaluationRuleService) Remove(in *command.DeleteRuleCommand) (interfac
return rule, nil
}
func (rs *EvaluationRuleService) List(in *command.QueryRuleCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
// FIXME 总数量是否使用Count获取一个总数量
count, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(count, rules), nil
}
//func (rs *EvaluationRuleService) List(in *command.QueryRuleCommand) (interface{}, error) {
// transactionContext, err := factory.StartTransaction()
// if err != nil {
// return nil, err
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
//
// total, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// return tool_funs.SimpleWrapGridMap(total, rules), nil
//}
func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
... ... @@ -171,8 +185,7 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
// FIXME 总数量是否使用Count获取一个总数量
count, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
total, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -197,5 +210,5 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
ras[i].CreatorName = v
}
}
return tool_funs.SimpleWrapGridMap(count, ras), nil
return tool_funs.SimpleWrapGridMap(total, ras), nil
}
... ...
... ... @@ -8,7 +8,7 @@ type CreateTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Name string `cname:"模板名称" json:"name" valid:"Required"`
Describe string `cname:"模板描述" json:"remark"`
Describe string `cname:"模板描述" json:"describe"`
}
func (in *CreateTemplateCommand) Valid(validation *validation.Validation) {
... ... @@ -25,4 +25,9 @@ func (in *CreateTemplateCommand) Valid(validation *validation.Validation) {
validation.SetError("name", "模板名称最大长度40个字符")
return
}
if len(in.Describe) > 100 {
validation.SetError("describe", "备注最大长度100个字符")
return
}
}
... ...
... ... @@ -6,12 +6,15 @@ import (
)
type StateTemplateCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
State int `cname:"模板状态" json:"state"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
State int `cname:"模板状态" json:"state"`
}
type CopyTemplateCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
}
func (in *StateTemplateCommand) Valid(validation *validation.Validation) {
... ...
package command
import "github.com/beego/beego/v2/core/validation"
import (
"github.com/beego/beego/v2/core/validation"
"time"
)
type QueryTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
Name string `cname:"模板名称" json:"name"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
Name string `cname:"模板名称" json:"name"`
State int `cname:"模板状态" json:"state"`
CreatedAt *time.Time `cname:"创建时间" json:"createdAt"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
}
func (in *QueryTemplateCommand) Valid(validation *validation.Validation) {
... ... @@ -16,14 +21,14 @@ func (in *QueryTemplateCommand) Valid(validation *validation.Validation) {
}
}
// AllEnableTemplateCommand 查询所有已启用的模板
type AllEnableTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
}
func (in *AllEnableTemplateCommand) Valid(validation *validation.Validation) {
if in.CompanyId == 0 {
validation.SetError("companyId", "公司ID无效")
return
}
}
//// AllEnableTemplateCommand 查询所有已启用的模板
//type AllEnableTemplateCommand struct {
// CompanyId int64 `cname:"公司ID" json:"companyId"`
//}
//
//func (in *AllEnableTemplateCommand) Valid(validation *validation.Validation) {
// if in.CompanyId == 0 {
// validation.SetError("companyId", "公司ID无效")
// return
// }
//}
... ...
... ... @@ -9,7 +9,7 @@ type UpdateTemplateCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
Name string `cname:"模板名称" json:"name" valid:"Required"`
Describe string `cname:"模板描述" json:"remark"`
Describe string `cname:"模板描述" json:"describe"`
LinkNodes []*domain.LinkNode `cname:"评估流程" json:"linkNodes"`
}
... ... @@ -24,6 +24,11 @@ func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) {
return
}
if len(in.Describe) > 100 {
validation.SetError("describe", "备注最大长度100个字符")
return
}
if len(in.LinkNodes) == 0 {
validation.SetError("linkNodes", "评估模板流程不能为空")
return
... ...
... ... @@ -184,35 +184,14 @@ func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (int
transactionContext.RollbackTransaction()
}()
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
// FIXME 总数量是否使用Count获取一个总数量
count, templates, err := templateRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
total, templates, err := templateRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(count, templates), nil
}
func (rs *EvaluationTemplateService) ListForEnable(in *command.AllEnableTemplateCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
count, templates, err := templateRepository.Find(map[string]interface{}{
"companyId": in.CompanyId,
"state": domain.TemplateStateEnable,
"offset": 0,
"limit": 9999999,
}, "linkNodes")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(count, templates), nil
return tool_funs.SimpleWrapGridMap(total, templates), nil
}
func (rs *EvaluationTemplateService) State(in *command.StateTemplateCommand) (interface{}, error) {
... ... @@ -257,10 +236,20 @@ func (rs *EvaluationTemplateService) Copy(in *command.CopyTemplateCommand) (inte
}
// ID重置
template.Id = 0
template.Name = template.Name + " 副本"
template.CreatorId = in.CreatorId
// 如果拷贝已经启用的模板,默认先设置为待启用
if template.State == domain.TemplateStateEnable {
template.State = domain.TemplateStateWaitActive
}
// 流程环节ID重置
sid, _ := utils.NewSnowflakeId()
for i := range template.LinkNodes {
template.LinkNodes[i].Id = sid + int64(i+1)
}
template, err = templateRepository.Insert(template)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -128,3 +128,27 @@ func CreateEvaluationProjectRepository(options map[string]interface{}) domain.Ev
}
return repository.NewEvaluationProjectRepository(transactionContext)
}
func CreateStaffAssessRepository(options map[string]interface{}) domain.StaffAssessRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewStaffAssessRepository(transactionContext)
}
func CreateStaffAssessContentRepository(options map[string]interface{}) domain.StaffAssessContentRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewStaffAssessContentRepository(transactionContext)
}
func CreateStaffAssessTaskRepository(options map[string]interface{}) domain.StaffAssessTaskRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewStaffAssessTaskRepository(transactionContext)
}
... ...
... ... @@ -6,7 +6,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type RoleService struct {
... ... @@ -17,122 +16,122 @@ func NewRoleService() *RoleService {
return newRoleService
}
// Create 创建
func (rs *RoleService) Create(in *command.CreateRoleCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复
count, err := roleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "角色名称已存在")
}
newRole := &domain.Role{
Id: 0,
Name: in.Name,
Type: domain.RoleTypeCommon,
Description: in.Description,
CompanyId: in.CompanyId,
}
role, err := roleRepository.Insert(newRole)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return role, nil
}
func (rs *RoleService) Update(in *command.UpdateRoleCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复(排除自己)
count, err := roleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId, "notId": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "角色名称已存在")
}
role, err := roleRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
role.Name = in.Name
role.Name = in.Description
role, err = roleRepository.Insert(role)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return role, nil
}
func (rs *RoleService) Remove(in *command.DeleteRoleCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
role, err := roleRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err := roleRepository.Remove(role); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取角色所有关联的用户,并删除
_, roleUsers, err := roleUserRepository.Find(map[string]interface{}{"roleId": in.Id, "companyId": in.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
ids := make([]int64, 0)
for i := range roleUsers {
ids = append(ids, roleUsers[i].Id)
}
if len(ids) > 0 {
err := roleUserRepository.BatchDeleteById(ids)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return role, nil
}
//// Create 创建
//func (rs *RoleService) Create(in *command.CreateRoleCommand) (interface{}, error) {
// transactionContext, err := factory.ValidateStartTransaction(in)
// if err != nil {
// return nil, err
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
//
// // 检测名称重复
// count, err := roleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if count > 0 {
// return nil, application.ThrowError(application.BUSINESS_ERROR, "角色名称已存在")
// }
// newRole := &domain.Role{
// Id: 0,
// Name: in.Name,
// Type: domain.RoleTypeCommon,
// Description: in.Description,
// CompanyId: in.CompanyId,
// }
// role, err := roleRepository.Insert(newRole)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return role, nil
//
//}
//
//func (rs *RoleService) Update(in *command.UpdateRoleCommand) (interface{}, error) {
// transactionContext, err := factory.ValidateStartTransaction(in)
// if err != nil {
// return nil, err
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
//
// roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
//
// // 检测名称重复(排除自己)
// count, err := roleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId, "notId": in.Id})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if count > 0 {
// return nil, application.ThrowError(application.BUSINESS_ERROR, "角色名称已存在")
// }
//
// role, err := roleRepository.FindOne(map[string]interface{}{"id": in.Id})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
//
// role.Name = in.Name
// role.Description = in.Description
//
// role, err = roleRepository.Insert(role)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return role, nil
//}
//
//func (rs *RoleService) Remove(in *command.DeleteRoleCommand) (interface{}, error) {
// transactionContext, err := factory.ValidateStartTransaction(in)
// if err != nil {
// return nil, err
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
//
// roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
// roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
//
// role, err := roleRepository.FindOne(map[string]interface{}{"id": in.Id})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if _, err := roleRepository.Remove(role); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
//
// // 获取角色所有关联的用户,并删除
// _, roleUsers, err := roleUserRepository.Find(map[string]interface{}{"roleId": in.Id, "companyId": in.CompanyId})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// ids := make([]int64, 0)
// for i := range roleUsers {
// ids = append(ids, roleUsers[i].Id)
// }
// if len(ids) > 0 {
// err := roleUserRepository.BatchDeleteById(ids)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// }
//
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return role, nil
//}
func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
... ... @@ -171,6 +170,5 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{
roleUser.Users = tempList
adapterList = append(adapterList, roleUser)
}
return map[string]interface{}{"list": adapterList}, nil
return tool_funs.SimpleWrapGridMap(int64(len(adapterList)), adapterList), nil
}
... ...
... ... @@ -2,6 +2,7 @@ package service
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
... ... @@ -88,47 +89,25 @@ func (rs *RoleUserService) Remove(in *command.UserRoleDeleteCommand) (interface{
return rus, nil
}
//func (rs *RoleUserService) ListForUser(in *command.UserRoleQueryCommand) (interface{}, error) {
// transactionContext, err := factory.StartTransaction()
// if err != nil {
// return nil, err
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// roleRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
// userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
//
// in.PageNumber = 1
// in.PageSize = 9999999
//
// conditionMap := tool_funs.SimpleStructToMap(in)
// _, roles, err := roleRepository.Find(conditionMap)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if len(roles) == 0 {
// return nil, application.ThrowError(application.BUSINESS_ERROR, "未找到角色数据")
// }
//
// ids := make([]int64, 0)
// for i := range roles {
// ids = append(ids, roles[i].Id)
// }
//
// _, users, err := userRepository.Find(conditionMap)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
//
// //for i := range users {
// // users[i].RoleUserIds
// //}
//
// //if err := transactionContext.CommitTransaction(); err != nil {
// // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// //}
// //groupAdapter := &adapter.RoleUserAdapter{}
// //newList := groupAdapter.TransformTree(groups)
// return map[string]interface{}{"list": users}, nil
//}
func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
ruRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
in.PageNumber = 1
in.PageSize = 9999999
tempList, err := ruRepository.FindAllContainUser(1, 10, in.CompanyId, in.RoleId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(int64(len(tempList)), tempList), nil
}
... ...
package adapter
import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
//评估内容详情
type AssessInfoResp struct {
CycleId int64 `json:"cycleId"` //周期id
CycleName string `json:"cycleName"` //周期名称
EvaluationProjectId int `json:"evaluationProjectId"` //项目id
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
BeginTime string `json:"beginTime"` //开始时间 2006-01-02 15:04:05
EndTime string `json:"endTime"` //结束时间 2006-01-02 15:04:05
Status string `json:"status"` //完成状态
TargetUserId int `json:"targetUser"` //
TargetUserName string `json:"targetUserName"` //
AssessContent []AssessContent `json:"assessContent"` //评估内容
}
type AssessContent struct {
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*domain.EntryItem `json:"entryItems" comment:"填写项"`
}
... ...
package adapter
import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
type AssessInviteUserResp struct {
LinkNodeId int `json:"linkNodeId"`
LinkNodeName string `json:"linkNodeName"`
BeginTime string `json:"beginTime"`
EndTime string `json:"endTime"`
AssessTaskId int `json:"assessTaskId"`
InviteSameSuper []domain.StaffDesc `json:"inviteSameSuper"`
InviteDiffSuper []domain.StaffDesc `json:"inviteDiffSuper"`
}
... ...
package adapter
type AssessSelfList struct {
AssessId int `json:"assessId"` //用户执行的评估项id
BeginTime string `json:"beginTime"` //开始时间 2006-01-02 15:04:05
EndTime string `json:"endTime"` //开始时间 2006-01-02 15:04:05
CycleId int64 `json:"cycleId"` //周期id
CycleName string `json:"cycleName"` //周期名称
EvaluationProjectId int `json:"evaluationProjectId"` //项目id
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
}
type StaffInfo struct {
UserName string `json:"userName"` //员工名称
CompanyName string `json:"companyName"` //公司名称
SupperUserName string `json:"supperUserName"` //上级名称
DutyTime string `json:"dutyTime"` //上岗时间
}
... ...
package adapter
type AssessTaskDescResp struct {
AssessTaskId int `json:"assessTaskId"` //
EvaluationProjectId int `json:"evaluationProjectId"` //项目id
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
CycleName string `json:"cycleName"` //周期名称
BeginTime string `json:"beginTime"` //开始时间 2006-01-02 15:04:05
EndTime string `json:"endTime"` //结束时间 2006-01-02 15:04:05
StepList []AssessTaskStep `json:"stepList"` // 考评流程
}
type AssessTaskStep struct {
SortBy int `json:"sortBy"` //排序
LinkNodeName string `json:"linkNodeName"` //流程名称
BeginTime string `json:"beginTime"` //开始时间时间
EndTime string `json:"endTime"` //结束时间
LinkNodeType int `json:"linkNodeType"` //流程类型
Desc string `json:"desc"` //情况描述
Status string `json:"status"` //流程是否完成 "":未参加,"uncompleted":未完成,"completed":完成
}
... ...
package adapter
type SearchAssessMeResp struct {
AssessTaskId int `json:"assessTaskId"`
BeginTime string `json:"beginTime"`
EndTime string `json:"endTime"`
CycleId int64 `json:"cycleId"`
CycleName string `json:"cycleName"`
EvaluationProjectId int `json:"evaluationProjectId"`
EvaluationProjectName string `json:"evaluationProjectName"`
}
... ...
package command
type CreateStaffAssessTask struct {
CompanyId int `json:"companyId"` //公司id
EvaluationProjectId int `json:"evaluationProjectId"` //项目id
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
CycleId int64 `json:"cycleId"` //对应的周期id
CycleName string `json:"cycleName"` //对应周期的名称
BeginTime string `json:"beginTime"` //绩效考核开始时间
EndTime string `json:"endTime"` //绩效考核截止时间
StepList []AssessTaskStep `json:"steps"` //考评的流程
ExecutorId []int `json:"executorId"` //参与此次考评的人
}
type AssessTaskStep struct {
SortBy int `json:"sortBy"` //排序
LinkNodeId int `json:"linkNodeId"` //考评的流程id
LinkNodeName string `json:"linkNodeName"` //流程名称
LinkNodeType int `json:"linkNodeType"` //流程类型 同evaluation_template.go->LinkNode.Type
BeginTime string `json:"beginTime"` //绩效考核开始时间
EndTime string `json:"endTime"` //绩效考核截止时间
}
... ...
package command
type SaveAssessInvite struct {
InviteSameSuper []string `json:"inviteSameSuper"` //相同上级同事
InviteDiffSuper []string `json:"inviteDiffSuper"` //不同上级同事
AssessTaskId int `json:"assessTaskId"` //评估任务id
TargetUserId int `json:"targetUserId"` //被评估的员工id
}
... ...
package query
type AssessInfoQuery struct {
AssessTaskId int `json:"assessTaskId"` //StaffAssess 的id
TargetUserId int `json:"targetUserId"` //被评估的人id
CompanyId int `json:"companyId"` //公司id
}
... ...
package query
type AssessSelfListQuery struct {
UserId int `json:"userId"` //用户id
CompanyId int `json:"companyId"` //公司Id
PageSize int `json:"pageSize"` //每页的记录数
PageNumber int `json:"pageNumber"` //页码
}
... ...
package query
type AssessTaskDescQuery struct {
AssessTaskId int `json:"assessTaskId"` //评估任务的id
UserId int `json:"userId"` //当前登录人的id
CompanyId int `json:"companyId"` //当前登录的公司
}
... ...
package query
type GetAssessInviteUserQuery struct {
CompanyId int `json:"companyId"` //对公司
UsrId int `json:"usrId"` //被评估的员工id
AssessTaskId int `json:"assessTaskId"` //评估任务的id
}
... ...
package query
type SearchAssessMeQuery struct {
UserId int `json:"userId"` // 当前登录人的用户id
CompanyId int `json:"companyId"` //当前登录人的公司Id
PageSize int `json:"pageSize"` //每页的记录数
PageNumber int `json:"pageNumber"` //页码
}
... ...
package service
import (
"fmt"
"strconv"
"time"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
// 员工评绩效评估
type StaffAssessServeice struct {
}
func NewStaffAssessServeice() *StaffAssessServeice {
newService := &StaffAssessServeice{}
return newService
}
// 获取我参与过的评估任务列表
func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQuery) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var limit int = 20
var offset int = 0
if param.PageSize > 0 {
limit = param.PageSize
}
offset = (param.PageNumber - 1) * param.PageSize
condition := map[string]interface{}{
"executorId": param.UserId,
"companyId": param.CompanyId,
"limit": limit,
}
if offset > 0 {
condition["offset"] = offset
}
cnt, assessTaskList, err := staffAssessTaskRepo.Find(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询周期"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
listData := make([]adapter.SearchAssessMeResp, 0, len(assessTaskList))
var temp adapter.SearchAssessMeResp
for _, v := range assessTaskList {
temp = adapter.SearchAssessMeResp{
AssessTaskId: v.Id,
BeginTime: v.BeginTime.Format("2006-01-02 15:04:05"),
EndTime: v.EndTime.Format("2006-01-02 15:04:05"),
CycleId: v.CycleId,
CycleName: v.CycleName,
EvaluationProjectId: v.EvaluationProjectId,
EvaluationProjectName: v.EvaluationProjectName,
}
listData = append(listData, temp)
}
return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
}
// 获取项目评估进度描述
func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery) (*adapter.AssessTaskDescResp, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 获取评估任务
staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取个人参与的评估流程
staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskData, err := staffAssessTaskRepo.FindOne(map[string]interface{}{
"id": param.AssessTaskId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "评估任务不存在,"+err.Error())
}
//返回的数据结果
result := adapter.AssessTaskDescResp{
AssessTaskId: assessTaskData.Id,
EvaluationProjectId: assessTaskData.EvaluationProjectId,
EvaluationProjectName: assessTaskData.EvaluationProjectName,
CycleName: assessTaskData.CycleName,
BeginTime: assessTaskData.BeginTime.Local().Format("2006-01-02 15:04-05"),
EndTime: assessTaskData.EndTime.Local().Format("2006-01-02 15:04-05"),
StepList: []adapter.AssessTaskStep{},
}
for _, v := range assessTaskData.StepList {
stepItem := adapter.AssessTaskStep{
SortBy: v.SortBy,
LinkNodeName: v.LinkNodeName,
BeginTime: v.BeginTime.Local().Format("2006-01-02 15:04:05"),
EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"),
LinkNodeType: v.LinkNodeType,
Desc: fmt.Sprintf("截止日期:%s", v.EndTime.Local().Format("2006-01-02 15:04:05")),
Status: "",
}
switch v.LinkNodeType {
case domain.LinkNodeSelfAssessment:
//个人自评完成情况
_, assessSelfData, err := staffAssessRepo.Find(map[string]interface{}{
"staffAssessTaskId": assessTaskData.Id,
"executorId": param.UserId,
"typesList": []string{string(domain.AssessSelf)},
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
if len(assessSelfData) > 0 {
stepItem.Status = string(assessSelfData[0].Status)
}
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
case domain.LinkNodeAllInvite:
//邀请别人评估自己
_, assessInviteData, err := staffAssessRepo.Find(map[string]interface{}{
"staffAssessTaskId": assessTaskData.Id,
"targetUserId": param.UserId,
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
"limit": 5,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
//待邀请人数,为5人减去已邀请的人数。若邀请人数已等于或大于5人,则只显示截止日期即可
if len(assessInviteData) > 5 {
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
stepItem.Status = string(domain.StaffAssessCompleted)
} else {
stepItem.Desc = fmt.Sprintf("截止日期:%s 待邀请%d人", stepItem.EndTime, 5-len(assessInviteData))
stepItem.Status = string(domain.StaffAssessUncompleted)
}
case domain.LinkNodeAllAssessment:
//我评估别人,被邀请评估
_, assessInviteList, err := staffAssessRepo.Find(map[string]interface{}{
"staffAssessTaskId": assessTaskData.Id,
"executorId": param.UserId,
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
if len(assessInviteList) > 0 {
stepItem.Status = string(domain.StaffAssessCompleted)
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
for _, v := range assessInviteList {
if v.Status == domain.StaffAssessUncompleted {
stepItem.Status = string(domain.StaffAssessUncompleted)
break
}
}
}
case domain.LinkNodeSuperiorAssessment:
//我评估别人,上级评估
_, assessSupperList, err := staffAssessRepo.Find(map[string]interface{}{
"staffAssessTaskId": assessTaskData.Id,
"executorId": param.UserId,
"typesList": []string{string(domain.AssessSuper)},
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
if len(assessSupperList) > 0 {
stepItem.Status = string(domain.StaffAssessCompleted)
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
uncompletedNum := 0
for _, v := range assessSupperList {
if v.Status == domain.StaffAssessUncompleted {
uncompletedNum += 1
}
}
if uncompletedNum > 0 {
stepItem.Desc = fmt.Sprintf("截止日期:%s 待评估%d人", stepItem.EndTime, uncompletedNum)
}
}
}
result.StepList = append(result.StepList, stepItem)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return &result, nil
}
// 获取个人的自评反馈历史记录列表
func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//获取个人参与的评估流程
staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var limit int = 20
var offset int = 0
if param.PageSize > 0 {
limit = param.PageSize
}
offset = (param.PageNumber - 1) * param.PageSize
condition := map[string]interface{}{
"executorId": param.UserId,
"companyId": param.CompanyId,
"typesList": []string{string(domain.AssessSelf)},
"limit": limit,
"status": string(domain.StaffAssessCompleted),
}
if offset > 0 {
condition["offset"] = offset
}
//获取历史列表
cnt, assessList, err := staffAssessRepo.Find(condition)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取评估任务列表,"+err.Error())
}
//获取公司数据
companyRep := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
companyData, err := companyRep.FindOne(map[string]interface{}{
"id": param.CompanyId,
})
if err != nil {
log.Logger.Error("获取公司信息," + err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取公司信息,"+err.Error())
}
//获取用户数据
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
userData, err := userRepo.FindOne(map[string]interface{}{
"id": param.UserId,
})
if err != nil {
log.Logger.Error("获取用户信息," + err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取用户信息,"+err.Error())
}
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var supperUserList []*domain.User
if len(userData.DepartmentId) > 0 {
_, departmentList, err := departmentRepo.Find(map[string]interface{}{
"ids": userData.DepartmentId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取部门信息,"+err.Error())
}
var chargeUserIds []int64
for _, v := range departmentList {
chargeUserIds = append(chargeUserIds, v.ChargeUserIds...)
}
if len(chargeUserIds) > 0 {
_, supperUserList, err = userRepo.Find(map[string]interface{}{
"ids": chargeUserIds,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取员工上级信息,"+err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
listData := make([]adapter.AssessSelfList, 0, len(assessList))
var itemTemp adapter.AssessSelfList
for _, v := range assessList {
itemTemp = adapter.AssessSelfList{
AssessId: v.Id,
BeginTime: v.BeginTime.Local().Format("2006-01-02 15:04:05"),
EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"),
CycleId: v.CycleId,
CycleName: v.CycleName,
EvaluationProjectId: v.EvaluationProjectId,
EvaluationProjectName: v.EvaluationProjectName,
}
listData = append(listData, itemTemp)
}
userInfo := adapter.StaffInfo{
UserName: userData.Name,
CompanyName: companyData.Name,
SupperUserName: "",
DutyTime: userData.CreatedAt.Local().Format("2006-01-02 15:04:05"),
}
for _, v := range supperUserList {
userInfo.SupperUserName = userInfo.SupperUserName + v.Name + ";"
}
result := tool_funs.SimpleWrapGridMap(int64(cnt), listData)
result["userInfo"] = userInfo
return result, nil
}
// 更具项目评估的配置,创建员工的评估任务
func (srv StaffAssessServeice) CreateStaffAssessTask(param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
taskBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "任务开始时间填写错误,"+param.BeginTime)
}
taskEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "任务结束时间填写错误,"+param.EndTime)
}
nowTime := time.Now()
//建立评估任务
assessTask := domain.StaffAssessTask{
Id: 0,
CompanyId: param.CompanyId,
EvaluationProjectId: param.EvaluationProjectId,
EvaluationProjectName: param.EvaluationProjectName,
CycleId: param.CycleId,
CycleName: param.CycleName,
BeginTime: taskBeginTime,
EndTime: taskEndTime,
StepList: []domain.AssessTaskStep{},
ExecutorId: nil,
CreatedAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
}
//填充评估环节
for _, v := range param.StepList {
stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)
}
stepEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "评估环节结束时间填写错误,"+param.EndTime)
}
step := domain.AssessTaskStep{
SortBy: v.SortBy,
LinkNodeId: v.LinkNodeId,
LinkNodeName: v.LinkNodeName,
LinkNodeType: v.LinkNodeType,
BeginTime: stepBeginTime,
EndTime: stepEndTime,
}
assessTask.StepList = append(assessTask.StepList, step)
}
assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, err = assessTaskRepo.Save(&assessTask)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
}
assessList, err := srv.createStaffAssess(transactionContext, &assessTask)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
}
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
for i := range assessList {
_, err = assessRepo.Save(&assessList[i])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return map[string]interface{}{
"assessTaskId": assessTask.Id,
}, nil
}
// 添加自评节点任务
func (srv StaffAssessServeice) createStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) {
//评估的参与人
selfUserId := []int{}
userIdMap := map[int]struct{}{} //过滤重复的用户
for _, v := range param.ExecutorId {
if _, ok := userIdMap[v]; ok {
continue
}
selfUserId = append(selfUserId, v)
}
// 获取用户的信息
if len(selfUserId) == 0 {
return nil, application.ThrowError(application.ARG_ERROR, "未填写评估任务的执行人")
}
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取员工信息
_, userList, err := userRepo.Find(map[string]interface{}{
"ids": selfUserId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息"+err.Error())
}
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取用户的部门
userDepartmentMap := map[int64][]*domain.Department{}
for _, v := range userList {
_, departmemtList, err := departmentRepo.Find(map[string]interface{}{
"ids": v.DepartmentId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取员工的部门信息"+err.Error())
}
userDepartmentMap[v.Id] = departmemtList
}
assessList := []domain.StaffAssess{}
//数据样板
stepSelfTemp := domain.StaffAssess{
Id: 0,
CompanyId: param.CompanyId,
EvaluationProjectId: param.EvaluationProjectId,
EvaluationProjectName: param.EvaluationProjectName,
CycleId: param.CycleId,
CycleName: param.CycleName,
StaffAssessTaskId: param.Id,
// TargetUser: domain.StaffDesc{},
// TargetDepartment: nil,
// Executor: domain.StaffDesc{},
Types: domain.AssessSelf,
// LinkNodeId: v.LinkNodeId,
Status: domain.StaffAssessUncompleted,
// BeginTime: time.Time{},
// EndTime: time.Time{},
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
DeletedAt: nil,
}
for _, v := range param.StepList {
if v.LinkNodeType == domain.LinkNodeSelfAssessment {
//员工自评
stepSelfTemp.BeginTime = v.BeginTime
stepSelfTemp.EndTime = v.EndTime
stepSelfTemp.LinkNodeId = v.LinkNodeId
stepSelfTemp.LinkNodeName = v.LinkNodeName
assessListTemp := srv.createStaffAssessSelf(stepSelfTemp, userList, userDepartmentMap)
assessList = append(assessList, assessListTemp...)
}
if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {
// TODO
stepSelfTemp.BeginTime = v.BeginTime
stepSelfTemp.EndTime = v.EndTime
stepSelfTemp.LinkNodeId = v.LinkNodeId
stepSelfTemp.LinkNodeName = v.LinkNodeName
assessListTemp, err := srv.createStaffAssessSupper(transactionContext, stepSelfTemp, userList, userDepartmentMap)
if err != nil {
return nil, err
}
assessList = append(assessList, assessListTemp...)
}
}
return assessList, nil
}
// 构建员工自评
func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAssess,
userList []*domain.User, userDepartmentMap map[int64][]*domain.Department) []domain.StaffAssess {
result := []domain.StaffAssess{}
for _, usr := range userList {
assessTemp.TargetUser = domain.StaffDesc{
UserId: int(usr.Id),
Account: usr.Account,
UserName: usr.Account,
}
assessTemp.Executor = domain.StaffDesc{
UserId: int(usr.Id),
Account: usr.Account,
UserName: usr.Account,
}
if depList, ok := userDepartmentMap[usr.Id]; ok {
for _, dep := range depList {
assessTemp.TargetDepartment = append(assessTemp.TargetDepartment, domain.StaffDepartment{
DepartmentId: int(dep.Id),
DepartmentName: dep.Name,
})
}
}
result = append(result, assessTemp)
}
return result
}
// 构建员工上级评估
func (srv StaffAssessServeice) createStaffAssessSupper(
transactionContext application.TransactionContext,
assessTemp domain.StaffAssess,
userList []*domain.User, userDepartmentMap map[int64][]*domain.Department,
) ([]domain.StaffAssess, error) {
// 获取员工的上级用户
return nil, nil
}
// 获取某个员工360邀请的人员
func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteUserQuery) (*adapter.AssessInviteUserResp, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskReps := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskData, err := assessTaskReps.FindOne(map[string]interface{}{
"id": param.AssessTaskId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取评估任务"+err.Error())
}
_, assessList, err := assessReps.Find(map[string]interface{}{
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
"staffAssessTaskId": param.AssessTaskId,
"targetUserId": param.UsrId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取个人评估任务"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := adapter.AssessInviteUserResp{
AssessTaskId: assessTaskData.Id,
}
for _, v := range assessTaskData.StepList {
if v.LinkNodeType != domain.LinkNodeAllInvite {
continue
}
result.LinkNodeId = v.LinkNodeId
result.LinkNodeName = v.LinkNodeName
result.BeginTime = v.BeginTime.Local().Format("2006-01-02 15:04:05")
result.EndTime = v.EndTime.Local().Format("2006-01-02 15:04:05")
break
}
for _, v := range assessList {
if v.Types == domain.AssessInviteDiffSuper {
result.InviteDiffSuper = append(result.InviteDiffSuper, v.Executor)
}
if v.Types == domain.AssessInviteSameSuper {
result.InviteSameSuper = append(result.InviteDiffSuper, v.Executor)
}
}
return &result, nil
}
// 获取某个员工360邀请的人员
func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInvite) (*adapter.AssessInviteUserResp, error) {
inviteSameSuperId := []int{}
InviteDiffSuperId := []int{}
for _, v := range param.InviteDiffSuper {
id, err := strconv.Atoi(v)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "用户填写错误")
}
InviteDiffSuperId = append(InviteDiffSuperId, id)
}
for _, v := range param.InviteSameSuper {
id, err := strconv.Atoi(v)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "用户填写错误")
}
inviteSameSuperId = append(inviteSameSuperId, id)
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskReps := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskData, err := assessTaskReps.FindOne(map[string]interface{}{
"id": param.AssessTaskId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取评估任务"+err.Error())
}
targetUser, err := userRepo.FindOne(map[string]interface{}{
"id": param.TargetUserId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取被评估员工"+err.Error())
}
//被评估人的部门
var targetUserDepartment []domain.StaffDepartment
if len(targetUser.DepartmentId) > 0 {
_, departmentList, err := departmentRepo.Find(map[string]interface{}{
"ids": targetUser.DepartmentId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取部门信息"+err.Error())
}
for _, v := range departmentList {
targetUserDepartment = append(targetUserDepartment, domain.StaffDepartment{
DepartmentId: int(v.Id),
DepartmentName: v.Name,
})
}
}
//邀请的相同上级的员工
var inviteSameSuper []domain.StaffDesc
if len(inviteSameSuperId) > 0 {
_, userList, err := userRepo.Find(map[string]interface{}{
"ids": inviteSameSuperId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取用户信息"+err.Error())
}
for _, v := range userList {
inviteSameSuper = append(inviteSameSuper, domain.StaffDesc{
UserId: int(v.Id),
UserName: v.Name,
Account: v.Account,
})
}
}
//邀请的不同上级的员工
var inviteDiffSuper []domain.StaffDesc
if len(InviteDiffSuperId) > 0 {
_, userList, err := userRepo.Find(map[string]interface{}{
"ids": InviteDiffSuperId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取用户信息"+err.Error())
}
for _, v := range userList {
inviteDiffSuper = append(inviteDiffSuper, domain.StaffDesc{
UserId: int(v.Id),
UserName: v.Name,
Account: v.Account,
})
}
}
_ = assessReps
_ = inviteSameSuper
_ = inviteDiffSuper
_ = targetUserDepartment
// _, assessList, err := assessReps.Find(map[string]interface{}{
// "typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
// "staffAssessTaskId": param.AssessTaskId,
// "targetUserId": param.TargetUserId,
// })
// if err != nil {
// return nil, application.ThrowError(application.ARG_ERROR, "获取个人评估任务"+err.Error())
// }
// TODO
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := adapter.AssessInviteUserResp{
AssessTaskId: assessTaskData.Id,
}
// for _, v := range assessTaskData.StepList {
// if v.LinkNodeType != domain.LinkNodeAllInvite {
// continue
// }
// result.LinkNodeId = v.LinkNodeId
// result.LinkNodeName = v.LinkNodeName
// result.BeginTime = v.BeginTime.Local().Format("2006-01-02 15:04:05")
// result.EndTime = v.EndTime.Local().Format("2006-01-02 15:04:05")
// break
// }
// for _, v := range assessList {
// if v.Types == domain.AssessInviteDiffSuper {
// result.InviteDiffSuper = append(result.InviteDiffSuper, v.Executor)
// }
// if v.Types == domain.AssessInviteSameSuper {
// result.InviteSameSuper = append(result.InviteDiffSuper, v.Executor)
// }
// }
return &result, nil
}
// 获取员工自评的评估内容详情
func (srv StaffAssessServeice) GetAssessSelfInfo(param *query.AssessInfoQuery) (*adapter.AssessInfoResp, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取员工的评估
_, assessList, err := assessReps.Find(map[string]interface{}{
"companyId": param.CompanyId,
"staffAssessTaskId": param.AssessTaskId,
"targetUserId": param.TargetUserId,
"typesList": []string{string(domain.AssessSelf)},
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
}
if len(assessList) == 0 {
return &adapter.AssessInfoResp{}, nil
}
assessData := assessList[0]
projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
projectData, err := projectRepo.FindOne(map[string]interface{}{
"id": assessData.EvaluationProjectId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目评估配置"+err.Error())
}
if projectData.Template == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未获取到项目评估配置模板")
}
var selfLinkNode *domain.LinkNode
for _, v := range projectData.Template.LinkNodes {
if v.Type == domain.LinkNodeSelfAssessment {
selfLinkNode = v
break
}
}
if selfLinkNode == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未获取到项目评估自评配置")
}
//获取员工评估的填写内容
// assessContentReps := factory.CreateStaffAssessContentRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// _, assessContentList, err := assessContentReps.Find(map[string]interface{}{
// "staffAssessId": assessData.Id,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目评估员工填写的内容"+err.Error())
// }
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := adapter.AssessInfoResp{
CycleId: assessData.CycleId,
CycleName: assessData.CycleName,
EvaluationProjectId: assessData.EvaluationProjectId,
EvaluationProjectName: assessData.EvaluationProjectName,
BeginTime: assessData.BeginTime.Local().Format("2006-01-02 15:04:05"),
EndTime: assessData.EndTime.Local().Format("2006-01-02 15:04:05"),
Status: string(assessData.Status),
TargetUserId: assessData.TargetUser.UserId,
TargetUserName: assessData.TargetUser.UserName,
AssessContent: nil,
}
assessContent := make([]adapter.AssessContent, 0)
for _, v := range selfLinkNode.NodeContents {
assessContent = append(assessContent, adapter.AssessContent{
Category: v.Category,
Name: v.Name,
PromptTitle: v.PromptTitle,
PromptText: v.PromptText,
EntryItems: v.EntryItems,
})
}
result.AssessContent = assessContent
return &result, nil
}
... ...
... ... @@ -4,6 +4,16 @@ import (
"time"
)
const (
KpiCycleDay int = 1 // 考核周期-日
KpiCycleWeek int = 2 // 考核周期-周
KpiCycleOneMonth int = 3 // 考核周期-月
KpiCycleTwoMonth int = 4 // 考核周期-双月
KpiCycleThreeMonth int = 5 // 考核周期-季度
KpiCycleSixMonth int = 6 // 考核周期-半年
KpiCycleYear int = 7 // 考核周期-年
)
type TemplateSimple struct {
Id int64 `json:"id,string" comment:"模板ID"`
Name string `json:"name" comment:"模板名称"`
... ... @@ -17,7 +27,7 @@ type EvaluationCycle struct {
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
KpiCycle int `json:"state" comment:"考核周期(0日、1周、2月)"`
KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
... ...
... ... @@ -42,8 +42,8 @@ type EvaluationRule struct {
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
Type int `json:"type" comment:"评估方式(0评级、1评分)"`
Rating *Rating `json:"rating" comment:"评级"`
Score *Score `json:"score" comment:"评分"`
Rating Rating `json:"rating" comment:"评级"`
Score Score `json:"score" comment:"评分"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
... ...
... ... @@ -24,12 +24,6 @@ const (
)
const (
KpiCycleDay int = 0 // 考核周期-日
KpiCycleWeek int = 1 // 考核周期-周
KpiCycleMonth int = 2 // 考核周期-月
)
type EntryItem struct {
Title string `json:"title" comment:"填写标题"`
HintText string `json:"hintText" comment:"文本内容提示"`
... ... @@ -37,19 +31,20 @@ type EntryItem struct {
// NodeContent 评估内容
type NodeContent struct {
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId int64 `json:"ruleId" comment:"评估规则ID"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*EntryItem `json:"entryItems" comment:"填写项"`
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId int64 `json:"ruleId" comment:"评估规则ID"`
Rule *EvaluationRule `json:"rule" comment:"评估规则对象"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*EntryItem `json:"entryItems" comment:"填写项"`
}
// NodeAllInvite 360°邀请
type NodeAllInvite struct {
ParentDifferentIds []int64 `json:"parentDifferentIds" comment:"不同上级同事ID"`
ParentSameIds []int64 `json:"parentSameIds" comment:"相同上级同事ID"`
}
//// NodeAllInvite 360°邀请
//type NodeAllInvite struct {
// ParentDifferentIds []string `json:"parentDifferentIds" comment:"不同上级同事ID"`
// ParentSameIds []string `json:"parentSameIds" comment:"相同上级同事ID"`
//}
//// NodeKpiResult 绩效结果查看
//type NodeKpiResult struct {
... ... @@ -57,15 +52,16 @@ type NodeAllInvite struct {
// 评估流程、环节
type LinkNode struct {
Id int64 `json:"id,string" comment:"环节ID"`
Type int `json:"type" comment:"环节类型"`
Name string `json:"name" comment:"环节名称"`
Describe string `json:"describe" comment:"环节描述"`
NodeContents []*NodeContent `json:"nodeContents" comment:"环节-评估内容"`
NodeAllInvite *NodeAllInvite `json:"nodeAllInvite" comment:"360°邀请人员"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
KpiCycle int `json:"state" comment:"考核周期(0日、1周、2月)"`
Id int64 `json:"id,string" comment:"环节ID"`
Type int `json:"type" comment:"环节类型"`
Name string `json:"name" comment:"环节名称"`
Describe string `json:"describe" comment:"环节描述"`
NodeContents []*NodeContent `json:"nodeContents" comment:"环节-评估内容"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
KpiCycle int `json:"state" comment:"考核周期(1日、2周、3月)"`
//NodeAllInvite *NodeAllInvite `json:"nodeAllInvite" comment:"360°邀请人员"`
}
// 评估模板
... ...
package domain
import "time"
//填写评估的类型
type StaffAssessType string
const (
AssessSelf StaffAssessType = "self" //自评
AssessSuper StaffAssessType = "super" //上级评估
AssessInviteSameSuper StaffAssessType = "invite_same_super" //360 邀请评估-相同上级的同事
AssessInviteDiffSuper StaffAssessType = "invite_diff_super" //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
EvaluationProjectName string `json:"evaluationProjectName"` //对应的项目名称
CycleId int64 `json:"cycleId"` //对应的周期id
CycleName string `json:"cycleName"` //对应的周期名称
StaffAssessTaskId int `json:"staffAssessTaskId"` //执行评估的任务id
TargetUser StaffDesc `json:"targetUser"` //被评估的目标用户
TargetDepartment []StaffDepartment `json:"targetDepartment"` //被评估的目标用户所在的部门
Executor StaffDesc `json:"executor"` //填写评估的用户
Types StaffAssessType `json:"types"` //填写评估对应的类型
LinkNodeId int `json:"linkNodeId"` //评估环节对应的id,用于调取评估模板
LinkNodeName string `json:"linkNodeName"` //评估环节对应的id,用于调取评估模板
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 `json:"id"` //id
StaffAssessId int `json:"staffAssessId"` //用户需要的评估项id
SortBy int `json:"sortBy"` //排序
Category string `json:"category"` //类别
Title string `json:"title"` //问题标题
Remark string `json:"remark"` //填写的反馈
Rate string `json:"rate"` //评估填写的值
ReteResult string `json:"reteResult"` //评估的结果
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
//TODO
}
type AssessContemtRemark struct {
Title string `json:"title"` //comment:"填写标题"
RemarkText string `json:"hintText"` // comment:"填写文本内容"
}
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
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
CycleId int64 `json:"cycleId"` //对应的周期id
CycleName string `json:"cycleName"` //对应周期的名称
BeginTime time.Time `json:"beginTime"` //绩效考核开始时间
EndTime time.Time `json:"endTime"` //绩效考核截止时间
StepList []AssessTaskStep `json:"stepList"` //考评的流程
ExecutorId []int `json:"executorId"` //参与此次考评的人
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
DeletedAt *time.Time `json:"deletedAt"` //数据删除时间
}
//考评的流程
type AssessTaskStep struct {
SortBy int `json:"sortBy"` //排序
LinkNodeId int `json:"linkNodeId"` //考评的流程id
LinkNodeName string `json:"linkNodeName"` //流程名称
LinkNodeType int `json:"linkNodeType"` //流程类型 同evaluation_template.go->LinkNode.Type
BeginTime time.Time `json:"beginTime"` //绩效考核开始时间
EndTime time.Time `json:"endTime"` //绩效考核截止时间
}
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)
}
... ...
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 {
}
... ... @@ -2,6 +2,7 @@ package pg
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"github.com/linmadan/egglib-go/persistent/pg/comment"
... ... @@ -34,6 +35,13 @@ func init() {
&models.Role{},
&models.RoleUser{},
&models.Position{},
&models.EvaluationRule{},
&models.EvaluationTemplate{},
&models.EvaluationCycle{},
&models.EvaluationCycleTemplate{},
&models.EvaluationProject{},
&models.StaffAssess{},
&models.StaffAssessTask{},
}
for _, model := range tables {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
... ...
... ... @@ -5,14 +5,14 @@ import (
)
type EvaluationCycle struct {
tableName struct{} `pg:"evaluation_cycle" comment:"评估周期"`
Id int64 `pg:"pk:id" comment:"周期ID"`
tableName struct{} `comment:"评估周期" pg:"evaluation_cycle"`
Id int64 `comment:"周期ID" pg:"pk:id"`
Name string `comment:"名称"`
TimeStart *time.Time `comment:"起始时间"`
TimeEnd *time.Time `comment:"截至时间"`
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
KpiCycle int `comment:"考核周期(0日、1周、2月)"`
KpiCycle int `comment:"考核周期(1日、2周、3月)"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
... ...
... ... @@ -6,8 +6,8 @@ import (
)
type EvaluationCycleTemplate struct {
tableName struct{} `pg:"evaluation_cycle_template" comment:"评估周期模板"`
Id int64 `pg:"pk:id" comment:"模板ID"`
tableName struct{} `comment:"评估周期模板" pg:"evaluation_cycle_template"`
Id int64 `comment:"模板ID" pg:"pk:id"`
Name string `comment:"模板名称"`
Template *domain.EvaluationTemplate `comment:"模板数据"`
CycleId int64 `comment:"周期ID"`
... ...
... ... @@ -6,14 +6,14 @@ import (
)
type EvaluationProject struct {
tableName struct{} `pg:"evaluation_project" comment:"评估项目"`
Id int64 `pg:"pk:id" comment:"ID"`
tableName struct{} `comment:"评估项目" pg:"evaluation_project"`
Id int64 `comment:"ID" pg:"pk:id"`
Name string `comment:"名称"`
Describe string `comment:"描述"`
CompanyId int64 `comment:"公司ID"`
CycleId int64 `comment:"周期ID"`
CreatorId int64 `comment:"创建人ID"`
State int `comment:"状态(0待完成配置、1待启用、2启用、3停用)"`
State int `comment:"状态(0待完成配置、1待启用、2启用、3停用)" pg:",use_zero"`
HrBp int `comment:"HR角色权限"`
Pmp int `comment:"PM角色权限"`
PmpIds []string `comment:"项目管理员ID"`
... ...
... ... @@ -6,16 +6,16 @@ import (
)
type EvaluationRule struct {
tableName struct{} `pg:"evaluation_rule" comment:"评估规则"`
Id int64 `pg:"pk:id" comment:"ID"`
Name string `comment:"名称"`
Remark string `comment:"备注"`
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
Type int `comment:"评估方式(0评级、1评分)"`
Rating *domain.Rating `comment:"评级"`
Score *domain.Score `comment:"评分"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
tableName struct{} `comment:"评估规则" pg:"evaluation_rule"`
Id int64 `comment:"ID" pg:"pk:id"`
Name string `comment:"名称"`
Remark string `comment:"备注"`
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
Type int `comment:"评估方式(0评级、1评分)" pg:",use_zero"`
Rating domain.Rating `comment:"评级"`
Score domain.Score `comment:"评分"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"`
}
... ...
... ... @@ -6,13 +6,13 @@ import (
)
type EvaluationTemplate struct {
tableName struct{} `pg:"evaluation_template" comment:"评估模板"`
Id int64 `comment:"ID"`
tableName struct{} `comment:"评估模板" pg:"evaluation_template"`
Id int64 `comment:"ID" pg:"pk:id"`
Name string `comment:"名称"`
Describe string `comment:"描述"`
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
State int `comment:"状态(0待完成配置、1待启用、2启用、3停用)"`
State int `comment:"状态(0待完成配置、1待启用、2启用、3停用)" pg:",use_zero"`
LinkNodes []*domain.LinkNode `comment:"评估流程"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
... ...
... ... @@ -6,7 +6,7 @@ type Role struct {
tableName struct{} `pg:"role" comment:"角色"`
Id int64 `pg:"pk:id" comment:"ID"`
Name string `comment:"角色名称"`
Type int `comment:"角色类型(0角色可删、1系统预置角色不可删)"`
Type int `comment:"角色类型(0角色可删、1系统预置角色不可删)" pg:",use_zero"`
Description string `comment:"角色描述"`
CompanyId int64 `comment:"公司ID"`
CreatedAt time.Time `comment:"创建时间"`
... ...
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
EvaluationProjectName string
CycleId int64 `comment:"对应的周期id"` //对应的周期id
CycleName string
StaffAssessTaskId int
TargetUser domain.StaffDesc `comment:"被评估的目标用户"` //被评估的目标用户
TargetDepartment []domain.StaffDepartment `comment:"被评估的用户所在的部门"` //被评估的用户所在的部门
Executor domain.StaffDesc `comment:"填写评估的用户"` //填写评估的用户
Types string `comment:"填写评估对应的类型"` //填写评估对应的类型
LinkNodeId int `comment:"评估环节id"`
LinkNodeName string
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"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// 执行评估的任务列表
type StaffAssessTask struct {
tableName struct{} `pg:"staff_assess_task" comment:"执行评估的任务列表"`
Id int `pg:",pk"`
CompanyId int `` //公司id
EvaluationProjectId int `` //项目id
EvaluationProjectName string `` //项目名称
CycleId int64 //对应的周期id
CycleName string //对应周期的名称
ExecutorId []int //参与考评的人
StepList []domain.AssessTaskStep `` //考评的流程
BeginTime time.Time //开始时间
EndTime time.Time //截止时间
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
DeletedAt *time.Time //数据删除时间
}
... ...
... ... @@ -91,9 +91,8 @@ func (repo *DepartmentRepository) FindOne(queryOptions map[string]interface{}) (
func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Department, error) {
tx := repo.transactionContext.PgTx
var dparmentModel []models.Department
query := tx.Model(&dparmentModel).
Limit(20)
dparmentModel := []models.Department{}
query := tx.Model(&dparmentModel).Where("delete_at isnull")
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
... ...
... ... @@ -3,13 +3,14 @@ package repository
import (
"errors"
"fmt"
"time"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
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"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"time"
)
type EvaluationCycleRepository struct {
... ... @@ -133,6 +134,16 @@ func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{})
query.Offset(v)
}
if v, ok := queryOptions["timeStart"]; ok {
t := v.(time.Time)
query.Where("time_start<=?", t)
}
if v, ok := queryOptions["timeEnd"]; ok {
t := v.(time.Time)
query.Where("time_end>=?", t)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
... ... @@ -58,9 +58,14 @@ func (repo *EvaluationCycleTemplateRepository) Insert(d *domain.EvaluationCycleT
d.Id = id
d.CreatedAt = time.Now()
d.UpdatedAt = d.CreatedAt
// 模板对象ID也更新
if d.Template != nil {
d.Template.Id = id
}
} else {
d.UpdatedAt = time.Now()
}
m := repo.TransformToModel(d)
tx := repo.transactionContext.PgTx
var err error
... ...
... ... @@ -123,6 +123,10 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{})
query.Where("name LIKE ? or remark LIKE ?", v, v)
}
if v, ok := queryOptions["ids"]; ok {
query.Where("id in(?)", pg.In(v))
}
if v, ok := queryOptions["name"]; ok {
query.Where("name = ?", v)
}
... ... @@ -131,6 +135,14 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{})
query.Where("company_id = ?", v)
}
if v, ok := queryOptions["creatorId"]; ok && v.(int64) > 0 {
query.Where("creator_id = ?", v)
}
if v, ok := queryOptions["type"]; ok && v.(int) >= 0 {
query.Where("type = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
... ...
... ... @@ -125,6 +125,10 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
query.Where("id in(?)", pg.In(v))
}
if v, ok := queryOptions["notId"]; ok {
query.Where("id != ?", v)
}
if v, ok := queryOptions["name"]; ok && len(v.(string)) > 0 {
query.Where("name LIKE ?", v)
}
... ... @@ -133,10 +137,14 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
query.Where("company_id = ?", v)
}
if v, ok := queryOptions["state"]; ok {
if v, ok := queryOptions["state"]; ok && v.(int) >= 0 {
query.Where("state = ?", v)
}
if v, ok := queryOptions["createdAt"]; ok {
query.Where("created_at = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
... ...
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 NewStaffAssessContentRepository(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)
}
if v, ok := queryOptions["staffAssessId"]; ok {
query.Where("staff_assess_id=?", 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,
EvaluationProjectName: d.EvaluationProjectName,
CycleId: d.CycleId,
CycleName: d.CycleName,
StaffAssessTaskId: d.StaffAssessTaskId,
TargetUser: d.TargetUser,
TargetDepartment: d.TargetDepartment,
Executor: d.Executor,
Types: domain.StaffAssessType(d.Types),
LinkNodeId: d.LinkNodeId,
LinkNodeName: d.LinkNodeName,
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,
EvaluationProjectName: d.EvaluationProjectName,
CycleId: d.CycleId,
CycleName: d.CycleName,
StaffAssessTaskId: d.StaffAssessTaskId,
TargetUser: d.TargetUser,
TargetDepartment: d.TargetDepartment,
Executor: d.Executor,
Types: string(d.Types),
LinkNodeId: d.LinkNodeId,
LinkNodeName: d.LinkNodeName,
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")
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)
}
if v, ok := queryOptions["targetUserId"].(int); ok && v > 0 {
query.Where(`target_user->>'userId'='?'`, v)
}
if v, ok := queryOptions["executorId"].(int); ok && v > 0 {
query.Where(`executor->>'userId'='?'`, v)
}
if v, ok := queryOptions["cycleId"].(int64); ok && v > 0 {
query.Where(`cycle_id=?`, v)
}
if v, ok := queryOptions["staffAssessTaskId"]; ok {
query.Where(`staff_assess_task_id=?`, v)
}
if v, ok := queryOptions["typesList"].([]string); ok && len(v) > 0 {
query.Where("types in(?)", pg.In(v))
}
if v, ok := queryOptions["status"].(string); ok && len(v) > 0 {
query.Where("status=?", 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,
EvaluationProjectName: d.EvaluationProjectName,
CycleId: d.CycleId,
CycleName: d.CycleName,
BeginTime: d.BeginTime,
EndTime: d.EndTime,
StepList: d.StepList,
ExecutorId: d.ExecutorId,
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,
EvaluationProjectName: d.EvaluationProjectName,
CycleId: d.CycleId,
CycleName: d.CycleName,
ExecutorId: d.ExecutorId,
StepList: d.StepList,
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 *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)
}
if v, ok := queryOptions["executorId"].(int); ok && v > 0 {
query.Where(`executor_id @>'[?]'`, 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
}
... ...
... ... @@ -77,7 +77,7 @@ func (repo *UserRepository) Remove(userId []int64) error {
func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domain.User, error) {
tx := repo.transactionContext.PgTx
userModel := models.User{}
query := tx.Model(&userModel)
query := tx.Model(&userModel).Where("deleted_at isnull")
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
... ...
... ... @@ -12,14 +12,17 @@ type CycleController struct {
beego.BaseController
}
func (controller *RoleController) CreateCycle() {
func (controller *CycleController) CreateCycle() {
ruService := service.NewEvaluationCycleService()
in := &command.CreateCycleCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ... @@ -30,7 +33,9 @@ func (controller *CycleController) UpdateCycle() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Update(in))
}
}
... ... @@ -65,7 +70,20 @@ func (controller *CycleController) ListCycle() {
if len(in.Name) > 0 {
in.Name = "%" + in.Name + "%"
}
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
controller.Response(ruService.List(in))
}
}
func (controller *CycleController) StatisticCycleUser() {
ruService := service.NewEvaluationCycleService()
in := &command.StatisticCycleProjectUserCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
controller.Response(ruService.StatisticCycleUser(in))
}
}
... ...
... ... @@ -12,14 +12,17 @@ type ProjectController struct {
beego.BaseController
}
func (controller *RoleController) CreateProject() {
func (controller *ProjectController) CreateProject() {
ruService := service.NewEvaluationProjectService()
in := &command.CreateProjectCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ... @@ -30,7 +33,9 @@ func (controller *ProjectController) UpdateProject() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Update(in))
}
}
... ... @@ -41,22 +46,13 @@ func (controller *ProjectController) UpdateProjectForTemplate() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.UpdateTemplate(in))
}
}
func (controller *ProjectController) UpdateProjectForTemplateNode() {
ruService := service.NewEvaluationProjectService()
in := &command.UpdateProjectTemplateNodeCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.UpdateTemplateNode(in))
}
}
func (controller *ProjectController) GetProject() {
ruService := service.NewEvaluationProjectService()
in := &command.GetProjectCommand{}
... ... @@ -88,18 +84,20 @@ func (controller *ProjectController) ListProject() {
if len(in.Name) > 0 {
in.Name = "%" + in.Name + "%"
}
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
}
func (controller *ProjectController) StateProject() {
func (controller *ProjectController) ActivateProject() {
ruService := service.NewEvaluationProjectService()
in := &command.StateProjectCommand{}
in := &command.ActivateProjectCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
controller.Response(ruService.State(in))
controller.Response(ruService.Activate(in))
}
}
... ... @@ -109,17 +107,20 @@ func (controller *ProjectController) CopyProject() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
ua := middlewares.GetUser(controller.Ctx)
in.CreatorId = ua.UserId
controller.Response(ruService.Copy(in))
}
}
func (controller *ProjectController) StatisticCycleUser() {
func (controller *ProjectController) CheckRecipients() {
ruService := service.NewEvaluationProjectService()
in := &command.StatisticCycleProjectUserCommand{}
in := &command.CheckRecipientCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.StatisticCycleUser(in))
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
controller.Response(ruService.CheckRecipients(in))
}
}
... ...
... ... @@ -12,14 +12,17 @@ type RuleController struct {
beego.BaseController
}
func (controller *RoleController) CreateRule() {
func (controller *RuleController) CreateRule() {
ruService := service.NewEvaluationRuleService()
in := &command.CreateRuleCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ... @@ -30,8 +33,11 @@ func (controller *RuleController) UpdateRule() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Update(in))
}
}
... ... @@ -57,27 +63,34 @@ func (controller *RuleController) RemoveRule() {
}
}
func (controller *RuleController) ListRule() {
//func (controller *RuleController) ListRule() {
// ruService := service.NewEvaluationRuleService()
// in := &command.QueryRuleCommand{}
// in.Type = -1
// if err := controller.Unmarshal(in); err != nil {
// controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
// } else {
// if len(in.NameOrRemark) > 0 {
// in.NameOrRemark = "%" + in.NameOrRemark + "%"
// }
// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
// controller.Response(ruService.List(in))
// }
//}
func (controller *RuleController) ListRuleRelCreator() {
ruService := service.NewEvaluationRuleService()
in := &command.QueryRuleCommand{}
in.Type = -1
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
if len(in.NameOrRemark) > 0 {
in.NameOrRemark = "%" + in.NameOrRemark + "%"
}
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
}
func (controller *RuleController) ListRuleRelCreator() {
ruService := service.NewEvaluationRuleService()
in := &command.QueryRuleCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListRelCreator(in))
}
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"github.com/linmadan/egglib-go/web/beego"
service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
... ... @@ -12,14 +13,17 @@ type TemplateController struct {
beego.BaseController
}
func (controller *RoleController) CreateTemplate() {
func (controller *TemplateController) CreateTemplate() {
ruService := service.NewEvaluationTemplateService()
in := &command.CreateTemplateCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ... @@ -30,7 +34,9 @@ func (controller *TemplateController) UpdateTemplate() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Update(in))
}
}
... ... @@ -59,25 +65,33 @@ func (controller *TemplateController) RemoveTemplate() {
func (controller *TemplateController) ListTemplate() {
ruService := service.NewEvaluationTemplateService()
in := &command.QueryTemplateCommand{}
in.State = -1
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
if len(in.Name) > 0 {
in.Name = "%" + in.Name + "%"
}
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
}
func (controller *TemplateController) ListEnableTemplate() {
ruService := service.NewEvaluationTemplateService()
in := &command.AllEnableTemplateCommand{}
in := &command.QueryTemplateCommand{}
in.State = domain.TemplateStateEnable
in.PageNumber = 1
in.PageSize = 999999
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListForEnable(in))
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
}
... ... @@ -87,6 +101,9 @@ func (controller *TemplateController) StateTemplate() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.State(in))
}
}
... ... @@ -97,6 +114,11 @@ func (controller *TemplateController) CopyTemplate() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Copy(in))
}
}
... ...
package controllers
import (
"github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/server/web/context"
)
type HelloController struct {
web.Controller
}
func (c *HelloController) Say() {
c.JSONResp(map[string]string{
"msg": "hello",
})
}
func SayHello(c *context.Context) {
c.JSONResp(map[string]string{
"msg": "hello",
})
}
... ... @@ -12,35 +12,48 @@ type RoleController struct {
beego.BaseController
}
func (controller *RoleController) CreateRole() {
ruService := service.NewRoleService()
in := &command.CreateRoleCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
func (controller *RoleController) UpdateRole() {
ruService := service.NewRoleService()
in := &command.UpdateRoleCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Update(in))
}
}
//func (controller *RoleController) CreateRole() {
// ruService := service.NewRoleService()
// in := &command.CreateRoleCommand{}
// if err := controller.Unmarshal(in); err != nil {
// controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
// } else {
// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
// controller.Response(ruService.Create(in))
// }
//}
//
//func (controller *RoleController) UpdateRole() {
// ruService := service.NewRoleService()
// in := &command.UpdateRoleCommand{}
// if err := controller.Unmarshal(in); err != nil {
// controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
// } else {
// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
// controller.Response(ruService.Update(in))
// }
//}
//
//func (controller *RoleController) RemoveRole() {
// ruService := service.NewRoleService()
// in := &command.DeleteRoleCommand{}
// if err := controller.Unmarshal(in); err != nil {
// controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
// } else {
// in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
// controller.Response(ruService.Remove(in))
// }
//}
func (controller *RoleController) RemoveRole() {
func (controller *RoleController) ListForUserRole() {
ruService := service.NewRoleService()
in := &command.DeleteRoleCommand{}
in := &command.QueryRoleUserCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Remove(in))
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListForUser(in))
}
}
... ...
... ... @@ -18,7 +18,9 @@ func (controller *RoleUserController) CreateRoleUser() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ... @@ -29,7 +31,22 @@ func (controller *RoleUserController) RemoveRoleUser() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Remove(in))
}
}
func (controller *RoleUserController) ListRoleUser() {
ruService := service.NewRoleUserService()
in := &command.UserRoleQueryCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListRole(in))
}
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/service"
)
type StaffAssessController struct {
beego.BaseController
}
// 获取我的绩效任务列表
func (c *StaffAssessController) SearchAssessTaskMe() {
srv := service.NewStaffAssessServeice()
paramReq := &query.SearchAssessMeQuery{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
//TODO 获取当前用户信息
paramReq.CompanyId = 1
paramReq.UserId = 1
data, err := srv.SearchAssessTaskMe(paramReq)
c.Response(data, err)
}
// 获取我的绩效任务各环节完成情况
func (c *StaffAssessController) AssessTaskMeDesc() {
srv := service.NewStaffAssessServeice()
paramReq := &query.AssessTaskDescQuery{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
//TODO 获取当前用户信息
paramReq.CompanyId = 1
paramReq.UserId = 1
data, err := srv.AssessTaskDesc(paramReq)
c.Response(data, err)
}
// 获取个人的自评反馈历史记录列表
func (c *StaffAssessController) AssessSelfMeList() {
srv := service.NewStaffAssessServeice()
paramReq := &query.AssessSelfListQuery{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
//TODO 获取当前用户信息
paramReq.CompanyId = 1
paramReq.UserId = 1
data, err := srv.AssessSelfList(paramReq)
c.Response(data, err)
}
// 更具项目评估的配置,创建员工的评估任务,(调试用)
func (c *StaffAssessController) CreateStaffAssessTask() {
srv := service.NewStaffAssessServeice()
paramReq := &command.CreateStaffAssessTask{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
//服务调用,实际由定时任务触发
data, err := srv.CreateStaffAssessTask(paramReq)
c.Response(data, err)
}
//获取员工自评详情
//保存员工自评填写内容
//获取员工邀请的人
//保持员工邀请的人
... ...
... ... @@ -6,6 +6,14 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
func GetUser(ctx *context.Context) *domain.UserAuth {
user := ctx.Input.GetData(domain.UserAuth{})
if user != nil {
return user.(*domain.UserAuth)
}
return nil
}
func CheckAdminToken() func(ctx *context.Context) {
return func(ctx *context.Context) {
adminToken := ctx.Input.Header("x-admin-token")
... ...
package middlewares
import (
"github.com/beego/beego/v2/server/web/context"
)
func setUserId(userId int64, ctx *context.Context) {
ctx.Input.SetData("_UserId", userId)
}
func GetUserId(ctx *context.Context) int64 {
userId := ctx.Input.GetData("_UserId")
return userId.(int64)
}
func setCompanyId(companyId int64, ctx *context.Context) {
ctx.Input.SetData("_CompanyId", companyId)
}
func GetCompanyId(ctx *context.Context) int64 {
companyId := ctx.Input.GetData("_CompanyId")
return companyId.(int64)
}
func setCompanyType(companyId int, ctx *context.Context) {
ctx.Input.SetData("_CompanyType", companyId)
}
func GetCompanyType(ctx *context.Context) int {
companyId := ctx.Input.GetData("_CompanyType")
return companyId.(int)
}
func invalidOrExpired(ctx *context.Context) {
resp := map[string]interface{}{
"code": 902,
"msg": "Authorization过期或无效,需要进行重新获取令牌",
}
_ = ctx.Output.JSON(resp, false, false)
}
func CheckToken() func(ctx *context.Context) {
return func(ctx *context.Context) {
tokenStr := ctx.Input.Header("x-mmm-accesstoken")
if tokenStr == "" { //没有带token
invalidOrExpired(ctx)
return
}
//userServe := service.UserService{}
//userTk, err := userServe.ValidLoginToken(tokenStr)
//if err != nil {
// invalidOrExpired(ctx)
// return
//}
//setUserId(userTk.UserId, ctx)
//setCompanyId(userTk.CompanyId, ctx)
//setCompanyType(userTk.CompanyType, ctx)
}
}
//
//import (
// "github.com/beego/beego/v2/server/web/context"
//)
//
//func setUserId(userId int64, ctx *context.Context) {
// ctx.Input.SetData("_UserId", userId)
//}
//
//func GetUserId(ctx *context.Context) int64 {
// userId := ctx.Input.GetData("_UserId")
// return userId.(int64)
//}
//
//func setCompanyId(companyId int64, ctx *context.Context) {
// ctx.Input.SetData("_CompanyId", companyId)
//}
//
//func GetCompanyId(ctx *context.Context) int64 {
// companyId := ctx.Input.GetData("_CompanyId")
// return companyId.(int64)
//}
//
//func setCompanyType(companyId int, ctx *context.Context) {
// ctx.Input.SetData("_CompanyType", companyId)
//}
//
//func GetCompanyType(ctx *context.Context) int {
// companyId := ctx.Input.GetData("_CompanyType")
// return companyId.(int)
//}
//
//func invalidOrExpired(ctx *context.Context) {
// resp := map[string]interface{}{
// "code": 902,
// "msg": "Authorization过期或无效,需要进行重新获取令牌",
// }
// _ = ctx.Output.JSON(resp, false, false)
//}
//
//func CheckToken() func(ctx *context.Context) {
// return func(ctx *context.Context) {
// tokenStr := ctx.Input.Header("x-mmm-accesstoken")
// if tokenStr == "" { //没有带token
// invalidOrExpired(ctx)
// return
// }
//
// //userServe := service.UserService{}
// //userTk, err := userServe.ValidLoginToken(tokenStr)
// //if err != nil {
// // invalidOrExpired(ctx)
// // return
// //}
// //setUserId(userTk.UserId, ctx)
// //setCompanyId(userTk.CompanyId, ctx)
// //setCompanyType(userTk.CompanyType, ctx)
// }
//}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/evaluation-cycle",
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSRouter("/", &controllers.CycleController{}, "Post:CreateCycle"),
web.NSRouter("/", &controllers.CycleController{}, "Put:UpdateCycle"),
web.NSRouter("/", &controllers.CycleController{}, "Delete:RemoveCycle"),
web.NSRouter("/:Id", &controllers.CycleController{}, "Get:GetCycle"),
web.NSRouter("/list", &controllers.CycleController{}, "Post:ListCycle"),
web.NSRouter("/statistic", &controllers.CycleController{}, "Post:StatisticCycleUser"),
)
web.AddNamespace(ns)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/evaluation-project",
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSRouter("/", &controllers.ProjectController{}, "Post:CreateProject"),
web.NSRouter("/", &controllers.ProjectController{}, "Put:UpdateProject"),
web.NSRouter("/", &controllers.ProjectController{}, "Delete:RemoveProject"),
web.NSRouter("/:Id", &controllers.ProjectController{}, "Get:GetProject"),
web.NSRouter("/list", &controllers.ProjectController{}, "Post:ListProject"),
web.NSRouter("/detail", &controllers.ProjectController{}, "Put:UpdateProjectForTemplate"),
web.NSRouter("/check-recipients", &controllers.ProjectController{}, "Post:CheckRecipients"),
web.NSRouter("/copy", &controllers.ProjectController{}, "Post:CopyProject"),
web.NSRouter("/activate", &controllers.ProjectController{}, "Post:ActivateProject"),
)
web.AddNamespace(ns)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/evaluation-rule",
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSRouter("/", &controllers.RuleController{}, "Post:CreateRule"),
web.NSRouter("/", &controllers.RuleController{}, "Put:UpdateRule"),
web.NSRouter("/", &controllers.RuleController{}, "Delete:RemoveRule"),
web.NSRouter("/:Id", &controllers.RuleController{}, "Get:GetRule"),
web.NSRouter("/list", &controllers.RuleController{}, "Post:ListRuleRelCreator"),
)
web.AddNamespace(ns)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/evaluation-template",
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSRouter("/", &controllers.TemplateController{}, "Post:CreateTemplate"),
web.NSRouter("/", &controllers.TemplateController{}, "Put:UpdateTemplate"),
web.NSRouter("/", &controllers.TemplateController{}, "Delete:RemoveTemplate"),
web.NSRouter("/:Id", &controllers.TemplateController{}, "Get:GetTemplate"),
web.NSRouter("/list", &controllers.TemplateController{}, "Post:ListTemplate"),
web.NSRouter("/list-enable", &controllers.TemplateController{}, "Post:ListEnableTemplate"),
)
web.AddNamespace(ns)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/role",
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
//web.NSRouter("/", &controllers.RoleController{}, "Post:CreateRole"),
//web.NSRouter("/", &controllers.RoleController{}, "Put:UpdateRole"),
//web.NSRouter("/", &controllers.RoleController{}, "Delete:RemoveRole"),
//web.NSRouter("/:Id", &controllers.RoleController{}, "Get:GetRole"),
web.NSRouter("/all", &controllers.RoleController{}, "Post:ListForUserRole"),
)
web.AddNamespace(ns)
}
... ...
... ... @@ -2,14 +2,17 @@ package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
h1 := web.NewNamespace("/v1/demo",
web.NSCtrlGet("/hello", (*controllers.HelloController).Say),
web.NSCtrlGet("/hello2", (*controllers.HelloController).Say),
// web.NSGet("/hello1", controllers.SayHello),
ns := web.NewNamespace("/v1/role-user",
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSRouter("/", &controllers.RoleUserController{}, "Post:CreateRoleUser"),
web.NSRouter("/", &controllers.RoleUserController{}, "Delete:RemoveRoleUser"),
web.NSRouter("/all", &controllers.RoleUserController{}, "Post:ListRoleUser"),
)
web.AddNamespace(h1)
web.AddNamespace(ns)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
)
func init() {
assessTaskNS := web.NewNamespace("/v1/staff-assess-task",
// web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
web.NSCtrlPost("/search/me", (*controllers.StaffAssessController).SearchAssessTaskMe), //获取我参与过的评估项目列表
web.NSCtrlPost("/desc/me", (*controllers.StaffAssessController).AssessTaskMeDesc), //获取我的项目评估进度描述
web.NSCtrlPost("/", (*controllers.StaffAssessController).CreateStaffAssessTask), //创建员工的评估任务
)
// /v1/staff-assess/self/me/list
assessNS := web.NewNamespace("/v1/staff-assess",
// web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
web.NSCtrlPost("/self/me/list", (*controllers.StaffAssessController).AssessSelfMeList), //获取我的自评反馈列表
// web.NSCtrlPost("/self/me/info", (*controllers.StaffAssessController).AssessSelfMeList),
)
web.AddNamespace(assessTaskNS)
web.AddNamespace(assessNS)
}
... ...