StatisticsController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. return error(-1, "查询失败");
  42. }
  43. }
  44. /**
  45. * 指标按间隔统计
  46. *
  47. * @param startDate 起始日期
  48. * @param endDate 结束时间
  49. * @param interval 时间间隔
  50. * @param area 区域或机构
  51. * @param level 级别
  52. * @param index 指标
  53. * @return
  54. */
  55. @RequestMapping(value = "/interval")
  56. @ResponseBody
  57. public String indexInterval(@RequestParam(required = true) String startDate,
  58. @RequestParam(required = true) String endDate,
  59. @RequestParam(required = true) int interval,
  60. @RequestParam(required = true) String area,
  61. @RequestParam(required = true) int level,
  62. @RequestParam(required = true) String index) {
  63. String tag = "";
  64. try {
  65. String[] indexes = index.split(",");
  66. JSONObject result = new JSONObject();
  67. if (index != null) {
  68. for (String idx : indexes) {
  69. result.put("index_" + idx, statisticsService.getDateIncrementDetail(startDate, endDate, interval, area, level, idx));
  70. }
  71. }
  72. return write(200, "查询成功!", "data", result);
  73. } catch (Exception e) {
  74. return error(-1, tag + "查询失败!");
  75. }
  76. }
  77. /**
  78. * 指标期间增长量
  79. *
  80. * @param startDate
  81. * @param endDate
  82. * @param area
  83. * @param level
  84. * @param index
  85. * @return
  86. */
  87. @RequestMapping("/increment")
  88. @ResponseBody
  89. public String getIndexIncrement(@RequestParam(required = true) String startDate,
  90. @RequestParam(required = true) String endDate,
  91. @RequestParam(required = true) String area,
  92. @RequestParam(required = true) int level,
  93. @RequestParam(required = true) String index) {
  94. try {
  95. String[] indexes = index.split(",");
  96. JSONObject result = new JSONObject();
  97. for (String idx : indexes) {
  98. result.put("index_" + idx, statisticsService.getIntervalIncrement(startDate, endDate, area, level, idx));
  99. }
  100. return write(200, "查询成功", "data", result);
  101. } catch (Exception e) {
  102. e.printStackTrace();
  103. return error(-1, "查询失败");
  104. }
  105. }
  106. /**
  107. * 指标截止日期累积量
  108. *
  109. * @param endDate
  110. * @param area
  111. * @param level
  112. * @param index
  113. * @return
  114. */
  115. @RequestMapping("/total")
  116. @ResponseBody
  117. public String getIndexTotal(@RequestParam(required = true) String endDate,
  118. @RequestParam(required = true) String area,
  119. @RequestParam(required = true) int level,
  120. @RequestParam(required = true) String index) {
  121. try {
  122. String[] indexes = index.split(",");
  123. JSONObject result = new JSONObject();
  124. for (String idx : indexes) {
  125. result.put("index_" + idx, statisticsService.getTotalAmount(endDate, area, level, idx));
  126. }
  127. return write(200, "查询成功", "data", result);
  128. } catch (Exception e) {
  129. return error(-1, "查询失败");
  130. }
  131. }
  132. /**
  133. * 指标期间增长量
  134. *
  135. * @param startDate
  136. * @param endDate
  137. * @param area
  138. * @param level
  139. * @param index
  140. * @return
  141. */
  142. @RequestMapping("/lowlevel_increment")
  143. @ResponseBody
  144. public String getIndexLowLevelIncrement(@RequestParam(required = true) String startDate,
  145. @RequestParam(required = true) String endDate,
  146. @RequestParam(required = true) String area,
  147. @RequestParam(required = true) int level,
  148. @RequestParam(required = true) String index,
  149. @RequestParam(required = true) int sort,
  150. @RequestParam(required = false) String lowLevel) {
  151. try {
  152. String[] indexes = index.split(",");
  153. JSONObject result = new JSONObject();
  154. for (String idx : indexes) {
  155. result.put("index_" + idx, statisticsService.getLowLevelIncrementDetail(startDate, endDate, area, level, idx, sort, lowLevel));
  156. }
  157. return write(200, "查询成功", "data", result);
  158. } catch (Exception e) {
  159. e.printStackTrace();
  160. return error(-1, "查询失败");
  161. }
  162. }
  163. /**
  164. * 指标截止日期累积量
  165. *
  166. * @param endDate
  167. * @param area
  168. * @param level
  169. * @param index
  170. * @return
  171. */
  172. @RequestMapping("/lowlevel_total")
  173. @ResponseBody
  174. public String getIndexLowLevelTotal(@RequestParam(required = true) String endDate,
  175. @RequestParam(required = true) String area,
  176. @RequestParam(required = true) int level,
  177. @RequestParam(required = true) String index,
  178. @RequestParam(required = true) int sort,
  179. @RequestParam(required = false) String lowLevel) {
  180. try {
  181. String[] indexes = index.split(",");
  182. JSONObject result = new JSONObject();
  183. for (String idx : indexes) {
  184. result.put("index_" + idx, statisticsService.getLowLevelTotalDetail(endDate, area, level, idx, sort, lowLevel));
  185. }
  186. return write(200, "查询成功", "data", result);
  187. } catch (Exception e) {
  188. return error(-1, "查询失败");
  189. }
  190. }
  191. /**
  192. * 指标期间增长量
  193. *
  194. * @param startDate
  195. * @param endDate
  196. * @param area
  197. * @param level
  198. * @param index
  199. * @return
  200. */
  201. @RequestMapping("/leveltwo_increment")
  202. @ResponseBody
  203. public String getIndexLevelTwoIncrement(@RequestParam(required = false) String startDate,
  204. @RequestParam(required = true) String endDate,
  205. @RequestParam(required = true) String area,
  206. @RequestParam(required = true) int level,
  207. @RequestParam(required = true) String index) {
  208. try {
  209. String[] indexes = index.split(",");
  210. JSONObject result = new JSONObject();
  211. for (String idx : indexes) {
  212. result.put("index_" + idx, statisticsAllService.getIndexLevelTwototal(endDate, area, level, idx));
  213. }
  214. return write(200, "查询成功", "data", result);
  215. } catch (Exception e) {
  216. e.printStackTrace();
  217. return error(-1, "查询失败");
  218. }
  219. }
  220. /**
  221. * 获取签约率、签约完成率
  222. *
  223. * @param endDate 截止日期
  224. * @param area 区域
  225. * @param level 区域级别 4:城市 3:区 2:社区 1:团队
  226. * @return
  227. */
  228. @RequestMapping(value = "/sign_info")
  229. @ResponseBody
  230. public String getAreaSignInfo(@RequestParam(required = true) String endDate,
  231. @RequestParam(required = true) String area,
  232. @RequestParam(required = true) int level,
  233. @RequestParam(required = false) String lowCode) {
  234. try {
  235. JSONObject result = new JSONObject();
  236. if (StringUtils.isEmpty(lowCode)) {
  237. long sign = statisticsAllService.getIndexTotal(endDate, area, level, "13");
  238. long weiJf = statisticsAllService.getWeiJiaoFei(endDate, area, level);
  239. JSONObject signRate = statisticsAllService.getSignRate(endDate, area, level);
  240. JSONObject signTaskRate = statisticsAllService.getSignTaskRate(endDate, area, level);
  241. result.put("sign", sign);
  242. result.put("expenses", weiJf);
  243. result.put("signRate", signRate);
  244. result.put("signTaskRate", signTaskRate);
  245. } else {
  246. result = statisticsAllService.getGroupInfo(endDate, lowCode, area, level);
  247. }
  248. return write(200, "查询成功", "data", result);
  249. } catch (Exception e) {
  250. return error(-1, "查询失败");
  251. }
  252. }
  253. /**
  254. * 获取三级指标增量
  255. *
  256. * @param startDate
  257. * @param endDate
  258. * @param area
  259. * @param level
  260. * @return
  261. */
  262. @RequestMapping(value = "/sixfive_statistics")
  263. @ResponseBody
  264. public String getSixFiveStatistics(@RequestParam(required = false) String startDate,
  265. @RequestParam(required = true) String endDate,
  266. @RequestParam(required = true) String area, int level) {
  267. try {
  268. JSONArray result = statisticsAllService.getSixFiveStatistics(endDate, area, level);
  269. return write(200, "查询成功", "data", result);
  270. } catch (Exception e) {
  271. e.printStackTrace();
  272. return error(-1, "查询失败");
  273. }
  274. }
  275. /**
  276. * 指标按间隔统计
  277. *
  278. * @param startDate 起始日期
  279. * @param endDate 结束时间
  280. * @param interval 时间间隔
  281. * @param area 区域或机构
  282. * @param level 级别
  283. * @param index 指标
  284. * @return
  285. */
  286. @RequestMapping(value = "/interval_total")
  287. @ResponseBody
  288. public String indexIntervalTotal(@RequestParam(required = true) String startDate,
  289. @RequestParam(required = true) String endDate,
  290. @RequestParam(required = true) int interval,
  291. @RequestParam(required = true) String area,
  292. @RequestParam(required = true) int level,
  293. @RequestParam(required = true) String index,
  294. @RequestParam(required = false) String lowCode) {
  295. try {
  296. String[] indexes = index.split(",");
  297. JSONObject result = new JSONObject();
  298. if (index != null) {
  299. for (String idx : indexes) {
  300. result.put("index_" + idx, statisticsAllService.getDateTotal(startDate, endDate, interval, area, level, idx, lowCode));
  301. }
  302. }
  303. return write(200, "查询成功!", "data", result);
  304. } catch (Exception e) {
  305. return error(-1, "查询失败!");
  306. }
  307. }
  308. /**
  309. * 指标截止日期累积量
  310. *
  311. * @param date
  312. * @param area
  313. * @param level level1_type等级 1:团队 2社区机构 3区级 4市级
  314. * @param index quotoCode 18/19两率
  315. * @param sort 1降序排列-1升序排列
  316. * @return
  317. */
  318. @RequestMapping("/lowlevel_all")
  319. @ResponseBody
  320. public String getIndexLowLevelTotalSign(@RequestParam(required = true) String date,
  321. @RequestParam(required = true) String area,
  322. @RequestParam(required = true) int level,
  323. @RequestParam(required = true) String index,
  324. @RequestParam(required = true) int sort,
  325. @RequestParam(required = false) String lowLevel,
  326. @RequestParam(required = false) String lowCode) {
  327. try {
  328. String[] indexes = index.split(",");
  329. JSONObject result = new JSONObject();
  330. if (StringUtils.isNotEmpty(lowCode)) {
  331. // 指定level下特定查询级别
  332. result.put("index_" + index, statisticsAllService.getLevelTwoLowLevelTotal(date, area, level, index, sort, lowLevel, lowCode));
  333. } else {
  334. // 未指定level下特定查询级别
  335. for (String idx : indexes) {
  336. if (idx.equals("18") || index.equals("19")) {
  337. result.put("index_" + idx, statisticsAllService.getLowLevelTotalSpecial(date, area, level, idx, sort, lowLevel));
  338. } else {
  339. result.put("index_" + idx, statisticsAllService.getLowLevelTotal(date, area, level, idx, sort, lowLevel));
  340. }
  341. }
  342. }
  343. return write(200, "查询成功", "data", result);
  344. } catch (Exception e) {
  345. e.printStackTrace();
  346. return error(-1, "查询失败");
  347. }
  348. }
  349. /**
  350. * 获取三师转签或高危人群
  351. *
  352. * @param endDate
  353. * @param area
  354. * @param level
  355. * @return
  356. */
  357. @RequestMapping(value = "/sszq_qwrq_info")
  358. @ResponseBody
  359. public String getSszqAndGwrq(@RequestParam(required = true) String endDate,
  360. @RequestParam(required = true) String area,
  361. @RequestParam(required = true) int level) {
  362. try {
  363. JSONObject result = new JSONObject();
  364. JSONObject sszq = statisticsAllService.getSszqAndGwrq(endDate, area, level, "18");
  365. JSONObject gwrq = statisticsAllService.getSszqAndGwrq(endDate, area, level, "19");
  366. result.put("sszq",sszq);
  367. result.put("gwrq",gwrq);
  368. return write(200, "查询成功", "data", result);
  369. } catch (Exception e) {
  370. return error(-1, "查询失败");
  371. }
  372. }
  373. /**
  374. * 二级指标到达量
  375. *
  376. * @param date
  377. * @param area
  378. * @param level
  379. * @param index
  380. * @return
  381. */
  382. @RequestMapping(value = "/leveltwo_all")
  383. @ResponseBody
  384. public String getIndexLevelTwoTotal(@RequestParam(required = true) String date,
  385. @RequestParam(required = true) String area,
  386. @RequestParam(required = true) int level,
  387. @RequestParam(required = true) String index) {
  388. try {
  389. String[] indexes = index.split(",");
  390. JSONObject result = new JSONObject();
  391. for (String idx : indexes) {
  392. result.put("index_" + idx, statisticsAllService.getIndexLevelTwototal(date, area, level, idx));
  393. }
  394. return write(200, "查询成功", "data", result);
  395. } catch (Exception e) {
  396. e.printStackTrace();
  397. return error(-1, "查询失败");
  398. }
  399. }
  400. /**
  401. * 指标截止日期到达量
  402. *
  403. * @param endDate
  404. * @param area
  405. * @param level
  406. * @param index
  407. * @return
  408. */
  409. @RequestMapping("/index_all")
  410. @ResponseBody
  411. public String getIndexAll(@RequestParam(required = true) String endDate,
  412. @RequestParam(required = true) String area,
  413. @RequestParam(required = true) int level,
  414. @RequestParam(required = true) String index) {
  415. try {
  416. String[] indexes = index.split(",");
  417. JSONObject result = new JSONObject();
  418. for (String idx : indexes) {
  419. result.put("index_" + idx, statisticsAllService.getIndexTotal(endDate, area, level, idx));
  420. }
  421. return write(200, "查询成功", "data", result);
  422. } catch (Exception e) {
  423. return error(-1, "查询失败");
  424. }
  425. }
  426. }