Commit 0119ac9e by fengshuonan

完善菜单管理,整理部分代码

parent a263c7b6
......@@ -36,16 +36,5 @@ public class GunsApplication {
public static void main(String[] args) {
SpringApplication.run(GunsApplication.class, args);
logger.info("GunsApplication is success!");
// GenerateParams generateParams = new GenerateParams();
//
// generateParams.setRemoveTablePrefix(new String[]{"sys_"});
// generateParams.setAuthor("stylefeng");
// generateParams.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/guns?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT");
// generateParams.setGeneratorInterface(false);
// generateParams.setParentPackage("cn.stylefeng.guns.modular.system");
// generateParams.setGeneratorInterface(false);
//
// SimpleGenerator.doGeneration(generateParams);
}
}
/**
* Copyright 2018-2020 stylefeng & fengshuonan (sn93@qq.com)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.stylefeng.guns.core.common.constant;
/**
......
......@@ -56,12 +56,6 @@ public class ConstantFactory implements IConstantFactory {
return SpringContextHolder.getBean("constantFactory");
}
/**
* 根据用户id获取用户名称
*
* @author stylefeng
* @Date 2017/5/9 23:41
*/
@Override
public String getUserNameById(Long userId) {
User user = userMapper.selectById(userId);
......@@ -72,12 +66,6 @@ public class ConstantFactory implements IConstantFactory {
}
}
/**
* 根据用户id获取用户账号
*
* @author stylefeng
* @date 2017年5月16日21:55:371
*/
@Override
public String getUserAccountById(Long userId) {
User user = userMapper.selectById(userId);
......@@ -88,9 +76,6 @@ public class ConstantFactory implements IConstantFactory {
}
}
/**
* 通过角色ids获取角色名称
*/
@Override
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds")
public String getRoleName(String roleIds) {
......@@ -108,9 +93,6 @@ public class ConstantFactory implements IConstantFactory {
return StrUtil.removeSuffix(sb.toString(), ",");
}
/**
* 通过角色id获取角色名称
*/
@Override
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_NAME + "'+#roleId")
public String getSingleRoleName(Long roleId) {
......@@ -124,9 +106,6 @@ public class ConstantFactory implements IConstantFactory {
return "";
}
/**
* 通过角色id获取角色英文名称
*/
@Override
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_TIP + "'+#roleId")
public String getSingleRoleTip(Long roleId) {
......@@ -140,9 +119,6 @@ public class ConstantFactory implements IConstantFactory {
return "";
}
/**
* 获取部门名称
*/
@Override
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.DEPT_NAME + "'+#deptId")
public String getDeptName(Long deptId) {
......@@ -159,9 +135,6 @@ public class ConstantFactory implements IConstantFactory {
}
}
/**
* 获取菜单的名称们(多个)
*/
@Override
public String getMenuNames(String menuIds) {
Integer[] menus = Convert.toIntArray(menuIds);
......@@ -175,9 +148,6 @@ public class ConstantFactory implements IConstantFactory {
return StrUtil.removeSuffix(sb.toString(), ",");
}
/**
* 获取菜单名称
*/
@Override
public String getMenuName(Long menuId) {
if (ToolUtil.isEmpty(menuId)) {
......@@ -192,13 +162,12 @@ public class ConstantFactory implements IConstantFactory {
}
}
/**
* 获取菜单名称通过编号
*/
@Override
public String getMenuNameByCode(String code) {
if (ToolUtil.isEmpty(code)) {
return "";
} else if (code.equals("0")) {
return "顶级";
} else {
Menu param = new Menu();
param.setCode(code);
......@@ -211,9 +180,20 @@ public class ConstantFactory implements IConstantFactory {
}
}
/**
* 获取字典名称
*/
@Override
public Long getMenuIdByCode(String code) {
if (ToolUtil.isEmpty(code)) {
return 0L;
} else if (code.equals("0")) {
return 0L;
} else {
Menu menu = new Menu();
menu.setCode(code);
Menu tempMenu = this.menuMapper.selectOne(menu);
return tempMenu.getMenuId();
}
}
@Override
public String getDictName(Long dictId) {
if (ToolUtil.isEmpty(dictId)) {
......@@ -228,9 +208,6 @@ public class ConstantFactory implements IConstantFactory {
}
}
/**
* 获取通知标题
*/
@Override
public String getNoticeTitle(Long dictId) {
if (ToolUtil.isEmpty(dictId)) {
......@@ -245,9 +222,6 @@ public class ConstantFactory implements IConstantFactory {
}
}
/**
* 根据字典名称和字典中的值获取对应的名称
*/
@Override
public String getDictsByName(String name, String code) {
Dict temp = new Dict();
......@@ -268,33 +242,21 @@ public class ConstantFactory implements IConstantFactory {
}
}
/**
* 获取性别名称
*/
@Override
public String getSexName(String sexCode) {
return getDictsByName("性别", sexCode);
}
/**
* 获取用户登录状态
*/
@Override
public String getStatusName(String status) {
return ManagerStatus.getDescription(status);
}
/**
* 获取菜单状态
*/
@Override
public String getMenuStatusName(String status) {
return MenuStatus.getDescription(status);
}
/**
* 查询字典
*/
@Override
public List<Dict> findInDict(Long id) {
if (ToolUtil.isEmpty(id)) {
......@@ -310,17 +272,11 @@ public class ConstantFactory implements IConstantFactory {
}
}
/**
* 获取被缓存的对象(用户删除业务)
*/
@Override
public String getCacheObject(String para) {
return LogObjectHolder.me().get().toString();
}
/**
* 获取子部门id
*/
@Override
public List<Long> getSubDeptId(Long deptId) {
Wrapper<Dept> wrapper = new EntityWrapper<>();
......@@ -338,9 +294,6 @@ public class ConstantFactory implements IConstantFactory {
return deptids;
}
/**
* 获取所有父部门id
*/
@Override
public List<Long> getParentDeptIds(Long deptId) {
Dept dept = deptMapper.selectById(deptId);
......
......@@ -79,6 +79,11 @@ public interface IConstantFactory {
String getMenuNameByCode(String code);
/**
* 获取菜单名称通过编号
*/
Long getMenuIdByCode(String code);
/**
* 获取字典名称
*/
String getDictName(Long dictId);
......
/**
* Copyright 2018-2020 stylefeng & fengshuonan (sn93@qq.com)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.stylefeng.guns.core.metadata;
import cn.stylefeng.guns.core.shiro.ShiroKit;
......
/**
* Copyright 2018-2020 stylefeng & fengshuonan (sn93@qq.com)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.stylefeng.guns.core.util;
import cn.stylefeng.guns.core.listener.ConfigListener;
......
......@@ -37,13 +37,11 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
......@@ -116,14 +114,12 @@ public class MenuController extends BaseController {
@RequestMapping(value = "/edit")
@BussinessLog(value = "修改菜单", key = "name", dict = MenuDict.class)
@ResponseBody
public ResponseData edit(@Valid Menu menu, BindingResult result) {
if (result.hasErrors()) {
throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
}
public ResponseData edit(MenuDto menu) {
//设置父级菜单编号
menuSetPcode(menu);
Menu resultMenu = menuSetPcode(menu);
this.menuService.updateById(menu);
this.menuService.updateById(resultMenu);
return SUCCESS_TIP;
}
......@@ -145,10 +141,7 @@ public class MenuController extends BaseController {
@RequestMapping(value = "/add")
@BussinessLog(value = "菜单新增", key = "name", dict = MenuDict.class)
@ResponseBody
public ResponseData add(@Valid Menu menu, BindingResult result) {
if (result.hasErrors()) {
throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
}
public ResponseData add(MenuDto menu) {
//判断是否存在该编号
String existedMenuName = ConstantFactory.me().getMenuNameByCode(menu.getCode());
......@@ -157,10 +150,10 @@ public class MenuController extends BaseController {
}
//设置父级菜单编号
menuSetPcode(menu);
Menu resultMenu = menuSetPcode(menu);
menu.setStatus(MenuStatus.ENABLE.getCode());
this.menuService.insert(menu);
resultMenu.setStatus(MenuStatus.ENABLE.getCode());
this.menuService.insert(resultMenu);
return SUCCESS_TIP;
}
......@@ -192,8 +185,8 @@ public class MenuController extends BaseController {
if (ToolUtil.isEmpty(menuId)) {
throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
}
this.menuService.selectById(menuId);
return SUCCESS_TIP;
Menu menu = this.menuService.selectById(menuId);
return ResponseData.success(menu);
}
/**
......@@ -208,7 +201,8 @@ public class MenuController extends BaseController {
Menu menu = this.menuService.selectById(menuId);
MenuDto menuDto = new MenuDto();
BeanUtil.copyProperties(menu,menuDto);
BeanUtil.copyProperties(menu, menuDto);
menuDto.setPid(ConstantFactory.me().getMenuIdByCode(menuDto.getPcode()));
menuDto.setPcodeName(ConstantFactory.me().getMenuNameByCode(menuDto.getPcode()));
return ResponseData.success(menuDto);
......@@ -251,25 +245,31 @@ public class MenuController extends BaseController {
/**
* 根据请求的父级菜单编号设置pcode和层级
*/
private void menuSetPcode(@Valid Menu menu) {
if (ToolUtil.isEmpty(menu.getPcode()) || menu.getPcode().equals("0")) {
menu.setPcode("0");
menu.setPcodes("[0],");
menu.setLevels(1);
private Menu menuSetPcode(MenuDto menuParam) {
Menu resultMenu = new Menu();
BeanUtil.copyProperties(menuParam, resultMenu);
if (ToolUtil.isEmpty(menuParam.getPid()) || menuParam.getPid().equals(0L)) {
resultMenu.setPcode("0");
resultMenu.setPcodes("[0],");
resultMenu.setLevels(1);
} else {
String code = menu.getPcode();
Menu pMenu = menuService.selectByCode(code);
Long pid = menuParam.getPid();
Menu pMenu = menuService.selectById(pid);
Integer pLevels = pMenu.getLevels();
menu.setPcode(pMenu.getCode());
resultMenu.setPcode(pMenu.getCode());
//如果编号和父编号一致会导致无限递归
if (menu.getCode().equals(menu.getPcode())) {
if (menuParam.getCode().equals(menuParam.getPcode())) {
throw new ServiceException(BizExceptionEnum.MENU_PCODE_COINCIDENCE);
}
menu.setLevels(pLevels + 1);
menu.setPcodes(pMenu.getPcodes() + "[" + pMenu.getCode() + "],");
resultMenu.setLevels(pLevels + 1);
resultMenu.setPcodes(pMenu.getPcodes() + "[" + pMenu.getCode() + "],");
}
return resultMenu;
}
}
......@@ -26,6 +26,10 @@ public class MenuDto implements Serializable {
*/
private String code;
/**
* 菜单父级id
*/
private Long pid;
/**
* 菜单父编号
*/
private String pcode;
......
......@@ -19,7 +19,7 @@
<h5>父级编号 <span class="text-danger">*</span></h5>
<div class="controls">
<input v-model="pcodeName" id="detpName" \@click="showMenuSelectTree" type="text" class="form-control" autocomplete="off">
<input v-model="pcode" type="hidden" class="form-control">
<input v-model="pid" type="hidden" class="form-control">
</div>
</div>
<div class="form-group">
......
......@@ -19,7 +19,7 @@
<h5>父级编号 <span class="text-danger">*</span></h5>
<div class="controls">
<input v-model="pcodeName" id="detpName" \@click="showMenuSelectTree" type="text" class="form-control" autocomplete="off">
<input v-model="pcode" type="hidden" class="form-control">
<input v-model="pid" type="hidden" class="form-control">
</div>
</div>
<div class="form-group">
......
......@@ -6,7 +6,7 @@ var MenuInfoDlg = {
menuId: "",
name: "",
code: "",
pcode: "",
pid: "",
pcodeName: "",
url: "",
sort: "",
......@@ -36,7 +36,7 @@ MenuInfoDlg.validateForm = function () {
if (!data.code) {
return "请输入菜单编号";
}
if (!data.pcode) {
if (!data.pid) {
return "请输入菜单上级";
}
if (!data.menuFlag) {
......@@ -74,7 +74,7 @@ $(function () {
},
showMenuSelectTree: function () {
var formName = encodeURIComponent("parent.MenuInfoDlg.app.pcodeName");
var formId = encodeURIComponent("parent.MenuInfoDlg.app.pcode");
var formId = encodeURIComponent("parent.MenuInfoDlg.app.pid");
var treeUrl = encodeURIComponent(Feng.ctxPath + "/menu/selectMenuTreeList");
layer.open({
......
......@@ -6,7 +6,7 @@ var MenuInfoDlg = {
menuId: "",
name: "",
code: "",
pcode: "",
pid: "",
pcodeName: "",
url: "",
sort: "",
......@@ -36,7 +36,7 @@ MenuInfoDlg.validateForm = function () {
if (!data.code) {
return "请输入菜单编号";
}
if (!data.pcode) {
if (!data.pid) {
return "请输入菜单上级";
}
if (!data.menuFlag) {
......@@ -80,7 +80,7 @@ $(function () {
},
showMenuSelectTree: function () {
var formName = encodeURIComponent("parent.MenuInfoDlg.app.pcodeName");
var formId = encodeURIComponent("parent.MenuInfoDlg.app.pcode");
var formId = encodeURIComponent("parent.MenuInfoDlg.app.pid");
var treeUrl = encodeURIComponent(Feng.ctxPath + "/menu/selectMenuTreeList");
layer.open({
......
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