From 3ced1dd8f97aa1628d5ff19bb43add39dc4cb318 Mon Sep 17 00:00:00 2001 From: licc <lichuchuan@jtep.com.cn> Date: Mon, 8 Mar 2021 15:42:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A6=E6=88=B7=E8=A1=A8=E9=95=9C=E5=83=8F?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wisenergy/mapper/LastAccountMapper.java | 24 ++++++++++++++- .../resources/mapper/LastAccountMapper.xml | 14 +++++++++ .../wisenergy/service/app/AccountService.java | 5 ++++ .../service/app/impl/AccountServiceImpl.java | 27 +++++++++++++++++ .../controller/app/LastAccountController.java | 30 +++++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/LastAccountController.java diff --git a/wisenergy-mapper/src/main/java/cn/wisenergy/mapper/LastAccountMapper.java b/wisenergy-mapper/src/main/java/cn/wisenergy/mapper/LastAccountMapper.java index ebc0780..32dcda0 100644 --- a/wisenergy-mapper/src/main/java/cn/wisenergy/mapper/LastAccountMapper.java +++ b/wisenergy-mapper/src/main/java/cn/wisenergy/mapper/LastAccountMapper.java @@ -1,6 +1,5 @@ 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); } diff --git a/wisenergy-mapper/src/main/resources/mapper/LastAccountMapper.xml b/wisenergy-mapper/src/main/resources/mapper/LastAccountMapper.xml index 2041c23..e01b71b 100644 --- a/wisenergy-mapper/src/main/resources/mapper/LastAccountMapper.xml +++ b/wisenergy-mapper/src/main/resources/mapper/LastAccountMapper.xml @@ -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 diff --git a/wisenergy-service/src/main/java/cn/wisenergy/service/app/AccountService.java b/wisenergy-service/src/main/java/cn/wisenergy/service/app/AccountService.java index d7cbf27..f4f5243 100644 --- a/wisenergy-service/src/main/java/cn/wisenergy/service/app/AccountService.java +++ b/wisenergy-service/src/main/java/cn/wisenergy/service/app/AccountService.java @@ -52,4 +52,9 @@ public interface AccountService { * @return true or false */ R<Boolean> progressPrizeCount(); + + /** + * 账户表镜åƒ---æ¯æœˆæ›´æ–°ä¸€æ¬¡ï¼Œä¿å˜ä¸Šä¸€ä¸ªçš„æ•°æ® + */ + void mirrorImage(); } diff --git a/wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/AccountServiceImpl.java b/wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/AccountServiceImpl.java index 5c40ff9..740487d 100644 --- a/wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/AccountServiceImpl.java +++ b/wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/AccountServiceImpl.java @@ -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); diff --git a/wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/LastAccountController.java b/wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/LastAccountController.java new file mode 100644 index 0000000..0b9f53e --- /dev/null +++ b/wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/LastAccountController.java @@ -0,0 +1,30 @@ +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(); + } +} -- 2.18.1