作者 tangxvhui

权重类型 变更

package adapter
type AssessCycleDayResp struct {
CycleId int `json:"cycleId"`
CycleName string `json:"cycleName"`
BeginDay string `json:"beginDay"`
}
... ...
package query
type AssessCycleDescQuery struct {
CycleId int `json:"cycleId"` //评估任务的id
UserId int `json:"userId"` //当前登录人的id
CompanyId int `json:"companyId"` //当前登录的公司
}
... ...
package service
import (
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
//调试用,手动调用CreateStaffAssessTask
... ... @@ -32,79 +28,3 @@ func (srv StaffAssessServeice) InvokCreateStaffAssessTask(param *command.CreateS
}
return data, nil
}
//保存员工绩效评估填写过程中即写即存的内容
func (srv StaffAssessServeice) SaveAssessContentTemp(param *command.SaveAssessInfoCommand) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//获取旧的临时数据内容
contentTempRepo := factory.CreateStaffAssessContentTempRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取评估填写的内容
// assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessData, err := assessRepo.FindOne(map[string]interface{}{
"id": param.AssessId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估任务"+err.Error())
}
// staffAssessId
_, contentTempList, err := contentTempRepo.Find(map[string]interface{}{
"staffAssessId": param.AssessId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取临时保存的内容"+err.Error())
}
nowTime := time.Now()
if len(contentTempList) == 0 {
//获取评估模板
assessContentList, err := srv.getAssessSelfInfoUncompleted(transactionContext, assessData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估模板,"+err.Error())
}
//转填入临时的数据
for _, v := range assessContentList {
item := &domain.StaffAssessContentTemp{
Id: 0,
StaffAssessId: v.StaffAssessId,
SortBy: v.SortBy,
Category: v.Category,
Name: v.Name,
Remark: v.Remark,
Value: "",
CreatedAt: nowTime,
UpdatedAt: nowTime,
}
contentTempList = append(contentTempList, item)
}
}
//更新assessContentTemp
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil, nil
}
//获取员工绩效评估填写内容
//临时数据存在时就获取临时数据
//不存在就获取实际保存的数据
func (srv StaffAssessServeice) GetAssessContentTemp(param *command.SaveAssessInfoCommand) (*adapter.AssessInfoResp, error) {
//将临时保存的数据填入模板中
return nil, nil
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
)
//获取我的项目周期
func (srv StaffAssessServeice) SearchAssessCycelMe(param *query.SearchAssessMeQuery) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
staffAssessTaskRepo := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
var limit int = 200
var offset int = 0
if param.PageSize > 0 {
limit = param.PageSize
}
offset = (param.PageNumber - 1) * param.PageSize
assessCycleList, err := staffAssessTaskRepo.SearchAssessCycleMe(param.UserId, param.CompanyId, limit, offset)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询评估周期"+err.Error())
}
cnt, err := staffAssessTaskRepo.CountAssessTaskMe(param.UserId, param.CompanyId)
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())
}
listData := make([]adapter.AssessCycleDayResp, 0, len(assessCycleList))
var temp adapter.AssessCycleDayResp
for _, v := range assessCycleList {
temp = adapter.AssessCycleDayResp{
CycleId: v.CycleId,
CycleName: v.CycleName,
BeginDay: v.BeginDay,
}
listData = append(listData, temp)
}
return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
}
//获取我的项目周期进度描述
func (srv StaffAssessServeice) AssessCycleMeDesc(param *query.AssessCycleDescQuery) (*adapter.AssessTaskDescResp, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 获取评估任务
staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取个人参与的评估流程
staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskData, err := staffAssessTaskRepo.FindOne(map[string]interface{}{
// "id": param.AssessTaskId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "评估任务不存在,"+err.Error())
}
//返回的数据结果
result := adapter.AssessTaskDescResp{
AssessTaskId: assessTaskData.Id,
EvaluationProjectId: assessTaskData.EvaluationProjectId,
EvaluationProjectName: assessTaskData.EvaluationProjectName,
CycleName: assessTaskData.CycleName,
BeginTime: assessTaskData.BeginTime.Local().Format("2006-01-02 15:04-05"),
EndTime: assessTaskData.EndTime.Local().Format("2006-01-02 15:04-05"),
StepList: []adapter.AssessTaskStep{},
}
for _, v := range assessTaskData.StepList {
stepItem := adapter.AssessTaskStep{
SortBy: v.SortBy,
LinkNodeName: v.LinkNodeName,
LinkNodeId: v.LinkNodeId,
BeginTime: v.BeginTime.Local().Format("2006-01-02 15:04:05"),
EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"),
LinkNodeType: v.LinkNodeType,
Desc: fmt.Sprintf("截止日期:%s", v.EndTime.Local().Format("2006-01-02 15:04:05")),
Status: "",
}
switch v.LinkNodeType {
case domain.LinkNodeSelfAssessment:
//个人自评完成情况
_, assessSelfData, err := staffAssessRepo.Find(map[string]interface{}{
"staffAssessTaskId": assessTaskData.Id,
"executorId": param.UserId,
"typesList": []string{string(domain.AssessSelf)},
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
if len(assessSelfData) > 0 {
stepItem.Status = string(assessSelfData[0].Status)
}
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
case domain.LinkNodeAllInvite:
//邀请别人评估自己
_, assessInviteData, err := staffAssessRepo.Find(map[string]interface{}{
"staffAssessTaskId": assessTaskData.Id,
"targetUserId": param.UserId,
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
"limit": 5,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
if len(assessInviteData) > 0 {
stepItem.Status = string(domain.StaffAssessCompleted)
} else {
stepItem.Status = string(domain.StaffAssessUncompleted)
}
//待邀请人数,为5人减去已邀请的人数。若邀请人数已等于或大于5人,则只显示截止日期即可
if len(assessInviteData) > 5 {
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
} else {
stepItem.Desc = fmt.Sprintf("截止日期:%s 待邀请%d人", stepItem.EndTime, 5-len(assessInviteData))
}
case domain.LinkNodeAllAssessment:
//我评估别人,被邀请评估
_, assessInviteList, err := staffAssessRepo.Find(map[string]interface{}{
"staffAssessTaskId": assessTaskData.Id,
"executorId": param.UserId,
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
if len(assessInviteList) > 0 {
stepItem.Status = string(domain.StaffAssessCompleted)
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
for _, v := range assessInviteList {
if v.Status == domain.StaffAssessUncompleted {
stepItem.Status = string(domain.StaffAssessUncompleted)
break
}
}
}
case domain.LinkNodeSuperiorAssessment:
//我评估别人,上级评估
_, assessSupperList, err := staffAssessRepo.Find(map[string]interface{}{
"staffAssessTaskId": assessTaskData.Id,
"executorId": param.UserId,
"typesList": []string{string(domain.AssessSuper)},
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
if len(assessSupperList) > 0 {
stepItem.Status = string(domain.StaffAssessCompleted)
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
uncompletedNum := 0
for _, v := range assessSupperList {
if v.Status == domain.StaffAssessUncompleted {
uncompletedNum += 1
}
}
if uncompletedNum > 0 {
stepItem.Status = string(domain.StaffAssessUncompleted)
stepItem.Desc = fmt.Sprintf("截止日期:%s 待评估%d人", stepItem.EndTime, uncompletedNum)
}
}
}
result.StepList = append(result.StepList, stepItem)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return &result, nil
}
... ...
... ... @@ -31,7 +31,7 @@ type NodeContent struct {
Name string `json:"name" comment:"名称"`
RuleId int64 `json:"ruleId,string" comment:"评估规则ID"`
Rule *EvaluationRule `json:"rule" comment:"评估规则对象"`
Weight int `json:"weight" comment:"权重"`
Weight float64 `json:"weight" comment:"权重"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*EntryItem `json:"entryItems" comment:"填写项"`
... ...
... ... @@ -22,7 +22,7 @@ type StaffAssessContent struct {
LevelValue string `json:"levelValue"` // 填写值按规则Rule转换为相应的等级值
ReteResult string `json:"reteResult"` //评估的结果
Rule EvaluationRule `json:"rule"` //评估的选项规则
Weight int `json:"weight" ` //"权重"
Weight float64 `json:"weight" ` //"权重"
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
DeletedAt *time.Time `json:"deletedAt"`
... ...
... ... @@ -131,7 +131,8 @@ func (d *StaffAssessDao) AllAssessCycleList(companyId int) ([]AssessCycle, error
//获取评估周期中的绩效考核日期
type AssessCycleDay struct {
BeginDay string `json:"beginDay"`
CycleId string `json:"cycleId"`
CycleId int `json:"cycleId"`
CycleName string `json:"cycleName"`
CompanyId string `json:"companyId"`
}
... ... @@ -139,6 +140,7 @@ type AssessCycleDay struct {
func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]AssessCycleDay, error) {
sqlStr := `select distinct staff_assess_task.begin_day ,
staff_assess_task.cycle_id ,
staff_assess_task.cycle_name
staff_assess_task.company_id
from staff_assess_task
where staff_assess_task.cycle_id = ?
... ... @@ -378,3 +380,48 @@ func (d *StaffAssessDao) ExportDataUserAssess(param SearchConditin1) ([]ExportDa
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// 根据评估的人执行人id,搜索 executorId参与的评估周期
func (d *StaffAssessDao) SearchAssessCycleMe(executorId int, companyId int, limit int, offset int) ([]AssessCycleDay, error) {
if limit < 0 {
limit = 20
}
if offset < 0 {
offset = 0
}
sqlStr := `
SELECT DISTINCT staff_assess_task.cycle_id ,staff_assess_task.cycle_name ,staff_assess_task.begin_day
FROM staff_assess_task
JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
WHERE staff_assess.company_id=?
and staff_assess_task.deleted_at isnull
and staff_assess.executor->>'userId'='?'
order by staff_assess_task.begin_day desc
`
tx := d.transactionContext.PgTx
condition := []interface{}{
companyId, executorId, limit, offset,
}
result := []AssessCycleDay{}
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// 根据评估的人执行人id,统计executorId参与的评估周期
func (d *StaffAssessDao) CountAssessCycleMe(executorId int, companyId int) (int, error) {
sqlStr := `
select count(DISTINCT (staff_assess_task.cycle_id ,staff_assess_task.cycle_name ,staff_assess_task.begin_day )) as cnt
FROM staff_assess_task
JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
WHERE staff_assess.company_id=?
and staff_assess_task.deleted_at isnull
and staff_assess.executor->>'userId'='?'
`
tx := d.transactionContext.PgTx
condition := []interface{}{
companyId, executorId,
}
var result int
_, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
return result, err
}
... ...
... ... @@ -22,7 +22,7 @@ type StaffAssessContent struct {
ReteResult string //评估的结果
Rule domain.EvaluationRule
Remark []domain.AssessContemtRemark
Weight int `pg:",use_zero"` //权重
Weight float64 `pg:",use_zero"` //权重
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
DeletedAt *time.Time
... ...
package controllers
import (
"strconv"
"strings"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"github.com/linmadan/egglib-go/web/beego"
... ... @@ -8,8 +11,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
"strconv"
"strings"
)
type ImportController struct {
... ... @@ -95,7 +96,7 @@ func (controller *ImportController) parseTemplateNodeContent(data []*domain.Perf
nc.RuleId = ruleId // 规则ID
sIndex := strings.Index(module.Weight, "%") // 权重
if sIndex != -1 {
iWeight, _ := strconv.Atoi(module.Weight[:sIndex])
iWeight, _ := strconv.ParseFloat(module.Weight[:sIndex], 64)
nc.Weight = iWeight
} else {
nc.Weight = 0
... ...
ALTER TABLE public.staff_assess_content ALTER COLUMN weight TYPE float8 USING weight::float8;
... ...