作者 tangxvhui

提取 更新评估的公用方法

package command
type EditEvaluationValue struct {
SummaryEvaluationId int `json:"summaryEvaluationId,string"`
ExecutorId int `json:"-"` // 执行人id
CompanyId int `json:"-"` // 公司id
EvaluationItems []struct {
Value string `json:"value"`
Remark string `json:"remark"`
EvaluationItemId int `json:"evaluationItemId,string"`
} `json:"evaluationItems"`
SummaryEvaluationId int `json:"summaryEvaluationId,string"`
ExecutorId int `json:"-"` // 执行人id
CompanyId int `json:"-"` // 公司id
EvaluationItems []UpdatedItemValue `json:"evaluationItems"`
}
type UpdatedItemValue struct {
Value string `json:"value"`
Remark string `json:"remark"`
EvaluationItemId int `json:"evaluationItemId,string"`
}
... ...
... ... @@ -7,9 +7,9 @@ package command
// }
type QueryEvaluation struct {
CycleId int `json:"cycleId,string"` //周期id
UserId int `json:"userId,string"` //员工id
CompanyId int `json:"-"` //公司id
CycleId int `json:"cycleId,string"` //周期id
TargetUserId int `json:"targetUserId,string"` //员工id
CompanyId int `json:"-"` //公司id
}
type QueryEvaluation360 struct {
... ...
... ... @@ -306,10 +306,10 @@ func (srv *SummaryEvaluationService) GetEvaluationSelfByCycle(param *command.Que
"transactionContext": transactionContext,
})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"limit": 1,
"cycleId": param.CycleId,
"executorId": param.UserId,
"types": domain.EvaluationSelf,
"limit": 1,
"cycleId": param.CycleId,
"targetUserId": param.TargetUserId,
"types": domain.EvaluationSelf,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -318,6 +318,9 @@ func (srv *SummaryEvaluationService) GetEvaluationSelfByCycle(param *command.Que
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationData := evaluationList[0]
if evaluationData.CompanyId != param.CompanyId {
return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
}
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
"evaluationProjectId": evaluationData.EvaluationProjectId,
"nodeType": int(domain.LinkNodeSelfAssessment),
... ... @@ -462,54 +465,19 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
evaluationData.TotalRating = nil //清空评级数量统计
for _, v := range itemList {
newValue := &domain.SummaryEvaluationValue{}
newValue.SetBlankValue(evaluationData, v)
evaluationValueMap[v.Id] = newValue
evaluationItemMap[v.Id] = v
//重置计数
evaluationData.ResetTotalRating(v)
err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, nil)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
evaluationData.Status = domain.EvaluationCompleted
//保存填写值
for _, v := range itemValueList {
if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
mValue.Id = v.Id
}
}
for _, v := range param.EvaluationItems {
updatedData, ok := evaluationValueMap[v.EvaluationItemId]
if !ok {
continue
}
evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
if !ok {
continue
}
//填充评估填写值
err = updatedData.FillValue(evaluationItem, v.Value, v.Remark)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
evaluationValueList := []*domain.SummaryEvaluationValue{}
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 = evaluationData.EvaluationTotalScore(evaluationValueList)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationData.Status = domain.EvaluationCompleted
//保存填写值
err = evaluationRepo.Save(evaluationData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -517,7 +485,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
itemValueAdapter := srv.buildSummaryItemValue(itemList, evaluationValueList)
itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
return map[string][]adapter.EvaluationItemAdapter{
"EvaluationItems": itemValueAdapter,
}, nil
... ... @@ -588,7 +556,7 @@ func (srv *SummaryEvaluationService) CountEvaluationSelfLevel(param *command.Que
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
levelCodeCountList, err := assessDao.CountAssessContentLevelCode(param.UserId, domain.AssessSelf, param.CycleId)
levelCodeCountList, err := assessDao.CountAssessContentLevelCode(param.TargetUserId, domain.AssessSelf, param.CycleId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -603,10 +571,10 @@ func (srv *SummaryEvaluationService) CountEvaluationSelfLevel(param *command.Que
"transactionContext": transactionContext,
})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"limit": 1,
"cycleId": param.CycleId,
"executorId": param.UserId,
"types": domain.EvaluationSelf,
"limit": 1,
"cycleId": param.CycleId,
"targetUserId": param.TargetUserId,
"types": domain.EvaluationSelf,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -764,24 +732,6 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval
}
//组合 评估填写的值和评估项
itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
// codeList := []*adapter.LevalCodeCount{}
// codeMap := map[string]*adapter.LevalCodeCount{}
// for _, v := range itemValuesAdapter {
// if v.Weight > 0 {
// continue
// }
// if _, ok := codeMap[v.Value]; !ok {
// code := &adapter.LevalCodeCount{
// Code: v.Value,
// Number: 0,
// ItemList: []string{},
// }
// codeMap[v.Value] = code
// codeList = append(codeList, code)
// }
// codeMap[v.Value].ItemList = append(codeMap[v.Value].ItemList, v.Name)
// codeMap[v.Value].Number += 1
// }
result := adapter.EvaluationInfoSuperAdapter{
EvaluationBaseAdapter: evaluationBase,
// LevelCount: codeList,
... ... @@ -849,62 +799,20 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
if err != nil {
return nil, err
}
evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
evaluationData.TotalRating = nil //清空评级数量统计
for _, v := range itemList {
newValue := &domain.SummaryEvaluationValue{}
//初始一个空白的value
newValue.SetBlankValue(evaluationData, v)
evaluationValueMap[v.Id] = newValue
evaluationItemMap[v.Id] = v
//重置评级统计数量
evaluationData.ResetTotalRating(v)
}
for _, v := range itemValueList {
if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
mValue.Id = v.Id
}
}
for _, v := range param.EvaluationItems {
updatedData, ok := evaluationValueMap[v.EvaluationItemId]
if !ok {
continue
}
evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
if !ok {
continue
}
if defaultValue, ok := hrbpOr360ItemValue[v.EvaluationItemId]; ok {
//填充值
err = updatedData.FillValue(evaluationItem, defaultValue.Value, v.Remark)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
} else {
err = updatedData.FillValue(evaluationItem, v.Value, v.Remark)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, hrbpOr360ItemValue)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationValueList := []*domain.SummaryEvaluationValue{}
for _, v := range evaluationValueMap {
//变更评估状态为已填写
evaluationData.Status = domain.EvaluationCompleted
for _, v := range itemValueList {
//保存填写值
err = itemValueRepo.Save(v)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationValueList = append(evaluationValueList, v)
}
//计算总得分
err = evaluationData.EvaluationTotalScore(evaluationValueList)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//变更评估状态为已填写
evaluationData.Status = domain.EvaluationCompleted
//保存填写值
err = evaluationRepo.Save(evaluationData)
if err != nil {
... ... @@ -913,7 +821,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
itemValueAdapter := srv.buildSummaryItemValue(itemList, evaluationValueList)
itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
return map[string][]adapter.EvaluationItemAdapter{
"EvaluationItems": itemValueAdapter,
}, nil
... ... @@ -922,7 +830,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
// getEvaluationSuperDefaultValue
// 按照权限设置,是否获取上级评估内容的默认值
func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) (
map[int]*domain.SummaryEvaluationValue, error) {
[]*domain.SummaryEvaluationValue, error) {
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
... ... @@ -968,9 +876,7 @@ func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionC
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 记录人资评估或者360评估的 填写项id
hrbpOr360ItemValue := map[int]*domain.SummaryEvaluationValue{}
result := map[int]*domain.SummaryEvaluationValue{}
hrbpOr360ItemValue := []*domain.SummaryEvaluationValue{}
if permissionData.OptEvalScore == domain.PermissionOff {
//上级是否可以修改360°综评分数
//获取360综合评分
... ... @@ -979,7 +885,7 @@ func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionC
if v.Types != domain.Evaluation360 {
continue
}
hrbpOr360ItemValue[v.EvaluationItemId] = v
hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)
}
}
if permissionData.OptHrScore == domain.PermissionOff {
... ... @@ -991,10 +897,10 @@ func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionC
continue
}
hrbpOr360ItemValue[v.EvaluationItemId] = v
hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)
}
}
return result, nil
return hrbpOr360ItemValue, nil
}
// 获取执行人的上级评估的列表
... ... @@ -1209,10 +1115,10 @@ func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command
"transactionContext": transactionContext,
})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"limit": 1,
"cycleId": param.CycleId,
"executorId": param.UserId,
"types": domain.EvaluationSuper,
"limit": 1,
"cycleId": param.CycleId,
"targetUserId": param.TargetUserId,
"types": domain.EvaluationSuper,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -1221,9 +1127,6 @@ func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有找到符合条件的数据")
}
evaluationData := evaluationList[0]
// if evaluationData.Types == domain.EvaluationSuper {
// return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
// }
if evaluationData.CompanyId == param.CompanyId {
return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
}
... ... @@ -1402,3 +1305,78 @@ func (srv *SummaryEvaluationService) ListAllEvaluationSuper(param *command.Query
result := tool_funs.SimpleWrapGridMap(int64(cnt), evaluationListAdapter)
return result, nil
}
// editEvaluationValue 编辑评估的填写值
// evaluationData 对应的评估任务
// evaluationItems 对应的评估项
// oldItemValue 旧的评估项填写的值
// updatedValue 新填的评估值
// defaultItemvalue 评估项保持的默认值
func (srv *SummaryEvaluationService) editEvaluationValue(
evaluationData *domain.SummaryEvaluation,
itemValueList *[]*domain.SummaryEvaluationValue,
evaluationItems []*domain.EvaluationItemUsed,
updatedValue []command.UpdatedItemValue,
defaultItemValue []*domain.SummaryEvaluationValue,
) error {
evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
evaluationData.TotalRating = nil //清空评级数量统计
for _, v := range evaluationItems {
newValue := &domain.SummaryEvaluationValue{}
newValue.SetBlankValue(evaluationData, v)
evaluationValueMap[v.Id] = newValue
evaluationItemMap[v.Id] = v
//重置计数
evaluationData.ResetTotalRating(v)
}
//新值的id 替换为旧值id
for _, v := range *itemValueList {
if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
mValue.Id = v.Id
}
}
//填入填写的更新值
for _, v := range updatedValue {
newItemValue, ok := evaluationValueMap[v.EvaluationItemId]
if !ok {
continue
}
evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
if !ok {
continue
}
//填充评估填写值
err := newItemValue.FillValue(evaluationItem, v.Value, v.Remark)
if err != nil {
return err
}
}
// 填入固定的默认值
for _, v := range defaultItemValue {
newItemValue, ok := evaluationValueMap[v.EvaluationItemId]
if !ok {
continue
}
evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
if !ok {
continue
}
//填充评估填写值
err := newItemValue.FillValue(evaluationItem, v.Value, v.Remark)
if err != nil {
return err
}
}
//完全更新itemValueList
*itemValueList = (*itemValueList)[0:0]
for _, v := range evaluationValueMap {
*itemValueList = append(*itemValueList, v)
}
// 计算总得分
err := evaluationData.EvaluationTotalScore(nil)
if err != nil {
return err
}
return nil
}
... ...
... ... @@ -145,8 +145,8 @@ func (d *StaffAssessDao) AllAssessCycleList(companyId int) ([]AssessCycle, error
staff_assess_task.cycle_id ,
staff_assess_task.company_id ,
staff_assess_task.cycle_name
from staff_assess_task
where staff_assess_task.company_id = ?
from staff_assess_task
where staff_assess_task.company_id = ?
and staff_assess_task.deleted_at isnull
order by staff_assess_task.cycle_id desc
`
... ... @@ -1254,6 +1254,33 @@ func (d *StaffAssessDao) CountUncompletedSelfAssess(companyId int, projectIds []
return result, err
}
func (d *StaffAssessDao) SearchAssesBeforeNow() {}
// SearchAssesBeforeNow
func (d *StaffAssessDao) SearchAssesBeforeNow(executorId int, companyId int, limit int, offset int) int {
sqlStr := `select
distinct on(cycle_id ,begin_day)
staff_assess.cycle_id ,
staff_assess.cycle_name ,
to_char(staff_assess.begin_time at time zone 'PRC','YYYY-MM-DD') as begin_day,
to_char(staff_assess.end_time at time zone 'PRC','YYYY-MM-DD HH24:MI:SS') as end_time,
to_char(staff_assess.begin_time at time zone 'PRC','YYYY-MM-DD HH24:MI:SS') as begin_time
from staff_assess
WHERE staff_assess.company_id=?
and staff_assess.deleted_at isnull
and (
staff_assess.end_time < now() or staff_assess.status ='completed'
)
and staff_assess.executor ->> 'userId'=''
order by begin_day desc
limit ? offset ?`
condition := []interface{}{
companyId, executorId, limit, offset,
}
_ = sqlStr
_ = condition
return 0
}
func (d *StaffAssessDao) SearchAssessAfterNow() {}
func (d *StaffAssessDao) SearchAssessAfterNow(executorId int, companyId int) {}
... ...
... ... @@ -56,7 +56,6 @@ func (c *SummaryEvaluationController) GetEvaluationSelf() {
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
paramReq.UserId = int(userReq.UserId)
data, err := srv.GetEvaluationSelfByCycle(paramReq)
c.Response(data, err)
... ... @@ -107,7 +106,6 @@ func (c *SummaryEvaluationController) CountEvaluationSelfLevel() {
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.UserId = int(userReq.UserId)
paramReq.CompanyId = int(userReq.CompanyId)
data, err := srv.CountEvaluationSelfLevel(paramReq)
c.Response(data, err)
... ... @@ -302,8 +300,6 @@ func (c *SummaryEvaluationController) GetTargetUserEvaluationSuper() {
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.UserId = int(userReq.UserId)
data, err := srv.GetTargetUserEvaluationSuper(paramReq)
c.Response(data, err)
}
... ...