Merge pull request #29 from hiparker/development

Development
pull/33/head 2.1.0
Parker 3 years ago committed by GitHub
commit 8567275fa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,10 @@
-- vue2
delete from sys_menu
where parent_ids like '0,1314068325453574145,1314071137365307394%'
or parent_ids like '0,1314068325453574145,1314123690283114498%';
--
delete ref from sys_role_menu_ref ref
left join sys_menu m on m.id = ref.menu_id
where m.id is null;

File diff suppressed because one or more lines are too long

@ -100,6 +100,14 @@ public interface MenuApi {
ResultWrapper<List<MenuModel>> findList();
/**
*
* @param parentId ID
* @return ResultWrapper
*/
@GetMapping("/getParent")
ResultWrapper<MenuModel> getParent(String parentId);
/**
*
* @param model

@ -18,6 +18,7 @@ package org.opsli.api.web.system.role;
import org.opsli.api.base.result.ResultWrapper;
import org.opsli.api.wrapper.system.role.RoleMenuRefModel;
import org.opsli.api.wrapper.system.role.RoleModel;
import org.opsli.common.annotation.ApiVersion;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -54,6 +55,15 @@ public interface RoleMenuRefApi {
@GetMapping("/getPerms")
ResultWrapper<?> getPerms(RoleMenuRefModel model);
/**
*
* @param model Id
* @return ResultWrapper
*/
@ApiVersion(2)
@GetMapping("/getPerms")
ResultWrapper<?> getPermsV2(RoleMenuRefModel model);
/**
*
* @param model roleId Id
@ -63,4 +73,14 @@ public interface RoleMenuRefApi {
@PostMapping("/setPerms")
ResultWrapper<?> setPerms(@RequestBody RoleMenuRefModel model);
/**
*
* @param model roleId Id
* @param model permsIds Id
* @return ResultWrapper
*/
@PostMapping("/setPerms")
@ApiVersion(2)
ResultWrapper<?> setPermsV2(@RequestBody RoleMenuRefModel model);
}

@ -17,9 +17,7 @@ package org.opsli.api.wrapper.system.user;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.*;
import org.opsli.common.annotation.validator.Validator;
import org.opsli.common.annotation.validator.ValidatorLenMax;
import org.opsli.common.enums.ValidatorType;
@ -35,6 +33,8 @@ import java.io.Serializable;
@Data
@EqualsAndHashCode(callSuper = false)
@ExcelIgnoreUnannotated
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class UserRoleRefModel implements Serializable {

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.core.log.bus;
package org.opsli.core.eventbus;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
@ -21,7 +21,6 @@ import com.google.common.eventbus.SubscriberExceptionContext;
import com.google.common.eventbus.SubscriberExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.opsli.common.thread.ThreadPoolFactory;
import org.opsli.core.eventbus.AbstractSpringEventBus;
import org.springframework.stereotype.Component;
import java.util.concurrent.ThreadPoolExecutor;
@ -34,11 +33,11 @@ import java.util.concurrent.TimeUnit;
*/
@Component
@Slf4j
public class OperationLogEventBus extends AbstractSpringEventBus implements SubscriberExceptionHandler {
public class SpringEventBus extends AbstractSpringEventBus implements SubscriberExceptionHandler {
private final EventBus eventBus;
public OperationLogEventBus() {
public SpringEventBus() {
// 异步事件配置线程池
eventBus = new AsyncEventBus(
ThreadPoolFactory.createInitThreadPool(5, 10, 60, TimeUnit.SECONDS,

@ -29,7 +29,7 @@ import org.opsli.core.base.dto.LoginUserDto;
import org.opsli.core.holder.UserContextHolder;
import org.opsli.core.log.annotation.OperateLogger;
import org.opsli.core.log.bean.OperationLog;
import org.opsli.core.log.bus.OperationLogEventBus;
import org.opsli.core.eventbus.SpringEventBus;
import org.opsli.core.log.enums.LogLevelEnum;
import org.opsli.core.log.enums.LogScopeEnum;
import org.opsli.core.utils.UserTokenUtil;
@ -57,7 +57,7 @@ public class OperateLogAspect {
private static final String RE = "\\$\\{([\\w\\.\\-\\/\\+\\$\\#\\@\\!\\^\\&\\(\\)]+)\\}";
@Resource
private OperationLogEventBus operationLogEventBus;
private SpringEventBus springEventBus;
@Pointcut("@annotation(org.opsli.core.log.annotation.OperateLogger)")
public void operationLog(){}
@ -156,7 +156,7 @@ public class OperateLogAspect {
}
// 存入数据库
if(annotation.db()){
operationLogEventBus.post(operationLog);
springEventBus.post(operationLog);
}
}

@ -287,6 +287,29 @@ public class MenuRestController extends BaseRestController<SysMenu, MenuModel, I
return ResultWrapper.getSuccessResultWrapper(model);
}
/**
*
* @param parentId ID
* @return ResultWrapper
*/
@ApiOperation(value = "获得单条菜单", notes = "获得单条菜单 - ID")
@PreAuthorize("hasAuthority('system_menu_select')")
@Override
public ResultWrapper<MenuModel> getParent(String parentId) {
if(StringUtils.isBlank(parentId)){
return ResultWrapper.getSuccessResultWrapper(null);
}
MenuModel model;
if(StringUtils.equals(MenuConstants.GEN_ID, parentId)){
// 生成根节点菜单
model = getGenMenuModel();
}else{
model = IService.get(parentId);
}
return ResultWrapper.getSuccessResultWrapper(model);
}
/**
*
* @param pageNo

@ -42,6 +42,14 @@ public interface IRoleMenuRefService {
*/
boolean setPerms(String roleId,String[] permsIds);
/**
* Vue3
* @param roleId ID
* @param permsIds
* @return boolean
*/
boolean setPermsV2(String roleId,String[] permsIds);
/**
* ID
* @param roleIds ID

@ -88,6 +88,38 @@ public class RoleMenuRefServiceImpl extends ServiceImpl<RoleMenuRefMapper,SysRol
return true;
}
/**
* Vue3
* @param roleId ID
* @param permsIds
* @return boolean
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean setPermsV2(String roleId, String[] permsIds) {
if(StringUtils.isEmpty(roleId)){
throw new ServiceException(SystemMsg.EXCEPTION_ROLE_ID_NOT_NULL);
}
// 删除已有权限
this.delPermsByRoleIds(Convert.toList(String.class, roleId));
List<SysRoleMenuRef> list = Lists.newArrayListWithCapacity(permsIds.length);
for (String permsId : permsIds) {
SysRoleMenuRef entity = new SysRoleMenuRef();
entity.setRoleId(roleId);
entity.setMenuId(permsId);
list.add(entity);
}
boolean ret = super.saveBatch(list);
if(ret){
// 清除缓存
this.clearCache(roleId);
}
return ret;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean delPermsByMenuIds(List<String> menuIds){

@ -19,6 +19,7 @@ import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.opsli.common.annotation.ApiVersion;
import org.opsli.core.log.annotation.OperateLogger;
import org.opsli.core.log.enums.ModuleEnum;
import org.opsli.core.log.enums.OperationTypeEnum;
@ -37,6 +38,7 @@ import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.menu.entity.SysMenu;
import org.opsli.modulars.system.role.service.IRoleMenuRefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
import java.util.Map;
@ -93,6 +95,31 @@ public class RoleMenuRefRestController implements RoleMenuRefApi {
return ResultWrapper.getSuccessResultWrapper(permsIds);
}
/**
* (Vue3 )
* @param model roleId Id
* @return ResultWrapper
*/
@PreAuthorize("hasAuthority('system_role_setMenuPerms')")
@Override
@ApiVersion(2)
public ResultWrapper<?> getPermsV2(RoleMenuRefModel model) {
if(model == null){
return ResultWrapper.getCustomResultWrapper(SystemMsg.EXCEPTION_ROLE_ID_NOT_NULL);
}
List<SysMenu> perms = iRoleMenuRefService.getPerms(model.getRoleId());
List<String> permsIds = Lists.newArrayListWithCapacity(perms.size());
if(!perms.isEmpty()){
for (SysMenu perm : perms) {
permsIds.add(perm.getId());
}
}
return ResultWrapper.getSuccessResultWrapper(permsIds);
}
/**
*
* @param model
@ -120,6 +147,33 @@ public class RoleMenuRefRestController implements RoleMenuRefApi {
}
/**
*
* @param model
* @return ResultWrapper
*/
@PreAuthorize("hasAuthority('system_role_setMenuPerms')")
@OperateLogger(description = "设置菜單权限",
module = ModuleEnum.MODULE_ROLE, operationType = OperationTypeEnum.UPDATE, db = true)
@Override
public ResultWrapper<?> setPermsV2(RoleMenuRefModel model) {
// 演示模式 不允许操作
this.demoError();
if(model == null){
return ResultWrapper.getErrorResultWrapper().setMsg("设置权限失败");
}
boolean ret = iRoleMenuRefService.setPermsV2(model.getRoleId(),
model.getPermsIds());
if(ret){
return ResultWrapper.getSuccessResultWrapper();
}
// 权限设置失败
return ResultWrapper.getCustomResultWrapper(SystemMsg.EXCEPTION_ROLE_PERMS_ERROR);
}
/**
*
*/

Loading…
Cancel
Save