Commit 0dc0c8af by fsn

整理

parent f38ee05b
#Guns #Guns
一款简洁并且通用的后台管理系统!整合了spring+mybatis-plus+beetl! 一款简洁通用的后台管理系统!整合了spring+mybatis-plus+beetl!
\ No newline at end of file \ No newline at end of file
...@@ -73,7 +73,7 @@ public class BaseController { ...@@ -73,7 +73,7 @@ public class BaseController {
/** /**
* 删除cookie * 删除cookie
*/ */
protected void deletePhoneCookie(String cookieName) { protected void deleteCookieByName(String cookieName) {
Cookie[] cookies = this.getHttpServletRequest().getCookies(); Cookie[] cookies = this.getHttpServletRequest().getCookies();
for (Cookie cookie : cookies) { for (Cookie cookie : cookies) {
if (cookie.getName().equals(cookieName)) { if (cookie.getName().equals(cookieName)) {
......
package com.stylefeng.guns.core.aop; 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.DateUtil;
import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.core.util.ToolUtil;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
...@@ -8,13 +12,14 @@ import org.aspectj.lang.annotation.Around; ...@@ -8,13 +12,14 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature; import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.lang.reflect.Method; import java.lang.reflect.Method;
/** /**
* @Description 日志记录
* @author fengshuonan * @author fengshuonan
* @Description 日志记录
* @date 2016年12月6日 下午8:48:30 * @date 2016年12月6日 下午8:48:30
*/ */
@Aspect @Aspect
...@@ -23,7 +28,10 @@ public class LogAop { ...@@ -23,7 +28,10 @@ public class LogAop {
private Logger log = Logger.getLogger(this.getClass()); private Logger log = Logger.getLogger(this.getClass());
@Pointcut("execution(* com.stylefeng.guns.*..service.*.*(..))") @Autowired
ILog factory;
@Pointcut("execution(* com.stylefeng.guns..service.*.*(..))")
public void cutService() { public void cutService() {
} }
...@@ -36,24 +44,24 @@ public class LogAop { ...@@ -36,24 +44,24 @@ public class LogAop {
String methodName = method.getName(); String methodName = method.getName();
//如果当前用户未登录,不做日志 //如果当前用户未登录,不做日志
// ShiroUser user = ShiroKit.getUser(); ShiroUser user = ShiroKit.getUser();
// if(null == user){ if (null == user) {
// return point.proceed(); return point.proceed();
// } }
//获取拦截方法的参数 //获取拦截方法的参数
String className = point.getTarget().getClass().getName(); String className = point.getTarget().getClass().getName();
Object[] params = point.getArgs(); Object[] params = point.getArgs();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for(Object param : params){ for (Object param : params) {
sb.append(param); sb.append(param);
sb.append(" & "); sb.append(" & ");
} }
String msg = ToolUtil.format("[时间]:{} [类名]:{} [方法]:{} [参数]:{}", DateUtil.getTime(), className, methodName, sb.toString()); String msg = ToolUtil.format("[时间]:{} [类名]:{} [方法]:{} [参数]:{}", DateUtil.getTime(), className, methodName, sb.toString());
// LogFactory.me().doLog("例如:新增",msg,true); log.info(StrKit.removeSuffix(msg, "& "));
log.info(msg); factory.doLog(methodName, StrKit.removeSuffix(msg, "& "), true);
return point.proceed(); return point.proceed();
} }
......
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; ...@@ -9,7 +9,8 @@ package com.stylefeng.guns.core.log;
public interface ILog { public interface ILog {
/** /**
* @Description 日志记录 * 日志记录
*
* @author fengshuonan * @author fengshuonan
*/ */
void doLog(String logName, String msg, boolean succeed); void doLog(String logName, String msg, boolean succeed);
......
package com.stylefeng.guns.core.log; 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 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; ...@@ -12,34 +16,20 @@ import com.stylefeng.guns.core.util.SpringContextHolder;
* @date 2016年12月6日 下午9:18:27 * @date 2016年12月6日 下午9:18:27
*/ */
@Component @Component
@DependsOn("springContextHolder")
public class LogFactory implements ILog { public class LogFactory implements ILog {
private LogFactory() { @Autowired
} OperationLogMapper operationLogMapper;
public static ILog me() {
return SpringContextHolder.getBean(ILog.class);
}
@Override @Override
public void doLog(String logName, String msg, boolean succeed) { public void doLog(String logName, String msg, boolean succeed) {
//添加到数据库 ShiroUser user = ShiroKit.getUser();
// ShiroUser user = ShiroKit.getUser(); OperationLog log = new OperationLog();
// if (null == user) { log.setMethod(msg);
// return true; log.setCreatetime(new Date());
// } log.setSucceed((succeed) ? "1" : "0");
// try { log.setUserid(String.valueOf(user.getId()));
// OperationLog log = new OperationLog(); log.setLogname(logName);
// log.setMethod(msg); operationLogMapper.insert(log);
// 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;
// }
} }
} }
package project.config.web.beetl; 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 com.stylefeng.guns.core.beetl.ShiroExt;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
public class BeetlConfiguration extends BeetlGroupUtilConfiguration { public class BeetlConfiguration extends BeetlGroupUtilConfiguration {
...@@ -11,7 +9,7 @@ public class BeetlConfiguration extends BeetlGroupUtilConfiguration { ...@@ -11,7 +9,7 @@ public class BeetlConfiguration extends BeetlGroupUtilConfiguration {
public void initOther() { public void initOther() {
groupTemplate.registerFunctionPackage("shiro", new ShiroExt()); groupTemplate.registerFunctionPackage("shiro", new ShiroExt());
groupTemplate.registerFunctionPackage("feng", new Feng());
} }
} }
...@@ -32,30 +32,22 @@ public class MpGenerator { ...@@ -32,30 +32,22 @@ public class MpGenerator {
// 全局配置 // 全局配置
GlobalConfig gc = new GlobalConfig(); 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.setFileOverride(true);
gc.setActiveRecord(true); gc.setActiveRecord(true);
gc.setEnableCache(false);// XML 二级缓存 gc.setEnableCache(false);// XML 二级缓存
gc.setBaseResultMap(true);// XML ResultMap gc.setBaseResultMap(true);// XML ResultMap
gc.setBaseColumnList(false);// XML columList gc.setBaseColumnList(false);// XML columList
gc.setAuthor("stylefeng"); gc.setAuthor("stylefeng");
// 自定义文件命名,注意 %s 会自动填充表实体属性!
// gc.setMapperName("%sMapper");
// gc.setXmlName("%sMapper");
// gc.setServiceName(null);
// gc.setServiceImplName(null);
// gc.setControllerName(null);
mpg.setGlobalConfig(gc); mpg.setGlobalConfig(gc);
// 数据源配置 // 数据源配置
DataSourceConfig dsc = new DataSourceConfig(); DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.MYSQL); dsc.setDbType(DbType.MYSQL);
dsc.setTypeConvert(new MySqlTypeConvert(){ dsc.setTypeConvert(new MySqlTypeConvert() {
// 自定义数据库表字段类型转换【可选】 // 自定义数据库表字段类型转换【可选】
@Override @Override
public DbColumnType processTypeConvert(String fieldType) { public DbColumnType processTypeConvert(String fieldType) {
// System.out.println("转换类型:" + fieldType);
return super.processTypeConvert(fieldType); return super.processTypeConvert(fieldType);
} }
}); });
...@@ -67,30 +59,12 @@ public class MpGenerator { ...@@ -67,30 +59,12 @@ public class MpGenerator {
// 策略配置 // 策略配置
StrategyConfig strategy = new StrategyConfig(); StrategyConfig strategy = new StrategyConfig();
strategy.setTablePrefix(new String[]{"dd_","_"});// 此处可以修改为您的表前缀 strategy.setTablePrefix(new String[]{"_"});// 此处可以修改为您的表前缀
strategy.setNaming(NamingStrategy.remove_prefix_and_camel);// 表名生成策略 strategy.setNaming(NamingStrategy.remove_prefix_and_camel);// 表名生成策略
// strategy.setInclude(new String[] { "user" }); // 需要生成的表 // strategy.setInclude(new String[] { "user" }); // 需要生成的表
// strategy.setExclude(new String[]{"test"}); // 排除生成的表 // strategy.setExclude(new String[]{"test"}); // 排除生成的表
// 字段名生成策略 // 字段名生成策略
strategy.setFieldNaming(NamingStrategy.nochange); 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); mpg.setStrategy(strategy);
// 包配置 // 包配置
...@@ -108,34 +82,13 @@ public class MpGenerator { ...@@ -108,34 +82,13 @@ public class MpGenerator {
InjectionConfig cfg = new InjectionConfig() { InjectionConfig cfg = new InjectionConfig() {
@Override @Override
public void initMap() { 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"); map.put("abc", this.getConfig().getGlobalConfig().getAuthor() + "-mp");
this.setMap(map); 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); 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(); mpg.execute();
......
...@@ -2,28 +2,20 @@ ...@@ -2,28 +2,20 @@
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function () {
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引 var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
$("#btn_close").bind("click", function() {
$("#btn_close").bind("click", function () {
parent.layer.close(index); 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);
var ajax = new $ax(Feng.ctxPath + "/role/setAuthority", $("#btn_save").bind("click", function () {
function(data) { var ids = Feng.zTreeCheckedNodes("zTree");
var ajax = new $ax(Feng.ctxPath + "/role/setAuthority", function (data) {
Feng.success("分配角色成功!"); Feng.success("分配角色成功!");
window.parent.Role.table.refresh(); window.parent.Role.table.refresh();
parent.layer.close(index); parent.layer.close(index);
}, function(data) { }, function (data) {
Feng.error("分配角色失败!" Feng.error("分配角色失败!"
+ data.responseJSON.message + "!"); + data.responseJSON.message + "!");
}); });
...@@ -37,12 +29,12 @@ ...@@ -37,12 +29,12 @@
function initZtree() { function initZtree() {
var setting = { var setting = {
check : { check: {
enable : true enable: true
}, },
data : { data: {
simpleData : { simpleData: {
enable : true enable: true
} }
} }
}; };
......
...@@ -2,25 +2,21 @@ ...@@ -2,25 +2,21 @@
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function () {
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引 var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
$("#btn_close").bind("click", function() {
$("#btn_close").bind("click", function () {
parent.layer.close(index); 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);
var ajax = new $ax(Feng.ctxPath + "/mgr/setRole", function(data) { $("#btn_save").bind("click", function () {
var ids = Feng.zTreeCheckedNodes("zTree");
var ajax = new $ax(Feng.ctxPath + "/mgr/setRole", function (data) {
Feng.success("分配角色成功!"); Feng.success("分配角色成功!");
window.parent.MgrUser.table.refresh(); window.parent.MgrUser.table.refresh();
parent.layer.close(index); parent.layer.close(index);
}, function(data) { }, function (data) {
Feng.error("分配角色失败!" + data.responseJSON.message + "!"); Feng.error("分配角色失败!" + data.responseJSON.message + "!");
}); });
ajax.set("roleIds", ids); ajax.set("roleIds", ids);
...@@ -33,22 +29,21 @@ ...@@ -33,22 +29,21 @@
function initZtree() { function initZtree() {
var setting = { var setting = {
check : { check: {
enable : true, enable: true,
chkboxType : { chkboxType: {
"Y" : "", "Y": "",
"N" : "" "N": ""
} }
}, },
data : { data: {
simpleData : { simpleData: {
enable : true enable: true
} }
} }
}; };
var ztree = new $ZTree("zTree", "/role/roleTreeListByUserId/" var ztree = new $ZTree("zTree", "/role/roleTreeListByUserId/${userId}");
+ "${userId}");
ztree.setSettings(setting); ztree.setSettings(setting);
ztree.init(); ztree.init();
} }
......
var Feng = { var Feng = {
ctxPath : "", ctxPath: "",
addCtx : function(ctx) { addCtx: function (ctx) {
if (this.ctxPath == "") { if (this.ctxPath == "") {
this.ctxPath = ctx; this.ctxPath = ctx;
} }
}, },
log : function(info) { log: function (info) {
console.log(info); console.log(info);
}, },
alert : function(info, iconIndex) { alert: function (info, iconIndex) {
parent.layer.msg(info, { parent.layer.msg(info, {
icon : iconIndex icon: iconIndex
}); });
}, },
info : function(info) { info: function (info) {
Feng.alert(info, 0); Feng.alert(info, 0);
}, },
success : function(info) { success: function (info) {
Feng.alert(info, 1); Feng.alert(info, 1);
}, },
error : function(info) { error: function (info) {
Feng.alert(info, 2); Feng.alert(info, 2);
}, },
writeObj : function(obj) { writeObj: function (obj) {
var description = ""; var description = "";
for ( var i in obj) { for (var i in obj) {
var property = obj[i]; var property = obj[i];
description += i + " = " + property + ","; description += i + " = " + property + ",";
} }
layer.alert(description, { layer.alert(description, {
skin : 'layui-layer-molv', skin: 'layui-layer-molv',
closeBtn : 0 closeBtn: 0
}); });
}, },
showInputTree : function(inputId,inputTreeContentId) { showInputTree: function (inputId, inputTreeContentId) {
var onBodyDown = function(event) { var onBodyDown = function (event) {
if (!(event.target.id == "menuBtn" || event.target.id == inputTreeContentId || $(event.target).parents("#" + inputTreeContentId).length > 0)) { if (!(event.target.id == "menuBtn" || event.target.id == inputTreeContentId || $(event.target).parents("#" + inputTreeContentId).length > 0)) {
$("#" + inputTreeContentId).fadeOut("fast"); $("#" + inputTreeContentId).fadeOut("fast");
$("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发,不用弹起 $("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发,不用弹起
...@@ -45,24 +45,30 @@ var Feng = { ...@@ -45,24 +45,30 @@ var Feng = {
var inputDivOffset = $("#" + inputId).offset(); var inputDivOffset = $("#" + inputId).offset();
$("#" + inputTreeContentId).css({ $("#" + inputTreeContentId).css({
left : inputDivOffset.left + "px", left: inputDivOffset.left + "px",
top : inputDivOffset.top + inputDiv.outerHeight() + "px" top: inputDivOffset.top + inputDiv.outerHeight() + "px"
}).slideDown("fast"); }).slideDown("fast");
$("body").bind("mousedown", onBodyDown); $("body").bind("mousedown", onBodyDown);
}, },
baseAjax : function(url,tip){ baseAjax: function (url, tip) {
var ajax = new $ax(Feng.ctxPath + url, function(data){ var ajax = new $ax(Feng.ctxPath + url, function (data) {
Feng.success(tip + "成功!"); Feng.success(tip + "成功!");
},function(data){ }, function (data) {
Feng.error(tip + "失败!" + data.responseJSON.message + "!"); Feng.error(tip + "失败!" + data.responseJSON.message + "!");
}); });
return ajax; return ajax;
}, },
changeAjax : function(url){ changeAjax: function (url) {
return Feng.baseAjax(url,"修改"); return Feng.baseAjax(url, "修改");
}, },
addAjax : function(url){ zTreeCheckedNodes: function (zTreeId) {
return Feng.baseAjax(url,"添加"); 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; 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.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
...@@ -10,4 +13,11 @@ import project.config.root.RootSpringConfig; ...@@ -10,4 +13,11 @@ import project.config.root.RootSpringConfig;
@ContextConfiguration(classes = RootSpringConfig.class) @ContextConfiguration(classes = RootSpringConfig.class)
public class BaseTest { 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