无关风月
2025-01-13 711e8da0ccf406ec77ff069458a09278ca4a0a9f
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
package com.sinata.ministryoftransport.util;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.exceptions.ClientException;
import com.sinata.ministryoftransport.server.IMinistryOfTransportService;
import com.sinata.ministryoftransport.util.httpClinet.HttpResult;
import com.sun.org.apache.bcel.internal.generic.FADD;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
 
 
/**
 * 定时任务工具类
 */
@Component
public class TaskUtil {
 
    @Autowired
    private ALiSendSms aLiSendSms;
 
    private boolean push = false;
 
    @Autowired
    private IMinistryOfTransportService ministryOfTransportService;
 
    private Integer counter = 0;
 
 
 
    /**
     * 每隔一分钟去处理的定时任务
     */
//    @Scheduled(fixedRate = 1000 * 60)
//    public void taskMinute(){
//        try {
//            String baseInfoCompany = "{\"CompanyName\":\"昭通市睿邦科技有限公司\",\"Identifier\":\"91530600MA6K70Q50D\",\"Address\":530602,\"BusinessScope\":\"网络预约出租汽车客运\"," +
//                    "\"ContactAddress\":\"云南省昭通市昭阳区龙泉路501号\",\"EconomicType\":\"150\",\"RegCapital\":\"一千万元\",\"LegalName\":\"虎尊国\",\"LegalID\":\"53210119760928201X\"," +
//                    "\"LegalPhone\":\"13118708883\",\"State\":0,\"Flag\":2,\"UpdateTime\":\"" +System.currentTimeMillis() + "\"}";
//            String result = ministryOfTransportService.baseInfoCompany(baseInfoCompany);
//            HttpResult httpResult = JSON.parseObject(result, HttpResult.class);
//            if(httpResult.getCode() == 200 || httpResult.getCode() == 201){
//                counter = 0;
//            }
//            if(null == httpResult){
//                sendSms();
//                System.err.println("请求接口出错!");
//                return;
//            }
//        } catch (Exception e) {
//            sendSms();
//            e.printStackTrace();
//        }
//    }
 
 
    /**
     * 每天的1点执行的任务
     */
//    @Scheduled(cron = "0 0 1 * * *")
//    public void taskDay(){
//        try {
//
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//    }
 
 
 
    /**
     * 每月第一天的1点执行的任务
     */
//    @Scheduled(cron = "0 0 1 1 * *")
//    public void taskMonth(){
//        try {
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//    }
 
 
 
 
    /**
     * 触发发送短信提醒
     */
    public void sendSms(){
        counter++;
        if(counter == 3){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time = sdf.format(new Date());
            try {
                aLiSendSms.sendSms("15907727138", "SMS_210780079", "{\"phone\":\"15907727138\",\"time\":\"" + time + "\"}");
            } catch (ClientException e) {
                e.printStackTrace();
            }
        }
    }
}