|
@@ -0,0 +1,116 @@
|
|
|
|
+package com.ssj.sys.controller;
|
|
|
|
+
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
|
+import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
|
+import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
|
|
|
+import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
|
|
|
+import com.ssj.framework.basic.common.bean.SplitPage;
|
|
|
|
+import com.ssj.framework.core.common.controller.BaseController;
|
|
|
|
+import com.ssj.framework.core.util.PropertiesUtil;
|
|
|
|
+import com.ssj.service.sys.jxy.service.JxyService;
|
|
|
|
+import com.ssj.service.sys.sort.service.SortService;
|
|
|
|
+import com.ssj.sys.model.ErrorModel;
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
+import org.springframework.ui.Model;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
+
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author sh
|
|
|
|
+ * @className ErrorController
|
|
|
|
+ * @description controller
|
|
|
|
+ * @date 2021/4/8
|
|
|
|
+ */
|
|
|
|
+@RequestMapping("sys/error")
|
|
|
|
+@Controller
|
|
|
|
+public class ErrorController extends BaseController {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private JxyService jxyService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SortService sortService;
|
|
|
|
+
|
|
|
|
+ @RequestMapping("/errorList")
|
|
|
|
+ public String errorList(Model model,
|
|
|
|
+ @RequestParam(required = false, defaultValue = "10") int pageSize,
|
|
|
|
+ @RequestParam(required = false, defaultValue = "1") int pageNo){
|
|
|
|
+
|
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
+ params.put("beginDate", request.getParameter("beginDate")==null?"":request.getParameter("beginDate"));
|
|
|
|
+ params.put("endDate", request.getParameter("endDate")==null?"":request.getParameter("endDate"));
|
|
|
|
+ params.put("lib_name", request.getParameter("lib_name")==null?"":request.getParameter("lib_name"));
|
|
|
|
+ params.put("subject", request.getParameter("subject")==null?"":request.getParameter("subject"));
|
|
|
|
+ SplitPage sp = new SplitPage();
|
|
|
|
+ sp.setAction(request.getRequestURI());
|
|
|
|
+ sp.setPageNo(pageNo);
|
|
|
|
+ sp.setPageSize(pageSize);
|
|
|
|
+ sp.setParams(params);
|
|
|
|
+ Page<ErrorModel> page= jxyService.errorList(params, initPage(pageNo,pageSize));
|
|
|
|
+ sp.setRowCnt((int) page.getTotalElements());
|
|
|
|
+ model.addAttribute("list", page.getContent());
|
|
|
|
+ model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
|
|
|
|
+ model.addAttribute("page", sp);
|
|
|
|
+ model.addAttribute("search", params);
|
|
|
|
+ model.addAttribute("zyb_course", sortService.getParamValByCode("zyb_course"));
|
|
|
|
+ return "sys/error/errorList";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "/exportErrorList", method = RequestMethod.POST)
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public void exportErrorList(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
+ params.put("beginDate", request.getParameter("beginDate")==null?"":request.getParameter("beginDate"));
|
|
|
|
+ params.put("endDate", request.getParameter("endDate")==null?"":request.getParameter("endDate"));
|
|
|
|
+ params.put("lib_name", request.getParameter("lib_name")==null?"":request.getParameter("lib_name"));
|
|
|
|
+ params.put("subject", request.getParameter("subject")==null?"":request.getParameter("subject"));
|
|
|
|
+ ServletOutputStream os = null;
|
|
|
|
+ String fileName="报错记录";
|
|
|
|
+ try {
|
|
|
|
+ os = response.getOutputStream();
|
|
|
|
+ response.reset();
|
|
|
|
+ exportExcelHead(response,fileName);
|
|
|
|
+ Page<ErrorModel> page= jxyService.errorList(params, initPage(0,100000));
|
|
|
|
+ List<ErrorModel> list = new ArrayList<>();
|
|
|
|
+ list.addAll(page.getContent());
|
|
|
|
+ list.forEach(o->o.setFileKey(PropertiesUtil.getValue("STATIC_FILE_URL").concat(o.getFileKey())));
|
|
|
|
+ //把我们构造好的bean对象放到params就可以了
|
|
|
|
+ Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(fileName, fileName, ExcelType.XSSF), ErrorModel.class,
|
|
|
|
+ list);
|
|
|
|
+ workbook.write(os);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }finally{
|
|
|
|
+ if(os != null){
|
|
|
|
+ try {
|
|
|
|
+ os.flush();
|
|
|
|
+ os.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void exportExcelHead(HttpServletResponse response, String fileName) throws Exception{
|
|
|
|
+ String lastFileName = new String(fileName.getBytes("gb2312"), "ISO8859-1") +".xlsx";
|
|
|
|
+ //设定输出文件头
|
|
|
|
+ response.setHeader("Content-disposition", "attachment; filename="+ lastFileName);
|
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
|
+ }
|
|
|
|
+}
|