| | |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.entity.AgvWrkMastLog; |
| | | import com.zy.asrs.entity.ViewWorkCountInView; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.mapper.ReportQueryMapper; |
| | | import com.zy.asrs.service.AgvWrkMastLogService; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.xml.soap.SAAJResult; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/report/download") |
| | | public class ReportDownloadController extends BaseController { |
| | |
| | | * |
| | | * @since 2.1.1 |
| | | */ |
| | | @GetMapping("/in") |
| | | public void download1(HttpServletResponse response, |
| | | @RequestParam Map<String, Object> param) throws IOException { |
| | | @GetMapping("/countIn") |
| | | public void download1(HttpServletResponse response, @RequestParam Map<String, Object> param) throws IOException { |
| | | try { |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | |
| | | String fileName = URLEncoder.encode("日入库汇总", "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | // 这里需要设置不关闭流 |
| | | EasyExcel.write(response.getOutputStream(), ViewWorkCountInView.class).autoCloseStream(Boolean.FALSE).sheet("sheet1") |
| | | .doWrite(getInData(param)); |
| | | EasyExcel.write(response.getOutputStream(), ViewWorkCountInView.class).autoCloseStream(Boolean.FALSE).sheet("sheet1").doWrite(getInData(param)); |
| | | } catch (Exception e) { |
| | | // 重置response |
| | | response.reset(); |
| | |
| | | * |
| | | * @since 2.1.1 |
| | | */ |
| | | @RequestMapping("/out") |
| | | public void download2(HttpServletResponse response, |
| | | @RequestParam Map<String, Object> param) throws IOException { |
| | | @RequestMapping("/countOut") |
| | | public void download2(HttpServletResponse response, @RequestParam Map<String, Object> param) throws IOException { |
| | | try { |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName = URLEncoder.encode("日出库汇总", "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | List<ViewWorkCountInView> outData = getOutData(param); |
| | | // 这里需要设置不关闭流 |
| | | EasyExcel.write(response.getOutputStream(), ViewWorkCountInView.class).autoCloseStream(Boolean.FALSE).sheet("sheet1") |
| | | .doWrite(getOutData(param)); |
| | | EasyExcel.write(response.getOutputStream(), ViewWorkCountInView.class).autoCloseStream(Boolean.FALSE).sheet("sheet1").doWrite(outData); |
| | | } catch (Exception e) { |
| | | // 重置response |
| | | response.reset(); |
| | |
| | | startTime = split[0].split(" ")[0].replace("-", "."); |
| | | endTime = split[1].split(" ")[0].replace("-", "."); |
| | | } |
| | | List<ViewWorkCountInView> allCountIn = reportQueryMapper.selectWorkCountOut(Integer.valueOf((String) param.get("pageNumber")), Integer.valueOf((String) param.get("pageSize")), (String) param.get("matnr"), startTime, endTime); |
| | | List<ViewWorkCountInView> allCountIn = reportQueryMapper.selectWorkCountOut(null,null, (String) param.get("matnr"), startTime, endTime); |
| | | return allCountIn; |
| | | } |
| | | |
| | |
| | | * @since 2.1.1 |
| | | */ |
| | | @RequestMapping("/wrkMastLog") |
| | | public void wrkMastLog(HttpServletResponse response, |
| | | @RequestParam Map<String, Object> param) throws IOException { |
| | | public void wrkMastLog(HttpServletResponse response, @RequestParam Map<String, Object> param) throws IOException { |
| | | try { |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | |
| | | String fileName = URLEncoder.encode("工作档维护日志", "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | // 这里需要设置不关闭流 |
| | | EasyExcel.write(response.getOutputStream(), ViewWorkCountInView.class).autoCloseStream(Boolean.FALSE).sheet("sheet1") |
| | | .doWrite(getWrkMastLogData(param)); |
| | | EasyExcel.write(response.getOutputStream(), ViewWorkCountInView.class).autoCloseStream(Boolean.FALSE).sheet("sheet1").doWrite(getWrkMastLogData(param)); |
| | | } catch (Exception e) { |
| | | // 重置response |
| | | response.reset(); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 文件下载并且失败的时候返回json(默认失败了会返回一个有部分数据的Excel) |
| | | * 日出库明细统计 |
| | | * |
| | | * @since 2.1.1 |
| | | */ |
| | | @RequestMapping("/out") |
| | | public void out(HttpServletResponse response, @RequestParam(required = false) Map<String, Object> bean) throws IOException { |
| | | try { |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName = URLEncoder.encode("日出库明细统计", "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | List<ViewWorkInBean> list = reportQueryMapper.queryViewWorkOutList(JSON.parseObject(JSON.toJSONString(bean), ViewWorkInBean.class)); |
| | | // 这里需要设置不关闭流 |
| | | EasyExcel.write(response.getOutputStream(), ViewWorkInBean.class).autoCloseStream(Boolean.FALSE).sheet("sheet1").doWrite(list); |
| | | } catch (Exception e) { |
| | | // 重置response |
| | | response.reset(); |
| | | response.setContentType("application/json"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("status", "failure"); |
| | | map.put("message", "下载文件失败" + e.getMessage()); |
| | | response.getWriter().println(JSON.toJSONString(map)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 文件下载并且失败的时候返回json(默认失败了会返回一个有部分数据的Excel) |
| | | * 日入库明细统计 |
| | | * |
| | | * @since 2.1.1 |
| | | */ |
| | | @RequestMapping("/in") |
| | | public void in(HttpServletResponse response, @RequestParam(required = false) Map<String, Object> bean) throws IOException { |
| | | try { |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName = URLEncoder.encode("日入库明细统计", "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | ViewWorkInBean viewWorkInBean = JSON.parseObject(JSON.toJSONString(bean), ViewWorkInBean.class); |
| | | List<ViewWorkInBean> list = reportQueryMapper.queryViewWorkInList(viewWorkInBean); |
| | | // 这里需要设置不关闭流 |
| | | EasyExcel.write(response.getOutputStream(), ViewWorkInBean.class).autoCloseStream(Boolean.FALSE).sheet("sheet1").doWrite(list); |
| | | } catch (Exception e) { |
| | | // 重置response |
| | | response.reset(); |
| | | response.setContentType("application/json"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("status", "failure"); |
| | | map.put("message", "下载文件失败" + e.getMessage()); |
| | | response.getWriter().println(JSON.toJSONString(map)); |
| | | } |
| | | } |
| | | } |