StatisticsController.java 12 KB

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