@gt6/sdk 1.0.42 → 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.
@@ -695,7 +695,17 @@ class ArticlesAPI {
695
695
  return false;
696
696
  }
697
697
  }
698
- // 3. mileage 范围过滤
698
+ // 3. Salary 范围过滤
699
+ if (searchOptions?.salaryRange) {
700
+ const salary = parseFloat(articleObj.Salary || '0');
701
+ if (searchOptions.salaryRange.min !== undefined && salary < searchOptions.salaryRange.min) {
702
+ return false;
703
+ }
704
+ if (searchOptions.salaryRange.max !== undefined && salary > searchOptions.salaryRange.max) {
705
+ return false;
706
+ }
707
+ }
708
+ // 4. mileage 范围过滤
699
709
  if (searchOptions?.mileageRange) {
700
710
  // 处理里程数格式,如 "26000 km" -> 26000
701
711
  const mileageStr = articleObj.Mileage || '0';
@@ -708,7 +718,7 @@ class ArticlesAPI {
708
718
  return false;
709
719
  }
710
720
  }
711
- // 4. propertyArea 范围过滤
721
+ // 5. propertyArea 范围过滤
712
722
  if (searchOptions?.propertyAreaRange) {
713
723
  const propertyArea = parseFloat(articleObj.propertyArea || '0');
714
724
  if (searchOptions.propertyAreaRange.min !== undefined && propertyArea < searchOptions.propertyAreaRange.min) {
@@ -718,7 +728,7 @@ class ArticlesAPI {
718
728
  return false;
719
729
  }
720
730
  }
721
- // 5. plotArea 范围过滤
731
+ // 6. plotArea 范围过滤
722
732
  if (searchOptions?.plotAreaRange) {
723
733
  const plotArea = parseFloat(articleObj.plotArea || '0');
724
734
  if (searchOptions.plotAreaRange.min !== undefined && plotArea < searchOptions.plotAreaRange.min) {
@@ -728,7 +738,7 @@ class ArticlesAPI {
728
738
  return false;
729
739
  }
730
740
  }
731
- // 6. tagIds 过滤
741
+ // 7. tagIds 过滤
732
742
  if (searchOptions?.tagIds && searchOptions.tagIds.length > 0) {
733
743
  if (!articleObj.tagIds || articleObj.tagIds.length === 0) {
734
744
  return false;
@@ -780,6 +790,151 @@ class ArticlesAPI {
780
790
  filteredTotal // 过滤后的总数
781
791
  };
782
792
  }
793
+ /**
794
+ * 1.2.2 根据分类ID获取文章列表(支持搜索过滤)
795
+ */
796
+ async getArticlesByCategory_all_search01(categoryId, searchOptions) {
797
+ // 将单个分类ID转换为数组
798
+ const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
799
+ // 收集所有指定分类下的文章数据
800
+ const allArticleData = [];
801
+ let totalArticles = 0;
802
+ // 遍历所有分类ID,获取每个分类的文章数据
803
+ for (const singleCategoryId of categoryIds) {
804
+ try {
805
+ const categoryData = await this.client.request(`/big-article-categories/${singleCategoryId}.json`);
806
+ if (categoryData && categoryData.articleIds && categoryData.articleIds.length > 0) {
807
+ allArticleData.push(...categoryData.articleIds);
808
+ totalArticles += categoryData.articleIds.length;
809
+ }
810
+ }
811
+ catch (error) {
812
+ console.warn(`Failed to fetch data for category ${singleCategoryId}:`, error);
813
+ // 继续处理其他分类,不中断整个流程
814
+ }
815
+ }
816
+ if (allArticleData.length === 0) {
817
+ return {
818
+ articles: [],
819
+ total: 0,
820
+ page: searchOptions?.page || 1,
821
+ limit: searchOptions?.limit || 10,
822
+ filteredTotal: 0
823
+ };
824
+ }
825
+ // 应用搜索过滤
826
+ let filteredArticleIds = allArticleData.filter(articleObj => {
827
+ // 1. regionId 过滤
828
+ if (searchOptions?.regionIds && searchOptions.regionIds.length > 0) {
829
+ if (!articleObj.regionId || !searchOptions.regionIds.includes(articleObj.regionId)) {
830
+ return false;
831
+ }
832
+ }
833
+ // 2. price 范围过滤
834
+ if (searchOptions?.priceRange) {
835
+ const price = parseFloat(articleObj.price || '0');
836
+ if (searchOptions.priceRange.min !== undefined && price < searchOptions.priceRange.min) {
837
+ return false;
838
+ }
839
+ if (searchOptions.priceRange.max !== undefined && price > searchOptions.priceRange.max) {
840
+ return false;
841
+ }
842
+ }
843
+ // 3. Salary 范围过滤
844
+ if (searchOptions?.salaryRange) {
845
+ const salary = parseFloat(articleObj.Salary || '0');
846
+ if (searchOptions.salaryRange.min !== undefined && salary < searchOptions.salaryRange.min) {
847
+ return false;
848
+ }
849
+ if (searchOptions.salaryRange.max !== undefined && salary > searchOptions.salaryRange.max) {
850
+ return false;
851
+ }
852
+ }
853
+ // 4. mileage 范围过滤
854
+ if (searchOptions?.mileageRange) {
855
+ // 处理里程数格式,如 "26000 km" -> 26000
856
+ const mileageStr = articleObj.Mileage || '0';
857
+ const mileageMatch = mileageStr.match(/(\d+(?:\.\d+)?)/);
858
+ const mileage = mileageMatch ? parseFloat(mileageMatch[1]) : 0;
859
+ if (searchOptions.mileageRange.min !== undefined && mileage < searchOptions.mileageRange.min) {
860
+ return false;
861
+ }
862
+ if (searchOptions.mileageRange.max !== undefined && mileage > searchOptions.mileageRange.max) {
863
+ return false;
864
+ }
865
+ }
866
+ // 5. propertyArea 范围过滤
867
+ if (searchOptions?.propertyAreaRange) {
868
+ const propertyArea = parseFloat(articleObj.propertyArea || '0');
869
+ if (searchOptions.propertyAreaRange.min !== undefined && propertyArea < searchOptions.propertyAreaRange.min) {
870
+ return false;
871
+ }
872
+ if (searchOptions.propertyAreaRange.max !== undefined && propertyArea > searchOptions.propertyAreaRange.max) {
873
+ return false;
874
+ }
875
+ }
876
+ // 6. plotArea 范围过滤
877
+ if (searchOptions?.plotAreaRange) {
878
+ const plotArea = parseFloat(articleObj.plotArea || '0');
879
+ if (searchOptions.plotAreaRange.min !== undefined && plotArea < searchOptions.plotAreaRange.min) {
880
+ return false;
881
+ }
882
+ if (searchOptions.plotAreaRange.max !== undefined && plotArea > searchOptions.plotAreaRange.max) {
883
+ return false;
884
+ }
885
+ }
886
+ // 7. tagIds 过滤
887
+ if (searchOptions?.tagIds && searchOptions.tagIds.length > 0) {
888
+ if (!articleObj.tagIds || articleObj.tagIds.length === 0) {
889
+ return false;
890
+ }
891
+ if (searchOptions.requireAllTags) {
892
+ // 要求包含所有指定的 tagIds
893
+ const hasAllTags = searchOptions.tagIds.every(tagId => articleObj.tagIds.includes(tagId));
894
+ if (!hasAllTags) {
895
+ return false;
896
+ }
897
+ }
898
+ else {
899
+ // 包含任意一个指定的 tagId 即可
900
+ const hasAnyTag = searchOptions.tagIds.some(tagId => articleObj.tagIds.includes(tagId));
901
+ if (!hasAnyTag) {
902
+ return false;
903
+ }
904
+ }
905
+ }
906
+ return true;
907
+ });
908
+ const filteredTotal = filteredArticleIds.length;
909
+ if (filteredTotal === 0) {
910
+ return {
911
+ articles: [],
912
+ total: totalArticles,
913
+ page: searchOptions?.page || 1,
914
+ limit: searchOptions?.limit || 10,
915
+ filteredTotal: 0
916
+ };
917
+ }
918
+ // 应用分页
919
+ const page = searchOptions?.page || 1;
920
+ const limit = searchOptions?.limit || 10;
921
+ const offset = (page - 1) * limit;
922
+ const paginatedArticleIds = filteredArticleIds.slice(offset, offset + limit);
923
+ // 获取文章详情
924
+ const articles = await Promise.all(paginatedArticleIds.map(articleObj => this.getArticle_all(articleObj.articleId)));
925
+ // 应用状态过滤
926
+ let finalArticles = articles;
927
+ if (searchOptions?.status) {
928
+ finalArticles = articles.filter(article => article.status === searchOptions.status);
929
+ }
930
+ return {
931
+ articles: finalArticles,
932
+ total: totalArticles, // 原始总数
933
+ page,
934
+ limit,
935
+ filteredTotal // 过滤后的总数
936
+ };
937
+ }
783
938
  /**
784
939
  * 1.2.1 根据平台ID获取文章列表(平台用户都可以使用)
785
940
  */
@@ -3232,6 +3387,12 @@ class GT6SDK {
3232
3387
  async getArticlesByCategory_all(categoryId, options) {
3233
3388
  return this.articles.getArticlesByCategory_all(categoryId, options);
3234
3389
  }
3390
+ async getArticlesByCategory_all_search(categoryId, options) {
3391
+ return this.articles.getArticlesByCategory_all_search(categoryId, options);
3392
+ }
3393
+ async getArticlesByCategory_all_search01(categoryId, options) {
3394
+ return this.articles.getArticlesByCategory_all_search01(categoryId, options);
3395
+ }
3235
3396
  async getArticlesByplatform_all(platformId, options) {
3236
3397
  return this.articles.getArticlesByplatform_all(platformId, options);
3237
3398
  }