Browse Source

update UserAccountTest#create

reghao 8 tháng trước cách đây
mục cha
commit
8c1f3e2355

+ 6 - 0
account/account-service/src/main/java/cn/reghao/tnb/account/app/db/mapper/UserAccountMapper.java

@@ -23,6 +23,10 @@ public interface UserAccountMapper extends BaseMapper<UserAccount> {
     void updateSetPassword(@Param("userId") long userId,
                            @Param("encodedPassword") String encodedPassword,
                            @Param("salt") String salt);
+    @Deprecated
+    void updateUserProfile(@Param("userId") long userId,
+                           @Param("username") String username,
+                           @Param("screenName") String screenName);
     void updateUserScreenName(@Param("userId") long userId, @Param("screenName") String screenName);
     void updateUserAvatar(@Param("userId") long userId, @Param("avatarUrl") String avatarUrl);
 
@@ -47,4 +51,6 @@ public interface UserAccountMapper extends BaseMapper<UserAccount> {
     UserAccount findByScreenName(String screenName);
     List<AccountInfo> findScreenNameByPage(Page page, String screenName);
     List<AccountInfo> findAccountInfoByPage(Page page);
+    @Deprecated
+    List<UserAccount> findNotUsedAccount(int size);
 }

+ 12 - 0
account/account-service/src/main/resources/mapper/UserAccountMapper.xml

@@ -31,6 +31,11 @@
         update user_account set encoded_password=#{encodedPassword},salt=#{salt}
         where user_id=#{userId}
     </update>
+    <update id="updateUserProfile">
+        update user_account
+        set update_time=now(),username=#{username},screen_name=#{screenName}
+        where user_id=#{userId}
+    </update>
     <update id="updateUserScreenName">
         update user_account
         set update_time=now(),screen_name=#{screenName}
@@ -166,4 +171,11 @@
         select user_id,screen_name,avatar_url,username,mobile,email
         from user_account
     </select>
+    <select id="findNotUsedAccount" resultType="cn.reghao.tnb.account.app.model.po.UserAccount">
+        select *
+        from user_account
+        where user_id > 10100 and user_id &lt;= 18000 and screen_name like 'tnb\_%'
+        order by user_id asc
+        limit #{size}
+    </select>
 </mapper>

+ 28 - 32
account/account-service/src/test/java/UserAccountTest.java

@@ -6,16 +6,13 @@ import cn.reghao.tnb.account.app.model.po.UserAccount;
 import cn.reghao.tnb.account.app.service.AccountRegistryService;
 import cn.reghao.tnb.account.app.service.OAuthAppService;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.FileUtils;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
 
 import java.io.File;
-import java.io.IOException;
 import java.util.List;
 
 /**
@@ -57,43 +54,42 @@ public class UserAccountTest {
         }
     }
 
+    /**
+     * 本地发布视频稿件时使用已创建但未使用的帐号
+     *
+     * @param
+     * @return
+     * @date 2025-07-05 23:07:787
+     */
     @Test
     public void create() {
-        List<UserAccount> list = userAccountMapper.findAll();
-
-        String basePath = "";
+        String basePath = "/home/reghao/disk/1/vod/1/12.个人/";
         File baseDir = new File(basePath);
-        File[] files = baseDir.listFiles();
-        for (int i = 0; i < files.length; i++) {
-            File srcDir = files[i];
-            String dirName = srcDir.getName();
+        int len = baseDir.listFiles().length;
 
-            UserAccount userAccount = list.get(i);
-            long userId = userAccount.getUserId();
-            //String screenName = dirName;
-            String namePrefix = "";
-            String screenName = String.format("%s%s", namePrefix, userId);
+        List<UserAccount> list = userAccountMapper.findNotUsedAccount(len);
+        if (list.size() != len) {
+            return;
+        }
 
-            String dirName1 = String.format("%s.%s", userId, screenName);
-            String destPath = String.format("%s/%s", srcDir.getParent(), dirName1);
-            File destDir = new File(destPath);
+        File[] subDirs = baseDir.listFiles();
+        for (int i = 0; i < len; i++) {
+            long userId = list.get(i).getUserId();
+            File subDir = subDirs[i];
 
-            try {
-                renameDir(srcDir, destDir);
-                userAccountMapper.updateUserScreenName(userId, screenName);
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-    }
+            /*String filename = subDir.getName();
+            UserAccount userAccount = userAccountMapper.findByUserId(userId);
+            String username = userAccount.getUsername();
+            String username1 = username.replace("_", "");
+            String screenName = filename;
+            userAccountMapper.updateUserProfile(userId, username1, screenName);
 
-    private boolean renameDir(File srcDir, File destDir) throws IOException {
-        if (srcDir.exists() && !destDir.exists()) {
-            FileUtils.moveDirectory(srcDir, destDir);
-            return true;
+            String password = "ecUgpUeIX2ub84EYPsiQ";
+            String salt = RandomString.getSalt(64);
+            String encodedPassword = passwordEncoder.encode(password + salt);
+            userAccountMapper.updateSetPassword(userId, encodedPassword, salt);*/
+            userId++;
         }
-
-        return false;
     }
 
     @Autowired