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();
|
}
|
}
|
}
|
}
|