jiangping
2023-09-14 352d337c355f60909d9dd24bd613c12ea92f8015
组织bug
已修改5个文件
175 ■■■■■ 文件已修改
h5_standard/src/views/tabPage/my.vue 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/src/main/java/doumeemes/config/shiro/ShiroCredentialsMatcher.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/src/main/java/doumeemes/config/shiro/ShiroRealm.java 138 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/src/main/java/doumeemes/config/shiro/ShiroToken.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/src/main/java/doumeemes/service/ext/impl/DepartmentExtServiceImpl.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
h5_standard/src/views/tabPage/my.vue
@@ -79,6 +79,7 @@
            if (res.code === 200) {
                // window.parent.postMessage('阿康', '*')
                // let href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6ea339a336f26380&redirect_url=https://www.mes.red/h5/redirect.html&response_type=code&scope=snsapi_base&state=#wechat_redirect'
               //  let href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6ea339a336f26380&redirect_url=https://www.mes.red/lingyangh5/redirect.html&response_type=code&scope=snsapi_base&state=#wechat_redirect'
                // let href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6ea339a336f26380&redirect_url=https://dmtest.ahapp.net/doumeeplant_h5/redirect.html&response_type=code&scope=snsapi_base&state=#wechat_redirect'
                let href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6ea339a336f26380&redirect_url=https://lingyang.mes.show:1801/h5/redirect.html&response_type=code&scope=snsapi_base&state=#wechat_redirect'
                window.open(href)
server/src/main/java/doumeemes/config/shiro/ShiroCredentialsMatcher.java
@@ -25,6 +25,9 @@
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        ShiroToken usernamePasswordToken = (ShiroToken) token;
        if(((ShiroToken) token).getUpdateFlag() ==1){
            return Boolean.TRUE;
        }
        SystemUser queryUserDto = new SystemUser();
        queryUserDto.setUsername(usernamePasswordToken.getUsername());
        queryUserDto.setDeleted(Boolean.FALSE);
server/src/main/java/doumeemes/config/shiro/ShiroRealm.java
@@ -90,76 +90,82 @@
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        // 获取用户名
        ShiroToken authenticationToken =(ShiroToken) token;
        String username = authenticationToken.getPrincipal().toString();
        boolean isDdLogin = authenticationToken.getDdLogin();
        // 根据用户名查询用户对象
        SystemUser queryDto = new SystemUser();
        queryDto.setUsername(username);
        queryDto.setDeleted(Boolean.FALSE);
        SystemUser user = systemUserService.findOne(queryDto);
        if (user == null) {
            return null;
        }
        SystemRole role = new SystemRole();
        SystemPermission per = new SystemPermission();
        DepartmentExtListVO rootDepart = null,comDepart=null, depart = null;
        List<Integer> dpList = null;
        CompanyExtListVO com = null;
        CompanyUserExtListVO cu =null;
        if(Constants.equalsInteger(user.getType(),Constants.PlatType.admin)){
            //如果是平台用户
            role.setType(Constants.ROLETYPE.plat);
            per.setType(Constants.PlatType.admin);
        if(authenticationToken .getUpdateFlag() == 1){
            //如果是更新session
            return new SimpleAuthenticationInfo(authenticationToken.getUpdateUser(), authenticationToken.getPassword(), this.getName());
        }else{
            if(authenticationToken.getCompanyId() == null){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该账户删除!");
            String username = authenticationToken.getPrincipal().toString();
            boolean isDdLogin = authenticationToken.getDdLogin();
            // 根据用户名查询用户对象
            SystemUser queryDto = new SystemUser();
            queryDto.setUsername(username);
            queryDto.setDeleted(Boolean.FALSE);
            SystemUser user = systemUserService.findOne(queryDto);
            if (user == null) {
                return null;
            }
            com = companyExtService.getModelById(authenticationToken.getCompanyId());
            if(com == null || Constants.equalsInteger( com.getDeleted(),Constants.ONE)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该账户删除!请联系管理员");
            }
            if(Constants.equalsInteger( com.getStatus(),Constants.ZERO) ){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业已禁用!");
            }
            if(com.getOepnValidDate() != null && com.getOepnValidDate().before(new Date())){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业已过使用有效期!");
            }
            //如果是企业用户
            QueryCompanyUserExtDTO c =new QueryCompanyUserExtDTO();
            c.setUserId(user.getId());
            c.setDeleted(Constants.ZERO);
            c.setCompanyId(authenticationToken.getCompanyId());
            cu = companyUserExtService.selectOne(c);
            if(cu == null){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业用户不存在!");
            }
            if(Constants.equalsInteger(cu.getStatus(),Constants.ONE)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业用户已禁用!");
            }
            rootDepart = departmentExtService.getModelById(c.getCompanyId(),cu.getRootDepartId());
            comDepart = departmentExtService.getModelById(c.getCompanyId(),cu.getComDepartId());
            depart = departmentExtService.getModelById(c.getCompanyId(),cu.getDepartmentId());
            if(rootDepart == null || comDepart == null || depart==null){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业用户账户异常!");
            }
            role.setCompanyId(authenticationToken.getCompanyId());
            role.setType(Constants.ROLETYPE.com);
            per.setType(Constants.PlatType.company);
            per.setRoleType(Constants.ROLETYPE.com);
            per.setCompanyId(authenticationToken.getCompanyId());
            SystemRole rt = new SystemRole();
            rt.setType(Constants.ROLETYPE.com);
            rt.setCompanyId(c.getCompanyId());
            //数据部门权限集合
            dpList =systemDataPermissionService.selectHighRole(new SystemDataPermission(),rt,user,depart);
            SystemRole role = new SystemRole();
            SystemPermission per = new SystemPermission();
            DepartmentExtListVO rootDepart = null,comDepart=null, depart = null;
            List<Integer> dpList = null;
            CompanyExtListVO com = null;
            CompanyUserExtListVO cu =null;
            if(Constants.equalsInteger(user.getType(),Constants.PlatType.admin)){
                //如果是平台用户
                role.setType(Constants.ROLETYPE.plat);
                per.setType(Constants.PlatType.admin);
            }else{
                if(authenticationToken.getCompanyId() == null){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该账户删除!");
                }
                com = companyExtService.getModelById(authenticationToken.getCompanyId());
                if(com == null || Constants.equalsInteger( com.getDeleted(),Constants.ONE)){
                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该账户删除!请联系管理员");
                }
                if(Constants.equalsInteger( com.getStatus(),Constants.ZERO) ){
                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业已禁用!");
                }
                if(com.getOepnValidDate() != null && com.getOepnValidDate().before(new Date())){
                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业已过使用有效期!");
                }
                //如果是企业用户
                QueryCompanyUserExtDTO c =new QueryCompanyUserExtDTO();
                c.setUserId(user.getId());
                c.setDeleted(Constants.ZERO);
                c.setCompanyId(authenticationToken.getCompanyId());
                cu = companyUserExtService.selectOne(c);
                if(cu == null){
                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业用户不存在!");
                }
                if(Constants.equalsInteger(cu.getStatus(),Constants.ONE)){
                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业用户已禁用!");
                }
                rootDepart = departmentExtService.getModelById(c.getCompanyId(),cu.getRootDepartId());
                comDepart = departmentExtService.getModelById(c.getCompanyId(),cu.getComDepartId());
                depart = departmentExtService.getModelById(c.getCompanyId(),cu.getDepartmentId());
                if(rootDepart == null || comDepart == null || depart==null){
                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业用户账户异常!");
                }
                role.setCompanyId(authenticationToken.getCompanyId());
                role.setType(Constants.ROLETYPE.com);
                per.setType(Constants.PlatType.company);
                per.setRoleType(Constants.ROLETYPE.com);
                per.setCompanyId(authenticationToken.getCompanyId());
                SystemRole rt = new SystemRole();
                rt.setType(Constants.ROLETYPE.com);
                rt.setCompanyId(c.getCompanyId());
                //数据部门权限集合
                dpList =systemDataPermissionService.selectHighRole(new SystemDataPermission(),rt,user,depart);
            }
            // 获取登录用户信息
            List<SystemRole> roles = systemRoleService.findByUserModel(user.getId(),role);
            List<SystemPermission> permissions = systemPermissionService.findByUserModel(user.getId(),per);
            LoginUserInfo userInfo = LoginUserInfo.from(user, roles, permissions,com,rootDepart,comDepart,depart,dpList,cu);
            // 验证用户
            return new SimpleAuthenticationInfo(userInfo, user.getPassword(), this.getName());
        }
        // 获取登录用户信息
        List<SystemRole> roles = systemRoleService.findByUserModel(user.getId(),role);
        List<SystemPermission> permissions = systemPermissionService.findByUserModel(user.getId(),per);
        LoginUserInfo userInfo = LoginUserInfo.from(user, roles, permissions,com,rootDepart,comDepart,depart,dpList,cu);
        // 验证用户
        return new SimpleAuthenticationInfo(userInfo, user.getPassword(), this.getName());
    }
}
server/src/main/java/doumeemes/config/shiro/ShiroToken.java
@@ -1,5 +1,6 @@
package doumeemes.config.shiro;
import doumeemes.core.model.LoginUserInfo;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.springframework.stereotype.Component;
@@ -17,6 +18,9 @@
    Integer companyId;
    Boolean isDdLogin;
    Boolean isWxLogin;
    LoginUserInfo updateUser;
    int updateFlag;
    public ShiroToken() {
    }
@@ -25,6 +29,12 @@
        this.companyId = companyId;
        this.isDdLogin = isDdLogin;
        this.isWxLogin = isWxLogin;
    }
    public ShiroToken(LoginUserInfo user,int updateFlag) {
        super(user.getUsername(), "", false, (String)null);
        this.updateUser = user;
        this.updateFlag = updateFlag;
        this.isDdLogin = true;
    }
    public Boolean getDdLogin() {
@@ -51,4 +61,20 @@
    public void setCompanyId(Integer companyId) {
        this.companyId = companyId;
    }
    public LoginUserInfo getUpdateUser() {
        return updateUser;
    }
    public void setUpdateUser(LoginUserInfo updateUser) {
        this.updateUser = updateUser;
    }
    public int getUpdateFlag() {
        return updateFlag;
    }
    public void setUpdateFlag(int updateFlag) {
        this.updateFlag = updateFlag;
    }
}
server/src/main/java/doumeemes/service/ext/impl/DepartmentExtServiceImpl.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import doumeemes.config.shiro.ShiroToken;
import doumeemes.core.constants.ResponseStatus;
import doumeemes.core.exception.BusinessException;
import doumeemes.core.model.LoginUserInfo;
@@ -30,6 +31,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
@@ -294,6 +296,11 @@
              throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起!只能切换到公司级部门!");
          }
          user.setCurComDepartment(d);
            // 校验用户名和密码
            Subject subject = SecurityUtils.getSubject();
            // 钉钉登录
            ShiroToken token = new ShiroToken(user.getId(),user.getUsername(), null,true,false);
            subject.login(token);
        }
    }