PeopleShipHomePageDataModel.ets 8.44 KB
import { OtherUserDetailRequestItem } from './OtherUserDetailRequestItem';
import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
import { PeopleShipUserDetailData, ArticleCountData, ArticleListData, InfluenceData } from 'wdBean';
import { Logger } from 'wdKit';
import { FollowListStatusRequestItem } from './FollowListStatusRequestItem';
import { QueryListIsFollowedItem } from './QueryListIsFollowedItem';

const TAG = 'PeopleShipHomePageDataModel';

export class PeopleShipHomePageDataModel {
  /*获取人民号主页详情*/
  static fetchPeopleUserDetailData(item: OtherUserDetailRequestItem) {
    let url = HttpUrlUtils.getOtherUserDetailDataUrl()
    return WDHttp.post<ResponseDTO<PeopleShipUserDetailData>>(url, item)
  }

  static async getPeopleShipHomePageDetailInfo(creatorId: string, userType: string, userId: string): Promise<PeopleShipUserDetailData> {
    let model = new OtherUserDetailRequestItem(creatorId, userType, userId)
    return new Promise<PeopleShipUserDetailData>((success, error) => {
      Logger.debug(TAG, `getMorningEveningCompInfo pageInfo start`);
      PeopleShipHomePageDataModel.fetchPeopleUserDetailData(model)
        .then((resDTO: ResponseDTO<PeopleShipUserDetailData>) => {
          if (!resDTO || !resDTO.data) {
            Logger.error(TAG, 'getPeopleShipHomePageDetailInfo then navResDTO is empty');
            error('resDTO is empty');
            return
          }
          if (resDTO.code != 0) {
            Logger.error(TAG, `getPeopleShipHomePageDetailInfo then code:${resDTO.code}, message:${resDTO.message}`);
            error('resDTO Response Code is failure');
            return
          }
          Logger.debug(TAG, "getPeopleShipHomePageDetailInfo then,navResDTO.timestamp:" + resDTO.timestamp);
          success(resDTO.data);
        })
        .catch((err: Error) => {
          Logger.error(TAG, `getPeopleShipHomePageDetailInfo catch, error.name : ${err.name},  error.message:${err.message}`);
          error(err);
        })
    })
  }


  /*客户端 客态查询发布作品数量*/
  static fetchArticleCountHotsData(includeLive: number, creatorId: string) {
    let url = HttpUrlUtils.getArticleCountHotsDataUrl() + `?includeLive=${includeLive}&creatorId=${creatorId}`
    // let url = 'https://pdapis.pdnews.cn/api/rmrb-content-search/zh/c/article/count' + `?includeLive=${includeLive}&creatorId=${creatorId}`
    Logger.debug(TAG, `${url}`);
    return WDHttp.get<ResponseDTO<ArticleCountData>>(url)
  }

  static async getPeopleShipHomePageArticleCountData(includeLive: number, creatorId: string): Promise<ArticleCountData> {
    Logger.debug(TAG, `getPeopleShipHomePageArticleCountData start`);
    return new Promise<ArticleCountData>((success, error) => {
      Logger.debug(TAG, `getPeopleShipHomePageArticleCountData pageInfo start`);
      PeopleShipHomePageDataModel.fetchArticleCountHotsData(includeLive, creatorId)
        .then((resDTO: ResponseDTO<ArticleCountData>) => {
          if (!resDTO || !resDTO.data) {
            Logger.error(TAG, 'getPeopleShipHomePageArticleCountData then ArticleCountData is empty');
            error('resDTO is empty');
            return
          }
          if (resDTO.code != 0) {
            Logger.error(TAG, `getPeopleShipHomePageArticleCountData then code:${resDTO.code}, message:${resDTO.message}`);
            error(resDTO.message);
            return
          }
          Logger.debug(TAG, "getPeopleShipHomePageArticleCountData then,ArticleCountData.timestamp:" + resDTO.timestamp);
          success(resDTO.data);
        })
        .catch((err: Error) => {
          Logger.error(TAG, `getPeopleShipHomePageArticleCountData catch, error.name : ${err.name},  error.message:${err.message}`);
          error(err);
        })
    })
  }

  /*客户端 客态主页页面-获取作品-从发布库获取该创作者下 稿件列表*/
  static fetchArticleListHotsData(creatorId: string, pageNum: number, pageSize: number, type?: number) {
    let url = HttpUrlUtils.getArticleListHotsDataUrl() + `?creatorId=${creatorId}&pageNum=${pageNum}&pageSize=${pageSize}`
    if (type) {
      url += `&type=${type}`
    }
    Logger.debug(TAG, `${url}`);
    return WDHttp.get<ResponseDTO<ArticleListData>>(url)
  }

  static async getPeopleShipHomePageArticleListData(creatorId: string, pageNum: number, pageSize: number, type?: number): Promise<ArticleListData> {
    Logger.debug(TAG, `getPeopleShipHomePageArticleListData start`);
    return new Promise<ArticleListData>((success, error) => {
      Logger.debug(TAG, `getPeopleShipHomePageArticleListData pageInfo start`);
      PeopleShipHomePageDataModel.fetchArticleListHotsData(creatorId, pageNum, pageSize, type)
        .then((resDTO: ResponseDTO<ArticleListData>) => {
          if (!resDTO || !resDTO.data) {
            Logger.error(TAG, 'getPeopleShipHomePageArticleListData then ArticleCountData is empty');
            error('resDTO is empty');
            return
          }
          if (resDTO.code != 0) {
            Logger.error(TAG, `getPeopleShipHomePageArticleListData then code:${resDTO.code}, message:${resDTO.message}`);
            error(resDTO.message);
            return
          }
          Logger.debug(TAG, "getPeopleShipHomePageArticleListData then,ArticleCountData.timestamp:" + resDTO.timestamp);
          success(resDTO.data);
        })
        .catch((err: Error) => {
          Logger.error(TAG, `getPeopleShipHomePageArticleListData catch, error.name : ${err.name},  error.message:${err.message}`);
          error(err);
        })
    })
  }

  /*客户端 客态查询影响力*/
  static fetchCreatorInfluenceInfoHotsData(creatorId: string) {
    let url = HttpUrlUtils.getCreatorInfluenceInfoHotsDataUrl() + `?creatorId=${creatorId}`
    Logger.debug(TAG, `${url}`);
    return WDHttp.get<ResponseDTO<InfluenceData>>(url)
  }

  static async getCreatorInfluenceInfoData(creatorId: string): Promise<InfluenceData> {
    Logger.debug(TAG, `getCreatorInfluenceInfoData start`);
    return new Promise<InfluenceData>((success, error) => {
      Logger.debug(TAG, `getCreatorInfluenceInfoData pageInfo start`);
      PeopleShipHomePageDataModel.fetchCreatorInfluenceInfoHotsData(creatorId)
        .then((resDTO: ResponseDTO<InfluenceData>) => {
          if (!resDTO || !resDTO.data) {
            Logger.error(TAG, 'getCreatorInfluenceInfoData then ArticleCountData is empty');
            error('resDTO is empty');
            return
          }
          if (resDTO.code != 0) {
            Logger.error(TAG, `getCreatorInfluenceInfoData then code:${resDTO.code}, message:${resDTO.message}`);
            error(resDTO.message);
            return
          }
          Logger.debug(TAG, "getCreatorInfluenceInfoData then,ArticleCountData.timestamp:" + resDTO.timestamp);
          success(resDTO.data);
        })
        .catch((err: Error) => {
          Logger.error(TAG, `getCreatorInfluenceInfoData catch, error.name : ${err.name},  error.message:${err.message}`);
          error(err);
        })
    })
  }

  // 获取关注
  static fetchHomePageFollowListStatusData(creatorId: string) {
    let url = HttpUrlUtils.getFollowListStatusDataUrl()
    let model = new QueryListIsFollowedItem(creatorId)
    let object = new FollowListStatusRequestItem()
    object.creatorIds = [model]
    return WDHttp.post<ResponseDTO<QueryListIsFollowedItem[]>>(url,object)
  };

  static async getHomePageFollowListStatusData(creatorId: string): Promise<QueryListIsFollowedItem[]> {
    Logger.debug(TAG, `getCreatorInfluenceInfoData start`);
    return new Promise<QueryListIsFollowedItem[]>((success, error) => {
      Logger.debug(TAG, `getCreatorInfluenceInfoData pageInfo start`);
      PeopleShipHomePageDataModel.fetchHomePageFollowListStatusData(creatorId)
        .then((resDTO: ResponseDTO<QueryListIsFollowedItem[]>) => {
          if (!resDTO || !resDTO.data) {
            Logger.error(TAG, 'getCreatorInfluenceInfoData then ArticleCountData is empty');
            error('resDTO is empty');
            return
          }
          if (resDTO.code != 0) {
            Logger.error(TAG, `getCreatorInfluenceInfoData then code:${resDTO.code}, message:${resDTO.message}`);
            error(resDTO.message);
            return
          }
          Logger.debug(TAG, "getCreatorInfluenceInfoData then,ArticleCountData.timestamp:" + resDTO.timestamp);
          success(resDTO.data);
        })
        .catch((err: Error) => {
          Logger.error(TAG, `getCreatorInfluenceInfoData catch, error.name : ${err.name},  error.message:${err.message}`);
          error(err);
        })
    })
  }



}