作者 tangxvhui

Merge branch 'test'

@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 "type": "go", 10 "type": "go",
11 "request": "launch", 11 "request": "launch",
12 "mode": "debug", 12 "mode": "debug",
13 - "buildFlags": "--tags=local", 13 + "buildFlags": "",
14 "program": "./main.go" 14 "program": "./main.go"
15 }, 15 },
16 ] 16 ]
@@ -173,6 +173,19 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i @@ -173,6 +173,19 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
173 ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext}) 173 ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
174 userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) 174 userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
175 175
  176 + // 查询系统默认规则
  177 + _, sysRules, err := ruleRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "sysType": domain.EvaluationSysTypeSystem, "limit": 1})
  178 + if err != nil {
  179 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  180 + }
  181 + // 不存在,生成默认规则
  182 + if len(sysRules) == 0 {
  183 + newRule := domain.GenerateSysRule(in.CompanyId)
  184 + if _, err := ruleRepository.Insert(newRule); err != nil {
  185 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  186 + }
  187 + }
  188 +
176 total, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in)) 189 total, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
177 if err != nil { 190 if err != nil {
178 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 191 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -180,31 +193,11 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i @@ -180,31 +193,11 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
180 193
181 ras := make([]*adapter.RuleAdapter, 0) 194 ras := make([]*adapter.RuleAdapter, 0)
182 creatorIds := make([]int64, 0) 195 creatorIds := make([]int64, 0)
183 - var havaSystemType = false  
184 for i := range rules { 196 for i := range rules {
185 ra := &adapter.RuleAdapter{} 197 ra := &adapter.RuleAdapter{}
186 ra.EvaluationRule = rules[i] 198 ra.EvaluationRule = rules[i]
187 ras = append(ras, ra) 199 ras = append(ras, ra)
188 creatorIds = append(creatorIds, rules[i].CreatorId) 200 creatorIds = append(creatorIds, rules[i].CreatorId)
189 -  
190 - if rules[i].SysType == domain.EvaluationSysTypeSystem {  
191 - havaSystemType = true  
192 - break  
193 - }  
194 - }  
195 -  
196 - // 如果不存在系统默认就生成一个  
197 - if !havaSystemType {  
198 - newRule := domain.GenerateSysRule(in.CompanyId)  
199 - rule, err := ruleRepository.Insert(newRule)  
200 - if err != nil {  
201 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
202 - }  
203 - ra := &adapter.RuleAdapter{}  
204 - ra.EvaluationRule = rule  
205 - ras = append(ras, ra)  
206 -  
207 - total += 1  
208 } 201 }
209 202
210 _, users, _ := userRepository.Find(map[string]interface{}{"ids": creatorIds, "limit": len(creatorIds)}) 203 _, users, _ := userRepository.Find(map[string]interface{}{"ids": creatorIds, "limit": len(creatorIds)})
@@ -218,7 +211,6 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i @@ -218,7 +211,6 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
218 if v, ok := userNameMap[ras[i].CreatorId]; ok { 211 if v, ok := userNameMap[ras[i].CreatorId]; ok {
219 ras[i].CreatorName = v 212 ras[i].CreatorName = v
220 } 213 }
221 -  
222 } 214 }
223 215
224 if err := transactionContext.CommitTransaction(); err != nil { 216 if err := transactionContext.CommitTransaction(); err != nil {
@@ -99,16 +99,16 @@ func (rs *NodeTaskService) SendEvaluationNode() error { @@ -99,16 +99,16 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
99 task.NextSentAt = &nextTime 99 task.NextSentAt = &nextTime
100 } 100 }
101 101
102 - // 下个周期的起始时间=当前周期的截止时间 102 + // 周期的截至时间=下一个周期的开始时间-1秒
103 if task.NextSentAt == nil { 103 if task.NextSentAt == nil {
104 cycleTimeEnd = maxTime 104 cycleTimeEnd = maxTime
105 } else { 105 } else {
106 - cycleTimeEnd = task.NextSentAt.Local() 106 + cycleTimeEnd = task.NextSentAt.Local().Add(-1 * time.Second)
107 } 107 }
108 108
109 // 格式化周期的起始和截止时间 109 // 格式化周期的起始和截止时间
110 - fmCycleStartTime := cycleTimeStart.Format("2006-1-2 15:04:05")  
111 - fmCycleTimeEnd := cycleTimeEnd.Format("2006-1-2 15:04:05") 110 + fmCycleStartTime := cycleTimeStart.Format("2006-01-02 15:04:05")
  111 + fmCycleTimeEnd := cycleTimeEnd.Format("2006-01-02 15:04:05")
112 112
113 csat := &command.CreateStaffAssessTask{ 113 csat := &command.CreateStaffAssessTask{
114 CompanyId: int(project.CompanyId), 114 CompanyId: int(project.CompanyId),
  1 +package adapter
  2 +
  3 +type ListUserAssessContent struct {
  4 + TableHeader []ListTableHeader `json:"tableHeader"`
  5 + List []map[string]string `json:"list"`
  6 + Total int `json:"total"`
  7 +}
1 package query 1 package query
2 2
3 type ListAssessContentCycleDay struct { 3 type ListAssessContentCycleDay struct {
4 - CompanyId int `json:"companyId"`  
5 - OperaterId int `json:"operaterId"`  
6 - CycleId int `json:"cycleId,string"`  
7 - BeginDay string `json:"beginDay"`  
8 - TargetUserName string `json:"targetUserName"`  
9 - PageNumber int `json:"pageNumber"`  
10 - PageSize int `json:"pageSize"` 4 + CompanyId int `json:"companyId"`
  5 + OperaterId int `json:"operaterId"`
  6 + CycleId int `json:"cycleId,string"`
  7 + BeginDay string `json:"beginDay"`
  8 + TargetUserName string `json:"targetUserName"`
  9 + TargetUserId []string `json:"targetUserId"`
  10 + PageNumber int `json:"pageNumber"`
  11 + PageSize int `json:"pageSize"`
11 } 12 }
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "fmt"
  5 + "strconv"
  6 + "strings"
  7 +
4 "github.com/linmadan/egglib-go/core/application" 8 "github.com/linmadan/egglib-go/core/application"
  9 + "github.com/xuri/excelize/v2"
5 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  11 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query" 12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
  13 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao" 14 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
8 ) 15 )
9 16
@@ -67,8 +74,142 @@ func (srv StaffAssessServeice) ListAllAssessCycleDay(param *query.ListAssessCycl @@ -67,8 +74,142 @@ func (srv StaffAssessServeice) ListAllAssessCycleDay(param *query.ListAssessCycl
67 } 74 }
68 75
69 //根据周期id和日期获取 员工填写评估内容 76 //根据周期id和日期获取 员工填写评估内容
70 -// 有过滤查看权限  
71 -func (srv StaffAssessServeice) ListAllAssessContentCycleDay(param *query.ListAssessContentCycleDay) (map[string]interface{}, error) { 77 +//有过滤查看权限
  78 +func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAssessContentCycleDay) (*adapter.ListUserAssessContent, error) {
  79 + transactionContext, err := factory.CreateTransactionContext(nil)
  80 + if err != nil {
  81 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  82 + }
  83 + if err := transactionContext.StartTransaction(); err != nil {
  84 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  85 + }
  86 + defer func() {
  87 + _ = transactionContext.RollbackTransaction()
  88 + }()
  89 +
  90 + roleRepo := factory.CreateRoleRepository(map[string]interface{}{
  91 + "transactionContext": transactionContext,
  92 + })
  93 + roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{
  94 + "transactionContext": transactionContext,
  95 + })
  96 + _, roleList, err := roleRepo.Find(map[string]interface{}{
  97 + "type": domain.RoleTypeSystem,
  98 + "companyId": param.CompanyId,
  99 + })
  100 + if err != nil {
  101 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
  102 + }
  103 + _, userRoleList, err := roleUserRepo.Find(map[string]interface{}{
  104 + "companyId": param.CompanyId,
  105 + "userId": param.OperaterId,
  106 + })
  107 + if err != nil {
  108 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
  109 + }
  110 + hrbp := -1
  111 + for _, v := range userRoleList {
  112 + for _, v2 := range roleList {
  113 + if v.RoleId == v2.Id {
  114 + hrbp = 1
  115 + break
  116 + }
  117 + }
  118 + if hrbp == 1 {
  119 + break
  120 + }
  121 + }
  122 + assessDao := dao.NewStaffAssessDao(map[string]interface{}{
  123 + "transactionContext": transactionContext,
  124 + })
  125 +
  126 + limit := param.PageSize
  127 + offset := (param.PageNumber - 1) * limit
  128 + cnt, err := assessDao.CountUserAssess(dao.SearchConditin1{
  129 + CompanyId: param.CompanyId,
  130 + CycleId: param.CycleId,
  131 + BeginDay: param.BeginDay,
  132 + TargetUserName: param.TargetUserName,
  133 + Limit: 5000,
  134 + Offset: 0,
  135 + OperaterId: param.OperaterId,
  136 + Hrbp: hrbp,
  137 + })
  138 + if err != nil {
  139 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计总数"+err.Error())
  140 + }
  141 + contentList, err := assessDao.SearchUserAssessContent(dao.SearchConditin1{
  142 + CompanyId: param.CompanyId,
  143 + CycleId: param.CycleId,
  144 + BeginDay: param.BeginDay,
  145 + TargetUserName: param.TargetUserName,
  146 + Limit: limit,
  147 + Offset: offset,
  148 + OperaterId: param.OperaterId,
  149 + Hrbp: hrbp,
  150 + })
  151 + if err != nil {
  152 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取数据列表"+err.Error())
  153 + }
  154 + if err := transactionContext.CommitTransaction(); err != nil {
  155 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  156 + }
  157 +
  158 + //可变的表格列
  159 + changeableHeader := []adapter.ListTableHeader{
  160 + {Key: "targetUserName", Name: "姓名"}, //固定列
  161 + }
  162 + //过滤重复的列
  163 + headerMap := map[string]string{}
  164 + // 获取已经填报的内容
  165 + changeableRows := map[string]map[string]string{}
  166 + tableSort := []string{} //确定列表行数据的顺序
  167 + for i, v := range contentList {
  168 + if _, ok := changeableRows[v.TargetUserId]; !ok {
  169 + changeableRows[v.TargetUserId] = map[string]string{}
  170 + tableSort = append(tableSort, v.TargetUserId)
  171 + }
  172 + changeableRows[v.TargetUserId]["targetUserName"] = v.TargetUserName
  173 + changeableRows[v.TargetUserId]["targetUserId"] = v.TargetUserId
  174 + if v.ContentId > 0 {
  175 + name := fmt.Sprintf("%s-%s", v.Category, v.ContentName)
  176 + key := fmt.Sprintf("k%d", i)
  177 + if _, ok := headerMap[name]; !ok {
  178 + changeableHeader = append(changeableHeader, adapter.ListTableHeader{
  179 + Key: key, Name: name,
  180 + })
  181 + headerMap[name] = key
  182 + }
  183 + key = headerMap[name]
  184 + changeableRows[v.TargetUserId][key] = v.Value
  185 + }
  186 + }
  187 + list := []map[string]string{}
  188 + for _, v := range tableSort {
  189 + for _, v2 := range changeableHeader {
  190 + if _, ok := changeableRows[v][v2.Key]; ok {
  191 + continue
  192 + }
  193 + changeableRows[v][v2.Key] = ""
  194 + }
  195 + list = append(list, changeableRows[v])
  196 + }
  197 + result := adapter.ListUserAssessContent{
  198 + TableHeader: changeableHeader,
  199 + Total: cnt,
  200 + List: list,
  201 + }
  202 + return &result, nil
  203 +}
  204 +
  205 +type excelTableHeader struct {
  206 + Level1 string
  207 + Level2 string
  208 + Level3 string
  209 + Level4 string
  210 +}
  211 +
  212 +func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCycleDay) (*excelize.File, error) {
72 transactionContext, err := factory.CreateTransactionContext(nil) 213 transactionContext, err := factory.CreateTransactionContext(nil)
73 if err != nil { 214 if err != nil {
74 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 215 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -79,11 +220,220 @@ func (srv StaffAssessServeice) ListAllAssessContentCycleDay(param *query.ListAss @@ -79,11 +220,220 @@ func (srv StaffAssessServeice) ListAllAssessContentCycleDay(param *query.ListAss
79 defer func() { 220 defer func() {
80 _ = transactionContext.RollbackTransaction() 221 _ = transactionContext.RollbackTransaction()
81 }() 222 }()
82 - // assessDao := dao.NewStaffAssessDao(map[string]interface{}{  
83 - // "transactionContext": transactionContext,  
84 - // }) 223 +
  224 + roleRepo := factory.CreateRoleRepository(map[string]interface{}{
  225 + "transactionContext": transactionContext,
  226 + })
  227 + roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{
  228 + "transactionContext": transactionContext,
  229 + })
  230 + _, roleList, err := roleRepo.Find(map[string]interface{}{
  231 + "type": domain.RoleTypeSystem,
  232 + "companyId": param.CompanyId,
  233 + })
  234 + if err != nil {
  235 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
  236 + }
  237 + _, userRoleList, err := roleUserRepo.Find(map[string]interface{}{
  238 + "companyId": param.CompanyId,
  239 + "userId": param.OperaterId,
  240 + })
  241 + if err != nil {
  242 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
  243 + }
  244 + hrbp := -1
  245 + for _, v := range userRoleList {
  246 + for _, v2 := range roleList {
  247 + if v.RoleId == v2.Id {
  248 + hrbp = 1
  249 + break
  250 + }
  251 + }
  252 + if hrbp == 1 {
  253 + break
  254 + }
  255 + }
  256 + assessDao := dao.NewStaffAssessDao(map[string]interface{}{
  257 + "transactionContext": transactionContext,
  258 + })
  259 + contentList, err := assessDao.ExportDataUserAssess(dao.SearchConditin1{
  260 + CompanyId: param.CompanyId,
  261 + CycleId: param.CycleId,
  262 + BeginDay: param.BeginDay,
  263 + TargetUserName: param.TargetUserName,
  264 + Limit: 5000,
  265 + Offset: 0,
  266 + OperaterId: param.OperaterId,
  267 + Hrbp: hrbp,
  268 + })
  269 + if err != nil {
  270 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取数据列表"+err.Error())
  271 + }
  272 +
85 if err := transactionContext.CommitTransaction(); err != nil { 273 if err := transactionContext.CommitTransaction(); err != nil {
86 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 274 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
87 } 275 }
88 - return nil, nil 276 +
  277 + //处理查询到的数据
  278 + //汇总 Excel表格的表头描述
  279 + level1 := []string{} //分类
  280 + level3 := map[string][]string{} // key=分类+得分项类型 val=名称
  281 + level4 := map[string]string{} //key=分类+名称 val=评估标准
  282 + for _, v := range contentList {
  283 + if v.ContentId == 0 {
  284 + continue
  285 + }
  286 + level1Item := ""
  287 + for _, v1 := range level1 {
  288 + if v.Category == v1 {
  289 + level1Item = v1
  290 + }
  291 + }
  292 + if len(level1Item) == 0 {
  293 + level1 = append(level1, v.Category)
  294 + }
  295 + if v.Weight == 0 {
  296 + level3Key := v.Category + "-加分项"
  297 + if _, ok := level3[level3Key]; !ok {
  298 + level3[level3Key] = []string{}
  299 + }
  300 + level3Item := ""
  301 + for _, v3 := range level3[level3Key] {
  302 + if v3 == v.ContentName {
  303 + level3Item = v.ContentName
  304 + }
  305 + }
  306 + if len(level3Item) == 0 {
  307 + level3[level3Key] = append(level3[level3Key], v.ContentName)
  308 + }
  309 + }
  310 + if v.Weight > 0 {
  311 + level3Key := v.Category + "-得分项"
  312 + if _, ok := level3[level3Key]; !ok {
  313 + level3[level3Key] = []string{}
  314 + }
  315 + level3Item := ""
  316 + for _, v3 := range level3[level3Key] {
  317 + if v3 == v.ContentName {
  318 + level3Item = v.ContentName
  319 + }
  320 + }
  321 + if len(level3Item) == 0 {
  322 + level3[level3Key] = append(level3[level3Key], v.ContentName)
  323 + }
  324 + }
  325 +
  326 + level4Key := v.Category + "+" + v.ContentName
  327 + if _, ok := level4[level4Key]; !ok {
  328 + level4[level4Key] = v.PromptText
  329 + }
  330 + }
  331 + //汇总表头,按列
  332 + headerList := []excelTableHeader{
  333 + {
  334 + Level1: "日期",
  335 + Level2: "",
  336 + Level3: "",
  337 + Level4: "评估标准",
  338 + }, {
  339 + Level1: "姓名",
  340 + Level2: "",
  341 + Level3: "",
  342 + Level4: "",
  343 + },
  344 + }
  345 + for _, v := range level1 {
  346 + item := excelTableHeader{
  347 + Level1: v,
  348 + }
  349 + level3Key := v + "-加分项"
  350 + if _, ok := level3[level3Key]; ok {
  351 + for _, v2 := range level3[level3Key] {
  352 + item.Level2 = "加分项"
  353 + item.Level3 = v2
  354 + level4Key := v + "+" + v2
  355 + item.Level4 = level4[level4Key]
  356 + headerList = append(headerList, item)
  357 + }
  358 + }
  359 + level3Key = v + "-得分项"
  360 + if _, ok := level3[level3Key]; ok {
  361 + for _, v2 := range level3[level3Key] {
  362 + item.Level2 = "得分项"
  363 + item.Level3 = v2
  364 + level4Key := v + "+" + v2
  365 + item.Level4 = level4[level4Key]
  366 + headerList = append(headerList, item)
  367 + }
  368 + }
  369 + }
  370 + //数据形式 进行 行列转换
  371 + tableRows := map[string]map[string]string{}
  372 + tableRowSort := []string{}
  373 + for _, v := range contentList {
  374 + if _, ok := tableRows[v.TargetUserId]; !ok {
  375 + tableRows[v.TargetUserId] = map[string]string{}
  376 + tableRowSort = append(tableRowSort, v.TargetUserId)
  377 + }
  378 + tableRows[v.TargetUserId]["TargetUserName"] = v.TargetUserName
  379 + tableRows[v.TargetUserId]["BeginDay"] = v.BeginDay
  380 + if v.ContentId > 0 {
  381 + value := []string{v.Value}
  382 + for _, v2 := range v.Remark {
  383 + value = append(value, v2.RemarkText)
  384 + }
  385 + key := v.Category + "+" + v.ContentName
  386 + tableRows[v.TargetUserId][key] = strings.Join(value, "\n")
  387 + }
  388 + }
  389 + //将数据写入xlsx
  390 + xlsxFile := excelize.NewFile()
  391 + sheetIndex := xlsxFile.GetActiveSheetIndex()
  392 + sheetName := xlsxFile.GetSheetName(sheetIndex)
  393 + //写入第一行
  394 + xlsxFile.SetCellStr(sheetName, "A1", "每日绩效汇总")
  395 + //写入二到五行
  396 + for k, v := range headerList {
  397 + colName, _ := excelize.ColumnNumberToName(k + 1)
  398 + xlsxFile.SetCellStr(sheetName, colName+"2", v.Level1)
  399 + xlsxFile.SetCellStr(sheetName, colName+"3", v.Level2)
  400 + xlsxFile.SetCellStr(sheetName, colName+"4", v.Level3)
  401 + xlsxFile.SetCellStr(sheetName, colName+"5", v.Level4)
  402 + }
  403 + //从第六行开始写入用户填写的评估数据
  404 + for k, v := range tableRowSort {
  405 + rowNum := strconv.Itoa(k + 6)
  406 + row := tableRows[v]
  407 + for k2, v2 := range headerList {
  408 + if k2 == 0 {
  409 + xlsxFile.SetCellStr(sheetName, "A"+rowNum, row["BeginDay"])
  410 + continue
  411 + }
  412 + if k2 == 1 {
  413 + xlsxFile.SetCellStr(sheetName, "B"+rowNum, row["TargetUserName"])
  414 + continue
  415 + }
  416 + colName, _ := excelize.ColumnNumberToName(k2 + 1)
  417 + key := v2.Level1 + "+" + v2.Level3
  418 + if mVal, ok := row[key]; ok {
  419 + xlsxFile.SetCellStr(sheetName, colName+rowNum, mVal)
  420 + }
  421 + }
  422 + }
  423 + //TODO 调整样式
  424 + xlsxFile.MergeCell(sheetName, "A2", "A4")
  425 + xlsxFile.MergeCell(sheetName, "B2", "B4")
  426 + xlsxFile.MergeCell(sheetName, "B5", "B5")
  427 + //设置行高
  428 + for i := range tableRowSort {
  429 + xlsxFile.SetRowHeight(sheetName, i+5, 50)
  430 + }
  431 + //设置列宽
  432 + for i := range headerList {
  433 + colName, _ := excelize.ColumnNumberToName(i + 1)
  434 + if i == 0 {
  435 + xlsxFile.SetColWidth(sheetName, colName, colName, 30)
  436 + }
  437 + }
  438 + return xlsxFile, nil
89 } 439 }
@@ -124,7 +124,7 @@ func (d *StaffAssessDao) AllAssessCycleList(companyId int) ([]AssessCycle, error @@ -124,7 +124,7 @@ func (d *StaffAssessDao) AllAssessCycleList(companyId int) ([]AssessCycle, error
124 companyId, 124 companyId,
125 } 125 }
126 result := []AssessCycle{} 126 result := []AssessCycle{}
127 - _, err := tx.QueryOne(&result, sqlStr, condition...) 127 + _, err := tx.Query(&result, sqlStr, condition...)
128 return result, err 128 return result, err
129 } 129 }
130 130
@@ -149,12 +149,14 @@ func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]As @@ -149,12 +149,14 @@ func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]As
149 cycleId, companyId, 149 cycleId, companyId,
150 } 150 }
151 result := []AssessCycleDay{} 151 result := []AssessCycleDay{}
152 - _, err := tx.QueryOne(&result, sqlStr, condition...) 152 + _, err := tx.Query(&result, sqlStr, condition...)
153 return result, err 153 return result, err
154 } 154 }
155 155
156 //获取员工填写评估内容 156 //获取员工填写评估内容
157 type UserAssessContent struct { 157 type UserAssessContent struct {
  158 + AssessId string `json:"assessId"`
  159 + ContentId int `json:"contentId"`
158 TargetUserId string `json:"targetUserId"` //被评估人的id 160 TargetUserId string `json:"targetUserId"` //被评估人的id
159 TargetUserName string `json:"targetUserName"` //被评估人的名称 161 TargetUserName string `json:"targetUserName"` //被评估人的名称
160 BeginDay string `json:"beginDay"` //评估的日期 162 BeginDay string `json:"beginDay"` //评估的日期
@@ -167,17 +169,19 @@ type UserAssessContent struct { @@ -167,17 +169,19 @@ type UserAssessContent struct {
167 } 169 }
168 170
169 type SearchConditin1 struct { 171 type SearchConditin1 struct {
170 - CompanyId int //公司id  
171 - CycleId int //周期id  
172 - BeginDay string //评估的日期  
173 - TargetUserName string //被评估人的名称  
174 - Limit int //分页  
175 - Offset int //分页  
176 - OperaterId int //用户的id是谁在搜索数据  
177 - Hrbp int // 172 + CompanyId int //公司id
  173 + AssessId int //评估任务id
  174 + CycleId int //周期id
  175 + BeginDay string //评估的日期
  176 + TargetUserName string //被评估人的名称
  177 + TargetUserId []string //查询指定的人
  178 + Limit int //分页
  179 + Offset int //分页
  180 + OperaterId int //用户的id是谁在搜索数据
  181 + Hrbp int //
178 } 182 }
179 183
180 -//根据周期的id和日期获取员工填写的评估内容 184 +//项目管理-成员列表 根据周期的id和日期获取员工填写的评估内容
181 //companyId int 公司id 185 //companyId int 公司id
182 //cycleId int, 评估周期id 186 //cycleId int, 评估周期id
183 //userId int, 用户id,谁要查看数据 187 //userId int, 用户id,谁要查看数据
@@ -186,18 +190,26 @@ type SearchConditin1 struct { @@ -186,18 +190,26 @@ type SearchConditin1 struct {
186 //limit int, 分页条数 190 //limit int, 分页条数
187 //offset int 分页偏移 191 //offset int 分页偏移
188 func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserAssessContent, error) { 192 func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserAssessContent, error) {
  193 + if param.Offset < 0 {
  194 + param.Offset = 0
  195 + }
  196 + if param.Limit < 0 {
  197 + param.Limit = 20
  198 + }
189 sqlStr := ` select 199 sqlStr := ` select
190 t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day, 200 t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
  201 + t_staff_assess_1.assess_id,staff_assess_content.id as content_id,
191 staff_assess_content.value ,staff_assess_content.sort_by , 202 staff_assess_content.value ,staff_assess_content.sort_by ,
192 staff_assess_content.category ,staff_assess_content."name" as content_name , 203 staff_assess_content.category ,staff_assess_content."name" as content_name ,
193 staff_assess_content.weight 204 staff_assess_content.weight
194 from t_staff_assess_1 205 from t_staff_assess_1
195 left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id 206 left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
  207 + where 1=1
196 ` 208 `
197 condition := []interface{}{} 209 condition := []interface{}{}
198 if len(param.TargetUserName) > 0 { 210 if len(param.TargetUserName) > 0 {
199 - sqlStr += ` where t_staff_assess_1.target_user_name like ? `  
200 - condition = append(condition, param.TargetUserName) 211 + sqlStr += ` and t_staff_assess_1.target_user_name like ? `
  212 + condition = append(condition, "%"+param.TargetUserName+"%")
201 } 213 }
202 //加入排序 214 //加入排序
203 sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by ` 215 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 @@ -206,11 +218,11 @@ func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserA
206 sqlStr = sqlStr0 + sqlStr 218 sqlStr = sqlStr0 + sqlStr
207 tx := d.transactionContext.PgTx 219 tx := d.transactionContext.PgTx
208 var result []UserAssessContent 220 var result []UserAssessContent
209 - _, err := tx.QueryOne(&result, sqlStr, condition...) 221 + _, err := tx.Query(&result, sqlStr, condition...)
210 return result, err 222 return result, err
211 } 223 }
212 224
213 -//根据周期的id和日期获取员工填写的评估内容,数量统计 225 +//项目管理-成员列表 根据周期的id和日期获取员工填写的评估内容,数量统计
214 //companyId int 公司id 226 //companyId int 公司id
215 //cycleId int, 评估周期id 227 //cycleId int, 评估周期id
216 //userId int, 用户id,谁要查看数据 228 //userId int, 用户id,谁要查看数据
@@ -218,28 +230,19 @@ func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserA @@ -218,28 +230,19 @@ func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserA
218 //hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否 230 //hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
219 //limit int, 分页条数 231 //limit int, 分页条数
220 //offset int 分页偏移 232 //offset int 分页偏移
221 -func (d *StaffAssessDao) CountUserAssess(param SearchConditin1) ([]UserAssessContent, error) {  
222 - sqlStr := ` select  
223 - t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,  
224 - staff_assess_content.value ,staff_assess_content.sort_by ,  
225 - staff_assess_content.category ,staff_assess_content."name" as content_name ,  
226 - staff_assess_content.weight  
227 - from t_staff_assess_1  
228 - left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id  
229 - ` 233 +func (d *StaffAssessDao) CountUserAssess(param SearchConditin1) (int, error) {
  234 + sqlStr := ` select count(*) from t_staff_assess_1 where 1=1 `
230 condition := []interface{}{} 235 condition := []interface{}{}
231 if len(param.TargetUserName) > 0 { 236 if len(param.TargetUserName) > 0 {
232 - sqlStr += ` where t_staff_assess_1.target_user_name like ? `  
233 - condition = append(condition, param.TargetUserName) 237 + sqlStr += ` and t_staff_assess_1.target_user_name like ? `
  238 + condition = append(condition, "%"+param.TargetUserName+"%")
234 } 239 }
235 - //加入排序  
236 - sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `  
237 //获取前置sql语句 240 //获取前置sql语句
238 - sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset) 241 + sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, 5000, 0)
239 sqlStr = sqlStr0 + sqlStr 242 sqlStr = sqlStr0 + sqlStr
240 tx := d.transactionContext.PgTx 243 tx := d.transactionContext.PgTx
241 - var result []UserAssessContent  
242 - _, err := tx.QueryOne(&result, sqlStr, condition...) 244 + var result int
  245 + _, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
243 return result, err 246 return result, err
244 } 247 }
245 248
@@ -323,3 +326,57 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, @@ -323,3 +326,57 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
323 sqlstr = fmt.Sprintf(sqlstr, params...) 326 sqlstr = fmt.Sprintf(sqlstr, params...)
324 return sqlstr 327 return sqlstr
325 } 328 }
  329 +
  330 +type ExportData1 struct {
  331 + AssessId string
  332 + ContentId int
  333 + TargetUserId string //被评估人的id
  334 + TargetUserName string //被评估人的名称
  335 + BeginDay string //评估的日期
  336 + EvaluationProjectId string //项目id
  337 + Value string //评估填写的值
  338 + SortBy int //评估项顺序
  339 + Category string //评估项分类
  340 + ContentName string //评估项名称
  341 + Weight int //权重
  342 + PromptText string //评估标准
  343 + Remark []domain.AssessContemtRemark
  344 +}
  345 +
  346 +//项目管理-成员列表 导出数据
  347 +func (d *StaffAssessDao) ExportDataUserAssess(param SearchConditin1) ([]ExportData1, error) {
  348 + if param.Offset < 0 {
  349 + param.Offset = 0
  350 + }
  351 + if param.Limit < 0 {
  352 + param.Limit = 5000
  353 + }
  354 + sqlStr := ` select
  355 + t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
  356 + t_staff_assess_1.assess_id,staff_assess_content.id as content_id,
  357 + staff_assess_content.value ,staff_assess_content.sort_by ,
  358 + staff_assess_content.category ,staff_assess_content."name" as content_name ,
  359 + staff_assess_content.weight,staff_assess_content.prompt_text ,staff_assess_content.remark
  360 + from t_staff_assess_1
  361 + left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
  362 + where 1=1
  363 + `
  364 + condition := []interface{}{}
  365 + if len(param.TargetUserName) > 0 {
  366 + sqlStr += ` and t_staff_assess_1.target_user_name like ? `
  367 + condition = append(condition, "%"+param.TargetUserName+"%")
  368 + }
  369 + if len(param.TargetUserId) > 0 {
  370 + sqlStr += ` and t_staff_assess_1.target_user_id in (?) `
  371 + condition = append(condition, pg.In(param.TargetUserId))
  372 + }
  373 + //加入排序
  374 + sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
  375 + //获取前置sql语句
  376 + sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset)
  377 + sqlStr = sqlStr0 + sqlStr
  378 + tx := d.transactionContext.PgTx
  379 + var result []ExportData1
  380 + _, err := tx.Query(&result, sqlStr, condition...)
  381 + return result, err
  382 +}
@@ -3,13 +3,14 @@ package repository @@ -3,13 +3,14 @@ package repository
3 import ( 3 import (
4 "errors" 4 "errors"
5 "fmt" 5 "fmt"
  6 + "time"
  7 +
6 "github.com/go-pg/pg/v10" 8 "github.com/go-pg/pg/v10"
7 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 9 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 10 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" 12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils" 13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
12 - "time"  
13 ) 14 )
14 15
15 type RoleRepository struct { 16 type RoleRepository struct {
@@ -117,6 +118,10 @@ func (repo *RoleRepository) Find(queryOptions map[string]interface{}) (int64, [] @@ -117,6 +118,10 @@ func (repo *RoleRepository) Find(queryOptions map[string]interface{}) (int64, []
117 query.Where("name = ?", v) 118 query.Where("name = ?", v)
118 } 119 }
119 120
  121 + if v, ok := queryOptions["type"]; ok {
  122 + query.Where("type=?", v)
  123 + }
  124 +
120 if companyId, ok := queryOptions["companyId"]; ok { 125 if companyId, ok := queryOptions["companyId"]; ok {
121 query.Where("company_id = ?", companyId) 126 query.Where("company_id = ?", companyId)
122 } 127 }
1 package controllers 1 package controllers
2 2
3 import ( 3 import (
  4 + "fmt"
  5 +
4 "github.com/linmadan/egglib-go/core/application" 6 "github.com/linmadan/egglib-go/core/application"
5 "github.com/linmadan/egglib-go/web/beego" 7 "github.com/linmadan/egglib-go/web/beego"
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" 8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
@@ -283,15 +285,7 @@ func (c *StaffAssessController) ListTargetUserMeSupperAssess() { @@ -283,15 +285,7 @@ func (c *StaffAssessController) ListTargetUserMeSupperAssess() {
283 //获取周期列表 285 //获取周期列表
284 func (c *StaffAssessController) ListAssessCycle() { 286 func (c *StaffAssessController) ListAssessCycle() {
285 srv := service.NewStaffAssessServeice() 287 srv := service.NewStaffAssessServeice()
286 - // paramReq := &query.ListTargetUserAssessQuery{}  
287 - // err := c.BindJSON(paramReq)  
288 - // if err != nil {  
289 - // e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())  
290 - // c.Response(nil, e)  
291 - // return  
292 - // }  
293 userReq := middlewares.GetUser(c.Ctx) 288 userReq := middlewares.GetUser(c.Ctx)
294 -  
295 data, err := srv.ListAllAssessCycle(int(userReq.CompanyId)) 289 data, err := srv.ListAllAssessCycle(int(userReq.CompanyId))
296 c.Response(data, err) 290 c.Response(data, err)
297 } 291 }
@@ -311,3 +305,46 @@ func (c *StaffAssessController) ListAssessCycleDay() { @@ -311,3 +305,46 @@ func (c *StaffAssessController) ListAssessCycleDay() {
311 data, err := srv.ListAllAssessCycleDay(paramReq) 305 data, err := srv.ListAllAssessCycleDay(paramReq)
312 c.Response(data, err) 306 c.Response(data, err)
313 } 307 }
  308 +
  309 +//根据周期里的考核日期,获取员工填写评估内容列表
  310 +func (c *StaffAssessController) ListAssessContentCycleDay() {
  311 + srv := service.NewStaffAssessServeice()
  312 + paramReq := &query.ListAssessContentCycleDay{}
  313 + err := c.BindJSON(paramReq)
  314 + if err != nil {
  315 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  316 + c.Response(nil, e)
  317 + return
  318 + }
  319 + userReq := middlewares.GetUser(c.Ctx)
  320 + paramReq.CompanyId = int(userReq.CompanyId)
  321 + paramReq.OperaterId = int(userReq.UserId)
  322 + data, err := srv.ListUserAssessContentCycleDay(paramReq)
  323 + c.Response(data, err)
  324 +}
  325 +
  326 +//根据周期里的考核日期,获取员工填写评估内容列表,导出为xlsx文件
  327 +func (c *StaffAssessController) ExportAssessContentCycleDay() {
  328 + srv := service.NewStaffAssessServeice()
  329 + paramReq := &query.ListAssessContentCycleDay{}
  330 + err := c.BindJSON(paramReq)
  331 + if err != nil {
  332 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  333 + c.Response(nil, e)
  334 + return
  335 + }
  336 + userReq := middlewares.GetUser(c.Ctx)
  337 + paramReq.CompanyId = int(userReq.CompanyId)
  338 + paramReq.OperaterId = int(userReq.UserId)
  339 + data, err := srv.ExportUserAssess(paramReq)
  340 + if err != nil {
  341 + c.Response(nil, err)
  342 + }
  343 + fileName := fmt.Sprintf("每日绩效汇总%s", paramReq.BeginDay)
  344 + c.Ctx.Output.Header("Content-Disposition", "attachment;filename="+fileName)
  345 + c.Ctx.Output.Header("Content-Description", "FileTransfer")
  346 + c.Ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  347 + c.Ctx.Output.Header("Content-Transfer-Encoding", "binary")
  348 + c.Ctx.Output.Header("Expires", "0")
  349 + data.Write(c.Ctx.ResponseWriter)
  350 +}
1 package middlewares 1 package middlewares
2 2
3 import ( 3 import (
  4 + "strings"
  5 +
4 "github.com/beego/beego/v2/server/web/context" 6 "github.com/beego/beego/v2/server/web/context"
5 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" 7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
@@ -8,7 +10,17 @@ import ( @@ -8,7 +10,17 @@ import (
8 10
9 func CheckFontToken() func(ctx *context.Context) { 11 func CheckFontToken() func(ctx *context.Context) {
10 return func(ctx *context.Context) { 12 return func(ctx *context.Context) {
11 - adminToken := ctx.Input.Header("x-font-token") 13 + // adminToken := ctx.Input.Header("x-font-token")
  14 + // Bearer authorization_token
  15 + adminToken := ctx.Input.Header("Authorization")
  16 + //以一个空格" ",做切分
  17 + strList := strings.Split(adminToken, " ")
  18 + if len(strList) > 1 {
  19 + adminToken = strList[1]
  20 + }
  21 + if len(strList) == 1 {
  22 + adminToken = strList[0]
  23 + }
12 userAuth, err := (&domain.UserAuth{}).ParseAccessToken(adminToken) 24 userAuth, err := (&domain.UserAuth{}).ParseAccessToken(adminToken)
13 if err != nil || userAuth.UserId <= 0 { 25 if err != nil || userAuth.UserId <= 0 {
14 forbidden(ctx) 26 forbidden(ctx)
@@ -10,11 +10,13 @@ import ( @@ -10,11 +10,13 @@ import (
10 func init() { 10 func init() {
11 assessTaskNS := web.NewNamespace("/v1/staff-assess-task", 11 assessTaskNS := web.NewNamespace("/v1/staff-assess-task",
12 web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()), 12 web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()),
13 - web.NSCtrlPost("/search/me", (*controllers.StaffAssessController).SearchAssessTaskMe), //获取我参与过的评估项目列表  
14 - web.NSCtrlPost("/desc/me", (*controllers.StaffAssessController).AssessTaskMeDesc), //获取我的项目评估进度描述  
15 - web.NSCtrlPost("/", (*controllers.StaffAssessController).CreateStaffAssessTask), //创建员工的评估任务  
16 - web.NSCtrlGet("/cycle", (*controllers.StaffAssessController).ListAssessCycle), //获取周期列表  
17 - web.NSCtrlPost("/cycle/day", (*controllers.StaffAssessController).ListAssessCycleDay), //获取周期中的考核日期 13 + web.NSCtrlPost("/search/me", (*controllers.StaffAssessController).SearchAssessTaskMe), //获取我参与过的评估项目列表
  14 + web.NSCtrlPost("/desc/me", (*controllers.StaffAssessController).AssessTaskMeDesc), //获取我的项目评估进度描述
  15 + web.NSCtrlPost("/", (*controllers.StaffAssessController).CreateStaffAssessTask), //创建员工的评估任务
  16 + web.NSCtrlGet("/cycle", (*controllers.StaffAssessController).ListAssessCycle), //获取周期列表
  17 + web.NSCtrlPost("/cycle/day", (*controllers.StaffAssessController).ListAssessCycleDay), //获取周期中的考核日期
  18 + web.NSCtrlPost("/cycle/day/content", (*controllers.StaffAssessController).ListAssessContentCycleDay), //根据周期里的考核日期,获取员工填写评估内容列表
  19 + web.NSCtrlPost("/cycle/day/content/export", (*controllers.StaffAssessController).ExportAssessContentCycleDay), //根据周期里的考核日期,导出员工填写评估内容列表
18 ) 20 )
19 // /v1/staff-assess/self/me/list 21 // /v1/staff-assess/self/me/list
20 assessNS := web.NewNamespace("/v1/staff-assess", 22 assessNS := web.NewNamespace("/v1/staff-assess",
  1 +ALTER TABLE public.staff_assess_content ADD score_value float8 NULL DEFAULT 0;
  2 +ALTER TABLE public.staff_assess_content ADD level_value varchar NULL;