StatisticsController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. package com.yihu.wlyy.web.statistic;
  2. import com.yihu.wlyy.entity.statistics.PopulationBase;
  3. import com.yihu.wlyy.service.app.statistics.StatisticsAllService;
  4. import com.yihu.wlyy.service.app.statistics.StatisticsService;
  5. import com.yihu.wlyy.web.BaseController;
  6. import io.swagger.annotations.Api;
  7. import org.json.JSONArray;
  8. import org.json.JSONObject;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.data.redis.core.StringRedisTemplate;
  11. import org.springframework.http.MediaType;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.bind.annotation.ResponseBody;
  16. /**
  17. * Created by lyr on 2016/08/16.
  18. */
  19. @Controller
  20. @RequestMapping(value = "/statistics", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  21. @Api(description = "统计")
  22. public class StatisticsController extends BaseController {
  23. @Autowired
  24. StatisticsService statisticsService;
  25. @Autowired
  26. StatisticsAllService statisticsAllService;
  27. /**
  28. * 获取统计时间
  29. *
  30. * @return
  31. */
  32. @RequestMapping(value = "/time")
  33. @ResponseBody
  34. public String getStatisticsTime() {
  35. try {
  36. return write(200, "查询成功", "data", statisticsService.getStatisticsTime());
  37. } catch (Exception e) {
  38. e.printStackTrace();
  39. return error(-1, "查询失败");
  40. }
  41. }
  42. /**
  43. * 指标按间隔统计
  44. *
  45. * @param startDate 起始日期
  46. * @param endDate 结束时间
  47. * @param interval 时间间隔
  48. * @param area 区域或机构
  49. * @param level 级别
  50. * @param index 指标
  51. * @return
  52. */
  53. @RequestMapping(value = "/interval")
  54. @ResponseBody
  55. public String indexInterval(String startDate, String endDate, int interval, String area, int level, String index) {
  56. String tag = "";
  57. try {
  58. String[] indexes = index.split(",");
  59. JSONObject result = new JSONObject();
  60. if (index != null) {
  61. for (String idx : indexes) {
  62. result.put("index_" + idx, statisticsService.getDateIncrementDetail(startDate, endDate, interval, area, level, idx));
  63. }
  64. }
  65. return write(200, "查询成功!", "data", result);
  66. } catch (Exception e) {
  67. e.printStackTrace();
  68. return error(-1, tag + "查询失败!");
  69. }
  70. }
  71. /**
  72. * 指标期间增长量
  73. *
  74. * @param startDate
  75. * @param endDate
  76. * @param area
  77. * @param level
  78. * @param index
  79. * @return
  80. */
  81. @RequestMapping("/increment")
  82. @ResponseBody
  83. public String getIndexIncrement(String startDate, String endDate, String area, int level, String index) {
  84. try {
  85. String[] indexes = index.split(",");
  86. JSONObject result = new JSONObject();
  87. for (String idx : indexes) {
  88. result.put("index_" + idx, statisticsService.getIntervalIncrement(startDate, endDate, area, level, idx));
  89. }
  90. return write(200, "查询成功", "data", result);
  91. } catch (Exception e) {
  92. e.printStackTrace();
  93. return error(-1, "查询失败");
  94. }
  95. }
  96. /**
  97. * 指标截止日期累积量
  98. *
  99. * @param endDate
  100. * @param area
  101. * @param level
  102. * @param index
  103. * @return
  104. */
  105. @RequestMapping("/total")
  106. @ResponseBody
  107. public String getIndexTotal(String endDate, String area, int level, String index) {
  108. try {
  109. String[] indexes = index.split(",");
  110. JSONObject result = new JSONObject();
  111. for (String idx : indexes) {
  112. result.put("index_" + idx, statisticsService.getTotalAmount(endDate, area, level, idx));
  113. }
  114. return write(200, "查询成功", "data", result);
  115. } catch (Exception e) {
  116. e.printStackTrace();
  117. return error(-1, "查询失败");
  118. }
  119. }
  120. /**
  121. * 指标期间增长量
  122. *
  123. * @param startDate
  124. * @param endDate
  125. * @param area
  126. * @param level
  127. * @param index
  128. * @return
  129. */
  130. @RequestMapping("/lowlevel_increment")
  131. @ResponseBody
  132. public String getIndexLowLevelIncrement(String startDate, String endDate, String area, int level, String index, int sort, String lowLevel) {
  133. try {
  134. String[] indexes = index.split(",");
  135. JSONObject result = new JSONObject();
  136. for (String idx : indexes) {
  137. result.put("index_" + idx, statisticsService.getLowLevelIncrementDetail(startDate, endDate, area, level, idx, sort, lowLevel));
  138. }
  139. return write(200, "查询成功", "data", result);
  140. } catch (Exception e) {
  141. e.printStackTrace();
  142. return error(-1, "查询失败");
  143. }
  144. }
  145. /**
  146. * 指标截止日期累积量
  147. *
  148. * @param endDate
  149. * @param area
  150. * @param level
  151. * @param index
  152. * @return
  153. */
  154. @RequestMapping("/lowlevel_total")
  155. @ResponseBody
  156. public String getIndexLowLevelTotal(String endDate, String area, int level, String index, int sort, String lowLevel) {
  157. try {
  158. String[] indexes = index.split(",");
  159. JSONObject result = new JSONObject();
  160. for (String idx : indexes) {
  161. result.put("index_" + idx, statisticsService.getLowLevelTotalDetail(endDate, area, level, idx, sort, lowLevel));
  162. }
  163. return write(200, "查询成功", "data", result);
  164. } catch (Exception e) {
  165. e.printStackTrace();
  166. return error(-1, "查询失败");
  167. }
  168. }
  169. /**
  170. * 指标期间增长量
  171. *
  172. * @param startDate
  173. * @param endDate
  174. * @param area
  175. * @param level
  176. * @param index
  177. * @return
  178. */
  179. @RequestMapping("/leveltwo_increment")
  180. @ResponseBody
  181. public String getIndexLevelTwoIncrement(String startDate, String endDate, String area, int level, String index) {
  182. try {
  183. String[] indexes = index.split(",");
  184. JSONObject result = new JSONObject();
  185. for (String idx : indexes) {
  186. result.put("index_" + idx, statisticsAllService.getIndexLevelTwototal(endDate, area, level, idx));
  187. }
  188. return write(200, "查询成功", "data", result);
  189. } catch (Exception e) {
  190. e.printStackTrace();
  191. return error(-1, "查询失败");
  192. }
  193. }
  194. /**
  195. * 获取签约率、签约完成率
  196. *
  197. * @param endDate 截止日期
  198. * @param area 区域
  199. * @param level 区域级别 4:城市 3:区 2:社区 1:团队
  200. * @return
  201. */
  202. @RequestMapping(value = "/sign_info")
  203. @ResponseBody
  204. public String getAreaSignInfo(String endDate, String area, int level) {
  205. try {
  206. JSONObject result = new JSONObject();
  207. long sign = statisticsAllService.getIndexTotal(endDate, area, level, "13");
  208. long weiJf = statisticsAllService.getWeiJiaoFei(endDate, area, level);
  209. JSONObject signRate = statisticsAllService.getSignRate(endDate, area, level);
  210. JSONObject signTaskRate = statisticsAllService.getSignTaskRate(endDate, area, level);
  211. result.put("sign", sign);
  212. result.put("expenses", weiJf);
  213. result.put("signRate", signRate);
  214. result.put("signTaskRate", signTaskRate);
  215. return write(200, "查询成功", "data", result);
  216. } catch (Exception e) {
  217. e.printStackTrace();
  218. return error(-1, "查询失败");
  219. }
  220. }
  221. /**
  222. * 获取三级指标增量
  223. *
  224. * @param startDate
  225. * @param endDate
  226. * @param area
  227. * @param level
  228. * @return
  229. */
  230. @RequestMapping(value = "/sixfive_statistics")
  231. @ResponseBody
  232. public String getSixFiveStatistics(String startDate, String endDate, String area, int level) {
  233. try {
  234. JSONArray result = statisticsAllService.getSixFiveStatistics(endDate, area, level);
  235. return write(200, "查询成功", "data", result);
  236. } catch (Exception e) {
  237. e.printStackTrace();
  238. return error(-1, "查询失败");
  239. }
  240. }
  241. /**
  242. * 指标按间隔统计
  243. *
  244. * @param startDate 起始日期
  245. * @param endDate 结束时间
  246. * @param interval 时间间隔
  247. * @param area 区域或机构
  248. * @param level 级别
  249. * @param index 指标
  250. * @return
  251. */
  252. @RequestMapping(value = "/interval_total")
  253. @ResponseBody
  254. public String indexIntervalTotal(String startDate, String endDate, int interval, String area, int level, String index) {
  255. try {
  256. String[] indexes = index.split(",");
  257. JSONObject result = new JSONObject();
  258. if (index != null) {
  259. for (String idx : indexes) {
  260. result.put("index_" + idx, statisticsAllService.getDateTotal(startDate, endDate, interval, area, level, idx));
  261. }
  262. }
  263. return write(200, "查询成功!", "data", result);
  264. } catch (Exception e) {
  265. e.printStackTrace();
  266. return error(-1, "查询失败!");
  267. }
  268. }
  269. /**
  270. * 指标截止日期累积量
  271. *
  272. * @param date
  273. * @param area
  274. * @param level
  275. * @param index
  276. * @return
  277. */
  278. @RequestMapping("/lowlevel_all")
  279. @ResponseBody
  280. public String getIndexLowLevelTotalSign(String date, String area, int level, String index, int sort, String lowLevel) {
  281. try {
  282. String[] indexes = index.split(",");
  283. JSONObject result = new JSONObject();
  284. for (String idx : indexes) {
  285. result.put("index_" + idx, statisticsAllService.getLowLevelTotal(date, area, level, idx, sort, lowLevel));
  286. }
  287. return write(200, "查询成功", "data", result);
  288. } catch (Exception e) {
  289. e.printStackTrace();
  290. return error(-1, "查询失败");
  291. }
  292. }
  293. /**
  294. * 二级指标到达量
  295. *
  296. * @param date
  297. * @param area
  298. * @param level
  299. * @param index
  300. * @return
  301. */
  302. @RequestMapping(value = "/leveltwo_all")
  303. @ResponseBody
  304. public String getIndexLevelTwoTotal(String date, String area, int level, String index) {
  305. try {
  306. String[] indexes = index.split(",");
  307. JSONObject result = new JSONObject();
  308. for (String idx : indexes) {
  309. result.put("index_" + idx, statisticsAllService.getIndexLevelTwototal(date, area, level, idx));
  310. }
  311. return write(200, "查询成功", "data", result);
  312. } catch (Exception e) {
  313. e.printStackTrace();
  314. return error(-1, "查询失败");
  315. }
  316. }
  317. /**
  318. * 指标截止日期到达量
  319. *
  320. * @param endDate
  321. * @param area
  322. * @param level
  323. * @param index
  324. * @return
  325. */
  326. @RequestMapping("/index_all")
  327. @ResponseBody
  328. public String getIndexAll(String endDate, String area, int level, String index) {
  329. try {
  330. String[] indexes = index.split(",");
  331. JSONObject result = new JSONObject();
  332. for (String idx : indexes) {
  333. result.put("index_" + idx, statisticsAllService.getIndexTotal(endDate, area, level, idx));
  334. }
  335. return write(200, "查询成功", "data", result);
  336. } catch (Exception e) {
  337. e.printStackTrace();
  338. return error(-1, "查询失败");
  339. }
  340. }
  341. }