Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
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
项目统一框架
amos-boot-biz
Commits
d4c85a91
Commit
d4c85a91
authored
Nov 02, 2023
by
chenzai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
条件灵活的分页查询以及优化uploadmass方法
parent
34602b20
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
172 additions
and
10 deletions
+172
-10
ClientHandler.java
.../main/java/com/yeejoin/amos/kgd/config/ClientHandler.java
+63
-7
IdxBizSyncService.java
...n/amos/boot/module/cas/api/service/IdxBizSyncService.java
+67
-0
IdxBizSyncController.java
...amos/boot/module/cas/controller/IdxBizSyncController.java
+39
-0
application-dev.properties
...ule-cas-biz/src/main/resources/application-dev.properties
+3
-3
No files found.
amos-boot-module/amos-boot-module-api/amos-boot-module-kgd-api/src/main/java/com/yeejoin/amos/kgd/config/ClientHandler.java
View file @
d4c85a91
...
@@ -30,6 +30,7 @@ import org.typroject.tyboot.core.foundation.context.SpringContextHelper;
...
@@ -30,6 +30,7 @@ import org.typroject.tyboot.core.foundation.context.SpringContextHelper;
import
java.io.*
;
import
java.io.*
;
import
java.net.Socket
;
import
java.net.Socket
;
import
java.nio.charset.StandardCharsets
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.*
;
...
@@ -69,6 +70,9 @@ public class ClientHandler<path> implements Runnable {
...
@@ -69,6 +70,9 @@ public class ClientHandler<path> implements Runnable {
}
}
private
String
upload2Maas
(
InputStream
inputStream
,
String
hostAndPort
)
throws
IOException
{
private
String
upload2Maas
(
InputStream
inputStream
,
String
hostAndPort
)
throws
IOException
{
InputStream
intercept
=
intercept
(
inputStream
);
AmosRequestContext
robotAuthentication
=
SpringContextHelper
.
getBean
(
AmosRequestContext
.
class
);
AmosRequestContext
robotAuthentication
=
SpringContextHelper
.
getBean
(
AmosRequestContext
.
class
);
if
(
Objects
.
nonNull
(
robotAuthentication
))
{
if
(
Objects
.
nonNull
(
robotAuthentication
))
{
String
token
=
robotAuthentication
.
getToken
();
String
token
=
robotAuthentication
.
getToken
();
...
@@ -93,16 +97,16 @@ public class ClientHandler<path> implements Runnable {
...
@@ -93,16 +97,16 @@ public class ClientHandler<path> implements Runnable {
}
}
};
};
params
.
add
(
"file"
,
resource
);
params
.
add
(
"file"
,
resource
);
HttpEntity
<
MultiValueMap
<
String
,
Object
>>
requestEntity
=
new
HttpEntity
<>(
params
,
getHeader
(
token
,
product
,
appKey
,
hostAndPort
,
true
));
HttpEntity
<
MultiValueMap
<
String
,
Object
>>
requestEntity
=
new
HttpEntity
<>(
params
,
getHeader
(
token
,
product
,
appKey
,
hostAndPort
,
true
));
RestTemplate
restTemplate
=
new
RestTemplate
();
RestTemplate
restTemplate
=
new
RestTemplate
();
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
uploadUrl
,
HttpMethod
.
POST
,
requestEntity
,
String
.
class
);
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
uploadUrl
,
HttpMethod
.
POST
,
requestEntity
,
String
.
class
);
String
body
=
responseEntity
.
getBody
();
String
body
=
responseEntity
.
getBody
();
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
body
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
body
);
String
result
=
jsonObject
.
getString
(
"result"
);
String
result
=
jsonObject
.
getString
(
"result"
);
String
path
=
jsonObject
.
getString
(
"path"
);
String
path
=
jsonObject
.
getString
(
"path"
);
if
(
jsonObject
.
getString
(
"status"
).
equals
(
"200"
)){
if
(
jsonObject
.
getString
(
"status"
).
equals
(
"200"
))
{
log
.
info
(
"路径:"
+
path
+
"/"
+
result
);
log
.
info
(
"路径:"
+
path
+
"/"
+
result
);
}
else
{
}
else
{
throw
new
RuntimeException
(
"返回状态码错误"
);
throw
new
RuntimeException
(
"返回状态码错误"
);
}
}
...
@@ -152,14 +156,14 @@ public class ClientHandler<path> implements Runnable {
...
@@ -152,14 +156,14 @@ public class ClientHandler<path> implements Runnable {
return
null
;
return
null
;
}
}
private
HttpHeaders
getHeader
(
String
token
,
String
product
,
String
appKey
,
String
hostAndPort
,
Boolean
isUpload
)
{
private
HttpHeaders
getHeader
(
String
token
,
String
product
,
String
appKey
,
String
hostAndPort
,
Boolean
isUpload
)
{
HttpHeaders
header
=
new
HttpHeaders
();
HttpHeaders
header
=
new
HttpHeaders
();
header
.
add
(
Constant
.
TOKEN
,
token
);
header
.
add
(
Constant
.
TOKEN
,
token
);
header
.
add
(
Constant
.
PRODUCT
,
product
);
header
.
add
(
Constant
.
PRODUCT
,
product
);
header
.
add
(
Constant
.
APPKEY
,
appKey
);
header
.
add
(
Constant
.
APPKEY
,
appKey
);
if
(
isUpload
){
if
(
isUpload
)
{
header
.
setContentType
(
MediaType
.
MULTIPART_FORM_DATA
);
header
.
setContentType
(
MediaType
.
MULTIPART_FORM_DATA
);
}
else
{
}
else
{
header
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
header
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
}
}
return
header
;
return
header
;
...
@@ -169,6 +173,58 @@ public class ClientHandler<path> implements Runnable {
...
@@ -169,6 +173,58 @@ public class ClientHandler<path> implements Runnable {
requestInfoToSocketServer
();
requestInfoToSocketServer
();
}
}
//截取文件流
public
static
InputStream
intercept
(
InputStream
is
)
{
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
is
));
StringBuilder
sb
=
new
StringBuilder
();
String
line
=
null
;
try
{
while
((
line
=
reader
.
readLine
())
!=
null
)
{
sb
.
append
(
line
+
"/n"
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
is
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
String
string1
=
sb
.
toString
();
int
startFilePath
=
string1
.
indexOf
(
"##STATITLE##"
);
int
endFilePath
=
string1
.
indexOf
(
"##ENDTITLE##"
);
int
startFile
=
string1
.
indexOf
(
"##STAFILE##"
);
int
endFile
=
string1
.
indexOf
(
"##ENDFILE##"
);
if
(
startFilePath
<
0
)
{
log
.
info
(
"不存在文件名开始标志"
);
return
null
;
}
if
(
endFilePath
<
0
)
{
log
.
info
(
"不存在文件名结束标志"
);
return
null
;
}
if
(
startFile
<
0
)
{
log
.
info
(
"不存在文件开始标志"
);
return
null
;
}
if
(
endFile
<
0
)
{
log
.
info
(
"不存在文件结束标志"
);
return
null
;
}
String
filePath
=
string1
.
substring
(
startFilePath
,
endFilePath
).
substring
(
"##STATITLE##"
.
length
());
log
.
info
(
"文件名:"
+
filePath
);
String
file
=
string1
.
substring
(
startFile
,
endFile
).
substring
(
"##STAFILE##"
.
length
());
log
.
info
(
"文件:"
+
file
);
InputStream
fileInputStream
=
new
ByteArrayInputStream
(
file
.
getBytes
());
return
fileInputStream
;
}
private
static
void
requestInfoToSocketServer
()
{
private
static
void
requestInfoToSocketServer
()
{
try
{
try
{
Socket
socket
=
new
Socket
(
"127.0.0.1"
,
7777
);
Socket
socket
=
new
Socket
(
"127.0.0.1"
,
7777
);
...
...
amos-boot-system-cas/amos-boot-module-cas-api/src/main/java/com/yeejoin/amos/boot/module/cas/api/service/IdxBizSyncService.java
0 → 100644
View file @
d4c85a91
package
com
.
yeejoin
.
amos
.
boot
.
module
.
cas
.
api
.
service
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageInfo
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.beans.factory.annotation.Value
;
import
java.util.List
;
import
java.sql.*
;
import
java.util.*
;
@Service
public
class
IdxBizSyncService
{
@Value
(
"${spring.datasource.url}"
)
private
String
url
;
@Value
(
"${spring.datasource.username}"
)
private
String
user
;
@Value
(
"${spring.datasource.password}"
)
private
String
passwd
;
// 多个查询(分页)
public
List
selectAllPageQuery
(
String
tableName
,
Map
params
,
int
current
,
int
size
)
throws
SQLException
{
Connection
connection
=
DriverManager
.
getConnection
(
url
,
user
,
passwd
);
System
.
out
.
println
(
getSql
(
tableName
,
params
,
current
,
size
));
PreparedStatement
preparedStatement
=
connection
.
prepareStatement
(
getSql
(
tableName
,
params
,
current
,
size
));
ResultSet
set
=
preparedStatement
.
executeQuery
();
List
list
=
convertList
(
set
);
Iterator
iterator
=
list
.
iterator
();
while
(
iterator
.
hasNext
())
{
System
.
out
.
println
(
iterator
.
next
());
}
return
list
;
}
public
String
getSql
(
String
tableName
,
Map
params
,
int
current
,
int
size
)
{
String
sql
=
"select * from "
+
tableName
;
sql
+=
" where "
;
Iterator
<
Map
.
Entry
<
String
,
Object
>>
it
=
params
.
entrySet
().
iterator
();
while
(
it
.
hasNext
())
{
Map
.
Entry
<
String
,
Object
>
entry
=
it
.
next
();
sql
=
sql
+
entry
.
getKey
()
+
" = "
+
"'"
+
entry
.
getValue
()
+
"'"
+
" AND "
;
}
sql
+=
"1 = 1 "
;
sql
+=
" limit "
+
(
current
-
1
)
*
size
+
","
+
size
;
// Page
return
sql
;
}
public
List
convertList
(
ResultSet
rs
)
throws
SQLException
{
List
list
=
new
ArrayList
();
ResultSetMetaData
md
=
rs
.
getMetaData
();
int
columnCount
=
md
.
getColumnCount
();
//Map rowData;
while
(
rs
.
next
())
{
//rowData = new HashMap(columnCount);
Map
rowData
=
new
HashMap
();
for
(
int
i
=
1
;
i
<=
columnCount
;
i
++)
{
rowData
.
put
(
md
.
getColumnName
(
i
),
rs
.
getObject
(
i
));
}
list
.
add
(
rowData
);
}
return
list
;
}
}
\ No newline at end of file
amos-boot-system-cas/amos-boot-module-cas-biz/src/main/java/com/yeejoin/amos/boot/module/cas/controller/IdxBizSyncController.java
0 → 100644
View file @
d4c85a91
package
com
.
yeejoin
.
amos
.
boot
.
module
.
cas
.
controller
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.github.pagehelper.PageInfo
;
import
com.yeejoin.amos.boot.module.cas.api.service.IdxBizSyncService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.restful.doc.TycloudOperation
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
@RestController
@Api
(
tags
=
"Api"
)
@RequestMapping
(
value
=
"/idx-biz-sync"
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
public
class
IdxBizSyncController
{
@Autowired
private
IdxBizSyncService
idxBizSyncService
;
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@RequestMapping
(
value
=
"/page/{tableName}"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"列表分页查询"
,
notes
=
"列表分页查询"
)
@ResponseBody
public
List
listPage
(
@PathVariable
String
tableName
,
@RequestParam
(
value
=
"current"
,
defaultValue
=
"1"
)
int
current
,
@RequestParam
(
value
=
"size"
,
defaultValue
=
"10"
)
int
size
,
@RequestBody
Map
params
)
throws
Exception
{
List
list
=
idxBizSyncService
.
selectAllPageQuery
(
tableName
,
params
,
current
,
size
);
return
list
;
}
}
amos-boot-system-cas/amos-boot-module-cas-biz/src/main/resources/application-dev.properties
View file @
d4c85a91
#DB properties:
#DB properties:
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
spring.datasource.url
=
jdbc:mysql://
172.16.10.210:3306/amos_idx_biz
?allowMultiQueries=true&serverTimezone=GMT%2B8
\
spring.datasource.url
=
jdbc:mysql://
36.46.151.113:5432/project_test
?allowMultiQueries=true&serverTimezone=GMT%2B8
\
&characterEncoding=utf8
&characterEncoding=utf8
spring.datasource.username
=
root
spring.datasource.username
=
admin
spring.datasource.password
=
Yeejoin@202
0
spring.datasource.password
=
Yeejoin@202
3
##eureka properties:
##eureka properties:
eureka.client.service-url.defaultZone
=
http://172.16.10.210:10001/eureka/
eureka.client.service-url.defaultZone
=
http://172.16.10.210:10001/eureka/
...
...
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