作者 庄敏学
FROM golang:latest
FROM 192.168.0.243:5000/mmm/performance-back:20221121test
#FROM 192.168.0.243:5000/mmm/digital-platform:20220831
ENV APP_DIR $GOPATH/src/performance
RUN mkdir -p $APP_DIR
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-prd get pods | grep -q performance-back
if [ "$?" == "1" ];then
kubectl create -f /tmp/prd/performance-back/performance-back.yaml --record
kubectl -n mmm-suplus-prd get svc | grep -q performance-back
if [ "$?" == "0" ];then
echo "performance-back service install success!"
else
echo "performance-back service install fail!"
fi
kubectl -n mmm-suplus-prd get pods | grep -q performance-back
if [ "$?" == "0" ];then
echo "performance-back deployment install success!"
else
echo "performance-back deployment install fail!"
fi
else
kubectl delete -f /tmp/prd/performance-back/performance-back.yaml
kubectl -n mmm-suplus-prd get svc | grep -q performance-back
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-prd get svc | grep -q performance-back
done
kubectl -n mmm-suplus-prd get pods | grep -q performance-back
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-prd get pods | grep -q performance-back
done
kubectl create -f /tmp/prd/performance-back/performance-back.yaml --record
kubectl -n mmm-suplus-prd get svc | grep -q performance-back
if [ "$?" == "0" ];then
echo "performance-back service update success!"
else
echo "performance-back service update fail!"
fi
kubectl -n mmm-suplus-prd get pods | grep -q performance-back
if [ "$?" == "0" ];then
echo "performance-back deployment update success!"
else
echo "performance-back deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: performance-back
namespace: mmm-suplus-prd
labels:
k8s-app: performance-back
spec:
ports:
- name: "http"
port: 80
targetPort: 8082
- name: "https"
port: 443
targetPort: 443
selector:
k8s-app: performance-back
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: performance-back
namespace: mmm-suplus-prd
labels:
k8s-app: performance-back
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: performance-back
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1ze
- cn-hangzhou.i-bp1djh1xn7taumbue1zd
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: performance-back
image: 192.168.0.243:5000/mmm/performance-back:master
imagePullPolicy: Always
ports:
- containerPort: 8082
- containerPort: 443
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
env:
- name: LOG_LEVEL
value: "debug"
- name: LOG_FILE
value: "true"
- name: ERROR_BASE_CODE
value: "1"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: POSTGRESQL_DB_NAME
value: "performance_prd"
- name: ENABLE_HTTPS
value: "true"
- name: POSTGRESQL_USER
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.user
- name: POSTGRESQL_PASSWORD
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.password
- name: POSTGRESQL_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.host
- name: POSTGRESQL_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.port
- name: REDIS_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: redis.ip
- name: REDIS_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: redis.port
- name: KAFKA_HOSTS
valueFrom:
configMapKeyRef:
name: suplus-config
key: kafka.host
- name: KAFKA_PERFORMANCE_ID
valueFrom:
configMapKeyRef:
name: suplus-config
key: kafkaperformance.id
- name: KAFKA_BUSINESS_TOPIC
value: "mmm_business_prd"
- name: UCENTER_SERVICE_HOST
value: "https://suplus-ucenter-prd.fjmaimaimai.com"
- name: BUSINESS_ADMIN_SERVICE_HOST
value: "https://suplus-business-admin-prd.fjmaimaimai.com"
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
... ... @@ -7,6 +7,7 @@ import (
serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
_ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer"
)
func main() {
... ... @@ -17,7 +18,7 @@ func main() {
// for k, v := range methods {
// fmt.Printf("%s => %v \n", k, v)
// }
// go consumer.Run()
go consumer.Run()
web.Run()
}
... ...
... ... @@ -88,16 +88,20 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
}
}
}
ruleMap := map[int64]*domain.EvaluationRule{}
ruleIds := make([]int64, 0)
for k := range ruleIdsMap {
ruleIds = append(ruleIds, k)
}
_, rules, err := ruleRepository.Find(map[string]interface{}{"ids": ruleIds, "companyId": in.CompanyId})
ruleMap := map[int64]*domain.EvaluationRule{}
for i := range rules {
ruleMap[rules[i].Id] = rules[i]
if len(ruleIds) > 0 {
if _, rules, err := ruleRepository.Find(map[string]interface{}{"ids": ruleIds, "companyId": in.CompanyId}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for i := range rules {
ruleMap[rules[i].Id] = rules[i]
}
}
}
ctAdapter := &adapter.CycleTemplateAdapter{}
... ... @@ -307,7 +311,10 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
// 删除周期
cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -316,11 +323,34 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// FIXME 删除周期关联的所有模板... 还需要删除关联的定时内容
// 删除周期关联的所有模板,真删
if err := cycleTemplateRepository.BatchDeleteByCycleId(cycle.Id); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 删除周期下的所有项目
_, projects, err := projectRepository.Find(map[string]interface{}{"cycleId": in.Id}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range projects {
if _, err := projectRepository.Remove(projects[i]); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
// 删除周期下的所有任务
tasks, err := taskRepository.Find(map[string]interface{}{"cycleId": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range tasks {
if _, err := taskRepository.Remove(tasks[i]); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -17,16 +17,14 @@ type UpdateProjectCommand struct {
}
type UpdateProjectTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string"`
Recipients []string `cname:"被评估人ID" json:"recipients"`
TimeStart string `cname:"自评起始时间" json:"timeStart" valid:"Required"`
TimeEnd string `cname:"自评截止时间" json:"timeEnd" valid:"Required"`
KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"`
KpiResultStart string `cname:"绩效结果开始查看时间" json:"kpiResultStart"`
Activate int `cname:"启动项目" json:"activate"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string"`
Recipients []string `cname:"被评估人ID" json:"recipients"`
TimeStart string `cname:"自评起始时间" json:"timeStart" valid:"Required"`
TimeEnd string `cname:"自评截止时间" json:"timeEnd" valid:"Required"`
KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"`
}
type CheckRecipientCommand struct {
... ...
... ... @@ -135,110 +135,169 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "template")
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.CycleId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 如果是已经启用的项目,只能编辑环节的截至时间
if project.State == domain.ProjectStateEnable {
end, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeEnd, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 周期内的所有项目,员工不能重复被评估
rids := map[string]bool{}
for i := range projects {
// 排除当前项目
if in.Id != projects[i].Id {
ids := projects[i].Recipients
for j := range ids {
rids[ids[j]] = true
cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.CycleId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
maxTime := cycle.TimeEnd.Local()
if end.After(maxTime) {
return nil, application.ThrowError(application.BUSINESS_ERROR, "评估截至时间不能超出周期截至时间")
}
if project.Template != nil {
for i := range project.Template.LinkNodes {
node := project.Template.LinkNodes[i]
node.TimeEnd = &end
}
}
}
repeatNum := 0
for i := range in.Recipients {
id := in.Recipients[i]
if _, ok := rids[id]; ok {
repeatNum++
// 项目起始截止时间(暂时环节中的时间未分开)
project.EndTime = end
project, err = projectRepository.Insert(project)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if repeatNum > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("有%d人已经在本周期其他项目内,需要将他们移除", repeatNum))
}
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 查看任务过程,重新日计算任务截至期
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
tasks, err := taskRepository.Find(map[string]interface{}{"projectId": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
now := time.Now().Local()
nowO := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) // 当前时间0点0分0秒时刻
for i := range tasks {
task := tasks[i]
task.TimeEnd = &end
// 重新计算
if task.NextSentAt == nil {
// 环节起始和截止本地时间
startLocal := task.TimeStart.Local()
endLocal := task.TimeEnd.Local()
// 在当前时间之前,则计算下一个周期时间
if startLocal.Before(now) {
nextTime := utils.NextTime(nowO, startLocal, task.KpiCycle)
task.NextSentAt = &nextTime
} else {
task.NextSentAt = &startLocal
}
// 如果超出截至时间,则周期置空
if task.NextSentAt.After(endLocal) {
task.NextSentAt = nil
}
} else {
// 新的截止时间在下一次发送周期任务之前,则结束
if end.Before(task.NextSentAt.Local()) {
task.NextSentAt = nil
} else {
// do nothing
}
}
}
if cycleTemplate == nil || cycleTemplate.Template == nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加模板")
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return project, nil
if len(in.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
} else {
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 周期内的所有项目,员工不能重复被评估
rids := map[string]bool{}
for i := range projects {
// 排除当前项目
if in.Id != projects[i].Id {
ids := projects[i].Recipients
for j := range ids {
rids[ids[j]] = true
}
}
}
repeatNum := 0
for i := range in.Recipients {
id := in.Recipients[i]
if _, ok := rids[id]; ok {
repeatNum++
}
}
if repeatNum > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("有%d人已经在本周期其他项目内,需要将他们移除", repeatNum))
}
start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
end, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeEnd, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
kpiStart, err := time.ParseInLocation("2006-01-02 15:04:05", in.KpiResultStart, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cycleTemplate == nil || cycleTemplate.Template == nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加模板")
}
minTime := cycle.TimeStart.Local()
maxTime := cycle.TimeEnd.Local()
start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
end, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeEnd, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if start.Before(minTime) {
return nil, application.ThrowError(application.BUSINESS_ERROR, "评估起始时间不能超出周期起始时间")
}
cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.CycleId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
minTime := cycle.TimeStart.Local()
maxTime := cycle.TimeEnd.Local()
if end.After(maxTime) {
return nil, application.ThrowError(application.BUSINESS_ERROR, "评估截至时间不能超出周期截至时间")
}
if start.Before(minTime) {
return nil, application.ThrowError(application.BUSINESS_ERROR, "评估起始时间不能超出周期起始时间")
}
//// FIXME 启动时,需要激活定时任务
//if in.Activate == 1 {
// project.State = domain.ProjectStateEnable
//} else {
// project.State = domain.ProjectStateWaitActive
//}
project.State = domain.ProjectStateWaitActive
if end.After(maxTime) {
return nil, application.ThrowError(application.BUSINESS_ERROR, "评估截至时间不能超出周期截至时间")
}
project.Recipients = in.Recipients
project.Template = cycleTemplate.Template
for i := range project.Template.LinkNodes {
node := project.Template.LinkNodes[i]
node.KpiCycle = in.KpiCycle // 设置周期
if node.Type == domain.LinkNodeViewResult {
node.TimeStart = &kpiStart
node.TimeEnd = &maxTime // 绩效查看时间跟随周期截止时间
} else {
if project.State == domain.ProjectStateWaitConfig {
project.State = domain.ProjectStateWaitActive
}
project.Recipients = in.Recipients
project.Template = cycleTemplate.Template
// 项目起始截止时间(环节中的时间暂未分开计算)
project.BeginTime = start
project.EndTime = end
for i := range project.Template.LinkNodes {
node := project.Template.LinkNodes[i]
node.KpiCycle = in.KpiCycle // 设置周期
node.TimeStart = &start
node.TimeEnd = &end
}
}
project, err = projectRepository.Insert(project)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
project, err = projectRepository.Insert(project)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return project, nil
}
return project, nil
}
func (rs *EvaluationProjectService) Get(in *command.GetProjectCommand) (interface{}, error) {
... ... @@ -285,6 +344,7 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
... ... @@ -294,6 +354,17 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 查看任务过程,移除项目关联的所有任务
tasks, err := taskRepository.Find(map[string]interface{}{"projectId": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range tasks {
if _, err := taskRepository.Remove(tasks[i]); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -314,6 +385,8 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
now := time.Now().Unix()
pmpUsers := make([]*domain.User, 0)
pmpUserIds := make([]int64, 0)
for i := range projects {
... ... @@ -322,7 +395,13 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter
userId, _ := strconv.ParseInt(project.PmpIds[j], 10, 64)
pmpUserIds = append(pmpUserIds, userId)
}
// 当前时间超过截至时间显示【已结束】
if now > project.EndTime.Unix() {
project.State = domain.ProjectStateDisable
}
}
if len(pmpUserIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": pmpUserIds, "limit": len(pmpUserIds)})
... ... @@ -342,29 +421,20 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
//cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if project.Template == nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加评估模板")
}
if len(project.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
if project.State == domain.TemplateStateEnable {
return nil, application.ThrowError(application.BUSINESS_ERROR, "项目已启动")
}
//cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": project.CycleId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//startMin := cycle.TimeStart
//maxTime := cycle.TimeEnd
project.State = domain.TemplateStateEnable
project, err = projectRepository.Insert(project)
... ... @@ -422,42 +492,6 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
return project, nil
}
//
//// 0点时刻为标准计算
//func (rs *EvaluationProjectService) nextTime(now0 time.Time, start *time.Time, kpiCycle int) time.Time {
// // 起始时间0点时刻
// start0 := time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, time.Local)
//
// var nextTime time.Time
// switch kpiCycle {
// case domain.KpiCycleDay:
// nextTime = timeconv.AddDate(now0, 0, 0, 1) // 当前时间的下一天开始发送
// break
// case domain.KpiCycleWeek:
// offsetSeconds := int64(now0.Sub(start0).Seconds())
// offsetDay := offsetSeconds / (24 * 60 * 60)
// cycleCount := int(offsetDay)/7 + 1
// nextTime = timeconv.AddDate(start0, 0, 0, cycleCount*7)
// break
// case domain.KpiCycleOneMonth:
// nextTime = timeconv.AddDate(start0, 0, 1, 0)
// break
// case domain.KpiCycleTwoMonth:
// nextTime = timeconv.AddDate(start0, 0, 2, 0)
// break
// case domain.KpiCycleThreeMonth:
// nextTime = timeconv.AddDate(start0, 0, 3, 0)
// break
// case domain.KpiCycleSixMonth:
// nextTime = timeconv.AddDate(start0, 0, 6, 0)
// break
// case domain.KpiCycleYear:
// nextTime = timeconv.AddDate(start0, 1, 0, 0)
// break
// }
// return nextTime
//}
func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
... ...
... ... @@ -22,19 +22,3 @@ type AssessInfoResp struct {
DutyTime string `json:"dutyTime"` //入职时间 //
AssessContent []*domain.StaffAssessContent `json:"assessContent"` //评估内容
}
type AssessContent struct {
Category string `json:"category"` //comment:"类别"
Name string `json:"name"` // comment:"名称"
PromptTitle string `json:"promptTitle"` //comment:"提示项标题"
PromptText string `json:"promptText"` // comment:"提示项正文"
Rule AssessContentRule `json:"rules"` //评定规则
Value string `json:"value"` // 实际填写评定值
Remark []domain.AssessContemtRemark `json:"entryItems"` // comment:"填写反馈"
}
type AssessContentRule struct {
Types int `json:"types"` //评估方式(0评级、1评分)
Rating domain.Rating `json:"rating"` //评级
Score domain.Score `json:"score"` //评分
}
... ...
... ... @@ -12,6 +12,7 @@ type AssessTaskDescResp struct {
type AssessTaskStep struct {
SortBy int `json:"sortBy"` //排序
LinkNodeId int `json:"linkNodeId"` //流程id
LinkNodeName string `json:"linkNodeName"` //流程名称
BeginTime string `json:"beginTime"` //开始时间时间
EndTime string `json:"endTime"` //结束时间
... ...
... ... @@ -2,6 +2,7 @@ package service
import (
"fmt"
"sort"
"strconv"
"time"
... ... @@ -37,9 +38,6 @@ func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQue
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
staffAssessTaskRepo := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -59,18 +57,7 @@ func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQue
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询评估任务"+err.Error())
}
// condition := map[string]interface{}{
// "executorId": param.UserId,
// "companyId": param.CompanyId,
// "limit": limit,
// }
// if offset > 0 {
// condition["offset"] = offset
// }
// cnt, assessTaskList, err := staffAssessTaskRepo.Find(condition)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询周期"+err.Error())
// }
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -79,8 +66,8 @@ func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQue
for _, v := range assessTaskList {
temp = adapter.SearchAssessMeResp{
AssessTaskId: v.Id,
BeginTime: v.BeginTime.Format("2006-01-02 15:04:05"),
EndTime: v.EndTime.Format("2006-01-02 15:04:05"),
BeginTime: v.BeginTime.Local().Format("2006-01-02 15:04:05"),
EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"),
CycleId: v.CycleId,
CycleName: v.CycleName,
EvaluationProjectId: v.EvaluationProjectId,
... ... @@ -132,6 +119,7 @@ func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery)
stepItem := adapter.AssessTaskStep{
SortBy: v.SortBy,
LinkNodeName: v.LinkNodeName,
LinkNodeId: v.LinkNodeId,
BeginTime: v.BeginTime.Local().Format("2006-01-02 15:04:05"),
EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"),
LinkNodeType: v.LinkNodeType,
... ... @@ -220,7 +208,10 @@ func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery)
}
}
}
result.StepList = append(result.StepList, stepItem)
//未参与的,不算在个人的评估环节里
if stepItem.Status != "" {
result.StepList = append(result.StepList, stepItem)
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -244,7 +235,7 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery)
staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var limit int = 20
var limit int = 100
var offset int = 0
if param.PageSize > 0 {
limit = param.PageSize
... ... @@ -255,8 +246,9 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery)
"companyId": param.CompanyId,
"typesList": []string{string(domain.AssessSelf)},
"limit": limit,
"status": string(domain.StaffAssessCompleted),
"endTime": time.Now(), //获取历史记录
}
// "status": string(domain.StaffAssessCompleted),
if offset > 0 {
condition["offset"] = offset
}
... ... @@ -347,16 +339,6 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery)
// 根据项目评估的配置,创建员工的评估任务
func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{
"param": param,
})
... ... @@ -372,30 +354,64 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat
return nil, application.ThrowError(application.ARG_ERROR, "任务结束时间填写错误,"+param.EndTime)
}
nowTime := time.Now()
//建立评估任务
assessTaskData := &domain.StaffAssessTask{
Id: 0,
CompanyId: param.CompanyId,
EvaluationProjectId: param.EvaluationProjectId,
EvaluationProjectName: param.EvaluationProjectName,
CycleId: param.CycleId,
CycleName: param.CycleName,
BeginTime: taskBeginTime,
EndTime: taskEndTime,
StepList: []domain.AssessTaskStep{},
ExecutorId: nil,
CreatedAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
BeginDay: taskBeginTime.Local().Format("2006-01-02"),
}
// }
//填充评估环节
_, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{
"evaluationProjectId": param.EvaluationProjectId,
"beginDay": taskBeginTime.Local().Format("2006-01-02"),
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期同项目已存在的评估任务"+err.Error())
}
var assessTaskData *domain.StaffAssessTask
//更新旧数据或者新建数据
if len(assassessTaskList) > 0 {
assessTaskData = assassessTaskList[0]
assessTaskData.UpdatedAt = nowTime
} else {
//建立新的评估任务
assessTaskData = &domain.StaffAssessTask{
Id: 0,
CompanyId: param.CompanyId,
EvaluationProjectId: param.EvaluationProjectId,
EvaluationProjectName: param.EvaluationProjectName,
CycleId: param.CycleId,
CycleName: param.CycleName,
BeginTime: taskBeginTime,
EndTime: taskEndTime,
StepList: []domain.AssessTaskStep{},
ExecutorId: []int{},
CreatedAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
BeginDay: taskBeginTime.Local().Format("2006-01-02"),
}
}
executorIds := []int{} //提取评估的参与人id
executorIdMap := map[int]struct{}{} //过滤重复的用户
//从入参中提取参与人
for _, v := range param.ExecutorId {
if _, ok := executorIdMap[v]; ok {
continue
}
executorIdMap[v] = struct{}{}
executorIds = append(executorIds, v)
}
//就数据中提取参与人
for _, v := range assessTaskData.ExecutorId {
if _, ok := executorIdMap[v]; ok {
continue
}
executorIdMap[v] = struct{}{}
executorIds = append(executorIds, v)
}
//填入新的参与人id
assessTaskData.ExecutorId = executorIds
//填充新的评估环节
loop:
for _, v := range param.StepList {
for _, vv := range assessTaskData.StepList {
if vv.LinkNodeType == v.LinkNodeType {
continue
if vv.LinkNodeId == v.LinkNodeId {
continue loop
}
}
stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
... ... @@ -416,44 +432,15 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat
}
assessTaskData.StepList = append(assessTaskData.StepList, step)
}
//评估的参与人
executorIds := []int{}
executorIdMap := map[int]struct{}{} //过滤重复的用户
for _, v := range param.ExecutorId {
if _, ok := executorIdMap[v]; ok {
continue
}
executorIdMap[v] = struct{}{}
executorIds = append(executorIds, v)
}
assessTaskData.ExecutorId = executorIds
//排序流程环节
stepList := domain.SortTaskStep(assessTaskData.StepList)
sort.Sort(stepList)
assessTaskData.StepList = stepList
//添加员工的节点任务
assessList, err := srv.createStaffAssess(transactionContext, assessTaskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
}
// var assessTaskData *domain.StaffAssessTask
_, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{
"evaluationProjectId": param.EvaluationProjectId,
"beginDay": taskBeginTime.Local().Format("2006-01-02"),
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期已存在评估任务"+err.Error())
}
if len(assassessTaskList) > 0 {
//过滤就数据
assessTaskData.Id = assassessTaskList[0].Id
for _, v := range assassessTaskList[0].ExecutorId {
if _, ok := executorIdMap[v]; ok {
continue
}
executorIdMap[v] = struct{}{}
executorIds = append(executorIds, v)
}
assessTaskData.ExecutorId = executorIds
assessTaskData.StepList = append(assassessTaskList[0].StepList, assessTaskData.StepList...)
}
_, err = assessTaskRepo.Save(assessTaskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
... ... @@ -469,10 +456,6 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())
}
}
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
return map[string]interface{}{
"assessTaskId": assessTaskData.Id,
}, nil
... ... @@ -480,8 +463,8 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat
// 添加节点任务
func (srv StaffAssessServeice) createStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) {
//评估的参与人
selfUserId := []int{}
selfUserId := []int{} //评估的参与人
userIdMap := map[int]struct{}{} //过滤重复的用户
for _, v := range param.ExecutorId {
if _, ok := userIdMap[v]; ok {
... ... @@ -557,7 +540,7 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application.
assessList = append(assessList, assessListTemp...)
}
if v.LinkNodeType == domain.LinkNodeSuperiorAssessment {
// TODO
// 创建上级评估
stepSelfTemp.BeginTime = v.BeginTime
stepSelfTemp.EndTime = v.EndTime
stepSelfTemp.LinkNodeId = v.LinkNodeId
... ... @@ -578,7 +561,6 @@ func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAsse
userList []*domain.User, userDepartmentMap map[int64][]*domain.Department) []domain.StaffAssess {
result := []domain.StaffAssess{}
for _, usr := range userList {
assessTemp.TargetUser = domain.StaffDesc{
UserId: int(usr.Id),
Account: usr.Account,
... ... @@ -602,7 +584,7 @@ func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAsse
return result
}
// 构建员工上级评估
// 构建员工上级评估
func (srv StaffAssessServeice) createStaffAssessSupper(
transactionContext application.TransactionContext,
assessTemp domain.StaffAssess,
... ... @@ -622,6 +604,7 @@ func (srv StaffAssessServeice) createStaffAssessSupper(
if len(vv2.ChargeUserIds) == 0 {
continue
}
//获取部门的主管
_, chargeUserList, err := userRepo.Find(map[string]interface{}{
"ids": vv2.ChargeUserIds,
"limit": 40,
... ... @@ -742,7 +725,6 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv
defer func() {
_ = transactionContext.RollbackTransaction()
}()
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
... ... @@ -775,6 +757,12 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv
if inviteNode == nil {
return nil, application.ThrowError(application.ARG_ERROR, "评估任务没有邀请评估的环节")
}
//检查节点的结束时间
endTimeInt := inviteNode.EndTime.Unix()
if endTimeInt < time.Now().Unix() {
e := fmt.Sprintf("该环节已在%s截止", inviteNode.EndTime.Local().Format("2006-01-02 15:04:05"))
return nil, application.ThrowError(application.BUSINESS_ERROR, e)
}
targetUser, err := userRepo.FindOne(map[string]interface{}{
"id": param.TargetUserId,
... ... @@ -1635,7 +1623,7 @@ func (srv *StaffAssessServeice) getStaffDescrip(transactionContext application.T
UserName: userData.Name,
CompanyName: companyData.Name,
SupperUserName: "",
DutyTime: userData.CreatedAt.Local().Format("2006-01-02 15:04:05"),
DutyTime: userData.EntryTime,
}
for _, v := range supperUserList {
userInfo.SupperUserName = userInfo.SupperUserName + v.Name + " "
... ... @@ -1665,6 +1653,13 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
}
//检查截止时间
endTimeInt := assessData.EndTime.Unix()
if endTimeInt < time.Now().Unix() {
return nil, application.ThrowError(application.BUSINESS_ERROR, "当前环节已过截止时间,提交后无法修改内容")
}
assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
... ... @@ -1672,7 +1667,6 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
assessContentList := []*domain.StaffAssessContent{}
if assessData.Status == domain.StaffAssessCompleted {
//已完成
_, assessContentList, err = assessContentRepo.Find(map[string]interface{}{
"staffAssessId": assessData.Id,
})
... ... @@ -1700,6 +1694,12 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
continue
}
v.Value = item.Value
//填入评估值描述
reteResult, err := v.Rule.ScoreOrRating(&v.Value)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
v.ReteResult = reteResult
for ii := range v.Remark {
for _, vvv := range item.Remark {
if v.Remark[ii].Title == vvv.Title {
... ... @@ -1708,6 +1708,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
}
}
}
}
//保存信息
... ...
... ... @@ -6,6 +6,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
)
//调试用,手动调用CreateStaffAssessTask
func (srv StaffAssessServeice) InvokCreateStaffAssessTask(param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ...
... ... @@ -8,7 +8,7 @@ const (
ProjectStateWaitConfig int = 0 // 项目状态-待完成配置
ProjectStateWaitActive int = 1 // 项目状态-待启用
ProjectStateEnable int = 2 // 项目状态-启用
ProjectStateDisable int = 3 // 项目状态-停用
ProjectStateDisable int = 3 // 项目状态-停用(假状态)
)
// 项目的评估内容配置
... ... @@ -25,6 +25,8 @@ type EvaluationProject struct {
PmpIds []string `json:"pmpIds" comment:"项目管理员ID"`
Recipients []string `json:"recipients" comment:"被评估人ID"`
Template *EvaluationTemplate `json:"template" comment:"评估模板"`
BeginTime time.Time `json:"beginTime" comment:"项目起始时间"`
EndTime time.Time `json:"endTime" comment:"项目截至时间"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
... ...
package domain
import (
"errors"
"fmt"
"strconv"
"time"
)
... ... @@ -55,6 +58,55 @@ type EvaluationRule struct {
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
// 根据评估填写的值,得出等级名称
// 如果 评估方式是评分,对评估填写的值的小数点后的位数进行处理,
// value 根据评估填写的值
func (rule *EvaluationRule) ScoreOrRating(value *string) (string, error) {
switch rule.Type {
case EvaluationTypeRating:
return rule.RatingValue(value)
case EvaluationTypeScore:
return rule.ScoreValue(value)
}
return "", errors.New("rule.Type 错误")
}
//根据评估填写的值,得出等级名称,
func (rule *EvaluationRule) ScoreValue(value *string) (string, error) {
valueFloat, err := strconv.ParseFloat(*value, 64)
if err != nil {
return "", errors.New("评分填写的值错误")
}
if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {
return "", fmt.Errorf("评分填写的值超出限制,>=%f且<=%f", rule.Score.Min, rule.Score.Max)
}
//保留小数处理
fStr := fmt.Sprintf("%%.%df", rule.Score.DecimalPlaces)
valueStr := fmt.Sprintf(fStr, valueFloat)
*value = valueStr
if rule.Score.IntervalState == 0 {
// 未开启按分数子区间匹配等级
return "", nil
}
valueDescrip := ""
for _, v := range rule.Score.Levels {
if valueFloat >= v.Start && valueFloat <= v.End {
valueDescrip = v.Name
}
}
return valueDescrip, nil
}
//根据评估填写的值,得出等级名称,
func (rule *EvaluationRule) RatingValue(value *string) (string, error) {
for _, v := range rule.Rating.Levels {
if v.Code == *value {
return v.Name, nil
}
}
return "", errors.New("评估填写的值错误")
}
// GenerateSysRule 当前公司下的生成默认规则
func GenerateSysRule(companyId int64) *EvaluationRule {
levels := make([]*RatingLevel, 0)
... ...
... ... @@ -10,7 +10,7 @@ type StaffAssessTask struct {
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
CycleId int64 `json:"cycleId"` //对应的周期id
CycleName string `json:"cycleName"` //对应周期的名称
BeginDay string `json:"beginDay"` //绩效考核日期
BeginDay string `json:"beginDay"` //绩效考核日期 ,2006-01-02
BeginTime time.Time `json:"beginTime"` //绩效考核开始时间
EndTime time.Time `json:"endTime"` //绩效考核截止时间
StepList []AssessTaskStep `json:"stepList"` //考评的流程
... ... @@ -30,6 +30,12 @@ type AssessTaskStep struct {
EndTime time.Time `json:"endTime"` //绩效考核截止时间
}
type SortTaskStep []AssessTaskStep
func (a SortTaskStep) Len() int { return len(a) }
func (a SortTaskStep) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortTaskStep) Less(i, j int) bool { return a[i].SortBy < a[j].SortBy }
type StaffAssessTaskRepository interface {
Save(param *StaffAssessTask) (*StaffAssessTask, error)
Remove(id int) error
... ...
... ... @@ -56,7 +56,7 @@ func (d *StaffAssessDao) CountInviteAssessByTargetUser(userIds []int, assessTask
return result, err
}
// 搜索 executorId 参与的评估任务
// 根据评估的人执行人id,搜索 executorId参与的评估任务
func (d *StaffAssessDao) SearchAssessTaskMe(executorId int, companyId int, limit int, offset int) ([]*domain.StaffAssessTask, error) {
if limit < 0 {
... ... @@ -70,6 +70,7 @@ func (d *StaffAssessDao) SearchAssessTaskMe(executorId int, companyId int, limit
JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
WHERE staff_assess.company_id=?
and staff_assess.executor->>'userId'='?'
order by staff_assess_task.id desc
limit ? offset ?
`
tx := d.transactionContext.PgTx
... ...
... ... @@ -19,6 +19,8 @@ type EvaluationProject struct {
PmpIds []string `comment:"项目管理员ID"`
Recipients []string `comment:"被评估人ID"`
Template *domain.EvaluationTemplate `comment:"评估模板"`
BeginTime time.Time `comment:"项目起始时间"`
EndTime time.Time `comment:"项目截至时间 "`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
... ...
package models
import (
"time"
)
type NodeTimerTask struct {
tableName struct{} `pg:"node_timer_task" comment:"流程节点定时任务"`
Id int64 `comment:"ID"`
CompanyId int64 `comment:"公司ID"`
CycleId int64 `comment:"周期ID"`
ProjectId int64 `comment:"项目ID"`
NodeId int64 `comment:"流程ID"`
LastSentAt *time.Time `comment:"最后一次发送时间"`
NextSentAt *time.Time `comment:"下一次发送时间"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ... @@ -148,6 +148,9 @@ func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{})
query.Where("time_end>=?", t)
}
// 按创建时间降序
query.Order("created_at DESC")
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
... ... @@ -34,6 +34,8 @@ func (repo *EvaluationProjectRepository) TransformToDomain(m *models.EvaluationP
PmpIds: m.PmpIds,
Recipients: m.Recipients,
Template: m.Template,
BeginTime: m.BeginTime,
EndTime: m.EndTime,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
DeletedAt: m.DeletedAt,
... ... @@ -54,6 +56,8 @@ func (repo *EvaluationProjectRepository) TransformToModel(d *domain.EvaluationPr
PmpIds: d.PmpIds,
Recipients: d.Recipients,
Template: d.Template,
BeginTime: d.BeginTime,
EndTime: d.EndTime,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
... ... @@ -166,6 +170,8 @@ func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
// 按创建时间降序
query.Order("created_at DESC")
count, err := query.SelectAndCount()
if err != nil {
... ...
... ... @@ -147,12 +147,15 @@ func (repo *StaffAssessRepository) Find(queryOptions map[string]interface{}) (in
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
if v, ok := queryOptions["typesList"].([]string); ok && len(v) > 0 {
if v, ok := queryOptions["typesList"].([]string); ok {
query.Where("types in(?)", pg.In(v))
}
if v, ok := queryOptions["status"].(string); ok && len(v) > 0 {
if v, ok := queryOptions["status"].(string); ok {
query.Where("status=?", v)
}
if v, ok := queryOptions["endTime"]; ok {
query.Where("end_time<=?", v)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
... ... @@ -21,8 +21,6 @@ func (controller *ProjectController) CreateProject() {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ... @@ -35,7 +33,6 @@ func (controller *ProjectController) UpdateProject() {
} else {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Update(in))
}
}
... ... @@ -48,7 +45,6 @@ func (controller *ProjectController) UpdateProjectForTemplate() {
} else {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.UpdateTemplate(in))
}
}
... ... @@ -86,7 +82,6 @@ func (controller *ProjectController) ListProject() {
}
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
}
... ...
... ... @@ -5,6 +5,7 @@ import (
timeconv "github.com/Andrew-M-C/go.timeconv"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"math"
"reflect"
"strings"
"time"
... ... @@ -53,24 +54,92 @@ func NextTime(now0 time.Time, start time.Time, kpiCycle int) time.Time {
nextTime = timeconv.AddDate(start0, 0, 0, cycleCount*7)
break
case domain.KpiCycleOneMonth:
nextTime = timeconv.AddDate(start0, 0, 1, 0)
offsetMonth := SubMonth(now0, start0)
nextTime = timeconv.AddDate(start0, 0, offsetMonth, 0)
if nextTime.Before(now0) {
nextTime = timeconv.AddDate(nextTime, 0, 1, 0)
}
break
case domain.KpiCycleTwoMonth:
nextTime = timeconv.AddDate(start0, 0, 2, 0)
offsetMonth := SubMonth(now0, start0)
multiple := float64(offsetMonth) / 2
if multiple == 0 {
multiple = 1
} else {
multiple = math.Ceil(multiple)
}
nextTime = timeconv.AddDate(start0, 0, int(multiple)*2, 0)
if nextTime.Before(now0) {
nextTime = timeconv.AddDate(nextTime, 0, 2, 0)
}
break
case domain.KpiCycleThreeMonth:
nextTime = timeconv.AddDate(start0, 0, 3, 0)
offsetMonth := SubMonth(now0, start0)
multiple := float64(offsetMonth) / 3
if multiple == 0 {
multiple = 1
} else {
multiple = math.Ceil(multiple)
}
nextTime = timeconv.AddDate(start0, 0, int(multiple)*3, 0)
if nextTime.Before(now0) {
nextTime = timeconv.AddDate(nextTime, 0, 3, 0)
}
break
case domain.KpiCycleSixMonth:
nextTime = timeconv.AddDate(start0, 0, 6, 0)
offsetMonth := SubMonth(now0, start0)
multiple := float64(offsetMonth) / 6
if multiple == 0 {
multiple = 1
} else {
multiple = math.Ceil(multiple)
}
nextTime = timeconv.AddDate(start0, 0, int(multiple)*6, 0)
if nextTime.Before(now0) {
nextTime = timeconv.AddDate(nextTime, 0, 6, 0)
}
break
case domain.KpiCycleYear:
nextTime = timeconv.AddDate(start0, 1, 0, 0)
offsetMonth := SubMonth(now0, start0)
multiple := float64(offsetMonth) / 12
if multiple == 0 {
multiple = 1
} else {
multiple = math.Ceil(multiple)
}
nextTime = timeconv.AddDate(start0, 0, int(multiple)*12, 0)
if nextTime.Before(now0) {
nextTime = timeconv.AddDate(nextTime, 0, 12, 0)
}
break
}
return nextTime
}
// SubMonth 计算日期相差多少月
func SubMonth(t1, t2 time.Time) (month int) {
y1 := t1.Year()
y2 := t2.Year()
m1 := int(t1.Month())
m2 := int(t2.Month())
d1 := t1.Day()
d2 := t2.Day()
yearInterval := y1 - y2
// 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数
if m1 < m2 || (m1 == m2 && d1 < d2) {
yearInterval--
}
// 获取月数差值
monthInterval := (m1 + 12) - m2
if d1 < d2 {
monthInterval--
}
monthInterval %= 12
month = yearInterval*12 + monthInterval
return
}
// NextTimeInc 0点时刻为标准计算
func NextTimeInc(start time.Time, kpiCycle int) time.Time {
year, month, day := start.Date()
... ...