作者 tangxvhui

暂存

@@ -196,3 +196,158 @@ func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAs @@ -196,3 +196,158 @@ func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAs
196 } 196 }
197 return &result, nil 197 return &result, nil
198 } 198 }
  199 +
  200 +type excelTableHeader struct {
  201 + Level1 string
  202 + Level2 string
  203 + Level3 string
  204 + Level4 string
  205 +}
  206 +
  207 +func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCycleDay) ([]byte, error) {
  208 + transactionContext, err := factory.CreateTransactionContext(nil)
  209 + if err != nil {
  210 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  211 + }
  212 + if err := transactionContext.StartTransaction(); err != nil {
  213 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  214 + }
  215 + defer func() {
  216 + _ = transactionContext.RollbackTransaction()
  217 + }()
  218 +
  219 + roleRepo := factory.CreateRoleRepository(map[string]interface{}{
  220 + "transactionContext": transactionContext,
  221 + })
  222 + roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{
  223 + "transactionContext": transactionContext,
  224 + })
  225 + _, roleList, err := roleRepo.Find(map[string]interface{}{
  226 + "type": domain.RoleTypeSystem,
  227 + "companyId": param.CompanyId,
  228 + })
  229 + if err != nil {
  230 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
  231 + }
  232 + _, userRoleList, err := roleUserRepo.Find(map[string]interface{}{
  233 + "companyId": param.CompanyId,
  234 + "userId": param.OperaterId,
  235 + })
  236 + if err != nil {
  237 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
  238 + }
  239 + hrbp := -1
  240 + for _, v := range userRoleList {
  241 + for _, v2 := range roleList {
  242 + if v.RoleId == v2.Id {
  243 + hrbp = 1
  244 + break
  245 + }
  246 + }
  247 + if hrbp == 1 {
  248 + break
  249 + }
  250 + }
  251 + assessDao := dao.NewStaffAssessDao(map[string]interface{}{
  252 + "transactionContext": transactionContext,
  253 + })
  254 + contentList, err := assessDao.ExportDataUserAssess(dao.SearchConditin1{
  255 + CompanyId: param.CompanyId,
  256 + CycleId: param.CycleId,
  257 + BeginDay: param.BeginDay,
  258 + TargetUserName: param.TargetUserName,
  259 + Limit: 5000,
  260 + Offset: 0,
  261 + OperaterId: param.OperaterId,
  262 + Hrbp: hrbp,
  263 + })
  264 + if err != nil {
  265 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取数据列表"+err.Error())
  266 + }
  267 +
  268 + if err := transactionContext.CommitTransaction(); err != nil {
  269 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  270 + }
  271 +
  272 + //处理查询到的数据
  273 + //汇总 Excel表格的表头描述
  274 + level1 := []string{} //分类
  275 + level3 := map[string][]string{} // key=分类+得分项类型 val=名称
  276 + level4 := map[string]string{} //key=分类+名称 val=评估标准
  277 + for _, v := range contentList {
  278 + level1Item := ""
  279 + for _, v1 := range level1 {
  280 + if v.Category == v1 {
  281 + level1Item = v1
  282 + }
  283 + }
  284 + if len(level1Item) == 0 {
  285 + level1 = append(level1, v.Category)
  286 + }
  287 + if v.Weight == 0 {
  288 + level3Key := v.Category + "-加分项"
  289 + if _, ok := level3[level3Key]; !ok {
  290 + level3[level3Key] = []string{}
  291 + }
  292 + level3Item := ""
  293 + for _, v3 := range level3[level3Key] {
  294 + if v3 == v.ContentName {
  295 + level3Item = v.ContentName
  296 + }
  297 + }
  298 + if len(level3Item) == 0 {
  299 + level3[level3Key] = append(level3[level3Key], v.ContentName)
  300 + }
  301 + }
  302 + if v.Weight > 0 {
  303 + level3Key := v.Category + "-得分项"
  304 + if _, ok := level3[level3Key]; !ok {
  305 + level3[level3Key] = []string{}
  306 + }
  307 + level3Item := ""
  308 + for _, v3 := range level3[level3Key] {
  309 + if v3 == v.ContentName {
  310 + level3Item = v.ContentName
  311 + }
  312 + }
  313 + if len(level3Item) == 0 {
  314 + level3[level3Key] = append(level3[level3Key], v.ContentName)
  315 + }
  316 + }
  317 +
  318 + level4Key := v.Category + "+" + v.ContentName
  319 + if _, ok := level4[level4Key]; !ok {
  320 + level4[level4Key] = v.PromptText
  321 + }
  322 + }
  323 + //汇总表头
  324 + headerList := []excelTableHeader{}
  325 + for _, v := range level1 {
  326 + item := excelTableHeader{
  327 + Level1: v,
  328 + }
  329 + level3Key := v + "-加分项"
  330 + if _, ok := level3[level3Key]; ok {
  331 + for _, v2 := range level3[level3Key] {
  332 + item.Level2 = "加分项"
  333 + item.Level3 = v2
  334 + level4Key := v + "+" + v2
  335 + item.Level4 = level4[level4Key]
  336 + headerList = append(headerList, item)
  337 + }
  338 + }
  339 + level3Key = v + "-得分项"
  340 + if _, ok := level3[level3Key]; ok {
  341 + for _, v2 := range level3[level3Key] {
  342 + item.Level2 = "得分项"
  343 + item.Level3 = v2
  344 + level4Key := v + "+" + v2
  345 + item.Level4 = level4[level4Key]
  346 + headerList = append(headerList, item)
  347 + }
  348 + }
  349 + }
  350 + //
  351 + // tab
  352 + return nil, nil
  353 +}
@@ -178,7 +178,7 @@ type SearchConditin1 struct { @@ -178,7 +178,7 @@ type SearchConditin1 struct {
178 Hrbp int // 178 Hrbp int //
179 } 179 }
180 180
181 -//根据周期的id和日期获取员工填写的评估内容 181 +//项目管理-成员列表 根据周期的id和日期获取员工填写的评估内容
182 //companyId int 公司id 182 //companyId int 公司id
183 //cycleId int, 评估周期id 183 //cycleId int, 评估周期id
184 //userId int, 用户id,谁要查看数据 184 //userId int, 用户id,谁要查看数据
@@ -218,7 +218,7 @@ func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserA @@ -218,7 +218,7 @@ func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserA
218 return result, err 218 return result, err
219 } 219 }
220 220
221 -//根据周期的id和日期获取员工填写的评估内容,数量统计 221 +//项目管理-成员列表 根据周期的id和日期获取员工填写的评估内容,数量统计
222 //companyId int 公司id 222 //companyId int 公司id
223 //cycleId int, 评估周期id 223 //cycleId int, 评估周期id
224 //userId int, 用户id,谁要查看数据 224 //userId int, 用户id,谁要查看数据
@@ -322,3 +322,50 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, @@ -322,3 +322,50 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
322 sqlstr = fmt.Sprintf(sqlstr, params...) 322 sqlstr = fmt.Sprintf(sqlstr, params...)
323 return sqlstr 323 return sqlstr
324 } 324 }
  325 +
  326 +type ExportData1 struct {
  327 + TargetUserId string //被评估人的id
  328 + TargetUserName string //被评估人的名称
  329 + BeginDay string //评估的日期
  330 + EvaluationProjectId string //项目id
  331 + Value string //评估填写的值
  332 + SortBy int //评估项顺序
  333 + Category string //评估项分类
  334 + ContentName string //评估项名称
  335 + Weight int //权重
  336 + PromptText string //评估标准
  337 + Remark []domain.AssessContemtRemark
  338 +}
  339 +
  340 +//项目管理-成员列表 导出数据
  341 +func (d *StaffAssessDao) ExportDataUserAssess(param SearchConditin1) ([]ExportData1, error) {
  342 + if param.Offset < 0 {
  343 + param.Offset = 0
  344 + }
  345 + if param.Limit < 0 {
  346 + param.Limit = 5000
  347 + }
  348 + sqlStr := ` select
  349 + t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
  350 + t_staff_assess_1.assess_id,
  351 + staff_assess_content.value ,staff_assess_content.sort_by ,
  352 + staff_assess_content.category ,staff_assess_content."name" as content_name ,
  353 + staff_assess_content.weight,staff_assess_content.prompt_text ,staff_assess_content.remark
  354 + from t_staff_assess_1
  355 + left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
  356 + `
  357 + condition := []interface{}{}
  358 + if len(param.TargetUserName) > 0 {
  359 + sqlStr += ` where t_staff_assess_1.target_user_name like ? `
  360 + condition = append(condition, param.TargetUserName)
  361 + }
  362 + //加入排序
  363 + sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
  364 + //获取前置sql语句
  365 + sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset)
  366 + sqlStr = sqlStr0 + sqlStr
  367 + tx := d.transactionContext.PgTx
  368 + var result []ExportData1
  369 + _, err := tx.Query(&result, sqlStr, condition...)
  370 + return result, err
  371 +}