refactor: 前后端基础部分
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package org.nl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: 单元测试
|
||||
* @Date: 2023/5/15
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class ApplicationTest {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJSONToMap() {
|
||||
JSONObject pa = new JSONObject();
|
||||
JSONObject pa2 = new JSONObject();
|
||||
pa2.put("a", 2);
|
||||
pa.put("name", "lyd");
|
||||
pa.put("age", pa2);
|
||||
String jsonString = pa.toJSONString();
|
||||
|
||||
// 使用Fastjson解析JSON字符串
|
||||
Map<String, String> map = JSON.parseObject(jsonString, new TypeReference<Map<String, String>>() {});
|
||||
|
||||
// 输出Map
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
System.out.println(entry.getKey() + " : " + entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.nl.ext;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description:
|
||||
* @Date: 2023/9/18
|
||||
*/
|
||||
public class StorageManager {
|
||||
private int requestCount = 0;
|
||||
|
||||
public String allocateStorage() {
|
||||
requestCount++;
|
||||
if (requestCount >= 1 && requestCount <= 5) {
|
||||
return "上货位";
|
||||
} else if (requestCount >= 6 && requestCount <= 10) {
|
||||
return "下货位";
|
||||
} else {
|
||||
// 如果请求次数大于10,循环上下
|
||||
requestCount = 1;
|
||||
return "上货位";
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
StorageManager manager = new StorageManager();
|
||||
|
||||
// 模拟外部系统的请求
|
||||
for (int i = 1; i <= 23; i++) {
|
||||
new Thread(() -> {
|
||||
String storage = manager.allocateStorage();
|
||||
System.out.println("第 " + Thread.currentThread().getName() + " 次请求,分配到:" + storage);
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.nl.point;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: 创建点位
|
||||
* @Date: 2023/6/15
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class PointCreate {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user