|
|
package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"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"
|
...
|
...
|
@@ -10,6 +11,163 @@ import ( |
|
|
"time"
|
|
|
)
|
|
|
|
|
|
func (srv *SummaryEvaluationService) Evaluation360List(param *command.QueryEvaluation360List) (*adapter.SummaryEvaluationAdapter, 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})
|
|
|
|
|
|
var searchTargetName string
|
|
|
if len(param.SearchName) > 0 {
|
|
|
searchTargetName = "%" + param.SearchName + "%"
|
|
|
} else {
|
|
|
searchTargetName = ""
|
|
|
}
|
|
|
limit := param.PageSize
|
|
|
offset := limit * (param.PageNumber - 1)
|
|
|
if offset < 0 {
|
|
|
offset = 0
|
|
|
}
|
|
|
count, list, err := evaluationRepo.Find(map[string]interface{}{
|
|
|
"companyId": param.CompanyId,
|
|
|
"cycleId": param.CycleId,
|
|
|
"executorId": param.UserId,
|
|
|
"types": domain.Evaluation360,
|
|
|
"searchTargetName": searchTargetName,
|
|
|
"limit": limit,
|
|
|
"offset": offset,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
ids := make([]int, 0)
|
|
|
projectIds := make([]int, 0)
|
|
|
for i := range list {
|
|
|
ids = append(ids, list[i].Id)
|
|
|
projectIds = append(projectIds, list[i].EvaluationProjectId)
|
|
|
}
|
|
|
|
|
|
// 固定列
|
|
|
changeableHeader := []adapter.TableHeader{
|
|
|
{Key: "targetUserName", Name: "姓名"},
|
|
|
{Key: "statusVal", Name: "状态"},
|
|
|
{Key: "relation", Name: "360°评估关系"},
|
|
|
{Key: "endTime", Name: "360°评估截止日期"},
|
|
|
}
|
|
|
changeableRowMap := map[int]map[string]interface{}{} // k,v(用户ID -> 数据集合)行数据内容
|
|
|
itemMap := map[int][]*domain.EvaluationItemUsed{} // k,v(项目ID -> 评估数组)归类评估内容
|
|
|
valueMap := map[string]*domain.SummaryEvaluationValue{} // k,v(周期+评估 -> 提交值)
|
|
|
uniqueColumnsMap := map[string]string{} // 列名称唯一
|
|
|
|
|
|
if len(ids) > 0 {
|
|
|
// 评估内容(注.使用自评模板,并过滤出360综评人的评估内容)
|
|
|
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectIds": projectIds, "node_type": domain.LinkNodeSelfAssessment, "evaluatorId": param.UserId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
// 填写值
|
|
|
_, valueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIds": ids})
|
|
|
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())
|
|
|
}
|
|
|
|
|
|
for i := range valueList {
|
|
|
key := fmt.Sprintf("%d-%d", valueList[i].SummaryEvaluationId, valueList[i].EvaluationItemId)
|
|
|
valueMap[key] = valueList[i]
|
|
|
}
|
|
|
|
|
|
for i := range itemList {
|
|
|
item := itemList[i]
|
|
|
key := fmt.Sprintf("k%d", i)
|
|
|
name := fmt.Sprintf("%s-%s", item.Category, item.Name)
|
|
|
if _, ok := uniqueColumnsMap[name]; !ok {
|
|
|
changeableHeader = append(changeableHeader, adapter.TableHeader{Key: key, Name: name})
|
|
|
uniqueColumnsMap[name] = key
|
|
|
}
|
|
|
|
|
|
if pList, ok := itemMap[item.EvaluationProjectId]; !ok {
|
|
|
pList = make([]*domain.EvaluationItemUsed, 0)
|
|
|
itemMap[item.EvaluationProjectId] = pList
|
|
|
} else {
|
|
|
pList = append(pList, item)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
now := time.Now().Local() // 当前时间
|
|
|
var rowMap map[string]interface{}
|
|
|
for i := range list {
|
|
|
v := list[i]
|
|
|
if rm, ok := changeableRowMap[v.TargetUser.UserId]; ok {
|
|
|
rowMap = rm
|
|
|
} else {
|
|
|
rowMap = map[string]interface{}{}
|
|
|
changeableRowMap[v.TargetUser.UserId] = rowMap
|
|
|
}
|
|
|
|
|
|
endTime := v.EndTime.Local()
|
|
|
statusVal := ""
|
|
|
if v.Status == domain.EvaluationCompleted {
|
|
|
statusVal = "已完成"
|
|
|
} else {
|
|
|
if now.After(endTime) {
|
|
|
statusVal = "已逾期"
|
|
|
} else {
|
|
|
statusVal = "待完成"
|
|
|
}
|
|
|
}
|
|
|
rowMap["id"] = v.Id
|
|
|
rowMap["targetUserName"] = v.TargetUser.UserName
|
|
|
rowMap["statusVal"] = statusVal
|
|
|
rowMap["relation"] = "项目组员"
|
|
|
rowMap["endTime"] = endTime.Format("2006-01-02 15:04")
|
|
|
|
|
|
// 当前项目所有评估内容
|
|
|
if pList, ok := itemMap[v.EvaluationProjectId]; ok {
|
|
|
for _, item := range pList {
|
|
|
name := fmt.Sprintf("%s-%s", item.Category, item.Name)
|
|
|
if key, ok := uniqueColumnsMap[name]; ok { // 动态列用name -> key
|
|
|
valueKey := fmt.Sprintf("%d-%d", v.Id, item.Id)
|
|
|
if it, ok := valueMap[valueKey]; ok {
|
|
|
rowMap[key] = it.Score
|
|
|
} else {
|
|
|
rowMap[key] = ""
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
targetList := make([]map[string]interface{}, 0)
|
|
|
for _, v1 := range list {
|
|
|
rowMap := changeableRowMap[v1.TargetUser.UserId]
|
|
|
for _, v2 := range changeableHeader { // 填充部分动态列缺失字段
|
|
|
if _, ok := rowMap[v2.Key]; !ok {
|
|
|
rowMap[v2.Key] = ""
|
|
|
}
|
|
|
}
|
|
|
targetList = append(targetList, rowMap)
|
|
|
}
|
|
|
result := &adapter.SummaryEvaluationAdapter{
|
|
|
TableHeader: changeableHeader,
|
|
|
Total: count,
|
|
|
List: targetList,
|
|
|
}
|
|
|
return result, nil
|
|
|
}
|
|
|
|
|
|
// GetEvaluation360 获取360综评详情
|
|
|
func (srv *SummaryEvaluationService) GetEvaluation360(param *command.QueryEvaluation360) (*adapter.EvaluationInfoAdapter, error) {
|
|
|
transactionContext, err := factory.ValidateStartTransaction(param)
|
...
|
...
|
|