|
|
@@ -1,138 +0,0 @@
|
|
|
-package com.fs.admin.controller;
|
|
|
-
|
|
|
-import java.util.*;
|
|
|
-
|
|
|
-import com.fs.admin.helper.AdminCrossTenantHelper;
|
|
|
-import com.fs.common.annotation.Excel;
|
|
|
-import com.fs.common.annotation.Log;
|
|
|
-import com.fs.common.core.controller.BaseController;
|
|
|
-import com.fs.common.core.domain.AjaxResult;
|
|
|
-import com.fs.common.core.page.TableDataInfo;
|
|
|
-import com.fs.common.enums.BusinessType;
|
|
|
-import com.fs.common.utils.poi.ExcelUtil;
|
|
|
-import lombok.Data;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-/**
|
|
|
- * 总后台文章内容审计控制器
|
|
|
- * 遍历所有租户库查询 fs_article 数据
|
|
|
- */
|
|
|
-@RestController
|
|
|
-@RequestMapping("/admin/article")
|
|
|
-public class ArticleAdminController extends BaseController {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private AdminCrossTenantHelper crossTenantHelper;
|
|
|
-
|
|
|
- private String str(Object o) { return o == null ? "" : o.toString(); }
|
|
|
-
|
|
|
- @Data
|
|
|
- public static class ArticleExportVO {
|
|
|
- @Excel(name = "租户名称") private String companyName;
|
|
|
- @Excel(name = "文章标题") private String articleTitle;
|
|
|
- @Excel(name = "分类") private String categoryName;
|
|
|
- @Excel(name = "作者") private String author;
|
|
|
- @Excel(name = "状态") private String status;
|
|
|
- @Excel(name = "创建时间") private String createTime;
|
|
|
- }
|
|
|
-
|
|
|
- @Log(title = "导出文章", businessType = BusinessType.EXPORT)
|
|
|
- @PreAuthorize("@ss.hasPermi('admin:article:list')")
|
|
|
- @GetMapping("/export")
|
|
|
- public AjaxResult export(@RequestParam(required = false) String articleTitle,
|
|
|
- @RequestParam(required = false) Long companyId,
|
|
|
- @RequestParam(required = false) String companyName) {
|
|
|
- List<Map<String, Object>> allList = crossTenantHelper.queryAcrossTenants(
|
|
|
- companyId, companyName, (tenant, jdbc) -> {
|
|
|
- StringBuilder sql = new StringBuilder(
|
|
|
- "SELECT a.article_id, a.article_title, a.category_name, a.author, " +
|
|
|
- "a.create_time, a.status " +
|
|
|
- "FROM fs_article a WHERE 1=1");
|
|
|
- List<Object> params = new ArrayList<>();
|
|
|
- if (articleTitle != null && !articleTitle.isEmpty()) {
|
|
|
- sql.append(" AND a.article_title LIKE ?");
|
|
|
- params.add("%" + articleTitle + "%");
|
|
|
- }
|
|
|
- sql.append(" ORDER BY a.create_time DESC");
|
|
|
- return params.isEmpty()
|
|
|
- ? jdbc.queryForList(sql.toString())
|
|
|
- : jdbc.queryForList(sql.toString(), params.toArray());
|
|
|
- });
|
|
|
- List<ArticleExportVO> voList = new ArrayList<>();
|
|
|
- for (Map<String, Object> m : allList) {
|
|
|
- ArticleExportVO vo = new ArticleExportVO();
|
|
|
- vo.setCompanyName(str(m.get("company_name")));
|
|
|
- vo.setArticleTitle(str(m.get("article_title")));
|
|
|
- vo.setCategoryName(str(m.get("category_name")));
|
|
|
- vo.setAuthor(str(m.get("author")));
|
|
|
- vo.setStatus(str(m.get("status")));
|
|
|
- vo.setCreateTime(str(m.get("create_time")));
|
|
|
- voList.add(vo);
|
|
|
- }
|
|
|
- ExcelUtil<ArticleExportVO> util = new ExcelUtil<>(ArticleExportVO.class);
|
|
|
- return util.exportExcel(voList, "文章数据");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询所有租户的文章列表
|
|
|
- */
|
|
|
- @PreAuthorize("@ss.hasPermi('admin:article:list')")
|
|
|
- @GetMapping("/list")
|
|
|
- public TableDataInfo list(@RequestParam(required = false) String articleTitle,
|
|
|
- @RequestParam(required = false) Long companyId,
|
|
|
- @RequestParam(required = false) String companyName) {
|
|
|
- List<Map<String, Object>> allList = crossTenantHelper.queryAcrossTenants(
|
|
|
- companyId, companyName, (tenant, jdbc) -> {
|
|
|
- StringBuilder sql = new StringBuilder(
|
|
|
- "SELECT a.article_id, a.article_title, a.category_name, a.author, " +
|
|
|
- "a.create_time, a.status " +
|
|
|
- "FROM fs_article a WHERE 1=1");
|
|
|
- List<Object> params = new ArrayList<>();
|
|
|
- if (articleTitle != null && !articleTitle.isEmpty()) {
|
|
|
- sql.append(" AND a.article_title LIKE ?");
|
|
|
- params.add("%" + articleTitle + "%");
|
|
|
- }
|
|
|
- sql.append(" ORDER BY a.create_time DESC LIMIT 200");
|
|
|
- return params.isEmpty()
|
|
|
- ? jdbc.queryForList(sql.toString())
|
|
|
- : jdbc.queryForList(sql.toString(), params.toArray());
|
|
|
- });
|
|
|
- return getDataTable(allList);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询待审计文章列表
|
|
|
- */
|
|
|
- @PreAuthorize("@ss.hasPermi('admin:article:list')")
|
|
|
- @GetMapping("/pending")
|
|
|
- public TableDataInfo pendingList(@RequestParam(required = false) Long companyId,
|
|
|
- @RequestParam(required = false) String companyName) {
|
|
|
- List<Map<String, Object>> allList = crossTenantHelper.queryAcrossTenants(
|
|
|
- companyId, companyName, (tenant, jdbc) ->
|
|
|
- jdbc.queryForList(
|
|
|
- "SELECT a.article_id, a.article_title, a.category_name, a.author, " +
|
|
|
- "a.create_time, a.status " +
|
|
|
- "FROM fs_article a WHERE a.status = 0 ORDER BY a.create_time DESC LIMIT 200"));
|
|
|
- return getDataTable(allList);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 文章统计信息
|
|
|
- */
|
|
|
- @PreAuthorize("@ss.hasPermi('admin:article:query')")
|
|
|
- @GetMapping("/statistics")
|
|
|
- public AjaxResult statistics(@RequestParam(required = false) Long companyId,
|
|
|
- @RequestParam(required = false) String companyName) {
|
|
|
- List<Map<String, Object>> allList = crossTenantHelper.queryAcrossTenants(
|
|
|
- companyId, companyName, (tenant, jdbc) ->
|
|
|
- jdbc.queryForList("SELECT article_id, status FROM fs_article"));
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("totalCount", allList.size());
|
|
|
- result.put("pendingCount", allList.stream().filter(r -> "0".equals(String.valueOf(r.get("status")))).count());
|
|
|
- result.put("approvedCount", allList.stream().filter(r -> "1".equals(String.valueOf(r.get("status")))).count());
|
|
|
- result.put("rejectedCount", allList.stream().filter(r -> "2".equals(String.valueOf(r.get("status")))).count());
|
|
|
- return AjaxResult.success(result);
|
|
|
- }
|
|
|
-}
|