作者 tangxvhui

Merge branch 'test'

正在显示 39 个修改的文件 包含 1219 行增加296 行删除
... ... @@ -8,7 +8,7 @@ prod 环境 http://performance-back-prd.fjmaimaimai.com/
前端页面地址
test环境 https://enterprise-platform-dev.fjmaimaimai.com/#/login
测试账号 17708397664 密码123456
测试账号 17708397664 密码 123456
短信模板ID:5475050 短信内容: 您好,#name#,百忙之中不要忘记填写今天的绩效自评反馈哦
\ No newline at end of file
... ...
package adapter
type MeInfo struct {
UserId int64 `json:"userId"` //用户名称
CompanyId int64 `json:"companyId"` //公司id
CompanyName string `json:"companyName"` //公司名称
Phone string `json:"phone"` // 手机号
Name string `json:"name"` // 员工名称
IsHrbp bool `json:"isHrbp"` //是否 是hrbp
IsParent bool `json:"isParent"` //是否 是上级
}
... ...
package command
type GetMeInfo struct {
UserId int64 `json:"-"`
CompanyId int64 `json:"-"`
}
... ...
... ... @@ -2,6 +2,7 @@ package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
... ... @@ -156,3 +157,78 @@ func (service *AuthService) MobileLogin(param *command.MobileLoginCommand) (map[
}
return result, nil
}
// 获取我的
func (service *AuthService) MeInfo(param *command.GetMeInfo) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if errStart := transactionContext.StartTransaction(); errStart != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errStart.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
companyRepository := factory.CreateCompanyRepository(map[string]interface{}{"transactionContext": transactionContext})
roleRepo := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
userData, err := userRepository.FindOne(map[string]interface{}{
"id": param.UserId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工数据"+err.Error())
}
_, parentUser, err := userRepository.Find(map[string]interface{}{
"parentId": userData.Id,
"limit": 1,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工数据"+err.Error())
}
companyData, err := companyRepository.FindOne(map[string]interface{}{
"id": param.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司数据"+err.Error())
}
_, roleList, err := roleRepo.Find(map[string]interface{}{"type": domain.RoleTypeSystem, "companyId": param.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
}
_, userRoleList, err := roleUserRepo.Find(map[string]interface{}{"companyId": param.CompanyId, "userId": param.UserId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
}
// 拥有HRBP权限
isHrbp := false
loop:
for _, v := range userRoleList {
for _, v2 := range roleList {
if v.RoleId == v2.Id {
isHrbp = true
break loop
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
info := adapter.MeInfo{
UserId: userData.Id,
CompanyId: companyData.Id,
CompanyName: companyData.Name,
Phone: userData.Account,
Name: userData.Name,
IsHrbp: isHrbp,
IsParent: false,
}
if len(parentUser) > 0 {
info.IsParent = true
}
return map[string]interface{}{
"user": info,
}, nil
}
... ...
... ... @@ -208,3 +208,11 @@ func CreateLogSmsRepository(options map[string]interface{}) domain.LogSmsReposit
}
return repository.NewLogSmsRepository(transactionContext)
}
func CreateMessagePersonalRepository(options map[string]interface{}) domain.MessagePersonalRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewMessagePersonalRepository(transactionContext)
}
... ...
... ... @@ -33,143 +33,295 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
transactionContext.RollbackTransaction()
if err := recover(); err != nil {
log.Logger.Error(application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("定时发送评估任务异常:%s", err)).Error())
log.Logger.Error(application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("定时发送评估任务[基础查询]异常:%s", err)).Error())
}
}()
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
tasks, err := taskRepository.Find(map[string]interface{}{"now": time.Now().Local()})
tasks, err := taskRepository.Find(map[string]interface{}{"lessNextSentAt": time.Now().Local()})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(tasks) == 0 {
return nil
}
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
projectIdsMap := map[int64]*domain.EvaluationProject{}
cycleIdsMap := map[int64]*domain.EvaluationCycle{}
projectMap := map[int64]*domain.EvaluationProject{}
cycleMap := map[int64]*domain.EvaluationCycle{}
for i := range tasks {
task := tasks[i]
projectIdsMap[task.ProjectId] = nil
cycleIdsMap[task.CycleId] = nil
projectMap[tasks[i].ProjectId] = nil
cycleMap[tasks[i].CycleId] = nil
}
projectIds := make([]int64, 0)
cycleIds := make([]int64, 0)
for k := range projectIdsMap {
for k := range projectMap {
projectIds = append(projectIds, k)
}
for k := range cycleIdsMap {
for k := range cycleMap {
cycleIds = append(cycleIds, k)
}
_, projects, err := projectRepository.Find(map[string]interface{}{"ids": projectIds}, "template")
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if len(projectIds) > 0 {
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projects, err := projectRepository.Find(map[string]interface{}{"ids": projectIds}, "template")
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range projects {
projectMap[projects[i].Id] = projects[i]
}
}
_, cycles, err := cycleRepository.Find(map[string]interface{}{"ids": cycleIds})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if len(cycleIds) > 0 {
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
_, cycles, err := cycleRepository.Find(map[string]interface{}{"ids": cycleIds})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range cycles {
cycleMap[cycles[i].Id] = cycles[i]
}
}
if err = transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
for i := range projects {
projectIdsMap[projects[i].Id] = projects[i]
// 相同项目节点先聚合
taskMap := map[int64][]*domain.NodeTask{}
for i := range tasks {
task := tasks[i]
array, ok := taskMap[task.ProjectId]
if !ok {
array = make([]*domain.NodeTask, 0)
}
taskMap[task.ProjectId] = append(array, task)
}
for i := range cycles {
cycleIdsMap[cycles[i].Id] = cycles[i]
for k, v := range taskMap {
project, ok := projectMap[k]
if ok && project != nil {
if err = rs.taskSend(project, v, cycleMap); err != nil {
return err
}
} else {
if err = rs.taskAbort(v); err != nil {
return err
}
}
}
staffAssessService := service.NewStaffAssessServeice()
//staffAssessService := service.NewStaffAssessServeice()
//now := time.Now().Local()
//for i := range tasks {
// task := tasks[i]
// project, ok := projectMap[task.ProjectId] // 项目还存在
// if ok && project != nil {
// // 环节截止时间
// maxTime := task.TimeEnd.Local()
//
// // 更新任务最后一次的发送时间(取当前时间)
// task.LastSentAt = &now
//
// // 当前周起始时间和截止时间
// var cycleTimeStart = task.NextSentAt.Local()
// var cycleTimeEnd time.Time
//
// // 下个周期起始时间
// nextTime := utils.NextTimeInc(cycleTimeStart, task.KpiCycle)
// // 超过截止时间
// if nextTime.After(maxTime) {
// task.NextSentAt = nil
// } else {
// task.NextSentAt = &nextTime
// }
//
// // 周期的截至时间=下一个周期的开始时间-1秒(需求方要求提交数据时间延长到第二天8点30分截止)
// if task.NextSentAt == nil {
// //cycleTimeEnd = maxTime
// maxYear, maxMonth, maxDay := maxTime.Date()
// cycleTimeEnd = time.Date(maxYear, maxMonth, maxDay, 0, 0, 0, 0, time.Local)
// cycleTimeEnd = cycleTimeEnd.Add(24*time.Hour + 8*time.Hour + 30*time.Minute) // 注.延长8.5小时
// } else {
// //cycleTimeEnd = task.NextSentAt.Local().Add(-1 * time.Second) // 周期截至时间=下一个周期起始时间-1秒
// cycleTimeEnd = task.NextSentAt.Local().Add(8*time.Hour + 30*time.Minute) // 注.延长8.5小时
// }
//
// // 格式化周期的起始和截止时间
// fmCycleStartTime := cycleTimeStart.Format("2006-01-02 15:04:05")
// fmCycleTimeEnd := cycleTimeEnd.Format("2006-01-02 15:04:05")
//
// csat := &command.CreateStaffAssessTask{
// CompanyId: int(project.CompanyId),
// EvaluationProjectId: int(project.Id),
// EvaluationProjectName: project.Name,
// CycleId: project.CycleId,
// StepList: make([]command.AssessTaskStep, 0),
// }
//
// // 周期名称
// if cycle, ok := cycleMap[project.CycleId]; ok {
// csat.CycleName = cycle.Name
// }
//
// // 接收人
// csat.ExecutorId = make([]int, 0)
// for rIndex := range project.Recipients {
// vInt, _ := strconv.Atoi(project.Recipients[rIndex])
// csat.ExecutorId = append(csat.ExecutorId, vInt)
// }
//
// csat.BeginTime = fmCycleStartTime
// csat.EndTime = fmCycleTimeEnd
// csat.StepList = append(csat.StepList, command.AssessTaskStep{
// SortBy: task.NodeSort,
// LinkNodeId: int(task.NodeId),
// LinkNodeName: task.NodeName,
// LinkNodeType: task.NodeType,
// BeginTime: fmCycleStartTime,
// EndTime: fmCycleTimeEnd,
// })
//
// // 创建发送任务
// _, err := staffAssessService.CreateStaffAssessTask(transactionContext, csat)
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建发送任务"+err.Error())
// }
// } else {
// task.NextSentAt = nil // 项目不存在,取消周期任务发送
// }
//
// task, err := taskRepository.Insert(task)
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
//}
return nil
}
func (rs *NodeTaskService) taskSend(project *domain.EvaluationProject, tasks []*domain.NodeTask, cycleMap map[int64]*domain.EvaluationCycle) error {
transactionContext, err := factory.StartTransaction()
if err != nil {
return err
}
defer func() {
_ = transactionContext.RollbackTransaction()
if err := recover(); err != nil {
log.Logger.Error(application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("定时发送评估任务异常:%s", err)).Error())
}
}()
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
now := time.Now().Local()
csat := &command.CreateStaffAssessTask{
CompanyId: int(project.CompanyId),
EvaluationProjectId: int(project.Id),
EvaluationProjectName: project.Name,
CycleId: project.CycleId,
StepList: make([]command.AssessTaskStep, 0),
}
// 周期名称
if cycle, ok := cycleMap[project.CycleId]; ok {
csat.CycleName = cycle.Name
}
// 接收人
csat.ExecutorId = make([]int, 0)
for rIndex := range project.Recipients {
vInt, _ := strconv.Atoi(project.Recipients[rIndex])
csat.ExecutorId = append(csat.ExecutorId, vInt)
}
for i := range tasks {
task := tasks[i]
project, ok := projectIdsMap[task.ProjectId] // 项目
if ok && project != nil {
// 环节截止时间
maxTime := task.TimeEnd.Local()
// 更新任务最后一次的发送时间(取当前时间)
task.LastSentAt = &now
// 当前周起始时间和截止时间
var cycleTimeStart = task.NextSentAt.Local()
var cycleTimeEnd time.Time
// 下个周期起始时间
nextTime := utils.NextTimeInc(cycleTimeStart, task.KpiCycle)
// 超过截止时间
if nextTime.After(maxTime) {
task.NextSentAt = nil
} else {
task.NextSentAt = &nextTime
}
// 周期的截至时间=下一个周期的开始时间-1秒(需求方要求提交数据时间延长到第二天8点30分截止)
if task.NextSentAt == nil {
//cycleTimeEnd = maxTime
maxYear, maxMonth, maxDay := maxTime.Date()
cycleTimeEnd = time.Date(maxYear, maxMonth, maxDay, 0, 0, 0, 0, time.Local)
cycleTimeEnd = cycleTimeEnd.Add(24*time.Hour + 8*time.Hour + 30*time.Minute) // 注.延长8.5小时
} else {
//cycleTimeEnd = task.NextSentAt.Local().Add(-1 * time.Second) // 周期截至时间=下一个周期起始时间-1秒
cycleTimeEnd = task.NextSentAt.Local().Add(8*time.Hour + 30*time.Minute) // 注.延长8.5小时
}
// 环节截止时间
maxTime := task.TimeEnd.Local()
// 格式化周期的起始和截止时间
fmCycleStartTime := cycleTimeStart.Format("2006-01-02 15:04:05")
fmCycleTimeEnd := cycleTimeEnd.Format("2006-01-02 15:04:05")
// 更新任务最后一次的发送时间(取当前时间)
task.LastSentAt = &now
csat := &command.CreateStaffAssessTask{
CompanyId: int(project.CompanyId),
EvaluationProjectId: int(project.Id),
EvaluationProjectName: project.Name,
CycleId: project.CycleId,
StepList: make([]command.AssessTaskStep, 0),
}
// 当前小周期范围[起始时间-截止时间]
var cycleTimeStart = task.NextSentAt.Local()
var cycleTimeEnd time.Time
// 周期名称
if cycle, ok := cycleIdsMap[project.CycleId]; ok {
csat.CycleName = cycle.Name
}
// 下个周期起始时间
nextTime := utils.NextTimeInc(cycleTimeStart, task.KpiCycle)
// 超过截止时间
if nextTime.After(maxTime) {
task.NextSentAt = nil
} else {
task.NextSentAt = &nextTime
}
// 更新下个周期
_, err = taskRepository.Insert(task)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 接收人
csat.ExecutorId = make([]int, 0)
for rIndex := range project.Recipients {
vInt, _ := strconv.Atoi(project.Recipients[rIndex])
csat.ExecutorId = append(csat.ExecutorId, vInt)
}
// 周期的截至时间=下一个周期的开始时间-1秒(需求方要求:提交数据时间延长到第二天8点30分截止)
if task.NextSentAt == nil {
//cycleTimeEnd = maxTime
maxYear, maxMonth, maxDay := maxTime.Date()
cycleTimeEnd = time.Date(maxYear, maxMonth, maxDay, 0, 0, 0, 0, time.Local)
cycleTimeEnd = cycleTimeEnd.Add(24*time.Hour + 8*time.Hour + 30*time.Minute) // 注.延长8.5小时
} else {
//cycleTimeEnd = task.NextSentAt.Local().Add(-1 * time.Second) // 周期截至时间=下一个周期起始时间-1秒
cycleTimeEnd = task.NextSentAt.Local().Add(8*time.Hour + 30*time.Minute) // 注.延长8.5小时
}
// 格式化周期的起始和截止时间
fmCycleStartTime := cycleTimeStart.Format("2006-01-02 15:04:05")
fmCycleTimeEnd := cycleTimeEnd.Format("2006-01-02 15:04:05")
// 格式化周期的起始和截止时间
if len(csat.BeginTime) == 0 {
csat.BeginTime = fmCycleStartTime
}
if len(csat.EndTime) == 0 {
csat.EndTime = fmCycleTimeEnd
csat.StepList = append(csat.StepList, command.AssessTaskStep{
SortBy: task.NodeSort,
LinkNodeId: int(task.NodeId),
LinkNodeName: task.NodeName,
LinkNodeType: task.NodeType,
BeginTime: fmCycleStartTime,
EndTime: fmCycleTimeEnd,
})
// 创建发送任务
_, err := staffAssessService.CreateStaffAssessTask(transactionContext, csat)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建发送任务"+err.Error())
}
} else {
task.NextSentAt = nil // 项目不存在,取消周期任务发送
}
csat.StepList = append(csat.StepList, command.AssessTaskStep{
SortBy: task.NodeSort,
LinkNodeId: int(task.NodeId),
LinkNodeName: task.NodeName,
LinkNodeType: task.NodeType,
BeginTime: fmCycleStartTime,
EndTime: fmCycleTimeEnd,
})
}
task, err := taskRepository.Insert(task)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 创建发送任务
_, err = service.NewStaffAssessServeice().CreateStaffAssessTask(transactionContext, csat)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建发送任务"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
if err = transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil
}
// 节点任务中止
func (rs *NodeTaskService) taskAbort(tasks []*domain.NodeTask) error {
transactionContext, err := factory.StartTransaction()
if err != nil {
return err
}
defer func() {
transactionContext.RollbackTransaction()
}()
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
for i := range tasks {
task := tasks[i]
task.NextSentAt = nil // 项目不存在,取消周期任务发送
_, err = taskRepository.Insert(task)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err = transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil
}
... ...
package command
type GetUserMessageCommand struct {
UserId int `json:"-"`
}
... ...
... ... @@ -2,6 +2,7 @@ package notify
import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
// 执行定时任务检查是否发送短信通知
var taskSmsNotify *notifySms
// 检查并发送短信通知
... ... @@ -11,7 +12,6 @@ func RunTaskSmsNotify() {
taskSmsNotify.regist(notifyStaffAssess{})
taskSmsNotify.regist(notifySummaryEvaluation{})
taskSmsNotify.runTask()
}
// 每日自评短信通知 ,预创建待发送的短信消息
... ...
package service
import (
"encoding/json"
"fmt"
"strconv"
"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/notify/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// 个人信息提示
type MessagePersonalService struct {
}
func NewMessagePersonalService() *MessagePersonalService {
newService := &MessagePersonalService{}
return newService
}
// 获取今天的周期综合自评消息提示
func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *command.GetUserMessageCommand) (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()
}()
nowTime := time.Now()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": param.UserId,
"types": domain.EvaluationSelf,
"beginTime": nowTime,
"endTime": nowTime,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "周期综合自评"+err.Error())
}
resp := map[string]interface{}{
"needNotify": false,
"content": "",
}
if len(evaluationList) == 0 {
return resp, nil
}
messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
newMessageList := []domain.MessagePersonal{}
for _, val := range evaluationList {
payload := map[string]string{
"id": strconv.Itoa(val.Id),
}
payloadStr, _ := json.Marshal(payload)
cnt, _, err := messageRepo.Find(map[string]interface{}{
"types": domain.MessageTypesOther,
"targetUserId": param.UserId,
"payload": string(payloadStr),
"limit": 1,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查自评消息记录"+err.Error())
}
if cnt == 0 {
newMessageList = append(newMessageList, domain.MessagePersonal{
Id: 0,
Types: domain.MessageTypesOther,
TargetUserId: val.TargetUser.UserId,
ReadFlag: domain.MessageIsRead,
Title: fmt.Sprintf("%s综合自评已开启,请前往进行评估.", val.CycleName),
Content: fmt.Sprintf("%s综合自评已开启,请前往进行评估.", val.CycleName),
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
Payload: string(payloadStr),
})
resp["needNotify"] = true
resp["content"] = fmt.Sprintf("%s综合自评已开启,请前往进行评估.", val.CycleName)
break
}
}
for i := range newMessageList {
err = messageRepo.Save(&newMessageList[i])
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())
}
return resp, nil
}
... ...
... ... @@ -43,6 +43,11 @@ func (notices notifyStaffAssess) makeNotify(param *domain.StaffAssess) *domain.L
// ifSend 确认是否发送通知
func (notices notifyStaffAssess) ifSend(index int) (bool, error) {
nowDay := time.Now().Weekday()
if nowDay == time.Sunday || nowDay == time.Saturday {
//周末不发
return false, nil
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return false, err
... ...
... ... @@ -44,6 +44,11 @@ func (notices notifySummaryEvaluation) makeNotify(param *domain.SummaryEvaluatio
// ifSend 确认是否发送通知
func (notices notifySummaryEvaluation) ifSend(index int) (bool, error) {
nowDay := time.Now().Weekday()
if nowDay == time.Sunday || nowDay == time.Saturday {
//周末不发
return false, nil
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return false, err
... ...
... ... @@ -13,8 +13,8 @@ type ListAssessContentCycleDay struct {
}
type ExportAssessContentCycleDay struct {
CompanyId int `json:"companyId"`
OperaterId int `json:"operaterId"`
CompanyId int `json:"-"`
OperaterId int `json:"-"`
CycleId int `json:"cycleId,string"` //周期id
BeginDayList []string `json:"beginDayList"` //评估开始的时间
TargetUserName string `json:"targetUserName"`
... ...
... ... @@ -1090,13 +1090,13 @@ func (srv StaffAssessServeice) getStaffSuper(transactionContext application.Tran
"transactionContext": transactionContext,
})
userData, err := userRepo.FindOne(map[string]interface{}{
_, userData, err := userRepo.Find(map[string]interface{}{
"id": targetUser.ParentId,
})
if err != nil {
return nil, err
}
return []*domain.User{userData}, nil
return userData, nil
}
func (srv StaffAssessServeice) recoverAssessCache(context application.TransactionContext, assessId int, dataArray []*domain.StaffAssessContent) {
... ...
... ... @@ -14,7 +14,7 @@ import (
// 导出数据
// 综合管理-周期评估
func (srv *SummaryEvaluationService) ExportAllEvaluationSuper(param *command.QueryEvaluationList) (*excelize.File, error) {
func (srv *SummaryEvaluationService) ExportAllEvaluationFinish(param *command.QueryEvaluationList) (*excelize.File, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -41,7 +41,7 @@ func (srv *SummaryEvaluationService) ExportAllEvaluationSuper(param *command.Que
"parentId": param.UserId,
"limit": 1,
})
if len(parentUser) == 0 {
if len(parentUser) == 0 && flagHrbp != 1 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "暂无数据")
}
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
... ... @@ -56,7 +56,7 @@ func (srv *SummaryEvaluationService) ExportAllEvaluationSuper(param *command.Que
//获取评估列表信息
condition1 := map[string]interface{}{
"cycleId": param.CycleId,
"types": int(domain.EvaluationSuper),
"types": int(domain.EvaluationFinish),
"limit": limit,
}
if offset > 0 {
... ... @@ -147,7 +147,15 @@ func (srv *SummaryEvaluationService) ExportAllEvaluationSuper(param *command.Que
firstSheetName := xlsxFile.GetSheetName(sheetIndex)
tableHead := []string{"姓名", "部门", "职位", "最终绩效得分"}
tableHead = append(tableHead, ratingHeader...)
xlsxFile.SetSheetRow(firstSheetName, "A1", &tableHead)
if len(evaluationList) > 0 {
xlsxFile.SetSheetRow(firstSheetName, "A1", &[]string{evaluationList[0].CycleName + "最终成绩"})
// if len(tableHead) > 1 {
// cellCode, _ := excelize.ColumnNumberToName(len(tableHead))
// xlsxFile.MergeCell(firstSheetName, "A1", cellCode+"1")
// }
}
xlsxFile.SetSheetRow(firstSheetName, "A2", &tableHead)
firstDataRow := 3
for i, v := range evaluationList {
departmentName := ""
for _, dep := range v.TargetDepartment {
... ... @@ -176,7 +184,7 @@ func (srv *SummaryEvaluationService) ExportAllEvaluationSuper(param *command.Que
dataRaw = append(dataRaw, "0")
}
}
xlsxFile.SetSheetRow(firstSheetName, fmt.Sprintf("A%d", i+2), &dataRaw)
xlsxFile.SetSheetRow(firstSheetName, fmt.Sprintf("A%d", i+firstDataRow), &dataRaw)
}
return xlsxFile, nil
}
... ...
... ... @@ -73,8 +73,12 @@ func sendSummaryEvaluation(project *domain.EvaluationProject,
}
nodeId := 0
executor360Map := map[int64]*domain.User{}
hrbpExist := false
for _, v := range itemList {
nodeId = v.NodeId
if v.EvaluatorId < 0 {
hrbpExist = true
}
if v.EvaluatorId <= 0 {
continue
}
... ... @@ -106,8 +110,8 @@ func sendSummaryEvaluation(project *domain.EvaluationProject,
DeletedAt: nil,
}
//确定自评
//确定 被评估人的 上级评估
//确定周期评估
for _, v := range targetUserMap {
//处理自评
evaluationTemp.TargetUser = domain.StaffDesc{
... ... @@ -136,13 +140,15 @@ func sendSummaryEvaluation(project *domain.EvaluationProject,
}
//确定自评
newEvaluationList = append(newEvaluationList, evaluationTemp)
//处理人资评估
evaluationTemp.BeginTime = beginTime360
evaluationTemp.EndTime = endTime360
evaluationTemp.Executor = domain.StaffDesc{}
evaluationTemp.Types = domain.EvaluationHrbp
//确定人资评估
newEvaluationList = append(newEvaluationList, evaluationTemp)
if hrbpExist {
//处理人资评估
evaluationTemp.BeginTime = beginTime360
evaluationTemp.EndTime = endTime360
evaluationTemp.Executor = domain.StaffDesc{}
evaluationTemp.Types = domain.EvaluationHrbp
//确定人资评估
newEvaluationList = append(newEvaluationList, evaluationTemp)
}
//处理360 评估
for _, v2 := range executor360Map {
evaluationTemp.BeginTime = beginTime360
... ... @@ -171,6 +177,12 @@ func sendSummaryEvaluation(project *domain.EvaluationProject,
//确定上级评估
newEvaluationList = append(newEvaluationList, evaluationTemp)
}
// 确定 考核结果 的评估记录
evaluationTemp.Types = domain.EvaluationFinish
evaluationTemp.Executor = domain.StaffDesc{}
evaluationTemp.BeginTime = endTimeSuper
evaluationTemp.EndTime = endTimeSuper.Add(2 * 24 * time.Hour)
newEvaluationList = append(newEvaluationList, evaluationTemp)
}
summaryEvaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
for i := range newEvaluationList {
... ... @@ -199,6 +211,11 @@ func dayZeroTime(t time.Time) time.Time {
// 下发周期评估
func TaskSendSummaryEvaluation() error {
nowTime := time.Now()
defer func() {
str := fmt.Sprintf("下发周期评估耗时%.2f s", time.Since(nowTime).Seconds())
log.Logger.Info(str)
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
... ...
... ... @@ -15,6 +15,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/xredis"
)
type SummaryEvaluationService struct {
... ... @@ -59,12 +60,12 @@ func (srv *SummaryEvaluationService) GetExecutorCycleList(param *command.QueryCy
offset = (param.PageNumber - 1) * param.PageSize
}
cycleData, err := evaluationDao.GetExecutorCycleList(param.UserId, offset, limit, isHrbp)
cycleData, err := evaluationDao.GetExecutorCycleList(param.CompanyId, param.UserId, offset, limit, isHrbp)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取周期列表"+err.Error())
}
cnt, err := evaluationDao.CountExecutorCycleList(param.UserId, domain.EvaluationSelf)
cnt, err := evaluationDao.CountExecutorCycleList(param.CompanyId, param.UserId, isHrbp)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -199,11 +200,12 @@ func (srv *SummaryEvaluationService) GetMenu(param *command.QueryMenu) (map[stri
}
//查找当前周期,我的考核结果
_, myEvaluationSuper, _ := evaluationRepo.Find(map[string]interface{}{
"types": int(domain.EvaluationSuper),
_, myEvaluationFinish, _ := evaluationRepo.Find(map[string]interface{}{
"types": int(domain.EvaluationFinish),
"limit": 1,
"targetUserId": param.UserId,
"cycleId": param.CycleId,
"beginTime": time.Now(),
})
if err := transactionContext.CommitTransaction(); err != nil {
... ... @@ -242,15 +244,13 @@ func (srv *SummaryEvaluationService) GetMenu(param *command.QueryMenu) (map[stri
}
menu1.Child = append(menu1.Child, menu1_1)
}
if len(myEvaluationSuper) > 0 {
if myEvaluationSuper[0].CheckResult == domain.EvaluationCheckCompleted {
if len(myEvaluationFinish) > 0 {
if myEvaluationFinish[0].CheckResult == domain.EvaluationCheckCompleted {
menu1_2.StatusName = "已完成"
} else {
menu1_2.StatusName = "未完成"
}
if myEvaluationSuper[0].Status == domain.EvaluationCompleted {
menu1.Child = append(menu1.Child, menu1_2)
}
menu1.Child = append(menu1.Child, menu1_2)
}
if len(selfEvaluation) > 0 {
... ... @@ -367,6 +367,7 @@ func (srv *SummaryEvaluationService) buildSummaryItemValue(itemList []*domain.Ev
item.Value = value.Value
item.Remark = value.Remark
item.Rating = value.Rating
item.EvaluatorName = value.Executor.UserName
}
itemValues = append(itemValues, item)
}
... ... @@ -462,24 +463,14 @@ func (srv *SummaryEvaluationService) getSummaryEvaluation(transactionContext app
TotalScore: evaluationData.TotalScore,
}
//获取用户信息
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,
})
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,
})
userData, err := userRepo.FindOne(map[string]interface{}{"id": evaluationData.TargetUser.UserId})
if err != nil {
return result
}
... ... @@ -487,22 +478,18 @@ func (srv *SummaryEvaluationService) getSummaryEvaluation(transactionContext app
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
if userData.ParentId > 0 {
pUserData, err := userRepo.FindOne(map[string]interface{}{"id": userData.ParentId})
if err != nil {
return result
}
result.SupperUser = pUserData.Name
}
result.SupperUser = pUserData.Name
return result
}
// 编辑综合自评详情
func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
// xredis.NewLockSummaryEvaluation(param.SummaryEvaluationId)
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -596,7 +583,17 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu
// 员工提交自评内容后,
// 员工作为被评估人,
// 变更360评估/人资评估/的开始时间
// 或者变更上级评估的开始时间
// 或者生成考核结果
func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.SummaryEvaluation) error {
lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
err := lock.Lock()
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -619,7 +616,18 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
//如果没有360评估和hrbp 评估,查找上级评估
_, evaluationList, err = evaluationRepo.Find(map[string]interface{}{
"targetUserId": param.TargetUser.UserId,
"typesList": []int{int(domain.EvaluationSuper)},
"cycleId": param.CycleId,
"limit": 10,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
nowTime := time.Now()
updatedId := []int{}
// 变更360评估/人资评估/上级评估的开始时间
... ... @@ -632,21 +640,52 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.
evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
"transactionContext": transactionContext,
})
err = evaluationDao.UpdateBeginTime(updatedId, nowTime)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
//没有上级评估、360评估、hrbp 评估
//直接进入考核结果阶段
_, evaluationList, err = evaluationRepo.Find(map[string]interface{}{
"targetUserId": param.TargetUser.UserId,
"typesList": []int{int(domain.EvaluationFinish)},
"cycleId": param.CycleId,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) > 0 {
// 进入考核结果阶段
if evaluationList[0].BeginTime.After(nowTime) {
evaluationList[0].BeginTime = nowTime
}
evaluationList[0].Status = domain.EvaluationCompleted
err = evaluationRepo.Save(evaluationList[0])
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
// 被评估员工的人资评估 或者 360 评估,
// 提交员工的人资评估 或者 360 评估
// 变更上级评估的开始时间
// 或者生成考核结果
func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *domain.SummaryEvaluation) error {
lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
err := lock.Lock()
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -684,7 +723,7 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *doma
"targetUserId": param.TargetUser.UserId,
"typesList": []int{int(domain.EvaluationSuper)},
"cycleId": param.CycleId,
"limit": 1000,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -705,6 +744,82 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *doma
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
//没有上级评估
//直接进入考核结果阶段
_, evaluationList, err = evaluationRepo.Find(map[string]interface{}{
"targetUserId": param.TargetUser.UserId,
"typesList": []int{int(domain.EvaluationFinish)},
"cycleId": param.CycleId,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) > 0 {
if evaluationList[0].BeginTime.After(nowTime) {
evaluationList[0].BeginTime = nowTime
}
evaluationList[0].Status = domain.EvaluationCompleted
err = evaluationRepo.Save(evaluationList[0])
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
// 员工提交上级评估后
// 生成考核结果
func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(param *domain.SummaryEvaluation) error {
lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
err := lock.Lock()
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//没有上级评估
//直接进入考核结果阶段
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": param.TargetUser.UserId,
"typesList": []int{int(domain.EvaluationFinish)},
"cycleId": param.CycleId,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
nowTime := time.Now()
if len(evaluationList) > 0 {
if evaluationList[0].BeginTime.After(nowTime) {
evaluationList[0].BeginTime = nowTime
}
evaluationList[0].Status = domain.EvaluationCompleted
err = evaluationRepo.Save(evaluationList[0])
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -1062,6 +1177,14 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if !param.IsTemporary {
err = srv.AfterCompletedEvaluationSuper(evaluationData)
if err != nil {
return nil, err
}
}
itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
return map[string][]adapter.EvaluationItemAdapter{
"EvaluationItems": itemValueAdapter,
... ... @@ -1295,40 +1418,117 @@ func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command.
return result, nil
}
// 员工确认综评考核结果
func (srv *SummaryEvaluationService) ConfirmScoreSuperEvaluation(param *command.ConfirmScore) error {
transactionContext, err := factory.CreateTransactionContext(nil)
// ConfirmScoreEvaluation 员工确认考核结果
func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.ConfirmScore) error {
transactionContext, err := factory.ValidateStartTransaction(param)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{
"id": param.SummaryEvaluationId,
})
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
// 考核结果
result, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if evaluationData.Types != domain.EvaluationSuper {
if result.Types != domain.EvaluationFinish {
return application.ThrowError(application.TRANSACTION_ERROR, "操作方式错误")
}
if evaluationData.TargetUser.UserId != param.UserId {
if result.TargetUser.UserId != param.UserId {
return application.ThrowError(application.TRANSACTION_ERROR, "没有操作权限")
}
if evaluationData.Status == domain.EvaluationUncompleted {
return application.ThrowError(application.TRANSACTION_ERROR, "上级还未正式提交评估内容")
if result.CheckResult == domain.EvaluationCheckCompleted {
return application.ThrowError(application.TRANSACTION_ERROR, "考核结果已确认过了!")
}
evaluationData.CheckResult = domain.EvaluationCheckCompleted
err = evaluationRepo.Save(evaluationData)
if result.Status == domain.EvaluationUncompleted {
return application.ThrowError(application.TRANSACTION_ERROR, "前面流程暂未完成提交评估内容")
}
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"companyId": result.CompanyId,
"cycleId": result.CycleId,
"targetUserId": result.TargetUser.UserId,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var super *domain.SummaryEvaluation // 上级评估
for i := range evaluationList {
it := evaluationList[i]
if it.Types == domain.EvaluationSuper {
super = it
break
}
}
// 评估内容和值
var itemList []*domain.EvaluationItemUsed
var itemValues []*domain.SummaryEvaluationValue
// 获取自评模板内容
_, itemList, err = evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 按评估项优先级顺序(已确认考核结果 ->上级评估 ->HR或360评估或自评)
if super != nil {
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 更新填写值
itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues, true)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
} else {
// 评估项ID(除考核结果和上级)
var evaluationIds = make([]int, 0)
for i := range evaluationList {
it := evaluationList[i]
if it.Types == domain.EvaluationSelf || it.Types == domain.Evaluation360 || it.Types == domain.EvaluationHrbp {
evaluationIds = append(evaluationIds, it.Id)
}
}
if len(evaluationIds) > 0 {
// 获取已填写的评估内容
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 更新填写值
itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues, false)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
for i := range itemValues {
if err := itemValueRepo.Save(itemValues[i]); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
//重置评级汇总
result.TotalRating = nil
for i := range itemList {
result.ResetTotalRating(itemList[i])
}
if err := result.EvaluationTotalScore(itemValues); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
result.CheckResult = domain.EvaluationCheckCompleted
if err := evaluationRepo.Save(result); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
... ... @@ -1337,107 +1537,184 @@ func (srv *SummaryEvaluationService) ConfirmScoreSuperEvaluation(param *command.
return nil
}
// 按照周期和被评估的人 获取上级评估详情
func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command.QueryEvaluation) (*adapter.EvaluationInfoSuperAdapter, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// 处理优先级
func (srv *SummaryEvaluationService) updateItemValuePriority(
result *domain.SummaryEvaluation,
itemList []*domain.EvaluationItemUsed,
itemValues []*domain.SummaryEvaluationValue,
superior bool) ([]*domain.SummaryEvaluationValue, error) {
tempSelf := map[int]*domain.SummaryEvaluationValue{}
temp360 := map[int]*domain.SummaryEvaluationValue{}
tempHRBP := map[int]*domain.SummaryEvaluationValue{}
tempSuperior := map[int]*domain.SummaryEvaluationValue{}
for i := range itemValues {
it := itemValues[i]
if it.Types == domain.EvaluationSelf {
tempSelf[it.EvaluationItemId] = it
} else if it.Types == domain.Evaluation360 {
temp360[it.EvaluationItemId] = it
} else if it.Types == domain.EvaluationHrbp {
tempHRBP[it.EvaluationItemId] = it
} else if it.Types == domain.EvaluationSuper {
tempSuperior[it.EvaluationItemId] = it
}
}
if err := transactionContext.StartTransaction(); err != nil {
nowTime := time.Now()
var newItemValues = make([]*domain.SummaryEvaluationValue, 0)
for i := range itemList {
it := itemList[i]
var tempValue domain.SummaryEvaluationValue
tempValue.SetBlankValue(result, it)
if superior /* 上级数据 */ {
if v, ok := tempSuperior[it.Id]; ok {
tempValue = *v
}
tempValue.Types = domain.EvaluationSuper
} else /* 其它数据 */ {
if it.EvaluatorId == 0 {
if v, ok := tempSelf[it.Id]; ok {
tempValue = *v
}
tempValue.Types = domain.EvaluationSelf
} else if it.EvaluatorId == -1 {
if v, ok := tempHRBP[it.Id]; ok {
tempValue = *v
}
tempValue.Types = domain.EvaluationHrbp
} else if it.EvaluatorId > 0 {
if v, ok := temp360[it.Id]; ok {
tempValue = *v
}
tempValue.Types = domain.Evaluation360
}
}
// ID置空
tempValue.Id = 0
tempValue.CreatedAt = nowTime
tempValue.UpdatedAt = nowTime
newItemValues = append(newItemValues, &tempValue)
}
return newItemValues, nil
}
// GetTargetEvaluationResult 按照周期和被评估的人 获取考核结果
func (srv *SummaryEvaluationService) GetTargetEvaluationResult(param *command.QueryEvaluation) (*adapter.EvaluationInfoSuperAdapter, error) {
transactionContext, err := factory.ValidateStartTransaction(param)
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()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
permissionRepository := factory.CreatePermissionRepository(map[string]interface{}{"transactionContext": transactionContext})
// 获取权限配置
_, permissionList, err := permissionRepository.Find(map[string]interface{}{"companyId": param.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"limit": 1,
"companyId": param.CompanyId,
"cycleId": param.CycleId,
"targetUserId": param.TargetUserId,
"types": domain.EvaluationSuper,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有找到符合条件的数据")
}
evaluationData := evaluationList[0]
if evaluationData.CompanyId != param.CompanyId {
return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
var result *domain.SummaryEvaluation // 绩效考核结果项
var super *domain.SummaryEvaluation // 上级评估
for i := range evaluationList {
it := evaluationList[i]
if it.Types == domain.EvaluationFinish {
result = it
continue
}
if it.Types == domain.EvaluationSuper {
super = it
continue
}
}
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
"evaluationProjectId": evaluationData.EvaluationProjectId,
"nodeType": int(domain.LinkNodeSelfAssessment),
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if result == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有找到符合条件的数据")
}
//获取已填写的评估内容
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{
"summaryEvaluationId": evaluationData.Id,
})
// 评估内容和值
var itemList []*domain.EvaluationItemUsed
var itemValues []*domain.SummaryEvaluationValue
// 获取自评模板内容
_, itemList, err = evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(itemValues) == 0 {
//上级还未填写评估,获取 360 ,人资评估
_, evaluationListOther, err := evaluationRepo.Find(map[string]interface{}{
"typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
"targetUserId": evaluationData.TargetUser.UserId,
"cycleId": evaluationData.CycleId,
})
// 按评估项优先级顺序(已确认考核结果 ->上级评估 ->HR或360评估或自评)
if result.CheckResult == domain.EvaluationCheckCompleted { /* 已完成考核*/
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id}) // 获取已填写的评估内容
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationIds := []int{}
for _, v := range evaluationListOther {
evaluationIds = append(evaluationIds, v.Id)
}
if len(evaluationIds) > 0 {
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{
"summaryEvaluationIdList": evaluationIds,
})
} else {
if super != nil {
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
} else {
// 评估项ID(除考核结果和上级)
var evaluationIds = make([]int, 0)
for i := range evaluationList {
it := evaluationList[i]
if it.Types == domain.EvaluationSelf || it.Types == domain.Evaluation360 || it.Types == domain.EvaluationHrbp {
evaluationIds = append(evaluationIds, it.Id)
}
}
if len(evaluationIds) > 0 {
// 获取已填写的评估内容
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 更新填写值
itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues, false)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
}
evaluationBase := srv.getSummaryEvaluation(transactionContext, evaluationData)
// 未完成考核,需要重新计算分数
if result.CheckResult == domain.EvaluationCheckUncompleted {
result.TotalRating = nil
for i := range itemList {
result.ResetTotalRating(itemList[i])
}
if err = result.EvaluationTotalScore(itemValues); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
// 基础数据
evaluationBase := srv.getSummaryEvaluation(transactionContext, result)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//组合 评估填写的值和评估项
// 组合 评估填写的值和评估项
itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
codeList := []*adapter.LevalCodeCount{}
codeMap := map[string]*adapter.LevalCodeCount{}
for i, v := range itemValuesAdapter {
if len(permissionList) > 0 {
if permissionList[0].OptEvalScore == domain.PermissionOff &&
v.EvaluatorId > 0 {
itemValuesAdapter[i].ForbidEdit = true
}
if permissionList[0].OptHrScore == domain.PermissionOff &&
v.EvaluatorId < 0 {
itemValuesAdapter[i].ForbidEdit = true
}
}
if v.Weight == 0 {
for _, v := range itemValuesAdapter {
//处理加分项评级汇总
if v.Weight == 0 && len(v.Value) > 0 {
if _, ok := codeMap[v.Value]; !ok {
code := &adapter.LevalCodeCount{
Code: v.Value,
... ... @@ -1445,23 +1722,33 @@ func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command
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{
codeList := make([]*adapter.LevalCodeCount, 0)
for _, val := range result.TotalRating {
if codeItem, ok := codeMap[val.Code]; ok {
codeList = append(codeList, codeItem)
} else {
codeList = append(codeList, &adapter.LevalCodeCount{
Code: val.Code,
Number: 0,
ItemList: []string{},
})
}
}
eiAdapter := adapter.EvaluationInfoSuperAdapter{
EvaluationBaseAdapter: evaluationBase,
LevelCount: codeList,
EvaluationItems: itemValuesAdapter,
}
return &result, nil
return &eiAdapter, nil
}
// 获取周期综合评估下,周期评估列表
func (srv *SummaryEvaluationService) ListAllEvaluationSuper(param *command.QueryEvaluationList) (map[string]interface{}, error) {
// 按周期获取所有员工的评估考核结果
func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.QueryEvaluationList) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -1489,7 +1776,7 @@ func (srv *SummaryEvaluationService) ListAllEvaluationSuper(param *command.Query
"parentId": param.UserId,
"limit": 1,
})
if len(parentUser) == 0 {
if len(parentUser) == 0 && flagHrbp != 1 {
return tool_funs.SimpleWrapGridMap(0, []string{}), nil
}
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
... ... @@ -1505,7 +1792,7 @@ func (srv *SummaryEvaluationService) ListAllEvaluationSuper(param *command.Query
//获取评估列表信息
condition1 := map[string]interface{}{
"cycleId": param.CycleId,
"types": int(domain.EvaluationSuper),
"types": int(domain.EvaluationFinish),
"limit": limit,
"beginTime": time.Now(),
}
... ... @@ -1606,12 +1893,14 @@ func (srv *SummaryEvaluationService) editEvaluationValue(
}
evaluationItemMap := map[int]*domain.EvaluationItemUsed{}
evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
evaluationValueSlice := []*domain.SummaryEvaluationValue{}
evaluationData.TotalRating = nil //清空评级数量统计
for _, v := range evaluationItems {
newValue := &domain.SummaryEvaluationValue{}
newValue.SetBlankValue(evaluationData, v)
evaluationValueMap[v.Id] = newValue
evaluationItemMap[v.Id] = v
evaluationValueSlice = append(evaluationValueSlice, newValue)
//重置计数
evaluationData.ResetTotalRating(v)
}
... ... @@ -1669,10 +1958,14 @@ func (srv *SummaryEvaluationService) editEvaluationValue(
}
}
//完全更新itemValueList
*itemValueList = (*itemValueList)[0:0]
for _, v := range evaluationValueMap {
*itemValueList = append(*itemValueList, v)
}
*itemValueList = evaluationValueSlice
// *itemValueList = (*itemValueList)[0:0]
// for _, v := range evaluationValueMap {
// *itemValueList = append(*itemValueList, v)
// }
// sort.Slice(*itemValueList, func(i, j int) bool {
// return (*itemValueList)[i].EvaluationItemId < (*itemValueList)[j].EvaluationItemId
// })
// 计算总得分
err := evaluationData.EvaluationTotalScore(*itemValueList)
if err != nil {
... ... @@ -1685,7 +1978,7 @@ func (srv *SummaryEvaluationService) editEvaluationValue(
func (srv *SummaryEvaluationService) ListExecutorNowEvaluationSelf(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, err
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -21,7 +21,7 @@ type EvaluationItemUsed struct {
Rule EvaluationRule //评估的选项规则
Weight float64 //"权重"
Required int //必填项 同 NodeContent.Required
EvaluatorId int //项目评估人ID ( 0=无评估人、-1=HRBP、 >0 =员工的id )
EvaluatorId int //项目评估人ID ( 0=无评估人、-1=HRBP、 >0 员工的id )
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
}
... ...
package domain
import "time"
// MessagePersonal 个人的消息提示
type MessagePersonal struct {
Id int `json:"id"` //
Types MessageTypes `json:"types"` //消息类型
TargetUserId int `json:"targetUserId"` //消息指向的用户
ReadFlag MessageReadFlag `json:"readFlag"` //1:已读、2:未读
Title string `json:"title"` //消息的标题
Content string `json:"content"` //消息的内容
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Payload string `json:"payload"` //消息的额外承载的数据
}
type MessageTypes string
const (
MessageTypesOther MessageTypes = "other"
)
type MessageReadFlag string
const (
MessageIsRead MessageReadFlag = "read"
MessageUnread MessageReadFlag = "unread"
)
type MessagePersonalRepository interface {
Save(param *MessagePersonal) error
Find(queryOptions map[string]interface{}) (int, []*MessagePersonal, error)
}
... ...
... ... @@ -263,6 +263,9 @@ func getEvaluator(items []*PerformanceApplicationForm) (string, error) {
return "", errors.New(item.ModuleName + " 对应的项目评估人填不一致")
}
}
if prevName == "/" {
prevName = ""
}
return prevName, nil
}
... ...
... ... @@ -39,11 +39,11 @@ type RatingCodeNumber struct {
type EvaluationType int //综合评估类型
const (
EvaluationSelf EvaluationType = 1 //自评
Evaluation360 EvaluationType = 2 //360评估
EvaluationSuper EvaluationType = 3 //上级评估
EvaluationHrbp EvaluationType = 4 //人资评估
EvaluationSelf EvaluationType = 1 //自评
Evaluation360 EvaluationType = 2 //360评估
EvaluationSuper EvaluationType = 3 //上级评估
EvaluationHrbp EvaluationType = 4 //人资评估
EvaluationFinish EvaluationType = 5 //考核结果
)
// 评估的填写状态
... ... @@ -72,6 +72,9 @@ type SummaryEvaluationRepository interface {
// 计算总分。TotalScore 保留1位小数
func (evaluation *SummaryEvaluation) EvaluationTotalScore(valueList []*SummaryEvaluationValue) error {
//重置计数
evaluation.TotalScore = "0"
//汇总评估填写值
var totalScore float64
for _, v := range valueList {
if v.Weight == 0 {
... ...
... ... @@ -17,6 +17,7 @@ type SummaryEvaluationValue struct {
Score string `json:"score"` //评定得分
Types EvaluationType `json:"types"` //评估类型
Remark string `json:"remark"` //填写的内容反馈
Executor StaffDesc `json:"executor"` //填写评估的用户,执行人
Weight float64 `json:"weight"` //"权重"
Rating RatingLevel `json:"rating"` //评级时的填写值
CreatedAt time.Time `json:"createdAt"` //数据创建时间
... ... @@ -36,11 +37,12 @@ func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvalua
itemValue.EvaluationItemId = item.Id
itemValue.SummaryEvaluationId = evaluation.Id
itemValue.Value = ""
itemValue.Score = ""
itemValue.Score = "0"
itemValue.Remark = ""
itemValue.Weight = item.Weight
itemValue.CreatedAt = time.Now()
itemValue.UpdatedAt = time.Now()
itemValue.Executor = evaluation.Executor
}
// 填充评估的内容
... ...
... ... @@ -50,6 +50,7 @@ func (userAuth *UserAuth) ParseAccessToken(token string) (*UserAuth, error) {
user.PlatformId = claim.PlatformId
user.Name = claim.Name
user.AdminType = claim.AdminType
user.CompanyName = claim.CompanyName
return user, nil
}
return user, errors.New("解析token失败")
... ...
package domain
import "testing"
import (
"testing"
"github.com/dgrijalva/jwt-go"
)
func TestGenerateToken(t *testing.T) {
ut := UserAuth{
CompanyId: 8,
UserId: 3422174102828544,
Phone: "17708397664",
UserId: 3422052605249024,
Phone: "13677777777",
PlatformId: 29,
AdminType: 1,
}
tk, _ := ut.CreateAccessToken()
t.Log(tk)
}
func TestParsetToken1(t *testing.T) {
ut := UserAuth{}
str := `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjM0MjE4NDc3MjcyOTYwMDAsImNvbXBhbnlJZCI6MTAsImNvbXBhbnlOYW1lIjoi5aSp6IGU5L-h5oGv56eR5oqA5pyJ6ZmQ5YWs5Y-4IiwicGhvbmUiOiIxNTY1OTM3NTk0MCIsInBsYXRmb3JtSWQiOjI5LCJuYW1lIjoi5bq35Lyf5Y2OIiwiYWRtaW5UeXBlIjoxfQ.v4qNLvYST03XpBdGnhYTK78A9v_k5IOdZ4r-WmDwfYg`
tk, _ := ut.ParseAccessToken(str)
t.Logf("%+v", tk)
}
func TestParsetToken2(t *testing.T) {
ut := UserAuth{}
str := `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjM0MjYxMDAxMTcwOTM4ODgsImNvbXBhbnlJZCI6MSwiY29tcGFueU5hbWUiOiLnpo_lt57ntKDlpKnkuIvpo5_lk4HmnInpmZDlhazlj7giLCJwaG9uZSI6IjE1NjU5Mzc1OTQwIiwicGxhdGZvcm1JZCI6MjksIm5hbWUiOiLlurfkvJ_ljY4iLCJhZG1pblR5cGUiOjF9.BwJ2mLdTlFKF322y4GeqPOW6wKroIrPSI8eNyuQEMkQ`
tk, _ := ut.ParseAccessToken(str)
t.Logf("===》%+v", tk)
tk.StandardClaims = jwt.StandardClaims{}
tk.PlatformId = 29
tkStr, _ := tk.CreateAccessToken()
t.Logf(" ===》%v", tkStr)
}
... ...
... ... @@ -5,7 +5,6 @@ import (
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type SummaryEvaluationDao struct {
... ... @@ -31,7 +30,7 @@ type ExecutorCycle struct {
// GetExecutorCycleList 获取执行人拥有的周期列表
// executorId 执行人id
// offset,limit 分页
func (d *SummaryEvaluationDao) GetExecutorCycleList(executorId int, offset int, limit int, isHrbp bool) ([]ExecutorCycle, error) {
func (d *SummaryEvaluationDao) GetExecutorCycleList(companyId int, executorId int, offset int, limit int, isHrbp bool) ([]ExecutorCycle, error) {
sqlStr := `select
distinct on(
summary_evaluation.cycle_id ,
... ... @@ -40,14 +39,16 @@ func (d *SummaryEvaluationDao) GetExecutorCycleList(executorId int, offset int,
summary_evaluation.cycle_id ,
summary_evaluation.cycle_name
from summary_evaluation
where summary_evaluation.executor ->>'userId'='?'
where summary_evaluation.company_id=?
`
tx := d.transactionContext.PgTx
condition := []interface{}{
executorId,
companyId, executorId,
}
if isHrbp {
sqlStr += ` or summary_evaluation."types"=4 `
sqlStr += ` and (summary_evaluation.executor ->>'userId'='?' or summary_evaluation."types"=4 ) `
} else {
sqlStr += ` and (summary_evaluation.executor ->>'userId'='?') `
}
condition = append(condition, offset, limit)
... ... @@ -58,22 +59,22 @@ func (d *SummaryEvaluationDao) GetExecutorCycleList(executorId int, offset int,
}
// CountExecutorCycleList 统计执行人拥有的周期列表
func (d *SummaryEvaluationDao) CountExecutorCycleList(executorId int, evaluationType domain.EvaluationType) (int, error) {
func (d *SummaryEvaluationDao) CountExecutorCycleList(companyId int, executorId int, isHrbp bool) (int, error) {
sqlStr := `select count(
distinct summary_evaluation.cycle_id
) as cnt
from summary_evaluation
where summary_evaluation.executor ->>'userId'='?' `
where summary_evaluation.company_id=? `
tx := d.transactionContext.PgTx
condition := []interface{}{
executorId,
companyId, executorId,
}
if evaluationType > 0 {
sqlStr += ` and summary_evaluation."types"=? `
condition = append(condition, int(evaluationType))
if isHrbp {
sqlStr += ` and (summary_evaluation.executor ->>'userId'='?' or summary_evaluation."types"=4 ) `
} else {
sqlStr += ` and (summary_evaluation.executor ->>'userId'='?') `
}
var cnt int
_, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...)
return cnt, err
... ...
... ... @@ -51,6 +51,7 @@ func init() {
&models.SummaryEvaluationValue{},
&models.Permission{},
&models.LogSms{},
&models.MessagePersonal{},
}
for _, model := range tables {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
... ...
package models
import "time"
// MessagePersonal 记录个人的提示消息
type MessagePersonal struct {
tableName struct{} `comment:"记录个人的提示消息" pg:"message_personal"`
Id int `pg:"id,pk"` //
Types string `pg:"types"` //消息类型
TargetUserId int `pg:"target_user_id"` //消息指向的用户
ReadFlag string `pg:"read_flag"` //1:已读、2:未读
Title string `pg:"title"` //消息的标题
Content string `pg:"content"` //消息的内容
CreatedAt time.Time `pg:"created_at"`
UpdatedAt time.Time `pg:"updated_at"`
Payload string `pg:"payload,type:jsonb"` //消息的额外承载的数据
}
... ...
... ... @@ -15,6 +15,7 @@ type SummaryEvaluationValue struct {
Value string //评估填写的评分
Score string //评定得分
Types int //评估类型
Executor domain.StaffDesc //填写评估的用户,执行人
Weight float64 //权重
Rating domain.RatingLevel //评级填写值
Remark string //填写的内容反馈
... ...
... ... @@ -36,6 +36,7 @@ func (repo *LogSmsRepository) Save(param *domain.LogSms) error {
if err != nil {
return err
}
return nil
}
_, err := tx.Model(&m).WherePK().Update()
if err != nil {
... ...
package repository
import (
"time"
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"
)
type MessagePersonalRepository struct {
transactionContext *pgTransaction.TransactionContext
}
var _ domain.MessagePersonalRepository = (*MessagePersonalRepository)(nil)
func NewMessagePersonalRepository(tx *pgTransaction.TransactionContext) *MessagePersonalRepository {
return &MessagePersonalRepository{
transactionContext: tx,
}
}
func (repo *MessagePersonalRepository) TransformToDomain(param *models.MessagePersonal) *domain.MessagePersonal {
return &domain.MessagePersonal{
Id: param.Id,
Types: domain.MessageTypes(param.Types),
TargetUserId: param.TargetUserId,
ReadFlag: domain.MessageReadFlag(param.ReadFlag),
Title: param.Title,
Content: param.Content,
Payload: param.Payload,
UpdatedAt: param.UpdatedAt,
CreatedAt: param.CreatedAt,
}
}
func (repo *MessagePersonalRepository) Save(param *domain.MessagePersonal) error {
message := &models.MessagePersonal{
Id: param.Id,
Types: string(param.Types),
TargetUserId: param.TargetUserId,
ReadFlag: string(param.ReadFlag),
Title: param.Title,
Content: param.Content,
Payload: param.Payload,
UpdatedAt: time.Now(),
CreatedAt: param.CreatedAt,
}
tx := repo.transactionContext.PgTx
if message.Id == 0 {
message.CreatedAt = time.Now()
_, err := tx.Model(message).Insert()
return err
}
_, err := tx.Model(message).WherePK().Update()
return err
}
func (repo *MessagePersonalRepository) Find(param map[string]interface{}) (int, []*domain.MessagePersonal, error) {
tx := repo.transactionContext.PgTx
var m []*models.MessagePersonal
query := tx.Model(&m).Limit(20)
if v, ok := param["targetUserId"]; ok {
query.Where("target_user_id=?", v)
}
if v, ok := param["types"]; ok {
query.Where("types=?", v)
}
if v, ok := param["payload"]; ok {
query.Where("payload @>?", v)
}
query.Order("id desc")
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var datas []*domain.MessagePersonal
for _, v := range m {
d := repo.TransformToDomain(v)
datas = append(datas, d)
}
return count, datas, nil
}
... ...
... ... @@ -131,7 +131,7 @@ func (repo *NodeTaskRepository) Find(queryOptions map[string]interface{}) ([]*do
var m []*models.NodeTask
query := tx.Model(&m).Where("deleted_at isnull")
if v, ok := queryOptions["now"].(time.Time); ok {
if v, ok := queryOptions["lessNextSentAt"].(time.Time); ok {
query.Where("next_sent_at <= ?", v)
}
... ...
... ... @@ -30,6 +30,7 @@ func (repo *SummaryEvaluationValueRepository) TransformToDomain(d *models.Summar
Score: d.Score,
Types: domain.EvaluationType(d.Types),
Remark: d.Remark,
Executor: d.Executor,
Weight: d.Weight,
Rating: d.Rating,
CreatedAt: d.CreatedAt,
... ... @@ -45,6 +46,7 @@ func (repo *SummaryEvaluationValueRepository) Save(param *domain.SummaryEvaluati
Value: param.Value,
Score: param.Score,
Types: int(param.Types),
Executor: param.Executor,
Weight: param.Weight,
Rating: param.Rating,
Remark: param.Remark,
... ... @@ -118,7 +120,7 @@ func (repo *SummaryEvaluationValueRepository) Find(queryOptions map[string]inter
if v, ok := queryOptions["types"]; ok {
query.Where("types=?", v)
}
query.Order("evaluation_item_id")
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
... ... @@ -10,8 +10,8 @@ type LockSummaryEvaluation struct {
m *redsync.Mutex
}
func NewLockSummaryEvaluation(id int) *LockSummaryEvaluation {
key := fmt.Sprintf("performance:summary_evaluation:%d", id)
func NewLockSummaryEvaluation(targetUserId int) *LockSummaryEvaluation {
key := fmt.Sprintf("performance:summary_evaluation:%d", targetUserId)
return &LockSummaryEvaluation{
m: rsync.NewMutex(key),
... ...
... ... @@ -20,14 +20,19 @@ func (controller *AuthController) Login() {
controller.Response(resp, err)
}
// 获取个人信息
func (controller *AuthController) User() {
userAuth := controller.Ctx.Input.GetData(domain.UserAuth{}).(*domain.UserAuth)
controller.Response(map[string]interface{}{
"user": userAuth,
}, nil)
authService := &service.AuthService{}
param := &command.GetMeInfo{
UserId: userAuth.UserId,
CompanyId: userAuth.CompanyId,
}
resp, err := authService.MeInfo(param)
controller.Response(resp, err)
}
// Login PC端登录
// Login 手机端登录
func (controller *AuthController) MobileLogin() {
authService := &service.AuthService{}
loginCommand := &command.MobileLoginCommand{}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/service"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
// 获取个人的消息提示
type MessagePersonalController struct {
beego.BaseController
}
// 周期综合自评是否开启,是否提示
func (c *MessagePersonalController) TodayMessageSummaryEvaluation() {
srv := service.NewMessagePersonalService()
userReq := middlewares.GetUser(c.Ctx)
param := command.GetUserMessageCommand{}
param.UserId = int(userReq.UserId)
data, err := srv.TodayMessageSummaryEvaluationSelf(&param)
c.Response(data, err)
}
... ...
... ... @@ -288,8 +288,8 @@ func (c *SummaryEvaluationController) ListExecutorEvaluationSuper() {
c.Response(data, err)
}
// 员工确认评估分数
func (c *SummaryEvaluationController) ConfirmScoreSuperEvaluation() {
// ConfirmScoreEvaluation 员工确认评估分数
func (c *SummaryEvaluationController) ConfirmScoreEvaluation() {
srv := service.NewSummaryEvaluationService()
param := &command.ConfirmScore{}
err := c.BindJSON(param)
... ... @@ -300,12 +300,12 @@ func (c *SummaryEvaluationController) ConfirmScoreSuperEvaluation() {
}
userReq := middlewares.GetUser(c.Ctx)
param.UserId = int(userReq.UserId)
err = srv.ConfirmScoreSuperEvaluation(param)
err = srv.ConfirmScoreEvaluation(param)
c.Response(nil, err)
}
// GetTargetUserEvaluationSuper 根据被评估人和周期获取 上级评估
func (c *SummaryEvaluationController) GetTargetUserEvaluationSuper() {
// GetTargetEvaluationResult 按照周期和被评估的人 获取考核结果
func (c *SummaryEvaluationController) GetTargetEvaluationResult() {
srv := service.NewSummaryEvaluationService()
paramReq := &command.QueryEvaluation{}
err := c.BindJSON(paramReq)
... ... @@ -316,12 +316,12 @@ func (c *SummaryEvaluationController) GetTargetUserEvaluationSuper() {
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
data, err := srv.GetTargetUserEvaluationSuper(paramReq)
data, err := srv.GetTargetEvaluationResult(paramReq)
c.Response(data, err)
}
// 按周期获取上级评估列表
func (c *SummaryEvaluationController) ListAllEvaluationSuper() {
func (c *SummaryEvaluationController) ListAllEvaluationFinish() {
srv := service.NewSummaryEvaluationService()
param := &command.QueryEvaluationList{}
err := c.BindJSON(param)
... ... @@ -333,12 +333,12 @@ func (c *SummaryEvaluationController) ListAllEvaluationSuper() {
userReq := middlewares.GetUser(c.Ctx)
param.CompanyId = int(userReq.CompanyId)
param.UserId = int(userReq.UserId)
data, err := srv.ListAllEvaluationSuper(param)
data, err := srv.ListAllEvaluationFinish(param)
c.Response(data, err)
}
// 按周期 导出上级评估列表
func (c *SummaryEvaluationController) ExportAllEvaluationSuper() {
func (c *SummaryEvaluationController) ExportAllEvaluationFinish() {
srv := service.NewSummaryEvaluationService()
param := &command.QueryEvaluationList{}
err := c.BindJSON(param)
... ... @@ -350,7 +350,7 @@ func (c *SummaryEvaluationController) ExportAllEvaluationSuper() {
userReq := middlewares.GetUser(c.Ctx)
param.UserId = int(userReq.UserId)
param.CompanyId = int(userReq.CompanyId)
data, err := srv.ExportAllEvaluationSuper(param)
data, err := srv.ExportAllEvaluationFinish(param)
if err != nil {
c.Response(nil, err)
return
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/message-personal",
web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()),
web.NSCtrlGet("/summary-evaluation/self/today", (*controllers.MessagePersonalController).TodayMessageSummaryEvaluation),
)
web.AddNamespace(ns)
}
... ...
... ... @@ -27,10 +27,13 @@ func init() {
web.NSCtrlPost("/evaluation-super", (*controllers.SummaryEvaluationController).GetEvaluationSuper),
web.NSCtrlPost("/evaluation-super/edit", (*controllers.SummaryEvaluationController).EditEvaluationSuper),
web.NSCtrlPost("/evaluation-super/list", (*controllers.SummaryEvaluationController).ListExecutorEvaluationSuper),
web.NSCtrlPost("/evaluation-super/confirm", (*controllers.SummaryEvaluationController).ConfirmScoreSuperEvaluation),
web.NSCtrlPost("/target_user/evaluation-super", (*controllers.SummaryEvaluationController).GetTargetUserEvaluationSuper),
web.NSCtrlPost("/evaluation-super/all", (*controllers.SummaryEvaluationController).ListAllEvaluationSuper),
web.NSCtrlPost("/evaluation-super/all/export", (*controllers.SummaryEvaluationController).ExportAllEvaluationSuper),
web.NSCtrlPost("/evaluation-super/confirm", (*controllers.SummaryEvaluationController).ConfirmScoreEvaluation),
web.NSCtrlPost("/evaluation-result", (*controllers.SummaryEvaluationController).GetTargetEvaluationResult),
//web.NSCtrlPost("/target_user/evaluation-super", (*controllers.SummaryEvaluationController).GetTargetEvaluationResult),
// web.NSCtrlPost("/evaluation-super/all", (*controllers.SummaryEvaluationController).ListAllEvaluationSuper),
web.NSCtrlPost("/evaluation-finish/all", (*controllers.SummaryEvaluationController).ListAllEvaluationFinish),
// web.NSCtrlPost("/evaluation-super/all/export", (*controllers.SummaryEvaluationController).ExportAllEvaluationSuper),
web.NSCtrlPost("/evaluation-finish/all/export", (*controllers.SummaryEvaluationController).ExportAllEvaluationFinish),
web.NSCtrlGet("/evaluation-self/now", (*controllers.SummaryEvaluationController).ListExecutorEvaluationSelf),
//
)
... ...
-- summary_evaluation_value表添加字段
ALTER TABLE public.summary_evaluation_value
ADD executor jsonb NULL;
-- 初始化旧数据的summary_evaluation_value.executor
UPDATE
public.summary_evaluation_value
SET
executor = public.summary_evaluation.executor
FROM
public.summary_evaluation
WHERE
public.summary_evaluation_value.summary_evaluation_id = public.summary_evaluation.id;
... ...