正在显示
15 个修改的文件
包含
325 行增加
和
97 行删除
@@ -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/infrastructure/utils" | ||
5 | "reflect" | 6 | "reflect" |
6 | "strings" | 7 | "strings" |
7 | 8 | ||
@@ -34,7 +35,15 @@ type CreateProductCalendarCommand struct { | @@ -34,7 +35,15 @@ type CreateProductCalendarCommand struct { | ||
34 | } | 35 | } |
35 | 36 | ||
36 | func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validation *validation.Validation) { | 37 | func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validation *validation.Validation) { |
37 | - validation.SetError("CustomValid", "未实现的自定义认证") | 38 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
39 | + if err := utils.ValidWorkTime(createProductCalendarCommand.InWorkAt); err != nil { | ||
40 | + validation.Error(err.Error()) | ||
41 | + return | ||
42 | + } | ||
43 | + if err := utils.ValidWorkTime(createProductCalendarCommand.OutWorkAt); err != nil { | ||
44 | + validation.Error(err.Error()) | ||
45 | + return | ||
46 | + } | ||
38 | } | 47 | } |
39 | 48 | ||
40 | func (createProductCalendarCommand *CreateProductCalendarCommand) ValidateCommand() error { | 49 | func (createProductCalendarCommand *CreateProductCalendarCommand) ValidateCommand() error { |
@@ -14,7 +14,7 @@ type RemoveProductCalendarCommand struct { | @@ -14,7 +14,7 @@ type RemoveProductCalendarCommand struct { | ||
14 | } | 14 | } |
15 | 15 | ||
16 | func (removeProductCalendarCommand *RemoveProductCalendarCommand) Valid(validation *validation.Validation) { | 16 | func (removeProductCalendarCommand *RemoveProductCalendarCommand) Valid(validation *validation.Validation) { |
17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 17 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
18 | } | 18 | } |
19 | 19 | ||
20 | func (removeProductCalendarCommand *RemoveProductCalendarCommand) ValidateCommand() error { | 20 | func (removeProductCalendarCommand *RemoveProductCalendarCommand) ValidateCommand() error { |
@@ -32,7 +32,7 @@ type UpdateProductCalendarCommand struct { | @@ -32,7 +32,7 @@ type UpdateProductCalendarCommand struct { | ||
32 | } | 32 | } |
33 | 33 | ||
34 | func (updateProductCalendarCommand *UpdateProductCalendarCommand) Valid(validation *validation.Validation) { | 34 | func (updateProductCalendarCommand *UpdateProductCalendarCommand) Valid(validation *validation.Validation) { |
35 | - validation.SetError("CustomValid", "未实现的自定义认证") | 35 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
36 | } | 36 | } |
37 | 37 | ||
38 | func (updateProductCalendarCommand *UpdateProductCalendarCommand) ValidateCommand() error { | 38 | func (updateProductCalendarCommand *UpdateProductCalendarCommand) ValidateCommand() error { |
1 | +package dto | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
5 | + "strings" | ||
6 | +) | ||
7 | + | ||
8 | +type ProductCalendarDto struct { | ||
9 | + // 工厂日历ID | ||
10 | + ProductCalendarId int `json:"productCalendarId,omitempty"` | ||
11 | + // 企业id | ||
12 | + //CompanyId int `json:"companyId,omitempty"` | ||
13 | + // 组织ID | ||
14 | + //OrgId int `json:"orgId,omitempty"` | ||
15 | + // 工作位置 | ||
16 | + *domain.WorkStation | ||
17 | + // 上班班次 1:全天 2:白班 4:中班 8:夜班 | ||
18 | + WorkOn int `json:"workOn,omitempty"` | ||
19 | + // 日历选择 | ||
20 | + CalendarSelected []string `json:"calendarSelected,omitempty"` | ||
21 | + // 上岗时间 | ||
22 | + InWorkAt string `json:"inWorkAt,omitempty"` | ||
23 | + // 下岗时间 | ||
24 | + OutWorkAt string `json:"outWorkAt,omitempty"` | ||
25 | + // 休息时间 (单位 h) | ||
26 | + BreakTime float64 `json:"breakTime,omitempty"` | ||
27 | + // 工时 (单位 h) | ||
28 | + WorkTime float64 `json:"workTime,omitempty"` | ||
29 | + // 已选择日历 | ||
30 | + CalendarSelectedString string `json:"calendarSelectedString,omitempty"` | ||
31 | +} | ||
32 | + | ||
33 | +func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar) *ProductCalendarDto { | ||
34 | + d.ProductCalendarId = m.ProductCalendarId | ||
35 | + d.WorkStation = m.WorkStation | ||
36 | + d.WorkOn = m.WorkOn | ||
37 | + d.CalendarSelected = m.CalendarSelected | ||
38 | + d.InWorkAt = m.InWorkAt | ||
39 | + d.OutWorkAt = m.OutWorkAt | ||
40 | + d.BreakTime = m.BreakTime | ||
41 | + d.WorkTime = m.WorkTime | ||
42 | + d.CalendarSelectedString = strings.Join(m.CalendarSelected, "/") | ||
43 | + return d | ||
44 | +} |
@@ -14,7 +14,7 @@ type GetProductCalendarQuery struct { | @@ -14,7 +14,7 @@ type GetProductCalendarQuery struct { | ||
14 | } | 14 | } |
15 | 15 | ||
16 | func (getProductCalendarQuery *GetProductCalendarQuery) Valid(validation *validation.Validation) { | 16 | func (getProductCalendarQuery *GetProductCalendarQuery) Valid(validation *validation.Validation) { |
17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 17 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
18 | } | 18 | } |
19 | 19 | ||
20 | func (getProductCalendarQuery *GetProductCalendarQuery) ValidateQuery() error { | 20 | func (getProductCalendarQuery *GetProductCalendarQuery) ValidateQuery() error { |
@@ -16,7 +16,7 @@ type ListProductCalendarQuery struct { | @@ -16,7 +16,7 @@ type ListProductCalendarQuery struct { | ||
16 | } | 16 | } |
17 | 17 | ||
18 | func (listProductCalendarQuery *ListProductCalendarQuery) Valid(validation *validation.Validation) { | 18 | func (listProductCalendarQuery *ListProductCalendarQuery) Valid(validation *validation.Validation) { |
19 | - validation.SetError("CustomValid", "未实现的自定义认证") | 19 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
20 | } | 20 | } |
21 | 21 | ||
22 | func (listProductCalendarQuery *ListProductCalendarQuery) ValidateQuery() error { | 22 | func (listProductCalendarQuery *ListProductCalendarQuery) ValidateQuery() error { |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + | ||
9 | + "github.com/beego/beego/v2/core/validation" | ||
10 | +) | ||
11 | + | ||
12 | +type SearchProductCalendarQuery struct { | ||
13 | + // 查询偏离量 | ||
14 | + Offset int `cname:"查询偏离量" json:"offset"` | ||
15 | + // 查询限制 | ||
16 | + Limit int `cname:"查询限制" json:"limit"` | ||
17 | + // 当前公司 | ||
18 | + CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"` | ||
19 | + // 当前登录的组织 | ||
20 | + OrgId int `cname:"当前登录的组织" json:"orgId,omitempty" valid:"Required"` | ||
21 | + // 页码 | ||
22 | + PageNumber int `cname:"页码" json:"pageNumber,omitempty"` | ||
23 | + // 页数 | ||
24 | + PageSize int `cname:"页数" json:"pageSize,omitempty"` | ||
25 | + // 车间名称 | ||
26 | + WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"` | ||
27 | + // 生产线名称 | ||
28 | + //LineName string `cname:"生产线名称" json:"lineName,omitempty"` | ||
29 | + // 工段名称 | ||
30 | + //SectionName string `cname:"工段名称" json:"sectionName,omitempty"` | ||
31 | + // 班次 | ||
32 | + WorkOn int `cname:"班次" json:"workOn,omitempty"` | ||
33 | +} | ||
34 | + | ||
35 | +func (cmd *SearchProductCalendarQuery) Valid(validation *validation.Validation) { | ||
36 | + cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize) | ||
37 | +} | ||
38 | + | ||
39 | +func (cmd *SearchProductCalendarQuery) ValidateQuery() error { | ||
40 | + valid := validation.Validation{} | ||
41 | + b, err := valid.Valid(cmd) | ||
42 | + if err != nil { | ||
43 | + return err | ||
44 | + } | ||
45 | + if !b { | ||
46 | + elem := reflect.TypeOf(cmd).Elem() | ||
47 | + for _, validErr := range valid.Errors { | ||
48 | + field, isExist := elem.FieldByName(validErr.Field) | ||
49 | + if isExist { | ||
50 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
51 | + } else { | ||
52 | + return fmt.Errorf(validErr.Message) | ||
53 | + } | ||
54 | + } | ||
55 | + } | ||
56 | + return nil | ||
57 | +} |
@@ -6,8 +6,11 @@ import ( | @@ -6,8 +6,11 @@ import ( | ||
6 | "github.com/linmadan/egglib-go/utils/tool_funs" | 6 | "github.com/linmadan/egglib-go/utils/tool_funs" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productCalendar/command" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productCalendar/command" |
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productCalendar/dto" | ||
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productCalendar/query" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productCalendar/query" |
10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
13 | + "time" | ||
11 | ) | 14 | ) |
12 | 15 | ||
13 | // 工厂日历服务 | 16 | // 工厂日历服务 |
@@ -15,8 +18,10 @@ type ProductCalendarService struct { | @@ -15,8 +18,10 @@ type ProductCalendarService struct { | ||
15 | } | 18 | } |
16 | 19 | ||
17 | // 创建工厂日历服务 | 20 | // 创建工厂日历服务 |
18 | -func (productCalendarService *ProductCalendarService) CreateProductCalendar(createProductCalendarCommand *command.CreateProductCalendarCommand) (interface{}, error) { | ||
19 | - if err := createProductCalendarCommand.ValidateCommand(); err != nil { | 21 | +func (productCalendarService *ProductCalendarService) CreateProductCalendar(operateInfo *domain.OperateInfo, cmd *command.CreateProductCalendarCommand) (interface{}, error) { |
22 | + cmd.CompanyId = operateInfo.CompanyId | ||
23 | + cmd.OrgId = operateInfo.OrgId | ||
24 | + if err := cmd.ValidateCommand(); err != nil { | ||
20 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 25 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
21 | } | 26 | } |
22 | transactionContext, err := factory.CreateTransactionContext(nil) | 27 | transactionContext, err := factory.CreateTransactionContext(nil) |
@@ -29,27 +34,42 @@ func (productCalendarService *ProductCalendarService) CreateProductCalendar(crea | @@ -29,27 +34,42 @@ func (productCalendarService *ProductCalendarService) CreateProductCalendar(crea | ||
29 | defer func() { | 34 | defer func() { |
30 | transactionContext.RollbackTransaction() | 35 | transactionContext.RollbackTransaction() |
31 | }() | 36 | }() |
32 | - newProductCalendar := &domain.ProductCalendar{ | ||
33 | - CompanyId: createProductCalendarCommand.CompanyId, | ||
34 | - OrgId: createProductCalendarCommand.OrgId, | ||
35 | - //WorkshopId: createProductCalendarCommand.WorkshopId, | ||
36 | - //LineId: createProductCalendarCommand.LineId, | ||
37 | - //SectionId: createProductCalendarCommand.SectionId, | ||
38 | - //WorkOn: createProductCalendarCommand.WorkOn, | ||
39 | - CalendarSelected: createProductCalendarCommand.CalendarSelected, | ||
40 | - InWorkAt: createProductCalendarCommand.InWorkAt, | ||
41 | - OutWorkAt: createProductCalendarCommand.OutWorkAt, | ||
42 | - BreakTime: createProductCalendarCommand.BreakTime, | ||
43 | - WorkTime: createProductCalendarCommand.WorkTime, | 37 | + |
38 | + var workStation *domain.WorkStation | ||
39 | + _, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId) | ||
40 | + if err != nil { | ||
41 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
44 | } | 42 | } |
45 | - var productCalendarRepository domain.ProductCalendarRepository | ||
46 | - if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{ | ||
47 | - "transactionContext": transactionContext, | ||
48 | - }); err != nil { | 43 | + |
44 | + // 判断同一个工作位置班次下,是否已重复排班 | ||
45 | + productCalendarRepository, _, _ := factory.FastPgProductCalendar(transactionContext, 0) | ||
46 | + if total, _, err := productCalendarRepository.Find(map[string]interface{}{ | ||
47 | + "companyId": cmd.CompanyId, | ||
48 | + "orgId": cmd.OrgId, | ||
49 | + "workStationId": workStation.WorkStationId, | ||
50 | + "workOn": cmd.WorkOn, | ||
51 | + "limit": 1, | ||
52 | + }); err == nil && total > 0 { | ||
53 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "工厂日历已存在") | ||
54 | + } | ||
55 | + | ||
56 | + newProductCalendar := &domain.ProductCalendar{ | ||
57 | + CompanyId: cmd.CompanyId, | ||
58 | + OrgId: cmd.OrgId, | ||
59 | + WorkStation: workStation, | ||
60 | + WorkOn: cmd.WorkOn, | ||
61 | + CalendarSelected: cmd.CalendarSelected, | ||
62 | + InWorkAt: cmd.InWorkAt, | ||
63 | + OutWorkAt: cmd.OutWorkAt, | ||
64 | + BreakTime: cmd.BreakTime, | ||
65 | + //WorkTime: cmd.WorkTime, | ||
66 | + CreatedAt: time.Now(), | ||
67 | + UpdatedAt: time.Now(), | ||
68 | + } | ||
69 | + if err = newProductCalendar.ResetWorkTime(cmd.WorkTime); err != nil { | ||
49 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 70 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
50 | - } else { | ||
51 | - productCalendarRepository = value | ||
52 | } | 71 | } |
72 | + | ||
53 | if productCalendar, err := productCalendarRepository.Save(newProductCalendar); err != nil { | 73 | if productCalendar, err := productCalendarRepository.Save(newProductCalendar); err != nil { |
54 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 74 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
55 | } else { | 75 | } else { |
@@ -93,7 +113,10 @@ func (productCalendarService *ProductCalendarService) GetProductCalendar(getProd | @@ -93,7 +113,10 @@ func (productCalendarService *ProductCalendarService) GetProductCalendar(getProd | ||
93 | if err := transactionContext.CommitTransaction(); err != nil { | 113 | if err := transactionContext.CommitTransaction(); err != nil { |
94 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 114 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
95 | } | 115 | } |
96 | - return productCalendar, nil | 116 | + |
117 | + result := &dto.ProductCalendarDto{} | ||
118 | + result.LoadDto(productCalendar) | ||
119 | + return result, nil | ||
97 | } | 120 | } |
98 | } | 121 | } |
99 | 122 | ||
@@ -174,8 +197,8 @@ func (productCalendarService *ProductCalendarService) RemoveProductCalendar(remo | @@ -174,8 +197,8 @@ func (productCalendarService *ProductCalendarService) RemoveProductCalendar(remo | ||
174 | } | 197 | } |
175 | 198 | ||
176 | // 更新工厂日历服务 | 199 | // 更新工厂日历服务 |
177 | -func (productCalendarService *ProductCalendarService) UpdateProductCalendar(updateProductCalendarCommand *command.UpdateProductCalendarCommand) (interface{}, error) { | ||
178 | - if err := updateProductCalendarCommand.ValidateCommand(); err != nil { | 200 | +func (productCalendarService *ProductCalendarService) UpdateProductCalendar(cmd *command.UpdateProductCalendarCommand) (interface{}, error) { |
201 | + if err := cmd.ValidateCommand(); err != nil { | ||
179 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 202 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
180 | } | 203 | } |
181 | transactionContext, err := factory.CreateTransactionContext(nil) | 204 | transactionContext, err := factory.CreateTransactionContext(nil) |
@@ -189,21 +212,42 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(upda | @@ -189,21 +212,42 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(upda | ||
189 | transactionContext.RollbackTransaction() | 212 | transactionContext.RollbackTransaction() |
190 | }() | 213 | }() |
191 | var productCalendarRepository domain.ProductCalendarRepository | 214 | var productCalendarRepository domain.ProductCalendarRepository |
192 | - if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{ | ||
193 | - "transactionContext": transactionContext, | ||
194 | - }); err != nil { | 215 | + var productCalendar *domain.ProductCalendar |
216 | + productCalendarRepository, productCalendar, err = factory.FastPgProductCalendar(transactionContext, cmd.ProductCalendarId) | ||
217 | + if err != nil { | ||
195 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 218 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
196 | - } else { | ||
197 | - productCalendarRepository = value | ||
198 | } | 219 | } |
199 | - productCalendar, err := productCalendarRepository.FindOne(map[string]interface{}{"productCalendarId": updateProductCalendarCommand.ProductCalendarId}) | 220 | + |
221 | + var workStation *domain.WorkStation | ||
222 | + _, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId, factory.WithSetPrincipal()) | ||
200 | if err != nil { | 223 | if err != nil { |
201 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 224 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
202 | } | 225 | } |
203 | - if productCalendar == nil { | ||
204 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductCalendarCommand.ProductCalendarId))) | 226 | + |
227 | + // 判断同一个工作位置班次下,是否已重复排班 | ||
228 | + if productCalendar.WorkOn != cmd.WorkOn || productCalendar.WorkStation.WorkStationId != workStation.WorkStationId { | ||
229 | + if total, _, err := productCalendarRepository.Find(map[string]interface{}{ | ||
230 | + "companyId": productCalendar.CompanyId, | ||
231 | + "orgId": productCalendar.OrgId, | ||
232 | + "workStationId": workStation.WorkStationId, | ||
233 | + "workOn": cmd.WorkOn, | ||
234 | + "limit": 1, | ||
235 | + }); err == nil && total > 0 { | ||
236 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "工厂日历已存在") | ||
237 | + } | ||
205 | } | 238 | } |
206 | - if err := productCalendar.Update(tool_funs.SimpleStructToMap(updateProductCalendarCommand)); err != nil { | 239 | + |
240 | + productCalendar.WorkStation = workStation | ||
241 | + productCalendar.WorkOn = cmd.WorkOn | ||
242 | + productCalendar.CalendarSelected = cmd.CalendarSelected | ||
243 | + productCalendar.InWorkAt = cmd.InWorkAt | ||
244 | + productCalendar.OutWorkAt = cmd.OutWorkAt | ||
245 | + productCalendar.BreakTime = cmd.BreakTime | ||
246 | + if err = productCalendar.ResetWorkTime(cmd.WorkTime); err != nil { | ||
247 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
248 | + } | ||
249 | + | ||
250 | + if err := productCalendar.Update(tool_funs.SimpleStructToMap(cmd)); err != nil { | ||
207 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 251 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
208 | } | 252 | } |
209 | if productCalendar, err := productCalendarRepository.Save(productCalendar); err != nil { | 253 | if productCalendar, err := productCalendarRepository.Save(productCalendar); err != nil { |
@@ -216,6 +260,45 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(upda | @@ -216,6 +260,45 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(upda | ||
216 | } | 260 | } |
217 | } | 261 | } |
218 | 262 | ||
263 | +// 返回工厂日历服务列表 | ||
264 | +func (productCalendarService *ProductCalendarService) SearchProductCalendar(operateInfo *domain.OperateInfo, listProductCalendarQuery *query.SearchProductCalendarQuery) (int64, interface{}, error) { | ||
265 | + listProductCalendarQuery.OrgId = operateInfo.OrgId | ||
266 | + listProductCalendarQuery.CompanyId = operateInfo.CompanyId | ||
267 | + if err := listProductCalendarQuery.ValidateQuery(); err != nil { | ||
268 | + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
269 | + } | ||
270 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
271 | + if err != nil { | ||
272 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
273 | + } | ||
274 | + if err := transactionContext.StartTransaction(); err != nil { | ||
275 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
276 | + } | ||
277 | + defer func() { | ||
278 | + transactionContext.RollbackTransaction() | ||
279 | + }() | ||
280 | + var productCalendarRepository domain.ProductCalendarRepository | ||
281 | + productCalendarRepository, _, _ = factory.FastPgProductCalendar(transactionContext, 0) | ||
282 | + | ||
283 | + count, productCalendars, err := productCalendarRepository.Find(utils.ObjectToMap(listProductCalendarQuery)) | ||
284 | + if err != nil { | ||
285 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
286 | + } | ||
287 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
288 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
289 | + } | ||
290 | + | ||
291 | + var result = make([]*dto.ProductCalendarDto, 0) | ||
292 | + for i := range productCalendars { | ||
293 | + item := productCalendars[i] | ||
294 | + newJobDto := &dto.ProductCalendarDto{} | ||
295 | + newJobDto.LoadDto(item) | ||
296 | + result = append(result, newJobDto) | ||
297 | + } | ||
298 | + | ||
299 | + return count, result, nil | ||
300 | +} | ||
301 | + | ||
219 | func NewProductCalendarService(options map[string]interface{}) *ProductCalendarService { | 302 | func NewProductCalendarService(options map[string]interface{}) *ProductCalendarService { |
220 | newProductCalendarService := &ProductCalendarService{} | 303 | newProductCalendarService := &ProductCalendarService{} |
221 | return newProductCalendarService | 304 | return newProductCalendarService |
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | -import "time" | 3 | +import ( |
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
5 | + "time" | ||
6 | +) | ||
4 | 7 | ||
5 | // 工厂日历 | 8 | // 工厂日历 |
6 | type ProductCalendar struct { | 9 | type ProductCalendar struct { |
@@ -47,62 +50,24 @@ func (productCalendar *ProductCalendar) Identify() interface{} { | @@ -47,62 +50,24 @@ func (productCalendar *ProductCalendar) Identify() interface{} { | ||
47 | } | 50 | } |
48 | 51 | ||
49 | func (productCalendar *ProductCalendar) Update(data map[string]interface{}) error { | 52 | func (productCalendar *ProductCalendar) Update(data map[string]interface{}) error { |
50 | - if productCalendarId, ok := data["productCalendarId"]; ok { | ||
51 | - productCalendar.ProductCalendarId = productCalendarId.(int) | ||
52 | - } | ||
53 | - if companyId, ok := data["companyId"]; ok { | ||
54 | - productCalendar.CompanyId = companyId.(int) | ||
55 | - } | ||
56 | - if orgId, ok := data["orgId"]; ok { | ||
57 | - productCalendar.OrgId = orgId.(int) | ||
58 | - } | ||
59 | - if workStationId, ok := data["workStationId"]; ok { | ||
60 | - productCalendar.WorkStation.WorkStationId = workStationId.(string) | ||
61 | - } | ||
62 | - if workshopId, ok := data["workshopId"]; ok { | ||
63 | - productCalendar.WorkStation.WorkshopId = workshopId.(int) | ||
64 | - } | ||
65 | - if workshopName, ok := data["workshopName"]; ok { | ||
66 | - productCalendar.WorkStation.WorkshopName = workshopName.(string) | ||
67 | - } | ||
68 | - if lineId, ok := data["lineId"]; ok { | ||
69 | - productCalendar.WorkStation.LineId = lineId.(int) | ||
70 | - } | ||
71 | - if lineName, ok := data["lineName"]; ok { | ||
72 | - productCalendar.WorkStation.LineName = lineName.(string) | ||
73 | - } | ||
74 | - if sectionId, ok := data["sectionId"]; ok { | ||
75 | - productCalendar.WorkStation.SectionId = sectionId.(int) | ||
76 | - } | ||
77 | - if sectionName, ok := data["sectionName"]; ok { | ||
78 | - productCalendar.WorkStation.SectionName = sectionName.(string) | ||
79 | - } | ||
80 | - if workOn, ok := data["workOn"]; ok { | ||
81 | - productCalendar.WorkOn = workOn.(int) | ||
82 | - } | ||
83 | - //if calendarSelected, ok := data["calendarSelected"]; ok { | ||
84 | - // productCalendar.CalendarSelected = calendarSelected.(array) | ||
85 | - //} | ||
86 | - if inWorkAt, ok := data["inWorkAt"]; ok { | ||
87 | - productCalendar.InWorkAt = inWorkAt.(string) | ||
88 | - } | ||
89 | - if outWorkAt, ok := data["outWorkAt"]; ok { | ||
90 | - productCalendar.OutWorkAt = outWorkAt.(string) | ||
91 | - } | ||
92 | - if breakTime, ok := data["breakTime"]; ok { | ||
93 | - productCalendar.BreakTime = breakTime.(float64) | ||
94 | - } | ||
95 | - if workTime, ok := data["workTime"]; ok { | ||
96 | - productCalendar.WorkTime = workTime.(float64) | ||
97 | - } | ||
98 | - if createdAt, ok := data["createdAt"]; ok { | ||
99 | - productCalendar.CreatedAt = createdAt.(time.Time) | 53 | + productCalendar.UpdatedAt = time.Now() |
54 | + return nil | ||
55 | +} | ||
56 | + | ||
57 | +func (productCalendar *ProductCalendar) ResetWorkTime(v float64) error { | ||
58 | + if v != 0 { | ||
59 | + productCalendar.WorkTime = v | ||
60 | + return nil | ||
100 | } | 61 | } |
101 | - if updatedAt, ok := data["updatedAt"]; ok { | ||
102 | - productCalendar.UpdatedAt = updatedAt.(time.Time) | 62 | + td, err := utils.ComputeTimeDuration(productCalendar.InWorkAt, productCalendar.OutWorkAt) |
63 | + if err != nil { | ||
64 | + return err | ||
103 | } | 65 | } |
104 | - if deletedAt, ok := data["deletedAt"]; ok { | ||
105 | - productCalendar.DeletedAt = deletedAt.(time.Time) | 66 | + if td.Hours() <= productCalendar.BreakTime { |
67 | + productCalendar.WorkTime = 0 | ||
68 | + return nil | ||
106 | } | 69 | } |
70 | + // 工作时长 = (上班时间-下班时间)- 休息时间 | ||
71 | + productCalendar.WorkTime = td.Hours() - productCalendar.BreakTime | ||
107 | return nil | 72 | return nil |
108 | } | 73 | } |
@@ -18,7 +18,7 @@ type ProductCalendar struct { | @@ -18,7 +18,7 @@ type ProductCalendar struct { | ||
18 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 | 18 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 |
19 | WorkOn int `comment:"上班班次 1:全天 2:白班 4:中班 8:夜班"` | 19 | WorkOn int `comment:"上班班次 1:全天 2:白班 4:中班 8:夜班"` |
20 | // 日历选择 | 20 | // 日历选择 |
21 | - CalendarSelected []string `comment:"日历选择" pg:",array"` | 21 | + CalendarSelected []string `comment:"日历选择"` |
22 | // 上岗时间 | 22 | // 上岗时间 |
23 | InWorkAt string `comment:"上岗时间"` | 23 | InWorkAt string `comment:"上岗时间"` |
24 | // 下岗时间 | 24 | // 下岗时间 |
@@ -63,7 +63,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | @@ -63,7 +63,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | ||
63 | &productCalendar.UpdatedAt, | 63 | &productCalendar.UpdatedAt, |
64 | &productCalendar.DeletedAt, | 64 | &productCalendar.DeletedAt, |
65 | ), | 65 | ), |
66 | - fmt.Sprintf("INSERT INTO product_calendars (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | 66 | + fmt.Sprintf("INSERT INTO manufacture.product_calendar (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), |
67 | productCalendar.CompanyId, | 67 | productCalendar.CompanyId, |
68 | productCalendar.OrgId, | 68 | productCalendar.OrgId, |
69 | productCalendar.WorkStation, | 69 | productCalendar.WorkStation, |
@@ -95,7 +95,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | @@ -95,7 +95,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | ||
95 | &productCalendar.UpdatedAt, | 95 | &productCalendar.UpdatedAt, |
96 | &productCalendar.DeletedAt, | 96 | &productCalendar.DeletedAt, |
97 | ), | 97 | ), |
98 | - fmt.Sprintf("UPDATE product_calendars SET %s WHERE product_calendar_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | 98 | + fmt.Sprintf("UPDATE manufacture.product_calendar SET %s WHERE product_calendar_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), |
99 | productCalendar.CompanyId, | 99 | productCalendar.CompanyId, |
100 | productCalendar.OrgId, | 100 | productCalendar.OrgId, |
101 | productCalendar.WorkStation, | 101 | productCalendar.WorkStation, |
@@ -146,7 +146,14 @@ func (repository *ProductCalendarRepository) Find(queryOptions map[string]interf | @@ -146,7 +146,14 @@ func (repository *ProductCalendarRepository) Find(queryOptions map[string]interf | ||
146 | var productCalendarModels []*models.ProductCalendar | 146 | var productCalendarModels []*models.ProductCalendar |
147 | productCalendars := make([]*domain.ProductCalendar, 0) | 147 | productCalendars := make([]*domain.ProductCalendar, 0) |
148 | query := sqlbuilder.BuildQuery(tx.Model(&productCalendarModels), queryOptions) | 148 | query := sqlbuilder.BuildQuery(tx.Model(&productCalendarModels), queryOptions) |
149 | - query.SetOffsetAndLimit(20) | 149 | + query.SetWhereByQueryOption("company_id = ?", "companyId") |
150 | + query.SetWhereByQueryOption("org_id = ?", "orgId") | ||
151 | + query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId") | ||
152 | + query.SetWhereByQueryOption("work_on & ? >0", "workOn") | ||
153 | + if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 { | ||
154 | + query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v)) | ||
155 | + } | ||
156 | + query.SetOffsetAndLimit(domain.MaxQueryRow) | ||
150 | query.SetOrderDirect("product_calendar_id", "DESC") | 157 | query.SetOrderDirect("product_calendar_id", "DESC") |
151 | if count, err := query.SelectAndCount(); err != nil { | 158 | if count, err := query.SelectAndCount(); err != nil { |
152 | return 0, productCalendars, err | 159 | return 0, productCalendars, err |
@@ -288,3 +288,30 @@ func ValidWorkTime(t string) error { | @@ -288,3 +288,30 @@ func ValidWorkTime(t string) error { | ||
288 | } | 288 | } |
289 | return nil | 289 | return nil |
290 | } | 290 | } |
291 | + | ||
292 | +// 计算两个时间间隔的时间 | ||
293 | +func ComputeTimeDuration(t1, t2 string) (result time.Duration, err error) { | ||
294 | + if err = ValidWorkTime(t1); err != nil { | ||
295 | + return | ||
296 | + } | ||
297 | + if err = ValidWorkTime(t2); err != nil { | ||
298 | + return | ||
299 | + } | ||
300 | + t1s := strings.Split(t1, ":") | ||
301 | + t1sHour, _ := strconv.Atoi(t1s[0]) | ||
302 | + t1sMin, _ := strconv.Atoi(t1s[1]) | ||
303 | + | ||
304 | + t2s := strings.Split(t2, ":") | ||
305 | + t2sHour, _ := strconv.Atoi(t2s[0]) | ||
306 | + t2sMin, _ := strconv.Atoi(t2s[1]) | ||
307 | + var t1t, t2t time.Time | ||
308 | + if t1sHour < t2sHour { | ||
309 | + t1t = time.Date(2006, 1, 1, t1sHour, t1sMin, 0, 0, time.Local) | ||
310 | + t2t = time.Date(2006, 1, 1, t2sHour, t2sMin, 0, 0, time.Local) | ||
311 | + } else { | ||
312 | + t1t = time.Date(2006, 1, 1, t1sHour, t1sMin, 0, 0, time.Local) | ||
313 | + t2t = time.Date(2006, 1, 2, t2sHour, t2sMin, 0, 0, time.Local) | ||
314 | + } | ||
315 | + ts := t2t.Sub(t1t) | ||
316 | + return ts, nil | ||
317 | +} |
@@ -3,6 +3,7 @@ package utils | @@ -3,6 +3,7 @@ package utils | ||
3 | import ( | 3 | import ( |
4 | "github.com/stretchr/testify/assert" | 4 | "github.com/stretchr/testify/assert" |
5 | "testing" | 5 | "testing" |
6 | + "time" | ||
6 | ) | 7 | ) |
7 | 8 | ||
8 | func TestTimeSpan(t *testing.T) { | 9 | func TestTimeSpan(t *testing.T) { |
@@ -26,3 +27,28 @@ func TestTimeSpan(t *testing.T) { | @@ -26,3 +27,28 @@ func TestTimeSpan(t *testing.T) { | ||
26 | } | 27 | } |
27 | } | 28 | } |
28 | } | 29 | } |
30 | + | ||
31 | +func TestComputeTimeDuration(t *testing.T) { | ||
32 | + assertDuration := func(s string) time.Duration { | ||
33 | + t, _ := time.ParseDuration(s) | ||
34 | + return t | ||
35 | + } | ||
36 | + inputs := []struct { | ||
37 | + t1 string | ||
38 | + t2 string | ||
39 | + ts time.Duration | ||
40 | + }{ | ||
41 | + { | ||
42 | + "9:00", "18:00", assertDuration("9h"), | ||
43 | + }, | ||
44 | + { | ||
45 | + "23:00", "6:00", assertDuration("7h"), | ||
46 | + }, | ||
47 | + } | ||
48 | + for i := range inputs { | ||
49 | + input := inputs[i] | ||
50 | + out, err := ComputeTimeDuration(input.t1, input.t2) | ||
51 | + assert.Nil(t, err) | ||
52 | + assert.Equal(t, input.ts, out) | ||
53 | + } | ||
54 | +} |
@@ -15,7 +15,7 @@ func (controller *ProductCalendarController) CreateProductCalendar() { | @@ -15,7 +15,7 @@ func (controller *ProductCalendarController) CreateProductCalendar() { | ||
15 | productCalendarService := service.NewProductCalendarService(nil) | 15 | productCalendarService := service.NewProductCalendarService(nil) |
16 | createProductCalendarCommand := &command.CreateProductCalendarCommand{} | 16 | createProductCalendarCommand := &command.CreateProductCalendarCommand{} |
17 | controller.Unmarshal(createProductCalendarCommand) | 17 | controller.Unmarshal(createProductCalendarCommand) |
18 | - data, err := productCalendarService.CreateProductCalendar(createProductCalendarCommand) | 18 | + data, err := productCalendarService.CreateProductCalendar(ParseOperateInfo(controller.BaseController), createProductCalendarCommand) |
19 | controller.Response(data, err) | 19 | controller.Response(data, err) |
20 | } | 20 | } |
21 | 21 | ||
@@ -58,3 +58,11 @@ func (controller *ProductCalendarController) ListProductCalendar() { | @@ -58,3 +58,11 @@ func (controller *ProductCalendarController) ListProductCalendar() { | ||
58 | data, err := productCalendarService.ListProductCalendar(listProductCalendarQuery) | 58 | data, err := productCalendarService.ListProductCalendar(listProductCalendarQuery) |
59 | controller.Response(data, err) | 59 | controller.Response(data, err) |
60 | } | 60 | } |
61 | + | ||
62 | +func (controller *ProductCalendarController) SearchProductCalendar() { | ||
63 | + productCalendarService := service.NewProductCalendarService(nil) | ||
64 | + cmd := &query.SearchProductCalendarQuery{} | ||
65 | + Must(controller.Unmarshal(cmd)) | ||
66 | + total, data, err := productCalendarService.SearchProductCalendar(ParseOperateInfo(controller.BaseController), cmd) | ||
67 | + ResponseGrid(controller.BaseController, total, data, err) | ||
68 | +} |
@@ -11,4 +11,6 @@ func init() { | @@ -11,4 +11,6 @@ func init() { | ||
11 | web.Router("/product-calendars/:productCalendarId", &controllers.ProductCalendarController{}, "Get:GetProductCalendar") | 11 | web.Router("/product-calendars/:productCalendarId", &controllers.ProductCalendarController{}, "Get:GetProductCalendar") |
12 | web.Router("/product-calendars/:productCalendarId", &controllers.ProductCalendarController{}, "Delete:RemoveProductCalendar") | 12 | web.Router("/product-calendars/:productCalendarId", &controllers.ProductCalendarController{}, "Delete:RemoveProductCalendar") |
13 | web.Router("/product-calendars/", &controllers.ProductCalendarController{}, "Get:ListProductCalendar") | 13 | web.Router("/product-calendars/", &controllers.ProductCalendarController{}, "Get:ListProductCalendar") |
14 | + | ||
15 | + web.Router("/product-calendars/search", &controllers.ProductCalendarController{}, "Post:SearchProductCalendar") | ||
14 | } | 16 | } |
-
请 注册 或 登录 后发表评论