作者 tangxvhui

暂存

... ... @@ -196,3 +196,158 @@ func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAs
}
return &result, nil
}
type excelTableHeader struct {
Level1 string
Level2 string
Level3 string
Level4 string
}
func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCycleDay) ([]byte, 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()
}()
roleRepo := factory.CreateRoleRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, roleList, err := roleRepo.Find(map[string]interface{}{
"type": domain.RoleTypeSystem,
"companyId": param.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
}
_, userRoleList, err := roleUserRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"userId": param.OperaterId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
}
hrbp := -1
for _, v := range userRoleList {
for _, v2 := range roleList {
if v.RoleId == v2.Id {
hrbp = 1
break
}
}
if hrbp == 1 {
break
}
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
contentList, err := assessDao.ExportDataUserAssess(dao.SearchConditin1{
CompanyId: param.CompanyId,
CycleId: param.CycleId,
BeginDay: param.BeginDay,
TargetUserName: param.TargetUserName,
Limit: 5000,
Offset: 0,
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())
}
//处理查询到的数据
//汇总 Excel表格的表头描述
level1 := []string{} //分类
level3 := map[string][]string{} // key=分类+得分项类型 val=名称
level4 := map[string]string{} //key=分类+名称 val=评估标准
for _, v := range contentList {
level1Item := ""
for _, v1 := range level1 {
if v.Category == v1 {
level1Item = v1
}
}
if len(level1Item) == 0 {
level1 = append(level1, v.Category)
}
if v.Weight == 0 {
level3Key := v.Category + "-加分项"
if _, ok := level3[level3Key]; !ok {
level3[level3Key] = []string{}
}
level3Item := ""
for _, v3 := range level3[level3Key] {
if v3 == v.ContentName {
level3Item = v.ContentName
}
}
if len(level3Item) == 0 {
level3[level3Key] = append(level3[level3Key], v.ContentName)
}
}
if v.Weight > 0 {
level3Key := v.Category + "-得分项"
if _, ok := level3[level3Key]; !ok {
level3[level3Key] = []string{}
}
level3Item := ""
for _, v3 := range level3[level3Key] {
if v3 == v.ContentName {
level3Item = v.ContentName
}
}
if len(level3Item) == 0 {
level3[level3Key] = append(level3[level3Key], v.ContentName)
}
}
level4Key := v.Category + "+" + v.ContentName
if _, ok := level4[level4Key]; !ok {
level4[level4Key] = v.PromptText
}
}
//汇总表头
headerList := []excelTableHeader{}
for _, v := range level1 {
item := excelTableHeader{
Level1: v,
}
level3Key := v + "-加分项"
if _, ok := level3[level3Key]; ok {
for _, v2 := range level3[level3Key] {
item.Level2 = "加分项"
item.Level3 = v2
level4Key := v + "+" + v2
item.Level4 = level4[level4Key]
headerList = append(headerList, item)
}
}
level3Key = v + "-得分项"
if _, ok := level3[level3Key]; ok {
for _, v2 := range level3[level3Key] {
item.Level2 = "得分项"
item.Level3 = v2
level4Key := v + "+" + v2
item.Level4 = level4[level4Key]
headerList = append(headerList, item)
}
}
}
//
// tab
return nil, nil
}
... ...
... ... @@ -178,7 +178,7 @@ type SearchConditin1 struct {
Hrbp int //
}
//根据周期的id和日期获取员工填写的评估内容
//项目管理-成员列表 根据周期的id和日期获取员工填写的评估内容
//companyId int 公司id
//cycleId int, 评估周期id
//userId int, 用户id,谁要查看数据
... ... @@ -218,7 +218,7 @@ func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserA
return result, err
}
//根据周期的id和日期获取员工填写的评估内容,数量统计
//项目管理-成员列表 根据周期的id和日期获取员工填写的评估内容,数量统计
//companyId int 公司id
//cycleId int, 评估周期id
//userId int, 用户id,谁要查看数据
... ... @@ -322,3 +322,50 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
sqlstr = fmt.Sprintf(sqlstr, params...)
return sqlstr
}
type ExportData1 struct {
TargetUserId string //被评估人的id
TargetUserName string //被评估人的名称
BeginDay string //评估的日期
EvaluationProjectId string //项目id
Value string //评估填写的值
SortBy int //评估项顺序
Category string //评估项分类
ContentName string //评估项名称
Weight int //权重
PromptText string //评估标准
Remark []domain.AssessContemtRemark
}
//项目管理-成员列表 导出数据
func (d *StaffAssessDao) ExportDataUserAssess(param SearchConditin1) ([]ExportData1, error) {
if param.Offset < 0 {
param.Offset = 0
}
if param.Limit < 0 {
param.Limit = 5000
}
sqlStr := ` 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,
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 t_staff_assess_1
left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
`
condition := []interface{}{}
if len(param.TargetUserName) > 0 {
sqlStr += ` where t_staff_assess_1.target_user_name like ? `
condition = append(condition, param.TargetUserName)
}
//加入排序
sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
//获取前置sql语句
sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset)
sqlStr = sqlStr0 + sqlStr
tx := d.transactionContext.PgTx
var result []ExportData1
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
... ...