作者 Your Name
... ... @@ -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
... ...
... ... @@ -188,29 +188,10 @@ func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (int
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(total, 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) {
... ... @@ -255,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())
... ...
... ... @@ -25,9 +25,13 @@ const (
)
const (
KpiCycleDay int = 1 // 考核周期-日
KpiCycleWeek int = 2 // 考核周期-周
KpiCycleMonth int = 3 // 考核周期-月
KpiCycleDay int = 1 // 考核周期-日
KpiCycleWeek int = 2 // 考核周期-周
KpiCycleOneMonth int = 3 // 考核周期-月
KpiCycleTwoMonth int = 4 // 考核周期-双月
KpiCycleThreeMonth int = 5 // 考核周期-季度
KpiCycleSixMonth int = 6 // 考核周期-半年
KpiCycleYear int = 7 // 考核周期-年
)
type EntryItem struct {
... ... @@ -39,17 +43,17 @@ type EntryItem struct {
type NodeContent struct {
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId int64 `json:"ruleId" comment:"评估规则ID"`
RuleId string `json:"ruleId" comment:"评估规则ID"`
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 +61,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:"考核周期(1日、2周、3月)"`
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°邀请人员"`
}
// 评估模板
... ...
... ... @@ -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)
}
... ...
... ... @@ -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"
)
... ... @@ -59,6 +60,7 @@ 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 {
... ... @@ -72,12 +74,15 @@ func (controller *TemplateController) ListTemplate() {
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))
controller.Response(ruService.List(in))
}
}
... ... @@ -87,6 +92,7 @@ func (controller *TemplateController) StateTemplate() {
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.State(in))
}
}
... ... @@ -97,6 +103,8 @@ func (controller *TemplateController) CopyTemplate() {
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)
controller.Response(ruService.Copy(in))
}
}
... ...
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.CheckToken()),
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)
}
... ...