wb = xlsx_package.workbook
wb.add_worksheet(name: '项目列表') do |sheet|
  sheet.add_row %w(序号 项目名称 是否为公开 项目类别 项目性质（原创/Fork） 是否镜像 issue数 PR接受数 PR拒绝数 里程碑数 成员数 发布版本数量 关注数 点赞数 fork数 平台内提交数 管理员 创建时间 项目地址)

  @projects.each_with_index do |project, index|
    data = [
      index + 1,
      project.name,
      project.is_public? ? "是" : "否",
      project.project_category.present? ? project.project_category.name : "",
      project.forked_from_project_id.blank? ? "原创" : "Fork",
      project.project_type == "sync_mirror" ? "是" : "否",
      project.issues.where(issue_classify: 'issue').count,
      project.issues.issue_pull_request.joins(:pull_request).where(pull_requests: {status: PullRequest::MERGED}).count,
      project.issues.issue_pull_request.joins(:pull_request).where(pull_requests: {status: PullRequest::CLOSED}).count,
      project.versions.count,
      project.members.count,
      project.repository.version_releases_count,
      project.watchers_count,
      project.praises_count,
      project.forked_count,
      project.commit_logs.count,
      project.owner&.real_name,
      project.created_on&.strftime('%Y-%m-%d %H:%M'),
      "#{@domain_url}/#{project.owner.login}/#{project.identifier}",
    ]
    sheet.add_row(data)
  end
end