作者 Your Name
... ... @@ -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) {
}
... ...
... ... @@ -62,6 +62,9 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
ctAdapter := &adapter.CycleTemplateAdapter{}
ctAdapter.EvaluationCycle = cycle
for i := range templates {
v := templates[i]
cycleTemplate := &domain.EvaluationCycleTemplate{
... ... @@ -74,12 +77,18 @@ 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: v.Id,
Name: v.Name,
CreatedAt: v.CreatedAt,
})
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cycle, nil
return ctAdapter, nil
}
... ... @@ -166,10 +175,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) {
... ... @@ -255,3 +280,51 @@ func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface
}
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())
}
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)
... ... @@ -290,7 +293,7 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter
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
... ... @@ -300,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())
... ... @@ -332,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
... ... @@ -346,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
... ... @@ -354,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
}
... ...
... ... @@ -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:"考核周期(1日、2周、3月)"`
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:"删除时间"`
... ...
... ... @@ -24,16 +24,6 @@ const (
)
const (
KpiCycleDay int = 1 // 考核周期-日
KpiCycleWeek int = 2 // 考核周期-周
KpiCycleOneMonth int = 3 // 考核周期-月
KpiCycleTwoMonth int = 4 // 考核周期-双月
KpiCycleThreeMonth int = 5 // 考核周期-季度
KpiCycleSixMonth int = 6 // 考核周期-半年
KpiCycleYear int = 7 // 考核周期-年
)
type EntryItem struct {
Title string `json:"title" comment:"填写标题"`
HintText string `json:"hintText" comment:"文本内容提示"`
... ...
... ... @@ -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() {
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))
}
}
... ...
... ... @@ -18,8 +18,11 @@ func (controller *RuleController) CreateRule() {
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))
}
}
... ... @@ -82,7 +88,9 @@ func (controller *RuleController) ListRuleRelCreator() {
if len(in.NameOrRemark) > 0 {
in.NameOrRemark = "%" + in.NameOrRemark + "%"
}
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))
}
}
... ...
... ... @@ -13,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))
}
}
... ... @@ -31,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))
}
}
... ... @@ -67,7 +72,9 @@ func (controller *TemplateController) ListTemplate() {
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))
}
}
... ... @@ -81,7 +88,9 @@ func (controller *TemplateController) ListEnableTemplate() {
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.List(in))
}
}
... ... @@ -92,7 +101,9 @@ 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)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.State(in))
}
}
... ... @@ -103,8 +114,11 @@ 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)
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))
}
}
... ...
... ... @@ -51,7 +51,9 @@ func (controller *RoleController) ListForUserRole() {
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.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,9 @@ 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))
}
}
... ... @@ -40,7 +44,9 @@ func (controller *RoleUserController) ListRoleUser() {
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.ListRole(in))
}
}
... ...
... ... @@ -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.AddNamespace(ns)
}
... ...
... ... @@ -9,7 +9,7 @@ import (
func init() {
ns := web.NewNamespace("/v1/evaluation-rule",
web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSRouter("/", &controllers.RuleController{}, "Post:CreateRule"),
web.NSRouter("/", &controllers.RuleController{}, "Put:UpdateRule"),
web.NSRouter("/", &controllers.RuleController{}, "Delete:RemoveRule"),
... ...
... ... @@ -9,8 +9,8 @@ import (
func init() {
ns := web.NewNamespace("/v1/evaluation-template",
web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
// web.NSRouter("/", &controllers.TemplateController{}, "Post:CreateTemplate"),
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"),
... ...
... ... @@ -9,7 +9,7 @@ import (
func init() {
ns := web.NewNamespace("/v1/role",
web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
//web.NSRouter("/", &controllers.RoleController{}, "Post:CreateRole"),
//web.NSRouter("/", &controllers.RoleController{}, "Put:UpdateRole"),
//web.NSRouter("/", &controllers.RoleController{}, "Delete:RemoveRole"),
... ...
... ... @@ -3,15 +3,16 @@ 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-user",
web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
// web.NSRouter("/", &controllers.RoleUserController{}, "Post:CreateRole"),
// web.NSRouter("/", &controllers.RoleUserController{}, "Delete:RemoveRole"),
// web.NSRouter("/all", &controllers.RoleUserController{}, "Post:ListRoleUser"),
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(ns)
}
... ...