StatisticsController.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. package com.yihu.wlyy.web.statistic;
  2. import com.yihu.wlyy.entity.statistics.PopulationBase;
  3. import com.yihu.wlyy.service.app.statistics.StatisticsService;
  4. import com.yihu.wlyy.web.BaseController;
  5. import io.swagger.annotations.Api;
  6. import org.json.JSONArray;
  7. import org.json.JSONObject;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.data.redis.core.StringRedisTemplate;
  10. import org.springframework.stereotype.Controller;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.ResponseBody;
  13. /**
  14. * Created by lyr on 2016/08/16.
  15. */
  16. @Controller
  17. @RequestMapping(value = "/statistics")
  18. @Api(description = "统计")
  19. public class StatisticsController extends BaseController {
  20. @Autowired
  21. StatisticsService statisticsService;
  22. /**
  23. * 缓存人口数据到redis
  24. *
  25. * @return
  26. */
  27. @RequestMapping(value = "/people_num_to_redis")
  28. @ResponseBody
  29. public String peopleNumToRedis(){
  30. try{
  31. statisticsService.peopleNumToRedis();
  32. return write(200,"更新成功");
  33. }catch (Exception e){
  34. e.printStackTrace();
  35. return error(-1,"更新失败");
  36. }
  37. }
  38. /**
  39. * 指标按间隔统计
  40. *
  41. * @param startDate 起始日期
  42. * @param endDate 结束时间
  43. * @param interval 时间间隔
  44. * @param area 区域或机构
  45. * @param level 级别
  46. * @param index 指标
  47. * @return
  48. */
  49. @RequestMapping(value = "/interval")
  50. @ResponseBody
  51. public String indexInterval(String startDate, String endDate, int interval, String area, int level, String index) {
  52. String tag = "";
  53. try {
  54. String[] indexes = index.split(",");
  55. JSONObject result = new JSONObject();
  56. if (index != null) {
  57. for (String idx : indexes) {
  58. result.put("index_" + idx, statisticsService.getDateIncrementDetail(startDate, endDate, interval, area, level, idx));
  59. }
  60. }
  61. return write(200, "查询成功!", "data", result);
  62. } catch (Exception e) {
  63. e.printStackTrace();
  64. return error(-1, tag + "查询失败!");
  65. }
  66. }
  67. /**
  68. * 指标期间增长量
  69. *
  70. * @param startDate
  71. * @param endDate
  72. * @param area
  73. * @param level
  74. * @param index
  75. * @return
  76. */
  77. @RequestMapping("/increment")
  78. @ResponseBody
  79. public String getIndexIncrement(String startDate, String endDate, String area, int level, String index) {
  80. try {
  81. String[] indexes = index.split(",");
  82. JSONObject result = new JSONObject();
  83. for (String idx : indexes) {
  84. result.put("index_" + idx, statisticsService.getIntervalIncrement(startDate, endDate, area, level, idx));
  85. }
  86. return write(200, "查询成功", "data", result);
  87. } catch (Exception e) {
  88. e.printStackTrace();
  89. return error(-1, "查询失败");
  90. }
  91. }
  92. /**
  93. * 指标截止日期累积量
  94. *
  95. * @param endDate
  96. * @param area
  97. * @param level
  98. * @param index
  99. * @return
  100. */
  101. @RequestMapping("/total")
  102. @ResponseBody
  103. public String getIndexTotal(String endDate, String area, int level, String index) {
  104. try {
  105. String[] indexes = index.split(",");
  106. JSONObject result = new JSONObject();
  107. for (String idx : indexes) {
  108. result.put("index_" + idx, statisticsService.getTotalAmount(endDate, area, level, idx));
  109. }
  110. return write(200, "查询成功", "data", result);
  111. } catch (Exception e) {
  112. e.printStackTrace();
  113. return error(-1, "查询失败");
  114. }
  115. }
  116. /**
  117. * 指标期间增长量
  118. *
  119. * @param startDate
  120. * @param endDate
  121. * @param area
  122. * @param level
  123. * @param index
  124. * @return
  125. */
  126. @RequestMapping("/lowlevel_increment")
  127. @ResponseBody
  128. public String getIndexLowLevelIncrement(String startDate, String endDate, String area, int level, String index, int sort,String lowLevel) {
  129. try {
  130. String[] indexes = index.split(",");
  131. JSONObject result = new JSONObject();
  132. for (String idx : indexes) {
  133. result.put("index_" + idx, statisticsService.getLowLevelIncrementDetail(startDate, endDate, area, level, idx, sort,lowLevel));
  134. }
  135. return write(200, "查询成功", "data", result);
  136. } catch (Exception e) {
  137. e.printStackTrace();
  138. return error(-1, "查询失败");
  139. }
  140. }
  141. /**
  142. * 指标截止日期累积量
  143. *
  144. * @param endDate
  145. * @param area
  146. * @param level
  147. * @param index
  148. * @return
  149. */
  150. @RequestMapping("/lowlevel_total")
  151. @ResponseBody
  152. public String getIndexLowLevelTotal(String endDate, String area, int level, String index, int sort, String lowLevel) {
  153. try {
  154. String[] indexes = index.split(",");
  155. JSONObject result = new JSONObject();
  156. for (String idx : indexes) {
  157. result.put("index_" + idx, statisticsService.getLowLevelTotalDetail(endDate, area, level, idx, sort, lowLevel));
  158. }
  159. return write(200, "查询成功", "data", result);
  160. } catch (Exception e) {
  161. e.printStackTrace();
  162. return error(-1, "查询失败");
  163. }
  164. }
  165. /**
  166. * 指标期间增长量
  167. *
  168. * @param startDate
  169. * @param endDate
  170. * @param area
  171. * @param level
  172. * @param index
  173. * @return
  174. */
  175. @RequestMapping("/leveltwo_increment")
  176. @ResponseBody
  177. public String getIndexLevelTwoIncrement(String startDate, String endDate, String area, int level, String index) {
  178. try {
  179. String[] indexes = index.split(",");
  180. JSONObject result = new JSONObject();
  181. for (String idx : indexes) {
  182. result.put("index_" + idx, statisticsService.getLevelTwoIndexIncrement(startDate, endDate, area, level, idx));
  183. }
  184. return write(200, "查询成功", "data", result);
  185. } catch (Exception e) {
  186. e.printStackTrace();
  187. return error(-1, "查询失败");
  188. }
  189. }
  190. /**
  191. * 获取签约率、签约完成率
  192. *
  193. * @param endDate 截止日期
  194. * @param area 区域
  195. * @param level 区域级别 4:城市 3:区 2:社区 1:团队
  196. * @param type 1:签约率 2:签约完成率
  197. * @return
  198. */
  199. @RequestMapping(value = "/rate")
  200. @ResponseBody
  201. public String getAreaRate(String endDate, String area, int level, String type) {
  202. try {
  203. JSONObject result = null;
  204. if (type.equals("1")) {
  205. result = statisticsService.getSignRate(endDate,area,level);
  206. } else {
  207. result = statisticsService.getSignTaskRate(endDate,area,level);
  208. }
  209. return write(200, "查询成功", "data", result);
  210. } catch (Exception e) {
  211. e.printStackTrace();
  212. return error(-1, "查询失败");
  213. }
  214. }
  215. /**
  216. * 获取三级指标增量
  217. *
  218. * @param startDate
  219. * @param endDate
  220. * @param area
  221. * @param level
  222. * @return
  223. */
  224. @RequestMapping(value = "/sixfive_statistics")
  225. @ResponseBody
  226. public String getSixFiveStatistics(String startDate, String endDate, String area, int level){
  227. try{
  228. JSONArray result = statisticsService.getSixFiveStatistics(startDate,endDate,area,level);
  229. return write(200,"查询成功","data",result);
  230. }catch (Exception e){
  231. e.printStackTrace();
  232. return error(-1,"查询失败");
  233. }
  234. }
  235. }