正在显示
6 个修改的文件
包含
37 行增加
和
18 行删除
@@ -2,15 +2,14 @@ package command | @@ -2,15 +2,14 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "github.com/beego/beego/v2/core/validation" | 4 | "github.com/beego/beego/v2/core/validation" |
5 | - "time" | ||
6 | ) | 5 | ) |
7 | 6 | ||
8 | type CreateCycleCommand struct { | 7 | type CreateCycleCommand struct { |
9 | CompanyId int64 `cname:"公司ID" json:"companyId"` | 8 | CompanyId int64 `cname:"公司ID" json:"companyId"` |
10 | CreatorId int64 `cname:"创建人ID" json:"creatorId"` | 9 | CreatorId int64 `cname:"创建人ID" json:"creatorId"` |
11 | Name string `cname:"周期名称" json:"name" valid:"Required"` | 10 | Name string `cname:"周期名称" json:"name" valid:"Required"` |
12 | - TimeStart *time.Time `cname:"起始时间" json:"timeStart"` | ||
13 | - TimeEnd *time.Time `cname:"截至时间" json:"timeEnd"` | 11 | + TimeStart string `cname:"起始时间" json:"timeStart"` |
12 | + TimeEnd string `cname:"截至时间" json:"timeEnd"` | ||
14 | KpiCycle int `cname:"考核周期" json:"kpiCycle" valid:"Required"` | 13 | KpiCycle int `cname:"考核周期" json:"kpiCycle" valid:"Required"` |
15 | TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"` | 14 | TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"` |
16 | } | 15 | } |
@@ -33,11 +32,11 @@ func (in *CreateCycleCommand) Valid(validation *validation.Validation) { | @@ -33,11 +32,11 @@ func (in *CreateCycleCommand) Valid(validation *validation.Validation) { | ||
33 | return | 32 | return |
34 | } | 33 | } |
35 | 34 | ||
36 | - if in.TimeStart == nil { | 35 | + if len(in.TimeStart) == 0 { |
37 | validation.SetError("timeStart", "请选择考核周期的开始时间") | 36 | validation.SetError("timeStart", "请选择考核周期的开始时间") |
38 | return | 37 | return |
39 | } | 38 | } |
40 | - if in.TimeEnd == nil { | 39 | + if len(in.TimeEnd) == 0 { |
41 | validation.SetError("timeEnd", "请选择考核周期的结束时间") | 40 | validation.SetError("timeEnd", "请选择考核周期的结束时间") |
42 | return | 41 | return |
43 | } | 42 | } |
@@ -2,15 +2,14 @@ package command | @@ -2,15 +2,14 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "github.com/beego/beego/v2/core/validation" | 4 | "github.com/beego/beego/v2/core/validation" |
5 | - "time" | ||
6 | ) | 5 | ) |
7 | 6 | ||
8 | type UpdateCycleCommand struct { | 7 | type UpdateCycleCommand struct { |
9 | CompanyId int64 `cname:"公司ID" json:"companyId"` | 8 | CompanyId int64 `cname:"公司ID" json:"companyId"` |
10 | Id int64 `cname:"周期ID" json:"id,string" valid:"Required"` | 9 | Id int64 `cname:"周期ID" json:"id,string" valid:"Required"` |
11 | Name string `cname:"周期名称" json:"name" valid:"Required"` | 10 | Name string `cname:"周期名称" json:"name" valid:"Required"` |
12 | - TimeStart *time.Time `cname:"起始时间" json:"timeStart"` | ||
13 | - TimeEnd *time.Time `cname:"截至时间" json:"timeEnd"` | 11 | + TimeStart string `cname:"起始时间" json:"timeStart"` |
12 | + TimeEnd string `cname:"截至时间" json:"timeEnd"` | ||
14 | KpiCycle int `cname:"考核周期(0日、1周、2月)" json:"kpiCycle" valid:"Required"` | 13 | KpiCycle int `cname:"考核周期(0日、1周、2月)" json:"kpiCycle" valid:"Required"` |
15 | TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"` | 14 | TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"` |
16 | } | 15 | } |
@@ -20,11 +19,11 @@ func (in *UpdateCycleCommand) Valid(validation *validation.Validation) { | @@ -20,11 +19,11 @@ func (in *UpdateCycleCommand) Valid(validation *validation.Validation) { | ||
20 | validation.SetError("name", "角色名称最大长度40个字符") | 19 | validation.SetError("name", "角色名称最大长度40个字符") |
21 | return | 20 | return |
22 | } | 21 | } |
23 | - if in.TimeStart == nil { | 22 | + if len(in.TimeStart) == 0 { |
24 | validation.SetError("timeStart", "请选择考核周期的开始时间") | 23 | validation.SetError("timeStart", "请选择考核周期的开始时间") |
25 | return | 24 | return |
26 | } | 25 | } |
27 | - if in.TimeEnd == nil { | 26 | + if len(in.TimeEnd) == 0 { |
28 | validation.SetError("timeEnd", "请选择考核周期的结束时间") | 27 | validation.SetError("timeEnd", "请选择考核周期的结束时间") |
29 | return | 28 | return |
30 | } | 29 | } |
@@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" |
9 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
10 | "strconv" | 10 | "strconv" |
11 | + "time" | ||
11 | ) | 12 | ) |
12 | 13 | ||
13 | type EvaluationCycleService struct { | 14 | type EvaluationCycleService struct { |
@@ -49,12 +50,21 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf | @@ -49,12 +50,21 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf | ||
49 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "模板不存在, 请重新选择") | 50 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "模板不存在, 请重新选择") |
50 | } | 51 | } |
51 | 52 | ||
53 | + start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local) | ||
54 | + if err != nil { | ||
55 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
56 | + } | ||
57 | + end, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeEnd, time.Local) | ||
58 | + if err != nil { | ||
59 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
60 | + } | ||
61 | + | ||
52 | // 生成新周期数据 | 62 | // 生成新周期数据 |
53 | newCycle := &domain.EvaluationCycle{ | 63 | newCycle := &domain.EvaluationCycle{ |
54 | Id: 0, | 64 | Id: 0, |
55 | Name: in.Name, | 65 | Name: in.Name, |
56 | - TimeStart: in.TimeStart, | ||
57 | - TimeEnd: in.TimeEnd, | 66 | + TimeStart: &start, |
67 | + TimeEnd: &end, | ||
58 | CompanyId: in.CompanyId, | 68 | CompanyId: in.CompanyId, |
59 | CreatorId: in.CreatorId, | 69 | CreatorId: in.CreatorId, |
60 | KpiCycle: in.KpiCycle, | 70 | KpiCycle: in.KpiCycle, |
@@ -210,9 +220,18 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf | @@ -210,9 +220,18 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf | ||
210 | } | 220 | } |
211 | } | 221 | } |
212 | 222 | ||
223 | + start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local) | ||
224 | + if err != nil { | ||
225 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
226 | + } | ||
227 | + end, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeEnd, time.Local) | ||
228 | + if err != nil { | ||
229 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
230 | + } | ||
231 | + | ||
213 | cycle.Name = in.Name | 232 | cycle.Name = in.Name |
214 | - cycle.TimeStart = in.TimeStart | ||
215 | - cycle.TimeEnd = in.TimeEnd | 233 | + cycle.TimeStart = &start |
234 | + cycle.TimeEnd = &end | ||
216 | cycle.KpiCycle = in.KpiCycle | 235 | cycle.KpiCycle = in.KpiCycle |
217 | cycle, err = cycleRepository.Insert(cycle) | 236 | cycle, err = cycleRepository.Insert(cycle) |
218 | if err != nil { | 237 | if err != nil { |
@@ -2,14 +2,13 @@ package command | @@ -2,14 +2,13 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "github.com/beego/beego/v2/core/validation" | 4 | "github.com/beego/beego/v2/core/validation" |
5 | - "time" | ||
6 | ) | 5 | ) |
7 | 6 | ||
8 | type QueryTemplateCommand struct { | 7 | type QueryTemplateCommand struct { |
9 | CompanyId int64 `cname:"公司ID" json:"companyId"` | 8 | CompanyId int64 `cname:"公司ID" json:"companyId"` |
10 | Name string `cname:"模板名称" json:"name"` | 9 | Name string `cname:"模板名称" json:"name"` |
11 | State int `cname:"模板状态" json:"state"` | 10 | State int `cname:"模板状态" json:"state"` |
12 | - CreatedAt *time.Time `cname:"创建时间" json:"createdAt"` | 11 | + CreatedAt string `cname:"创建时间" json:"createdAt"` |
13 | PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"` | 12 | PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"` |
14 | PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"` | 13 | PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"` |
15 | } | 14 | } |
@@ -190,7 +190,7 @@ func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (int | @@ -190,7 +190,7 @@ func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (int | ||
190 | }() | 190 | }() |
191 | 191 | ||
192 | queryOptions := tool_funs.SimpleStructToMap(in) | 192 | queryOptions := tool_funs.SimpleStructToMap(in) |
193 | - if in.CreatedAt == nil { | 193 | + if len(in.CreatedAt) == 0 { |
194 | delete(queryOptions, "createdAt") // 删除创建时间 | 194 | delete(queryOptions, "createdAt") // 删除创建时间 |
195 | } | 195 | } |
196 | 196 |
@@ -142,13 +142,16 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface | @@ -142,13 +142,16 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface | ||
142 | } | 142 | } |
143 | 143 | ||
144 | if v, ok := queryOptions["createdAt"]; ok { | 144 | if v, ok := queryOptions["createdAt"]; ok { |
145 | - t := v.(*time.Time) | 145 | + ts := v.(string) |
146 | + t, err := time.ParseInLocation("2006-01-02", ts, time.Local) | ||
147 | + if err == nil { | ||
146 | year, month, day := t.Date() | 148 | year, month, day := t.Date() |
147 | begin := time.Date(year, month, day, 0, 0, 0, 0, time.Local) | 149 | begin := time.Date(year, month, day, 0, 0, 0, 0, time.Local) |
148 | end := time.Date(year, month, day, 23, 59, 59, 0, time.Local) | 150 | end := time.Date(year, month, day, 23, 59, 59, 0, time.Local) |
149 | query.Where("created_at >= ?", begin) | 151 | query.Where("created_at >= ?", begin) |
150 | query.Where("created_at <= ?", end) | 152 | query.Where("created_at <= ?", end) |
151 | } | 153 | } |
154 | + } | ||
152 | 155 | ||
153 | if v, ok := queryOptions["limit"].(int64); ok { | 156 | if v, ok := queryOptions["limit"].(int64); ok { |
154 | query.Limit(int(v)) | 157 | query.Limit(int(v)) |
-
请 注册 或 登录 后发表评论