diff --git a/src/main/java/club/joylink/rtss/controller/DataHandleController.java b/src/main/java/club/joylink/rtss/controller/DataHandleController.java index 49feab88a..44ae5e6b0 100644 --- a/src/main/java/club/joylink/rtss/controller/DataHandleController.java +++ b/src/main/java/club/joylink/rtss/controller/DataHandleController.java @@ -57,7 +57,7 @@ public class DataHandleController { msgList.addAll(paperCompositionController.oldDataHandle()); - userController.sync(response); + msgList.addAll(userController.sync()); return msgList; } diff --git a/src/main/java/club/joylink/rtss/controller/user/UserController.java b/src/main/java/club/joylink/rtss/controller/user/UserController.java index a91e45f3a..4cbeb760c 100644 --- a/src/main/java/club/joylink/rtss/controller/user/UserController.java +++ b/src/main/java/club/joylink/rtss/controller/user/UserController.java @@ -17,6 +17,7 @@ import club.joylink.rtss.vo.client.user.WeChatBindStatusVO; import club.joylink.rtss.vo.user.AccountCreateVO; import club.joylink.rtss.vo.user.CreateAccountCheck; import club.joylink.rtss.vo.user.UserGenerateConfigVO; +import com.google.common.collect.Lists; import org.apache.tomcat.util.http.fileupload.FileUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; @@ -65,31 +66,11 @@ public class UserController { } @Role({RoleEnum.SuperAdmin, RoleEnum.Admin}) @GetMapping(path = "sync") - public String sync( HttpServletResponse response){ + public List sync(){ if(!this.syncService.initData()){ - return "正在同步。。。"; + throw new RuntimeException("正在同步。。。"); } - File file = this.syncService.sync(); - if(Objects.isNull(file) || !file.exists()){ - return "未找到统计的同步文件"; - } - response.reset(); - response.setContentType("application/octet-stream"); - response.setCharacterEncoding("utf-8"); - response.setContentLength((int) file.length()); - response.setHeader("Content-Disposition", "attachment;filename=" + file.getName()); - try(BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))) { - byte[] buff = new byte[1024]; - OutputStream os = response.getOutputStream(); - int i = 0; - while ((i = bis.read(buff)) != -1) { - os.write(buff, 0, i); - os.flush(); - } - } catch (IOException e) { - return "文件下载失败"; - } - return ""; + return this.syncService.sync(); } /** *分页获取用户数据 diff --git a/src/main/java/club/joylink/rtss/services/permission/OldPermissionDataSyncService.java b/src/main/java/club/joylink/rtss/services/permission/OldPermissionDataSyncService.java index d5d1c7e1f..4183469dc 100644 --- a/src/main/java/club/joylink/rtss/services/permission/OldPermissionDataSyncService.java +++ b/src/main/java/club/joylink/rtss/services/permission/OldPermissionDataSyncService.java @@ -114,7 +114,7 @@ public class OldPermissionDataSyncService { } @Transactional(rollbackFor = Exception.class) - public File sync(){ + public List sync(){ try{ List userPermissionList = findUserPermissionData(); Map> funMapIdMap = this.findSystemAbilityGroupMapId(); @@ -124,8 +124,8 @@ public class OldPermissionDataSyncService { insertPermission(syncVOList); insertDistribute(distributeDataVOList); insertUserPermission(psList); - File file = outErrorMsg(); - return file; + return SYNC_RESULT_LIST.stream().map(d ->d.toString()).collect(Collectors.toList()); + }catch (Exception e){ log.error("用户权限同步失败 msg:" + e.getMessage(),e); throw e; @@ -150,25 +150,29 @@ public class OldPermissionDataSyncService { return newList; } - private File outErrorMsg(){ - - BufferedWriter bw = null; - try{ - File file = File.createTempFile("error",".txt"); - bw = new BufferedWriter(new FileWriter(file)); - bw.write("------------------------------\n"); -// bw.write("创建子系统错误【下架】的数据\n"); +/* private String getErrorMsg(){ + StringBuilder sb = new StringBuilder("------------------------------\n"); + // bw.write("创建子系统错误【下架】的数据\n"); // bw.write(Joiner.on(",").join(xiajiaList)); // bw.write("\n\n"); // bw.write("------------------------------\n"); // bw.write("创建子系统正常【创建失败】的数据\n"); // bw.write(Joiner.on(",").join(zhengchangList)); // bw.write("\n\n\n\n"); - bw.write("------------------------------\n"); - for (ErrorMsgVO errorMsgVO : SYNC_RESULT_LIST) { - bw.write(errorMsgVO.toString()); - bw.write("\n"); - } + sb.append("------------------------------\n"); + for (ErrorMsgVO errorMsgVO : SYNC_RESULT_LIST) { + sb.append(errorMsgVO.toString()); + sb.append("\n"); + } + return sb.toString(); + }*/ + /*private File outErrorMsg(){ + + BufferedWriter bw = null; + try{ + File file = File.createTempFile("error",".txt"); + bw = new BufferedWriter(new FileWriter(file)); + bw.write(this.getErrorMsg()); return file; }catch(Exception e){ log.error("权限同步统计失败 msg:{}",e.getMessage(),e); @@ -182,8 +186,7 @@ public class OldPermissionDataSyncService { } } } - - } + }*/ private void insertPermission(List syncVOList){ Set existPermissSet = Sets.newHashSet(); diff --git a/src/test/java/club/joylink/rtss/services/permission/SyncServiceTest.java b/src/test/java/club/joylink/rtss/services/permission/SyncServiceTest.java index c82c49d67..3e23552d7 100644 --- a/src/test/java/club/joylink/rtss/services/permission/SyncServiceTest.java +++ b/src/test/java/club/joylink/rtss/services/permission/SyncServiceTest.java @@ -15,12 +15,7 @@ public class SyncServiceTest { @Test public void sync(){ this.syncService.initData(); - File file = this.syncService.sync(); - if(Objects.isNull(file)){ + this.syncService.sync(); - }else{ - System.out.println(file.getPath()); - - } } }