...
|
...
|
@@ -2,7 +2,9 @@ package syncdata |
|
|
|
|
|
import (
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
...
|
...
|
@@ -437,19 +439,110 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error { |
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
//var userService = domainService.NewUserService()
|
|
|
//org, err := userService.Organization(constant.MANUFACTURE_DEFAULT_ORGID)
|
|
|
//if err != nil {
|
|
|
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//}
|
|
|
|
|
|
//同步ProductPlan 表数据
|
|
|
//err = prdMoDao.SyncDataProductPlan(version, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, org.OrgName)
|
|
|
//if err != nil {
|
|
|
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//}
|
|
|
if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 同步生产计划
|
|
|
func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.TransactionContext) error {
|
|
|
/*
|
|
|
1.获取更新时间
|
|
|
2.获取prd_mo_k3cloud从更新时间开始的有变化的数据
|
|
|
3.查询是否有重复的批次号
|
|
|
4.有进行更新,其他的插入
|
|
|
*/
|
|
|
lastTime, err := redis.GetLastK3CloudFetchTime()
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
prdMoK3cloudDao, _ := dao.NewPrdMoK3cloudDao(ptr)
|
|
|
records, err := prdMoK3cloudDao.GetLatestData(lastTime)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
var userService = domainService.NewUserService()
|
|
|
org, err := userService.Organization(constant.MANUFACTURE_DEFAULT_ORGID)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var (
|
|
|
cid = constant.MANUFACTURE_DEFAULT_COMPANYID
|
|
|
oid = constant.MANUFACTURE_DEFAULT_ORGID
|
|
|
workshop *domain.Workshop
|
|
|
exists bool
|
|
|
)
|
|
|
|
|
|
//同步ProductPlan 表数据
|
|
|
err = prdMoDao.SyncDataProductPlan(version, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, org.OrgName)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
workshops, _ := factory.FastPgWorkshops(ptr, cid)
|
|
|
|
|
|
productPlanRepository, _, _ := factory.FastPgProductPlan(ptr, 0)
|
|
|
productRepository, _, _ := factory.FastPgProduct(ptr, 0)
|
|
|
for _, v := range records {
|
|
|
if workshop, exists = workshops.ExistsWorkshops(v.WorkShopName); !exists {
|
|
|
continue
|
|
|
}
|
|
|
var plan *domain.ProductPlan
|
|
|
var product *domain.Product
|
|
|
|
|
|
// 产品信息
|
|
|
product, err = productRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "productCode": v.MaterialNumber})
|
|
|
if err != nil || err == domain.ErrorNotFound {
|
|
|
continue
|
|
|
}
|
|
|
// 计划信息
|
|
|
plan, err = productPlanRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "batchNumber": v.BillNo})
|
|
|
if err == nil && plan != nil {
|
|
|
plan.UpdatedAt = time.Now()
|
|
|
continue
|
|
|
}
|
|
|
if err == domain.ErrorNotFound {
|
|
|
plan = &domain.ProductPlan{
|
|
|
CompanyId: cid,
|
|
|
OrgId: oid,
|
|
|
BatchNumber: v.BillNo,
|
|
|
ProductDate: v.PlanStartDate,
|
|
|
Workshop: workshop.CloneSample(),
|
|
|
WorkOn: 0,
|
|
|
Machine: "",
|
|
|
PlanStatus: domain.PlanOffline,
|
|
|
WorkStation: &domain.WorkStation{},
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
}
|
|
|
}
|
|
|
// 更新数据
|
|
|
plan.PlanDevoted = &domain.UnitQuantity{
|
|
|
Unit: product.ProductSpec.Unit,
|
|
|
Quantity: 0,
|
|
|
Weight: product.ProductWeigh(0),
|
|
|
UnitWeight: product.ProductSpec.UnitWeight,
|
|
|
}
|
|
|
plan.Workshop = workshop.CloneSample()
|
|
|
plan.UpdatedAt = time.Now()
|
|
|
plan.Ext = domain.NewExt(org.OrgName).WithProductPlanExt(&domain.ProductPlanExt{
|
|
|
ProductId: product.ProductId,
|
|
|
ProductCode: product.ProductCode,
|
|
|
ProductName: product.ProductName,
|
|
|
DevotedUnit: "份",
|
|
|
})
|
|
|
plan.PlanProductName = product.ProductName
|
|
|
plan.Remark = v.Description
|
|
|
|
|
|
if plan, err = productPlanRepository.Save(plan); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|