作者 郑周

1. 文件导出指标ni

... ... @@ -18,3 +18,19 @@ type MemberPerformanceIndicatorCommand struct {
CompanyId int `cname:"公司ID" json:"companyId"`
OperatorId int `cname:"操作人ID" json:"operatorId"`
}
// ExportPerformanceIndicatorCommand 成员绩效导出-指标-导出表格
type ExportPerformanceIndicatorCommand struct {
CycleId int `cname:"周期ID" json:"cycleId,string"`
Title string `cname:"标题" json:"title"`
Selected []ExportSelected `cname:"选中用户" json:"selected"`
CompanyId int `cname:"公司ID" json:"companyId"`
OperatorId int `cname:"操作人ID" json:"operatorId"`
}
type ExportSelected struct {
UserId string `cname:"用户ID" json:"userId"`
UserName string `cname:"用户名称" json:"userName"`
Category string `cname:"评估内容分类" json:"category"`
Name string `cname:"评估内容名称" json:"name"`
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"github.com/xuri/excelize/v2"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
... ... @@ -10,6 +12,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
"strconv"
"strings"
)
// 调试用,手动调用CreateStaffAssessTask
... ... @@ -326,3 +329,150 @@ func (srv StaffAssessServeice) QueryMemberPerformanceIndicator(in *query.MemberP
return tool_funs.SimpleWrapGridMap(int64(len(adapterList)), adapterList), nil
}
func (srv StaffAssessServeice) ExportPerformanceIndicator(in *query.ExportPerformanceIndicatorCommand) (*excelize.File, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
hrbp, err := srv.getHRBP(transactionContext, in.CompanyId, in.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 用户ID
userIds := make([]string, 0)
selectedMap := map[string]*query.ExportSelected{}
for i := range in.Selected {
userIds = append(userIds, in.Selected[i].UserId)
selectedMap[in.Selected[i].UserId] = &in.Selected[i]
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
list, err := assessDao.ExportPerformanceIndicator(
in.CompanyId,
in.OperatorId,
in.CycleId,
hrbp,
string(domain.AssessSelf),
userIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 过滤当前选中的分类和指标
conditionMap := map[string]dao.ExportPerformanceIndicator{}
conditionList := make([]dao.ExportPerformanceIndicator, 0)
for i := range list {
it := list[i]
if v, ok := selectedMap[it.TargetUserId]; ok {
v.UserName = it.TargetUserName
if v.Category == it.ContentCategory && v.Name == it.ContentName {
conditionList = append(conditionList, it)
conditionMap[it.TargetUserId+it.BeginDay] = it
}
}
}
// 获取的所有的日期行
rowDayMap := map[string]int{}
rowDayList := make([]string, 0)
for i := range conditionList {
it := conditionList[i]
if _, ok := rowDayMap[it.BeginDay]; !ok {
rowDayMap[it.BeginDay] = 0
rowDayList = append(rowDayList, it.BeginDay)
}
}
sheetName := "个人绩效指标"
f := excelize.NewFile()
f.SetSheetName("Sheet1", sheetName)
f.SetCellStr(sheetName, "A1", in.Title)
f.SetRowHeight(sheetName, 1, 40) // 设置第1行高度
styleId1, _ := f.NewStyle(&excelize.Style{
Font: &excelize.Font{
Bold: true,
Size: 20,
Color: "#000000",
},
Alignment: &excelize.Alignment{
Horizontal: "center",
Vertical: "center",
},
})
f.SetCellStyle(sheetName, "A1", "A1", styleId1)
f.MergeCell(sheetName, "A1", "P1") // 合并第一行
f.SetCellStr(sheetName, "A2", "注:红色部分为林董标识:")
f.SetRowHeight(sheetName, 2, 22) // 设置第2行高度
styleId2, _ := f.NewStyle(&excelize.Style{
Font: &excelize.Font{
Size: 14,
Color: "#FF0000",
},
})
f.SetCellStyle(sheetName, "A2", "A2", styleId2)
// 内容居中自动换行样式
styleId100, _ := f.NewStyle(&excelize.Style{
Alignment: &excelize.Alignment{
Horizontal: "center",
Vertical: "center",
WrapText: true,
},
})
f.SetCellStr(sheetName, "A3", "日期")
for i := range rowDayList {
var rowIndex = 4 + (i * 3)
axisStart := fmt.Sprintf("A%d", rowIndex)
axisEnd := fmt.Sprintf("A%d", rowIndex+2)
f.SetCellStr(sheetName, axisStart, rowDayList[i]) // 设置日期
f.MergeCell(sheetName, axisStart, axisEnd) // 合并三行
f.SetCellStyle(sheetName, axisStart, axisEnd, styleId100)
}
var columnIndex = 'B'
for i := range in.Selected {
axis := fmt.Sprintf("%v3", string(columnIndex))
f.SetCellStr(sheetName, axis, in.Selected[i].UserName) // 设置名称
columnIndex += 1
}
// 填写反馈内容
for i := range rowDayList {
var columnIndex = 'B' // 从B4开始填充数据内容
var rowIndex = 4 + (i * 3)
for j := range in.Selected {
axisStart := fmt.Sprintf("%v%v", string(columnIndex), rowIndex)
axisEnd := fmt.Sprintf("%v%v", string(columnIndex), rowIndex+2)
key := in.Selected[j].UserId + rowDayList[i] // key = 用户ID+日期
if v, ok := conditionMap[key]; ok {
var builder strings.Builder
for _, r := range v.Remark {
builder.WriteString(r.RemarkText)
}
f.SetCellStr(sheetName, axisStart, builder.String()) // 设置反馈内容
}
f.MergeCell(sheetName, axisStart, axisEnd) // 合并三行
f.SetCellStyle(sheetName, axisStart, axisEnd, styleId100)
columnIndex += 1
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return f, nil
}
... ...
... ... @@ -795,6 +795,135 @@ func (d *StaffAssessDao) MemberPerformanceIndicator(likeUserName string, company
}
type ExportPerformanceIndicator struct {
AssessId int `json:"assessId"` // ID
TargetUserId string `json:"targetUserId"` // 被评估人的id
TargetUserName string `json:"targetUserName"` // 被评估人的名称
BeginDay string `json:"beginDay"` // 评估的开始日期
CycleId int `json:"cycleId"` // 周期ID
ContentId int `json:"contentId"` // 评估内容ID
ContentCategory string `json:"contentCategory"` // 评估内容分类
ContentName string `json:"contentName"` // 评估内容名称
SortBy int `json:"sort_by"` // 评估内容排序
Remark []domain.AssessContemtRemark `json:"remark"` // 评估内容填写反馈内容
}
func (d *StaffAssessDao) ExportPerformanceIndicator(companyId int, operatorId int, cycleId int, hrbp int, assessType string, userIds []string) ([]ExportPerformanceIndicator, error) {
sqlString := `
set time zone 'PRC';
with t_user_department as (
select "user".id as user_id ,jsonb_array_elements_text ("user".department_id) as depart_id from "user"
where "user".company_id= %d and "user".deleted_at isnull
),
t_department as (
select department.id::text as depart_id from department where charge_user_ids @>'[%d]'
and "department".deleted_at isnull
),
-- 部门主管(所有下级用户ID)
t_user_1 as (
select t_user_department.user_id::text from t_user_department
join t_department on t_user_department.depart_id = t_department.depart_id
),
-- 如果是HRBP
t_project_1 as(
select evaluation_project.id as project_id
from evaluation_project
where evaluation_project.cycle_id =%d
and evaluation_project.hr_bp = %d
and evaluation_project.deleted_at isnull
),
-- 如果的项目管理员
t_project_2 as(
select evaluation_project.id as project_id
from evaluation_project
where evaluation_project.cycle_id =%d
and evaluation_project.pmp =1
and evaluation_project.pmp_ids @>'["%d"]'
and evaluation_project.deleted_at isnull
),
-- 合并数据
t_project_3 as (
select t_project_2.project_id from t_project_2
union
select t_project_1.project_id from t_project_1
),
-- 初步过滤数据
t_staff_assess_0 as (
select
staff_assess.id as assess_id,
staff_assess.cycle_id,
staff_assess.target_user->>'userId' as target_user_id,
staff_assess.target_user->>'userName' as target_user_name,
to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
staff_assess.evaluation_project_id
from staff_assess
join staff_assess_task on staff_assess.staff_assess_task_id = staff_assess_task.id
and staff_assess_task.deleted_at isnull
where
staff_assess.cycle_id = %d
and staff_assess.types ='%s'
),
-- 根据查看权限过滤合并数据
t_staff_assess_1 as (
( select
t_staff_assess_0.assess_id,
t_staff_assess_0.target_user_id,
t_staff_assess_0.target_user_name,
t_staff_assess_0.begin_day,
t_staff_assess_0.cycle_id
from t_staff_assess_0
join t_project_3 on t_staff_assess_0.evaluation_project_id = t_project_3.project_id
) union (
select
t_staff_assess_0.assess_id,
t_staff_assess_0.target_user_id,
t_staff_assess_0.target_user_name,
t_staff_assess_0.begin_day,
t_staff_assess_0.cycle_id
from t_staff_assess_0
join t_user_1 on t_staff_assess_0.target_user_id = t_user_1.user_id
)
)
`
params := []interface{}{companyId, operatorId, cycleId, hrbp, cycleId, operatorId, cycleId, assessType}
sqlString = fmt.Sprintf(sqlString, params...)
sqlString += ` select
t_staff_assess_1.target_user_id,
t_staff_assess_1.target_user_name,
t_staff_assess_1.begin_day,
t_staff_assess_1.cycle_id,
t_staff_assess_1.assess_id,
staff_assess_content.id as content_id,
staff_assess_content.name as content_name,
staff_assess_content.category as content_category,
staff_assess_content.remark,
staff_assess_content.sort_by
from t_staff_assess_1
left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
where 1=1
-- AND staff_assess_content.id NOTNULL 部分脏数据
`
condition := make([]interface{}, 0)
//if len(likeUserName) > 0 {
// sqlString += ` and t_staff_assess_1.target_user_name like ? `
// condition = append(condition, "%"+likeUserName+"%")
//}
if len(userIds) > 0 {
sqlString += ` and t_staff_assess_1.target_user_id in (?) `
condition = append(condition, pg.In(userIds))
}
//sqlString += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'), staff_assess_content.sort_by`
sqlString += ` order by t_staff_assess_1.begin_day`
tx := d.transactionContext.PgTx
var result = make([]ExportPerformanceIndicator, 0)
_, err := tx.Query(&result, sqlString, condition...)
return result, err
}
type ExportData1 struct {
AssessId string
ContentId int
... ... @@ -981,7 +1110,7 @@ type ExportData2 struct {
Remark []domain.AssessContemtRemark `pg:"remark"`
}
// 员工绩效-综合管理-导出绩效指标
// 员工绩效-综合管理-导出绩效-个人
// companyId int 公司id
// cycleId int, 评估周期id
// userId int, 用户id,谁要查看数据
... ...
... ... @@ -404,6 +404,32 @@ func (c *StaffAssessController) QueryMemberPerformanceIndicator() {
}
}
// ExportPerformanceIndicator 导出表格-员工绩效-综合管理-绩效导出指标-
func (c *StaffAssessController) ExportPerformanceIndicator() {
srv := service.NewStaffAssessServeice()
in := &query.ExportPerformanceIndicatorCommand{}
if err := c.Unmarshal(in); err != nil {
c.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
if user := middlewares.GetUser(c.Ctx); user != nil {
in.CompanyId = int(user.CompanyId)
in.OperatorId = int(user.UserId)
}
f, err := srv.ExportPerformanceIndicator(in)
if err != nil {
c.Response(nil, err)
return
}
fileName := "个人绩效指标"
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")
f.Write(c.Ctx.ResponseWriter)
}
}
// 员工绩效-项目管理-矩阵分析
func (c *StaffAssessController) AnalysisData() {
srv := service.NewStaffAssessServeice()
... ...
... ... @@ -32,6 +32,7 @@ func init() {
web.NSCtrlPost("/summary", (*controllers.StaffAssessController).QuerySummary), //员工绩效-项目管理-总览
web.NSCtrlPost("/summary/users", (*controllers.StaffAssessController).QueryMemberSummary), //员工绩效-综合管理-成员列表
web.NSCtrlPost("/summary/users-indicator", (*controllers.StaffAssessController).QueryMemberPerformanceIndicator), //员工绩效-综合管理-绩效导出指标
web.NSCtrlPost("/summary/export-indicator", (*controllers.StaffAssessController).ExportPerformanceIndicator), //员工绩效-综合管理-绩效导出指标
)
//v2 改版
assessTaskV2NS := web.NewNamespace("/v2/staff-assess-task",
... ...