From 61747a14819075bf6da2c1597b6c22e22e026686 Mon Sep 17 00:00:00 2001 From: fei.wang <wf18701153496@163.com> Date: 星期一, 15 四月 2024 14:25:11 +0800 Subject: [PATCH] 4-15修改提交 --- src/main/java/com/flow/controller/ZongInvoicesController.java | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 226 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/flow/controller/ZongInvoicesController.java b/src/main/java/com/flow/controller/ZongInvoicesController.java index ee96cb8..7fe9060 100644 --- a/src/main/java/com/flow/controller/ZongInvoicesController.java +++ b/src/main/java/com/flow/controller/ZongInvoicesController.java @@ -5,23 +5,45 @@ 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.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +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() { } @@ -48,8 +70,208 @@ 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<List<Zonginvoices>> tableSearch(Zonginvoices manager, int page, int limit) throws Exception { + PageInfo<Zonginvoices> 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<min){ + rand= random.nextInt(max); + } + //鐢熸垚鏂扮殑鏂囦欢鍚嶇О + String newName=dateStr.concat(rand+"").concat(suffix); + /*File.separator:鏄郴缁熻嚜鍔ㄥ垽瀹氬垎闅旂锛堜笉鍚岀殑鎿嶄綔绯荤粺涓� 璺緞鍒嗛殧绗︿笉涓�鏍� 浣嗘槸java璇█鏄法骞冲彴鐨� 鎵�浠ュ氨闇�瑕� 缁熶竴 鍒嗛殧绗︼級*/ + File file1=new File(path+File.separator+newName); + //鎶婃垜浠笂娆$殑鏂囦欢閫氳繃transferTo鍐欏叆鏈湴鏂囦欢 + file.transferTo(file1); + return newName; + } + @ResponseBody + @RequestMapping("/down") + public void down( Integer id,HttpServletRequest request, HttpServletResponse response) throws Exception{ + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.eq("sqnum", id); + Zonginvoices zonginvoices = zongInvoicesMapper.selectOne(queryWrapper); + + //妯℃嫙鏂囦欢锛宮yfile.txt涓洪渶瑕佷笅杞界殑鏂囦欢 + String fileName = request.getSession().getServletContext().getRealPath("WEB-INF")+"/"+zonginvoices.getDanhao(); + //鑾峰彇杈撳叆娴� + InputStream bis = new BufferedInputStream(new FileInputStream(new File(fileName))); + //鍋囧浠ヤ腑鏂囧悕涓嬭浇鐨勮瘽 + String filename = zonginvoices.getDanhao(); + //杞爜锛屽厤寰楁枃浠跺悕涓枃涔辩爜 + filename = URLEncoder.encode(filename,"UTF-8"); + //璁剧疆鏂囦欢涓嬭浇澶� + response.addHeader("Content-Disposition", "attachment;filename=" + filename); + //1.璁剧疆鏂囦欢ContentType绫诲瀷锛岃繖鏍疯缃紝浼氳嚜鍔ㄥ垽鏂笅杞芥枃浠剁被鍨� + response.setContentType("multipart/form-data"); + BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); + int len = 0; + while((len = bis.read()) != -1){ + out.write(len); + out.flush(); + } + out.close(); + } + /** + * 涓嬭浇鏂囨。 + */ + @ResponseBody + @RequestMapping("/downloadDocument") + public ResponseEntity<byte[]> downloadDocument(Integer id, HttpServletRequest request) { + + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.eq("sqnum", id); + Zonginvoices zonginvoices = zongInvoicesMapper.selectOne(queryWrapper); + //鑾峰緱璇oc瀵硅薄 +// Doc doc = docService.getById(id); + //鐢ㄦ枃浠朵笅杞藉伐鍏风被 涓嬭浇鏂囦欢 + ResponseEntity<byte[]> responseEntity = this.FileDownLoad(id, zonginvoices, request); + return responseEntity; + } + + public static ResponseEntity<byte[]> 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.鐢╰itle(瀛樺湪涓枃)涓烘枃浠跺悕锛屽彲鑳戒細鏈変贡鐮侀棶棰� + * + * 2.鐢╢ileName(涓嶅瓨鍦ㄤ腑鏂� )涓烘枃浠跺悕锛屼笉浼氭湁涔辩爜闂 + * 濡�: 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); + // 鐢╯pringmvc 鎻愪緵鐨勪笅杞芥柟寮� + ResponseEntity<byte[]> responseEntity = new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.OK); + return responseEntity; + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return null; + } } -- Gitblit v1.9.3