LandStatisticController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. package platform.modules.government.web;
  2. import com.alibaba.excel.EasyExcel;
  3. import com.alibaba.excel.EasyExcelFactory;
  4. import com.alibaba.excel.ExcelWriter;
  5. import com.alibaba.excel.metadata.Sheet;
  6. import com.alibaba.excel.metadata.Table;
  7. import com.alibaba.excel.write.merge.LoopMergeStrategy;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.ui.ModelMap;
  11. import org.springframework.web.bind.annotation.*;
  12. import platform.common.base.controller.BaseController;
  13. import platform.common.util.excel.DynamicOneSheetEasyExcel;
  14. import platform.common.util.excel.OneSheetEasyExcel;
  15. import platform.modules.government.dto.ApproveStatisticMonthly;
  16. import platform.modules.government.entity.Street;
  17. import platform.modules.government.service.LandStatisticsService;
  18. import platform.modules.government.service.StreetService;
  19. import platform.modules.sys.web.ResponseMessage;
  20. import javax.servlet.http.HttpServletResponse;
  21. import java.io.FileNotFoundException;
  22. import java.io.FileOutputStream;
  23. import java.net.URLEncoder;
  24. import java.text.ParseException;
  25. import java.util.ArrayList;
  26. import java.util.List;
  27. import java.util.Map;
  28. import java.util.Objects;
  29. /**
  30. * 用地统计Controller
  31. */
  32. @Controller
  33. @RequestMapping("/land_statistic")
  34. public class LandStatisticController extends BaseController {
  35. @Autowired
  36. private LandStatisticsService landStatisticsService;
  37. @Autowired
  38. private StreetService streetService;
  39. @GetMapping("/region/index")
  40. public String region() {
  41. return BASE_GOVERNMENT_PATH + "land_statistic/region";
  42. }
  43. @GetMapping("/plate/index")
  44. public String plate(ModelMap modelMap) {
  45. modelMap.put("streetList", streetService.findList());
  46. return BASE_GOVERNMENT_PATH + "land_statistic/plate";
  47. }
  48. /**
  49. * @Author: huZhiHao
  50. * @Description: 获取待审核 审核中 已审核 统计
  51. * @Date: 2020/1/13
  52. * @Params:
  53. * @Return:
  54. **/
  55. @GetMapping("/approve/status")
  56. @ResponseBody
  57. public ResponseMessage approveStatus(@RequestParam(value = "street_id", defaultValue = "", required = false) String streetId) {
  58. Object o = landStatisticsService.getApproveStatusStatistic(streetId);
  59. return ResponseMessage.success("获取数据成功", o);
  60. }
  61. /**
  62. * @Author: huZhiHao
  63. * @Description: 获取月度分类统计
  64. * @Date: 2020/1/13
  65. * @Params:
  66. * @Return:
  67. **/
  68. @GetMapping("/approve/type")
  69. @ResponseBody
  70. public ResponseMessage getTypeStatistic(
  71. @RequestParam(value = "street_id", defaultValue = "", required = false) String streetId,
  72. @RequestParam(value = "start_time", defaultValue = "", required = false) String startTime,
  73. @RequestParam(value = "end_time", defaultValue = "", required = false) String endTime
  74. ) {
  75. Object o = landStatisticsService.getTypeStatistic(streetId, startTime, endTime);
  76. return ResponseMessage.success("获取数据成功", o);
  77. }
  78. /**
  79. * @Author: huZhiHao
  80. * @Description: 获取月度审核结果对比
  81. * @Date: 2020/1/13
  82. * @Params:
  83. * @Return:
  84. **/
  85. @GetMapping("/approve/result/monthly")
  86. @ResponseBody
  87. public ResponseMessage getMonthlyApproveResult() {
  88. Object o = landStatisticsService.getMonthlyApproveResult();
  89. return ResponseMessage.success("获取数据成功", o);
  90. }
  91. /**
  92. * @Author: huZhiHao
  93. * @Description: 获取月度审核统计表
  94. * @Date: 2020/1/13
  95. * @Params:
  96. * @Return:
  97. **/
  98. // @GetMapping("/approve/statistic/monthly")
  99. // @ResponseBody
  100. // public ResponseMessage getMonthlyApproveStatistic(
  101. // @RequestParam(value = "street_id", defaultValue = "", required = false) String streetId,
  102. // @RequestParam(value = "start_time", defaultValue = "", required = false) String startTime,
  103. // @RequestParam(value = "end_time", defaultValue = "", required = false) String endTime
  104. // ) {
  105. //
  106. // Object o = landStatisticsService.getMonthlyApproveStatistic(streetId, startTime, endTime);
  107. // return ResponseMessage.success("获取数据成功", o);
  108. // }
  109. /**
  110. * @Author: huZhiHao
  111. * @Description: 获取月度审核统计表
  112. * @Date: 2020/1/13
  113. * @Params:
  114. * @Return:
  115. **/
  116. @GetMapping("/approve/statistic/monthly")
  117. public String getMonthlyApproveStatistic(
  118. @RequestParam(value = "street_id", defaultValue = "", required = false) String streetId,
  119. @RequestParam(value = "start_time", defaultValue = "", required = false) String startTime,
  120. @RequestParam(value = "end_time", defaultValue = "", required = false) String endTime,
  121. ModelMap modelMap) {
  122. Object o = landStatisticsService.getMonthlyApproveStatistic(streetId, startTime, endTime);
  123. modelMap.put("list", o);
  124. return BASE_GOVERNMENT_PATH + "land_statistic/region::approve_statistic_monthly";
  125. }
  126. /**
  127. * @Author: huZhiHao
  128. * @Description: 获取月度审核统计表
  129. * @Date: 2020/1/13
  130. * @Params:
  131. * @Return:
  132. **/
  133. // @GetMapping("/approve/statistic/plate")
  134. // @ResponseBody
  135. // public ResponseMessage getPlateStatistic(
  136. // @RequestParam(value = "start_time", defaultValue = "", required = false) String startTime,
  137. // @RequestParam(value = "end_time", defaultValue = "", required = false) String endTime
  138. // ) {
  139. //
  140. // Object o = landStatisticsService.getPlateStatistic(startTime, endTime);
  141. // return ResponseMessage.success("获取数据成功", o);
  142. // }
  143. /**
  144. * @Author: huZhiHao
  145. * @Description: 获取板块统计表
  146. * @Date: 2020/1/13
  147. * @Params:
  148. * @Return:
  149. **/
  150. @GetMapping("/approve/statistic/plate")
  151. public String getPlateStatistic(
  152. @RequestParam(value = "start_time", defaultValue = "", required = false) String startTime,
  153. @RequestParam(value = "end_time", defaultValue = "", required = false) String endTime,
  154. ModelMap modelMap) {
  155. Map o = (Map) landStatisticsService.getPlateStatistic(startTime, endTime);
  156. modelMap.put("head", o.get("head"));
  157. modelMap.put("data", o.get("data"));
  158. return BASE_GOVERNMENT_PATH + "land_statistic/region::approve_statistic_plate";
  159. }
  160. /**
  161. * @Author: huZhiHao
  162. * @Description: 获取每日统计表
  163. * @Date: 2020/1/13
  164. * @Params:
  165. * @Return:
  166. **/
  167. @GetMapping("/approve/statistic/daily")
  168. @ResponseBody
  169. public ResponseMessage getDailyStatistic(
  170. @RequestParam(value = "street_id", defaultValue = "", required = false) String streetId,
  171. @RequestParam(value = "start_time", defaultValue = "", required = false) String startTime,
  172. @RequestParam(value = "end_time", defaultValue = "", required = false) String endTime
  173. ) throws ParseException {
  174. Map o = (Map) landStatisticsService.getDailyStatistic(streetId, startTime, endTime);
  175. return ResponseMessage.success("获取数据成功", o);
  176. }
  177. /*
  178. * 导出月度审核统计
  179. * */
  180. @GetMapping("/approve/statistic/monthly/export")
  181. public ResponseMessage approveStatisticMonthlyExport(
  182. HttpServletResponse response,
  183. @RequestParam(value = "street_id", defaultValue = "", required = false) String streetId,
  184. @RequestParam(value = "start_time", defaultValue = "", required = false) String startTime,
  185. @RequestParam(value = "end_time", defaultValue = "", required = false) String endTime) throws Exception {
  186. // 文件输出位置
  187. /*String outPath = "C:\\Users\\oukele\\Desktop\\test.xlsx";
  188. try {
  189. // 所有行的集合
  190. List<List<Object>> list = new ArrayList<List<Object>>();
  191. for (int i = 1; i <= 10; i++) {
  192. // 第 n 行的数据
  193. List<Object> row = new ArrayList<Object>();
  194. row.add("第" + i + "单元格");
  195. row.add("第" + i + "单元格");
  196. list.add(row);
  197. }
  198. ExcelWriter excelWriter = EasyExcelFactory.getWriter(new FileOutputStream(outPath));
  199. // 表单
  200. Sheet sheet = new Sheet(1,0);
  201. sheet.setSheetName("第一个Sheet");
  202. // 创建一个表格
  203. Table table = new Table(1);
  204. // 动态添加 表头 headList --> 所有表头行集合
  205. List<List<String>> headList = new ArrayList<List<String>>();
  206. // 第 n 行 的表头
  207. List<String> headTitle0 = new ArrayList<String>();
  208. List<String> headTitle1 = new ArrayList<String>();
  209. List<String> headTitle2 = new ArrayList<String>();
  210. headTitle0.add("最顶部-1");
  211. headTitle0.add("标题1");
  212. headTitle1.add("最顶部-1");
  213. headTitle1.add("标题2");
  214. headTitle2.add("最顶部-1");
  215. headTitle2.add("标题3");
  216. headList.add(headTitle0);
  217. headList.add(headTitle1);
  218. headList.add(headTitle2);
  219. table.setHead(headList);
  220. excelWriter.write1(list,sheet,table);
  221. // 记得 释放资源
  222. excelWriter.finish();
  223. System.out.println("ok");
  224. } catch (FileNotFoundException e) {
  225. e.printStackTrace();
  226. }*/
  227. // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
  228. response.setContentType("application/vnd.ms-excel");
  229. response.setCharacterEncoding("utf-8");
  230. // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
  231. String fileName = URLEncoder.encode("全区统计-月度审核统计表", "UTF-8");
  232. response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
  233. List<Map> list = (List<Map>) landStatisticsService.getMonthlyApproveStatistic(streetId, startTime, endTime);
  234. List<ApproveStatisticMonthly> data = new ArrayList<>();
  235. for (Map map : list) {
  236. ApproveStatisticMonthly approveStatisticMonthly = new ApproveStatisticMonthly();
  237. approveStatisticMonthly.setRowName(map.get("rowName") + "");
  238. approveStatisticMonthly.setRentApplyNum(map.get("rentApplyNum") + "");
  239. approveStatisticMonthly.setRentPassNum(map.get("rentPassNum") + "");
  240. approveStatisticMonthly.setRentPassRate(map.get("rentPassRate") + "%");
  241. approveStatisticMonthly.setUseChangeApplyNum(map.get("useChangeApplyNum") + "");
  242. approveStatisticMonthly.setUseChangePassNum(map.get("useChangePassNum") + "");
  243. approveStatisticMonthly.setUseChangePassRate(map.get("useChangePassRate") + "%");
  244. approveStatisticMonthly.setImmovablesChangeApplyNum(map.get("immovablesChangeApplyNum") + "");
  245. approveStatisticMonthly.setImmovablesChangePassNum(map.get("immovablesChangePassNum") + "");
  246. approveStatisticMonthly.setImmovablesChangePassRate(map.get("immovablesChangePassRate") + "%");
  247. approveStatisticMonthly.setEquityStructureChangeApplyNum(map.get("equityStructureChangeApplyNum") + "");
  248. approveStatisticMonthly.setEquityStructureChangePassNum(map.get("equityStructureChangePassNum") + "");
  249. approveStatisticMonthly.setEquityStructureChangePassRate(map.get("equityStructureChangePassRate") + "");
  250. approveStatisticMonthly.setTotalApplyNum(map.get("totalApplyNum") + "");
  251. approveStatisticMonthly.setTotalPassNum(map.get("totalPassNum") + "");
  252. approveStatisticMonthly.setTotalPassRate(map.get("totalPassRate") + "%");
  253. data.add(approveStatisticMonthly);
  254. }
  255. EasyExcel.write(response.getOutputStream(), ApproveStatisticMonthly.class).sheet("sheet1").doWrite(data);
  256. return ResponseMessage.success("获取数据成功");
  257. }
  258. /*
  259. * 导出月度审核统计
  260. * */
  261. @GetMapping("/approve/statistic/plate/export")
  262. public ResponseMessage approveStatisticMonthlyExport(
  263. HttpServletResponse response,
  264. @RequestParam(value = "start_time", defaultValue = "", required = false) String startTime,
  265. @RequestParam(value = "end_time", defaultValue = "", required = false) String endTime) throws Exception {
  266. Map o = (Map) landStatisticsService.getPlateStatistic(startTime, endTime);
  267. List<Street> headers = (List<Street>) o.get("head");
  268. List<Map> datas = (List<Map>) o.get("data");
  269. //填充数据实体
  270. List<List<String>> data = new ArrayList<>();
  271. for (Map map : datas) {
  272. String name = (String) map.get("name");
  273. int[] num = (int[]) map.get("num");
  274. List<String> dataList = new ArrayList<>();
  275. dataList.add(name);
  276. for (int i : num) {
  277. dataList.add(i + "");
  278. }
  279. data.add(dataList);
  280. List<Map> ResultList = (List<Map>) map.get("type");
  281. for (Map map1 : ResultList) {
  282. String name1 = (String) map1.get("name");
  283. List<String> dataList1 = new ArrayList<>();
  284. dataList1.add(name1);
  285. if (Objects.equals("存量工业用地项目公司股权(结构)变更登记", name1)
  286. ||Objects.equals("存量工业用地不动产权权属转移登记", name1)) {
  287. String[] num1 = (String[]) map1.get("streetNum");
  288. for (String i : num1) {
  289. dataList1.add(i);
  290. }
  291. data.add(dataList1);
  292. } else {
  293. int[] num1 = (int[]) map1.get("streetNum");
  294. for (int i : num1) {
  295. dataList1.add(i + "");
  296. }
  297. data.add(dataList1);
  298. }
  299. }
  300. List<String> empty = new ArrayList<>();
  301. empty.add("");
  302. data.add(empty);
  303. }
  304. response.setContentType("application/vnd.ms-excel");
  305. response.setCharacterEncoding("utf-8");
  306. // 这里URLEncoder.encode可以防止中文乱码
  307. String fileName = URLEncoder.encode("板块统计表", "UTF-8");
  308. OneSheetEasyExcel excel = new DynamicOneSheetEasyExcel();
  309. // 设置excel文件名称
  310. excel.setName(fileName);
  311. // 设置sheet名称,只导出一个sheet,所以只设置一次
  312. excel.setSheetName("sheet1");
  313. // 按顺序设置列头
  314. // excel.setHeader("姓名")
  315. // .setHeader("年龄")
  316. // .setHeader("性别");
  317. for (Street street : headers) {
  318. excel.setHeader(street.getName());
  319. }
  320. // 设置返回文件名称
  321. response.setHeader("Content-disposition", "attachment;filename=" + excel.getName());
  322. // 准备数据 , 下面这部分代码可以直接由service里完成
  323. // List<List<String>> data = new ArrayList<>();
  324. // List<Person> list = new ArrayList<>();
  325. // list.add(new Person("陈1", 34, false));
  326. // list.add(new Person("王2", 33, true));
  327. // list.add(new Person("三3", 7, true));
  328. // list.forEach(person -> {
  329. // data.add(
  330. // Arrays.asList(
  331. // person.getName(),
  332. // person.getAge().toString(),
  333. // person.getSex().toString()
  334. // ));
  335. // });
  336. // 将准备好的data 塞入excel对象里,实现导出
  337. excel.exportData(data, response);
  338. return ResponseMessage.success("获取数据成功");
  339. }
  340. }