Pu Zhibing
2025-02-14 5228e24ff93fae148db40c44d9deb8e93110c6eb
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
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.system.dao.ComplaintMapper;
import com.stylefeng.guns.modular.system.dao.SensitiveWordsMapper;
import com.stylefeng.guns.modular.system.model.Complaint;
import com.stylefeng.guns.modular.system.model.SensitiveWords;
import com.stylefeng.guns.modular.system.model.TEmail;
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.service.IComplaintService;
import com.stylefeng.guns.modular.system.service.ISystemNoticeService;
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 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 javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.util.*;
import java.util.stream.Collectors;
 
 
@Service
public class ComplaintServiceImpl extends ServiceImpl<ComplaintMapper, Complaint> implements IComplaintService {
 
    @Resource
    private SensitiveWordsMapper sensitiveWordsMapper;
 
    @Autowired
    private ISystemNoticeService systemNoticeService;
 
    @Autowired
    private IUserInfoService userInfoService;
 
    @Value("${spring.mail.template-path}")
    private String templatePath;
 
    @Autowired
    private TEmailService emailService;
 
 
 
    /**
     * 添加投诉
     * @param driverId      司机id
     * @param reason        投诉原因
     * @param description   描述
     * @param uid           投诉人
     * @throws Exception
     */
    @Override
    public void saveData(Integer orderId, Integer orderType, Integer driverId, String reason, String description, Integer uid, Integer language) throws Exception {
        if(ToolUtil.isNotEmpty(description)){
            List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null);
            List<String> list = Arrays.asList(description.split(" "));
            for(SensitiveWords s : sensitiveWords){
                List<String> str = new ArrayList<>();
                String lowerCase = s.getContent().toLowerCase();
                for (String s1 : list) {
                    if(lowerCase.equals(s1.toLowerCase())){
                        str.add("***");
                    }else{
                        str.add(s1);
                    }
                }
                list = str;
            }
            description = list.stream().collect(Collectors.joining(" "));
        }
        Complaint complaint = new Complaint();
        complaint.setInsertTime(new Date());
        complaint.setDriverId(driverId);
        complaint.setReason(reason);
        complaint.setOrderId(orderId);
        complaint.setOrderType(orderType);
        complaint.setDescription(description);
        complaint.setUserId(uid);
        complaint.setIsHandle(0);
        this.insert(complaint);
 
        UserInfo userInfo = userInfoService.selectById(uid);
        if(ToolUtil.isNotEmpty(userInfo.getEmail())){
            String path = templatePath +  "user/complaint.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 chinese_user = document.getElementById("chinese_user");
                chinese_user.text("您好 " + userInfo.getNickName() + ",");
            }
            if(language == 2){
                document.getElementById("chinese").remove();
                document.getElementById("french").remove();
                document.getElementsByTag("title").get(0).text("Complain against driver");
                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("Porter plainte contre le chauffeur");
                Element french_user = document.getElementById("french_user");
                french_user.text("Bonjour " + userInfo.getNickName() + ",");
            }
            EmailUtil.send(userInfo.getEmail(), language == 1 ? "投诉司机" : language == 2 ? "Complain against driver" : "Porter plainte contre le chauffeur",  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/complain_" + 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/complain_" + randomString + ".html";
            TEmail tEmail = new TEmail();
            tEmail.setLink(link);
            tEmail.setUserId(uid);
            tEmail.setType(1);
            tEmail.setName(language == 1 ? "投诉司机" : language == 2 ? "Complain against driver" : "Porter plainte contre le chauffeur");
            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);
 
        }
        systemNoticeService.addSystemNotice(1, language == 1 ? "您的投诉已提交成功,我们会尽快处理!" : language == 2 ? "Your complaints were submitted successfully, we shall handle it as soon as possible." : "Vos réclamations ont été déposées avec succès, nous les traiterons dans les plus brefs délais.", uid, 1);
    }
}