<commit_before>package cn.crap.controller.front;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.crap.adapter.ArticleAdapter;
import cn.crap.adapter.CommentAdapter;
import cn.crap.dto.ArticleDto;
import cn.crap.dto.CrumbDto;
import cn.crap.enumer.ArticleStatus;
import cn.crap.enumer.MyError;
import cn.crap.model.mybatis.*;
import cn.crap.service.custom.CustomArticleService;
import cn.crap.service.custom.CustomCommentService;
import cn.crap.service.custom.CustomModuleService;
import cn.crap.service.mybatis.ArticleService;
import cn.crap.utils.MyCrumbDtoList;
import cn.crap.utils.MyHashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.crap.enumer.ArticleType;
import cn.crap.framework.JsonResult;
import cn.crap.framework.MyException;
import cn.crap.framework.base.BaseController;
import cn.crap.model.mybatis.Project;
import cn.crap.utils.Page;
import cn.crap.utils.Tools;

/**
 * front article page
 * @author Ehsan
 */
@Controller("frontArticleController")
public class ArticleController extends BaseController {
    @Autowired
    private CustomModuleService customModuleService;
    @Autowired
    private CustomArticleService customArticleService;
    @Autowired
    private ArticleService articleService;
    @Autowired
    private CustomCommentService customCommentService;


    @RequestMapping("/front/article/diclist.do")
    @ResponseBody
    public JsonResult list(@RequestParam String moduleId,
                           String name,
                           @RequestParam(defaultValue = "1") Integer currentPage,
                           String password,
                           String visitCode) throws MyException {

        String type = ArticleType.DICTIONARY.name();
        Module module = moduleCache.get(moduleId);
        Project project = projectCache.get(module.getProjectId());

        // private project need login, public project need check password
        checkFrontPermission(password, visitCode, project);

        Page page = new Page(currentPage);
        List<Article> articles = customArticleService.queryArticle(moduleId, name, type, null, null, page);
        page.setAllRow(customArticleService.countByModuleId(moduleId, name, type, null, null));

        Map<String, Object> others = Tools.getMap("crumbs", Tools.getCrumbs(type + "-" + module.getName(), "void"));

        return new JsonResult().success().data(ArticleAdapter.getDto(articles, module)).page(page).others(others);
    }


    @RequestMapping("/front/article/list.do")
    @ResponseBody
    public JsonResult list( Integer currentPage,
                           String moduleId,
                           @RequestParam String type, String category,
                           String password,
                           String visitCode, Byte status) throws MyException {
        Page page = new Page(currentPage);
        if (status == null || !status.equals(ArticleStatus.RECOMMEND.getStatus())){
            Module module = moduleCache.get(moduleId);
            Project project = projectCache.get(module.getProjectId());

            // 如果是私有项目，必须登录才能访问，公开项目需要查看是否需要密码
            checkFrontPermission(password, visitCode, project);

            List<String> categories = customModuleService.queryCategoryByModuleId(module.getId());

            List<Article> articles = customArticleService.queryArticle(moduleId, null,  type, category, status, page);
            page.setAllRow(customArticleService.countByModuleId(moduleId, null,  type, category, status));
            List<ArticleDto> articleDtos = ArticleAdapter.getDto(articles, module);

            Map<String, Object> others = MyHashMap.getMap("type", ArticleType.valueOf(type).getName())
                    .put("category", category)
                    .put("categorys", categories)
                    .put("crumbs", Tools.getCrumbs("模块:" + project.getName(), "#/" + project.getId() + "/module/list", "文章:" + module.getName(), "void"))
                    .getMap();
            return new JsonResult().success().data(articleDtos).page(page).others(others);
        }

        // 推荐的文章
        List<String> categories = customArticleService.queryTop10RecommendCategory();
        List<Article> articles = customArticleService.queryArticle(null, null,  type, category, status, page);
        List<ArticleDto> articleDtos = ArticleAdapter.getDto(articles, null);

        Map<String, Object> others = MyHashMap.getMap("type", ArticleType.valueOf(type).getName())
                .put("category", category)
                .put("categorys", categories)
                .put("crumbs", Tools.getCrumbs( "推荐文章列表", "void"))
                .getMap();

        return new JsonResult().success().data(articleDtos).page(page).others(others);
    }


    @RequestMapping("/front/article/detail.do")
    @ResponseBody
    public JsonResult articleDetail(@RequestParam String id,
                                String password, String visitCode,
                                 Integer currentPage) throws MyException {
        Map<String, Object> returnMap = new HashMap<>();
        ArticleWithBLOBs article = null;

        article = articleService.getById(id);
        if (article == null) {
            article = customArticleService.selectByKey(id);
        }

        if (article == null) {
            throw new MyException(MyError.E000020);
        }<commit_msg>修改bug<commit_after>package cn.crap.controller.front;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.crap.adapter.ArticleAdapter;
import cn.crap.adapter.CommentAdapter;
import cn.crap.dto.ArticleDto;
import cn.crap.dto.CrumbDto;
import cn.crap.enumer.ArticleStatus;
import cn.crap.enumer.MyError;
import cn.crap.model.mybatis.*;
import cn.crap.service.custom.CustomArticleService;
import cn.crap.service.custom.CustomCommentService;
import cn.crap.service.custom.CustomModuleService;
import cn.crap.service.mybatis.ArticleService;
import cn.crap.utils.MyCrumbDtoList;
import cn.crap.utils.MyHashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.crap.enumer.ArticleType;
import cn.crap.framework.JsonResult;
import cn.crap.framework.MyException;
import cn.crap.framework.base.BaseController;
import cn.crap.model.mybatis.Project;
import cn.crap.utils.Page;
import cn.crap.utils.Tools;

/**
 * front article page
 * @author Ehsan
 */
@Controller("frontArticleController")
public class ArticleController extends BaseController {
    @Autowired
    private CustomModuleService customModuleService;
    @Autowired
    private CustomArticleService customArticleService;
    @Autowired
    private ArticleService articleService;
    @Autowired
    private CustomCommentService customCommentService;


    @RequestMapping("/front/article/diclist.do")
    @ResponseBody
    public JsonResult list(@RequestParam String moduleId,
                           String name,
                           @RequestParam(defaultValue = "1") Integer currentPage,
                           String password,
                           String visitCode) throws MyException {

        String type = ArticleType.DICTIONARY.name();
        Module module = moduleCache.get(moduleId);
        Project project = projectCache.get(module.getProjectId());

        // private project need login, public project need check password
        checkFrontPermission(password, visitCode, project);

        Page page = new Page(currentPage);
        List<Article> articles = customArticleService.queryArticle(moduleId, name, type, null, null, page);
        page.setAllRow(customArticleService.countByModuleId(moduleId, name, type, null, null));

        Map<String, Object> others = Tools.getMap("crumbs", Tools.getCrumbs(type + "-" + module.getName(), "void"));

        return new JsonResult().success().data(ArticleAdapter.getDto(articles, module)).page(page).others(others);
    }


    @RequestMapping("/front/article/list.do")
    @ResponseBody
    public JsonResult list( Integer currentPage,
                           String moduleId,
                           @RequestParam String type, String category,
                           String password,
                           String visitCode, Byte status) throws MyException {
        Page page = new Page(currentPage);
        if (status == null || !status.equals(ArticleStatus.RECOMMEND.getStatus())){
            Module module = moduleCache.get(moduleId);
            Project project = projectCache.get(module.getProjectId());

            // 如果是私有项目，必须登录才能访问，公开项目需要查看是否需要密码
            checkFrontPermission(password, visitCode, project);

            List<String> categories = customModuleService.queryCategoryByModuleId(module.getId());

            List<Article> articles = customArticleService.queryArticle(moduleId, null,  type, category, status, page);
            page.setAllRow(customArticleService.countByModuleId(moduleId, null,  type, category, status));
            List<ArticleDto> articleDtos = ArticleAdapter.getDto(articles, module);

            Map<String, Object> others = MyHashMap.getMap("type", ArticleType.valueOf(type).getName())
                    .put("category", category)
                    .put("categorys", categories)
                    .put("crumbs", Tools.getCrumbs("模块:" + project.getName(), "#/" + project.getId() + "/module/list", "文章:" + module.getName(), "void"))
                    .getMap();
            return new JsonResult().success().data(articleDtos).page(page).others(others);
        }

        // 推荐的文章
        List<String> categories = customArticleService.queryTop10RecommendCategory();
        List<Article> articles = customArticleService.queryArticle(null, null,  type, category, status, page);
        List<ArticleDto> articleDtos = ArticleAdapter.getDto(articles, null);

        page.setAllRow(customArticleService.countByModuleId(null, null,  type, category, status));
        Map<String, Object> others = MyHashMap.getMap("type", ArticleType.valueOf(type).getName())
                .put("category", category)
                .put("categorys", categories)
                .put("crumbs", Tools.getCrumbs( "推荐文章列表", "void"))
                .getMap();

        return new JsonResult().success().data(articleDtos).page(page).others(others);
    }


    @RequestMapping("/front/article/detail.do")
    @ResponseBody
    public JsonResult articleDetail(@RequestParam String id,
                                String password, String visitCode,
                                 Integer currentPage) throws MyException {
        Map<String, Object> returnMap = new HashMap<>();
        ArticleWithBLOBs article = null;

        article = articleService.getById(id);
        if (article == null) {
            article = customArticleService.selectByKey(id);
        }

        if (article == null) {
            throw new MyException(MyError.E000020);
        }
{'fraction_non_alphanumeric': 0.10865173473869126, 'fraction_numerical': 0.0015810276679841897, 'mean_word_length': 2.988091068301226, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5106998', 'n_tokens_mistral': 3152, 'n_tokens_neox': 3122, 'n_words': 611}