作者 yangfu

refactor: 计划管理、生产班组、物料

@@ -159,27 +159,6 @@ func (productPlanService *ProductPlanService) ListProductPlan(listProductPlanQue @@ -159,27 +159,6 @@ func (productPlanService *ProductPlanService) ListProductPlan(listProductPlanQue
159 } 159 }
160 } 160 }
161 161
162 -// 领料  
163 -func (productPlanService *ProductPlanService) ReceiveMaterial(receiveMaterialCommand *command.ReceiveMaterialCommand) (interface{}, error) {  
164 - if err := receiveMaterialCommand.ValidateCommand(); err != nil {  
165 - return nil, application.ThrowError(application.ARG_ERROR, err.Error())  
166 - }  
167 - transactionContext, err := factory.CreateTransactionContext(nil)  
168 - if err != nil {  
169 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
170 - }  
171 - if err := transactionContext.StartTransaction(); err != nil {  
172 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
173 - }  
174 - defer func() {  
175 - transactionContext.RollbackTransaction()  
176 - }()  
177 - if err := transactionContext.CommitTransaction(); err != nil {  
178 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
179 - }  
180 - return nil, nil  
181 -}  
182 -  
183 // 移除生产计划服务 162 // 移除生产计划服务
184 func (productPlanService *ProductPlanService) RemoveProductPlan(removeProductPlanCommand *command.RemoveProductPlanCommand) (interface{}, error) { 163 func (productPlanService *ProductPlanService) RemoveProductPlan(removeProductPlanCommand *command.RemoveProductPlanCommand) (interface{}, error) {
185 if err := removeProductPlanCommand.ValidateCommand(); err != nil { 164 if err := removeProductPlanCommand.ValidateCommand(); err != nil {
@@ -220,9 +199,9 @@ func (productPlanService *ProductPlanService) RemoveProductPlan(removeProductPla @@ -220,9 +199,9 @@ func (productPlanService *ProductPlanService) RemoveProductPlan(removeProductPla
220 } 199 }
221 } 200 }
222 201
223 -// 退料  
224 -func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialCommand *command.ReturnMaterialCommand) (interface{}, error) {  
225 - if err := returnMaterialCommand.ValidateCommand(); err != nil { 202 +// 更新生产计划服务
  203 +func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.UpdateProductPlanCommand) (interface{}, error) {
  204 + if err := cmd.ValidateCommand(); err != nil {
226 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 205 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
227 } 206 }
228 transactionContext, err := factory.CreateTransactionContext(nil) 207 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -235,10 +214,79 @@ func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialComma @@ -235,10 +214,79 @@ func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialComma
235 defer func() { 214 defer func() {
236 transactionContext.RollbackTransaction() 215 transactionContext.RollbackTransaction()
237 }() 216 }()
  217 + var productPlanRepository domain.ProductPlanRepository
  218 + var productPlan *domain.ProductPlan
  219 + productPlanRepository, productPlan, err = factory.FastPgProductPlan(transactionContext, cmd.ProductPlanId)
  220 + if err != nil {
  221 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  222 + }
  223 +
  224 + //if productPlan.Workshop.WorkshopId != cmd.WorkshopId{
  225 + // // 检查批次号是否有重复的
  226 + // if item, err := productPlanRepository.FindOne(map[string]interface{}{"companyId": cmd.CompanyId, "orgId": cmd.OrgId, "batchNumber": cmd.BatchNumber}); err == nil && item != nil {
  227 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "批次号重复")
  228 + // }
  229 + //}
  230 +
  231 + _, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId)
  232 + if err != nil {
  233 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  234 + }
  235 + productPlan.Workshop = workshop.CloneSample()
  236 +
  237 + if err := productPlan.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
  238 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  239 + }
  240 + if productPlan, err = productPlanRepository.Save(productPlan); err != nil {
  241 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  242 + }
  243 +
238 if err := transactionContext.CommitTransaction(); err != nil { 244 if err := transactionContext.CommitTransaction(); err != nil {
239 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 245 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
240 } 246 }
241 - return nil, nil 247 +
  248 + result := &dto.ProductPlanDto{}
  249 + return result.LoadDto(productPlan, cmd.OrgId), nil
  250 +}
  251 +
  252 +// 搜索生产计划服务列表
  253 +func (productPlanService *ProductPlanService) SearchProductPlan(operateInfo *domain.OperateInfo, cmd *query.SearchProductPlanQuery) (int64, interface{}, error) {
  254 + if err := cmd.ValidateQuery(); err != nil {
  255 + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
  256 + }
  257 + transactionContext, err := factory.CreateTransactionContext(nil)
  258 + if err != nil {
  259 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  260 + }
  261 + if err := transactionContext.StartTransaction(); err != nil {
  262 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  263 + }
  264 + defer func() {
  265 + transactionContext.RollbackTransaction()
  266 + }()
  267 + var productPlanRepository domain.ProductPlanRepository
  268 + if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
  269 + "transactionContext": transactionContext,
  270 + }); err != nil {
  271 + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  272 + } else {
  273 + productPlanRepository = value
  274 + }
  275 + count, productPlans, err := productPlanRepository.Find(utils.ObjectToMap(cmd))
  276 + if err != nil {
  277 + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  278 + }
  279 + if err := transactionContext.CommitTransaction(); err != nil {
  280 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  281 + }
  282 + var result = make([]*dto.ProductPlanDto, 0)
  283 + for i := range productPlans {
  284 + item := productPlans[i]
  285 + newItem := &dto.ProductPlanDto{}
  286 + newItem.LoadDto(item, operateInfo.OrgId)
  287 + result = append(result, newItem)
  288 + }
  289 + return count, result, nil
242 } 290 }
243 291
244 // 计划下线 292 // 计划下线
@@ -331,27 +379,6 @@ func (productPlanService *ProductPlanService) SetOnline(cmd *command.SetOnlineCo @@ -331,27 +379,6 @@ func (productPlanService *ProductPlanService) SetOnline(cmd *command.SetOnlineCo
331 return productPlan, nil 379 return productPlan, nil
332 } 380 }
333 381
334 -// 提交成品记录 (成品 二级品)  
335 -func (productPlanService *ProductPlanService) SubmitProductRecord(submitProductRecordCommand *command.SubmitProductRecordCommand) (interface{}, error) {  
336 - if err := submitProductRecordCommand.ValidateCommand(); err != nil {  
337 - return nil, application.ThrowError(application.ARG_ERROR, err.Error())  
338 - }  
339 - transactionContext, err := factory.CreateTransactionContext(nil)  
340 - if err != nil {  
341 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
342 - }  
343 - if err := transactionContext.StartTransaction(); err != nil {  
344 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
345 - }  
346 - defer func() {  
347 - transactionContext.RollbackTransaction()  
348 - }()  
349 - if err := transactionContext.CommitTransaction(); err != nil {  
350 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
351 - }  
352 - return nil, nil  
353 -}  
354 -  
355 // 换单 382 // 换单
356 func (productPlanService *ProductPlanService) Exchange(switchCommand *command.SwitchCommand) (interface{}, error) { 383 func (productPlanService *ProductPlanService) Exchange(switchCommand *command.SwitchCommand) (interface{}, error) {
357 if err := switchCommand.ValidateCommand(); err != nil { 384 if err := switchCommand.ValidateCommand(); err != nil {
@@ -407,9 +434,9 @@ func (productPlanService *ProductPlanService) Exchange(switchCommand *command.Sw @@ -407,9 +434,9 @@ func (productPlanService *ProductPlanService) Exchange(switchCommand *command.Sw
407 return struct{}{}, nil 434 return struct{}{}, nil
408 } 435 }
409 436
410 -// 更新生产计划服务  
411 -func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.UpdateProductPlanCommand) (interface{}, error) {  
412 - if err := cmd.ValidateCommand(); err != nil { 437 +// 领料
  438 +func (productPlanService *ProductPlanService) ReceiveMaterial(receiveMaterialCommand *command.ReceiveMaterialCommand) (interface{}, error) {
  439 + if err := receiveMaterialCommand.ValidateCommand(); err != nil {
413 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 440 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
414 } 441 }
415 transactionContext, err := factory.CreateTransactionContext(nil) 442 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -422,79 +449,52 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.Upd @@ -422,79 +449,52 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.Upd
422 defer func() { 449 defer func() {
423 transactionContext.RollbackTransaction() 450 transactionContext.RollbackTransaction()
424 }() 451 }()
425 - var productPlanRepository domain.ProductPlanRepository  
426 - var productPlan *domain.ProductPlan  
427 - productPlanRepository, productPlan, err = factory.FastPgProductPlan(transactionContext, cmd.ProductPlanId)  
428 - if err != nil {  
429 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 452 + if err := transactionContext.CommitTransaction(); err != nil {
  453 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
430 } 454 }
  455 + return nil, nil
  456 +}
431 457
432 - //if productPlan.Workshop.WorkshopId != cmd.WorkshopId{  
433 - // // 检查批次号是否有重复的  
434 - // if item, err := productPlanRepository.FindOne(map[string]interface{}{"companyId": cmd.CompanyId, "orgId": cmd.OrgId, "batchNumber": cmd.BatchNumber}); err == nil && item != nil {  
435 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "批次号重复")  
436 - // }  
437 - //}  
438 -  
439 - _, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId)  
440 - if err != nil {  
441 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 458 +// 退料
  459 +func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialCommand *command.ReturnMaterialCommand) (interface{}, error) {
  460 + if err := returnMaterialCommand.ValidateCommand(); err != nil {
  461 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
442 } 462 }
443 - productPlan.Workshop = workshop.CloneSample()  
444 -  
445 - if err := productPlan.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {  
446 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 463 + transactionContext, err := factory.CreateTransactionContext(nil)
  464 + if err != nil {
  465 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
447 } 466 }
448 - if productPlan, err = productPlanRepository.Save(productPlan); err != nil {  
449 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 467 + if err := transactionContext.StartTransaction(); err != nil {
  468 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
450 } 469 }
451 - 470 + defer func() {
  471 + transactionContext.RollbackTransaction()
  472 + }()
452 if err := transactionContext.CommitTransaction(); err != nil { 473 if err := transactionContext.CommitTransaction(); err != nil {
453 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 474 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
454 } 475 }
455 -  
456 - result := &dto.ProductPlanDto{}  
457 - return result.LoadDto(productPlan, cmd.OrgId), nil 476 + return nil, nil
458 } 477 }
459 478
460 -// 搜索生产计划服务列表  
461 -func (productPlanService *ProductPlanService) SearchProductPlan(operateInfo *domain.OperateInfo, cmd *query.SearchProductPlanQuery) (int64, interface{}, error) {  
462 - if err := cmd.ValidateQuery(); err != nil {  
463 - return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error()) 479 +// 提交成品记录 (成品 二级品)
  480 +func (productPlanService *ProductPlanService) SubmitProductRecord(submitProductRecordCommand *command.SubmitProductRecordCommand) (interface{}, error) {
  481 + if err := submitProductRecordCommand.ValidateCommand(); err != nil {
  482 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
464 } 483 }
465 transactionContext, err := factory.CreateTransactionContext(nil) 484 transactionContext, err := factory.CreateTransactionContext(nil)
466 if err != nil { 485 if err != nil {
467 - return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 486 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
468 } 487 }
469 if err := transactionContext.StartTransaction(); err != nil { 488 if err := transactionContext.StartTransaction(); err != nil {
470 - return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 489 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
471 } 490 }
472 defer func() { 491 defer func() {
473 transactionContext.RollbackTransaction() 492 transactionContext.RollbackTransaction()
474 }() 493 }()
475 - var productPlanRepository domain.ProductPlanRepository  
476 - if value, err := factory.CreateProductPlanRepository(map[string]interface{}{  
477 - "transactionContext": transactionContext,  
478 - }); err != nil {  
479 - return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
480 - } else {  
481 - productPlanRepository = value  
482 - }  
483 - count, productPlans, err := productPlanRepository.Find(utils.ObjectToMap(cmd))  
484 - if err != nil {  
485 - return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
486 - }  
487 if err := transactionContext.CommitTransaction(); err != nil { 494 if err := transactionContext.CommitTransaction(); err != nil {
488 - return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
489 - }  
490 - var result = make([]*dto.ProductPlanDto, 0)  
491 - for i := range productPlans {  
492 - item := productPlans[i]  
493 - newItem := &dto.ProductPlanDto{}  
494 - newItem.LoadDto(item, operateInfo.OrgId)  
495 - result = append(result, newItem) 495 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
496 } 496 }
497 - return count, result, nil 497 + return nil, nil
498 } 498 }
499 499
500 func NewProductPlanService(options map[string]interface{}) *ProductPlanService { 500 func NewProductPlanService(options map[string]interface{}) *ProductPlanService {
@@ -6,10 +6,10 @@ import "time" @@ -6,10 +6,10 @@ import "time"
6 type ProductAttendanceRecord struct { 6 type ProductAttendanceRecord struct {
7 // 考勤记录ID 7 // 考勤记录ID
8 ProductAttendanceId int `json:"productAttendanceId,omitempty"` 8 ProductAttendanceId int `json:"productAttendanceId,omitempty"`
  9 + // 企业id
  10 + CompanyId int `json:"companyId,omitempty"`
9 // 组织ID 11 // 组织ID
10 OrgId int `json:"orgId,omitempty"` 12 OrgId int `json:"orgId,omitempty"`
11 - // 产品ID  
12 - ProductId int `json:"productId,omitempty"`  
13 // 考勤类型 1.正常 2.支援 13 // 考勤类型 1.正常 2.支援
14 AttendanceType int `json:"attendanceType,omitempty"` 14 AttendanceType int `json:"attendanceType,omitempty"`
15 // 生产工人 15 // 生产工人
@@ -57,9 +57,6 @@ func (productAttendanceRecord *ProductAttendanceRecord) Update(data map[string]i @@ -57,9 +57,6 @@ func (productAttendanceRecord *ProductAttendanceRecord) Update(data map[string]i
57 if orgId, ok := data["orgId"]; ok { 57 if orgId, ok := data["orgId"]; ok {
58 productAttendanceRecord.OrgId = orgId.(int) 58 productAttendanceRecord.OrgId = orgId.(int)
59 } 59 }
60 - if productId, ok := data["productId"]; ok {  
61 - productAttendanceRecord.ProductId = productId.(int)  
62 - }  
63 if attendanceType, ok := data["attendanceType"]; ok { 60 if attendanceType, ok := data["attendanceType"]; ok {
64 productAttendanceRecord.AttendanceType = attendanceType.(int) 61 productAttendanceRecord.AttendanceType = attendanceType.(int)
65 } 62 }
@@ -13,8 +13,6 @@ type ProductAttendanceRecord struct { @@ -13,8 +13,6 @@ type ProductAttendanceRecord struct {
13 CompanyId int `comment:"企业id"` 13 CompanyId int `comment:"企业id"`
14 // 组织ID 14 // 组织ID
15 OrgId int `comment:"组织ID"` 15 OrgId int `comment:"组织ID"`
16 - // 产品ID  
17 - ProductId int `comment:"产品ID"`  
18 // 考勤类型 1.正常 2.支援 16 // 考勤类型 1.正常 2.支援
19 AttendanceType int `comment:"考勤类型 1.正常 2.支援"` 17 AttendanceType int `comment:"考勤类型 1.正常 2.支援"`
20 // 生产工人 18 // 生产工人
@@ -9,7 +9,7 @@ func TransformToProductAttendanceRecordDomainModelFromPgModels(productAttendance @@ -9,7 +9,7 @@ func TransformToProductAttendanceRecordDomainModelFromPgModels(productAttendance
9 return &domain.ProductAttendanceRecord{ 9 return &domain.ProductAttendanceRecord{
10 ProductAttendanceId: productAttendanceRecordModel.ProductAttendanceId, 10 ProductAttendanceId: productAttendanceRecordModel.ProductAttendanceId,
11 OrgId: productAttendanceRecordModel.OrgId, 11 OrgId: productAttendanceRecordModel.OrgId,
12 - ProductId: productAttendanceRecordModel.ProductId, 12 + CompanyId: productAttendanceRecordModel.CompanyId,
13 AttendanceType: productAttendanceRecordModel.AttendanceType, 13 AttendanceType: productAttendanceRecordModel.AttendanceType,
14 ProductWorker: productAttendanceRecordModel.ProductWorker, 14 ProductWorker: productAttendanceRecordModel.ProductWorker,
15 WorkStation: productAttendanceRecordModel.WorkStation, 15 WorkStation: productAttendanceRecordModel.WorkStation,