作者 Your Name

Merge branch 'dev-tangxvhui'

... ... @@ -128,3 +128,27 @@ func CreateEvaluationProjectRepository(options map[string]interface{}) domain.Ev
}
return repository.NewEvaluationProjectRepository(transactionContext)
}
func CreateStaffAssessRepository(options map[string]interface{}) domain.StaffAssessRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewStaffAssessRepository(transactionContext)
}
func CreateStaffAssessContentRepository(options map[string]interface{}) domain.StaffAssessContentRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewStaffAssessContentRepository(transactionContext)
}
func CreateStaffAssessTaskRepository(options map[string]interface{}) domain.StaffAssessTaskRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewStaffAssessTaskRepository(transactionContext)
}
... ...
package adapter
import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
//评估内容详情
type AssessInfoResp struct {
CycleId int64 `json:"cycleId"` //周期id
CycleName string `json:"cycleName"` //周期名称
EvaluationProjectId int `json:"evaluationProjectId"` //项目id
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
BeginTime string `json:"beginTime"` //开始时间 2006-01-02 15:04:05
EndTime string `json:"endTime"` //结束时间 2006-01-02 15:04:05
Status string `json:"status"` //完成状态
TargetUserId int `json:"targetUser"` //
TargetUserName string `json:"targetUserName"` //
AssessContent []AssessContent `json:"assessContent"` //评估内容
}
type AssessContent struct {
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*domain.EntryItem `json:"entryItems" comment:"填写项"`
}
... ...
package adapter
import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
type AssessInviteUserResp struct {
LinkNodeId int `json:"linkNodeId"`
LinkNodeName string `json:"linkNodeName"`
BeginTime string `json:"beginTime"`
EndTime string `json:"endTime"`
AssessTaskId int `json:"assessTaskId"`
InviteSameSuper []domain.StaffDesc `json:"inviteSameSuper"`
InviteDiffSuper []domain.StaffDesc `json:"inviteDiffSuper"`
}
... ...
package adapter
type AssessSelfList struct {
AssessId int `json:"assessId"` //用户执行的评估项id
BeginTime string `json:"beginTime"` //开始时间 2006-01-02 15:04:05
EndTime string `json:"endTime"` //开始时间 2006-01-02 15:04:05
CycleId int64 `json:"cycleId"` //周期id
CycleName string `json:"cycleName"` //周期名称
EvaluationProjectId int `json:"evaluationProjectId"` //项目id
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
}
type StaffInfo struct {
UserName string `json:"userName"` //员工名称
CompanyName string `json:"companyName"` //公司名称
SupperUserName string `json:"supperUserName"` //上级名称
DutyTime string `json:"dutyTime"` //上岗时间
}
... ...
package adapter
type AssessTaskDescResp struct {
AssessTaskId int `json:"assessTaskId"` //
EvaluationProjectId int `json:"evaluationProjectId"` //项目id
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
CycleName string `json:"cycleName"` //周期名称
BeginTime string `json:"beginTime"` //开始时间 2006-01-02 15:04:05
EndTime string `json:"endTime"` //结束时间 2006-01-02 15:04:05
StepList []AssessTaskStep `json:"stepList"` // 考评流程
}
type AssessTaskStep struct {
SortBy int `json:"sortBy"` //排序
LinkNodeName string `json:"linkNodeName"` //流程名称
BeginTime string `json:"beginTime"` //开始时间时间
EndTime string `json:"endTime"` //结束时间
LinkNodeType int `json:"linkNodeType"` //流程类型
Desc string `json:"desc"` //情况描述
Status string `json:"status"` //流程是否完成 "":未参加,"uncompleted":未完成,"completed":完成
}
... ...
package adapter
type SearchAssessMeResp struct {
AssessTaskId int `json:"assessTaskId"`
BeginTime string `json:"beginTime"`
EndTime string `json:"endTime"`
CycleId int64 `json:"cycleId"`
CycleName string `json:"cycleName"`
EvaluationProjectId int `json:"evaluationProjectId"`
EvaluationProjectName string `json:"evaluationProjectName"`
}
... ...
package command
type CreateStaffAssessTask struct {
CompanyId int `json:"companyId"` //公司id
EvaluationProjectId int `json:"evaluationProjectId"` //项目id
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
CycleId int64 `json:"cycleId"` //对应的周期id
CycleName string `json:"cycleName"` //对应周期的名称
BeginTime string `json:"beginTime"` //绩效考核开始时间
EndTime string `json:"endTime"` //绩效考核截止时间
StepList []AssessTaskStep `json:"steps"` //考评的流程
ExecutorId []int `json:"executorId"` //参与此次考评的人
}
type AssessTaskStep struct {
SortBy int `json:"sortBy"` //排序
LinkNodeId int `json:"linkNodeId"` //考评的流程id
LinkNodeName string `json:"linkNodeName"` //流程名称
LinkNodeType int `json:"linkNodeType"` //流程类型 同evaluation_template.go->LinkNode.Type
BeginTime string `json:"beginTime"` //绩效考核开始时间
EndTime string `json:"endTime"` //绩效考核截止时间
}
... ...
package command
type SaveAssessInvite struct {
InviteSameSuper []string `json:"inviteSameSuper"` //相同上级同事
InviteDiffSuper []string `json:"inviteDiffSuper"` //不同上级同事
AssessTaskId int `json:"assessTaskId"` //评估任务id
TargetUserId int `json:"targetUserId"` //被评估的员工id
}
... ...
package query
type AssessInfoQuery struct {
AssessTaskId int `json:"assessTaskId"` //StaffAssess 的id
TargetUserId int `json:"targetUserId"` //被评估的人id
CompanyId int `json:"companyId"` //公司id
}
... ...
package query
type AssessSelfListQuery struct {
UserId int `json:"userId"` //用户id
CompanyId int `json:"companyId"` //公司Id
PageSize int `json:"pageSize"` //每页的记录数
PageNumber int `json:"pageNumber"` //页码
}
... ...
package query
type AssessTaskDescQuery struct {
AssessTaskId int `json:"assessTaskId"` //评估任务的id
UserId int `json:"userId"` //当前登录人的id
CompanyId int `json:"companyId"` //当前登录的公司
}
... ...
package query
type GetAssessInviteUserQuery struct {
CompanyId int `json:"companyId"` //对公司
UsrId int `json:"usrId"` //被评估的员工id
AssessTaskId int `json:"assessTaskId"` //评估任务的id
}
... ...
package query
type SearchAssessMeQuery struct {
UserId int `json:"userId"` // 当前登录人的用户id
CompanyId int `json:"companyId"` //当前登录人的公司Id
PageSize int `json:"pageSize"` //每页的记录数
PageNumber int `json:"pageNumber"` //页码
}
... ...
package service
import (
"fmt"
"strconv"
"time"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/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/log"
)
// 员工评绩效评估
type StaffAssessServeice struct {
}
func NewStaffAssessServeice() *StaffAssessServeice {
newService := &StaffAssessServeice{}
return newService
}
// 获取我参与过的评估任务列表
func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQuery) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var limit int = 20
var offset int = 0
if param.PageSize > 0 {
limit = param.PageSize
}
offset = (param.PageNumber - 1) * param.PageSize
condition := map[string]interface{}{
"executorId": param.UserId,
"companyId": param.CompanyId,
"limit": limit,
}
if offset > 0 {
condition["offset"] = offset
}
cnt, assessTaskList, err := staffAssessTaskRepo.Find(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询周期"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
listData := make([]adapter.SearchAssessMeResp, 0, len(assessTaskList))
var temp adapter.SearchAssessMeResp
for _, v := range assessTaskList {
temp = adapter.SearchAssessMeResp{
AssessTaskId: v.Id,
BeginTime: v.BeginTime.Format("2006-01-02 15:04:05"),
EndTime: v.EndTime.Format("2006-01-02 15:04:05"),
CycleId: v.CycleId,
CycleName: v.CycleName,
EvaluationProjectId: v.EvaluationProjectId,
EvaluationProjectName: v.EvaluationProjectName,
}
listData = append(listData, temp)
}
return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
}
// 获取项目评估进度描述
func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery) (*adapter.AssessTaskDescResp, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 获取评估任务
staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取个人参与的评估流程
staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskData, err := staffAssessTaskRepo.FindOne(map[string]interface{}{
"id": param.AssessTaskId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "评估任务不存在,"+err.Error())
}
//返回的数据结果
result := adapter.AssessTaskDescResp{
AssessTaskId: assessTaskData.Id,
EvaluationProjectId: assessTaskData.EvaluationProjectId,
EvaluationProjectName: assessTaskData.EvaluationProjectName,
CycleName: assessTaskData.CycleName,
BeginTime: assessTaskData.BeginTime.Local().Format("2006-01-02 15:04-05"),
EndTime: assessTaskData.EndTime.Local().Format("2006-01-02 15:04-05"),
StepList: []adapter.AssessTaskStep{},
}
for _, v := range assessTaskData.StepList {
stepItem := adapter.AssessTaskStep{
SortBy: v.SortBy,
LinkNodeName: v.LinkNodeName,
BeginTime: v.BeginTime.Local().Format("2006-01-02 15:04:05"),
EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"),
LinkNodeType: v.LinkNodeType,
Desc: fmt.Sprintf("截止日期:%s", v.EndTime.Local().Format("2006-01-02 15:04:05")),
Status: "",
}
switch v.LinkNodeType {
case domain.LinkNodeSelfAssessment:
//个人自评完成情况
_, assessSelfData, err := staffAssessRepo.Find(map[string]interface{}{
"staffAssessTaskId": assessTaskData.Id,
"executorId": param.UserId,
"typesList": []string{string(domain.AssessSelf)},
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
if len(assessSelfData) > 0 {
stepItem.Status = string(assessSelfData[0].Status)
}
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
case domain.LinkNodeAllInvite:
//邀请别人评估自己
_, assessInviteData, err := staffAssessRepo.Find(map[string]interface{}{
"staffAssessTaskId": assessTaskData.Id,
"targetUserId": param.UserId,
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
"limit": 5,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
//待邀请人数,为5人减去已邀请的人数。若邀请人数已等于或大于5人,则只显示截止日期即可
if len(assessInviteData) > 5 {
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
stepItem.Status = string(domain.StaffAssessCompleted)
} else {
stepItem.Desc = fmt.Sprintf("截止日期:%s 待邀请%d人", stepItem.EndTime, 5-len(assessInviteData))
stepItem.Status = string(domain.StaffAssessUncompleted)
}
case domain.LinkNodeAllAssessment:
//我评估别人,被邀请评估
_, assessInviteList, err := staffAssessRepo.Find(map[string]interface{}{
"staffAssessTaskId": assessTaskData.Id,
"executorId": param.UserId,
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
if len(assessInviteList) > 0 {
stepItem.Status = string(domain.StaffAssessCompleted)
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
for _, v := range assessInviteList {
if v.Status == domain.StaffAssessUncompleted {
stepItem.Status = string(domain.StaffAssessUncompleted)
break
}
}
}
case domain.LinkNodeSuperiorAssessment:
//我评估别人,上级评估
_, assessSupperList, err := staffAssessRepo.Find(map[string]interface{}{
"staffAssessTaskId": assessTaskData.Id,
"executorId": param.UserId,
"typesList": []string{string(domain.AssessSuper)},
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
if len(assessSupperList) > 0 {
stepItem.Status = string(domain.StaffAssessCompleted)
stepItem.Desc = fmt.Sprintf("截止日期:%s", stepItem.EndTime)
uncompletedNum := 0
for _, v := range assessSupperList {
if v.Status == domain.StaffAssessUncompleted {
uncompletedNum += 1
}
}
if uncompletedNum > 0 {
stepItem.Desc = fmt.Sprintf("截止日期:%s 待评估%d人", stepItem.EndTime, uncompletedNum)
}
}
}
result.StepList = append(result.StepList, stepItem)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return &result, nil
}
// 获取个人的自评反馈历史记录列表
func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) (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()
}()
//获取个人参与的评估流程
staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var limit int = 20
var offset int = 0
if param.PageSize > 0 {
limit = param.PageSize
}
offset = (param.PageNumber - 1) * param.PageSize
condition := map[string]interface{}{
"executorId": param.UserId,
"companyId": param.CompanyId,
"typesList": []string{string(domain.AssessSelf)},
"limit": limit,
"status": string(domain.StaffAssessCompleted),
}
if offset > 0 {
condition["offset"] = offset
}
//获取历史列表
cnt, assessList, err := staffAssessRepo.Find(condition)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取评估任务列表,"+err.Error())
}
//获取公司数据
companyRep := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
companyData, err := companyRep.FindOne(map[string]interface{}{
"id": param.CompanyId,
})
if err != nil {
log.Logger.Error("获取公司信息," + err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取公司信息,"+err.Error())
}
//获取用户数据
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
userData, err := userRepo.FindOne(map[string]interface{}{
"id": param.UserId,
})
if err != nil {
log.Logger.Error("获取用户信息," + err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取用户信息,"+err.Error())
}
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var supperUserList []*domain.User
if len(userData.DepartmentId) > 0 {
_, departmentList, err := departmentRepo.Find(map[string]interface{}{
"ids": userData.DepartmentId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取部门信息,"+err.Error())
}
var chargeUserIds []int64
for _, v := range departmentList {
chargeUserIds = append(chargeUserIds, v.ChargeUserIds...)
}
if len(chargeUserIds) > 0 {
_, supperUserList, err = userRepo.Find(map[string]interface{}{
"ids": chargeUserIds,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取员工上级信息,"+err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
listData := make([]adapter.AssessSelfList, 0, len(assessList))
var itemTemp adapter.AssessSelfList
for _, v := range assessList {
itemTemp = adapter.AssessSelfList{
AssessId: v.Id,
BeginTime: v.BeginTime.Local().Format("2006-01-02 15:04:05"),
EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"),
CycleId: v.CycleId,
CycleName: v.CycleName,
EvaluationProjectId: v.EvaluationProjectId,
EvaluationProjectName: v.EvaluationProjectName,
}
listData = append(listData, itemTemp)
}
userInfo := adapter.StaffInfo{
UserName: userData.Name,
CompanyName: companyData.Name,
SupperUserName: "",
DutyTime: userData.CreateAt.Local().Format("2006-01-02 15:04:05"),
}
for _, v := range supperUserList {
userInfo.SupperUserName = userInfo.SupperUserName + v.Name + ";"
}
result := tool_funs.SimpleWrapGridMap(int64(cnt), listData)
result["userInfo"] = userInfo
return result, nil
}
// 更具项目评估的配置,创建员工的评估任务
func (srv StaffAssessServeice) CreateStaffAssessTask(param *command.CreateStaffAssessTask) (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()
}()
taskBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "任务开始时间填写错误,"+param.BeginTime)
}
taskEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "任务结束时间填写错误,"+param.EndTime)
}
nowTime := time.Now()
//建立评估任务
assessTask := domain.StaffAssessTask{
Id: 0,
CompanyId: param.CompanyId,
EvaluationProjectId: param.EvaluationProjectId,
EvaluationProjectName: param.EvaluationProjectName,
CycleId: param.CycleId,
CycleName: param.CycleName,
BeginTime: taskBeginTime,
EndTime: taskEndTime,
StepList: []domain.AssessTaskStep{},
ExecutorId: nil,
CreatedAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
}
//填充评估环节
for _, v := range param.StepList {
stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)
}
stepEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.EndTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "评估环节结束时间填写错误,"+param.EndTime)
}
step := domain.AssessTaskStep{
SortBy: v.SortBy,
LinkNodeId: v.LinkNodeId,
LinkNodeName: v.LinkNodeName,
LinkNodeType: v.LinkNodeType,
BeginTime: stepBeginTime,
EndTime: stepEndTime,
}
assessTask.StepList = append(assessTask.StepList, step)
}
assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, err = assessTaskRepo.Save(&assessTask)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
}
assessList, err := srv.createStaffAssess(transactionContext, &assessTask)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
}
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
for i := range assessList {
_, err = assessRepo.Save(&assessList[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 map[string]interface{}{
"assessTaskId": assessTask.Id,
}, nil
}
// 添加自评节点任务
func (srv StaffAssessServeice) createStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) {
//评估的参与人
selfUserId := []int{}
userIdMap := map[int]struct{}{} //过滤重复的用户
for _, v := range param.ExecutorId {
if _, ok := userIdMap[v]; ok {
continue
}
selfUserId = append(selfUserId, v)
}
// 获取用户的信息
if len(selfUserId) == 0 {
return nil, application.ThrowError(application.ARG_ERROR, "未填写评估任务的执行人")
}
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取员工信息
_, userList, err := userRepo.Find(map[string]interface{}{
"ids": selfUserId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息"+err.Error())
}
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取用户的部门
userDepartmentMap := map[int64][]*domain.Department{}
for _, v := range userList {
_, departmemtList, err := departmentRepo.Find(map[string]interface{}{
"ids": v.DepartmentId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取员工的部门信息"+err.Error())
}
userDepartmentMap[v.Id] = departmemtList
}
assessList := []domain.StaffAssess{}
//数据样板
stepSelfTemp := domain.StaffAssess{
Id: 0,
CompanyId: param.CompanyId,
EvaluationProjectId: param.EvaluationProjectId,
EvaluationProjectName: param.EvaluationProjectName,
CycleId: param.CycleId,
CycleName: param.CycleName,
StaffAssessTaskId: param.Id,
// TargetUser: domain.StaffDesc{},
// TargetDepartment: nil,
// Executor: domain.StaffDesc{},
Types: domain.AssessSelf,
// LinkNodeId: v.LinkNodeId,
Status: domain.StaffAssessUncompleted,
// BeginTime: time.Time{},
// EndTime: time.Time{},
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
DeletedAt: nil,
}
for _, v := range param.StepList {
if v.LinkNodeType == domain.LinkNodeSelfAssessment {
//员工自评
stepSelfTemp.BeginTime = v.BeginTime
stepSelfTemp.EndTime = v.EndTime
stepSelfTemp.LinkNodeId = v.LinkNodeId
stepSelfTemp.LinkNodeName = v.LinkNodeName
assessListTemp := srv.createStaffAssessSelf(stepSelfTemp, userList, userDepartmentMap)
assessList = append(assessList, assessListTemp...)
}
if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {
// TODO
stepSelfTemp.BeginTime = v.BeginTime
stepSelfTemp.EndTime = v.EndTime
stepSelfTemp.LinkNodeId = v.LinkNodeId
stepSelfTemp.LinkNodeName = v.LinkNodeName
assessListTemp, err := srv.createStaffAssessSupper(transactionContext, stepSelfTemp, userList, userDepartmentMap)
if err != nil {
return nil, err
}
assessList = append(assessList, assessListTemp...)
}
}
return assessList, nil
}
// 构建员工自评
func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAssess,
userList []*domain.User, userDepartmentMap map[int64][]*domain.Department) []domain.StaffAssess {
result := []domain.StaffAssess{}
for _, usr := range userList {
assessTemp.TargetUser = domain.StaffDesc{
UserId: int(usr.Id),
Account: usr.Account,
UserName: usr.Account,
}
assessTemp.Executor = domain.StaffDesc{
UserId: int(usr.Id),
Account: usr.Account,
UserName: usr.Account,
}
if depList, ok := userDepartmentMap[usr.Id]; ok {
for _, dep := range depList {
assessTemp.TargetDepartment = append(assessTemp.TargetDepartment, domain.StaffDepartment{
DepartmentId: int(dep.Id),
DepartmentName: dep.Name,
})
}
}
result = append(result, assessTemp)
}
return result
}
// 构建员工上级评估
func (srv StaffAssessServeice) createStaffAssessSupper(
transactionContext application.TransactionContext,
assessTemp domain.StaffAssess,
userList []*domain.User, userDepartmentMap map[int64][]*domain.Department,
) ([]domain.StaffAssess, error) {
// 获取员工的上级用户
return nil, nil
}
// 获取某个员工360邀请的人员
func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteUserQuery) (*adapter.AssessInviteUserResp, 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()
}()
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskReps := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskData, err := assessTaskReps.FindOne(map[string]interface{}{
"id": param.AssessTaskId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取评估任务"+err.Error())
}
_, assessList, err := assessReps.Find(map[string]interface{}{
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
"staffAssessTaskId": param.AssessTaskId,
"targetUserId": param.UsrId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取个人评估任务"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := adapter.AssessInviteUserResp{
AssessTaskId: assessTaskData.Id,
}
for _, v := range assessTaskData.StepList {
if v.LinkNodeType != domain.LinkNodeAllInvite {
continue
}
result.LinkNodeId = v.LinkNodeId
result.LinkNodeName = v.LinkNodeName
result.BeginTime = v.BeginTime.Local().Format("2006-01-02 15:04:05")
result.EndTime = v.EndTime.Local().Format("2006-01-02 15:04:05")
break
}
for _, v := range assessList {
if v.Types == domain.AssessInviteDiffSuper {
result.InviteDiffSuper = append(result.InviteDiffSuper, v.Executor)
}
if v.Types == domain.AssessInviteSameSuper {
result.InviteSameSuper = append(result.InviteDiffSuper, v.Executor)
}
}
return &result, nil
}
// 获取某个员工360邀请的人员
func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInvite) (*adapter.AssessInviteUserResp, error) {
inviteSameSuperId := []int{}
InviteDiffSuperId := []int{}
for _, v := range param.InviteDiffSuper {
id, err := strconv.Atoi(v)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "用户填写错误")
}
InviteDiffSuperId = append(InviteDiffSuperId, id)
}
for _, v := range param.InviteSameSuper {
id, err := strconv.Atoi(v)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "用户填写错误")
}
inviteSameSuperId = append(inviteSameSuperId, id)
}
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()
}()
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskReps := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskData, err := assessTaskReps.FindOne(map[string]interface{}{
"id": param.AssessTaskId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取评估任务"+err.Error())
}
targetUser, err := userRepo.FindOne(map[string]interface{}{
"id": param.TargetUserId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取被评估员工"+err.Error())
}
//被评估人的部门
var targetUserDepartment []domain.StaffDepartment
if len(targetUser.DepartmentId) > 0 {
_, departmentList, err := departmentRepo.Find(map[string]interface{}{
"ids": targetUser.DepartmentId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取部门信息"+err.Error())
}
for _, v := range departmentList {
targetUserDepartment = append(targetUserDepartment, domain.StaffDepartment{
DepartmentId: int(v.Id),
DepartmentName: v.Name,
})
}
}
//邀请的相同上级的员工
var inviteSameSuper []domain.StaffDesc
if len(inviteSameSuperId) > 0 {
_, userList, err := userRepo.Find(map[string]interface{}{
"ids": inviteSameSuperId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取用户信息"+err.Error())
}
for _, v := range userList {
inviteSameSuper = append(inviteSameSuper, domain.StaffDesc{
UserId: int(v.Id),
UserName: v.Name,
Account: v.Account,
})
}
}
//邀请的不同上级的员工
var inviteDiffSuper []domain.StaffDesc
if len(InviteDiffSuperId) > 0 {
_, userList, err := userRepo.Find(map[string]interface{}{
"ids": InviteDiffSuperId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取用户信息"+err.Error())
}
for _, v := range userList {
inviteDiffSuper = append(inviteDiffSuper, domain.StaffDesc{
UserId: int(v.Id),
UserName: v.Name,
Account: v.Account,
})
}
}
_ = assessReps
_ = inviteSameSuper
_ = inviteDiffSuper
_ = targetUserDepartment
// _, assessList, err := assessReps.Find(map[string]interface{}{
// "typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
// "staffAssessTaskId": param.AssessTaskId,
// "targetUserId": param.TargetUserId,
// })
// if err != nil {
// return nil, application.ThrowError(application.ARG_ERROR, "获取个人评估任务"+err.Error())
// }
// TODO
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := adapter.AssessInviteUserResp{
AssessTaskId: assessTaskData.Id,
}
// for _, v := range assessTaskData.StepList {
// if v.LinkNodeType != domain.LinkNodeAllInvite {
// continue
// }
// result.LinkNodeId = v.LinkNodeId
// result.LinkNodeName = v.LinkNodeName
// result.BeginTime = v.BeginTime.Local().Format("2006-01-02 15:04:05")
// result.EndTime = v.EndTime.Local().Format("2006-01-02 15:04:05")
// break
// }
// for _, v := range assessList {
// if v.Types == domain.AssessInviteDiffSuper {
// result.InviteDiffSuper = append(result.InviteDiffSuper, v.Executor)
// }
// if v.Types == domain.AssessInviteSameSuper {
// result.InviteSameSuper = append(result.InviteDiffSuper, v.Executor)
// }
// }
return &result, nil
}
// 获取员工自评的评估内容详情
func (srv StaffAssessServeice) GetAssessSelfInfo(param *query.AssessInfoQuery) (*adapter.AssessInfoResp, 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()
}()
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取员工的评估
_, assessList, err := assessReps.Find(map[string]interface{}{
"companyId": param.CompanyId,
"staffAssessTaskId": param.AssessTaskId,
"targetUserId": param.TargetUserId,
"typesList": []string{string(domain.AssessSelf)},
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
}
if len(assessList) == 0 {
return &adapter.AssessInfoResp{}, nil
}
assessData := assessList[0]
projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
projectData, err := projectRepo.FindOne(map[string]interface{}{
"id": assessData.EvaluationProjectId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目评估配置"+err.Error())
}
if projectData.Template == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未获取到项目评估配置模板")
}
var selfLinkNode *domain.LinkNode
for _, v := range projectData.Template.LinkNodes {
if v.Type == domain.LinkNodeSelfAssessment {
selfLinkNode = v
break
}
}
if selfLinkNode == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未获取到项目评估自评配置")
}
//获取员工评估的填写内容
// assessContentReps := factory.CreateStaffAssessContentRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// _, assessContentList, err := assessContentReps.Find(map[string]interface{}{
// "staffAssessId": assessData.Id,
// })
// 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())
}
result := adapter.AssessInfoResp{
CycleId: assessData.CycleId,
CycleName: assessData.CycleName,
EvaluationProjectId: assessData.EvaluationProjectId,
EvaluationProjectName: assessData.EvaluationProjectName,
BeginTime: assessData.BeginTime.Local().Format("2006-01-02 15:04:05"),
EndTime: assessData.EndTime.Local().Format("2006-01-02 15:04:05"),
Status: string(assessData.Status),
TargetUserId: assessData.TargetUser.UserId,
TargetUserName: assessData.TargetUser.UserName,
AssessContent: nil,
}
assessContent := make([]adapter.AssessContent, 0)
for _, v := range selfLinkNode.NodeContents {
assessContent = append(assessContent, adapter.AssessContent{
Category: v.Category,
Name: v.Name,
PromptTitle: v.PromptTitle,
PromptText: v.PromptText,
EntryItems: v.EntryItems,
})
}
result.AssessContent = assessContent
return &result, nil
}
... ...
... ... @@ -21,20 +21,21 @@ const (
StaffAssessCompleted StaffAssessStatus = "completed" //已完成
)
// 记录用户需要的评估项
// 记录用户需要的评估项
type StaffAssess struct {
Id int `json:"id"` //id
CompanyId int `json:"companyId"` //公司id
EvaluationProjectId int `json:"evaluationProjectId"` //对应的项目id
EvaluationProjectName string `json:"evaluationProjectName"` //对应的项目名称
CycleId int64 `json:"cycleId"` //对应的周期id
CycleName int64 `json:"cycleName"` //对应的周期名称
CycleName string `json:"cycleName"` //对应的周期名称
StaffAssessTaskId int `json:"staffAssessTaskId"` //执行评估的任务id
TargetUser StaffDesc `json:"targetUser"` //被评估的目标用户
TargetDepartment []StaffDepartment `json:"targetDepartment"` //被评估的目标用户所在的部门
Executor StaffDesc `json:"executor"` //填写评估的用户
Types StaffAssessType `json:"types"` //填写评估对应的类型
LinkNodeId int `json:"linkNodeId"` //评估环节对应的id,用于调取评估模板
LinkNodeName string `json:"linkNodeName"` //评估环节对应的id,用于调取评估模板
Status StaffAssessStatus `json:"status"` //评估的填写状态
BeginTime time.Time `json:"beginTime"` //开始时间
EndTime time.Time `json:"endTime"` //截止时间
... ...
... ... @@ -17,6 +17,11 @@ type StaffAssessContent struct {
//TODO
}
type AssessContemtRemark struct {
Title string `json:"title"` //comment:"填写标题"
RemarkText string `json:"hintText"` // comment:"填写文本内容"
}
type StaffAssessContentRepository interface {
Save(param *StaffAssessContent) (*StaffAssessContent, error)
Remove(id int) error
... ...
... ... @@ -26,17 +26,20 @@ type StaffAssessTask struct {
BeginTime time.Time `json:"beginTime"` //绩效考核开始时间
EndTime time.Time `json:"endTime"` //绩效考核截止时间
StepList []AssessTaskStep `json:"steps"` //考评的流程
ExecutorId []int `json:"executorId"` //参与此次考评的人
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
DeletedAt time.Time `json:"deletedAt"` //数据删除时间
DeletedAt *time.Time `json:"deletedAt"` //数据删除时间
}
//考评的流程
type AssessTaskStep struct {
SortBy int `json:"sortBy"` //排序
LinkNodeId int `json:"linkNodeId"` //考评的流程id
LinkNodeName string `json:"linkNodeName"` //流程名称
LinkNodeType int `json:"linkNodeType"` //流程类型 同evaluation_template.go->LinkNode.Type
SortBy int `json:"sortBy"` //排序
LinkNodeId int `json:"linkNodeId"` //考评的流程id
LinkNodeName string `json:"linkNodeName"` //流程名称
LinkNodeType int `json:"linkNodeType"` //流程类型 同evaluation_template.go->LinkNode.Type
BeginTime time.Time `json:"beginTime"` //绩效考核开始时间
EndTime time.Time `json:"endTime"` //绩效考核截止时间
}
type StaffAssessTaskRepository interface {
... ...
... ... @@ -2,6 +2,7 @@ package pg
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"github.com/linmadan/egglib-go/persistent/pg/comment"
... ... @@ -39,6 +40,8 @@ func init() {
&models.EvaluationCycle{},
&models.EvaluationCycleTemplate{},
&models.EvaluationProject{},
&models.StaffAssess{},
&models.StaffAssessTask{},
}
for _, model := range tables {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
... ...
... ... @@ -8,20 +8,24 @@ import (
// 记录用户需要的评估项
type StaffAssess struct {
tableName struct{} `pg:"staff_assess" comment:"记录用户需要的评估项"`
Id int `pg:",pk"` //id
CompanyId int `comment:"公司id"` //公司id
EvaluationProjectId int `comment:"对应的项目id"` //对应的项目id
CycleId int64 `comment:"对应的周期id"` //对应的周期id
TargetUser domain.StaffDesc `comment:"被评估的目标用户"` //被评估的目标用户
TargetDepartment []domain.StaffDepartment `comment:"被评估的用户所在的部门"` //被评估的用户所在的部门
Executor domain.StaffDesc `comment:"填写评估的用户"` //填写评估的用户
Types string `comment:"填写评估对应的类型"` //填写评估对应的类型
LinkNodeId int `comment:"评估环节id"`
Status string `comment:"评估的填写状态"` //评估的填写状态
BeginTime time.Time `comment:"开始时间"` //开始时间
EndTime time.Time `comment:"截止时间"` //截止时间
CreatedAt time.Time `comment:"数据创建时间"` //数据创建时间
UpdatedAt time.Time `comment:"数据更新时间"` //数据更新时间
DeletedAt *time.Time `comment:"数据删除时间"` //数据删除时间
tableName struct{} `pg:"staff_assess" comment:"记录用户需要的评估项"`
Id int `pg:",pk"` //id
CompanyId int `comment:"公司id"` //公司id
EvaluationProjectId int `comment:"对应的项目id"` //对应的项目id
EvaluationProjectName string
CycleId int64 `comment:"对应的周期id"` //对应的周期id
CycleName string
StaffAssessTaskId int
TargetUser domain.StaffDesc `comment:"被评估的目标用户"` //被评估的目标用户
TargetDepartment []domain.StaffDepartment `comment:"被评估的用户所在的部门"` //被评估的用户所在的部门
Executor domain.StaffDesc `comment:"填写评估的用户"` //填写评估的用户
Types string `comment:"填写评估对应的类型"` //填写评估对应的类型
LinkNodeId int `comment:"评估环节id"`
LinkNodeName string
Status string `comment:"评估的填写状态"` //评估的填写状态
BeginTime time.Time `comment:"开始时间"` //开始时间
EndTime time.Time `comment:"截止时间"` //截止时间
CreatedAt time.Time `comment:"数据创建时间"` //数据创建时间
UpdatedAt time.Time `comment:"数据更新时间"` //数据更新时间
DeletedAt *time.Time `comment:"数据删除时间"` //数据删除时间
}
... ...
package models
import "time"
import (
"time"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// 执行评估的任务列表
type StaffAssessTask struct {
tableName struct{} `pg:"staff_assess_task" comment:"执行评估的任务列表"`
Id int `pg:",pk"`
CompanyId int `` //公司id
EvaluationProjectId int `` //项目id
EvaluationProjectName string `` //项目名称
CycleId int64 //对应的周期id
CycleName string //对应周期的名称
BeginTime time.Time //开始时间
EndTime time.Time //截止时间
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
DeletedAt time.Time //数据删除时间
tableName struct{} `pg:"staff_assess_task" comment:"执行评估的任务列表"`
Id int `pg:",pk"`
CompanyId int `` //公司id
EvaluationProjectId int `` //项目id
EvaluationProjectName string `` //项目名称
CycleId int64 //对应的周期id
CycleName string //对应周期的名称
ExecutorId []int //参与考评的人
StepList []domain.AssessTaskStep `` //考评的流程
BeginTime time.Time //开始时间
EndTime time.Time //截止时间
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
DeletedAt *time.Time //数据删除时间
}
... ...
... ... @@ -91,9 +91,8 @@ func (repo *DepartmentRepository) FindOne(queryOptions map[string]interface{}) (
func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Department, error) {
tx := repo.transactionContext.PgTx
var dparmentModel []models.Department
query := tx.Model(&dparmentModel).
Limit(20)
dparmentModel := []models.Department{}
query := tx.Model(&dparmentModel).Where("delete_at isnull")
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
... ...
... ... @@ -3,13 +3,14 @@ package repository
import (
"errors"
"fmt"
"time"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
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"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"time"
)
type EvaluationCycleRepository struct {
... ... @@ -133,6 +134,16 @@ func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{})
query.Offset(v)
}
if v, ok := queryOptions["timeStart"]; ok {
t := v.(time.Time)
query.Where("time_start<=?", t)
}
if v, ok := queryOptions["timeEnd"]; ok {
t := v.(time.Time)
query.Where("time_end>=?", t)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
... ... @@ -17,7 +17,7 @@ type StaffAssessContentRepository struct {
var _ domain.StaffAssessContentRepository = (*StaffAssessContentRepository)(nil)
func NewStaffEvaluationRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessContentRepository {
func NewStaffAssessContentRepository(transactionContext *pgTransaction.TransactionContext) *StaffAssessContentRepository {
return &StaffAssessContentRepository{transactionContext: transactionContext}
}
... ... @@ -89,7 +89,9 @@ func (repo *StaffAssessContentRepository) Find(queryOptions map[string]interface
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
if v, ok := queryOptions["staffAssessId"]; ok {
query.Where("staff_assess_id=?", v)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
... ... @@ -23,39 +23,49 @@ func NewStaffAssessRepository(transactionContext *pgTransaction.TransactionConte
func (repo *StaffAssessRepository) TransformToDomain(d *models.StaffAssess) *domain.StaffAssess {
return &domain.StaffAssess{
Id: d.Id,
CompanyId: d.CompanyId,
EvaluationProjectId: d.EvaluationProjectId,
CycleId: d.CycleId,
TargetUser: d.TargetUser,
TargetDepartment: d.TargetDepartment,
Executor: d.Executor,
Types: domain.StaffAssessType(d.Types),
Status: domain.StaffAssessStatus(d.Status),
BeginTime: d.BeginTime,
EndTime: d.EndTime,
CreatedAt: d.EndTime,
UpdatedAt: d.CreatedAt,
DeletedAt: d.DeletedAt,
Id: d.Id,
CompanyId: d.CompanyId,
EvaluationProjectId: d.EvaluationProjectId,
EvaluationProjectName: d.EvaluationProjectName,
CycleId: d.CycleId,
CycleName: d.CycleName,
StaffAssessTaskId: d.StaffAssessTaskId,
TargetUser: d.TargetUser,
TargetDepartment: d.TargetDepartment,
Executor: d.Executor,
Types: domain.StaffAssessType(d.Types),
LinkNodeId: d.LinkNodeId,
LinkNodeName: d.LinkNodeName,
Status: domain.StaffAssessStatus(d.Status),
BeginTime: d.BeginTime,
EndTime: d.EndTime,
CreatedAt: d.EndTime,
UpdatedAt: d.CreatedAt,
DeletedAt: d.DeletedAt,
}
}
func (repo *StaffAssessRepository) Save(d *domain.StaffAssess) (*domain.StaffAssess, error) {
saveModel := models.StaffAssess{
Id: d.Id,
CompanyId: d.CompanyId,
EvaluationProjectId: d.EvaluationProjectId,
CycleId: d.CycleId,
TargetUser: d.TargetUser,
TargetDepartment: d.TargetDepartment,
Executor: d.Executor,
Types: string(d.Types),
Status: string(d.Status),
BeginTime: d.BeginTime,
EndTime: d.EndTime,
CreatedAt: d.EndTime,
UpdatedAt: d.CreatedAt,
DeletedAt: d.DeletedAt,
Id: d.Id,
CompanyId: d.CompanyId,
EvaluationProjectId: d.EvaluationProjectId,
EvaluationProjectName: d.EvaluationProjectName,
CycleId: d.CycleId,
CycleName: d.CycleName,
StaffAssessTaskId: d.StaffAssessTaskId,
TargetUser: d.TargetUser,
TargetDepartment: d.TargetDepartment,
Executor: d.Executor,
Types: string(d.Types),
LinkNodeId: d.LinkNodeId,
LinkNodeName: d.LinkNodeName,
Status: string(d.Status),
BeginTime: d.BeginTime,
EndTime: d.EndTime,
CreatedAt: d.EndTime,
UpdatedAt: d.CreatedAt,
DeletedAt: d.DeletedAt,
}
tx := repo.transactionContext.PgTx
var err error
... ... @@ -107,7 +117,7 @@ func (repo *StaffAssessRepository) Find(queryOptions map[string]interface{}) (in
tx := repo.transactionContext.PgTx
var m []*models.StaffAssess
query := tx.Model(&m).
Where("deleted_at isnull").Limit(20)
Where("deleted_at isnull")
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
}
... ... @@ -117,7 +127,26 @@ func (repo *StaffAssessRepository) Find(queryOptions map[string]interface{}) (in
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
if v, ok := queryOptions["targetUserId"].(int); ok && v > 0 {
query.Where(`target_user->>'userId'='?'`, v)
}
if v, ok := queryOptions["executorId"].(int); ok && v > 0 {
query.Where(`executor->>'userId'='?'`, v)
}
if v, ok := queryOptions["cycleId"].(int64); ok && v > 0 {
query.Where(`cycle_id=?`, v)
}
if v, ok := queryOptions["staffAssessTaskId"]; ok {
query.Where(`staff_assess_task_id=?`, v)
}
if v, ok := queryOptions["typesList"].([]string); ok && len(v) > 0 {
query.Where("types in(?)", pg.Array(v))
}
if v, ok := queryOptions["status"].(string); ok && len(v) > 0 {
query.Where("status=?", v)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
... ... @@ -111,7 +111,9 @@ func (repo *StaffAssessTaskRepository) Find(queryOptions map[string]interface{})
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
if v, ok := queryOptions["executorId"].(int); ok && v > 0 {
query.Where(`executorId @>[?]`, v)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
... ... @@ -73,7 +73,7 @@ func (repo *UserRepository) Remove(userId []int64) error {
func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domain.User, error) {
tx := repo.transactionContext.PgTx
userModel := models.User{}
query := tx.Model(&userModel)
query := tx.Model(&userModel).Where("delete_at isnull")
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/web/beego"
"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/application/staff_assess/service"
)
type StaffAssessController struct {
beego.BaseController
}
// 获取我的绩效任务列表
func (c *StaffAssessController) SearchAssessTaskMe() {
srv := service.NewStaffAssessServeice()
paramReq := &query.SearchAssessMeQuery{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
//TODO 获取当前用户信息
data, err := srv.SearchAssessTaskMe(paramReq)
c.Response(data, err)
}
// 获取我的绩效任务各环节完成情况
func (c *StaffAssessController) AssessTaskMeDesc() {
srv := service.NewStaffAssessServeice()
paramReq := &query.AssessTaskDescQuery{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
//TODO 获取当前用户信息
data, err := srv.AssessTaskDesc(paramReq)
c.Response(data, err)
}
// 获取个人的自评反馈历史记录列表
func (c *StaffAssessController) AssessSelfMeList() {
srv := service.NewStaffAssessServeice()
paramReq := &query.AssessSelfListQuery{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
//TODO 获取当前用户信息
data, err := srv.AssessSelfList(paramReq)
c.Response(data, err)
}
// 更具项目评估的配置,创建员工的评估任务,(调试用)
func (c *StaffAssessController) CreateStaffAssessTask() {
srv := service.NewStaffAssessServeice()
paramReq := &command.CreateStaffAssessTask{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
//服务调用,实际由定时任务触发
data, err := srv.CreateStaffAssessTask(paramReq)
c.Response(data, err)
}
... ...