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

import cn.crap.adapter.ErrorAdapter;
import cn.crap.adapter.InterfaceAdapter;
import cn.crap.beans.Config;
import cn.crap.dto.CategoryDto;
import cn.crap.dto.DictionaryDto;
import cn.crap.dto.InterfacePDFDto;
import cn.crap.dto.SettingDto;
import cn.crap.enumer.ArticleType;
import cn.crap.enumer.MyError;
import cn.crap.enumer.ProjectType;
import cn.crap.framework.JsonResult;
import cn.crap.framework.MyException;
import cn.crap.framework.base.BaseController;
import cn.crap.model.*;
import cn.crap.model.Error;
import cn.crap.query.ArticleQuery;
import cn.crap.query.ErrorQuery;
import cn.crap.query.InterfaceQuery;
import cn.crap.query.ModuleQuery;
import cn.crap.service.ArticleService;
import cn.crap.service.ErrorService;
import cn.crap.service.InterfaceService;
import cn.crap.service.ModuleService;
import cn.crap.utils.*;
import net.sf.json.JSONArray;
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 org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/user/staticize")
public class StaticizeController extends BaseController{
	@Autowired
	private ModuleService moduleService;
	@Autowired
	private Config config;
	@Autowired
	private InterfaceService interfaceService;
	@Autowired
	private ErrorService errorService;
	@Autowired
	private ArticleService articleService;

	/**
	 * 静态化错误码列表
	 */
	@RequestMapping("/errorList.do")
	public ModelAndView staticizeError(HttpServletRequest req, @RequestParam String projectId,@RequestParam int currentPage,
			String needStaticizes, @RequestParam String secretKey) throws MyException {
		// 验证是否是非法请求
		if( !settingCache.get(S_SECRETKEY).getValue().equals(secretKey) ){
			throw new MyException(MyError.E000056);
		}
		Project project = projectCache.get(projectId);
		String path = Tools.getStaticPath(project);
		if(project.getType() != ProjectType.PUBLIC.getType()){
			Tools.deleteFile(path);
			// 删除旧的静态化文件
			throw new MyException(MyError.E000044);
		}
		
		Map<String, Object> returnMap = getProjectModuleInfor(null, project, "-错误码");
		

		ErrorQuery errorQuery = new ErrorQuery().setProjectId(projectId);
		errorQuery.setCurrentPage(currentPage);
		Page page = new Page(errorQuery);
		List<Error> errorModels = errorService.query(errorQuery);
		page.setAllRow(errorService.count(errorQuery));

		returnMap.put("page", page);
		returnMap.put("errorList", ErrorAdapter.getDto(errorModels));
		returnMap.put("activePage","errorList");
		returnMap.put("url", "errorList");
		returnMap.put("needStaticizes", needStaticizes);
		return new ModelAndView("WEB-INF/views/staticize/default/errorList.jsp",returnMap);
	}

	

	/**
	 * 静态化接口列表
	 */
	@RequestMapping("/interfaceList.do")
	public ModelAndView interfaceList(HttpServletRequest req, @RequestParam String moduleId, @RequestParam int currentPage,
			String needStaticizes, @RequestParam String secretKey) throws MyException {
		// 验证是否是非法请求
		if( !settingCache.get(S_SECRETKEY).getValue().equals(secretKey) ){
			throw new MyException(MyError.E000056);
		}
		
		Module module = moduleCache.get(moduleId);
		Project project = projectCache.get(module.getProjectId());
		String path = Tools.getStaticPath(project);

		if(project.getType() != ProjectType.PUBLIC.getType()){
			Tools.deleteFile(path);
			// 删除旧的静态化文件
			throw new MyException(MyError.E000044);
		}
		
		Map<String, Object> returnMap = getProjectModuleInfor(module, project, "-接口");
		
		Map<String, Object> map = Tools.getMap("moduleId", moduleId);

        InterfaceQuery interfaceQuery = new InterfaceQuery().setCurrentPage(currentPage).setModuleId(moduleId);
        Page page = new Page(interfaceQuery);
        page.setAllRow(interfaceService.count(interfaceQuery));
		returnMap.put("page", page);
		returnMap.put("interfaceList", InterfaceAdapter.getDtoWithBLOBs(interfaceService.queryAll(interfaceQuery), module, null));
		returnMap.put("activePage",moduleId+"_interface");
		returnMap.put("url", module.getId() + "-interfaceList");
		returnMap.put("needStaticizes", needStaticizes);
		return new ModelAndView("WEB-INF/views/staticize/default/interfaceList.jsp",returnMap);
	}

	
	/**
	 * 静态化模块文章列表
	 */
	@RequestMapping("/articleList.do")
	public ModelAndView staticizeModule(HttpServletRequest req, @RequestParam String moduleId,@RequestParam String category,@RequestParam int currentPage,
			String type, String needStaticizes, @RequestParam String secretKey) throws MyException {
		// 验证是否是非法请求
		if( !settingCache.get(S_SECRETKEY).getValue().equals(secretKey) ){
			throw new MyException(MyError.E000056);
		}
		Module module = moduleCache.get(moduleId);
		Project project = projectCache.get(module.getProjectId());
		String path = Tools.getStaticPath(project);

		if(project.getType() != ProjectType.PUBLIC.getType()){
			Tools.deleteFile(path);
			// 删除旧的静态化文件
			throw new MyException(MyError.E000044);
		}<commit_msg>静态化bug<commit_after>package cn.crap.controller.user;

import cn.crap.adapter.ErrorAdapter;
import cn.crap.adapter.InterfaceAdapter;
import cn.crap.beans.Config;
import cn.crap.dto.*;
import cn.crap.enumer.ArticleType;
import cn.crap.enumer.MyError;
import cn.crap.enumer.ProjectType;
import cn.crap.framework.JsonResult;
import cn.crap.framework.MyException;
import cn.crap.framework.base.BaseController;
import cn.crap.model.*;
import cn.crap.model.Error;
import cn.crap.query.ArticleQuery;
import cn.crap.query.ErrorQuery;
import cn.crap.query.InterfaceQuery;
import cn.crap.query.ModuleQuery;
import cn.crap.service.ArticleService;
import cn.crap.service.ErrorService;
import cn.crap.service.InterfaceService;
import cn.crap.service.ModuleService;
import cn.crap.utils.*;
import net.sf.json.JSONArray;
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 org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/user/staticize")
public class StaticizeController extends BaseController{
	@Autowired
	private ModuleService moduleService;
	@Autowired
	private Config config;
	@Autowired
	private InterfaceService interfaceService;
	@Autowired
	private ErrorService errorService;
	@Autowired
	private ArticleService articleService;

	/**
	 * 静态化错误码列表
	 */
	@RequestMapping("/errorList.do")
	public ModelAndView staticizeError(HttpServletRequest req, @RequestParam String projectId,@RequestParam int currentPage,
			String needStaticizes, @RequestParam String secretKey) throws MyException {
		// 验证是否是非法请求
		if( !settingCache.get(S_SECRETKEY).getValue().equals(secretKey) ){
			throw new MyException(MyError.E000056);
		}
		Project project = projectCache.get(projectId);
		String path = Tools.getStaticPath(project);
		if(project.getType() != ProjectType.PUBLIC.getType()){
			Tools.deleteFile(path);
			// 删除旧的静态化文件
			throw new MyException(MyError.E000044);
		}
		
		Map<String, Object> returnMap = getProjectModuleInfor(null, project, "-错误码");
		

		ErrorQuery errorQuery = new ErrorQuery().setProjectId(projectId);
		errorQuery.setCurrentPage(currentPage);
		Page page = new Page(errorQuery);
		List<Error> errorModels = errorService.query(errorQuery);
		page.setAllRow(errorService.count(errorQuery));

		returnMap.put("page", page);
		returnMap.put("errorList", ErrorAdapter.getDto(errorModels));
		returnMap.put("activePage","errorList");
		returnMap.put("url", "errorList");
		returnMap.put("needStaticizes", needStaticizes);
		return new ModelAndView("WEB-INF/views/staticize/default/errorList.jsp",returnMap);
	}

	

	/**
	 * 静态化接口列表
	 */
	@RequestMapping("/interfaceList.do")
	public ModelAndView interfaceList(HttpServletRequest req, @RequestParam String moduleId, @RequestParam int currentPage,
			String needStaticizes, @RequestParam String secretKey) throws MyException {
		// 验证是否是非法请求
		if( !settingCache.get(S_SECRETKEY).getValue().equals(secretKey) ){
			throw new MyException(MyError.E000056);
		}
		
		Module module = moduleCache.get(moduleId);
		Project project = projectCache.get(module.getProjectId());
		String path = Tools.getStaticPath(project);

		if(project.getType() != ProjectType.PUBLIC.getType()){
			Tools.deleteFile(path);
			// 删除旧的静态化文件
			throw new MyException(MyError.E000044);
		}
		
		Map<String, Object> returnMap = getProjectModuleInfor(module, project, "-接口");
		
		Map<String, Object> map = Tools.getMap("moduleId", moduleId);

        InterfaceQuery interfaceQuery = new InterfaceQuery().setCurrentPage(currentPage).setModuleId(moduleId);
        Page page = new Page(interfaceQuery);
        page.setAllRow(interfaceService.count(interfaceQuery));
		returnMap.put("page", page);
		returnMap.put("interfaceList", InterfaceAdapter.getDto(interfaceService.query(interfaceQuery), module, null));
		returnMap.put("activePage",moduleId+"_interface");
		returnMap.put("url", module.getId() + "-interfaceList");
		returnMap.put("needStaticizes", needStaticizes);
		return new ModelAndView("WEB-INF/views/staticize/default/interfaceList.jsp",returnMap);
	}

	
	/**
	 * 静态化模块文章列表
	 */
	@RequestMapping("/articleList.do")
	public ModelAndView staticizeModule(HttpServletRequest req, @RequestParam String moduleId,@RequestParam String category,@RequestParam int currentPage,
			String type, String needStaticizes, @RequestParam String secretKey) throws MyException {
		// 验证是否是非法请求
		if( !settingCache.get(S_SECRETKEY).getValue().equals(secretKey) ){
			throw new MyException(MyError.E000056);
		}
		Module module = moduleCache.get(moduleId);
		Project project = projectCache.get(module.getProjectId());
		String path = Tools.getStaticPath(project);

		if(project.getType() != ProjectType.PUBLIC.getType()){
			Tools.deleteFile(path);
			// 删除旧的静态化文件
			throw new MyException(MyError.E000044);
		}
{'fraction_non_alphanumeric': 0.11960227272727272, 'fraction_numerical': 0.006818181818181818, 'mean_word_length': 5.804768041237113, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2892433', 'n_tokens_mistral': 3585, 'n_tokens_neox': 3421, 'n_words': 580}