Browse Source

权限修改

pra 3 years ago
parent
commit
4a2156986b

+ 2 - 0
tofly-auth/src/main/java/com/tofly/auth/config/AuthorizationServerConfiguration.java

@@ -107,6 +107,8 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu
             additionalInfo.put(SecurityConstants.DETAILS_DEPT_NAME,user.getDepartemntName());
             additionalInfo.put(SecurityConstants.DETAILS_DEPT_NAME,user.getDepartemntName());
             additionalInfo.put(SecurityConstants.DETAILS_REAL_NAME,user.getRealName());
             additionalInfo.put(SecurityConstants.DETAILS_REAL_NAME,user.getRealName());
             additionalInfo.put(SecurityConstants.DETAILS_USER_AVATAR,user.getAvatar());
             additionalInfo.put(SecurityConstants.DETAILS_USER_AVATAR,user.getAvatar());
+            additionalInfo.put(SecurityConstants.DETAILS_COMPANY_NAME,user.getCompanyName());
+            additionalInfo.put(SecurityConstants.DETAILS_COMPANY_ID,user.getCompanyId());
             ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
             ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
             return accessToken;
             return accessToken;
         };
         };

+ 1 - 1
tofly-auth/src/main/resources/bootstrap.yml

@@ -8,7 +8,7 @@ eureka:
     prefer-ip-address: true
     prefer-ip-address: true
   client:
   client:
     service-url:
     service-url:
-      defaultZone: http://36.134.195.46:${EUREKAPORT:9999}/eureka/
+      defaultZone: http://tofly-eureka:${EUREKAPORT:9999}/eureka/
 spring:
 spring:
   application:
   application:
     name: tofly-auth
     name: tofly-auth

+ 5 - 0
tofly-base/base-api/src/main/java/com/tofly/base/api/entity/SysUser.java

@@ -3,6 +3,7 @@ package com.tofly.base.api.entity;
 import com.baomidou.mybatisplus.annotation.*;
 import com.baomidou.mybatisplus.annotation.*;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.Data;
 import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.format.annotation.DateTimeFormat;
 
 
@@ -103,4 +104,8 @@ public class SysUser implements Serializable {
     private Date loginTime;
     private Date loginTime;
 
 
     private String realName;
     private String realName;
+
+    private Long companyId;
+    @TableField(exist=false)
+    private String companyName;
 }
 }

+ 1 - 0
tofly-base/base-service/src/main/java/com/tofly/base/controller/CodeController.java

@@ -18,6 +18,7 @@ import com.tofly.common.log.annotation.ToFlyAppLog;
 import com.tofly.common.oauth.feign.FlowableAddUserGroupEvent;
 import com.tofly.common.oauth.feign.FlowableAddUserGroupEvent;
 import com.tofly.common.oauth.feign.FlowableDeleteGroupEvent;
 import com.tofly.common.oauth.feign.FlowableDeleteGroupEvent;
 import com.tofly.common.oauth.feign.FlowableUpdateGroupEvent;
 import com.tofly.common.oauth.feign.FlowableUpdateGroupEvent;
+import com.tofly.common.oauth.util.SecurityUtils;
 import io.swagger.annotations.*;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;

+ 6 - 2
tofly-base/base-service/src/main/java/com/tofly/base/controller/ProjectinfoController.java

@@ -17,6 +17,7 @@ import com.tofly.common.oauth.util.SecurityUtils;
 import com.tofly.common.service.CommonOauthService;
 import com.tofly.common.service.CommonOauthService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
@@ -33,6 +34,7 @@ import java.util.List;
 @RestController
 @RestController
 @RequestMapping("/projectinfo")
 @RequestMapping("/projectinfo")
 @Api(tags="项目基本信息表接口")
 @Api(tags="项目基本信息表接口")
+@Slf4j
 public class ProjectinfoController {
 public class ProjectinfoController {
 
 
     @Value("${user.logo}")
     @Value("${user.logo}")
@@ -79,6 +81,7 @@ public class ProjectinfoController {
     @GetMapping("/get" )
     @GetMapping("/get" )
     @ApiOperation(value = "查询基本信息")
     @ApiOperation(value = "查询基本信息")
     public ResultRespone get(@ModelAttribute Projectinfo projectinfo) {
     public ResultRespone get(@ModelAttribute Projectinfo projectinfo) {
+        log.info("----------"+SecurityUtils.getCompanyId()+"2222"+SecurityUtils.compareCompany(projectinfo.getCompanyId()));
         Long companyId = commonOauthService.compareCompany(projectinfo.getCompanyId());
         Long companyId = commonOauthService.compareCompany(projectinfo.getCompanyId());
         projectinfo.setCompanyId(companyId);
         projectinfo.setCompanyId(companyId);
         return ResultRespone.success(projectinfoService.getOne(Wrappers.query(projectinfo),false));
         return ResultRespone.success(projectinfoService.getOne(Wrappers.query(projectinfo),false));
@@ -126,13 +129,14 @@ public class ProjectinfoController {
 //        if(checkAuth()){
 //        if(checkAuth()){
 //            return ResultRespone.failed("必须是超级管理员才能操作");
 //            return ResultRespone.failed("必须是超级管理员才能操作");
 //        }
 //        }
-
+        Long companyId = commonOauthService.compareCompany(projectinfo.getCompanyId());
+        projectinfo.setCompanyId(companyId);
         if(file!=null){
         if(file!=null){
             String filename = logoPath+ IdWorker.getIdStr()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
             String filename = logoPath+ IdWorker.getIdStr()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
             boolean b= FtpUtil.uploadFile2Ftp(file,filename);
             boolean b= FtpUtil.uploadFile2Ftp(file,filename);
             if(b){
             if(b){
                 //查找以前的FTP并删除
                 //查找以前的FTP并删除
-                Projectinfo oldprojectinfo=projectinfoService.getOne(Wrappers.query());
+                Projectinfo oldprojectinfo=projectinfoService.getById(projectinfo);
                 //如果logo不为空,需要清空以前的logo
                 //如果logo不为空,需要清空以前的logo
                 if(!StringUtil.isEmpty(oldprojectinfo.getProjectLogo())){
                 if(!StringUtil.isEmpty(oldprojectinfo.getProjectLogo())){
                     FtpUtil.deleteFile(oldprojectinfo.getProjectLogo());
                     FtpUtil.deleteFile(oldprojectinfo.getProjectLogo());

+ 12 - 4
tofly-base/base-service/src/main/java/com/tofly/base/service/impl/SysUserServiceImpl.java

@@ -6,12 +6,10 @@ import com.tofly.base.api.dto.UserInfo;
 import com.tofly.base.api.entity.SysMenu;
 import com.tofly.base.api.entity.SysMenu;
 import com.tofly.base.api.entity.SysRole;
 import com.tofly.base.api.entity.SysRole;
 import com.tofly.base.api.entity.SysUser;
 import com.tofly.base.api.entity.SysUser;
+import com.tofly.base.entity.Company;
 import com.tofly.base.entity.Department;
 import com.tofly.base.entity.Department;
 import com.tofly.base.mapper.SysUserMapper;
 import com.tofly.base.mapper.SysUserMapper;
-import com.tofly.base.service.DepartmentService;
+import com.tofly.base.service.*;
-import com.tofly.base.service.SysMenuService;
-import com.tofly.base.service.SysRoleService;
-import com.tofly.base.service.SysUserService;
 import com.tofly.common.core.util.StringUtil;
 import com.tofly.common.core.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -37,6 +35,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
     @Autowired
     @Autowired
     private DepartmentService departmentService;
     private DepartmentService departmentService;
 
 
+    @Autowired
+    private CompanyService companyService;
+
     @Autowired
     @Autowired
     private SysUserMapper sysUserMapper;
     private SysUserMapper sysUserMapper;
 
 
@@ -50,6 +51,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
             sysUser.setDepartemntName(department.getName());
             sysUser.setDepartemntName(department.getName());
         }
         }
 
 
+        //加入公司名称
+        if(sysUser.getCompanyId()!=null){
+            Company company=companyService.getOne(Wrappers.<Company>lambdaQuery().
+                    eq(Company::getId,sysUser.getCompanyId()));
+            sysUser.setCompanyName(company.getName());
+        }
+
         userInfo.setSysUser(sysUser);//用户信息
         userInfo.setSysUser(sysUser);//用户信息
 
 
         //设置角色
         //设置角色

+ 1 - 0
tofly-base/base-service/src/main/resources/mapper/SysUserMapper.xml

@@ -25,6 +25,7 @@
 		<result property="lastIp" column="LAST_IP"/>
 		<result property="lastIp" column="LAST_IP"/>
 		<result property="pwderrtimes" column="PWDERRTIMES"/>
 		<result property="pwderrtimes" column="PWDERRTIMES"/>
 		<result property="loginTime" column="LOGIN_TIME"/>
 		<result property="loginTime" column="LOGIN_TIME"/>
+		<result property="companyId" column="COMPANY_ID"/>
 	</resultMap>
 	</resultMap>
 
 
 	<update id="updateUserInfo"  >
 	<update id="updateUserInfo"  >

+ 2 - 0
tofly-base/base-service/src/main/resources/mapper/UserMapper.xml

@@ -31,6 +31,8 @@
         <result column="USER_LEVEL" property="userLevel"/>
         <result column="USER_LEVEL" property="userLevel"/>
         <result property="companyId" column="COMPANY_ID"/>
         <result property="companyId" column="COMPANY_ID"/>
         <association property="departmentName" column="DEPARTMENT_ID" select="getDName"></association>
         <association property="departmentName" column="DEPARTMENT_ID" select="getDName"></association>
+        <association property="companyName" column="COMPANY_ID"
+                     select="com.tofly.common.mapper.ToflyCodeCommonMapper.getCompanyName"></association>
 
 
     </resultMap>
     </resultMap>
 
 

+ 10 - 0
tofly-common/common-core/src/main/java/com/tofly/common/core/constant/SecurityConstants.java

@@ -88,6 +88,16 @@ public interface SecurityConstants {
      */
      */
     String DETAILS_DEPT_ID = "departmentId";
     String DETAILS_DEPT_ID = "departmentId";
 
 
+    /**
+     * 用户公司段
+     */
+    String DETAILS_COMPANY_NAME = "companyName";
+
+    /**
+     * 用户公司字段
+     */
+    String DETAILS_COMPANY_ID = "companyId";
+
 
 
     /**
     /**
      * 用户级别字段
      * 用户级别字段

+ 1 - 1
tofly-common/common-oauth/src/main/java/com/tofly/common/oauth/auth/ToFlyUserDetailsService.java

@@ -92,7 +92,7 @@ public class ToFlyUserDetailsService implements UserDetailsService {
         Collection<? extends GrantedAuthority> authorities
         Collection<? extends GrantedAuthority> authorities
                 = AuthorityUtils.createAuthorityList(dbauthSet.toArray(new String[0]));
                 = AuthorityUtils.createAuthorityList(dbauthSet.toArray(new String[0]));
 
 
-        return new ToflyUser(user.getPwderrtimes(),user.getId(),user.getDepartmentId(),user.getUserLevel(),
+        return new ToflyUser(user.getCompanyId(),user.getCompanyName(),user.getPwderrtimes(),user.getId(),user.getDepartmentId(),user.getUserLevel(),
                 user.getRealName(),user.getDepartemntName(),user.getAvatar(),
                 user.getRealName(),user.getDepartemntName(),user.getAvatar(),
                 user.getUsername(),/*SecurityConstants.BCRYPT+*/user.getPassword(),
                 user.getUsername(),/*SecurityConstants.BCRYPT+*/user.getPassword(),
                 CommonConstants.STATUS_NORMAL.equals(user.getLockFlag()),true,
                 CommonConstants.STATUS_NORMAL.equals(user.getLockFlag()),true,

+ 24 - 1
tofly-common/common-oauth/src/main/java/com/tofly/common/oauth/auth/ToflyUser.java

@@ -33,6 +33,12 @@ public class ToflyUser extends User{
     @Getter
     @Getter
     private Short pwderrtimes;
     private Short pwderrtimes;
 
 
+    @Getter
+    private Long companyId;
+
+    @Getter
+    private String companyName;
+
 
 
 
 
 
 
@@ -48,7 +54,7 @@ public class ToflyUser extends User{
         this.avatar=avatar;
         this.avatar=avatar;
     }
     }
 
 
-    public ToflyUser(Short pwderrtimes,Long useid,Long departmentId,String userLevel,String realName, String departemntName,String avatar,
+    public ToflyUser(Long companyId,String companyName,Short pwderrtimes,Long useid,Long departmentId,String userLevel,String realName, String departemntName,String avatar,
                      String username, String password, boolean enabled, boolean accountNonExpired,
                      String username, String password, boolean enabled, boolean accountNonExpired,
                      boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
                      boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
         super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
         super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
@@ -59,5 +65,22 @@ public class ToflyUser extends User{
         this.departemntName=departemntName;
         this.departemntName=departemntName;
         this.avatar=avatar;
         this.avatar=avatar;
         this.pwderrtimes=pwderrtimes;
         this.pwderrtimes=pwderrtimes;
+        this.companyId=companyId;
+        this.companyName=companyName;
+    }
+
+    public ToflyUser(Long companyId,String companyName,Long useid,Long departmentId,String userLevel,String realName, String departemntName,String avatar,
+                     String username, String password, boolean enabled, boolean accountNonExpired,
+                     boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
+        super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
+        this.userid=useid;
+        this.departmentId=departmentId;
+        this.userLevel=userLevel;
+        this.realName=realName;
+        this.departemntName=departemntName;
+        this.avatar=avatar;
+        this.companyId=companyId;
+        this.companyName=companyName;
     }
     }
+
 }
 }

+ 8 - 1
tofly-common/common-oauth/src/main/java/com/tofly/common/oauth/compent/ToFlyUserAuthenticationConverter.java

@@ -52,7 +52,14 @@ public class ToFlyUserAuthenticationConverter implements UserAuthenticationConve
 
 
             String avatar = (String)map.get(SecurityConstants.DETAILS_USER_AVATAR);
             String avatar = (String)map.get(SecurityConstants.DETAILS_USER_AVATAR);
 
 
-            ToflyUser user = new ToflyUser(id, deptId, userLevel,realName,deptName,avatar,username, N_A, true
+            Long companyId=null;
+            if(map.get(SecurityConstants.DETAILS_COMPANY_ID)!=null){
+                companyId = ((Integer) map.get(SecurityConstants.DETAILS_COMPANY_ID)).longValue();
+            }
+
+            String companyName = (String)map.get(SecurityConstants.DETAILS_COMPANY_NAME);
+
+            ToflyUser user = new ToflyUser(companyId,companyName,id, deptId, userLevel,realName,deptName,avatar,username, N_A, true
                     , true, true, true, authorities);
                     , true, true, true, authorities);
             return new UsernamePasswordAuthenticationToken(user, N_A, authorities);
             return new UsernamePasswordAuthenticationToken(user, N_A, authorities);
         }
         }

+ 2 - 2
tofly-common/common-oauth/src/main/java/com/tofly/common/oauth/config/ToflyAuthenticationProvider.java

@@ -125,7 +125,7 @@ public class ToflyAuthenticationProvider implements AuthenticationProvider {
             ResultRespone resultRespone=authTokenService.removeTokenByUser(params,SecurityConstants.FROM_IN);
             ResultRespone resultRespone=authTokenService.removeTokenByUser(params,SecurityConstants.FROM_IN);
             //如果密码错误次数不为0,则将缓存中的次数修改为0
             //如果密码错误次数不为0,则将缓存中的次数修改为0
             if(pwdt!=0){
             if(pwdt!=0){
-                ToflyUser toflyUser1=new ToflyUser(Short.valueOf("0"),toflyUser.getUserid(),toflyUser.getDepartmentId(),toflyUser.getUserLevel(),
+                ToflyUser toflyUser1=new ToflyUser(toflyUser.getCompanyId(),toflyUser.getCompanyName(),Short.valueOf("0"),toflyUser.getUserid(),toflyUser.getDepartmentId(),toflyUser.getUserLevel(),
                         toflyUser.getRealName(),toflyUser.getDepartemntName(),toflyUser.getAvatar(),
                         toflyUser.getRealName(),toflyUser.getDepartemntName(),toflyUser.getAvatar(),
                         toflyUser.getUsername(),/*SecurityConstants.BCRYPT+*/toflyUser.getPassword(),
                         toflyUser.getUsername(),/*SecurityConstants.BCRYPT+*/toflyUser.getPassword(),
                         true,true,
                         true,true,
@@ -134,7 +134,7 @@ public class ToflyAuthenticationProvider implements AuthenticationProvider {
             }
             }
 
 
             if (username1.contains("_ms")) {
             if (username1.contains("_ms")) {
-                ToflyUser toflyUser2 = new ToflyUser(Short.valueOf("0"), toflyUser.getUserid(), toflyUser.getDepartmentId(), toflyUser.getUserLevel(),
+                ToflyUser toflyUser2 = new ToflyUser(toflyUser.getCompanyId(),toflyUser.getCompanyName(),Short.valueOf("0"), toflyUser.getUserid(), toflyUser.getDepartmentId(), toflyUser.getUserLevel(),
                         toflyUser.getRealName(), toflyUser.getDepartemntName(), toflyUser.getAvatar(),
                         toflyUser.getRealName(), toflyUser.getDepartemntName(), toflyUser.getAvatar(),
                         username1,/*SecurityConstants.BCRYPT+*/toflyUser.getPassword(),
                         username1,/*SecurityConstants.BCRYPT+*/toflyUser.getPassword(),
                         true, true,
                         true, true,

+ 19 - 0
tofly-common/common-oauth/src/main/java/com/tofly/common/oauth/util/SecurityUtils.java

@@ -67,6 +67,25 @@ public class SecurityUtils {
        return toflyUser.getUserid();
        return toflyUser.getUserid();
     }
     }
 
 
+    /**
+     * 获取用户公司ID
+     */
+    public Long getCompanyId() {
+        ToflyUser toflyUser=getUser();
+        return toflyUser.getCompanyId();
+    }
+
+    /**
+     * 获取用户公司ID
+     */
+    public Long compareCompany(Long companyId) {
+        if (companyId != null){
+            return  companyId;
+        }
+        ToflyUser toflyUser=getUser();
+        return toflyUser.getCompanyId();
+    }
+
     /**
     /**
      * 获取用户部门ID
      * 获取用户部门ID
      */
      */