新开分支整理代码:

1.帮助文档修改功能
2.帮助文档与上一版对比功能
3.单点问题解决
4.markdown帮助文档

Conflicts:
	src/main/resources/messages/message_en.properties
	src/main/resources/messages/message_ru.properties
	src/main/resources/messages/message_zh_CN.properties
This commit is contained in:
wangwenrui
2019-01-30 18:17:51 +08:00
committed by 段冬梅
parent 785150f921
commit db00cafd84
654 changed files with 138408 additions and 14 deletions

View File

@@ -0,0 +1,34 @@
package com.nis.domain.configuration;
import java.util.Date;
import com.nis.domain.BaseEntity;
import com.nis.util.excel.ExcelField;
public class HelpInfo extends BaseEntity<HelpInfo>{
private static final long serialVersionUID = 2451757008384840494L;
private String fileName;
private String fileComment;
private String backFileComment;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getFileComment() {
return fileComment;
}
public void setFileComment(String fileComment) {
this.fileComment = fileComment;
}
public String getBackFileComment() {
return backFileComment;
}
public void setBackFileComment(String backFileComment) {
this.backFileComment = backFileComment;
}
}

View File

@@ -0,0 +1,69 @@
package com.nis.util.redis;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.apache.log4j.Logger;
import com.nis.util.Configurations;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
public class RedisPoolHelper {
private Logger logger=Logger.getLogger(RedisPoolHelper.class);
private JedisPool jedisPool;
private String host;
private int timeout;
public RedisPoolHelper(){
init();
}
private void init() {
synchronized (this) {
if (jedisPool == null) {
host=Configurations.getStringProperty("redis.host", "127.0.0.1:6379");
timeout=Configurations.getIntProperty("redis.timeout", 10000);
String[] hostAndPort = host.split(":");
jedisPool = new JedisPool(getPoolConfig(), hostAndPort[0], Integer.parseInt(hostAndPort[1]), timeout);
logger.info("redis pool init complate! host-->"+hostAndPort[0]+" port:"+Integer.parseInt(hostAndPort[1]));
}
}
}
public Jedis getJedis() {
if (jedisPool == null) {
init();
}
return jedisPool.getResource();
}
public JedisPool getJedisPool() {
return jedisPool;
}
public void setJedisPool(JedisPool jedisPool) {
this.jedisPool = jedisPool;
}
/**
*
* getPoolConfig(初始化连接池的配置,这里可以设置很多参数的,不过目前没加)
* (这里描述这个方法适用条件 可选)
* @return
*GenericObjectPoolConfig
* @exception
* @since 1.0.0
*/
private GenericObjectPoolConfig getPoolConfig(){
GenericObjectPoolConfig config=new GenericObjectPoolConfig();
config.setMaxTotal(Configurations.getIntProperty("redis.pool.maxtotal", 500));//整个池的最大值
config.setMaxIdle(Configurations.getIntProperty("redis.pool.maxidle", 100));//最大空闲
config.setMaxWaitMillis(Configurations.getIntProperty("redis.pool.maxwaitmillis", -1));//获取不到永远等待
config.setBlockWhenExhausted(Configurations.getBooleanProperty("redis.pool.blockwhenexhausted", true));
config.setNumTestsPerEvictionRun(Configurations.getIntProperty("redis.pool.numtestsperevictionrun", Integer.MAX_VALUE));//always test all idle object
config.setTestOnBorrow(Configurations.getBooleanProperty("redis.pool.testonborrow", true));
config.setTestOnReturn(Configurations.getBooleanProperty("redis.pool.testonreturn", false));
config.setTestWhileIdle(Configurations.getBooleanProperty("redis.pool.testwhileidle", true));//发呆过长时间是否先test一下
config.setTimeBetweenEvictionRunsMillis(Configurations.getLongProperty("redis.pool.timebetweenevictionrunsmillis", 60000L));//-1不启动默认1min一次
config.setMinEvictableIdleTimeMillis(Configurations.getLongProperty("redis.pool.minevictableidletimemillis", 60000L));//可发呆的时间10mins
return config;
}
}

View File

@@ -0,0 +1,38 @@
package com.nis.util.redis;
import org.apache.log4j.Logger;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
public class SaveHelpInfoThread extends Thread {
private Logger logger=Logger.getLogger(SaveHelpInfoThread.class);
private JedisPool jedisPool;
private Jedis jedis;
private String key;
private String value;
private int expire;
public SaveHelpInfoThread(JedisPool jedisPool,String key,String value,int expire){
this.jedisPool=jedisPool;
this.key=key;
this.value=value;
this.expire=expire;
jedis=jedisPool.getResource();
}
@Override
public void run() {
try {
jedis.set(key, value);
if(expire!=-1){
jedis.expire(key, expire);
}
logger.debug("cache help[key --> "+key+"]");
} catch (Exception e) {
logger.error("save redis error",e);
}finally{
jedis.close();
}
}
}

View File

@@ -1,23 +1,31 @@
package com.nis.web.controller;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.nis.domain.SysMenu;
import com.nis.domain.configuration.HelpInfo;
import com.nis.util.StringUtil;
import com.nis.util.StringUtils;
import com.nis.web.security.UserUtils;
import com.nis.web.service.configuration.HelpInfoService;
@Controller
@RequestMapping("${adminPath}/sys/")
public class SystemController extends BaseController{
@Autowired
private HelpInfoService helpService;
@RequestMapping("index")
public String index(HttpServletRequest request, HttpServletResponse response,ModelMap model){
return "/sys/sysIndex";
@@ -91,6 +99,9 @@ public class SystemController extends BaseController{
System.out.println(menu.getParentIds());
newList.add(menu);
}*/
//将帮助文档缓存到redis
helpService.cacheAllHelpInfo();
}
} catch (Exception e) {
@@ -100,6 +111,91 @@ public class SystemController extends BaseController{
model.addAttribute("menuList",newList);
return "/help";
}
/**
* @param request
* @param response
* @param model
* @param editedHelpInfo 修改之后的帮助文档内容
* @param helpHrefVal 文档的路径
* @return
*/
@RequestMapping("saveHelp")
@ResponseBody
public boolean saveHelp(HttpServletRequest request, HttpServletResponse response,ModelMap model,@RequestParam(required=true,value="editedHelpInfo")String editedHelpInfo,@RequestParam(required=true,value="helpHrefVal")String helpHrefVal){
if(StringUtils.strIsBlank(helpHrefVal)){
return false;
}
try {
StringBuffer helpInfoText=new StringBuffer(); //修改之后的内容
helpInfoText.append(URLDecoder.decode(editedHelpInfo,"utf-8"));
String helpHref=URLDecoder.decode(helpHrefVal,"utf-8");
String[] split = StringUtils.split(helpHref, "/");
if(split!=null&&split.length>0){
HelpInfo helpInfo = new HelpInfo();
helpInfo.setFileComment(helpInfoText.toString());
helpInfo.setFileName(split[split.length-1]);
helpService.saveHelpInfo(helpInfo);
return true;
}
} catch (Exception e) {
logger.error("save helpInfo error",e);
}
return false;
}
/**
* 查看帮助文档内容
* @param request
* @param response
* @param model
* @param helpHref
* @return
*/
@RequestMapping("viewHelp")
@ResponseBody
public HelpInfo viewHelp(HttpServletRequest request, HttpServletResponse response,ModelMap model,@RequestParam(required=true,value="helpHref")String helpHref){
if(StringUtils.strIsBlank(helpHref)){
return null;
}
try {
helpHref=URLDecoder.decode(helpHref,"utf-8");
String[] split = StringUtils.split(helpHref, "/");
if(split!=null&&split.length>0){
HelpInfo helpInfo = helpService.findHelpCommentByName(split[split.length-1]);
return helpInfo;
}
} catch (Exception e) {
logger.error("view helpInfo error",e);
}
return null;
}
/**
* 查看帮助文档备份内容
* @param request
* @param response
* @param model
* @param helpHref
* @return
*/
@RequestMapping("viewBakHelp")
@ResponseBody
public HelpInfo viewBakHelp(HttpServletRequest request, HttpServletResponse response,ModelMap model,@RequestParam(required=true,value="helpHref")String helpHref){
if(StringUtils.strIsBlank(helpHref)){
return null;
}
try {
helpHref=URLDecoder.decode(helpHref,"utf-8");
String[] split = StringUtils.split(helpHref, "/");
if(split!=null&&split.length>0){
HelpInfo helpInfo = helpService.findHelpBakCommentByName(split[split.length-1]);
return helpInfo;
}
} catch (Exception e) {
logger.error("view helpBakInfo error",e);
}
return null;
}
}

View File

@@ -0,0 +1,18 @@
package com.nis.web.dao.configuration;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.nis.domain.configuration.HelpInfo;
import com.nis.domain.configuration.UserManage;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.MyBatisDao;
@MyBatisDao
public interface HelpInfoDao extends CrudDao<HelpInfo>{
public List<HelpInfo> findComment(@Param("fileName")String fileName);
public List<HelpInfo> findBakComment(@Param("fileName")String fileName);
public List<HelpInfo> findAllComment();
public void saveHelpInfo(HelpInfo helpInfo);
}

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.nis.web.dao.configuration.HelpInfoDao">
<resultMap id="helpInfoMap" type="com.nis.domain.configuration.HelpInfo" >
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="file_name" property="fileName" jdbcType="VARCHAR"/>
<result column="file_comment" property="fileComment" jdbcType="VARCHAR"/>
<result column="back_file_comment" property="backFileComment" jdbcType="VARCHAR"/>
</resultMap>
<!-- 查询帮助文档内容 -->
<select id="findComment" parameterType="com.nis.domain.configuration.HelpInfo" resultMap="helpInfoMap">
select file_name,file_comment from help_document
<if test="fileName != null and fileName != ''">
where file_name=#{fileName}
</if>
</select>
<!-- 查询帮助文档上一版内容 -->
<select id="findBakComment" parameterType="com.nis.domain.configuration.HelpInfo" resultMap="helpInfoMap">
select file_name,back_file_comment from help_document
<if test="fileName != null and fileName != ''">
where file_name=#{fileName}
</if>
</select>
<!-- 获取帮助文档所有的信息 -->
<select id="findAllComment" parameterType="com.nis.domain.configuration.HelpInfo" resultMap="helpInfoMap">
select file_name,file_comment,back_file_comment from help_document
</select>
<!-- 保存修改内容,并备份 -->
<update id="saveHelpInfo" parameterType="com.nis.domain.configuration.HelpInfo">
update help_document set back_file_comment=file_comment,file_comment=#{fileComment} where file_name=#{fileName};
</update>
</mapper>

View File

@@ -0,0 +1,208 @@
package com.nis.web.service.configuration;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.crazycake.shiro.RedisManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.nis.domain.configuration.HelpInfo;
import com.nis.util.StringUtils;
import com.nis.util.redis.RedisPoolHelper;
import com.nis.util.redis.SaveHelpInfoThread;
import com.nis.web.dao.configuration.HelpInfoDao;
import com.nis.web.service.SpringContextHolder;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
@Service
public class HelpInfoService{
@Autowired
private HelpInfoDao dao;
private JedisPool jedisPool;
private Logger logger=Logger.getLogger(HelpInfoService.class);
private ExecutorService pool = Executors.newFixedThreadPool(5);
private final String HELP_CACHE_PRE="help:cache:";//帮助文档redis key的前缀
private final String BACK_HELP_CACHE_PRE="help:cache:back:"; //帮助文档上一版redis key的前缀
private final String HELP_CACHE_FLAG="help:cache:cacheFlag";//是否已经缓存的标识
public HelpInfoService(){
jedisPool=new RedisPoolHelper().getJedisPool();
}
/**
* 通过文件名称查询文件内容
* @param fileName
* @return
* @throws Exception
*/
public HelpInfo findHelpCommentByName(String fileName){
HelpInfo helpInfo = getCacheHelpInfo(fileName);
if(helpInfo==null){
List<HelpInfo> list = dao.findComment(fileName);
if(list!=null&&list.size()>0){
helpInfo= list.get(0);
}
}
return helpInfo;
}
/**
* 查询所有的帮助文档信息
* @return
*/
public List<HelpInfo> findHelpComments(){
List<HelpInfo> list = dao.findComment(null);
return list;
}
/**
* 查询某个文档的备份内容
* @param fileName
* @return
* @throws Exception
*/
public HelpInfo findHelpBakCommentByName(String fileName){
HelpInfo helpInfo = getCacheBakHelpInfo(fileName);
if(helpInfo==null){
List<HelpInfo> list = dao.findBakComment(fileName);
if(list!=null&&list.size()>0){
helpInfo= list.get(0);
}
}
return helpInfo;
}
/**
* 查询所有文档的备份内容
* @return
*/
public List<HelpInfo> findHelpBakComments(){
List<HelpInfo> list = dao.findBakComment(null);
return list;
}
/**
* 从数据库获取所有的帮助文档信息
* @return
*/
public List<HelpInfo> findAllHelpComments(){
List<HelpInfo> list = dao.findAllComment();
return list;
}
public void saveHelpInfo(HelpInfo helpInfo){
Jedis jedis=jedisPool.getResource();
try {
if(jedis!=null){
String fileName=helpInfo.getFileName();
String oldComment=jedis.get(HELP_CACHE_PRE+fileName);
if(StringUtils.strIsBlank(oldComment)){//redis宕机等意外原因导致获取不到信息从数据库中读取
List<HelpInfo> list = dao.findComment(fileName);
if(list!=null&&list.size()>0){
oldComment=list.get(0).getFileComment();
}
}
pool.execute(new SaveHelpInfoThread(jedisPool,HELP_CACHE_PRE+fileName, helpInfo.getFileComment(), -1));
pool.execute(new SaveHelpInfoThread(jedisPool,BACK_HELP_CACHE_PRE+fileName, oldComment, -1));
}
} catch (Exception e) {
logger.error("save help info to cache error",e);
}finally{
jedis.close();
}
dao.saveHelpInfo(helpInfo);
}
/**
* 缓存帮助文档
* @throws Exception
*/
public void cacheAllHelpInfo() {
Jedis jedis=jedisPool.getResource();
if(jedis==null) {
return;
}
try {
String cacheFlag = jedis.get(HELP_CACHE_FLAG);
if(StringUtils.strIsBlank(cacheFlag)||!cacheFlag.equals("true")){
logger.info("start cache help document");
long startTime=System.currentTimeMillis();
List<HelpInfo> helpInfos = findAllHelpComments();
for (HelpInfo helpInfo : helpInfos) {
String helpFileName=helpInfo.getFileName();
String key=HELP_CACHE_PRE+helpFileName;
String backKey=BACK_HELP_CACHE_PRE+helpFileName;
String fileComment = helpInfo.getFileComment();
String backFileComment = helpInfo.getBackFileComment();
if(!StringUtils.strIsBlank(fileComment)){
pool.execute(new SaveHelpInfoThread(jedisPool,key,fileComment , -1));
}
if(!StringUtils.strIsBlank(backFileComment)){
pool.execute(new SaveHelpInfoThread(jedisPool,backKey, helpInfo.getBackFileComment(), -1));
}
}
pool.execute(new SaveHelpInfoThread(jedisPool,HELP_CACHE_FLAG, "true", -1));
long endTime=System.currentTimeMillis();
logger.info("cache help info complate Time--> "+(endTime-startTime)+"ms");
}
} catch (Exception e) {
logger.error("cache Help Info error",e);
return ;
}finally{
jedis.close();
}
}
/**
* 从redis缓存中获取帮助文档
* @param fileName
* @return
*/
public HelpInfo getCacheHelpInfo(String fileName){
Jedis jedis=jedisPool.getResource();
if(jedis==null){
return null;
}
try {
String comment = jedis.get(HELP_CACHE_PRE+fileName);
HelpInfo helpInfo = new HelpInfo();
helpInfo.setFileComment(comment);
return helpInfo;
} catch (Exception e) {
logger.error("get Help Info error",e);
return null;
}finally{
jedis.close();
}
}
/**
* 从redis缓存中获取帮助文档备份
* @param fileName
* @return
*/
public HelpInfo getCacheBakHelpInfo(String fileName) {
Jedis jedis=jedisPool.getResource();
if(jedis==null){
return null;
}
try {
String backComment = jedis.get(BACK_HELP_CACHE_PRE+fileName);
HelpInfo helpInfo = new HelpInfo();
helpInfo.setBackFileComment(backComment);
return helpInfo;
} catch (Exception e) {
logger.error("get back Help Info error",e);
return null;
}finally{
jedis.close();
}
}
}