luodangjia
2024-07-22 f9fff682ff6b21344401bb86f85d25c97c37b073
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;
    /**
     * 跳转到首页
@@ -149,13 +159,46 @@
                if(ToolUtil.isNotEmpty(userInfo.getEmail())){
                    String path = templatePath +  "user/reportLossResult.html";
                    Document document = Jsoup.parse(new File(path), "UTF-8");
                    document.getElementById("chinese").attr("style", "display: none;");
                    document.getElementById("french").attr("style", "display: none;");
                    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();