// // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) // package com.flow.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.flow.mapper.zongInvoicesMapper; import com.flow.pojo.Manager; import com.flow.pojo.OperationLog; import com.flow.pojo.TbFuwuqi; import com.flow.pojo.Zonginvoices; import com.flow.service.zongInvoicesService; import com.flow.util.result; import com.flow.util.resultutil; import com.github.pagehelper.PageInfo; import java.io.*; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Random; import java.util.UUID; import org.apache.commons.io.FileUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @RestController @RequestMapping({"/hxzk"}) public class ZongInvoicesController { @Autowired zongInvoicesService zongInvoicesService; @Autowired zongInvoicesMapper zongInvoicesMapper; public ZongInvoicesController() { } @GetMapping({"zongkaipiao"}) public result> findinvoicesjilu(Integer page, Integer limit) { PageInfo cz = this.zongInvoicesService.findinvoicesjilu(page, limit); return resultutil.returnSuccess(cz.getTotal(), cz.getList()); } @GetMapping({"zongkaipiaoZi"}) public result> findinvoicesjilu(Integer page, Integer limit, Zonginvoices zonginvoices) { PageInfo cz = this.zongInvoicesService.findinvoicesjilu(page, limit, zonginvoices); return resultutil.returnSuccess(cz.getTotal(), cz.getList()); } @PostMapping({"zongfpadd"}) public int zongfpadd(Zonginvoices zonginvoices) { return this.zongInvoicesService.zongfpadd(zonginvoices); } @PostMapping({"findsqnum"}) public Zonginvoices findsqnum(Zonginvoices zonginvoices) { return this.zongInvoicesService.findsqnum(zonginvoices); } @PostMapping({"UpdateKaiPiao"}) public ModelAndView UpdateKaiPiao(Zonginvoices zonginvoices) { this.zongInvoicesService.UpdateKaiPiao(zonginvoices); // QueryWrapper queryWrapper = new QueryWrapper(); // queryWrapper.eq("id", tbFuwuqi.getId()); // TbFuwuqi tbFuwuqi1 = tbFuwuqiMapper.selectOne(queryWrapper); // OperationLog operationLog = new OperationLog(); // operationLog.setCaozuotype("修改"); // operationLog.setCaozuocontent("修改服务器:"+tbFuwuqi1.getServername()); // operationLogService.addOperationLog(operationLog); // Date date = new Date(); // SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // operationLog.setCaozuodate(formatter.format(date)); // operationLogMapper.insert(operationLog); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("/page/ChongZhi.jsp"); return modelAndView; } @PostMapping({"DeleteKaiPiao"}) public int DeleteKaiPiao(String kaipiaoId) { return this.zongInvoicesService.DeleteKaiPiao(kaipiaoId); } @PostMapping({"adddanhao"}) public int adddanhao(Zonginvoices zonginvoices) { return this.zongInvoicesService.adddanhao(zonginvoices); } @PostMapping({"ZonginvoicesSearch"}) public result> tableSearch(Zonginvoices manager, int page, int limit) throws Exception { PageInfo cz = this.zongInvoicesService.tableSearch(manager, page, limit); // for(int i = 0; i < cz.getSize(); ++i) { // if (((Manager)cz.getList().get(i)).getCompany() != null) { // SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd"); // Date date = new Date(); // Date endDay = date2.parse(cz.getList().get(i).getEnddate());//结束时间 // Long starTime = date.getTime(); // Long endTime = endDay.getTime(); // Long num11 = endTime - starTime;//时间戳 // //// if ((num11/24/60/60/1000)<0){ //// ((Manager)cz.getList().get(i)).setRemainingdays("0天"); //// }else{ //// ((Manager)cz.getList().get(i)).setRemainingdays(+num11/24/60/60/1000+"天"); //// } //// this.cardService.UpdateCard((Card)cz.getList().get(i)); //// this.cardService.UpdateCard((Card)cz.getList().get(i)); // } // } return resultutil.returnSuccess(cz.getTotal(), cz.getList()); } /** * 文档上传 */ @ResponseBody @PostMapping("/saveDocument") public ModelAndView saveDocument(MultipartFile file, HttpServletRequest request,Zonginvoices zonginvoices) throws IOException { System.out.println("打印数据=========》》》》》》》》》》》》》》》"); String filename = this.AddXcd(file,request); System.out.println(filename ); // System.out.println("doc=" + doc); //1.获取原始文件名 // String uploadFileName = file.getOriginalFilename(); // System.out.println("要上传的原始文件名字是:" + uploadFileName); // //2.截取文件扩展名 // String extendName = uploadFileName.substring(uploadFileName.lastIndexOf(".") + 1, uploadFileName.length()); // //3.把文件加上随机数,防止文件重复 // String uuid = UUID.randomUUID().toString().replace("-", "").toUpperCase(); // //4.生成的新的服务器文件名 // String newfileName = uuid + "." + extendName; // System.out.println("生成的新的服务器文件名是:" + newfileName); //防止服务器文件名重名 // //5.获取真实的服务器文件上传地址 (文件的存储位置) // String filePath = request.getServletContext().getRealPath("WEB-INF") + "\\" + newfileName; // System.out.println("服务器运行目录,最终上传的路径:" + filePath); // //6.执行上传 // file.transferTo(new File(filePath)); // System.out.println("文件上传结束!"); // //调用文件上传工具类 上传文件 zonginvoices.setDanhao(filename); this.zongInvoicesService.UpdateKaiPiao(zonginvoices); // FileUpLoadUtils.Fileupload(file, request, doc, docService); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("/page/KaiPiaoJiLu.jsp"); return modelAndView; // return t } public static String AddXcd(MultipartFile file,HttpServletRequest request) throws IOException { // 获取图片的原始文件名称 String oldName=file.getOriginalFilename(); //获取服务器路径:upload getRealPath:获取一个相对路径的真实路径 // String path="D:\\HxzkFlow\\HxzkFlow\\HxzkFlow\\src\\webapp\\WEB-INF"; String path="C:\\Users\\Administrator\\Desktop\\nginx\\html\\apache-tomcat-7.0.70\\webapps\\HxzkFlow\\WEB-INF"; //文件改名================================ //1.截取后缀格式.png .jpg String suffix=null; if (oldName.length()>0){ suffix= oldName.substring(oldName.lastIndexOf(".")); } //2.生成新的文件名 SimpleDateFormat dateFormat=new SimpleDateFormat("yyyyMMddHHmmssSSS"); String dateStr=dateFormat.format(new Date()); //生成随机数 Random random=new Random(); int max=1000000; int min=100000; int rand= random.nextInt(max); while (rand downloadDocument(Integer id, HttpServletRequest request) { QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.eq("sqnum", id); Zonginvoices zonginvoices = zongInvoicesMapper.selectOne(queryWrapper); //获得该doc对象 // Doc doc = docService.getById(id); //用文件下载工具类 下载文件 ResponseEntity responseEntity = this.FileDownLoad(id, zonginvoices, request); return responseEntity; } public static ResponseEntity FileDownLoad(Integer id, Zonginvoices zonginvoices ,HttpServletRequest request) { //获得要下载的地址 // String path = request.getSession().getServletContext().getRealPath("D:\\HxzkFlow\\HxzkFlow\\HxzkFlow\\src\\webapp\\WEB-INF"); String path = request.getSession().getServletContext().getRealPath("D:\\HxzkFlow\\HxzkFlow\\HxzkFlow\\src\\webapp\\WEB-INF\\")+zonginvoices.getDanhao(); File file = new File(path, zonginvoices.getDanhao()); if (file.exists()) { try { //设置请求头 HttpHeaders headers = new HttpHeaders(); /** * 1.用title(存在中文)为文件名,可能会有乱码问题 * * 2.用fileName(不存在中文 )为文件名,不会有乱码问题 * 如: String downName = new String(doc.getFileName().getBytes("utf-8"), "ISO-8859-1"); * ---要保证没有乱码问题可第二种方式 * */ //文件下载的名字, 可能存在乱码问题 String newFileName = zonginvoices.getDanhao().split("\\.")[1]; String downName = new String(newFileName.getBytes("utf-8"), "ISO-8859-1"); // 设置以附件的形式下载 headers.setContentDispositionFormData("attachment", downName); // 设置文件内容以流的形式来下载 headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); // 用springmvc 提供的下载方式 ResponseEntity responseEntity = new ResponseEntity(FileUtils.readFileToByteArray(file), headers, HttpStatus.OK); return responseEntity; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return null; } }