Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
73027637
提交
73027637
authored
2月 06, 2021
作者:
吴德鹏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
图片压缩
上级
24529114
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
239 行增加
和
129 行删除
+239
-129
TbCfStationItem.java
.../java/com/example/afrishop_v3/models/TbCfStationItem.java
+9
-0
TbCfStationItemRepository.java
...ple/afrishop_v3/repository/TbCfStationItemRepository.java
+11
-1
AfrishopV3ApplicationTests.java
...a/com/example/afrishop_v3/AfrishopV3ApplicationTests.java
+219
-128
没有找到文件。
src/main/java/com/example/afrishop_v3/models/TbCfStationItem.java
浏览文件 @
73027637
...
@@ -125,6 +125,8 @@ public class TbCfStationItem {
...
@@ -125,6 +125,8 @@ public class TbCfStationItem {
private
Integer
sort
;
private
Integer
sort
;
private
String
handled
;
@JsonIgnore
@JsonIgnore
@ManyToOne
@ManyToOne
@JoinColumn
(
columnDefinition
=
"template"
,
name
=
"template"
)
@JoinColumn
(
columnDefinition
=
"template"
,
name
=
"template"
)
...
@@ -504,4 +506,11 @@ public class TbCfStationItem {
...
@@ -504,4 +506,11 @@ public class TbCfStationItem {
return
itemDescritionId
;
return
itemDescritionId
;
}
}
public
String
getHandled
()
{
return
handled
;
}
public
void
setHandled
(
String
handled
)
{
this
.
handled
=
handled
;
}
}
}
src/main/java/com/example/afrishop_v3/repository/TbCfStationItemRepository.java
浏览文件 @
73027637
...
@@ -5,9 +5,11 @@ import com.example.afrishop_v3.models.TbCfStationItem;
...
@@ -5,9 +5,11 @@ import com.example.afrishop_v3.models.TbCfStationItem;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
org.springframework.data.repository.query.Param
;
import
org.springframework.data.repository.query.Param
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
import
java.util.List
;
...
@@ -37,7 +39,7 @@ public interface TbCfStationItemRepository extends PagingAndSortingRepository<Tb
...
@@ -37,7 +39,7 @@ public interface TbCfStationItemRepository extends PagingAndSortingRepository<Tb
Page
<
TbCfStationItem
>
findByItemCategory
(
String
itemName
,
Pageable
pageable
);
Page
<
TbCfStationItem
>
findByItemCategory
(
String
itemName
,
Pageable
pageable
);
List
<
TbCfStationItem
>
findAllByItemDescritionId
(
String
id
,
Sort
sort
);
List
<
TbCfStationItem
>
findAllByItemDescritionId
(
String
id
,
Sort
sort
);
@Query
(
value
=
"select i from #{#entityName} i inner join AdvertisementItem a on i.itemId=a.itemId where a.adId=?1 order by a.sort"
)
@Query
(
value
=
"select i from #{#entityName} i inner join AdvertisementItem a on i.itemId=a.itemId where a.adId=?1 order by a.sort"
)
Page
<
TbCfStationItem
>
getAdvertisementItem
(
String
adId
,
Pageable
pageable
);
Page
<
TbCfStationItem
>
getAdvertisementItem
(
String
adId
,
Pageable
pageable
);
...
@@ -49,4 +51,12 @@ public interface TbCfStationItemRepository extends PagingAndSortingRepository<Tb
...
@@ -49,4 +51,12 @@ public interface TbCfStationItemRepository extends PagingAndSortingRepository<Tb
List
<
TbCfStationItem
>
findAllByItemIdIn
(
String
[]
ids
);
List
<
TbCfStationItem
>
findAllByItemIdIn
(
String
[]
ids
);
@Query
(
value
=
"select i from #{#entityName} i where i.handled is null "
)
List
<
TbCfStationItem
>
queryItemsAll
();
@Modifying
@Query
(
value
=
"update TbCfStationItem set handled='Y',itemImg=:itemImg where itemId=:itemId"
)
@Transactional
int
updateItmeImg
(
@Param
(
"itemImg"
)
String
itemImg
,
@Param
(
"itemId"
)
String
itemId
);
}
}
src/test/java/com/example/afrishop_v3/AfrishopV3ApplicationTests.java
浏览文件 @
73027637
//package com.example.afrishop_v3;
package
com
.
example
.
afrishop_v3
;
//
//import com.example.afrishop_v3.models.Country;
import
com.example.afrishop_v3.models.*
;
//import com.example.afrishop_v3.models.JsonTag;
import
com.example.afrishop_v3.repository.CountryRepository
;
//import com.example.afrishop_v3.models.TbCfOrder;
import
com.example.afrishop_v3.repository.TbCfOrderRepository
;
//import com.example.afrishop_v3.models.Token;
import
com.example.afrishop_v3.repository.TbCfStationItemRepository
;
//import com.example.afrishop_v3.repository.CountryRepository;
import
com.example.afrishop_v3.repository.TokenRepository
;
//import com.example.afrishop_v3.repository.TbCfOrderRepository;
import
com.example.afrishop_v3.util.IdUtil
;
//import com.example.afrishop_v3.repository.TokenRepository;
import
com.example.afrishop_v3.util.OssUtil
;
//import com.example.afrishop_v3.util.IdUtil;
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.text.SimpleDateFormat;
import
java.io.ByteArrayOutputStream
;
//import java.time.LocalDateTime;
import
java.io.IOException
;
//import java.util.*;
import
java.io.InputStream
;
//import java.util.concurrent.ExecutorService;
import
java.net.HttpURLConnection
;
//import java.util.concurrent.Executors;
import
java.net.URL
;
//import java.util.concurrent.Future;
import
java.text.SimpleDateFormat
;
//import java.util.concurrent.locks.ReentrantLock;
import
java.time.LocalDateTime
;
//
import
java.util.*
;
//@RunWith(SpringRunner.class)
import
java.util.concurrent.ExecutorService
;
//@SpringBootTest
import
java.util.concurrent.Executors
;
//public class AfrishopV3ApplicationTests {
import
java.util.concurrent.Future
;
//
import
java.util.concurrent.locks.ReentrantLock
;
// RestTemplate restTemplate = new RestTemplate();
import
java.util.stream.Collectors
;
//
// @Test
@RunWith
(
SpringRunner
.
class
)
// public void contextLoads() {
@SpringBootTest
// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
public
class
AfrishopV3ApplicationTests
{
// String now = format.format(new Date());
// System.out.println(now);
RestTemplate
restTemplate
=
new
RestTemplate
();
// }
//
@Test
// private String url = "http://localhost:8099/afrishop/discover/bonus/saveNetworkMarketing";
public
void
contextLoads
()
{
// @Autowired
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm:ss"
);
// private TbCfOrderRepository orderRepository;
String
now
=
format
.
format
(
new
Date
());
//
System
.
out
.
println
(
now
);
//// post35789572fbf643cdab55901d1dc511a6
}
//// userInfo00297bf300ed45e092a5182dececad21
//// productSharervv32GmG4q
private
String
url
=
"http://localhost:8099/afrishop/discover/bonus/saveNetworkMarketing"
;
//// amount0.9
@Autowired
//// orderId008272b1fb994aef9b199449f46d5aa5
private
TbCfOrderRepository
orderRepository
;
//
// @Test
// post35789572fbf643cdab55901d1dc511a6
// public void test1() {
// userInfo00297bf300ed45e092a5182dececad21
//
// productSharervv32GmG4q
// Optional<TbCfOrder> byId = orderRepository.findById("12a9d7d1042348278c97980a00fc67c4");
// amount0.9
// JSONObject json = new JSONObject();
// orderId008272b1fb994aef9b199449f46d5aa5
// json.put("userInfo", "32dcda5a709c4265a6f01686ae9b1c1c");
// json.put("amount", byId.get().getItemsPrice());
@Test
// json.put("orderId", "12a9d7d1042348278c97980a00fc67c4");
public
void
test1
()
{
// System.out.println(json);
// ResponseEntity<Result> resultResponseEntity = restTemplate.postForEntity(url, json, Result.class);
Optional
<
TbCfOrder
>
byId
=
orderRepository
.
findById
(
"12a9d7d1042348278c97980a00fc67c4"
);
// System.err.println(resultResponseEntity);
JSONObject
json
=
new
JSONObject
();
// }
json
.
put
(
"userInfo"
,
"32dcda5a709c4265a6f01686ae9b1c1c"
);
//
json
.
put
(
"amount"
,
byId
.
get
().
getItemsPrice
());
// @Autowired
json
.
put
(
"orderId"
,
"12a9d7d1042348278c97980a00fc67c4"
);
// private TokenRepository tokenRepository;
System
.
out
.
println
(
json
);
//
ResponseEntity
<
Result
>
resultResponseEntity
=
restTemplate
.
postForEntity
(
url
,
json
,
Result
.
class
);
// @Autowired
System
.
err
.
println
(
resultResponseEntity
);
// private CountryRepository countryRepository;
}
//
//
@Autowired
// @Test
private
TokenRepository
tokenRepository
;
// public void test2() {
// List list = new ArrayList();
@Autowired
// list.add(2);
private
CountryRepository
countryRepository
;
// list.add(1);
// list.add(3);
// list.forEach(System.out::println);
@Test
//
public
void
test2
()
{
// }
List
list
=
new
ArrayList
();
//
list
.
add
(
2
);
// private ReentrantLock reentrantLock = new ReentrantLock();
list
.
add
(
1
);
//
list
.
add
(
3
);
// @Test
list
.
forEach
(
System
.
out
::
println
);
// public void testImport() {
// ExecutorService executorService = Executors.newCachedThreadPool();
}
//
// for (int i = 0; i < 20; i++) {
private
ReentrantLock
reentrantLock
=
new
ReentrantLock
();
// executorService.execute(() -> importCountry());
// }
@Test
//
public
void
testImport
()
{
// }
ExecutorService
executorService
=
Executors
.
newCachedThreadPool
();
//
// @Test
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
// public void importCountry() {
executorService
.
execute
(()
->
importCountry
());
//
}
// String url = "https://api.jisuapi.com/country/query?name=&continent=非洲&language=&iscountry=&appkey=732afb9ddae9eef8";
// ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
}
// String body = forEntity.getBody();
// System.err.println(body);
@Test
// JSONObject jsonObject = JSONObject.fromObject(body);
public
void
importCountry
()
{
// String status = jsonObject.getString("status");
// if ("0".equals(status)) {
String
url
=
"https://api.jisuapi.com/country/query?name=&continent=非洲&language=&iscountry=&appkey=732afb9ddae9eef8"
;
// JSONArray jsonArray = jsonObject.getJSONArray("result");
ResponseEntity
<
String
>
forEntity
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
// for (int i = 0; i < jsonArray.size(); i++) {
String
body
=
forEntity
.
getBody
();
// Country country = new Country();
System
.
err
.
println
(
body
);
// JSONObject object = jsonArray.getJSONObject(i);
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
body
);
// String ename = object.getString("ename");
String
status
=
jsonObject
.
getString
(
"status"
);
// String cname = object.getString("cname");
if
(
"0"
.
equals
(
status
))
{
// String areaCode = object.getString("areacode");
JSONArray
jsonArray
=
jsonObject
.
getJSONArray
(
"result"
);
// String nationalFlag = object.getString("nationalflag");
for
(
int
i
=
0
;
i
<
jsonArray
.
size
();
i
++)
{
// country.setAreaCode(areaCode);
Country
country
=
new
Country
();
// country.setCountryCname(cname);
JSONObject
object
=
jsonArray
.
getJSONObject
(
i
);
// country.setCountryName(ename);
String
ename
=
object
.
getString
(
"ename"
);
// country.setNationalFlag(nationalFlag);
String
cname
=
object
.
getString
(
"cname"
);
// country.setId(IdUtil.createIdbyUUID());
String
areaCode
=
object
.
getString
(
"areacode"
);
// countryRepository.save(country);
String
nationalFlag
=
object
.
getString
(
"nationalflag"
);
//
country
.
setAreaCode
(
areaCode
);
// }
country
.
setCountryCname
(
cname
);
// }
country
.
setCountryName
(
ename
);
//
country
.
setNationalFlag
(
nationalFlag
);
//
country
.
setId
(
IdUtil
.
createIdbyUUID
());
// }
countryRepository
.
save
(
country
);
//
//
}
//}
}
}
private
volatile
int
count
=
1
;
@Autowired
private
TbCfStationItemRepository
tbCfStationItemRepository
;
@Test
public
void
testImg
()
{
List
<
TbCfStationItem
>
list
=
tbCfStationItemRepository
.
queryItemsAll
();
try
{
for
(
TbCfStationItem
item
:
list
)
{
System
.
out
.
println
(
"压缩数量:"
+
count
++);
System
.
err
.
println
(
"商品ID:"
+
item
.
getItemId
());
String
itemImg
=
item
.
getItemImg
();
String
[]
urlArr
=
itemImg
.
split
(
";"
);
List
<
String
>
strList
=
new
ArrayList
<>();
for
(
String
url
:
urlArr
)
{
InputStream
stream
=
getImageStream
(
url
);
if
(
stream
==
null
)
{
continue
;
}
byte
[]
bytes
=
new
byte
[
0
];
try
{
bytes
=
toByteArray
(
stream
);
byte
[]
by
=
PicUtils
.
compressPicForScale
(
bytes
,
70
);
long
l
=
System
.
currentTimeMillis
();
String
urlName
=
UUID
.
randomUUID
()
+
"-"
+
String
.
valueOf
(
l
).
substring
(
6
)
+
".jpg"
;
String
compressedUrl
=
OssUtil
.
upload
(
by
,
urlName
,
"afrishop_new"
);
strList
.
add
(
compressedUrl
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
tbCfStationItemRepository
.
updateItmeImg
(
strList
.
stream
().
collect
(
Collectors
.
joining
(
";"
)),
item
.
getItemId
());
}
}
catch
(
Exception
e
)
{
}
finally
{
}
}
/**
* 通过URL获取网络图片
* 获取网络图片流
*
* @param url 传入的 URL 必须是以 http:// 开头的,因为我们使用了 HttpURLConnection
* @return 输入流
*/
public
static
InputStream
getImageStream
(
String
url
)
{
try
{
HttpURLConnection
connection
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
connection
.
setReadTimeout
(
10000
);
connection
.
setConnectTimeout
(
10000
);
connection
.
setRequestMethod
(
"GET"
);
if
(
connection
.
getResponseCode
()
==
HttpURLConnection
.
HTTP_OK
)
{
return
connection
.
getInputStream
();
}
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"获取网络图片出现异常,图片路径为:"
+
url
);
e
.
printStackTrace
();
}
return
null
;
}
/**
* 将 InputStream 流转换为 byte[]
*
* @param input InputStream
* @return byte[]
* @throws IOException IO流异常
*/
public
static
byte
[]
toByteArray
(
InputStream
input
)
throws
IOException
{
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
1024
*
4
];
int
n
=
0
;
while
(-
1
!=
(
n
=
input
.
read
(
buffer
)))
{
output
.
write
(
buffer
,
0
,
n
);
}
return
output
.
toByteArray
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论