Commit ea7a3616 by fsn

增加字典管理

parent a4db626d
package com.stylefeng.guns.modular.system.controller;
import com.stylefeng.guns.common.annotion.log.BussinessLog;
import com.stylefeng.guns.common.controller.BaseController;
import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.dao.DictDao;
import com.stylefeng.guns.persistence.dao.DictMapper;
import com.stylefeng.guns.persistence.model.Dict;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* 字典控制器
*
* @author fengshuonan
* @Date 2017年4月26日 12:55:31
*/
@Controller
@RequestMapping("/dict")
public class DictController extends BaseController {
private String PREFIX = "/system/dict/";
@Resource
DictDao dictDao;
@Resource
DictMapper dictMapper;
/**
* 跳转到字典管理首页
*/
@RequestMapping("")
public String index() {
return PREFIX + "dict.html";
}
/**
* 跳转到添加字典
*/
@RequestMapping("/dict_add")
public String deptAdd() {
return PREFIX + "dict_add.html";
}
/**
* 跳转到修改字典
*/
@RequestMapping("/dict_edit/{dictId}")
public String deptUpdate(@PathVariable Integer dictId, Model model) {
Dict dict = dictMapper.selectById(dictId);
model.addAttribute(dict);
return PREFIX + "dict_edit.html";
}
/**
* 新增字典
*/
@BussinessLog("添加字典记录")
@RequestMapping(value = "/add")
@ResponseBody
public Object add(Dict dict) {
if (ToolUtil.isOneEmpty(dict, dict.getName())) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
}
return this.dictMapper.insert(dict);
}
/**
* 获取所有字典列表
*/
@RequestMapping(value = "/list")
@ResponseBody
public Object list(String condition) {
List<Map<String, Object>> list = this.dictDao.list(condition);
return list;
}
/**
* 字典详情
*/
@RequestMapping(value = "/detail/{dictId}")
@ResponseBody
public Object detail(@PathVariable("dictId") Integer dictId) {
return dictMapper.selectById(dictId);
}
/**
* 修改字典
*/
@BussinessLog("修改字典")
@RequestMapping(value = "/update")
@ResponseBody
public Object update(Dict dict) {
if (ToolUtil.isEmpty(dict) || dict.getId() == null) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
}
dictMapper.updateById(dict);
return super.SUCCESS_TIP;
}
/**
* 删除字典记录
*/
@BussinessLog(value = "删除字典记录", key = "dictId")
@RequestMapping(value = "/delete/{dictId}")
@ResponseBody
public Object delete(@PathVariable("dictId") Integer dictId) {
dictMapper.deleteById(dictId);
return SUCCESS_TIP;
}
}
...@@ -4,9 +4,10 @@ import com.stylefeng.guns.persistence.model.Dict; ...@@ -4,9 +4,10 @@ import com.stylefeng.guns.persistence.model.Dict;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 常量的dao * 字典的dao
* *
* @author fengshuonan * @author fengshuonan
* @date 2017年2月13日 下午11:10:24 * @date 2017年2月13日 下午11:10:24
...@@ -21,4 +22,12 @@ public interface DictDao { ...@@ -21,4 +22,12 @@ public interface DictDao {
* @date 2017年2月13日 下午11:11:28 * @date 2017年2月13日 下午11:11:28
*/ */
List<Dict> selectByCode(@Param("code") String code); List<Dict> selectByCode(@Param("code") String code);
/**
* 查询字典列表
*
* @author fengshuonan
* @Date 2017/4/26 13:04
*/
List<Map<String,Object>> list(@Param("condition") String conditiion);
} }
...@@ -13,4 +13,12 @@ ...@@ -13,4 +13,12 @@
where code = #{code} where code = #{code}
</select> </select>
<select id="list" resultType="map">
select * from _dict
<if test="condition != null and condition != ''">
where name like CONCAT('%',#{condition},'%') or num like CONCAT('%',#{condition},'%')
</if>
order by code ASC
</select>
</mapper> </mapper>
\ No newline at end of file
@layout("/common/_container.html"){
<div class="row">
<div class="col-sm-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>部门管理</h5>
</div>
<div class="ibox-content">
<div class="row row-lg">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-3">
<#NameCon id="condition" name="名称" />
</div>
<div class="col-sm-3">
<#button name="搜索" icon="fa-search" clickFun="Dict.search()"/>
</div>
</div>
<div class="hidden-xs" id="DictTableToolbar" role="group">
<#button name="添加" icon="fa-plus" clickFun="Dict.openAddDept()"/>
<#button name="修改" icon="fa-plus" clickFun="Dict.openDeptDetail()" space="true"/>
<#button name="删除" icon="fa-plus" clickFun="Dict.delete()" space="true"/>
</div>
<#table id="DictTable"/>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="${ctxPath}/static/modular/system/dict/dict.js"></script>
@}
@layout("/common/_container.html"){
<div class="ibox float-e-margins">
<div class="ibox-content">
<div class="form-horizontal">
<input type="hidden" id="id" value="">
<div class="row">
<div class="col-sm-6 b-r">
<#input id="simplename" name="部门名称" underline="true"/>
<#input id="fullname" name="部门全称" underline="true"/>
<#input id="tips" name="备注" underline="true"/>
</div>
<div class="col-sm-6">
<#input id="num" name="排序" underline="true"/>
<#input id="pName" name="上级部门" readonly="readonly" hidden="pid"
clickFun="DeptInfoDlg.showDeptSelectTree(); return false;"
style="background-color: #ffffff !important;"/>
</div>
</div>
<!-- 父级部门的选择框 -->
<div id="parentDeptMenu" class="menuContent"
style="display: none; position: absolute; z-index: 200;">
<ul id="parentDeptMenuTree" class="ztree tree-box" style="width: 245px !important;"></ul>
</div>
<div class="row btn-group-m-t">
<div class="col-sm-10">
<#button btnCss="info" name="提交" id="ensure" icon="fa-check" clickFun="DeptInfoDlg.addSubmit()"/>
<#button btnCss="danger" name="取消" id="cancel" icon="fa-eraser" clickFun="DeptInfoDlg.close()"/>
</div>
</div>
</div>
</div>
</div>
<script src="${ctxPath}/static/modular/system/dict/dict_info.js"></script>
@}
@layout("/common/_container.html"){
<div class="ibox float-e-margins">
<div class="ibox-content">
<div class="form-horizontal">
<input type="hidden" id="id" value="${dept.id}">
<div class="row">
<div class="col-sm-6 b-r">
<#input id="simplename" name="部门名称" underline="true" value="${dept.simplename}"/>
<#input id="fullname" name="部门全称" underline="true" value="${dept.fullname}"/>
<#input id="tips" name="备注" underline="true" value="${dept.tips}"/>
</div>
<div class="col-sm-6">
<#input id="num" name="排序" underline="true" value="${dept.num}"/>
<#input id="pName" name="上级部门" readonly="readonly" hidden="pid"
hiddenValue="${dept.pid}" value="${pName}"
clickFun="DeptInfoDlg.showDeptSelectTree(); return false;"
style="background-color: #ffffff !important;"/>
</div>
</div>
<!-- 父级部门的选择框 -->
<div id="parentDeptMenu" class="menuContent"
style="display: none; position: absolute; z-index: 200;">
<ul id="parentDeptMenuTree" class="ztree tree-box" style="width: 245px !important;"></ul>
</div>
<div class="row btn-group-m-t">
<div class="col-sm-10">
<#button btnCss="info" name="提交" id="ensure" icon="fa-check" clickFun="DeptInfoDlg.editSubmit()"/>
<#button btnCss="danger" name="取消" id="cancel" icon="fa-eraser" clickFun="DeptInfoDlg.close()"/>
</div>
</div>
</div>
</div>
</div>
<script src="${ctxPath}/static/modular/system/dict/dict_info.js"></script>
@}
...@@ -84,7 +84,7 @@ Dept.delete = function () { ...@@ -84,7 +84,7 @@ Dept.delete = function () {
}; };
/** /**
* 查询日志列表 * 查询部门列表
*/ */
Dept.search = function () { Dept.search = function () {
var queryData = {}; var queryData = {};
......
/** /**
* 初始化部门详情对话框 * 初始化字典详情对话框
*/ */
var DeptInfoDlg = { var DictInfoDlg = {
deptInfoData : {} dictInfoData : {}
}; };
/** /**
* 清除数据 * 清除数据
*/ */
DeptInfoDlg.clearData = function() { DictInfoDlg.clearData = function() {
this.deptInfoData = {}; this.dictInfoData = {};
} }
/** /**
...@@ -18,8 +18,8 @@ DeptInfoDlg.clearData = function() { ...@@ -18,8 +18,8 @@ DeptInfoDlg.clearData = function() {
* @param key 数据的名称 * @param key 数据的名称
* @param val 数据的具体值 * @param val 数据的具体值
*/ */
DeptInfoDlg.set = function(key, val) { DictInfoDlg.set = function(key, val) {
this.deptInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value; this.dictInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
return this; return this;
} }
...@@ -29,15 +29,15 @@ DeptInfoDlg.set = function(key, val) { ...@@ -29,15 +29,15 @@ DeptInfoDlg.set = function(key, val) {
* @param key 数据的名称 * @param key 数据的名称
* @param val 数据的具体值 * @param val 数据的具体值
*/ */
DeptInfoDlg.get = function(key) { DictInfoDlg.get = function(key) {
return $("#" + key).val(); return $("#" + key).val();
} }
/** /**
* 关闭此对话框 * 关闭此对话框
*/ */
DeptInfoDlg.close = function() { DictInfoDlg.close = function() {
parent.layer.close(window.parent.Dept.layerIndex); parent.layer.close(window.parent.Dict.layerIndex);
} }
/** /**
...@@ -48,7 +48,7 @@ DeptInfoDlg.close = function() { ...@@ -48,7 +48,7 @@ DeptInfoDlg.close = function() {
* @param treeNode * @param treeNode
* @returns * @returns
*/ */
DeptInfoDlg.onClickDept = function(e, treeId, treeNode) { DictInfoDlg.onClickDept = function(e, treeId, treeNode) {
$("#pName").attr("value", instance.getSelectedVal()); $("#pName").attr("value", instance.getSelectedVal());
$("#pid").attr("value", treeNode.id); $("#pid").attr("value", treeNode.id);
} }
...@@ -58,7 +58,7 @@ DeptInfoDlg.onClickDept = function(e, treeId, treeNode) { ...@@ -58,7 +58,7 @@ DeptInfoDlg.onClickDept = function(e, treeId, treeNode) {
* *
* @returns * @returns
*/ */
DeptInfoDlg.showDeptSelectTree = function() { DictInfoDlg.showDeptSelectTree = function() {
var pName = $("#pName"); var pName = $("#pName");
var pNameOffset = $("#pName").offset(); var pNameOffset = $("#pName").offset();
$("#parentDeptMenu").css({ $("#parentDeptMenu").css({
...@@ -72,7 +72,7 @@ DeptInfoDlg.showDeptSelectTree = function() { ...@@ -72,7 +72,7 @@ DeptInfoDlg.showDeptSelectTree = function() {
/** /**
* 隐藏部门选择的树 * 隐藏部门选择的树
*/ */
DeptInfoDlg.hideDeptSelectTree = function() { DictInfoDlg.hideDeptSelectTree = function() {
$("#parentDeptMenu").fadeOut("fast"); $("#parentDeptMenu").fadeOut("fast");
$("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发,不用弹起 $("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发,不用弹起
} }
...@@ -80,60 +80,57 @@ DeptInfoDlg.hideDeptSelectTree = function() { ...@@ -80,60 +80,57 @@ DeptInfoDlg.hideDeptSelectTree = function() {
/** /**
* 收集数据 * 收集数据
*/ */
DeptInfoDlg.collectData = function() { DictInfoDlg.collectData = function() {
this.set('id').set('simplename').set('fullname').set('tips').set('num').set('pid'); this.set('id').set('simplename').set('fullname').set('tips').set('num').set('pid');
} }
/** /**
* 提交添加部门 * 提交添加部门
*/ */
DeptInfoDlg.addSubmit = function() { DictInfoDlg.addSubmit = function() {
this.clearData(); this.clearData();
this.collectData(); this.collectData();
//提交信息 //提交信息
var ajax = new $ax(Feng.ctxPath + "/dept/add", function(data){ var ajax = new $ax(Feng.ctxPath + "/dict/add", function(data){
Feng.success("添加成功!"); Feng.success("添加成功!");
window.parent.Dept.table.refresh(); window.parent.Dept.table.refresh();
DeptInfoDlg.close(); DictInfoDlg.close();
},function(data){ },function(data){
Feng.error("添加失败!" + data.responseJSON.message + "!"); Feng.error("添加失败!" + data.responseJSON.message + "!");
}); });
ajax.set(this.deptInfoData); ajax.set(this.dictInfoData);
ajax.start(); ajax.start();
} }
/** /**
* 提交修改 * 提交修改
*/ */
DeptInfoDlg.editSubmit = function() { DictInfoDlg.editSubmit = function() {
this.clearData(); this.clearData();
this.collectData(); this.collectData();
//提交信息 //提交信息
var ajax = new $ax(Feng.ctxPath + "/dept/update", function(data){ var ajax = new $ax(Feng.ctxPath + "/dict/update", function(data){
Feng.success("修改成功!"); Feng.success("修改成功!");
window.parent.Dept.table.refresh(); window.parent.Dept.table.refresh();
DeptInfoDlg.close(); DictInfoDlg.close();
},function(data){ },function(data){
Feng.error("修改失败!" + data.responseJSON.message + "!"); Feng.error("修改失败!" + data.responseJSON.message + "!");
}); });
ajax.set(this.deptInfoData); ajax.set(this.dictInfoData);
ajax.start(); ajax.start();
} }
function onBodyDown(event) { function onBodyDown(event) {
if (!(event.target.id == "menuBtn" || event.target.id == "parentDeptMenu" || $( if (!(event.target.id == "menuBtn" || event.target.id == "parentDeptMenu" || $(
event.target).parents("#parentDeptMenu").length > 0)) { event.target).parents("#parentDeptMenu").length > 0)) {
DeptInfoDlg.hideDeptSelectTree(); DictInfoDlg.hideDeptSelectTree();
} }
} }
$(function() { $(function() {
var ztree = new $ZTree("parentDeptMenuTree", "/dept/tree");
ztree.bindOnClick(DeptInfoDlg.onClickDept);
ztree.init();
instance = ztree;
}); });
/**
* 字典管理初始化
*/
var Dict = {
id: "DictTable", //表格id
seItem: null, //选中的条目
table: null,
layerIndex: -1
};
/**
* 初始化表格的列
*/
Dict.initColumn = function () {
return [
{field: 'selectItem', radio: true},
{title: 'id', field: 'id', align: 'center', valign: 'middle'},
{title: '编号', field: 'code', align: 'center', valign: 'middle'},
{title: '值', field: 'num', align: 'center', valign: 'middle'},
{title: '父id', field: 'pid', align: 'center', valign: 'middle'},
{title: '名称', field: 'name', align: 'center', valign: 'middle'},
{title: '备注', field: 'tips', align: 'center', valign: 'middle'}];
};
/**
* 检查是否选中
*/
Dict.check = function () {
var selected = $('#' + this.id).bootstrapTable('getSelections');
if(selected.length == 0){
Feng.info("请先选中表格中的某一记录!");
return false;
}else{
Dict.seItem = selected[0];
return true;
}
};
/**
* 点击添加字典
*/
Dict.openAddDict = function () {
var index = layer.open({
type: 2,
title: '添加字典',
area: ['800px', '420px'], //宽高
fix: false, //不固定
maxmin: true,
content: Feng.ctxPath + '/dict/dict_add'
});
this.layerIndex = index;
};
/**
* 打开查看字典详情
*/
Dict.openDictDetail = function () {
if (this.check()) {
var index = layer.open({
type: 2,
title: '字典详情',
area: ['800px', '420px'], //宽高
fix: false, //不固定
maxmin: true,
content: Feng.ctxPath + '/dict/dict_edit/' + Dict.seItem.id
});
this.layerIndex = index;
}
};
/**
* 删除字典
*/
Dict.delete = function () {
if (this.check()) {
var ajax = new $ax(Feng.ctxPath + "/dict/delete/" + this.seItem.id, function (data) {
Feng.success("删除成功!");
Dict.table.refresh();
}, function (data) {
Feng.error("删除失败!");
});
ajax.start();
}
};
/**
* 查询字典列表
*/
Dict.search = function () {
var queryData = {};
queryData['condition'] = $("#condition").val();
Dict.table.refresh({query: queryData});
};
$(function () {
var defaultColunms = Dict.initColumn();
var table = new BSTable(Dict.id, "/dict/list", defaultColunms);
table.setPaginationType("client");
Dict.table = table.init();
});
/**
* 初始化部门详情对话框
*/
var DeptInfoDlg = {
deptInfoData : {}
};
/**
* 清除数据
*/
DeptInfoDlg.clearData = function() {
this.deptInfoData = {};
}
/**
* 设置对话框中的数据
*
* @param key 数据的名称
* @param val 数据的具体值
*/
DeptInfoDlg.set = function(key, val) {
this.deptInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
return this;
}
/**
* 设置对话框中的数据
*
* @param key 数据的名称
* @param val 数据的具体值
*/
DeptInfoDlg.get = function(key) {
return $("#" + key).val();
}
/**
* 关闭此对话框
*/
DeptInfoDlg.close = function() {
parent.layer.close(window.parent.Dept.layerIndex);
}
/**
* 点击部门ztree列表的选项时
*
* @param e
* @param treeId
* @param treeNode
* @returns
*/
DeptInfoDlg.onClickDept = function(e, treeId, treeNode) {
$("#pName").attr("value", instance.getSelectedVal());
$("#pid").attr("value", treeNode.id);
}
/**
* 显示部门选择的树
*
* @returns
*/
DeptInfoDlg.showDeptSelectTree = function() {
var pName = $("#pName");
var pNameOffset = $("#pName").offset();
$("#parentDeptMenu").css({
left : pNameOffset.left + "px",
top : pNameOffset.top + pName.outerHeight() + "px"
}).slideDown("fast");
$("body").bind("mousedown", onBodyDown);
}
/**
* 隐藏部门选择的树
*/
DeptInfoDlg.hideDeptSelectTree = function() {
$("#parentDeptMenu").fadeOut("fast");
$("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发,不用弹起
}
/**
* 收集数据
*/
DeptInfoDlg.collectData = function() {
this.set('id').set('simplename').set('fullname').set('tips').set('num').set('pid');
}
/**
* 提交添加部门
*/
DeptInfoDlg.addSubmit = function() {
this.clearData();
this.collectData();
//提交信息
var ajax = new $ax(Feng.ctxPath + "/dept/add", function(data){
Feng.success("添加成功!");
window.parent.Dept.table.refresh();
DeptInfoDlg.close();
},function(data){
Feng.error("添加失败!" + data.responseJSON.message + "!");
});
ajax.set(this.deptInfoData);
ajax.start();
}
/**
* 提交修改
*/
DeptInfoDlg.editSubmit = function() {
this.clearData();
this.collectData();
//提交信息
var ajax = new $ax(Feng.ctxPath + "/dept/update", function(data){
Feng.success("修改成功!");
window.parent.Dept.table.refresh();
DeptInfoDlg.close();
},function(data){
Feng.error("修改失败!" + data.responseJSON.message + "!");
});
ajax.set(this.deptInfoData);
ajax.start();
}
function onBodyDown(event) {
if (!(event.target.id == "menuBtn" || event.target.id == "parentDeptMenu" || $(
event.target).parents("#parentDeptMenu").length > 0)) {
DeptInfoDlg.hideDeptSelectTree();
}
}
$(function() {
var ztree = new $ZTree("parentDeptMenuTree", "/dept/tree");
ztree.bindOnClick(DeptInfoDlg.onClickDept);
ztree.init();
instance = ztree;
});
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