作者 tangxvhui

Merge branch 'test'

... ... @@ -10,7 +10,7 @@
"type": "go",
"request": "launch",
"mode": "debug",
"buildFlags": "--tags=local",
"buildFlags": "",
"program": "./main.go"
},
]
... ...
... ... @@ -173,6 +173,19 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
// 查询系统默认规则
_, sysRules, err := ruleRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "sysType": domain.EvaluationSysTypeSystem, "limit": 1})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 不存在,生成默认规则
if len(sysRules) == 0 {
newRule := domain.GenerateSysRule(in.CompanyId)
if _, err := ruleRepository.Insert(newRule); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
total, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -180,31 +193,11 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
ras := make([]*adapter.RuleAdapter, 0)
creatorIds := make([]int64, 0)
var havaSystemType = false
for i := range rules {
ra := &adapter.RuleAdapter{}
ra.EvaluationRule = rules[i]
ras = append(ras, ra)
creatorIds = append(creatorIds, rules[i].CreatorId)
if rules[i].SysType == domain.EvaluationSysTypeSystem {
havaSystemType = true
break
}
}
// 如果不存在系统默认就生成一个
if !havaSystemType {
newRule := domain.GenerateSysRule(in.CompanyId)
rule, err := ruleRepository.Insert(newRule)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
ra := &adapter.RuleAdapter{}
ra.EvaluationRule = rule
ras = append(ras, ra)
total += 1
}
_, users, _ := userRepository.Find(map[string]interface{}{"ids": creatorIds, "limit": len(creatorIds)})
... ... @@ -218,7 +211,6 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
if v, ok := userNameMap[ras[i].CreatorId]; ok {
ras[i].CreatorName = v
}
}
if err := transactionContext.CommitTransaction(); err != nil {
... ...
... ... @@ -99,16 +99,16 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
task.NextSentAt = &nextTime
}
// 下个周期的起始时间=当前周期的截止时间
// 周期的截至时间=下一个周期的开始时间-1秒
if task.NextSentAt == nil {
cycleTimeEnd = maxTime
} else {
cycleTimeEnd = task.NextSentAt.Local()
cycleTimeEnd = task.NextSentAt.Local().Add(-1 * time.Second)
}
// 格式化周期的起始和截止时间
fmCycleStartTime := cycleTimeStart.Format("2006-1-2 15:04:05")
fmCycleTimeEnd := cycleTimeEnd.Format("2006-1-2 15:04:05")
fmCycleStartTime := cycleTimeStart.Format("2006-01-02 15:04:05")
fmCycleTimeEnd := cycleTimeEnd.Format("2006-01-02 15:04:05")
csat := &command.CreateStaffAssessTask{
CompanyId: int(project.CompanyId),
... ...
package adapter
type ListUserAssessContent struct {
TableHeader []ListTableHeader `json:"tableHeader"`
List []map[string]string `json:"list"`
Total int `json:"total"`
}
... ...
package query
type ListAssessContentCycleDay struct {
CompanyId int `json:"companyId"`
OperaterId int `json:"operaterId"`
CycleId int `json:"cycleId,string"`
BeginDay string `json:"beginDay"`
TargetUserName string `json:"targetUserName"`
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
CompanyId int `json:"companyId"`
OperaterId int `json:"operaterId"`
CycleId int `json:"cycleId,string"`
BeginDay string `json:"beginDay"`
TargetUserName string `json:"targetUserName"`
TargetUserId []string `json:"targetUserId"`
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
}
... ...
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,142 @@ 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())
}
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,
})
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())
... ... @@ -79,11 +220,220 @@ 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,
})
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
}
... ...
... ... @@ -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,14 @@ 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"`
ContentId int `json:"contentId"`
TargetUserId string `json:"targetUserId"` //被评估人的id
TargetUserName string `json:"targetUserName"` //被评估人的名称
BeginDay string `json:"beginDay"` //评估的日期
... ... @@ -167,17 +169,19 @@ type UserAssessContent struct {
}
type SearchConditin1 struct {
CompanyId int //公司id
CycleId int //周期id
BeginDay string //评估的日期
TargetUserName string //被评估人的名称
Limit int //分页
Offset int //分页
OperaterId int //用户的id是谁在搜索数据
Hrbp int //
CompanyId int //公司id
AssessId int //评估任务id
CycleId int //周期id
BeginDay string //评估的日期
TargetUserName string //被评估人的名称
TargetUserId []string //查询指定的人
Limit int //分页
Offset int //分页
OperaterId int //用户的id是谁在搜索数据
Hrbp int //
}
//根据周期的id和日期获取员工填写的评估内容
//项目管理-成员列表 根据周期的id和日期获取员工填写的评估内容
//companyId int 公司id
//cycleId int, 评估周期id
//userId int, 用户id,谁要查看数据
... ... @@ -186,18 +190,26 @@ type SearchConditin1 struct {
//limit int, 分页条数
//offset int 分页偏移
func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserAssessContent, error) {
if param.Offset < 0 {
param.Offset = 0
}
if param.Limit < 0 {
param.Limit = 20
}
sqlStr := ` 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.assess_id,staff_assess_content.id as content_id,
staff_assess_content.value ,staff_assess_content.sort_by ,
staff_assess_content.category ,staff_assess_content."name" as content_name ,
staff_assess_content.weight
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
`
condition := []interface{}{}
if len(param.TargetUserName) > 0 {
sqlStr += ` where t_staff_assess_1.target_user_name like ? `
condition = append(condition, param.TargetUserName)
sqlStr += ` and t_staff_assess_1.target_user_name like ? `
condition = append(condition, "%"+param.TargetUserName+"%")
}
//加入排序
sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
... ... @@ -206,11 +218,11 @@ func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserA
sqlStr = sqlStr0 + sqlStr
tx := d.transactionContext.PgTx
var result []UserAssessContent
_, err := tx.QueryOne(&result, sqlStr, condition...)
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
//根据周期的id和日期获取员工填写的评估内容,数量统计
//项目管理-成员列表 根据周期的id和日期获取员工填写的评估内容,数量统计
//companyId int 公司id
//cycleId int, 评估周期id
//userId int, 用户id,谁要查看数据
... ... @@ -218,28 +230,19 @@ func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserA
//hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
//limit int, 分页条数
//offset int 分页偏移
func (d *StaffAssessDao) CountUserAssess(param SearchConditin1) ([]UserAssessContent, error) {
sqlStr := ` select
t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
staff_assess_content.value ,staff_assess_content.sort_by ,
staff_assess_content.category ,staff_assess_content."name" as content_name ,
staff_assess_content.weight
from t_staff_assess_1
left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
`
func (d *StaffAssessDao) CountUserAssess(param SearchConditin1) (int, error) {
sqlStr := ` select count(*) from t_staff_assess_1 where 1=1 `
condition := []interface{}{}
if len(param.TargetUserName) > 0 {
sqlStr += ` where t_staff_assess_1.target_user_name like ? `
condition = append(condition, param.TargetUserName)
sqlStr += ` and t_staff_assess_1.target_user_name like ? `
condition = append(condition, "%"+param.TargetUserName+"%")
}
//加入排序
sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
//获取前置sql语句
sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset)
sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, 5000, 0)
sqlStr = sqlStr0 + sqlStr
tx := d.transactionContext.PgTx
var result []UserAssessContent
_, err := tx.QueryOne(&result, sqlStr, condition...)
var result int
_, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
return result, err
}
... ... @@ -323,3 +326,57 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
sqlstr = fmt.Sprintf(sqlstr, params...)
return sqlstr
}
type ExportData1 struct {
AssessId string
ContentId int
TargetUserId string //被评估人的id
TargetUserName string //被评估人的名称
BeginDay string //评估的日期
EvaluationProjectId string //项目id
Value string //评估填写的值
SortBy int //评估项顺序
Category string //评估项分类
ContentName string //评估项名称
Weight int //权重
PromptText string //评估标准
Remark []domain.AssessContemtRemark
}
//项目管理-成员列表 导出数据
func (d *StaffAssessDao) ExportDataUserAssess(param SearchConditin1) ([]ExportData1, error) {
if param.Offset < 0 {
param.Offset = 0
}
if param.Limit < 0 {
param.Limit = 5000
}
sqlStr := ` 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.assess_id,staff_assess_content.id as content_id,
staff_assess_content.value ,staff_assess_content.sort_by ,
staff_assess_content.category ,staff_assess_content."name" as content_name ,
staff_assess_content.weight,staff_assess_content.prompt_text ,staff_assess_content.remark
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
`
condition := []interface{}{}
if len(param.TargetUserName) > 0 {
sqlStr += ` and t_staff_assess_1.target_user_name like ? `
condition = append(condition, "%"+param.TargetUserName+"%")
}
if len(param.TargetUserId) > 0 {
sqlStr += ` and t_staff_assess_1.target_user_id in (?) `
condition = append(condition, pg.In(param.TargetUserId))
}
//加入排序
sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
//获取前置sql语句
sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset)
sqlStr = sqlStr0 + sqlStr
tx := d.transactionContext.PgTx
var result []ExportData1
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
... ...
... ... @@ -3,13 +3,14 @@ package repository
import (
"errors"
"fmt"
"time"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"time"
)
type RoleRepository struct {
... ... @@ -117,6 +118,10 @@ func (repo *RoleRepository) Find(queryOptions map[string]interface{}) (int64, []
query.Where("name = ?", v)
}
if v, ok := queryOptions["type"]; ok {
query.Where("type=?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
}
... ...
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"
... ... @@ -283,15 +285,7 @@ func (c *StaffAssessController) ListTargetUserMeSupperAssess() {
//获取周期列表
func (c *StaffAssessController) ListAssessCycle() {
srv := service.NewStaffAssessServeice()
// paramReq := &query.ListTargetUserAssessQuery{}
// 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)
data, err := srv.ListAllAssessCycle(int(userReq.CompanyId))
c.Response(data, err)
}
... ... @@ -311,3 +305,46 @@ func (c *StaffAssessController) ListAssessCycleDay() {
data, err := srv.ListAllAssessCycleDay(paramReq)
c.Response(data, err)
}
//根据周期里的考核日期,获取员工填写评估内容列表
func (c *StaffAssessController) ListAssessContentCycleDay() {
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.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,11 +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("/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",
... ...
ALTER TABLE public.staff_assess_content ADD score_value float8 NULL DEFAULT 0;
ALTER TABLE public.staff_assess_content ADD level_value varchar NULL;
... ...