SysCuratorController.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. package com.ssj.sys.controller;
  2. import cn.afterturn.easypoi.excel.ExcelExportUtil;
  3. import cn.afterturn.easypoi.excel.entity.ExportParams;
  4. import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
  5. import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import com.ssj.bean.conch.curator.dto.CuratorTeacherListDto;
  8. import com.ssj.bean.sys.fx.domain.Merchant;
  9. import com.ssj.bean.weixin.libmy.domain.TbLibJoin;
  10. import com.ssj.framework.basic.common.bean.SplitPage;
  11. import com.ssj.framework.basic.utils.DateHelper;
  12. import com.ssj.framework.core.common.controller.BaseController;
  13. import com.ssj.framework.core.util.ResponseEntity;
  14. import com.ssj.framework.weixin.util.Collections3;
  15. import com.ssj.framework.weixin.util.DateUtil;
  16. import com.ssj.service.conch.parents.service.ParentService;
  17. import com.ssj.service.conch.parents.v1.dto.CorrectDetailDto4;
  18. import com.ssj.service.sys.fx.service.MerchantService;
  19. import com.ssj.service.sys.fx.service.SysCuratorService;
  20. import com.ssj.service.weixin.library.service.ILibJoinService;
  21. import org.apache.commons.lang3.StringUtils;
  22. import org.apache.poi.ss.usermodel.Workbook;
  23. import org.springframework.stereotype.Controller;
  24. import org.springframework.ui.Model;
  25. import org.springframework.web.bind.annotation.RequestMapping;
  26. import org.springframework.web.bind.annotation.RequestMethod;
  27. import org.springframework.web.bind.annotation.RequestParam;
  28. import org.springframework.web.bind.annotation.ResponseBody;
  29. import javax.servlet.ServletOutputStream;
  30. import javax.servlet.http.HttpServletRequest;
  31. import javax.servlet.http.HttpServletResponse;
  32. import java.io.IOException;
  33. import java.util.*;
  34. /**
  35. * @author sh
  36. * @className SysCuratorController
  37. * @description TODO
  38. * @date 2020/6/17
  39. */
  40. @Controller
  41. @RequestMapping("/sys/admin/curator")
  42. public class SysCuratorController extends BaseController {
  43. @Autowired
  44. private SysCuratorService sysCuratorService;
  45. @Autowired
  46. private ILibJoinService joinService;
  47. @Autowired
  48. private MerchantService merchantService;
  49. @Autowired
  50. private ParentService parentService;
  51. @RequestMapping("/index")
  52. public String index(Model model, @RequestParam String libId){
  53. Map<String,Object> data = sysCuratorService.findIndexData(libId);
  54. TbLibJoin join = joinService.getById(libId);
  55. model.addAllAttributes(data);
  56. model.addAttribute("libId",libId);
  57. model.addAttribute("leagueName",join.getLeagueName());
  58. Merchant merchant=merchantService.getMerchantByLibId(libId);
  59. model.addAttribute("merchant",merchant);
  60. return "sys/fx/curator/index";
  61. }
  62. @RequestMapping("/studentIndex")
  63. public String studentIndex(Model model, @RequestParam String libId,@RequestParam(required = false, defaultValue = "10") int pageSize,
  64. @RequestParam(required = false, defaultValue = "1") int pageNo,@RequestParam(required = false, defaultValue = "") String searchValue){
  65. Map<String, Object> params = new HashMap<String, Object>();
  66. params.put("searchValue",searchValue);
  67. params.put("libId",libId);
  68. params.put("stat",request.getParameter("stat")==null?"":request.getParameter("stat"));
  69. params.put("startDate",request.getParameter("startDate")==null?"":request.getParameter("startDate"));
  70. params.put("endDate",request.getParameter("endDate")==null?"":request.getParameter("endDate"));
  71. params.put("serviceType",request.getParameter("serviceType")==null?"":request.getParameter("serviceType"));
  72. params.put("pageSize",pageSize);
  73. params.put("pageNo",pageNo);
  74. String classId = request.getParameter("classId")==null?"":request.getParameter("classId");
  75. params.put("classId",classId);
  76. Map<String,Object> data = sysCuratorService.studentIndex(libId,params);
  77. getModel(model,data,params,pageSize,pageNo);
  78. return "sys/fx/curator/studentIndex";
  79. }
  80. @RequestMapping("/teacherIndex")
  81. public String teacherIndex(Model model, @RequestParam String libId,@RequestParam(required = false, defaultValue = "10") int pageSize,
  82. @RequestParam(required = false, defaultValue = "1") int pageNo,@RequestParam(required = false, defaultValue = "") String searchValue){
  83. String classId = request.getParameter("classId")==null?"":request.getParameter("classId");
  84. Map<String,Object> data = sysCuratorService.teacherIndex(libId,pageSize,pageNo,searchValue,classId);
  85. Map<String, Object> params = new HashMap<String, Object>();
  86. params.put("searchValue",searchValue);
  87. params.put("libId",libId);
  88. params.put("classId",classId);
  89. getModel(model,data,params,pageSize,pageNo);
  90. return "sys/fx/curator/teacherIndex";
  91. }
  92. @RequestMapping("/classIndex")
  93. public String classIndex(Model model, @RequestParam String libId,@RequestParam(required = false, defaultValue = "10") int pageSize,
  94. @RequestParam(required = false, defaultValue = "1") int pageNo,@RequestParam(required = false, defaultValue = "") String searchValue){
  95. String teacherId = request.getParameter("teacherId")==null?"":request.getParameter("teacherId");
  96. Map<String,Object> data = sysCuratorService.classIndex(libId,pageSize,pageNo,searchValue,teacherId);
  97. Map<String, Object> params = new HashMap<String, Object>();
  98. params.put("searchValue",searchValue);
  99. params.put("libId",libId);
  100. params.put("teacherId",teacherId);
  101. getModel(model,data,params,pageSize,pageNo);
  102. return "sys/fx/curator/classIndex";
  103. }
  104. @RequestMapping("/homeworkIndex")
  105. public String homeworkIndex(Model model, @RequestParam String libId,@RequestParam(required = false, defaultValue = "10") int pageSize,
  106. @RequestParam(required = false, defaultValue = "1") int pageNo,@RequestParam(required = false, defaultValue = "") String searchValue){
  107. Map<String, Object> params = new HashMap<String, Object>();
  108. String queryDate = request.getParameter("queryDate")==null? DateHelper.format(new Date(),"yyyy-MM-dd"):request.getParameter("queryDate");
  109. params.put("searchValue",searchValue==null?"":searchValue);
  110. params.put("queryDate",queryDate);
  111. params.put("libId",libId);
  112. Map<String,Object> data = sysCuratorService.homeworkIndex(libId,pageSize,pageNo,params);
  113. getModel(model,data,params,pageSize,pageNo);
  114. return "sys/fx/curator/homeworkIndex";
  115. }
  116. public Model getModel(Model model,Map<String,Object> data,Map<String, Object> params,int pageSize,int pageNo){
  117. SplitPage sp = new SplitPage();
  118. sp.setAction(request.getRequestURI());
  119. sp.setPageNo(pageNo);
  120. sp.setPageSize(pageSize);
  121. sp.setParams(params);
  122. sp.setRowCnt(Integer.parseInt(data.get("total").toString()));
  123. model.addAttribute("page", sp);
  124. model.addAllAttributes(data);
  125. model.addAttribute("search", params);
  126. model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
  127. return model;
  128. }
  129. @RequestMapping("/allLibIndex")
  130. public String allLibIndex(Model model){
  131. String queryDate = request.getParameter("queryDate")==null? DateHelper.format(DateUtil.addDays(new Date(),-1),"yyyy-MM-dd"):request.getParameter("queryDate");
  132. Map<String,Object> data = sysCuratorService.allLibIndex(queryDate);
  133. model.addAllAttributes(data);
  134. return "sys/fx/curator/home";
  135. }
  136. @RequestMapping(value = "/searchTop")
  137. @ResponseBody
  138. public ResponseEntity searchTop(String startDate,String endDate,String subject) {
  139. ResponseEntity responseEntity = new ResponseEntity();
  140. try{
  141. int pageSize = 10;
  142. int pageNo = 1;
  143. Map<String, Object> map=sysCuratorService.searchTop(startDate,endDate,pageNo,pageSize,subject);
  144. responseEntity.success(map,"操作成功");
  145. }catch (Exception e) {
  146. e.printStackTrace();
  147. }
  148. return responseEntity;
  149. }
  150. @RequestMapping(value = "/searchActiveTop")
  151. @ResponseBody
  152. public ResponseEntity searchActiveTop(String startDate,String endDate,String subject) {
  153. ResponseEntity responseEntity = new ResponseEntity();
  154. try{
  155. int pageSize = 10;
  156. int pageNo = 1;
  157. Map<String, Object> map=sysCuratorService.searchActiveTop(startDate,endDate,pageNo,pageSize);
  158. responseEntity.success(map,"操作成功");
  159. }catch (Exception e) {
  160. e.printStackTrace();
  161. }
  162. return responseEntity;
  163. }
  164. @RequestMapping(value = "/exportActiveInfo", method = RequestMethod.POST)
  165. @ResponseBody
  166. public void exportActiveInfo(Model model, HttpServletRequest request, HttpServletResponse response) {
  167. String startDate = request.getParameter("startDate")==null?"":request.getParameter("startDate");
  168. String endDate = request.getParameter("endDate")==null?"":request.getParameter("endDate");
  169. ServletOutputStream os = null;
  170. try {
  171. String libName= "活跃度排行";
  172. os = response.getOutputStream(); //获得输出流
  173. response.reset(); //清空输出流
  174. String fileName = new String(libName.getBytes("gb2312"), "ISO8859-1") +".xlsx";
  175. response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
  176. response.setContentType("application/vnd.ms-excel;charset=UTF-8");
  177. response.setCharacterEncoding("utf-8");
  178. Map<String, Object> params = new HashMap<String, Object>();
  179. int pageSize = 10000;
  180. int pageNo = 1;
  181. Map<String, Object> data=sysCuratorService.searchActiveTop(startDate,endDate,pageNo,pageSize);
  182. List<Map<String, Object>> studentList = (List<Map<String, Object>>)data.get("list");
  183. //学生数据
  184. List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
  185. entity.add(new ExcelExportEntity("馆名称", "league_name"));
  186. entity.add(new ExcelExportEntity("活跃人数", "active_count"));
  187. entity.add(new ExcelExportEntity("总人数", "all_vips"));
  188. entity.add(new ExcelExportEntity("百分比(%)", "percent"));
  189. //把我们构造好的bean对象放到params就可以了
  190. List<Map<String, Object>> studentList2 = new ArrayList<>();
  191. studentList2.addAll(studentList);
  192. Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(libName, libName, ExcelType.XSSF), entity,
  193. studentList2);
  194. workbook.write(os);
  195. }catch (IOException e) {
  196. e.printStackTrace();
  197. }catch (Exception e1){
  198. e1.printStackTrace();
  199. }finally{
  200. if(os != null){
  201. try {
  202. os.flush();
  203. os.close();
  204. } catch (IOException e) {
  205. e.printStackTrace();
  206. }
  207. }
  208. }
  209. }
  210. @RequestMapping(value = "/exportInfo", method = RequestMethod.POST)
  211. @ResponseBody
  212. public void exportInfo(Model model, HttpServletRequest request, HttpServletResponse response) {
  213. String startDate = request.getParameter("startDate")==null?"":request.getParameter("startDate");
  214. String endDate = request.getParameter("endDate")==null?"":request.getParameter("endDate");
  215. String subject = request.getParameter("type")==null?"":request.getParameter("type");
  216. ServletOutputStream os = null;
  217. try {
  218. String libName= StringUtils.isEmpty(subject)?"上传作业总排行":subject+"作业排行";
  219. os = response.getOutputStream(); //获得输出流
  220. response.reset(); //清空输出流
  221. String fileName = new String(libName.getBytes("gb2312"), "ISO8859-1") +".xlsx";
  222. response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
  223. response.setContentType("application/vnd.ms-excel;charset=UTF-8");
  224. response.setCharacterEncoding("utf-8");
  225. Map<String, Object> params = new HashMap<String, Object>();
  226. int pageSize = 10000;
  227. int pageNo = 1;
  228. Map<String, Object> data=sysCuratorService.searchTop(startDate,endDate,pageNo,pageSize,subject);
  229. List<Map<String, Object>> studentList = (List<Map<String, Object>>)data.get("list");
  230. //学生数据
  231. List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
  232. entity.add(new ExcelExportEntity("馆名称", "league_name"));
  233. entity.add(new ExcelExportEntity("作业份数", "totolCount"));
  234. //把我们构造好的bean对象放到params就可以了
  235. List<Map<String, Object>> studentList2 = new ArrayList<>();
  236. studentList2.addAll(studentList);
  237. Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(libName, libName, ExcelType.XSSF), entity,
  238. studentList2);
  239. workbook.write(os);
  240. }catch (IOException e) {
  241. e.printStackTrace();
  242. }catch (Exception e1){
  243. e1.printStackTrace();
  244. }finally{
  245. if(os != null){
  246. try {
  247. os.flush();
  248. os.close();
  249. } catch (IOException e) {
  250. e.printStackTrace();
  251. }
  252. }
  253. }
  254. }
  255. @RequestMapping(value = "/exportDetail", method = RequestMethod.POST)
  256. @ResponseBody
  257. public void exportDetail(Model model, HttpServletRequest request, HttpServletResponse response) {
  258. String type = request.getParameter("reportType");
  259. ServletOutputStream os = null;
  260. try {
  261. String libName=type.equals("1")?"学生":type.equals("2")?"老师":"作业";
  262. os = response.getOutputStream(); //获得输出流
  263. response.reset(); //清空输出流
  264. String fileName = new String(libName.getBytes("gb2312"), "ISO8859-1") +".xlsx";
  265. response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
  266. response.setContentType("application/vnd.ms-excel;charset=UTF-8");
  267. response.setCharacterEncoding("utf-8");
  268. Map<String, Object> params = new HashMap<String, Object>();
  269. String libId = request.getParameter("libId");
  270. int pageSize = request.getParameter("pageSize")==null?1:Integer.parseInt(request.getParameter("pageSize"));
  271. int pageNo = request.getParameter("pageNo")==null?1:Integer.parseInt(request.getParameter("pageNo"));
  272. String searchValue = request.getParameter("searchValue")==null?"":request.getParameter("searchValue");
  273. String classId = request.getParameter("classId")==null?"":request.getParameter("classId");
  274. String serviceType = request.getParameter("serviceType") ==null?"":request.getParameter("serviceType");
  275. if("1".equals(type)){
  276. params.put("searchValue",request.getParameter("searchValue"));
  277. params.put("libId",request.getParameter("libId"));
  278. params.put("startDate",request.getParameter("startDate")==null?"":request.getParameter("startDate"));
  279. params.put("endDate",request.getParameter("endDate")==null?"":request.getParameter("endDate"));
  280. params.put("stat",request.getParameter("stat")==null?"":request.getParameter("stat"));
  281. params.put("classId",classId);
  282. params.put("serviceType",serviceType);
  283. params.put("pageSize",1);
  284. params.put("pageNo",1);
  285. Map<String,Object> data = sysCuratorService.studentIndex(request.getParameter("libId"),params);
  286. params.put("pageSize",data.get("total"));
  287. data = sysCuratorService.studentIndex(request.getParameter("libId"),params);
  288. List<Map<String, Object>> studentList = (List<Map<String, Object>>)data.get("list");
  289. //学生数据
  290. List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
  291. //构造对象等同于@Excel
  292. ExcelExportEntity excelentity0 = new ExcelExportEntity("学生姓名", "childName");
  293. excelentity0.setNeedMerge(true);
  294. entity.add(excelentity0);
  295. ExcelExportEntity excelentity = new ExcelExportEntity("班级名称", "className");
  296. excelentity.setNeedMerge(true);
  297. entity.add(excelentity);
  298. ExcelExportEntity excelentity2 = new ExcelExportEntity("年级", "grade");
  299. excelentity2.setNeedMerge(true);
  300. entity.add(excelentity2);
  301. ExcelExportEntity excelentity6 = new ExcelExportEntity("电话", "phone");
  302. excelentity6.setNeedMerge(true);
  303. entity.add(excelentity6);
  304. ExcelExportEntity excelentity5 = new ExcelExportEntity(null, "serviceList");
  305. List<ExcelExportEntity> temp = new ArrayList<ExcelExportEntity>();
  306. temp.add(new ExcelExportEntity("服务开始时间", "start_time"));
  307. temp.add(new ExcelExportEntity("服务结束时间", "end_time"));
  308. temp.add(new ExcelExportEntity("是否有效", "stat"));
  309. temp.add(new ExcelExportEntity("服务类型", "correct_type"));
  310. //构造List等同于@ExcelCollection
  311. excelentity5.setList(temp);
  312. entity.add(excelentity5);
  313. //把我们构造好的bean对象放到params就可以了
  314. List<Map<String, Object>> studentList2 = new ArrayList<>();
  315. studentList2.addAll(studentList);
  316. Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(libName, libName, ExcelType.XSSF), entity,
  317. studentList2);
  318. workbook.write(os);
  319. }else if("2".equals(type)){
  320. //老师数据
  321. Map<String,Object> data = sysCuratorService.teacherIndex(libId,pageSize,pageNo,searchValue,classId);
  322. pageSize = Integer.parseInt(data.get("total").toString());
  323. data = sysCuratorService.teacherIndex(libId,pageSize,pageNo,searchValue,classId);
  324. List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
  325. entity.add(new ExcelExportEntity("老师姓名","name"));
  326. entity.add(new ExcelExportEntity("科目","subject"));
  327. entity.add(new ExcelExportEntity("模块","teacherTypeValues"));
  328. entity.add(new ExcelExportEntity("班级数","classSum"));
  329. entity.add(new ExcelExportEntity("电话号码","phone"));
  330. //把我们构造好的bean对象放到params就可以了
  331. List<CuratorTeacherListDto> teacherList = (List<CuratorTeacherListDto>)data.get("list");
  332. List<Map<String, Object>> teacherListNew = dtoToMap(teacherList);
  333. Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(libName, libName, ExcelType.XSSF), entity,
  334. teacherListNew);
  335. workbook.write(os);
  336. }else{
  337. String queryDate = request.getParameter("queryDate")==null? DateHelper.format(new Date(),"yyyy-MM-dd"):request.getParameter("queryDate");
  338. params.put("queryDate",queryDate);
  339. params.put("libId",request.getParameter("libId"));
  340. params.put("searchValue",searchValue);
  341. Map<String,Object> data = sysCuratorService.homeworkIndex(libId,pageSize,pageNo,params);
  342. pageSize =Integer.parseInt(data.get("total").toString());
  343. data = sysCuratorService.homeworkIndex(libId,pageSize,pageNo,params);
  344. List<Map<String, Object>> homeworkList = (List<Map<String, Object>>)data.get("list");
  345. List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
  346. entity.add(new ExcelExportEntity("学生名称","child_name"));
  347. entity.add(new ExcelExportEntity("年级","grade"));
  348. entity.add(new ExcelExportEntity("学校","school"));
  349. entity.add(new ExcelExportEntity("绑定校区","league_name"));
  350. entity.add(new ExcelExportEntity("上传作业份数","pictureCount"));
  351. entity.add(new ExcelExportEntity("语文作业份数","count1"));
  352. entity.add(new ExcelExportEntity("数学作业份数","count2"));
  353. entity.add(new ExcelExportEntity("英语作业份数","count3"));
  354. entity.add(new ExcelExportEntity("批改作业份数","correctedCount"));
  355. List<Map<String, Object>> studentList2 = new ArrayList<>();
  356. studentList2.addAll(homeworkList);
  357. Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(libName, libName, ExcelType.XSSF), entity,
  358. studentList2);
  359. workbook.write(os);
  360. }
  361. }catch (IOException e) {
  362. e.printStackTrace();
  363. }catch (Exception e1){
  364. e1.printStackTrace();
  365. }finally{
  366. if(os != null){
  367. try {
  368. os.flush();
  369. os.close();
  370. } catch (IOException e) {
  371. e.printStackTrace();
  372. }
  373. }
  374. }
  375. }
  376. private List<Map<String, Object>> dtoToMap(List<CuratorTeacherListDto> teacherList){
  377. if(Collections3.isEmpty(teacherList)){
  378. return new ArrayList<>();
  379. }
  380. List<Map<String, Object>> list = new ArrayList<>();
  381. for (CuratorTeacherListDto dto:teacherList){
  382. Map<String, Object> map = new HashMap<>();
  383. map.put("name",dto.getName());
  384. map.put("subject",dto.getSubject());
  385. List<String> teacherTypeList = dto.getTeacherTypeList();
  386. if(Collections3.isEmpty(teacherTypeList)){
  387. map.put("teacherTypeList","");
  388. }else{
  389. String teacherTypeValues = "";
  390. for (String str:teacherTypeList){
  391. if(str.equals("2")){
  392. teacherTypeValues+="现场管理、";
  393. }else if(str.equals("3")){
  394. teacherTypeValues+="学科答疑、";
  395. }else{
  396. teacherTypeValues+="作业标注";
  397. }
  398. }
  399. if(teacherTypeValues.endsWith("、")){
  400. teacherTypeValues = teacherTypeValues.substring(0,teacherTypeValues.length()-1);
  401. }
  402. map.put("teacherTypeValues",teacherTypeValues);
  403. }
  404. map.put("classSum",dto.getClassSum());
  405. map.put("phone",dto.getPhone());
  406. list.add(map);
  407. }
  408. return list;
  409. }
  410. @RequestMapping("/homeworkInfoVip")
  411. public String homeworkInfoVip(Model model,
  412. @RequestParam String vipId,
  413. @RequestParam String subject,
  414. @RequestParam String queryDate){
  415. CorrectDetailDto4 correctDetail = parentService.correctDetail4(vipId, subject,queryDate);
  416. model.addAttribute("correctDetail", correctDetail);
  417. return "sys/fx/curator/homeworkInfoVip";
  418. }
  419. }