作者 tangxvhui

更新查询

... ... @@ -582,30 +582,108 @@ func (srv *StaffAssessServeice) ExportUserAssess(param *query.ExportAssessConten
// 根据周期id和日期获取 员工填写评估内容;项目管理-成员列表
// 有过滤查看权限
// func (srv StaffAssessServeice) ListUserAssessContentCycleDayV2(param *query.ListAssessContentCycleDay) (*adapter.ListUserAssessContent, 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.OperaterId)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
func (srv StaffAssessServeice) ListUserAssessContentCycleDayV2(param *query.ListAssessContentCycleDay) (*adapter.ListUserAssessContent, 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.OperaterId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
// assessDao := dao.NewStaffAssessDao(map[string]interface{}{
// "transactionContext": transactionContext,
// })
limit := param.PageSize
offset := (param.PageNumber - 1) * limit
if offset < 0 {
offset = 0
}
// 总数----------
cnt, err := assessDao.CountUserSelfStaffAssess(dao.SearchConditin3{
CompanyId: param.CompanyId,
CycleId: param.CycleId,
BeginDay: param.BeginDay,
TargetUserName: param.TargetUserName,
OperaterId: param.OperaterId,
Hrbp: hrbp,
Status: "",
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计总数"+err.Error())
}
contentList, err := assessDao.SearchUserAssessContentV2(dao.SearchConditin3{
CompanyId: param.CompanyId,
CycleId: param.CycleId,
BeginDay: param.BeginDay,
TargetUserName: param.TargetUserName,
Limit: limit,
Offset: offset,
OperaterId: param.OperaterId,
Hrbp: hrbp,
})
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())
}
log.Logger.Debug(fmt.Sprintf("获取到的数据列表%d", len(contentList)))
//可变的表格列
changeableHeader := []adapter.ListTableHeader{
{Key: "targetUserName", Name: "姓名"}, //固定列
}
//过滤重复的列
headerMap := map[string]string{}
// 获取已经填报的内容
changeableRows := map[string]map[string]interface{}{}
tableSort := []string{} //确定列表行数据的顺序
for i, v := range contentList {
if _, ok := changeableRows[v.TargetUserId]; !ok {
changeableRows[v.TargetUserId] = map[string]interface{}{}
tableSort = append(tableSort, v.TargetUserId)
}
changeableRows[v.TargetUserId]["targetUserName"] = v.TargetUserName
changeableRows[v.TargetUserId]["targetUserId"] = v.TargetUserId
changeableRows[v.TargetUserId]["assessId"] = v.AssessId
changeableRows[v.TargetUserId]["cycleId"] = v.CycleId
changeableRows[v.TargetUserId]["beginDay"] = v.BeginDay
if v.ContentId > 0 {
name := fmt.Sprintf("%s-%s", v.Category, v.ContentName)
key := fmt.Sprintf("k%d", i)
if _, ok := headerMap[name]; !ok {
changeableHeader = append(changeableHeader, adapter.ListTableHeader{
Key: key, Name: name,
})
headerMap[name] = key
}
key = headerMap[name]
changeableRows[v.TargetUserId][key] = v.Value
}
}
list := []map[string]interface{}{}
for _, v := range tableSort {
for _, v2 := range changeableHeader {
if _, ok := changeableRows[v][v2.Key]; ok {
continue
}
changeableRows[v][v2.Key] = ""
}
list = append(list, changeableRows[v])
}
result := adapter.ListUserAssessContent{
TableHeader: changeableHeader,
Total: cnt,
List: list,
}
// limit := param.PageSize
// offset := (param.PageNumber - 1) * limit
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// return nil, nil
// }
return &result, nil
}
... ...
... ... @@ -330,7 +330,7 @@ type SearchConditin3 struct {
// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
// limit int, 分页条数
// offset int 分页偏移
func (d *StaffAssessDao) SearchUserSelfStaffAssess(param SearchConditin3) ([]UserSelfStaffAssess, error) {
func (d *StaffAssessDao) SearchUserAssessContentV2(param SearchConditin3) ([]UserAssessContent, error) {
withSql := d.catchProjectIdByPermission(param.CompanyId, param.CycleId, param.OperaterId, param.Hrbp)
sqlStr := `select
staff_assess.cycle_id ,
... ... @@ -363,9 +363,27 @@ func (d *StaffAssessDao) SearchUserSelfStaffAssess(param SearchConditin3) ([]Use
condition = append(condition, param.Limit, param.Offset)
sqlStr += ` order by convert_to(staff_assess.target_user ->>'userName','GBK') limit ? offset ? `
sqlStr2 := withSql + withSql
withSql2 := withSql + `,t_staff_assess_1 as( ` + sqlStr + ` )`
sqlStr2 := `select
t_staff_assess_1.target_user_id,
t_staff_assess_1.target_user_name,
t_staff_assess_1.begin_day,
t_staff_assess_1.assess_id,
t_staff_assess_1.cycle_id,
staff_assess_content.id as content_id,
staff_assess_content.value ,
evaluation_item_used.sort_by ,
evaluation_item_used.category ,
evaluation_item_used."name" as content_name ,
evaluation_item_used.weight,
staff_assess_content.level_value,
evaluation_item_used."rule"
from t_staff_assess_1
left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
where 1=1`
sqlStr2 = withSql2 + sqlStr2
tx := d.transactionContext.PgTx
var result []UserSelfStaffAssess
var result []UserAssessContent
_, err := tx.Query(&result, sqlStr2, condition...)
return result, err
}
... ...