Commit 3ced1dd8 authored by licc's avatar licc

账户表镜像实现

parent 3a0b4d5f
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);
}
......@@ -56,6 +56,10 @@
<if test="updateTime != null">and #{updateTime} &gt;= 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
......@@ -52,4 +52,9 @@ public interface AccountService {
* @return true or false
*/
R<Boolean> progressPrizeCount();
/**
* 账户表镜像---每月更新一次,保存上一个的数据
*/
void mirrorImage();
}
......@@ -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);
......
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();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment