controller层:
@Api(tags = "系统")
@RestController
@RequestMapping("/login")
public class LoginController extends BaseController{
@Autowired
private UplusUserService uplusUserService;
@ApiOperation(value = "登录")
@PostMapping(value = "/userLogin", name = "登录")
public Result userLogin(HttpServletRequest request,@RequestBody LoginDto loginDto) {
return uplusUserService.userLogin(request,loginDto);
}
}
入参Dto层:
@Data
@ApiModel(value = "LoginDto",description = "登录入参实体")
public class LoginDto implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "手机号")
private String phone;
@ApiModelProperty(value = "密码")
private String password;
@ApiModelProperty(value = "验证码")
private String phoneCode;
@ApiModelProperty(value = "登录方式:1.验证码登录;2.密码登录")
private Integer loginWay;
}
出参Vo层:
@Data
@ApiModel(value = "UserLoginVo",description = "登录出参")
public class UserLoginVo implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("授权码")
private String authorization;
@ApiModelProperty("用户信息")
private UplusUser user;
}
@Table(name = "UPLUS_USER")
public class UplusUser implements Serializable {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "DEPOT_ID")
private Long depotId;
@Column(name = "USER_NAME")
private String userName;
@Column(name = "PASSWORD")
private String password;
@Column(name = "PROXY_NUMBER")
private String proxyNumber;
@Column(name = "NICK_NAME")
private String nickName;
@Column(name = "PHONE")
private String phone;
@Column(name = "TYPE_CD")
private String typeCd;
@Column(name = "TYPE")
private String type;
@Column(name = "SEX")
private String sex;
@Column(name = "COMPANY")
private String company;
@Column(name = "SECURITY_KEY")
private String securityKey;
@Column(name = "SUPER_USER_ID")
private Long superUserId;
@Column(name = "LOCK_USER")
private String lockUser;
@Column(name = "CREATE_DATE")
private Date createDate;
@Column(name = "CREATE_USER")
private Long createUser;
@Column(name = "UPDATE_DATE")
private Date updateDate;
@Column(name = "UPDATE_USER")
private Long updateUser;
@Column(name = "HEADER_URL")
private String headerUrl;
@Column(name = "DELETE_DATE")
private Date deleteDate;
@Column(name = "DELETE_USER")
private Long deleteUser;
@Column(name = "DELETE_FLAG")
private String deleteFlag;
@Column(name = "INVITE_CODE")
private String inviteCode;
@Column(name = "INVITE_END_DATE")
private Date inviteEndDate;
@Column(name = "PROFIT_DATE")
private Date profitDate;
@Column(name = "PROFIT")
private Integer profit;
}
Service层:
public interface UplusUserService{
/**
* 登录
* */
Result userLogin(HttpServletRequest request,LoginDto loginDto);
}
Service层impl:
@Service
public class UplusUserServiceImpl implements UplusUserService {
@Autowired
private UplusUserDao uplusUserDao;
@Autowired
private UplusOrderDao uplusOrderDao;
@Autowired
private UplusMasterDao uplusMasterDao;
@Autowired
private UPlusWalletFlowDao uPlusWalletFlowDao;
@Autowired
private RedisUtil redisUtil;
@Autowired
UplusBrokerageRecordDao uplusBrokerageRecordDao;
@Override
public Result userLogin(HttpServletRequest request, LoginDto ldto) {
if (null == ldto) {
return Result.failure(ResultCode.PARAM_IS_BLANK);
}
if (null == ldto.getPhone() || "".equals(ldto.getPhone())) {
return Result.failure(ResultCode.PARAM_IS_BLANK);
}
// 根据手机查询用户是否存在
UplusUser uu = new UplusUser();
uu.setPhone(ldto.getPhone());
UplusUser uplusUser = this.uplusUserDao.selectOne(uu);
if (uplusUser == null) {
return Result.failure(ResultCode.USER_OR_PSW_ERROR);
}
// 判断用户权限
if ((UserEnum.UserTypeEnum.FWS.getValue().equals(uplusUser.getType()))
|| (UserEnum.UserTypeEnum.GHS.getValue().equals(uplusUser.getType()))) {
return Result.failure(ResultCode.LOGIN_NO_ACCESS);
}
// 判断当前用户状态
if (uplusUser.getLockUser().equals(UserEnum.UserLockEnum.LOCK.getCode().toString())) {
return Result.failure(ResultCode.USER_LOCK);
}
// 验证码登录
if (ldto.getLoginWay() == UserEnum.UserLoginWayEnum.CODE.getCode()) {
// String phoneCode = (String) redisUtil.get(ldto.getPhone());
// if (null == phoneCode || "".equals(phoneCode)) {
// return Result.failure(ResultCode.USER_LOGIN_ERROR_NOTPHONEORCODE);
// }
if (!"123456".equals(ldto.getPhoneCode())) {
return Result.failure(ResultCode.USER_LOGIN_CODE_OFNOAVAIL);
}
} else {
// 判断用户密码是否正确
String pswMD5 = CommonUtil.Md5(ldto.getPassword() + uplusUser.getSecurityKey());
if (!pswMD5.equals(uplusUser.getPassword())) {
return Result.failure(ResultCode.USER_OR_PSW_ERROR);
}
}
String authorization = JwtUtil.sign(uplusUser.getId(), uplusUser.getSecurityKey());
UserLoginVo userLoginVo = new UserLoginVo();
userLoginVo.setAuthorization(authorization);
userLoginVo.setUser(uplusUser);
request.getSession().setAttribute(CommonUtil.Md5(uplusUser.getId().toString()), uplusUser);
// 销毁redis验证码
redisUtil.delete(ldto.getPhone());
return Result.success(userLoginVo);
}
}
mapper层:
public interface UplusUserDao extends Mapper {
/**
* 查询我的团队总人数
*/
int selectCountById(Long id);
Page queryMember(TeamListDto td);
Page queryHeadUserSales(TeamListDto td);
UserExpand findUserExpandById(Long id);
/**
* 根据Phone 查询用户
*/
UserLoginVo findByPhone(String phone);
/**
* 根据用户id查询用户业绩
*/
}