作者 郑周

Merge remote-tracking branch 'origin/test' into test

# Conflicts:
#	pkg/application/summary_evaluation/service/service2.go
... ... @@ -116,6 +116,12 @@ spec:
value: "https://suplus-business-admin-prd.fjmaimaimai.com"
- name: MMM_OPEN_API_SERVICE_HOST
value: "https://public-interface.fjmaimaimai.com/openapi"
- name: PUSH_DATA_HOST
value: "https://character-library-metadata-bastion.sumifcc.com"
- name: PUSH_DATA_APPKEY
value: "7q9Kd8ktoB"
- name: PUSH_DATA_APPSECRET
value: "pQSoBj44Wk"
volumes:
- name: accesslogs
emptyDir: {}
... ...
package service
import (
"fmt"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
roleService "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/xredis"
)
// 超管直接修改考核结果分数
// 修改周期考核的分数
func (srv *SummaryEvaluationService) ModifyFinishScore(param *command.ModifyFinishScore) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 只有超级管理员可以使用的功能
superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.UserId)
if err != nil {
return err
}
if superAdmin != domain.RoleTypeSuperAdmin {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
//获取周期评估任务finish
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"id": []int{param.SummaryEvaluationId},
"companyId": param.CompanyId,
})
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if len(evaluationList) == 0 {
return nil
}
evaluationFinishData := evaluationList[0]
//按照被评估人id ,加锁
lock := xredis.NewLockSummaryEvaluation(evaluationFinishData.TargetUser.UserId)
err = lock.Lock()
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
if evaluationFinishData.Types != domain.EvaluationFinish {
return nil
}
// 获取考核评估项
var evaluationFinishValue []*domain.SummaryEvaluationValue
var saveNewValue bool //是否需要保存新的考核评估项评估
//尝试 获取考核结果的评估项
_, evaluationFinishValue, err = evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationFinishData.Id})
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if len(evaluationFinishValue) == 0 {
saveNewValue = true
evaluationFinishValue, err = srv.buildSummaryFinishValue(transactionContext, evaluationFinishData)
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
if saveNewValue {
// 重置评级汇总
for _, val := range evaluationFinishValue {
err = evaluationValueRepo.Save(val)
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
}
}
}
scoreStr := fmt.Sprintf("%.2f", param.Score)
evaluationFinishData.TotalScore = scoreStr
evaluationFinishData.Status = domain.EvaluationCompleted
err = evaluationRepo.Save(evaluationFinishData)
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
// buildSummaryFinishValue
// 当未能按照id直接查询到考核结果的评估项时,
// 从目标人员的上级评估 或者360评估、人资评估、自评 构建考核结果
func (srv *SummaryEvaluationService) buildSummaryFinishValue(transactionContext application.TransactionContext, evaluationFinisih *domain.SummaryEvaluation) (
[]*domain.SummaryEvaluationValue, error) {
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
//尝试获取目标人员的所有评估
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": evaluationFinisih.TargetUser.UserId,
"cycleId": evaluationFinisih.CycleId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
_, itemUsed, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": evaluationFinisih.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var evaluationFinishValue []*domain.SummaryEvaluationValue
var evaluationData *domain.SummaryEvaluation
//尝试获取目标人员的上级评估
for _, val := range evaluationList {
if val.Types == domain.EvaluationSuper {
evaluationData = val
break
}
}
if evaluationData != nil {
//使用上级评估的评估内容
_, itemValue, err := evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
for _, val := range itemUsed {
var newItemValue *domain.SummaryEvaluationValue
for _, val2 := range itemValue {
if val2.EvaluationItemId == val.Id {
newItemValue = val2
newItemValue.Id = 0
newItemValue.SummaryEvaluationId = 0
break
}
}
if newItemValue == nil {
newItemValue = &domain.SummaryEvaluationValue{}
newItemValue.SetBlankValue(evaluationFinisih, val)
}
evaluationFinishValue = append(evaluationFinishValue, newItemValue)
}
} else {
//使用360评估、人资评估、自评 构建考核结果的评估项内容
var itemValueBack []*domain.SummaryEvaluationValue
var summaryEvaluationId []int
for _, val := range evaluationList {
if val.Types == domain.Evaluation360 || val.Types == domain.EvaluationHrbp || val.Types == domain.EvaluationSelf {
summaryEvaluationId = append(summaryEvaluationId, val.Id)
}
}
if len(summaryEvaluationId) > 0 {
_, itemValueBack, err = evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": summaryEvaluationId})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
tempSelf := map[int]*domain.SummaryEvaluationValue{}
temp360 := map[int]*domain.SummaryEvaluationValue{}
tempHRBP := map[int]*domain.SummaryEvaluationValue{}
for i := range itemValueBack {
it := itemValueBack[i]
switch it.Types {
case domain.EvaluationSelf:
tempSelf[it.EvaluationItemId] = it
case domain.Evaluation360:
temp360[it.EvaluationItemId] = it
case domain.EvaluationHrbp:
tempHRBP[it.EvaluationItemId] = it
}
}
nowTime := time.Now()
for _, val := range itemUsed {
var newItemValue *domain.SummaryEvaluationValue
if val.EvaluatorId == 0 {
newItemValue = tempSelf[val.Id]
} else if val.EvaluatorId == -1 {
newItemValue = tempHRBP[val.Id]
} else {
newItemValue = temp360[val.Id]
}
if newItemValue == nil {
newItemValue = &domain.SummaryEvaluationValue{}
newItemValue.SetBlankValue(evaluationFinisih, val)
}
newItemValue.SummaryEvaluationId = 0
newItemValue.Id = 0
newItemValue.CreatedAt = nowTime
newItemValue.UpdatedAt = nowTime
evaluationFinishValue = append(evaluationFinishValue, newItemValue)
}
}
// 重置评级汇总
evaluationFinisih.TotalRating = nil
for i := range itemUsed {
evaluationFinisih.ResetTotalRating(itemUsed[i])
}
// 计算分数
if err := evaluationFinisih.EvaluationTotalScore(evaluationFinishValue); err != nil {
return evaluationFinishValue, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return evaluationFinishValue, nil
}
... ...
... ... @@ -726,152 +726,143 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBPComplete(param *command.Qu
}
// ModifyFinishScore 修改周期考核的分数
func (srv *SummaryEvaluationService) ModifyFinishScore(param *command.ModifyFinishScore) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 只有超级管理员可以使用的功能
superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.UserId)
if err != nil {
return err
}
if superAdmin != domain.RoleTypeSuperAdmin {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
// func (srv *SummaryEvaluationService) ModifyFinishScore(param *command.ModifyFinishScore) error {
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
// // 只有超级管理员可以使用的功能
// superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.UserId)
// if err != nil {
// return err
// }
// if superAdmin != domain.RoleTypeSuperAdmin {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// 获取周期评估任务finish
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
// // 获取周期评估任务finish
// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
// itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{"id": []int{param.SummaryEvaluationId}, "companyId": param.CompanyId})
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if len(evaluationList) == 0 {
return nil
}
result := evaluationList[0]
if result.Types != domain.EvaluationFinish {
return nil
}
// 按照被评估人id ,加锁
lock := xredis.NewLockSummaryEvaluation(result.TargetUser.UserId)
err = lock.Lock()
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{"id": []int{param.SummaryEvaluationId}, "companyId": param.CompanyId})
// if err != nil {
// return application.ThrowError(application.BUSINESS_ERROR, err.Error())
// }
// if len(evaluationList) == 0 {
// return nil
// }
// result := evaluationList[0]
// if result.Types != domain.EvaluationFinish {
// return nil
// }
// 获取考核结果评分
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 如果已经存在考核结果分数,只更新分数(反之先默认生成考核结果,再更新分数)
if len(itemValues) > 0 {
// do nothing...
} else {
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
// // 获取考核结果评分
// _, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id})
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// // 如果已经存在考核结果分数,只更新分数(反之先默认生成考核结果,再更新分数)
// if len(itemValues) > 0 {
// // do nothing...
// } else {
// evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
// 周期内所有评估类型
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"companyId": result.CompanyId,
"cycleId": result.CycleId,
"targetUserId": result.TargetUser.UserId,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// // 周期内所有评估类型
// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
// "companyId": result.CompanyId,
// "cycleId": result.CycleId,
// "targetUserId": result.TargetUser.UserId,
// })
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
var super *domain.SummaryEvaluation // 上级评估
for i := range evaluationList {
it := evaluationList[i]
if it.Types == domain.EvaluationSuper {
super = it
break
}
}
// var super *domain.SummaryEvaluation // 上级评估
// for i := range evaluationList {
// it := evaluationList[i]
// if it.Types == domain.EvaluationSuper {
// super = it
// break
// }
// }
// 获取自评模板
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// // 获取自评模板
// _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
if super != nil {
_, superValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 更新填写值
itemValues, err = srv.updateItemValuePriority(result, itemList, superValues, true)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
} else {
// 评估项ID(除考核结果和上级)
var evaluationIds = make([]int, 0)
for i := range evaluationList {
it := evaluationList[i]
if it.Types == domain.EvaluationSelf || it.Types == domain.Evaluation360 || it.Types == domain.EvaluationHrbp {
evaluationIds = append(evaluationIds, it.Id)
}
}
if len(evaluationIds) > 0 {
// 已填写的评估内容
_, otherValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// if super != nil {
// _, superValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// // 更新填写值
// itemValues, err = srv.updateItemValuePriority(result, itemList, superValues, true)
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// } else {
// // 评估项ID(除考核结果和上级)
// var evaluationIds = make([]int, 0)
// for i := range evaluationList {
// it := evaluationList[i]
// if it.Types == domain.EvaluationSelf || it.Types == domain.Evaluation360 || it.Types == domain.EvaluationHrbp {
// evaluationIds = append(evaluationIds, it.Id)
// }
// }
// if len(evaluationIds) > 0 {
// // 已填写的评估内容
// _, otherValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// 更新填写值
itemValues, err = srv.updateItemValuePriority(result, itemList, otherValues, false)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
err = itemValueRepo.RemoveBySummaryEvaluationId(result.Id)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range itemValues {
if err := itemValueRepo.Save(itemValues[i]); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
// 重置评级汇总
result.TotalRating = nil
for i := range itemList {
result.ResetTotalRating(itemList[i])
}
//// 计算分数
//if err := result.EvaluationTotalScore(itemValues); err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//}
}
// // 更新填写值
// itemValues, err = srv.updateItemValuePriority(result, itemList, otherValues, false)
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// }
// }
// err = itemValueRepo.RemoveBySummaryEvaluationId(result.Id)
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// for i := range itemValues {
// if err := itemValueRepo.Save(itemValues[i]); err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// }
// // 重置评级汇总
// result.TotalRating = nil
// for i := range itemList {
// result.ResetTotalRating(itemList[i])
// }
// //// 计算分数
// //if err := result.EvaluationTotalScore(itemValues); err != nil {
// // return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// //}
// }
scoreStr := fmt.Sprintf("%.2f", param.Score)
result.TotalScore = scoreStr
result.Status = domain.EvaluationCompleted
err = evaluationRepo.Save(result)
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
// scoreStr := fmt.Sprintf("%.2f", param.Score)
// result.TotalScore = scoreStr
// result.Status = domain.EvaluationCompleted
// err = evaluationRepo.Save(result)
// if err != nil {
// return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// return nil
// }
// GetUnconfirmedCycleList 获取未确认绩效成绩的周期列表
func (srv *SummaryEvaluationService) GetUnconfirmedCycleList(companyId int, userId int) (map[string]interface{}, error) {
... ...
package constant
import "os"
//推送数据到字库
var PUSH_DATA_HOST string = "http://character-library-metadata-bastion-test.fjmaimaimai.com"
var PUSH_DATA_APPKEY string = "GnAmG4jybB"
var PUSH_DATA_APPSECRET string = "3Oo4dG64X0"
func init() {
if os.Getenv("PUSH_DATA_HOST") != "" {
PUSH_DATA_HOST = os.Getenv("PUSH_DATA_HOST")
}
if os.Getenv("PUSH_DATA_APPKEY") != "" {
PUSH_DATA_APPKEY = os.Getenv("PUSH_DATA_APPKEY")
}
if os.Getenv("PUSH_DATA_APPSECRET") != "" {
PUSH_DATA_APPSECRET = os.Getenv("PUSH_DATA_APPSECRET")
}
}
... ...
... ... @@ -8,6 +8,7 @@ import (
"time"
"github.com/dgrijalva/jwt-go"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
)
type FieldName struct {
... ... @@ -31,9 +32,9 @@ type Client struct {
func NewClient() *Client {
return &Client{
Host: "http://character-library-metadata-bastion-test.fjmaimaimai.com",
AppSecret: "3Oo4dG64X0",
AppKey: "GnAmG4jybB",
Host: constant.PUSH_DATA_HOST,
AppSecret: constant.PUSH_DATA_APPSECRET,
AppKey: constant.PUSH_DATA_APPKEY,
}
}
... ... @@ -94,6 +95,7 @@ type ReqSearchTable struct {
// SearchTable 查询应用数据表
func (c *Client) SearchTable(name string) {
apiUrl := `/api/app-table-file/list`
//TODO
_ = apiUrl
}
... ... @@ -106,5 +108,6 @@ type ReqCreateTable struct {
// CreateTable 创建应用表
func (c *Client) CreateTable() {
apiUrl := `/api/app-table-file/create`
//TODO
_ = apiUrl
}
... ...
... ... @@ -8,6 +8,8 @@ import (
func TestToken(t *testing.T) {
c := NewClient()
c.AppKey = "7q9Kd8ktoB"
c.AppSecret = "pQSoBj44Wk"
h := c.useHeader()
t.Logf("%v", h)
}
... ... @@ -21,8 +23,17 @@ func TestField(t *testing.T) {
func TestPushData(t *testing.T) {
nowTime := time.Unix(1688572800, 0)
err := SendDataStaffAssess(nowTime)
c := NewClient()
c.Host = ""
c.AppKey = ""
c.AppSecret = ""
entry := StaffAssessItem{}
data, err := entry.DataForAppend(nowTime)
if err != nil {
t.Logf("获取每日评估的数据 %s", err)
}
err = c.AppendData(data)
if err != nil {
t.Error(err)
t.Logf("获取每日评估的数据 %s", err)
}
}
... ...
... ... @@ -7,9 +7,10 @@ import (
)
func PushData() {
//每天15:30点运行
nowTime := time.Now()
y, m, d := nowTime.Date()
t1 := time.Date(y, m, d, 10, 0, 0, 0, time.Local) //今天的10点
t1 := time.Date(y, m, d, 16, 50, 0, 0, time.Local) //今天的15:30
interval := t1.Sub(nowTime)
if interval < 0 {
interval = (24 * time.Hour) + interval
... ... @@ -20,7 +21,7 @@ func PushData() {
nowTime = time.Now()
err := SendDataStaffAssess(nowTime)
if err != nil {
log.Logger.Error("发送每日评估任务")
log.Logger.Error("发送每日评估任务" + err.Error())
}
timer.Reset(24 * time.Hour)
... ...