作者 郑周

周期统计项目 人员和部门数量

... ... @@ -7,7 +7,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"strconv"
)
... ... @@ -174,14 +173,13 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf
}
func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{}, error) {
// Get 不需要事务
if err := utils.ValidateCommand(in); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
... ... @@ -204,6 +202,10 @@ func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{},
CreatedAt: cycleTemplates[i].CreatedAt,
})
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return ctAdapter, nil
}
... ... @@ -247,12 +249,8 @@ func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface
transactionContext.RollbackTransaction()
}()
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
inMap := tool_funs.SimpleStructToMap(in)
if len(in.Name) > 0 {
inMap["name"] = "%" + in.Name + "%"
}
// FIXME 总数量是否使用Count获取一个总数量
count, cycles, err := cycleRepository.Find(inMap)
count, cycles, err := cycleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -17,3 +17,12 @@ 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) {
}
... ...
... ... @@ -42,7 +42,7 @@ func (in *UpdateProjectCommand) Valid(validation *validation.Validation) {
func (in *UpdateProjectTemplateCommand) Valid(validation *validation.Validation) {
if len(in.Recipients) == 0 {
validation.SetError("recipients", "请选择被评估人")
validation.SetError("recipients", "请添加被评估人")
return
}
}
... ...
... ... @@ -7,7 +7,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_project/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"strconv"
)
... ... @@ -172,16 +171,14 @@ func (rs *EvaluationProjectService) UpdateTemplateNode(in *command.UpdateProject
}
func (rs *EvaluationProjectService) Get(in *command.GetProjectCommand) (interface{}, error) {
// Get 不需要事务
if err := utils.ValidateCommand(in); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
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})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -201,6 +198,9 @@ func (rs *EvaluationProjectService) Get(in *command.GetProjectCommand) (interfac
projectAdapter.TransformRecipientAdapter(users)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectAdapter, nil
}
... ... @@ -317,3 +317,52 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf
}
return project, nil
}
func (rs *EvaluationProjectService) 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 {
user := users[i]
for _, v := range user.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
}
... ...
... ... @@ -7,7 +7,6 @@ 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"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
)
type EvaluationRuleService struct {
... ... @@ -100,19 +99,22 @@ func (rs *EvaluationRuleService) Update(in *command.UpdateRuleCommand) (interfac
}
func (rs *EvaluationRuleService) Get(in *command.GetRuleCommand) (interface{}, error) {
// Get 不需要事务
if err := utils.ValidateCommand(in); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
rule, err := ruleRepository.FindOne(map[string]interface{}{"id": in.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.TRANSACTION_ERROR, err.Error())
}
return rule, nil
}
... ...
... ... @@ -6,7 +6,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
)
type EvaluationTemplateService struct {
... ... @@ -124,19 +123,22 @@ func (rs *EvaluationTemplateService) Update(in *command.UpdateTemplateCommand) (
}
func (rs *EvaluationTemplateService) Get(in *command.GetTemplateCommand) (interface{}, error) {
// Get 不需要事务
if err := utils.ValidateCommand(in); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
template, err := templateRepository.FindOne(map[string]interface{}{"id": in.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.TRANSACTION_ERROR, err.Error())
}
return template, nil
}
... ...
... ... @@ -112,3 +112,14 @@ func (controller *ProjectController) CopyProject() {
controller.Response(ruService.Copy(in))
}
}
func (controller *ProjectController) StatisticCycleUser() {
ruService := service.NewEvaluationProjectService()
in := &command.StatisticCycleProjectUserCommand{}
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))
}
}
... ...