作者 tangxvhui
... ... @@ -2,8 +2,8 @@ package command
type EditEvaluationValue struct {
SummaryEvaluationId int `json:"summaryEvaluationId,string"`
ExecutorId int `json:"-"` //执行人id
CompanyId int `json:"-"` //公司id
ExecutorId int `json:"-"` // 执行人id
CompanyId int `json:"-"` // 公司id
EvaluationItems []struct {
Value string `json:"value"`
Remark string `json:"remark"`
... ...
... ... @@ -5,3 +5,13 @@ type QueryEvaluationInfo struct {
ExecutorId int `json:"executorId,string"` //执行人id
CompanyId int `json:"-"` //公司id
}
type QueryEvaluation360 struct {
SummaryEvaluationId int `json:"summaryEvaluationId,string"`
UserId int `json:"-"` // 用户ID
}
type QueryEvaluationHRBP struct {
SummaryEvaluationId int `json:"summaryEvaluationId,string"`
UserId int `json:"-"` // 用户ID
}
... ...
... ... @@ -241,8 +241,7 @@ func (srv *SummaryEvaluationService) GetMenu(param *command.QueryMenu) (map[stri
}
// buildSummaryItemValue 将填写值填充进评估项
func (srv *SummaryEvaluationService) buildSummaryItemValue(itemList []*domain.EvaluationItemUsed, valueList []*domain.SummaryEvaluationValue) (
itemValues []adapter.EvaluationItemAdapter) {
func (srv *SummaryEvaluationService) buildSummaryItemValue(itemList []*domain.EvaluationItemUsed, valueList []*domain.SummaryEvaluationValue) (itemValues []adapter.EvaluationItemAdapter) {
itemValues = []adapter.EvaluationItemAdapter{}
valueMap := map[int]*domain.SummaryEvaluationValue{}
for _, v := range valueList {
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"time"
)
// GetEvaluation360 获取360综评详情
func (srv *SummaryEvaluationService) GetEvaluation360(param *command.QueryEvaluation360) (*adapter.EvaluationInfoAdapter, error) {
transactionContext, err := factory.ValidateStartTransaction(param)
if err != nil {
return nil, err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
sEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 自评评估内容(自评模板、筛选项目评估人)
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
"evaluationProjectId": sEvaluation.EvaluationProjectId,
"nodeType": domain.LinkNodeSelfAssessment,
"evaluatorId": param.UserId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 评估内容对应的分数
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": sEvaluation.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())
}
itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
result := adapter.EvaluationInfoAdapter{
SummaryEvaluationId: sEvaluation.Id,
CycleId: int(sEvaluation.CycleId),
CycleName: sEvaluation.CycleName,
EvaluationProjectId: sEvaluation.EvaluationProjectId,
EvaluationProjectName: sEvaluation.EvaluationProjectName,
LinkNodeId: sEvaluation.NodeId,
BeginTime: sEvaluation.BeginTime.Format("2006-01-02 15:04:05"),
EndTime: sEvaluation.EndTime.Format("2006-01-02 15:04:05"),
TargetUserId: sEvaluation.TargetUser.UserId,
TargetUserName: sEvaluation.TargetUser.UserName,
Status: string(sEvaluation.Status),
EvaluationItems: itemValuesAdapter,
}
return &result, nil
}
// EditEvaluation360 编辑提交360综评
func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, 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()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
summaryEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if summaryEvaluation.Executor.UserId != param.ExecutorId {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
if summaryEvaluation.CompanyId != param.CompanyId {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
// 自评评估内容(自评模板、筛选项目评估人)
_, itemList, err := itemUsedRepo.Find(map[string]interface{}{
"evaluationProjectId": summaryEvaluation.EvaluationProjectId,
"nodeType": domain.LinkNodeSelfAssessment,
"evaluatorId": param.ExecutorId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 评估内容对应的分数
_, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": summaryEvaluation.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
for _, v := range itemList {
newValue := &domain.SummaryEvaluationValue{}
newValue.SetBlankValue(summaryEvaluation, v)
evaluationValueMap[v.Id] = newValue
}
for _, v := range itemValueList {
if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
mValue.Id = v.Id
}
}
nowTime := time.Now()
for _, v := range param.EvaluationItems {
updatedData, ok := evaluationValueMap[v.EvaluationItemId]
if !ok {
continue
}
updatedData.UpdatedAt = nowTime
updatedData.Value = v.Value
updatedData.Remark = v.Remark
//计算得分
err = updatedData.SummaryEvaluationScore()
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
evaluationValueList := make([]*domain.SummaryEvaluationValue, 0)
for _, v := range evaluationValueMap {
//保存填写值
err = itemValueRepo.Save(v)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationValueList = append(evaluationValueList, v)
}
//计算总得分
err = summaryEvaluation.EvaluationTotalScore(evaluationValueList)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
summaryEvaluation.UpdatedAt = nowTime
//保存填写值
err = evaluationRepo.Save(summaryEvaluation)
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())
}
itemValueAdapter := srv.buildSummaryItemValue(itemList, evaluationValueList)
return map[string][]adapter.EvaluationItemAdapter{
"evaluationItems": itemValueAdapter,
}, nil
}
// GetEvaluationHRBP 获取人资综评详情
func (srv *SummaryEvaluationService) GetEvaluationHRBP(param *command.QueryEvaluationHRBP) (*adapter.EvaluationInfoAdapter, error) {
transactionContext, err := factory.ValidateStartTransaction(param)
if err != nil {
return nil, err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
sEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 自评评估内容(自评模板、筛选项目评估人)
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
"evaluationProjectId": sEvaluation.EvaluationProjectId,
"nodeType": domain.LinkNodeSelfAssessment,
"evaluatorId": -1,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 评估内容对应的分数
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": sEvaluation.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())
}
itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
result := adapter.EvaluationInfoAdapter{
SummaryEvaluationId: sEvaluation.Id,
CycleId: int(sEvaluation.CycleId),
CycleName: sEvaluation.CycleName,
EvaluationProjectId: sEvaluation.EvaluationProjectId,
EvaluationProjectName: sEvaluation.EvaluationProjectName,
LinkNodeId: sEvaluation.NodeId,
BeginTime: sEvaluation.BeginTime.Format("2006-01-02 15:04:05"),
EndTime: sEvaluation.EndTime.Format("2006-01-02 15:04:05"),
TargetUserId: sEvaluation.TargetUser.UserId,
TargetUserName: sEvaluation.TargetUser.UserName,
Status: string(sEvaluation.Status),
EvaluationItems: itemValuesAdapter,
}
return &result, nil
}
// EditEvaluationHRBP 编辑提交人资综评
func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, 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()
}()
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
// 必须是HRBP权限的人才能编辑操作
hrbp, err := service.GetHRBP(transactionContext, param.CompanyId, param.ExecutorId)
if hrbp != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
summaryEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if summaryEvaluation.Types != domain.EvaluationHrbp {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
if summaryEvaluation.CompanyId != param.CompanyId {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
// 自评评估内容(自评模板、筛选项目评估人)
_, itemList, err := itemUsedRepo.Find(map[string]interface{}{
"evaluationProjectId": summaryEvaluation.EvaluationProjectId,
"nodeType": domain.LinkNodeSelfAssessment,
"evaluatorId": -1,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 评估内容对应的分数
_, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": summaryEvaluation.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
for _, v := range itemList {
newValue := &domain.SummaryEvaluationValue{}
newValue.SetBlankValue(summaryEvaluation, v)
evaluationValueMap[v.Id] = newValue
}
for _, v := range itemValueList {
if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
mValue.Id = v.Id
}
}
nowTime := time.Now()
for _, v := range param.EvaluationItems {
updatedData, ok := evaluationValueMap[v.EvaluationItemId]
if !ok {
continue
}
updatedData.UpdatedAt = nowTime
updatedData.Value = v.Value
updatedData.Remark = v.Remark
//计算得分
err = updatedData.SummaryEvaluationScore()
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
evaluationValueList := make([]*domain.SummaryEvaluationValue, 0)
for _, v := range evaluationValueMap {
//保存填写值
err = itemValueRepo.Save(v)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationValueList = append(evaluationValueList, v)
}
//计算总得分
err = summaryEvaluation.EvaluationTotalScore(evaluationValueList)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 针对HRBP类型,更新最后一次操作的HRBP人
user, err := userRepo.FindOne(map[string]interface{}{"id": param.ExecutorId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
summaryEvaluation.Executor.UserId = param.ExecutorId
summaryEvaluation.Executor.Account = user.Account
summaryEvaluation.Executor.UserName = user.Name
summaryEvaluation.Executor.CompanyName = "" // 暂时无用
summaryEvaluation.UpdatedAt = nowTime
//保存填写值
err = evaluationRepo.Save(summaryEvaluation)
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())
}
itemValueAdapter := srv.buildSummaryItemValue(itemList, evaluationValueList)
return map[string][]adapter.EvaluationItemAdapter{
"evaluationItems": itemValueAdapter,
}, nil
}
... ...
... ... @@ -41,16 +41,24 @@ func (itemValue *SummaryEvaluationValue) SummaryEvaluationScore() error {
return nil
}
func (item *SummaryEvaluationValue) SumScore(weight float64, value string) (float64, error) {
if item.Weight == 0 {
func (itemValue *SummaryEvaluationValue) SumScore(weight float64, value string) (float64, error) {
if itemValue.Types == EvaluationHrbp {
valueFloat, err := strconv.ParseFloat(itemValue.Value, 64)
if err != nil {
return 0, fmt.Errorf("条目%d系数值异常,%s", itemValue.Id, itemValue.Value)
}
return valueFloat, nil
}
if itemValue.Weight == 0 {
return 0, nil
}
valueFloat, err := strconv.ParseFloat(item.Value, 64)
valueFloat, err := strconv.ParseFloat(itemValue.Value, 64)
if err != nil {
return 0, fmt.Errorf("条目%d系数值异常,%s", item.Id, item.Value)
return 0, fmt.Errorf("条目%d系数值异常,%s", itemValue.Id, itemValue.Value)
}
//计算方式
score := item.Weight * valueFloat
score := itemValue.Weight * valueFloat
return score, nil
}
... ...
... ... @@ -86,7 +86,11 @@ func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface
}
if v, ok := queryOptions["nodeType"]; ok {
query.Where(" node_type=?", v)
query.Where("node_type=?", v)
}
if v, ok := queryOptions["evaluatorId"]; ok {
query.Where("evaluator_id=?", v)
}
count, err := query.SelectAndCount()
... ...
... ... @@ -92,3 +92,65 @@ func (c *SummaryEvaluationController) GetTargetUserCycleList() {
data, err := srv.GetTargetUserCycleList(paramReq)
c.Response(data, err)
}
func (c *SummaryEvaluationController) GetEvaluation360() {
srv := service.NewSummaryEvaluationService()
in := &command.QueryEvaluation360{}
err := c.BindJSON(in)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
in.UserId = int(userReq.UserId)
data, err := srv.GetEvaluation360(in)
c.Response(data, err)
}
func (c *SummaryEvaluationController) EditEvaluation360() {
srv := service.NewSummaryEvaluationService()
in := &command.EditEvaluationValue{}
err := c.BindJSON(in)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
in.CompanyId = int(userReq.CompanyId)
in.ExecutorId = int(userReq.UserId)
data, err := srv.EditEvaluation360(in)
c.Response(data, err)
}
func (c *SummaryEvaluationController) GetEvaluationHRBP() {
srv := service.NewSummaryEvaluationService()
in := &command.QueryEvaluationHRBP{}
err := c.BindJSON(in)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
in.UserId = int(userReq.UserId)
data, err := srv.GetEvaluationHRBP(in)
c.Response(data, err)
}
func (c *SummaryEvaluationController) EditEvaluationHRBP() {
srv := service.NewSummaryEvaluationService()
in := &command.EditEvaluationValue{}
err := c.BindJSON(in)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
in.CompanyId = int(userReq.CompanyId)
in.ExecutorId = int(userReq.UserId)
data, err := srv.EditEvaluationHRBP(in)
c.Response(data, err)
}
... ...
... ... @@ -15,6 +15,10 @@ func init() {
web.NSCtrlPost("/cycle/menu", (*controllers.SummaryEvaluationController).GetMenu),
web.NSCtrlPost("/self", (*controllers.SummaryEvaluationController).GetEvaluationSelf),
web.NSCtrlPost("/self/edit", (*controllers.SummaryEvaluationController).EditEvaluationSelf),
web.NSCtrlPost("/evaluation-360", (*controllers.SummaryEvaluationController).GetEvaluation360),
web.NSCtrlPost("/evaluation-360/edit", (*controllers.SummaryEvaluationController).EditEvaluation360),
web.NSCtrlPost("/evaluation-hr", (*controllers.SummaryEvaluationController).GetEvaluationHRBP),
web.NSCtrlPost("/evaluation-hr/edit", (*controllers.SummaryEvaluationController).EditEvaluationHRBP),
)
web.AddNamespace(summaryNS)
}
... ...