作者 tangxvhui

日常保存

... ... @@ -17,6 +17,7 @@ type ExportAssessContentCycleDay struct {
OperaterId int `json:"operaterId"`
CycleId int `json:"cycleId,string"` //周期id
BeginDay string `json:"beginDay"` //评估开始的时间
BeginDayList []string `json:"beginDayList"` //评估开始的时间
TargetUserName string `json:"targetUserName"`
TargetUserId []string `json:"targetUserId"`
ExportItems []struct {
... ...
... ... @@ -7,3 +7,10 @@ type SummaryCommand struct {
CompanyId int `cname:"公司ID" json:"companyId"`
OperatorId int `cname:"操作人ID" json:"operatorId"`
}
type ExportUserAssess2Commad struct {
CycleId int `cname:"周期ID" json:"cycleId,string"`
CompanyId int `cname:"公司ID" json:"companyId"`
OperatorId int `cname:"操作人ID" json:"operatorId"`
ExportUserId []string `cname:"指定员工数据导出" json:"exportUserId"`
}
... ...
... ... @@ -159,3 +159,64 @@ func (e *exportData) weightDesc(weight float64) string {
func (e *exportData) userDayKey(userName string) string {
return userName
}
type exportData2 struct {
tableHeader HeaderLevel //数据表格对应表头
userIdMap map[string]string //员工id 对应的名称
rowSort HeaderLevel //
data map[string]*strings.Builder //需要导出的数据 key=员工Id+日期+表头
}
func newExportData2() *exportData2 {
return &exportData2{
tableHeader: HeaderLevel{
Name: "每日绩效汇总",
Filter: map[string]int{},
Child: []HeaderLevel{},
},
userIdMap: map[string]string{},
rowSort: HeaderLevel{
Name: "",
Filter: map[string]int{},
Child: []HeaderLevel{},
},
data: map[string]*strings.Builder{},
}
}
func (e *exportData2) setData(param []dao.ExportData1) {
for _, v := range param {
e.userIdMap[v.TargetUserId] = v.TargetUserName
//提取表头数据
child := e.tableHeader.addChild(v.Category) //第一级 ,分类
weigh := e.weightDesc(v.Weight)
child = child.addChild(weigh) //第二级,加分项、得分项
child = child.addChild(v.ContentName) //第三级,评估项名称
child.addChild(v.PromptText) //第四级, 标准
//提取 纵向列表 索引
child = e.rowSort.addChild(v.BeginDay) //日期
child.addChild(v.TargetUserId) //员工id
key := e.dataKey(v.TargetUserId, v.BeginDay, v.Category, v.ContentName)
e.data[key] = &strings.Builder{}
e.data[key].WriteString(v.Value + "\n")
for _, v2 := range v.Remark {
e.data[key].WriteString(v2.Definition + "\n")
e.data[key].WriteString(v2.RemarkText + "\n")
}
}
}
func (e *exportData2) weightDesc(weight float64) string {
if weight == 0 {
return "加分项"
} else {
return "得分项"
}
}
func (e *exportData2) dataKey(userId string, beginDay string, category string, contentName string) string {
key := fmt.Sprintf("%s-%s-%s-%s", userId, beginDay, category, contentName)
return key
}
... ...
... ... @@ -258,7 +258,7 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ExportAssessContent
//处理查询到的数据
//汇总 Excel表格的表头描述
level1 := []string{} //分类
level3 := map[string][]string{} // key=分类+得分项类型 val=名称
level3 := map[string][]string{} //key=分类+得分项类型 val=名称
level4 := map[string]string{} //key=分类+名称 val=评估标准
for _, v := range contentList {
if v.ContentId == 0 {
... ... @@ -447,38 +447,6 @@ func (srv StaffAssessServeice) AnalysisData(param *query.ListAssessContentCycleD
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//roleRepo := factory.CreateRoleRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//})
//roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//})
//_, roleList, err := roleRepo.Find(map[string]interface{}{
// "type": domain.RoleTypeSystem,
// "companyId": param.CompanyId,
//})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
//}
//_, userRoleList, err := roleUserRepo.Find(map[string]interface{}{
// "companyId": param.CompanyId,
// "userId": param.OperaterId,
//})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
//}
//hrbp := -1
//for _, v := range userRoleList {
// for _, v2 := range roleList {
// if v.RoleId == v2.Id {
// hrbp = 1
// break
// }
// }
// if hrbp == 1 {
// break
// }
//}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
... ... @@ -569,7 +537,7 @@ func (srv StaffAssessServeice) AnalysisData(param *query.ListAssessContentCycleD
}
// 员工绩效-综合管理-导出绩效-个人
func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (*excelize.File, error) {
func (srv StaffAssessServeice) ExportUserAssess2(param *query.ExportUserAssess2Commad) (*excelize.File, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -598,6 +566,7 @@ func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (*
param.CycleId,
param.OperatorId,
hrbp,
param.ExportUserId,
)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -738,3 +707,126 @@ func (srv StaffAssessServeice) QueryPerformanceIndicator(param *query.ListAssess
}
return result, nil
}
// 员工绩效-项目管理-成员列表导出
func (srv StaffAssessServeice) ExportUserAssess3(param *query.ExportAssessContentCycleDay) (*excelize.File, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperaterId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
contentList, err := assessDao.ExportDataUserAssess(dao.SearchConditin1{
CompanyId: param.CompanyId,
CycleId: param.CycleId,
BeginDay: param.BeginDay,
TargetUserName: param.TargetUserName,
TargetUserId: param.TargetUserId,
Limit: 5000,
Offset: 0,
OperaterId: param.OperaterId,
Hrbp: hrbp,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取数据列表"+err.Error())
}
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{}{}
}
eData := newExportData2()
eData.setData(contentList)
//将数据写入xlsx
xlsxFile := excelize.NewFile()
sheetIndex := xlsxFile.GetActiveSheetIndex()
sheetName := xlsxFile.GetSheetName(sheetIndex)
//写入第一行
xlsxFile.SetCellStr(sheetName, "A1", "每日绩效汇总")
xlsxFile.SetCellStr(sheetName, "A2", "日期")
xlsxFile.MergeCell(sheetName, "A2", "A4")
xlsxFile.SetCellStr(sheetName, "B2", "姓名")
xlsxFile.MergeCell(sheetName, "B2", "B4")
xlsxFile.SetCellStr(sheetName, "A5", "评估标准")
//填充1,2 列
rowNum := 0
for _, v := range eData.rowSort.Child {
for _, v2 := range v.Child {
rowNum++
axisNum := fmt.Sprintf("%d", rowNum+5)
xlsxFile.SetCellStr(sheetName, "A"+axisNum, v.Name)
xlsxFile.SetCellStr(sheetName, "B"+axisNum, v2.Name)
}
}
for _, v := range eData.tableHeader.Child {
for _, v2 := range v.Child {
for _, v3 := range v2.Child {
_ = v3
}
}
}
//写入二到五行
// for k, v := range headerList {
// colName, _ := excelize.ColumnNumberToName(k + 1)
// xlsxFile.SetCellStr(sheetName, colName+"2", v.Level1)
// xlsxFile.SetCellStr(sheetName, colName+"3", v.Level2)
// xlsxFile.SetCellStr(sheetName, colName+"4", v.Level3)
// xlsxFile.SetCellStr(sheetName, colName+"5", v.Level4)
// }
//从第六行开始写入用户填写的评估数据
// 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+5, 50)
// }
// //设置列宽
// for i := range headerList {
// colName, _ := excelize.ColumnNumberToName(i + 1)
// if i == 0 {
// xlsxFile.SetColWidth(sheetName, colName, colName, 30)
// }
// }
return xlsxFile, nil
}
... ...
... ... @@ -1149,7 +1149,8 @@ type ExportData2 struct {
// cycleId int, 评估周期id
// userId int, 用户id,谁要查看数据
// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, operaterId int, hrbp int) ([]*ExportData2, error) {
// exportUserIds 只导出选中的员工的数据
func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) ([]*ExportData2, error) {
sqlStr := ` select
t_staff_assess_1.target_user_id,
t_staff_assess_1.target_user_name,
... ... @@ -1167,6 +1168,10 @@ func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, opera
where 1=1
`
condition := []interface{}{}
if len(exportUserIds) > 0 {
condition = append(condition, pg.In(exportUserIds))
sqlStr += ` and t_staff_assess_1.target_user_id in(?) `
}
//加入排序
sqlStr += ` order by t_staff_assess_1.begin_day`
//获取前置sql语句
... ...
... ... @@ -467,7 +467,7 @@ func (c *StaffAssessController) AnalysisData() {
// 根据周期里的考核日期,获取员工填写评估内容列表,导出为xlsx文件
func (c *StaffAssessController) ExportUserAssess2() {
srv := service.NewStaffAssessServeice()
paramReq := &query.SummaryCommand{}
paramReq := &query.ExportUserAssess2Commad{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
... ...