正在显示
10 个修改的文件
包含
65 行增加
和
4 行删除
deploy/db/v1.0.1 db_script.sql
0 → 100644
@@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
6 | "reflect" | 7 | "reflect" |
7 | "strings" | 8 | "strings" |
@@ -32,6 +33,8 @@ type CreateProductCalendarCommand struct { | @@ -32,6 +33,8 @@ type CreateProductCalendarCommand struct { | ||
32 | BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"` | 33 | BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"` |
33 | // 工时 (单位 h) | 34 | // 工时 (单位 h) |
34 | WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"` | 35 | WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"` |
36 | + // 休息时间周期列表 | ||
37 | + BreakTimePeriods []*domain.ProductCalendarBreakTimePeriod `json:"breakTimePeriods"` | ||
35 | } | 38 | } |
36 | 39 | ||
37 | func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validation *validation.Validation) { | 40 | func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validation *validation.Validation) { |
@@ -44,6 +47,16 @@ func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validati | @@ -44,6 +47,16 @@ func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validati | ||
44 | validation.Error(err.Error()) | 47 | validation.Error(err.Error()) |
45 | return | 48 | return |
46 | } | 49 | } |
50 | + for _, v := range createProductCalendarCommand.BreakTimePeriods { | ||
51 | + if err := utils.ValidWorkTime(v.BeginAt); err != nil { | ||
52 | + validation.Error(err.Error() + " " + v.BeginAt) | ||
53 | + return | ||
54 | + } | ||
55 | + if err := utils.ValidWorkTime(v.EndAt); err != nil { | ||
56 | + validation.Error(err.Error() + " " + v.EndAt) | ||
57 | + return | ||
58 | + } | ||
59 | + } | ||
47 | } | 60 | } |
48 | 61 | ||
49 | func (createProductCalendarCommand *CreateProductCalendarCommand) ValidateCommand() error { | 62 | func (createProductCalendarCommand *CreateProductCalendarCommand) ValidateCommand() error { |
@@ -2,6 +2,8 @@ package command | @@ -2,6 +2,8 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
5 | "reflect" | 7 | "reflect" |
6 | "strings" | 8 | "strings" |
7 | 9 | ||
@@ -29,10 +31,21 @@ type UpdateProductCalendarCommand struct { | @@ -29,10 +31,21 @@ type UpdateProductCalendarCommand struct { | ||
29 | BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"` | 31 | BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"` |
30 | // 工时 (单位 h) | 32 | // 工时 (单位 h) |
31 | WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"` | 33 | WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"` |
34 | + // 休息时间周期列表 | ||
35 | + BreakTimePeriods []*domain.ProductCalendarBreakTimePeriod `json:"breakTimePeriods"` | ||
32 | } | 36 | } |
33 | 37 | ||
34 | func (updateProductCalendarCommand *UpdateProductCalendarCommand) Valid(validation *validation.Validation) { | 38 | func (updateProductCalendarCommand *UpdateProductCalendarCommand) Valid(validation *validation.Validation) { |
35 | - //validation.SetError("CustomValid", "未实现的自定义认证") | 39 | + for _, v := range updateProductCalendarCommand.BreakTimePeriods { |
40 | + if err := utils.ValidWorkTime(v.BeginAt); err != nil { | ||
41 | + validation.Error(err.Error() + " " + v.BeginAt) | ||
42 | + return | ||
43 | + } | ||
44 | + if err := utils.ValidWorkTime(v.EndAt); err != nil { | ||
45 | + validation.Error(err.Error() + " " + v.EndAt) | ||
46 | + return | ||
47 | + } | ||
48 | + } | ||
36 | } | 49 | } |
37 | 50 | ||
38 | func (updateProductCalendarCommand *UpdateProductCalendarCommand) ValidateCommand() error { | 51 | func (updateProductCalendarCommand *UpdateProductCalendarCommand) ValidateCommand() error { |
@@ -32,6 +32,10 @@ type ProductCalendarDto struct { | @@ -32,6 +32,10 @@ type ProductCalendarDto struct { | ||
32 | OrgName string `json:"orgName"` | 32 | OrgName string `json:"orgName"` |
33 | // 权限标识 (当前登录组织匹配为true,否则false) | 33 | // 权限标识 (当前登录组织匹配为true,否则false) |
34 | AuthFlag bool `json:"authFlag"` | 34 | AuthFlag bool `json:"authFlag"` |
35 | + // 休息时间周期列表 | ||
36 | + BreakTimePeriods []*domain.ProductCalendarBreakTimePeriod `json:"breakTimePeriods"` | ||
37 | + // 累计休息时间 (单位 h) | ||
38 | + TotalBreakTime float64 `json:"totalBreakTime"` | ||
35 | } | 39 | } |
36 | 40 | ||
37 | func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar, orgId int) *ProductCalendarDto { | 41 | func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar, orgId int) *ProductCalendarDto { |
@@ -48,5 +52,9 @@ func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar, orgId int) *Prod | @@ -48,5 +52,9 @@ func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar, orgId int) *Prod | ||
48 | if m.Ext != nil { | 52 | if m.Ext != nil { |
49 | d.OrgName = m.Ext.OrgName | 53 | d.OrgName = m.Ext.OrgName |
50 | } | 54 | } |
55 | + d.BreakTimePeriods = m.BreakTimePeriods | ||
56 | + for _, v := range d.BreakTimePeriods { | ||
57 | + d.TotalBreakTime += v.BreakTime | ||
58 | + } | ||
51 | return d | 59 | return d |
52 | } | 60 | } |
@@ -71,9 +71,10 @@ func (productCalendarService *ProductCalendarService) CreateProductCalendar(oper | @@ -71,9 +71,10 @@ func (productCalendarService *ProductCalendarService) CreateProductCalendar(oper | ||
71 | OutWorkAt: cmd.OutWorkAt, | 71 | OutWorkAt: cmd.OutWorkAt, |
72 | BreakTime: cmd.BreakTime, | 72 | BreakTime: cmd.BreakTime, |
73 | //WorkTime: cmd.WorkTime, | 73 | //WorkTime: cmd.WorkTime, |
74 | - CreatedAt: time.Now(), | ||
75 | - UpdatedAt: time.Now(), | ||
76 | - Ext: domain.NewExt(org.OrgName), | 74 | + BreakTimePeriods: cmd.BreakTimePeriods, |
75 | + CreatedAt: time.Now(), | ||
76 | + UpdatedAt: time.Now(), | ||
77 | + Ext: domain.NewExt(org.OrgName), | ||
77 | } | 78 | } |
78 | if err = newProductCalendar.ResetWorkTime(cmd.WorkTime); err != nil { | 79 | if err = newProductCalendar.ResetWorkTime(cmd.WorkTime); err != nil { |
79 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 80 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -306,6 +307,7 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(cmd | @@ -306,6 +307,7 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(cmd | ||
306 | productCalendar.InWorkAt = cmd.InWorkAt | 307 | productCalendar.InWorkAt = cmd.InWorkAt |
307 | productCalendar.OutWorkAt = cmd.OutWorkAt | 308 | productCalendar.OutWorkAt = cmd.OutWorkAt |
308 | productCalendar.BreakTime = cmd.BreakTime | 309 | productCalendar.BreakTime = cmd.BreakTime |
310 | + productCalendar.BreakTimePeriods = cmd.BreakTimePeriods | ||
309 | productCalendar.Ext = domain.NewExt(org.OrgName) | 311 | productCalendar.Ext = domain.NewExt(org.OrgName) |
310 | if err = productCalendar.ResetWorkTime(cmd.WorkTime); err != nil { | 312 | if err = productCalendar.ResetWorkTime(cmd.WorkTime); err != nil { |
311 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 313 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
@@ -37,6 +37,8 @@ type ProductCalendar struct { | @@ -37,6 +37,8 @@ type ProductCalendar struct { | ||
37 | DeletedAt time.Time `json:"deletedAt,omitempty"` | 37 | DeletedAt time.Time `json:"deletedAt,omitempty"` |
38 | // 扩展数据 | 38 | // 扩展数据 |
39 | Ext *Ext `json:"ext,omitempty"` | 39 | Ext *Ext `json:"ext,omitempty"` |
40 | + // 休息时间周期列表 | ||
41 | + BreakTimePeriods []*ProductCalendarBreakTimePeriod `json:"breakTimePeriods"` | ||
40 | } | 42 | } |
41 | 43 | ||
42 | type ProductCalendarRepository interface { | 44 | type ProductCalendarRepository interface { |
1 | +package domain | ||
2 | + | ||
3 | +type ProductCalendarBreakTimePeriod struct { | ||
4 | + // 开始时间 eg: 11:00 | ||
5 | + BeginAt string `json:"beginAt,omitempty"` | ||
6 | + // 结束时间 eg: 11:30 | ||
7 | + EndAt string `json:"endAt,omitempty"` | ||
8 | + // 休息时间 (单位 h) eg:0.5 | ||
9 | + BreakTime float64 `json:"breakTime,omitempty"` | ||
10 | + // 备注 eg:午饭 | ||
11 | + Remark string `json:"remark,omitempty"` | ||
12 | +} |
@@ -35,4 +35,6 @@ type ProductCalendar struct { | @@ -35,4 +35,6 @@ type ProductCalendar struct { | ||
35 | DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` | 35 | DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` |
36 | // 扩展数据 | 36 | // 扩展数据 |
37 | Ext *domain.Ext `comment:"扩展数据"` | 37 | Ext *domain.Ext `comment:"扩展数据"` |
38 | + // 休息时间周期列表 | ||
39 | + BreakTimePeriods []*domain.ProductCalendarBreakTimePeriod `comment:"休息时间周期列表"` | ||
38 | } | 40 | } |
@@ -21,5 +21,6 @@ func TransformToProductCalendarDomainModelFromPgModels(productCalendarModel *mod | @@ -21,5 +21,6 @@ func TransformToProductCalendarDomainModelFromPgModels(productCalendarModel *mod | ||
21 | UpdatedAt: productCalendarModel.UpdatedAt, | 21 | UpdatedAt: productCalendarModel.UpdatedAt, |
22 | DeletedAt: productCalendarModel.DeletedAt, | 22 | DeletedAt: productCalendarModel.DeletedAt, |
23 | Ext: productCalendarModel.Ext, | 23 | Ext: productCalendarModel.Ext, |
24 | + BreakTimePeriods: productCalendarModel.BreakTimePeriods, | ||
24 | }, nil | 25 | }, nil |
25 | } | 26 | } |
@@ -41,6 +41,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | @@ -41,6 +41,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | ||
41 | "updated_at", | 41 | "updated_at", |
42 | "deleted_at", | 42 | "deleted_at", |
43 | "ext", | 43 | "ext", |
44 | + "break_time_periods", | ||
44 | } | 45 | } |
45 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at")) | 46 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at")) |
46 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at")) | 47 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at")) |
@@ -65,6 +66,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | @@ -65,6 +66,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | ||
65 | &productCalendar.UpdatedAt, | 66 | &productCalendar.UpdatedAt, |
66 | &productCalendar.DeletedAt, | 67 | &productCalendar.DeletedAt, |
67 | &productCalendar.Ext, | 68 | &productCalendar.Ext, |
69 | + &productCalendar.BreakTimePeriods, | ||
68 | ), | 70 | ), |
69 | fmt.Sprintf("INSERT INTO manufacture.product_calendar (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | 71 | fmt.Sprintf("INSERT INTO manufacture.product_calendar (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), |
70 | productCalendar.CompanyId, | 72 | productCalendar.CompanyId, |
@@ -79,6 +81,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | @@ -79,6 +81,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | ||
79 | productCalendar.CreatedAt, | 81 | productCalendar.CreatedAt, |
80 | productCalendar.UpdatedAt, | 82 | productCalendar.UpdatedAt, |
81 | productCalendar.Ext, | 83 | productCalendar.Ext, |
84 | + productCalendar.BreakTimePeriods, | ||
82 | ); err != nil { | 85 | ); err != nil { |
83 | return productCalendar, err | 86 | return productCalendar, err |
84 | } | 87 | } |
@@ -99,6 +102,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | @@ -99,6 +102,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | ||
99 | &productCalendar.UpdatedAt, | 102 | &productCalendar.UpdatedAt, |
100 | &productCalendar.DeletedAt, | 103 | &productCalendar.DeletedAt, |
101 | &productCalendar.Ext, | 104 | &productCalendar.Ext, |
105 | + &productCalendar.BreakTimePeriods, | ||
102 | ), | 106 | ), |
103 | fmt.Sprintf("UPDATE manufacture.product_calendar SET %s WHERE product_calendar_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | 107 | fmt.Sprintf("UPDATE manufacture.product_calendar SET %s WHERE product_calendar_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), |
104 | productCalendar.CompanyId, | 108 | productCalendar.CompanyId, |
@@ -113,6 +117,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | @@ -113,6 +117,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | ||
113 | productCalendar.CreatedAt, | 117 | productCalendar.CreatedAt, |
114 | productCalendar.UpdatedAt, | 118 | productCalendar.UpdatedAt, |
115 | productCalendar.Ext, | 119 | productCalendar.Ext, |
120 | + productCalendar.BreakTimePeriods, | ||
116 | productCalendar.Identify(), | 121 | productCalendar.Identify(), |
117 | ); err != nil { | 122 | ); err != nil { |
118 | return productCalendar, err | 123 | return productCalendar, err |
-
请 注册 或 登录 后发表评论