|  | @@ -1,5 +1,6 @@
 | 
	
		
			
				|  |  |  package com.ym.mec.web.controller;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.google.common.collect.Lists;
 | 
	
		
			
				|  |  |  import com.yonge.log.wrapper.HistoryMessageTencentWrapper;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.ImGroupService;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.UploadFileService;
 | 
	
	
		
			
				|  | @@ -20,6 +21,8 @@ import org.springframework.web.bind.annotation.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.io.File;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.concurrent.ExecutorService;
 | 
	
		
			
				|  |  | +import java.util.concurrent.Executors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @RequestMapping("${app-config.url.web:}/imHistoryMessage")
 | 
	
		
			
				|  |  |  @Api(tags = "系统操作日志")
 | 
	
	
		
			
				|  | @@ -27,93 +30,114 @@ import java.util.List;
 | 
	
		
			
				|  |  |  @RestController
 | 
	
		
			
				|  |  |  public class ImHistoryMessageController extends BaseController {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	@Autowired
 | 
	
		
			
				|  |  | -	private HistoryMessageService historyMessageService;
 | 
	
		
			
				|  |  | -	@Autowired
 | 
	
		
			
				|  |  | -	private UploadFileService uploadFileService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private HistoryMessageService historyMessageService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private UploadFileService uploadFileService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	@Autowired
 | 
	
		
			
				|  |  | -	private ImGroupService imGroupService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private ImGroupService imGroupService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private HistoryMessageTenantService historyMessageTenantService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	@GetMapping("/save")
 | 
	
		
			
				|  |  | -	public Object saveImHistoryMessage(String fileDir) throws Exception {
 | 
	
		
			
				|  |  | -		File file = new File(fileDir);
 | 
	
		
			
				|  |  | -		UploadReturnBean uploadReturnBean = uploadFileService.uploadImHistoryMsgFile(file);
 | 
	
		
			
				|  |  | -		historyMessageService.saveImHistoryMessage(file);
 | 
	
		
			
				|  |  | -		return succeed();
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | +    @GetMapping("/save")
 | 
	
		
			
				|  |  | +    public Object saveImHistoryMessage(String fileDir) throws Exception {
 | 
	
		
			
				|  |  | +        File file = new File(fileDir);
 | 
	
		
			
				|  |  | +        UploadReturnBean uploadReturnBean = uploadFileService.uploadImHistoryMsgFile(file);
 | 
	
		
			
				|  |  | +        historyMessageService.saveImHistoryMessage(file);
 | 
	
		
			
				|  |  | +        return succeed();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @ApiOperation("IM导入消息")
 | 
	
		
			
				|  |  | +    @PostMapping(value = "/ImportIM")
 | 
	
		
			
				|  |  | +    public void ImportIM() {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	@ApiOperation("IM导入消息")
 | 
	
		
			
				|  |  | -	@PostMapping(value = "/ImportIM")
 | 
	
		
			
				|  |  | -	public void ImportIM() throws Exception {
 | 
	
		
			
				|  |  | -		com.yonge.mongodb.PageInfo<HistoryMessage> info;
 | 
	
		
			
				|  |  | +        ExecutorService executor = Executors.newSingleThreadExecutor();
 | 
	
		
			
				|  |  | +        executor.execute(() -> {
 | 
	
		
			
				|  |  | +            com.yonge.mongodb.PageInfo<HistoryMessage> info;
 | 
	
		
			
				|  |  |  //        historyMessageService.updateAllStatus(0);
 | 
	
		
			
				|  |  | -		//计算总数据量
 | 
	
		
			
				|  |  | -		int count = imGroupService.queryInfoCount();
 | 
	
		
			
				|  |  | -		//计算调用次数
 | 
	
		
			
				|  |  | -		int num = (int) Math.ceil(count / 100);
 | 
	
		
			
				|  |  | -		for (int i = 0; i <=num ; i++) {
 | 
	
		
			
				|  |  | -			int size =100;
 | 
	
		
			
				|  |  | -			//获取融云消息
 | 
	
		
			
				|  |  | -			//List<ImGroup> list = imGroupService.lambdaQuery().last("limit "+(page-1)*size+","+size).list();
 | 
	
		
			
				|  |  | -			info = imGroupService.getRongYunInfo(1,size);
 | 
	
		
			
				|  |  | -			List<HistoryMessage> footer = info.getRows();
 | 
	
		
			
				|  |  | -            if (CollectionUtils.isEmpty(footer)) {
 | 
	
		
			
				|  |  | -                break;
 | 
	
		
			
				|  |  | +            //计算总数据量
 | 
	
		
			
				|  |  | +            int count = imGroupService.queryInfoCount();
 | 
	
		
			
				|  |  | +            //计算调用次数
 | 
	
		
			
				|  |  | +            int num = (int) Math.ceil(count / 100);
 | 
	
		
			
				|  |  | +            for (int i = 0; i <= num; i++) {
 | 
	
		
			
				|  |  | +                int size = 100;
 | 
	
		
			
				|  |  | +                //获取融云消息
 | 
	
		
			
				|  |  | +                //List<ImGroup> list = imGroupService.lambdaQuery().last("limit "+(page-1)*size+","+size).list();
 | 
	
		
			
				|  |  | +                info = imGroupService.getRongYunInfo(1, size);
 | 
	
		
			
				|  |  | +                List<HistoryMessage> footer = info.getRows();
 | 
	
		
			
				|  |  | +                if (CollectionUtils.isEmpty(footer)) {
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                //IM导入
 | 
	
		
			
				|  |  | +                try {
 | 
	
		
			
				|  |  | +                    imGroupService.importInfo(footer);
 | 
	
		
			
				|  |  | +                } catch (Exception e) {
 | 
	
		
			
				|  |  | +                    log.error("IM导入失败",e);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -			//IM导入
 | 
	
		
			
				|  |  | -			imGroupService.importInfo(footer);
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @ApiOperation("融云im To 腾讯")
 | 
	
		
			
				|  |  |      @PostMapping(value = "/imToTencent")
 | 
	
		
			
				|  |  |      public void imToTencent() throws Exception {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        // 删除旧数据
 | 
	
		
			
				|  |  | +        ExecutorService executor = Executors.newSingleThreadExecutor();
 | 
	
		
			
				|  |  | +        executor.execute(() -> {
 | 
	
		
			
				|  |  | +            // 删除旧数据
 | 
	
		
			
				|  |  |  //        historyMessageTenantService.deleteOld();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        com.yonge.mongodb.PageInfo<HistoryMessage> info;
 | 
	
		
			
				|  |  | +            com.yonge.mongodb.PageInfo<HistoryMessage> info;
 | 
	
		
			
				|  |  |  //        historyMessageService.updateAllStatus(0);
 | 
	
		
			
				|  |  | -        //计算总数据量
 | 
	
		
			
				|  |  | -        long count = historyMessageService.querySyncCount();
 | 
	
		
			
				|  |  | -        log.info("总数据量:"+count);
 | 
	
		
			
				|  |  | -        //计算调用次数
 | 
	
		
			
				|  |  | -        long num = (int) Math.ceil(count / 100);
 | 
	
		
			
				|  |  | -        for (long i = 0; i <=num ; i++) {
 | 
	
		
			
				|  |  | -            int size =100;
 | 
	
		
			
				|  |  | -            //获取融云消息
 | 
	
		
			
				|  |  | -            //List<ImGroup> list = imGroupService.lambdaQuery().last("limit "+(page-1)*size+","+size).list();
 | 
	
		
			
				|  |  | -            info = historyMessageService.getImToTencent(1,size);
 | 
	
		
			
				|  |  | -            List<HistoryMessage> footer = info.getRows();
 | 
	
		
			
				|  |  | -            if (CollectionUtils.isEmpty(footer)) {
 | 
	
		
			
				|  |  | -                break;
 | 
	
		
			
				|  |  | +            //计算总数据量
 | 
	
		
			
				|  |  | +            long count = historyMessageService.querySyncCount();
 | 
	
		
			
				|  |  | +            log.info("总数据量:"+count);
 | 
	
		
			
				|  |  | +            //计算调用次数
 | 
	
		
			
				|  |  | +            long num = (int) Math.ceil(count / 100);
 | 
	
		
			
				|  |  | +            for (long i = 0; i <=num ; i++) {
 | 
	
		
			
				|  |  | +                int size = 100;
 | 
	
		
			
				|  |  | +                //获取融云消息
 | 
	
		
			
				|  |  | +                //List<ImGroup> list = imGroupService.lambdaQuery().last("limit "+(page-1)*size+","+size).list();
 | 
	
		
			
				|  |  | +                info = historyMessageService.getImToTencent(1, size);
 | 
	
		
			
				|  |  | +                List<HistoryMessage> footer = info.getRows();
 | 
	
		
			
				|  |  | +                if (CollectionUtils.isEmpty(footer)) {
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                //IM转换
 | 
	
		
			
				|  |  | +                Lists.partition(footer,10).parallelStream().forEach(historyMessages -> {
 | 
	
		
			
				|  |  | +                    try {
 | 
	
		
			
				|  |  | +                        imGroupService.imToTencent(footer);
 | 
	
		
			
				|  |  | +                    } catch (Exception e) {
 | 
	
		
			
				|  |  | +                        log.error("IM转换失败",e);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +                log.info("已转换:" + (i + 1) * size);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            //IM转换
 | 
	
		
			
				|  |  | -            imGroupService.imToTencent(footer);
 | 
	
		
			
				|  |  | -            log.info("已转换:"+(i+1)*size);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @ApiOperation("初始化消息体")
 | 
	
		
			
				|  |  |      @PostMapping(value = "/initMsgBodyJson")
 | 
	
		
			
				|  |  |      public void initMsgBodyJson() throws Exception {
 | 
	
		
			
				|  |  | -        //计算总数据量
 | 
	
		
			
				|  |  | -        int count = historyMessageTenantService.initMsgBodyJsonCount();
 | 
	
		
			
				|  |  | -        log.info("总数据量:"+count);
 | 
	
		
			
				|  |  | -        //计算调用次数
 | 
	
		
			
				|  |  | -        int num = (int) Math.ceil(count / 100);
 | 
	
		
			
				|  |  | -        for (int i = 0; i <=num ; i++) {
 | 
	
		
			
				|  |  | -            int size =100;
 | 
	
		
			
				|  |  | -            //获取融云消息
 | 
	
		
			
				|  |  | -            //List<ImGroup> list = imGroupService.lambdaQuery().last("limit "+(page-1)*size+","+size).list();
 | 
	
		
			
				|  |  | -            historyMessageTenantService.initMsgBodyJson(1,size);
 | 
	
		
			
				|  |  | -            log.info("已转换:"+(i+1)*size);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        ExecutorService executor = Executors.newSingleThreadExecutor();
 | 
	
		
			
				|  |  | +        executor.execute(() -> {
 | 
	
		
			
				|  |  | +            //计算总数据量
 | 
	
		
			
				|  |  | +            int count = historyMessageTenantService.initMsgBodyJsonCount();
 | 
	
		
			
				|  |  | +            log.info("总数据量:" + count);
 | 
	
		
			
				|  |  | +            //计算调用次数
 | 
	
		
			
				|  |  | +            int num = (int) Math.ceil(count / 100);
 | 
	
		
			
				|  |  | +            for (int i = 0; i <= num; i++) {
 | 
	
		
			
				|  |  | +                int size = 100;
 | 
	
		
			
				|  |  | +                //获取融云消息
 | 
	
		
			
				|  |  | +                //List<ImGroup> list = imGroupService.lambdaQuery().last("limit "+(page-1)*size+","+size).list();
 | 
	
		
			
				|  |  | +                historyMessageTenantService.initMsgBodyJson(1, size);
 | 
	
		
			
				|  |  | +                log.info("已转换:" + (i + 1) * size);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @ApiOperation("历史聊天记录查询")
 |