Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bme-access-upload
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李洪明
bme-access-upload
Commits
1ffff686
Commit
1ffff686
authored
Jul 10, 2025
by
曹军
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传定时任务
parent
efa95437
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
100 additions
and
9 deletions
+100
-9
UploadDataNewTask.java
...ain/java/com/bme/access/upload/job/UploadDataNewTask.java
+1
-1
InFactoryTransportVehicleInfoService.java
.../module/service/InFactoryTransportVehicleInfoService.java
+1
-0
Base64Utils.java
.../java/com/bme/access/upload/module/utils/Base64Utils.java
+45
-0
BeanConverter.java
...ava/com/bme/access/upload/module/utils/BeanConverter.java
+8
-8
TestBase.java
...ain/java/com/bme/access/upload/module/utils/TestBase.java
+34
-0
TestController.java
...java/com/bme/access/upload/module/web/TestController.java
+11
-0
No files found.
src/main/java/com/bme/access/upload/job/UploadDataNewTask.java
View file @
1ffff686
...
...
@@ -25,7 +25,7 @@ public class UploadDataNewTask {
/**
* 场内运输车辆信息-添加
*/
@Scheduled
(
cron
=
"0 0/
15
* * * *"
)
@Scheduled
(
cron
=
"0 0/
2
* * * *"
)
public
void
uploadInFactoryTransportVehicleInfo
()
{
log
.
info
(
"场内运输车辆信息-添加"
);
try
{
...
...
src/main/java/com/bme/access/upload/module/service/InFactoryTransportVehicleInfoService.java
View file @
1ffff686
...
...
@@ -40,6 +40,7 @@ public class InFactoryTransportVehicleInfoService {
}
for
(
InFactoryTransportVehicleInfo
inFactoryTransportVehicleInfo
:
inFactoryTransportVehicleInfos
)
{
String
bodyJson
=
JSONObject
.
toJSONString
(
inFactoryTransportVehicleInfo
);
// log.info("场内车辆最终被发送的数据bodyJson={}", bodyJson);
HttpUtils
.
sendPost
(
IN_FACTORY_URL
,
null
,
null
,
bodyJson
);
Thread
.
sleep
(
50
);
}
...
...
src/main/java/com/bme/access/upload/module/utils/Base64Utils.java
View file @
1ffff686
...
...
@@ -7,6 +7,7 @@ import sun.misc.BASE64Encoder;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
java.util.Base64
;
/**
...
...
@@ -191,6 +192,50 @@ public class Base64Utils {
return
null
;
}
public
static
String
encodeImageUrl
(
String
originalUrl
)
{
try
{
// 1. 分割URL为协议+主机部分和路径部分
int
protocolEndIndex
=
originalUrl
.
indexOf
(
"://"
);
if
(
protocolEndIndex
==
-
1
)
{
throw
new
IllegalArgumentException
(
"Invalid URL format"
);
}
String
protocol
=
originalUrl
.
substring
(
0
,
protocolEndIndex
+
3
);
String
remainingUrl
=
originalUrl
.
substring
(
protocolEndIndex
+
3
);
int
pathStartIndex
=
remainingUrl
.
indexOf
(
"/"
);
if
(
pathStartIndex
==
-
1
)
{
return
originalUrl
;
// 没有路径部分,直接返回原始URL
}
String
hostPart
=
remainingUrl
.
substring
(
0
,
pathStartIndex
);
String
pathPart
=
remainingUrl
.
substring
(
pathStartIndex
);
// 2. 分割路径为目录部分和文件名部分
int
lastSlashIndex
=
pathPart
.
lastIndexOf
(
"/"
);
String
directoryPart
=
pathPart
.
substring
(
0
,
lastSlashIndex
+
1
);
String
fileName
=
pathPart
.
substring
(
lastSlashIndex
+
1
);
// 3. 对文件名进行编码处理,保留必要的特殊字符
String
encodedFileName
=
URLEncoder
.
encode
(
fileName
,
"UTF-8"
)
.
replaceAll
(
"\\+"
,
"%20"
)
// 将加号替换为%20
.
replaceAll
(
"%3A"
,
":"
)
// 恢复冒号
.
replaceAll
(
"%2F"
,
"/"
)
// 恢复斜杠
.
replaceAll
(
"%3F"
,
"?"
)
// 恢复问号
.
replaceAll
(
"%3D"
,
"="
)
// 恢复等号
.
replaceAll
(
"%26"
,
"&"
);
// 恢复和号
// 4. 重新组合完整URL
return
protocol
+
hostPart
+
directoryPart
+
encodedFileName
;
}
catch
(
UnsupportedEncodingException
|
IllegalArgumentException
e
)
{
// 处理编码异常或非法URL格式
System
.
err
.
println
(
"Error encoding URL: "
+
e
.
getMessage
());
return
originalUrl
;
// 出错时返回原始URL
}
}
public
static
void
main
(
String
[]
args
)
{
byte
[]
bytes
=
getByteImgByUrl
(
"https://q1.itc.cn/q_70/images03/20240430/59fe8596e4cb4824a6f27315328a3559.jpeg"
);
System
.
out
.
println
(
bytes
);
...
...
src/main/java/com/bme/access/upload/module/utils/BeanConverter.java
View file @
1ffff686
...
...
@@ -28,14 +28,14 @@ public class BeanConverter {
InFactoryTransportVehicleInfo
info
=
new
InFactoryTransportVehicleInfo
();
info
.
setCarNo
(
item
.
getNumberPlate
());
if
(
StringUtils
.
isNotBlank
(
item
.
getOnBoardList
()))
{
info
.
setVehicleListImg
(
Base64Utils
.
getBase64ByUrl
(
item
.
getOnBoardList
(
)));
info
.
setVehicleListImg
(
Base64Utils
.
imgToBase64
(
Base64Utils
.
encodeImageUrl
(
item
.
getOnBoardList
()
)));
}
if
(
StringUtils
.
isNotBlank
(
item
.
getDrivingLicense
()))
{
info
.
setDrivingLicenseImg
(
Base64Utils
.
getBase64ByUrl
(
item
.
getDrivingLicense
(
)));
info
.
setDrivingLicenseImg
(
Base64Utils
.
imgToBase64
(
Base64Utils
.
encodeImageUrl
(
item
.
getDrivingLicense
()
)));
}
info
.
setSensorCatalyticConverterImg
(
null
);
if
(
StringUtils
.
isNotBlank
(
item
.
getVehicleImage
()))
{
info
.
setCarImg
(
Base64Utils
.
getBase64ByUrl
(
item
.
getVehicleImage
()));
info
.
setCarImg
(
Base64Utils
.
imgToBase64
(
item
.
getVehicleImage
()));
}
if
(
item
.
getVehicleEmissions
()
==
null
)
{
info
.
setEmissionStandard
(
"X"
);
...
...
@@ -123,10 +123,10 @@ public class BeanConverter {
}
if
(
StringUtils
.
isNotBlank
(
item
.
getDrivingLicenseImage
()))
{
info
.
setDrivingLicenseImg
(
Base64Utils
.
getBase64ByUrl
(
item
.
getDrivingLicenseImage
(
)));
info
.
setDrivingLicenseImg
(
Base64Utils
.
imgToBase64
(
Base64Utils
.
encodeImageUrl
(
item
.
getDrivingLicenseImage
()
)));
}
if
(
StringUtils
.
isNotBlank
(
item
.
getOnBoardList
()))
{
info
.
setVehicleListImg
(
Base64Utils
.
getBase64ByUrl
(
item
.
getOnBoardList
(
)));
info
.
setVehicleListImg
(
Base64Utils
.
imgToBase64
(
Base64Utils
.
encodeImageUrl
(
item
.
getOnBoardList
()
)));
}
info
.
setVehicleMode
(
item
.
getModel
());
info
.
setVehicleType
(
item
.
getVehicleType
());
...
...
@@ -162,11 +162,11 @@ public class BeanConverter {
info
.
setEngineManufacturer
(
item
.
getEngineVendor
());
info
.
setEngineModel
(
item
.
getEngineModel
());
if
(
StringUtils
.
isNotBlank
(
item
.
getEngineImage
()))
{
info
.
setEnginePlaque
(
Base64Utils
.
getBase64ByUrl
(
item
.
getEngineImage
(
)));
info
.
setEnginePlaque
(
Base64Utils
.
imgToBase64
(
Base64Utils
.
encodeImageUrl
(
item
.
getEngineImage
()
)));
}
info
.
setEngineSerialNumber
(
item
.
getEnvironmentSN
());
if
(
StringUtils
.
isNotBlank
(
item
.
getVehicleLable
()))
{
info
.
setEnvIronMentalLabel
(
Base64Utils
.
getBase64ByUrl
(
item
.
getVehicleLable
(
)));
info
.
setEnvIronMentalLabel
(
Base64Utils
.
imgToBase64
(
Base64Utils
.
encodeImageUrl
(
item
.
getVehicleLable
()
)));
}
info
.
setEquipmentModel
(
item
.
getMechanicalModel
());
info
.
setEquipmentType
(
item
.
getMechanicalType
());
...
...
@@ -176,7 +176,7 @@ public class BeanConverter {
info
.
setOwner
(
item
.
getOwener
());
info
.
setPin
(
item
.
getMechanicalEnvironment
());
if
(
StringUtils
.
isNotBlank
(
item
.
getDeviceImage
()))
{
info
.
setVehiclePlaque
(
Base64Utils
.
getBase64ByUrl
(
item
.
getDeviceImage
(
)));
info
.
setVehiclePlaque
(
Base64Utils
.
imgToBase64
(
Base64Utils
.
encodeImageUrl
(
item
.
getDeviceImage
()
)));
}
info
.
setMachMfr
(
null
);
info
.
setEngNetPower
(
null
);
...
...
src/main/java/com/bme/access/upload/module/utils/TestBase.java
0 → 100644
View file @
1ffff686
package
com
.
bme
.
access
.
upload
.
module
.
utils
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.util.Base64
;
public
class
TestBase
{
public
static
String
convert
(
String
imageUrl
)
throws
Exception
{
try
(
InputStream
inputStream
=
new
URL
(
imageUrl
).
openStream
();
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
())
{
byte
[]
buffer
=
new
byte
[
4096
];
int
bytesRead
;
// 分块读取图片数据
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
outputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
// 转换为Base64字符串
return
Base64
.
getEncoder
().
encodeToString
(
outputStream
.
toByteArray
());
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
url
=
"http://visimg.bmetech.com/access/control/146/in_and_out_%E7%9A%96N79079_inOutImage_20250701173146.jpg"
;
System
.
out
.
println
(
"=============="
);
// 输出Base64字符串
System
.
out
.
println
(
"data:image/jpeg;base64,"
+
convert
(
url
));
// 输出Base64字符串
System
.
out
.
println
(
"=============="
);
// 输出Base64字符串
}
}
src/main/java/com/bme/access/upload/module/web/TestController.java
View file @
1ffff686
...
...
@@ -8,11 +8,13 @@ import com.bme.access.upload.model.InAndOutDate;
import
com.bme.access.upload.model.InAndOutDateUrl
;
import
com.bme.access.upload.model.MaterialInfo
;
import
com.bme.access.upload.model.TransportDate
;
import
com.bme.access.upload.module.service.InFactoryTransportVehicleInfoService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -28,6 +30,9 @@ public class TestController {
private
final
static
String
CARGO_URL
=
"https://dctapi.soszyzg.com/dct/addCargo"
;
private
final
static
String
COMPANY_CODE
=
"1302847854"
;
@Autowired
private
InFactoryTransportVehicleInfoService
inFactoryTransportVehicleInfoService
;
@GetMapping
(
"/uploadInAndOutDate"
)
public
CommonResult
uploadInAndOutDate
()
throws
Exception
{
// 313683 川L99718 2025-07-09 16:07:36.210 http://192.168.2.80:8080/250709/Vehicle_Plate/16_7_36_140.jpg 2 GC_1MEN http://192.168.2.80:8080/250709/ALL_Vehicle_SmallPlate/16_7_36_207.jpg 2 1 1 1752048456
...
...
@@ -113,4 +118,10 @@ public class TestController {
materialInfo
.
setEntryexitflownumber
(
rsn
);
return
materialInfo
;
}
@GetMapping
(
"/uploadInfactory"
)
public
void
uploadInfactory
()
throws
Exception
{
inFactoryTransportVehicleInfoService
.
getAndUploadInFactoryTransportVehicleInfo
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment