TheatreAnalysisController.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. package com.ylcm.sys.controller;
  2. import javax.annotation.Resource;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.ylcm.sys.common.ExcelUtil;
  7. import com.ylcm.sys.common.Util;
  8. import com.ylcm.sys.domain.AdTv;
  9. import com.ylcm.sys.excel.model.SpecialAnalysisExportDTO;
  10. import com.ylcm.sys.service.AdTvService;
  11. import com.ylcm.sys.vo.*;
  12. import org.apache.commons.collections.CollectionUtils;
  13. import org.springframework.stereotype.Controller;
  14. import org.springframework.ui.ModelMap;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import com.baomidou.mybatisplus.core.metadata.IPage;
  17. import com.ylcm.sys.common.Constants;
  18. import com.ylcm.sys.form.AdTheatreAnalysisDetailQueryForm;
  19. import com.ylcm.sys.form.AdTheatreAnalysisQueryForm;
  20. import com.ylcm.sys.service.AdTheatreTvStatService;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.springframework.web.bind.annotation.RequestParam;
  23. import java.util.ArrayList;
  24. import java.util.Arrays;
  25. import java.util.List;
  26. import java.util.stream.Collectors;
  27. @Slf4j
  28. @Controller
  29. @RequestMapping("/theatre_analysis")
  30. public class TheatreAnalysisController extends BaseController{
  31. @Resource
  32. private AdTheatreTvStatService adTheatreTvStatService;
  33. @Resource
  34. private AdTvService adTvService;
  35. /**
  36. * @param keyword 电视剧名称
  37. * @return
  38. */
  39. @RequestMapping(value = "/index.do")
  40. public String brandAnalysis(ModelMap model,String keyword) {
  41. /**
  42. * 1.跳转到列表页面
  43. */
  44. model.put("keyword", keyword);
  45. return "analysis/theatre_analysis";
  46. }
  47. @RequestMapping(value = "/ajax_list.do")
  48. public void ajaxSearchList(HttpServletResponse response, AdTheatreAnalysisQueryForm queryForm) {
  49. try {
  50. IPage<AdTheatreAnalysisVO> page = adTheatreTvStatService.getPage(queryForm);
  51. /**
  52. * 3.返回结果
  53. */
  54. JSONObject jsonobj = new JSONObject();
  55. jsonobj.put("data", page);
  56. jsonobj.put("code", Constants.CODE_SUCCESS);
  57. ajaxJson(jsonobj.toString(), response);
  58. } catch (Exception e) {
  59. log.error(e.getMessage(), e);
  60. ajaxJson("{\"code\":\"0\",\"msg\":\"获取列表失败\"}", response);
  61. }
  62. }
  63. @RequestMapping(value = "/export_list.do")
  64. public void exportSearchList(HttpServletResponse response, AdTheatreAnalysisQueryForm queryForm) {
  65. ExcelUtil.exportExcelToWebsite(response,"央卫视电视剧收视指标",new AdTheatreAnalysisVO(),(currentPage, pageSize) -> {
  66. queryForm.setPageNo(currentPage);
  67. queryForm.setPageSize(pageSize);
  68. return adTheatreTvStatService.getPage(queryForm).getRecords();
  69. });
  70. }
  71. /**
  72. * 央卫视电视剧收视明细
  73. * @param response
  74. * @param queryForm
  75. */
  76. @RequestMapping(value = "/ajax_detail_list.do")
  77. public void ajaxDetailList(HttpServletResponse response, AdTheatreAnalysisDetailQueryForm queryForm) {
  78. try {
  79. IPage<AdTheatreAnalysisDetailVO> page = adTheatreTvStatService.getDetailPage(queryForm);
  80. /**
  81. * 3.返回结果
  82. */
  83. JSONObject jsonobj = new JSONObject();
  84. jsonobj.put("data", page);
  85. jsonobj.put("code", Constants.CODE_SUCCESS);
  86. ajaxJson(jsonobj.toString(), response);
  87. } catch (Exception e) {
  88. log.error(e.getMessage(), e);
  89. ajaxJson("{\"code\":\"0\",\"msg\":\"获取列表失败\"}", response);
  90. }
  91. }
  92. @RequestMapping(value = "/export_detail_list.do")
  93. public void exportDetailList(HttpServletResponse response, AdTheatreAnalysisDetailQueryForm queryForm) {
  94. ExcelUtil.exportExcelToWebsite(response,"央卫视电视剧收视明细",new AdTheatreAnalysisDetailVO(),(currentPage, pageSize) -> {
  95. queryForm.setPageNo(currentPage);
  96. queryForm.setPageSize(pageSize);
  97. return adTheatreTvStatService.getDetailPage(queryForm).getRecords();
  98. });
  99. }
  100. /**
  101. * 山东卫视电视剧收视分析
  102. */
  103. @RequestMapping(value = "/ajax_tv_ratio.do")
  104. public void tvRatio(HttpServletResponse response, AdTheatreAnalysisDetailQueryForm queryForm) {
  105. try {
  106. AdTvRatioVO adTvRatioVO = adTheatreTvStatService.getTvRatioVO(queryForm);
  107. /**
  108. * 3.返回结果
  109. */
  110. JSONObject jsonobj = new JSONObject();
  111. jsonobj.put("data", adTvRatioVO);
  112. jsonobj.put("code", Constants.CODE_SUCCESS);
  113. ajaxJson(jsonobj.toString(), response);
  114. } catch (Exception e) {
  115. log.error(e.getMessage(), e);
  116. ajaxJson("{\"code\":\"0\",\"msg\":\"获取列表失败\"}", response);
  117. }
  118. }
  119. /**
  120. * 电视剧收视区域分布
  121. */
  122. @RequestMapping(value = "/ajax_tv_zone.do")
  123. public void tvZone(HttpServletResponse response, AdTheatreAnalysisDetailQueryForm queryForm) {
  124. try {
  125. AdTvZoneVO adTvZoneVO = adTheatreTvStatService.getTvZoneVO(queryForm);
  126. /**
  127. * 3.返回结果
  128. */
  129. JSONObject jsonobj = new JSONObject();
  130. jsonobj.put("data", adTvZoneVO);
  131. jsonobj.put("code", Constants.CODE_SUCCESS);
  132. ajaxJson(jsonobj.toString(), response);
  133. } catch (Exception e) {
  134. log.error(e.getMessage(), e);
  135. ajaxJson("{\"code\":\"0\",\"msg\":\"获取列表失败\"}", response);
  136. }
  137. }
  138. /**
  139. * 电视剧产品投放分析
  140. */
  141. @RequestMapping(value = "/ajax_tv_product.do")
  142. public void tvProduct(HttpServletResponse response, AdTheatreAnalysisDetailQueryForm queryForm) {
  143. try {
  144. List<AdTheatreProductDistVO> productVO = adTheatreTvStatService.getProductVO(queryForm);
  145. /**
  146. * 3.返回结果
  147. */
  148. JSONObject jsonobj = new JSONObject();
  149. jsonobj.put("data", productVO);
  150. jsonobj.put("code", Constants.CODE_SUCCESS);
  151. ajaxJson(jsonobj.toString(), response);
  152. } catch (Exception e) {
  153. log.error(e.getMessage(), e);
  154. ajaxJson("{\"code\":\"0\",\"msg\":\"获取列表失败\"}", response);
  155. }
  156. }
  157. /**
  158. * 电视剧体裁结构分析
  159. */
  160. @RequestMapping(value = "/ajax_tv_theme.do")
  161. public void tvTheme(HttpServletResponse response, AdTheatreAnalysisDetailQueryForm queryForm) {
  162. try {
  163. List<AdThemeDistVO> themeVOs = adTheatreTvStatService.getThemeDistVO(queryForm);
  164. if (CollectionUtils.isNotEmpty(themeVOs)) {
  165. float ratio = 0.0f;
  166. for (AdThemeDistVO adThemeDistVO:themeVOs) {
  167. ratio += adThemeDistVO.getRatio();
  168. }
  169. ratio = Util.newScale(ratio/themeVOs.size(), 3);
  170. themeVOs.add(new AdThemeDistVO("平均",0,ratio));
  171. }
  172. /**
  173. * 3.返回结果
  174. */
  175. JSONObject jsonobj = new JSONObject();
  176. jsonobj.put("data", themeVOs);
  177. jsonobj.put("code", Constants.CODE_SUCCESS);
  178. ajaxJson(jsonobj.toString(), response);
  179. } catch (Exception e) {
  180. log.error(e.getMessage(), e);
  181. ajaxJson("{\"code\":\"0\",\"msg\":\"获取列表失败\"}", response);
  182. }
  183. }
  184. /**
  185. * 剧场电视剧收视率排名
  186. * @param response
  187. * @param startDate
  188. * @param endDate
  189. */
  190. @RequestMapping(value = "/ajax_tvTop_list.do")
  191. public void ajaxTvTopList(HttpServletResponse response, Integer theatreTime, String startDate, String endDate) {
  192. try {
  193. List<AdTheatreTopVO> list = adTheatreTvStatService.getTvTop(theatreTime, startDate, endDate);
  194. /**
  195. * 3.返回结果
  196. */
  197. JSONObject jsonobj = new JSONObject();
  198. jsonobj.put("data", list);
  199. jsonobj.put("code", Constants.CODE_SUCCESS);
  200. ajaxJson(jsonobj.toString(), response);
  201. } catch (Exception e) {
  202. log.error(e.getMessage(), e);
  203. ajaxJson("{\"code\":\"0\",\"msg\":\"获取列表失败\"}", response);
  204. }
  205. }
  206. /**
  207. * 卫视剧场排名
  208. * @param name 剧名
  209. * @param theatreTime 剧场:0日间 1黄金2午夜3凌晨
  210. * @param startDate 播放时间
  211. * @param endDate 播放时间
  212. */
  213. @RequestMapping(value = "/ajax_mediaTop_list.do")
  214. public void ajaxMediaTopList(HttpServletResponse response, String name, Integer theatreTime, String startDate, String endDate, Integer limitSize) {
  215. try {
  216. limitSize = (limitSize == null ? 30 : limitSize);
  217. List<AdTheatreTopVO> list = adTheatreTvStatService.getMediaTop(name, theatreTime, startDate, endDate, limitSize);
  218. /**
  219. * 3.返回结果
  220. */
  221. JSONObject jsonobj = new JSONObject();
  222. jsonobj.put("data", list);
  223. jsonobj.put("code", Constants.CODE_SUCCESS);
  224. ajaxJson(jsonobj.toString(), response);
  225. } catch (Exception e) {
  226. log.error(e.getMessage(), e);
  227. ajaxJson("{\"code\":\"0\",\"msg\":\"获取列表失败\"}", response);
  228. }
  229. }
  230. @RequestMapping(value = "/ajax_topList.do")
  231. public void ajaxTopList(HttpServletResponse response, Integer theatreTime, String startDate, String endDate) {
  232. try {
  233. List<AdTheatreTopVO> tvList = adTheatreTvStatService.getTvTop(theatreTime, startDate, endDate);
  234. List<AdTheatreTopVO> mediaList = adTheatreTvStatService.getMediaTop(null, theatreTime, startDate, endDate, null);
  235. JSONObject listJson = new JSONObject();
  236. listJson.put("tv", tvList);
  237. listJson.put("media", mediaList);
  238. /**
  239. * 3.返回结果
  240. */
  241. JSONObject jsonobj = new JSONObject();
  242. jsonobj.put("data", listJson);
  243. jsonobj.put("code", Constants.CODE_SUCCESS);
  244. ajaxJson(jsonobj.toString(), response);
  245. } catch (Exception e) {
  246. log.error(e.getMessage(), e);
  247. ajaxJson("{\"code\":\"0\",\"msg\":\"获取列表失败\"}", response);
  248. }
  249. }
  250. /**
  251. * to 对标页
  252. * @param ids 对标的剧id
  253. * @param startDate 日期范围
  254. * @param endDate 日期范围
  255. * @param day 日期范围的天数
  256. */
  257. @RequestMapping(value = "/benchmarking.do")
  258. public String benchmarking(@RequestParam String ids, String startDate, String endDate, Integer day, HttpServletRequest request){
  259. request.setAttribute("ids", ids);
  260. request.setAttribute("startDate", startDate);
  261. request.setAttribute("endDate", endDate);
  262. request.setAttribute("day", day);
  263. // 参数转型
  264. List<Integer> idList = Arrays.stream(ids.split(",")).map(s -> Integer.parseInt(s.trim()))
  265. .collect(Collectors.toList());
  266. // 获取剧列表
  267. List<AdTv> tvList = adTvService.getListByIds(idList);
  268. request.setAttribute("tvList", tvList);
  269. return "analysis/tv_benchmarking";
  270. }
  271. @RequestMapping(value = "/add_benchmarking_tv.do")
  272. public String addTv(ModelMap model, String ids, String startDate, String endDate, Integer day) {
  273. model.put("ids", ids);
  274. model.put("startDate", startDate);
  275. model.put("endDate", endDate);
  276. model.put("day", day);
  277. return "analysis/benchmark_tv_choose";
  278. }
  279. }