Commit e4d09c3d by ypenglv

冲突解决

2 parents fa32d93b 1c3ef6d9
......@@ -2,9 +2,11 @@ package org.nafmii.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nafmii.dto.user.LoginDto;
import org.nafmii.dto.user.RegisterDto;
import org.nafmii.response.ApiResponse;
import org.nafmii.service.UserService;
import org.nafmii.vo.AppUser;
import org.nafmii.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -40,5 +42,13 @@ public class UserController {
return register;
}
@ApiOperation( value = "app用户登陆接口(密码加验证码)",notes = "app用户登陆接口(密码加验证码)")
@PostMapping("/login")
@ResponseBody
public ApiResponse<UserVO> login (@RequestBody LoginDto loginDto){
ApiResponse<UserVO> login = userService.userLogin(loginDto);
return login;
}
}
package org.nafmii.dto.user;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/4/26 16:41
* @ClassName:
* @version:
* @remark:
*/
@Data
@ApiModel("app用户登陆参数对象")
public class LoginDto {
@NotNull(message = "手机号或登录账号不能为空")
@ApiModelProperty("手机号/登录账号")
private String phone;
@NotNull(message = "注册密码不能为空")
@ApiModelProperty("登陆密码")
private String loginPwd;
@NotNull(message = "验证码不能为空")
@ApiModelProperty("验证码")
private String code;
@NotNull(message = "登陆方式不能为空")
@ApiModelProperty("登陆方式0密码1验证码")
private String type;
}
......@@ -7,7 +7,6 @@ import java.util.Date;
public class AppUser implements Serializable {
private Long id;
@ApiModelProperty(value = "昵称")
private String userName;
......
......@@ -25,6 +25,9 @@ public enum UserEnum {
*/
ENABLE("0","有效用户"),
NOTENABLE("1","无效用户"),
LOGINPHONE("1","验证码"),
LOGINPWD("0","密码"),
;
UserEnum(String code, String name){
......
......@@ -2,8 +2,10 @@ package org.nafmii.mapper.user;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.nafmii.dto.user.LoginDto;
import org.nafmii.entity.user.AppUser;
import org.nafmii.entity.user.AppUserExample;
import org.nafmii.vo.UserVO;
import java.util.List;
@Mapper
......@@ -20,6 +22,10 @@ public interface AppUserMapper {
List<AppUser> selectByExample(AppUserExample example);
List<UserVO> selectByPassword(LoginDto loginDto);
List<UserVO> selectByPhone(@Param("phone") String phone);
AppUser selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") AppUser record, @Param("example") AppUserExample example);
......
package org.nafmii.service;
import org.nafmii.dto.user.LoginDto;
import org.nafmii.dto.user.RegisterDto;
import org.nafmii.response.ApiResponse;
import org.nafmii.vo.UserVO;
......@@ -17,4 +18,6 @@ public interface UserService {
ApiResponse<UserVO> login();
//app注册接口
ApiResponse register(RegisterDto registerDto);
//用户登陆接口
ApiResponse<UserVO> userLogin(LoginDto loginDto);
}
......@@ -3,8 +3,10 @@ package org.nafmii.service.impl;
import lombok.extern.slf4j.Slf4j;
import org.nafmii.dto.user.LoginDto;
import org.nafmii.dto.user.RegisterDto;
import org.nafmii.entity.user.AppUser;
import org.nafmii.entity.user.AppUserExample;
import org.nafmii.enums.UserEnum;
import org.nafmii.exception.BusinessException;
import org.nafmii.mapper.user.AppUserMapper;
......@@ -46,7 +48,7 @@ public class UserServiceImpl implements UserService {
ApiResponse result = new ApiResponse();
//假设验证数据通过
UserVO userVO = new UserVO();
userVO.setPassword("zzz");
userVO.setLoginPwd("zzz");
userVO.setUserName("zzz");
List<UserAndRoleVo> roleList =new ArrayList<>();
UserAndRoleVo roleVo = new UserAndRoleVo();
......@@ -55,7 +57,7 @@ public class UserServiceImpl implements UserService {
roleList.add(roleVo);
roleTwoVo.setRole("b");
roleList.add(roleTwoVo);
userVO.setAuthorities(roleList);
// userVO.setAuthorities(roleList);
StringBuilder sbf = new StringBuilder();
for (UserAndRoleVo role:roleList
) {
......@@ -65,7 +67,7 @@ public class UserServiceImpl implements UserService {
String sRole = sbf.toString();
String substring = sRole.substring(0, sRole.lastIndexOf(","));
String token = JwtUtils.createToken(userVO.getUserName(),substring);
userVO.setToken(token);
// userVO.setToken(token);
result.setData(userVO);
return result;
}
......@@ -92,7 +94,7 @@ public class UserServiceImpl implements UserService {
appUser.setLoginPwd(registerDto.getLoginPwd());
appUser.setCreateTime(new Date());
appUser.setUpdateTime(new Date());
log.info("用户注册实体==============>"+appUser);
log.info("用户注册参数==============>"+registerDto);
//将验证码放入到缓存当中(过期时间60s)test
// GuavaUtil.putTrackGuava(registerDto.getPhone(),registerDto.getCode());
//重缓存中获取(通过手机号获取)
......@@ -111,4 +113,39 @@ public class UserServiceImpl implements UserService {
}
return new ApiResponse();
}
/**
* 用户登陆接口
* @param loginDto
* @return
*/
@Override
public ApiResponse<UserVO> userLogin(LoginDto loginDto) {
List<UserVO> userVo = new ArrayList<>();
//首先判断登陆方式
if (loginDto.getType().equals("0")){
//密码登陆
userVo = appUserMapper.selectByPassword(loginDto);
if (userVo.isEmpty()){
throw new BusinessException("请先注册");
}
}else{
//验证码登陆
String code = (String) GuavaUtil.getTrackGuava(loginDto.getPhone());
log.info("冲缓存中获取的验证码===============》{}",code);
if (null == code){
throw new BusinessException("验证码已过期");
}
if (!code.equals(loginDto.getCode())){
throw new BusinessException("验证码错误请重新输入");
}
userVo = appUserMapper.selectByPhone(loginDto.getPhone());
if (userVo.isEmpty()){
throw new BusinessException("请先注册");
}
}
ApiResponse apiResponse =new ApiResponse();
apiResponse.setData(userVo);
return apiResponse;
}
}
package org.nafmii.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
......@@ -13,10 +16,53 @@ import java.util.List;
* @remark:
*/
@Data
@ApiModel("用户返回报文")
public class UserVO {
private Long id;
@ApiModelProperty(value = "昵称")
private String userName;
private String password;
private String token;
private List<UserAndRoleVo> authorities;//角色集合
@ApiModelProperty(value = "登录密码")
private String loginPwd;
@ApiModelProperty(value = "中文姓名")
private String realName;
@ApiModelProperty(value = "手机号/登录账号")
private String phone;
@ApiModelProperty(value = "出生日期")
private String birthday;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "头像图片地址")
private String headPicture;
@ApiModelProperty(value = "国籍")
private String nationality;
@ApiModelProperty(value = "单位全称")
private String unitName;
@ApiModelProperty(value = "微信OPENT_ID")
private String openId;
@ApiModelProperty(value = "是否开启指纹登录 0 未开启 1 已开启")
private String figerprintFalg;
@ApiModelProperty(value = "是否开启人脸识别登录 0 未开启 1 已开启")
private String faceidFalg;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "更新时间")
private Date updateTime;
@ApiModelProperty(value = "是否有效标识 0 有效用户 1无效用户")
private String isEnable;
}
......@@ -81,6 +81,27 @@
ID, USER_NAME, LOGIN_PWD, REAL_NAME, PHONE, BIRTHDAY, EMAIL, HEAD_PICTURE, NATIONALITY,
UNIT_NAME, OPEN_ID, FIGERPRINT_FALG, FACEID_FALG, CREATE_TIME, UPDATE_TIME, IS_ENABLE
</sql>
<select id="selectByPassword" parameterType="org.nafmii.dto.user.LoginDto" resultType="org.nafmii.vo.UserVO">
select ID as id,
USER_NAME as userName, LOGIN_PWD as loginPwd, REAL_NAME as realName, PHONE as phone, BIRTHDAY as birthday, EMAIL as email, HEAD_PICTURE as headPicture, NATIONALITY as nationality,
UNIT_NAME as unitName, OPEN_ID as openId, FIGERPRINT_FALG as figerprintFalg, FACEID_FALG as faceidFalg, CREATE_TIME as createTime, UPDATE_TIME as updateTime, IS_ENABLE as isEnable
from APP_USER where IS_ENABLE = 0
<if test="phone !=null">
and PHONE !=#{phone}
</if>
<if test="loginPwd !=null">
and LOGIN_PWD !=#{loginPwd}
</if>
</select>
<select id="selectByPhone" parameterType="map" resultType="org.nafmii.vo.UserVO">
select ID as id,
USER_NAME as userName, LOGIN_PWD as loginPwd, REAL_NAME as realName, PHONE as phone, BIRTHDAY as birthday, EMAIL as email, HEAD_PICTURE as headPicture, NATIONALITY as nationality,
UNIT_NAME as unitName, OPEN_ID as openId, FIGERPRINT_FALG as figerprintFalg, FACEID_FALG as faceidFalg, CREATE_TIME as createTime, UPDATE_TIME as updateTime, IS_ENABLE as isEnable
from APP_USER where IS_ENABLE = 0
<if test="phone !=null">
and PHONE !=#{phone}
</if>
</select>
<select id="selectByExample" parameterType="org.nafmii.entity.user.AppUserExample" resultMap="BaseResultMap">
select
<if test="distinct">
......@@ -105,13 +126,13 @@
delete from APP_USER
where ID = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="org.nafmii.entity.user.AppUserExample">
<delete id="deleteByExample" parameterType="org.nafmii.nafmiimbg.model.AppUserExample">
delete from APP_USER
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="org.nafmii.entity.user.AppUser">
<insert id="insert" parameterType="org.nafmii.nafmiimbg.model.AppUser">
insert into APP_USER (ID, USER_NAME, LOGIN_PWD,
REAL_NAME, PHONE, BIRTHDAY,
EMAIL, HEAD_PICTURE, NATIONALITY,
......@@ -125,7 +146,7 @@
#{faceidFalg,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
#{isEnable,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="org.nafmii.entity.user.AppUser">
<insert id="insertSelective" parameterType="org.nafmii.entity.user.AppUserExample">
insert into APP_USER
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
......@@ -312,7 +333,7 @@
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="org.nafmii.entity.user.AppUser">
<update id="updateByPrimaryKeySelective" parameterType="org.nafmii.entity.user.AppUserExample">
update APP_USER
<set>
<if test="userName != null">
......@@ -363,7 +384,7 @@
</set>
where ID = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="org.nafmii.entity.user.AppUser">
<update id="updateByPrimaryKey" parameterType="org.nafmii.nafmiimbg.model.AppUser">
update APP_USER
set USER_NAME = #{userName,jdbcType=VARCHAR},
LOGIN_PWD = #{loginPwd,jdbcType=VARCHAR},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!