StatisticsController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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.*;
  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. * 根据2个ID合并指标
  194. *
  195. * @param endDate
  196. * @param area
  197. * @param level
  198. * @param index
  199. * @return
  200. */
  201. @RequestMapping("/lowlevel_total_mesh")
  202. @ResponseBody
  203. public String getIndexLowLevelTotalMesh(@RequestParam(required = true) String endDate, // 2007-10-02
  204. @RequestParam(required = true) String area,//区域 350205
  205. @RequestParam(required = true) int level,//等级
  206. @RequestParam(required = true) String index,//指标code
  207. @RequestParam(required = true) int sort,//1是倒叙 0是正序
  208. @RequestParam(required = false) String lowLevel) {
  209. try {
  210. String[] indexes = index.split(",");
  211. JSONObject result = new JSONObject();
  212. JSONArray returnJa = new JSONArray();
  213. List<JSONArray> jsonArrays = new ArrayList<>();
  214. for (String idx : indexes) {
  215. JSONArray jsonArray = statisticsService.getLowLevelTotalDetail(endDate, area, level, idx, sort, lowLevel);
  216. jsonArrays.add(jsonArray);
  217. }
  218. //遍历合并2个指标中key值一样的
  219. for (int i = 0; i < jsonArrays.get(0).length(); i++) {
  220. if (jsonArrays.get(1).length() == 0) {
  221. //未回复咨询不存在的时候默认是0
  222. JSONObject map1 = jsonArrays.get(0).getJSONObject(i);
  223. String amount = map1.get("amount").toString() + ",0";
  224. map1.put("amount", amount);
  225. returnJa.put(map1);
  226. } else {
  227. for (int j = 0; j < jsonArrays.get(1).length(); j++) {
  228. JSONObject map1 = jsonArrays.get(0).getJSONObject(i);
  229. JSONObject map2 = jsonArrays.get(1).getJSONObject(j);
  230. String amount = "";
  231. if (map1.get("code").equals(map2.get("code"))) {
  232. amount = map1.get("amount").toString() + "," + map2.get("amount").toString();
  233. map1.put("amount", amount);
  234. returnJa.put(map1);
  235. }
  236. }
  237. }
  238. }
  239. result.put("index", returnJa);
  240. return write(200, "查询成功", "data", result);
  241. } catch (Exception e) {
  242. e.printStackTrace();
  243. return error(-1, "查询失败");
  244. }
  245. }
  246. /**
  247. * 指标期间增长量
  248. *
  249. * @param startDate
  250. * @param endDate
  251. * @param area
  252. * @param level
  253. * @param index
  254. * @return
  255. */
  256. @RequestMapping("/leveltwo_increment")
  257. @ResponseBody
  258. public String getIndexLevelTwoIncrement(@RequestParam(required = false) String startDate,
  259. @RequestParam(required = true) String endDate,
  260. @RequestParam(required = true) String area,
  261. @RequestParam(required = true) int level,
  262. @RequestParam(required = true) String index) {
  263. try {
  264. String[] indexes = index.split(",");
  265. JSONObject result = new JSONObject();
  266. for (String idx : indexes) {
  267. result.put("index_" + idx, statisticsAllService.getIndexLevelTwototal(endDate, area, level, idx));
  268. }
  269. return write(200, "查询成功", "data", result);
  270. } catch (Exception e) {
  271. e.printStackTrace();
  272. return error(-1, "查询失败");
  273. }
  274. }
  275. /**
  276. * 获取签约率、签约完成率
  277. *
  278. * @param endDate 截止日期
  279. * @param area 区域
  280. * @param level 区域级别 4:城市 3:区 2:社区 1:团队
  281. * @return
  282. */
  283. @RequestMapping(value = "/sign_info")
  284. @ResponseBody
  285. public String getAreaSignInfo(@RequestParam(required = true) String endDate,
  286. @RequestParam(required = true) String area,
  287. @RequestParam(required = true) int level,
  288. @RequestParam(required = false) String lowCode) {
  289. try {
  290. JSONObject result = new JSONObject();
  291. if (StringUtils.isEmpty(lowCode)) {
  292. long sign = statisticsAllService.getIndexTotal(endDate, area, level, "13");
  293. long weiJf = statisticsAllService.getWeiJiaoFei(endDate, area, level);
  294. JSONObject signRate = statisticsAllService.getSignRate(endDate, area, level);
  295. JSONObject signTaskRate = statisticsAllService.getSignTaskRate(endDate, area, level);
  296. result.put("sign", sign);
  297. result.put("expenses", weiJf);
  298. result.put("signRate", signRate);
  299. result.put("signTaskRate", signTaskRate);
  300. } else {
  301. result = statisticsAllService.getGroupInfo(endDate, lowCode, area, level);
  302. }
  303. return write(200, "查询成功", "data", result);
  304. } catch (Exception e) {
  305. return error(-1, "查询失败");
  306. }
  307. }
  308. /**
  309. * 获取三级指标增量
  310. *
  311. * @param startDate
  312. * @param endDate
  313. * @param area
  314. * @param level
  315. * @return
  316. */
  317. @RequestMapping(value = "/sixfive_statistics")
  318. @ResponseBody
  319. public String getSixFiveStatistics(@RequestParam(required = false) String startDate,
  320. @RequestParam(required = true) String endDate,
  321. @RequestParam(required = true) String area, int level) {
  322. try {
  323. JSONArray result = statisticsAllService.getSixFiveStatistics(endDate, area, level);
  324. return write(200, "查询成功", "data", result);
  325. } catch (Exception e) {
  326. e.printStackTrace();
  327. return error(-1, "查询失败");
  328. }
  329. }
  330. /**
  331. * 指标按间隔统计
  332. *
  333. * @param startDate 起始日期
  334. * @param endDate 结束时间
  335. * @param interval 时间间隔
  336. * @param area 区域或机构
  337. * @param level 级别
  338. * @param index 指标
  339. * @return
  340. */
  341. @RequestMapping(value = "/interval_total")
  342. @ResponseBody
  343. public String indexIntervalTotal(@RequestParam(required = true) String startDate,
  344. @RequestParam(required = true) String endDate,
  345. @RequestParam(required = true) int interval,
  346. @RequestParam(required = true) String area,
  347. @RequestParam(required = true) int level,
  348. @RequestParam(required = true) String index,
  349. @RequestParam(required = false) String lowCode) {
  350. try {
  351. String[] indexes = index.split(",");
  352. JSONObject result = new JSONObject();
  353. if (index != null) {
  354. for (String idx : indexes) {
  355. result.put("index_" + idx, statisticsAllService.getDateTotal(startDate, endDate, interval, area, level, idx, lowCode));
  356. }
  357. }
  358. return write(200, "查询成功!", "data", result);
  359. } catch (Exception e) {
  360. return error(-1, "查询失败!");
  361. }
  362. }
  363. /**
  364. * 指标截止日期累积量
  365. *
  366. * @param date
  367. * @param area
  368. * @param level level1_type等级 1:团队 2社区机构 3区级 4市级
  369. * @param index quotoCode 18/19两率
  370. * @param sort 1降序排列-1升序排列
  371. * @return
  372. */
  373. @RequestMapping("/lowlevel_all")
  374. @ResponseBody
  375. public String getIndexLowLevelTotalSign(@RequestParam(required = true) String date,
  376. @RequestParam(required = true) String area,
  377. @RequestParam(required = true) int level,
  378. @RequestParam(required = true) String index,
  379. @RequestParam(required = true) int sort,
  380. @RequestParam(required = false) String lowLevel,
  381. @RequestParam(required = false) String lowCode) {
  382. try {
  383. String[] indexes = index.split(",");
  384. JSONObject result = new JSONObject();
  385. if (StringUtils.isNotEmpty(lowCode)) {
  386. // 指定level下特定查询级别
  387. result.put("index_" + index, statisticsAllService.getLevelTwoLowLevelTotal(date, area, level, index, sort, lowLevel, lowCode));
  388. } else {
  389. // 未指定level下特定查询级别
  390. for (String idx : indexes) {
  391. if (idx.equals("18") || index.equals("19")) {
  392. result.put("index_" + idx, statisticsAllService.getLowLevelTotalSpecial(date, area, level, idx, sort, lowLevel));
  393. } else {
  394. result.put("index_" + idx, statisticsAllService.getLowLevelTotal(date, area, level, idx, sort, lowLevel));
  395. }
  396. }
  397. }
  398. return write(200, "查询成功", "data", result);
  399. } catch (Exception e) {
  400. e.printStackTrace();
  401. return error(-1, "查询失败");
  402. }
  403. }
  404. /**
  405. * 获取三师转签或高危人群
  406. *
  407. * @param endDate
  408. * @param area
  409. * @param level
  410. * @return
  411. */
  412. @RequestMapping(value = "/sszq_qwrq_info")
  413. @ResponseBody
  414. public String getSszqAndGwrq(@RequestParam(required = true) String endDate,
  415. @RequestParam(required = true) String area,
  416. @RequestParam(required = true) int level) {
  417. try {
  418. JSONObject result = new JSONObject();
  419. JSONObject sszq = statisticsAllService.getSszqAndGwrq(endDate, area, level, "18");
  420. JSONObject gwrq = statisticsAllService.getSszqAndGwrq(endDate, area, level, "19");
  421. result.put("sszq", sszq);
  422. result.put("gwrq", gwrq);
  423. return write(200, "查询成功", "data", result);
  424. } catch (Exception e) {
  425. return error(-1, "查询失败");
  426. }
  427. }
  428. /**
  429. * 二级指标到达量
  430. *
  431. * @param date
  432. * @param area
  433. * @param level
  434. * @param index
  435. * @return
  436. */
  437. @RequestMapping(value = "/leveltwo_all")
  438. @ResponseBody
  439. public String getIndexLevelTwoTotal(@RequestParam(required = true) String date,
  440. @RequestParam(required = true) String area,
  441. @RequestParam(required = true) int level,
  442. @RequestParam(required = true) String index) {
  443. try {
  444. String[] indexes = index.split(",");
  445. JSONObject result = new JSONObject();
  446. for (String idx : indexes) {
  447. result.put("index_" + idx, statisticsAllService.getIndexLevelTwototal(date, area, level, idx));
  448. }
  449. return write(200, "查询成功", "data", result);
  450. } catch (Exception e) {
  451. e.printStackTrace();
  452. return error(-1, "查询失败");
  453. }
  454. }
  455. /**
  456. * 指标截止日期到达量
  457. *
  458. * @param endDate
  459. * @param area
  460. * @param level
  461. * @param index
  462. * @return
  463. */
  464. @RequestMapping("/index_all")
  465. @ResponseBody
  466. public String getIndexAll(@RequestParam(required = true) String endDate,
  467. @RequestParam(required = true) String area,
  468. @RequestParam(required = true) int level,
  469. @RequestParam(required = true) String index) {
  470. try {
  471. String[] indexes = index.split(",");
  472. JSONObject result = new JSONObject();
  473. for (String idx : indexes) {
  474. result.put("index_" + idx, statisticsAllService.getIndexTotal(endDate, area, level, idx));
  475. }
  476. return write(200, "查询成功", "data", result);
  477. } catch (Exception e) {
  478. return error(-1, "查询失败");
  479. }
  480. }
  481. }