StatisticsController.java 19 KB

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