Merge remote-tracking branch 'origin/test' into test
正在显示
5 个修改的文件
包含
83 行增加
和
6 行删除
@@ -2,6 +2,7 @@ package service | @@ -2,6 +2,7 @@ package service | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "strconv" | ||
5 | "strings" | 6 | "strings" |
6 | 7 | ||
7 | "github.com/linmadan/egglib-go/core/application" | 8 | "github.com/linmadan/egglib-go/core/application" |
@@ -206,7 +207,7 @@ type excelTableHeader struct { | @@ -206,7 +207,7 @@ type excelTableHeader struct { | ||
206 | Level4 string | 207 | Level4 string |
207 | } | 208 | } |
208 | 209 | ||
209 | -func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCycleDay) ([]byte, error) { | 210 | +func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCycleDay) (*excelize.File, error) { |
210 | transactionContext, err := factory.CreateTransactionContext(nil) | 211 | transactionContext, err := factory.CreateTransactionContext(nil) |
211 | if err != nil { | 212 | if err != nil { |
212 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 213 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
@@ -382,7 +383,7 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy | @@ -382,7 +383,7 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy | ||
382 | xlsxFile := excelize.NewFile() | 383 | xlsxFile := excelize.NewFile() |
383 | sheetIndex := xlsxFile.GetActiveSheetIndex() | 384 | sheetIndex := xlsxFile.GetActiveSheetIndex() |
384 | sheetName := xlsxFile.GetSheetName(sheetIndex) | 385 | sheetName := xlsxFile.GetSheetName(sheetIndex) |
385 | - // 写入第一行 | 386 | + //写入第一行 |
386 | xlsxFile.SetCellStr(sheetName, "A1", "每日绩效汇总") | 387 | xlsxFile.SetCellStr(sheetName, "A1", "每日绩效汇总") |
387 | //写入二到五行 | 388 | //写入二到五行 |
388 | for k, v := range headerList { | 389 | for k, v := range headerList { |
@@ -393,5 +394,39 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy | @@ -393,5 +394,39 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy | ||
393 | xlsxFile.SetCellStr(sheetName, colName+"5", v.Level4) | 394 | xlsxFile.SetCellStr(sheetName, colName+"5", v.Level4) |
394 | } | 395 | } |
395 | //从第六行开始写入用户填写的评估数据 | 396 | //从第六行开始写入用户填写的评估数据 |
396 | - return nil, nil | 397 | + for k, v := range tableRowSort { |
398 | + rowNum := strconv.Itoa(k + 6) | ||
399 | + row := tableRows[v] | ||
400 | + for k2, v2 := range headerList { | ||
401 | + if k2 == 0 { | ||
402 | + xlsxFile.SetCellStr(sheetName, "A"+rowNum, row["BeginDay"]) | ||
403 | + continue | ||
404 | + } | ||
405 | + if k2 == 1 { | ||
406 | + xlsxFile.SetCellStr(sheetName, "B"+rowNum, row["TargetUserName"]) | ||
407 | + continue | ||
408 | + } | ||
409 | + colName, _ := excelize.ColumnNumberToName(k2 + 1) | ||
410 | + key := v2.Level1 + "+" + v2.Level3 | ||
411 | + if mVal, ok := row[key]; ok { | ||
412 | + xlsxFile.SetCellStr(sheetName, colName+rowNum, mVal) | ||
413 | + } | ||
414 | + } | ||
415 | + } | ||
416 | + //TODO 调整样式 | ||
417 | + xlsxFile.MergeCell(sheetName, "A2", "A4") | ||
418 | + xlsxFile.MergeCell(sheetName, "B2", "B4") | ||
419 | + xlsxFile.MergeCell(sheetName, "B5", "B5") | ||
420 | + //设置行高 | ||
421 | + for i := range tableRowSort { | ||
422 | + xlsxFile.SetRowHeight(sheetName, i+6, 50) | ||
423 | + } | ||
424 | + //设置列宽 | ||
425 | + for i := range headerList { | ||
426 | + colName, _ := excelize.ColumnNumberToName(i + 1) | ||
427 | + if i == 0 { | ||
428 | + xlsxFile.SetColWidth(sheetName, colName, colName, 70) | ||
429 | + } | ||
430 | + } | ||
431 | + return xlsxFile, nil | ||
397 | } | 432 | } |
@@ -124,7 +124,7 @@ func (d *StaffAssessDao) AllAssessCycleList(companyId int) ([]AssessCycle, error | @@ -124,7 +124,7 @@ func (d *StaffAssessDao) AllAssessCycleList(companyId int) ([]AssessCycle, error | ||
124 | companyId, | 124 | companyId, |
125 | } | 125 | } |
126 | result := []AssessCycle{} | 126 | result := []AssessCycle{} |
127 | - _, err := tx.QueryOne(&result, sqlStr, condition...) | 127 | + _, err := tx.Query(&result, sqlStr, condition...) |
128 | return result, err | 128 | return result, err |
129 | } | 129 | } |
130 | 130 | ||
@@ -149,12 +149,13 @@ func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]As | @@ -149,12 +149,13 @@ func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]As | ||
149 | cycleId, companyId, | 149 | cycleId, companyId, |
150 | } | 150 | } |
151 | result := []AssessCycleDay{} | 151 | result := []AssessCycleDay{} |
152 | - _, err := tx.QueryOne(&result, sqlStr, condition...) | 152 | + _, err := tx.Query(&result, sqlStr, condition...) |
153 | return result, err | 153 | return result, err |
154 | } | 154 | } |
155 | 155 | ||
156 | //获取员工填写评估内容 | 156 | //获取员工填写评估内容 |
157 | type UserAssessContent struct { | 157 | type UserAssessContent struct { |
158 | + AssessId string `json:"assessId"` | ||
158 | TargetUserId string `json:"targetUserId"` //被评估人的id | 159 | TargetUserId string `json:"targetUserId"` //被评估人的id |
159 | TargetUserName string `json:"targetUserName"` //被评估人的名称 | 160 | TargetUserName string `json:"targetUserName"` //被评估人的名称 |
160 | BeginDay string `json:"beginDay"` //评估的日期 | 161 | BeginDay string `json:"beginDay"` //评估的日期 |
1 | package controllers | 1 | package controllers |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
5 | + | ||
4 | "github.com/linmadan/egglib-go/core/application" | 6 | "github.com/linmadan/egglib-go/core/application" |
5 | "github.com/linmadan/egglib-go/web/beego" | 7 | "github.com/linmadan/egglib-go/web/beego" |
6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" | 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" |
@@ -320,3 +322,29 @@ func (c *StaffAssessController) ListAssessContentCycleDay() { | @@ -320,3 +322,29 @@ func (c *StaffAssessController) ListAssessContentCycleDay() { | ||
320 | data, err := srv.ListUserAssessContentCycleDay(paramReq) | 322 | data, err := srv.ListUserAssessContentCycleDay(paramReq) |
321 | c.Response(data, err) | 323 | c.Response(data, err) |
322 | } | 324 | } |
325 | + | ||
326 | +//根据周期里的考核日期,获取员工填写评估内容列表,导出为xlsx文件 | ||
327 | +func (c *StaffAssessController) ExportAssessContentCycleDay() { | ||
328 | + srv := service.NewStaffAssessServeice() | ||
329 | + paramReq := &query.ListAssessContentCycleDay{} | ||
330 | + err := c.BindJSON(paramReq) | ||
331 | + if err != nil { | ||
332 | + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error()) | ||
333 | + c.Response(nil, e) | ||
334 | + return | ||
335 | + } | ||
336 | + userReq := middlewares.GetUser(c.Ctx) | ||
337 | + paramReq.CompanyId = int(userReq.CompanyId) | ||
338 | + paramReq.OperaterId = int(userReq.UserId) | ||
339 | + data, err := srv.ExportUserAssess(paramReq) | ||
340 | + if err != nil { | ||
341 | + c.Response(nil, err) | ||
342 | + } | ||
343 | + fileName := fmt.Sprintf("每日绩效汇总%s", paramReq.BeginDay) | ||
344 | + c.Ctx.Output.Header("Content-Disposition", "attachment;filename="+fileName) | ||
345 | + c.Ctx.Output.Header("Content-Description", "FileTransfer") | ||
346 | + c.Ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") | ||
347 | + c.Ctx.Output.Header("Content-Transfer-Encoding", "binary") | ||
348 | + c.Ctx.Output.Header("Expires", "0") | ||
349 | + data.Write(c.Ctx.ResponseWriter) | ||
350 | +} |
1 | package middlewares | 1 | package middlewares |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "strings" | ||
5 | + | ||
4 | "github.com/beego/beego/v2/server/web/context" | 6 | "github.com/beego/beego/v2/server/web/context" |
5 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" | 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" |
6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
@@ -8,7 +10,17 @@ import ( | @@ -8,7 +10,17 @@ import ( | ||
8 | 10 | ||
9 | func CheckFontToken() func(ctx *context.Context) { | 11 | func CheckFontToken() func(ctx *context.Context) { |
10 | return func(ctx *context.Context) { | 12 | return func(ctx *context.Context) { |
11 | - adminToken := ctx.Input.Header("x-font-token") | 13 | + // adminToken := ctx.Input.Header("x-font-token") |
14 | + // Bearer authorization_token | ||
15 | + adminToken := ctx.Input.Header("Authorization") | ||
16 | + //以一个空格" ",做切分 | ||
17 | + strList := strings.Split(adminToken, " ") | ||
18 | + if len(strList) > 1 { | ||
19 | + adminToken = strList[1] | ||
20 | + } | ||
21 | + if len(strList) == 1 { | ||
22 | + adminToken = strList[0] | ||
23 | + } | ||
12 | userAuth, err := (&domain.UserAuth{}).ParseAccessToken(adminToken) | 24 | userAuth, err := (&domain.UserAuth{}).ParseAccessToken(adminToken) |
13 | if err != nil || userAuth.UserId <= 0 { | 25 | if err != nil || userAuth.UserId <= 0 { |
14 | forbidden(ctx) | 26 | forbidden(ctx) |
@@ -16,6 +16,7 @@ func init() { | @@ -16,6 +16,7 @@ func init() { | ||
16 | web.NSCtrlGet("/cycle", (*controllers.StaffAssessController).ListAssessCycle), //获取周期列表 | 16 | web.NSCtrlGet("/cycle", (*controllers.StaffAssessController).ListAssessCycle), //获取周期列表 |
17 | web.NSCtrlPost("/cycle/day", (*controllers.StaffAssessController).ListAssessCycleDay), //获取周期中的考核日期 | 17 | web.NSCtrlPost("/cycle/day", (*controllers.StaffAssessController).ListAssessCycleDay), //获取周期中的考核日期 |
18 | web.NSCtrlPost("/cycle/day/content", (*controllers.StaffAssessController).ListAssessContentCycleDay), //根据周期里的考核日期,获取员工填写评估内容列表 | 18 | web.NSCtrlPost("/cycle/day/content", (*controllers.StaffAssessController).ListAssessContentCycleDay), //根据周期里的考核日期,获取员工填写评估内容列表 |
19 | + web.NSCtrlPost("/cycle/day/content/export", (*controllers.StaffAssessController).ExportAssessContentCycleDay), //根据周期里的考核日期,导出员工填写评估内容列表 | ||
19 | ) | 20 | ) |
20 | // /v1/staff-assess/self/me/list | 21 | // /v1/staff-assess/self/me/list |
21 | assessNS := web.NewNamespace("/v1/staff-assess", | 22 | assessNS := web.NewNamespace("/v1/staff-assess", |
-
请 注册 或 登录 后发表评论