소스 검색

单点登录

LLL 4 달 전
부모
커밋
f0df0d2acb

+ 5 - 1
jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -77,6 +77,10 @@ public class ShiroConfig {
         }
         // 配置不会被拦截的链接 顺序判断
         filterChainDefinitionMap.put("/sys/cas/client/validateLogin", "anon"); //cas验证登录
+
+        filterChainDefinitionMap.put("/sso/dy/**", "anon"); //SSO单点登录
+
+
         filterChainDefinitionMap.put("/sys/randomImage/**", "anon"); //登录验证码接口排除
         filterChainDefinitionMap.put("/sys/checkCaptcha", "anon"); //登录验证码接口排除
         filterChainDefinitionMap.put("/sys/login", "anon"); //登录接口排除
@@ -130,7 +134,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/jmreport/**", "anon");
         filterChainDefinitionMap.put("/**/*.js.map", "anon");
         filterChainDefinitionMap.put("/**/*.css.map", "anon");
-        
+
         //大屏模板例子
         filterChainDefinitionMap.put("/test/bigScreen/**", "anon");
         filterChainDefinitionMap.put("/bigscreen/template1/**", "anon");

+ 13 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/iotedgeConfig/util/ConfigInfo.java

@@ -29,4 +29,17 @@ public class ConfigInfo {
 
     /** 邮件定义的群组 */
     public static String GETGROUPINFO = "IoTEdge.Notification.GetGroupInfo";
+
+
+
+    /** SSO登录 */
+    public static String SSO_LOGIN_URL = "SSO_LOGIN_URL";
+    /** SSO登出 */
+    public static String SSO_LOGOUT_URL = "SSO_LOGOUT_URL";
+    /** SSO校验token */
+    public static String SSO_TOKENVALIDATION = "SSO_TOKENVALIDATION";
+
+    public static String CS = "CS";
+
+
 }

+ 29 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/ssoClient/constants/SSOConstants.java

@@ -0,0 +1,29 @@
+package org.jeecg.modules.ssoClient.constants;
+
+/**
+ * 功能描述
+ *
+ * @author: nn
+ * @date: 2024年07月11日 16:29
+ */
+public class SSOConstants {
+
+    // 登出状态
+    public static final String LOGOUT_SUCCESS = "SUCCESS"; //登出返回状态-成功
+    // 校验用户是否有效结果
+    public static final String BCZ = "该用户不存在,请注册"; // 不存在
+    public static final String YZX = "该用户已注销"; // 已注销
+    public static final String YDj = "该用户已冻结"; // 已冻结
+
+    // 用户状态(1-正常,2-冻结)
+    public static final Integer STATUS_ZC = 1; // 正常
+    // 用户删除状态(0-正常,1-已删除)
+    public static final Integer DEL_FLAG_ZC = 0; // 正常
+
+    // 管理员角色id
+    public static final String ADMIN_ROLE_ID = "1801434362368741377";
+
+
+
+
+}

+ 465 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/ssoClient/controller/SSOLoginLogoutController.java

@@ -0,0 +1,465 @@
+package org.jeecg.modules.ssoClient.controller;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.constant.CacheConstant;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.constant.SymbolConstant;
+import org.jeecg.common.system.util.JwtUtil;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.PasswordUtil;
+import org.jeecg.common.util.RedisUtil;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.base.service.BaseCommonService;
+import org.jeecg.modules.iotedgeConfig.service.IIotedgeConfigService;
+import org.jeecg.modules.iotedgeConfig.util.ConfigInfo;
+import org.jeecg.modules.ssoClient.constants.SSOConstants;
+import org.jeecg.modules.system.entity.SysDepart;
+import org.jeecg.modules.system.entity.SysTenant;
+import org.jeecg.modules.system.entity.SysUser;
+import org.jeecg.modules.system.model.SysLoginModel;
+import org.jeecg.modules.system.service.ISysDepartService;
+import org.jeecg.modules.system.service.ISysDictService;
+import org.jeecg.modules.system.service.ISysTenantService;
+import org.jeecg.modules.system.service.ISysUserService;
+import org.jeecg.modules.system.service.impl.SysBaseApiImpl;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.*;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
+
+import javax.annotation.Resource;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+/**
+ * 调用SSO接口登录登出
+ *
+ * @author: nn
+ * @date: 2024年07月11日 14:33
+ */
+@RestController
+@RequestMapping("/sso/dy")
+@Api(tags=".....................调用SSO接口登录登出")
+@Slf4j
+public class SSOLoginLogoutController {
+    @Autowired
+    private ISysUserService sysUserService;
+    @Autowired
+    private RedisUtil redisUtil;
+    @Autowired
+    private ISysDepartService sysDepartService;
+    @Autowired
+    private ISysTenantService sysTenantService;
+    @Autowired
+    private ISysDictService sysDictService;
+    @Resource
+    private BaseCommonService baseCommonService;
+    @Autowired
+    @SuppressWarnings("all")
+    private IIotedgeConfigService configService;
+    @Autowired
+    private SysBaseApiImpl sysBaseApi;
+
+
+
+    /**
+     * sso校验token
+     * */
+    @GetMapping("/tokenvalidation")
+    @ApiOperation("sso校验token")
+    public Boolean ssoJYToken(String token){
+        Result<JSONObject> result = ssoTokenValidation(token);
+        if(result.isSuccess()){
+            return true;
+        }
+        else return false;
+    }
+
+    public Result<JSONObject> ssoTokenValidation(String token) {
+        //        String url = "http://192.168.2.248:8188/v4.0/tokenvalidation;
+        String url = configService.getConfigValue(ConfigInfo.SSO_TOKENVALIDATION);
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("token",token);
+
+        // 设置请求头部
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+
+        // 创建RestTemplate实例
+        RestTemplate restTemplate = new RestTemplate();
+
+        // 创建HttpEntity封装请求体和头部信息
+        HttpEntity<String> entity = new HttpEntity<>(jsonObject.toString(), headers);
+
+        try {
+            // 发送POST请求并获取响应
+            ResponseEntity<String> response = restTemplate.exchange(
+                    url,
+                    HttpMethod.POST,
+                    entity,
+                    String.class);
+
+            // 处理响应
+            if (response.getStatusCode() == HttpStatus.OK) {
+//                return Result.ok();
+                String responseBody = response.getBody();
+                if (responseBody != null && !responseBody.equals("")) {
+                    // 假设body中包含了token信息,可以在这里进行处理
+                    if (responseBody.contains("Token") || responseBody.contains("Token")) {
+                        String accessToken = extractAccessTokenFromResponseBody(responseBody,"accessToken");
+                        String refreshToken = extractAccessTokenFromResponseBody(responseBody,"refreshToken");
+                        System.out.println("成功获取到token:" + token);
+                        return Result.ok(accessToken);
+                    }
+                } else {
+                    System.out.println("未找到body信息");
+                    return Result.ok("未找到body信息");
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return Result.error("校验失败");
+    }
+
+
+
+    @ApiOperation("登录接口")
+    @RequestMapping(value = "/login", method = RequestMethod.POST)
+    public Result<JSONObject> login(HttpServletRequest request, HttpServletResponse response, @RequestBody SysLoginModel sysLoginModel){
+
+        Result<JSONObject> result = new Result<JSONObject>();
+        String username = sysLoginModel.getUsername();
+        String password = sysLoginModel.getPassword();
+
+        String eiToken = ssodlcs(username, password);
+        if(eiToken==null || "".equals(eiToken)){
+            result.error("登录请求失败");
+            return result;
+        }
+
+        //1. 校验用户是否有效
+        SysUser sysUser = sysUserService.getUserAll(username);
+        result = sysUserService.checkUserIsEffective(sysUser);
+        if(!result.isSuccess()) {
+            // TODO 已经单点登录成功了的用户如果在本系统不存在,新增用户?
+            if(result.getMessage().equals(SSOConstants.BCZ) ){
+                log.info("用户在本系统不存在,新增该用户");
+                JSONObject addJSONObject = toAddJSONObject(username,  password);
+                addUser(addJSONObject);
+            }else if(result.getMessage().equals(SSOConstants.YZX) || result.getMessage().equals(SSOConstants.YDj)){
+                // TODO 已注销或冻结的用户怎么处理?——首先不应该允许在本系统注销或者冻结用户?——如果真的有恢复正常状态?
+                editUserStatusOrDel(username);
+            }
+        }
+
+        //用户登录信息 TODO-token
+        userInfo1(sysUser, result, eiToken);
+        LoginUser loginUser = new LoginUser();
+        BeanUtils.copyProperties(sysUser, loginUser);
+        baseCommonService.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null,loginUser);
+        //update-end--Author:wangshuai  Date:20200714  for:登录日志没有记录人员
+        return result;
+    }
+
+    private JSONObject toAddJSONObject(String username, String password){
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("workNo", "");
+        jsonObject.put("password", password);
+        jsonObject.put("confirmpassword", password);
+        jsonObject.put("phone", "18888888888");
+        jsonObject.put("selecteddeparts", "");
+        jsonObject.put("selectedroles", SSOConstants.ADMIN_ROLE_ID);
+        jsonObject.put("activitiSync", "1");
+        jsonObject.put("departIds", "");
+        jsonObject.put("userIdentity", "1");
+        jsonObject.put("username", username);
+        jsonObject.put("realname", username);
+        return jsonObject;
+    }
+
+    private  void  addUser(JSONObject jsonObject){
+        String selectedRoles = jsonObject.getString("selectedroles");
+        String selectedDeparts = jsonObject.getString("selecteddeparts");
+        try {
+            SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
+            user.setCreateTime(new Date());//设置创建时间
+            String salt = oConvertUtils.randomGen(8);
+            user.setSalt(salt);
+            String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
+            user.setPassword(passwordEncode);
+            user.setStatus(1);
+            user.setDelFlag(CommonConstant.DEL_FLAG_0);
+            //用户表字段org_code不能在这里设置他的值
+            user.setOrgCode(null);
+            // 保存用户走一个service 保证事务
+            sysUserService.saveUser(user, selectedRoles, selectedDeparts);
+            baseCommonService.addLog("添加用户,username: " +user.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+    }
+
+    public void editUserStatusOrDel(String username){
+        try {
+            baseCommonService.addLog("还原被逻辑删除、被冻结的用户,username: " +username ,CommonConstant.LOG_TYPE_2, 2);
+            sysUserService.editUserStatusOrDel(username);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+    }
+
+    /**
+     *  sso登录,获取token
+     */
+    public  String ssodlcs(String username, String password){
+        // String url = "http://192.168.2.248:8188/v4.0/auth/native";
+        String url = configService.getConfigValue(ConfigInfo.SSO_LOGIN_URL);
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("username",username);
+        jsonObject.put("password",password);
+
+        // 设置请求头部
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+
+        // 创建RestTemplate实例
+        RestTemplate restTemplate = new RestTemplate();
+
+        // 创建HttpEntity封装请求体和头部信息
+        HttpEntity<String> entity = new HttpEntity<>(jsonObject.toString(), headers);
+
+        try {
+            // 发送POST请求并获取响应
+            ResponseEntity<String> response = restTemplate.exchange(
+                    url,
+                    HttpMethod.POST,
+                    entity,
+                    String.class);
+
+            // 处理响应
+            if (response.getStatusCode() == HttpStatus.OK) {
+                String responseBody = response.getBody();
+                if (responseBody != null && !responseBody.equals("")) {
+                    // 假设body中包含了token信息,可以在这里进行处理
+                    if (responseBody.contains("Token") || responseBody.contains("Token")) {
+                        String token = extractTokenFromResponseBody(responseBody);
+                        System.out.println("成功获取到token:" + token);
+                        // 可以将token保存到本地或者设置到后续请求的Header中
+                        return token;
+                    }
+                } else {
+                    System.out.println("未找到body信息");
+                }
+            } else {
+                System.out.println("登录失败,HTTP状态码:" + response.getStatusCode());
+            }
+        } catch (Exception e) {
+            System.err.println("登录请求失败:" + e.getMessage());
+            e.printStackTrace();
+        }
+        return "";
+    }
+
+    private static String extractTokenFromResponseBody(String responseBody) {
+        // 假设body格式为 {"accessToken":"token","expiresIn":1720663523,"refreshToken":"a6ab6460-3f21-11ef-beaa-e454e833f52c","tokenType":"Bearer"}
+        try {
+            // 使用ObjectMapper解析JSON
+            ObjectMapper mapper = new ObjectMapper();
+            JsonNode jsonNode = mapper.readTree(responseBody);
+
+            String accessToken = jsonNode.get("accessToken").asText();
+            System.out.println("Access Token: " + accessToken);
+
+            return accessToken;
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private static String extractAccessTokenFromResponseBody(String responseBody, String tokenType) {
+        // 假设body格式为 {"accessToken":"token","expiresIn":1720663523,"refreshToken":"a6ab6460-3f21-11ef-beaa-e454e833f52c","tokenType":"Bearer"}
+        try {
+            // 使用ObjectMapper解析JSON
+            ObjectMapper mapper = new ObjectMapper();
+            JsonNode jsonNode = mapper.readTree(responseBody);
+
+            String token = jsonNode.get(tokenType).asText();
+            System.out.println(tokenType+ ": " + token);
+
+            return token;
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+    /**
+     * 用户信息
+     *
+     * @param sysUser
+     * @param result
+     * @return
+     */
+    private Result<JSONObject> userInfo1(SysUser sysUser, Result<JSONObject> result, String eiToken) {
+        String username = sysUser.getUsername();
+        String syspassword = sysUser.getPassword();
+        // 获取用户部门信息
+        JSONObject obj = new JSONObject(new LinkedHashMap<>());
+
+        // 生成token TODO 用本系统生成的token还是sso的token
+//        String token = JwtUtil.sign(username, syspassword);
+        String token =eiToken;
+        // 设置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);
+
+        // 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(SymbolConstant.COMMA)){
+                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:获取用户租户信息
+
+        obj.put("userInfo", sysUser);
+
+        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);
+        }
+        obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
+        result.setResult(obj);
+        result.success("登录成功");
+        return result;
+    }
+
+
+    /**
+     * 退出登录
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/logout")
+    public Result<Object> logout(HttpServletRequest request, HttpServletResponse response) {
+        log.info("开始退出登录----------------------------------");
+
+        //SSO登出
+        String msg = IoTedgessolgout(response);
+        if(!SSOConstants.LOGOUT_SUCCESS.equals(msg)) return Result.error(msg);
+
+        // 创建一个同名的 Cookie 对象
+        Cookie cookie = new Cookie("EIToken", "");
+        // 设置 Cookie 的路径和最大生存时间(单位:秒)
+        cookie.setPath("/"); // 设置路径为根路径,确保能在整个应用中删除该 Cookie
+        cookie.setMaxAge(0); // 将 Cookie 的最大生存时间设置为 0,使其立即过期
+        // 将 Cookie 添加到 HttpServletResponse 中
+        response.addCookie(cookie);
+
+        //用户退出逻辑
+        String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
+        if(oConvertUtils.isEmpty(token)) {
+            return Result.error("退出登录失败!");
+        }
+        String username = JwtUtil.getUsername(token);
+        LoginUser sysUser = sysBaseApi.getUserByName(username);
+        if(sysUser!=null) {
+            //update-begin--Author:wangshuai  Date:20200714  for:登出日志没有记录人员
+            baseCommonService.addLog("用户名: "+sysUser.getRealname()+",退出成功!", CommonConstant.LOG_TYPE_1, null,sysUser);
+            //update-end--Author:wangshuai  Date:20200714  for:登出日志没有记录人员
+            log.info(" 用户名:  "+sysUser.getRealname()+",退出成功! ");
+            //清空用户登录Token缓存
+            redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token);
+            //清空用户登录Shiro权限缓存
+            redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId());
+            //清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username>
+            redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername()));
+            //调用shiro的logout
+            SecurityUtils.getSubject().logout();
+            return Result.ok("退出登录成功!");
+        }else {
+            return Result.error("Token无效!");
+        }
+    }
+
+    /**IoTedge sso登出*/
+    public String IoTedgessolgout(HttpServletResponse response1){
+        //String url = "http://192.168.2.248:8082/v1/sso/auth";
+        String url = configService.getConfigValue(ConfigInfo.SSO_LOGOUT_URL);
+
+        // 设置请求头部
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+
+        // 创建RestTemplate实例
+        RestTemplate restTemplate = new RestTemplate();
+
+        // 创建HttpEntity封装请求体和头部信息
+        HttpEntity<String> entity = new HttpEntity<>(headers);
+
+        try {
+            // 发送POST请求并获取响应
+            ResponseEntity<String> response = restTemplate.exchange(
+                    url,
+                    HttpMethod.DELETE,
+                    entity,
+                    String.class);
+
+            // 处理响应
+            if (response.getStatusCode() == HttpStatus.NO_CONTENT) {
+                return SSOConstants.LOGOUT_SUCCESS;
+            }
+        } catch (Exception e) {
+            System.err.println("登出请求失败:" + e.getMessage());
+            e.printStackTrace();
+        }
+        return "";
+    }
+
+}

+ 16 - 5
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/mapper/SysUserMapper.java

@@ -21,6 +21,17 @@ import java.util.List;
  * @since 2018-12-20
  */
 public interface SysUserMapper extends BaseMapper<SysUser> {
+
+	/**
+	 * 还原被逻辑删除、被冻结的用户
+	 */
+	public void editUserStatusOrDel(@Param("username") String username);
+
+	/**
+	 * 根据用户名查询——不管是否被删
+	 */
+	public SysUser getUserAll(@Param("username") String username);
+
 	/**
 	  * 通过用户账号查询用户信息
 	 * @param username
@@ -61,22 +72,22 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
 	 * @return
 	 */
 	IPage<SysUser> getUserByRoleId(Page page, @Param("roleId") String roleId, @Param("username") String username);
-	
+
 	/**
 	 * 根据用户名设置部门ID
 	 * @param username
 	 * @param orgCode
 	 */
 	void updateUserDepart(@Param("username") String username,@Param("orgCode") String orgCode);
-	
+
 	/**
 	 * 根据手机号查询用户信息
 	 * @param phone
 	 * @return
 	 */
 	public SysUser getUserByPhone(@Param("phone") String phone);
-	
-	
+
+
 	/**
 	 * 根据邮箱查询用户信息
 	 * @param email
@@ -149,7 +160,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
      */
     @Deprecated
     int updateNullByEmptyString(@Param("fieldName") String fieldName);
-    
+
 	/**
 	 *  根据部门Ids,查询部门下用户信息
 	 * @param departIds

+ 19 - 3
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/mapper/xml/SysUserMapper.xml

@@ -2,6 +2,22 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.modules.system.mapper.SysUserMapper">
 
+	<!-- 还原被逻辑删除、被冻结的用户 -->
+	<update id="editUserStatusOrDel">
+		UPDATE
+		sys_user
+		SET
+		del_flag = 0,
+		status = 1
+		WHERE
+		username = #{username}
+	</update>
+
+	<!-- 根据用户名查询——不管是否被删 -->
+	<select id="getUserAll" resultType="org.jeecg.modules.system.entity.SysUser">
+		select * from  sys_user  where username = #{username}
+	</select>
+
 	<!-- 根据用户名查询 -->
 	<select id="getUserByName" resultType="org.jeecg.modules.system.entity.SysUser">
 		select * from  sys_user  where username = #{username} and del_flag = 0
@@ -45,7 +61,7 @@
 			and username = #{username}
 		</if>
 	</select>
-	
+
 	<!--  修改用户部门code -->
 	<update id="updateUserDepart">
 		UPDATE sys_user SET org_code = #{orgCode} where username = #{username}
@@ -55,7 +71,7 @@
 	<select id="getUserByPhone"  resultType="org.jeecg.modules.system.entity.SysUser">
 		select * from  sys_user  where phone = #{phone} and del_flag = 0
 	</select>
-	
+
 	<!-- 根据邮箱查询用户信息 -->
 	<select id="getUserByEmail" resultType="org.jeecg.modules.system.entity.SysUser">
 	select * from  sys_user  where email = #{email} and del_flag = 0
@@ -182,4 +198,4 @@
 			and username != #{username}
 		</if>
 	</select>
-</mapper>
+</mapper>

+ 18 - 7
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysUserService.java

@@ -28,6 +28,17 @@ import java.util.Set;
  */
 public interface ISysUserService extends IService<SysUser> {
 
+
+	/**
+	 * 还原被逻辑删除、被冻结的用户
+	 */
+	void editUserStatusOrDel(String username);
+
+	/**
+	 * 根据用户名查询——不管是否被删除
+	 */
+	public SysUser getUserAll( String username);
+
 	/**
 	 * 重置密码
 	 *
@@ -67,15 +78,15 @@ public interface ISysUserService extends IService<SysUser> {
      * @return SysUser
      */
 	public SysUser getUserByName(String username);
-	
+
 	/**
 	 * 添加用户和用户角色关系
 	 * @param user
 	 * @param roles
 	 */
 	public void addUserWithRole(SysUser user,String roles);
-	
-	
+
+
 	/**
 	 * 修改用户和用户角色关系
 	 * @param user
@@ -98,7 +109,7 @@ public interface ISysUserService extends IService<SysUser> {
 	 * @return
 	 */
 	public SysRoleIndex getDynamicIndexByUserRole(String username,String version);
-	
+
 	/**
 	  * 查询用户信息包括 部门信息
 	 * @param username
@@ -178,14 +189,14 @@ public interface ISysUserService extends IService<SysUser> {
 	 * @return 权限集合
 	 */
 	Set<String> getUserPermissionsSet(String username);
-	
+
 	/**
 	 * 根据用户名设置部门ID
 	 * @param username
 	 * @param orgCode
 	 */
 	void updateUserDepart(String username,String orgCode);
-	
+
 	/**
 	 * 根据手机号获取用户名和密码
      * @param phone 手机号
@@ -215,7 +226,7 @@ public interface ISysUserService extends IService<SysUser> {
 	 * @param departs
 	 */
 	void editUserWithDepart(SysUser user, String departs);
-	
+
 	/**
 	   * 校验用户是否有效
 	 * @param sysUser

+ 21 - 6
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java

@@ -44,7 +44,7 @@ import java.util.stream.Collectors;
 @Service
 @Slf4j
 public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
-	
+
 	@Autowired
 	private SysUserMapper userMapper;
 	@Autowired
@@ -72,6 +72,21 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 	@Autowired
 	SysRoleIndexMapper sysRoleIndexMapper;
 
+
+	/**
+	 * 还原被逻辑删除、被冻结的用户
+	 */
+	public void editUserStatusOrDel(String username){
+		userMapper.editUserStatusOrDel(username);
+	}
+
+	/**
+	 * 根据用户名查询——不管是否被删
+	 */
+	public SysUser getUserAll( String username){
+		return userMapper.getUserAll(username);
+	}
+
     @Override
     @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
     public Result<?> resetPassword(String username, String oldpassword, String newpassword, String confirmpassword) {
@@ -125,8 +140,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 	public SysUser getUserByName(String username) {
 		return userMapper.getUserByName(username);
 	}
-	
-	
+
+
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void addUserWithRole(SysUser user, String roles) {
@@ -187,7 +202,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 				roleIndex = list.get(0);
 			}
 		}
-		
+
 		//如果componentUrl为空,则返回空
 		if(oConvertUtils.isEmpty(roleIndex.getComponent())){
 			return null;
@@ -253,7 +268,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 			info.setSysUserName(sysUser.getRealname());
 			info.setSysOrgCode(sysUser.getOrgCode());
 		}
-		
+
 		//多部门支持in查询
 		List<SysDepart> list = sysDepartMapper.queryUserDeparts(sysUser.getId());
 		List<String> sysMultiOrgCode = new ArrayList<String>();
@@ -269,7 +284,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 			}
 		}
 		info.setSysMultiOrgCode(sysMultiOrgCode);
-		
+
 		return info;
 	}