Compare commits

...

2 Commits

Author SHA1 Message Date
佟明轩 20e85cd3e9 Merge branch 'master' of ssh://git.jizhiweb.cn:2222/clinic-v2/server 2025-05-21 11:52:33 +08:00
佟明轩 6986069333 同步mongodb 2025-05-21 11:52:18 +08:00
2 changed files with 50 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -162,6 +163,9 @@ public class SocialDirectoryController extends BaseController {
return success(socialItemService.pageList(pageNum,pageSize,keyword)); return success(socialItemService.pageList(pageNum,pageSize,keyword));
} }
@PostMapping("syncToMongo")
public Result<Object> syncToMongo() {
return success(socialDirectoryService.syncSocialDirectoryCache(parmsUtil.getInteger("page","请输入page")));
}
} }

View File

@ -232,7 +232,6 @@ public class SocialDirectoryService extends BaseService {
} }
} }
/* /*
* 搜索接口 * 搜索接口
* @param keyword 关键字 * @param keyword 关键字
@ -553,4 +552,49 @@ public class SocialDirectoryService extends BaseService {
return socialDirectoryMapper.selectMaps(codeqw); return socialDirectoryMapper.selectMaps(codeqw);
} }
public HashMap<String, Object> syncSocialDirectoryCache(int page) {
HashMap<String, Object> map = new HashMap<>();
int syncCount = 50000;
map.put("page",page);
String outString = "syncSocialDirectoryCache:"+"page:"+page+":";
DebugUtil.out(outString+"start");
initMongoDb();
if (page == 1)
{
mongoTemplate.dropCollection("social_directory");
long count = socialDirectoryMapper.selectCount(null);
DebugUtil.out(outString+"database_count:"+count);
map.put("total_count",(int)count);
int total_page = (int) Math.ceil((double) count / syncCount);
map.put("total_page",total_page);
DebugUtil.out(outString+"database_page:"+total_page);
}
QueryWrapper<SocialDirectory> queryWrapper = new QueryWrapper<>();
queryWrapper.last("limit "+syncCount+" offset " + (page - 1) * syncCount);
List<SocialDirectory> socialDirectoryList = socialDirectoryMapper.selectList(queryWrapper);
DebugUtil.out(outString+"database_select_success:"+socialDirectoryList.size());
saveListToMongoDb(socialDirectoryList);
DebugUtil.out(outString+"mongo_insert_success");
return map;
}
} }