baihe преди 1 година
родител
ревизия
982f24f0d0

+ 3 - 3
component-common/src/main/resources/application-common.yml

@@ -3,7 +3,7 @@ gihon:
   common:
     module-type: 1
     module-code: sso  
-    login-path: login
+    sso-path: sso
     muti-login: true
     white-url-list: 
       - /**error**
@@ -14,8 +14,8 @@ gihon:
       - /v3/**
       - /doc.html
       - /favicon.ico
-      - /**login
-      - /**login/refresh
+      - /**/login
+      - /**/login/refresh
       
     id-strategy:
       worker-id: 2

+ 1 - 0
component-springboot/src/main/java/com/gihon/component/rbac/controller/CompanyController.java

@@ -36,6 +36,7 @@ public class CompanyController {
     @ApiOperation("COMPANY:列表")
     @GetMapping("list")
     public Response<PageBean<GihonCompany>> list(@Validated CompanyListReq companyListReq) {
+        companyListReq.setCompanyId(AuthUtils.getCompanyId());
         IPage<GihonCompany> list = companyService.getCompanylistPage(companyListReq);
         return Response.okPage(list);
     }

+ 16 - 7
component-springboot/src/main/java/com/gihon/component/rbac/controller/RoleController.java

@@ -20,6 +20,8 @@ import com.gihon.component.rbac.vo.RoleButtonReq;
 import com.gihon.component.rbac.vo.RoleListReq;
 import com.gihon.component.response.PageBean;
 import com.gihon.component.response.Response;
+import com.gihon.component.response.SelectVal;
+import com.gihon.component.web.auth.AuthUtils;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -35,24 +37,25 @@ public class RoleController {
 	@ApiOperation("ROLE:角色列表")
 	@GetMapping("list")
 	public Response<PageBean<GihonRole>> list(RoleListReq roleListReq) {
+	    roleListReq.setCompanyId(AuthUtils.getCompanyId());
 		IPage<GihonRole> list = roleService.getRolelistPage(roleListReq);
 		return Response.okPage(list);
 	}
 
-	@ApiOperation("模块:新增")
+	@ApiOperation("ROLE:新增")
 	@PostMapping("")
 	public Response<Void> saveRole(@RequestBody GihonRole role) {
 		roleService.saveRole(role);
 		return Response.ok();
 	}
 	
-	@ApiOperation("模块:详情")
+	@ApiOperation("ROLE:详情")
 	@GetMapping("/{id}")
 	public Response<GihonRole> saveRole(@PathVariable Long id) {
 		return Response.ok(roleService.getById(id));
 	}
 
-	@ApiOperation("模块:编辑")
+	@ApiOperation("ROLE:编辑")
 	@PostMapping("/{id}")
 	public Response<Void> updateRole(@RequestBody GihonRole role, @PathVariable Long id) {
 		role.setId(id);
@@ -60,14 +63,19 @@ public class RoleController {
 		return Response.ok();
 	}
 
-	@ApiOperation("模块:删除")
+	@ApiOperation("ROLE:删除")
 	@DeleteMapping("/{id}")
-	public Response<Void> removeRole(@RequestBody GihonRole role, @PathVariable Long id) {
-		role.setId(id);
-		roleService.removeRole(role);
+	public Response<Void> removeRole(@PathVariable Long id) {
+		roleService.removeRole(id);
 		return Response.ok();
 	}
 
+    @ApiOperation("ROLE:列表")
+    @GetMapping("/labelAndValue")
+    public Response<List<SelectVal>> labelAndValue(Long comanyId,String roleName) {
+        return Response.ok(roleService.labelAndValue(comanyId,roleName));
+    }
+    
 	@ApiOperation("ROLE:权限列表")
 	@PostMapping("button/list")
 	public Response<List<GihonButton>> getButtonByRoleModule(@RequestParam Long roleId, @RequestParam Long moduleId) {
@@ -80,4 +88,5 @@ public class RoleController {
 		roleService.setButtonByRoleModule(req);
 		return Response.ok();
 	}
+	
 }

+ 4 - 1
component-springboot/src/main/java/com/gihon/component/rbac/service/GihonRoleService.java

@@ -8,6 +8,7 @@ import com.gihon.component.rbac.entity.GihonButton;
 import com.gihon.component.rbac.entity.GihonRole;
 import com.gihon.component.rbac.vo.RoleButtonReq;
 import com.gihon.component.rbac.vo.RoleListReq;
+import com.gihon.component.response.SelectVal;
 
 public interface GihonRoleService extends IService<GihonRole> {
 
@@ -39,7 +40,7 @@ public interface GihonRoleService extends IService<GihonRole> {
     /**
      * 移除一个角色
      */
-    public boolean removeRole(GihonRole role);
+    public boolean removeRole(Long roleId);
 
     /**
      * 获取在某个模块下的按钮权限
@@ -50,4 +51,6 @@ public interface GihonRoleService extends IService<GihonRole> {
      * 设置角色在某个模块下的按钮权限
      */
     public boolean setButtonByRoleModule(RoleButtonReq req);
+    
+    public List<SelectVal> labelAndValue(Long companyId,String roleName);
 }

+ 1 - 1
component-springboot/src/main/java/com/gihon/component/rbac/service/PermissionService.java

@@ -6,5 +6,5 @@ import com.gihon.component.web.vo.MenuVO;
 
 public interface PermissionService {
 
-    List<MenuVO> getPermission();
+    List<MenuVO> getPermission(String moduleCode,int moduleType);
 }

+ 5 - 3
component-springboot/src/main/java/com/gihon/component/rbac/service/impl/GihonCompanyServiceImpl.java

@@ -30,9 +30,11 @@ public class GihonCompanyServiceImpl extends ServiceImpl<GihonCompanyMapper, Gih
      * 分页获取公司列表
      */
     public IPage<GihonCompany> getCompanylistPage(CompanyListReq companyListReq) {
-        Page<GihonCompany> page = new Page<GihonCompany>(companyListReq.getPageIndex(), companyListReq.getPageSize());
-        return this.lambdaQuery().like(StringUtils.hasText(companyListReq.getCompanyName()),
-            GihonCompany::getCompanyName, companyListReq.getCompanyName()).page(page);
+        Page<GihonCompany> page = new Page<>(companyListReq.getPageIndex(), companyListReq.getPageSize());
+        return this.lambdaQuery()
+            .like(StringUtils.hasText(companyListReq.getCompanyName()), GihonCompany::getCompanyName, companyListReq.getCompanyName())
+            .eq(companyListReq.getCompanyId()!=null,GihonCompany::getId, companyListReq.getCompanyId())
+            .page(page);
     }
 
     /**

+ 38 - 15
component-springboot/src/main/java/com/gihon/component/rbac/service/impl/GihonRoleServiceImpl.java

@@ -12,13 +12,16 @@ import org.springframework.util.StringUtils;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gihon.component.entity.BaseEntity;
 import com.gihon.component.exception.BusinessException;
 import com.gihon.component.rbac.entity.GihonButton;
+import com.gihon.component.rbac.entity.GihonCompany;
 import com.gihon.component.rbac.entity.GihonRole;
 import com.gihon.component.rbac.mapper.GihonRoleMapper;
 import com.gihon.component.rbac.service.GihonRoleService;
 import com.gihon.component.rbac.vo.RoleButtonReq;
 import com.gihon.component.rbac.vo.RoleListReq;
+import com.gihon.component.response.SelectVal;
 
 /**
  * 直接继承没有多实现处理
@@ -63,19 +66,26 @@ public class GihonRoleServiceImpl extends ServiceImpl<GihonRoleMapper, GihonRole
      * 前端分页获取角色列表
      */
     public IPage<GihonRole> getRolelistPage(RoleListReq companyListReq) {
-        Page<GihonRole> page = new Page<GihonRole>(companyListReq.getPageIndex(), companyListReq.getPageSize());
-        return this.lambdaQuery().like(StringUtils.hasText(companyListReq.getRoleName()), GihonRole::getRoleName, companyListReq.getRoleName())
-                .like(StringUtils.hasText(companyListReq.getRoleCode()), GihonRole::getRoleCode, companyListReq.getRoleCode()).page(page);
+        Page<GihonRole> page = new Page<>(companyListReq.getPageIndex(), companyListReq.getPageSize());
+        return this.lambdaQuery()
+            .like(StringUtils.hasText(companyListReq.getRoleName()), GihonRole::getRoleName,
+                companyListReq.getRoleName())
+            .like(StringUtils.hasText(companyListReq.getRoleCode()), GihonRole::getRoleCode,
+                companyListReq.getRoleCode())
+            .eq(companyListReq.getCompanyId() != null, GihonRole::getCompanyId, companyListReq.getCompanyId())
+            .page(page);
     }
 
     /**
      * 新增角色
      */
     public boolean saveRole(GihonRole role) {
-        int count = this.lambdaQuery().eq(GihonRole::getRoleName, role.getRoleName()).or().eq(GihonRole::getRoleCode, role.getRoleCode()).count();
+        int count = this.lambdaQuery().eq(GihonRole::getRoleName, role.getRoleName()).or()
+            .eq(GihonRole::getRoleCode, role.getRoleCode()).count();
         if (count > 0) {
             throw new BusinessException("角色名称或编码重复");
         }
+        role.setState(0);
         return this.save(role);
     }
 
@@ -107,24 +117,24 @@ public class GihonRoleServiceImpl extends ServiceImpl<GihonRoleMapper, GihonRole
      * 移除一个角色
      */
     @Transactional(rollbackFor = Exception.class)
-    public boolean removeRole(GihonRole role) {
-        GihonRole roleOld = this.getById(role.getId());
+    public boolean removeRole(Long roleId) {
+        GihonRole roleOld = this.getById(roleId);
         if (roleOld == null) {
             throw new BusinessException("角色不存在");
         }
         // 异步通知
-        gihonRoleButtonService.removeButtonByRoleId(role.getId(), null);
-        gihonUserRoleService.removeRoleByUserId(role.getId());
-        return this.removeById(role.getId());
+        gihonRoleButtonService.removeButtonByRoleId(roleId, null);
+        gihonUserRoleService.removeRoleByUserId(roleId);
+        return this.removeById(roleId);
     }
 
     /**
-     * 获取在某个模块下的按钮权限
-     * 如果是缓存的时候需要异步通知
+     * 获取在某个模块下的按钮权限 如果是缓存的时候需要异步通知
      */
     public List<GihonButton> getButtonByRoleModule(Long roleId, Long moduleId) {
-        List<Long> menuIdList = gihonMenuService.getAllMenu(moduleId,true).stream().map(m -> m.getId()).collect(Collectors.toList());
-        List<GihonButton> btnList = gihonButtonService.getMenuButton(menuIdList,false);
+        List<Long> menuIdList =
+            gihonMenuService.getAllMenu(moduleId, true).stream().map(BaseEntity::getId).collect(Collectors.toList());
+        List<GihonButton> btnList = gihonButtonService.getMenuButton(menuIdList, false);
         List<Long> btnCheckedList = gihonRoleButtonService.getButtonListByRole(roleId);
         btnList.forEach(b -> b.setChecked(btnCheckedList.contains(b.getId())));
         return btnList;
@@ -135,8 +145,10 @@ public class GihonRoleServiceImpl extends ServiceImpl<GihonRoleMapper, GihonRole
      */
     @Transactional(rollbackFor = Exception.class)
     public boolean setButtonByRoleModule(RoleButtonReq req) {
-        List<Long> menuIdList = gihonMenuService.getAllMenu(req.getModuleId(),true).stream().map(m -> m.getId()).collect(Collectors.toList());
-        List<Long> allbtnList = gihonButtonService.getMenuButton(menuIdList,true).stream().map(m -> m.getId()).collect(Collectors.toList());
+        List<Long> menuIdList = gihonMenuService.getAllMenu(req.getModuleId(), true).stream().map(m -> m.getId())
+            .collect(Collectors.toList());
+        List<Long> allbtnList = gihonButtonService.getMenuButton(menuIdList, true).stream().map(m -> m.getId())
+            .collect(Collectors.toList());
         List<Long> btnoldList = gihonRoleButtonService.getButtonListByRole(req.getRoleId());
         btnoldList.retainAll(allbtnList);// 求交集,属于当前模块的角色配置
         req.getButtonList().retainAll(allbtnList);
@@ -155,4 +167,15 @@ public class GihonRoleServiceImpl extends ServiceImpl<GihonRoleMapper, GihonRole
 
         return true;
     }
+
+    @Override
+    public List<SelectVal> labelAndValue(Long companyId, String roleName) {
+        return this.lambdaQuery()
+            .like(StringUtils.hasText(roleName), GihonRole::getRoleName, roleName)
+            .eq(companyId != null, GihonRole::getId, companyId)
+            .orderByDesc(GihonRole::getRoleName)
+            .list().stream().map(c -> SelectVal.builder().value(c.getId().toString()).label(c.getRoleName()).build())
+            .collect(Collectors.toList());
+    }
+    
 }

+ 6 - 11
component-springboot/src/main/java/com/gihon/component/rbac/service/impl/PermissionServiceImpl.java

@@ -15,7 +15,6 @@ import org.springframework.stereotype.Service;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.gihon.component.entity.BaseEntity;
 import com.gihon.component.enums.ModuleType;
-import com.gihon.component.properties.GihonCommonProperties;
 import com.gihon.component.properties.RedisConstants;
 import com.gihon.component.rbac.entity.GihonButton;
 import com.gihon.component.rbac.entity.GihonMenu;
@@ -43,9 +42,6 @@ public class PermissionServiceImpl implements PermissionService {
     @Autowired
     private StringRedisTemplate stringRedisTemplate;
 
-    @Autowired
-    private GihonCommonProperties gihonCommonProperties;
-
     @Autowired
     private GihonModuleService gihonModuleService;
 
@@ -62,10 +58,9 @@ public class PermissionServiceImpl implements PermissionService {
     private GihonRoleService gihonRoleService;
 
     @Override
-    public List<MenuVO> getPermission() {
+    public List<MenuVO> getPermission(String moduleCode,int moduleType) {
 
-        String menuJson = (String)stringRedisTemplate.opsForHash().get(RedisConstants.MENU_TREE_REDIS,
-            gihonCommonProperties.getModuleCode() + RedisConstants.SEP + gihonCommonProperties.getModuleType());
+        String menuJson = (String)stringRedisTemplate.opsForHash().get(RedisConstants.MENU_TREE_REDIS, moduleCode + RedisConstants.SEP + moduleType);
         TypeReference<List<MenuVO>> valueTypeRef = new TypeReference<List<MenuVO>>() {};
         List<MenuVO> root = JacksonJsonUtils.readObject(menuJson, valueTypeRef);
         // 原始
@@ -73,7 +68,7 @@ public class PermissionServiceImpl implements PermissionService {
 
         AuthUser user = AuthUtils.getUser();
         if (AuthConstans.SUPER_ADMIN.equals(user.getUsername())
-            && gihonCommonProperties.getModuleType() == ModuleType.WEB.getCode()) {
+            && moduleType == ModuleType.WEB.getCode()) {
 
             return root;
         }
@@ -134,7 +129,7 @@ public class PermissionServiceImpl implements PermissionService {
                 List<MenuVO> menus = new ArrayList<>();
 
                 MenuVO root = new MenuVO();
-                root.setMenuCode(gihonCommonProperties.getModuleCode());
+                root.setMenuCode(module.getModuleCode());
                 root.setMenuId(-1L);
 
                 menus.add(root);
@@ -180,11 +175,11 @@ public class PermissionServiceImpl implements PermissionService {
                 }
                 // 用于拦截器的访问权限按钮
                 stringRedisTemplate.opsForHash().put(RedisConstants.PERMISSN_REDIS,
-                    gihonCommonProperties.getModuleCode() + RedisConstants.SEP + gihonCommonProperties.getModuleType(),
+                    module.getModuleCode() + RedisConstants.SEP + module.getModuleType(),
                     JacksonJsonUtils.writeObject(plist));
                 // 用于拦截器的访问权限按钮
                 stringRedisTemplate.opsForHash().put(RedisConstants.MENU_TREE_REDIS,
-                    gihonCommonProperties.getModuleCode() + RedisConstants.SEP + gihonCommonProperties.getModuleType(),
+                    module.getModuleCode() + RedisConstants.SEP + module.getModuleType(),
                     JacksonJsonUtils.writeObject(menus));
             }
         } catch (Exception e) {

+ 3 - 0
component-springboot/src/main/java/com/gihon/component/rbac/vo/CompanyListReq.java

@@ -15,4 +15,7 @@ public class CompanyListReq extends PageReq{
 	@ApiModelProperty("公司名称")
 	private String companyName;
 	
+	@ApiModelProperty("公司名称")
+    private Long companyId;
+	
 }

+ 3 - 1
component-springboot/src/main/java/com/gihon/component/rbac/vo/RoleListReq.java

@@ -17,5 +17,7 @@ public class RoleListReq extends PageReq {
 
 	@ApiModelProperty("角色编码")
 	private String roleCode;
-
+	
+	@ApiModelProperty("所属公司")
+	private Long companyId;
 }

+ 1 - 1
component-springboot/src/main/java/com/gihon/component/sso/controller/LoginController.java

@@ -24,7 +24,7 @@ import lombok.extern.slf4j.Slf4j;
 
 @Api("SSO认证模块")
 @Slf4j
-@RequestMapping("${gihon.common.login-path:'login'}")
+@RequestMapping("${gihon.common.sso-path:'sso'}/login")
 @RestController
 public class LoginController {
 

+ 4 - 4
component-springboot/src/main/java/com/gihon/component/rbac/controller/PermissionContoller.java → component-springboot/src/main/java/com/gihon/component/sso/controller/PermissionContoller.java

@@ -1,4 +1,4 @@
-package com.gihon.component.rbac.controller;
+package com.gihon.component.sso.controller;
 
 import java.util.List;
 
@@ -16,7 +16,7 @@ import io.swagger.annotations.ApiOperation;
 
 @Api(value ="根据权限获取菜单当前系统菜单" ,tags = "根据权限获取菜单当前系统菜单")
 @RestController
-@RequestMapping("/rbac/permission")
+@RequestMapping("${gihon.common.sso-path:'sso'}/permission")
 public class PermissionContoller {
 
     @Autowired
@@ -24,8 +24,8 @@ public class PermissionContoller {
     
     @ApiOperation("权限菜单:列表用于前后端分离判断路由和按钮")
     @GetMapping()
-    public Response<List<MenuVO>> getPermission() {
-        List<MenuVO> list = permissionService.getPermission();
+    public Response<List<MenuVO>> getPermission(String moduleCode,int moduleType) {
+        List<MenuVO> list = permissionService.getPermission(moduleCode,moduleType);
         return Response.ok(list);
     }
 }

+ 0 - 1
component-springboot/src/main/resources/application-dev.yml

@@ -13,6 +13,5 @@ gihon:
   common:
     executor: false
     async: false
-    login-path: 'sso/login'
     module-type: 1
     module-code: SystemManage