fix: 修复若干bug

1. 修复菜单更换上级时,parent_ids 拼接错误问题
2. 修复代码生成器,生成代码时参数为空问题
pull/16/head
Parker 3 years ago
parent 51539d0bc9
commit 7d322db9ca

@ -0,0 +1,42 @@
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
update sys_menu
set parent_ids = CONCAT_WS(',', 0, id)
where parent_id = 0;
update sys_menu pp
left join sys_menu p on p.id = pp.parent_id
set
pp.parent_ids = CONCAT_WS(',', p.parent_ids, pp.id)
where p.parent_id = 0;
update sys_menu ppp
left join sys_menu pp on pp.id = ppp.parent_id
left join sys_menu p on p.id = pp.parent_id
set
ppp.parent_ids = CONCAT_WS(',', pp.parent_ids, ppp.id)
where p.parent_id = 0;
update sys_menu pppp
left join sys_menu ppp on ppp.id = pppp.parent_id
left join sys_menu pp on pp.id = ppp.parent_id
left join sys_menu p on p.id = pp.parent_id
set
pppp.parent_ids = CONCAT_WS(',', ppp.parent_ids, pppp.id)
where p.parent_id = 0;
update sys_menu ppppp
left join sys_menu pppp on pppp.id = ppppp.parent_id
left join sys_menu ppp on ppp.id = pppp.parent_id
left join sys_menu pp on pp.id = ppp.parent_id
left join sys_menu p on p.id = pp.parent_id
set
ppppp.parent_ids = CONCAT_WS(',', pppp.parent_ids, ppppp.id)
where p.parent_id = 0;
SET FOREIGN_KEY_CHECKS = 1;

@ -20,6 +20,7 @@ import org.opsli.modulars.generator.logs.wrapper.GenLogsModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -51,10 +52,9 @@ public interface GenLogsApi {
/**
*
* @param model
*/
@GetMapping("/create")
void create(GenLogsModel model, HttpServletResponse response);
void create(HttpServletRequest request, HttpServletResponse response);
/**
*

@ -18,6 +18,7 @@ package org.opsli.modulars.generator.logs.web;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.common.annotation.ApiRestController;
@ -28,7 +29,10 @@ import org.opsli.modulars.generator.logs.entity.GenLogs;
import org.opsli.modulars.generator.logs.service.IGenLogsService;
import org.opsli.modulars.generator.logs.wrapper.GenLogsModel;
import org.opsli.plugins.generator.utils.GeneratorHandleUtil;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -57,13 +61,20 @@ public class GenLogsRestController extends BaseRestController<GenLogs, GenLogsMo
/**
*
* @param model
*/
@ApiOperation(value = "代码生成", notes = "代码生成")
@RequiresPermissions("dev_generator_create")
@EnableLog
@Override
public void create(GenLogsModel model, HttpServletResponse response) {
public void create(HttpServletRequest request, HttpServletResponse response) {
// request 对象属性
GenLogsModel model = new GenLogsModel();
try {
BeanUtils.populate(model, request.getParameterMap());
}catch (Exception e){
log.error(e.getMessage(), e);
}
// 判断代码生成器 是否启用
GeneratorHandleUtil.judgeGeneratorEnable(super.globalProperties);

@ -101,6 +101,8 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
model.setParentId(MenuConstants.GEN_ID);
}
// 容错处理
// 如果根结点为0 且 为菜单类型 判断首位是否为 / 如果没有则自动加 /
if(MenuConstants.GEN_ID.equals(model.getParentId())){
@ -113,7 +115,15 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
// 刷新缓存
clearCache(Collections.singletonList(model));
return super.insert(model);
// 新增并更新 parent_ids
MenuModel menuModel = super.insert(model);
MenuModel newParentModel = getParentMenuModel(menuModel.getParentId());
String newParentIds = unWrap(
StrUtil.join(",",
newParentModel.getParentIds(), menuModel.getId()), ',');
menuModel.setParentIds(newParentIds);
menuModel.setVersion(null);
return super.update(menuModel);
}
@Transactional(rollbackFor = Exception.class)
@ -148,11 +158,11 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
// 去除 两边的[,] 然后拼接 parentIds
String ordParentIds = unWrap(
StrUtil.join(",",
oldParentModel.getParentIds(), oldParentModel.getId(), sourceModel.getId()), ',');
oldParentModel.getParentIds(), sourceModel.getId()), ',');
String newParentIds = unWrap(
StrUtil.join(",",
newParentModel.getParentIds(), newParentModel.getId(), model.getId()), ',');
newParentModel.getParentIds(), model.getId()), ',');
// 判断 上级是否发生变更 如果发生变更 则当前菜单 继承上级菜单的 label
if(!sourceModel.getParentId().equals(model.getParentId())){
@ -175,6 +185,7 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
// 内部修改 防止版本行锁出现问题
sysMenu.setVersion(null);
}
this.saveOrUpdateBatch(menuList);
}
@ -224,8 +235,8 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
if(TreeBuildUtil.DEF_PARENT_ID.equals(parentId)){
parentModel = new MenuModel();
parentModel.setId(TreeBuildUtil.DEF_PARENT_ID);
parentModel.setParentId("");
parentModel.setParentIds("");
parentModel.setParentId(TreeBuildUtil.DEF_PARENT_ID);
parentModel.setParentIds(TreeBuildUtil.DEF_PARENT_ID);
parentModel.setLabel(DictType.MENU_LABEL_SYSTEM.getValue());
}else {
parentModel = this.get(parentId);

Loading…
Cancel
Save