puzhibing
2023-12-13 302b40b8702f3b203223bacf71d44d76c5a598c0
ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/TReportLossController.java
@@ -6,9 +6,12 @@
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;
@@ -25,6 +28,10 @@
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;
/**
@@ -47,6 +54,9 @@
    @Value("${spring.mail.template-path}")
    private String templatePath;
    @Autowired
    private TEmailService emailService;
    /**
     * 跳转到首页
@@ -151,11 +161,55 @@
                    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();
                    FileInputStream fileInputStream = new FileInputStream(file);
                    File file1 = new File("/usr/local/nginx/html/files/pdf/");
                    if(!file1.exists()){
                        file1.mkdirs();
                    }
                    file1 = new File("/usr/local/nginx/html/files/pdf/reportLossResult_" + randomString + ".pdf");
                    if(!file1.exists()){
                        file1.createNewFile();
                    }
                    FileOutputStream fileOutputStream = new FileOutputStream(file1);
                    HtmlToPdfUtils.convertToPdf(fileInputStream, "IGO", fileOutputStream);
                    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();