Bladeren bron

优化登录公司和人员列表

baihe 1 jaar geleden
bovenliggende
commit
dade0fa72a
27 gewijzigde bestanden met toevoegingen van 423 en 173 verwijderingen
  1. 8 1
      component-common/src/main/java/com/gihon/component/config/ScheduleConfig.java
  2. 5 0
      component-common/src/main/java/com/gihon/component/config/ThreadPoolConfig.java
  3. 1 1
      component-common/src/main/java/com/gihon/component/properties/GihonCommonProperties.java
  4. 1 1
      component-common/src/main/java/com/gihon/component/web/auth/AuthConstans.java
  5. 12 10
      component-common/src/main/java/com/gihon/component/web/auth/AuthUtils.java
  6. 10 10
      component-database/src/main/java/com/gihon/component/config/MyMetaObjectHandler.java
  7. 6 0
      component-database/src/main/java/com/gihon/component/service/GihonCompanyService.java
  8. 44 1
      component-database/src/main/java/com/gihon/component/service/GihonUserService.java
  9. 28 9
      component-database/src/main/java/com/gihon/component/service/impl/GihonCompanyServiceImpl.java
  10. 29 1
      component-database/src/main/java/com/gihon/component/service/impl/GihonUserServiceImpl.java
  11. 24 0
      component-database/src/main/java/com/gihon/component/vo/rabc/UserListReq.java
  12. 10 0
      component-entity/src/main/java/com/gihon/component/entity/CompanyBaseEntity.java
  13. 2 2
      component-entity/src/main/java/com/gihon/component/entity/rbac/GihonButton.java
  14. 7 0
      component-entity/src/main/java/com/gihon/component/entity/rbac/GihonCompany.java
  15. 2 2
      component-entity/src/main/java/com/gihon/component/entity/rbac/GihonMenu.java
  16. 1 0
      component-entity/src/main/java/com/gihon/component/entity/rbac/GihonModule.java
  17. 39 26
      component-entity/src/main/java/com/gihon/component/entity/rbac/GihonUser.java
  18. 1 1
      component-entity/src/main/java/com/gihon/component/response/ResponseStatus.java
  19. 16 0
      component-entity/src/main/java/com/gihon/component/response/SelectVal.java
  20. 63 49
      component-springboot/src/main/java/com/gihon/component/rbac/controller/CompanyController.java
  21. 64 15
      component-springboot/src/main/java/com/gihon/component/rbac/controller/UserController.java
  22. 27 28
      component-springboot/src/main/java/com/gihon/component/rbac/service/impl/PermissionServiceImpl.java
  23. 5 5
      component-springboot/src/main/resources/application.yml
  24. 5 1
      component-websecurity/src/main/java/com/gihon/component/web/auth/impl/AuthServiceImpl.java
  25. 1 1
      component-websecurity/src/main/java/com/gihon/component/web/config/CommonWebConfig.java
  26. 11 8
      component-websecurity/src/main/java/com/gihon/component/web/config/DemoKnife4jConfig.java
  27. 1 1
      component-websecurity/src/main/java/com/gihon/component/web/service/impl/TokenServiceImpl.java

+ 8 - 1
component-common/src/main/java/com/gihon/component/config/ScheduleConfig.java

@@ -10,7 +10,14 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.annotation.SchedulingConfigurer;
 import org.springframework.scheduling.config.ScheduledTaskRegistrar;
 
-@ConditionalOnProperty(prefix = "gihon.common",havingValue = "true",matchIfMissing = false,name = "sync")
+/**
+ * Springboot 开启async 使用的线程池
+ * 默认是个单线程的
+ * 
+ * @author baihe
+ * @date 2023/03/20
+ */
+@ConditionalOnProperty(prefix = "gihon.common",havingValue = "true",matchIfMissing = false,name = "async")
 @Configuration
 public class ScheduleConfig implements SchedulingConfigurer {
     @Override

+ 5 - 0
component-common/src/main/java/com/gihon/component/config/ThreadPoolConfig.java

@@ -9,6 +9,11 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.core.task.TaskExecutor;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 
+/**
+ * Springboot 配置schedule的线程池
+ * @author baihe
+ * @date 2023/03/20
+ */
 @ConditionalOnProperty(prefix = "gihon.common",havingValue = "true",matchIfMissing = false,name = "executor")
 @Configuration
 public class ThreadPoolConfig {

+ 1 - 1
component-common/src/main/java/com/gihon/component/properties/GihonCommonProperties.java

@@ -30,7 +30,7 @@ public class GihonCommonProperties {
 
 	private IdStrategy idStrategy;
 	
-	private boolean sync;//是否开启异步或者schedule定时器
+	private boolean async;//是否开启异步或者schedule定时器
 	
 	private boolean executor;//是否创建一个线程池
 	 

+ 1 - 1
component-common/src/main/java/com/gihon/component/web/auth/AuthConstans.java

@@ -2,7 +2,7 @@ package com.gihon.component.web.auth;
 
 public interface AuthConstans {
 	
-	static final String BEARER_TYPE = "Bearear";
+	static final String BEARER_TYPE = "Bearer";
 	
 	static final String ACCESS_TOKEN = "token";
 	

+ 12 - 10
component-common/src/main/java/com/gihon/component/web/auth/AuthUtils.java

@@ -34,7 +34,7 @@ public class AuthUtils {
 
     public static ServletRequestAttributes getRequestAttributes() {
         RequestAttributes r = RequestContextHolder.currentRequestAttributes();
-    	return (ServletRequestAttributes) r;
+        return (ServletRequestAttributes)r;
     }
 
     public static HttpServletRequest getRequest() {
@@ -48,9 +48,15 @@ public class AuthUtils {
     }
 
     public static String getToken() {
-        HttpServletRequest request = getRequest();
-        return (String) request.getAttribute(AuthUtils.REQ_TOKEN);
+        try {
+            HttpServletRequest request = getRequest();
+            return (String)request.getAttribute(AuthUtils.REQ_TOKEN);
+        } catch (Exception e) {
+            log.error("获取当前登录用户异常:{}", e.getMessage());
+        }
+        return null;
     }
+
     public static Long getUserId() {
         AuthUser user = getUser();
         if (user != null) {
@@ -65,10 +71,10 @@ public class AuthUtils {
             HttpServletRequest request = getRequest();
             Object o = request.getAttribute(REQ_USER);
             if (o != null) {
-                user = (AuthUser) o;
+                user = (AuthUser)o;
             }
-        }catch (Exception e) {
-            log.error("获取当前登录用户异常:{}",e.getMessage());
+        } catch (Exception e) {
+            log.error("获取当前登录用户异常:{}", e.getMessage());
         }
         return user;
     }
@@ -96,7 +102,6 @@ public class AuthUtils {
         return token;
     }
 
-    @SuppressWarnings("unchecked")
     public static String parseHeaderToken(HttpServletRequest request) {
         Enumeration<String> headers = request.getHeaders(AuthConstans.HEADE_TOKEN);
         while (headers.hasMoreElements()) { // typically there is only one (most servers enforce that)
@@ -109,9 +114,6 @@ public class AuthUtils {
                 }
                 return authHeaderValue;
             } else {
-                // todo: support additional authorization schemes for different token types,
-                // e.g. "MAC" specified by
-                // http://tools.ietf.org/html/draft-hammer-oauth-v2-mac-token
                 String authHeaderValue = value.trim();
                 int commaIndex = authHeaderValue.indexOf(',');
                 if (commaIndex > 0) {

+ 10 - 10
component-database/src/main/java/com/gihon/component/config/MyMetaObjectHandler.java

@@ -1,19 +1,14 @@
 package com.gihon.component.config;
 
 import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.List;
 
 import org.apache.ibatis.reflection.MetaObject;
 import org.springframework.util.StringUtils;
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
-import com.baomidou.mybatisplus.core.handlers.StrictFill;
 import com.baomidou.mybatisplus.core.metadata.TableInfo;
 import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
-import com.gihon.component.entity.BaseEntity;
-import com.gihon.component.entity.CompanyBaseEntity;
 import com.gihon.component.util.Snowflake;
 import com.gihon.component.web.auth.AuthUtils;
 
@@ -30,6 +25,9 @@ public class MyMetaObjectHandler implements MetaObjectHandler {
     private static final String ID_TYPE = "java.lang.String";
 
     private static final String FIELD_ID = "id";
+    private static final String FIELD_COMPANYID= "companyId";
+    private static final String FIELD_CREATE_USER = "createUser";
+    private static final String FIELD_UPDATE_USER = "updateUser";
 
     private Snowflake snowflake;
 
@@ -60,11 +58,13 @@ public class MyMetaObjectHandler implements MetaObjectHandler {
         this.setFieldValByName("state", 0, metaObject);
         Long userId = AuthUtils.getUserId();
         if (userId != null) {
-            this.setFieldValByName("createUser", userId, metaObject);
-            this.setFieldValByName("updateUser", userId, metaObject);
+            this.setFieldValByName(FIELD_CREATE_USER, userId, metaObject);
+            this.setFieldValByName(FIELD_UPDATE_USER, userId, metaObject);
         }
-        this.setFieldValByName("companyId", AuthUtils.getCompanyId(), metaObject);
-        
+        if (metaObject.hasGetter(FIELD_COMPANYID) && this.getFieldValByName(FIELD_COMPANYID, metaObject) == null) {
+            this.setFieldValByName(FIELD_COMPANYID, AuthUtils.getCompanyId(), metaObject);
+        }
+
         TableInfo tableInfo = TableInfoHelper.getTableInfo(metaObject.getOriginalObject().getClass());
         if (tableInfo == null || tableInfo.getIdType() == IdType.AUTO) {
             return;
@@ -100,7 +100,7 @@ public class MyMetaObjectHandler implements MetaObjectHandler {
         this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
         Long userId = AuthUtils.getUserId();
         if (userId != null) {
-            this.setFieldValByName("updateUser", userId, metaObject);
+            this.setFieldValByName(FIELD_UPDATE_USER, userId, metaObject);
         }
 
     }

+ 6 - 0
component-database/src/main/java/com/gihon/component/service/GihonCompanyService.java

@@ -1,8 +1,11 @@
 package com.gihon.component.service;
 
+import java.util.List;
+
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.gihon.component.entity.rbac.GihonCompany;
+import com.gihon.component.response.SelectVal;
 import com.gihon.component.vo.CompanyListReq;
 
 public interface GihonCompanyService extends IService<GihonCompany> {
@@ -26,4 +29,7 @@ public interface GihonCompanyService extends IService<GihonCompany> {
      * 更新公司
      */
     public boolean updateCompany(GihonCompany company);
+    
+    
+    public List<SelectVal> labelAndValue(Long companyId,String companyName);
 }

+ 44 - 1
component-database/src/main/java/com/gihon/component/service/GihonUserService.java

@@ -1,8 +1,51 @@
 package com.gihon.component.service;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.gihon.component.entity.rbac.GihonUser;
+import com.gihon.component.exception.BusinessException;
+import com.gihon.component.util.PasswordUtils;
+import com.gihon.component.vo.rabc.UserListReq;
 
-public interface GihonUserService extends IService<GihonUser>{
+public interface GihonUserService extends IService<GihonUser> {
 
+    IPage<GihonUser> getUserlistPage(UserListReq search);
+    
+    default boolean enableCompany(Long userId, boolean enableFlag) {
+        return this.lambdaUpdate().eq(GihonUser::getId, userId).eq(GihonUser::getCompanyAdmin, !enableFlag)
+            .set(GihonUser::getCompanyAdmin, enableFlag).update();
+    }
+    
+    /**
+     * 新增
+     */
+    default boolean saveUser(GihonUser user) {
+        int count = this.lambdaQuery().eq(GihonUser::getUsername, user.getUsername()).count();
+        if (count > 0) {
+            throw new BusinessException("账号重复");
+        }
+        user.setState(0);
+        user.setCompanyAdmin(false);
+        user.setPassword(PasswordUtils.makePassword("123456", user.getUsername()));
+        return this.save(user);
+
+    }
+
+    /**
+     * 更新
+     */
+    default boolean updateUser(GihonUser user) {
+        GihonUser compnayOld = this.getById(user.getId());
+        if (compnayOld == null) {
+            throw new BusinessException("账号不存在");
+        }
+        
+        GihonUser userUpdate = new GihonUser();
+        userUpdate.setId(user.getId());
+        userUpdate.setNickName(user.getNickName());
+        userUpdate.setTelephone(user.getTelephone());
+        userUpdate.setGender(user.getGender());
+        return this.updateById(userUpdate);
+
+    }
 }

+ 28 - 9
component-database/src/main/java/com/gihon/component/service/impl/GihonCompanyServiceImpl.java

@@ -1,5 +1,8 @@
 package com.gihon.component.service.impl;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
@@ -9,6 +12,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.gihon.component.entity.rbac.GihonCompany;
 import com.gihon.component.exception.BusinessException;
 import com.gihon.component.mapper.GihonCompanyMapper;
+import com.gihon.component.response.SelectVal;
 import com.gihon.component.service.GihonCompanyService;
 import com.gihon.component.vo.CompanyListReq;
 
@@ -19,15 +23,16 @@ import com.gihon.component.vo.CompanyListReq;
  *
  */
 @Service
-public class GihonCompanyServiceImpl extends ServiceImpl<GihonCompanyMapper, GihonCompany> implements GihonCompanyService {
+public class GihonCompanyServiceImpl extends ServiceImpl<GihonCompanyMapper, GihonCompany>
+    implements GihonCompanyService {
 
     /**
      * 分页获取公司列表
      */
     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);
+        return this.lambdaQuery().like(StringUtils.hasText(companyListReq.getCompanyName()),
+            GihonCompany::getCompanyName, companyListReq.getCompanyName()).page(page);
     }
 
     /**
@@ -35,20 +40,22 @@ public class GihonCompanyServiceImpl extends ServiceImpl<GihonCompanyMapper, Gih
      */
     public boolean enableCompany(Long companyId, Long userId, boolean enableFlag) {
 
-        return this.lambdaUpdate().eq(GihonCompany::getId, companyId).eq(GihonCompany::getEnable, !enableFlag).set(GihonCompany::getEnable, enableFlag)
-                .update();
+        return this.lambdaUpdate().eq(GihonCompany::getId, companyId).eq(GihonCompany::getEnable, !enableFlag)
+            .set(GihonCompany::getEnable, enableFlag).update();
 
     }
 
     /**
      * 新增公司
      */
-    public boolean saveCompany(GihonCompany compnay) {
-        int count = this.lambdaQuery().eq(GihonCompany::getCompanyName, compnay.getCompanyName()).count();
+    public boolean saveCompany(GihonCompany company) {
+        int count = this.lambdaQuery().eq(GihonCompany::getCompanyName, company.getCompanyName()).count();
         if (count > 0) {
             throw new BusinessException("公司名称重复");
         }
-        return this.save(compnay);
+        company.setState(0);
+        company.setEnable(true);
+        return this.save(company);
 
     }
 
@@ -60,7 +67,8 @@ public class GihonCompanyServiceImpl extends ServiceImpl<GihonCompanyMapper, Gih
         if (compnayOld == null) {
             throw new BusinessException("公司不存在");
         }
-        int count = this.lambdaQuery().eq(GihonCompany::getCompanyName, company.getCompanyName()).ne(GihonCompany::getId, company.getId()).count();
+        int count = this.lambdaQuery().eq(GihonCompany::getCompanyName, company.getCompanyName())
+            .ne(GihonCompany::getId, company.getId()).count();
         if (count > 0) {
             throw new BusinessException("公司名称重复");
         }
@@ -73,4 +81,15 @@ public class GihonCompanyServiceImpl extends ServiceImpl<GihonCompanyMapper, Gih
         return this.updateById(compnayUpdate);
 
     }
+
+    @Override
+    public List<SelectVal> labelAndValue(Long companyId, String companyName) {
+        return this.lambdaQuery().eq(StringUtils.hasText(companyName), GihonCompany::getCompanyName, companyName)
+            .eq(companyId != null, GihonCompany::getId, companyId)
+            .orderByDesc(GihonCompany::getCompanyName)
+            .list().stream().map(c -> SelectVal.builder().value(c.getId().toString()).label(c.getCompanyName()).build())
+            .collect(Collectors.toList());
+
+    }
+
 }

+ 29 - 1
component-database/src/main/java/com/gihon/component/service/impl/GihonUserServiceImpl.java

@@ -1,18 +1,46 @@
 package com.gihon.component.service.impl;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+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.rbac.GihonCompany;
 import com.gihon.component.entity.rbac.GihonUser;
 import com.gihon.component.mapper.rabc.GihonUserMapper;
+import com.gihon.component.service.GihonCompanyService;
 import com.gihon.component.service.GihonUserService;
+import com.gihon.component.vo.rabc.UserListReq;
 
 /**
  * 直接继承没有多实现处理
+ * 
  * @author baihe
  *
  */
 @Service
-public class GihonUserServiceImpl extends ServiceImpl<GihonUserMapper, GihonUser> implements GihonUserService{
+public class GihonUserServiceImpl extends ServiceImpl<GihonUserMapper, GihonUser> implements GihonUserService {
+
+    @Autowired
+    private GihonCompanyService gihonCompanyService;
+
+    public IPage<GihonUser> getUserlistPage(UserListReq search) {
+        Page<GihonUser> page = new Page<>(search.getPageIndex(), search.getPageSize());
+        IPage<GihonUser> result = this.lambdaQuery()
+            .like(StringUtils.hasText(search.getUsername()), GihonUser::getUsername, search.getUsername())
+            .eq(search.getCompanyId() != null, GihonUser::getCompanyId, search.getCompanyId())
+            .eq(search.getCompanyAdmin() != null, GihonUser::getCompanyAdmin, search.getCompanyAdmin()).page(page);
+        result.getRecords().forEach(u->{
+            if(u.getCompanyId()!=null) {
+                GihonCompany c = gihonCompanyService.getById(u.getCompanyId());
+                if (c != null) {
+                    u.setCompanyName(c.getCompanyName());
+                }
+            }
+        }); 
+        return result;
+    }
 
 }

+ 24 - 0
component-database/src/main/java/com/gihon/component/vo/rabc/UserListReq.java

@@ -0,0 +1,24 @@
+package com.gihon.component.vo.rabc;
+
+import com.gihon.component.vo.PageReq;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Setter
+@Getter
+@ApiModel("用户列表")
+public class UserListReq extends PageReq {
+
+	@ApiModelProperty("用户名称")
+	private String username;
+
+	@ApiModelProperty("所属公司")
+	private Long companyId;
+	
+	@ApiModelProperty("公司管理员")
+    private Boolean companyAdmin;
+
+}

+ 10 - 0
component-entity/src/main/java/com/gihon/component/entity/CompanyBaseEntity.java

@@ -1,5 +1,9 @@
 package com.gihon.component.entity;
 
+import javax.validation.constraints.NotNull;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Getter;
 import lombok.Setter;
@@ -13,7 +17,13 @@ import lombok.Setter;
 @Setter
 public class CompanyBaseEntity extends BaseEntity{
 	
+    @NotNull(message="所属公司必选")
 	@ApiModelProperty(value = "公司Id(支持SAAS)")
 	protected Long companyId;
 	
+	@TableField(exist = false)
+	@ApiModelProperty(value = "公司名称(支持SAAS)")
+    protected String companyName;
+	
+	
 }

+ 2 - 2
component-entity/src/main/java/com/gihon/component/entity/rbac/GihonButton.java

@@ -11,7 +11,7 @@ import lombok.Setter;
 /**
  * 系统模块下菜单按钮权限(RBAC)
  * 不在此中管理的全部值设为登录即可
- * 模块
+ * 模块(子系统)
  * 	->菜单1
  * 		->子菜单1
  * 			->list
@@ -35,7 +35,7 @@ public class GihonButton extends CompanyBaseEntity{
 	@ApiModelProperty(value = "菜单名称")
 	private String buttonName;
 	
-	@ApiModelProperty(value = "菜单编码唯一")
+	@ApiModelProperty(value = "菜单编码唯一:Vue通过此编码判断按钮功能权限")
 	private String buttonCode;
 	
 	@ApiModelProperty(value = "排序号升序")

+ 7 - 0
component-entity/src/main/java/com/gihon/component/entity/rbac/GihonCompany.java

@@ -1,5 +1,9 @@
 package com.gihon.component.entity.rbac;
 
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.Size;
+
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.gihon.component.entity.BaseEntity;
 
@@ -9,6 +13,7 @@ import lombok.Setter;
 
 /**
  * 系统公司
+ * 
  * @author baihe
  *
  */
@@ -17,6 +22,8 @@ import lombok.Setter;
 @TableName("gihon_company")
 public class GihonCompany extends BaseEntity{
 
+    @Size(max = 120,message="名称不能超过120个字符")
+    @NotBlank(message="名称不能为空")
 	@ApiModelProperty(value = "名称")
 	private String companyName;
 	

+ 2 - 2
component-entity/src/main/java/com/gihon/component/entity/rbac/GihonMenu.java

@@ -12,7 +12,7 @@ import lombok.Setter;
 
 /**
  * 系统模块下菜单(RBAC)
- * 模块
+ * 模块(子系统)
  * 	->菜单1
  * 		->子菜单1(显示页面,但是获取(操作)数据需要有按钮权限)
  *  	->子菜单2
@@ -47,6 +47,6 @@ public class GihonMenu extends CompanyBaseEntity{
 	@ApiModelProperty(value = "父菜单:-1的代表顶级菜单")
 	private Long parentId = -1L;
 	
-	@ApiModelProperty(value = "路由路径:可以为空")
+	@ApiModelProperty(value = "路由路径:可以为空,前段Vue通过路由匹配")
 	private String path;
 }

+ 1 - 0
component-entity/src/main/java/com/gihon/component/entity/rbac/GihonModule.java

@@ -14,6 +14,7 @@ import lombok.Setter;
 
 /**
  * 系统模块(RBAC)
+ * 不同的子系统模块
  * @author baihe
  *
  */

+ 39 - 26
component-entity/src/main/java/com/gihon/component/entity/rbac/GihonUser.java

@@ -1,5 +1,10 @@
 package com.gihon.component.entity.rbac;
 
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.Size;
+
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.gihon.component.entity.CompanyBaseEntity;
@@ -10,36 +15,44 @@ import lombok.Setter;
 
 /**
  * 系统账号
+ * 
  * @author baihe
  *
  */
 @Setter
 @Getter
 @TableName("gihon_user")
-public class GihonUser extends CompanyBaseEntity{
-
-	@ApiModelProperty(value = "名称")
-	private String nickName;
-	
-	@ApiModelProperty(value = "账号")
-	private String username;
-	
-	@ApiModelProperty(value = "电话")
-	private String telephone;
-	
-	@JsonIgnore
-	@ApiModelProperty(value = "密码")
-	private String password;
-	
-	/**
-	 * @see com.gihon.component.enums.Gender
-	 */
-	@ApiModelProperty(value = "性别1男2女")
-	private Integer gender;
-
-	/**
-	 * @see com.gihon.component.enums.Gender
-	 */
-	@ApiModelProperty(value = "是否是公司管理员")
-	private Boolean companyAdmin = false;
+public class GihonUser extends CompanyBaseEntity {
+
+    @NotBlank(message="昵称不能为空")
+    @Size(max = 16 ,message="昵称不超过16位")
+    @ApiModelProperty(value = "名称")
+    private String nickName;
+
+    @NotBlank(message="账号不能为空")
+    @Size(max = 16 ,message="账号不超过16位")
+    @ApiModelProperty(value = "账号")
+    private String username;
+
+    @Size(max = 16 ,message="电话不超过16位")
+    @ApiModelProperty(value = "电话")
+    private String telephone;
+
+    @JsonIgnore
+    @ApiModelProperty(value = "密码")
+    private String password;
+
+    /**
+     * @see com.gihon.component.enums.Gender
+     */
+    @Max(value = 2, message = "性别取值范围1-2")
+    @Min(value = 1, message = "性别取值范围1-2")
+    @ApiModelProperty(value = "性别1男2女")
+    private Integer gender;
+
+    /**
+     * @see com.gihon.component.enums.Gender
+     */
+    @ApiModelProperty(value = "是否是公司管理员")
+    private Boolean companyAdmin = false;
 }

+ 1 - 1
component-entity/src/main/java/com/gihon/component/response/ResponseStatus.java

@@ -12,7 +12,7 @@ public enum ResponseStatus {
 	TOKEN_EXPIRED(301, "Token已过期"), //
 	REFRESH_TOKEN_EXPIRED(301, "RereshToken已过期"), //
 	RESOURCE_ERROR(400, "资源错误"), // 资源不不存在
-	UNAUTHORIATION(401, "未登录未经授权"),
+	UNAUTHORIATION(401, "未登录"),
 	FORBIDDEN(403, "没有权限"),
 	SQL_ERROR(500, "SQL运行异常"), 
 	ERROR(500, "服务器错误");

+ 16 - 0
component-entity/src/main/java/com/gihon/component/response/SelectVal.java

@@ -0,0 +1,16 @@
+package com.gihon.component.response;
+
+import lombok.Builder;
+import lombok.Getter;
+import lombok.Setter;
+
+@Builder
+@Getter
+@Setter
+public class SelectVal {
+
+    private String value;//值
+    
+    private String label;//名称
+    
+}

+ 63 - 49
component-springboot/src/main/java/com/gihon/component/rbac/controller/CompanyController.java

@@ -1,6 +1,9 @@
 package com.gihon.component.rbac.controller;
 
+import java.util.List;
+
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -14,6 +17,7 @@ import com.gihon.component.exception.BusinessException;
 import com.gihon.component.response.PageBean;
 import com.gihon.component.response.Response;
 import com.gihon.component.response.ResponseStatus;
+import com.gihon.component.response.SelectVal;
 import com.gihon.component.service.GihonCompanyService;
 import com.gihon.component.vo.CompanyListReq;
 import com.gihon.component.web.auth.AuthUtils;
@@ -21,57 +25,67 @@ import com.gihon.component.web.auth.AuthUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 
-@Api(value ="公司模块" ,tags = "公司模块")
+@Api(value = "公司模块", tags = "公司模块")
 @RestController
 @RequestMapping("company")
 public class CompanyController {
 
-	@Autowired
-	private GihonCompanyService companyService;	
-	
-	@ApiOperation("COMPANY:列表")
-	@GetMapping("list")
-	public Response<PageBean<GihonCompany>> list(CompanyListReq  companyListReq) {
-		IPage<GihonCompany> list = companyService.getCompanylistPage(companyListReq);
-		return Response.okPage(list);
-	}
-	
-	@ApiOperation("COMPANY:启用")
-	@PostMapping("enable/{id}")
-	public Response<Void> enable(@PathVariable Long id) {
-		companyService.enableCompany(id, AuthUtils.getUserId(), true);
-		return Response.ok();
-	}
-	@ApiOperation("COMPANY:禁用")
-	@PostMapping("disable/{id}")
-	public Response<Void> disable(@PathVariable Long id) {
-		companyService.enableCompany(id, AuthUtils.getUserId(), false);
-		return Response.ok();
-	}
-	@ApiOperation("COMPANY:新增")
-	@PostMapping("")
-	public Response<Void> saveCompany(@RequestBody GihonCompany company) {
-		companyService.saveCompany(company);
-		return Response.ok();
-	}
-	@ApiOperation("COMPANY:编辑")
-	@PostMapping("/{id}")
-	public Response<Void> updateCompany(@RequestBody GihonCompany company,@PathVariable Long id) {
-		Long companyId = AuthUtils.getCompanyId();
-		if(companyId!=null&&!companyId.equals(id)) {
-			throw new BusinessException(ResponseStatus.FORBIDDEN);
-		}
-		company.setId(id);
-		companyService.updateCompany(company);
-		return Response.ok();
-	}
-	@ApiOperation("COMPANY:详情")
-	@GetMapping("/{id}")
-	public Response<GihonCompany> getCompany(@PathVariable Long id) {
-		Long companyId = AuthUtils.getCompanyId();
-		if(companyId!=null&&!companyId.equals(id)) {
-			throw new BusinessException(ResponseStatus.FORBIDDEN);
-		}
-		return Response.ok(companyService.getById(id));
-	}
+    @Autowired
+    private GihonCompanyService companyService;
+
+    @ApiOperation("COMPANY:列表")
+    @GetMapping("list")
+    public Response<PageBean<GihonCompany>> list(@Validated CompanyListReq companyListReq) {
+        IPage<GihonCompany> list = companyService.getCompanylistPage(companyListReq);
+        return Response.okPage(list);
+    }
+
+    @ApiOperation("COMPANY:启用")
+    @PostMapping("enable/{id}")
+    public Response<Void> enable(@PathVariable Long id) {
+        companyService.enableCompany(id, AuthUtils.getUserId(), true);
+        return Response.ok();
+    }
+
+    @ApiOperation("COMPANY:禁用")
+    @PostMapping("disable/{id}")
+    public Response<Void> disable(@PathVariable Long id) {
+        companyService.enableCompany(id, AuthUtils.getUserId(), false);
+        return Response.ok();
+    }
+
+    @ApiOperation("COMPANY:新增")
+    @PostMapping("")
+    public Response<Void> saveCompany(@Validated @RequestBody GihonCompany company) {
+        companyService.saveCompany(company);
+        return Response.ok();
+    }
+
+    @ApiOperation("COMPANY:编辑")
+    @PostMapping("/{id}")
+    public Response<Void> updateCompany(@Validated @RequestBody GihonCompany company, @PathVariable Long id) {
+        Long companyId = AuthUtils.getCompanyId();
+        if (companyId != null && !companyId.equals(id)) {
+            throw new BusinessException(ResponseStatus.FORBIDDEN);
+        }
+        company.setId(id);
+        companyService.updateCompany(company);
+        return Response.ok();
+    }
+
+    @ApiOperation("COMPANY:详情")
+    @GetMapping("/{id}")
+    public Response<GihonCompany> getCompany(@PathVariable Long id) {
+        Long companyId = AuthUtils.getCompanyId();
+        if (companyId != null && !companyId.equals(id)) {
+            throw new BusinessException(ResponseStatus.FORBIDDEN);
+        }
+        return Response.ok(companyService.getById(id));
+    }
+
+    @ApiOperation("COMPANY:列表")
+    @GetMapping("/labelAndValue")
+    public Response<List<SelectVal>> labelAndValue(String companyName) {
+        return Response.ok(companyService.labelAndValue(AuthUtils.getCompanyId(),companyName));
+    }
 }

+ 64 - 15
component-springboot/src/main/java/com/gihon/component/rbac/controller/UserController.java

@@ -1,36 +1,85 @@
 package com.gihon.component.rbac.controller;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.gihon.component.entity.rbac.GihonUser;
+import com.gihon.component.exception.BusinessException;
+import com.gihon.component.response.PageBean;
 import com.gihon.component.response.Response;
-import com.gihon.component.web.vo.LoginUser;
+import com.gihon.component.response.ResponseStatus;
+import com.gihon.component.service.GihonUserService;
+import com.gihon.component.vo.rabc.UserListReq;
+import com.gihon.component.web.auth.AuthUtils;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 
-@Api(value ="人员模块" ,tags = "人员模块")
+@Api(value = "人员模块", tags = "人员模块")
 @Slf4j
 @RestController
 @RequestMapping("user")
 public class UserController {
+    @Autowired
+    private GihonUserService gihonUserService;
+
+    @ApiOperation("USER:用户列表")
+    @GetMapping("list")
+    public Response<PageBean<GihonUser>> list(@Validated UserListReq search) {
+        IPage<GihonUser> list = gihonUserService.getUserlistPage(search);
+        return Response.okPage(list);
+    }
+
+    @ApiOperation("USER:启用管理员")
+    @PostMapping("enable/{id}")
+    public Response<Void> enable(@PathVariable Long id) {
+        gihonUserService.enableCompany(id, true);
+        return Response.ok();
+    }
+
+    @ApiOperation("USER:禁用管理员")
+    @PostMapping("disable/{id}")
+    public Response<Void> disable(@PathVariable Long id) {
+        gihonUserService.enableCompany(id, false);
+        return Response.ok();
+    }
+
+    @ApiOperation("USER:用户详情")
+    @GetMapping("{id}")
+    public Response<GihonUser> user(@Validated @PathVariable Long id) {
+        return Response.ok(gihonUserService.getById(id));
+    }
+    
+
+    @ApiOperation("USER:新增")
+    @PostMapping("")
+    public Response<Void> saveUser(@Validated @RequestBody GihonUser user) {
+        Long companyId = AuthUtils.getCompanyId();
+        if (companyId != null && !companyId.equals(user.getCompanyId())) {
+            throw new BusinessException(ResponseStatus.FORBIDDEN);
+        }
+        gihonUserService.saveUser(user);
+        return Response.ok();
+    }
+
+    @ApiOperation("USER:编辑")
+    @PostMapping("/{id}")
+    public Response<Void> updateUser(@Validated @RequestBody GihonUser user, @PathVariable Long id) {
+        Long companyId = AuthUtils.getCompanyId();
+        if (companyId != null && !companyId.equals(user.getCompanyId())) {
+            throw new BusinessException(ResponseStatus.FORBIDDEN);
+        }
+        user.setId(id);
+        gihonUserService.updateUser(user);
+        return Response.ok();
+    }
 
-	@ApiOperation("USER:用户列表")
-	@GetMapping("list")
-	public Response<Void> list(@RequestBody LoginUser loginUser) {
-		log.debug("用户列表:{}", loginUser.getUserAccount());
-		return Response.ok();
-	}
-	@ApiOperation("USER:用户详情")
-	@GetMapping("{id}")
-	public Response<Void> list(@Validated @PathVariable Long id) {
-		log.debug("用户列表:{}", id);
-		return Response.ok();
-	}
-	
 }

+ 27 - 28
component-springboot/src/main/java/com/gihon/component/rbac/service/impl/PermissionServiceImpl.java

@@ -28,30 +28,29 @@ public class PermissionServiceImpl implements PermissionService {
 
     @Autowired
     private GihonCommonProperties gihonCommonProperties;
-    
+
     @Override
     public List<MenuVO> getPermission() {
-        
-        String menuJson = (String) stringRedisTemplate.opsForHash().get(RedisConstants.MENU_TREE_REDIS,
-                gihonCommonProperties.getModuleCode() + RedisConstants.SEP + gihonCommonProperties.getModuleType());
-        TypeReference<List<MenuVO>> valueTypeRef = new TypeReference<List<MenuVO>>() {
-        };
+
+        String menuJson = (String)stringRedisTemplate.opsForHash().get(RedisConstants.MENU_TREE_REDIS,
+            gihonCommonProperties.getModuleCode() + RedisConstants.SEP + gihonCommonProperties.getModuleType());
+        TypeReference<List<MenuVO>> valueTypeRef = new TypeReference<List<MenuVO>>() {};
         List<MenuVO> root = JacksonJsonUtils.readObject(menuJson, valueTypeRef);
-        //原始
+        // 原始
         List<MenuVO> list = new ArrayList<>(root.size());
-        
+
         AuthUser user = AuthUtils.getUser();
-        if (AuthConstans.SUPER_ADMIN.equals(user.getUsername()) && gihonCommonProperties.getModuleType() == ModuleType.WEB.getCode()) {
-           
+        if (AuthConstans.SUPER_ADMIN.equals(user.getUsername())
+            && gihonCommonProperties.getModuleType() == ModuleType.WEB.getCode()) {
+
             return root;
         }
-        
+
         // 获取全部的角色
         List<String> role = user.getRoleList();
-        //返回有权限的终极菜单。其他不需要后台控制的菜单有前端自行展示
-        cloneCopyMenu(root,list,role);
-        
-        
+        // 返回有权限的终极菜单。其他不需要后台控制的菜单有前端自行展示
+        cloneCopyMenu(root, list, role);
+
         return list;
     }
 
@@ -62,8 +61,8 @@ public class PermissionServiceImpl implements PermissionService {
      * @param list
      */
     private void cloneCopyMenu(List<MenuVO> root, List<MenuVO> list, List<String> role) {
-        if(role==null ||role.isEmpty()) {
-            //无角色就无权限
+        if (role == null || role.isEmpty()) {
+            // 无角色就无权限
             return;
         }
         for (MenuVO voi : root) {
@@ -72,23 +71,23 @@ public class PermissionServiceImpl implements PermissionService {
                 continue;
             }
             List<PermissionVO> pt = permissions.stream().filter(poi -> {
-                if (poi.getRoleList() == null || poi.getRoleList().isEmpty()) {//未配置角色就是只有超级管理员有权限@See AuthServiceImpl#checkPermission
+                if (poi.getRoleList() == null || poi.getRoleList().isEmpty()) {
+                    // 未配置角色就是只有超级管理员有权限@See AuthServiceImpl#checkPermission
                     return false;
-                }else if(poi.getRoleList().stream().anyMatch(s->role.contains(s))) {//角色是任意一个即可
+                } else if (poi.getRoleList().stream().anyMatch(role::contains)) {// 角色是任意一个即可
                     return true;
                 }
                 return false;
             }).collect(Collectors.toList());
-            
-            if(pt.isEmpty()) {//菜单需要有任意一个操作权限
-                continue;
+
+            if (!pt.isEmpty()) {// 菜单需要有任意一个操作权限
+                MenuVO mv = new MenuVO();
+                mv.setMenuCode(voi.getMenuCode());
+                mv.setMenuId(voi.getMenuId());
+                mv.setPermissions(pt);
+                list.add(mv);
             }
-            MenuVO mv = new MenuVO();
-            mv.setMenuCode(voi.getMenuCode());
-            mv.setMenuId(voi.getMenuId());
-            mv.setPermissions(pt);
-            list.add(mv);
         }
     }
-    
+
 }

+ 5 - 5
component-springboot/src/main/resources/application.yml

@@ -1,7 +1,7 @@
 server:
   port: 10021
   servlet:
-    context-path: /rabc
+    context-path: /rbac
   tomcat: 
     uri-encoding: UTF-8
     basedir: /data/tmp
@@ -32,7 +32,7 @@ knife4j:
   setting: 
     swaggerModelName: '模型名称'
     enableFooter: false
-#  documents:
-#    - 
-#      group: SSO
-#      name: 登录验证模块
+  documents:
+    - 
+      group: RBAC
+      name: 系统管理模块

+ 5 - 1
component-websecurity/src/main/java/com/gihon/component/web/auth/impl/AuthServiceImpl.java

@@ -34,6 +34,7 @@ import com.gihon.component.web.service.TokenService;
 import com.gihon.component.web.vo.MenuVO;
 import com.gihon.component.web.vo.PermissionVO;
 import com.gihon.component.web.vo.TokenVal;
+import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
 
 import lombok.extern.slf4j.Slf4j;
 
@@ -99,7 +100,7 @@ public class AuthServiceImpl implements AuthService{
             return false;
         }
         // Empty是配置权限但是没有角色 只有管理员才行 @See PermissionServiceImpl#cloneCopyMenu
-        return needRole.stream().anyMatch(r -> role.contains(r));
+        return needRole.stream().anyMatch(role::contains);
     }
 
     /**
@@ -113,6 +114,9 @@ public class AuthServiceImpl implements AuthService{
         Comparator<String> c = antMatcher.getPatternComparator("/**");
 
         List<PermissionVO> list = getPermissionList();
+        if(CollectionUtils.isEmpty(list)) {
+            return null;
+        }
         // 排序
         HttpMethod m = HttpMethod.valueOf(uris[0]);
         list = list.stream().filter(p -> m.matches(p.getMethod())).sorted((p, p2) -> {

+ 1 - 1
component-websecurity/src/main/java/com/gihon/component/web/config/CommonWebConfig.java

@@ -110,7 +110,7 @@ public class CommonWebConfig implements WebMvcConfigurer {
         // 允许cookies跨域
         config.setAllowCredentials(true);
         // #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin
-        config.addAllowedOrigin("*");
+        config.addAllowedOriginPattern("*");
         // #允许访问的头信息,*表示全部
         config.addAllowedHeader("*");
         // 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了

+ 11 - 8
component-springboot/src/main/java/com/gihon/component/config/swagger/DemoKnife4jConfig.java → component-websecurity/src/main/java/com/gihon/component/web/config/DemoKnife4jConfig.java

@@ -1,4 +1,4 @@
-package com.gihon.component.config.swagger;
+package com.gihon.component.web.config;
 
 import java.net.Inet4Address;
 import java.net.InetAddress;
@@ -6,6 +6,7 @@ import java.util.List;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.web.context.WebServerInitializedEvent;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.annotation.Bean;
@@ -13,15 +14,14 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Import;
 
 import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
+import com.github.xiaoymin.knife4j.spring.configuration.Knife4jProperties;
 import com.google.common.collect.Lists;
 
 import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
 import springfox.documentation.builders.ApiInfoBuilder;
 import springfox.documentation.builders.PathSelectors;
 import springfox.documentation.builders.RequestHandlerSelectors;
-import springfox.documentation.builders.RequestParameterBuilder;
 import springfox.documentation.service.ApiInfo;
-import springfox.documentation.service.ParameterType;
 import springfox.documentation.service.RequestParameter;
 import springfox.documentation.spi.DocumentationType;
 import springfox.documentation.spring.web.plugins.Docket;
@@ -37,7 +37,10 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
 public class DemoKnife4jConfig implements ApplicationListener<WebServerInitializedEvent> {
 
     private static Logger logger = LoggerFactory.getLogger(DemoKnife4jConfig.class);
-
+    
+    @Autowired
+    private Knife4jProperties knife4jProperties;
+    
     @Bean(value = "web")
     public Docket createRestAdmin() {
         // 添加请求参数,我们这里把token作为请求头部参数传入后端(defaultValue还不能使用具体问题不祥)
@@ -47,8 +50,8 @@ public class DemoKnife4jConfig implements ApplicationListener<WebServerInitializ
         return new Docket(DocumentationType.SWAGGER_2)
         		.enable(true)
                 .useDefaultResponseMessages(false)
-                .groupName("RABC")
-                .apiInfo(apiInfo())
+                .groupName(knife4jProperties.getDocuments().get(0).getGroup())
+                .apiInfo(apiInfo(knife4jProperties.getDocuments().get(0).getName()))
                 .globalRequestParameters(parameters)
                 .select()
                 .apis(RequestHandlerSelectors.basePackage("com.gihon.component"))
@@ -57,9 +60,9 @@ public class DemoKnife4jConfig implements ApplicationListener<WebServerInitializ
 
     }
 
-    private ApiInfo apiInfo() {
+    private ApiInfo apiInfo(String title) {
         return new ApiInfoBuilder()
-                .title("SpringBootRbac")
+                .title(title)
                 .build();
     }
 

+ 1 - 1
component-websecurity/src/main/java/com/gihon/component/web/service/impl/TokenServiceImpl.java

@@ -92,7 +92,7 @@ public class TokenServiceImpl implements TokenService {
         SsoToken tokenEntity = new SsoToken();
         tokenEntity.setModuleType(moduleType);
         tokenEntity.setUserInfo(userInfo);
-        //TODO 修改JWT
+        //TODO 修改JWT
         tokenEntity.setToken(parseToken(userInfo.getUsername() + RedisConstants.SEP + UUIDGenerater.genUUID()));
         tokenEntity.setRefreshToken(parseToken(userInfo.getUsername() + RedisConstants.SEP + UUIDGenerater.genUUID()));