系统逻辑结构优化

v1.4.1
Parker 4 years ago
parent 515fba85a7
commit b072a00654

@ -109,6 +109,15 @@ public interface UserApi {
@PostMapping("/resetPasswordById")
ResultVo<?> resetPasswordById(String userId);
/**
*
*
* @param userId ID
* @param locked
* @return ResultVo
*/
@PostMapping("/lockAccount")
ResultVo<?> lockAccount(String userId, String locked);
/**
*

@ -0,0 +1,35 @@
/**
* Copyright 2020 OPSLI https://www.opsli.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 org.opsli.common.constants;
/**
*
*
* @author Parker
* @date 202131015:50:16
*/
public interface MenuConstants {
/** 菜单类型 */
String MENU = "1";
/** 按钮类型 */
String BUTTON = "2";
/** 外链类型 */
String EXTERNAL = "3";
}

@ -20,8 +20,17 @@ public enum DictType {
this.code = code;
}
public String getCode(){
return this.code;
}
public static DictType getType(String code) {
DictType[] var1 = values();
for (DictType type : var1) {
if (type.code.equalsIgnoreCase(code)) {
return type;
}
}
return null;
}
}

@ -101,7 +101,7 @@ public final class WrapperUtil {
*/
public static <T,M> List<M> transformInstance(Collection<T> source, Class<M> target, boolean isClone){
if(CollUtil.isEmpty(source)){
return null;
return Lists.newArrayList();
}
if(isClone){

@ -61,6 +61,9 @@ public enum SystemMsg implements BaseMsg {
EXCEPTION_USER_ORG_ERROR(20308,"用户组织设置失败"),
EXCEPTION_USER_NULL(20309,"暂无该用户: {}"),
EXCEPTION_USER_FILE_NULL(20310,"请选择文件"),
EXCEPTION_USER_ILLEGAL_PARAMETER(20311,"非法参数"),
EXCEPTION_USER_LOCK_SELF(20312,"不可锁定自身"),
EXCEPTION_USER_DEL_SELF(20312,"不可删除自身"),
/**

@ -35,6 +35,7 @@ import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog;
import org.opsli.common.annotation.RequiresPermissionsCus;
import org.opsli.common.constants.MenuConstants;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.WrapperUtil;
import org.opsli.core.base.controller.BaseRestController;
@ -69,9 +70,6 @@ import java.util.Map;
public class MenuRestController extends BaseRestController<SysMenu, MenuModel, IMenuService>
implements MenuApi {
/** 外部链接值 */
private static final String EXTERNAL_LINKS_VAL = "3";
/**
* -
*
@ -90,6 +88,14 @@ public class MenuRestController extends BaseRestController<SysMenu, MenuModel, I
throw new ServiceException(SystemMsg.EXCEPTION_USER_MENU_NOT_NULL);
}
// 这里有坑 如果 为 菜单数据 且 组件(Component)地址为空 不会跳转到主页 也不报错
// 修复菜单问题导致无法跳转主页
menuModelList.removeIf(menuModel -> MenuConstants.MENU.equals(menuModel.getType()) &&
(StringUtils.isEmpty(menuModel.getComponent()) ||
StringUtils.isEmpty(menuModel.getMenuCode()) ||
StringUtils.isEmpty(menuModel.getUrl())
));
// 获得当前用户权限
List<String> perms = UserUtil.getUserAllPermsByUserId(user.getId());
if(CollUtil.isNotEmpty(perms)){
@ -117,7 +123,7 @@ public class MenuRestController extends BaseRestController<SysMenu, MenuModel, I
tree.setName(treeNode.getMenuName());
// 扩展属性 ...
// 不是外链 则处理组件
if(!EXTERNAL_LINKS_VAL.equals(treeNode.getType())){
if(!MenuConstants.EXTERNAL.equals(treeNode.getType())){
tree.putExtra("component", treeNode.getComponent());
}
tree.putExtra("type", treeNode.getType());
@ -128,7 +134,7 @@ public class MenuRestController extends BaseRestController<SysMenu, MenuModel, I
metaMap.put("title", treeNode.getMenuName());
metaMap.put("icon", treeNode.getIcon());
// 外链处理
if(EXTERNAL_LINKS_VAL.equals(treeNode.getType())){
if(MenuConstants.EXTERNAL.equals(treeNode.getType())){
metaMap.put("target", "_blank");
metaMap.put("badge", "New");
}
@ -159,7 +165,7 @@ public class MenuRestController extends BaseRestController<SysMenu, MenuModel, I
// 这里有坑 如果 为 菜单数据 且 组件(Component)地址为空 不会跳转到主页 也不报错
// 修复菜单问题导致无法跳转主页
menuList.removeIf(menuModel -> "1".equals(menuModel.getType()) &&
menuList.removeIf(menuModel -> MenuConstants.MENU.equals(menuModel.getType()) &&
(StringUtils.isEmpty(menuModel.getComponent()) ||
StringUtils.isEmpty(menuModel.getMenuCode()) ||
StringUtils.isEmpty(menuModel.getUrl())
@ -181,7 +187,7 @@ public class MenuRestController extends BaseRestController<SysMenu, MenuModel, I
tree.setName(treeNode.getMenuCode());
// 扩展属性 ...
// 不是外链 则处理组件
if(!EXTERNAL_LINKS_VAL.equals(treeNode.getType())){
if(!MenuConstants.EXTERNAL.equals(treeNode.getType())){
tree.putExtra("component", treeNode.getComponent());
}else{
// 如果是外链 则判断是否存在 BASE_PATH
@ -200,7 +206,7 @@ public class MenuRestController extends BaseRestController<SysMenu, MenuModel, I
metaMap.put("title", treeNode.getMenuName());
metaMap.put("icon", treeNode.getIcon());
// 外链处理
if(EXTERNAL_LINKS_VAL.equals(treeNode.getType())){
if(MenuConstants.EXTERNAL.equals(treeNode.getType())){
metaMap.put("target", "_blank");
}
tree.putExtra("meta", metaMap);

@ -131,13 +131,6 @@ public class SysOptionsServiceImpl extends CrudServiceImpl<SysOptionsMapper, Sys
throw new ServiceException(SystemMsg.EXCEPTION_OPTIONS_UPDATE);
}
// 唯一验证
Integer count = this.uniqueVerificationByCode(optionsModel);
if(count != null && count > 0){
// 重复
throw new ServiceException(SystemMsg.EXCEPTION_OPTIONS_UNIQUE);
}
// 设置值
optionsModel.setOptionValue(value);
optionsModel.setVersion(null);

@ -22,11 +22,13 @@ import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.util.ReflectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.api.web.system.org.SysOrgRestApi;
@ -88,6 +90,7 @@ public class SysOrgRestController extends BaseRestController<SysOrg, SysOrgModel
// 获得用户 对应菜单
List<SysOrg> dataList = IService.findList(wrapper);
List<SysOrgModel> orgModelList = WrapperUtil.transformInstance(dataList, modelClazz);
// 0 为初始值
if(PARENT_ID.equals(parentId)){
// 显示全部

@ -89,7 +89,7 @@ public class RoleRestController extends BaseRestController<SysRole, RoleModel, I
* @return ResultVo
*/
@ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器")
@RequiresPermissions("system_role_select")
//@RequiresPermissions("system_role_select")
@Override
public ResultVo<?> findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) {

@ -82,7 +82,7 @@ public class TenantRestController extends BaseRestController<SysTenant, TenantMo
* @return ResultVo
*/
@ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器")
@RequiresPermissions("system_tenant_select")
//@RequiresPermissions("system_tenant_select")
@Override
public ResultVo<?> findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) {

@ -104,6 +104,14 @@ public interface IUserService extends CrudServiceInterface<SysUser, UserModel> {
boolean updateAvatar(UserModel model);
/**
*
* @param userId ID
* @param locked
* @return
*/
boolean lockAccount(String userId, String locked);
/**
*
*

@ -24,6 +24,7 @@ import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.menu.MenuModel;
import org.opsli.api.wrapper.system.options.OptionsModel;
import org.opsli.api.wrapper.system.user.UserAndOrgModel;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.api.wrapper.system.user.UserPassword;
@ -38,13 +39,17 @@ import org.opsli.core.persistence.Page;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.persistence.querybuilder.chain.TenantHandler;
import org.opsli.core.utils.OptionsUtil;
import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.menu.entity.SysMenu;
import org.opsli.modulars.system.menu.service.IMenuService;
import org.opsli.modulars.system.role.entity.SysRole;
import org.opsli.modulars.system.role.service.IRoleService;
import org.opsli.modulars.system.user.entity.SysUser;
import org.opsli.modulars.system.user.entity.SysUserAndOrg;
import org.opsli.modulars.system.user.mapper.UserMapper;
import org.opsli.modulars.system.user.service.IUserRoleRefService;
import org.opsli.modulars.system.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -67,6 +72,10 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
private UserMapper mapper;
@Autowired
private IMenuService iMenuService;
@Autowired
private IRoleService iRoleService;
@Autowired
private IUserRoleRefService iUserRoleRefService;
@Override
@Transactional(rollbackFor = Exception.class)
@ -121,7 +130,33 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
this.update(updateWrapper);
}
return super.insert(model);
UserModel insertModel = super.insert(model);
// 新增用户 设置默认角色
if(insertModel != null){
String defRole = null;
// 获得option 缓存中 角色编号
OptionsModel optionsModel = OptionsUtil.getOptionByCode("def_role");
if(optionsModel != null){
defRole = optionsModel.getOptionValue();
}
if(StringUtils.isNotBlank(defRole)){
QueryWrapper<SysRole> roleQueryWrapper = new QueryWrapper<>();
roleQueryWrapper.eq("role_code", defRole);
roleQueryWrapper.eq(
HumpUtil.humpToUnderline(MyBatisConstants.FIELD_DELETE_LOGIC),
DictType.NO_YES_NO.getCode());
SysRole sysRole = iRoleService.getOne(roleQueryWrapper);
if(sysRole != null){
// 设置用户默认角色
iUserRoleRefService.setRoles(insertModel.getId(),
Convert.toStrArray(sysRole.getId()));
}
}
}
return insertModel;
}
@Override
@ -160,6 +195,7 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
model.setPassword(null);
model.setSecretKey(null);
model.setLoginIp(null);
model.setLocked(null);
UserModel update = super.update(model);
if(update != null){
@ -178,12 +214,39 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
return update;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean lockAccount(String userId, String locked) {
UserModel model = this.get(userId);
if(model == null){
return false;
}
UserModel currUser = UserUtil.getUser();
if(StringUtils.equals(currUser.getId(), userId)){
// 不可锁定自身
throw new ServiceException(SystemMsg.EXCEPTION_USER_LOCK_SELF);
}
UpdateWrapper<SysUser> updateWrapper = new UpdateWrapper<>();
updateWrapper.set("locked", locked).eq(
HumpUtil.humpToUnderline(MyBatisConstants.FIELD_ID), userId
);
if(this.update(updateWrapper)){
// 刷新用户缓存
this.clearCache(Collections.singletonList(model));
return true;
}
return false;
}
@Override
public boolean delete(String id) {
// 杜绝我删我自己行为
UserModel currUser = UserUtil.getUser();
if(StringUtils.equals(currUser.getId(), id)){
return false;
// 不可删除自身
throw new ServiceException(SystemMsg.EXCEPTION_USER_DEL_SELF);
}
UserModel userModel = super.get(id);
@ -210,7 +273,8 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
// 杜绝我删我自己行为
UserModel currUser = UserUtil.getUser();
if(StringUtils.equals(currUser.getId(), userModel.getId())){
return false;
// 不可删除自身
throw new ServiceException(SystemMsg.EXCEPTION_USER_DEL_SELF);
}
boolean ret = super.delete(model);
@ -232,7 +296,8 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
UserModel currUser = UserUtil.getUser();
for (String id : ids) {
if(StringUtils.equals(currUser.getId(), id)){
return false;
// 不可删除自身
throw new ServiceException(SystemMsg.EXCEPTION_USER_DEL_SELF);
}
}
@ -266,7 +331,8 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
List<String> idList = Lists.newArrayListWithCapacity(models.size());
for (UserModel model : models) {
if(StringUtils.equals(currUser.getId(), model.getId())){
return false;
// 不可删除自身
throw new ServiceException(SystemMsg.EXCEPTION_USER_DEL_SELF);
}
idList.add(model.getId());
}

@ -35,11 +35,13 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.api.web.system.user.UserApi;
import org.opsli.api.wrapper.system.menu.MenuModel;
import org.opsli.api.wrapper.system.options.OptionsModel;
import org.opsli.api.wrapper.system.user.*;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog;
import org.opsli.common.annotation.RequiresPermissionsCus;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.enums.DictType;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.exception.TokenException;
import org.opsli.common.utils.HumpUtil;
@ -50,6 +52,7 @@ import org.opsli.core.persistence.Page;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.persistence.querybuilder.WebQueryBuilder;
import org.opsli.core.utils.OptionsUtil;
import org.opsli.core.utils.OrgUtil;
import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.system.SystemMsg;
@ -259,8 +262,17 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
// 演示模式 不允许操作
super.demoError();
// 配置文件默认密码
String defPass = globalProperties.getAuth().getDefaultPass();
// 缓存默认密码 优先缓存
OptionsModel optionsModel = OptionsUtil.getOptionByCode("def_pass");
if(optionsModel != null){
defPass = optionsModel.getOptionValue();
}
UserPassword userPassword = new UserPassword();
userPassword.setNewPassword(globalProperties.getAuth().getDefaultPass());
userPassword.setNewPassword(defPass);
userPassword.setUserId(userId);
boolean resetPasswordFlag = IService.resetPassword(userPassword);
@ -268,9 +280,36 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
return ResultVo.error("重置密码失败");
}
return ResultVo.success("重置密码成功!默认密码为:" + globalProperties.getAuth().getDefaultPass());
return ResultVo.success("重置密码成功!默认密码为:" + defPass);
}
/**
*
* @return ResultVo
*/
@ApiOperation(value = "锁定账户", notes = "锁定账户")
@RequiresPermissions("system_user_lockAccount")
@EnableLog
@Override
public ResultVo<?> lockAccount(String userId, String locked) {
// 演示模式 不允许操作
super.demoError();
DictType dictType = DictType.getType(locked);
if(dictType == null){
// 非法参数
throw new ServiceException(SystemMsg.EXCEPTION_USER_ILLEGAL_PARAMETER);
}
// 锁定账户
boolean lockAccountFlag = IService.lockAccount(userId, locked);
if(!lockAccountFlag){
return ResultVo.error("锁定账户失败");
}
return ResultVo.success();
}
/**
*
* @param model

@ -183,6 +183,7 @@ opsli:
# 超级管理员账号
super-admin: system
# 重置默认密码 密码至少包含大小写字母数字且不少于6位
# 优先使用 option 缓存, 如果缓存为空则使用配置文件
default-pass: Aa123456
# Token
token:

Loading…
Cancel
Save