作者 tangxvhui

日常保存

@@ -17,6 +17,7 @@ type ExportAssessContentCycleDay struct { @@ -17,6 +17,7 @@ type ExportAssessContentCycleDay struct {
17 OperaterId int `json:"operaterId"` 17 OperaterId int `json:"operaterId"`
18 CycleId int `json:"cycleId,string"` //周期id 18 CycleId int `json:"cycleId,string"` //周期id
19 BeginDay string `json:"beginDay"` //评估开始的时间 19 BeginDay string `json:"beginDay"` //评估开始的时间
  20 + BeginDayList []string `json:"beginDayList"` //评估开始的时间
20 TargetUserName string `json:"targetUserName"` 21 TargetUserName string `json:"targetUserName"`
21 TargetUserId []string `json:"targetUserId"` 22 TargetUserId []string `json:"targetUserId"`
22 ExportItems []struct { 23 ExportItems []struct {
@@ -7,3 +7,10 @@ type SummaryCommand struct { @@ -7,3 +7,10 @@ type SummaryCommand struct {
7 CompanyId int `cname:"公司ID" json:"companyId"` 7 CompanyId int `cname:"公司ID" json:"companyId"`
8 OperatorId int `cname:"操作人ID" json:"operatorId"` 8 OperatorId int `cname:"操作人ID" json:"operatorId"`
9 } 9 }
  10 +
  11 +type ExportUserAssess2Commad struct {
  12 + CycleId int `cname:"周期ID" json:"cycleId,string"`
  13 + CompanyId int `cname:"公司ID" json:"companyId"`
  14 + OperatorId int `cname:"操作人ID" json:"operatorId"`
  15 + ExportUserId []string `cname:"指定员工数据导出" json:"exportUserId"`
  16 +}
@@ -159,3 +159,64 @@ func (e *exportData) weightDesc(weight float64) string { @@ -159,3 +159,64 @@ func (e *exportData) weightDesc(weight float64) string {
159 func (e *exportData) userDayKey(userName string) string { 159 func (e *exportData) userDayKey(userName string) string {
160 return userName 160 return userName
161 } 161 }
  162 +
  163 +type exportData2 struct {
  164 + tableHeader HeaderLevel //数据表格对应表头
  165 + userIdMap map[string]string //员工id 对应的名称
  166 + rowSort HeaderLevel //
  167 + data map[string]*strings.Builder //需要导出的数据 key=员工Id+日期+表头
  168 +
  169 +}
  170 +
  171 +func newExportData2() *exportData2 {
  172 + return &exportData2{
  173 + tableHeader: HeaderLevel{
  174 + Name: "每日绩效汇总",
  175 + Filter: map[string]int{},
  176 + Child: []HeaderLevel{},
  177 + },
  178 + userIdMap: map[string]string{},
  179 + rowSort: HeaderLevel{
  180 + Name: "",
  181 + Filter: map[string]int{},
  182 + Child: []HeaderLevel{},
  183 + },
  184 + data: map[string]*strings.Builder{},
  185 + }
  186 +}
  187 +
  188 +func (e *exportData2) setData(param []dao.ExportData1) {
  189 + for _, v := range param {
  190 + e.userIdMap[v.TargetUserId] = v.TargetUserName
  191 + //提取表头数据
  192 + child := e.tableHeader.addChild(v.Category) //第一级 ,分类
  193 + weigh := e.weightDesc(v.Weight)
  194 + child = child.addChild(weigh) //第二级,加分项、得分项
  195 + child = child.addChild(v.ContentName) //第三级,评估项名称
  196 + child.addChild(v.PromptText) //第四级, 标准
  197 +
  198 + //提取 纵向列表 索引
  199 + child = e.rowSort.addChild(v.BeginDay) //日期
  200 + child.addChild(v.TargetUserId) //员工id
  201 + key := e.dataKey(v.TargetUserId, v.BeginDay, v.Category, v.ContentName)
  202 + e.data[key] = &strings.Builder{}
  203 + e.data[key].WriteString(v.Value + "\n")
  204 + for _, v2 := range v.Remark {
  205 + e.data[key].WriteString(v2.Definition + "\n")
  206 + e.data[key].WriteString(v2.RemarkText + "\n")
  207 + }
  208 + }
  209 +}
  210 +
  211 +func (e *exportData2) weightDesc(weight float64) string {
  212 + if weight == 0 {
  213 + return "加分项"
  214 + } else {
  215 + return "得分项"
  216 + }
  217 +}
  218 +
  219 +func (e *exportData2) dataKey(userId string, beginDay string, category string, contentName string) string {
  220 + key := fmt.Sprintf("%s-%s-%s-%s", userId, beginDay, category, contentName)
  221 + return key
  222 +}
@@ -258,7 +258,7 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ExportAssessContent @@ -258,7 +258,7 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ExportAssessContent
258 //处理查询到的数据 258 //处理查询到的数据
259 //汇总 Excel表格的表头描述 259 //汇总 Excel表格的表头描述
260 level1 := []string{} //分类 260 level1 := []string{} //分类
261 - level3 := map[string][]string{} // key=分类+得分项类型 val=名称 261 + level3 := map[string][]string{} //key=分类+得分项类型 val=名称
262 level4 := map[string]string{} //key=分类+名称 val=评估标准 262 level4 := map[string]string{} //key=分类+名称 val=评估标准
263 for _, v := range contentList { 263 for _, v := range contentList {
264 if v.ContentId == 0 { 264 if v.ContentId == 0 {
@@ -447,38 +447,6 @@ func (srv StaffAssessServeice) AnalysisData(param *query.ListAssessContentCycleD @@ -447,38 +447,6 @@ func (srv StaffAssessServeice) AnalysisData(param *query.ListAssessContentCycleD
447 if err != nil { 447 if err != nil {
448 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 448 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
449 } 449 }
450 - //roleRepo := factory.CreateRoleRepository(map[string]interface{}{  
451 - // "transactionContext": transactionContext,  
452 - //})  
453 - //roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{  
454 - // "transactionContext": transactionContext,  
455 - //})  
456 - //_, roleList, err := roleRepo.Find(map[string]interface{}{  
457 - // "type": domain.RoleTypeSystem,  
458 - // "companyId": param.CompanyId,  
459 - //})  
460 - //if err != nil {  
461 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())  
462 - //}  
463 - //_, userRoleList, err := roleUserRepo.Find(map[string]interface{}{  
464 - // "companyId": param.CompanyId,  
465 - // "userId": param.OperaterId,  
466 - //})  
467 - //if err != nil {  
468 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())  
469 - //}  
470 - //hrbp := -1  
471 - //for _, v := range userRoleList {  
472 - // for _, v2 := range roleList {  
473 - // if v.RoleId == v2.Id {  
474 - // hrbp = 1  
475 - // break  
476 - // }  
477 - // }  
478 - // if hrbp == 1 {  
479 - // break  
480 - // }  
481 - //}  
482 assessDao := dao.NewStaffAssessDao(map[string]interface{}{ 450 assessDao := dao.NewStaffAssessDao(map[string]interface{}{
483 "transactionContext": transactionContext, 451 "transactionContext": transactionContext,
484 }) 452 })
@@ -569,7 +537,7 @@ func (srv StaffAssessServeice) AnalysisData(param *query.ListAssessContentCycleD @@ -569,7 +537,7 @@ func (srv StaffAssessServeice) AnalysisData(param *query.ListAssessContentCycleD
569 } 537 }
570 538
571 // 员工绩效-综合管理-导出绩效-个人 539 // 员工绩效-综合管理-导出绩效-个人
572 -func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (*excelize.File, error) { 540 +func (srv StaffAssessServeice) ExportUserAssess2(param *query.ExportUserAssess2Commad) (*excelize.File, error) {
573 transactionContext, err := factory.CreateTransactionContext(nil) 541 transactionContext, err := factory.CreateTransactionContext(nil)
574 if err != nil { 542 if err != nil {
575 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 543 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -598,6 +566,7 @@ func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (* @@ -598,6 +566,7 @@ func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (*
598 param.CycleId, 566 param.CycleId,
599 param.OperatorId, 567 param.OperatorId,
600 hrbp, 568 hrbp,
  569 + param.ExportUserId,
601 ) 570 )
602 if err != nil { 571 if err != nil {
603 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 572 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -738,3 +707,126 @@ func (srv StaffAssessServeice) QueryPerformanceIndicator(param *query.ListAssess @@ -738,3 +707,126 @@ func (srv StaffAssessServeice) QueryPerformanceIndicator(param *query.ListAssess
738 } 707 }
739 return result, nil 708 return result, nil
740 } 709 }
  710 +
  711 +// 员工绩效-项目管理-成员列表导出
  712 +
  713 +func (srv StaffAssessServeice) ExportUserAssess3(param *query.ExportAssessContentCycleDay) (*excelize.File, error) {
  714 + transactionContext, err := factory.CreateTransactionContext(nil)
  715 + if err != nil {
  716 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  717 + }
  718 + if err := transactionContext.StartTransaction(); err != nil {
  719 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  720 + }
  721 + defer func() {
  722 + _ = transactionContext.RollbackTransaction()
  723 + }()
  724 +
  725 + hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperaterId)
  726 + if err != nil {
  727 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  728 + }
  729 +
  730 + assessDao := dao.NewStaffAssessDao(map[string]interface{}{
  731 + "transactionContext": transactionContext,
  732 + })
  733 + contentList, err := assessDao.ExportDataUserAssess(dao.SearchConditin1{
  734 + CompanyId: param.CompanyId,
  735 + CycleId: param.CycleId,
  736 + BeginDay: param.BeginDay,
  737 + TargetUserName: param.TargetUserName,
  738 + TargetUserId: param.TargetUserId,
  739 + Limit: 5000,
  740 + Offset: 0,
  741 + OperaterId: param.OperaterId,
  742 + Hrbp: hrbp,
  743 + })
  744 + if err != nil {
  745 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取数据列表"+err.Error())
  746 + }
  747 +
  748 + if err := transactionContext.CommitTransaction(); err != nil {
  749 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  750 + }
  751 + //选择导出的评估项
  752 + includeCol := map[string]struct{}{}
  753 + for _, v := range param.ExportItems {
  754 + includeCol[v.Category+"+"+v.Name] = struct{}{}
  755 + }
  756 +
  757 + eData := newExportData2()
  758 + eData.setData(contentList)
  759 + //将数据写入xlsx
  760 + xlsxFile := excelize.NewFile()
  761 + sheetIndex := xlsxFile.GetActiveSheetIndex()
  762 + sheetName := xlsxFile.GetSheetName(sheetIndex)
  763 + //写入第一行
  764 + xlsxFile.SetCellStr(sheetName, "A1", "每日绩效汇总")
  765 + xlsxFile.SetCellStr(sheetName, "A2", "日期")
  766 + xlsxFile.MergeCell(sheetName, "A2", "A4")
  767 + xlsxFile.SetCellStr(sheetName, "B2", "姓名")
  768 + xlsxFile.MergeCell(sheetName, "B2", "B4")
  769 + xlsxFile.SetCellStr(sheetName, "A5", "评估标准")
  770 +
  771 + //填充1,2 列
  772 + rowNum := 0
  773 + for _, v := range eData.rowSort.Child {
  774 + for _, v2 := range v.Child {
  775 + rowNum++
  776 + axisNum := fmt.Sprintf("%d", rowNum+5)
  777 + xlsxFile.SetCellStr(sheetName, "A"+axisNum, v.Name)
  778 + xlsxFile.SetCellStr(sheetName, "B"+axisNum, v2.Name)
  779 + }
  780 + }
  781 + for _, v := range eData.tableHeader.Child {
  782 + for _, v2 := range v.Child {
  783 + for _, v3 := range v2.Child {
  784 + _ = v3
  785 + }
  786 + }
  787 + }
  788 + //写入二到五行
  789 + // for k, v := range headerList {
  790 + // colName, _ := excelize.ColumnNumberToName(k + 1)
  791 + // xlsxFile.SetCellStr(sheetName, colName+"2", v.Level1)
  792 + // xlsxFile.SetCellStr(sheetName, colName+"3", v.Level2)
  793 + // xlsxFile.SetCellStr(sheetName, colName+"4", v.Level3)
  794 + // xlsxFile.SetCellStr(sheetName, colName+"5", v.Level4)
  795 + // }
  796 + //从第六行开始写入用户填写的评估数据
  797 + // for k, v := range tableRowSort {
  798 + // rowNum := strconv.Itoa(k + 6)
  799 + // row := tableRows[v]
  800 + // for k2, v2 := range headerList {
  801 + // if k2 == 0 {
  802 + // xlsxFile.SetCellStr(sheetName, "A"+rowNum, row["BeginDay"])
  803 + // continue
  804 + // }
  805 + // if k2 == 1 {
  806 + // xlsxFile.SetCellStr(sheetName, "B"+rowNum, row["TargetUserName"])
  807 + // continue
  808 + // }
  809 + // colName, _ := excelize.ColumnNumberToName(k2 + 1)
  810 + // key := v2.Level1 + "+" + v2.Level3
  811 + // if mVal, ok := row[key]; ok {
  812 + // xlsxFile.SetCellStr(sheetName, colName+rowNum, mVal)
  813 + // }
  814 + // }
  815 + // }
  816 + //TODO 调整样式
  817 + xlsxFile.MergeCell(sheetName, "A2", "A4")
  818 + xlsxFile.MergeCell(sheetName, "B2", "B4")
  819 + xlsxFile.MergeCell(sheetName, "B5", "B5")
  820 + // //设置行高
  821 + // for i := range tableRowSort {
  822 + // xlsxFile.SetRowHeight(sheetName, i+5, 50)
  823 + // }
  824 + // //设置列宽
  825 + // for i := range headerList {
  826 + // colName, _ := excelize.ColumnNumberToName(i + 1)
  827 + // if i == 0 {
  828 + // xlsxFile.SetColWidth(sheetName, colName, colName, 30)
  829 + // }
  830 + // }
  831 + return xlsxFile, nil
  832 +}
@@ -1149,7 +1149,8 @@ type ExportData2 struct { @@ -1149,7 +1149,8 @@ type ExportData2 struct {
1149 // cycleId int, 评估周期id 1149 // cycleId int, 评估周期id
1150 // userId int, 用户id,谁要查看数据 1150 // userId int, 用户id,谁要查看数据
1151 // hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否 1151 // hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
1152 -func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, operaterId int, hrbp int) ([]*ExportData2, error) { 1152 +// exportUserIds 只导出选中的员工的数据
  1153 +func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) ([]*ExportData2, error) {
1153 sqlStr := ` select 1154 sqlStr := ` select
1154 t_staff_assess_1.target_user_id, 1155 t_staff_assess_1.target_user_id,
1155 t_staff_assess_1.target_user_name, 1156 t_staff_assess_1.target_user_name,
@@ -1167,6 +1168,10 @@ func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, opera @@ -1167,6 +1168,10 @@ func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, opera
1167 where 1=1 1168 where 1=1
1168 ` 1169 `
1169 condition := []interface{}{} 1170 condition := []interface{}{}
  1171 + if len(exportUserIds) > 0 {
  1172 + condition = append(condition, pg.In(exportUserIds))
  1173 + sqlStr += ` and t_staff_assess_1.target_user_id in(?) `
  1174 + }
1170 //加入排序 1175 //加入排序
1171 sqlStr += ` order by t_staff_assess_1.begin_day` 1176 sqlStr += ` order by t_staff_assess_1.begin_day`
1172 //获取前置sql语句 1177 //获取前置sql语句
@@ -467,7 +467,7 @@ func (c *StaffAssessController) AnalysisData() { @@ -467,7 +467,7 @@ func (c *StaffAssessController) AnalysisData() {
467 // 根据周期里的考核日期,获取员工填写评估内容列表,导出为xlsx文件 467 // 根据周期里的考核日期,获取员工填写评估内容列表,导出为xlsx文件
468 func (c *StaffAssessController) ExportUserAssess2() { 468 func (c *StaffAssessController) ExportUserAssess2() {
469 srv := service.NewStaffAssessServeice() 469 srv := service.NewStaffAssessServeice()
470 - paramReq := &query.SummaryCommand{} 470 + paramReq := &query.ExportUserAssess2Commad{}
471 err := c.BindJSON(paramReq) 471 err := c.BindJSON(paramReq)
472 if err != nil { 472 if err != nil {
473 e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error()) 473 e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())