作者 tangxvhui

处理excecl数据异常

... ... @@ -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++
... ...
... ... @@ -205,3 +205,58 @@ func (d *StaffAssessDao) SearchTargetUserCycleProject(companyId int, targetUserI
_, 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
}
... ...