puzhibing
2023-08-03 7558a21c1ae1b48b0888f3e3906eb4ba6a68b06f
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
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.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.util.EmailUtil;
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.util.Date;
import java.util.List;
 
 
@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;
 
 
 
    /**
     * 添加投诉
     * @param driverId      司机id
     * @param reason        投诉原因
     * @param description   描述
     * @param uid           投诉人
     * @throws Exception
     */
    @Override
    public void saveData(Integer driverId, String reason, String description, Integer uid, Integer language) throws Exception {
        if(ToolUtil.isNotEmpty(description)){
            List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null);
            for(SensitiveWords s : sensitiveWords){
                description = description.replaceAll(s.getContent(), "***");
            }
        }
        language = userInfoService.queryLanguage(uid, language);
        Complaint complaint = new Complaint();
        complaint.setInsertTime(new Date());
        complaint.setDriverId(driverId);
        complaint.setReason(reason);
        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();
                Element chinese_user = document.getElementById("chinese_user");
                chinese_user.text("您好 " + userInfo.getNickName() + ",");
            }
            if(language == 2){
                document.getElementById("chinese").remove();
                document.getElementById("french").remove();
                Element english_user = document.getElementById("english_user");
                english_user.text("Hello " + userInfo.getNickName() + ",");
            }
            if(language == 3){
                document.getElementById("chinese").remove();
                document.getElementById("english").remove();
                Element french_user = document.getElementById("french_user");
                french_user.text("Bonjour " + userInfo.getNickName() + ",");
            }
            EmailUtil.send(userInfo.getEmail(), language == 1 ? "投诉司机" : language == 2 ? "Complain Driver" : "Se plaindre du conducteur",  document.html());
        }
        systemNoticeService.addSystemNotice(1, language == 1 ? "您的投诉已提交成功,我们会尽快处理!" : language == 2 ? "Your complaint has been submitted successfully and we will deal with it as soon as possible" : "Votre plainte a été soumise avec succès et nous la traiterons dès que possible", uid, 1);
    }
}