Search in sources :

Example 1 with SysTenant

use of org.jeecg.modules.system.entity.SysTenant in project jeecg-boot by jeecgboot.

the class SysTenantController method getCurrentUserTenant.

/**
 *  查询当前用户的所有有效租户 【当前用于vue3版本】
 * @return
 */
@RequestMapping(value = "/getCurrentUserTenant", method = RequestMethod.GET)
public Result<Map<String, Object>> getCurrentUserTenant() {
    Result<Map<String, Object>> result = new Result<Map<String, Object>>();
    try {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String tenantIds = sysUser.getRelTenantIds();
        Map<String, Object> map = new HashMap<String, Object>();
        if (oConvertUtils.isNotEmpty(tenantIds)) {
            List<Integer> tenantIdList = new ArrayList<>();
            for (String id : tenantIds.split(",")) {
                tenantIdList.add(Integer.valueOf(id));
            }
            // 该方法仅查询有效的租户,如果返回0个就说明所有的租户均无效。
            List<SysTenant> tenantList = sysTenantService.queryEffectiveTenant(tenantIdList);
            map.put("list", tenantList);
        }
        result.setSuccess(true);
        result.setResult(map);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        result.error500("查询失败!");
    }
    return result;
}
Also used : LoginUser(org.jeecg.common.system.vo.LoginUser) Result(org.jeecg.common.api.vo.Result) SysTenant(org.jeecg.modules.system.entity.SysTenant)

Example 2 with SysTenant

use of org.jeecg.modules.system.entity.SysTenant in project jeecg-boot by jeecgboot.

the class SysTenantController method queryById.

/**
 * 通过id查询
 * @param id
 * @return
 */
@RequestMapping(value = "/queryById", method = RequestMethod.GET)
public Result<SysTenant> queryById(@RequestParam(name = "id", required = true) String id) {
    Result<SysTenant> result = new Result<SysTenant>();
    SysTenant sysTenant = sysTenantService.getById(id);
    if (sysTenant == null) {
        result.error500("未找到对应实体");
    } else {
        result.setResult(sysTenant);
        result.setSuccess(true);
    }
    return result;
}
Also used : SysTenant(org.jeecg.modules.system.entity.SysTenant) Result(org.jeecg.common.api.vo.Result)

Example 3 with SysTenant

use of org.jeecg.modules.system.entity.SysTenant in project jeecg-boot by jeecgboot.

the class LoginController method userInfo.

/**
 * 用户信息
 *
 * @param sysUser
 * @param result
 * @return
 */
private Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {
    String syspassword = sysUser.getPassword();
    String username = sysUser.getUsername();
    // 获取用户部门信息
    JSONObject obj = new JSONObject();
    List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
    obj.put("departs", departs);
    if (departs == null || departs.size() == 0) {
        obj.put("multi_depart", 0);
    } else if (departs.size() == 1) {
        sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
        obj.put("multi_depart", 1);
    } else {
        // 查询当前是否有登录部门
        // update-begin--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
        SysUser sysUserById = sysUserService.getById(sysUser.getId());
        if (oConvertUtils.isEmpty(sysUserById.getOrgCode())) {
            sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
        }
        // update-end--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
        obj.put("multi_depart", 2);
    }
    // update-begin--Author:sunjianlei Date:20210802 for:获取用户租户信息
    String tenantIds = sysUser.getRelTenantIds();
    if (oConvertUtils.isNotEmpty(tenantIds)) {
        List<Integer> tenantIdList = new ArrayList<>();
        for (String id : tenantIds.split(",")) {
            tenantIdList.add(Integer.valueOf(id));
        }
        // 该方法仅查询有效的租户,如果返回0个就说明所有的租户均无效。
        List<SysTenant> tenantList = sysTenantService.queryEffectiveTenant(tenantIdList);
        if (tenantList.size() == 0) {
            result.error500("与该用户关联的租户均已被冻结,无法登录!");
            return result;
        } else {
            obj.put("tenantList", tenantList);
        }
    }
    // update-end--Author:sunjianlei Date:20210802 for:获取用户租户信息
    // 生成token
    String token = JwtUtil.sign(username, syspassword);
    // 设置token缓存有效时间
    redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
    redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
    obj.put("token", token);
    obj.put("userInfo", sysUser);
    obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
    result.setResult(obj);
    result.success("登录成功");
    return result;
}
Also used : SysTenant(org.jeecg.modules.system.entity.SysTenant) JSONObject(com.alibaba.fastjson.JSONObject) SysUser(org.jeecg.modules.system.entity.SysUser) SysDepart(org.jeecg.modules.system.entity.SysDepart) EncryptedString(org.jeecg.common.util.encryption.EncryptedString)

Example 4 with SysTenant

use of org.jeecg.modules.system.entity.SysTenant in project kms by mahonelau.

the class SysTenantController method queryById.

/**
 * 通过id查询
 * @param id
 * @return
 */
@RequestMapping(value = "/queryById", method = RequestMethod.GET)
public Result<SysTenant> queryById(@RequestParam(name = "id", required = true) String id) {
    Result<SysTenant> result = new Result<SysTenant>();
    SysTenant sysTenant = sysTenantService.getById(id);
    if (sysTenant == null) {
        result.error500("未找到对应实体");
    } else {
        result.setResult(sysTenant);
        result.setSuccess(true);
    }
    return result;
}
Also used : SysTenant(org.jeecg.modules.system.entity.SysTenant) Result(org.jeecg.common.api.vo.Result)

Example 5 with SysTenant

use of org.jeecg.modules.system.entity.SysTenant in project kykms by mahonelau.

the class SysTenantController method queryById.

/**
 * 通过id查询
 * @param id
 * @return
 */
@RequestMapping(value = "/queryById", method = RequestMethod.GET)
public Result<SysTenant> queryById(@RequestParam(name = "id", required = true) String id) {
    Result<SysTenant> result = new Result<SysTenant>();
    SysTenant sysTenant = sysTenantService.getById(id);
    if (sysTenant == null) {
        result.error500("未找到对应实体");
    } else {
        result.setResult(sysTenant);
        result.setSuccess(true);
    }
    return result;
}
Also used : SysTenant(org.jeecg.modules.system.entity.SysTenant) Result(org.jeecg.common.api.vo.Result)

Aggregations

SysTenant (org.jeecg.modules.system.entity.SysTenant)8 Result (org.jeecg.common.api.vo.Result)7 JSONObject (com.alibaba.fastjson.JSONObject)1 LoginUser (org.jeecg.common.system.vo.LoginUser)1 EncryptedString (org.jeecg.common.util.encryption.EncryptedString)1 SysDepart (org.jeecg.modules.system.entity.SysDepart)1 SysUser (org.jeecg.modules.system.entity.SysUser)1