作者 tangxvhui

更新自评小结

... ... @@ -596,8 +596,3 @@ func (srv *StaffAssessServeice) ExportUserAssess(param *query.ExportAssessConten
xlsxFile.MergeCell(sheetName, "A1", colName+"1")
return xlsxFile, nil
}
// 自评小结统计
func (srv *StaffAssessServeice) AssessSelfSummary() {
}
... ...
... ... @@ -14,6 +14,10 @@ type EvaluationInfoAdapter struct {
EndTime string `json:"endTime"` //结束时间 2006-01-02 15:04:05
TargetUserId int `json:"targetUserId"` //被评估的目标用户,被执行的
TargetUserName string `json:"targetUserName"` //
CompanyLogo string `json:"companyLogo,string,"` //公司logo
CompanyName string `json:"companyName"` //公司名称
SupperUser string `json:"superUser"` //目标用户的上级
DutyTime string `json:"dutyTime"` //入职时间
Status string `json:"status"` //完成状态
EvaluationItems []EvaluationItemAdapter `json:"evaluationItems"`
}
... ...
package command
type QueryEvaluationInfo struct {
// type QueryEvaluationInfo struct {
// CycleId int `json:"cycleId,string"` //周期id
// ExecutorId int `json:"executorId,string"` //执行人id
// CompanyId int `json:"-"` //公司id
// }
type QueryEvaluation struct {
CycleId int `json:"cycleId,string"` //周期id
ExecutorId int `json:"executorId,string"` //执行人id
UserId int `json:"userId,string"` //员工id
CompanyId int `json:"-"` //公司id
}
... ...
package service
import (
"fmt"
"time"
"github.com/linmadan/egglib-go/core/application"
... ... @@ -266,19 +267,18 @@ func (srv *SummaryEvaluationService) buildSummaryItemValue(itemList []*domain.Ev
Remark: "",
}
value, ok := valueMap[v.Id]
if !ok {
continue
}
if ok {
item.Score = value.Score
item.Value = value.Value
item.Remark = value.Remark
}
itemValues = append(itemValues, item)
}
return itemValues
}
// 获取综合自评详情
func (srv *SummaryEvaluationService) GetEvaluationSelf(param *command.QueryEvaluationInfo) (*adapter.EvaluationInfoAdapter, error) {
func (srv *SummaryEvaluationService) GetEvaluationSelf(param *command.QueryEvaluation) (*adapter.EvaluationInfoAdapter, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -301,7 +301,7 @@ func (srv *SummaryEvaluationService) GetEvaluationSelf(param *command.QueryEvalu
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"limit": 1,
"cycleId": param.CompanyId,
"executorId": param.ExecutorId,
"executorId": param.UserId,
"types": domain.EvaluationSelf,
})
if err != nil {
... ... @@ -326,12 +326,17 @@ func (srv *SummaryEvaluationService) GetEvaluationSelf(param *command.QueryEvalu
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := srv.getSummaryEvaluation(transactionContext, evaluationData)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
result.EvaluationItems = itemValuesAdapter
return result, nil
}
func (srv *SummaryEvaluationService) getSummaryEvaluation(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) *adapter.EvaluationInfoAdapter {
result := adapter.EvaluationInfoAdapter{
SummaryEvaluationId: evaluationData.Id,
CycleId: int(evaluationData.CycleId),
... ... @@ -343,10 +348,50 @@ func (srv *SummaryEvaluationService) GetEvaluationSelf(param *command.QueryEvalu
EndTime: evaluationData.EndTime.Format("2006-01-02 15:04:05"),
TargetUserId: evaluationData.TargetUser.UserId,
TargetUserName: evaluationData.TargetUser.UserName,
CompanyLogo: "",
CompanyName: "",
SupperUser: "",
DutyTime: "",
Status: string(evaluationData.Status),
EvaluationItems: itemValuesAdapter,
EvaluationItems: []adapter.EvaluationItemAdapter{},
}
//获取用户信息
companyRepo := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
companyData, err := companyRepo.FindOne(map[string]interface{}{
"id": evaluationData.CompanyId,
})
if err != nil {
return &result
}
userData, err := userRepo.FindOne(map[string]interface{}{
"id": evaluationData.TargetUser.UserId,
})
if err != nil {
return &result
}
result.DutyTime = userData.EntryTime
result.CompanyLogo = companyData.Logo
result.CompanyName = companyData.Name
if userData.ParentId <= 0 {
return &result
}
pUserData, err := userRepo.FindOne(map[string]interface{}{
"id": userData.ParentId,
})
if err != nil {
return &result
}
return &result, nil
result.SupperUser = pUserData.Name
return &result
}
// 编辑综合自评详情
... ... @@ -377,6 +422,10 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if evaluationData.Types != domain.EvaluationSelf {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
if evaluationData.Executor.UserId != param.ExecutorId {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
... ... @@ -388,6 +437,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu
_, itemList, err := itemUsedRepo.Find(map[string]interface{}{
"evaluationProjectId": evaluationData.EvaluationProjectId,
"nodeType": domain.LinkNodeSelfAssessment,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -443,6 +493,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationData.UpdatedAt = nowTime
evaluationData.Status = domain.EvaluationCompleted
//保存填写值
err = evaluationRepo.Save(evaluationData)
if err != nil {
... ... @@ -506,15 +557,23 @@ func (srv *SummaryEvaluationService) GetTargetUserCycleList(param *command.Query
}
// 自评小结详情
func (srv *SummaryEvaluationService) CountEvaluationSelfLevel(param *command.QueryEvaluationInfo) (*adapter.EvaluationInfoAdapter, error) {
func (srv *SummaryEvaluationService) CountEvaluationSelfLevel(param *command.QueryEvaluation) (*adapter.EvaluationInfoAdapter, error) {
evaluationInfo, err := srv.GetEvaluationSelf(param)
if err != nil {
return nil, err
}
_ = evaluationInfo
//TODO 组装等级数量统计
levelCodeMap := map[int][]adapter.LevalCodeCount{}
for _, v := range evaluationInfo.EvaluationItems {
codes := v.Rule.GetLevelCodes()
levelCode := []adapter.LevalCodeCount{}
for _, v2 := range codes {
levelCode = append(levelCode, adapter.LevalCodeCount{
Code: v2,
Number: 0,
})
}
levelCodeMap[v.EvaluationItemId] = levelCode
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -526,8 +585,42 @@ func (srv *SummaryEvaluationService) CountEvaluationSelfLevel(param *command.Que
_ = transactionContext.RollbackTransaction()
}()
//统计周期内,评估项等级的数量
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
levelCodeCountList, err := assessDao.CountAssessContentLevelCode(param.UserId, domain.AssessSelf, param.CycleId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
levelCodeCountMap := map[string]int{}
for _, v := range levelCodeCountList {
key := fmt.Sprintf("%s-%s-%s", v.Category, v.Name, v.LevelValue)
levelCodeCountMap[key] = v.Cnt
}
for i := range evaluationInfo.EvaluationItems {
itemId := evaluationInfo.EvaluationItems[i].EvaluationItemId
levelCodes, ok := levelCodeMap[itemId]
if !ok {
continue
}
evaluationInfo.EvaluationItems[i].LevelCount = levelCodes
for i2 := range levelCodes {
key := fmt.Sprintf("%s-%s-%s",
evaluationInfo.EvaluationItems[i].Category,
evaluationInfo.EvaluationItems[i].Name,
levelCodes[i2].Code,
)
if mVal, ok := levelCodeCountMap[key]; ok {
levelCodes[i2].Number = mVal
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil, nil
return evaluationInfo, nil
}
... ...
... ... @@ -114,3 +114,18 @@ type EvaluationRuleRepository interface {
Find(queryOptions map[string]interface{}) (int64, []*EvaluationRule, error)
Count(queryOptions map[string]interface{}) (int64, error)
}
func (rule *EvaluationRule) GetLevelCodes() []string {
codes := []string{}
if rule.Type == EvaluationTypeRating {
for _, v := range rule.Rating.Levels {
codes = append(codes, v.Code)
}
}
if rule.Type == EvaluationTypeScore {
for _, v := range rule.Score.Levels {
codes = append(codes, v.Code)
}
}
return codes
}
... ...
... ... @@ -64,7 +64,7 @@ type SummaryEvaluationRepository interface {
func (evaluation *SummaryEvaluation) EvaluationTotalScore(valueList []*SummaryEvaluationValue) error {
var totalScore float64
for _, v := range valueList {
score, err := v.SumScore(v.Weight, v.Value)
score, err := v.SumScore()
if err != nil {
return err
}
... ...
... ... @@ -33,7 +33,7 @@ type SummaryEvaluationValueRepository interface {
// 分数保留2位小数
func (itemValue *SummaryEvaluationValue) SummaryEvaluationScore() error {
//计算方式
score, err := itemValue.SumScore(itemValue.Weight, itemValue.Value)
score, err := itemValue.SumScore()
if err != nil {
return err
}
... ... @@ -41,7 +41,7 @@ func (itemValue *SummaryEvaluationValue) SummaryEvaluationScore() error {
return nil
}
func (item *SummaryEvaluationValue) SumScore(weight float64, value string) (float64, error) {
func (item *SummaryEvaluationValue) SumScore() (float64, error) {
if item.Weight == 0 {
return 0, nil
}
... ...
... ... @@ -1191,3 +1191,35 @@ func (d *StaffAssessDao) SearchContentValueByAssessId(assessId []int) map[int][]
return valueMap
}
type AssessContentLevelCode struct {
Cnt int `pg:"cnt"` //数量
LevelValue string `pg:"levelValue"` //评估的等级值
Category string `pg:"category"` //评估的分类
Name string `pg:"name"` //名称
}
func (d *StaffAssessDao) CountAssessContentLevelCode(targetUserId int, assessType domain.StaffAssessType, cycleId int) ([]AssessContentLevelCode, error) {
sqlStr := `
select
count(staff_assess_content.level_value) as cnt ,
staff_assess_content.level_value ,
staff_assess_content.category ,
staff_assess_content."name"
from staff_assess_content
join staff_assess on staff_assess_content.staff_assess_id = staff_assess.id
where 1=1 and staff_assess.deleted_at isnull
and target_user ->>'userId'='?'
and staff_assess."types" = '?'
and staff_assess_content.level_value notnull
and staff_assess.cycle_id =?
group by level_value,category,"name" `
var result []AssessContentLevelCode
condition := []interface{}{
targetUserId, string(assessType), cycleId,
}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
... ...
... ... @@ -46,7 +46,7 @@ func (c *SummaryEvaluationController) GetMenu() {
func (c *SummaryEvaluationController) GetEvaluationSelf() {
srv := service.NewSummaryEvaluationService()
paramReq := &command.QueryEvaluationInfo{}
paramReq := &command.QueryEvaluation{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
... ... @@ -55,12 +55,13 @@ func (c *SummaryEvaluationController) GetEvaluationSelf() {
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
paramReq.ExecutorId = int(userReq.UserId)
paramReq.UserId = int(userReq.UserId)
data, err := srv.GetEvaluationSelf(paramReq)
c.Response(data, err)
}
// EditEvaluationSelf 编辑综合自评
func (c *SummaryEvaluationController) EditEvaluationSelf() {
srv := service.NewSummaryEvaluationService()
paramReq := &command.EditEvaluationValue{}
... ... @@ -78,6 +79,7 @@ func (c *SummaryEvaluationController) EditEvaluationSelf() {
}
// GetTargetUserCycleList 根据被评估人获取周期列表
func (c *SummaryEvaluationController) GetTargetUserCycleList() {
srv := service.NewSummaryEvaluationService()
paramReq := &command.QueryCycleList{}
... ... @@ -92,3 +94,20 @@ func (c *SummaryEvaluationController) GetTargetUserCycleList() {
data, err := srv.GetTargetUserCycleList(paramReq)
c.Response(data, err)
}
// CountEvaluationSelfLevel 获取自评小结
func (c *SummaryEvaluationController) CountEvaluationSelfLevel() {
srv := service.NewSummaryEvaluationService()
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)
}
... ...
... ... @@ -15,6 +15,7 @@ func init() {
web.NSCtrlPost("/cycle/menu", (*controllers.SummaryEvaluationController).GetMenu),
web.NSCtrlPost("/self", (*controllers.SummaryEvaluationController).GetEvaluationSelf),
web.NSCtrlPost("/self/edit", (*controllers.SummaryEvaluationController).EditEvaluationSelf),
web.NSCtrlPost("/self/summary", (*controllers.SummaryEvaluationController).CountEvaluationSelfLevel),
)
web.AddNamespace(summaryNS)
}
... ...