作者 郑周

1. 360综评列表(动态行转列)

package adapter
type TableHeader struct {
Key string `json:"key"`
Name string `json:"name"`
}
type SummaryEvaluationAdapter struct {
TableHeader []TableHeader `json:"tableHeader"`
List []map[string]interface{} `json:"list"`
Total int `json:"total"`
}
... ...
package command
// QueryEvaluation360List 360综评列表
type QueryEvaluation360List struct {
CycleId int `cname:"周期ID" json:"cycleId,string" valid:"Required"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
SearchName string `cname:"用户名称" json:"searchName"`
CompanyId int `cname:"公司ID" json:"-"`
UserId int `cname:"用户ID" json:"-"`
}
// QueryEvaluationHRList 人资综评列表
type QueryEvaluationHRList struct {
CycleId int `json:"cycleId,string"` // 周期ID
SearchName string `json:"searchName"` // 模糊搜索(用户名称)
CompanyId int `json:"-"` // 公司ID
UserId int `json:"-"` // 用户ID
}
... ...
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)
... ...
package repository
import (
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
... ... @@ -85,6 +86,10 @@ func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface
query.Where("evaluation_project_id=?", v)
}
if v, ok := queryOptions["evaluationProjectIds"]; ok {
query.Where("evaluation_project_id in(?)", pg.In(v))
}
if v, ok := queryOptions["nodeType"]; ok {
query.Where("node_type=?", v)
}
... ...
... ... @@ -125,6 +125,10 @@ func (repo *SummaryEvaluationRepository) Find(queryOptions map[string]interface{
query.Offset(v)
}
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id=?", v)
}
if v, ok := queryOptions["types"]; ok {
query.Where("types=?", v)
}
... ... @@ -140,6 +144,10 @@ func (repo *SummaryEvaluationRepository) Find(queryOptions map[string]interface{
query.Where(`summary_evaluation.target_user->>'userId'='?'`, v)
}
if v, ok := queryOptions["searchTargetName"]; ok {
query.Where(`summary_evaluation.target_user->>'userName' LIKE '?'`, v)
}
if v, ok := queryOptions["executorId"]; ok {
query.Where(`summary_evaluation.executor->>'userId'='?'`, v)
}
... ...
... ... @@ -108,6 +108,10 @@ func (repo *SummaryEvaluationValueRepository) Find(queryOptions map[string]inter
if v, ok := queryOptions["summaryEvaluationId"]; ok {
query.Where("summary_evaluation_id=?", v)
}
if v, ok := queryOptions["summaryEvaluationIds"]; ok {
query.Where("summary_evaluation_id in(?)", pg.In(v))
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
... ... @@ -95,9 +95,27 @@ func (c *SummaryEvaluationController) GetTargetUserCycleList() {
c.Response(data, err)
}
func (c *SummaryEvaluationController) GetEvaluation360() {
// CountEvaluationSelfLevel 获取自评小结
func (c *SummaryEvaluationController) CountEvaluationSelfLevel() {
srv := service.NewSummaryEvaluationService()
in := &command.QueryEvaluation360{}
paramReq := &command.QueryEvaluation{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
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)
}
func (c *SummaryEvaluationController) Evaluation360List() {
srv := service.NewSummaryEvaluationService()
in := &command.QueryEvaluation360List{}
err := c.BindJSON(in)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
... ... @@ -105,27 +123,25 @@ func (c *SummaryEvaluationController) GetEvaluation360() {
return
}
userReq := middlewares.GetUser(c.Ctx)
in.CompanyId = int(userReq.CompanyId)
in.UserId = int(userReq.UserId)
data, err := srv.GetEvaluation360(in)
data, err := srv.Evaluation360List(in)
c.Response(data, err)
}
// CountEvaluationSelfLevel 获取自评小结
func (c *SummaryEvaluationController) CountEvaluationSelfLevel() {
func (c *SummaryEvaluationController) GetEvaluation360() {
srv := service.NewSummaryEvaluationService()
paramReq := &command.QueryEvaluation{}
err := c.BindJSON(paramReq)
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)
paramReq.UserId = int(userReq.UserId)
paramReq.CompanyId = int(userReq.CompanyId)
data, err := srv.CountEvaluationSelfLevel(paramReq)
in.UserId = int(userReq.UserId)
data, err := srv.GetEvaluation360(in)
c.Response(data, err)
}
func (c *SummaryEvaluationController) EditEvaluation360() {
... ...
... ... @@ -17,6 +17,7 @@ func init() {
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-360/list", (*controllers.SummaryEvaluationController).Evaluation360List),
web.NSCtrlPost("/evaluation-hr", (*controllers.SummaryEvaluationController).GetEvaluationHRBP),
web.NSCtrlPost("/evaluation-hr/edit", (*controllers.SummaryEvaluationController).EditEvaluationHRBP),
web.NSCtrlPost("/self/summary", (*controllers.SummaryEvaluationController).CountEvaluationSelfLevel),
... ...