From d3917f85da1a654f08a1ab6ba040d0817f0847b3 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期一, 17 二月 2025 17:53:38 +0800 Subject: [PATCH] bug修改 --- ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TOrderInvoiceController.java | 151 ++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 134 insertions(+), 17 deletions(-) diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TOrderInvoiceController.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TOrderInvoiceController.java index 5132faf..8f1cde2 100644 --- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TOrderInvoiceController.java +++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TOrderInvoiceController.java @@ -9,13 +9,13 @@ import com.ruoyi.common.core.web.page.PageInfo; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; +import com.ruoyi.common.security.annotation.Logical; +import com.ruoyi.common.security.annotation.RequiresPermissions; +import com.ruoyi.common.security.service.TokenService; import com.ruoyi.order.api.model.TOrderInvoice; import com.ruoyi.order.api.query.TOrderInvoiceQuery; import com.ruoyi.order.api.vo.TOrderInvoiceVO; -import com.ruoyi.order.dto.AddOrderInvoice; -import com.ruoyi.order.dto.GetOrderInvoiceList; -import com.ruoyi.order.dto.MyOrderInvoiceInfo; -import com.ruoyi.order.dto.OrderInvoiceList; +import com.ruoyi.order.dto.*; import com.ruoyi.order.export.OrderInvoiceExport; import com.ruoyi.order.service.TOrderInvoiceService; import io.swagger.annotations.Api; @@ -53,6 +53,9 @@ @Resource private TOrderInvoiceService orderInvoiceService; + @Resource + private TokenService tokenService; + @@ -62,23 +65,20 @@ public AjaxResult addOrderInvoice(@RequestBody AddOrderInvoice addOrderInvoice){ return orderInvoiceService.addOrderInvoice(addOrderInvoice); } - + + + @RequiresPermissions(value = {"/invoiceManagement"}, logical = Logical.OR) @PostMapping("/pageList") @ApiOperation(value = "查询开票分页列表", tags = {"管理后台-发票管理"}) public AjaxResult<PageInfo<TOrderInvoiceVO>> pageList(@RequestBody TOrderInvoiceQuery query){ return AjaxResult.success(orderInvoiceService.pageList(query)); } - @GetMapping("/uploadPdf") - @ApiOperation(value = "上传发票", tags = {"管理后台-发票管理"}) - public AjaxResult<String> uploadPdf(@RequestParam("id") Long id, - @RequestParam("invoiceUrl") String invoiceUrl){ - TOrderInvoice orderInvoice = orderInvoiceService.getById(id); - orderInvoice.setInvoiceUrl(invoiceUrl); - orderInvoiceService.updateById(orderInvoice); + + public static void main(String[] args) { // 发送邮箱 // 收件人电子邮箱,TODO 换成自己的收件箱 - String to = orderInvoice.getMailbox(); + String to = "619865809@qq.com"; // 发件人电子邮箱,TODO 换成自己的发件箱 String from = "13281306557@163.com"; // 指定发送邮件的主机为 @@ -128,12 +128,12 @@ //组装的顺序非常重要,一定要先组装文本域,再组装文件 MimeBodyPart htmlPart = new MimeBodyPart(); // 组装内容 - htmlPart.setContent("This is message content", "text/html;charset=UTF-8"); + htmlPart.setContent("开票", "text/html;charset=UTF-8"); msgMultipart.addBodyPart(htmlPart); // 组装附件 MimeBodyPart filePart = new MimeBodyPart(); - String imageUrl = invoiceUrl; + String imageUrl = "https://mxcd.zhinenganguan.com/file/2025-02-14/_1@2x.png"; try { // 下载数据 URL url = new URL(imageUrl); @@ -141,7 +141,116 @@ byte[] imageBytes = IOUtils.toByteArray(inputStream); // 创建临时文件 - File tempFile = File.createTempFile("tempImage", ".png"); + // 截取imageUrl后缀名 + String fileExtension = imageUrl.substring(imageUrl.lastIndexOf(".")); + File tempFile = File.createTempFile("tempImage", fileExtension); + try (FileOutputStream fos = new FileOutputStream(tempFile)) { + fos.write(imageBytes); + } + + // 创建 FileDataSource + FileDataSource fileDataSource = new FileDataSource(tempFile); + System.out.println("FileDataSource created: " + fileDataSource.getName()); + // 如果需要,可以使用 DataHandler 进行进一步处理 + DataHandler dh = new DataHandler(fileDataSource); + // 清理:删除临时文件(如果不再需要) + tempFile.deleteOnExit(); // 可根据需要保留或删除 + filePart.setDataHandler(dh); + // 附件区别内嵌内容的一个特点是有文件名,为防止中文乱码要编码 + filePart.setFileName(MimeUtility.encodeText(dh.getName())); + msgMultipart.addBodyPart(filePart); + message.saveChanges(); + //发送 + //Transport.send(message, message.getAllRecipients()); + Transport.send(message); + System.out.println("发送成功"); + } catch (Exception e) { + e.printStackTrace(); + } + }catch (MessagingException | UnsupportedEncodingException mex) { + mex.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @RequiresPermissions(value = {"/invoiceManagement/accept_hear_case"}, logical = Logical.OR) + @PostMapping("/uploadPdf") + @ApiOperation(value = "上传发票", tags = {"管理后台-发票管理"}) + public AjaxResult<String> uploadPdf(@RequestBody UploadPdfDTO dto){ + TOrderInvoice orderInvoice = orderInvoiceService.getById(dto.getId()); + orderInvoice.setInvoiceUrl(dto.getInvoiceUrl()); + orderInvoice.setStatus(3); + orderInvoiceService.updateById(orderInvoice); + // 发送邮箱 + // 收件人电子邮箱,TODO 换成自己的收件箱 + String to = orderInvoice.getMailbox(); + // 发件人电子邮箱,TODO 换成自己的发件箱 + String from = "13281306557@163.com"; + // 指定发送邮件的主机为 + String host = "smtp.163.com"; + // 获取系统属性 + Properties properties = new Properties(); + // 设置邮件服务器 + properties.setProperty("mail.smtp.host", host); + properties.setProperty("mail.smtp.port", "465"); // 使用SSL端口 + // 邮件发送协议 + properties.setProperty("mail.transport.protocol", "smtp"); + //是否启用调试模式(启用调试模式可打印客户端与服务器交互过程时一问一答的响应消息) + properties.setProperty("mail.debug","true"); + properties.setProperty("mail.smtp.auth", "true"); + // 获取默认session对象 + Session session = Session.getDefaultInstance(properties,new Authenticator(){ + @Override + public PasswordAuthentication getPasswordAuthentication() + { + //发件人邮件用户名、授权码,换成自己的发件箱及授权码 + return new PasswordAuthentication("13281306557@163.com", "NUSdxDQqadYvVek2"); + } + }); + + try{ + // 创建默认的 MimeMessage 对象 + MimeMessage message = new MimeMessage(session); + // Set From,设置发件人 + InternetAddress fromMail = new InternetAddress(from); + //设置发件人名称,TODO 换成自己的发件箱 + fromMail.setPersonal(MimeUtility.encodeText("明星电力<13281306557@163.com>")); + message.setFrom(fromMail); + // Set To: 设置收件人 + InternetAddress toMail = new InternetAddress(to); + // TODO 换成自己的收件箱 + InternetAddress toMail2 = new InternetAddress(to); + //发多个邮箱 + Address[] allRecipients = {toMail, toMail2}; + message.setRecipients(Message.RecipientType.TO, allRecipients); + // Set Subject: 邮件主体 + message.setSubject("明星电力"); + // 设置消息体 + message.setSentDate(new Date()); + // 指定为混合关系 + MimeMultipart msgMultipart = new MimeMultipart("mixed"); + message.setContent(msgMultipart); + // 邮件信息组装 + //组装的顺序非常重要,一定要先组装文本域,再组装文件 + MimeBodyPart htmlPart = new MimeBodyPart(); + // 组装内容 + htmlPart.setContent("开票", "text/html;charset=UTF-8"); + msgMultipart.addBodyPart(htmlPart); + + // 组装附件 + MimeBodyPart filePart = new MimeBodyPart(); + String imageUrl = dto.getInvoiceUrl(); + try { + // 下载数据 + URL url = new URL(imageUrl); + InputStream inputStream = url.openStream(); + byte[] imageBytes = IOUtils.toByteArray(inputStream); + + // 创建临时文件 + // 截取imageUrl后缀名 + String fileExtension = imageUrl.substring(imageUrl.lastIndexOf(".")); + File tempFile = File.createTempFile("tempImage", fileExtension); try (FileOutputStream fos = new FileOutputStream(tempFile)) { fos.write(imageBytes); } @@ -172,7 +281,9 @@ } return AjaxResult.success(); } - + + + @RequiresPermissions(value = {"/invoiceManagement"}, logical = Logical.OR) @PostMapping("/statusCount") @ApiOperation(value = "查询开票状态数量", tags = {"管理后台-发票管理"}) public AjaxResult<Map<String,Integer>> statusCount(@RequestBody TOrderInvoiceQuery query){ @@ -182,6 +293,7 @@ /** * 发票管理导出 */ + @RequiresPermissions(value = {"/invoiceManagement/export"}, logical = Logical.OR) @ApiOperation(value = "发票管理导出", tags = {"管理后台-发票管理"}) @Log(title = "发票管理导出", businessType = BusinessType.EXPORT) @PutMapping("/export") @@ -235,6 +347,11 @@ @GetMapping("/getMyOrderInvoiceInfo/{id}") @ApiOperation(value = "获取开票记录详情", tags = {"小程序-充电发票"}) public AjaxResult<MyOrderInvoiceInfo> getMyOrderInvoiceInfo(@PathVariable String id){ + TOrderInvoice orderInvoice = orderInvoiceService.getById(id); + Long userId = tokenService.getLoginUserApplet().getUserId(); + if(!orderInvoice.getAppUserId().equals(userId)){ + return AjaxResult.error("权限不足"); + } MyOrderInvoiceInfo myOrderInvoiceInfo = orderInvoiceService.getMyOrderInvoiceInfo(id); return AjaxResult.success(myOrderInvoiceInfo); } -- Gitblit v1.7.1