ContentDetailRequest.ets 9.36 KB
import { Logger, ResourcesUtils, EmitterUtils, EmitterEventId  } from 'wdKit';
import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
import { ContentDetailDTO, InteractDataDTO } from 'wdBean';
import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest';

const TAG = 'ContentDetailRequest';

const mock_switch = false;

export interface ContentDetailRequestParams {
  contentId: string
  relId: string
  relType: string
}

export interface contentsItem {
  contentId: string;
  contentRelId: string;
  contentType: number;
  relId: string;
  relType: string;
}

export interface batchContentDetailParams {
  contents: contentsItem[]
}

export interface recommentVideoListParams {
  pageSize: number;
  refreshCnt: number;
}

interface contentListItem {
  contentId: string;
  contentType: number;
}

export interface contentListParams {
  contentList: contentListItem[];
}

export interface getRecCompInfoParams {
  groupId: string;
  pageId: string;
  channelId: string;
  loadStrategy: string;
  channelStrategy: string;
  pageNum: number;
  pageSize: number;
  refreshTime: number;
}


// 为空的值不声明,需要时再加
export interface operDataListItem {
  objectId: string;
  objectType: string;
  relId: string;
  relType: string;
  channelId: string;
}

export interface compListItem {
  compStyle: string;
  compType: string;
  hasMore: number;
  recommend: number;
  operDataList: operDataListItem[];
}

export interface getRecCompInfoResult {
  blockDesc: string;
  id: number;
  name: string;
  pageId: string;
  pageNum: number;
  pageSize: number;
  recommend: number;
  totalCount: number;
  compList: compListItem[]
}

export interface IStatusContentList {
  contentId: string;

  // relType: string;
  contentType: string;
  // contentRelId: string;
}

export interface batchLikeAndCollectParams {
  // userType: number;
  // userId: string;
  contentList: IStatusContentList[]
}

export interface batchLikeAndCollectResult {
  collectStatus: number;
  contentType: string;
  likeStatus: string;
  relType: string;
  contentId: string;
  contentRelId: string;
}

export interface postBatchAttentionStatusParamsItem {
  creatorId: string;
}

export interface postBatchAttentionStatusParams {
  creatorIds: postBatchAttentionStatusParamsItem[]
}

export interface postBatchAttentionStatusResult {
  creatorId: string;
  status: string;
  userId: string;
}


export interface postExecuteLikeParams {
  status: string;
  contentId: string;
  contentType: string;
  relType?: string;
  userName?: string;
  title?: string;
  contentRelId?: string;
  userHeaderUrl?: string;
  channelId?: string;
}

export interface postExecuteCollectRecordParamsItem {
  contentId: string;
  contentType: string;
  relType?: string;
  contentRelId?: string;
}

export interface postExecuteCollectRecordParams {
  status: string;
  contentList: postExecuteCollectRecordParamsItem[]
}

export interface postPointLevelOperateParams {
  operateType: number;
}

export interface postCommentPublishParams {
  targetId: string;
  keyArticle: string;
  commentPics: string;
  targetTitle: string;
  commentType: string;
  targetType: string;
  commentContent: string;
  parentId: string;
  rootCommentId: string;
}

export interface postInteractBrowsOperateParamsContent {
  browseTime: string;
  contentId: string;
  contentType: number;
}

export interface postInteractBrowsOperateParams {
  delStatus: number;
  contentList: postInteractBrowsOperateParamsContent[]
}

export interface postInteractAccentionOperateParams {
  attentionUserType: string;
  attentionUserId: string;
  attentionCreatorId: string;

  // userType: number;
  // userId: string;
  status: number;
}

export class ContentDetailRequest {
  static getContentDetailDataMock(context: Context): Promise<ResponseDTO<ContentDetailDTO[]>> {
    Logger.info(TAG, `getContentDetailDataMock start`);
    return ResourcesUtils.getResourcesJson<ResponseDTO<ContentDetailDTO[]>>(context, 'content_detail2.json')
  }

  // /**
  //  * 现网-新闻内容详情域名
  //  */
  // static readonly HOST2: string = "https://pdapis.pdnews.cn";
  /**
   * 新闻内容详情【get】接口
   */
  // static readonly CONTENT_DETAIL_PATH: string = "/api/rmrb-bff-display-zh/content/zh/c/content/detail";

  static getContentDetailUrl(contentId: string, relId: string, relType: string) {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.DETAIL_PATH
    url = url + "?&contentId=" + contentId
      + "&relId=" + relId
      + "&relType=" + relType;
    return url;
  }

  static getContentDetail(params: ContentDetailRequestParams): Promise<ResponseDTO<ContentDetailDTO[]>> {
    if (mock_switch) {
      return ContentDetailRequest.getContentDetailDataMock(getContext());
    }
    let url = ContentDetailRequest.getContentDetailUrl(params.contentId, params.relId, params.relType)
    return WDHttp.get<ResponseDTO<ContentDetailDTO[]>>(url)
  }

  /**
   * 查询沉浸式视频频道推荐楼层数据
   * @returns
   */
  static getRecCompInfo(params: getRecCompInfoParams): Promise<ResponseDTO<getRecCompInfoResult>> {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.DISPLAY_REC_COMPINFO
    return WDHttp.request({ url, method: 'GET', params, headers: HttpRequest.buildHeaderWithGlobalHeader() })
  }

  /**
   * 批量查询沉浸式视频详情
   * @returns
   */
  static batchContentDetail(params: batchContentDetailParams): Promise<ResponseDTO<ContentDetailDTO[]>> {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.DETAIL_PATH
    return WDHttp.request({
      url,
      method: 'POST',
      data: params,
      headers: HttpRequest.buildHeaderWithGlobalHeader()
    })
  }


  /**
   * 批量查询作品点赞、收藏、分享、阅读、评论数量
   * @returns
   */
  static getContentInteract(params: contentListParams): Promise<ResponseDTO<InteractDataDTO[]>> {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_DATA_PATH
    return WDHttp.post(url, params)
  }

  /**
   * 批量查询作品查询点赞、收藏状态
   * @returns
   */
  static postBatchLikeAndCollectStatus(params: batchLikeAndCollectParams): Promise<ResponseDTO<batchLikeAndCollectResult[]>> {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_DATA_STATUS
    return WDHttp.post(url, params)
  }

  /**
   * 批量查号主是否为用户关注
   * @returns
   */
  static postBatchAttentionStatus(params: postBatchAttentionStatusParams): Promise<ResponseDTO<postBatchAttentionStatusResult[]>> {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.FOLLOW_LIST_STATUS_DATA_PATH
    return WDHttp.post(url, params)
  }


  /**
   * 沉浸式視頻查詢近20条数据
   * @returns
   */

  static postRecommendVideoList(params: recommentVideoListParams): Promise<ResponseDTO<ContentDetailDTO[]>> {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.RECOMMEND_VIDEOLIST
    return WDHttp.post(url, params)
  }

  /**
   * 用户点赞、取消点赞
   * @param params
   * @returns
   */
  static postExecuteLike(params: postExecuteLikeParams): Promise<ResponseDTO> {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_EXECUTELIKE
    return WDHttp.post(url, params)
  }

  /**
   * 用户收藏、取消收藏
   * @param params
   * @returns
   */
  static postExecuteCollectRecord(params: postExecuteCollectRecordParams): Promise<ResponseDTO> {
    let url = HttpUrlUtils.getExecuteCollcetUrl()
    return WDHttp.post(url, params)
  }

  /**
   *用户等级/积分-APP根据业务场景动态增减成长值(APP)
   * 操作类型:1阅读 2评论 3回复(积分任务同评论) 4分享 5点赞 6关注 7打开客户端 8上传头像 9打开推送开关
   */
  static postPointLevelOperate(params: postPointLevelOperateParams): Promise<ResponseDTO> {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.USERPOINT_OPERATE
    return WDHttp.post(url, params)
  }

  /**
   * 评论发布
   */
  static postCommentPublish(params: postCommentPublishParams): Promise<ResponseDTO> {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.COMMENT_PUBLISH
    return WDHttp.post(url, params)
  }


  /**
   * 浏览历史新增、删除接口
   */
  static postInteractBrowsOperate(params: postInteractBrowsOperateParams): Promise<ResponseDTO> {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_BROWS_OPERATE
    return WDHttp.post(url, params)
  }

  /**
   * 关注号主
   */
  private static postInteractAccentionOperateInfo(params: postInteractAccentionOperateParams): Promise<ResponseDTO> {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_ACCENTION_OPERATION
    return WDHttp.post(url, params)
  }

  /**
   * 关注号主
   */
  static postInteractAccentionOperate(params: postInteractAccentionOperateParams): Promise<ResponseDTO> {
    return new Promise<ResponseDTO>((success, error) => {
      Logger.debug(TAG, `postInteractAccentionOperate pageInfo start`);
      ContentDetailRequest.postInteractAccentionOperateInfo(params)
        .then((resDTO: ResponseDTO) => {
          if (!resDTO || resDTO.code != 0) {
            error(null)
            return
          }
          Logger.debug(TAG, "postInteractAccentionOperate then,navResDTO.timestamp:" + resDTO.timestamp);
          // 关注号后发送-更新关注页面
          EmitterUtils.sendEvent(EmitterEventId.PEOPLE_SHIP_ATTENTION)
          success(resDTO);
        })
        .catch((err: Error) => {
          Logger.error(TAG, `postInteractAccentionOperate catch, error.name : ${err.name},  error.message:${err.message}`);
          error(err);
        })
    })
  }
}