作者 tangxvhui

修正excel 样式处理

package query
//根据周期id和日期获取 员工填写评估内容
// 根据周期id和日期获取 员工填写评估内容
type ListAssessContentCycleDay struct {
CompanyId int `json:"companyId"`
OperaterId int `json:"operaterId"`
... ... @@ -11,3 +11,16 @@ type ListAssessContentCycleDay struct {
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
}
type ExportAssessContentCycleDay struct {
CompanyId int `json:"companyId"`
OperaterId int `json:"operaterId"`
CycleId int `json:"cycleId,string"` //周期id
BeginDay string `json:"beginDay"` //评估开始的时间
TargetUserName string `json:"targetUserName"`
TargetUserId []string `json:"targetUserId"`
ExportItems []struct {
Category string `json:"category"` //指标类别
Name string `json:"name"` //指标名称
} `json:"exportItems"`
}
... ...
... ... @@ -7,7 +7,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
)
// 员工绩效-综合管理-导出绩效指标
// 员工绩效-综合管理-导出绩效-个人
// excel表头部字段
type HeaderLevel struct {
... ...
... ... @@ -211,7 +211,7 @@ func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAs
return &result, nil
}
func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCycleDay) (*excelize.File, error) {
func (srv StaffAssessServeice) ExportUserAssess(param *query.ExportAssessContentCycleDay) (*excelize.File, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -249,6 +249,11 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//选择导出的评估项
includeCol := map[string]struct{}{}
for _, v := range param.ExportItems {
includeCol[v.Category+"+"+v.Name] = struct{}{}
}
//处理查询到的数据
//汇总 Excel表格的表头描述
... ... @@ -259,6 +264,11 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy
if v.ContentId == 0 {
continue
}
if len(includeCol) > 0 {
if _, ok := includeCol[v.Category+"+"+v.ContentName]; !ok {
continue
}
}
level1Item := ""
for _, v1 := range level1 {
if v.Category == v1 {
... ... @@ -354,6 +364,11 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy
tableRows[v.TargetUserId]["TargetUserName"] = v.TargetUserName
tableRows[v.TargetUserId]["BeginDay"] = v.BeginDay
if v.ContentId > 0 {
if len(includeCol) > 0 {
if _, ok := includeCol[v.Category+"+"+v.ContentName]; !ok {
continue
}
}
value := []string{v.Value}
for _, v2 := range v.Remark {
value = append(value, v2.RemarkText)
... ... @@ -619,14 +634,14 @@ func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (*
//日期
dayList := eData.userDayMap[v]
for ii, vv := range dayList {
if ii == 0 {
axis := fmt.Sprintf("A%d", ii+7)
xlsxFile.SetCellStr(v, axis, vv)
} else {
axis := fmt.Sprintf("A%d", 7+3*(ii+1))
xlsxFile.SetCellStr(v, axis, vv)
}
//填写在第几行
axisNum := 7 + 3*ii
axis := fmt.Sprintf("A%d", axisNum)
xlsxFile.SetCellStr(v, axis, vv)
axisEnd := fmt.Sprintf("A%d", axisNum+2)
xlsxFile.MergeCell(v, axis, axisEnd) //单元格高度按三个单元格合并
}
//第一行
for _, v2 := range tableHeader.Child {
//第二行
for _, v3 := range v2.Child {
... ... @@ -645,13 +660,13 @@ func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (*
//按日期填充评估的填写的值
for i5, v5 := range dayList {
k1 := eData.dataKey(v, v5, v2.Name, v3.Name, v4.Name)
if i5 > 0 {
axis := fmt.Sprintf("%s%d", colName, 7+3*(i5+1)) //单元格高度按三个单元格合并
xlsxFile.SetCellStr(v, axis, eData.data[k1].String())
} else {
axis := fmt.Sprintf("%s%d", colName, i5+7)
xlsxFile.SetCellStr(v, axis, eData.data[k1].String())
}
//填写在第几行
axisNum := 7 + 3*i5
axis := fmt.Sprintf("%s%d", colName, axisNum)
xlsxFile.SetCellStr(v, axis, eData.data[k1].String())
//单元格高度按三个单元格合并
axisEnd := fmt.Sprintf("%s%d", colName, axisNum+2)
xlsxFile.MergeCell(v, axis, axisEnd)
}
}
}
... ...
... ... @@ -342,7 +342,7 @@ func (c *StaffAssessController) ListAssessContentIndicator() {
// 根据周期里的考核日期,获取员工填写评估内容列表,导出为xlsx文件
func (c *StaffAssessController) ExportAssessContentCycleDay() {
srv := service.NewStaffAssessServeice()
paramReq := &query.ListAssessContentCycleDay{}
paramReq := &query.ExportAssessContentCycleDay{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
... ...