作者 yangfu

fix: 物料同步修改

... ... @@ -473,7 +473,44 @@ func (srv *PullDataK3CloudService) SyncDataProduct(ptr *pgTransaction.Transactio
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return prdMoDao.SyncDataProductByTime(fromTime, org.OrgName)
materials, err := prdMoDao.SearchProductByTime(fromTime, "素天下") // 默认企业名称素天下、或者使用组织ID
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var (
cid = constant.MANUFACTURE_DEFAULT_COMPANYID
oid = constant.MANUFACTURE_DEFAULT_ORGID
)
productRepository, _, _ := factory.FastPgProduct(ptr, 0)
for _, v := range materials {
var product *domain.Product
product, err = productRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "productCode": v.Number})
if err == nil && product != nil {
continue
}
if err == domain.ErrorNotFound {
err = nil
product = &domain.Product{
CompanyId: cid,
OrgId: oid,
ProductCode: v.Number,
ProductName: v.Name,
ProductCategory: v.MaterialGroupName,
ProductSpec: &domain.UnitQuantity{
Unit: v.Specification,
UnitWeight: 0,
},
CreatedAt: v.CreateDate,
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName),
}
}
if product, err = productRepository.Save(product); err != nil {
return err
}
}
return nil
//return prdMoDao.SyncDataProductByTime(fromTime, org.OrgName)
}
// 同步生产计划
... ...
... ... @@ -152,6 +152,18 @@ func (d *MaterialK3cloudDao) SyncDataProductByTime(t time.Time, orgName string)
return err
}
func (d *MaterialK3cloudDao) SearchProductByTime(t time.Time, orgName string) ([]*models.MaterialK3cloud, error) {
var materialData []*models.MaterialK3cloud
query := d.transactionContext.PgTx.Model(&materialData)
query.Where("modify_date>=?", t)
query.Where("use_org_name =?", orgName)
query.Where("material_group_number LIKE '05%%'")
if err := query.Select(); err != nil {
return nil, err
}
return materialData, nil
}
func (d *MaterialK3cloudDao) GetLastVersion() (int64, error) {
var materialData []models.MaterialK3cloud
err := d.transactionContext.PgTx.Model(&materialData).
... ...