Showing
5 changed files
with
106 additions
and
24 deletions
| @@ -38,4 +38,7 @@ export class SpConstants{ | @@ -38,4 +38,7 @@ export class SpConstants{ | ||
| 38 | //启动页数据存储key | 38 | //启动页数据存储key |
| 39 | static APP_LAUNCH_PAGE_DATA_MODEL = 'app_launch_page_data_model' | 39 | static APP_LAUNCH_PAGE_DATA_MODEL = 'app_launch_page_data_model' |
| 40 | 40 | ||
| 41 | + //频道信息流页面左右挂角 | ||
| 42 | + static APP_PAGE_CORNER_ADV = 'app_page_corner_adv_' | ||
| 43 | + | ||
| 41 | } | 44 | } |
| @@ -68,14 +68,9 @@ export interface CompAdvBean { | @@ -68,14 +68,9 @@ export interface CompAdvBean { | ||
| 68 | displayPriority: number; | 68 | displayPriority: number; |
| 69 | 69 | ||
| 70 | /** | 70 | /** |
| 71 | - * 展示的次数 | ||
| 72 | - */ | ||
| 73 | - showCount: number; | ||
| 74 | - | ||
| 75 | - /** | ||
| 76 | * 页面id | 71 | * 页面id |
| 77 | */ | 72 | */ |
| 78 | - pageId: String ; | 73 | + pageId: String; |
| 79 | 74 | ||
| 80 | /** | 75 | /** |
| 81 | * 开屏广告-显示时长 | 76 | * 开屏广告-显示时长 |
| @@ -97,6 +92,4 @@ export interface CompAdvBean { | @@ -97,6 +92,4 @@ export interface CompAdvBean { | ||
| 97 | displayRound: number; | 92 | displayRound: number; |
| 98 | 93 | ||
| 99 | 94 | ||
| 100 | - | ||
| 101 | - | ||
| 102 | } | 95 | } |
| @@ -65,7 +65,6 @@ export struct PageComponent { | @@ -65,7 +65,6 @@ export struct PageComponent { | ||
| 65 | this.pageModel.pullDownRefreshText, this.pageModel.pullDownRefreshHeight) | 65 | this.pageModel.pullDownRefreshText, this.pageModel.pullDownRefreshHeight) |
| 66 | }) | 66 | }) |
| 67 | } | 67 | } |
| 68 | - | ||
| 69 | LazyForEach(this.pageModel.compList, (compDTO: CompDTO, compIndex: number) => { | 68 | LazyForEach(this.pageModel.compList, (compDTO: CompDTO, compIndex: number) => { |
| 70 | ListItem() { | 69 | ListItem() { |
| 71 | Column() { | 70 | Column() { |
| @@ -124,9 +123,10 @@ export struct PageComponent { | @@ -124,9 +123,10 @@ export struct PageComponent { | ||
| 124 | 123 | ||
| 125 | if (this.pageAdvModel.isShowAds) { | 124 | if (this.pageAdvModel.isShowAds) { |
| 126 | if (this.pageAdvModel.pageCornerAdv.matInfo != null) { | 125 | if (this.pageAdvModel.pageCornerAdv.matInfo != null) { |
| 127 | - // 页面右边挂角 | 126 | + // 广告中心的挂角广告 |
| 128 | this.drawPageCornerAdvView(1, 1 == this.pageAdvModel.isRightAdv) | 127 | this.drawPageCornerAdvView(1, 1 == this.pageAdvModel.isRightAdv) |
| 129 | } else if (this.pageAdvModel.pageCornerContentInfo.advert != null) { | 128 | } else if (this.pageAdvModel.pageCornerContentInfo.advert != null) { |
| 129 | + // 展现中心的挂角广告业务 | ||
| 130 | this.drawPageCornerAdvView(2, 1 == this.pageAdvModel.isRightAdv) | 130 | this.drawPageCornerAdvView(2, 1 == this.pageAdvModel.isRightAdv) |
| 131 | } | 131 | } |
| 132 | } | 132 | } |
| 1 | import { PageInfoDTO } from 'wdBean/Index'; | 1 | import { PageInfoDTO } from 'wdBean/Index'; |
| 2 | import { AdvRuleBean, CompAdvBean } from 'wdBean/src/main/ets/bean/adv/AdvsRuleBean'; | 2 | import { AdvRuleBean, CompAdvBean } from 'wdBean/src/main/ets/bean/adv/AdvsRuleBean'; |
| 3 | +import { DateTimeUtils, SPHelper } from 'wdKit/Index'; | ||
| 4 | +import { ArrayList } from '@kit.ArkTS'; | ||
| 5 | +import { SpConstants } from 'wdConstant/Index'; | ||
| 3 | 6 | ||
| 4 | /** | 7 | /** |
| 5 | * @Description: 处理页面的广告业务 | 8 | * @Description: 处理页面的广告业务 |
| @@ -18,16 +21,11 @@ export default class PageAdModel { | @@ -18,16 +21,11 @@ export default class PageAdModel { | ||
| 18 | // 1:右边;2:左边 -> 默认右边 | 21 | // 1:右边;2:左边 -> 默认右边 |
| 19 | pageCornerContentInfo: AdvRuleBean = {} as AdvRuleBean | 22 | pageCornerContentInfo: AdvRuleBean = {} as AdvRuleBean |
| 20 | 23 | ||
| 21 | - // 展现中心业务信息 | ||
| 22 | - | ||
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | /** | 24 | /** |
| 27 | * 解析广告资源 | 25 | * 解析广告资源 |
| 28 | * @param pageInfo | 26 | * @param pageInfo |
| 29 | */ | 27 | */ |
| 30 | - analysisAdvSource(pageInfo: PageInfoDTO): void { | 28 | + async analysisAdvSource(pageInfo: PageInfoDTO) { |
| 31 | 29 | ||
| 32 | if (pageInfo.hasAdInfo === 1 && pageInfo.cornersAdv != null) { | 30 | if (pageInfo.hasAdInfo === 1 && pageInfo.cornersAdv != null) { |
| 33 | // 优先展示展现中心广告 | 31 | // 优先展示展现中心广告 |
| @@ -55,12 +53,26 @@ export default class PageAdModel { | @@ -55,12 +53,26 @@ export default class PageAdModel { | ||
| 55 | } else if (pageInfo.cornersAdv2 != null && pageInfo.cornersAdv2.length > 0) { | 53 | } else if (pageInfo.cornersAdv2 != null && pageInfo.cornersAdv2.length > 0) { |
| 56 | // 广告中心-挂角广告信息 | 54 | // 广告中心-挂角广告信息 |
| 57 | let cornersAdv2 = pageInfo.cornersAdv2 | 55 | let cornersAdv2 = pageInfo.cornersAdv2 |
| 58 | - // 获取 | ||
| 59 | - let showCompAdvBean = cornersAdv2[0] | 56 | + |
| 57 | + if (cornersAdv2.length == 0) { | ||
| 58 | + return | ||
| 59 | + } | ||
| 60 | + // 加工处理广告中心的广告数据 | ||
| 61 | + let pageCoreAdvArray = this.treatPageInfoAdsData(cornersAdv2); | ||
| 62 | + | ||
| 63 | + let advLength = pageCoreAdvArray.length; | ||
| 64 | + let pageId = pageInfo.id.toString(); | ||
| 65 | + let a = 0; | ||
| 66 | + if (advLength > 1) { | ||
| 67 | + a = await this.calPageAdvIndex(pageId,advLength) | ||
| 68 | + } | ||
| 69 | + // 获取投放 | ||
| 70 | + let showCompAdvBean = pageCoreAdvArray.convertToArray()[a] | ||
| 60 | 71 | ||
| 61 | if (showCompAdvBean.matInfo == null) { | 72 | if (showCompAdvBean.matInfo == null) { |
| 62 | return | 73 | return |
| 63 | } | 74 | } |
| 75 | + this.saveReleaseAdvIndex(pageId, a) | ||
| 64 | // | 76 | // |
| 65 | let slotInfo = showCompAdvBean.slotInfo; | 77 | let slotInfo = showCompAdvBean.slotInfo; |
| 66 | let postion = slotInfo.position | 78 | let postion = slotInfo.position |
| @@ -76,4 +88,84 @@ export default class PageAdModel { | @@ -76,4 +88,84 @@ export default class PageAdModel { | ||
| 76 | } | 88 | } |
| 77 | 89 | ||
| 78 | } | 90 | } |
| 91 | + /** | ||
| 92 | + * 计算投放广告的序列号 | ||
| 93 | + * @param pageId | ||
| 94 | + * @param advLength | ||
| 95 | + * @returns | ||
| 96 | + */ | ||
| 97 | + private async calPageAdvIndex(pageId: string , advLength: number): Promise<number>{ | ||
| 98 | + | ||
| 99 | + let index = await this.obtainReleaseAdvIndex(pageId); | ||
| 100 | + let a = await index + 1; | ||
| 101 | + if (a >= advLength) { | ||
| 102 | + a = 0; | ||
| 103 | + } | ||
| 104 | + return a; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 获取已投放挂角广告的编号 | ||
| 109 | + * @param pageId | ||
| 110 | + * @returns | ||
| 111 | + */ | ||
| 112 | + private async obtainReleaseAdvIndex(pageId: string): Promise<number> { | ||
| 113 | + | ||
| 114 | + let index: number = await SPHelper.default.get(SpConstants.APP_PAGE_CORNER_ADV + pageId, -1) as number; | ||
| 115 | + | ||
| 116 | + return index; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * 存储已经投放广告的编号 | ||
| 121 | + * @param pageId | ||
| 122 | + * @param index | ||
| 123 | + */ | ||
| 124 | + private async saveReleaseAdvIndex(pageId: string, index: number) { | ||
| 125 | + await SPHelper.default.save(SpConstants.APP_PAGE_CORNER_ADV + pageId, index) | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * 删除数据 | ||
| 130 | + * @param pageId | ||
| 131 | + */ | ||
| 132 | + private async clearHistoryAdvIndex(pageId: string){ | ||
| 133 | + | ||
| 134 | + SPHelper.default.deleteSync(SpConstants.APP_PAGE_CORNER_ADV + pageId) | ||
| 135 | + | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + private checkPageCornerAdv(pageId: string): Promise<boolean> { | ||
| 139 | + let haveData = SPHelper.default.has(SpConstants.APP_PAGE_CORNER_ADV + pageId) | ||
| 140 | + return haveData | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + /** | ||
| 144 | + * 对广告中心的广告 数据按不同维度加工 筛选出符合的数据 | ||
| 145 | + * @param cornersAdv2 页面的广告数据 | ||
| 146 | + * @param pageId 所在页面pageid | ||
| 147 | + */ | ||
| 148 | + private treatPageInfoAdsData(cornersAdv2: CompAdvBean[]): ArrayList<CompAdvBean> { | ||
| 149 | + | ||
| 150 | + // 按时间维度过滤出广告数据 | ||
| 151 | + let compAdsArray: ArrayList<CompAdvBean> = new ArrayList(); | ||
| 152 | + let serverTimeLong: number = DateTimeUtils.getTimeStamp(); | ||
| 153 | + for (let advBean of cornersAdv2) { | ||
| 154 | + let startLong = advBean.startTime; | ||
| 155 | + let endLong = advBean.endTime; | ||
| 156 | + | ||
| 157 | + if (serverTimeLong >= startLong && serverTimeLong <= endLong) { | ||
| 158 | + //符合开始时间和结束时间要求 | ||
| 159 | + compAdsArray.add(advBean) | ||
| 160 | + } | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + //按展现优先级维度 数值越小,等级越高 | ||
| 164 | + if (compAdsArray.length > 1) { | ||
| 165 | + //B、按展现优先级维度 数值越小,等级越高 | ||
| 166 | + compAdsArray.sort((a: CompAdvBean, b: CompAdvBean) => a.displayPriority - b.displayPriority) | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + return compAdsArray; | ||
| 170 | + } | ||
| 79 | } | 171 | } |
| @@ -51,12 +51,6 @@ export default class PageModel { | @@ -51,12 +51,6 @@ export default class PageModel { | ||
| 51 | // keyGenerator相关字符串,用于刷新list布局 | 51 | // keyGenerator相关字符串,用于刷新list布局 |
| 52 | timestamp: String = '1'; | 52 | timestamp: String = '1'; |
| 53 | 53 | ||
| 54 | - // //左右挂角广告对象 | ||
| 55 | - // pageCornerAdv:CompAdvBean = {} as CompAdvBean // 挂角广告 | ||
| 56 | - // isShowAds : boolean = false; | ||
| 57 | - // isRightAdv : number = 1;// 1:右边;2:左边 -> 默认右边 | ||
| 58 | - // pageCornerContentInfo:AdvRuleBean = {} as AdvRuleBean // 展现中心业务信息 | ||
| 59 | - | ||
| 60 | 54 | ||
| 61 | /** | 55 | /** |
| 62 | * 简单复制业务数据 | 56 | * 简单复制业务数据 |
-
Please register or login to post a comment