作者 tangxvhui

修正excel 样式处理

1 package query 1 package query
2 2
3 -//根据周期id和日期获取 员工填写评估内容 3 +// 根据周期id和日期获取 员工填写评估内容
4 type ListAssessContentCycleDay struct { 4 type ListAssessContentCycleDay struct {
5 CompanyId int `json:"companyId"` 5 CompanyId int `json:"companyId"`
6 OperaterId int `json:"operaterId"` 6 OperaterId int `json:"operaterId"`
@@ -11,3 +11,16 @@ type ListAssessContentCycleDay struct { @@ -11,3 +11,16 @@ type ListAssessContentCycleDay struct {
11 PageNumber int `json:"pageNumber"` 11 PageNumber int `json:"pageNumber"`
12 PageSize int `json:"pageSize"` 12 PageSize int `json:"pageSize"`
13 } 13 }
  14 +
  15 +type ExportAssessContentCycleDay struct {
  16 + CompanyId int `json:"companyId"`
  17 + OperaterId int `json:"operaterId"`
  18 + CycleId int `json:"cycleId,string"` //周期id
  19 + BeginDay string `json:"beginDay"` //评估开始的时间
  20 + TargetUserName string `json:"targetUserName"`
  21 + TargetUserId []string `json:"targetUserId"`
  22 + ExportItems []struct {
  23 + Category string `json:"category"` //指标类别
  24 + Name string `json:"name"` //指标名称
  25 + } `json:"exportItems"`
  26 +}
@@ -7,7 +7,7 @@ import ( @@ -7,7 +7,7 @@ import (
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao" 7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
8 ) 8 )
9 9
10 -// 员工绩效-综合管理-导出绩效指标 10 +// 员工绩效-综合管理-导出绩效-个人
11 11
12 // excel表头部字段 12 // excel表头部字段
13 type HeaderLevel struct { 13 type HeaderLevel struct {
@@ -211,7 +211,7 @@ func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAs @@ -211,7 +211,7 @@ func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAs
211 return &result, nil 211 return &result, nil
212 } 212 }
213 213
214 -func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCycleDay) (*excelize.File, error) { 214 +func (srv StaffAssessServeice) ExportUserAssess(param *query.ExportAssessContentCycleDay) (*excelize.File, error) {
215 transactionContext, err := factory.CreateTransactionContext(nil) 215 transactionContext, err := factory.CreateTransactionContext(nil)
216 if err != nil { 216 if err != nil {
217 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 217 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -249,6 +249,11 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy @@ -249,6 +249,11 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy
249 if err := transactionContext.CommitTransaction(); err != nil { 249 if err := transactionContext.CommitTransaction(); err != nil {
250 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 250 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
251 } 251 }
  252 + //选择导出的评估项
  253 + includeCol := map[string]struct{}{}
  254 + for _, v := range param.ExportItems {
  255 + includeCol[v.Category+"+"+v.Name] = struct{}{}
  256 + }
252 257
253 //处理查询到的数据 258 //处理查询到的数据
254 //汇总 Excel表格的表头描述 259 //汇总 Excel表格的表头描述
@@ -259,6 +264,11 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy @@ -259,6 +264,11 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy
259 if v.ContentId == 0 { 264 if v.ContentId == 0 {
260 continue 265 continue
261 } 266 }
  267 + if len(includeCol) > 0 {
  268 + if _, ok := includeCol[v.Category+"+"+v.ContentName]; !ok {
  269 + continue
  270 + }
  271 + }
262 level1Item := "" 272 level1Item := ""
263 for _, v1 := range level1 { 273 for _, v1 := range level1 {
264 if v.Category == v1 { 274 if v.Category == v1 {
@@ -354,6 +364,11 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy @@ -354,6 +364,11 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy
354 tableRows[v.TargetUserId]["TargetUserName"] = v.TargetUserName 364 tableRows[v.TargetUserId]["TargetUserName"] = v.TargetUserName
355 tableRows[v.TargetUserId]["BeginDay"] = v.BeginDay 365 tableRows[v.TargetUserId]["BeginDay"] = v.BeginDay
356 if v.ContentId > 0 { 366 if v.ContentId > 0 {
  367 + if len(includeCol) > 0 {
  368 + if _, ok := includeCol[v.Category+"+"+v.ContentName]; !ok {
  369 + continue
  370 + }
  371 + }
357 value := []string{v.Value} 372 value := []string{v.Value}
358 for _, v2 := range v.Remark { 373 for _, v2 := range v.Remark {
359 value = append(value, v2.RemarkText) 374 value = append(value, v2.RemarkText)
@@ -619,14 +634,14 @@ func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (* @@ -619,14 +634,14 @@ func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (*
619 //日期 634 //日期
620 dayList := eData.userDayMap[v] 635 dayList := eData.userDayMap[v]
621 for ii, vv := range dayList { 636 for ii, vv := range dayList {
622 - if ii == 0 {  
623 - axis := fmt.Sprintf("A%d", ii+7)  
624 - xlsxFile.SetCellStr(v, axis, vv)  
625 - } else {  
626 - axis := fmt.Sprintf("A%d", 7+3*(ii+1)) 637 + //填写在第几行
  638 + axisNum := 7 + 3*ii
  639 + axis := fmt.Sprintf("A%d", axisNum)
627 xlsxFile.SetCellStr(v, axis, vv) 640 xlsxFile.SetCellStr(v, axis, vv)
  641 + axisEnd := fmt.Sprintf("A%d", axisNum+2)
  642 + xlsxFile.MergeCell(v, axis, axisEnd) //单元格高度按三个单元格合并
628 } 643 }
629 - } 644 + //第一行
630 for _, v2 := range tableHeader.Child { 645 for _, v2 := range tableHeader.Child {
631 //第二行 646 //第二行
632 for _, v3 := range v2.Child { 647 for _, v3 := range v2.Child {
@@ -645,13 +660,13 @@ func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (* @@ -645,13 +660,13 @@ func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (*
645 //按日期填充评估的填写的值 660 //按日期填充评估的填写的值
646 for i5, v5 := range dayList { 661 for i5, v5 := range dayList {
647 k1 := eData.dataKey(v, v5, v2.Name, v3.Name, v4.Name) 662 k1 := eData.dataKey(v, v5, v2.Name, v3.Name, v4.Name)
648 - if i5 > 0 {  
649 - axis := fmt.Sprintf("%s%d", colName, 7+3*(i5+1)) //单元格高度按三个单元格合并 663 + //填写在第几行
  664 + axisNum := 7 + 3*i5
  665 + axis := fmt.Sprintf("%s%d", colName, axisNum)
650 xlsxFile.SetCellStr(v, axis, eData.data[k1].String()) 666 xlsxFile.SetCellStr(v, axis, eData.data[k1].String())
651 - } else {  
652 - axis := fmt.Sprintf("%s%d", colName, i5+7)  
653 - xlsxFile.SetCellStr(v, axis, eData.data[k1].String())  
654 - } 667 + //单元格高度按三个单元格合并
  668 + axisEnd := fmt.Sprintf("%s%d", colName, axisNum+2)
  669 + xlsxFile.MergeCell(v, axis, axisEnd)
655 } 670 }
656 } 671 }
657 } 672 }
@@ -342,7 +342,7 @@ func (c *StaffAssessController) ListAssessContentIndicator() { @@ -342,7 +342,7 @@ func (c *StaffAssessController) ListAssessContentIndicator() {
342 // 根据周期里的考核日期,获取员工填写评估内容列表,导出为xlsx文件 342 // 根据周期里的考核日期,获取员工填写评估内容列表,导出为xlsx文件
343 func (c *StaffAssessController) ExportAssessContentCycleDay() { 343 func (c *StaffAssessController) ExportAssessContentCycleDay() {
344 srv := service.NewStaffAssessServeice() 344 srv := service.NewStaffAssessServeice()
345 - paramReq := &query.ListAssessContentCycleDay{} 345 + paramReq := &query.ExportAssessContentCycleDay{}
346 err := c.BindJSON(paramReq) 346 err := c.BindJSON(paramReq)
347 if err != nil { 347 if err != nil {
348 e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error()) 348 e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())