作者 郑周

新建项目逻辑补充

... ... @@ -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) {
}
... ...
... ... @@ -280,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
}
... ...
... ... @@ -72,7 +72,18 @@ func (controller *CycleController) ListCycle() {
}
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
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))
}
}
... ...
... ... @@ -53,19 +53,6 @@ func (controller *ProjectController) UpdateProjectForTemplate() {
}
}
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 {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.UpdateTemplateNode(in))
}
}
func (controller *ProjectController) GetProject() {
ruService := service.NewEvaluationProjectService()
in := &command.GetProjectCommand{}
... ... @@ -106,11 +93,11 @@ func (controller *ProjectController) ListProject() {
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))
}
}
... ... @@ -120,19 +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 {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.StatisticCycleUser(in))
controller.Response(ruService.CheckRecipients(in))
}
}
... ...
... ... @@ -15,6 +15,7 @@ func init() {
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)
}
... ...