fei.wang
2024-05-13 19fe5a3d816184549e8ffa011c39f218734da8d5
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
package com.flow.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.flow.mapper.*;
import com.flow.pojo.*;
import com.flow.service.DuanxinlogService;
import com.flow.service.TbFuwuqiService;
import com.flow.util.DESUtil;
import com.flow.util.result;
import com.flow.util.resultutil;
import com.github.pagehelper.PageInfo;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
 
import java.text.SimpleDateFormat;
import java.util.*;
 
@RestController
@RequestMapping({"/hxzk"})
@Component
public class DuanxinlogController {
 
    private String SecretId = "AKIDrjZOI4e6KLZu9FAsSRN8eOwSt52lbMBz";
    private String SecretKey = "xnRtHUL3YqdMyOLVSBjKkz1pQoxujS4d";
    @Autowired
    DuanxinlogService duanxinlogService;
 
    @Autowired
    CardMapper cardMapper;
    @Autowired
    TbFuwuqiMapper tbFuwuqiMapper;
    @Autowired
    DuanxinlogMapper duanxinlogMapper;
 
    @Autowired
    TbFuwuqiService tbFuwuqiService;
 
    @Autowired
    CompanyMapper companyMapper;
 
    @Autowired
    ManagerMapper managerMapper;
    @GetMapping({"findDuanxinlog"})
    result<List<Duanxinlog>> findDuanxinlog(Integer page, Integer limit) {
        PageInfo<Duanxinlog> cz = this.duanxinlogService.FindDuanxinlog(page, limit);
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
    @PostMapping({"DeleteDuanxinlog"})
    public ModelAndView DeleteManager(String num) {
        this.duanxinlogService.DeleteDuanxinlog(num);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/page/Duanxinlog.jsp");
        return modelAndView;
 
    }
 
    /*
     * 函数名     : smsfuwuqi
     * 说明      :
                        服务器
                        查询所有服务器数据
                        根据公司名称查询电话
                        使用当前时间减去结束时间
                        使用号码查询短信表取出发送日期,如果当前日期大于发送日期
                        发送短信
     * 返回值            : 无
     * 作者            : 王飞
//     * 日期    : 2024年2月28日
     */
//    @EnableScheduling
//    @Scheduled(cron = "*/10 * * * * ?")//测试10一次
//    @Scheduled(cron = "0 46 17 * * ?")
    @Scheduled(cron = "0 0 */1 * * ?")//一小时执行一次
    public void smsfuwuqi() throws Exception {
        System.out.println("服务器定时器执行============》》》》》》》》》》》》》》》》");
        QueryWrapper queryWrapper1 = new QueryWrapper();
        queryWrapper1.eq("none", "0");
        List<TbFuwuqi> fuwuqiList = (tbFuwuqiMapper).selectList(queryWrapper1);
        for (int i = 0; i < fuwuqiList.size(); i++) {
            QueryWrapper queryWrapper3 = new QueryWrapper();
            queryWrapper3.eq("none", "0");
            queryWrapper3.eq("companyName", fuwuqiList.get(i).getCompany());
            Company companyList = (companyMapper).selectOne(queryWrapper3);
            SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = new Date();
            Date endDay = date2.parse(fuwuqiList.get(i).getEnddate());//结束时间
            Long starTime = date.getTime();
            Long endTime = endDay.getTime();
            Long num11 = endTime - starTime;//时间戳
            //不足一天的算作一天,因此在到期天数上加1
            if (+num11 / 24 / 60 / 60 / 1000 == 19 | +num11 / 24 / 60 / 60 / 1000 == 9 | +num11 / 24 / 60 / 60 / 1000 == 4 | +num11 / 24 / 60 / 60 / 1000 == 0) {
                String dispatchDate = this.duanxinlogService.userdate(fuwuqiList.get(i).getServername());
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                String dtext = formatter.format(date);
                if (dispatchDate == null || !dtext.equals(dispatchDate)) {
                    // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
                    // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
                    // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
                    Credential cred = new Credential(SecretId, SecretKey);
                    // 实例化一个http选项,可选的,没有特殊需求可以跳过
                    HttpProfile httpProfile = new HttpProfile();
                    httpProfile.setEndpoint("sms.tencentcloudapi.com");
                    // 实例化一个client选项,可选的,没有特殊需求可以跳过
                    ClientProfile clientProfile = new ClientProfile();
                    clientProfile.setHttpProfile(httpProfile);
                    // 实例化要请求产品的client对象,clientProfile是可选的
                    SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
                    // 实例化一个请求对象,每个接口都会对应一个request对象
                    SendSmsRequest req = new SendSmsRequest();
//                    String[] phoneNumberSet1 = {"18701153496"};
                    String[] phoneNumberSet1 = {DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key)};
                    QueryWrapper sms = new QueryWrapper();
                    sms.eq("none", "0");
                    sms.eq("smsreception", "1");
                    List<Manager> managerList = (managerMapper).selectList(sms);
                    for (int s=0;s<managerList.size();s++){
//                        System.out.println(managerList.get(s).getPhone());
//                        phoneNumberSet1[s] = managerList.get(s).getPhone();
                        String[] phoneNumberSet12  = {managerList.get(s).getPhone()};
                        System.out.println(phoneNumberSet12);
                        req.setPhoneNumberSet(phoneNumberSet12);
 
                        req.setSmsSdkAppId("1400838975");
                        req.setSignName("北京华星北斗智控");
                        req.setTemplateId("2100321");
 
//                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
                        String[] templateParamSet1 = {String.valueOf("您有流量卡将于:"  + fuwuqiList.get(i).getEnddate()+"到期,")};
                        req.setTemplateParamSet(templateParamSet1);
                        // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                        SendSmsResponse resp = client.SendSms(req);
                    }
                    req.setPhoneNumberSet(phoneNumberSet1);
 
                    req.setSmsSdkAppId("1400838975");
                    req.setSignName("北京华星北斗智控");
                    req.setTemplateId("2100321");
 
//                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
                    String[] templateParamSet1 = {String.valueOf("您有服务器将于:"  + fuwuqiList.get(i).getEnddate()+"到期,")};
                    req.setTemplateParamSet(templateParamSet1);
                    // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                    SendSmsResponse resp = client.SendSms(req);
                    // 输出json格式的字符串回包
                    Duanxinlog duanxinlog = new Duanxinlog();
                    duanxinlog.setIdentification(fuwuqiList.get(i).getServername());
                    duanxinlog.setReceiver(fuwuqiList.get(i).getCompany());
                    duanxinlog.setNumber(DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key));
                    duanxinlog.setNumber(DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key));
                    duanxinlog.setContent("尊敬的用户,您好!您有服务器将于"+fuwuqiList.get(i).getEnddate()+"到期,为避免影响您的正常使用请及时续费,您可登录华星智控公司物联网管理平台查询详情续费,如有疑问可咨询我公司客服人员,祝您生活愉快!");
                    this.duanxinlogService.addDuanxinlog(duanxinlog);
                }
            }
 
        }
    }
 
 
    /*
     * 函数名     : sms
     * 说明      : 查询所有卡号数据
                    使用当前时间减去结束时间
                    使用号码查询短信表取出发送日期,如果当前日期大于发送日期
                        发送短信
                        发送短信
 
     * 返回值            : 无
     * 作者            : 王飞
//     * 日期    : 2024年2月28日
     */
//    @EnableScheduling
//    @Scheduled(cron = "*/10 * * * * ?")//测试10秒执行一次
//    @Scheduled(cron = "0 11 16 * * ?")
    @Scheduled(cron = "0 0 */1 * * ?")//一小时执行一次
    public void sms() throws Exception {
        System.out.println("短信定时器执行============》》》》》》》》》》》》》》》》");
        //查询数据库中所有的引擎数据
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("none", "0");
//        queryWrapper.eq("num", "1");
        List<Card> cardList = (cardMapper).selectList(queryWrapper);
        for (int i = 0; i < cardList.size(); i++) {
            QueryWrapper queryWrapper3 = new QueryWrapper();
            queryWrapper3.eq("none", "0");
            queryWrapper3.eq("companyName", cardList.get(i).getCompany());
            Company companyList = new Company();
            companyList = (companyMapper).selectOne(queryWrapper3);
            if (companyList == null) {
                QueryWrapper queryWrapper4 = new QueryWrapper();
                queryWrapper4.eq("none", "0");
                queryWrapper4.eq("companyabbname", cardList.get(i).getCompany());
                companyList = (companyMapper).selectOne(queryWrapper4);
            }
            SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            Date endDay = date2.parse(cardList.get(i).getEnddate());//结束时间
            Long starTime = date.getTime();
            Long endTime = endDay.getTime();
            Long num11 = endTime - starTime;//时间戳
 
            if (+num11 / 24 / 60 / 60 / 1000 == 19 | +num11 / 24 / 60 / 60 / 1000 == 9 | +num11 / 24 / 60 / 60 / 1000 == 4 | +num11 / 24 / 60 / 60 / 1000 == 0) {
                String dispatchDate = this.duanxinlogService.userdate(cardList.get(i).getCardnumber());
//                    String dispatchDate = this.duanxinlogService.userdate(cardList.get(i).getCardnumber());
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date dtext = formatter.parse(dispatchDate);//结束时间
                Long endTime1 = dtext.getTime();
                if ((endTime1-starTime) / 24 / 60 / 60 / 1000 != 0) {
                    String randomNumber = new String();
                    // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
                    // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
                    // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
                    Credential cred = new Credential(SecretId, SecretKey);
                    // 实例化一个http选项,可选的,没有特殊需求可以跳过
                    HttpProfile httpProfile = new HttpProfile();
                    httpProfile.setEndpoint("sms.tencentcloudapi.com");
                    // 实例化一个client选项,可选的,没有特殊需求可以跳过
                    ClientProfile clientProfile = new ClientProfile();
                    clientProfile.setHttpProfile(httpProfile);
                    // 实例化要请求产品的client对象,clientProfile是可选的
                    SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
                    // 实例化一个请求对象,每个接口都会对应一个request对象
                    SendSmsRequest req = new SendSmsRequest();
//                        String[] phoneNumberSet1 = {cardList.get(i).getCardnumber()};
                    String[] phoneNumberSet1 = {DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key)};
//                    String[] phoneNumberSet1 = {"18701153496"};
                    QueryWrapper sms = new QueryWrapper();
                    sms.eq("none", "0");
                    sms.eq("smsreception", "1");
                    List<Manager> managerList = (managerMapper).selectList(sms);
                    String string = new String();
                    for (int s=0;s<managerList.size();s++){
 
                        if (s!=0){
                            string+=",";
                        }
                        string += managerList.get(s).getPhone();
                        String[] phoneNumberSet12  = {managerList.get(s).getPhone()};
                        System.out.println(phoneNumberSet12);
                        req.setPhoneNumberSet(phoneNumberSet12);
 
                        req.setSmsSdkAppId("1400838975");
                        req.setSignName("北京华星北斗智控");
                        req.setTemplateId("2100321");
 
//                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
                        String[] templateParamSet1 = {String.valueOf("您有流量卡将于:"  + cardList.get(i).getEnddate()+"到期,")};
                        req.setTemplateParamSet(templateParamSet1);
                        // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                        SendSmsResponse resp = client.SendSms(req);
                    }
//                    phoneNumberSet1[managerList.size()] = DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key);
//                    System.out.println(phoneNumberSet1);
                    req.setPhoneNumberSet(phoneNumberSet1);
 
                    req.setSmsSdkAppId("1400838975");
                    req.setSignName("北京华星北斗智控");
                    req.setTemplateId("2100321");
 
//                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
                    String[] templateParamSet1 = {String.valueOf("您有流量卡将于:"  + cardList.get(i).getEnddate()+"到期,")};
                    req.setTemplateParamSet(templateParamSet1);
                    // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                    SendSmsResponse resp = client.SendSms(req);
                    System.out.println(SendSmsResponse.toJsonString(resp));
                    // 输出json格式的字符串回包
                    Duanxinlog duanxinlog = new Duanxinlog();
                    duanxinlog.setIdentification(cardList.get(i).getCardnumber());
                    duanxinlog.setReceiver(cardList.get(i).getCompany());
                    duanxinlog.setNumber(string);
                    duanxinlog.setContent("尊敬的用户,您好!您有流量卡将于"+cardList.get(i).getEnddate()+"到期,为避免影响您的正常使用请及时续费,您可登录华星智控公司物联网管理平台查询详情续费,如有疑问可咨询我公司客服人员,祝您生活愉快!"
                    );
                    this.duanxinlogService.addDuanxinlog(duanxinlog);
                }
            }
 
        }
    }
 
}