Browse Source

场景报表修改

jun.zhou 9 years ago
parent
commit
266ac62011

+ 107 - 0
src/main/java/com/cloudcross/ssp/model/mapper/report.sql.xml

@@ -1892,4 +1892,111 @@ sum(click) as totalClick, if(sum(a.impression) > 0,sum(a.click)/sum(a.impression
 		  </where> 
 	</select>
 	
+	<!-- 没有关联媒体的场景报表 -->
+	<select id="queryPlaceName" parameterType="java.util.Map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select d.name placeName,SUM(a.impression) impression, SUM(a.click) click,100*SUM(a.click)/SUM(a.impression) clickRate,SUM(a.visit) visit,
+		100*SUM(a.visit)/SUM(a.click) visitRate,SUM(a.conversion) conversion,100*SUM(a.conversion)/SUM(a.visit) conversionRate,SUM(a.ecpm) as ecpm, SUM(a.consume) consume
+		from t_rpt_adv_place a,t_place b,t_place_class c,t_place_class_info d,t_account e where a.place_id = b.id and b.id = c.place_id and c.place_id = d.id and e.advertiser_id = a.advertiser_id
+		<if test="agentId != null">
+			and e.agent_id  = #{agentId}
+		</if>
+		<if test="advertiserId != null">
+			and a.advertiser_id = #{advertiserId}
+		</if>
+		<if test="orderId != null">
+			and a.order_id = #{orderId}
+		</if>
+		<if test="campaignId != null">
+			and a.campaign_id = #{campaignId}
+		</if>
+		<if test="adGroupId != null">
+			and a.adgroup_id = #{adGroupId}
+		</if>
+		<if test="startDate != null and endDate != null">
+			and a.date &gt;= #{startDate} and a.date &lt;= #{endDate}
+		</if>
+		 group by d.name
+		 limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<!-- 没有关联媒体的场景报表的记录条数 -->
+	<select id="queryPlaceCount" parameterType="java.util.Map" resultType="java.lang.Integer">
+		select count(1) from (
+			select d.name placeName,SUM(a.impression) impression, SUM(a.click) click,100*SUM(a.click)/SUM(a.impression) clickRate,SUM(a.visit) visit,
+			100*SUM(a.visit)/SUM(a.click) visitRate,SUM(a.conversion) conversion,100*SUM(a.conversion)/SUM(a.visit) conversionRate,SUM(a.ecpm) as ecpm, SUM(a.consume) consume
+			from t_rpt_adv_place a,t_place b,t_place_class c,t_place_class_info d,t_account e where a.place_id = b.id and b.id = c.place_id and c.place_id = d.id and e.advertiser_id = a.advertiser_id
+			<if test="agentId != null">
+				and e.agent_id  = #{agentId}
+			</if>
+			<if test="advertiserId != null">
+				and a.advertiser_id = #{advertiserId}
+			</if>
+			<if test="orderId != null">
+				and a.order_id = #{orderId}
+			</if>
+			<if test="campaignId != null">
+				and a.campaign_id = #{campaignId}
+			</if>
+			<if test="adGroupId != null">
+				and a.adgroup_id = #{adGroupId}
+			</if>
+			<if test="startDate != null and endDate != null">
+				and a.date &gt;= #{startDate} and a.date &lt;= #{endDate}
+			</if>
+			 group by d.name
+		) t
+	</select>
+	
+	<select id="queryPlaceCountWithOperator" parameterType="java.util.Map" resultType="java.lang.Integer">
+		select count(1) from (
+			select b.name placeName,SUM(a.impression) impression, SUM(a.click) click,100*SUM(a.click)/SUM(a.impression) clickRate,SUM(a.visit) visit,
+			100*SUM(a.visit)/SUM(a.click) visitRate,SUM(a.conversion) conversion,100*SUM(a.conversion)/SUM(a.visit) conversionRate,SUM(a.ecpm) as ecpm, SUM(a.consume) consume
+			from t_rpt_adv_place a,t_place_operator b,t_account c  where a.place_id = b.place_id and a.advertiser_id = c.advertiser_id  
+			<if test="agentId != null">
+				and c.agent_id = #{agentId}
+			</if>
+			<if test="advertiserId != null">
+				and a.advertiser_id = #{advertiserId}
+			</if>
+			<if test="orderId != null">
+				and a.order_id = #{orderId}
+			</if>
+			<if test="campaignId != null">
+				and a.campaign_id = #{campaignId}
+			</if>
+			<if test="adGroupId != null">
+				and a.adgroup_id = #{adGroupId}
+			</if>
+			<if test="startDate != null and endDate != null">
+				and a.date &gt;= #{startDate} and a.date &lt;= #{endDate}
+			</if>
+			group by b.name
+		)t
+	</select>
+	
+	<select id="queryPlaceNameWithOperator" parameterType="java.util.Map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select b.name placeName,SUM(a.impression) impression, SUM(a.click) click,100*SUM(a.click)/SUM(a.impression) clickRate,SUM(a.visit) visit,
+		100*SUM(a.visit)/SUM(a.click) visitRate,SUM(a.conversion) conversion,100*SUM(a.conversion)/SUM(a.visit) conversionRate,SUM(a.ecpm) as ecpm, SUM(a.consume) consume
+		from t_rpt_adv_place a,t_place_operator b,t_account c  where a.place_id = b.place_id and a.advertiser_id = c.advertiser_id  
+		<if test="agentId != null">
+			and c.agent_id = #{agentId}
+		</if>
+		<if test="advertiserId != null">
+			and a.advertiser_id = #{advertiserId}
+		</if>
+		<if test="orderId != null">
+			and a.order_id = #{orderId}
+		</if>
+		<if test="campaignId != null">
+			and a.campaign_id = #{campaignId}
+		</if>
+		<if test="adGroupId != null">
+			and a.adgroup_id = #{adGroupId}
+		</if>
+		<if test="startDate != null and endDate != null">
+			and a.date &gt;= #{startDate} and a.date &lt;= #{endDate}
+		</if>
+		group by b.name
+		limit #{pager.offset}, #{pager.limit}
+	</select>
 </mapper>

+ 5 - 0
src/main/java/com/cloudcross/ssp/service/IAdReportService.java

@@ -151,4 +151,9 @@ public interface IAdReportService extends IGenericService<DeliverAnalysis>{
     DeliverAnalysis findSumOperator(Map<String, Object> paramMap);
     
     List<DeliverAnalysis> findAllAreaOperator(Map<String, Object> paramMap);
+    
+    public Integer queryPlaceCount(Map<String,Object>condition);
+    public List<DeliverAnalysis> queryPlaceName(Map<String,Object>condition,Pager pager);
+    public Integer queryPlaceCountWithOperatorId(Map<String, Object> condition);
+    public List<DeliverAnalysis> queryPlaceNameWithOperatorId(Map<String, Object>condition,Pager pager);
 }

+ 21 - 0
src/main/java/com/cloudcross/ssp/service/impl/AdReportService.java

@@ -594,5 +594,26 @@ public class AdReportService implements IAdReportService {
 		return null;
 	}
 
+	@Override
+	public Integer queryPlaceCount(Map<String, Object> condition) {
+		return iBatisDao.get("adReportSqlMapper.queryPlaceCount", condition);
+	}
+
+	@Override
+	public List<DeliverAnalysis> queryPlaceName(Map<String, Object> condition,Pager pager) {
+		condition.put("pager", pager);
+		return iBatisDao.getList("adReportSqlMapper.queryPlaceName", condition);
+	}
+	
+	public Integer queryPlaceCountWithOperatorId(Map<String, Object> condition) {
+		return iBatisDao.get("adReportSqlMapper.queryPlaceCount", condition);
+	}
+	
+	
+	public List<DeliverAnalysis> queryPlaceNameWithOperatorId(Map<String, Object> condition,Pager pager) {
+		condition.put("pager", pager);
+		return iBatisDao.getList("adReportSqlMapper.queryPlaceName", condition);
+	}
+
 	
 }

+ 164 - 155
src/main/java/com/cloudcross/ssp/web/advertiser/main/ad/report/AdvertiserReportController.java

@@ -784,166 +784,175 @@ public class AdvertiserReportController extends SimpleController {
 	
 	//下面是场景报表
 	@RequestMapping("/sceneReport")
-	public String sceneReport(Model model,
-			@RequestParam HashMap<String, Object> paramMap,
-			@RequestParam(defaultValue="1") int page) {
+	public String sceneReport(Model model,@RequestParam HashMap<String, Object> paramMap,@RequestParam(defaultValue="1") int page) {
 		
 		//日期
-				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-				String startDate = null;
-				String endDate = null;
-				
-				//广告主,订单,活动,投放
-				Long advertiserId = null;
-				Long orderId = null;
-				Long campaignId = null;
-				Long adGroupId = null;
-				
-				String advertiserName = "全部广告主";
-				String orderName = "全部订单";
-				String campaignName = "全部活动";
-				String adGroupName = "全部投放";
-				/**
-				 * 下面对下拉框中传进来的值进行判断,若是未操作,则为空值,前端设置时默认为全部(-1)
-				 * 注意前后层次关系,同时要考虑到登录帐号权限问题,此时暂未考虑
-				 * 下拉框传值Id需要同步
-				 */
-				
-				//广告主选择与否
-				if (null == paramMap.get("selectedadvertiserId")
-							|| "".equals(paramMap.get("selectedadvertiserId"))) {
-						advertiserId = null;
-						advertiserName = "全部广告主";
-					} else {
-						// 如果要查询的是所有广告主则让广告主id为空
-						if (-1 == Long.parseLong((String) paramMap
-								.get("selectedadvertiserId"))) {
-							advertiserId = null;
-							advertiserName = "全部广告主";
-						} else {
-							advertiserId = Long.parseLong((String) paramMap
-									.get("selectedadvertiserId"));
-							advertiserName = advertiserService.findById(advertiserId).getName();
-						}
-					}
-				
-				//订单选择与否
-				if (null == paramMap.get("selectedorderId")
-						|| "".equals(paramMap.get("selectedorderId"))) {
-					orderId = null;
-					orderName = "全部订单";
-				} else {
-					if (-1 == Long.parseLong((String) paramMap
-							.get("selectedorderId"))) {
-						orderId = null;
-						orderName = "全部订单";
-					} else {
-						orderId = Long.parseLong((String) paramMap
-								.get("selectedorderId"));
-						orderName = orderService.findById(orderId).getName();
-					}
-				}
-				
-				//活动选择与否
-				if (null == paramMap.get("selectedcampaignId")
-						|| "".equals(paramMap.get("selectedcampaignId"))) {
-					campaignId = null;
-					campaignName = "全部活动";
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+		String startDate = null;
+		String endDate = null;
+		
+		//广告主,订单,活动,投放
+		Long advertiserId = null;
+		Long orderId = null;
+		Long campaignId = null;
+		Long adGroupId = null;
+		
+		String advertiserName = "全部广告主";
+		String orderName = "全部订单";
+		String campaignName = "全部活动";
+		String adGroupName = "全部投放";
+		/**
+		 * 下面对下拉框中传进来的值进行判断,若是未操作,则为空值,前端设置时默认为全部(-1)
+		 * 注意前后层次关系,同时要考虑到登录帐号权限问题,此时暂未考虑
+		 * 下拉框传值Id需要同步
+		 */
+		
+		//广告主选择与否
+		if (null == paramMap.get("selectedadvertiserId")
+					|| "".equals(paramMap.get("selectedadvertiserId"))) {
+				advertiserId = null;
+				advertiserName = "全部广告主";
+			} else {
+				// 如果要查询的是所有广告主则让广告主id为空
+				if (-1 == Long.parseLong((String) paramMap
+						.get("selectedadvertiserId"))) {
+					advertiserId = null;
+					advertiserName = "全部广告主";
 				} else {
-					if (-1 == Long.parseLong((String) paramMap
-							.get("selectedcampaignId"))) {
-						campaignId = null;
-						campaignName = "全部活动";
-					} else {
-						campaignId = Long.parseLong((String) paramMap
-								.get("selectedcampaignId"));
-						campaignName = campaignService.findById(campaignId).getName();
-					}
+					advertiserId = Long.parseLong((String) paramMap
+							.get("selectedadvertiserId"));
+					advertiserName = advertiserService.findById(advertiserId).getName();
 				}
-				
-				//投放选择与否
-				if (null == paramMap.get("selectedadGroupId")
-						|| "".equals(paramMap.get("selectedadGroupId"))) {
-					adGroupId = null;
-					adGroupName = "全部投放";
-				} else {
-					if (-1 == Long.parseLong((String) paramMap
-							.get("selectedadGroupId"))) {
-						adGroupId = null;
-						adGroupName = "全部投放";
-					} else {
-						adGroupId = Long.parseLong((String) paramMap
-								.get("selectedadGroupId"));
-						adGroupName = adGroupService.findById(adGroupId).getAdGroupName();
-					}
-				}		
-							
-					//判断日期是否为默认值昨天,日期格式与上面相统一,用 to 分割
-					if (null == paramMap.get("dateRangePicker")
-							|| "".equals(paramMap.get("dateRangePicker"))) {
-						startDate = endDate = sdf.format(new Date((new Date())
-								.getTime() - 24 * 60 * 60 * 1000));
-					} else {
-						String[] choosedDate = ((String) paramMap
-								.get("dateRangePicker")).split("to");
-						startDate = choosedDate[0].trim();
-						endDate = choosedDate[1].trim();
-					} 
-				
-				paramMap.put("advertiserId", advertiserId);
-				paramMap.put("orderId", orderId);
-				paramMap.put("campaignId", campaignId);
-				paramMap.put("adGroupId",  adGroupId);
-				paramMap.put("selectedadvertiserName", advertiserName);
-				paramMap.put("selectedorderName", orderName);
-				paramMap.put("selectedcampaignName", campaignName);
-				paramMap.put("selectedadGroupName",  adGroupName);
-				paramMap.put("startDate",  startDate);
-				paramMap.put("endDate",  endDate);
-				
-				//查询搜索对应的数据
-				int totalRow = adReportService.findCountForScene(paramMap);
+			}
+		
+		//订单选择与否
+		if (null == paramMap.get("selectedorderId")
+				|| "".equals(paramMap.get("selectedorderId"))) {
+			orderId = null;
+			orderName = "全部订单";
+		} else {
+			if (-1 == Long.parseLong((String) paramMap
+					.get("selectedorderId"))) {
+				orderId = null;
+				orderName = "全部订单";
+			} else {
+				orderId = Long.parseLong((String) paramMap
+						.get("selectedorderId"));
+				orderName = orderService.findById(orderId).getName();
+			}
+		}
+		
+		//活动选择与否
+		if (null == paramMap.get("selectedcampaignId")
+				|| "".equals(paramMap.get("selectedcampaignId"))) {
+			campaignId = null;
+			campaignName = "全部活动";
+		} else {
+			if (-1 == Long.parseLong((String) paramMap
+					.get("selectedcampaignId"))) {
+				campaignId = null;
+				campaignName = "全部活动";
+			} else {
+				campaignId = Long.parseLong((String) paramMap
+						.get("selectedcampaignId"));
+				campaignName = campaignService.findById(campaignId).getName();
+			}
+		}
+		
+		//投放选择与否
+		if (null == paramMap.get("selectedadGroupId")
+				|| "".equals(paramMap.get("selectedadGroupId"))) {
+			adGroupId = null;
+			adGroupName = "全部投放";
+		} else {
+			if (-1 == Long.parseLong((String) paramMap
+					.get("selectedadGroupId"))) {
+				adGroupId = null;
+				adGroupName = "全部投放";
+			} else {
+				adGroupId = Long.parseLong((String) paramMap
+						.get("selectedadGroupId"));
+				adGroupName = adGroupService.findById(adGroupId).getAdGroupName();
+			}
+		}		
+					
+			//判断日期是否为默认值昨天,日期格式与上面相统一,用 to 分割
+			if (null == paramMap.get("dateRangePicker")
+					|| "".equals(paramMap.get("dateRangePicker"))) {
+				startDate = endDate = sdf.format(new Date((new Date())
+						.getTime() - 24 * 60 * 60 * 1000));
+			} else {
+				String[] choosedDate = ((String) paramMap
+						.get("dateRangePicker")).split("to");
+				startDate = choosedDate[0].trim();
+				endDate = choosedDate[1].trim();
+			} 
+		
+		paramMap.put("advertiserId", advertiserId);
+		paramMap.put("orderId", orderId);
+		paramMap.put("campaignId", campaignId);
+		paramMap.put("adGroupId",  adGroupId);
+		paramMap.put("selectedadvertiserName", advertiserName);
+		paramMap.put("selectedorderName", orderName);
+		paramMap.put("selectedcampaignName", campaignName);
+		paramMap.put("selectedadGroupName",  adGroupName);
+		paramMap.put("startDate",  startDate);
+		paramMap.put("endDate",  endDate);
+		
+		//查询搜索对应的数据
+		int totalRow = 0;
+		List<DeliverAnalysis> reportList = null;
+		Pager pager = new Pager();
+		pager.setPage(page);
+		Account account = getLoginUser();
+		paramMap.put("agentId", account.getAgentId());
+		if(account.getAdvertiserId() != 0){
+			paramMap.put("advertiserId", account.getAdvertiserId());
+		}
+		Long operatorId = getLoginUser().getOperatorId();
+		if(operatorId == 0){//当前账户没有关联媒体,显示大场景
+			totalRow = adReportService.queryPlaceCount(paramMap);
+			pager.setTotalRow(totalRow);
+			reportList = adReportService.queryPlaceName(paramMap,pager);
+		}else{//当前账户关联了媒体,显示媒体自己的场景
+			totalRow = adReportService.queryPlaceCountWithOperatorId(paramMap);
+			pager.setTotalRow(totalRow);
+			reportList = adReportService.queryPlaceNameWithOperatorId(paramMap, pager);
+		}
+
+		if(reportList.size() == 0){
+			DeliverAnalysis map = new DeliverAnalysis();
+			DeliverAnalysis deliver = new DeliverAnalysis();
+			deliver.setImpression(0);
+			deliver.setClick(0);
+			deliver.setVisit(0);
+			deliver.setConversion(0);
+			deliver.setConsume(0);
+			deliver.seteCmp(0);
+			deliver.setClickRate(0);
+			deliver.setVisitRate(0);
+			deliver.setConversionRate(0);
+			map = deliver;
+			model.addAttribute("reportMap", map);
+		}else{
+			int impressionSum = 0;
+			//场景总曝光数
+			for(DeliverAnalysis d:reportList){
+				impressionSum += d.getImpression();
+			}
+			double impressionRate = 0d;
+			for(DeliverAnalysis de:reportList){
+				impressionRate = 100.0*de.getImpression()/impressionSum;
+				de.setImpressionRate(impressionRate);
+			}
 			
-				Pager pager = new Pager();
-				pager.setPage(page);
-				pager.setTotalRow(totalRow);
-				
-				List<DeliverAnalysis> reportList = adReportService.findByPlaceName(paramMap, pager);
-				
-				if(reportList.size() == 0){
-					DeliverAnalysis map = new DeliverAnalysis();
-					DeliverAnalysis deliver = new DeliverAnalysis();
-					deliver.setImpression(0);
-					deliver.setClick(0);
-					deliver.setVisit(0);
-					deliver.setConversion(0);
-					deliver.setConsume(0);
-					deliver.seteCmp(0);
-					deliver.setClickRate(0);
-					deliver.setVisitRate(0);
-					deliver.setConversionRate(0);
-					map = deliver;
-					model.addAttribute("reportMap", map);
-				}else {
-				//数据报表中第一栏 全部  的显示
-				HashMap<String,Double> map = new HashMap<String,Double>();
-				map.put("impressionSum", reportList.get(0).getImpressionSum());
-				map.put("clickSum", reportList.get(0).getClickSum());
-				map.put("visitSum", reportList.get(0).getVisitSum());
-				map.put("conversionSum", reportList.get(0).getConversionSum());
-				map.put("consumeSum", reportList.get(0).getConsumeSum());
-				map.put("eCmpSum", reportList.get(0).geteCmpSum());
-				map.put("clickRatesum", reportList.get(0).getClickRatesum());
-				map.put("visitRatesum", reportList.get(0).getVisitRatesum());
-				map.put("conversionRatesum", reportList.get(0).getConversionRatesum());
-				model.addAttribute("reportMap", map);
-				}
-				
-				
-				model.addAllAttributes(paramMap);
-				model.addAttribute("pager", pager);
-				model.addAttribute("reportList", reportList);
-		        return page("sceneReport");
+		}
+		
+		
+		model.addAllAttributes(paramMap);
+		model.addAttribute("pager", pager);
+		model.addAttribute("reportList", reportList);
+        return page("sceneReport");
 	}
 	
 	//数据报表导出

+ 1 - 1
src/main/webapp/WEB-INF/pages/advertiser/main/ad/report/advertiser-report/sceneReport.ftl

@@ -97,7 +97,7 @@
 				            <th class="theadTh hidden-consume" style="width:18%" colspan=2>花费</th>
 						</tr>
 						<tr class="theadTr">
-			               	<td class="theadTd" style="width:10%"></td>     
+			               	<td class="theadTd" style="width:10%">场景</td>     
 			                <td class="theadTd hidden-impression" style="width:9%">曝光占比</td>
 			                <td class="theadTd hidden-impression" style="width:9%">曝光数</td>
 			                <td class="theadTd hidden-click" style="width:9%">点击数</td>