正在显示
14 个修改的文件
包含
243 行增加
和
137 行删除
@@ -14,7 +14,7 @@ type SetOnlineCommand struct { | @@ -14,7 +14,7 @@ type SetOnlineCommand struct { | ||
14 | // 车间ID | 14 | // 车间ID |
15 | WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` | 15 | WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` |
16 | // 生产线ID | 16 | // 生产线ID |
17 | - LineId int `cname:"生产线ID" json:"lineId" valid:"Required"` | 17 | + //LineId int `cname:"生产线ID" json:"lineId" valid:"Required"` |
18 | // 工段ID | 18 | // 工段ID |
19 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` | 19 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` |
20 | } | 20 | } |
@@ -39,7 +39,7 @@ type UpdateProductPlanCommand struct { | @@ -39,7 +39,7 @@ type UpdateProductPlanCommand struct { | ||
39 | // 备注 | 39 | // 备注 |
40 | Remark string `cname:"备注" json:"remark" valid:"Required"` | 40 | Remark string `cname:"备注" json:"remark" valid:"Required"` |
41 | // 生产日期 | 41 | // 生产日期 |
42 | - ProductDateTime time.Time `cname:"生产日期" json:"-" ` | 42 | + ProductDateTime time.Time `cname:"生产日期" json:"productDateTime" ` |
43 | } | 43 | } |
44 | 44 | ||
45 | func (updateProductPlanCommand *UpdateProductPlanCommand) Valid(validation *validation.Validation) { | 45 | func (updateProductPlanCommand *UpdateProductPlanCommand) Valid(validation *validation.Validation) { |
@@ -256,15 +256,28 @@ func (productPlanService *ProductPlanService) SetOffline(setOfflineCommand *comm | @@ -256,15 +256,28 @@ func (productPlanService *ProductPlanService) SetOffline(setOfflineCommand *comm | ||
256 | defer func() { | 256 | defer func() { |
257 | transactionContext.RollbackTransaction() | 257 | transactionContext.RollbackTransaction() |
258 | }() | 258 | }() |
259 | + | ||
260 | + var productPlanRepository domain.ProductPlanRepository | ||
261 | + var productPlan *domain.ProductPlan | ||
262 | + productPlanRepository, productPlan, _ = factory.FastPgProductPlan(transactionContext, setOfflineCommand.ProductPlanId) | ||
263 | + | ||
264 | + if err = productPlan.ChangeStatus(domain.PlanOffline); err != nil { | ||
265 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
266 | + } | ||
267 | + | ||
268 | + if productPlan, err = productPlanRepository.Save(productPlan); err != nil { | ||
269 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
270 | + } | ||
271 | + | ||
259 | if err := transactionContext.CommitTransaction(); err != nil { | 272 | if err := transactionContext.CommitTransaction(); err != nil { |
260 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 273 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
261 | } | 274 | } |
262 | - return nil, nil | 275 | + return productPlan, nil |
263 | } | 276 | } |
264 | 277 | ||
265 | // 计划上线 | 278 | // 计划上线 |
266 | -func (productPlanService *ProductPlanService) SetOnline(setOnlineCommand *command.SetOnlineCommand) (interface{}, error) { | ||
267 | - if err := setOnlineCommand.ValidateCommand(); err != nil { | 279 | +func (productPlanService *ProductPlanService) SetOnline(cmd *command.SetOnlineCommand) (interface{}, error) { |
280 | + if err := cmd.ValidateCommand(); err != nil { | ||
268 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 281 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
269 | } | 282 | } |
270 | transactionContext, err := factory.CreateTransactionContext(nil) | 283 | transactionContext, err := factory.CreateTransactionContext(nil) |
@@ -277,10 +290,45 @@ func (productPlanService *ProductPlanService) SetOnline(setOnlineCommand *comman | @@ -277,10 +290,45 @@ func (productPlanService *ProductPlanService) SetOnline(setOnlineCommand *comman | ||
277 | defer func() { | 290 | defer func() { |
278 | transactionContext.RollbackTransaction() | 291 | transactionContext.RollbackTransaction() |
279 | }() | 292 | }() |
293 | + var productPlanRepository domain.ProductPlanRepository | ||
294 | + var productPlan *domain.ProductPlan | ||
295 | + | ||
296 | + productPlanRepository, productPlan, err = factory.FastPgProductPlan(transactionContext, cmd.ProductPlanId) | ||
297 | + if err != nil { | ||
298 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
299 | + } | ||
300 | + | ||
301 | + if err = productPlan.ChangeStatus(domain.PlanOnline); err != nil { | ||
302 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
303 | + } | ||
304 | + | ||
305 | + var workshop *domain.Workshop | ||
306 | + _, workshop, err = factory.FastPgWorkshop(transactionContext, cmd.WorkshopId) | ||
307 | + if err != nil { | ||
308 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
309 | + } | ||
310 | + | ||
311 | + line, section, err := workshop.FindSectionById(cmd.SectionId) | ||
312 | + if err != nil { | ||
313 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
314 | + } | ||
315 | + | ||
316 | + var workStation *domain.WorkStation | ||
317 | + workStation, err = workshop.FindWorkStation(workshop.WorkshopId, line.LineId, section.SectionId) | ||
318 | + if err != nil { | ||
319 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
320 | + } | ||
321 | + | ||
322 | + productPlan.WorkStation = workStation | ||
323 | + | ||
324 | + if productPlan, err = productPlanRepository.Save(productPlan); err != nil { | ||
325 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
326 | + } | ||
327 | + | ||
280 | if err := transactionContext.CommitTransaction(); err != nil { | 328 | if err := transactionContext.CommitTransaction(); err != nil { |
281 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 329 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
282 | } | 330 | } |
283 | - return nil, nil | 331 | + return productPlan, nil |
284 | } | 332 | } |
285 | 333 | ||
286 | // 提交成品记录 (成品 二级品) | 334 | // 提交成品记录 (成品 二级品) |
@@ -326,8 +374,8 @@ func (productPlanService *ProductPlanService) Exchange(switchCommand *command.Sw | @@ -326,8 +374,8 @@ func (productPlanService *ProductPlanService) Exchange(switchCommand *command.Sw | ||
326 | } | 374 | } |
327 | 375 | ||
328 | // 更新生产计划服务 | 376 | // 更新生产计划服务 |
329 | -func (productPlanService *ProductPlanService) UpdateProductPlan(updateProductPlanCommand *command.UpdateProductPlanCommand) (interface{}, error) { | ||
330 | - if err := updateProductPlanCommand.ValidateCommand(); err != nil { | 377 | +func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.UpdateProductPlanCommand) (interface{}, error) { |
378 | + if err := cmd.ValidateCommand(); err != nil { | ||
331 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 379 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
332 | } | 380 | } |
333 | transactionContext, err := factory.CreateTransactionContext(nil) | 381 | transactionContext, err := factory.CreateTransactionContext(nil) |
@@ -341,31 +389,38 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(updateProductPla | @@ -341,31 +389,38 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(updateProductPla | ||
341 | transactionContext.RollbackTransaction() | 389 | transactionContext.RollbackTransaction() |
342 | }() | 390 | }() |
343 | var productPlanRepository domain.ProductPlanRepository | 391 | var productPlanRepository domain.ProductPlanRepository |
344 | - if value, err := factory.CreateProductPlanRepository(map[string]interface{}{ | ||
345 | - "transactionContext": transactionContext, | ||
346 | - }); err != nil { | 392 | + var productPlan *domain.ProductPlan |
393 | + productPlanRepository, productPlan, err = factory.FastPgProductPlan(transactionContext, cmd.ProductPlanId) | ||
394 | + if err != nil { | ||
347 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 395 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
348 | - } else { | ||
349 | - productPlanRepository = value | ||
350 | } | 396 | } |
351 | - productPlan, err := productPlanRepository.FindOne(map[string]interface{}{"productPlanId": updateProductPlanCommand.ProductPlanId}) | 397 | + |
398 | + //if productPlan.Workshop.WorkshopId != cmd.WorkshopId{ | ||
399 | + // // 检查批次号是否有重复的 | ||
400 | + // if item, err := productPlanRepository.FindOne(map[string]interface{}{"companyId": cmd.CompanyId, "orgId": cmd.OrgId, "batchNumber": cmd.BatchNumber}); err == nil && item != nil { | ||
401 | + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "批次号重复") | ||
402 | + // } | ||
403 | + //} | ||
404 | + | ||
405 | + _, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId) | ||
352 | if err != nil { | 406 | if err != nil { |
353 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 407 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
354 | } | 408 | } |
355 | - if productPlan == nil { | ||
356 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductPlanCommand.ProductPlanId))) | ||
357 | - } | ||
358 | - if err := productPlan.Update(tool_funs.SimpleStructToMap(updateProductPlanCommand)); err != nil { | 409 | + productPlan.Workshop = workshop.CloneSample() |
410 | + | ||
411 | + if err := productPlan.Update(tool_funs.SimpleStructToMap(cmd)); err != nil { | ||
359 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 412 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
360 | } | 413 | } |
361 | - if productPlan, err := productPlanRepository.Save(productPlan); err != nil { | 414 | + if productPlan, err = productPlanRepository.Save(productPlan); err != nil { |
362 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 415 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
363 | - } else { | ||
364 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
365 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
366 | - } | ||
367 | - return productPlan, nil | ||
368 | } | 416 | } |
417 | + | ||
418 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
419 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
420 | + } | ||
421 | + | ||
422 | + result := &dto.ProductPlanDto{} | ||
423 | + return result.LoadDto(productPlan, cmd.OrgId), nil | ||
369 | } | 424 | } |
370 | 425 | ||
371 | // 搜索生产计划服务列表 | 426 | // 搜索生产计划服务列表 |
@@ -326,6 +326,38 @@ func (workshopService *WorkshopService) SelectorWorkshop(operateInfo *domain.Ope | @@ -326,6 +326,38 @@ func (workshopService *WorkshopService) SelectorWorkshop(operateInfo *domain.Ope | ||
326 | 326 | ||
327 | } | 327 | } |
328 | 328 | ||
329 | +// 车间工段列表 | ||
330 | +func (workshopService *WorkshopService) SelectorWorkshopSection(operateInfo *domain.OperateInfo, getWorkshopQuery *query.GetWorkshopQuery) (interface{}, error) { | ||
331 | + if err := getWorkshopQuery.ValidateQuery(); err != nil { | ||
332 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
333 | + } | ||
334 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
335 | + if err != nil { | ||
336 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
337 | + } | ||
338 | + if err := transactionContext.StartTransaction(); err != nil { | ||
339 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
340 | + } | ||
341 | + defer func() { | ||
342 | + transactionContext.RollbackTransaction() | ||
343 | + }() | ||
344 | + | ||
345 | + var workshop *domain.Workshop | ||
346 | + _, workshop, err = factory.FastPgWorkshop(transactionContext, getWorkshopQuery.WorkshopId) | ||
347 | + if err != nil { | ||
348 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
349 | + } | ||
350 | + | ||
351 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
352 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
353 | + } | ||
354 | + sections := workshop.AllProductSections(domain.All) | ||
355 | + return map[string]interface{}{ | ||
356 | + "count": len(sections), | ||
357 | + "sections": sections, | ||
358 | + }, nil | ||
359 | +} | ||
360 | + | ||
329 | func NewWorkshopService(options map[string]interface{}) *WorkshopService { | 361 | func NewWorkshopService(options map[string]interface{}) *WorkshopService { |
330 | newWorkshopService := &WorkshopService{} | 362 | newWorkshopService := &WorkshopService{} |
331 | return newWorkshopService | 363 | return newWorkshopService |
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | +import "fmt" | ||
4 | + | ||
3 | // 生产线 | 5 | // 生产线 |
4 | type ProductLine struct { | 6 | type ProductLine struct { |
5 | // 生产线ID | 7 | // 生产线ID |
@@ -12,6 +14,17 @@ type ProductLine struct { | @@ -12,6 +14,17 @@ type ProductLine struct { | ||
12 | Removed int `json:"removed,omitempty"` | 14 | Removed int `json:"removed,omitempty"` |
13 | } | 15 | } |
14 | 16 | ||
17 | +// 查询生产线 | ||
18 | +func (productLine *ProductLine) FindSection(sectionId int) (*ProductSection, error) { | ||
19 | + for i := range productLine.ProductSections { | ||
20 | + item := productLine.ProductSections[i] | ||
21 | + if item.SectionId == sectionId { | ||
22 | + return item, nil | ||
23 | + } | ||
24 | + } | ||
25 | + return nil, fmt.Errorf("工段不存在") | ||
26 | +} | ||
27 | + | ||
15 | func (productLine *ProductLine) GetProductSections(removed int) []*ProductSection { | 28 | func (productLine *ProductLine) GetProductSections(removed int) []*ProductSection { |
16 | var result = make([]*ProductSection, 0) | 29 | var result = make([]*ProductSection, 0) |
17 | for i := range productLine.ProductSections { | 30 | for i := range productLine.ProductSections { |
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | -import "time" | 3 | +import ( |
4 | + "errors" | ||
5 | + "time" | ||
6 | +) | ||
4 | 7 | ||
5 | const ( | 8 | const ( |
6 | PlanOnline = 1 // 计划上线 | 9 | PlanOnline = 1 // 计划上线 |
@@ -60,119 +63,47 @@ func (productPlan *ProductPlan) Identify() interface{} { | @@ -60,119 +63,47 @@ func (productPlan *ProductPlan) Identify() interface{} { | ||
60 | } | 63 | } |
61 | 64 | ||
62 | func (productPlan *ProductPlan) Update(data map[string]interface{}) error { | 65 | func (productPlan *ProductPlan) Update(data map[string]interface{}) error { |
63 | - //if productPlanId, ok := data["productPlanId"]; ok { | ||
64 | - // productPlan.ProductPlanId = productPlanId.(int) | ||
65 | - //} | ||
66 | - //if companyId, ok := data["companyId"]; ok { | ||
67 | - // productPlan.CompanyId = companyId.(int) | ||
68 | - //} | ||
69 | - //if orgId, ok := data["orgId"]; ok { | ||
70 | - // productPlan.OrgId = orgId.(int) | ||
71 | - //} | ||
72 | //if batchNumber, ok := data["batchNumber"]; ok { | 66 | //if batchNumber, ok := data["batchNumber"]; ok { |
73 | // productPlan.BatchNumber = batchNumber.(string) | 67 | // productPlan.BatchNumber = batchNumber.(string) |
74 | //} | 68 | //} |
75 | - //if productDate, ok := data["productDate"]; ok { | ||
76 | - // productPlan.ProductDate = productDate.(time.Time) | ||
77 | - //} | ||
78 | - //if companyId, ok := data["companyId"]; ok { | ||
79 | - // productPlan.Workshop.CompanyId = companyId.(int) | ||
80 | - //} | ||
81 | - //if orgId, ok := data["orgId"]; ok { | ||
82 | - // productPlan.Workshop.OrgId = orgId.(int) | ||
83 | - //} | ||
84 | - //if workshopId, ok := data["workshopId"]; ok { | ||
85 | - // productPlan.Workshop.WorkshopId = workshopId.(int) | ||
86 | - //} | ||
87 | - //if workshopName, ok := data["workshopName"]; ok { | ||
88 | - // productPlan.Workshop.WorkshopName = workshopName.(string) | ||
89 | - //} | ||
90 | - //if userId, ok := data["userId"]; ok { | ||
91 | - // productPlan.Workshop.Principal.UserId = userId.(int) | ||
92 | - //} | ||
93 | - //if userName, ok := data["userName"]; ok { | ||
94 | - // productPlan.Workshop.Principal.UserName = userName.(string) | ||
95 | - //} | ||
96 | - //if employeeType, ok := data["employeeType"]; ok { | ||
97 | - // productPlan.Workshop.Principal.EmployeeType = employeeType.(int) | ||
98 | - //} | ||
99 | - //if icCardNumber, ok := data["icCardNumber"]; ok { | ||
100 | - // productPlan.Workshop.Principal.IcCardNumber = icCardNumber.(string) | ||
101 | - //} | ||
102 | - //if avatar, ok := data["avatar"]; ok { | ||
103 | - // productPlan.Workshop.Principal.Avatar = avatar.(string) | ||
104 | - //} | ||
105 | - //if phone, ok := data["phone"]; ok { | ||
106 | - // productPlan.Workshop.Principal.Phone = phone.(string) | ||
107 | - //} | ||
108 | - //if productLines, ok := data["productLines"]; ok { | ||
109 | - // productPlan.Workshop.ProductLines = productLines.(array) | ||
110 | - //} | ||
111 | - //if createdAt, ok := data["createdAt"]; ok { | ||
112 | - // productPlan.Workshop.CreatedAt = createdAt.(time.Time) | ||
113 | - //} | ||
114 | - //if updatedAt, ok := data["updatedAt"]; ok { | ||
115 | - // productPlan.Workshop.UpdatedAt = updatedAt.(time.Time) | ||
116 | - //} | ||
117 | - //if deletedAt, ok := data["deletedAt"]; ok { | ||
118 | - // productPlan.Workshop.DeletedAt = deletedAt.(time.Time) | ||
119 | - //} | ||
120 | - //if workOn, ok := data["workOn"]; ok { | ||
121 | - // productPlan.WorkOn = workOn.(int) | ||
122 | - //} | ||
123 | - //if machine, ok := data["machine"]; ok { | ||
124 | - // productPlan.Machine = machine.(string) | ||
125 | - //} | ||
126 | - //if planProductName, ok := data["planProductName"]; ok { | ||
127 | - // productPlan.PlanProductName = planProductName.(string) | ||
128 | - //} | ||
129 | - //if quantity, ok := data["quantity"]; ok { | ||
130 | - // productPlan.PlanDevoted.Quantity = quantity.(float64) | ||
131 | - //} | ||
132 | - //if unit, ok := data["unit"]; ok { | ||
133 | - // productPlan.PlanDevoted.Unit = unit.(string) | ||
134 | - //} | ||
135 | - //if unitWeight, ok := data["unitWeight"]; ok { | ||
136 | - // productPlan.PlanDevoted.UnitWeight = unitWeight.(float64) | ||
137 | - //} | ||
138 | - //if weight, ok := data["weight"]; ok { | ||
139 | - // productPlan.PlanDevoted.Weight = weight.(float64) | ||
140 | - //} | ||
141 | - //if planStatus, ok := data["planStatus"]; ok { | ||
142 | - // productPlan.PlanStatus = planStatus.(int) | ||
143 | - //} | ||
144 | - //if workStationId, ok := data["workStationId"]; ok { | ||
145 | - // productPlan.WorkStation.WorkStationId = workStationId.(string) | ||
146 | - //} | ||
147 | - //if workshopId, ok := data["workshopId"]; ok { | ||
148 | - // productPlan.WorkStation.WorkshopId = workshopId.(int) | ||
149 | - //} | ||
150 | - //if workshopName, ok := data["workshopName"]; ok { | ||
151 | - // productPlan.WorkStation.WorkshopName = workshopName.(string) | ||
152 | - //} | ||
153 | - //if lineId, ok := data["lineId"]; ok { | ||
154 | - // productPlan.WorkStation.LineId = lineId.(int) | ||
155 | - //} | ||
156 | - //if lineName, ok := data["lineName"]; ok { | ||
157 | - // productPlan.WorkStation.LineName = lineName.(string) | ||
158 | - //} | ||
159 | - //if sectionId, ok := data["sectionId"]; ok { | ||
160 | - // productPlan.WorkStation.SectionId = sectionId.(int) | ||
161 | - //} | ||
162 | - //if sectionName, ok := data["sectionName"]; ok { | ||
163 | - // productPlan.WorkStation.SectionName = sectionName.(string) | ||
164 | - //} | ||
165 | - //if remark, ok := data["remark"]; ok { | ||
166 | - // productPlan.Remark = remark.(string) | ||
167 | - //} | ||
168 | - //if createdAt, ok := data["createdAt"]; ok { | ||
169 | - // productPlan.CreatedAt = createdAt.(time.Time) | ||
170 | - //} | ||
171 | - //if updatedAt, ok := data["updatedAt"]; ok { | ||
172 | - // productPlan.UpdatedAt = updatedAt.(time.Time) | ||
173 | - //} | ||
174 | - //if deletedAt, ok := data["deletedAt"]; ok { | ||
175 | - // productPlan.DeletedAt = deletedAt.(time.Time) | ||
176 | - //} | 69 | + if productDate, ok := data["productDateTime"]; ok { |
70 | + productPlan.ProductDate = productDate.(time.Time) | ||
71 | + } | ||
72 | + if workOn, ok := data["workOn"]; ok { | ||
73 | + productPlan.WorkOn = workOn.(int) | ||
74 | + } | ||
75 | + if machine, ok := data["machine"]; ok { | ||
76 | + productPlan.Machine = machine.(string) | ||
77 | + } | ||
78 | + if planProductName, ok := data["planProductName"]; ok { | ||
79 | + productPlan.PlanProductName = planProductName.(string) | ||
80 | + } | ||
81 | + if quantity, ok := data["quantity"]; ok { | ||
82 | + productPlan.PlanDevoted.Quantity = quantity.(float64) | ||
83 | + } | ||
84 | + if unit, ok := data["unit"]; ok { | ||
85 | + productPlan.PlanDevoted.Unit = unit.(string) | ||
86 | + } | ||
87 | + if weight, ok := data["weight"]; ok { | ||
88 | + productPlan.PlanDevoted.Weight = weight.(float64) | ||
89 | + } | ||
90 | + if remark, ok := data["remark"]; ok { | ||
91 | + productPlan.Remark = remark.(string) | ||
92 | + } | ||
93 | + productPlan.UpdatedAt = time.Now() | ||
94 | + return nil | ||
95 | +} | ||
96 | + | ||
97 | +func (productPlan *ProductPlan) ChangeStatus(status int) error { | ||
98 | + if productPlan.PlanStatus == status && productPlan.PlanStatus == PlanOnline { | ||
99 | + return errors.New("计划已经上线") | ||
100 | + } | ||
101 | + if productPlan.PlanStatus == status && productPlan.PlanStatus == PlanOffline { | ||
102 | + return errors.New("计划已经下线") | ||
103 | + } | ||
104 | + if !(productPlan.PlanStatus == PlanOnline || productPlan.PlanStatus == PlanOffline) { | ||
105 | + return errors.New("计划状态有误") | ||
106 | + } | ||
107 | + productPlan.PlanStatus = status | ||
177 | return nil | 108 | return nil |
178 | } | 109 | } |
@@ -9,3 +9,16 @@ type ProductSection struct { | @@ -9,3 +9,16 @@ type ProductSection struct { | ||
9 | // 已删除标识 1:正常 2:已删除 | 9 | // 已删除标识 1:正常 2:已删除 |
10 | Removed int `json:"removed,omitempty"` | 10 | Removed int `json:"removed,omitempty"` |
11 | } | 11 | } |
12 | + | ||
13 | +func (m *ProductSection) CloneSample() *ProductSection { | ||
14 | + return &ProductSection{ | ||
15 | + SectionId: m.SectionId, | ||
16 | + SectionName: m.SectionName, | ||
17 | + } | ||
18 | +} | ||
19 | + | ||
20 | +type ProductSections []*ProductSection | ||
21 | + | ||
22 | +func (ms ProductSections) Len() int { return len(ms) } | ||
23 | +func (ms ProductSections) Less(i, j int) bool { return ms[i].SectionId < ms[j].SectionId } | ||
24 | +func (ms ProductSections) Swap(i, j int) { ms[i], ms[j] = ms[j], ms[i] } |
@@ -31,6 +31,6 @@ func NewWorkStation(w *Workshop, l *ProductLine, s *ProductSection) *WorkStation | @@ -31,6 +31,6 @@ func NewWorkStation(w *Workshop, l *ProductLine, s *ProductSection) *WorkStation | ||
31 | LineName: l.LineName, | 31 | LineName: l.LineName, |
32 | SectionId: s.SectionId, | 32 | SectionId: s.SectionId, |
33 | SectionName: s.SectionName, | 33 | SectionName: s.SectionName, |
34 | - Principal: w.Principal, | 34 | + //Principal: w.Principal, |
35 | } | 35 | } |
36 | } | 36 | } |
@@ -2,10 +2,13 @@ package domain | @@ -2,10 +2,13 @@ package domain | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "sort" | ||
5 | "time" | 6 | "time" |
6 | ) | 7 | ) |
7 | 8 | ||
8 | const ( | 9 | const ( |
10 | + // 所有 | ||
11 | + All = 0 | ||
9 | // 未删除 | 12 | // 未删除 |
10 | NotDeleted = 1 | 13 | NotDeleted = 1 |
11 | // 已删除 | 14 | // 已删除 |
@@ -220,6 +223,36 @@ func (workshop *Workshop) GetProductLines(removed int) []*ProductLine { | @@ -220,6 +223,36 @@ func (workshop *Workshop) GetProductLines(removed int) []*ProductLine { | ||
220 | return result | 223 | return result |
221 | } | 224 | } |
222 | 225 | ||
226 | +func (workshop *Workshop) AllProductSections(removed int) []*ProductSection { | ||
227 | + var result ProductSections = make([]*ProductSection, 0) | ||
228 | + lines := workshop.GetProductLines(removed) | ||
229 | + for i := range lines { | ||
230 | + for j := range lines[i].ProductSections { | ||
231 | + section := lines[i].ProductSections[j] | ||
232 | + if removed > 0 && section.Removed != removed { | ||
233 | + continue | ||
234 | + } | ||
235 | + result = append(result, section.CloneSample()) | ||
236 | + } | ||
237 | + } | ||
238 | + | ||
239 | + sort.Stable(result) | ||
240 | + return result | ||
241 | +} | ||
242 | + | ||
243 | +// 查询生产线 | ||
244 | +func (workshop *Workshop) FindSectionById(sectionId int) (*ProductLine, *ProductSection, error) { | ||
245 | + lines := workshop.GetProductLines(0) | ||
246 | + for k := range lines { | ||
247 | + line := lines[k] | ||
248 | + section, _ := line.FindSection(sectionId) | ||
249 | + if section != nil { | ||
250 | + return line, section, nil | ||
251 | + } | ||
252 | + } | ||
253 | + return nil, nil, fmt.Errorf("工段不存在") | ||
254 | +} | ||
255 | + | ||
223 | func (workshop *Workshop) CloneSample() *Workshop { | 256 | func (workshop *Workshop) CloneSample() *Workshop { |
224 | return &Workshop{ | 257 | return &Workshop{ |
225 | WorkshopId: workshop.WorkshopId, | 258 | WorkshopId: workshop.WorkshopId, |
@@ -172,6 +172,17 @@ func (repository *ProductPlanRepository) Find(queryOptions map[string]interface{ | @@ -172,6 +172,17 @@ func (repository *ProductPlanRepository) Find(queryOptions map[string]interface{ | ||
172 | var productPlanModels []*models.ProductPlan | 172 | var productPlanModels []*models.ProductPlan |
173 | productPlans := make([]*domain.ProductPlan, 0) | 173 | productPlans := make([]*domain.ProductPlan, 0) |
174 | query := sqlbuilder.BuildQuery(tx.Model(&productPlanModels), queryOptions) | 174 | query := sqlbuilder.BuildQuery(tx.Model(&productPlanModels), queryOptions) |
175 | + query.SetWhereByQueryOption("company_id = ?", "companyId") | ||
176 | + query.SetWhereByQueryOption("org_id = ?", "orgId") | ||
177 | + query.SetWhereByQueryOption("batch_number=?", "batchNumber") | ||
178 | + | ||
179 | + if v, ok := queryOptions["batchNumber"]; ok && len(v.(string)) > 0 { | ||
180 | + query.Where(fmt.Sprintf(`batch_number like '%%%v%%'`, v)) | ||
181 | + } | ||
182 | + if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 { | ||
183 | + query.Where(fmt.Sprintf(`workshop->>'workshopName' like '%%%v%%'`, v)) | ||
184 | + } | ||
185 | + query.SetWhereByQueryOption("plan_status=?", "planStatus") | ||
175 | query.SetOffsetAndLimit(20) | 186 | query.SetOffsetAndLimit(20) |
176 | query.SetOrderDirect("product_plan_id", "DESC") | 187 | query.SetOrderDirect("product_plan_id", "DESC") |
177 | if count, err := query.SelectAndCount(); err != nil { | 188 | if count, err := query.SelectAndCount(); err != nil { |
@@ -86,6 +86,14 @@ func (controller *ProductPlanController) SetOnline() { | @@ -86,6 +86,14 @@ func (controller *ProductPlanController) SetOnline() { | ||
86 | controller.Response(data, err) | 86 | controller.Response(data, err) |
87 | } | 87 | } |
88 | 88 | ||
89 | +func (controller *ProductPlanController) SetOffline() { | ||
90 | + productPlanService := service.NewProductPlanService(nil) | ||
91 | + setOnlineCommand := &command.SetOfflineCommand{} | ||
92 | + Must(controller.Unmarshal(setOnlineCommand)) | ||
93 | + data, err := productPlanService.SetOffline(setOnlineCommand) | ||
94 | + controller.Response(data, err) | ||
95 | +} | ||
96 | + | ||
89 | func (controller *ProductPlanController) Switch() { | 97 | func (controller *ProductPlanController) Switch() { |
90 | productPlanService := service.NewProductPlanService(nil) | 98 | productPlanService := service.NewProductPlanService(nil) |
91 | switchCommand := &command.SwitchCommand{} | 99 | switchCommand := &command.SwitchCommand{} |
@@ -74,3 +74,11 @@ func (controller *WorkshopController) SelectorWorkshop() { | @@ -74,3 +74,11 @@ func (controller *WorkshopController) SelectorWorkshop() { | ||
74 | data, err := workshopService.SearchWorkshop(ParseOperateInfo(controller.BaseController), listWorkshopQuery) | 74 | data, err := workshopService.SearchWorkshop(ParseOperateInfo(controller.BaseController), listWorkshopQuery) |
75 | controller.Response(data, err) | 75 | controller.Response(data, err) |
76 | } | 76 | } |
77 | + | ||
78 | +func (controller *WorkshopController) SelectorWorkshopSection() { | ||
79 | + workshopService := service.NewWorkshopService(nil) | ||
80 | + getWorkshopQuery := &query.GetWorkshopQuery{} | ||
81 | + Must(controller.Unmarshal(getWorkshopQuery)) | ||
82 | + data, err := workshopService.SelectorWorkshopSection(ParseOperateInfo(controller.BaseController), getWorkshopQuery) | ||
83 | + controller.Response(data, err) | ||
84 | +} |
@@ -14,6 +14,7 @@ func init() { | @@ -14,6 +14,7 @@ func init() { | ||
14 | web.Router("/product-plans/receive-material", &controllers.ProductPlanController{}, "Post:ReceiveMaterial") | 14 | web.Router("/product-plans/receive-material", &controllers.ProductPlanController{}, "Post:ReceiveMaterial") |
15 | web.Router("/product-plans/return-material", &controllers.ProductPlanController{}, "Post:ReturnMaterial") | 15 | web.Router("/product-plans/return-material", &controllers.ProductPlanController{}, "Post:ReturnMaterial") |
16 | web.Router("/product-plans/set-online", &controllers.ProductPlanController{}, "Post:SetOnline") | 16 | web.Router("/product-plans/set-online", &controllers.ProductPlanController{}, "Post:SetOnline") |
17 | + web.Router("/product-plans/set-offline", &controllers.ProductPlanController{}, "Post:SetOffline") | ||
17 | web.Router("/product-plans/switch", &controllers.ProductPlanController{}, "Post:Switch") | 18 | web.Router("/product-plans/switch", &controllers.ProductPlanController{}, "Post:Switch") |
18 | web.Router("/product-plans/submit-product-record", &controllers.ProductPlanController{}, "Post:SubmitProductRecord") | 19 | web.Router("/product-plans/submit-product-record", &controllers.ProductPlanController{}, "Post:SubmitProductRecord") |
19 | web.Router("/product-plans/search", &controllers.ProductPlanController{}, "Post:SearchProductPlan") | 20 | web.Router("/product-plans/search", &controllers.ProductPlanController{}, "Post:SearchProductPlan") |
@@ -13,4 +13,5 @@ func init() { | @@ -13,4 +13,5 @@ func init() { | ||
13 | web.Router("/workshops/", &controllers.WorkshopController{}, "Get:ListWorkshop") | 13 | web.Router("/workshops/", &controllers.WorkshopController{}, "Get:ListWorkshop") |
14 | web.Router("/workshops/search", &controllers.WorkshopController{}, "Post:SearchWorkshop") | 14 | web.Router("/workshops/search", &controllers.WorkshopController{}, "Post:SearchWorkshop") |
15 | web.Router("/workshops/selector", &controllers.WorkshopController{}, "Post:SelectorWorkshop") | 15 | web.Router("/workshops/selector", &controllers.WorkshopController{}, "Post:SelectorWorkshop") |
16 | + web.Router("/workshops/sections-selector", &controllers.WorkshopController{}, "Post:SelectorWorkshopSection") | ||
16 | } | 17 | } |
-
请 注册 或 登录 后发表评论