无关风月
2024-06-21 1ee144305cba138c3fbf461432562c8550940eab
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\":\"91450200MA5K99GK3Y\",\"Address\":450204,\"BusinessScope\":\"网络预约出租车客运\"," +
                    "\"ContactAddress\":\"柳州市柳南区航银路8号万利大厦3楼303室\",\"EconomicType\":\"150\",\"RegCapital\":\"一千万元\",\"LegalName\":\"翁克顺\",\"LegalID\":\"44052419650805207X\"," +
                    "\"LegalPhone\":\"13907728585\",\"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();
            }
        }
    }
}