Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
shop-Mall
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
shop-Mall
Commits
3ced1dd8
Commit
3ced1dd8
authored
Mar 08, 2021
by
licc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
账户表镜像实现
parent
3a0b4d5f
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
1 deletion
+99
-1
LastAccountMapper.java
.../src/main/java/cn/wisenergy/mapper/LastAccountMapper.java
+23
-1
LastAccountMapper.xml
...gy-mapper/src/main/resources/mapper/LastAccountMapper.xml
+14
-0
AccountService.java
...rc/main/java/cn/wisenergy/service/app/AccountService.java
+5
-0
AccountServiceImpl.java
...ava/cn/wisenergy/service/app/impl/AccountServiceImpl.java
+27
-0
LastAccountController.java
...nergy/web/admin/controller/app/LastAccountController.java
+30
-0
No files found.
wisenergy-mapper/src/main/java/cn/wisenergy/mapper/LastAccountMapper.java
View file @
3ced1dd8
package
cn
.
wisenergy
.
mapper
;
import
cn.wisenergy.model.app.AccountInfo
;
import
cn.wisenergy.model.app.LastMonthAccount
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Param
;
...
...
@@ -15,4 +14,27 @@ public interface LastAccountMapper extends BaseMapper<LastMonthAccount> {
* @return 账户信息
*/
LastMonthAccount
getByUserIdAndTime
(
@Param
(
"userId"
)
String
userId
,
@Param
(
"yearMonth"
)
String
yearMonth
);
/**
* 把 A 表的结构数据 复制给 B表
*
* @param oldTable A
* @param newTable B
*/
void
copyTable
(
@Param
(
"oldTable"
)
String
oldTable
,
@Param
(
"newTable"
)
String
newTable
);
/**
* 删除表
*
* @param tableName 表名
*/
void
deleteTable
(
@Param
(
"tableName"
)
String
tableName
);
/**
* 更新表名
*
* @param oldTableName 旧表名
* @param newTableName 新表名
*/
void
updateTableName
(
@Param
(
"oldTableName"
)
String
oldTableName
,
@Param
(
"newTableName"
)
String
newTableName
);
}
wisenergy-mapper/src/main/resources/mapper/LastAccountMapper.xml
View file @
3ced1dd8
...
...
@@ -56,6 +56,10 @@
<if
test=
"updateTime != null"
>
and #{updateTime}
>
= update_time
</if>
</sql>
<delete
id=
"deleteTable"
>
drop table ${tableName}
</delete>
<select
id=
"getByUserIdAndTime"
resultType=
"cn.wisenergy.model.app.LastMonthAccount"
>
select
...
...
@@ -68,4 +72,14 @@
</where>
</select>
<update
id=
"copyTable"
>
CREATE TABLE ${newTable} SELECT * FROM ${oldTable};
</update>
<update
id=
"updateTableName"
>
rename table ${oldTableName} to ${newTableName};
</update>
</mapper>
\ No newline at end of file
wisenergy-service/src/main/java/cn/wisenergy/service/app/AccountService.java
View file @
3ced1dd8
...
...
@@ -52,4 +52,9 @@ public interface AccountService {
* @return true or false
*/
R
<
Boolean
>
progressPrizeCount
();
/**
* 账户表镜像---每月更新一次,保存上一个的数据
*/
void
mirrorImage
();
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/AccountServiceImpl.java
View file @
3ced1dd8
...
...
@@ -55,6 +55,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
@Autowired
private
ProgressPrizeMapper
progressPrizeMapper
;
@Autowired
private
LastAccountMapper
lastAccountMapper
;
private
static
final
String
PATTERN
=
"yyyy-MM"
;
private
static
final
Integer
TWENTY
=
20
;
...
...
@@ -282,6 +285,30 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
return
R
.
ok
(
0
,
true
);
}
@Override
public
void
mirrorImage
()
{
//1、把账户表account_info复制给表account_image CREATE TABLE table_2 SELECT * FROM table_1;
lastAccountMapper
.
copyTable
(
"account_info"
,
"account_image"
);
//删除上月备份
lastAccountMapper
.
deleteTable
(
"account_backup"
);
//备份
lastAccountMapper
.
copyTable
(
"account_info"
,
"account_backup"
);
//2、把上月账户表last_month_account 复制给month_account_image
lastAccountMapper
.
copyTable
(
"last_month_account"
,
"month_account_image"
);
//3、删除last_month_account
lastAccountMapper
.
deleteTable
(
"last_month_account"
);
//4、把account_image 更名为 last_month_account rename table table_2 to table_1;
lastAccountMapper
.
updateTableName
(
"account_image"
,
"last_month_account"
);
//5、删除month_account_image DROP table table_2;
lastAccountMapper
.
deleteTable
(
"month_account_image"
);
}
public
void
getUser
(
List
<
User
>
list
,
String
userId
)
{
User
user
=
usersMapper
.
getByUserId
(
userId
);
list
.
add
(
user
);
...
...
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/LastAccountController.java
0 → 100644
View file @
3ced1dd8
package
cn
.
wisenergy
.
web
.
admin
.
controller
.
app
;
import
cn.wisenergy.service.app.AccountService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PutMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @author 86187
*/
@Api
(
tags
=
"表镜像管理"
)
@RestController
@RequestMapping
(
"/image"
)
@Slf4j
public
class
LastAccountController
{
@Autowired
private
AccountService
accountService
;
@ApiOperation
(
value
=
"复制表-结构和数据"
,
notes
=
"复制表-结构和数据"
,
httpMethod
=
"PUT"
)
@PutMapping
(
"/add"
)
public
void
copyTable
(){
accountService
.
mirrorImage
();
}
}
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