|
@@ -2,7 +2,9 @@ package syncdata |
|
@@ -2,7 +2,9 @@ package syncdata |
|
2
|
|
2
|
|
|
3
|
import (
|
3
|
import (
|
|
4
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
|
4
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
|
|
|
|
5
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
5
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
|
|
|
7
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
|
|
6
|
"strconv"
|
8
|
"strconv"
|
|
7
|
"strings"
|
9
|
"strings"
|
|
8
|
"time"
|
10
|
"time"
|
|
@@ -437,19 +439,110 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error { |
|
@@ -437,19 +439,110 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error { |
|
437
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
439
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
438
|
}
|
440
|
}
|
|
439
|
|
441
|
|
|
|
|
442
|
+ //var userService = domainService.NewUserService()
|
|
|
|
443
|
+ //org, err := userService.Organization(constant.MANUFACTURE_DEFAULT_ORGID)
|
|
|
|
444
|
+ //if err != nil {
|
|
|
|
445
|
+ // return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
|
446
|
+ //}
|
|
|
|
447
|
+
|
|
|
|
448
|
+ //同步ProductPlan 表数据
|
|
|
|
449
|
+ //err = prdMoDao.SyncDataProductPlan(version, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, org.OrgName)
|
|
|
|
450
|
+ //if err != nil {
|
|
|
|
451
|
+ // return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
|
452
|
+ //}
|
|
|
|
453
|
+ if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
|
454
|
+ return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
|
455
|
+ }
|
|
|
|
456
|
+ return nil
|
|
|
|
457
|
+}
|
|
|
|
458
|
+
|
|
|
|
459
|
+// 同步生产计划
|
|
|
|
460
|
+func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.TransactionContext) error {
|
|
|
|
461
|
+ /*
|
|
|
|
462
|
+ 1.获取更新时间
|
|
|
|
463
|
+ 2.获取prd_mo_k3cloud从更新时间开始的有变化的数据
|
|
|
|
464
|
+ 3.查询是否有重复的批次号
|
|
|
|
465
|
+ 4.有进行更新,其他的插入
|
|
|
|
466
|
+ */
|
|
|
|
467
|
+ lastTime, err := redis.GetLastK3CloudFetchTime()
|
|
|
|
468
|
+ if err != nil {
|
|
|
|
469
|
+ return err
|
|
|
|
470
|
+ }
|
|
|
|
471
|
+ prdMoK3cloudDao, _ := dao.NewPrdMoK3cloudDao(ptr)
|
|
|
|
472
|
+ records, err := prdMoK3cloudDao.GetLatestData(lastTime)
|
|
|
|
473
|
+ if err != nil {
|
|
|
|
474
|
+ return err
|
|
|
|
475
|
+ }
|
|
440
|
var userService = domainService.NewUserService()
|
476
|
var userService = domainService.NewUserService()
|
|
441
|
org, err := userService.Organization(constant.MANUFACTURE_DEFAULT_ORGID)
|
477
|
org, err := userService.Organization(constant.MANUFACTURE_DEFAULT_ORGID)
|
|
442
|
if err != nil {
|
478
|
if err != nil {
|
|
443
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
479
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
444
|
}
|
480
|
}
|
|
|
|
481
|
+ var (
|
|
|
|
482
|
+ cid = constant.MANUFACTURE_DEFAULT_COMPANYID
|
|
|
|
483
|
+ oid = constant.MANUFACTURE_DEFAULT_ORGID
|
|
|
|
484
|
+ workshop *domain.Workshop
|
|
|
|
485
|
+ exists bool
|
|
|
|
486
|
+ )
|
|
445
|
|
487
|
|
|
446
|
- //同步ProductPlan 表数据
|
|
|
|
447
|
- err = prdMoDao.SyncDataProductPlan(version, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, org.OrgName)
|
|
|
|
448
|
- if err != nil {
|
|
|
|
449
|
- return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
|
450
|
- }
|
|
|
|
451
|
- if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
|
452
|
- return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
488
|
+ workshops, _ := factory.FastPgWorkshops(ptr, cid)
|
|
|
|
489
|
+
|
|
|
|
490
|
+ productPlanRepository, _, _ := factory.FastPgProductPlan(ptr, 0)
|
|
|
|
491
|
+ productRepository, _, _ := factory.FastPgProduct(ptr, 0)
|
|
|
|
492
|
+ for _, v := range records {
|
|
|
|
493
|
+ if workshop, exists = workshops.ExistsWorkshops(v.WorkShopName); !exists {
|
|
|
|
494
|
+ continue
|
|
|
|
495
|
+ }
|
|
|
|
496
|
+ var plan *domain.ProductPlan
|
|
|
|
497
|
+ var product *domain.Product
|
|
|
|
498
|
+
|
|
|
|
499
|
+ // 产品信息
|
|
|
|
500
|
+ product, err = productRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "productCode": v.MaterialNumber})
|
|
|
|
501
|
+ if err != nil || err == domain.ErrorNotFound {
|
|
|
|
502
|
+ continue
|
|
|
|
503
|
+ }
|
|
|
|
504
|
+ // 计划信息
|
|
|
|
505
|
+ plan, err = productPlanRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "batchNumber": v.BillNo})
|
|
|
|
506
|
+ if err == nil && plan != nil {
|
|
|
|
507
|
+ plan.UpdatedAt = time.Now()
|
|
|
|
508
|
+ continue
|
|
|
|
509
|
+ }
|
|
|
|
510
|
+ if err == domain.ErrorNotFound {
|
|
|
|
511
|
+ plan = &domain.ProductPlan{
|
|
|
|
512
|
+ CompanyId: cid,
|
|
|
|
513
|
+ OrgId: oid,
|
|
|
|
514
|
+ BatchNumber: v.BillNo,
|
|
|
|
515
|
+ ProductDate: v.PlanStartDate,
|
|
|
|
516
|
+ Workshop: workshop.CloneSample(),
|
|
|
|
517
|
+ WorkOn: 0,
|
|
|
|
518
|
+ Machine: "",
|
|
|
|
519
|
+ PlanStatus: domain.PlanOffline,
|
|
|
|
520
|
+ WorkStation: &domain.WorkStation{},
|
|
|
|
521
|
+ CreatedAt: time.Now(),
|
|
|
|
522
|
+ UpdatedAt: time.Now(),
|
|
|
|
523
|
+ }
|
|
|
|
524
|
+ }
|
|
|
|
525
|
+ // 更新数据
|
|
|
|
526
|
+ plan.PlanDevoted = &domain.UnitQuantity{
|
|
|
|
527
|
+ Unit: product.ProductSpec.Unit,
|
|
|
|
528
|
+ Quantity: 0,
|
|
|
|
529
|
+ Weight: product.ProductWeigh(0),
|
|
|
|
530
|
+ UnitWeight: product.ProductSpec.UnitWeight,
|
|
|
|
531
|
+ }
|
|
|
|
532
|
+ plan.Workshop = workshop.CloneSample()
|
|
|
|
533
|
+ plan.UpdatedAt = time.Now()
|
|
|
|
534
|
+ plan.Ext = domain.NewExt(org.OrgName).WithProductPlanExt(&domain.ProductPlanExt{
|
|
|
|
535
|
+ ProductId: product.ProductId,
|
|
|
|
536
|
+ ProductCode: product.ProductCode,
|
|
|
|
537
|
+ ProductName: product.ProductName,
|
|
|
|
538
|
+ DevotedUnit: "份",
|
|
|
|
539
|
+ })
|
|
|
|
540
|
+ plan.PlanProductName = product.ProductName
|
|
|
|
541
|
+ plan.Remark = v.Description
|
|
|
|
542
|
+
|
|
|
|
543
|
+ if plan, err = productPlanRepository.Save(plan); err != nil {
|
|
|
|
544
|
+ return err
|
|
|
|
545
|
+ }
|
|
453
|
}
|
546
|
}
|
|
454
|
return nil
|
547
|
return nil
|
|
455
|
} |
548
|
} |