zhibing.pu
2024-09-02 71a68f675e319967c3078f3f2b86ee971b47b50b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.stylefeng.guns.modular.system.service.impl;
 
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
import com.stylefeng.guns.modular.system.dao.ReportLossMapper;
import com.stylefeng.guns.modular.system.model.ReportLoss;
import com.stylefeng.guns.modular.system.model.TEmail;
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.service.IReportLossService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
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 com.stylefeng.guns.modular.taxi.model.OrderTaxi;
import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.util.Date;
 
@Service
public class ReportLossServiceImpl extends ServiceImpl<ReportLossMapper, ReportLoss> implements IReportLossService {
 
    @Autowired
    private IOrderPrivateCarService orderPrivateCarService;
 
    @Autowired
    private IOrderTaxiService orderTaxiService;
 
    @Autowired
    private IOrderCrossCityService orderCrossCityService;
 
    @Autowired
    private IOrderLogisticsService orderLogisticsService;
 
    @Autowired
    private IUserInfoService userInfoService;
 
    @Value("${spring.mail.template-path}")
    private String templatePath;
 
    @Autowired
    private TEmailService emailService;
 
 
 
    @Override
    public void addReportLoss(Integer orderType, Integer orderId, String remark, String image, Integer language) throws Exception {
        ReportLoss reportLoss = new ReportLoss();
        reportLoss.setImage(image);
        reportLoss.setInsertTime(new Date());
        reportLoss.setOrderId(orderId);
        reportLoss.setOrderType(orderType);
        reportLoss.setRemark(remark);
        reportLoss.setState(1);
        reportLoss.setStatus(1);
        switch (orderType){
            case 1:
                OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId);
                reportLoss.setUserId(orderPrivateCar.getUserId());
                break;
            case 2:
                OrderTaxi orderTaxi = orderTaxiService.selectById(orderId);
                reportLoss.setUserId(orderTaxi.getUserId());
                break;
            case 3:
                OrderCrossCity orderCrossCity = orderCrossCityService.selectById(orderId);
                reportLoss.setUserId(orderCrossCity.getUserId());
                break;
            case 4:
                OrderLogistics orderLogistics = orderLogisticsService.selectById(orderId);
                reportLoss.setUserId(orderLogistics.getUserId());
                break;
            case 5:
                OrderLogistics orderLogistics1 = orderLogisticsService.selectById(orderId);
                reportLoss.setUserId(orderLogistics1.getUserId());
                break;
        }
        this.insert(reportLoss);
 
        UserInfo userInfo = userInfoService.selectById(reportLoss.getUserId());
 
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    if(ToolUtil.isNotEmpty(userInfo.getEmail())){
                        String path = templatePath + "user/reportLoss.html";
                        Document document = Jsoup.parse(new File(path), "UTF-8");
                        if(language == 1){
                            document.getElementById("english").remove();
                            document.getElementById("french").remove();
                            document.getElementsByTag("title").get(0).text("物品报失");
                            Element english_user = document.getElementById("chinese_user");
                            english_user.text("您好 " + userInfo.getNickName() + ",");
                        }
                        if(language == 2){
                            document.getElementById("chinese").remove();
                            document.getElementById("french").remove();
                            document.getElementsByTag("title").get(0).text("Report items lost");
                            Element english_user = document.getElementById("english_user");
                            english_user.text("Hello " + userInfo.getNickName() + ",");
                        }
                        if(language == 3){
                            document.getElementById("chinese").remove();
                            document.getElementById("english").remove();
                            document.getElementsByTag("title").get(0).text("Signaler l'objet perdu");
                            Element english_user = document.getElementById("french_user");
                            english_user.text("Bonjour! " + userInfo.getNickName() + ",");
                        }
                        EmailUtil.send(userInfo.getEmail(), language == 1 ? "物品报失" : language == 2 ? "Report items lost" : "Signaler l'objet perdu",  document.html());
 
                        //开始生成pdf收据和html收据
                        File file = new File("/home/igotechgh/nginx/html/files/html/");
                        if(!file.exists()){
                            file.mkdirs();
                        }
                        String randomString = ToolUtil.getRandomString(10);
                        file = new File("/home/igotechgh/nginx/html/files/html/reportLoss_" + randomString + ".html");
                        if(!file.exists()){
                            file.createNewFile();
                        }
                        FileWriter fileWriter = new FileWriter(file);
                        fileWriter.write(document.html());
                        fileWriter.flush();
                        fileWriter.close();
 
                        String link ="https://igo.i-go.group/files/html/reportLoss_" + randomString + ".html";
                        TEmail tEmail = new TEmail();
                        tEmail.setLink(link);
                        tEmail.setUserId(userInfo.getId());
                        tEmail.setType(1);
                        tEmail.setName(language == 1 ? "物品报失" : language == 2 ? "Report items lost" : "Signaler l'objet perdu");
                        tEmail.setCreateTime(new Date());
                        int i = cn.hutool.core.date.DateUtil.dayOfWeek(new Date())-1;
                        tEmail.setWeek(EmailUtil.getWeek(language,i));
                        boolean am = cn.hutool.core.date.DateUtil.isAM(new Date());
                        if(am){
                            tEmail.setAmOrPm(language==1?"上午":language==2?"morning":"matin");
                        }else {
                            tEmail.setAmOrPm(language==1?"下午":language==2?"afternoon":"après-midi");
                        }
                        emailService.insert(tEmail);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }).start();
    }
}