作者 yangfu

fix: 物料同步修改

@@ -473,7 +473,44 @@ func (srv *PullDataK3CloudService) SyncDataProduct(ptr *pgTransaction.Transactio @@ -473,7 +473,44 @@ func (srv *PullDataK3CloudService) SyncDataProduct(ptr *pgTransaction.Transactio
473 if err != nil { 473 if err != nil {
474 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 474 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
475 } 475 }
476 - return prdMoDao.SyncDataProductByTime(fromTime, org.OrgName) 476 + materials, err := prdMoDao.SearchProductByTime(fromTime, "素天下") // 默认企业名称素天下、或者使用组织ID
  477 + if err != nil {
  478 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  479 + }
  480 + var (
  481 + cid = constant.MANUFACTURE_DEFAULT_COMPANYID
  482 + oid = constant.MANUFACTURE_DEFAULT_ORGID
  483 + )
  484 + productRepository, _, _ := factory.FastPgProduct(ptr, 0)
  485 + for _, v := range materials {
  486 + var product *domain.Product
  487 + product, err = productRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "productCode": v.Number})
  488 + if err == nil && product != nil {
  489 + continue
  490 + }
  491 + if err == domain.ErrorNotFound {
  492 + err = nil
  493 + product = &domain.Product{
  494 + CompanyId: cid,
  495 + OrgId: oid,
  496 + ProductCode: v.Number,
  497 + ProductName: v.Name,
  498 + ProductCategory: v.MaterialGroupName,
  499 + ProductSpec: &domain.UnitQuantity{
  500 + Unit: v.Specification,
  501 + UnitWeight: 0,
  502 + },
  503 + CreatedAt: v.CreateDate,
  504 + UpdatedAt: time.Now(),
  505 + Ext: domain.NewExt(org.OrgName),
  506 + }
  507 + }
  508 + if product, err = productRepository.Save(product); err != nil {
  509 + return err
  510 + }
  511 + }
  512 + return nil
  513 + //return prdMoDao.SyncDataProductByTime(fromTime, org.OrgName)
477 } 514 }
478 515
479 // 同步生产计划 516 // 同步生产计划
@@ -152,6 +152,18 @@ func (d *MaterialK3cloudDao) SyncDataProductByTime(t time.Time, orgName string) @@ -152,6 +152,18 @@ func (d *MaterialK3cloudDao) SyncDataProductByTime(t time.Time, orgName string)
152 return err 152 return err
153 } 153 }
154 154
  155 +func (d *MaterialK3cloudDao) SearchProductByTime(t time.Time, orgName string) ([]*models.MaterialK3cloud, error) {
  156 + var materialData []*models.MaterialK3cloud
  157 + query := d.transactionContext.PgTx.Model(&materialData)
  158 + query.Where("modify_date>=?", t)
  159 + query.Where("use_org_name =?", orgName)
  160 + query.Where("material_group_number LIKE '05%%'")
  161 + if err := query.Select(); err != nil {
  162 + return nil, err
  163 + }
  164 + return materialData, nil
  165 +}
  166 +
155 func (d *MaterialK3cloudDao) GetLastVersion() (int64, error) { 167 func (d *MaterialK3cloudDao) GetLastVersion() (int64, error) {
156 var materialData []models.MaterialK3cloud 168 var materialData []models.MaterialK3cloud
157 err := d.transactionContext.PgTx.Model(&materialData). 169 err := d.transactionContext.PgTx.Model(&materialData).