zoujiajian преди 3 години
родител
ревизия
0eb075161b

+ 1 - 1
netflix-dao/src/main/resources/mapper/UserTransferLogMapper.xml

@@ -4,7 +4,7 @@
 
 
     <insert id="batchInsert">
-        insert into user_transfer_log(`old_appid`,`new_appid`,`user_id`,`old_unionid`,`new_unionid`,`type`,`created_time`,`update_time`)
+        insert into user_transfer_log(`old_app_id`,`new_app_id`,`user_id`,`old_unionid`,`new_unionid`,`type`,`created_time`,`update_time`)
         values
         <foreach collection="list" item="item" separator=",">
             (#{item.oldAppId},#{item.newAppId},#{item.userId},#{item.oldUnionid},#{item.newUnionid},#{item.type},now(),now())

+ 23 - 13
netflix-web/src/main/java/com/cyksj/web/controller/user/UserController.java

@@ -128,12 +128,18 @@ public class UserController {
 	 * 获取微信用户信息, 迁移后通过openid同步用户unionid
 	 */
 	@GetMapping("/get/wx/user")
-	public void syncUser() {
+	public void syncUser() throws Exception {
 		String oldAppId = weChatConfig.getOldAppid();
 		String newAppId = weChatConfig.getAppid();
 		LambdaQueryWrapper<WxSyncLog> wrapper = Wrappers.lambdaQuery(WxSyncLog.class)
 				.ne(WxSyncLog::getNewOpenid, "")
-				.in(WxSyncLog ::getUserId,List.of(9909,11201))
+				.in(WxSyncLog ::getUserId,List.of(6657,
+						7235,
+						1727,
+						31262,
+						17398,
+						14063,
+						9909))
 				.orderByAsc(WxSyncLog::getId);
 		Integer limit = 12000;
 		Integer count = wxSyncLogMapper.selectCount(wrapper);
@@ -143,9 +149,9 @@ public class UserController {
 			Page<WxSyncLog> wxSyncLogs = wxSyncLogMapper.selectPage(new Page<>(start, limit),wrapper);
 			List<WxSyncLog> records = wxSyncLogs.getRecords();
 			List<UserTransferLog> userTransferLogs = new ArrayList<>(records.size());
+			String accessToken = weChatService.getAccessToken();
 			records.forEach(syncUser -> {
 				try {
-					String accessToken = weChatService.getAccessToken();
 					String oriOpenid = syncUser.getOriOpenid();
 					String newOpenId = syncUser.getNewOpenid();
 					GzhUnionidUserinfo userInfo2 = weChatService.getUserInfo2(accessToken, newOpenId);
@@ -181,16 +187,20 @@ public class UserController {
 						if (StrUtil.isNotEmpty(userInfo2.getUnionid())) {
 							user.setUnionid(userInfo2.getUnionid());
 						}
-//						userService.updateById(user);
-
-						UserTransferLog log = new UserTransferLog();
-						log.setOldAppId(oldAppId);
-						log.setNewAppId(newAppId);
-						log.setUserId(user.getId());
-						log.setOldUnionid(unionid);
-						log.setType("手动同步");
-						log.setNewUnionid(userInfo2.getUnionid());
-						userTransferLogs.add(log);
+						userService.updateById(user);
+						UserTransferLog userTransferLog = userTransferLogMapper.selectOne(Wrappers.lambdaQuery(UserTransferLog.class)
+								.eq(UserTransferLog::getOldAppId, oldAppId)
+								.eq(UserTransferLog::getUserId, user.getId()).last("limit 1"));
+						if (userTransferLog == null) {
+							UserTransferLog log = new UserTransferLog();
+							log.setOldAppId(oldAppId);
+							log.setNewAppId(newAppId);
+							log.setUserId(user.getId());
+							log.setOldUnionid(unionid);
+							log.setType("手动同步");
+							log.setNewUnionid(userInfo2.getUnionid());
+							userTransferLogs.add(log);
+						}
 					}
 				} catch (Exception e) {
 					System.out.println("获取accesstoken错误");