@gt6/sdk 1.0.43 → 1.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -786,6 +786,151 @@ class ArticlesAPI {
786
786
  filteredTotal // 过滤后的总数
787
787
  };
788
788
  }
789
+ /**
790
+ * 1.2.2 根据分类ID获取文章列表(支持搜索过滤)
791
+ */
792
+ async getArticlesByCategory_all_search01(categoryId, searchOptions) {
793
+ // 将单个分类ID转换为数组
794
+ const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
795
+ // 收集所有指定分类下的文章数据
796
+ const allArticleData = [];
797
+ let totalArticles = 0;
798
+ // 遍历所有分类ID,获取每个分类的文章数据
799
+ for (const singleCategoryId of categoryIds) {
800
+ try {
801
+ const categoryData = await this.client.request(`/big-article-categories/${singleCategoryId}.json`);
802
+ if (categoryData && categoryData.articleIds && categoryData.articleIds.length > 0) {
803
+ allArticleData.push(...categoryData.articleIds);
804
+ totalArticles += categoryData.articleIds.length;
805
+ }
806
+ }
807
+ catch (error) {
808
+ console.warn(`Failed to fetch data for category ${singleCategoryId}:`, error);
809
+ // 继续处理其他分类,不中断整个流程
810
+ }
811
+ }
812
+ if (allArticleData.length === 0) {
813
+ return {
814
+ articles: [],
815
+ total: 0,
816
+ page: searchOptions?.page || 1,
817
+ limit: searchOptions?.limit || 10,
818
+ filteredTotal: 0
819
+ };
820
+ }
821
+ // 应用搜索过滤
822
+ let filteredArticleIds = allArticleData.filter(articleObj => {
823
+ // 1. regionId 过滤
824
+ if (searchOptions?.regionIds && searchOptions.regionIds.length > 0) {
825
+ if (!articleObj.regionId || !searchOptions.regionIds.includes(articleObj.regionId)) {
826
+ return false;
827
+ }
828
+ }
829
+ // 2. price 范围过滤
830
+ if (searchOptions?.priceRange) {
831
+ const price = parseFloat(articleObj.price || '0');
832
+ if (searchOptions.priceRange.min !== undefined && price < searchOptions.priceRange.min) {
833
+ return false;
834
+ }
835
+ if (searchOptions.priceRange.max !== undefined && price > searchOptions.priceRange.max) {
836
+ return false;
837
+ }
838
+ }
839
+ // 3. Salary 范围过滤
840
+ if (searchOptions?.salaryRange) {
841
+ const salary = parseFloat(articleObj.Salary || '0');
842
+ if (searchOptions.salaryRange.min !== undefined && salary < searchOptions.salaryRange.min) {
843
+ return false;
844
+ }
845
+ if (searchOptions.salaryRange.max !== undefined && salary > searchOptions.salaryRange.max) {
846
+ return false;
847
+ }
848
+ }
849
+ // 4. mileage 范围过滤
850
+ if (searchOptions?.mileageRange) {
851
+ // 处理里程数格式,如 "26000 km" -> 26000
852
+ const mileageStr = articleObj.Mileage || '0';
853
+ const mileageMatch = mileageStr.match(/(\d+(?:\.\d+)?)/);
854
+ const mileage = mileageMatch ? parseFloat(mileageMatch[1]) : 0;
855
+ if (searchOptions.mileageRange.min !== undefined && mileage < searchOptions.mileageRange.min) {
856
+ return false;
857
+ }
858
+ if (searchOptions.mileageRange.max !== undefined && mileage > searchOptions.mileageRange.max) {
859
+ return false;
860
+ }
861
+ }
862
+ // 5. propertyArea 范围过滤
863
+ if (searchOptions?.propertyAreaRange) {
864
+ const propertyArea = parseFloat(articleObj.propertyArea || '0');
865
+ if (searchOptions.propertyAreaRange.min !== undefined && propertyArea < searchOptions.propertyAreaRange.min) {
866
+ return false;
867
+ }
868
+ if (searchOptions.propertyAreaRange.max !== undefined && propertyArea > searchOptions.propertyAreaRange.max) {
869
+ return false;
870
+ }
871
+ }
872
+ // 6. plotArea 范围过滤
873
+ if (searchOptions?.plotAreaRange) {
874
+ const plotArea = parseFloat(articleObj.plotArea || '0');
875
+ if (searchOptions.plotAreaRange.min !== undefined && plotArea < searchOptions.plotAreaRange.min) {
876
+ return false;
877
+ }
878
+ if (searchOptions.plotAreaRange.max !== undefined && plotArea > searchOptions.plotAreaRange.max) {
879
+ return false;
880
+ }
881
+ }
882
+ // 7. tagIds 过滤
883
+ if (searchOptions?.tagIds && searchOptions.tagIds.length > 0) {
884
+ if (!articleObj.tagIds || articleObj.tagIds.length === 0) {
885
+ return false;
886
+ }
887
+ if (searchOptions.requireAllTags) {
888
+ // 要求包含所有指定的 tagIds
889
+ const hasAllTags = searchOptions.tagIds.every(tagId => articleObj.tagIds.includes(tagId));
890
+ if (!hasAllTags) {
891
+ return false;
892
+ }
893
+ }
894
+ else {
895
+ // 包含任意一个指定的 tagId 即可
896
+ const hasAnyTag = searchOptions.tagIds.some(tagId => articleObj.tagIds.includes(tagId));
897
+ if (!hasAnyTag) {
898
+ return false;
899
+ }
900
+ }
901
+ }
902
+ return true;
903
+ });
904
+ const filteredTotal = filteredArticleIds.length;
905
+ if (filteredTotal === 0) {
906
+ return {
907
+ articles: [],
908
+ total: totalArticles,
909
+ page: searchOptions?.page || 1,
910
+ limit: searchOptions?.limit || 10,
911
+ filteredTotal: 0
912
+ };
913
+ }
914
+ // 应用分页
915
+ const page = searchOptions?.page || 1;
916
+ const limit = searchOptions?.limit || 10;
917
+ const offset = (page - 1) * limit;
918
+ const paginatedArticleIds = filteredArticleIds.slice(offset, offset + limit);
919
+ // 获取文章详情
920
+ const articles = await Promise.all(paginatedArticleIds.map(articleObj => this.getArticle_all(articleObj.articleId)));
921
+ // 应用状态过滤
922
+ let finalArticles = articles;
923
+ if (searchOptions?.status) {
924
+ finalArticles = articles.filter(article => article.status === searchOptions.status);
925
+ }
926
+ return {
927
+ articles: finalArticles,
928
+ total: totalArticles, // 原始总数
929
+ page,
930
+ limit,
931
+ filteredTotal // 过滤后的总数
932
+ };
933
+ }
789
934
  /**
790
935
  * 1.2.1 根据平台ID获取文章列表(平台用户都可以使用)
791
936
  */
@@ -3238,6 +3383,12 @@ class GT6SDK {
3238
3383
  async getArticlesByCategory_all(categoryId, options) {
3239
3384
  return this.articles.getArticlesByCategory_all(categoryId, options);
3240
3385
  }
3386
+ async getArticlesByCategory_all_search(categoryId, options) {
3387
+ return this.articles.getArticlesByCategory_all_search(categoryId, options);
3388
+ }
3389
+ async getArticlesByCategory_all_search01(categoryId, options) {
3390
+ return this.articles.getArticlesByCategory_all_search01(categoryId, options);
3391
+ }
3241
3392
  async getArticlesByplatform_all(platformId, options) {
3242
3393
  return this.articles.getArticlesByplatform_all(platformId, options);
3243
3394
  }