如何导出带条件的数据

How to export data with condition

我需要导出模型的一些实例,但我不想全部导出。我只需要具有特定属性的那个。

我可以通过代码做到这一点,我想知道如何使用 Impex 做到这一点?

我可以从 Backoffice -> Tools -> Script generated 生成导出模型。

然后我可以添加一个灵活的搜索查询来过滤导出的结果:

# ---- Extension: core ---- Type: Customer ----
"#% impex.setTargetFile( ""Customer.csv"" );"
insert_update Customer;&Item;Europe1PriceFactory_UDG(code,itemtype(code));Europe1PriceFactory_UPG(code,itemtype(code));Europe1PriceFactory_UTG(code,itemtype(code));allowSubstitution[allownull=true];...
"#% impex.exportItemsFlexibleSearch(""select {PK} from {Customer} where {uid}='anonymous'"", Collections.EMPTY_MAP, Collections.singletonList( Item.class ), true, true, -1, -1  );"

Cf : Impex API for the documentation about impex.exportItems[FlexibleSearch] and this page 更多例子

您可以用其他方式导出您的实例:

第 1 步:

转到 HMC 界面,选择脚本生成器 tool System->Tools->Script Generator,然后生成 ImpEx 脚本模型,然后选择要导出的实例类型脚本,例如:

"#% impex.setTargetFile( ""Customer.csv"" );"  // 1. where to export
insert_update Customer;&Item;@password[translator=de.hybris.platform.impex.jalo.translators.UserPasswordTranslator];CN;CodeNaf(code);DN;Europe1PriceFactory_UDG(code,itemtype(code));Europe1PriceFactory_UPG(code,itemtype(code));Europe1PriceFactory_UTG(code,itemtype(code));accountOrigine(&Item);accountVerificationType;addresses(&Item);authentificationDate[dateformat=dd.MM.yyyy hh:mm:ss];authorizedToUnlockPages[allownull=true];birthDate[dateformat=dd.MM.yyyy hh:mm:ss];carts(code);codeAPE;codeRCS;codeSiret;company;companyType(code,itemtype(code));creationtime[forceWrite=true,dateformat=dd.MM.yyyy hh:mm:ss];customerID;dateOfBirth[dateformat=dd.MM.yyyy hh:mm:ss];defaultPaymentAddress(&Item);defaultPaymentInfo(&Item);defaultShipmentAddress(&Item);description;domain;emailAlias;encodedPassword;enseigne(code)[allownull=true];erosId;europe1Discounts(&Item);firstname;fraudStatus(code,itemtype(code));hmcLoginDisabled;interestAreaList(code,itemtype(code));isprofessionnel;lastLogin[dateformat=dd.MM.yyyy hh:mm:ss];lastname;ldapaccount[allownull=true];ldaplogin;ldapsearchbase;locationType(code,itemtype(code));loginDisabled[allownull=true];modifiedtime[dateformat=dd.MM.yyyy hh:mm:ss];name;nbChild;nbGodSon;orders(code,versionID);origin;originalUid;owner(&Item)[allownull=true];password;passwordAnswer;passwordEncoding;passwordQuestion;paymentInfos(&Item);previewCatalogVersions(catalog(id),version);profilePicture(catalogVersion(catalog(id),version),code);recevedDocs;sessionCurrency(isocode);sessionLanguage(isocode);subscriptionTelContact(&Item);title(code);token;type(code,itemtype(code));uid[unique=true,allownull=true];userprofile(&Item);verificationDate[dateformat=dd.MM.yyyy hh:mm:ss];verificationflag // 2. how to export
"#% impex.exportItems( ""Customer"" , false );" // 3. what to export

为了进一步说明您要查找的内容,我将重点放在第 3 行

#% impex.exportItems( ""Customer"" , false );" // 3. what to export

因此您可以以不同的方式使用 exportItems 方法:

  • exportItems 按项目集:

    public void exportItems( Collection<Item> items ) public void exportItems( String[] pklist )

这些方法导出给定项目,其中项目可以作为 PK(字符串)列表传递或直接用作项目集合。

  • exportItems 按类型代码:

    public void exportItems( String typecode ) public void exportItems( String typecode, int count ) public void exportItems( String typecode, boolean inclSubTypes ) public void exportItems( String typecode, int count, boolean inclSubTypes )

  • exportItems 由 FlexibleSearch:

    public void exportItemsFlexibleSearch( 字符串查询 ) public void exportItemsFlexibleSearch(字符串查询、地图值、列表结果类、最终布尔值 failOnUnknownFields、最终布尔值 dontNeedTotal、int 开始、int 计数)<br> public void exportItemsFlexibleSearch(字符串查询,整数计数)

注意:Exporter API 默认使用搜索结果分页。因此,要获得准确的结果,您的 FlexibleSearch 查询必须包含 ORDER BY 子句示例:

impex.exportItemsFlexibleSearch(""select {PK} from {Customer} where {uid}='anonymous' ORDER BY {pk}"")

如果您有权访问 help.hybris,请检查:

如果您只能访问 wiki :

步骤 2:

转到 HAC 界面,ImpEx Export,然后放置脚本并导出项目。