Commit d22a126f authored by zhangc's avatar zhangc

Merge branch 'dm_dev' of gitlab.ioubuy.cn:yaobenzhang/dm_project into dm_dev

parents 05951075 e44ed819
......@@ -10,4 +10,5 @@ public class BaseController {
public Integer getCurrentUserId(){
return getCurrentUser().getUserId();
}*/
}
package com.jz.common.base;
import com.jz.common.bean.MallCustomerApiDto;
import javax.servlet.http.HttpServletRequest;
/**
* @ClassName:
* @Author: Carl
* @Date: 2020/12/3
* @Version:
*/
public class CurrentUser {
/**
* 获取用户信息
* @param req
* @return
*/
public static MallCustomerApiDto getCurrentUser(HttpServletRequest req){
MallCustomerApiDto mallCustomerApiDto =(MallCustomerApiDto) req.getAttribute("mallCustomer");
return mallCustomerApiDto;
}
/**
* 用户id
* @param request
* @return
*/
public static Long getCustomerId(HttpServletRequest request) {
Long customerId = getCurrentUser(request).getCustomerId();
return customerId;
}
/**
* 企业id
* @param request
* @return
*/
public static Long getDepartmentId(HttpServletRequest request) {
Long departmentId = getCurrentUser(request).getDepartmentId();
return departmentId;
}
}
package com.jz.common.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;
/**
* 账户
*/
@ApiModelProperty(value = "账户")
private String customerAccount;
/**
* 用户真实姓名
*/
@ApiModelProperty(value = "用户真实姓名")
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;
}
}
......@@ -3,4 +3,6 @@ package com.jz.common.constant;
public interface RedisMessageConstant {
static final String SENDTYPE_GETPWD = "001";//用于缓存找回密码时发送的验证码
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;
}
}
package com.jz.common.utils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
/**
......@@ -19,19 +16,16 @@ public class SessionUtils {
* @param objName 存储到session中的对象的变量名
* @param o 存储的任意数据
*/
public static void push(String objName, Object o) {
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
public static void setUserCurrent(String objName, Object o, HttpServletRequest request) {
request.getSession().setAttribute(objName, o);
}
/**
* 从session中获取数据
* @param objName 存储到session中的对象的变量名
* @param key 存储到session中的对象的变量名
*/
public static Object pop(String objName) {
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
return request.getSession().getAttribute(objName);
public static Object getUserCurrent(HttpServletRequest request, String key){
return request.getSession().getAttribute(key);
}
}
......@@ -74,10 +74,10 @@
</dependency>
<!-- spring boot 和mybatis -->
<!--<dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>-->
</dependency>
<!-- mybatis plus -->
<dependency>
......
package com.jz.dm.mall.moduls.controller.customer;
import com.jz.common.base.CurrentUser;
import com.jz.dm.mall.moduls.entity.MallCustomer;
import com.jz.common.utils.Result;
import com.jz.common.utils.StatusCode;
......@@ -12,8 +13,8 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
/**
* @ClassName:
......@@ -40,27 +41,24 @@ public class LoginController {
* @return
*/
@PostMapping(value = "/login")
public Result<MallCustomer> login(String username, String password, HttpServletRequest request) {
public Result<MallCustomer> login(String username, String password, HttpServletRequest request) throws Exception{
// 手机
String ph = "^[1][34578]\\d{9}$";
HttpSession session = request.getSession();
// 如果是手机验证
if (username.matches(username)) {
MallCustomer mallCustomer = mallCustomerService.selectByPhone(username);
MallCustomer mallCustomer = mallCustomerService.selectByPhone(username, request);
if (mallCustomer != null) {
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<>(false, "用户名或密码错误!", StatusCode.ERROR);
}
}
MallCustomer mallCustomer = mallCustomerService.selectByAccount(username);
MallCustomer mallCustomer = mallCustomerService.selectByAccount(username, request);
if (mallCustomer != null) {
if (mallCustomer.getCustomerAccount().equals(username) && mallCustomer.getPassword().equals(password)){
session.setAttribute("customer_id", mallCustomer.getCustomerId());
session.setAttribute("customer_account", mallCustomer.getCustomerAccount());
System.out.println(CurrentUser.getCurrentUser(request));
return new Result<>(true, "登录成功!", StatusCode.OK);
}
}
......
......@@ -2,6 +2,8 @@ package com.jz.dm.mall.moduls.controller.customer;
import com.jz.common.base.BaseController;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.constant.ResultCode;
import com.jz.common.constant.ResultMsg;
import com.jz.dm.mall.moduls.entity.MallCustomer;
import com.jz.common.utils.Result;
import com.jz.common.utils.StatusCode;
......@@ -32,6 +34,32 @@ public class MallCustomerController extends BaseController {
@Autowired
private RedisTemplate redisTemplate;
/**
* 添加用户
* @param paramMap
* @return
*/
@PostMapping("/saveCustomer")
public Result saveCustomer(@RequestParam(required = false) Map<String, String> paramMap) {
if (paramMap != null) {
String username = paramMap.get("username");
String telephone = paramMap.get("telephone");
if (username == null) {
return new Result(false, "请输入用户名!");
}
// // 根据用户名查询用户信息
//// MallCustomer mallCustomer = mallCustomerService.selectByAccount(username);
//// if (mallCustomer.getCustomerAccount().equals(username)) {
//// return new Result(false, "用户名相同!");
//// }
//// if (mallCustomer.getCustomerPhone().equals(telephone)) {
//// return new Result(false,"手机号相同!");
//// }
mallCustomerService.saveCustomer(paramMap);
return new Result(true, "注册成功!", StatusCode.OK);
}
return new Result(false, "注册失败!", StatusCode.ERROR);
}
/**
* 手机号码校验
......
//package com.jz.dm.mall.moduls.controller.customer;
//
//import com.aliyuncs.exceptions.ClientException;
//import com.jz.common.constant.RedisMessageConstant;
//import com.jz.common.utils.Result;
//import com.jz.common.utils.SMSUtils;
//import com.jz.common.utils.ValidateCodeUtils;
//import io.swagger.annotations.Api;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import redis.clients.jedis.Jedis;
//import redis.clients.jedis.JedisPool;
//
///**
// * @ClassName: 短信发送接口
// * @Author: Carl
// * @Date: 2020/12/2
// * @Version:
// */
//@RestController
//@RequestMapping("/validateCode")
//@Api(tags = "短信发送api")
//public class ValidateCodeController {
//
// //@Autowired
// //private JedisPool jedisPool;
//
// /**
// * 注册时发送的验证码
// * @param telephone
// * @return
// */
// @PostMapping("/send4Login")
// public Result send4Login(String telephone) {
// // 查询redis里是否存在该手机号
// Jedis jedis = jedisPool.getResource();
// String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
// String codeInRedis = jedis.get(key);
// if (codeInRedis != null && !codeInRedis.equals("")) {
// // redis中的数据还未过期
// return new Result(false, "验证码已发送,请注意查收!");
// }else {
// Integer code = ValidateCodeUtils.generateValidateCode(6);
// try {
// SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE, telephone, code.toString());
// } catch (Exception e) {
// e.printStackTrace();
// }
// jedis.setex(key,5*60,code+"");
// return new Result(true, "验证码发送成功!");
// }
// }
//
// /**
// * 修改密码发送验证码
// * @param telephone
// * @return
// */
// @PostMapping("/send4Code")
// public Result send4Code(String telephone) {
// // 查询redis里是否存在该手机号
// Jedis jedis = jedisPool.getResource();
// String key = RedisMessageConstant.SENDTYPE_GETPWD + "_" + telephone;
// String codeInRedis = jedis.get(key);
// if (codeInRedis != null && !codeInRedis.equals("")) {
// // redis中的数据还未过期
// return new Result(false, "验证码已发送,请注意查收!");
// }else {
// Integer code = ValidateCodeUtils.generateValidateCode(6);
// try {
// SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE, telephone, code.toString());
// } catch (Exception e) {
// e.printStackTrace();
// }
// jedis.setex(key,5*60,code+"");
// return new Result(true, "验证码发送成功!");
// }
// }
//}
package com.jz.dm.mall.moduls.controller.customer;
import com.aliyuncs.exceptions.ClientException;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.utils.Result;
import com.jz.common.utils.SMSUtils;
import com.jz.common.utils.ValidateCodeUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.TimeUnit;
/**
* @ClassName: 短信发送接口
* @Author: Carl
* @Date: 2020/12/2
* @Version:
*/
@RestController
@RequestMapping("/validateCode")
@Api(tags = "短信发送api")
public class ValidateCodeController {
@Autowired
private RedisTemplate redisTemplate;
/**
* 注册时发送的验证码
* @param telephone
* @return
*/
@PostMapping(value = "/sendForLogin")
public Result sendForLogin(String telephone) {
String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
// 通过手机号从redis获取验证码
String codeInRedis = (String) redisTemplate.opsForValue().get(key);
if (!StringUtils.isEmpty(codeInRedis)) {
return new Result(false, "验证码已发送,请注意查收!");
}else {
// 生成验证码
String code = ValidateCodeUtils.generateValidateCode(6) + "";
// 发送
try {
SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE, telephone, code);
} catch (ClientException e) {
e.printStackTrace();
return new Result(false, "验证码发送失败!");
}
// 存入redis, 有效期为5分钟
redisTemplate.opsForValue().set(key,code,5, TimeUnit.MINUTES);
return new Result(true, "验证码发送成功!");
}
}
/**
* 修改密码发送验证码
* @param telephone
* @return
*/
@PostMapping("/send4Code")
public Result send4Code(String telephone) {
String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
// 通过手机号从redis获取验证码
String codeInRedis = (String) redisTemplate.opsForValue().get(key);
if (!StringUtils.isEmpty(codeInRedis)) {
return new Result(false, "验证码已发送,请注意查收!");
} else {
// 生成验证码
String code = ValidateCodeUtils.generateValidateCode(6) + "";
// 发送
try {
SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE, telephone, code);
} catch (ClientException e) {
e.printStackTrace();
return new Result(false, "验证码发送失败!");
}
// 存入redis, 有效期为5分钟
redisTemplate.opsForValue().set(key, code, 5, TimeUnit.MINUTES);
return new Result(true, "验证码发送成功!");
}
}
}
......@@ -2,7 +2,7 @@ package com.jz.dm.mall.moduls.controller.finance;
import com.jz.common.base.BaseController;
import com.jz.common.utils.Result;
import com.jz.dm.mall.moduls.controller.order.bean.OrderDto;
import com.jz.dm.mall.moduls.controller.finance.bean.FinanceCustomerAssetsDto;
import com.jz.dm.mall.moduls.service.FinanceTradeFlowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
* 企业客户交易流水(TFinanceTradeFlow)表控制层
......@@ -33,11 +35,19 @@ public class FinanceTradeFlowController extends BaseController {
* 充值----获取企业账户余额
*
* @author Bellamy
* @since 2020-12-03
*/
@GetMapping(value = "/getAccountMoney")
@ApiOperation(value = "充值----获取账户余额", notes = "获取账户余额")
public Result<OrderDto> getAccountMoney(HttpServletRequest req) throws Exception {
return new Result<>();
@ApiOperation(value = "充值----获取账户余额", notes = "获取账户余额,只有已审核(认证)企业才可以充值")
public Result<FinanceCustomerAssetsDto> getAccountMoney(HttpServletRequest requset) throws Exception {
Result<FinanceCustomerAssetsDto> result = new Result<>();
//requset.getSession().getAttribute(""); //从session中获取商城用户的 id,和企业资产账户id
Map map = new HashMap();
map.put("assetsId", 1); //企业资产账户id
map.put("departmentId", 1); //企业ID
FinanceCustomerAssetsDto dto = financeTradeFlowService.queryAccountMoneyByMap(map);
result.setResult(dto);
return result;
}
}
\ No newline at end of file
package com.jz.dm.mall.moduls.controller.finance.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 商城企业客户资产(TFinanceCustomerAssets)实体类
*
* @author Bellamy
* @since 2020-12-01 10:41:38
*/
@ApiModel
public class FinanceCustomerAssetsDto implements Serializable {
private static final long serialVersionUID = -86484762300825431L;
/**
* 资产id
*/
@TableId(value = "assets_id",type = IdType.AUTO)
@ApiModelProperty(value = "资产id")
private Long assetsId;
/**
* 企业id
*/
@ApiModelProperty(value = "企业id")
private Long departmentId;
/**
* 可用金额
*/
@ApiModelProperty(value = "可用金额")
private BigDecimal useMoney;
/**
* 冻结金额
*/
@ApiModelProperty(value = "冻结金额")
private BigDecimal frozenMoney;
/**
* 总金额
*/
@ApiModelProperty(value = "总金额")
private BigDecimal totalMoney;
public Long getAssetsId() {
return assetsId;
}
public void setAssetsId(Long assetsId) {
this.assetsId = assetsId;
}
public Long getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Long departmentId) {
this.departmentId = departmentId;
}
public BigDecimal getUseMoney() {
return useMoney;
}
public void setUseMoney(BigDecimal useMoney) {
this.useMoney = useMoney;
}
public BigDecimal getFrozenMoney() {
return frozenMoney;
}
public void setFrozenMoney(BigDecimal frozenMoney) {
this.frozenMoney = frozenMoney;
}
public BigDecimal getTotalMoney() {
return totalMoney;
}
public void setTotalMoney(BigDecimal totalMoney) {
this.totalMoney = totalMoney;
}
}
\ No newline at end of file
package com.jz.dm.mall.moduls.mapper;
import com.jz.common.base.BaseMapper;
import com.jz.dm.mall.moduls.controller.finance.bean.FinanceCustomerAssetsDto;
import com.jz.dm.mall.moduls.entity.FinanceTradeFlow;
import java.util.Map;
/**
* 企业客户交易流水(TFinanceTradeFlow)表数据库访问层
*
......@@ -13,4 +16,5 @@ import com.jz.dm.mall.moduls.entity.FinanceTradeFlow;
public interface FinanceTradeFlowDao extends BaseMapper<FinanceTradeFlow> {
FinanceCustomerAssetsDto queryAccountMoneyByMap(Map map) throws Exception ;
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.jz.dm.mall.moduls.mapper;
import com.jz.common.base.BaseMapper;
import com.jz.dm.mall.moduls.entity.MallCustomer;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
......@@ -29,6 +30,10 @@ public interface MallCustomerDao extends BaseMapper<MallCustomer> {
*/
MallCustomer selectByPhone(String username);
@Insert("INSERT into t_mall_customer(customer_account, customer_phone, password) VALUES (#{customerAccount},#{customerPhone}, #{password})")
@ResultType(MallCustomer.class)
void saveCustomer(MallCustomer mallCustomer);
/**
* 根据ID查询用户信息
* @param customerId
......@@ -37,4 +42,5 @@ public interface MallCustomerDao extends BaseMapper<MallCustomer> {
@Select("select * from t_mall_customer where customer_id =#{customerId}")
@ResultType(MallCustomer.class)
MallCustomer findById(Long customerId);
}
\ No newline at end of file
package com.jz.dm.mall.moduls.service;
import com.jz.dm.mall.moduls.controller.finance.bean.FinanceCustomerAssetsDto;
import java.util.Map;
/**
* 企业客户交易流水(TFinanceTradeFlow)表服务接口
*
......@@ -9,4 +13,5 @@ package com.jz.dm.mall.moduls.service;
public interface FinanceTradeFlowService {
FinanceCustomerAssetsDto queryAccountMoneyByMap(Map map) throws Exception ;
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.jz.dm.mall.moduls.service;
import com.jz.dm.mall.moduls.entity.MallCustomer;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
......@@ -17,14 +18,18 @@ public interface MallCustomerService {
* @param username
* @return
*/
MallCustomer selectByAccount(String username);
MallCustomer selectByAccount(String username,HttpServletRequest request);
/**
* 通过手机号进行查询
* @param username
* @return
*/
MallCustomer selectByPhone(String username);
MallCustomer selectByPhone(String username, HttpServletRequest request);
/**
* 注册账号
* @param paramMap
*/
void saveCustomer(Map<String, String> paramMap);
}
\ No newline at end of file
package com.jz.dm.mall.moduls.service.impl;
import com.jz.dm.mall.moduls.controller.finance.bean.FinanceCustomerAssetsDto;
import com.jz.dm.mall.moduls.mapper.FinanceTradeFlowDao;
import com.jz.dm.mall.moduls.service.FinanceTradeFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* 企业客户交易流水(TFinanceTradeFlow)表服务实现类
*
......@@ -13,7 +16,12 @@ import org.springframework.stereotype.Service;
*/
@Service("financeTradeFlowService")
public class FinanceTradeFlowServiceImpl implements FinanceTradeFlowService {
@Autowired
private FinanceTradeFlowDao tFinanceTradeFlowDao;
private FinanceTradeFlowDao financeTradeFlowDao;
@Override
public FinanceCustomerAssetsDto queryAccountMoneyByMap(Map map) throws Exception {
return financeTradeFlowDao.queryAccountMoneyByMap(map);
}
}
\ No newline at end of file
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.common.bean.MallCustomerApiDto;
import com.jz.dm.mall.moduls.entity.MallCustomer;
import com.jz.dm.mall.moduls.mapper.MallCustomerDao;
import com.jz.dm.mall.moduls.service.MallCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* 商城用户(TMallCustomer)表服务实现类
*
......@@ -18,6 +29,9 @@ public class MallCustomerServiceImpl implements MallCustomerService {
@Autowired
private MallCustomerDao tMallCustomerDao;
@Autowired
private RedisTemplate redisTemplate;
/**
* 通过用户账号进行查询
*
......@@ -25,10 +39,28 @@ public class MallCustomerServiceImpl implements MallCustomerService {
* @return
*/
@Override
public MallCustomer selectByAccount(String username) {
return tMallCustomerDao.selectByAccount(username);
public MallCustomer selectByAccount(String username, HttpServletRequest request) {
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
request.getSession().setAttribute("mallCustomer", mallCustomerApiDto);
// 存入到redis
redisTemplate.opsForValue().set("user_" + RedisMessageConstant.SENDTYPE_LOGIN_CUSTOMER , mallCustomerApiDto, 3, TimeUnit.DAYS);
}
return mallCustomer;
}
/**
* 通过手机号进行查询
*
......@@ -36,9 +68,46 @@ public class MallCustomerServiceImpl implements MallCustomerService {
* @return
*/
@Override
public MallCustomer selectByPhone(String username) {
return tMallCustomerDao.selectByPhone(username);
public MallCustomer selectByPhone(String username, HttpServletRequest request) {
MallCustomer mallCustomer = tMallCustomerDao.selectByPhone(username);
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, request);
// 存入到redis
redisTemplate.opsForValue().set("user_" + RedisMessageConstant.SENDTYPE_LOGIN_CUSTOMER , mallCustomerApiDto, 3, TimeUnit.DAYS);
}
return mallCustomer;
}
/**
* 注册账号
*
* @param paramMap
*/
@Override
public void saveCustomer(Map<String, String> paramMap) {
MallCustomer mallCustomer = new MallCustomer();
// 获取验证码
String vailCode = paramMap.get("vailCode");
String telephone = paramMap.get("telephone");
// 从redis获取验证码
// String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
String key = "18179617425";
// String codeInRedis = (String) redisTemplate.opsForValue().get(key);
String codeInRedis = "147826";
if (codeInRedis.equals(vailCode)) {
mallCustomer.setCustomerAccount(paramMap.get("username"));
mallCustomer.setPassword(paramMap.get("password"));
mallCustomer.setCustomerPhone(telephone);
tMallCustomerDao.saveCustomer(mallCustomer);
}
}
}
\ No newline at end of file
......@@ -2,18 +2,18 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jz.dm.mall.moduls.mapper.FinanceCustomerAssetsDao">
<!-- <resultMap type="com.jz.manage.moduls.entity.FinanceCustomerAssets" id="TFinanceCustomerAssetsMap">-->
<!-- <result property="assetsId" column="assets_id" jdbcType="INTEGER"/>-->
<!-- <result property="departmentId" column="department_id" jdbcType="INTEGER"/>-->
<!-- <result property="useMoney" column="use_money" jdbcType="NUMERIC"/>-->
<!-- <result property="frozenMoney" column="frozen_money" jdbcType="NUMERIC"/>-->
<!-- <result property="totalMoney" column="total_money" jdbcType="NUMERIC"/>-->
<!-- <result property="creTime" column="cre_time" jdbcType="TIMESTAMP"/>-->
<!-- <result property="crePerson" column="cre_person" jdbcType="VARCHAR"/>-->
<!-- <result property="uptTime" column="upt_time" jdbcType="TIMESTAMP"/>-->
<!-- <result property="uptPerson" column="upt_person" jdbcType="VARCHAR"/>-->
<!-- <result property="delFlag" column="del_flag" jdbcType="VARCHAR"/>-->
<!-- </resultMap>-->
<resultMap type="com.jz.dm.mall.moduls.entity.FinanceCustomerAssets" id="TFinanceCustomerAssetsMap">
<result property="assetsId" column="assets_id" jdbcType="INTEGER"/>
<result property="departmentId" column="department_id" jdbcType="INTEGER"/>
<result property="useMoney" column="use_money" jdbcType="NUMERIC"/>
<result property="frozenMoney" column="frozen_money" jdbcType="NUMERIC"/>
<result property="totalMoney" column="total_money" jdbcType="NUMERIC"/>
<result property="creTime" column="cre_time" jdbcType="TIMESTAMP"/>
<result property="crePerson" column="cre_person" jdbcType="VARCHAR"/>
<result property="uptTime" column="upt_time" jdbcType="TIMESTAMP"/>
<result property="uptPerson" column="upt_person" jdbcType="VARCHAR"/>
<result property="delFlag" column="del_flag" jdbcType="VARCHAR"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="TFinanceCustomerAssetsMap">
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jz.dm.mall.moduls.mapper.FinanceTradeFlowDao">
<!--商城 充值 只有已审核(认证)企业-->
<select id="queryAccountMoneyByMap" resultType="com.jz.dm.mall.moduls.controller.finance.bean.FinanceCustomerAssetsDto" parameterType="map">
select
assets_id as assetsId,
department_id as departmentId,
use_money as useMoney,
frozen_money as frozenMoney,
total_money as totalMoney
from t_finance_customer_assets t
left join t_department t1 on t.department_id=t1.department_id and t1.audit_status='02'
where 1=1
<if test="assetsId != null">and assets_id = #{assetsId}</if>
<if test="departmentId != null">and department_id = #{departmentId}</if>
</select>
</mapper>
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.jz.manage.moduls.controller.sys;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.entity.SysUser;
import com.jz.common.utils.Result;
import com.jz.common.utils.SessionUtils;
import com.jz.common.utils.StatusCode;
import com.jz.manage.moduls.controller.BaseController;
import com.jz.manage.moduls.service.SysUserService;
......@@ -38,14 +39,12 @@ public class LoginController extends BaseController {
public Result login(String username, String password, HttpServletRequest request) {
// 手机
String ph = "^[1][34578]\\d{9}$";
HttpSession session = request.getSession();
// 如果是手机验证
if (username.matches(username)) {
SysUser sysUser = sysUserService.selectByPhone(username);
if (sysUser != null) {
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<>(false, "用户名或密码错误!", StatusCode.ERROR);
......@@ -54,8 +53,6 @@ public class LoginController extends BaseController {
SysUser sysUser = sysUserService.selectByUsername(username);
if (sysUser != null) {
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);
}
}
......@@ -64,7 +61,6 @@ public class LoginController extends BaseController {
/**
* 手机号码校验
* @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;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jz.common.constant.RedisMessageConstant;
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.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* 平台系统用户表(SysUser)表服务实现类
......@@ -23,19 +29,50 @@ public class SysUserServiceImpl implements SysUserService {
@Autowired
private SysUserDao sysUserDao;
@Autowired
private RedisTemplate redisTemplate;
@Override
public SysUser selectByUsername(String account) {
public SysUser selectByUsername(String username) {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("account", account);
return sysUserDao.selectOne(queryWrapper);
}
queryWrapper.eq("account", username);
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
public SysUser selectByPhone(String username) {
QueryWrapper queryWrapper = new QueryWrapper();
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
......
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