Commit 0dc0c8af by fsn

整理

parent f38ee05b
#Guns
一款简洁并且通用的后台管理系统!整合了spring+mybatis-plus+beetl!
\ No newline at end of file
一款简洁通用的后台管理系统!整合了spring+mybatis-plus+beetl!
\ No newline at end of file
......@@ -73,7 +73,7 @@ public class BaseController {
/**
* 删除cookie
*/
protected void deletePhoneCookie(String cookieName) {
protected void deleteCookieByName(String cookieName) {
Cookie[] cookies = this.getHttpServletRequest().getCookies();
for (Cookie cookie : cookies) {
if (cookie.getName().equals(cookieName)) {
......
package com.stylefeng.guns.core.aop;
import com.stylefeng.guns.core.log.ILog;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.shiro.ShiroUser;
import com.stylefeng.guns.core.support.StrKit;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import org.apache.log4j.Logger;
......@@ -8,53 +12,57 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
/**
* @Description 日志记录
* @author fengshuonan
* @Description 日志记录
* @date 2016年12月6日 下午8:48:30
*/
@Aspect
@Component
public class LogAop {
private Logger log = Logger.getLogger(this.getClass());
@Pointcut("execution(* com.stylefeng.guns.*..service.*.*(..))")
public void cutService() {
}
@Around("cutService()")
public Object recordSysLog(ProceedingJoinPoint point) throws Throwable {
//获取拦截的方法名
MethodSignature ms = (MethodSignature) point.getSignature();
Method method = ms.getMethod();
String methodName = method.getName();
//如果当前用户未登录,不做日志
// ShiroUser user = ShiroKit.getUser();
// if(null == user){
// return point.proceed();
// }
//获取拦截方法的参数
String className = point.getTarget().getClass().getName();
Object[] params = point.getArgs();
StringBuilder sb = new StringBuilder();
for(Object param : params){
sb.append(param);
sb.append(" & ");
}
String msg = ToolUtil.format("[时间]:{} [类名]:{} [方法]:{} [参数]:{}", DateUtil.getTime(), className, methodName, sb.toString());
// LogFactory.me().doLog("例如:新增",msg,true);
log.info(msg);
return point.proceed();
}
private Logger log = Logger.getLogger(this.getClass());
@Autowired
ILog factory;
@Pointcut("execution(* com.stylefeng.guns..service.*.*(..))")
public void cutService() {
}
@Around("cutService()")
public Object recordSysLog(ProceedingJoinPoint point) throws Throwable {
//获取拦截的方法名
MethodSignature ms = (MethodSignature) point.getSignature();
Method method = ms.getMethod();
String methodName = method.getName();
//如果当前用户未登录,不做日志
ShiroUser user = ShiroKit.getUser();
if (null == user) {
return point.proceed();
}
//获取拦截方法的参数
String className = point.getTarget().getClass().getName();
Object[] params = point.getArgs();
StringBuilder sb = new StringBuilder();
for (Object param : params) {
sb.append(param);
sb.append(" & ");
}
String msg = ToolUtil.format("[时间]:{} [类名]:{} [方法]:{} [参数]:{}", DateUtil.getTime(), className, methodName, sb.toString());
log.info(StrKit.removeSuffix(msg, "& "));
factory.doLog(methodName, StrKit.removeSuffix(msg, "& "), true);
return point.proceed();
}
}
\ No newline at end of file
package com.stylefeng.guns.core.beetl;
public class Feng {
public Integer parseInt(Double value){
if(value != null){
return value.intValue();
}else{
return 0;
}
}
}
......@@ -9,7 +9,8 @@ package com.stylefeng.guns.core.log;
public interface ILog {
/**
* @Description 日志记录
* 日志记录
*
* @author fengshuonan
*/
void doLog(String logName, String msg, boolean succeed);
......
package com.stylefeng.guns.core.log;
import org.springframework.context.annotation.DependsOn;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.shiro.ShiroUser;
import com.stylefeng.guns.persistence.dao.OperationLogMapper;
import com.stylefeng.guns.persistence.model.OperationLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.stylefeng.guns.core.util.SpringContextHolder;
import java.util.Date;
/**
* 日志记录工厂
......@@ -12,34 +16,20 @@ import com.stylefeng.guns.core.util.SpringContextHolder;
* @date 2016年12月6日 下午9:18:27
*/
@Component
@DependsOn("springContextHolder")
public class LogFactory implements ILog {
private LogFactory() {
}
public static ILog me() {
return SpringContextHolder.getBean(ILog.class);
}
@Autowired
OperationLogMapper operationLogMapper;
@Override
public void doLog(String logName, String msg, boolean succeed) {
//添加到数据库
// ShiroUser user = ShiroKit.getUser();
// if (null == user) {
// return true;
// }
// try {
// OperationLog log = new OperationLog();
// log.setMethod(msg);
// log.setCreatetime(new Date());
// log.setSucceed((succeed)?"1":"0");
// log.setUserid(Func.toStr(user.getId()));
// log.setLogname(logName);
// boolean temp = Blade.create(OperationLog.class).save(log);
// return temp;
// } catch (Exception ex) {
// return false;
// }
ShiroUser user = ShiroKit.getUser();
OperationLog log = new OperationLog();
log.setMethod(msg);
log.setCreatetime(new Date());
log.setSucceed((succeed) ? "1" : "0");
log.setUserid(String.valueOf(user.getId()));
log.setLogname(logName);
operationLogMapper.insert(log);
}
}
......@@ -13,12 +13,12 @@ public class ShiroUser implements Serializable {
private static final long serialVersionUID = 1L;
public Integer id; // 主键ID
public String account; // 账号
public String name; // 姓名
public Integer deptId; // 部门id
public Integer id; // 主键ID
public String account; // 账号
public String name; // 姓名
public Integer deptId; // 部门id
public List<Integer> roleList; // 角色集
public String deptName; // 部门名称
public String deptName; // 部门名称
public List<String> roleNames; // 角色名称集
......
package project.config.web.beetl;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
import com.stylefeng.guns.core.beetl.Feng;
import com.stylefeng.guns.core.beetl.ShiroExt;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
public class BeetlConfiguration extends BeetlGroupUtilConfiguration {
......@@ -11,7 +9,7 @@ public class BeetlConfiguration extends BeetlGroupUtilConfiguration {
public void initOther() {
groupTemplate.registerFunctionPackage("shiro", new ShiroExt());
groupTemplate.registerFunctionPackage("feng", new Feng());
}
}
......@@ -32,30 +32,22 @@ public class MpGenerator {
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir("D:\\ideaSpace\\guns\\src\\main\\java");
gc.setOutputDir("D:\\ideaSpace\\guns\\src\\main\\java");//这里写你自己的java目录
gc.setFileOverride(true);
gc.setActiveRecord(true);
gc.setEnableCache(false);// XML 二级缓存
gc.setBaseResultMap(true);// XML ResultMap
gc.setBaseColumnList(false);// XML columList
gc.setAuthor("stylefeng");
// 自定义文件命名,注意 %s 会自动填充表实体属性!
// gc.setMapperName("%sMapper");
// gc.setXmlName("%sMapper");
// gc.setServiceName(null);
// gc.setServiceImplName(null);
// gc.setControllerName(null);
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.MYSQL);
dsc.setTypeConvert(new MySqlTypeConvert(){
dsc.setTypeConvert(new MySqlTypeConvert() {
// 自定义数据库表字段类型转换【可选】
@Override
public DbColumnType processTypeConvert(String fieldType) {
// System.out.println("转换类型:" + fieldType);
return super.processTypeConvert(fieldType);
}
});
......@@ -67,30 +59,12 @@ public class MpGenerator {
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setTablePrefix(new String[]{"dd_","_"});// 此处可以修改为您的表前缀
strategy.setTablePrefix(new String[]{"_"});// 此处可以修改为您的表前缀
strategy.setNaming(NamingStrategy.remove_prefix_and_camel);// 表名生成策略
// strategy.setInclude(new String[] { "user" }); // 需要生成的表
// strategy.setExclude(new String[]{"test"}); // 排除生成的表
// 字段名生成策略
strategy.setFieldNaming(NamingStrategy.nochange);
// 自定义实体父类
// strategy.setSuperEntityClass("com.baomidou.demo.TestEntity");
// 自定义实体,公共字段
// strategy.setSuperEntityColumns(new String[] { "test_id", "age" });
// 自定义 mapper 父类
// strategy.setSuperMapperClass("com.baomidou.demo.TestMapper");
// 自定义 service 父类
// strategy.setSuperServiceClass("com.baomidou.demo.TestService");
// 自定义 service 实现类父类
// strategy.setSuperServiceImplClass("com.baomidou.demo.TestServiceImpl");
// 自定义 controller 父类
// strategy.setSuperControllerClass("com.baomidou.demo.TestController");
// 【实体】是否生成字段常量(默认 false)
// public static final String ID = "test_id";
// strategy.setEntityColumnConstant(true);
// 【实体】是否为构建者模型(默认 false)
// public User setName(String name) {this.name = name; return this;}
// strategy.setEntityBuliderModel(true);
mpg.setStrategy(strategy);
// 包配置
......@@ -108,34 +82,13 @@ public class MpGenerator {
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("abc", this.getConfig().getGlobalConfig().getAuthor() + "-mp");
this.setMap(map);
}
};
// 自定义 xxList.jsp 生成
// List<FileOutConfig> focList = new ArrayList<FileOutConfig>();
// focList.add(new FileOutConfig("/template/list.jsp.vm") {
// @Override
// public String outputFile(TableInfo tableInfo) {
// // 自定义输入文件名称
// return "D://my_" + tableInfo.getEntityName() + ".jsp";
// }
// });
// cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
// 自定义模板配置,可以 copy 源码 mybatis-plus/src/main/resources/template 下面内容修改,
// 放置自己项目的 src/main/resources/template 目录下, 默认名称一下可以不配置,也可以自定义模板名称
// TemplateConfig tc = new TemplateConfig();
// tc.setController("...");
// tc.setEntity("...");
// tc.setMapper("...");
// tc.setXml("...");
// tc.setService("...");
// tc.setServiceImpl("...");
// mpg.setTemplate(tc);
// 执行生成
mpg.execute();
......
......@@ -2,81 +2,73 @@
<script type="text/javascript">
$(function() {
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
$("#btn_close").bind("click", function() {
parent.layer.close(index);
});
$("#btn_save").bind(
"click",
function() {
var zTree = $.fn.zTree.getZTreeObj("zTree");
var nodes = zTree.getCheckedNodes();
var ids = "";
for (var i = 0, l = nodes.length; i < l; i++) {
ids += "," + nodes[i].id;
}
ids = ids.substring(1);
$(function () {
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
var ajax = new $ax(Feng.ctxPath + "/role/setAuthority",
function(data) {
Feng.success("分配角色成功!");
window.parent.Role.table.refresh();
parent.layer.close(index);
}, function(data) {
Feng.error("分配角色失败!"
+ data.responseJSON.message + "!");
});
ajax.set("roleId", "${roleId}");
ajax.set("ids", ids);
ajax.start();
});
$("#btn_close").bind("click", function () {
parent.layer.close(index);
});
initZtree();
});
$("#btn_save").bind("click", function () {
var ids = Feng.zTreeCheckedNodes("zTree");
var ajax = new $ax(Feng.ctxPath + "/role/setAuthority", function (data) {
Feng.success("分配角色成功!");
window.parent.Role.table.refresh();
parent.layer.close(index);
}, function (data) {
Feng.error("分配角色失败!"
+ data.responseJSON.message + "!");
});
ajax.set("roleId", "${roleId}");
ajax.set("ids", ids);
ajax.start();
});
function initZtree() {
var setting = {
check : {
enable : true
},
data : {
simpleData : {
enable : true
}
}
};
initZtree();
});
var ztree = new $ZTree("zTree", "/menu/menuTreeListByRoleId/"
+ "${roleId}");
ztree.setSettings(setting);
ztree.init();
}
function initZtree() {
var setting = {
check: {
enable: true
},
data: {
simpleData: {
enable: true
}
}
};
var ztree = new $ZTree("zTree", "/menu/menuTreeListByRoleId/"
+ "${roleId}");
ztree.setSettings(setting);
ztree.init();
}
</script>
<!-- 配置grid -->
<div class="container" style="padding: 0px 10px !important;margin-top: -10px;text-align: center !important;">
<div class="row">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>${roleName!}</h5>
</div>
<div class="ibox-content">
<ul id="zTree" class="ztree"></ul>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-info" type="button" id="btn_save">
<i class="ace-icon fa fa-check bigger-110"></i>保存
</button>
&nbsp;
<button class="btn btn-sm btn-danger" type="button" id="btn_close">
<i class="ace-icon fa fa-close bigger-110"></i>关闭
</button>
</div>
</div>
<div class="row">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>${roleName!}</h5>
</div>
<div class="ibox-content">
<ul id="zTree" class="ztree"></ul>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-info" type="button" id="btn_save">
<i class="ace-icon fa fa-check bigger-110"></i>保存
</button>
&nbsp;
<button class="btn btn-sm btn-danger" type="button" id="btn_close">
<i class="ace-icon fa fa-close bigger-110"></i>关闭
</button>
</div>
</div>
</div>
@}
......@@ -2,83 +2,78 @@
<script type="text/javascript">
$(function() {
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
$("#btn_close").bind("click", function() {
parent.layer.close(index);
});
$("#btn_save").bind("click", function() {
var zTree = $.fn.zTree.getZTreeObj("zTree");
var nodes = zTree.getCheckedNodes();
var ids = "";
for (var i = 0, l = nodes.length; i < l; i++) {
ids += "," + nodes[i].id;
}
ids = ids.substring(1);
$(function () {
var ajax = new $ax(Feng.ctxPath + "/mgr/setRole", function(data) {
Feng.success("分配角色成功!");
window.parent.MgrUser.table.refresh();
parent.layer.close(index);
}, function(data) {
Feng.error("分配角色失败!" + data.responseJSON.message + "!");
});
ajax.set("roleIds", ids);
ajax.set("userId", "${userId}");
ajax.start();
});
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
initZtree();
});
$("#btn_close").bind("click", function () {
parent.layer.close(index);
});
function initZtree() {
var setting = {
check : {
enable : true,
chkboxType : {
"Y" : "",
"N" : ""
}
},
data : {
simpleData : {
enable : true
}
}
};
$("#btn_save").bind("click", function () {
var ids = Feng.zTreeCheckedNodes("zTree");
var ajax = new $ax(Feng.ctxPath + "/mgr/setRole", function (data) {
Feng.success("分配角色成功!");
window.parent.MgrUser.table.refresh();
parent.layer.close(index);
}, function (data) {
Feng.error("分配角色失败!" + data.responseJSON.message + "!");
});
ajax.set("roleIds", ids);
ajax.set("userId", "${userId}");
ajax.start();
});
var ztree = new $ZTree("zTree", "/role/roleTreeListByUserId/"
+ "${userId}");
ztree.setSettings(setting);
ztree.init();
}
initZtree();
});
function initZtree() {
var setting = {
check: {
enable: true,
chkboxType: {
"Y": "",
"N": ""
}
},
data: {
simpleData: {
enable: true
}
}
};
var ztree = new $ZTree("zTree", "/role/roleTreeListByUserId/${userId}");
ztree.setSettings(setting);
ztree.init();
}
</script>
<!-- 配置grid -->
<div class="container"
style="padding: 0px 10px !important; margin-top: -10px; text-align: center !important;">
<div class="row">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>${userAccount!}</h5>
</div>
<div class="ibox-content">
<ul id="zTree" class="ztree"></ul>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-info" type="button" id="btn_save">
<i class="ace-icon fa fa-check bigger-110"></i> 保存
</button>
&nbsp;
<button class="btn btn-sm btn-danger" type="button" id="btn_close">
<i class="ace-icon fa fa-close bigger-110"></i> 关闭
</button>
</div>
</div>
style="padding: 0px 10px !important; margin-top: -10px; text-align: center !important;">
<div class="row">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>${userAccount!}</h5>
</div>
<div class="ibox-content">
<ul id="zTree" class="ztree"></ul>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-info" type="button" id="btn_save">
<i class="ace-icon fa fa-check bigger-110"></i> 保存
</button>
&nbsp;
<button class="btn btn-sm btn-danger" type="button" id="btn_close">
<i class="ace-icon fa fa-close bigger-110"></i> 关闭
</button>
</div>
</div>
</div>
@}
var Feng = {
ctxPath : "",
addCtx : function(ctx) {
if (this.ctxPath == "") {
this.ctxPath = ctx;
}
},
log : function(info) {
console.log(info);
},
alert : function(info, iconIndex) {
parent.layer.msg(info, {
icon : iconIndex
});
},
info : function(info) {
Feng.alert(info, 0);
},
success : function(info) {
Feng.alert(info, 1);
},
error : function(info) {
Feng.alert(info, 2);
},
writeObj : function(obj) {
var description = "";
for ( var i in obj) {
var property = obj[i];
description += i + " = " + property + ",";
}
layer.alert(description, {
skin : 'layui-layer-molv',
closeBtn : 0
});
},
showInputTree : function(inputId,inputTreeContentId) {
var onBodyDown = function(event) {
if (!(event.target.id == "menuBtn" || event.target.id == inputTreeContentId || $(event.target).parents("#" + inputTreeContentId).length > 0)) {
$("#" + inputTreeContentId).fadeOut("fast");
$("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发,不用弹起
}
};
var inputDiv = $("#" + inputId);
var inputDivOffset = $("#" + inputId).offset();
$("#" + inputTreeContentId).css({
left : inputDivOffset.left + "px",
top : inputDivOffset.top + inputDiv.outerHeight() + "px"
}).slideDown("fast");
ctxPath: "",
addCtx: function (ctx) {
if (this.ctxPath == "") {
this.ctxPath = ctx;
}
},
log: function (info) {
console.log(info);
},
alert: function (info, iconIndex) {
parent.layer.msg(info, {
icon: iconIndex
});
},
info: function (info) {
Feng.alert(info, 0);
},
success: function (info) {
Feng.alert(info, 1);
},
error: function (info) {
Feng.alert(info, 2);
},
writeObj: function (obj) {
var description = "";
for (var i in obj) {
var property = obj[i];
description += i + " = " + property + ",";
}
layer.alert(description, {
skin: 'layui-layer-molv',
closeBtn: 0
});
},
showInputTree: function (inputId, inputTreeContentId) {
var onBodyDown = function (event) {
if (!(event.target.id == "menuBtn" || event.target.id == inputTreeContentId || $(event.target).parents("#" + inputTreeContentId).length > 0)) {
$("#" + inputTreeContentId).fadeOut("fast");
$("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发,不用弹起
}
};
$("body").bind("mousedown", onBodyDown);
},
baseAjax : function(url,tip){
var ajax = new $ax(Feng.ctxPath + url, function(data){
Feng.success(tip + "成功!");
},function(data){
Feng.error(tip + "失败!" + data.responseJSON.message + "!");
});
return ajax;
},
changeAjax : function(url){
return Feng.baseAjax(url,"修改");
},
addAjax : function(url){
return Feng.baseAjax(url,"添加");
}
var inputDiv = $("#" + inputId);
var inputDivOffset = $("#" + inputId).offset();
$("#" + inputTreeContentId).css({
left: inputDivOffset.left + "px",
top: inputDivOffset.top + inputDiv.outerHeight() + "px"
}).slideDown("fast");
$("body").bind("mousedown", onBodyDown);
},
baseAjax: function (url, tip) {
var ajax = new $ax(Feng.ctxPath + url, function (data) {
Feng.success(tip + "成功!");
}, function (data) {
Feng.error(tip + "失败!" + data.responseJSON.message + "!");
});
return ajax;
},
changeAjax: function (url) {
return Feng.baseAjax(url, "修改");
},
zTreeCheckedNodes: function (zTreeId) {
var zTree = $.fn.zTree.getZTreeObj(zTreeId);
var nodes = zTree.getCheckedNodes();
var ids = "";
for (var i = 0, l = nodes.length; i < l; i++) {
ids += "," + nodes[i].id;
}
return ids.substring(1);
}
};
package com.stylefeng.guns.base;
import com.stylefeng.guns.core.log.ILog;
import com.stylefeng.guns.core.util.SpringContextHolder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
......@@ -10,4 +13,11 @@ import project.config.root.RootSpringConfig;
@ContextConfiguration(classes = RootSpringConfig.class)
public class BaseTest {
@Test
public void test() {
ILog logFactory = SpringContextHolder.getBean(ILog.class);
logFactory.doLog("12", "message", true);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment