From cbade6b843e8bc8eddae6d2e4d47adb951f2d6d9 Mon Sep 17 00:00:00 2001 From: zwzw1219 Date: Sat, 18 Nov 2017 21:21:14 +0800 Subject: [PATCH] !9 dict Merge pull request !9 from zwzw1219/dict --- doc/db/boot_backend.sql | 36 +++++ .../server/controller/DictController.java | 91 ++++++++++++ .../java/com/zw/admin/server/dao/DictDao.java | 40 +++++ .../java/com/zw/admin/server/model/Dict.java | 34 +++++ .../resources/mybatis-mappers/DictMapper.xml | 55 +++++++ src/main/resources/static/js/dict.js | 36 +++++ .../resources/static/pages/dict/addDict.html | 78 ++++++++++ .../resources/static/pages/dict/dictList.html | 138 ++++++++++++++++++ .../static/pages/dict/updateDict.html | 99 +++++++++++++ .../static/pages/notice/addNotice.html | 5 +- .../static/pages/notice/noticeList.html | 12 +- .../static/pages/notice/noticePubList.html | 6 +- .../static/pages/notice/updateNotice.html | 5 +- .../resources/static/pages/user/addUser.html | 7 +- .../static/pages/user/updateMyself.html | 2 + .../static/pages/user/updateUser.html | 8 +- .../resources/static/pages/user/userList.html | 18 +-- 17 files changed, 636 insertions(+), 34 deletions(-) create mode 100644 src/main/java/com/zw/admin/server/controller/DictController.java create mode 100644 src/main/java/com/zw/admin/server/dao/DictDao.java create mode 100644 src/main/java/com/zw/admin/server/model/Dict.java create mode 100644 src/main/resources/mybatis-mappers/DictMapper.xml create mode 100644 src/main/resources/static/js/dict.js create mode 100644 src/main/resources/static/pages/dict/addDict.html create mode 100644 src/main/resources/static/pages/dict/dictList.html create mode 100644 src/main/resources/static/pages/dict/updateDict.html diff --git a/doc/db/boot_backend.sql b/doc/db/boot_backend.sql index a25a4c2..aa31f84 100644 --- a/doc/db/boot_backend.sql +++ b/doc/db/boot_backend.sql @@ -321,6 +321,10 @@ INSERT INTO `sys_permission` VALUES ('33', '30', '删除', '', '', '2', 'job:del INSERT INTO `sys_permission` VALUES ('34', '0', 'excel导出', 'fa-arrow-circle-down', 'pages/excel/sql.html', '1', '', '16'); INSERT INTO `sys_permission` VALUES ('35', '34', '导出', '', '', '2', 'excel:down', '100'); INSERT INTO `sys_permission` VALUES ('36', '34', '页面显示数据', '', '', '2', 'excel:show:datas', '100'); +INSERT INTO `sys_permission` VALUES ('37', '0', '字典管理', 'fa-reddit', 'pages/dict/dictList.html', '1', '', '17'); +INSERT INTO `sys_permission` VALUES ('38', '37', '查询', '', '', '2', 'dict:query', '100'); +INSERT INTO `sys_permission` VALUES ('39', '37', '新增', '', '', '2', 'dict:add', '100'); +INSERT INTO `sys_permission` VALUES ('40', '37', '删除', '', '', '2', 'dict:del', '100'); -- ---------------------------- -- Table structure for sys_role @@ -390,6 +394,10 @@ INSERT INTO `sys_role_permission` VALUES ('1', '33'); INSERT INTO `sys_role_permission` VALUES ('1', '34'); INSERT INTO `sys_role_permission` VALUES ('1', '35'); INSERT INTO `sys_role_permission` VALUES ('1', '36'); +INSERT INTO `sys_role_permission` VALUES ('1', '37'); +INSERT INTO `sys_role_permission` VALUES ('1', '38'); +INSERT INTO `sys_role_permission` VALUES ('1', '39'); +INSERT INTO `sys_role_permission` VALUES ('1', '40'); INSERT INTO `sys_role_permission` VALUES ('2', '1'); INSERT INTO `sys_role_permission` VALUES ('2', '2'); INSERT INTO `sys_role_permission` VALUES ('2', '3'); @@ -464,6 +472,34 @@ CREATE TABLE `sys_user` ( INSERT INTO `sys_user` VALUES ('1', 'admin', '1015ed3b5f1345911198c995f9ad097e', '87e03afa1f0122531f729c9a7453f475', '管理员', null, '', '', '', '1998-07-01', '0', '1', '2017-04-10 15:21:38', '2017-07-06 09:20:19'); INSERT INTO `sys_user` VALUES ('2', 'user', '72c2e62dba72e5f178542313803f33d1', '143292269df8c63e2da1a9ba2aeff43c', '用户', null, '', '', '', null, '1', '1', '2017-08-01 21:47:18', '2017-08-01 21:47:18'); +-- ---------------------------- +-- Table structure for t_dict +-- ---------------------------- +DROP TABLE IF EXISTS `t_dict`; +CREATE TABLE `t_dict` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `type` varchar(16) NOT NULL, + `k` varchar(16) NOT NULL, + `val` varchar(64) NOT NULL, + `createTime` datetime NOT NULL, + `updateTime` datetime NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `type` (`type`,`k`) +) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Records of t_dict +-- ---------------------------- +INSERT INTO `t_dict` VALUES ('1', 'sex', '0', '女', '2017-11-17 09:58:24', '2017-11-18 14:21:05'); +INSERT INTO `t_dict` VALUES ('2', 'sex', '1', '男', '2017-11-17 10:03:46', '2017-11-17 10:03:46'); +INSERT INTO `t_dict` VALUES ('3', 'userStatus', '0', '无效', '2017-11-17 16:26:06', '2017-11-17 16:26:09'); +INSERT INTO `t_dict` VALUES ('4', 'userStatus', '1', '正常', '2017-11-17 16:26:06', '2017-11-17 16:26:09'); +INSERT INTO `t_dict` VALUES ('5', 'userStatus', '2', '锁定', '2017-11-17 16:26:06', '2017-11-17 16:26:09'); +INSERT INTO `t_dict` VALUES ('6', 'noticeStatus', '0', '草稿', '2017-11-17 16:26:06', '2017-11-17 16:26:09'); +INSERT INTO `t_dict` VALUES ('7', 'noticeStatus', '1', '发布', '2017-11-17 16:26:06', '2017-11-17 16:26:09'); +INSERT INTO `t_dict` VALUES ('8', 'isRead', '0', '未读', '2017-11-17 16:26:06', '2017-11-17 16:26:09'); +INSERT INTO `t_dict` VALUES ('9', 'isRead', '1', '已读', '2017-11-17 16:26:06', '2017-11-17 16:26:09'); + -- ---------------------------- -- Table structure for t_job -- ---------------------------- diff --git a/src/main/java/com/zw/admin/server/controller/DictController.java b/src/main/java/com/zw/admin/server/controller/DictController.java new file mode 100644 index 0000000..d8368d5 --- /dev/null +++ b/src/main/java/com/zw/admin/server/controller/DictController.java @@ -0,0 +1,91 @@ +package com.zw.admin.server.controller; + +import java.util.List; + +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.zw.admin.server.page.table.PageTableRequest; +import com.zw.admin.server.page.table.PageTableHandler; +import com.zw.admin.server.page.table.PageTableResponse; +import com.zw.admin.server.page.table.PageTableHandler.CountHandler; +import com.zw.admin.server.page.table.PageTableHandler.ListHandler; +import com.zw.admin.server.dao.DictDao; +import com.zw.admin.server.model.Dict; + +import io.swagger.annotations.ApiOperation; + +@RestController +@RequestMapping("/dicts") +public class DictController { + + @Autowired + private DictDao dictDao; + + @RequiresPermissions("dict:add") + @PostMapping + @ApiOperation(value = "保存") + public Dict save(@RequestBody Dict dict) { + Dict d = dictDao.getByTypeAndK(dict.getType(), dict.getK()); + if (d != null) { + throw new IllegalArgumentException("类型和key已存在"); + } + dictDao.save(dict); + + return dict; + } + + @GetMapping("/{id}") + @ApiOperation(value = "根据id获取") + public Dict get(@PathVariable Long id) { + return dictDao.getById(id); + } + + @RequiresPermissions("dict:add") + @PutMapping + @ApiOperation(value = "修改") + public Dict update(@RequestBody Dict dict) { + dictDao.update(dict); + + return dict; + } + + @RequiresPermissions("dict:query") + @GetMapping(params = { "start", "length" }) + @ApiOperation(value = "列表") + public PageTableResponse list(PageTableRequest request) { + return new PageTableHandler(new CountHandler() { + + @Override + public int count(PageTableRequest request) { + return dictDao.count(request.getParams()); + } + }, new ListHandler() { + + @Override + public List list(PageTableRequest request) { + return dictDao.list(request.getParams(), request.getOffset(), request.getLimit()); + } + }).handle(request); + } + + @RequiresPermissions("dict:del") + @DeleteMapping("/{id}") + @ApiOperation(value = "删除") + public void delete(@PathVariable Long id) { + dictDao.delete(id); + } + + @GetMapping(params = "type") + public List listByType(String type) { + return dictDao.listByType(type); + } +} diff --git a/src/main/java/com/zw/admin/server/dao/DictDao.java b/src/main/java/com/zw/admin/server/dao/DictDao.java new file mode 100644 index 0000000..f4aa208 --- /dev/null +++ b/src/main/java/com/zw/admin/server/dao/DictDao.java @@ -0,0 +1,40 @@ +package com.zw.admin.server.dao; + +import java.util.List; +import java.util.Map; + +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Options; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import com.zw.admin.server.model.Dict; + +@Mapper +public interface DictDao { + + @Select("select * from t_dict t where t.id = #{id}") + Dict getById(Long id); + + @Delete("delete from t_dict where id = #{id}") + int delete(Long id); + + int update(Dict dict); + + @Options(useGeneratedKeys = true, keyProperty = "id") + @Insert("insert into t_dict(type, k, val, createTime, updateTime) values(#{type}, #{k}, #{val}, now(), now())") + int save(Dict dict); + + int count(@Param("params") Map params); + + List list(@Param("params") Map params, @Param("offset") Integer offset, + @Param("limit") Integer limit); + + @Select("select * from t_dict t where t.type = #{type} and k = #{k}") + Dict getByTypeAndK(@Param("type") String type, @Param("k") String k); + + @Select("select * from t_dict t where t.type = #{type}") + List listByType(String type); +} diff --git a/src/main/java/com/zw/admin/server/model/Dict.java b/src/main/java/com/zw/admin/server/model/Dict.java new file mode 100644 index 0000000..03ac962 --- /dev/null +++ b/src/main/java/com/zw/admin/server/model/Dict.java @@ -0,0 +1,34 @@ +package com.zw.admin.server.model; + +public class Dict extends BaseEntity { + + private static final long serialVersionUID = -2431140186410912787L; + private String type; + private String k; + private String val; + + public String getType() { + return type; + } + + public String setType() { + return type; + } + + public String getK() { + return k; + } + + public String setK() { + return k; + } + + public String getVal() { + return val; + } + + public String setVal() { + return val; + } + +} diff --git a/src/main/resources/mybatis-mappers/DictMapper.xml b/src/main/resources/mybatis-mappers/DictMapper.xml new file mode 100644 index 0000000..0e3374c --- /dev/null +++ b/src/main/resources/mybatis-mappers/DictMapper.xml @@ -0,0 +1,55 @@ + + + + + + + + and id = #{params.id} + + + and type = #{params.type} + + + and k = #{params.k} + + + and val = #{params.val} + + + + + + + + + + + update t_dict t + + + type = #{type}, + + + k = #{k}, + + + val = #{val}, + + updateTime = now() + + + + where t.id = #{id} + + + diff --git a/src/main/resources/static/js/dict.js b/src/main/resources/static/js/dict.js new file mode 100644 index 0000000..f4677ff --- /dev/null +++ b/src/main/resources/static/js/dict.js @@ -0,0 +1,36 @@ +function showDictSelect(id, type, all) { + var data = getDict(type); + var select = $("#" + id); + select.empty(); + + if (all != undefined || all) { + select.append(""); + } + + $.each(data, function(k, v) { + select.append(""); + }); + + return data; +} + +function getDict(type) { + var v = sessionStorage[type]; + if (v == null || v == "") { + $.ajax({ + type : 'get', + url : '/dicts?type=' + type, + async : false, + success : function(data) { + v = {}; + $.each(data, function(i, d) { + v[d.k] = d.val; + }); + + sessionStorage[type] = JSON.stringify(v); + } + }); + } + + return JSON.parse(sessionStorage[type]); +} diff --git a/src/main/resources/static/pages/dict/addDict.html b/src/main/resources/static/pages/dict/addDict.html new file mode 100644 index 0000000..2baaf49 --- /dev/null +++ b/src/main/resources/static/pages/dict/addDict.html @@ -0,0 +1,78 @@ + + + + + + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ + +
+
+
+ +
+
+
+ + + + + + + + diff --git a/src/main/resources/static/pages/dict/dictList.html b/src/main/resources/static/pages/dict/dictList.html new file mode 100644 index 0000000..c469243 --- /dev/null +++ b/src/main/resources/static/pages/dict/dictList.html @@ -0,0 +1,138 @@ + + + + +Insert title here + + + + + +
+
+
+
+
+ + + + + +
+
+
+ type: + + +
+
+
+ +
+
+
+ +
+
+ + + + + + + + + + + + + + + + +
idtypekvalcreateTimeupdateTime操作
+
+
+
+
+
+ + + + + + + + + + diff --git a/src/main/resources/static/pages/dict/updateDict.html b/src/main/resources/static/pages/dict/updateDict.html new file mode 100644 index 0000000..39dcf3a --- /dev/null +++ b/src/main/resources/static/pages/dict/updateDict.html @@ -0,0 +1,99 @@ + + + + + + +
+
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ + +
+
+
+ +
+
+
+ + + + + + + + diff --git a/src/main/resources/static/pages/notice/addNotice.html b/src/main/resources/static/pages/notice/addNotice.html index 44892b7..71bd55f 100644 --- a/src/main/resources/static/pages/notice/addNotice.html +++ b/src/main/resources/static/pages/notice/addNotice.html @@ -25,8 +25,6 @@
@@ -49,7 +47,10 @@ + + + + + + + + +