no message
parent
a05914d0f7
commit
5d93f39d49
|
|
@ -1,20 +1,8 @@
|
|||
package com.youchain;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.youchain.businessdata.domain.AgvTask;
|
||||
import com.youchain.utils.PostRequestSigner;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class EladminSystemApplicationTests {
|
||||
|
||||
|
|
@ -23,149 +11,8 @@ public class EladminSystemApplicationTests {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// 示例参数
|
||||
String host = "les-f3-api-stg.nioint.com";
|
||||
String path = "/api/intg/v1/kuka/task/report";
|
||||
String appId = "2000458";
|
||||
String appSecret = "f65F67a8778b79bE7BcBEf49B3CE1214";
|
||||
long timestamp = System.currentTimeMillis() / 1000; // Unix时间戳(秒)
|
||||
// URL参数(不包含signe)
|
||||
Map<String, String> urlParams = new HashMap<>();
|
||||
urlParams.put("app_id", appId);
|
||||
urlParams.put("timestamp", String.valueOf(timestamp));
|
||||
urlParams.put("hash_type", "sha256");
|
||||
|
||||
// JSON请求体
|
||||
String jsonBody = "{\"location\":\"beijing\",\"language\":\"zh-CN\"}";
|
||||
|
||||
// 生成签名
|
||||
String sign = PostRequestSigner.generateSign(host, path, urlParams, jsonBody, appSecret, null);
|
||||
System.out.println("生成的签名: " + sign);
|
||||
|
||||
// 可以将签名添加到URL参数中,用于实际请求
|
||||
urlParams.put("signe", sign);
|
||||
|
||||
// 构建完整的请求URL示例
|
||||
StringBuilder urlBuilder = new StringBuilder();
|
||||
urlBuilder.append("https://").append(host).append(path).append("?");
|
||||
for (Map.Entry<String, String> entry : urlParams.entrySet()) {
|
||||
urlBuilder.append(entry.getKey()).append("=")
|
||||
.append(URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.name())).append("&");
|
||||
}
|
||||
String requestUrl = urlBuilder.toString();
|
||||
if (requestUrl.endsWith("&")) {
|
||||
requestUrl = requestUrl.substring(0, requestUrl.length() - 1);
|
||||
}
|
||||
System.out.println("完整请求URL: " + requestUrl);
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查订单日期是否早于指定月份之前的日期(包括当天)。
|
||||
*
|
||||
* @param orderDate 订单日期字符串(格式为 "yyyy/MM/dd")
|
||||
* @param months 不允许导入的月份数
|
||||
* @return 如果订单日期早于日期,则返回 false;否则返回 true。
|
||||
*/
|
||||
public static boolean isOrderDateValid3(String orderDate, int months) {
|
||||
// 定义日期格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/M/d");
|
||||
|
||||
// 将订单日期字符串转换为 LocalDate 对象
|
||||
try {
|
||||
LocalDate orderLocalDate = LocalDate.parse(orderDate, formatter);
|
||||
|
||||
// 获取当前日期
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
|
||||
// 计算截止日期
|
||||
LocalDate cutoffDate = currentDate.minusMonths(months);
|
||||
|
||||
// 比较订单日期和截止日期
|
||||
return !orderLocalDate.isBefore(cutoffDate) || orderLocalDate.equals(cutoffDate);
|
||||
}catch (Exception e){
|
||||
throw new IllegalArgumentException("日期格式错误: " + orderDate, e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查订单日期是否早于指定月份之前的日期。
|
||||
*
|
||||
* @param orderDate 订单日期字符串(格式为 "yyyy/MM/dd")
|
||||
* @param months 不允许导入的月份数
|
||||
* @return 如果订单日期早于截止日期,则返回 false;否则返回 true。
|
||||
*/
|
||||
public static boolean isOrderDateValid(String orderDate, int months) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
||||
try {
|
||||
Date date = sdf.parse(orderDate);
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
calendar.add(Calendar.MONTH, -months);
|
||||
|
||||
return date.after(calendar.getTime());
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalArgumentException("Invalid date format: " + orderDate, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isOrderDateValid2(String orderDate, int months) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
||||
try {
|
||||
Date date = sdf.parse(orderDate);
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
calendar.add(Calendar.MONTH, -months);
|
||||
|
||||
// 检查订单日期是否早于或等于截止日期
|
||||
return !date.before(calendar.getTime());
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalArgumentException("Invalid date format: " + orderDate, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int MAX_TASK_COUNT = 4;
|
||||
private static final long TIMEOUT_MS = 600000; // 10分钟,以毫秒为单位
|
||||
private long lastTaskTime = System.currentTimeMillis();
|
||||
private List<Integer> taskQueue = new ArrayList<>(MAX_TASK_COUNT);
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
List<Integer> taskLists=new ArrayList<>();
|
||||
taskLists.add(1);
|
||||
taskLists.add(2);
|
||||
taskLists.add(3);
|
||||
taskLists.add(4);
|
||||
taskLists.add(5);
|
||||
taskLists.add(6);
|
||||
|
||||
for(Integer id:taskLists) {
|
||||
try {
|
||||
taskQueue.add(id);
|
||||
if (taskQueue.size() >= MAX_TASK_COUNT) {
|
||||
System.out.println("任务已满足,当前任务数:" + taskQueue.size());
|
||||
taskQueue.clear();
|
||||
lastTaskTime = System.currentTimeMillis();
|
||||
} else if (System.currentTimeMillis() - lastTaskTime >= TIMEOUT_MS) {
|
||||
System.out.println("超过10分钟未满足4个任务,当前任务数:" + taskQueue.size());
|
||||
taskQueue.clear();
|
||||
lastTaskTime = System.currentTimeMillis();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.out.println(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,105 +1,7 @@
|
|||
package com.youchain;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class testMain {
|
||||
@Test
|
||||
public static void main(String[] args) {
|
||||
/*List<Long> list=new ArrayList<>();
|
||||
list.add(1L);
|
||||
list.add(1L);
|
||||
list.add(1L);
|
||||
list.add(2L);
|
||||
list.add(3L);
|
||||
HashMap<Long, Integer> map = new HashMap<Long, Integer>();
|
||||
for(Long id:list){
|
||||
if (map.containsKey(id)) {
|
||||
map.put(id,map.get(id)+1);
|
||||
}else{
|
||||
map.put(id,1);
|
||||
}
|
||||
}
|
||||
|
||||
for (Long key:map.keySet()){
|
||||
System.out.println("key= "+key+" and value= "+map.get(key));
|
||||
}*/
|
||||
|
||||
/*for (int i = 1; i < 2; i++) {
|
||||
System.out.println(i);
|
||||
}
|
||||
|
||||
int i = 1;
|
||||
do{
|
||||
System.out.println(i++);
|
||||
} while( i< 2 );
|
||||
|
||||
for(int j=1;j<2;System.out.println(++j));
|
||||
|
||||
for(int x=1;x++<2;System.out.println(x));*/
|
||||
|
||||
/* int i = 1,j = 10;
|
||||
do {
|
||||
if(i>j){continue;}
|
||||
j--;
|
||||
}while(++i<6);System.out.println("¡="+i+" and j="+j);*/
|
||||
|
||||
/* int a[]={4,2,-7,5,1,6,3};
|
||||
System.out.println(a[a[4]]);*/
|
||||
|
||||
/*int m = 12, n = 34;
|
||||
System.out.print(m++);
|
||||
System.out.print(++n);
|
||||
System.out.print(n++);
|
||||
System.out.print(++m);*/
|
||||
|
||||
/*String a = "a";
|
||||
String b = "b";
|
||||
String c = a + b;
|
||||
String d = new String("ab");
|
||||
System.out.println(c.equals(d));*/
|
||||
|
||||
/* try {
|
||||
int i = 100 / 01;
|
||||
System.out.print(i);
|
||||
} catch (Exception e) {
|
||||
System.out.print(1);
|
||||
throw new RuntimeException();
|
||||
} finally {
|
||||
System.out.print(2);
|
||||
}
|
||||
|
||||
|
||||
System.out.print(3);*/
|
||||
|
||||
/* String a="hello";
|
||||
String b="hello";
|
||||
System.out.println(a.equals(b));*/
|
||||
|
||||
/* int one=0;
|
||||
int two=0;
|
||||
int three=0;
|
||||
for(int i=1;i<1001;i++){
|
||||
if(String.valueOf(i).contains("0")){
|
||||
one++;
|
||||
}
|
||||
if(String.valueOf(i).contains("00")){
|
||||
two++;
|
||||
}
|
||||
if(String.valueOf(i).contains("000")){
|
||||
three++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
System.out.println(one+two+three);*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue