StatisticsController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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
  314. * @param index
  315. * @return
  316. */
  317. @RequestMapping("/lowlevel_all")
  318. @ResponseBody
  319. public String getIndexLowLevelTotalSign(@RequestParam(required = true) String date,
  320. @RequestParam(required = true) String area,
  321. @RequestParam(required = true) int level,
  322. @RequestParam(required = true) String index,
  323. @RequestParam(required = true) int sort,
  324. @RequestParam(required = false) String lowLevel,
  325. @RequestParam(required = false) String lowCode) {
  326. try {
  327. String[] indexes = index.split(",");
  328. JSONObject result = new JSONObject();
  329. if (StringUtils.isNotEmpty(lowCode)) {
  330. result.put("index_" + index, statisticsAllService.getLevelTwoLowLevelTotal(date, area, level, index, sort, lowLevel, lowCode));
  331. } else {
  332. for (String idx : indexes) {
  333. if (idx.equals("18") || index.equals("19")) {
  334. result.put("index_" + idx, statisticsAllService.getLowLevelTotalSpecial(date, area, level, idx, sort, lowLevel));
  335. } else {
  336. result.put("index_" + idx, statisticsAllService.getLowLevelTotal(date, area, level, idx, sort, lowLevel));
  337. }
  338. }
  339. }
  340. return write(200, "查询成功", "data", result);
  341. } catch (Exception e) {
  342. e.printStackTrace();
  343. return error(-1, "查询失败");
  344. }
  345. }
  346. /**
  347. * 获取三师转签或高危人群
  348. *
  349. * @param endDate
  350. * @param area
  351. * @param level
  352. * @return
  353. */
  354. @RequestMapping(value = "/sszq_qwrq_info")
  355. @ResponseBody
  356. public String getSszqAndGwrq(@RequestParam(required = true) String endDate,
  357. @RequestParam(required = true) String area,
  358. @RequestParam(required = true) int level) {
  359. try {
  360. JSONObject result = new JSONObject();
  361. JSONObject sszq = statisticsAllService.getSszqAndGwrq(endDate, area, level, "18");
  362. JSONObject gwrq = statisticsAllService.getSszqAndGwrq(endDate, area, level, "19");
  363. result.put("sszq",sszq);
  364. result.put("gwrq",gwrq);
  365. return write(200, "查询成功", "data", result);
  366. } catch (Exception e) {
  367. return error(-1, "查询失败");
  368. }
  369. }
  370. /**
  371. * 二级指标到达量
  372. *
  373. * @param date
  374. * @param area
  375. * @param level
  376. * @param index
  377. * @return
  378. */
  379. @RequestMapping(value = "/leveltwo_all")
  380. @ResponseBody
  381. public String getIndexLevelTwoTotal(@RequestParam(required = true) String date,
  382. @RequestParam(required = true) String area,
  383. @RequestParam(required = true) int level,
  384. @RequestParam(required = true) String index) {
  385. try {
  386. String[] indexes = index.split(",");
  387. JSONObject result = new JSONObject();
  388. for (String idx : indexes) {
  389. result.put("index_" + idx, statisticsAllService.getIndexLevelTwototal(date, area, level, idx));
  390. }
  391. return write(200, "查询成功", "data", result);
  392. } catch (Exception e) {
  393. e.printStackTrace();
  394. return error(-1, "查询失败");
  395. }
  396. }
  397. /**
  398. * 指标截止日期到达量
  399. *
  400. * @param endDate
  401. * @param area
  402. * @param level
  403. * @param index
  404. * @return
  405. */
  406. @RequestMapping("/index_all")
  407. @ResponseBody
  408. public String getIndexAll(@RequestParam(required = true) String endDate,
  409. @RequestParam(required = true) String area,
  410. @RequestParam(required = true) int level,
  411. @RequestParam(required = true) String index) {
  412. try {
  413. String[] indexes = index.split(",");
  414. JSONObject result = new JSONObject();
  415. for (String idx : indexes) {
  416. result.put("index_" + idx, statisticsAllService.getIndexTotal(endDate, area, level, idx));
  417. }
  418. return write(200, "查询成功", "data", result);
  419. } catch (Exception e) {
  420. return error(-1, "查询失败");
  421. }
  422. }
  423. }