Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
data-server
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
licc
data-server
Commits
d910a637
Commit
d910a637
authored
Jun 17, 2021
by
licc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化sql
parent
9aab3052
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
111 additions
and
45 deletions
+111
-45
UserDataMapper.java
...per/src/main/java/cn/wisenergy/mapper/UserDataMapper.java
+2
-0
UserRechargeMapper.java
...src/main/java/cn/wisenergy/mapper/UserRechargeMapper.java
+7
-0
UsersMapper.java
...mapper/src/main/java/cn/wisenergy/mapper/UsersMapper.java
+9
-1
UserDataMapper.xml
...nergy-mapper/src/main/resources/mapper/UserDataMapper.xml
+21
-14
UserRechargeMapper.xml
...y-mapper/src/main/resources/mapper/UserRechargeMapper.xml
+4
-0
UsersMapper.xml
wisenergy-mapper/src/main/resources/mapper/UsersMapper.xml
+11
-9
UserData.java
...-model/src/main/java/cn/wisenergy/model/app/UserData.java
+3
-0
UsersInfoDto.java
...el/src/main/java/cn/wisenergy/model/dto/UsersInfoDto.java
+1
-0
UserQueryVo.java
...odel/src/main/java/cn/wisenergy/model/vo/UserQueryVo.java
+16
-0
UserDataService.java
...c/main/java/cn/wisenergy/service/app/UserDataService.java
+3
-1
UserDataServiceImpl.java
...va/cn/wisenergy/service/app/impl/UserDataServiceImpl.java
+28
-16
UserDataController.java
...isenergy/web/admin/controller/app/UserDataController.java
+6
-4
No files found.
wisenergy-mapper/src/main/java/cn/wisenergy/mapper/UserDataMapper.java
View file @
d910a637
...
...
@@ -14,4 +14,6 @@ public interface UserDataMapper extends BaseMapper<UserData> {
int
edit
(
UserData
userData
);
UserData
getByUserId
(
@Param
(
"userId"
)
Long
userId
);
Long
getMaxId
();
}
wisenergy-mapper/src/main/java/cn/wisenergy/mapper/UserRechargeMapper.java
View file @
d910a637
...
...
@@ -14,4 +14,11 @@ public interface UserRechargeMapper extends BaseMapper<UserRechargeMapper> {
*/
Double
getTotalRecharge
(
@Param
(
"userId"
)
Long
userId
);
/**
* 获取充币地址
* @param userId 用户id
* @return 充币地址
*/
String
getReceiveAddr
(
@Param
(
"userId"
)
Long
userId
);
}
wisenergy-mapper/src/main/java/cn/wisenergy/mapper/UsersMapper.java
View file @
d910a637
...
...
@@ -71,7 +71,15 @@ public interface UsersMapper extends BaseMapper<Users> {
*/
Integer
getTotal
(
@Param
(
"id"
)
Long
id
);
List
<
UserDto
>
getAllUserData
();
/**
* 获取用户 基本数据
*
* @param startNumber 开始编号
* @param endNo 结束编号
* @return 列表
*/
List
<
UserDto
>
getAllUserData
(
@Param
(
"startNo"
)
Integer
startNumber
,
@Param
(
"endNo"
)
Integer
endNo
);
/*************** chenqi****************/
...
...
wisenergy-mapper/src/main/resources/mapper/UserDataMapper.xml
View file @
d910a637
...
...
@@ -15,12 +15,13 @@
<result
column=
"total_people"
property=
"totalPeople"
/>
<result
column=
"buy_total"
property=
"buyTotal"
/>
<result
column=
"sale_total"
property=
"saleTotal"
/>
<result
column=
"receive_addr"
property=
"receiveAddr"
/>
<result
column=
"created_at"
property=
"createdAt"
/>
<result
column=
"updated_at"
property=
"updatedAt"
/>
</resultMap>
<sql
id=
"table"
>
user_dat
e
user_dat
a
</sql>
<sql
id=
"cols_all"
>
...
...
@@ -30,12 +31,12 @@
<sql
id=
"cols_exclude_id"
>
user_id,real_name,id_number,phone,total_recharge,total_withdrawal,rank, bottom,total_people,buy_total,
sale_total,created_at,updated_at
sale_total,
receive_addr,
created_at,updated_at
</sql>
<sql
id=
"vals"
>
#{userId},#{realName},#{idNumber},#{phone},#{totalRecharge},#{totalWithdrawal},#{rank},#{bottom},
#{totalPeople},#{buyTotal},#{saleTotal},now(),now()
#{totalPeople},#{buyTotal},#{saleTotal},
#{receiveAddr},
now(),now()
</sql>
<sql
id=
"updateCondition"
>
...
...
@@ -50,22 +51,24 @@
<if
test=
"totalPeople != null"
>
total_people = #{totalPeople},
</if>
<if
test=
"buyTotal != null"
>
buy_total = #{buyTotal},
</if>
<if
test=
"saleTotal != null"
>
sale_total =#{saleTotal},
</if>
<if
test=
"receiveAddr != null"
>
receive_addr =#{receiveAddr},
</if>
updated_at =now()
</sql>
<sql
id=
"criteria"
>
<if
test=
"id != null"
>
id = #{id}
</if>
<if
test=
"userId != null"
>
and user_id = #{userId},
</if>
<if
test=
"realName != null"
>
and real_name =#{realName},
</if>
<if
test=
"idNumber != null"
>
and id_number =#{idNumber},
</if>
<if
test=
"phone != null"
>
and phone =#{phone},
</if>
<if
test=
"totalRecharge != null"
>
and total_recharge = #{totalRecharge},
</if>
<if
test=
"totalWithdrawal != null"
>
and total_withdrawal =#{totalWithdrawal},
</if>
<if
test=
"rank != null"
>
and rank =#{rank},
</if>
<if
test=
"bottom != null"
>
and bottom =#{bottom},
</if>
<if
test=
"totalPeople != null"
>
and total_people = #{totalPeople},
</if>
<if
test=
"buyTotal != null"
>
and buy_total = #{buyTotal},
</if>
<if
test=
"saleTotal != null"
>
and sale_total =#{saleTotal},
</if>
<if
test=
"userId != null"
>
and user_id = #{userId}
</if>
<if
test=
"realName != null"
>
and real_name =#{realName}
</if>
<if
test=
"idNumber != null"
>
and id_number =#{idNumber}
</if>
<if
test=
"phone != null"
>
and phone =#{phone}
</if>
<if
test=
"totalRecharge != null"
>
and total_recharge = #{totalRecharge}
</if>
<if
test=
"totalWithdrawal != null"
>
and total_withdrawal =#{totalWithdrawal}
</if>
<if
test=
"rank != null"
>
and rank =#{rank}
</if>
<if
test=
"bottom != null"
>
and bottom =#{bottom}
</if>
<if
test=
"totalPeople != null"
>
and total_people = #{totalPeople}
</if>
<if
test=
"buyTotal != null"
>
and buy_total = #{buyTotal}
</if>
<if
test=
"saleTotal != null"
>
and sale_total =#{saleTotal}
</if>
<if
test=
"receiveAddr != null"
>
and receive_addr =#{receiveAddr}
</if>
<if
test=
"createdAt != null"
>
and created_at
>
= #{createdAt}
</if>
<if
test=
"updatedAt != null"
>
and #{updatedAt}
>
= updated_at
</if>
</sql>
...
...
@@ -101,4 +104,8 @@
</where>
</select>
<select
id=
"getMaxId"
resultType=
"java.lang.Long"
>
select user_id from user_data order by user_id desc limit 1
</select>
</mapper>
wisenergy-mapper/src/main/resources/mapper/UserRechargeMapper.xml
View file @
d910a637
...
...
@@ -99,4 +99,8 @@
select sum(amount) from user_recharge where status=1 and user_id=#{userId}
</select>
<select
id=
"getReceiveAddr"
resultType=
"java.lang.String"
>
select receive_addr from user_recharge where status=1 and user_id=#{userId} limit 1
</select>
</mapper>
wisenergy-mapper/src/main/resources/mapper/UsersMapper.xml
View file @
d910a637
...
...
@@ -172,12 +172,13 @@
<select
id=
"getLevelAndTotal"
resultType=
"cn.wisenergy.model.dto.UsersInfoDto"
>
SELECT
MAX(rank) 'bottom',
count(*)-1 'totalPeople'
FROM users
WHERE
FIND_IN_SET(#{userId},path)
SELECT u1.rank,u2.count
FROM
users u1,(select count(*) 'count',max(LENGTH(path)) 'maxrank'
from users
where path like CONCAT((SELECT path FROM users WHERE id=#{userId}), '%')) u2
WHERE path like CONCAT((SELECT path FROM users WHERE id=#{userId}), '%')
and LENGTH(path) = u2.maxrank LIMIT 1
</select>
<select
id=
"getTotal"
resultType=
"java.lang.Integer"
>
...
...
@@ -236,9 +237,10 @@ GROUP BY user_id
</select>
<select
id=
"getAllUserData"
resultType=
"cn.wisenergy.model.dto.UserDto"
>
select id as userId,rank,phone
from
<include
refid=
"table"
/>
select id as userId,rank,phone
from
<include
refid=
"table"
/>
limit #{startNo},#{endNo}
</select>
</mapper>
wisenergy-model/src/main/java/cn/wisenergy/model/app/UserData.java
View file @
d910a637
...
...
@@ -51,6 +51,9 @@ public class UserData {
@ApiModelProperty
(
name
=
"saleTotal"
,
value
=
"otc卖出总额"
)
private
Double
saleTotal
;
@ApiModelProperty
(
name
=
"receiveAddr"
,
value
=
"充币地址"
)
private
String
receiveAddr
;
private
Date
createdAt
;
private
Date
updatedAt
;
...
...
wisenergy-model/src/main/java/cn/wisenergy/model/dto/UsersInfoDto.java
View file @
d910a637
...
...
@@ -6,6 +6,7 @@ import lombok.Data;
import
lombok.experimental.Accessors
;
/**
* @author 86187
* @Authotr:陈奇
* @QQ1799796883
*/
...
...
wisenergy-model/src/main/java/cn/wisenergy/model/vo/UserQueryVo.java
0 → 100644
View file @
d910a637
package
cn
.
wisenergy
.
model
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* @author 86187
*/
@Data
@ApiModel
(
value
=
"UserQueryVo"
)
public
class
UserQueryVo
{
@ApiModelProperty
(
value
=
"要统计的数量"
,
name
=
"number"
)
private
Integer
number
;
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/UserDataService.java
View file @
d910a637
package
cn
.
wisenergy
.
service
.
app
;
import
cn.wisenergy.common.utils.R
;
import
cn.wisenergy.model.vo.UserQueryVo
;
/**
* @author 86187
...
...
@@ -9,8 +10,9 @@ public interface UserDataService {
/**
* 批量添加用户统计数据
*
* @param queryVo 查询参数
* @return true or false
*/
R
<
Boolean
>
addBatch
();
R
<
Boolean
>
addBatch
(
UserQueryVo
queryVo
);
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/UserDataServiceImpl.java
View file @
d910a637
...
...
@@ -4,8 +4,10 @@ import cn.wisenergy.common.utils.R;
import
cn.wisenergy.mapper.*
;
import
cn.wisenergy.model.app.Actives
;
import
cn.wisenergy.model.app.UserData
;
import
cn.wisenergy.model.app.Users
;
import
cn.wisenergy.model.dto.UserDto
;
import
cn.wisenergy.model.dto.UsersInfoDto
;
import
cn.wisenergy.model.vo.UserQueryVo
;
import
cn.wisenergy.service.Manager.UserDataManger
;
import
cn.wisenergy.service.app.UserDataService
;
import
org.apache.shiro.util.CollectionUtils
;
...
...
@@ -38,20 +40,32 @@ public class UserDataServiceImpl implements UserDataService {
@Resource
private
UserDataManger
userDataManger
;
@Resource
private
UserDataMapper
userDataMapper
;
@Override
public
R
<
Boolean
>
addBatch
()
{
public
R
<
Boolean
>
addBatch
(
UserQueryVo
queryVo
)
{
if
(
null
==
queryVo
.
getNumber
()
||
queryVo
.
getNumber
()
==
0
)
{
return
R
.
error
(
"参数不能为空或0!"
);
}
Long
usersId
=
userDataMapper
.
getMaxId
();
if
(
null
==
usersId
)
{
usersId
=
0L
;
}
Integer
startNo
=
Math
.
toIntExact
(
usersId
);
Integer
endNo
=
queryVo
.
getNumber
();
//获取所有用户数据
List
<
UserDto
>
userDtos
=
usersMapper
.
getAllUserData
();
List
<
UserDto
>
userDtos
=
usersMapper
.
getAllUserData
(
startNo
,
endNo
);
if
(
CollectionUtils
.
isEmpty
(
userDtos
))
{
return
R
.
ok
(
1
,
false
);
}
UserData
userData
=
new
UserData
();
List
<
UserData
>
list
=
new
ArrayList
<>();
for
(
UserDto
userDto
:
userDtos
)
{
Long
userId
=
userDto
.
getUserId
();
UserData
userData
=
new
UserData
();
//1、用户基本信息
userData
.
setUserId
(
userDto
.
getUserId
());
...
...
@@ -76,27 +90,25 @@ public class UserDataServiceImpl implements UserDataService {
//4、充值总额
Double
totalRecharge
=
userRechargeMapper
.
getTotalRecharge
(
userId
);
if
(
null
!=
totalRecharge
)
{
userData
.
setTotalRecharge
(
totalRecharge
);
}
userData
.
setTotalRecharge
(
totalRecharge
);
//5、提现总额
Double
totalWithdrawal
=
withdrawsMapper
.
getTotalWithdrawal
(
userId
);
if
(
null
!=
totalWithdrawal
)
{
userData
.
setTotalWithdrawal
(
totalWithdrawal
);
}
userData
.
setTotalWithdrawal
(
totalWithdrawal
);
//6、otc卖出总额
Double
buyTotal
=
orderDetailsMapper
.
getBuyTotal
(
userId
);
if
(
null
!=
buyTotal
)
{
userData
.
setBuyTotal
(
buyTotal
);
}
userData
.
setBuyTotal
(
buyTotal
);
//7、otc买入总额
Double
saleTotal
=
orderDetailsMapper
.
getSaleTotal
(
userId
);
if
(
null
!=
saleTotal
)
{
userData
.
setSaleTotal
(
saleTotal
);
}
userData
.
setSaleTotal
(
saleTotal
);
//8、充币地址
String
receiveAddr
=
userRechargeMapper
.
getReceiveAddr
(
userId
);
userData
.
setReceiveAddr
(
receiveAddr
);
list
.
add
(
userData
);
}
...
...
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/UserDataController.java
View file @
d910a637
package
cn
.
wisenergy
.
web
.
admin
.
controller
.
app
;
import
cn.wisenergy.common.utils.R
;
import
cn.wisenergy.model.vo.UserQueryVo
;
import
cn.wisenergy.service.app.UserDataService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
jdk.nashorn.internal.ir.annotations.Reference
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
...
...
@@ -24,8 +25,9 @@ public class UserDataController {
private
UserDataService
userDataService
;
@ApiOperation
(
value
=
"获取token接口"
,
notes
=
"获取token接口"
,
httpMethod
=
"POST"
)
@ApiImplicitParam
(
name
=
"queryVo"
,
value
=
"每次统计条数"
,
dataType
=
"UserQueryVo"
)
@PostMapping
(
value
=
"/user/saveBatchUserData"
)
public
R
<
Boolean
>
saveBatchUserData
()
{
return
userDataService
.
addBatch
();
public
R
<
Boolean
>
saveBatchUserData
(
@RequestBody
UserQueryVo
queryVo
)
{
return
userDataService
.
addBatch
(
queryVo
);
}
}
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