StatisticsController.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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. @RequestParam(required = false) String level2_type) {
  64. String tag = "";
  65. try {
  66. String[] indexes = index.split(",");
  67. JSONObject result = new JSONObject();
  68. if (index != null) {
  69. for (String idx : indexes) {
  70. result.put("index_" + idx, statisticsService.getDateIncrementDetail(startDate, endDate, interval, area, level,idx,level2_type));
  71. }
  72. }
  73. return write(200, "查询成功!", "data", result);
  74. } catch (Exception e) {
  75. return error(-1, tag + "查询失败!");
  76. }
  77. }
  78. /**
  79. * 指标期间增长量
  80. *
  81. * @param startDate
  82. * @param endDate
  83. * @param area
  84. * @param level
  85. * @param index
  86. * @return
  87. */
  88. @RequestMapping("/increment")
  89. @ResponseBody
  90. public String getIndexIncrement(@RequestParam(required = true) String startDate,
  91. @RequestParam(required = true) String endDate,
  92. @RequestParam(required = true) String area,
  93. @RequestParam(required = true) int level,
  94. @RequestParam(required = true) String index) {
  95. try {
  96. String[] indexes = index.split(",");
  97. JSONObject result = new JSONObject();
  98. for (String idx : indexes) {
  99. result.put("index_" + idx, statisticsService.getIntervalIncrement(startDate, endDate, area, level, idx));
  100. }
  101. return write(200, "查询成功", "data", result);
  102. } catch (Exception e) {
  103. e.printStackTrace();
  104. return error(-1, "查询失败");
  105. }
  106. }
  107. /**
  108. * 指标截止日期累积量
  109. *
  110. * @param endDate 结束时间
  111. * @param area 父code
  112. * @param level 等级 1 团队,2 机构,3 区,4 市
  113. * @param index 指标代码
  114. * @param level2_type 指标代码 例如性别 1 男 2 女 不传就返回男和女的总和
  115. * @return
  116. */
  117. @RequestMapping("/total")
  118. @ResponseBody
  119. public String getIndexTotal(@RequestParam(required = true) String endDate,
  120. @RequestParam(required = true) String area,
  121. @RequestParam(required = true) int level,
  122. @RequestParam(required = true) String index,
  123. @RequestParam(required = false) String level2_type) {
  124. try {
  125. String[] indexes = index.split(",");
  126. JSONObject result = new JSONObject();
  127. for (String idx : indexes) {
  128. result.put("index_" + idx, statisticsService.getTotalAmount(endDate, area, level, idx,level2_type));
  129. }
  130. return write(200, "查询成功", "data", result);
  131. } catch (Exception e) {
  132. return error(-1, "查询失败");
  133. }
  134. }
  135. /**
  136. * 指标期间增长量
  137. *
  138. * @param startDate
  139. * @param endDate
  140. * @param area
  141. * @param level
  142. * @param index
  143. * @return
  144. */
  145. @RequestMapping("/lowlevel_increment")
  146. @ResponseBody
  147. public String getIndexLowLevelIncrement(@RequestParam(required = true) String startDate,
  148. @RequestParam(required = true) String endDate,
  149. @RequestParam(required = true) String area,
  150. @RequestParam(required = true) int level,
  151. @RequestParam(required = true) String index,
  152. @RequestParam(required = true) int sort,
  153. @RequestParam(required = false) String lowLevel) {
  154. try {
  155. String[] indexes = index.split(",");
  156. JSONObject result = new JSONObject();
  157. for (String idx : indexes) {
  158. result.put("index_" + idx, statisticsService.getLowLevelIncrementDetail(startDate, endDate, area, level, idx, sort, lowLevel));
  159. }
  160. return write(200, "查询成功", "data", result);
  161. } catch (Exception e) {
  162. e.printStackTrace();
  163. return error(-1, "查询失败");
  164. }
  165. }
  166. /**
  167. * 指标截止日期增量
  168. *
  169. * @param endDate 结束时间
  170. * @param area 父code
  171. * @param level 等级 1 团队,2 机构,3 区,4 市
  172. * @param index 指标代码
  173. * @param sort 排序 1倒叙 2是 正序
  174. * @param lowLevel
  175. * @param level2_type 指标代码 例如性别 1 男 2 女 不传就返回男和女的总和
  176. * @return
  177. */
  178. @RequestMapping("/lowlevel_total")
  179. @ResponseBody
  180. public String getIndexLowLevelTotal(@RequestParam(required = true) String endDate,
  181. @RequestParam(required = true) String area,
  182. @RequestParam(required = true) int level,
  183. @RequestParam(required = true) String index,
  184. @RequestParam(required = true) int sort,
  185. @RequestParam(required = false) String lowLevel,
  186. @RequestParam(required = false) String level2_type) {
  187. try {
  188. String[] indexes = index.split(",");
  189. JSONObject result = new JSONObject();
  190. for (String idx : indexes) {
  191. result.put("index_" + idx, statisticsService.getLowLevelTotalDetail(endDate, area, level, idx, sort, lowLevel,level2_type));
  192. }
  193. return write(200, "查询成功", "data", result);
  194. } catch (Exception e) {
  195. return error(-1, "查询失败");
  196. }
  197. }
  198. /**
  199. * 指标截止日期累积量
  200. * 根据2个ID合并指标
  201. *
  202. * @param endDate
  203. * @param area
  204. * @param level
  205. * @param index
  206. * @return
  207. */
  208. @RequestMapping("/lowlevel_total_mesh")
  209. @ResponseBody
  210. public String getIndexLowLevelTotalMesh(@RequestParam(required = true) String endDate, // 2007-10-02
  211. @RequestParam(required = true) String area,//区域 350205
  212. @RequestParam(required = true) int level,//等级
  213. @RequestParam(required = true) String index,//指标code
  214. @RequestParam(required = true) int sort,//1是倒叙 0是正序
  215. @RequestParam(required = false) String lowLevel) {
  216. try {
  217. String[] indexes = index.split(",");
  218. JSONObject result = new JSONObject();
  219. JSONArray returnJa = new JSONArray();
  220. List<JSONArray> jsonArrays = new ArrayList<>();
  221. JSONArray jsonArray1 = statisticsService.getLowLevelTotalDetail(endDate, area, level, indexes[0], sort, lowLevel,null);
  222. jsonArrays.add(jsonArray1);
  223. JSONArray jsonArray2 = statisticsService.getLowLevelIncrementDetail(endDate, endDate, area, level, indexes[1], sort, lowLevel);
  224. jsonArrays.add(jsonArray2);
  225. //遍历合并2个指标中key值一样的
  226. for (int i = 0; i < jsonArrays.get(0).length(); i++) {
  227. if (jsonArrays.get(1).length() == 0) {
  228. //未回复咨询不存在的时候默认是0
  229. JSONObject map1 = jsonArrays.get(0).getJSONObject(i);
  230. String amount = map1.get("amount").toString() + ",0";
  231. map1.put("amount", amount);
  232. returnJa.put(map1);
  233. } else {
  234. for (int j = 0; j < jsonArrays.get(1).length(); j++) {
  235. JSONObject map1 = jsonArrays.get(0).getJSONObject(i);
  236. JSONObject map2 = jsonArrays.get(1).getJSONObject(j);
  237. String amount = "";
  238. if (map1.get("code").equals(map2.get("code"))) {
  239. amount = map1.get("amount").toString() + "," + map2.get("amount").toString();
  240. map1.put("amount", amount);
  241. returnJa.put(map1);
  242. }
  243. }
  244. }
  245. }
  246. result.put("index_" + indexes[0], returnJa);
  247. return write(200, "查询成功", "data", result);
  248. } catch (Exception e) {
  249. e.printStackTrace();
  250. return error(-1, "查询失败");
  251. }
  252. }
  253. /**
  254. * 指标期间增长量
  255. *
  256. * @param startDate
  257. * @param endDate
  258. * @param area
  259. * @param level
  260. * @param index
  261. * @return
  262. */
  263. @RequestMapping("/leveltwo_increment")
  264. @ResponseBody
  265. public String getIndexLevelTwoIncrement(@RequestParam(required = false) String startDate,
  266. @RequestParam(required = true) String endDate,
  267. @RequestParam(required = true) String area,
  268. @RequestParam(required = true) int level,
  269. @RequestParam(required = true) String index) {
  270. try {
  271. String[] indexes = index.split(",");
  272. JSONObject result = new JSONObject();
  273. for (String idx : indexes) {
  274. result.put("index_" + idx, statisticsAllService.getIndexLevelTwototal(endDate, area, level, idx));
  275. }
  276. return write(200, "查询成功", "data", result);
  277. } catch (Exception e) {
  278. e.printStackTrace();
  279. return error(-1, "查询失败");
  280. }
  281. }
  282. /**
  283. * 获取签约率、签约完成率
  284. *
  285. * @param endDate 截止日期
  286. * @param area 区域
  287. * @param level 区域级别 4:城市 3:区 2:社区 1:团队
  288. * @return
  289. */
  290. @RequestMapping(value = "/sign_info")
  291. @ResponseBody
  292. public String getAreaSignInfo(@RequestParam(required = true) String endDate,
  293. @RequestParam(required = true) String area,
  294. @RequestParam(required = true) int level,
  295. @RequestParam(required = false) String lowCode) {
  296. try {
  297. JSONObject result = new JSONObject();
  298. if (StringUtils.isEmpty(lowCode)) {
  299. long sign = statisticsAllService.getIndexTotal(endDate, area, level, "13");
  300. long weiJf = statisticsAllService.getWeiJiaoFei(endDate, area, level);
  301. JSONObject signRate = statisticsAllService.getSignRate(endDate, area, level);
  302. JSONObject signTaskRate = statisticsAllService.getSignTaskRate(endDate, area, level);
  303. result.put("sign", sign);
  304. result.put("expenses", weiJf);
  305. result.put("signRate", signRate);
  306. result.put("signTaskRate", signTaskRate);
  307. } else {
  308. result = statisticsAllService.getGroupInfo(endDate, lowCode, area, level);
  309. }
  310. return write(200, "查询成功", "data", result);
  311. } catch (Exception e) {
  312. return error(-1, "查询失败");
  313. }
  314. }
  315. /**
  316. * 获取三级指标增量
  317. *
  318. * @param startDate
  319. * @param endDate
  320. * @param area
  321. * @param level
  322. * @return
  323. */
  324. @RequestMapping(value = "/sixfive_statistics")
  325. @ResponseBody
  326. public String getSixFiveStatistics(@RequestParam(required = false) String startDate,
  327. @RequestParam(required = true) String endDate,
  328. @RequestParam(required = true) String area, int level) {
  329. try {
  330. JSONArray result = statisticsAllService.getSixFiveStatistics(endDate, area, level);
  331. return write(200, "查询成功", "data", result);
  332. } catch (Exception e) {
  333. e.printStackTrace();
  334. return error(-1, "查询失败");
  335. }
  336. }
  337. /**
  338. * 指标按间隔统计
  339. *
  340. * @param startDate 起始日期
  341. * @param endDate 结束时间
  342. * @param interval 时间间隔
  343. * @param area 区域或机构
  344. * @param level 级别
  345. * @param index 指标
  346. * @return
  347. */
  348. @RequestMapping(value = "/interval_total")
  349. @ResponseBody
  350. public String indexIntervalTotal(@RequestParam(required = true) String startDate,
  351. @RequestParam(required = true) String endDate,
  352. @RequestParam(required = true) int interval,
  353. @RequestParam(required = true) String area,
  354. @RequestParam(required = true) int level,
  355. @RequestParam(required = true) String index,
  356. @RequestParam(required = false) String lowCode) {
  357. try {
  358. String[] indexes = index.split(",");
  359. JSONObject result = new JSONObject();
  360. if (index != null) {
  361. for (String idx : indexes) {
  362. result.put("index_" + idx, statisticsAllService.getDateTotal(startDate, endDate, interval, area, level, idx, lowCode));
  363. }
  364. }
  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 level1_type等级 1:团队 2社区机构 3区级 4市级
  376. * @param index quotoCode 18/19两率
  377. * @param sort 1降序排列-1升序排列
  378. * @return
  379. */
  380. @RequestMapping("/lowlevel_all")
  381. @ResponseBody
  382. public String getIndexLowLevelTotalSign(@RequestParam(required = true) String date,
  383. @RequestParam(required = true) String area,
  384. @RequestParam(required = true) int level,
  385. @RequestParam(required = true) String index,
  386. @RequestParam(required = true) int sort,
  387. @RequestParam(required = false) String lowLevel,
  388. @RequestParam(required = false) String lowCode) {
  389. try {
  390. String[] indexes = index.split(",");
  391. JSONObject result = new JSONObject();
  392. if (StringUtils.isNotEmpty(lowCode)) {
  393. // 指定level下特定查询级别
  394. result.put("index_" + index, statisticsAllService.getLevelTwoLowLevelTotal(date, area, level, index, sort, lowLevel, lowCode));
  395. } else {
  396. // 未指定level下特定查询级别
  397. for (String idx : indexes) {
  398. if (idx.equals("18") || index.equals("19")) {
  399. result.put("index_" + idx, statisticsAllService.getLowLevelTotalSpecial(date, area, level, idx, sort, lowLevel));
  400. } else if (idx.equals("1") || index.equals("21")) {
  401. result.put("index_" + idx, statisticsAllService.getLowLevelTotal2(date, area, level, idx, sort, lowLevel));
  402. } else {
  403. result.put("index_" + idx, statisticsAllService.getLowLevelTotal(date, area, level, idx, sort, lowLevel));
  404. }
  405. }
  406. }
  407. return write(200, "查询成功", "data", result);
  408. } catch (Exception e) {
  409. e.printStackTrace();
  410. return error(-1, "查询失败");
  411. }
  412. }
  413. /**
  414. * 获取三师转签或高危人群
  415. *
  416. * @param endDate
  417. * @param area
  418. * @param level
  419. * @return
  420. */
  421. @RequestMapping(value = "/sszq_qwrq_info")
  422. @ResponseBody
  423. public String getSszqAndGwrq(@RequestParam(required = true) String endDate,
  424. @RequestParam(required = true) String area,
  425. @RequestParam(required = true) int level) {
  426. try {
  427. JSONObject result = new JSONObject();
  428. JSONObject sszq = statisticsAllService.getSszqAndGwrq(endDate, area, level, "18");
  429. JSONObject gwrq = statisticsAllService.getSszqAndGwrq(endDate, area, level, "19");
  430. result.put("sszq", sszq);
  431. result.put("gwrq", gwrq);
  432. return write(200, "查询成功", "data", result);
  433. } catch (Exception e) {
  434. return error(-1, "查询失败");
  435. }
  436. }
  437. /**
  438. * 二级指标到达量
  439. *
  440. * @param date
  441. * @param area
  442. * @param level
  443. * @param index
  444. * @return
  445. */
  446. @RequestMapping(value = "/leveltwo_all")
  447. @ResponseBody
  448. public String getIndexLevelTwoTotal(@RequestParam(required = true) String date,
  449. @RequestParam(required = true) String area,
  450. @RequestParam(required = true) int level,
  451. @RequestParam(required = true) String index) {
  452. try {
  453. String[] indexes = index.split(",");
  454. JSONObject result = new JSONObject();
  455. for (String idx : indexes) {
  456. result.put("index_" + idx, statisticsAllService.getIndexLevelTwototal(date, area, level, idx));
  457. }
  458. return write(200, "查询成功", "data", result);
  459. } catch (Exception e) {
  460. e.printStackTrace();
  461. return error(-1, "查询失败");
  462. }
  463. }
  464. /**
  465. * 指标截止日期到达量
  466. *
  467. * @param endDate
  468. * @param area
  469. * @param level
  470. * @param index
  471. * @return
  472. */
  473. @RequestMapping("/index_all")
  474. @ResponseBody
  475. public String getIndexAll(@RequestParam(required = true) String endDate,
  476. @RequestParam(required = true) String area,
  477. @RequestParam(required = true) int level,
  478. @RequestParam(required = true) String index) {
  479. try {
  480. String[] indexes = index.split(",");
  481. JSONObject result = new JSONObject();
  482. for (String idx : indexes) {
  483. result.put("index_" + idx, statisticsAllService.getIndexTotal(endDate, area, level, idx));
  484. }
  485. return write(200, "查询成功", "data", result);
  486. } catch (Exception e) {
  487. return error(-1, "查询失败");
  488. }
  489. }
  490. /**
  491. * 咨询统计
  492. * 咨询分析页面具体交互与业务分析内一致,即按市、区、社区、机构有不同展示,可一级级进入查看
  493. * ①回复及时率------医生首次回复24小时内比例
  494. * ②未回复数(数、率)----------当前未回复咨询数、以及相应比例
  495. * ③处理咨询回复时间分布---------全部咨询的首次回复咨询时间分布
  496. *
  497. * @param level 查询的等级,按市、区、机构
  498. * @param area 查询的等级对应Code
  499. * @return
  500. */
  501. @RequestMapping("/Consulting_Stat")
  502. @ResponseBody
  503. public String getConsultingStatistics(@RequestParam(required = true) Integer level,
  504. @RequestParam(required = true) String area) {
  505. try {
  506. return write(200, "查询成功", "data", statisticsService.getConsultingStatistics(level, area));
  507. } catch (Exception e) {
  508. return error(-1, "查询失败");
  509. }
  510. }
  511. /**
  512. * 咨询统计
  513. * 咨询分析页面具体交互与业务分析内一致,即按市、区、社区、机构有不同展示,可一级级进入查看
  514. * ①回复及时率------医生首次回复24小时内比例
  515. * ②未回复数(数、率)----------当前未回复咨询数、以及相应比例
  516. * ③处理咨询回复时间分布---------全部咨询的首次回复咨询时间分布
  517. *
  518. * @param level 查询的等级,按市、区、机构
  519. * @return
  520. */
  521. @RequestMapping("/Consulting_StatList")
  522. @ResponseBody
  523. public String getConsultingStatisticsList(@RequestParam(required = true) Integer level,
  524. @RequestParam(required = true) String area ,
  525. @RequestParam(required = false) String lowlevel) {
  526. try {
  527. JSONObject data = statisticsService.getConsultingStatisticsList(level,area,lowlevel);
  528. if(data!=null){
  529. return write(200, "查询成功", "data", data);
  530. }else{
  531. return error(-1, "查询失败");
  532. }
  533. } catch (Exception e) {
  534. return error(-1, "查询失败");
  535. }
  536. }
  537. /**
  538. * 咨询统计
  539. * 咨询分析页面具体交互与业务分析内一致,即按市、区、社区、机构有不同展示,可一级级进入查看
  540. * ①回复及时率------医生首次回复24小时内比例
  541. * ②未回复数(数、率)----------当前未回复咨询数、以及相应比例
  542. * ③处理咨询回复时间分布---------全部咨询的首次回复咨询时间分布
  543. *
  544. * @param level 查询的等级,按市、区、机构
  545. * @return
  546. */
  547. @RequestMapping("/Consulting_Title")
  548. @ResponseBody
  549. public String getConsultingTitle(@RequestParam(required = true) Integer level,
  550. @RequestParam(required = true) String area) {
  551. try {
  552. JSONObject data = statisticsService.getConsultingTitle(level,area);
  553. if(data!=null){
  554. return write(200, "查询成功", "data", data);
  555. }else{
  556. return error(-1, "查询失败");
  557. }
  558. } catch (Exception e) {
  559. return error(-1, "查询失败");
  560. }
  561. }
  562. /**
  563. * 获取回复数时间分布数
  564. * @param level
  565. * @param area
  566. * @return
  567. */
  568. @RequestMapping("/getCoutListByTime")
  569. @ResponseBody
  570. public String getCoutListByTime(@RequestParam(required = true)String level,@RequestParam(required = true) String area){
  571. try {
  572. return write(200, "查询成功", "data", statisticsService.getCoutListByTime(level,area));
  573. } catch (Exception e) {
  574. return error(-1, "查询失败");
  575. }
  576. }
  577. /**
  578. * 获取绑定率
  579. * 1、选定绑定微信指标,下面排行内,在绑定微信数后新增:"绑定率:xx.22%"
  580. * 2、绑定率=绑定数/已签约数
  581. *
  582. * @return
  583. */
  584. @RequestMapping("/bindingRate_stat")
  585. @ResponseBody
  586. public String getBindingRate() {
  587. try {
  588. return write(200, "查询成功", "data", statisticsService.getBindingRate());
  589. } catch (Exception e) {
  590. return error(-1, "查询失败");
  591. }
  592. }
  593. }