Browse Source

测试工作日

tall3
zy_Java 4 years ago
parent
commit
f4f369a23d
  1. 43
      tall/src/main/java/com/ccsens/tall/web/DebugController.java
  2. 1
      tcm/src/main/java/com/ccsens/tcm/TcmApplication.java
  3. 1
      util/src/main/java/com/ccsens/util/RestTemplateUtil.java
  4. 95
      util/src/test/java/com/ccsens/util/DateTest.java
  5. 38
      util/src/test/java/com/ccsens/util/OtherTest.java

43
tall/src/main/java/com/ccsens/tall/web/DebugController.java

@ -23,6 +23,7 @@ import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.Test;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
@ -30,6 +31,7 @@ import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@ -55,6 +57,10 @@ public class DebugController {
@Resource
SqlSessionFactory sqlSessionFactory;
@Resource
private RestTemplate restTemplate;
private static RestTemplateUtil util;
@ApiOperation(value = "/测试",notes = "")
@ApiImplicitParams({
@ -297,6 +303,43 @@ public class DebugController {
} catch (DocumentException e) {
System.out.println(e);
}
}
@ApiOperation(value = "图片验证码")
@ApiImplicitParams({
})
@RequestMapping(value = "/https", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
public void httpsTest() throws Exception {
int year = 2021;
int month = 8;
String a = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query="+year+"%E5%B9%B4"+month+"%E6%9C%88&co=&resource_id=39043&t=1617089428269&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=wisetpl&cb=jQuery110203576901702188473_1617089118772&_=1617089118776";
// long a1 = System.currentTimeMillis();
String s = RestTemplateUtil.getForEntity(a,new HashMap<>(),StringBuilder.class).toString();
System.out.println(s.toString());
// String s = HttpsUtil.httpsRequest(a,"GET","");
// System.out.println(System.currentTimeMillis() - a1);
s = s.substring(s.indexOf("("));
s = s.substring(1, s.length() - 2);
Map<String, Object> map = (Map<String, Object>) JSONObject.parse(s);
List list = (List) map.get("data");
Map data = (Map) list.get(0);
List<Map> almanac = (List<Map>) data.get("almanac");
if(almanac == null || almanac.size() == 0) {
return;
}
for(int i = 1; i < almanac.size(); i++) {
String key = ((String)almanac.get(i).get("oDate")).substring(0, 10);
String status = (String)almanac.get(i - 1).get("status");
if("1".equals(status) || "2".equals(status)) {
System.out.println(key);
System.out.println(status);
}
}
}
}

1
tcm/src/main/java/com/ccsens/tcm/TcmApplication.java

@ -15,6 +15,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
@EnableCircuitBreaker
@EnableFeignClients(basePackages = "com.ccsens.cloudutil.feign")
@SpringBootApplication(scanBasePackages = "com.ccsens")
public class TcmApplication {
public static void main(String[] args) {

1
util/src/main/java/com/ccsens/util/RestTemplateUtil.java

@ -60,6 +60,7 @@ public class RestTemplateUtil {
log.info("url:{}, params:{}", url, params);
ResponseEntity<String> entity = util.restTemplate.getForEntity(url, String.class);
log.info("entity:{}",entity);
// return entity;
return JSONObject.parseObject(entity.getBody(), returnClass);
}

95
util/src/test/java/com/ccsens/util/DateTest.java

@ -0,0 +1,95 @@
package com.ccsens.util;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
import com.alibaba.fastjson.JSONObject;
public class DateTest {
public static String sendGet(String url, String param) {
String result = "";
BufferedReader in = null;
try {
String urlNameString = url + "/" + param;
URL realUrl = new URL(urlNameString);
URLConnection connection = realUrl.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
connection.connect();
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
int cot = 0;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送GET请求出现异常!" + e);
e.printStackTrace();
}
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
static Map totalMap = new TreeMap();
public static void main(String[] args) throws Exception {
int startYear = 2021;//开始的年份
int year = 8; //统计的年份
loop(startYear + 2021 + "", 8 + "");
// for(int i = 0; i <= (year - 1); i++){
//// for(int j = 1; j <= 12; j++) {
// loop(startYear + i + "", j + "");
//// }
// }
Iterator it = totalMap.keySet().iterator();
while(it.hasNext()) {
String temp = (String) it.next();
System.out.println(temp + " " + totalMap.get(temp));
}
}
public static void loop(String year, String month) throws Exception {
String s = DateTest.sendGet("https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query="+year+"%E5%B9%B4"+month+"%E6%9C%88&co=&resource_id=39043&t=1617089428269&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=wisetpl&cb=jQuery110203576901702188473_1617089118772&_=1617089118776", "");
// String a = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query="+year+"%E5%B9%B4"+month+"%E6%9C%88&co=&resource_id=39043&t=1617089428269&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=wisetpl&cb=jQuery110203576901702188473_1617089118772&_=1617089118776";
// long a1 = System.currentTimeMillis();
// RestTemplateUtil.getForEntity(a,new HashMap<>(),StringBuilder.class);
//// String s = HttpsUtil.httpsRequest(a,"GET","");
// System.out.println(System.currentTimeMillis() - a1);
s = s.substring(s.indexOf("("));
s = s.substring(1, s.length() - 2);
Map<String, Object> map = (Map<String, Object>) JSONObject.parse(s);
List list = (List) map.get("data");
Map data = (Map) list.get(0);
List<Map> almanac = (List<Map>) data.get("almanac");
if(almanac == null || almanac.size() == 0) {
return;
}
for(int i = 1; i < almanac.size(); i++) {
String key = ((String)almanac.get(i).get("oDate")).substring(0, 10);
String status = (String)almanac.get(i - 1).get("status");
if("1".equals(status) || "2".equals(status)) {
totalMap.put(key, status);
}
}
}
}

38
util/src/test/java/com/ccsens/util/OtherTest.java

@ -14,6 +14,8 @@ import javax.annotation.Resource;
import javax.script.ScriptException;
import java.io.*;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
@ -25,6 +27,42 @@ public class OtherTest {
public static final String REGEX_PHONE = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,1-9]))\\d{8}$";
@Test
public void test15() {
String httpArg = "20211001";
String httpUrl = "http://api.goseek.cn/Tools/holiday";
BufferedReader reader = null;
String result = null;
StringBuffer sbf = new StringBuffer();
httpUrl = httpUrl + "?date=" + httpArg;
int d=0;//工作日对应结果为 0, 休息日对应结果为 1, 节假日对应的结果为 2
try {
URL url = new URL(httpUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
InputStream is = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String strRead = null;
while ((strRead = reader.readLine()) != null) {
sbf.append(strRead);
sbf.append("\r\n");
}
reader.close();
result = sbf.toString();
// JSONObject ob= JSONObject.fromObject(result);
// if(ob!=null){
// d=Integer.parseInt(ob.getString("data"));
// }
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void test2() throws ScriptException {
String str = "18200000000";

Loading…
Cancel
Save