From a5c2c7e633e0dba4b80c8a15fd34c38ae097befc Mon Sep 17 00:00:00 2001 From: zhibing.pu <393733352@qq.com> Date: 星期五, 21 六月 2024 10:03:06 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/2.0' into 2.0 --- ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/TReportLossController.java | 74 +++++++++++++++++++++++++++++++++++++ 1 files changed, 74 insertions(+), 0 deletions(-) diff --git a/ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/TReportLossController.java b/ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/TReportLossController.java index bcdccd8..aa9afb7 100644 --- a/ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/TReportLossController.java +++ b/ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/TReportLossController.java @@ -5,6 +5,17 @@ import com.stylefeng.guns.core.common.constant.factory.PageFactory; import com.stylefeng.guns.core.shiro.ShiroKit; import com.stylefeng.guns.core.util.SinataUtil; +import com.stylefeng.guns.core.util.ToolUtil; +import com.stylefeng.guns.modular.system.model.TEmail; +import com.stylefeng.guns.modular.system.model.TUser; +import com.stylefeng.guns.modular.system.service.ITUserService; +import com.stylefeng.guns.modular.system.service.TEmailService; +import com.stylefeng.guns.modular.system.util.EmailUtil; +import com.stylefeng.guns.modular.system.util.itextpdf.HtmlToPdfUtils; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @@ -16,6 +27,11 @@ import com.stylefeng.guns.modular.system.model.TReportLoss; import com.stylefeng.guns.modular.system.service.ITReportLossService; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.util.Date; import java.util.Map; /** @@ -32,6 +48,15 @@ @Autowired private ITReportLossService tReportLossService; + + @Autowired + private ITUserService userService; + + @Value("${spring.mail.template-path}") + private String templatePath; + + @Autowired + private TEmailService emailService; /** * 跳转到首页 @@ -129,6 +154,55 @@ tReportLoss.setHandleUserId(ShiroKit.getUser().getObjectId()); boolean b = tReportLossService.updateById(tReportLoss); if(b){ + try { + TUser userInfo = userService.selectById(tReportLoss.getUserId()); + if(ToolUtil.isNotEmpty(userInfo.getEmail())){ + String path = templatePath + "user/reportLossResult.html"; + Document document = Jsoup.parse(new File(path), "UTF-8"); + document.getElementById("chinese").remove(); + document.getElementById("french").remove(); + document.getElementsByTag("title").get(0).text("Notification of the result of the loss report"); + Element english_user = document.getElementById("english_user"); + english_user.text("Hello " + userInfo.getNickName() + ","); + Element english_content = document.getElementById("english_content"); + english_content.text(info); + EmailUtil.send(userInfo.getEmail(), "Notification of the result of the loss report", document.html()); + + //开始生成pdf收据和html收据 + File file = new File("/usr/local/nginx/html/files/html/"); + if(!file.exists()){ + file.mkdirs(); + } + String randomString = ToolUtil.getRandomString(10); + file = new File("/usr/local/nginx/html/files/html/reportLossResult_" + randomString + ".html"); + if(!file.exists()){ + file.createNewFile(); + } + FileWriter fileWriter = new FileWriter(file); + fileWriter.write(document.html()); + fileWriter.flush(); + fileWriter.close(); + + String link ="http://182.160.16.251:81/files/html/reportLossResult_" + randomString + ".html"; + TEmail tEmail = new TEmail(); + tEmail.setLink(link); + tEmail.setUserId(userInfo.getId()); + tEmail.setType(1); + tEmail.setName("Notification of the result of the loss report"); + tEmail.setCreateTime(new Date()); + int i = cn.hutool.core.date.DateUtil.dayOfWeek(new Date())-1; + tEmail.setWeek(EmailUtil.getWeek(2,i)); + boolean am = cn.hutool.core.date.DateUtil.isAM(new Date()); + if(am){ + tEmail.setAmOrPm("AM"); + }else { + tEmail.setAmOrPm("PM"); + } + emailService.insert(tEmail); + } + }catch (Exception e){ + e.printStackTrace(); + } return SUCCESS_TIP; } return ERROR; -- Gitblit v1.7.1