Merge branch 'test' of http://gitlab.fjmaimaimai.com/allied-creation/performance into test
正在显示
23 个修改的文件
包含
545 行增加
和
212 行删除
| 1 | -FROM golang:latest | 1 | +FROM 192.168.0.243:5000/mmm/performance-back:20221121test |
| 2 | #FROM 192.168.0.243:5000/mmm/digital-platform:20220831 | 2 | #FROM 192.168.0.243:5000/mmm/digital-platform:20220831 |
| 3 | ENV APP_DIR $GOPATH/src/performance | 3 | ENV APP_DIR $GOPATH/src/performance |
| 4 | RUN mkdir -p $APP_DIR | 4 | RUN mkdir -p $APP_DIR |
deploy/k8s/prd/.gitkeep
0 → 100644
deploy/k8s/prd/install.sh
0 → 100644
| 1 | +#!/bin/bash | ||
| 2 | +export PATH=/root/local/bin:$PATH | ||
| 3 | +kubectl -n mmm-suplus-prd get pods | grep -q performance-back | ||
| 4 | +if [ "$?" == "1" ];then | ||
| 5 | + kubectl create -f /tmp/prd/performance-back/performance-back.yaml --record | ||
| 6 | + kubectl -n mmm-suplus-prd get svc | grep -q performance-back | ||
| 7 | + if [ "$?" == "0" ];then | ||
| 8 | + echo "performance-back service install success!" | ||
| 9 | + else | ||
| 10 | + echo "performance-back service install fail!" | ||
| 11 | + fi | ||
| 12 | + kubectl -n mmm-suplus-prd get pods | grep -q performance-back | ||
| 13 | + if [ "$?" == "0" ];then | ||
| 14 | + echo "performance-back deployment install success!" | ||
| 15 | + else | ||
| 16 | + echo "performance-back deployment install fail!" | ||
| 17 | + fi | ||
| 18 | +else | ||
| 19 | + kubectl delete -f /tmp/prd/performance-back/performance-back.yaml | ||
| 20 | + kubectl -n mmm-suplus-prd get svc | grep -q performance-back | ||
| 21 | + while [ "$?" == "0" ] | ||
| 22 | + do | ||
| 23 | + kubectl -n mmm-suplus-prd get svc | grep -q performance-back | ||
| 24 | + done | ||
| 25 | + kubectl -n mmm-suplus-prd get pods | grep -q performance-back | ||
| 26 | + while [ "$?" == "0" ] | ||
| 27 | + do | ||
| 28 | + kubectl -n mmm-suplus-prd get pods | grep -q performance-back | ||
| 29 | + done | ||
| 30 | + kubectl create -f /tmp/prd/performance-back/performance-back.yaml --record | ||
| 31 | + kubectl -n mmm-suplus-prd get svc | grep -q performance-back | ||
| 32 | + if [ "$?" == "0" ];then | ||
| 33 | + echo "performance-back service update success!" | ||
| 34 | + else | ||
| 35 | + echo "performance-back service update fail!" | ||
| 36 | + fi | ||
| 37 | + kubectl -n mmm-suplus-prd get pods | grep -q performance-back | ||
| 38 | + if [ "$?" == "0" ];then | ||
| 39 | + echo "performance-back deployment update success!" | ||
| 40 | + else | ||
| 41 | + echo "performance-back deployment update fail!" | ||
| 42 | + fi | ||
| 43 | +fi |
deploy/k8s/prd/performance-back.yaml
0 → 100644
| 1 | +apiVersion: v1 | ||
| 2 | +kind: Service | ||
| 3 | +metadata: | ||
| 4 | + name: performance-back | ||
| 5 | + namespace: mmm-suplus-prd | ||
| 6 | + labels: | ||
| 7 | + k8s-app: performance-back | ||
| 8 | +spec: | ||
| 9 | + ports: | ||
| 10 | + - name: "http" | ||
| 11 | + port: 80 | ||
| 12 | + targetPort: 8082 | ||
| 13 | + - name: "https" | ||
| 14 | + port: 443 | ||
| 15 | + targetPort: 443 | ||
| 16 | + selector: | ||
| 17 | + k8s-app: performance-back | ||
| 18 | +--- | ||
| 19 | +apiVersion: extensions/v1beta1 | ||
| 20 | +kind: Deployment | ||
| 21 | +metadata: | ||
| 22 | + name: performance-back | ||
| 23 | + namespace: mmm-suplus-prd | ||
| 24 | + labels: | ||
| 25 | + k8s-app: performance-back | ||
| 26 | +spec: | ||
| 27 | + replicas: 1 | ||
| 28 | + template: | ||
| 29 | + metadata: | ||
| 30 | + labels: | ||
| 31 | + k8s-app: performance-back | ||
| 32 | + spec: | ||
| 33 | + affinity: | ||
| 34 | + nodeAffinity: | ||
| 35 | + preferredDuringSchedulingIgnoredDuringExecution: | ||
| 36 | + - preference: {} | ||
| 37 | + weight: 100 | ||
| 38 | + requiredDuringSchedulingIgnoredDuringExecution: | ||
| 39 | + nodeSelectorTerms: | ||
| 40 | + - matchExpressions: | ||
| 41 | + - key: kubernetes.io/hostname | ||
| 42 | + operator: In | ||
| 43 | + values: | ||
| 44 | + - cn-hangzhou.i-bp1djh1xn7taumbue1ze | ||
| 45 | + - cn-hangzhou.i-bp1djh1xn7taumbue1zd | ||
| 46 | + - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb | ||
| 47 | + - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy | ||
| 48 | + containers: | ||
| 49 | + - name: performance-back | ||
| 50 | + image: 192.168.0.243:5000/mmm/performance-back:master | ||
| 51 | + imagePullPolicy: Always | ||
| 52 | + ports: | ||
| 53 | + - containerPort: 8082 | ||
| 54 | + - containerPort: 443 | ||
| 55 | + volumeMounts: | ||
| 56 | + - mountPath: /opt/logs | ||
| 57 | + name: accesslogs | ||
| 58 | + env: | ||
| 59 | + - name: LOG_LEVEL | ||
| 60 | + value: "debug" | ||
| 61 | + - name: LOG_FILE | ||
| 62 | + value: "true" | ||
| 63 | + - name: ERROR_BASE_CODE | ||
| 64 | + value: "1" | ||
| 65 | + - name: ERROR_BASE_CODE_MULTIPLE | ||
| 66 | + value: "1000" | ||
| 67 | + - name: POSTGRESQL_DB_NAME | ||
| 68 | + value: "performance_prd" | ||
| 69 | + - name: ENABLE_HTTPS | ||
| 70 | + value: "true" | ||
| 71 | + - name: POSTGRESQL_USER | ||
| 72 | + valueFrom: | ||
| 73 | + configMapKeyRef: | ||
| 74 | + name: suplus-config | ||
| 75 | + key: postgresql.user | ||
| 76 | + - name: POSTGRESQL_PASSWORD | ||
| 77 | + valueFrom: | ||
| 78 | + configMapKeyRef: | ||
| 79 | + name: suplus-config | ||
| 80 | + key: postgresql.password | ||
| 81 | + - name: POSTGRESQL_HOST | ||
| 82 | + valueFrom: | ||
| 83 | + configMapKeyRef: | ||
| 84 | + name: suplus-config | ||
| 85 | + key: postgresql.host | ||
| 86 | + - name: POSTGRESQL_PORT | ||
| 87 | + valueFrom: | ||
| 88 | + configMapKeyRef: | ||
| 89 | + name: suplus-config | ||
| 90 | + key: postgresql.port | ||
| 91 | + - name: REDIS_HOST | ||
| 92 | + valueFrom: | ||
| 93 | + configMapKeyRef: | ||
| 94 | + name: suplus-config | ||
| 95 | + key: redis.ip | ||
| 96 | + - name: REDIS_PORT | ||
| 97 | + valueFrom: | ||
| 98 | + configMapKeyRef: | ||
| 99 | + name: suplus-config | ||
| 100 | + key: redis.port | ||
| 101 | + - name: KAFKA_HOSTS | ||
| 102 | + valueFrom: | ||
| 103 | + configMapKeyRef: | ||
| 104 | + name: suplus-config | ||
| 105 | + key: kafka.host | ||
| 106 | + - name: KAFKA_PERFORMANCE_ID | ||
| 107 | + valueFrom: | ||
| 108 | + configMapKeyRef: | ||
| 109 | + name: suplus-config | ||
| 110 | + key: kafkaperformance.id | ||
| 111 | + - name: KAFKA_BUSINESS_TOPIC | ||
| 112 | + value: "mmm_business_prd" | ||
| 113 | + - name: UCENTER_SERVICE_HOST | ||
| 114 | + value: "https://suplus-ucenter-prd.fjmaimaimai.com" | ||
| 115 | + - name: BUSINESS_ADMIN_SERVICE_HOST | ||
| 116 | + value: "https://suplus-business-admin-prd.fjmaimaimai.com" | ||
| 117 | + volumes: | ||
| 118 | + - name: accesslogs | ||
| 119 | + emptyDir: {} | ||
| 120 | + |
| @@ -7,6 +7,7 @@ import ( | @@ -7,6 +7,7 @@ import ( | ||
| 7 | serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task" | 7 | serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" | 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" |
| 9 | _ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego" | 9 | _ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego" |
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer" | ||
| 10 | ) | 11 | ) |
| 11 | 12 | ||
| 12 | func main() { | 13 | func main() { |
| @@ -17,7 +18,7 @@ func main() { | @@ -17,7 +18,7 @@ func main() { | ||
| 17 | // for k, v := range methods { | 18 | // for k, v := range methods { |
| 18 | // fmt.Printf("%s => %v \n", k, v) | 19 | // fmt.Printf("%s => %v \n", k, v) |
| 19 | // } | 20 | // } |
| 20 | - // go consumer.Run() | 21 | + go consumer.Run() |
| 21 | web.Run() | 22 | web.Run() |
| 22 | } | 23 | } |
| 23 | 24 |
| @@ -88,17 +88,21 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf | @@ -88,17 +88,21 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf | ||
| 88 | } | 88 | } |
| 89 | } | 89 | } |
| 90 | } | 90 | } |
| 91 | + | ||
| 92 | + ruleMap := map[int64]*domain.EvaluationRule{} | ||
| 91 | ruleIds := make([]int64, 0) | 93 | ruleIds := make([]int64, 0) |
| 92 | for k := range ruleIdsMap { | 94 | for k := range ruleIdsMap { |
| 93 | ruleIds = append(ruleIds, k) | 95 | ruleIds = append(ruleIds, k) |
| 94 | } | 96 | } |
| 95 | - | ||
| 96 | - _, rules, err := ruleRepository.Find(map[string]interface{}{"ids": ruleIds, "companyId": in.CompanyId}) | ||
| 97 | - | ||
| 98 | - ruleMap := map[int64]*domain.EvaluationRule{} | 97 | + if len(ruleIds) > 0 { |
| 98 | + if _, rules, err := ruleRepository.Find(map[string]interface{}{"ids": ruleIds, "companyId": in.CompanyId}); err != nil { | ||
| 99 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 100 | + } else { | ||
| 99 | for i := range rules { | 101 | for i := range rules { |
| 100 | ruleMap[rules[i].Id] = rules[i] | 102 | ruleMap[rules[i].Id] = rules[i] |
| 101 | } | 103 | } |
| 104 | + } | ||
| 105 | + } | ||
| 102 | 106 | ||
| 103 | ctAdapter := &adapter.CycleTemplateAdapter{} | 107 | ctAdapter := &adapter.CycleTemplateAdapter{} |
| 104 | ctAdapter.EvaluationCycle = cycle | 108 | ctAdapter.EvaluationCycle = cycle |
| @@ -307,7 +311,10 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf | @@ -307,7 +311,10 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf | ||
| 307 | 311 | ||
| 308 | cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext}) | 312 | cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 309 | cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext}) | 313 | cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 314 | + projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
| 315 | + taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
| 310 | 316 | ||
| 317 | + // 删除周期 | ||
| 311 | cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.Id}) | 318 | cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.Id}) |
| 312 | if err != nil { | 319 | if err != nil { |
| 313 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 320 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| @@ -316,11 +323,34 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf | @@ -316,11 +323,34 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf | ||
| 316 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 323 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 317 | } | 324 | } |
| 318 | 325 | ||
| 319 | - // FIXME 删除周期关联的所有模板... 还需要删除关联的定时内容 | 326 | + // 删除周期关联的所有模板,真删 |
| 320 | if err := cycleTemplateRepository.BatchDeleteByCycleId(cycle.Id); err != nil { | 327 | if err := cycleTemplateRepository.BatchDeleteByCycleId(cycle.Id); err != nil { |
| 321 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 328 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 322 | } | 329 | } |
| 323 | 330 | ||
| 331 | + // 删除周期下的所有项目 | ||
| 332 | + _, projects, err := projectRepository.Find(map[string]interface{}{"cycleId": in.Id}, "template") | ||
| 333 | + if err != nil { | ||
| 334 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 335 | + } | ||
| 336 | + for i := range projects { | ||
| 337 | + if _, err := projectRepository.Remove(projects[i]); err != nil { | ||
| 338 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 339 | + } | ||
| 340 | + } | ||
| 341 | + | ||
| 342 | + // 删除周期下的所有任务 | ||
| 343 | + tasks, err := taskRepository.Find(map[string]interface{}{"cycleId": in.Id}) | ||
| 344 | + if err != nil { | ||
| 345 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + for i := range tasks { | ||
| 349 | + if _, err := taskRepository.Remove(tasks[i]); err != nil { | ||
| 350 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 351 | + } | ||
| 352 | + } | ||
| 353 | + | ||
| 324 | if err := transactionContext.CommitTransaction(); err != nil { | 354 | if err := transactionContext.CommitTransaction(); err != nil { |
| 325 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 355 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 326 | } | 356 | } |
| @@ -25,8 +25,6 @@ type UpdateProjectTemplateCommand struct { | @@ -25,8 +25,6 @@ type UpdateProjectTemplateCommand struct { | ||
| 25 | TimeStart string `cname:"自评起始时间" json:"timeStart" valid:"Required"` | 25 | TimeStart string `cname:"自评起始时间" json:"timeStart" valid:"Required"` |
| 26 | TimeEnd string `cname:"自评截止时间" json:"timeEnd" valid:"Required"` | 26 | TimeEnd string `cname:"自评截止时间" json:"timeEnd" valid:"Required"` |
| 27 | KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"` | 27 | KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"` |
| 28 | - KpiResultStart string `cname:"绩效结果开始查看时间" json:"kpiResultStart"` | ||
| 29 | - Activate int `cname:"启动项目" json:"activate"` | ||
| 30 | } | 28 | } |
| 31 | 29 | ||
| 32 | type CheckRecipientCommand struct { | 30 | type CheckRecipientCommand struct { |
| @@ -135,7 +135,14 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | @@ -135,7 +135,14 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | ||
| 135 | cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext}) | 135 | cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 136 | cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext}) | 136 | cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 137 | 137 | ||
| 138 | - _, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "template") | 138 | + project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id}) |
| 139 | + if err != nil { | ||
| 140 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + // 如果是已经启用的项目,只能编辑环节的截至时间 | ||
| 144 | + if project.State == domain.ProjectStateEnable { | ||
| 145 | + end, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeEnd, time.Local) | ||
| 139 | if err != nil { | 146 | if err != nil { |
| 140 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 147 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 141 | } | 148 | } |
| @@ -144,7 +151,74 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | @@ -144,7 +151,74 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | ||
| 144 | if err != nil { | 151 | if err != nil { |
| 145 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 152 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 146 | } | 153 | } |
| 154 | + maxTime := cycle.TimeEnd.Local() | ||
| 155 | + if end.After(maxTime) { | ||
| 156 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "评估截至时间不能超出周期截至时间") | ||
| 157 | + } | ||
| 158 | + if project.Template != nil { | ||
| 159 | + for i := range project.Template.LinkNodes { | ||
| 160 | + node := project.Template.LinkNodes[i] | ||
| 161 | + node.TimeEnd = &end | ||
| 162 | + } | ||
| 163 | + } | ||
| 164 | + // 项目起始截止时间(暂时环节中的时间未分开) | ||
| 165 | + project.EndTime = end | ||
| 166 | + project, err = projectRepository.Insert(project) | ||
| 167 | + if err != nil { | ||
| 168 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + // 查看任务过程,重新日计算任务截至期 | ||
| 172 | + taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
| 173 | + tasks, err := taskRepository.Find(map[string]interface{}{"projectId": in.Id}) | ||
| 174 | + if err != nil { | ||
| 175 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + now := time.Now().Local() | ||
| 179 | + nowO := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) // 当前时间0点0分0秒时刻 | ||
| 180 | + | ||
| 181 | + for i := range tasks { | ||
| 182 | + task := tasks[i] | ||
| 183 | + task.TimeEnd = &end | ||
| 184 | + | ||
| 185 | + // 重新计算 | ||
| 186 | + if task.NextSentAt == nil { | ||
| 187 | + // 环节起始和截止本地时间 | ||
| 188 | + startLocal := task.TimeStart.Local() | ||
| 189 | + endLocal := task.TimeEnd.Local() | ||
| 190 | + | ||
| 191 | + // 在当前时间之前,则计算下一个周期时间 | ||
| 192 | + if startLocal.Before(now) { | ||
| 193 | + nextTime := utils.NextTime(nowO, startLocal, task.KpiCycle) | ||
| 194 | + task.NextSentAt = &nextTime | ||
| 195 | + } else { | ||
| 196 | + task.NextSentAt = &startLocal | ||
| 197 | + } | ||
| 198 | + // 如果超出截至时间,则周期置空 | ||
| 199 | + if task.NextSentAt.After(endLocal) { | ||
| 200 | + task.NextSentAt = nil | ||
| 201 | + } | ||
| 202 | + } else { | ||
| 203 | + // 新的截止时间在下一次发送周期任务之前,则结束 | ||
| 204 | + if end.Before(task.NextSentAt.Local()) { | ||
| 205 | + task.NextSentAt = nil | ||
| 206 | + } else { | ||
| 207 | + // do nothing | ||
| 208 | + } | ||
| 209 | + } | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 213 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 214 | + } | ||
| 215 | + return project, nil | ||
| 147 | 216 | ||
| 217 | + } else { | ||
| 218 | + _, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "template") | ||
| 219 | + if err != nil { | ||
| 220 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 221 | + } | ||
| 148 | // 周期内的所有项目,员工不能重复被评估 | 222 | // 周期内的所有项目,员工不能重复被评估 |
| 149 | rids := map[string]bool{} | 223 | rids := map[string]bool{} |
| 150 | for i := range projects { | 224 | for i := range projects { |
| @@ -167,24 +241,14 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | @@ -167,24 +241,14 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | ||
| 167 | return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("有%d人已经在本周期其他项目内,需要将他们移除", repeatNum)) | 241 | return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("有%d人已经在本周期其他项目内,需要将他们移除", repeatNum)) |
| 168 | } | 242 | } |
| 169 | 243 | ||
| 170 | - project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id}) | ||
| 171 | - if err != nil { | ||
| 172 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 173 | - } | ||
| 174 | - | ||
| 175 | cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true}) | 244 | cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true}) |
| 176 | if err != nil { | 245 | if err != nil { |
| 177 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 246 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 178 | } | 247 | } |
| 179 | - | ||
| 180 | if cycleTemplate == nil || cycleTemplate.Template == nil { | 248 | if cycleTemplate == nil || cycleTemplate.Template == nil { |
| 181 | return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加模板") | 249 | return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加模板") |
| 182 | } | 250 | } |
| 183 | 251 | ||
| 184 | - if len(in.Recipients) == 0 { | ||
| 185 | - return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人") | ||
| 186 | - } | ||
| 187 | - | ||
| 188 | start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local) | 252 | start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local) |
| 189 | if err != nil { | 253 | if err != nil { |
| 190 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 254 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| @@ -193,11 +257,11 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | @@ -193,11 +257,11 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | ||
| 193 | if err != nil { | 257 | if err != nil { |
| 194 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 258 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 195 | } | 259 | } |
| 196 | - kpiStart, err := time.ParseInLocation("2006-01-02 15:04:05", in.KpiResultStart, time.Local) | 260 | + |
| 261 | + cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.CycleId}) | ||
| 197 | if err != nil { | 262 | if err != nil { |
| 198 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 263 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 199 | } | 264 | } |
| 200 | - | ||
| 201 | minTime := cycle.TimeStart.Local() | 265 | minTime := cycle.TimeStart.Local() |
| 202 | maxTime := cycle.TimeEnd.Local() | 266 | maxTime := cycle.TimeEnd.Local() |
| 203 | 267 | ||
| @@ -209,27 +273,21 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | @@ -209,27 +273,21 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | ||
| 209 | return nil, application.ThrowError(application.BUSINESS_ERROR, "评估截至时间不能超出周期截至时间") | 273 | return nil, application.ThrowError(application.BUSINESS_ERROR, "评估截至时间不能超出周期截至时间") |
| 210 | } | 274 | } |
| 211 | 275 | ||
| 212 | - //// FIXME 启动时,需要激活定时任务 | ||
| 213 | - //if in.Activate == 1 { | ||
| 214 | - // project.State = domain.ProjectStateEnable | ||
| 215 | - //} else { | ||
| 216 | - // project.State = domain.ProjectStateWaitActive | ||
| 217 | - //} | 276 | + if project.State == domain.ProjectStateWaitConfig { |
| 218 | project.State = domain.ProjectStateWaitActive | 277 | project.State = domain.ProjectStateWaitActive |
| 219 | - | 278 | + } |
| 220 | project.Recipients = in.Recipients | 279 | project.Recipients = in.Recipients |
| 221 | project.Template = cycleTemplate.Template | 280 | project.Template = cycleTemplate.Template |
| 281 | + | ||
| 282 | + // 项目起始截止时间(环节中的时间暂未分开计算) | ||
| 283 | + project.BeginTime = start | ||
| 284 | + project.EndTime = end | ||
| 222 | for i := range project.Template.LinkNodes { | 285 | for i := range project.Template.LinkNodes { |
| 223 | node := project.Template.LinkNodes[i] | 286 | node := project.Template.LinkNodes[i] |
| 224 | node.KpiCycle = in.KpiCycle // 设置周期 | 287 | node.KpiCycle = in.KpiCycle // 设置周期 |
| 225 | - if node.Type == domain.LinkNodeViewResult { | ||
| 226 | - node.TimeStart = &kpiStart | ||
| 227 | - node.TimeEnd = &maxTime // 绩效查看时间跟随周期截止时间 | ||
| 228 | - } else { | ||
| 229 | node.TimeStart = &start | 288 | node.TimeStart = &start |
| 230 | node.TimeEnd = &end | 289 | node.TimeEnd = &end |
| 231 | } | 290 | } |
| 232 | - } | ||
| 233 | 291 | ||
| 234 | project, err = projectRepository.Insert(project) | 292 | project, err = projectRepository.Insert(project) |
| 235 | if err != nil { | 293 | if err != nil { |
| @@ -239,6 +297,7 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | @@ -239,6 +297,7 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | ||
| 239 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 297 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 240 | } | 298 | } |
| 241 | return project, nil | 299 | return project, nil |
| 300 | + } | ||
| 242 | } | 301 | } |
| 243 | 302 | ||
| 244 | func (rs *EvaluationProjectService) Get(in *command.GetProjectCommand) (interface{}, error) { | 303 | func (rs *EvaluationProjectService) Get(in *command.GetProjectCommand) (interface{}, error) { |
| @@ -285,6 +344,7 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in | @@ -285,6 +344,7 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in | ||
| 285 | }() | 344 | }() |
| 286 | 345 | ||
| 287 | projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) | 346 | projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 347 | + taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
| 288 | 348 | ||
| 289 | project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id}) | 349 | project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id}) |
| 290 | if err != nil { | 350 | if err != nil { |
| @@ -294,6 +354,17 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in | @@ -294,6 +354,17 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in | ||
| 294 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 354 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 295 | } | 355 | } |
| 296 | 356 | ||
| 357 | + // 查看任务过程,移除项目关联的所有任务 | ||
| 358 | + tasks, err := taskRepository.Find(map[string]interface{}{"projectId": in.Id}) | ||
| 359 | + if err != nil { | ||
| 360 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 361 | + } | ||
| 362 | + for i := range tasks { | ||
| 363 | + if _, err := taskRepository.Remove(tasks[i]); err != nil { | ||
| 364 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 365 | + } | ||
| 366 | + } | ||
| 367 | + | ||
| 297 | if err := transactionContext.CommitTransaction(); err != nil { | 368 | if err := transactionContext.CommitTransaction(); err != nil { |
| 298 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 369 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 299 | } | 370 | } |
| @@ -314,6 +385,8 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter | @@ -314,6 +385,8 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter | ||
| 314 | if err != nil { | 385 | if err != nil { |
| 315 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 386 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 316 | } | 387 | } |
| 388 | + | ||
| 389 | + now := time.Now().Unix() | ||
| 317 | pmpUsers := make([]*domain.User, 0) | 390 | pmpUsers := make([]*domain.User, 0) |
| 318 | pmpUserIds := make([]int64, 0) | 391 | pmpUserIds := make([]int64, 0) |
| 319 | for i := range projects { | 392 | for i := range projects { |
| @@ -322,7 +395,13 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter | @@ -322,7 +395,13 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter | ||
| 322 | userId, _ := strconv.ParseInt(project.PmpIds[j], 10, 64) | 395 | userId, _ := strconv.ParseInt(project.PmpIds[j], 10, 64) |
| 323 | pmpUserIds = append(pmpUserIds, userId) | 396 | pmpUserIds = append(pmpUserIds, userId) |
| 324 | } | 397 | } |
| 398 | + | ||
| 399 | + // 当前时间超过截至时间显示【已结束】 | ||
| 400 | + if now > project.EndTime.Unix() { | ||
| 401 | + project.State = domain.ProjectStateDisable | ||
| 402 | + } | ||
| 325 | } | 403 | } |
| 404 | + | ||
| 326 | if len(pmpUserIds) > 0 { | 405 | if len(pmpUserIds) > 0 { |
| 327 | userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) | 406 | userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 328 | _, users, _ := userRepository.Find(map[string]interface{}{"ids": pmpUserIds, "limit": len(pmpUserIds)}) | 407 | _, users, _ := userRepository.Find(map[string]interface{}{"ids": pmpUserIds, "limit": len(pmpUserIds)}) |
| @@ -342,29 +421,20 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) | @@ -342,29 +421,20 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) | ||
| 342 | }() | 421 | }() |
| 343 | 422 | ||
| 344 | projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) | 423 | projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) |
| 345 | - //cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
| 346 | 424 | ||
| 347 | project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id}) | 425 | project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id}) |
| 348 | if err != nil { | 426 | if err != nil { |
| 349 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 427 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 350 | } | 428 | } |
| 351 | - | ||
| 352 | if project.Template == nil { | 429 | if project.Template == nil { |
| 353 | return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加评估模板") | 430 | return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加评估模板") |
| 354 | } | 431 | } |
| 355 | - | ||
| 356 | if len(project.Recipients) == 0 { | 432 | if len(project.Recipients) == 0 { |
| 357 | return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人") | 433 | return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人") |
| 358 | } | 434 | } |
| 359 | if project.State == domain.TemplateStateEnable { | 435 | if project.State == domain.TemplateStateEnable { |
| 360 | return nil, application.ThrowError(application.BUSINESS_ERROR, "项目已启动") | 436 | return nil, application.ThrowError(application.BUSINESS_ERROR, "项目已启动") |
| 361 | } | 437 | } |
| 362 | - //cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": project.CycleId}) | ||
| 363 | - //if err != nil { | ||
| 364 | - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 365 | - //} | ||
| 366 | - //startMin := cycle.TimeStart | ||
| 367 | - //maxTime := cycle.TimeEnd | ||
| 368 | 438 | ||
| 369 | project.State = domain.TemplateStateEnable | 439 | project.State = domain.TemplateStateEnable |
| 370 | project, err = projectRepository.Insert(project) | 440 | project, err = projectRepository.Insert(project) |
| @@ -422,42 +492,6 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) | @@ -422,42 +492,6 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) | ||
| 422 | return project, nil | 492 | return project, nil |
| 423 | } | 493 | } |
| 424 | 494 | ||
| 425 | -// | ||
| 426 | -//// 0点时刻为标准计算 | ||
| 427 | -//func (rs *EvaluationProjectService) nextTime(now0 time.Time, start *time.Time, kpiCycle int) time.Time { | ||
| 428 | -// // 起始时间0点时刻 | ||
| 429 | -// start0 := time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, time.Local) | ||
| 430 | -// | ||
| 431 | -// var nextTime time.Time | ||
| 432 | -// switch kpiCycle { | ||
| 433 | -// case domain.KpiCycleDay: | ||
| 434 | -// nextTime = timeconv.AddDate(now0, 0, 0, 1) // 当前时间的下一天开始发送 | ||
| 435 | -// break | ||
| 436 | -// case domain.KpiCycleWeek: | ||
| 437 | -// offsetSeconds := int64(now0.Sub(start0).Seconds()) | ||
| 438 | -// offsetDay := offsetSeconds / (24 * 60 * 60) | ||
| 439 | -// cycleCount := int(offsetDay)/7 + 1 | ||
| 440 | -// nextTime = timeconv.AddDate(start0, 0, 0, cycleCount*7) | ||
| 441 | -// break | ||
| 442 | -// case domain.KpiCycleOneMonth: | ||
| 443 | -// nextTime = timeconv.AddDate(start0, 0, 1, 0) | ||
| 444 | -// break | ||
| 445 | -// case domain.KpiCycleTwoMonth: | ||
| 446 | -// nextTime = timeconv.AddDate(start0, 0, 2, 0) | ||
| 447 | -// break | ||
| 448 | -// case domain.KpiCycleThreeMonth: | ||
| 449 | -// nextTime = timeconv.AddDate(start0, 0, 3, 0) | ||
| 450 | -// break | ||
| 451 | -// case domain.KpiCycleSixMonth: | ||
| 452 | -// nextTime = timeconv.AddDate(start0, 0, 6, 0) | ||
| 453 | -// break | ||
| 454 | -// case domain.KpiCycleYear: | ||
| 455 | -// nextTime = timeconv.AddDate(start0, 1, 0, 0) | ||
| 456 | -// break | ||
| 457 | -// } | ||
| 458 | -// return nextTime | ||
| 459 | -//} | ||
| 460 | - | ||
| 461 | func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interface{}, error) { | 495 | func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interface{}, error) { |
| 462 | transactionContext, err := factory.ValidateStartTransaction(in) | 496 | transactionContext, err := factory.ValidateStartTransaction(in) |
| 463 | if err != nil { | 497 | if err != nil { |
| @@ -22,19 +22,3 @@ type AssessInfoResp struct { | @@ -22,19 +22,3 @@ type AssessInfoResp struct { | ||
| 22 | DutyTime string `json:"dutyTime"` //入职时间 // | 22 | DutyTime string `json:"dutyTime"` //入职时间 // |
| 23 | AssessContent []*domain.StaffAssessContent `json:"assessContent"` //评估内容 | 23 | AssessContent []*domain.StaffAssessContent `json:"assessContent"` //评估内容 |
| 24 | } | 24 | } |
| 25 | - | ||
| 26 | -type AssessContent struct { | ||
| 27 | - Category string `json:"category"` //comment:"类别" | ||
| 28 | - Name string `json:"name"` // comment:"名称" | ||
| 29 | - PromptTitle string `json:"promptTitle"` //comment:"提示项标题" | ||
| 30 | - PromptText string `json:"promptText"` // comment:"提示项正文" | ||
| 31 | - Rule AssessContentRule `json:"rules"` //评定规则 | ||
| 32 | - Value string `json:"value"` // 实际填写评定值 | ||
| 33 | - Remark []domain.AssessContemtRemark `json:"entryItems"` // comment:"填写反馈" | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -type AssessContentRule struct { | ||
| 37 | - Types int `json:"types"` //评估方式(0评级、1评分) | ||
| 38 | - Rating domain.Rating `json:"rating"` //评级 | ||
| 39 | - Score domain.Score `json:"score"` //评分 | ||
| 40 | -} |
| @@ -12,6 +12,7 @@ type AssessTaskDescResp struct { | @@ -12,6 +12,7 @@ type AssessTaskDescResp struct { | ||
| 12 | 12 | ||
| 13 | type AssessTaskStep struct { | 13 | type AssessTaskStep struct { |
| 14 | SortBy int `json:"sortBy"` //排序 | 14 | SortBy int `json:"sortBy"` //排序 |
| 15 | + LinkNodeId int `json:"linkNodeId"` //流程id | ||
| 15 | LinkNodeName string `json:"linkNodeName"` //流程名称 | 16 | LinkNodeName string `json:"linkNodeName"` //流程名称 |
| 16 | BeginTime string `json:"beginTime"` //开始时间时间 | 17 | BeginTime string `json:"beginTime"` //开始时间时间 |
| 17 | EndTime string `json:"endTime"` //结束时间 | 18 | EndTime string `json:"endTime"` //结束时间 |
| @@ -2,6 +2,7 @@ package service | @@ -2,6 +2,7 @@ package service | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "sort" | ||
| 5 | "strconv" | 6 | "strconv" |
| 6 | "time" | 7 | "time" |
| 7 | 8 | ||
| @@ -37,9 +38,6 @@ func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQue | @@ -37,9 +38,6 @@ func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQue | ||
| 37 | defer func() { | 38 | defer func() { |
| 38 | _ = transactionContext.RollbackTransaction() | 39 | _ = transactionContext.RollbackTransaction() |
| 39 | }() | 40 | }() |
| 40 | - // staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{ | ||
| 41 | - // "transactionContext": transactionContext, | ||
| 42 | - // }) | ||
| 43 | 41 | ||
| 44 | staffAssessTaskRepo := dao.NewStaffAssessDao(map[string]interface{}{ | 42 | staffAssessTaskRepo := dao.NewStaffAssessDao(map[string]interface{}{ |
| 45 | "transactionContext": transactionContext, | 43 | "transactionContext": transactionContext, |
| @@ -59,18 +57,7 @@ func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQue | @@ -59,18 +57,7 @@ func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQue | ||
| 59 | if err != nil { | 57 | if err != nil { |
| 60 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询评估任务"+err.Error()) | 58 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询评估任务"+err.Error()) |
| 61 | } | 59 | } |
| 62 | - // condition := map[string]interface{}{ | ||
| 63 | - // "executorId": param.UserId, | ||
| 64 | - // "companyId": param.CompanyId, | ||
| 65 | - // "limit": limit, | ||
| 66 | - // } | ||
| 67 | - // if offset > 0 { | ||
| 68 | - // condition["offset"] = offset | ||
| 69 | - // } | ||
| 70 | - // cnt, assessTaskList, err := staffAssessTaskRepo.Find(condition) | ||
| 71 | - // if err != nil { | ||
| 72 | - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询周期"+err.Error()) | ||
| 73 | - // } | 60 | + |
| 74 | if err := transactionContext.CommitTransaction(); err != nil { | 61 | if err := transactionContext.CommitTransaction(); err != nil { |
| 75 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 62 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 76 | } | 63 | } |
| @@ -79,8 +66,8 @@ func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQue | @@ -79,8 +66,8 @@ func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQue | ||
| 79 | for _, v := range assessTaskList { | 66 | for _, v := range assessTaskList { |
| 80 | temp = adapter.SearchAssessMeResp{ | 67 | temp = adapter.SearchAssessMeResp{ |
| 81 | AssessTaskId: v.Id, | 68 | AssessTaskId: v.Id, |
| 82 | - BeginTime: v.BeginTime.Format("2006-01-02 15:04:05"), | ||
| 83 | - EndTime: v.EndTime.Format("2006-01-02 15:04:05"), | 69 | + BeginTime: v.BeginTime.Local().Format("2006-01-02 15:04:05"), |
| 70 | + EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"), | ||
| 84 | CycleId: v.CycleId, | 71 | CycleId: v.CycleId, |
| 85 | CycleName: v.CycleName, | 72 | CycleName: v.CycleName, |
| 86 | EvaluationProjectId: v.EvaluationProjectId, | 73 | EvaluationProjectId: v.EvaluationProjectId, |
| @@ -132,6 +119,7 @@ func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery) | @@ -132,6 +119,7 @@ func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery) | ||
| 132 | stepItem := adapter.AssessTaskStep{ | 119 | stepItem := adapter.AssessTaskStep{ |
| 133 | SortBy: v.SortBy, | 120 | SortBy: v.SortBy, |
| 134 | LinkNodeName: v.LinkNodeName, | 121 | LinkNodeName: v.LinkNodeName, |
| 122 | + LinkNodeId: v.LinkNodeId, | ||
| 135 | BeginTime: v.BeginTime.Local().Format("2006-01-02 15:04:05"), | 123 | BeginTime: v.BeginTime.Local().Format("2006-01-02 15:04:05"), |
| 136 | EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"), | 124 | EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"), |
| 137 | LinkNodeType: v.LinkNodeType, | 125 | LinkNodeType: v.LinkNodeType, |
| @@ -220,8 +208,11 @@ func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery) | @@ -220,8 +208,11 @@ func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery) | ||
| 220 | } | 208 | } |
| 221 | } | 209 | } |
| 222 | } | 210 | } |
| 211 | + //未参与的,不算在个人的评估环节里 | ||
| 212 | + if stepItem.Status != "" { | ||
| 223 | result.StepList = append(result.StepList, stepItem) | 213 | result.StepList = append(result.StepList, stepItem) |
| 224 | } | 214 | } |
| 215 | + } | ||
| 225 | if err := transactionContext.CommitTransaction(); err != nil { | 216 | if err := transactionContext.CommitTransaction(); err != nil { |
| 226 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 217 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 227 | } | 218 | } |
| @@ -244,7 +235,7 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) | @@ -244,7 +235,7 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) | ||
| 244 | staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{ | 235 | staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{ |
| 245 | "transactionContext": transactionContext, | 236 | "transactionContext": transactionContext, |
| 246 | }) | 237 | }) |
| 247 | - var limit int = 20 | 238 | + var limit int = 100 |
| 248 | var offset int = 0 | 239 | var offset int = 0 |
| 249 | if param.PageSize > 0 { | 240 | if param.PageSize > 0 { |
| 250 | limit = param.PageSize | 241 | limit = param.PageSize |
| @@ -255,8 +246,9 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) | @@ -255,8 +246,9 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) | ||
| 255 | "companyId": param.CompanyId, | 246 | "companyId": param.CompanyId, |
| 256 | "typesList": []string{string(domain.AssessSelf)}, | 247 | "typesList": []string{string(domain.AssessSelf)}, |
| 257 | "limit": limit, | 248 | "limit": limit, |
| 258 | - "status": string(domain.StaffAssessCompleted), | 249 | + "endTime": time.Now(), //获取历史记录 |
| 259 | } | 250 | } |
| 251 | + // "status": string(domain.StaffAssessCompleted), | ||
| 260 | if offset > 0 { | 252 | if offset > 0 { |
| 261 | condition["offset"] = offset | 253 | condition["offset"] = offset |
| 262 | } | 254 | } |
| @@ -347,16 +339,6 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) | @@ -347,16 +339,6 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery) | ||
| 347 | 339 | ||
| 348 | // 根据项目评估的配置,创建员工的评估任务 | 340 | // 根据项目评估的配置,创建员工的评估任务 |
| 349 | func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (map[string]interface{}, error) { | 341 | func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (map[string]interface{}, error) { |
| 350 | - // transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 351 | - // if err != nil { | ||
| 352 | - // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 353 | - // } | ||
| 354 | - // if err := transactionContext.StartTransaction(); err != nil { | ||
| 355 | - // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 356 | - // } | ||
| 357 | - // defer func() { | ||
| 358 | - // _ = transactionContext.RollbackTransaction() | ||
| 359 | - // }() | ||
| 360 | log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{ | 342 | log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{ |
| 361 | "param": param, | 343 | "param": param, |
| 362 | }) | 344 | }) |
| @@ -372,8 +354,22 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat | @@ -372,8 +354,22 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat | ||
| 372 | return nil, application.ThrowError(application.ARG_ERROR, "任务结束时间填写错误,"+param.EndTime) | 354 | return nil, application.ThrowError(application.ARG_ERROR, "任务结束时间填写错误,"+param.EndTime) |
| 373 | } | 355 | } |
| 374 | nowTime := time.Now() | 356 | nowTime := time.Now() |
| 375 | - //建立评估任务 | ||
| 376 | - assessTaskData := &domain.StaffAssessTask{ | 357 | + |
| 358 | + _, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{ | ||
| 359 | + "evaluationProjectId": param.EvaluationProjectId, | ||
| 360 | + "beginDay": taskBeginTime.Local().Format("2006-01-02"), | ||
| 361 | + }) | ||
| 362 | + if err != nil { | ||
| 363 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期同项目已存在的评估任务"+err.Error()) | ||
| 364 | + } | ||
| 365 | + var assessTaskData *domain.StaffAssessTask | ||
| 366 | + //更新旧数据或者新建数据 | ||
| 367 | + if len(assassessTaskList) > 0 { | ||
| 368 | + assessTaskData = assassessTaskList[0] | ||
| 369 | + assessTaskData.UpdatedAt = nowTime | ||
| 370 | + } else { | ||
| 371 | + //建立新的评估任务 | ||
| 372 | + assessTaskData = &domain.StaffAssessTask{ | ||
| 377 | Id: 0, | 373 | Id: 0, |
| 378 | CompanyId: param.CompanyId, | 374 | CompanyId: param.CompanyId, |
| 379 | EvaluationProjectId: param.EvaluationProjectId, | 375 | EvaluationProjectId: param.EvaluationProjectId, |
| @@ -383,19 +379,39 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat | @@ -383,19 +379,39 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat | ||
| 383 | BeginTime: taskBeginTime, | 379 | BeginTime: taskBeginTime, |
| 384 | EndTime: taskEndTime, | 380 | EndTime: taskEndTime, |
| 385 | StepList: []domain.AssessTaskStep{}, | 381 | StepList: []domain.AssessTaskStep{}, |
| 386 | - ExecutorId: nil, | 382 | + ExecutorId: []int{}, |
| 387 | CreatedAt: nowTime, | 383 | CreatedAt: nowTime, |
| 388 | UpdatedAt: nowTime, | 384 | UpdatedAt: nowTime, |
| 389 | DeletedAt: nil, | 385 | DeletedAt: nil, |
| 390 | BeginDay: taskBeginTime.Local().Format("2006-01-02"), | 386 | BeginDay: taskBeginTime.Local().Format("2006-01-02"), |
| 391 | } | 387 | } |
| 392 | - // } | ||
| 393 | - | ||
| 394 | - //填充评估环节 | 388 | + } |
| 389 | + executorIds := []int{} //提取评估的参与人id | ||
| 390 | + executorIdMap := map[int]struct{}{} //过滤重复的用户 | ||
| 391 | + //从入参中提取参与人 | ||
| 392 | + for _, v := range param.ExecutorId { | ||
| 393 | + if _, ok := executorIdMap[v]; ok { | ||
| 394 | + continue | ||
| 395 | + } | ||
| 396 | + executorIdMap[v] = struct{}{} | ||
| 397 | + executorIds = append(executorIds, v) | ||
| 398 | + } | ||
| 399 | + //就数据中提取参与人 | ||
| 400 | + for _, v := range assessTaskData.ExecutorId { | ||
| 401 | + if _, ok := executorIdMap[v]; ok { | ||
| 402 | + continue | ||
| 403 | + } | ||
| 404 | + executorIdMap[v] = struct{}{} | ||
| 405 | + executorIds = append(executorIds, v) | ||
| 406 | + } | ||
| 407 | + //填入新的参与人id | ||
| 408 | + assessTaskData.ExecutorId = executorIds | ||
| 409 | + //填充新的评估环节 | ||
| 410 | +loop: | ||
| 395 | for _, v := range param.StepList { | 411 | for _, v := range param.StepList { |
| 396 | for _, vv := range assessTaskData.StepList { | 412 | for _, vv := range assessTaskData.StepList { |
| 397 | - if vv.LinkNodeType == v.LinkNodeType { | ||
| 398 | - continue | 413 | + if vv.LinkNodeId == v.LinkNodeId { |
| 414 | + continue loop | ||
| 399 | } | 415 | } |
| 400 | } | 416 | } |
| 401 | stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local) | 417 | stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local) |
| @@ -416,44 +432,15 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat | @@ -416,44 +432,15 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat | ||
| 416 | } | 432 | } |
| 417 | assessTaskData.StepList = append(assessTaskData.StepList, step) | 433 | assessTaskData.StepList = append(assessTaskData.StepList, step) |
| 418 | } | 434 | } |
| 419 | - //评估的参与人 | ||
| 420 | - executorIds := []int{} | ||
| 421 | - executorIdMap := map[int]struct{}{} //过滤重复的用户 | ||
| 422 | - for _, v := range param.ExecutorId { | ||
| 423 | - if _, ok := executorIdMap[v]; ok { | ||
| 424 | - continue | ||
| 425 | - } | ||
| 426 | - executorIdMap[v] = struct{}{} | ||
| 427 | - executorIds = append(executorIds, v) | ||
| 428 | - } | ||
| 429 | - assessTaskData.ExecutorId = executorIds | 435 | + //排序流程环节 |
| 436 | + stepList := domain.SortTaskStep(assessTaskData.StepList) | ||
| 437 | + sort.Sort(stepList) | ||
| 438 | + assessTaskData.StepList = stepList | ||
| 439 | + //添加员工的节点任务 | ||
| 430 | assessList, err := srv.createStaffAssess(transactionContext, assessTaskData) | 440 | assessList, err := srv.createStaffAssess(transactionContext, assessTaskData) |
| 431 | if err != nil { | 441 | if err != nil { |
| 432 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error()) | 442 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error()) |
| 433 | } | 443 | } |
| 434 | - // var assessTaskData *domain.StaffAssessTask | ||
| 435 | - _, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{ | ||
| 436 | - "evaluationProjectId": param.EvaluationProjectId, | ||
| 437 | - "beginDay": taskBeginTime.Local().Format("2006-01-02"), | ||
| 438 | - }) | ||
| 439 | - if err != nil { | ||
| 440 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期已存在评估任务"+err.Error()) | ||
| 441 | - } | ||
| 442 | - | ||
| 443 | - if len(assassessTaskList) > 0 { | ||
| 444 | - //过滤就数据 | ||
| 445 | - assessTaskData.Id = assassessTaskList[0].Id | ||
| 446 | - for _, v := range assassessTaskList[0].ExecutorId { | ||
| 447 | - if _, ok := executorIdMap[v]; ok { | ||
| 448 | - continue | ||
| 449 | - } | ||
| 450 | - executorIdMap[v] = struct{}{} | ||
| 451 | - executorIds = append(executorIds, v) | ||
| 452 | - } | ||
| 453 | - assessTaskData.ExecutorId = executorIds | ||
| 454 | - assessTaskData.StepList = append(assassessTaskList[0].StepList, assessTaskData.StepList...) | ||
| 455 | - | ||
| 456 | - } | ||
| 457 | _, err = assessTaskRepo.Save(assessTaskData) | 444 | _, err = assessTaskRepo.Save(assessTaskData) |
| 458 | if err != nil { | 445 | if err != nil { |
| 459 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error()) | 446 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error()) |
| @@ -469,10 +456,6 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat | @@ -469,10 +456,6 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat | ||
| 469 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error()) | 456 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error()) |
| 470 | } | 457 | } |
| 471 | } | 458 | } |
| 472 | - | ||
| 473 | - // if err := transactionContext.CommitTransaction(); err != nil { | ||
| 474 | - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 475 | - // } | ||
| 476 | return map[string]interface{}{ | 459 | return map[string]interface{}{ |
| 477 | "assessTaskId": assessTaskData.Id, | 460 | "assessTaskId": assessTaskData.Id, |
| 478 | }, nil | 461 | }, nil |
| @@ -480,8 +463,8 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat | @@ -480,8 +463,8 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat | ||
| 480 | 463 | ||
| 481 | // 添加节点任务 | 464 | // 添加节点任务 |
| 482 | func (srv StaffAssessServeice) createStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) { | 465 | func (srv StaffAssessServeice) createStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) { |
| 483 | - //评估的参与人 | ||
| 484 | - selfUserId := []int{} | 466 | + |
| 467 | + selfUserId := []int{} //评估的参与人 | ||
| 485 | userIdMap := map[int]struct{}{} //过滤重复的用户 | 468 | userIdMap := map[int]struct{}{} //过滤重复的用户 |
| 486 | for _, v := range param.ExecutorId { | 469 | for _, v := range param.ExecutorId { |
| 487 | if _, ok := userIdMap[v]; ok { | 470 | if _, ok := userIdMap[v]; ok { |
| @@ -557,7 +540,7 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application. | @@ -557,7 +540,7 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application. | ||
| 557 | assessList = append(assessList, assessListTemp...) | 540 | assessList = append(assessList, assessListTemp...) |
| 558 | } | 541 | } |
| 559 | if v.LinkNodeType == domain.LinkNodeSuperiorAssessment { | 542 | if v.LinkNodeType == domain.LinkNodeSuperiorAssessment { |
| 560 | - // TODO | 543 | + // 创建上级评估 |
| 561 | stepSelfTemp.BeginTime = v.BeginTime | 544 | stepSelfTemp.BeginTime = v.BeginTime |
| 562 | stepSelfTemp.EndTime = v.EndTime | 545 | stepSelfTemp.EndTime = v.EndTime |
| 563 | stepSelfTemp.LinkNodeId = v.LinkNodeId | 546 | stepSelfTemp.LinkNodeId = v.LinkNodeId |
| @@ -578,7 +561,6 @@ func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAsse | @@ -578,7 +561,6 @@ func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAsse | ||
| 578 | userList []*domain.User, userDepartmentMap map[int64][]*domain.Department) []domain.StaffAssess { | 561 | userList []*domain.User, userDepartmentMap map[int64][]*domain.Department) []domain.StaffAssess { |
| 579 | result := []domain.StaffAssess{} | 562 | result := []domain.StaffAssess{} |
| 580 | for _, usr := range userList { | 563 | for _, usr := range userList { |
| 581 | - | ||
| 582 | assessTemp.TargetUser = domain.StaffDesc{ | 564 | assessTemp.TargetUser = domain.StaffDesc{ |
| 583 | UserId: int(usr.Id), | 565 | UserId: int(usr.Id), |
| 584 | Account: usr.Account, | 566 | Account: usr.Account, |
| @@ -602,7 +584,7 @@ func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAsse | @@ -602,7 +584,7 @@ func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAsse | ||
| 602 | return result | 584 | return result |
| 603 | } | 585 | } |
| 604 | 586 | ||
| 605 | -// 构建员工上级评估 | 587 | +// 构建员工的上级评估 |
| 606 | func (srv StaffAssessServeice) createStaffAssessSupper( | 588 | func (srv StaffAssessServeice) createStaffAssessSupper( |
| 607 | transactionContext application.TransactionContext, | 589 | transactionContext application.TransactionContext, |
| 608 | assessTemp domain.StaffAssess, | 590 | assessTemp domain.StaffAssess, |
| @@ -622,6 +604,7 @@ func (srv StaffAssessServeice) createStaffAssessSupper( | @@ -622,6 +604,7 @@ func (srv StaffAssessServeice) createStaffAssessSupper( | ||
| 622 | if len(vv2.ChargeUserIds) == 0 { | 604 | if len(vv2.ChargeUserIds) == 0 { |
| 623 | continue | 605 | continue |
| 624 | } | 606 | } |
| 607 | + //获取部门的主管 | ||
| 625 | _, chargeUserList, err := userRepo.Find(map[string]interface{}{ | 608 | _, chargeUserList, err := userRepo.Find(map[string]interface{}{ |
| 626 | "ids": vv2.ChargeUserIds, | 609 | "ids": vv2.ChargeUserIds, |
| 627 | "limit": 40, | 610 | "limit": 40, |
| @@ -742,7 +725,6 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv | @@ -742,7 +725,6 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv | ||
| 742 | defer func() { | 725 | defer func() { |
| 743 | _ = transactionContext.RollbackTransaction() | 726 | _ = transactionContext.RollbackTransaction() |
| 744 | }() | 727 | }() |
| 745 | - | ||
| 746 | assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{ | 728 | assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{ |
| 747 | "transactionContext": transactionContext, | 729 | "transactionContext": transactionContext, |
| 748 | }) | 730 | }) |
| @@ -775,6 +757,12 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv | @@ -775,6 +757,12 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv | ||
| 775 | if inviteNode == nil { | 757 | if inviteNode == nil { |
| 776 | return nil, application.ThrowError(application.ARG_ERROR, "评估任务没有邀请评估的环节") | 758 | return nil, application.ThrowError(application.ARG_ERROR, "评估任务没有邀请评估的环节") |
| 777 | } | 759 | } |
| 760 | + //检查节点的结束时间 | ||
| 761 | + endTimeInt := inviteNode.EndTime.Unix() | ||
| 762 | + if endTimeInt < time.Now().Unix() { | ||
| 763 | + e := fmt.Sprintf("该环节已在%s截止", inviteNode.EndTime.Local().Format("2006-01-02 15:04:05")) | ||
| 764 | + return nil, application.ThrowError(application.BUSINESS_ERROR, e) | ||
| 765 | + } | ||
| 778 | 766 | ||
| 779 | targetUser, err := userRepo.FindOne(map[string]interface{}{ | 767 | targetUser, err := userRepo.FindOne(map[string]interface{}{ |
| 780 | "id": param.TargetUserId, | 768 | "id": param.TargetUserId, |
| @@ -1635,7 +1623,7 @@ func (srv *StaffAssessServeice) getStaffDescrip(transactionContext application.T | @@ -1635,7 +1623,7 @@ func (srv *StaffAssessServeice) getStaffDescrip(transactionContext application.T | ||
| 1635 | UserName: userData.Name, | 1623 | UserName: userData.Name, |
| 1636 | CompanyName: companyData.Name, | 1624 | CompanyName: companyData.Name, |
| 1637 | SupperUserName: "", | 1625 | SupperUserName: "", |
| 1638 | - DutyTime: userData.CreatedAt.Local().Format("2006-01-02 15:04:05"), | 1626 | + DutyTime: userData.EntryTime, |
| 1639 | } | 1627 | } |
| 1640 | for _, v := range supperUserList { | 1628 | for _, v := range supperUserList { |
| 1641 | userInfo.SupperUserName = userInfo.SupperUserName + v.Name + " " | 1629 | userInfo.SupperUserName = userInfo.SupperUserName + v.Name + " " |
| @@ -1665,6 +1653,13 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | @@ -1665,6 +1653,13 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | ||
| 1665 | if err != nil { | 1653 | if err != nil { |
| 1666 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error()) | 1654 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error()) |
| 1667 | } | 1655 | } |
| 1656 | + | ||
| 1657 | + //检查截止时间 | ||
| 1658 | + endTimeInt := assessData.EndTime.Unix() | ||
| 1659 | + if endTimeInt < time.Now().Unix() { | ||
| 1660 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "当前环节已过截止时间,提交后无法修改内容") | ||
| 1661 | + } | ||
| 1662 | + | ||
| 1668 | assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{ | 1663 | assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{ |
| 1669 | "transactionContext": transactionContext, | 1664 | "transactionContext": transactionContext, |
| 1670 | }) | 1665 | }) |
| @@ -1672,7 +1667,6 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | @@ -1672,7 +1667,6 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | ||
| 1672 | assessContentList := []*domain.StaffAssessContent{} | 1667 | assessContentList := []*domain.StaffAssessContent{} |
| 1673 | if assessData.Status == domain.StaffAssessCompleted { | 1668 | if assessData.Status == domain.StaffAssessCompleted { |
| 1674 | //已完成 | 1669 | //已完成 |
| 1675 | - | ||
| 1676 | _, assessContentList, err = assessContentRepo.Find(map[string]interface{}{ | 1670 | _, assessContentList, err = assessContentRepo.Find(map[string]interface{}{ |
| 1677 | "staffAssessId": assessData.Id, | 1671 | "staffAssessId": assessData.Id, |
| 1678 | }) | 1672 | }) |
| @@ -1700,6 +1694,12 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | @@ -1700,6 +1694,12 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | ||
| 1700 | continue | 1694 | continue |
| 1701 | } | 1695 | } |
| 1702 | v.Value = item.Value | 1696 | v.Value = item.Value |
| 1697 | + //填入评估值描述 | ||
| 1698 | + reteResult, err := v.Rule.ScoreOrRating(&v.Value) | ||
| 1699 | + if err != nil { | ||
| 1700 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 1701 | + } | ||
| 1702 | + v.ReteResult = reteResult | ||
| 1703 | for ii := range v.Remark { | 1703 | for ii := range v.Remark { |
| 1704 | for _, vvv := range item.Remark { | 1704 | for _, vvv := range item.Remark { |
| 1705 | if v.Remark[ii].Title == vvv.Title { | 1705 | if v.Remark[ii].Title == vvv.Title { |
| @@ -1708,6 +1708,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | @@ -1708,6 +1708,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | ||
| 1708 | } | 1708 | } |
| 1709 | } | 1709 | } |
| 1710 | } | 1710 | } |
| 1711 | + | ||
| 1711 | } | 1712 | } |
| 1712 | 1713 | ||
| 1713 | //保存信息 | 1714 | //保存信息 |
| @@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" | 6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" |
| 7 | ) | 7 | ) |
| 8 | 8 | ||
| 9 | +//调试用,手动调用CreateStaffAssessTask | ||
| 9 | func (srv StaffAssessServeice) InvokCreateStaffAssessTask(param *command.CreateStaffAssessTask) (map[string]interface{}, error) { | 10 | func (srv StaffAssessServeice) InvokCreateStaffAssessTask(param *command.CreateStaffAssessTask) (map[string]interface{}, error) { |
| 10 | transactionContext, err := factory.CreateTransactionContext(nil) | 11 | transactionContext, err := factory.CreateTransactionContext(nil) |
| 11 | if err != nil { | 12 | if err != nil { |
| @@ -8,7 +8,7 @@ const ( | @@ -8,7 +8,7 @@ const ( | ||
| 8 | ProjectStateWaitConfig int = 0 // 项目状态-待完成配置 | 8 | ProjectStateWaitConfig int = 0 // 项目状态-待完成配置 |
| 9 | ProjectStateWaitActive int = 1 // 项目状态-待启用 | 9 | ProjectStateWaitActive int = 1 // 项目状态-待启用 |
| 10 | ProjectStateEnable int = 2 // 项目状态-启用 | 10 | ProjectStateEnable int = 2 // 项目状态-启用 |
| 11 | - ProjectStateDisable int = 3 // 项目状态-停用 | 11 | + ProjectStateDisable int = 3 // 项目状态-停用(假状态) |
| 12 | ) | 12 | ) |
| 13 | 13 | ||
| 14 | // 项目的评估内容配置 | 14 | // 项目的评估内容配置 |
| @@ -25,6 +25,8 @@ type EvaluationProject struct { | @@ -25,6 +25,8 @@ type EvaluationProject struct { | ||
| 25 | PmpIds []string `json:"pmpIds" comment:"项目管理员ID"` | 25 | PmpIds []string `json:"pmpIds" comment:"项目管理员ID"` |
| 26 | Recipients []string `json:"recipients" comment:"被评估人ID"` | 26 | Recipients []string `json:"recipients" comment:"被评估人ID"` |
| 27 | Template *EvaluationTemplate `json:"template" comment:"评估模板"` | 27 | Template *EvaluationTemplate `json:"template" comment:"评估模板"` |
| 28 | + BeginTime time.Time `json:"beginTime" comment:"项目起始时间"` | ||
| 29 | + EndTime time.Time `json:"endTime" comment:"项目截至时间"` | ||
| 28 | CreatedAt time.Time `json:"createdAt" comment:"创建时间"` | 30 | CreatedAt time.Time `json:"createdAt" comment:"创建时间"` |
| 29 | UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"` | 31 | UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"` |
| 30 | DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` | 32 | DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` |
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "errors" | ||
| 5 | + "fmt" | ||
| 6 | + "strconv" | ||
| 4 | "time" | 7 | "time" |
| 5 | ) | 8 | ) |
| 6 | 9 | ||
| @@ -55,6 +58,55 @@ type EvaluationRule struct { | @@ -55,6 +58,55 @@ type EvaluationRule struct { | ||
| 55 | DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` | 58 | DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` |
| 56 | } | 59 | } |
| 57 | 60 | ||
| 61 | +// 根据评估填写的值,得出等级名称 | ||
| 62 | +// 如果 评估方式是评分,对评估填写的值的小数点后的位数进行处理, | ||
| 63 | +// value 根据评估填写的值 | ||
| 64 | +func (rule *EvaluationRule) ScoreOrRating(value *string) (string, error) { | ||
| 65 | + switch rule.Type { | ||
| 66 | + case EvaluationTypeRating: | ||
| 67 | + return rule.RatingValue(value) | ||
| 68 | + case EvaluationTypeScore: | ||
| 69 | + return rule.ScoreValue(value) | ||
| 70 | + } | ||
| 71 | + return "", errors.New("rule.Type 错误") | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +//根据评估填写的值,得出等级名称, | ||
| 75 | +func (rule *EvaluationRule) ScoreValue(value *string) (string, error) { | ||
| 76 | + valueFloat, err := strconv.ParseFloat(*value, 64) | ||
| 77 | + if err != nil { | ||
| 78 | + return "", errors.New("评分填写的值错误") | ||
| 79 | + } | ||
| 80 | + if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max { | ||
| 81 | + return "", fmt.Errorf("评分填写的值超出限制,>=%f且<=%f", rule.Score.Min, rule.Score.Max) | ||
| 82 | + } | ||
| 83 | + //保留小数处理 | ||
| 84 | + fStr := fmt.Sprintf("%%.%df", rule.Score.DecimalPlaces) | ||
| 85 | + valueStr := fmt.Sprintf(fStr, valueFloat) | ||
| 86 | + *value = valueStr | ||
| 87 | + if rule.Score.IntervalState == 0 { | ||
| 88 | + // 未开启按分数子区间匹配等级 | ||
| 89 | + return "", nil | ||
| 90 | + } | ||
| 91 | + valueDescrip := "" | ||
| 92 | + for _, v := range rule.Score.Levels { | ||
| 93 | + if valueFloat >= v.Start && valueFloat <= v.End { | ||
| 94 | + valueDescrip = v.Name | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + return valueDescrip, nil | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +//根据评估填写的值,得出等级名称, | ||
| 101 | +func (rule *EvaluationRule) RatingValue(value *string) (string, error) { | ||
| 102 | + for _, v := range rule.Rating.Levels { | ||
| 103 | + if v.Code == *value { | ||
| 104 | + return v.Name, nil | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + return "", errors.New("评估填写的值错误") | ||
| 108 | +} | ||
| 109 | + | ||
| 58 | // GenerateSysRule 当前公司下的生成默认规则 | 110 | // GenerateSysRule 当前公司下的生成默认规则 |
| 59 | func GenerateSysRule(companyId int64) *EvaluationRule { | 111 | func GenerateSysRule(companyId int64) *EvaluationRule { |
| 60 | levels := make([]*RatingLevel, 0) | 112 | levels := make([]*RatingLevel, 0) |
| @@ -10,7 +10,7 @@ type StaffAssessTask struct { | @@ -10,7 +10,7 @@ type StaffAssessTask struct { | ||
| 10 | EvaluationProjectName string `json:"evaluationProjectName"` //项目名称 | 10 | EvaluationProjectName string `json:"evaluationProjectName"` //项目名称 |
| 11 | CycleId int64 `json:"cycleId"` //对应的周期id | 11 | CycleId int64 `json:"cycleId"` //对应的周期id |
| 12 | CycleName string `json:"cycleName"` //对应周期的名称 | 12 | CycleName string `json:"cycleName"` //对应周期的名称 |
| 13 | - BeginDay string `json:"beginDay"` //绩效考核日期 | 13 | + BeginDay string `json:"beginDay"` //绩效考核日期 ,2006-01-02 |
| 14 | BeginTime time.Time `json:"beginTime"` //绩效考核开始时间 | 14 | BeginTime time.Time `json:"beginTime"` //绩效考核开始时间 |
| 15 | EndTime time.Time `json:"endTime"` //绩效考核截止时间 | 15 | EndTime time.Time `json:"endTime"` //绩效考核截止时间 |
| 16 | StepList []AssessTaskStep `json:"stepList"` //考评的流程 | 16 | StepList []AssessTaskStep `json:"stepList"` //考评的流程 |
| @@ -30,6 +30,12 @@ type AssessTaskStep struct { | @@ -30,6 +30,12 @@ type AssessTaskStep struct { | ||
| 30 | EndTime time.Time `json:"endTime"` //绩效考核截止时间 | 30 | EndTime time.Time `json:"endTime"` //绩效考核截止时间 |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | +type SortTaskStep []AssessTaskStep | ||
| 34 | + | ||
| 35 | +func (a SortTaskStep) Len() int { return len(a) } | ||
| 36 | +func (a SortTaskStep) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | ||
| 37 | +func (a SortTaskStep) Less(i, j int) bool { return a[i].SortBy < a[j].SortBy } | ||
| 38 | + | ||
| 33 | type StaffAssessTaskRepository interface { | 39 | type StaffAssessTaskRepository interface { |
| 34 | Save(param *StaffAssessTask) (*StaffAssessTask, error) | 40 | Save(param *StaffAssessTask) (*StaffAssessTask, error) |
| 35 | Remove(id int) error | 41 | Remove(id int) error |
| @@ -56,7 +56,7 @@ func (d *StaffAssessDao) CountInviteAssessByTargetUser(userIds []int, assessTask | @@ -56,7 +56,7 @@ func (d *StaffAssessDao) CountInviteAssessByTargetUser(userIds []int, assessTask | ||
| 56 | return result, err | 56 | return result, err |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | -// 搜索 executorId 参与的评估任务 | 59 | +// 根据评估的人执行人id,搜索 executorId参与的评估任务 |
| 60 | func (d *StaffAssessDao) SearchAssessTaskMe(executorId int, companyId int, limit int, offset int) ([]*domain.StaffAssessTask, error) { | 60 | func (d *StaffAssessDao) SearchAssessTaskMe(executorId int, companyId int, limit int, offset int) ([]*domain.StaffAssessTask, error) { |
| 61 | 61 | ||
| 62 | if limit < 0 { | 62 | if limit < 0 { |
| @@ -70,6 +70,7 @@ func (d *StaffAssessDao) SearchAssessTaskMe(executorId int, companyId int, limit | @@ -70,6 +70,7 @@ func (d *StaffAssessDao) SearchAssessTaskMe(executorId int, companyId int, limit | ||
| 70 | JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id" | 70 | JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id" |
| 71 | WHERE staff_assess.company_id=? | 71 | WHERE staff_assess.company_id=? |
| 72 | and staff_assess.executor->>'userId'='?' | 72 | and staff_assess.executor->>'userId'='?' |
| 73 | + order by staff_assess_task.id desc | ||
| 73 | limit ? offset ? | 74 | limit ? offset ? |
| 74 | ` | 75 | ` |
| 75 | tx := d.transactionContext.PgTx | 76 | tx := d.transactionContext.PgTx |
| @@ -19,6 +19,8 @@ type EvaluationProject struct { | @@ -19,6 +19,8 @@ type EvaluationProject struct { | ||
| 19 | PmpIds []string `comment:"项目管理员ID"` | 19 | PmpIds []string `comment:"项目管理员ID"` |
| 20 | Recipients []string `comment:"被评估人ID"` | 20 | Recipients []string `comment:"被评估人ID"` |
| 21 | Template *domain.EvaluationTemplate `comment:"评估模板"` | 21 | Template *domain.EvaluationTemplate `comment:"评估模板"` |
| 22 | + BeginTime time.Time `comment:"项目起始时间"` | ||
| 23 | + EndTime time.Time `comment:"项目截至时间 "` | ||
| 22 | CreatedAt time.Time `comment:"创建时间"` | 24 | CreatedAt time.Time `comment:"创建时间"` |
| 23 | UpdatedAt time.Time `comment:"更新时间"` | 25 | UpdatedAt time.Time `comment:"更新时间"` |
| 24 | DeletedAt *time.Time `comment:"删除时间"` | 26 | DeletedAt *time.Time `comment:"删除时间"` |
| 1 | -package models | ||
| 2 | - | ||
| 3 | -import ( | ||
| 4 | - "time" | ||
| 5 | -) | ||
| 6 | - | ||
| 7 | -type NodeTimerTask struct { | ||
| 8 | - tableName struct{} `pg:"node_timer_task" comment:"流程节点定时任务"` | ||
| 9 | - Id int64 `comment:"ID"` | ||
| 10 | - CompanyId int64 `comment:"公司ID"` | ||
| 11 | - CycleId int64 `comment:"周期ID"` | ||
| 12 | - ProjectId int64 `comment:"项目ID"` | ||
| 13 | - NodeId int64 `comment:"流程ID"` | ||
| 14 | - LastSentAt *time.Time `comment:"最后一次发送时间"` | ||
| 15 | - NextSentAt *time.Time `comment:"下一次发送时间"` | ||
| 16 | - CreatedAt time.Time `comment:"创建时间"` | ||
| 17 | - UpdatedAt time.Time `comment:"更新时间"` | ||
| 18 | - DeletedAt *time.Time `comment:"删除时间"` | ||
| 19 | -} |
| @@ -148,6 +148,9 @@ func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{}) | @@ -148,6 +148,9 @@ func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{}) | ||
| 148 | query.Where("time_end>=?", t) | 148 | query.Where("time_end>=?", t) |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | + // 按创建时间降序 | ||
| 152 | + query.Order("created_at DESC") | ||
| 153 | + | ||
| 151 | count, err := query.SelectAndCount() | 154 | count, err := query.SelectAndCount() |
| 152 | if err != nil { | 155 | if err != nil { |
| 153 | return 0, nil, err | 156 | return 0, nil, err |
| @@ -34,6 +34,8 @@ func (repo *EvaluationProjectRepository) TransformToDomain(m *models.EvaluationP | @@ -34,6 +34,8 @@ func (repo *EvaluationProjectRepository) TransformToDomain(m *models.EvaluationP | ||
| 34 | PmpIds: m.PmpIds, | 34 | PmpIds: m.PmpIds, |
| 35 | Recipients: m.Recipients, | 35 | Recipients: m.Recipients, |
| 36 | Template: m.Template, | 36 | Template: m.Template, |
| 37 | + BeginTime: m.BeginTime, | ||
| 38 | + EndTime: m.EndTime, | ||
| 37 | CreatedAt: m.CreatedAt, | 39 | CreatedAt: m.CreatedAt, |
| 38 | UpdatedAt: m.UpdatedAt, | 40 | UpdatedAt: m.UpdatedAt, |
| 39 | DeletedAt: m.DeletedAt, | 41 | DeletedAt: m.DeletedAt, |
| @@ -54,6 +56,8 @@ func (repo *EvaluationProjectRepository) TransformToModel(d *domain.EvaluationPr | @@ -54,6 +56,8 @@ func (repo *EvaluationProjectRepository) TransformToModel(d *domain.EvaluationPr | ||
| 54 | PmpIds: d.PmpIds, | 56 | PmpIds: d.PmpIds, |
| 55 | Recipients: d.Recipients, | 57 | Recipients: d.Recipients, |
| 56 | Template: d.Template, | 58 | Template: d.Template, |
| 59 | + BeginTime: d.BeginTime, | ||
| 60 | + EndTime: d.EndTime, | ||
| 57 | CreatedAt: d.CreatedAt, | 61 | CreatedAt: d.CreatedAt, |
| 58 | UpdatedAt: d.UpdatedAt, | 62 | UpdatedAt: d.UpdatedAt, |
| 59 | DeletedAt: d.DeletedAt, | 63 | DeletedAt: d.DeletedAt, |
| @@ -166,6 +170,8 @@ func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{ | @@ -166,6 +170,8 @@ func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{ | ||
| 166 | if v, ok := queryOptions["offset"].(int64); ok { | 170 | if v, ok := queryOptions["offset"].(int64); ok { |
| 167 | query.Offset(int(v)) | 171 | query.Offset(int(v)) |
| 168 | } | 172 | } |
| 173 | + // 按创建时间降序 | ||
| 174 | + query.Order("created_at DESC") | ||
| 169 | 175 | ||
| 170 | count, err := query.SelectAndCount() | 176 | count, err := query.SelectAndCount() |
| 171 | if err != nil { | 177 | if err != nil { |
| @@ -147,12 +147,15 @@ func (repo *StaffAssessRepository) Find(queryOptions map[string]interface{}) (in | @@ -147,12 +147,15 @@ func (repo *StaffAssessRepository) Find(queryOptions map[string]interface{}) (in | ||
| 147 | if v, ok := queryOptions["id"]; ok { | 147 | if v, ok := queryOptions["id"]; ok { |
| 148 | query.Where("id=?", v) | 148 | query.Where("id=?", v) |
| 149 | } | 149 | } |
| 150 | - if v, ok := queryOptions["typesList"].([]string); ok && len(v) > 0 { | 150 | + if v, ok := queryOptions["typesList"].([]string); ok { |
| 151 | query.Where("types in(?)", pg.In(v)) | 151 | query.Where("types in(?)", pg.In(v)) |
| 152 | } | 152 | } |
| 153 | - if v, ok := queryOptions["status"].(string); ok && len(v) > 0 { | 153 | + if v, ok := queryOptions["status"].(string); ok { |
| 154 | query.Where("status=?", v) | 154 | query.Where("status=?", v) |
| 155 | } | 155 | } |
| 156 | + if v, ok := queryOptions["endTime"]; ok { | ||
| 157 | + query.Where("end_time<=?", v) | ||
| 158 | + } | ||
| 156 | count, err := query.SelectAndCount() | 159 | count, err := query.SelectAndCount() |
| 157 | if err != nil { | 160 | if err != nil { |
| 158 | return 0, nil, err | 161 | return 0, nil, err |
| @@ -21,8 +21,6 @@ func (controller *ProjectController) CreateProject() { | @@ -21,8 +21,6 @@ func (controller *ProjectController) CreateProject() { | ||
| 21 | ua := middlewares.GetUser(controller.Ctx) | 21 | ua := middlewares.GetUser(controller.Ctx) |
| 22 | in.CompanyId = ua.CompanyId | 22 | in.CompanyId = ua.CompanyId |
| 23 | in.CreatorId = ua.UserId | 23 | in.CreatorId = ua.UserId |
| 24 | - //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
| 25 | - //in.CreatorId = middlewares.GetUserId(controller.Ctx) | ||
| 26 | controller.Response(ruService.Create(in)) | 24 | controller.Response(ruService.Create(in)) |
| 27 | } | 25 | } |
| 28 | } | 26 | } |
| @@ -35,7 +33,6 @@ func (controller *ProjectController) UpdateProject() { | @@ -35,7 +33,6 @@ func (controller *ProjectController) UpdateProject() { | ||
| 35 | } else { | 33 | } else { |
| 36 | ua := middlewares.GetUser(controller.Ctx) | 34 | ua := middlewares.GetUser(controller.Ctx) |
| 37 | in.CompanyId = ua.CompanyId | 35 | in.CompanyId = ua.CompanyId |
| 38 | - //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
| 39 | controller.Response(ruService.Update(in)) | 36 | controller.Response(ruService.Update(in)) |
| 40 | } | 37 | } |
| 41 | } | 38 | } |
| @@ -48,7 +45,6 @@ func (controller *ProjectController) UpdateProjectForTemplate() { | @@ -48,7 +45,6 @@ func (controller *ProjectController) UpdateProjectForTemplate() { | ||
| 48 | } else { | 45 | } else { |
| 49 | ua := middlewares.GetUser(controller.Ctx) | 46 | ua := middlewares.GetUser(controller.Ctx) |
| 50 | in.CompanyId = ua.CompanyId | 47 | in.CompanyId = ua.CompanyId |
| 51 | - //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
| 52 | controller.Response(ruService.UpdateTemplate(in)) | 48 | controller.Response(ruService.UpdateTemplate(in)) |
| 53 | } | 49 | } |
| 54 | } | 50 | } |
| @@ -86,7 +82,6 @@ func (controller *ProjectController) ListProject() { | @@ -86,7 +82,6 @@ func (controller *ProjectController) ListProject() { | ||
| 86 | } | 82 | } |
| 87 | ua := middlewares.GetUser(controller.Ctx) | 83 | ua := middlewares.GetUser(controller.Ctx) |
| 88 | in.CompanyId = ua.CompanyId | 84 | in.CompanyId = ua.CompanyId |
| 89 | - //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
| 90 | controller.Response(ruService.List(in)) | 85 | controller.Response(ruService.List(in)) |
| 91 | } | 86 | } |
| 92 | } | 87 | } |
| @@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
| 5 | timeconv "github.com/Andrew-M-C/go.timeconv" | 5 | timeconv "github.com/Andrew-M-C/go.timeconv" |
| 6 | "github.com/beego/beego/v2/core/validation" | 6 | "github.com/beego/beego/v2/core/validation" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
| 8 | + "math" | ||
| 8 | "reflect" | 9 | "reflect" |
| 9 | "strings" | 10 | "strings" |
| 10 | "time" | 11 | "time" |
| @@ -53,24 +54,92 @@ func NextTime(now0 time.Time, start time.Time, kpiCycle int) time.Time { | @@ -53,24 +54,92 @@ func NextTime(now0 time.Time, start time.Time, kpiCycle int) time.Time { | ||
| 53 | nextTime = timeconv.AddDate(start0, 0, 0, cycleCount*7) | 54 | nextTime = timeconv.AddDate(start0, 0, 0, cycleCount*7) |
| 54 | break | 55 | break |
| 55 | case domain.KpiCycleOneMonth: | 56 | case domain.KpiCycleOneMonth: |
| 56 | - nextTime = timeconv.AddDate(start0, 0, 1, 0) | 57 | + offsetMonth := SubMonth(now0, start0) |
| 58 | + nextTime = timeconv.AddDate(start0, 0, offsetMonth, 0) | ||
| 59 | + if nextTime.Before(now0) { | ||
| 60 | + nextTime = timeconv.AddDate(nextTime, 0, 1, 0) | ||
| 61 | + } | ||
| 57 | break | 62 | break |
| 58 | case domain.KpiCycleTwoMonth: | 63 | case domain.KpiCycleTwoMonth: |
| 59 | - nextTime = timeconv.AddDate(start0, 0, 2, 0) | 64 | + offsetMonth := SubMonth(now0, start0) |
| 65 | + multiple := float64(offsetMonth) / 2 | ||
| 66 | + if multiple == 0 { | ||
| 67 | + multiple = 1 | ||
| 68 | + } else { | ||
| 69 | + multiple = math.Ceil(multiple) | ||
| 70 | + } | ||
| 71 | + nextTime = timeconv.AddDate(start0, 0, int(multiple)*2, 0) | ||
| 72 | + if nextTime.Before(now0) { | ||
| 73 | + nextTime = timeconv.AddDate(nextTime, 0, 2, 0) | ||
| 74 | + } | ||
| 60 | break | 75 | break |
| 61 | case domain.KpiCycleThreeMonth: | 76 | case domain.KpiCycleThreeMonth: |
| 62 | - nextTime = timeconv.AddDate(start0, 0, 3, 0) | 77 | + offsetMonth := SubMonth(now0, start0) |
| 78 | + multiple := float64(offsetMonth) / 3 | ||
| 79 | + if multiple == 0 { | ||
| 80 | + multiple = 1 | ||
| 81 | + } else { | ||
| 82 | + multiple = math.Ceil(multiple) | ||
| 83 | + } | ||
| 84 | + nextTime = timeconv.AddDate(start0, 0, int(multiple)*3, 0) | ||
| 85 | + if nextTime.Before(now0) { | ||
| 86 | + nextTime = timeconv.AddDate(nextTime, 0, 3, 0) | ||
| 87 | + } | ||
| 63 | break | 88 | break |
| 64 | case domain.KpiCycleSixMonth: | 89 | case domain.KpiCycleSixMonth: |
| 65 | - nextTime = timeconv.AddDate(start0, 0, 6, 0) | 90 | + offsetMonth := SubMonth(now0, start0) |
| 91 | + multiple := float64(offsetMonth) / 6 | ||
| 92 | + if multiple == 0 { | ||
| 93 | + multiple = 1 | ||
| 94 | + } else { | ||
| 95 | + multiple = math.Ceil(multiple) | ||
| 96 | + } | ||
| 97 | + nextTime = timeconv.AddDate(start0, 0, int(multiple)*6, 0) | ||
| 98 | + if nextTime.Before(now0) { | ||
| 99 | + nextTime = timeconv.AddDate(nextTime, 0, 6, 0) | ||
| 100 | + } | ||
| 66 | break | 101 | break |
| 67 | case domain.KpiCycleYear: | 102 | case domain.KpiCycleYear: |
| 68 | - nextTime = timeconv.AddDate(start0, 1, 0, 0) | 103 | + offsetMonth := SubMonth(now0, start0) |
| 104 | + multiple := float64(offsetMonth) / 12 | ||
| 105 | + if multiple == 0 { | ||
| 106 | + multiple = 1 | ||
| 107 | + } else { | ||
| 108 | + multiple = math.Ceil(multiple) | ||
| 109 | + } | ||
| 110 | + nextTime = timeconv.AddDate(start0, 0, int(multiple)*12, 0) | ||
| 111 | + if nextTime.Before(now0) { | ||
| 112 | + nextTime = timeconv.AddDate(nextTime, 0, 12, 0) | ||
| 113 | + } | ||
| 69 | break | 114 | break |
| 70 | } | 115 | } |
| 71 | return nextTime | 116 | return nextTime |
| 72 | } | 117 | } |
| 73 | 118 | ||
| 119 | +// SubMonth 计算日期相差多少月 | ||
| 120 | +func SubMonth(t1, t2 time.Time) (month int) { | ||
| 121 | + y1 := t1.Year() | ||
| 122 | + y2 := t2.Year() | ||
| 123 | + m1 := int(t1.Month()) | ||
| 124 | + m2 := int(t2.Month()) | ||
| 125 | + d1 := t1.Day() | ||
| 126 | + d2 := t2.Day() | ||
| 127 | + | ||
| 128 | + yearInterval := y1 - y2 | ||
| 129 | + // 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数 | ||
| 130 | + if m1 < m2 || (m1 == m2 && d1 < d2) { | ||
| 131 | + yearInterval-- | ||
| 132 | + } | ||
| 133 | + // 获取月数差值 | ||
| 134 | + monthInterval := (m1 + 12) - m2 | ||
| 135 | + if d1 < d2 { | ||
| 136 | + monthInterval-- | ||
| 137 | + } | ||
| 138 | + monthInterval %= 12 | ||
| 139 | + month = yearInterval*12 + monthInterval | ||
| 140 | + return | ||
| 141 | +} | ||
| 142 | + | ||
| 74 | // NextTimeInc 0点时刻为标准计算 | 143 | // NextTimeInc 0点时刻为标准计算 |
| 75 | func NextTimeInc(start time.Time, kpiCycle int) time.Time { | 144 | func NextTimeInc(start time.Time, kpiCycle int) time.Time { |
| 76 | year, month, day := start.Date() | 145 | year, month, day := start.Date() |
-
请 注册 或 登录 后发表评论