微调
This commit is contained in:
@@ -74,4 +74,12 @@ public interface SystemValidMessage {
|
||||
String DATA_TYPE_NOT_BLANK = "数据模型不能为空,请检查dataType参数";
|
||||
|
||||
String CLASS_ID_NOT_BLANK = "数据表表名不能为空,请检查classId参数";
|
||||
|
||||
String AUTO_GENERATE_NOT_NULL = "是否自动生成不能为空,请检查autoGenerate参数";
|
||||
|
||||
String MAX_RECHECK_NOT_NULL = "最大复检次数不能为空,请检查maxRecheck参数";
|
||||
|
||||
String DATA_RULE_NOT_BLANK = "数据处理规则不能为空,请检查dataRule参数";
|
||||
|
||||
String DATA_RULE_FORMAT_ERROR = "数据处理规则格式错误,请检查dataRule参数";
|
||||
}
|
||||
|
||||
@@ -47,4 +47,6 @@ public interface UserValidMessage {
|
||||
String TYPE_NOT_BLANK = "类型不能为空,请检查type参数";
|
||||
|
||||
String PARAM_FORMAT_ERROR = "参数值非法";
|
||||
|
||||
String LOGIN_FAILED = "登录失败,用户名或密码错误";
|
||||
}
|
||||
|
||||
@@ -4,13 +4,16 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.constant.SecurityConstants;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.user.pojo.constant.UserValidMessage;
|
||||
import com.njcn.gather.user.user.pojo.param.SysUserParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysUser;
|
||||
import com.njcn.gather.user.user.service.ISysUserService;
|
||||
import com.njcn.gather.user.user.util.JwtUtil;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -19,9 +22,11 @@ import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -38,17 +43,31 @@ public class SysUserController extends BaseController {
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
// @PostMapping("/login")
|
||||
// @ApiOperation("登录")
|
||||
// public HttpResult<Object> login(@RequestBody SysUserParam.UserLoginParam loginParam) {}
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.AUTHENTICATE)
|
||||
@PostMapping("/login")
|
||||
@ApiOperation("登录")
|
||||
public HttpResult<Object> login(@RequestBody SysUserParam.LoginParam param) {
|
||||
String methodDescribe = getMethodDescribe("login");
|
||||
LogUtil.njcnDebug(log, "{},登录参数为:{}", methodDescribe, param);
|
||||
SysUser user = sysUserService.getUserByLoginNameAndPassword(param.getLoginName(), param.getPassword());
|
||||
if (user == null) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, UserValidMessage.LOGIN_FAILED, methodDescribe);
|
||||
} else {
|
||||
String token = JwtUtil.generateToken(user.getId());
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, token, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
// @OperateInfo(info = LogEnum.SYSTEM_SERIOUS, operateType = OperateType.LOGOUT)
|
||||
// @ApiOperation("注销登录")
|
||||
// @DeleteMapping("/logout")
|
||||
// public HttpResult<Object> logout() {
|
||||
//
|
||||
// }
|
||||
@OperateInfo(info = LogEnum.SYSTEM_SERIOUS, operateType = OperateType.LOGOUT)
|
||||
@ApiOperation("注销登录")
|
||||
@PostMapping("/logout")
|
||||
public HttpResult<Object> logout(HttpServletRequest request) {
|
||||
String methodDescribe = getMethodDescribe("logout");
|
||||
LogUtil.njcnDebug(log, "{},注销登录", methodDescribe);
|
||||
String token = request.getHeader("Authorization").replace(SecurityConstants.AUTHORIZATION_PREFIX, Strings.EMPTY);
|
||||
JwtUtil.invalidateToken(token);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/list")
|
||||
|
||||
@@ -102,4 +102,16 @@ public class SysUserParam {
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class LoginParam {
|
||||
@ApiModelProperty("登录名")
|
||||
@NotBlank(message = UserValidMessage.LOGIN_NAME_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.LOGIN_NAME_REGEX, message = UserValidMessage.LOGIN_NAME_FORMAT_ERROR)
|
||||
private String loginName;
|
||||
|
||||
@ApiModelProperty("密码")
|
||||
@NotBlank(message = UserValidMessage.PASSWORD_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.PASSWORD_REGEX, message = UserValidMessage.PASSWORD_FORMAT_ERROR)
|
||||
private String password;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,5 +107,13 @@ public interface ISysUserService extends IService<SysUser> {
|
||||
*/
|
||||
boolean deleteUser(List<String> ids);
|
||||
|
||||
/**
|
||||
* 根据登录名和密码查询用户
|
||||
*
|
||||
* @param loginName 登录名
|
||||
* @param password 密码
|
||||
* @return 用户对象,如果没有查询到则返回null
|
||||
*/
|
||||
SysUser getUserByLoginNameAndPassword(String loginName, String password);
|
||||
|
||||
}
|
||||
|
||||
@@ -173,6 +173,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser getUserByLoginNameAndPassword(String loginName, String password) {
|
||||
return this.lambdaQuery().ne(SysUser::getState, UserState.DELETE)
|
||||
.eq(SysUser::getLoginName, loginName)
|
||||
.eq(SysUser::getPassword, password).one();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验重复
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user