作者 郑周

Merge remote-tracking branch 'origin/test' into test

... ... @@ -2,6 +2,7 @@ package service
import (
"fmt"
"strconv"
"strings"
"github.com/linmadan/egglib-go/core/application"
... ... @@ -206,7 +207,7 @@ type excelTableHeader struct {
Level4 string
}
func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCycleDay) ([]byte, error) {
func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCycleDay) (*excelize.File, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -382,7 +383,7 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy
xlsxFile := excelize.NewFile()
sheetIndex := xlsxFile.GetActiveSheetIndex()
sheetName := xlsxFile.GetSheetName(sheetIndex)
// 写入第一行
//写入第一行
xlsxFile.SetCellStr(sheetName, "A1", "每日绩效汇总")
//写入二到五行
for k, v := range headerList {
... ... @@ -393,5 +394,39 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy
xlsxFile.SetCellStr(sheetName, colName+"5", v.Level4)
}
//从第六行开始写入用户填写的评估数据
return nil, nil
for k, v := range tableRowSort {
rowNum := strconv.Itoa(k + 6)
row := tableRows[v]
for k2, v2 := range headerList {
if k2 == 0 {
xlsxFile.SetCellStr(sheetName, "A"+rowNum, row["BeginDay"])
continue
}
if k2 == 1 {
xlsxFile.SetCellStr(sheetName, "B"+rowNum, row["TargetUserName"])
continue
}
colName, _ := excelize.ColumnNumberToName(k2 + 1)
key := v2.Level1 + "+" + v2.Level3
if mVal, ok := row[key]; ok {
xlsxFile.SetCellStr(sheetName, colName+rowNum, mVal)
}
}
}
//TODO 调整样式
xlsxFile.MergeCell(sheetName, "A2", "A4")
xlsxFile.MergeCell(sheetName, "B2", "B4")
xlsxFile.MergeCell(sheetName, "B5", "B5")
//设置行高
for i := range tableRowSort {
xlsxFile.SetRowHeight(sheetName, i+6, 50)
}
//设置列宽
for i := range headerList {
colName, _ := excelize.ColumnNumberToName(i + 1)
if i == 0 {
xlsxFile.SetColWidth(sheetName, colName, colName, 70)
}
}
return xlsxFile, nil
}
... ...
... ... @@ -124,7 +124,7 @@ func (d *StaffAssessDao) AllAssessCycleList(companyId int) ([]AssessCycle, error
companyId,
}
result := []AssessCycle{}
_, err := tx.QueryOne(&result, sqlStr, condition...)
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
... ... @@ -149,12 +149,13 @@ func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]As
cycleId, companyId,
}
result := []AssessCycleDay{}
_, err := tx.QueryOne(&result, sqlStr, condition...)
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
//获取员工填写评估内容
type UserAssessContent struct {
AssessId string `json:"assessId"`
TargetUserId string `json:"targetUserId"` //被评估人的id
TargetUserName string `json:"targetUserName"` //被评估人的名称
BeginDay string `json:"beginDay"` //评估的日期
... ...
package controllers
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
... ... @@ -320,3 +322,29 @@ func (c *StaffAssessController) ListAssessContentCycleDay() {
data, err := srv.ListUserAssessContentCycleDay(paramReq)
c.Response(data, err)
}
//根据周期里的考核日期,获取员工填写评估内容列表,导出为xlsx文件
func (c *StaffAssessController) ExportAssessContentCycleDay() {
srv := service.NewStaffAssessServeice()
paramReq := &query.ListAssessContentCycleDay{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
paramReq.OperaterId = int(userReq.UserId)
data, err := srv.ExportUserAssess(paramReq)
if err != nil {
c.Response(nil, err)
}
fileName := fmt.Sprintf("每日绩效汇总%s", paramReq.BeginDay)
c.Ctx.Output.Header("Content-Disposition", "attachment;filename="+fileName)
c.Ctx.Output.Header("Content-Description", "FileTransfer")
c.Ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
c.Ctx.Output.Header("Content-Transfer-Encoding", "binary")
c.Ctx.Output.Header("Expires", "0")
data.Write(c.Ctx.ResponseWriter)
}
... ...
package middlewares
import (
"strings"
"github.com/beego/beego/v2/server/web/context"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
... ... @@ -8,7 +10,17 @@ import (
func CheckFontToken() func(ctx *context.Context) {
return func(ctx *context.Context) {
adminToken := ctx.Input.Header("x-font-token")
// adminToken := ctx.Input.Header("x-font-token")
// Bearer authorization_token
adminToken := ctx.Input.Header("Authorization")
//以一个空格" ",做切分
strList := strings.Split(adminToken, " ")
if len(strList) > 1 {
adminToken = strList[1]
}
if len(strList) == 1 {
adminToken = strList[0]
}
userAuth, err := (&domain.UserAuth{}).ParseAccessToken(adminToken)
if err != nil || userAuth.UserId <= 0 {
forbidden(ctx)
... ...
... ... @@ -10,12 +10,13 @@ import (
func init() {
assessTaskNS := web.NewNamespace("/v1/staff-assess-task",
web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()),
web.NSCtrlPost("/search/me", (*controllers.StaffAssessController).SearchAssessTaskMe), //获取我参与过的评估项目列表
web.NSCtrlPost("/desc/me", (*controllers.StaffAssessController).AssessTaskMeDesc), //获取我的项目评估进度描述
web.NSCtrlPost("/", (*controllers.StaffAssessController).CreateStaffAssessTask), //创建员工的评估任务
web.NSCtrlGet("/cycle", (*controllers.StaffAssessController).ListAssessCycle), //获取周期列表
web.NSCtrlPost("/cycle/day", (*controllers.StaffAssessController).ListAssessCycleDay), //获取周期中的考核日期
web.NSCtrlPost("/cycle/day/content", (*controllers.StaffAssessController).ListAssessContentCycleDay), //根据周期里的考核日期,获取员工填写评估内容列表
web.NSCtrlPost("/search/me", (*controllers.StaffAssessController).SearchAssessTaskMe), //获取我参与过的评估项目列表
web.NSCtrlPost("/desc/me", (*controllers.StaffAssessController).AssessTaskMeDesc), //获取我的项目评估进度描述
web.NSCtrlPost("/", (*controllers.StaffAssessController).CreateStaffAssessTask), //创建员工的评估任务
web.NSCtrlGet("/cycle", (*controllers.StaffAssessController).ListAssessCycle), //获取周期列表
web.NSCtrlPost("/cycle/day", (*controllers.StaffAssessController).ListAssessCycleDay), //获取周期中的考核日期
web.NSCtrlPost("/cycle/day/content", (*controllers.StaffAssessController).ListAssessContentCycleDay), //根据周期里的考核日期,获取员工填写评估内容列表
web.NSCtrlPost("/cycle/day/content/export", (*controllers.StaffAssessController).ExportAssessContentCycleDay), //根据周期里的考核日期,导出员工填写评估内容列表
)
// /v1/staff-assess/self/me/list
assessNS := web.NewNamespace("/v1/staff-assess",
... ...