¶Ô±ÈÐÂÎļþ |
| | |
| | | // |
| | | // 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 com.tencentcloudapi.common.exception.TencentCloudSDKException; |
| | | 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<List<Zonginvoices>> findinvoicesjilu(Integer page, Integer limit) { |
| | | PageInfo<Zonginvoices> cz = this.zongInvoicesService.findinvoicesjilu(page, limit); |
| | | return resultutil.returnSuccess(cz.getTotal(), cz.getList()); |
| | | } |
| | | |
| | | @GetMapping({"zongkaipiaoZi"}) |
| | | public result<List<Zonginvoices>> findinvoicesjilu(Integer page, Integer limit, Zonginvoices zonginvoices) { |
| | | PageInfo<Zonginvoices> cz = this.zongInvoicesService.findinvoicesjilu(page, limit, zonginvoices); |
| | | return resultutil.returnSuccess(cz.getTotal(), cz.getList()); |
| | | } |
| | | |
| | | @PostMapping({"zongfpadd"}) |
| | | public int zongfpadd(Zonginvoices zonginvoices) throws TencentCloudSDKException { |
| | | 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<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); |
| | | |
| | | //模ææä»¶ï¼myfile.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); |
| | | //è·å¾è¯¥doc对象 |
| | | // 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.ç¨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<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; |
| | | } |
| | | } |