作者 tangxvhui

Merge branch 'test'

正在显示 37 个修改的文件 包含 1970 行增加287 行删除
... ... @@ -56,7 +56,7 @@ func startSummaryEvaluation() {
timer := time.NewTimer(duration)
for {
<-timer.C
if err := serviceSummary.TaskSendSummaryEvaluation(); err != nil {
if err := serviceSummary.TaskSendSummaryEvaluationV2(); err != nil {
log.Logger.Error(err.Error())
}
timer.Reset(duration) // 重置定时
... ...
... ... @@ -2,6 +2,7 @@ package adapter
type MeInfo struct {
UserId int64 `json:"userId"` //用户名称
CompanyLogo string `json:"companyLogo"` //图标
CompanyId int64 `json:"companyId"` //公司id
CompanyName string `json:"companyName"` //公司名称
Phone string `json:"phone"` // 手机号
... ...
... ... @@ -220,6 +220,7 @@ loop:
UserId: userData.Id,
CompanyId: companyData.Id,
CompanyName: companyData.Name,
CompanyLogo: companyData.Logo,
Phone: userData.Account,
Name: userData.Name,
IsHrbp: isHrbp,
... ...
... ... @@ -3,6 +3,7 @@ package service
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/linmadan/egglib-go/core/application"
... ... @@ -170,7 +171,7 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 项目调整截止时间,同步更新任务时间
if err := rs.updateTaskTime(transactionContext, in.Id, end); err != nil {
if err := rs.updateTaskTime(transactionContext, in.Id, &end); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -179,31 +180,35 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
}
return project, nil
} else {
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 周期内的所有项目,员工不能重复被评估
rids := map[string]bool{}
for i := range projects {
// 排除当前项目
if in.Id != projects[i].Id {
ids := projects[i].Recipients
for j := range ids {
rids[ids[j]] = true
}
}
}
repeatNum := 0
for i := range in.Recipients {
id := in.Recipients[i]
if _, ok := rids[id]; ok {
repeatNum++
}
}
if repeatNum > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("有%d人已经在本周期其他项目内,需要将他们移除", repeatNum))
}
//_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "template")
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//// 周期内的所有项目,员工不能重复被评估
//rids := map[string]bool{}
//for i := range projects {
// it := projects[i]
// // 排除当前项目
// if in.Id == it.Id {
// continue
// }
// // 启用状态
// if it.State == domain.ProjectStateEnable {
// for j := range it.Recipients {
// rids[it.Recipients[j]] = true
// }
// }
//}
//repeatNum := 0
//for i := range in.Recipients {
// id := in.Recipients[i]
// if _, ok := rids[id]; ok {
// repeatNum++
// }
//}
//if repeatNum > 0 {
// return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("有%d人已经在本周期其他项目内,需要将他们移除", repeatNum))
//}
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true})
if err != nil {
... ... @@ -237,6 +242,32 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
return nil, application.ThrowError(application.BUSINESS_ERROR, "评估截至时间不能超出周期截至时间")
}
// 判断起始时间,是否有被评估人的任务
assessTaskRepository := factory.CreateStaffAssessTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
_, assessTasks, err := assessTaskRepository.Find(map[string]interface{}{
"companyId": in.CompanyId,
"cycleId": in.CycleId,
"beginDay": start.Format("2006-01-02"),
})
rids := map[int]int{}
for i1 := range assessTasks {
it := assessTasks[i1]
for i2 := range it.ExecutorId {
rids[it.ExecutorId[i2]] = 0
}
}
for i := range in.Recipients {
id := in.Recipients[i]
id2, _ := strconv.Atoi(id)
if _, ok := rids[id2]; ok {
year, month, day := start.Date()
start0 := time.Date(year, month, day, 0, 0, 0, 0, time.Local) // 当前时间0点0分0秒时刻
today := start0.Add(24 * time.Hour).Format("2006-01-02 15:04:05")
return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("当前时间已有正在进行的项目,请将项目开始时间设置至 %s 之后", today))
}
}
if project.State == domain.ProjectStateWaitConfig {
project.State = domain.ProjectStateWaitActive
}
... ... @@ -264,7 +295,7 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
}
// 更新项目截止时间,同步任务截止时间
func (rs *EvaluationProjectService) updateTaskTime(context application.TransactionContext, projectId int64, end time.Time) error {
func (rs *EvaluationProjectService) updateTaskTime(context application.TransactionContext, projectId int64, end *time.Time) error {
// 查看任务过程,重新日计算任务截至期
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": context})
tasks, err := taskRepository.Find(map[string]interface{}{"projectId": projectId})
... ... @@ -278,7 +309,10 @@ func (rs *EvaluationProjectService) updateTaskTime(context application.Transacti
for i := range tasks {
task := tasks[i]
task.TimeEnd = &end // 先赋值
if end != nil {
task.TimeEnd = end // 先赋值
}
if task.NextSentAt == nil { // 重新计算
// 环节起始和截止本地时间
... ... @@ -469,11 +503,58 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
if len(project.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
if project.State == domain.TemplateStateEnable {
if project.State == domain.ProjectStateEnable {
return nil, application.ThrowError(application.BUSINESS_ERROR, "项目已启动")
}
project.State = domain.TemplateStateEnable
// 周期内的所有项目,已启用的员工不能重复被评估
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": project.CompanyId, "cycleId": project.CycleId}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
userMap := map[string]*domain.User{}
for i := range projects {
it := projects[i]
// 排除当前项目
if in.Id == it.Id {
continue
}
// 启用状态的被评估人
if it.State == domain.ProjectStateEnable {
for j := range it.Recipients {
userMap[it.Recipients[j]] = nil
}
}
}
ids := make([]string, 0)
for k := range userMap {
ids = append(ids, k)
}
if len(ids) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, err := userRepository.Find(map[string]interface{}{"ids": ids})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range users {
s64 := strconv.FormatInt(users[i].Id, 10)
userMap[s64] = users[i]
}
var build strings.Builder
for i := range project.Recipients {
id := project.Recipients[i]
if user, ok := userMap[id]; ok {
build.WriteString("[")
build.WriteString(user.Name)
build.WriteString("]")
}
}
if build.Len() > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("请先停止%s正在进行的项目", build.String()))
}
}
project.State = domain.ProjectStateEnable
project, err = projectRepository.Insert(project)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -535,6 +616,139 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
return project, nil
}
func (rs *EvaluationProjectService) Pause(in *command.ActivateProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if project.State != domain.ProjectStateEnable {
return nil, application.ThrowError(application.BUSINESS_ERROR, "项目未启动")
}
project.State = domain.ProjectStatePause
project, err = projectRepository.Insert(project)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
tasks, err := taskRepository.Find(map[string]interface{}{"projectId": project.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range tasks {
it := tasks[i]
it.NextSentAt = nil
_, err = taskRepository.Insert(it)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return project, nil
}
func (rs *EvaluationProjectService) Resume(in *command.ActivateProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if project.Template == nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加评估模板")
}
if len(project.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
if project.State == domain.ProjectStateEnable {
return nil, application.ThrowError(application.BUSINESS_ERROR, "项目已启动")
}
// 周期内的所有项目,已启用的员工不能重复被评估
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": project.CompanyId, "cycleId": project.CycleId}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
userMap := map[string]*domain.User{}
for i := range projects {
it := projects[i]
// 排除当前项目
if in.Id == it.Id {
continue
}
// 启用状态的被评估人
if it.State == domain.ProjectStateEnable {
for j := range it.Recipients {
userMap[it.Recipients[j]] = nil
}
}
}
ids := make([]string, 0)
for k := range userMap {
ids = append(ids, k)
}
if len(ids) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, err := userRepository.Find(map[string]interface{}{"ids": ids})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range users {
s64 := strconv.FormatInt(users[i].Id, 10)
userMap[s64] = users[i]
}
var build strings.Builder
for i := range project.Recipients {
id := project.Recipients[i]
if user, ok := userMap[id]; ok {
build.WriteString("[")
build.WriteString(user.Name)
build.WriteString("]")
}
}
if build.Len() > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("请先停止%s正在进行的项目", build.String()))
}
}
project.State = domain.ProjectStateEnable
project, err = projectRepository.Insert(project)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 项目恢复,同步更新任务时间
if err = rs.updateTaskTime(transactionContext, in.Id, nil); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return project, nil
}
func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
... ... @@ -555,7 +769,7 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf
project.Recipients = make([]string, 0) // 重置被评估人
// 如果拷贝已经启用的模板,默认先设置为待启用
if project.State == domain.ProjectStateEnable {
if project.State == domain.ProjectStateEnable || project.State == domain.ProjectStatePause {
project.State = domain.ProjectStateWaitActive
}
project, err = projectRepository.Insert(project)
... ... @@ -587,11 +801,14 @@ func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCo
// 周期内的所有项目,员工不能重复被评估
rids := map[string]bool{}
for i := range projects {
it := projects[i]
// 排除当前项目
if in.Id != projects[i].Id {
ids := projects[i].Recipients
for j := range ids {
rids[ids[j]] = true
if in.Id == it.Id {
continue
}
if it.State == domain.ProjectStateEnable {
for j := range it.Recipients {
rids[it.Recipients[j]] = true
}
}
}
... ...
... ... @@ -23,3 +23,40 @@ type AssessInfoResp struct {
DutyTime string `json:"dutyTime"` //入职时间 //
AssessContent []*domain.StaffAssessContent `json:"assessContent"` //评估内容
}
// 周期内的每日自评小结
type AssessCountLevelResp struct {
CycleId int64 `json:"cycleId,string"` //周期id
CycleName string `json:"cycleName"` //周期名称
EvaluationProjectId int `json:"evaluationProjectId,string"` //项目id
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
TargetUserId int `json:"targetUserId,string"` //被评估的目标用户,被执行的
TargetUserName string `json:"targetUserName"` //
CompanyLogo string `json:"companyLogo,"` //公司logo
CompanyName string `json:"companyName"` //公司名称
SupperUser string `json:"superUser"` //目标用户的上级
DutyTime string `json:"dutyTime"` //入职时间
EvaluationItems []AssessCountLeveltItem `json:"evaluationItems"`
}
type AssessCountLeveltItem struct {
EvaluationItemId int `json:"evaluationItemId,string"` //评估条目的id
SortBy int `json:"sortBy"` //排序
Category string `json:"category"` //类别
Name string `json:"name"` //名称
PromptTitle string `json:"promptTitle"` //提示项标题
PromptText string `json:"promptText"` //提示项正文
EntryItems []*domain.EntryItem `json:"entryItems"` //填写的反馈
RuleType int `json:"ruleType"` //评估方式(0评级、1评分)
Rule domain.EvaluationRule `json:"rule"` //评估的选项规则
Weight float64 `json:"weight"` //"权重"
Remark string `json:"remark"` //填写的内容反馈
EvaluatorId int `json:"evaluatorId"` //评估人id
LevelCount []LevalCodeCount `json:"levelCount"` //周期内每次评估的等级数量统计
}
// 评级数量
type LevalCodeCount struct {
Code string `json:"code"` //评级代码
Number int `json:"number"` //数量
}
... ...
package query
type ListTargetUserCycleQuery struct {
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
CompanyId int `json:"-"` //
TargetUserId int `json:"targetUserId,string"` //评估的执行人,必填
}
... ...
... ... @@ -14,3 +14,10 @@ type ExportUserAssess2Commad struct {
OperatorId int `cname:"操作人ID" json:"operatorId"`
ExportUserId []string `cname:"指定员工数据导出" json:"exportUserId"`
}
type StaffAsessSelfCountLevel struct {
CompanyId int `cname:"公司ID" json:"-"`
TargetUserId int `json:"targetUserId,string"`
ProjectId int `json:"projectId,string"`
CycleId int `cname:"周期ID" json:"cycleId,string"`
}
... ...
... ... @@ -13,7 +13,7 @@ type MemberSummaryListCommand struct {
// MemberPerformanceIndicatorCommand 成员绩效导出-指标
type MemberPerformanceIndicatorCommand struct {
CycleId int `cname:"周期ID" json:"cycleId,string"`
UserName string `cname:"用户名称" json:"userName"`
UserName string `cname:"搜索用户名称" json:"userName"`
UserIds []string `cname:"用户ID" json:"userIds"`
CompanyId int `cname:"公司ID" json:"companyId"`
OperatorId int `cname:"操作人ID" json:"operatorId"`
... ...
package service
import (
"fmt"
"strings"
"github.com/linmadan/egglib-go/core/application"
"github.com/xuri/excelize/v2"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
)
// 员工绩效-综合管理-导出绩效-个人
func (srv *StaffAssessServeice) ExportUserAssess2V2(param *query.ExportUserAssess2Commad) (*excelize.File, 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()
}()
hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
// 按照cycleId获取项目的指标项
evaluationItemList, err := assessDao.SearchEvaluationItemUsed2(param.CompanyId,
param.CycleId, param.OperatorId, hrbp, param.ExportUserId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 按照项目获取填写的内容
assessContentList, err := assessDao.SearchStaffAssessContent2(param.CompanyId,
param.CycleId, param.OperatorId, hrbp, param.ExportUserId)
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())
}
eData := newExportData3()
eData.FormatTableHead(evaluationItemList)
eData.FormatListValue(assessContentList)
xlsxFile := excelize.NewFile()
//设置默认的第一个sheet
sheetIndex := xlsxFile.GetActiveSheetIndex()
firstSheetName := xlsxFile.GetSheetName(sheetIndex)
cycleName := ""
if len(evaluationItemList) > 0 {
cycleName = evaluationItemList[0].CycleName
}
for k1, val := range eData.userProjcetMap {
for k2, val2 := range val {
// 根据员工名称 添加一个sheet
uname := eData.userIdName[k1]
if len(uname) == 0 {
continue
}
tableHeader, ok := eData.tableHeader[eData.tableHeaderKey(k1, val2)]
if !ok {
continue
}
newSheetName := uname + fmt.Sprintf("_%d", k2+1)
xlsxFile.NewSheet(newSheetName)
xlsxFile.SetCellStr(newSheetName, "B2", uname)
xlsxFile.MergeCell(newSheetName, "B2", "B4")
//填充第一列数据
xlsxFile.SetCellStr(newSheetName, "A1", tableHeader.Name)
xlsxFile.SetCellStr(newSheetName, "A2", cycleName)
xlsxFile.MergeCell(newSheetName, "A2", "A4")
xlsxFile.SetCellStr(newSheetName, "A5", "权重")
xlsxFile.MergeCell(newSheetName, "A5", "B5")
xlsxFile.SetCellStr(newSheetName, "A6", "评估标准")
xlsxFile.MergeCell(newSheetName, "A6", "B6")
// 日期
dayList := eData.userDayMap[eData.userDayKey(k1, val2)]
for ii, vv := range dayList {
//填写在第几行
axisNum := 7 + 3*ii
axis := fmt.Sprintf("A%d", axisNum)
xlsxFile.SetCellStr(newSheetName, axis, vv)
axisEnd := fmt.Sprintf("B%d", axisNum+2)
xlsxFile.MergeCell(newSheetName, axis, axisEnd) //单元格高度按三个单元格合并
}
allColNum := 0 //计算总共有多少列
//第一行
for _, v2 := range tableHeader.Child {
//第二行
for _, v3 := range v2.Child {
//第三行
for _, v4 := range v3.Child {
allColNum++
//按列填充数据
colName, _ := excelize.ColumnNumberToName(allColNum + 2) //第3列开始
xlsxFile.SetCellStr(newSheetName, colName+"2", v2.Name) //分类
xlsxFile.SetCellStr(newSheetName, colName+"3", v3.Name) //加分项 得分项
xlsxFile.SetCellStr(newSheetName, colName+"4", v4.Name) // 评估项名称
//权重 填写第5行数据
k23 := eData.data23Key(k1, v2.Name, v3.Name, v4.Name)
xlsxFile.SetCellStr(newSheetName, colName+"5", eData.data3[k23])
//评估标准 填写第6行数据
xlsxFile.SetCellStr(newSheetName, colName+"6", eData.data2[k23])
//按日期填充评估的填写的值
for i5, v5 := range dayList {
k1 := eData.dataKey(k1, val2, v5, v2.Name, v3.Name, v4.Name)
//填写在第几行
axisNum := 7 + 3*i5
axis := fmt.Sprintf("%s%d", colName, axisNum)
if d, ok := eData.data[k1]; ok {
xlsxFile.SetCellStr(newSheetName, axis, d.String())
}
//单元格高度按三个单元格合并
axisEnd := fmt.Sprintf("%s%d", colName, axisNum+2)
xlsxFile.MergeCell(newSheetName, axis, axisEnd)
}
}
}
}
//
colName, _ := excelize.ColumnNumberToName(allColNum + 2)
xlsxFile.MergeCell(newSheetName, "A1", fmt.Sprintf("%s1", colName))
}
}
//删除默认的第一个sheet
xlsxFile.DeleteSheet(firstSheetName)
return xlsxFile, nil
}
// 处理原始数据,方便进行 excel导出
type exportData3 struct {
userIdName map[string]string //员工id对应的名字 id=>员工名称
userProjcetMap map[string][]string //员工的项目 员工id=>项目id
tableHeader map[string]*HeaderLevel //表头数据 key=员工id+项目id
userDayMap map[string][]string //每个员工对应的日期列表 key=员工id+项目id value= 日期列表
data map[string]*strings.Builder //每个员工表头对应的评估填写的数据 key=员工id+项目id+日期+表头
data2 map[string]string //每个员工评估项的标准描述 key=员工id+项目id+表头
data3 map[string]string //每个员工评估项的标准权重 key=员工id+项目id+表头
}
func newExportData3() *exportData3 {
return &exportData3{
userIdName: map[string]string{},
userProjcetMap: map[string][]string{},
tableHeader: map[string]*HeaderLevel{},
userDayMap: map[string][]string{},
data: map[string]*strings.Builder{},
data2: map[string]string{}, data3: map[string]string{}}
}
func (e *exportData3) FormatTableHead(param []dao.DataEvaluationItemUsed2) {
userNameMap := map[string]struct{}{} //员工名字过滤
projectIdMap := map[string]struct{}{} //项目id过滤
for _, val := range param {
//
if _, ok := e.userProjcetMap[val.TargetUserId]; !ok {
e.userProjcetMap[val.TargetUserId] = []string{}
}
//处理一个员工多项目的情况
if _, ok := projectIdMap[val.EvaluationProjectId]; !ok {
e.userProjcetMap[val.TargetUserId] = append(e.userProjcetMap[val.TargetUserId], val.EvaluationProjectId)
projectIdMap[val.EvaluationProjectId] = struct{}{}
}
//处理员工的名称
if _, ok := e.userIdName[val.TargetUserId]; !ok {
if _, ok := userNameMap[val.TargetUserName]; ok {
//员工重名
uname := fmt.Sprintf("%s(%d)", val.TargetUserName, len(userNameMap))
e.userIdName[val.TargetUserId] = uname
userNameMap[uname] = struct{}{}
} else {
e.userIdName[val.TargetUserId] = val.TargetUserName
userNameMap[val.TargetUserName] = struct{}{}
}
}
//每个员工对应的日期列表
key1 := e.tableHeaderKey(val.TargetUserId, val.EvaluationProjectId)
if _, ok := e.tableHeader[key1]; !ok {
e.tableHeader[key1] = &HeaderLevel{
Name: "个人绩效评估等级统计表",
Filter: map[string]int{},
Child: []HeaderLevel{},
}
}
child := e.tableHeader[key1].addChild(val.Category) //第一级,"分类"
weight := e.weightDesc(val.Weight)
child = child.addChild(weight) //第二级 '得分项' '加分项'
child.addChild(val.ContentName) //第三级 评估项名称
}
}
func (e *exportData3) FormatListValue(param []dao.DataStaffAssessContent2) {
userDay := map[string]struct{}{}
for _, val := range param {
weight := e.weightDesc(val.Weight)
key := e.dataKey(val.TargetUserId, val.EvaluationProjectId, val.BeginDay, val.Category, weight, val.ContentName)
e.data[key] = &strings.Builder{}
e.data[key].WriteString(val.Value + "\n") //填写的等级
for _, vv := range val.Remark {
e.data[key].WriteString(vv.Title + "\n")
e.data[key].WriteString(vv.RemarkText + "\n")
}
dayKey := val.TargetUserId + val.EvaluationProjectId + val.BeginDay
if _, ok := userDay[dayKey]; !ok {
userDay[dayKey] = struct{}{}
k := e.userDayKey(val.TargetUserId, val.EvaluationProjectId)
e.userDayMap[k] = append(e.userDayMap[k], val.BeginDay)
}
key23 := e.data23Key(val.TargetUserId, val.Category, weight, val.ContentName)
e.data2[key23] = val.PromptText
if val.Weight == 0 {
e.data3[key23] = ""
} else {
e.data3[key23] = fmt.Sprintf("%.2f%%", val.Weight)
}
}
}
func (e *exportData3) weightDesc(weight float64) string {
if weight == 0 {
return "加分项"
} else {
return "得分项"
}
}
func (e *exportData3) dataKey(userId string, projectId string, beginDay string, category string, weight string, contentName string) string {
key := fmt.Sprintf("%s-%s-%s-%s-%s-%s", userId, projectId, weight, beginDay, category, contentName)
return key
}
func (e *exportData3) data23Key(userId string, category string, weight string, contentName string) string {
key := fmt.Sprintf("%s-%s-%s-%s", userId, weight, category, contentName)
return key
}
func (e *exportData3) userDayKey(userId string, projectId string) string {
return fmt.Sprintf("%s-%s", userId, projectId)
}
func (e *exportData3) tableHeaderKey(targetUserId, evaluationProjectId string) string {
return targetUserId + "-" + evaluationProjectId
}
... ...
... ... @@ -31,34 +31,9 @@ func (h *HeaderLevel) addChild(name string) (child *HeaderLevel) {
return &h.Child[cIndex]
}
// 获取表头的所有列表名
// func (h *HeaderLevel) collectAllColumn(all *[][]string) {
// for _, v := range h.Child {
// v.collectColumn(&v, all, nil)
// }
// }
// func (h *HeaderLevel) collectColumn(child *HeaderLevel, columns *[][]string, column *[]string) {
// if column == nil {
// column = &[]string{}
// }
// *column = append(*column, h.Name)
// for _, v := range child.Child {
// if len(v.Child) > 0 {
// v.collectColumn(&v, columns, column)
// }
// if len(v.Child) == 0 {
// item := make([]string, len(*column))
// copy(item, *column)
// item = append(item, v.Name)
// *columns = append(*columns, item)
// }
// }
// }
type exportData struct {
userName []string //员工的名称列表 ,对应excel文件的多个sheet
usrIdMap map[string]string
userName []string //员工的名称列表 ,对应excel文件的多个sheet
usrIdMap map[string]string //员工id对应的名字
userDayMap map[string][]string //每个员工对应的日期列表 key=员工名称 value= 日期列表
tableHeader map[string]*HeaderLevel //每个员工数据表格对应表头 key=员工名称
data map[string]*strings.Builder //每个员工表头对应的评估填写的数据 key=员工名称+日期+表头
... ... @@ -156,10 +131,6 @@ func (e *exportData) weightDesc(weight float64) string {
}
}
// func (e *exportData) userDayKey(userName string) string {
// return userName
// }
type exportData2 struct {
tableHeader HeaderLevel //数据表格对应表头
userIdMap map[string]string //员工id 对应的名称
... ...
... ... @@ -14,6 +14,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"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"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
... ... @@ -241,11 +242,23 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat
assassessTaskList[0].ExecutorId = executorIds
//更新步骤
assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, assessTaskData.StepList...)
for _, val := range assessTaskData.StepList {
hasFound := false
for _, val2 := range assassessTaskList[0].StepList {
if val.LinkNodeType == val2.LinkNodeType {
hasFound = true
break
}
}
if !hasFound {
assassessTaskList[0].StepList = append(assassessTaskList[0].StepList, val)
}
}
assessTaskData = assassessTaskList[0]
//排序流程环节
stepList := domain.SortTaskStep(assessTaskData.StepList)
sort.Sort(stepList)
}
stepList := domain.SortTaskStep(assessTaskData.StepList)
sort.Sort(stepList)
_, err = assessTaskRepo.Save(assessTaskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
... ... @@ -346,7 +359,10 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application.
stepSelfTemp.LinkNodeId = v.LinkNodeId
stepSelfTemp.LinkNodeName = v.LinkNodeName
stepSelfTemp.Types = domain.AssessSelf
assessListTemp := srv.createStaffAssessSelf(stepSelfTemp, userList, userDepartmentMap)
assessListTemp, err := srv.createStaffAssessSelf(transactionContext, stepSelfTemp, userList, userDepartmentMap)
if err != nil {
return nil, err
}
assessList = append(assessList, assessListTemp...)
}
if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {
... ... @@ -367,10 +383,28 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application.
}
// 构建员工自评
func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAssess,
userList []*domain.User, userDepartmentMap map[int64][]*domain.Department) []domain.StaffAssess {
result := []domain.StaffAssess{}
for _, usr := range userList {
func (srv StaffAssessServeice) createStaffAssessSelf(
transactionContext application.TransactionContext,
assessTemp domain.StaffAssess,
userList []*domain.User,
userDepartmentMap map[int64][]*domain.Department) ([]domain.StaffAssess, error) {
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
beginDay := assessTemp.BeginTime.Format("2006-01-02")
_, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSelf})
if err != nil {
return nil, err
}
userMapReal := map[int]*domain.User{}
for _, val := range userList {
userMapReal[int(val.Id)] = val
}
for _, val := range assessListOld {
delete(userMapReal, val.TargetUser.UserId)
}
assessListNew := []domain.StaffAssess{}
for _, usr := range userMapReal {
assessTemp.TargetUser = domain.StaffDesc{
UserId: int(usr.Id),
Account: usr.Account,
... ... @@ -389,9 +423,9 @@ func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAsse
})
}
}
result = append(result, assessTemp)
assessListNew = append(assessListNew, assessTemp)
}
return result
return assessListNew, nil
}
// 构建员工的上级评估
... ... @@ -400,8 +434,24 @@ func (srv StaffAssessServeice) createStaffAssessSupper(
assessTemp domain.StaffAssess,
userList []*domain.User, userDepartmentMap map[int64][]*domain.Department,
) ([]domain.StaffAssess, error) {
var assessList []domain.StaffAssess
for _, v := range userList {
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
beginDay := assessTemp.BeginTime.Format("2006-01-02")
_, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSuper})
if err != nil {
return nil, err
}
userMapReal := map[int]*domain.User{}
for _, val := range userList {
userMapReal[int(val.Id)] = val
}
for _, val := range assessListOld {
delete(userMapReal, val.TargetUser.UserId)
}
var assessListNew []domain.StaffAssess
for _, v := range userMapReal {
//获取上级
chargeUserList, err := srv.getStaffSuper(transactionContext, *v)
if err != nil {
... ... @@ -431,11 +481,11 @@ func (srv StaffAssessServeice) createStaffAssessSupper(
}
}
assessTemp.TargetDepartment = targetDepartment
assessList = append(assessList, assessTemp)
assessListNew = append(assessListNew, assessTemp)
}
}
return assessList, nil
return assessListNew, nil
}
// 获取某个员工360评估邀请的人员
... ... @@ -1124,3 +1174,167 @@ func (srv StaffAssessServeice) recoverAssessCache(context application.Transactio
}
}
}
// 获取目标员工自评周期列表
func (srv StaffAssessServeice) ListTargetUserSelfCycle(param *query.ListTargetUserCycleQuery) (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()
}()
staffAssessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
var limit int = 1000
var offset int = 0
if param.PageSize > 0 {
limit = param.PageSize
}
offset = (param.PageNumber - 1) * param.PageSize
cycleList, err := staffAssessDao.SearchTargetUserCycleProject(param.CompanyId, param.TargetUserId, limit, offset)
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 tool_funs.SimpleWrapGridMap(int64(len(cycleList)), cycleList), nil
}
// 按照周期获取员工的每日自评小结
func (srv StaffAssessServeice) GetStaffAsessSelfCountLevel(param *query.StaffAsessSelfCountLevel) (*adapter.AssessCountLevelResp, 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()
}()
// 统计周期内,评估项等级的数量
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
levelCodeCountList, err := assessDao.CountAssessContentLevelCode(param.ProjectId, param.TargetUserId, domain.AssessSelf, param.CycleId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
"evaluationProjectId": param.ProjectId,
"nodeType": int(domain.LinkNodeSelfAssessment),
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//获取员工的评估
_, assessList, err := assessReps.Find(map[string]interface{}{
"companyId": param.CompanyId,
"limit": 1,
"cycleId": param.CycleId,
"targetUserId": param.TargetUserId,
"evaluationProjectId": param.ProjectId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(assessList) == 0 {
return &adapter.AssessCountLevelResp{
EvaluationProjectId: param.ProjectId,
CycleId: int64(param.CycleId),
TargetUserId: param.TargetUserId,
}, nil
}
assessData := assessList[0]
targetUserDesc, err := srv.getStaffDescrip(transactionContext, int64(param.TargetUserId))
if err != nil {
log.Logger.Error("获取员工描述" + err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := adapter.AssessCountLevelResp{
CycleId: assessData.CycleId,
CycleName: assessData.CycleName,
EvaluationProjectId: assessData.EvaluationProjectId,
EvaluationProjectName: assessData.EvaluationProjectName,
TargetUserId: assessData.TargetUser.UserId,
TargetUserName: assessData.TargetUser.UserName,
CompanyLogo: "",
CompanyName: "",
SupperUser: "",
DutyTime: "",
EvaluationItems: []adapter.AssessCountLeveltItem{},
}
if targetUserDesc != nil {
result.CompanyName = targetUserDesc.CompanyName
result.SupperUser = targetUserDesc.SupperUserName
result.CompanyLogo = targetUserDesc.CompanyLogo
result.DutyTime = targetUserDesc.DutyTime
}
levelCodeMap := map[int][]adapter.LevalCodeCount{}
for _, v := range itemList {
codes := v.Rule.GetLevelCodes()
levelCode := []adapter.LevalCodeCount{}
for _, v2 := range codes {
levelCode = append(levelCode, adapter.LevalCodeCount{
Code: v2,
Number: 0,
})
}
levelCodeMap[v.Id] = levelCode
}
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 _, v := range itemList {
itemCount := adapter.AssessCountLeveltItem{
EvaluationItemId: v.Id,
SortBy: v.SortBy,
Category: v.Category,
Name: v.Name,
PromptTitle: v.PromptTitle,
PromptText: v.PromptText,
EntryItems: v.EntryItems,
RuleType: v.RuleType,
Rule: v.Rule,
Weight: v.Weight,
EvaluatorId: v.EvaluatorId,
LevelCount: []adapter.LevalCodeCount{},
}
levelCodes := levelCodeMap[v.Id]
for i2 := range levelCodes {
key := fmt.Sprintf("%s-%s-%s",
itemCount.Category,
itemCount.Name,
levelCodes[i2].Code,
)
if mVal, ok := levelCodeCountMap[key]; ok {
levelCodes[i2].Number = mVal
}
}
itemCount.LevelCount = levelCodes
result.EvaluationItems = append(result.EvaluationItems, itemCount)
}
return &result, nil
}
... ...
... ... @@ -231,105 +231,259 @@ func (srv StaffAssessServeice) QueryMemberPerformanceIndicator(in *query.MemberP
transactionContext.RollbackTransaction()
}()
hrbp, err := srv.getHRBP(transactionContext, in.CompanyId, in.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
var projectItemUsed = map[int][]*domain.EvaluationItemUsed{} // 项目ID-> 评估内容项
var userProjectMap = map[int][]*dao.IndicatorUserProject{} // 用户ID-> 用户评估的项目(用户在周期内可能有多个项目模板,激活状态只能是1个)
var projectIds = make([]int, 0)
var userIds = make([]string, 0)
if len(in.UserIds) > 0 {
userIds = in.UserIds // 赋值
staffAssessRepository := factory.CreateStaffAssessRepository(map[string]interface{}{"transactionContext": transactionContext})
_, assessList, err := staffAssessRepository.Find(map[string]interface{}{
"cycleId": in.CycleId,
"targetUserIds": in.UserIds,
"types": domain.AssessSelf,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
projectIdsMap := map[int]int{}
for i := range assessList {
it := assessList[i]
projectIdsMap[it.EvaluationProjectId] = it.EvaluationProjectId
// 用户存在多个项目模板
array, ok := userProjectMap[it.TargetUser.UserId]
if !ok {
array = make([]*dao.IndicatorUserProject, 0)
}
userProjectMap[it.TargetUser.UserId] = append(array, &dao.IndicatorUserProject{
AssessId: it.Id,
EvaluationProjectId: it.EvaluationProjectId,
TargetUserId: it.TargetUser.UserId,
TargetUserName: it.TargetUser.UserName,
})
}
for k, _ := range projectIdsMap {
projectIds = append(projectIds, k)
}
} else {
hrbp, err := srv.getHRBP(transactionContext, in.CompanyId, in.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
list, err := assessDao.MemberAllProjectId(
in.CompanyId,
in.UserName,
in.OperatorId,
in.CycleId,
hrbp)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
projectIdsMap := map[int]int{}
for i := range list {
it := list[i]
projectIdsMap[it.EvaluationProjectId] = it.EvaluationProjectId
// 用户存在多个项目模板
array, ok := userProjectMap[it.TargetUserId]
if !ok {
array = make([]*dao.IndicatorUserProject, 0)
}
userProjectMap[it.TargetUserId] = append(array, &it)
}
for k := range userProjectMap {
userIds = append(userIds, strconv.Itoa(k))
}
for k, _ := range projectIdsMap {
projectIds = append(projectIds, k)
}
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
list, err := assessDao.MemberPerformanceIndicator(
in.UserName,
in.CompanyId,
in.OperatorId,
in.CycleId,
hrbp,
string(domain.AssessSelf),
in.UserIds)
if err != nil {
// 项目ID->查询所有评估项
if len(projectIds) > 0 {
itemUsedRepository := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
_, itemList, err := itemUsedRepository.Find(map[string]interface{}{"evaluationProjectIds": projectIds, "nodeType": domain.LinkNodeSelfAssessment})
if err != nil {
return nil, err
}
for i := range itemList {
it := itemList[i]
array, ok := projectItemUsed[it.EvaluationProjectId]
if !ok {
array = make([]*domain.EvaluationItemUsed, 0)
}
projectItemUsed[it.EvaluationProjectId] = append(array, it)
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// (全部周期数据)筛选出第一个周期的数据,减少后续数据遍历
dupleMap := map[string]string{}
dupleList := make([]dao.PerformanceIndicatorAssess, 0)
for i := range list {
it := list[i]
if v, ok := dupleMap[it.TargetUserId]; ok {
if v == it.BeginDay {
dupleList = append(dupleList, it)
adapterList := make([]*adapter.PerformanceIndicatorAdapter, 0)
categoryMap := map[string]int{} // 内容分类
categoryNameMap := map[string]int{} // 内容名称
for i := range userIds {
userId := userIds[i]
userIdInt, err := strconv.Atoi(userId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
iupArray, ok := userProjectMap[userIdInt]
if !ok {
continue
}
var pia = &adapter.PerformanceIndicatorAdapter{
TargetUserId: userId,
TargetUserName: iupArray[0].TargetUserName,
PIContents: make([]adapter.PIContent, 0),
}
adapterList = append(adapterList, pia)
for _, assess := range iupArray {
items, ok := projectItemUsed[assess.EvaluationProjectId]
if !ok {
continue
}
} else {
// 有内容分类,才算正常数据,反之不显示
if len(it.ContentCategory) > 0 {
dupleMap[it.TargetUserId] = it.BeginDay
dupleList = append(dupleList, it)
for _, item := range items {
if len(item.Category) == 0 {
continue
}
onlyKey1 := userId + item.Category
if _, ok := categoryMap[onlyKey1]; !ok {
categoryMap[onlyKey1] = 0
// 不存在分类时,创建分类内容
pia.PIContents = append(pia.PIContents, adapter.PIContent{
Category: item.Category,
Names: make([]string, 0),
})
}
// 内容名称有值合并到数组
if len(item.Name) > 0 {
onlyKey2 := userId + item.Category + item.Name
if _, ok := categoryNameMap[onlyKey2]; !ok {
categoryNameMap[onlyKey2] = 0
for index := range pia.PIContents {
piContent := &pia.PIContents[index]
if piContent.Category == item.Category {
piContent.Names = append(piContent.Names, item.Name)
break
}
}
}
}
}
}
}
piaMap := map[string]*adapter.PerformanceIndicatorAdapter{}
categoryMap := map[string]int{} // 内容分类
//categoryNameMap := map[string]int{} // 内容分类下的名称
/*
// 旧版(如果未填写自评会出现数据评估项丢失的BUG)
hrbp, err := srv.getHRBP(transactionContext, in.CompanyId, in.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
adapterList := make([]*adapter.PerformanceIndicatorAdapter, 0)
for i := range dupleList {
it := dupleList[i]
var pia *adapter.PerformanceIndicatorAdapter
if v, ok := piaMap[it.TargetUserId]; ok {
pia = v
} else {
pia = &adapter.PerformanceIndicatorAdapter{
TargetUserId: it.TargetUserId,
TargetUserName: it.TargetUserName,
PIContents: make([]adapter.PIContent, 0),
assessDao := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
list, err := assessDao.MemberPerformanceIndicator(
in.UserName,
in.CompanyId,
in.OperatorId,
in.CycleId,
hrbp,
string(domain.AssessSelf),
in.UserIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// (全部周期数据)筛选出第一个周期的数据,减少后续数据遍历
dupleMap := map[string]string{}
dupleList := make([]dao.PerformanceIndicatorAssess, 0)
for i := range list {
it := list[i]
if v, ok := dupleMap[it.TargetUserId]; ok {
if v == it.BeginDay {
dupleList = append(dupleList, it)
}
} else {
// 有内容分类,才算正常数据,反之不显示
if len(it.ContentCategory) > 0 {
dupleMap[it.TargetUserId] = it.BeginDay
dupleList = append(dupleList, it)
}
}
piaMap[it.TargetUserId] = pia
adapterList = append(adapterList, pia)
}
// 分类名称有值才能合并分类数组
if len(it.ContentCategory) > 0 {
onlyKey1 := it.TargetUserId + it.ContentCategory
if _, ok := categoryMap[onlyKey1]; !ok {
categoryMap[onlyKey1] = 0
// 不存在分类时,创建分类内容
pia.PIContents = append(pia.PIContents, adapter.PIContent{
Category: it.ContentCategory,
Names: make([]string, 0),
})
piaMap := map[string]*adapter.PerformanceIndicatorAdapter{}
categoryMap := map[string]int{} // 内容分类
//categoryNameMap := map[string]int{} // 内容分类下的名称
adapterList := make([]*adapter.PerformanceIndicatorAdapter, 0)
for i := range dupleList {
it := dupleList[i]
var pia *adapter.PerformanceIndicatorAdapter
if v, ok := piaMap[it.TargetUserId]; ok {
pia = v
} else {
pia = &adapter.PerformanceIndicatorAdapter{
TargetUserId: it.TargetUserId,
TargetUserName: it.TargetUserName,
PIContents: make([]adapter.PIContent, 0),
}
piaMap[it.TargetUserId] = pia
adapterList = append(adapterList, pia)
}
// 内容名称有值合并到数组
if len(it.ContentName) > 0 {
// 周期筛选过的,不再需要唯一值验证判断,直接添加到对应的分类下
for index := range pia.PIContents {
piContent := &pia.PIContents[index]
if piContent.Category == it.ContentCategory {
piContent.Names = append(piContent.Names, it.ContentName)
break
// 分类名称有值才能合并分类数组
if len(it.ContentCategory) > 0 {
onlyKey1 := it.TargetUserId + it.ContentCategory
if _, ok := categoryMap[onlyKey1]; !ok {
categoryMap[onlyKey1] = 0
// 不存在分类时,创建分类内容
pia.PIContents = append(pia.PIContents, adapter.PIContent{
Category: it.ContentCategory,
Names: make([]string, 0),
})
}
// 内容名称有值合并到数组
if len(it.ContentName) > 0 {
// 周期筛选过的,不再需要唯一值验证判断,直接添加到对应的分类下
for index := range pia.PIContents {
piContent := &pia.PIContents[index]
if piContent.Category == it.ContentCategory {
piContent.Names = append(piContent.Names, it.ContentName)
break
}
}
//onlyKey2 := it.TargetUserId + it.ContentCategory + it.ContentName
//if _, ok := categoryNameMap[onlyKey2]; !ok {
// categoryNameMap[onlyKey2] = 0
//
// for index := range pia.PIContents {
// piContent := pia.PIContents[index]
// if piContent.Category == it.ContentCategory {
// piContent.Names = append(piContent.Names, it.ContentName)
// break
// }
// }
//}
}
//onlyKey2 := it.TargetUserId + it.ContentCategory + it.ContentName
//if _, ok := categoryNameMap[onlyKey2]; !ok {
// categoryNameMap[onlyKey2] = 0
//
// for index := range pia.PIContents {
// piContent := pia.PIContents[index]
// if piContent.Category == it.ContentCategory {
// piContent.Names = append(piContent.Names, it.ContentName)
// break
// }
// }
//}
}
}
}
if err := transactionContext.CommitTransaction(); 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 tool_funs.SimpleWrapGridMap(int64(len(adapterList)), adapterList), nil
}
... ... @@ -374,8 +528,7 @@ func (srv StaffAssessServeice) ExportPerformanceIndicator(in *query.ExportPerfor
for i := range list {
it := list[i]
if v, ok := selectedMap[it.TargetUserId]; ok {
v.UserName = it.TargetUserName
//v.UserName = it.TargetUserName
if v.Category == it.ContentCategory && v.Name == it.ContentName {
conditionList = append(conditionList, it)
conditionMap[it.TargetUserId+it.BeginDay] = it
... ...
... ... @@ -435,7 +435,7 @@ func (srv StaffAssessServeice) QueryPerformanceIndicator(param *query.ListAssess
Hrbp: hrbp,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计总数"+err.Error())
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())
... ... @@ -478,14 +478,12 @@ func (srv *StaffAssessServeice) ExportUserAssess(param *query.ExportAssessConten
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
contentList, err := assessDao.ExportDataUserAssess(dao.SearchConditin1{
contentList, err := assessDao.ExportDataUserAssessV2(dao.SearchConditin2{
CompanyId: param.CompanyId,
CycleId: param.CycleId,
BeginDay: "",
BeginDayList: param.BeginDayList,
TargetUserName: param.TargetUserName,
TargetUserId: param.TargetUserId,
Limit: 5000,
Offset: 0,
OperaterId: param.OperaterId,
Hrbp: hrbp,
})
... ... @@ -501,11 +499,7 @@ func (srv *StaffAssessServeice) ExportUserAssess(param *query.ExportAssessConten
for _, v := range param.ExportItems {
includeCol[v.Category+"+"+v.Name] = struct{}{}
}
includeBeginDay := map[string]struct{}{}
for _, v := range param.BeginDayList {
includeBeginDay[v] = struct{}{}
}
//过滤日期
eData := newExportData2()
eData.setData(contentList)
//将数据写入xlsx
... ... @@ -523,11 +517,6 @@ func (srv *StaffAssessServeice) ExportUserAssess(param *query.ExportAssessConten
rowNum := 0
for _, v := range eData.rowSort.Child {
//纵向-索引-第一列-日期
if len(includeBeginDay) > 0 {
if _, ok := includeBeginDay[v.Name]; !ok {
continue
}
}
for _, v2 := range v.Child {
//纵向-索引-第二列-员工id
//填充1,2 列
... ... @@ -572,11 +561,6 @@ func (srv *StaffAssessServeice) ExportUserAssess(param *query.ExportAssessConten
rowNum = 0
for _, v4 := range eData.rowSort.Child {
//纵向-索引-第一列-日期
if len(includeBeginDay) > 0 {
if _, ok := includeBeginDay[v4.Name]; !ok {
continue
}
}
for _, v5 := range v4.Child {
//纵向-索引-第二列-员工id
rowNum++
... ...
... ... @@ -2,6 +2,7 @@ package service
import (
"fmt"
"sort"
"strconv"
"github.com/linmadan/egglib-go/core/application"
... ... @@ -36,14 +37,6 @@ func (srv StaffAssessServeice) SearchAssessTaskMeV2(param *query.SearchAssessMeQ
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())
// }
assessCycleList, cnt, err := staffAssessDao.SearchExecutorAssessBeforeNow(param.UserId, param.CompanyId, limit, offset)
if err != nil {
... ... @@ -231,6 +224,10 @@ func (srv StaffAssessServeice) AssessTaskDescV2(param *query.AssessTaskDescV2Que
}
result.StepList = append(result.StepList, stepItem)
}
//排序评估阶段
sort.Slice(result.StepList, func(i, j int) bool {
return result.StepList[i].SortBy < result.StepList[j].SortBy
})
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
package service
// // excel表头部字段
// type excelTableHeader struct {
// Level1 string
// Level2 string
// Level3 string
// Level4 string
// }
... ... @@ -149,10 +149,10 @@ func (srv *SummaryEvaluationService) ExportAllEvaluationFinish(param *command.Qu
tableHead = append(tableHead, ratingHeader...)
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")
// }
if len(tableHead) > 1 {
cellCode, _ := excelize.ColumnNumberToName(len(tableHead))
xlsxFile.MergeCell(firstSheetName, "A1", cellCode+"1")
}
}
xlsxFile.SetSheetRow(firstSheetName, "A2", &tableHead)
firstDataRow := 3
... ...
... ... @@ -138,7 +138,6 @@ func sendSummaryEvaluation(project *domain.EvaluationProject,
DepartmentName: depart.Name,
})
}
//确定自评
newEvaluationList = append(newEvaluationList, evaluationTemp)
if hrbpExist {
//处理人资评估
... ... @@ -146,7 +145,6 @@ func sendSummaryEvaluation(project *domain.EvaluationProject,
evaluationTemp.EndTime = endTime360
evaluationTemp.Executor = domain.StaffDesc{}
evaluationTemp.Types = domain.EvaluationHrbp
//确定人资评估
newEvaluationList = append(newEvaluationList, evaluationTemp)
}
//处理360 评估
... ... @@ -159,7 +157,6 @@ func sendSummaryEvaluation(project *domain.EvaluationProject,
UserName: v2.Name,
}
evaluationTemp.Types = domain.Evaluation360
//确定人资评估
newEvaluationList = append(newEvaluationList, evaluationTemp)
}
... ...
package service
import (
"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/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
// 定时下发周期评估任务
func TaskSendSummaryEvaluationV2() error {
nowTime := time.Now()
defer func() {
str := fmt.Sprintf("下发周期评估耗时%.2f s", time.Since(nowTime).Seconds())
log.Logger.Info(str)
}()
for {
cycleList, err := getPrepareEvaluationCycle()
if err != nil {
return err
}
if len(cycleList) == 0 {
break
}
err = sendSummaryEvaluationByCycle(cycleList[0])
if err != nil {
return err
}
}
return nil
}
// 获取周期
func getPrepareEvaluationCycle() ([]*domain.EvaluationCycle, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, err
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
cycleRepo := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleList, err := cycleRepo.FindCycleEnd(1)
if err != nil {
return nil, fmt.Errorf("获取可用的周期数据,%s", err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, err
}
return cycleList, nil
}
// 获取可用的项目
// func getPrepareSummaryEvaluation(cycleId int) ([]*domain.EvaluationProject, error) {
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return nil, err
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, err
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
// projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// // 获取项目数据总数
// _, projectList, err := projectRepo.Find(map[string]interface{}{
// "cycleId": cycleId,
// "summaryState": domain.ProjectSummaryStateNo,
// "state": domain.ProjectStateEnable,
// "limit": 200,
// }, "template")
// if err != nil {
// return nil, fmt.Errorf("获取可用的项目数据,%s", err)
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, err
// }
// return projectList, nil
// }
// 按周期下发 综合评估任务
func sendSummaryEvaluationByCycle(cycleParam *domain.EvaluationCycle) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
// 获取项目数据总数
_, projectList, err := projectRepo.Find(map[string]interface{}{
"cycleId": cycleParam.Id,
"summaryState": domain.ProjectSummaryStateNo,
"state": domain.ProjectStateEnable,
"limit": 500,
}, "template")
if err != nil {
return fmt.Errorf("获取可用的项目数据,%s", err)
}
var newEvaluationList []domain.SummaryEvaluation
newPublisher := summaryEvaluationPublisher{}
for _, val := range projectList {
evaluationList, err := newPublisher.sendSummaryEvaluationV2(transactionContext, val, cycleParam)
if err != nil {
return fmt.Errorf("按项目下发综合评估任务数据,%s", err)
}
newEvaluationList = append(newEvaluationList, evaluationList...)
}
// 回填周期的状态
cycleDao := dao.NewEvaluationCycleDao(map[string]interface{}{"transactionContext": transactionContext})
err = cycleDao.UpdateSummaryState(cycleParam.Id, domain.ProjectSummaryStateYes)
if err != nil {
return fmt.Errorf("保存项目周期状态%s", err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return err
}
err = sendSmsEvalation(newEvaluationList)
if err != nil {
return fmt.Errorf("设置短信消息%s", err)
}
return nil
}
// 下发周期综合评估
type summaryEvaluationPublisher struct {
userCache map[int64]*domain.User
departCache map[int]*domain.Department
}
func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
transactionContext application.TransactionContext,
projectParam *domain.EvaluationProject, cycleData *domain.EvaluationCycle,
) ([]domain.SummaryEvaluation, error) {
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return err
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return err
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
_, evaluationItemList, err := evaluationItemRepo.Find(map[string]interface{}{
"evaluationProjectId": projectParam.Id,
"nodeType": int(domain.LinkNodeSelfAssessment),
})
if err != nil {
return nil, err
}
if len(evaluationItemList) == 0 {
return nil, nil
}
nodeId := evaluationItemList[0].NodeId
executor360Map := map[int64]*domain.User{}
hrbpExist := false
for _, v := range evaluationItemList {
nodeId = v.NodeId
if v.EvaluatorId < 0 {
hrbpExist = true
}
if v.EvaluatorId <= 0 {
continue
}
user360, err := se.getUserData(userRepo, int64(v.EvaluatorId))
if err != nil {
return nil, fmt.Errorf("获取360用户%s", err)
}
executor360Map[user360.Id] = user360
}
if cycleData.TimeEnd == nil {
return nil, fmt.Errorf("周期%d:%s 结束时间错误", cycleData.Id, cycleData.Name)
}
//自评的时间范围
beginTimeSelf := *cycleData.TimeEnd
endTimeSelf := dayZeroTime(beginTimeSelf).Add(3*24*time.Hour - time.Second)
//人资、360评估的时间范围
beginTime360 := endTimeSelf
endTime360 := endTimeSelf.Add(2 * 24 * time.Hour)
//上级评估的是时间范围
beginTimeSuper := endTime360
endTimeSuper := endTime360.Add(2 * 24 * time.Hour)
// 创建周期评估任务
var newEvaluationList []domain.SummaryEvaluation
evaluationTemp := domain.SummaryEvaluation{
Id: 0,
CompanyId: int(projectParam.CompanyId),
EvaluationProjectId: int(projectParam.Id),
EvaluationProjectName: projectParam.Name,
CycleId: cycleData.Id,
CycleName: cycleData.Name,
NodeId: nodeId,
TargetUser: domain.StaffDesc{}, //待填充
TargetDepartment: []domain.StaffDepartment{}, //待填充
Executor: domain.StaffDesc{},
Types: 0, //待填充
Status: domain.EvaluationUncompleted,
CheckResult: domain.EvaluationCheckUncompleted,
BeginTime: time.Time{}, //待填充
EndTime: time.Time{}, //待填充
TotalScore: "",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
DeletedAt: nil,
}
for _, val := range projectParam.Recipients {
targetUserId, _ := strconv.ParseInt(val, 10, 64)
if targetUserId == 0 {
continue
}
targetUser, err := se.getUserData(userRepo, targetUserId)
if err != nil {
return nil, fmt.Errorf("获取员工数据%s", err)
}
if targetUser == nil {
continue
}
targetUserDepartment, err := se.getDepartmentData(departmentRepo, targetUser.DepartmentId)
if err != nil {
return nil, fmt.Errorf("获取员工的部门数据%s", err)
}
evaluationTemp.TargetDepartment = []domain.StaffDepartment{}
for _, d := range targetUserDepartment {
evaluationTemp.TargetDepartment = append(evaluationTemp.TargetDepartment, domain.StaffDepartment{
DepartmentId: int(d.Id),
DepartmentName: d.Name,
})
}
evaluationTemp.TargetUser = domain.StaffDesc{
UserId: int(targetUser.Id),
Account: targetUser.Account,
UserName: targetUser.Name,
}
//处理自评
{
evaluationTemp.Types = domain.EvaluationSelf
evaluationTemp.Executor = domain.StaffDesc{
UserId: int(targetUser.Id),
Account: targetUser.Account,
UserName: targetUser.Name,
}
evaluationTemp.BeginTime = beginTimeSelf
evaluationTemp.EndTime = endTimeSelf
newEvaluationList = append(newEvaluationList, evaluationTemp)
}
//处理360评估
{
for _, val2 := range executor360Map {
evaluationTemp.BeginTime = beginTime360
evaluationTemp.EndTime = endTime360
evaluationTemp.Executor = domain.StaffDesc{
UserId: int(val2.Id),
Account: val2.Account,
UserName: val2.Name,
}
evaluationTemp.Types = domain.Evaluation360
//确定人资评估
newEvaluationList = append(newEvaluationList, evaluationTemp)
}
}
//处理人资评估
{
if hrbpExist {
//处理人资评估
evaluationTemp.BeginTime = beginTime360
evaluationTemp.EndTime = endTime360
evaluationTemp.Executor = domain.StaffDesc{}
evaluationTemp.Types = domain.EvaluationHrbp
newEvaluationList = append(newEvaluationList, evaluationTemp)
}
}
//处理上级评估
{
superUser, _ := se.getUserData(userRepo, targetUser.ParentId)
if superUser != nil {
evaluationTemp.Types = domain.EvaluationSuper
evaluationTemp.Executor = domain.StaffDesc{
UserId: int(superUser.Id),
Account: superUser.Account,
UserName: superUser.Name,
}
evaluationTemp.BeginTime = beginTimeSuper
evaluationTemp.EndTime = endTimeSuper
//确定上级评估
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 {
err = summaryEvaluationRepo.Save(&newEvaluationList[i])
if err != nil {
return nil, fmt.Errorf("保存周期综合评估%s", err)
}
}
//回填项目的状态
projectDao := dao.NewEvaluationProjectDao(map[string]interface{}{"transactionContext": transactionContext})
err = projectDao.UpdateSummaryState(projectParam.Id, domain.ProjectSummaryStateYes)
if err != nil {
return nil, fmt.Errorf("保存项目状态%s", err)
}
// if err := transactionContext.CommitTransaction(); err != nil {
// return err
// }
return newEvaluationList, nil
}
// 获取周期设置数据
// func (se *summaryEvaluationPublisher) getCycleData(cycleRepo domain.EvaluationCycleRepository, cycleId int64) (*domain.EvaluationCycle, error) {
// var cycleData *domain.EvaluationCycle
// if val, ok := se.cycleCache[cycleId]; ok {
// cycleData = val
// } else {
// _, cycleList, err := cycleRepo.Find(map[string]interface{}{"id": cycleId})
// if err != nil {
// return nil, err
// }
// if len(cycleList) == 0 {
// return nil, nil
// }
// cycleData = cycleList[0]
// }
// return cycleData, nil
// }
// 获取用户数据
func (se *summaryEvaluationPublisher) getUserData(userRepo domain.UserRepository, userId int64) (*domain.User, error) {
if userId == 0 {
return nil, nil
}
var userData *domain.User
if val, ok := se.userCache[userId]; ok {
userData = val
} else {
_, userList, err := userRepo.Find(map[string]interface{}{"id": userId})
if err != nil {
return nil, err
}
if len(userList) == 0 {
return nil, nil
}
userData = userList[0]
}
return userData, nil
}
// 获取部门数据
func (se *summaryEvaluationPublisher) getDepartmentData(departmentRepo domain.DepartmentRepository, departmentIds []int) ([]*domain.Department, error) {
departmentList := []*domain.Department{}
for _, departmentId := range departmentIds {
if val, ok := se.departCache[departmentId]; ok {
departmentList = append(departmentList, val)
} else {
_, departments, err := departmentRepo.Find(map[string]interface{}{"id": departmentId})
if err != nil {
return nil, err
}
if len(departmentList) == 0 {
continue
}
departmentList = append(departmentList, departments[0])
}
}
return departmentList, nil
}
... ...
... ... @@ -657,10 +657,9 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.
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].BeginTime = param.EndTime
evaluationList[0].Status = domain.EvaluationCompleted
err = evaluationRepo.Save(evaluationList[0])
if err != nil {
... ... @@ -757,9 +756,8 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *doma
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) > 0 {
if evaluationList[0].BeginTime.After(nowTime) {
evaluationList[0].BeginTime = nowTime
}
//360评估的结束时间
evaluationList[0].BeginTime = param.EndTime
evaluationList[0].Status = domain.EvaluationCompleted
err = evaluationRepo.Save(evaluationList[0])
if err != nil {
... ... @@ -809,11 +807,10 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(param *domain
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].BeginTime = param.EndTime
evaluationList[0].Status = domain.EvaluationCompleted
err = evaluationRepo.Save(evaluationList[0])
if err != nil {
... ... @@ -875,7 +872,7 @@ func (srv *SummaryEvaluationService) GetTargetUserCycleList(param *command.Query
return tool_funs.SimpleWrapGridMap(int64(cnt), cycleList), nil
}
// 自评小结详情
// 周期综合自评小结详情
func (srv *SummaryEvaluationService) CountEvaluationSelfLevel(param *command.QueryEvaluation) (*adapter.EvaluationInfoCountCodeAdapter, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -887,16 +884,10 @@ func (srv *SummaryEvaluationService) CountEvaluationSelfLevel(param *command.Que
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//统计周期内,评估项等级的数量
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
levelCodeCountList, err := assessDao.CountAssessContentLevelCode(param.TargetUserId, domain.AssessSelf, param.CycleId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
... ... @@ -919,6 +910,10 @@ func (srv *SummaryEvaluationService) CountEvaluationSelfLevel(param *command.Que
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationData := evaluationList[0]
levelCodeCountList, err := assessDao.CountAssessContentLevelCode(evaluationData.EvaluationProjectId, param.TargetUserId, domain.AssessSelf, param.CycleId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
"evaluationProjectId": evaluationData.EvaluationProjectId,
"nodeType": int(domain.LinkNodeSelfAssessment),
... ...
... ... @@ -21,16 +21,17 @@ type TemplateSimple struct {
}
type EvaluationCycle struct {
Id int64 `json:"id,string" comment:"ID"`
Name string `json:"name" comment:"名称"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
Id int64 `json:"id,string" comment:"ID"`
Name string `json:"name" comment:"名称"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`
SummaryState ProjectSummaryState `json:"summaryState" comment:"周期评估是否下发"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
type EvaluationCycleRepository interface {
... ... @@ -39,4 +40,5 @@ type EvaluationCycleRepository interface {
FindOne(queryOptions map[string]interface{}) (*EvaluationCycle, error)
Find(queryOptions map[string]interface{}) (int64, []*EvaluationCycle, error)
Count(queryOptions map[string]interface{}) (int64, error)
FindCycleEnd(limit int) ([]*EvaluationCycle, error) // 获取已结束的周期,且还没下发周期评估
}
... ...
... ... @@ -7,11 +7,12 @@ import (
const (
ProjectStateWaitConfig int = 0 // 项目状态-待完成配置
ProjectStateWaitActive int = 1 // 项目状态-待启用
ProjectStateEnable int = 2 // 项目状态-启用
ProjectStateDisable int = 3 // 项目状态-停用(假状态)
ProjectStateEnable int = 2 // 项目状态-启动
ProjectStateDisable int = 3 // 项目状态-结束(假状态)
ProjectStatePause int = 4 // 项目状态-暂停(可恢复启动)
)
// 项目的评估内容配置
// EvaluationProject 项目的评估内容配置
type EvaluationProject struct {
Id int64 `json:"id,string" comment:"ID"`
Name string `json:"name" comment:"名称"`
... ... @@ -33,6 +34,7 @@ type EvaluationProject struct {
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
// 周期评估的下发状态
type ProjectSummaryState int
const (
... ...
... ... @@ -42,5 +42,6 @@ func (sms *LogSms) SummaryEvaluationMessage(phone string, name string) {
type LogSmsRepository interface {
Save(param *LogSms) error
BatchInsert(params []*LogSms) error
Find(queryOptions map[string]interface{}) (int, []*LogSms, error)
}
... ...
... ... @@ -9,8 +9,8 @@ import (
func TestGenerateToken(t *testing.T) {
ut := UserAuth{
CompanyId: 8,
UserId: 3422052542754304,
Phone: "13678998765",
UserId: 3422174102828544,
Phone: "17708397664",
PlatformId: 29,
AdminType: 1,
}
... ...
package dao
import (
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 EvaluationCycleDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewEvaluationCycleDao(options map[string]interface{}) *EvaluationCycleDao {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return &EvaluationCycleDao{
transactionContext: transactionContext,
}
}
func (d *EvaluationCycleDao) UpdateSummaryState(id int64, status domain.ProjectSummaryState) error {
db := d.transactionContext.PgTx
_, err := db.Model(&models.EvaluationCycle{}).
Where("id=?", id).
Set("summary_state=?", int(status)).
Update()
return err
}
... ...
... ... @@ -383,7 +383,8 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
t_staff_assess_0.target_user_name,
t_staff_assess_0.begin_day,
t_staff_assess_0.cycle_name,
t_staff_assess_0.cycle_id
t_staff_assess_0.cycle_id,
t_staff_assess_0.evaluation_project_id
from t_staff_assess_0
join t_project_3 on t_staff_assess_0.evaluation_project_id = t_project_3.project_id
) union (select t_staff_assess_0.assess_id,
... ... @@ -391,7 +392,8 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
t_staff_assess_0.target_user_name,
t_staff_assess_0.begin_day,
t_staff_assess_0.cycle_name,
t_staff_assess_0.cycle_id
t_staff_assess_0.cycle_id,
t_staff_assess_0.evaluation_project_id
from t_staff_assess_0
join t_user_1 on t_staff_assess_0.target_user_id=t_user_1.user_id
)
... ... @@ -804,6 +806,38 @@ func (d *StaffAssessDao) MemberPerformanceIndicator(likeUserName string, company
}
type IndicatorUserProject struct {
AssessId int `json:"assessId"` // ID
TargetUserId int `json:"targetUserId"` // 目标用户ID
TargetUserName string `json:"targetUserName"` // 目标用户名称
EvaluationProjectId int `json:"evaluationProjectId"` // 项目ID
}
func (d *StaffAssessDao) MemberAllProjectId(companyId int, likeUserName string, operatorId int, cycleId int, hrbp int) ([]IndicatorUserProject, error) {
sqlStr := ` select
t_staff_assess_1.evaluation_project_id,
t_staff_assess_1.target_user_id,
t_staff_assess_1.target_user_name,
t_staff_assess_1.assess_id
from t_staff_assess_1
where 1=1
`
var condition []interface{}
if len(likeUserName) > 0 {
sqlStr += ` and t_staff_assess_1.target_user_name like ? `
condition = append(condition, "%"+likeUserName+"%")
}
// 获取前置sql语句
sqlStr0 := d.useTStaffAssess(companyId, cycleId, operatorId, "", hrbp, 5000, 0, string(domain.AssessSelf))
sqlStr = sqlStr0 + sqlStr
tx := d.transactionContext.PgTx
var result []IndicatorUserProject
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
type ExportPerformanceIndicator struct {
AssessId int `json:"assessId"` // ID
TargetUserId string `json:"targetUserId"` // 被评估人的id
... ... @@ -1199,7 +1233,7 @@ type AssessContentLevelCode struct {
Name string `pg:"name"` //名称
}
func (d *StaffAssessDao) CountAssessContentLevelCode(targetUserId int, assessType domain.StaffAssessType, cycleId int) ([]AssessContentLevelCode, error) {
func (d *StaffAssessDao) CountAssessContentLevelCode(projectId int, targetUserId int, assessType domain.StaffAssessType, cycleId int) ([]AssessContentLevelCode, error) {
sqlStr := `
select
count(staff_assess_content.level_value) as cnt ,
... ... @@ -1208,16 +1242,18 @@ 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
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 =?
and staff_assess.evaluation_project_id=?
group by level_value,category,"name" `
var result []AssessContentLevelCode
condition := []interface{}{
targetUserId, string(assessType), cycleId,
targetUserId, string(assessType), cycleId, projectId,
}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, condition...)
... ...
package dao
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type DataStaffAssessContent2 struct {
CycleId string `pg:"cycle_id"` //周期id
CycleName string `pg:"cycle_name"` //周期名称
EvaluationProjectId string `pg:"evaluation_project_id"` //
TargetUserId string `pg:"target_user_id"` //被评估人的id
TargetUserName string `pg:"target_user_name"` //被评估人的名称
BeginDay string `pg:"begin_day"` //评估的日期
Value string `pg:"value"` //评估填写的值
Category string `pg:"category"` //评估项分类
ContentName string `pg:"content_name"` //评估项名称
Weight float64 `pg:"weight"` //权重
PromptText string `pg:"prompt_text"` //评估标准
Remark []domain.AssessContemtRemark `pg:"remark"`
}
// SearchStaffAssessContent2 用于员工绩效-综合管理-导出绩效-个人
// 获取所有评估的填写内容
// companyId 公司id
// cycleId 周期id
// operaterId 操作人、查看人的id
// hrbp 操作人、查看人是否hrbp 1:是;-1:否
func (d *StaffAssessDao) SearchStaffAssessContent2(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) (
[]DataStaffAssessContent2, error) {
withSql := d.catchProjectIdByPermission(companyId, cycleId, operaterId, hrbp)
sqlStr := ` select
staff_assess.target_user ->>'userId' as target_user_id,
staff_assess.evaluation_project_id,
staff_assess.target_user ->>'userName' as target_user_name,
to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
staff_assess.cycle_id,
staff_assess.cycle_name,
staff_assess_content.value ,
staff_assess_content.category ,
staff_assess_content."name" as content_name ,
staff_assess_content.weight,
staff_assess_content.prompt_text,
staff_assess_content.remark
from staff_assess
join staff_assess_content on staff_assess.id = staff_assess_content.staff_assess_id
where 1=1
and staff_assess.cycle_id =? and "types" ='self'
and staff_assess.evaluation_project_id in (
select t_project_4.project_id from t_project_4
) `
condition := []interface{}{cycleId}
if len(exportUserIds) > 0 {
sqlStr += ` and staff_assess.target_user->>'userId' in(?) `
condition = append(condition, pg.In(exportUserIds))
}
sqlStr = withSql + sqlStr + ` order by staff_assess.begin_time `
result := []DataStaffAssessContent2{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
type DataEvaluationItemUsed2 struct {
CycleId string `pg:"cycle_id"` //周期id
CycleName string `pg:"cycle_name"` //周期名称
EvaluationProjectId string `pg:"evaluation_project_id"` //评估的项目
TargetUserId string `pg:"target_user_id"` //被评估人的id
TargetUserName string `pg:"target_user_name"` //被评估人的名称
BeginDay string `pg:"begin_day"` //评估的日期
Category string `pg:"category"` //评估项分类
ContentName string `pg:"content_name"` //评估项名称
Weight float64 `pg:"weight"` //权重
PromptText string `pg:"prompt_text"` //评估标准
}
// SearchEvaluationItemUsed2 用于员工绩效-综合管理-导出绩效-个人
// 获取所有评估的填写项
// companyId 公司id
// cycleId 周期id
// operaterId 操作人、查看人的id
// hrbp 操作人、查看人是否hrbp 1:是;-1:否
func (d *StaffAssessDao) SearchEvaluationItemUsed2(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) (
[]DataEvaluationItemUsed2, error) {
withSql := d.catchProjectIdByPermission(companyId, cycleId, operaterId, hrbp)
sqlStr := `select
staff_assess.target_user ->>'userId' as target_user_id,
staff_assess.evaluation_project_id ,
staff_assess.target_user ->>'userName' as target_user_name,
to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
staff_assess.cycle_id,
staff_assess.cycle_name,
evaluation_item_used.category ,
evaluation_item_used."name" as content_name ,
evaluation_item_used.weight,
evaluation_item_used.prompt_text
from staff_assess
join evaluation_item_used on evaluation_item_used.evaluation_project_id = staff_assess.evaluation_project_id
where 1=1
and staff_assess.cycle_id =? and "types" ='self'
and staff_assess.evaluation_project_id in (
select t_project_4.project_id from t_project_4
) `
condition := []interface{}{cycleId}
if len(exportUserIds) > 0 {
sqlStr += ` and staff_assess.target_user->>'userId' in(?) `
condition = append(condition, pg.In(exportUserIds))
}
sqlStr = withSql + sqlStr
result := []DataEvaluationItemUsed2{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// sql 语句片段
// 按照人员可查看权限的过滤
// companyId int 公司id (必填)
// cycleId int, 评估周期id (必填)
// userId int, 用户id,谁要查看数据 (必填)
// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否 (必填)
func (d *StaffAssessDao) catchProjectIdByPermission(companyId int, cycleId int, operaterId int, hrbp int) string {
withSql := `
with
t_project_0 as(
select evaluation_project.id as project_id,
jsonb_array_elements_text(evaluation_project.recipients) as target_user_id,
evaluation_project.pmp,
evaluation_project.pmp_ids,
evaluation_project.hr_bp
from evaluation_project
where evaluation_project.cycle_id =%d
and evaluation_project.deleted_at isnull
),
-- 查我的下级员工
t_user_1 as (
select "user".id::text as user_id from "user"
where "user".parent_id =%d and company_id=%d
),
-- 如果是HRBP
t_project_1 as(
select t_project_0.project_id,t_project_0.target_user_id
from t_project_0
where t_project_0.hr_bp =%d
),
-- 如果的项目管理员
t_project_2 as(
select t_project_0.project_id,t_project_0.target_user_id
from t_project_0
where t_project_0.pmp =1
and t_project_0.pmp_ids @>'["%d"]'
),
-- 如果是上级员工
t_project_3 as (
select t_project_0.project_id,t_project_0.target_user_id
from t_project_0
join t_user_1 on t_user_1.user_id = t_project_0.target_user_id
),
-- 合并数据
t_project_4 as (
select t_project_2.project_id,t_project_2.target_user_id from t_project_2
union
select t_project_1.project_id,t_project_1.target_user_id from t_project_1
union
select t_project_3.project_id,t_project_3.target_user_id from t_project_3
)`
params := []interface{}{cycleId, operaterId, companyId, hrbp, operaterId}
return fmt.Sprintf(withSql, params...)
}
type TargetUserCycleProject struct {
CycleId string `pg:"cycle_id" json:"cycleId"` //周期id
CycleName string `pg:"cycle_name" json:"cycleName"` //周期名称
EvaluationProjectId string `pg:"evaluation_project_id" json:"evaluationProjectId"`
EvaluationProjectName string `pg:"evaluation_project_name" json:"evaluationProjectName"`
TargetUserId string `pg:"target_user_id" json:"targetUserId"`
}
// 获取目标员工的自评周期和项目
func (d *StaffAssessDao) SearchTargetUserCycleProject(companyId int, targetUserId int, limit int, offset int) ([]TargetUserCycleProject, error) {
sqlStr := `select distinct
staff_assess.cycle_name,
staff_assess.cycle_id ,
staff_assess.evaluation_project_id,
staff_assess.target_user ->>'userId' as target_user_id,
staff_assess.evaluation_project_name
from staff_assess ,staff_assess_task
where 1=1
and staff_assess_task.id =staff_assess.staff_assess_task_id
and staff_assess."types" ='self'
and staff_assess_task.deleted_at isnull
and staff_assess.deleted_at isnull
and staff_assess.target_user ->>'userId'='?'
and staff_assess.company_id=?
`
sqlStr += ` order by cycle_id desc limit ? offset ? `
condition := []interface{}{targetUserId, companyId, limit, offset}
result := []TargetUserCycleProject{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
type SearchConditin2 struct {
CompanyId int //公司id
CycleId int //周期id
BeginDayList []string //评估的日期
TargetUserName string //被评估人的名称
TargetUserId []string //查询指定的人
OperaterId int //用户的id是谁在搜索数据
Hrbp int //
}
// 项目管理-成员列表 导出数据
func (d *StaffAssessDao) ExportDataUserAssessV2(param SearchConditin2) ([]ExportData1, error) {
withSql := d.catchProjectIdByPermission(param.CompanyId, param.CycleId, param.OperaterId, param.Hrbp)
sqlStr := `select
staff_assess.target_user->>'userId' as target_user_id ,
staff_assess.target_user->>'userName' as target_user_name ,
to_char(staff_assess.begin_time at time zone 'PRC','YYYY-MM-DD') as begin_day,
staff_assess.id as assess_id,
staff_assess.cycle_id,
staff_assess.cycle_name,
staff_assess_content.id as content_id,
staff_assess_content.value ,
staff_assess_content.sort_by ,
staff_assess_content.category ,
staff_assess_content."name" as content_name ,
staff_assess_content.weight,
staff_assess_content.prompt_text ,
staff_assess_content.remark
from staff_assess
join t_project_4 on staff_assess.evaluation_project_id =t_project_4.project_id
left join staff_assess_content on staff_assess.id = staff_assess_content.staff_assess_id
where 1=1
and staff_assess."types" ='self'
`
condition := []interface{}{}
if len(param.TargetUserName) > 0 {
condition = append(condition, "%"+param.TargetUserName+"%")
sqlStr += ` and staff_assess.target_user->>'userName' like ? `
}
if len(param.BeginDayList) > 0 {
condition = append(condition, pg.In(param.BeginDayList))
sqlStr += ` and to_char(staff_assess.begin_time at time zone 'PRC','YYYY-MM-DD') in(?) `
}
if len(param.TargetUserId) > 0 {
condition = append(condition, pg.In(param.TargetUserId))
sqlStr += ` and staff_assess.target_user->>'userId' in (?) `
}
sqlStr = withSql + sqlStr + ` order by convert_to(staff_assess.target_user->>'userName','GBK'),begin_day,staff_assess_content.sort_by `
tx := d.transactionContext.PgTx
var result []ExportData1
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
... ...
... ... @@ -5,15 +5,16 @@ import (
)
type EvaluationCycle struct {
tableName struct{} `comment:"评估周期" pg:"evaluation_cycle"`
Id int64 `comment:"周期ID" pg:"pk:id"`
Name string `comment:"名称"`
TimeStart *time.Time `comment:"起始时间"`
TimeEnd *time.Time `comment:"截至时间"`
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
KpiCycle int `comment:"考核周期(1日、2周、3月)"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
tableName struct{} `comment:"评估周期" pg:"evaluation_cycle"`
Id int64 `comment:"周期ID" pg:"pk:id"`
Name string `comment:"名称"`
TimeStart *time.Time `comment:"起始时间"`
TimeEnd *time.Time `comment:"截至时间"`
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
KpiCycle int `comment:"考核周期(1日、2周、3月)"`
SummaryState int `comment:"周期评估是否下发" pg:",use_zero"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
... ... @@ -23,31 +23,33 @@ func NewEvaluationCycleRepository(transactionContext *pgTransaction.TransactionC
func (repo *EvaluationCycleRepository) TransformToDomain(m *models.EvaluationCycle) domain.EvaluationCycle {
return domain.EvaluationCycle{
Id: m.Id,
Name: m.Name,
TimeStart: m.TimeStart,
TimeEnd: m.TimeEnd,
CompanyId: m.CompanyId,
CreatorId: m.CreatorId,
KpiCycle: m.KpiCycle,
CreatedAt: m.CreatedAt.Local(),
UpdatedAt: m.UpdatedAt.Local(),
DeletedAt: m.DeletedAt,
Id: m.Id,
Name: m.Name,
TimeStart: m.TimeStart,
TimeEnd: m.TimeEnd,
CompanyId: m.CompanyId,
CreatorId: m.CreatorId,
KpiCycle: m.KpiCycle,
SummaryState: domain.ProjectSummaryState(m.SummaryState),
CreatedAt: m.CreatedAt.Local(),
UpdatedAt: m.UpdatedAt.Local(),
DeletedAt: m.DeletedAt,
}
}
func (repo *EvaluationCycleRepository) TransformToModel(d *domain.EvaluationCycle) models.EvaluationCycle {
return models.EvaluationCycle{
Id: d.Id,
Name: d.Name,
TimeStart: d.TimeStart,
TimeEnd: d.TimeEnd,
CompanyId: d.CompanyId,
CreatorId: d.CreatorId,
KpiCycle: d.KpiCycle,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
Id: d.Id,
Name: d.Name,
TimeStart: d.TimeStart,
TimeEnd: d.TimeEnd,
CompanyId: d.CompanyId,
CreatorId: d.CreatorId,
KpiCycle: d.KpiCycle,
SummaryState: int(d.SummaryState),
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
}
}
... ... @@ -127,6 +129,10 @@ func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{})
query.Where("id in (?)", pg.In(v))
}
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
... ... @@ -191,3 +197,25 @@ func (repo *EvaluationCycleRepository) Count(queryOptions map[string]interface{}
}
return int64(count), nil
}
// 获取已结束的周期
func (repo *EvaluationCycleRepository) FindCycleEnd(limit int) ([]*domain.EvaluationCycle, error) {
tx := repo.transactionContext.PgTx
var m []*models.EvaluationCycle
query := tx.Model(&m).
Where("deleted_at isnull").
Where("time_end<=?", time.Now()).
Where("summary_state=0").
Limit(limit)
err := query.Select()
if err != nil {
return nil, err
}
var arrays []*domain.EvaluationCycle
for _, v := range m {
d := repo.TransformToDomain(v)
arrays = append(arrays, &d)
}
return arrays, nil
}
... ...
... ... @@ -96,3 +96,33 @@ func (repo *LogSmsRepository) TransformToDomain(d *models.LogSms) *domain.LogSms
CreatedAt: d.CreatedAt,
}
}
//批量添加
func (repo *LogSmsRepository) BatchInsert(params []*domain.LogSms) error {
smsList := []models.LogSms{}
for _, param := range params {
m := models.LogSms{
Id: param.Id,
Phone: param.Phone,
TemplateId: param.TemplateId,
Template: param.Template,
Value: param.Value,
CreatedAt: param.CreatedAt,
Result: param.Result,
Status: string(param.Status),
From: param.From,
Index: param.Index,
ExecuteAt: param.ExecuteAt,
}
smsList = append(smsList, m)
}
tx := repo.transactionContext.PgTx
_, err := tx.Model(&smsList).Insert()
if err != nil {
return err
}
return nil
}
... ...
... ... @@ -128,9 +128,15 @@ func (repo *StaffAssessRepository) Find(queryOptions map[string]interface{}) (in
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
if v, ok := queryOptions["id"]; ok {
query.Where("staff_assess.id=?", v)
}
if v, ok := queryOptions["targetUserId"]; ok {
query.Where(`staff_assess.target_user->>'userId'='?'`, v)
}
if v, ok := queryOptions["targetUserIds"]; ok {
query.Where(`staff_assess.target_user->>'userId' in(?)`, pg.In(v))
}
if v, ok := queryOptions["targetUserName"].(string); ok {
query.Where(`staff_assess.target_user->>'userName' like ?`, fmt.Sprintf("%%%v%%", v))
... ... @@ -138,16 +144,14 @@ func (repo *StaffAssessRepository) Find(queryOptions map[string]interface{}) (in
if v, ok := queryOptions["executorId"]; ok {
query.Where(`staff_assess.executor->>'userId'='?'`, v)
}
if v, ok := queryOptions["cycleId"]; ok {
query.Where(`staff_assess.cycle_id=?`, v)
}
if v, ok := queryOptions["staffAssessTaskId"]; ok {
query.Where(`staff_assess.staff_assess_task_id=?`, v)
}
if v, ok := queryOptions["id"]; ok {
query.Where("staff_assess.id=?", v)
if v, ok := queryOptions["types"]; ok {
query.Where(`staff_assess.types=?`, v)
}
if v, ok := queryOptions["typesList"].([]string); ok {
query.Where("staff_assess.types in(?)", pg.In(v))
... ... @@ -161,6 +165,9 @@ func (repo *StaffAssessRepository) Find(queryOptions map[string]interface{}) (in
if v, ok := queryOptions["beginDay"]; ok {
query.Where("to_char(staff_assess.begin_time at time zone 'PRC','YYYY-MM-DD')= ? ", v)
}
if v, ok := queryOptions["evaluationProjectId"]; ok {
query.Where("staff_assess.evaluation_project_id=?", v)
}
query.Order("staff_assess.id DESC")
count, err := query.SelectAndCount()
if err != nil {
... ...
... ... @@ -96,6 +96,26 @@ func (controller *ProjectController) ActivateProject() {
}
}
func (controller *ProjectController) PauseProject() {
ruService := service.NewEvaluationProjectService()
in := &command.ActivateProjectCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
controller.Response(ruService.Pause(in))
}
}
func (controller *ProjectController) ResumeProject() {
ruService := service.NewEvaluationProjectService()
in := &command.ActivateProjectCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
controller.Response(ruService.Resume(in))
}
}
func (controller *ProjectController) CopyProject() {
ruService := service.NewEvaluationProjectService()
in := &command.CopyProjectCommand{}
... ...
... ... @@ -249,7 +249,6 @@ func (c *StaffAssessController) QueryMemberPerformanceIndicator() {
if user := middlewares.GetUser(c.Ctx); user != nil {
in.CompanyId = int(user.CompanyId)
in.OperatorId = int(user.UserId)
}
c.Response(srv.QueryMemberPerformanceIndicator(in))
}
... ... @@ -311,7 +310,7 @@ func (c *StaffAssessController) ExportUserAssess2() {
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
paramReq.OperatorId = int(userReq.UserId)
data, err := srv.ExportUserAssess2(paramReq)
data, err := srv.ExportUserAssess2V2(paramReq)
if err != nil {
c.Response(nil, err)
return
... ... @@ -324,3 +323,35 @@ func (c *StaffAssessController) ExportUserAssess2() {
c.Ctx.Output.Header("Expires", "0")
data.Write(c.Ctx.ResponseWriter)
}
// ListTargetUserSelfCycle 获取目标员工自评周期列表
func (c *StaffAssessController) ListTargetUserSelfCycle() {
srv := service.NewStaffAssessServeice()
paramReq := &query.ListTargetUserCycleQuery{}
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.CompanyId = int(userReq.CompanyId)
data, err := srv.ListTargetUserSelfCycle(paramReq)
c.Response(data, err)
}
// ListTargetUserSelfCycle 按照周期获取员工的每日自评小结
func (c *StaffAssessController) GetStaffAsessSelfCountLevel() {
srv := service.NewStaffAssessServeice()
paramReq := &query.StaffAsessSelfCountLevel{}
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.CompanyId = int(userReq.CompanyId)
data, err := srv.GetStaffAsessSelfCountLevel(paramReq)
c.Response(data, err)
}
... ...
... ... @@ -90,8 +90,6 @@ func (c *SummaryEvaluationController) GetTargetUserCycleList() {
c.Response(nil, e)
return
}
// userReq := middlewares.GetUser(c.Ctx)
// paramReq.UserId = int(userReq.UserId)
data, err := srv.GetTargetUserCycleList(paramReq)
c.Response(data, err)
}
... ... @@ -110,7 +108,6 @@ func (c *SummaryEvaluationController) CountEvaluationSelfLevel() {
paramReq.CompanyId = int(userReq.CompanyId)
data, err := srv.CountEvaluationSelfLevel(paramReq)
c.Response(data, err)
}
func (c *SummaryEvaluationController) Evaluation360List() {
... ...
... ... @@ -19,6 +19,8 @@ func init() {
web.NSRouter("/check-recipients", &controllers.ProjectController{}, "Post:CheckRecipients"),
web.NSRouter("/copy", &controllers.ProjectController{}, "Post:CopyProject"),
web.NSRouter("/activate", &controllers.ProjectController{}, "Post:ActivateProject"),
web.NSRouter("/pause", &controllers.ProjectController{}, "Post:PauseProject"),
web.NSRouter("/resume", &controllers.ProjectController{}, "Post:ResumeProject"),
)
web.AddNamespace(ns)
}
... ...
... ... @@ -20,7 +20,6 @@ func init() {
web.NSCtrlPost("/cycle/day/content/export", (*controllers.StaffAssessController).ExportAssessContentCycleDay), //根据周期里的考核日期,导出员工填写评估内容列表
web.NSCtrlPost("/cycle/day/analysis", (*controllers.StaffAssessController).AnalysisData), //员工绩效-项目管理-矩阵分析
web.NSCtrlPost("/cycle/day/content/export2", (*controllers.StaffAssessController).ExportUserAssess2), //员工绩效-综合管理-导出绩效-个人
)
assessNS := web.NewNamespace("/v1/staff-assess",
... ... @@ -35,6 +34,8 @@ func init() {
web.NSCtrlPost("/summary/users", (*controllers.StaffAssessController).QueryMemberSummary), //员工绩效-综合管理-成员列表
web.NSCtrlPost("/summary/users-indicator", (*controllers.StaffAssessController).QueryMemberPerformanceIndicator), //员工绩效-综合管理-绩效导出指标
web.NSCtrlPost("/summary/export-indicator", (*controllers.StaffAssessController).ExportPerformanceIndicator), //员工绩效-综合管理-绩效导出指标
web.NSCtrlPost("/target_user/self/cycle", (*controllers.StaffAssessController).ListTargetUserSelfCycle), //获取员工自评的周期下拉列表
web.NSCtrlPost("/target_user/self/summary", (*controllers.StaffAssessController).GetStaffAsessSelfCountLevel), //获取员工每日自评小结
)
//v2 改版
assessTaskV2NS := web.NewNamespace("/v2/staff-assess-task",
... ...
... ... @@ -58,7 +58,6 @@ func NextTime(now0 time.Time, start time.Time, kpiCycle int) time.Time {
switch kpiCycle {
case domain.KpiCycleDay:
nextTime = now0 // 当前时间的0点开始发送
//nextTime = timeconv.AddDate(now0, 0, 0, 0) // 当前时间的0点开始发送
break
case domain.KpiCycleWeek:
offsetSeconds := int64(now0.Sub(start0).Seconds())
... ...
-- 添加summary_cycle 表字段
ALTER TABLE public.evaluation_cycle
ADD summary_state int4 NOT NULL DEFAULT 0;
-- 初始化数据的值
UPDATE
public.evaluation_cycle
SET
summary_state = 1
WHERE
time_end <= now()
AND summary_state = 0;
... ...