|
|
package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"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/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -67,8 +74,8 @@ func (srv StaffAssessServeice) ListAllAssessCycleDay(param *query.ListAssessCycl |
|
|
}
|
|
|
|
|
|
//根据周期id和日期获取 员工填写评估内容
|
|
|
// 有过滤查看权限
|
|
|
func (srv StaffAssessServeice) ListAllAssessContentCycleDay(param *query.ListAssessContentCycleDay) (map[string]interface{}, error) {
|
|
|
//有过滤查看权限
|
|
|
func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAssessContentCycleDay) (*adapter.ListUserAssessContent, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -79,11 +86,354 @@ func (srv StaffAssessServeice) ListAllAssessContentCycleDay(param *query.ListAss |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
// assessDao := dao.NewStaffAssessDao(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
// })
|
|
|
|
|
|
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,
|
|
|
})
|
|
|
|
|
|
limit := param.PageSize
|
|
|
offset := (param.PageNumber - 1) * limit
|
|
|
cnt, err := assessDao.CountUserAssess(dao.SearchConditin1{
|
|
|
CompanyId: param.CompanyId,
|
|
|
CycleId: param.CycleId,
|
|
|
BeginDay: param.BeginDay,
|
|
|
TargetUserName: param.TargetUserName,
|
|
|
Limit: 5000,
|
|
|
Offset: 0,
|
|
|
OperaterId: param.OperaterId,
|
|
|
Hrbp: hrbp,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计总数"+err.Error())
|
|
|
}
|
|
|
contentList, err := assessDao.SearchUserAssessContent(dao.SearchConditin1{
|
|
|
CompanyId: param.CompanyId,
|
|
|
CycleId: param.CycleId,
|
|
|
BeginDay: param.BeginDay,
|
|
|
TargetUserName: param.TargetUserName,
|
|
|
Limit: limit,
|
|
|
Offset: offset,
|
|
|
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())
|
|
|
}
|
|
|
|
|
|
//可变的表格列
|
|
|
changeableHeader := []adapter.ListTableHeader{
|
|
|
{Key: "targetUserName", Name: "姓名"}, //固定列
|
|
|
}
|
|
|
//过滤重复的列
|
|
|
headerMap := map[string]string{}
|
|
|
// 获取已经填报的内容
|
|
|
changeableRows := map[string]map[string]string{}
|
|
|
tableSort := []string{} //确定列表行数据的顺序
|
|
|
for i, v := range contentList {
|
|
|
if _, ok := changeableRows[v.TargetUserId]; !ok {
|
|
|
changeableRows[v.TargetUserId] = map[string]string{}
|
|
|
tableSort = append(tableSort, v.TargetUserId)
|
|
|
}
|
|
|
changeableRows[v.TargetUserId]["targetUserName"] = v.TargetUserName
|
|
|
changeableRows[v.TargetUserId]["targetUserId"] = v.TargetUserId
|
|
|
if v.ContentId > 0 {
|
|
|
name := fmt.Sprintf("%s-%s", v.Category, v.ContentName)
|
|
|
key := fmt.Sprintf("k%d", i)
|
|
|
if _, ok := headerMap[name]; !ok {
|
|
|
changeableHeader = append(changeableHeader, adapter.ListTableHeader{
|
|
|
Key: key, Name: name,
|
|
|
})
|
|
|
headerMap[name] = key
|
|
|
}
|
|
|
key = headerMap[name]
|
|
|
changeableRows[v.TargetUserId][key] = v.Value
|
|
|
}
|
|
|
}
|
|
|
list := []map[string]string{}
|
|
|
for _, v := range tableSort {
|
|
|
for _, v2 := range changeableHeader {
|
|
|
if _, ok := changeableRows[v][v2.Key]; ok {
|
|
|
continue
|
|
|
}
|
|
|
changeableRows[v][v2.Key] = ""
|
|
|
}
|
|
|
list = append(list, changeableRows[v])
|
|
|
}
|
|
|
result := adapter.ListUserAssessContent{
|
|
|
TableHeader: changeableHeader,
|
|
|
Total: cnt,
|
|
|
List: list,
|
|
|
}
|
|
|
return &result, nil
|
|
|
}
|
|
|
|
|
|
type excelTableHeader struct {
|
|
|
Level1 string
|
|
|
Level2 string
|
|
|
Level3 string
|
|
|
Level4 string
|
|
|
}
|
|
|
|
|
|
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())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
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,
|
|
|
})
|
|
|
contentList, err := assessDao.ExportDataUserAssess(dao.SearchConditin1{
|
|
|
CompanyId: param.CompanyId,
|
|
|
CycleId: param.CycleId,
|
|
|
BeginDay: param.BeginDay,
|
|
|
TargetUserName: param.TargetUserName,
|
|
|
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())
|
|
|
}
|
|
|
return nil, nil
|
|
|
|
|
|
//处理查询到的数据
|
|
|
//汇总 Excel表格的表头描述
|
|
|
level1 := []string{} //分类
|
|
|
level3 := map[string][]string{} // key=分类+得分项类型 val=名称
|
|
|
level4 := map[string]string{} //key=分类+名称 val=评估标准
|
|
|
for _, v := range contentList {
|
|
|
if v.ContentId == 0 {
|
|
|
continue
|
|
|
}
|
|
|
level1Item := ""
|
|
|
for _, v1 := range level1 {
|
|
|
if v.Category == v1 {
|
|
|
level1Item = v1
|
|
|
}
|
|
|
}
|
|
|
if len(level1Item) == 0 {
|
|
|
level1 = append(level1, v.Category)
|
|
|
}
|
|
|
if v.Weight == 0 {
|
|
|
level3Key := v.Category + "-加分项"
|
|
|
if _, ok := level3[level3Key]; !ok {
|
|
|
level3[level3Key] = []string{}
|
|
|
}
|
|
|
level3Item := ""
|
|
|
for _, v3 := range level3[level3Key] {
|
|
|
if v3 == v.ContentName {
|
|
|
level3Item = v.ContentName
|
|
|
}
|
|
|
}
|
|
|
if len(level3Item) == 0 {
|
|
|
level3[level3Key] = append(level3[level3Key], v.ContentName)
|
|
|
}
|
|
|
}
|
|
|
if v.Weight > 0 {
|
|
|
level3Key := v.Category + "-得分项"
|
|
|
if _, ok := level3[level3Key]; !ok {
|
|
|
level3[level3Key] = []string{}
|
|
|
}
|
|
|
level3Item := ""
|
|
|
for _, v3 := range level3[level3Key] {
|
|
|
if v3 == v.ContentName {
|
|
|
level3Item = v.ContentName
|
|
|
}
|
|
|
}
|
|
|
if len(level3Item) == 0 {
|
|
|
level3[level3Key] = append(level3[level3Key], v.ContentName)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
level4Key := v.Category + "+" + v.ContentName
|
|
|
if _, ok := level4[level4Key]; !ok {
|
|
|
level4[level4Key] = v.PromptText
|
|
|
}
|
|
|
}
|
|
|
//汇总表头,按列
|
|
|
headerList := []excelTableHeader{
|
|
|
{
|
|
|
Level1: "日期",
|
|
|
Level2: "",
|
|
|
Level3: "",
|
|
|
Level4: "评估标准",
|
|
|
}, {
|
|
|
Level1: "姓名",
|
|
|
Level2: "",
|
|
|
Level3: "",
|
|
|
Level4: "",
|
|
|
},
|
|
|
}
|
|
|
for _, v := range level1 {
|
|
|
item := excelTableHeader{
|
|
|
Level1: v,
|
|
|
}
|
|
|
level3Key := v + "-加分项"
|
|
|
if _, ok := level3[level3Key]; ok {
|
|
|
for _, v2 := range level3[level3Key] {
|
|
|
item.Level2 = "加分项"
|
|
|
item.Level3 = v2
|
|
|
level4Key := v + "+" + v2
|
|
|
item.Level4 = level4[level4Key]
|
|
|
headerList = append(headerList, item)
|
|
|
}
|
|
|
}
|
|
|
level3Key = v + "-得分项"
|
|
|
if _, ok := level3[level3Key]; ok {
|
|
|
for _, v2 := range level3[level3Key] {
|
|
|
item.Level2 = "得分项"
|
|
|
item.Level3 = v2
|
|
|
level4Key := v + "+" + v2
|
|
|
item.Level4 = level4[level4Key]
|
|
|
headerList = append(headerList, item)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//数据形式 进行 行列转换
|
|
|
tableRows := map[string]map[string]string{}
|
|
|
tableRowSort := []string{}
|
|
|
for _, v := range contentList {
|
|
|
if _, ok := tableRows[v.TargetUserId]; !ok {
|
|
|
tableRows[v.TargetUserId] = map[string]string{}
|
|
|
tableRowSort = append(tableRowSort, v.TargetUserId)
|
|
|
}
|
|
|
tableRows[v.TargetUserId]["TargetUserName"] = v.TargetUserName
|
|
|
tableRows[v.TargetUserId]["BeginDay"] = v.BeginDay
|
|
|
if v.ContentId > 0 {
|
|
|
value := []string{v.Value}
|
|
|
for _, v2 := range v.Remark {
|
|
|
value = append(value, v2.RemarkText)
|
|
|
}
|
|
|
key := v.Category + "+" + v.ContentName
|
|
|
tableRows[v.TargetUserId][key] = strings.Join(value, "\n")
|
|
|
}
|
|
|
}
|
|
|
//将数据写入xlsx
|
|
|
xlsxFile := excelize.NewFile()
|
|
|
sheetIndex := xlsxFile.GetActiveSheetIndex()
|
|
|
sheetName := xlsxFile.GetSheetName(sheetIndex)
|
|
|
//写入第一行
|
|
|
xlsxFile.SetCellStr(sheetName, "A1", "每日绩效汇总")
|
|
|
//写入二到五行
|
|
|
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
|
|
|
} |
...
|
...
|
|