From 5ea0f32f3d7fb6982558cc03bd027bb345215e35 Mon Sep 17 00:00:00 2001 From: xhxu Date: Fri, 21 Aug 2020 13:13:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mem/WxCUserBasicInfoController.java | 25 ++++++++++++ .../V202007311200__FOR_MEMBER_ONLY_001.sql | 40 ++++++++++++++++++- .../mapper/WxCUserBasicInfoMapper.java | 1 + .../mapper/WxProjectConfigMapper.java | 2 +- .../service/WxCUserBasicInfoService.java | 2 + .../impl/WxCUserBasicInfoServiceImpl.java | 8 +++- .../mapper/WxCUserBasicInfoMapper.xml | 4 ++ 7 files changed, 78 insertions(+), 4 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/mem/WxCUserBasicInfoController.java b/mallinkAdmin/src/main/java/com/iformall/controller/mem/WxCUserBasicInfoController.java index aa55a6aa4..8af83d537 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/mem/WxCUserBasicInfoController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/mem/WxCUserBasicInfoController.java @@ -566,4 +566,29 @@ public class WxCUserBasicInfoController extends BaseController { return wxCUserBasicInfoService.updateStatus(wxCUserBasicInfo); } + @ApiOperation("根据手机号迁移") + @PostMapping("/cuserOldToNew") + @SystemControllerLog(description = "会员管理-迁移数据") + public ResultData cuserOldToNew(@RequestBody Map map) { + logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::cuserOldToNew"); + String oldCuserPhone = (String) map.get("oldCuserPhone"); + String newCuserPhone = (String) map.get("newCuserPhone"); + if(StringUtils.isNotBlank(oldCuserPhone) && StringUtils.isNotBlank(newCuserPhone)){ + WxCUserBasicInfo oldCuser = wxCUserBasicInfoService.findInfoByPhone(ifParentUpdateTenantInfo(), oldCuserPhone); + WxCUserBasicInfo newCuser = wxCUserBasicInfoService.findInfoByPhone(ifParentUpdateTenantInfo(), newCuserPhone); + if(null != oldCuser && null != newCuser){ + if(!oldCuserPhone.equals(newCuserPhone)){ + wxCUserBasicInfoService.cuserOldToNew(oldCuser.getId(),newCuser.getId()); + return new ResultData(); + }else{ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"同一个用户"); + } + }else{ + return new ResultData(ErrorCode.USER_IS_EMPTY); + } + }else{ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + } + } \ No newline at end of file diff --git a/mallinkAdmin/src/main/resources/db/migration/V202007311200__FOR_MEMBER_ONLY_001.sql b/mallinkAdmin/src/main/resources/db/migration/V202007311200__FOR_MEMBER_ONLY_001.sql index f9616631a..a8b841c4b 100644 --- a/mallinkAdmin/src/main/resources/db/migration/V202007311200__FOR_MEMBER_ONLY_001.sql +++ b/mallinkAdmin/src/main/resources/db/migration/V202007311200__FOR_MEMBER_ONLY_001.sql @@ -10,8 +10,7 @@ ADD COLUMN `final_tenant_id` varchar(5) NOT NULL COMMENT '归属租户ID' AFTER update wx_c_user_basic_info set final_tenant_id = parent_tenant_id; update wx_c_user_basic_info set final_tenant_id = tenant_id where (parent_tenant_id is null or trim(parent_tenant_id) = ""); -DROP INDEX `PHONE_UNIQUE`, -ADD UNIQUE INDEX `PHONE_UNIQUE`(`final_tenant_id`, `phone`) USING BTREE; +ALTER TABLE wx_c_user_basic_info ADD UNIQUE INDEX `PHONE_UNIQUE`(`final_tenant_id`, `phone`) USING BTREE; ALTER TABLE `wx_c_user_basic_info` @@ -69,5 +68,42 @@ ADD COLUMN `from_id` BIGINT(20) DEFAULT NULL COMMENT '来源ID,针对续签, 合同状态为4(即将到期)更新为计租中,合同状态为8(补录),9(续签)更新为草稿。 +CREATE DEFINER=`root`@`%` PROCEDURE `cuser_old_to_new`(IN `oldCuserId` bigint,IN `newCuserId` bigint) +BEGIN + DECLARE err_flag INT DEFAULT FALSE; + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET err_flag = TRUE; + + UPDATE wx_c_user SET user_id = newCuserId WHERE user_id = oldCuserId ; + UPDATE wx_activity_join SET user_id = newCuserId WHERE user_id = oldCuserId ; + UPDATE wx_c_user_tags SET user_id = newCuserId WHERE user_id = oldCuserId ; + UPDATE wx_game_action_log SET user_id = newCuserId WHERE user_id = oldCuserId ; + UPDATE wx_order_group SET user_id = newCuserId WHERE user_id = oldCuserId ; + UPDATE wx_order_press SET user_id = newCuserId WHERE user_id = oldCuserId ; + UPDATE wx_question_log SET user_id = newCuserId WHERE user_id = oldCuserId ; + + UPDATE wx_c_user_car SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; + UPDATE wx_c_user_from_b SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; + UPDATE wx_coupon_order SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; + UPDATE wx_credit_history SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; + UPDATE wx_order SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; + UPDATE wx_pay_order SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; + UPDATE wx_refund_order SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; + UPDATE wx_score_history SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; + + UPDATE wx_card_spend SET owner_id = newCuserId WHERE owner_id = oldCuserId ; + UPDATE wx_coupon_order SET owner_id = newCuserId WHERE owner_id = oldCuserId ; + + UPDATE wx_credit_history SET operator_id = newCuserId WHERE operator_type in (1,2) and operator_id = oldCuserId ; + + UPDATE wx_c_user_basic_info SET phone = phone + '(作废)',`status` = 1 WHERE id = oldCuserId ; + + IF err_flag THEN + ROLLBACK; + ELSE + COMMIT; + END IF; +END + + diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCUserBasicInfoMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCUserBasicInfoMapper.java index ed2546897..33a8d5968 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxCUserBasicInfoMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCUserBasicInfoMapper.java @@ -73,6 +73,7 @@ public interface WxCUserBasicInfoMapper extends CommonMapper selectNotCUserList(); + void cuserOldToNew(@Param(value = "oldCuserId")Long oldCuserId, @Param(value = "newCuserId")Long newCuserId); } diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxProjectConfigMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxProjectConfigMapper.java index 12113664c..5bce69db0 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxProjectConfigMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxProjectConfigMapper.java @@ -7,6 +7,6 @@ import org.apache.ibatis.annotations.Param; public interface WxProjectConfigMapper extends BaseMapper { - void initAfterGroup(@Param(value = "tenantId")String tenantId, @Param(value = "subTenantIds")String subTenantIds); + } diff --git a/mallinkService/src/main/java/com/iformall/service/WxCUserBasicInfoService.java b/mallinkService/src/main/java/com/iformall/service/WxCUserBasicInfoService.java index 363637141..8487ffa49 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCUserBasicInfoService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCUserBasicInfoService.java @@ -168,5 +168,7 @@ public interface WxCUserBasicInfoService { List findListByScore(TenantEntity tenantEntity, WxCUserBasicInfoDto wxCUserBasicInfoDto); List findBirthdayList(TenantEntity tenantEntity, String format, String format1); + + void cuserOldToNew(Long oldCuserId, Long newCuserId); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java index b6bcc33ba..e9c0adf74 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserBasicInfoServiceImpl.java @@ -1207,7 +1207,13 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService,IExc return wxCUserBasicInfoMapper.findBirthdayList(finalTenantId,format,format1); } } - @Override + + @Override + public void cuserOldToNew(Long oldCuserId, Long newCuserId) { + wxCUserBasicInfoMapper.cuserOldToNew(oldCuserId,newCuserId); + } + + @Override public List selectListForExcelExport(Object queryParams, int page) { Map params = (Map) queryParams; WxCUserBasicInfo basicInfo = (WxCUserBasicInfo) params.get("basicInfo"); diff --git a/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml b/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml index bf3d5af65..2fc1d8abd 100644 --- a/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml @@ -1065,4 +1065,8 @@ + + + {call cuser_old_to_new(#{oldCuserId},#{newCuserId})} + \ No newline at end of file