Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lingxi-lxy-yanshou
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
后端-黄柯铭
lingxi-lxy-yanshou
Commits
a1ea745a
Commit
a1ea745a
authored
Jun 15, 2021
by
技术总监-万宁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加初始化内容
parent
7e024c9c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
199 additions
and
2 deletions
+199
-2
ServiceInitConfig.java
...ain/java/com/ssy/lingxi/pay/config/ServiceInitConfig.java
+26
-0
PayWay.java
...rvice/src/main/java/com/ssy/lingxi/pay/entity/PayWay.java
+1
-1
PlatformPayWay.java
...c/main/java/com/ssy/lingxi/pay/entity/PlatformPayWay.java
+1
-1
IPayDataInitService.java
.../java/com/ssy/lingxi/pay/service/IPayDataInitService.java
+15
-0
PayDataInitServiceImpl.java
...om/ssy/lingxi/pay/serviceimpl/PayDataInitServiceImpl.java
+156
-0
No files found.
pay-service/src/main/java/com/ssy/lingxi/pay/config/ServiceInitConfig.java
0 → 100644
View file @
a1ea745a
package
com
.
ssy
.
lingxi
.
pay
.
config
;
import
com.ssy.lingxi.pay.service.IPayDataInitService
;
import
org.springframework.context.annotation.Configuration
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
/**
* 服务启动后,执行数据初始化
* @author 万宁
* @version 2.0.0
* @date 2021-06-15
*/
@Configuration
public
class
ServiceInitConfig
{
@Resource
private
IPayDataInitService
payDataInitService
;
@PostConstruct
public
void
systemInit
()
{
//初始化支付服务数据
payDataInitService
.
initPayServiceData
();
}
}
pay-service/src/main/java/com/ssy/lingxi/pay/entity/PayWay.java
View file @
a1ea745a
...
...
@@ -20,7 +20,7 @@ public class PayWay {
*/
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
SEQUENCE
,
generator
=
"pay_pay_way_seq"
)
@SequenceGenerator
(
sequenceName
=
"pay_pay_
pay_
way_seq"
,
name
=
"pay_pay_way_seq"
,
allocationSize
=
1
)
@SequenceGenerator
(
sequenceName
=
"pay_pay_way_seq"
,
name
=
"pay_pay_way_seq"
,
allocationSize
=
1
)
private
Long
id
;
/**
...
...
pay-service/src/main/java/com/ssy/lingxi/pay/entity/PlatformPayWay.java
View file @
a1ea745a
...
...
@@ -18,7 +18,7 @@ public class PlatformPayWay {
*/
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
SEQUENCE
,
generator
=
"pay_platform_pay_way_seq"
)
@SequenceGenerator
(
sequenceName
=
"pay_p
ay_p
latform_pay_way_seq"
,
name
=
"pay_platform_pay_way_seq"
,
allocationSize
=
1
)
@SequenceGenerator
(
sequenceName
=
"pay_platform_pay_way_seq"
,
name
=
"pay_platform_pay_way_seq"
,
allocationSize
=
1
)
private
Long
id
;
/**
...
...
pay-service/src/main/java/com/ssy/lingxi/pay/service/IPayDataInitService.java
0 → 100644
View file @
a1ea745a
package
com
.
ssy
.
lingxi
.
pay
.
service
;
/**
* 服务数据初始化
* @author 万宁
* @version 2.0.0
* @date 2021-06-15
*/
public
interface
IPayDataInitService
{
/**
* 初始化支付服务数据
*/
void
initPayServiceData
();
}
pay-service/src/main/java/com/ssy/lingxi/pay/serviceimpl/PayDataInitServiceImpl.java
0 → 100644
View file @
a1ea745a
package
com
.
ssy
.
lingxi
.
pay
.
serviceimpl
;
import
com.ssy.lingxi.pay.entity.PayWay
;
import
com.ssy.lingxi.pay.entity.PlatformPayWay
;
import
com.ssy.lingxi.pay.repository.PayWayRepository
;
import
com.ssy.lingxi.pay.repository.PlatformPayWayRepository
;
import
com.ssy.lingxi.pay.service.IPayDataInitService
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.support.rowset.SqlRowSet
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 服务数据初始化
* @author 万宁
* @version 2.0.0
* @date 2021-06-15
*/
@Service
public
class
PayDataInitServiceImpl
implements
IPayDataInitService
{
@Resource
private
JdbcTemplate
jdbcTemplate
;
@Resource
private
PayWayRepository
payWayRepository
;
@Resource
private
PlatformPayWayRepository
platformPayWayRepository
;
/**
* 初始化支付服务数据
*/
@Override
public
void
initPayServiceData
()
{
//支付方式
initPayWay
();
//平台支付方式
initPlatformPayWay
();
}
/**
* 初始化支付方式
*/
private
void
initPayWay
()
{
if
(
countTable
(
"pay_pay_way"
)
>
0
)
{
return
;
}
alterSequence
(
"pay_pay_way_seq"
);
List
<
PayWay
>
payWayList
=
new
ArrayList
<>();
PayWay
payWay
=
new
PayWay
();
payWay
.
setIsPitchOn
(
1
);
payWay
.
setPayType
(
1
);
payWay
.
setWay
(
"支付宝"
);
payWayList
.
add
(
payWay
);
payWay
=
new
PayWay
();
payWay
.
setIsPitchOn
(
1
);
payWay
.
setPayType
(
1
);
payWay
.
setWay
(
"微信"
);
payWayList
.
add
(
payWay
);
payWay
=
new
PayWay
();
payWay
.
setIsPitchOn
(
1
);
payWay
.
setPayType
(
1
);
payWay
.
setWay
(
"银联"
);
payWayList
.
add
(
payWay
);
payWay
=
new
PayWay
();
payWay
.
setIsPitchOn
(
1
);
payWay
.
setPayType
(
1
);
payWay
.
setWay
(
"余额支付"
);
payWayList
.
add
(
payWay
);
payWay
=
new
PayWay
();
payWay
.
setIsPitchOn
(
1
);
payWay
.
setPayType
(
2
);
payWay
.
setWay
(
"线下支付线上确认"
);
payWayList
.
add
(
payWay
);
payWay
=
new
PayWay
();
payWay
.
setIsPitchOn
(
1
);
payWay
.
setPayType
(
3
);
payWay
.
setWay
(
"授信额度支付"
);
payWayList
.
add
(
payWay
);
payWay
=
new
PayWay
();
payWay
.
setIsPitchOn
(
1
);
payWay
.
setPayType
(
4
);
payWay
.
setWay
(
"货到付款"
);
payWayList
.
add
(
payWay
);
payWayRepository
.
saveAll
(
payWayList
);
}
/**
* 初始化平台支付方式
*/
private
void
initPlatformPayWay
()
{
if
(
countTable
(
"pay_platform_pay_way"
)
>
0
)
{
return
;
}
List
<
PayWay
>
payWayList
=
payWayRepository
.
findAll
(
Sort
.
by
(
"id"
).
ascending
());
if
(
CollectionUtils
.
isEmpty
(
payWayList
))
{
return
;
}
alterSequence
(
"pay_platform_pay_way_seq"
);
List
<
PlatformPayWay
>
platformPayWayList
=
new
ArrayList
<>();
for
(
PayWay
payWay
:
payWayList
)
{
PlatformPayWay
platformPayWay
=
new
PlatformPayWay
();
platformPayWay
.
setIsPitchOn
(
payWay
.
getIsPitchOn
());
platformPayWay
.
setPayType
(
payWay
.
getPayType
());
platformPayWay
.
setWay
(
payWay
.
getWay
());
platformPayWay
.
setPayWayId
(
payWay
.
getId
());
platformPayWayList
.
add
(
platformPayWay
);
}
platformPayWayRepository
.
saveAll
(
platformPayWayList
);
}
/**
* 执行 select count(id) from table 语句
* @param dbTableName 数据库的表名称
* @return 表数据行数
*/
private
long
countTable
(
String
dbTableName
)
{
String
sql
=
"select count(id) as total from "
+
dbTableName
+
";"
;
SqlRowSet
sqlRowSet
=
jdbcTemplate
.
queryForRowSet
(
sql
);
long
total
=
0
;
while
(
sqlRowSet
.
next
())
{
total
=
sqlRowSet
.
getLong
(
"total"
);
}
return
total
;
}
/**
* 更改序列值为1
* @param sequenceName 序列名称
*/
private
void
alterSequence
(
String
sequenceName
)
{
String
sql
=
"alter sequence "
+
sequenceName
+
" restart with 1"
;
jdbcTemplate
.
execute
(
sql
);
}
}
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