Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
0ccafebf
提交
0ccafebf
authored
3月 15, 2021
作者:
吴德鹏
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev'
上级
34cd118e
6caf5af9
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
225 行增加
和
223 行删除
+225
-223
CartController.java
...a/com/example/afrishop_v3/controllers/CartController.java
+2
-0
application.properties
src/main/resources/application.properties
+1
-1
AfrishopV3ApplicationTests.java
...a/com/example/afrishop_v3/AfrishopV3ApplicationTests.java
+222
-222
没有找到文件。
src/main/java/com/example/afrishop_v3/controllers/CartController.java
浏览文件 @
0ccafebf
...
@@ -72,6 +72,8 @@ public class CartController extends Controller {
...
@@ -72,6 +72,8 @@ public class CartController extends Controller {
if
(
itemCount
<=
0
)
{
if
(
itemCount
<=
0
)
{
record
.
setCheckFlag
(
0
);
record
.
setCheckFlag
(
0
);
itemCount
=
0
;
itemCount
=
0
;
if
(
itemCount
!=
0
)
record
.
setItemCount
(
itemCount
);
}
}
result
.
setData
(
itemCount
);
result
.
setData
(
itemCount
);
result
.
setMessage
(
"Out of stock"
);
result
.
setMessage
(
"Out of stock"
);
...
...
src/main/resources/application.properties
浏览文件 @
0ccafebf
server.servlet.context-path
=
/zion
server.servlet.context-path
=
/zion
spring.jpa.hibernate.ddl-auto
=
update
spring.jpa.hibernate.ddl-auto
=
update
server.port
=
8083
server.port
=
8083
spring.profiles.active
=
dev
spring.profiles.active
=
test
#spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/afrishop_test?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
#spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/afrishop_test?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
#spring.datasource.username=root
#spring.datasource.username=root
#spring.datasource.password=Diaoyunnuli.8
#spring.datasource.password=Diaoyunnuli.8
...
...
src/test/java/com/example/afrishop_v3/AfrishopV3ApplicationTests.java
浏览文件 @
0ccafebf
package
com
.
example
.
afrishop_v3
;
//
package com.example.afrishop_v3;
//
import
com.example.afrishop_v3.models.*
;
//
import com.example.afrishop_v3.models.*;
import
com.example.afrishop_v3.repository.*
;
//
import com.example.afrishop_v3.repository.*;
import
com.example.afrishop_v3.util.IdUtil
;
//
import com.example.afrishop_v3.util.IdUtil;
import
com.example.afrishop_v3.util.OssUtil
;
//
import com.example.afrishop_v3.util.OssUtil;
import
com.example.afrishop_v3.util.PicUtils
;
//
import com.example.afrishop_v3.util.PicUtils;
import
com.google.gson.JsonObject
;
//
import com.google.gson.JsonObject;
import
net.sf.json.JSONArray
;
//
import net.sf.json.JSONArray;
import
net.sf.json.JSONObject
;
//
import net.sf.json.JSONObject;
import
org.junit.Test
;
//
import org.junit.Test;
import
org.junit.runner.Result
;
//
import org.junit.runner.Result;
import
org.junit.runner.RunWith
;
//
import org.junit.runner.RunWith;
import
org.springframework.beans.factory.annotation.Autowired
;
//
import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.test.context.SpringBootTest
;
//
import org.springframework.boot.test.context.SpringBootTest;
import
org.springframework.http.ResponseEntity
;
//
import org.springframework.http.ResponseEntity;
import
org.springframework.test.context.junit4.SpringRunner
;
//
import org.springframework.test.context.junit4.SpringRunner;
import
org.springframework.web.client.RestTemplate
;
//
import org.springframework.web.client.RestTemplate;
//
import
java.io.ByteArrayOutputStream
;
//
import java.io.ByteArrayOutputStream;
import
java.io.IOException
;
//
import java.io.IOException;
import
java.io.InputStream
;
//
import java.io.InputStream;
import
java.net.HttpURLConnection
;
//
import java.net.HttpURLConnection;
import
java.net.URL
;
//
import java.net.URL;
import
java.text.SimpleDateFormat
;
//
import java.text.SimpleDateFormat;
import
java.time.LocalDateTime
;
//
import java.time.LocalDateTime;
import
java.util.*
;
//
import java.util.*;
import
java.util.concurrent.ExecutorService
;
//
import java.util.concurrent.ExecutorService;
import
java.util.concurrent.Executors
;
//
import java.util.concurrent.Executors;
import
java.util.concurrent.Future
;
//
import java.util.concurrent.Future;
import
java.util.concurrent.locks.ReentrantLock
;
//
import java.util.concurrent.locks.ReentrantLock;
import
java.util.stream.Collectors
;
//
import java.util.stream.Collectors;
//
@RunWith
(
SpringRunner
.
class
)
//
@RunWith(SpringRunner.class)
@SpringBootTest
//
@SpringBootTest
public
class
AfrishopV3ApplicationTests
{
//
public class AfrishopV3ApplicationTests {
//
RestTemplate
restTemplate
=
new
RestTemplate
();
//
RestTemplate restTemplate = new RestTemplate();
//
@Test
//
@Test
public
void
contextLoads
()
{
//
public void contextLoads() {
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm:ss"
);
//
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String
now
=
format
.
format
(
new
Date
());
//
String now = format.format(new Date());
System
.
out
.
println
(
now
);
//
System.out.println(now);
}
//
}
//
private
String
url
=
"http://localhost:8099/afrishop/discover/bonus/saveNetworkMarketing"
;
//
private String url = "http://localhost:8099/afrishop/discover/bonus/saveNetworkMarketing";
@Autowired
//
@Autowired
private
TbCfOrderRepository
orderRepository
;
//
private TbCfOrderRepository orderRepository;
//
// post35789572fbf643cdab55901d1dc511a6
//
//
post35789572fbf643cdab55901d1dc511a6
// userInfo00297bf300ed45e092a5182dececad21
//
//
userInfo00297bf300ed45e092a5182dececad21
// productSharervv32GmG4q
//
//
productSharervv32GmG4q
// amount0.9
//
//
amount0.9
// orderId008272b1fb994aef9b199449f46d5aa5
//
//
orderId008272b1fb994aef9b199449f46d5aa5
//
@Test
//
@Test
public
void
test1
()
{
//
public void test1() {
//
Optional
<
TbCfOrder
>
byId
=
orderRepository
.
findById
(
"12a9d7d1042348278c97980a00fc67c4"
);
//
Optional<TbCfOrder> byId = orderRepository.findById("12a9d7d1042348278c97980a00fc67c4");
JSONObject
json
=
new
JSONObject
();
//
JSONObject json = new JSONObject();
json
.
put
(
"userInfo"
,
"32dcda5a709c4265a6f01686ae9b1c1c"
);
//
json.put("userInfo", "32dcda5a709c4265a6f01686ae9b1c1c");
json
.
put
(
"amount"
,
byId
.
get
().
getItemsPrice
());
//
json.put("amount", byId.get().getItemsPrice());
json
.
put
(
"orderId"
,
"12a9d7d1042348278c97980a00fc67c4"
);
//
json.put("orderId", "12a9d7d1042348278c97980a00fc67c4");
System
.
out
.
println
(
json
);
//
System.out.println(json);
ResponseEntity
<
Result
>
resultResponseEntity
=
restTemplate
.
postForEntity
(
url
,
json
,
Result
.
class
);
//
ResponseEntity<Result> resultResponseEntity = restTemplate.postForEntity(url, json, Result.class);
System
.
err
.
println
(
resultResponseEntity
);
//
System.err.println(resultResponseEntity);
}
//
}
//
@Autowired
//
@Autowired
private
TokenRepository
tokenRepository
;
//
private TokenRepository tokenRepository;
//
@Autowired
//
@Autowired
private
CountryRepository
countryRepository
;
//
private CountryRepository countryRepository;
//
//
@Test
//
@Test
public
void
test2
()
{
//
public void test2() {
List
list
=
new
ArrayList
();
//
List list = new ArrayList();
list
.
add
(
2
);
//
list.add(2);
list
.
add
(
1
);
//
list.add(1);
list
.
add
(
3
);
//
list.add(3);
list
.
forEach
(
System
.
out
::
println
);
//
list.forEach(System.out::println);
//
}
//
}
//
private
ReentrantLock
reentrantLock
=
new
ReentrantLock
();
//
private ReentrantLock reentrantLock = new ReentrantLock();
//
@Test
//
@Test
public
void
testImport
()
{
//
public void testImport() {
ExecutorService
executorService
=
Executors
.
newCachedThreadPool
();
//
ExecutorService executorService = Executors.newCachedThreadPool();
//
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
//
for (int i = 0; i < 20; i++) {
executorService
.
execute
(()
->
importCountry
());
//
executorService.execute(() -> importCountry());
}
//
}
//
}
//
}
//
@Test
//
@Test
public
void
importCountry
()
{
//
public void importCountry() {
//
String
url
=
"https://api.jisuapi.com/country/query?name=&continent=非洲&language=&iscountry=&appkey=732afb9ddae9eef8"
;
//
String url = "https://api.jisuapi.com/country/query?name=&continent=非洲&language=&iscountry=&appkey=732afb9ddae9eef8";
ResponseEntity
<
String
>
forEntity
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
//
ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
String
body
=
forEntity
.
getBody
();
//
String body = forEntity.getBody();
System
.
err
.
println
(
body
);
//
System.err.println(body);
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
body
);
//
JSONObject jsonObject = JSONObject.fromObject(body);
String
status
=
jsonObject
.
getString
(
"status"
);
//
String status = jsonObject.getString("status");
if
(
"0"
.
equals
(
status
))
{
//
if ("0".equals(status)) {
JSONArray
jsonArray
=
jsonObject
.
getJSONArray
(
"result"
);
//
JSONArray jsonArray = jsonObject.getJSONArray("result");
for
(
int
i
=
0
;
i
<
jsonArray
.
size
();
i
++)
{
//
for (int i = 0; i < jsonArray.size(); i++) {
Country
country
=
new
Country
();
//
Country country = new Country();
JSONObject
object
=
jsonArray
.
getJSONObject
(
i
);
//
JSONObject object = jsonArray.getJSONObject(i);
String
ename
=
object
.
getString
(
"ename"
);
//
String ename = object.getString("ename");
String
cname
=
object
.
getString
(
"cname"
);
//
String cname = object.getString("cname");
String
areaCode
=
object
.
getString
(
"areacode"
);
//
String areaCode = object.getString("areacode");
String
nationalFlag
=
object
.
getString
(
"nationalflag"
);
//
String nationalFlag = object.getString("nationalflag");
country
.
setAreaCode
(
areaCode
);
//
country.setAreaCode(areaCode);
country
.
setCountryCname
(
cname
);
//
country.setCountryCname(cname);
country
.
setCountryName
(
ename
);
//
country.setCountryName(ename);
country
.
setNationalFlag
(
nationalFlag
);
//
country.setNationalFlag(nationalFlag);
country
.
setId
(
IdUtil
.
createIdbyUUID
());
//
country.setId(IdUtil.createIdbyUUID());
countryRepository
.
save
(
country
);
//
countryRepository.save(country);
//
}
//
}
}
//
}
//
//
}
//
}
//
private
volatile
int
count
=
1
;
//
private volatile int count = 1;
@Autowired
//
@Autowired
private
TbCfStationItemRepository
tbCfStationItemRepository
;
//
private TbCfStationItemRepository tbCfStationItemRepository;
//
@Test
//
@Test
public
void
testImg
()
{
//
public void testImg() {
List
<
TbCfStationItem
>
list
=
tbCfStationItemRepository
.
queryItemsAll
();
//
List<TbCfStationItem> list = tbCfStationItemRepository.queryItemsAll();
try
{
//
try {
//
for
(
TbCfStationItem
item
:
list
)
{
//
for (TbCfStationItem item : list) {
System
.
out
.
println
(
"压缩数量:"
+
count
++);
//
System.out.println("压缩数量:" + count++);
System
.
err
.
println
(
"商品ID:"
+
item
.
getItemId
());
//
System.err.println("商品ID:" + item.getItemId());
//
String
itemImg
=
item
.
getItemImg
();
//
String itemImg = item.getItemImg();
String
[]
urlArr
=
itemImg
.
split
(
";"
);
//
String[] urlArr = itemImg.split(";");
List
<
String
>
strList
=
new
ArrayList
<>();
//
List<String> strList = new ArrayList<>();
for
(
String
url
:
urlArr
)
{
//
for (String url : urlArr) {
//
InputStream
stream
=
getImageStream
(
url
);
//
InputStream stream = getImageStream(url);
if
(
stream
==
null
)
{
//
if (stream == null) {
continue
;
//
continue;
}
//
}
byte
[]
bytes
=
new
byte
[
0
];
//
byte[] bytes = new byte[0];
try
{
//
try {
bytes
=
toByteArray
(
stream
);
//
bytes = toByteArray(stream);
byte
[]
by
=
PicUtils
.
compressPicForScale
(
bytes
,
70
);
//
byte[] by = PicUtils.compressPicForScale(bytes, 70);
long
l
=
System
.
currentTimeMillis
();
//
long l = System.currentTimeMillis();
String
urlName
=
UUID
.
randomUUID
()
+
"-"
+
String
.
valueOf
(
l
).
substring
(
6
)
+
".jpg"
;
//
String urlName = UUID.randomUUID() + "-" + String.valueOf(l).substring(6) + ".jpg";
//
String
compressedUrl
=
OssUtil
.
upload
(
by
,
urlName
,
"afrishop_new"
);
//
String compressedUrl = OssUtil.upload(by, urlName, "afrishop_new");
strList
.
add
(
compressedUrl
);
//
strList.add(compressedUrl);
}
catch
(
Exception
e
)
{
//
} catch (Exception e) {
e
.
printStackTrace
();
//
e.printStackTrace();
}
//
}
}
//
}
tbCfStationItemRepository
.
updateItmeImg
(
strList
.
stream
().
collect
(
Collectors
.
joining
(
";"
)),
item
.
getItemId
());
//
tbCfStationItemRepository.updateItmeImg(strList.stream().collect(Collectors.joining(";")), item.getItemId());
}
//
}
//
}
catch
(
Exception
e
)
{
//
} catch (Exception e) {
//
}
finally
{
//
} finally {
//
//
}
//
}
}
//
}
//
/**
//
/**
* 通过URL获取网络图片
//
* 通过URL获取网络图片
* 获取网络图片流
//
* 获取网络图片流
*
//
*
* @param url 传入的 URL 必须是以 http:// 开头的,因为我们使用了 HttpURLConnection
//
* @param url 传入的 URL 必须是以 http:// 开头的,因为我们使用了 HttpURLConnection
* @return 输入流
//
* @return 输入流
*/
//
*/
public
static
InputStream
getImageStream
(
String
url
)
{
//
public static InputStream getImageStream(String url) {
try
{
//
try {
HttpURLConnection
connection
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
//
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection
.
setReadTimeout
(
10000
);
//
connection.setReadTimeout(10000);
connection
.
setConnectTimeout
(
10000
);
//
connection.setConnectTimeout(10000);
connection
.
setRequestMethod
(
"GET"
);
//
connection.setRequestMethod("GET");
if
(
connection
.
getResponseCode
()
==
HttpURLConnection
.
HTTP_OK
)
{
//
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
return
connection
.
getInputStream
();
//
return connection.getInputStream();
}
//
}
}
catch
(
IOException
e
)
{
//
} catch (IOException e) {
System
.
out
.
println
(
"获取网络图片出现异常,图片路径为:"
+
url
);
//
System.out.println("获取网络图片出现异常,图片路径为:" + url);
e
.
printStackTrace
();
//
e.printStackTrace();
}
//
}
return
null
;
//
return null;
}
//
}
//
/**
//
/**
* 将 InputStream 流转换为 byte[]
//
* 将 InputStream 流转换为 byte[]
*
//
*
* @param input InputStream
//
* @param input InputStream
* @return byte[]
//
* @return byte[]
* @throws IOException IO流异常
//
* @throws IOException IO流异常
*/
//
*/
public
static
byte
[]
toByteArray
(
InputStream
input
)
throws
IOException
{
//
public static byte[] toByteArray(InputStream input) throws IOException {
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
//
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte
[]
buffer
=
new
byte
[
1024
*
4
];
//
byte[] buffer = new byte[1024 * 4];
int
n
=
0
;
//
int n = 0;
while
(-
1
!=
(
n
=
input
.
read
(
buffer
)))
{
//
while (-1 != (n = input.read(buffer))) {
output
.
write
(
buffer
,
0
,
n
);
//
output.write(buffer, 0, n);
}
//
}
return
output
.
toByteArray
();
//
return output.toByteArray();
}
//
}
//
@Test
//
@Test
public
void
test001
(){
//
public void test001(){
System
.
out
.
println
(
"test001"
);
//
System.out.println("test001");
}
//
}
//
//
}
//
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论