Commit 7f7bda24 authored by ysongq's avatar ysongq

commit

parent 4b65d01d
...@@ -3,4 +3,6 @@ package com.jz.common.constant; ...@@ -3,4 +3,6 @@ package com.jz.common.constant;
public interface RedisMessageConstant { public interface RedisMessageConstant {
static final String SENDTYPE_GETPWD = "001";//用于缓存找回密码时发送的验证码 static final String SENDTYPE_GETPWD = "001";//用于缓存找回密码时发送的验证码
static final String SENDTYPE_LOGIN = "002"; // 用于缓存注册用户时发送的验证码 static final String SENDTYPE_LOGIN = "002"; // 用于缓存注册用户时发送的验证码
static final String SENDTYPE_LOGIN_CUSTOMER = "003";
static final String SENDTYPE_LOGIN_SYS = "004";
} }
\ No newline at end of file
package com.jz.common.enums;
/**
* @Author: Carl
* @Date: 2020/12/3
* @Version:
*/
public enum UserTypeEnum {
COMPANY_ROLE("商城的id","1"),
BACKGROUND_ROLE("企业的id", "2"),
;
private String code;
private String value;
private UserTypeEnum(String code, String value) {
this.code = code;
this.value = value;
}
public String getCode() {
return code;
}
public String getValue() {
return value;
}
}
...@@ -19,7 +19,7 @@ public class SessionUtils { ...@@ -19,7 +19,7 @@ public class SessionUtils {
* @param objName 存储到session中的对象的变量名 * @param objName 存储到session中的对象的变量名
* @param o 存储的任意数据 * @param o 存储的任意数据
*/ */
public static void push(String objName, Object o) { public static void setUserCurrent(String objName, Object o) {
HttpServletRequest request = HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
request.getSession().setAttribute(objName, o); request.getSession().setAttribute(objName, o);
...@@ -29,7 +29,7 @@ public class SessionUtils { ...@@ -29,7 +29,7 @@ public class SessionUtils {
* 从session中获取数据 * 从session中获取数据
* @param objName 存储到session中的对象的变量名 * @param objName 存储到session中的对象的变量名
*/ */
public static Object pop(String objName) { public static Object getUserCurrent(String objName) {
HttpServletRequest request = HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
return request.getSession().getAttribute(objName); return request.getSession().getAttribute(objName);
......
...@@ -12,8 +12,6 @@ import org.springframework.web.bind.annotation.PostMapping; ...@@ -12,8 +12,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/** /**
* @ClassName: * @ClassName:
...@@ -40,17 +38,14 @@ public class LoginController { ...@@ -40,17 +38,14 @@ public class LoginController {
* @return * @return
*/ */
@PostMapping(value = "/login") @PostMapping(value = "/login")
public Result<MallCustomer> login(String username, String password, HttpServletRequest request) { public Result<MallCustomer> login(String username, String password) {
// 手机 // 手机
String ph = "^[1][34578]\\d{9}$"; String ph = "^[1][34578]\\d{9}$";
HttpSession session = request.getSession();
// 如果是手机验证 // 如果是手机验证
if (username.matches(username)) { if (username.matches(username)) {
MallCustomer mallCustomer = mallCustomerService.selectByPhone(username); MallCustomer mallCustomer = mallCustomerService.selectByPhone(username);
if (mallCustomer != null) { if (mallCustomer != null) {
if (mallCustomer.getCustomerPhone().equals(username) && mallCustomer.getPassword().equals(password)){ if (mallCustomer.getCustomerPhone().equals(username) && mallCustomer.getPassword().equals(password)){
session.setAttribute("customer_id", mallCustomer.getCustomerId());
session.setAttribute("customer_account", mallCustomer.getCustomerAccount());
return new Result<>(true, "登录成功!", StatusCode.OK); return new Result<>(true, "登录成功!", StatusCode.OK);
} }
return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR); return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR);
...@@ -59,8 +54,6 @@ public class LoginController { ...@@ -59,8 +54,6 @@ public class LoginController {
MallCustomer mallCustomer = mallCustomerService.selectByAccount(username); MallCustomer mallCustomer = mallCustomerService.selectByAccount(username);
if (mallCustomer != null) { if (mallCustomer != null) {
if (mallCustomer.getCustomerAccount().equals(username) && mallCustomer.getPassword().equals(password)){ if (mallCustomer.getCustomerAccount().equals(username) && mallCustomer.getPassword().equals(password)){
session.setAttribute("customer_id", mallCustomer.getCustomerId());
session.setAttribute("customer_account", mallCustomer.getCustomerAccount());
return new Result<>(true, "登录成功!", StatusCode.OK); return new Result<>(true, "登录成功!", StatusCode.OK);
} }
} }
......
package com.jz.dm.mall.moduls.controller.customer.bean;
import com.jz.common.enums.UserTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
/**
* @ClassName: 商城用户状态信息
* @Author: Carl
* @Date: 2020/12/3
* @Version:
*/
@ApiModel
public class MallCustomerApiDto implements Serializable {
private static final long serialVersionUID = 8769496459018372044L;
@ApiModelProperty(value = "用户id")
private Long customerId;
@ApiModelProperty(value = "用户类型")
private UserTypeEnum userTypeEnum;
@ApiModelProperty(value = "企业id")
private Long departmentId;
/**
* 账户
*/
private String customerAccount;
/**
* 用户真实姓名
*/
private String customerName;
public static long getSerialVersionUID() {
return serialVersionUID;
}
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public UserTypeEnum getUserTypeEnum() {
return userTypeEnum;
}
public void setUserTypeEnum(UserTypeEnum userTypeEnum) {
this.userTypeEnum = userTypeEnum;
}
public Long getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Long departmentId) {
this.departmentId = departmentId;
}
public String getCustomerAccount() {
return customerAccount;
}
public void setCustomerAccount(String customerAccount) {
this.customerAccount = customerAccount;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
}
package com.jz.dm.mall.moduls.service.impl; package com.jz.dm.mall.moduls.service.impl;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.enums.UserTypeEnum;
import com.jz.common.utils.SessionUtils;
import com.jz.dm.mall.moduls.controller.customer.bean.MallCustomerApiDto;
import com.jz.dm.mall.moduls.entity.MallCustomer; import com.jz.dm.mall.moduls.entity.MallCustomer;
import com.jz.dm.mall.moduls.mapper.MallCustomerDao; import com.jz.dm.mall.moduls.mapper.MallCustomerDao;
import com.jz.dm.mall.moduls.service.MallCustomerService; import com.jz.dm.mall.moduls.service.MallCustomerService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
/** /**
* 商城用户(TMallCustomer)表服务实现类 * 商城用户(TMallCustomer)表服务实现类
...@@ -18,6 +25,9 @@ public class MallCustomerServiceImpl implements MallCustomerService { ...@@ -18,6 +25,9 @@ public class MallCustomerServiceImpl implements MallCustomerService {
@Autowired @Autowired
private MallCustomerDao tMallCustomerDao; private MallCustomerDao tMallCustomerDao;
@Autowired
private RedisTemplate redisTemplate;
/** /**
* 通过用户账号进行查询 * 通过用户账号进行查询
* *
...@@ -26,7 +36,23 @@ public class MallCustomerServiceImpl implements MallCustomerService { ...@@ -26,7 +36,23 @@ public class MallCustomerServiceImpl implements MallCustomerService {
*/ */
@Override @Override
public MallCustomer selectByAccount(String username) { public MallCustomer selectByAccount(String username) {
return tMallCustomerDao.selectByAccount(username); MallCustomer mallCustomer = tMallCustomerDao.selectByAccount(username);
// String customer = JSON.toJSONString(mallCustomer);
if (mallCustomer != null) {
MallCustomerApiDto mallCustomerApiDto = new MallCustomerApiDto();
// 赋值
mallCustomerApiDto.setCustomerId(mallCustomer.getCustomerId());
mallCustomerApiDto.setDepartmentId(mallCustomer.getDepartmentId());
mallCustomerApiDto.setUserTypeEnum(UserTypeEnum.COMPANY_ROLE);
mallCustomerApiDto.setCustomerAccount(mallCustomer.getCustomerAccount());
mallCustomerApiDto.setCustomerName(mallCustomer.getCustomerName());
// 存入到session
SessionUtils.setUserCurrent("mallCustomer", mallCustomerApiDto);
// 存入到redis
redisTemplate.opsForValue().set("user_" + RedisMessageConstant.SENDTYPE_LOGIN_CUSTOMER , mallCustomerApiDto, 3, TimeUnit.DAYS);
}
return mallCustomer;
} }
/** /**
...@@ -37,7 +63,9 @@ public class MallCustomerServiceImpl implements MallCustomerService { ...@@ -37,7 +63,9 @@ public class MallCustomerServiceImpl implements MallCustomerService {
*/ */
@Override @Override
public MallCustomer selectByPhone(String username) { public MallCustomer selectByPhone(String username) {
return tMallCustomerDao.selectByPhone(username); MallCustomer mallCustomer = tMallCustomerDao.selectByPhone(username);
return mallCustomer;
} }
......
...@@ -3,6 +3,7 @@ package com.jz.manage.moduls.controller.sys; ...@@ -3,6 +3,7 @@ package com.jz.manage.moduls.controller.sys;
import com.jz.common.constant.RedisMessageConstant; import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.entity.SysUser; import com.jz.common.entity.SysUser;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.common.utils.SessionUtils;
import com.jz.common.utils.StatusCode; import com.jz.common.utils.StatusCode;
import com.jz.manage.moduls.controller.BaseController; import com.jz.manage.moduls.controller.BaseController;
import com.jz.manage.moduls.service.SysUserService; import com.jz.manage.moduls.service.SysUserService;
...@@ -38,14 +39,12 @@ public class LoginController extends BaseController { ...@@ -38,14 +39,12 @@ public class LoginController extends BaseController {
public Result login(String username, String password, HttpServletRequest request) { public Result login(String username, String password, HttpServletRequest request) {
// 手机 // 手机
String ph = "^[1][34578]\\d{9}$"; String ph = "^[1][34578]\\d{9}$";
HttpSession session = request.getSession();
// 如果是手机验证 // 如果是手机验证
if (username.matches(username)) { if (username.matches(username)) {
SysUser sysUser = sysUserService.selectByPhone(username); SysUser sysUser = sysUserService.selectByPhone(username);
if (sysUser != null) { if (sysUser != null) {
if (sysUser.getTelephone().equals(username) && sysUser.getPassword().equals(password)){ if (sysUser.getTelephone().equals(username) && sysUser.getPassword().equals(password)){
session.setAttribute("account", sysUser.getAccount());
session.setAttribute("password", sysUser.getPassword());
return new Result<>(true, "登录成功!", StatusCode.OK); return new Result<>(true, "登录成功!", StatusCode.OK);
} }
return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR); return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR);
...@@ -54,8 +53,6 @@ public class LoginController extends BaseController { ...@@ -54,8 +53,6 @@ public class LoginController extends BaseController {
SysUser sysUser = sysUserService.selectByUsername(username); SysUser sysUser = sysUserService.selectByUsername(username);
if (sysUser != null) { if (sysUser != null) {
if (sysUser.getAccount().equals(username) && sysUser.getPassword().equals(password)){ if (sysUser.getAccount().equals(username) && sysUser.getPassword().equals(password)){
session.setAttribute("account", sysUser.getAccount());
session.setAttribute("password", sysUser.getPassword());
return new Result<>(true, "登录成功!", StatusCode.OK); return new Result<>(true, "登录成功!", StatusCode.OK);
} }
} }
...@@ -64,7 +61,6 @@ public class LoginController extends BaseController { ...@@ -64,7 +61,6 @@ public class LoginController extends BaseController {
/** /**
* 手机号码校验 * 手机号码校验
* @param paramMap * @param paramMap
......
package com.jz.manage.moduls.controller.sys.bean;
import com.jz.common.enums.UserTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
/**
* @ClassName: 后台用户状态信息
* @Author: Carl
* @Date: 2020/12/3
* @Version:
*/
@ApiModel
public class SysUserDto implements Serializable {
private static final long serialVersionUID = -8194718171444972705L;
/**
* 平台用户id
*/
@ApiModelProperty(value = "平台用户id")
private Long userId;
/**
* 组织机构id
*/
@ApiModelProperty(value = "组织机构id")
private Long orgId;
/**
* 用户姓名
*/
@ApiModelProperty(value = "用户姓名")
private String userName;
/**
* 账户
*/
@ApiModelProperty(value = "账户")
private String account;
/**
* 电话
*/
@ApiModelProperty(value = "账号类型")
private UserTypeEnum userTypeEnum;
public static long getSerialVersionUID() {
return serialVersionUID;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Long getOrgId() {
return orgId;
}
public void setOrgId(Long orgId) {
this.orgId = orgId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public UserTypeEnum getUserTypeEnum() {
return userTypeEnum;
}
public void setUserTypeEnum(UserTypeEnum userTypeEnum) {
this.userTypeEnum = userTypeEnum;
}
}
package com.jz.manage.moduls.service.impl; package com.jz.manage.moduls.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.entity.SysUser; import com.jz.common.entity.SysUser;
import com.jz.common.enums.UserTypeEnum;
import com.jz.common.utils.SessionUtils;
import com.jz.manage.moduls.controller.sys.bean.SysUserDto;
import com.jz.manage.moduls.mapper.SysUserDao; import com.jz.manage.moduls.mapper.SysUserDao;
import com.jz.manage.moduls.service.SysUserService; import com.jz.manage.moduls.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* 平台系统用户表(SysUser)表服务实现类 * 平台系统用户表(SysUser)表服务实现类
...@@ -23,19 +29,50 @@ public class SysUserServiceImpl implements SysUserService { ...@@ -23,19 +29,50 @@ public class SysUserServiceImpl implements SysUserService {
@Autowired @Autowired
private SysUserDao sysUserDao; private SysUserDao sysUserDao;
@Autowired
private RedisTemplate redisTemplate;
@Override @Override
public SysUser selectByUsername(String account) { public SysUser selectByUsername(String username) {
QueryWrapper queryWrapper = new QueryWrapper(); QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("account", account); queryWrapper.eq("account", username);
return sysUserDao.selectOne(queryWrapper); SysUser sysUser = sysUserDao.selectOne(queryWrapper);
if (sysUser != null) {
SysUserDto SysUserDto = new SysUserDto();
// 赋值
SysUserDto.setUserId(sysUser.getUserId());
SysUserDto.setOrgId(sysUser.getOrgId());
SysUserDto.setAccount(sysUser.getAccount());
SysUserDto.setUserTypeEnum(UserTypeEnum.BACKGROUND_ROLE);
SysUserDto.setUserName(sysUser.getUserName());
// 存入到session
SessionUtils.setUserCurrent("sysUser", SysUserDto);
// 存入到redis
redisTemplate.opsForValue().set("user_" + RedisMessageConstant.SENDTYPE_LOGIN_SYS, SysUserDto, 3, TimeUnit.DAYS);
}
return sysUser;
} }
@Override @Override
public SysUser selectByPhone(String username) { public SysUser selectByPhone(String username) {
QueryWrapper queryWrapper = new QueryWrapper(); QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("telephone", username); queryWrapper.eq("telephone", username);
return sysUserDao.selectOne(queryWrapper); SysUser sysUser = sysUserDao.selectOne(queryWrapper);
if (sysUser != null) {
SysUserDto SysUserDto = new SysUserDto();
// 赋值
SysUserDto.setUserId(sysUser.getUserId());
SysUserDto.setOrgId(sysUser.getOrgId());
SysUserDto.setAccount(sysUser.getAccount());
SysUserDto.setUserTypeEnum(UserTypeEnum.BACKGROUND_ROLE);
SysUserDto.setUserName(sysUser.getUserName());
// 存入到session
SessionUtils.setUserCurrent("sysUser", SysUserDto);
// 存入到redis
redisTemplate.opsForValue().set("user_" + RedisMessageConstant.SENDTYPE_LOGIN_SYS, SysUserDto, 3, TimeUnit.DAYS);
}
return sysUser;
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment