Commit 1fcaba78 authored by machengbo's avatar machengbo

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

parents 02e4baa8 7254e1c8
package com.itheima.health.constant;
public interface RedisMessageConstant {
static final String SENDTYPE_ORDER = "001";//用于缓存体检预约时发送的验证码
static final String SENDTYPE_LOGIN = "002";//用于缓存手机号快速登录时发送的验证码
static final String SENDTYPE_GETPWD = "003";//用于缓存找回密码时发送的验证码
}
\ No newline at end of file
package com.jz.common.utils;
/**
* @ClassName:
* @Author: Carl
* @Date: 2020/12/1
* @Version:
*/
public class SMSUtils {
}
package com.jz.common.utils;
/**
* @ClassName:
* @Author: Carl
* @Date: 2020/12/1
* @Version:
*/
public class ValidateCodeUtils {
}
package com.jz.dm.mall; package com.jz.dm.mall;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
...@@ -8,6 +9,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; ...@@ -8,6 +9,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication @SpringBootApplication
@EnableRedisHttpSession @EnableRedisHttpSession
@EnableTransactionManagement @EnableTransactionManagement
@MapperScan("com.jz.dm.mall.moduls.mapper")
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {
......
package com.jz.dm.mall.moduls.controller.customer;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.entity.MallCustomer;
import com.jz.common.entity.SysUser;
import com.jz.common.utils.Result;
import com.jz.common.utils.StatusCode;
import com.jz.dm.mall.moduls.service.MallCustomerService;
import com.jz.manage.moduls.controller.BaseController;
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.*;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/**
* 商城用户(MallCustomer)表控制层
*
* @author Bellamy
* @since 2020-12-01 10:41:40
*/
@RestController
@RequestMapping("/mallCustomer")
public class MallCustomerController extends BaseController {
/**
* 服务对象
*/
@Autowired
private MallCustomerService mallCustomerService;
@Autowired
private RedisTemplate redisTemplate;
/**
* 登录功能
* @param customerAccount 账号
* @param password 密码
* @return
*/
@GetMapping(value = "/login")
public Result<SysUser> login(String customerAccount, String password) {
// 获取用户的信息
MallCustomer mallCustomer = mallCustomerService.selectByUsername(customerAccount);
if (mallCustomer == null) {
return new Result<>(false, "用户不存在!", StatusCode.LOGINERROR);
}
if (mallCustomer.getCustomerAccount().equals(customerAccount) && mallCustomer.getPassword().equals(password)) {
return new Result<>(true, "登录成功!", StatusCode.OK);
}
return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR);
}
/**
* 手机号码校验
* @param paramMap
* @param res
* @return
*/
@PostMapping(value = "/check")
public Result loginCheck(@RequestBody Map<String, String> paramMap, HttpServletResponse res) {
// 获取手机号码
String telephone = paramMap.get("telephone");
String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
// 获取redis中key对应的值
String codeInRedis = (String) redisTemplate.opsForValue().get(key);
if (StringUtils.isEmpty(codeInRedis)) {
return new Result(false, "请重新获取验证码!", StatusCode.ERROR);
}
// 判断验证码是否一致
if (!codeInRedis.equals(paramMap.get("validateCode"))) {
return new Result(false, "验证码不正确!", StatusCode.ERROR);
}
// 删除redis的验证码
redisTemplate.delete(key);
return new Result(true, "验证码正确!", StatusCode.OK);
}
}
\ No newline at end of file
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 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/1
* @Version:
*/
@RestController
@RequestMapping("/ValidateCode")
public class ValidateCodeController {
@Autowired
private RedisTemplate redisTemplate;
@PostMapping(value = "/sendForCode")
public Result sendForCode(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, "验证码发送成功!");
}
}
}
package com.jz.dm.mall.moduls.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import java.io.Serializable;
import java.util.Date;
/**
* 商城用户(TMallCustomer)实体类
*
* @author Bellamy
* @since 2020-12-01 10:41:39
*/
@TableName("t_mall_customer")
@ApiModel
public class MallCustomer implements Serializable {
private static final long serialVersionUID = 844124479008859411L;
/**
* 用户id
*/
private Long customerId;
/**
* 企业id
*/
private Long departmentId;
/**
* 密码
*/
private String password;
/**
* 账户
*/
private String customerAccount;
/**
* 用户真实姓名
*/
private String customerName;
/**
* 联系电话
*/
private String customerPhone;
/**
* 邮箱
*/
private String customerEmail;
/**
* 地址
*/
private String customerAddress;
/**
* 用户积分
*/
private Long customerPoint;
/**
* 注册时间
*/
private Date registerTime;
/**
* 会员等级
*/
private String customerLevel;
/**
* 证件号
*/
private String identityCard;
/**
* 创建时间
*/
private Date creTime;
/**
* 更新时间
*/
private Date uptTime;
/**
* 删除标识:Y是,N否
*/
private String delFlag;
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public Long getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Long departmentId) {
this.departmentId = departmentId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
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;
}
public String getCustomerPhone() {
return customerPhone;
}
public void setCustomerPhone(String customerPhone) {
this.customerPhone = customerPhone;
}
public String getCustomerEmail() {
return customerEmail;
}
public void setCustomerEmail(String customerEmail) {
this.customerEmail = customerEmail;
}
public String getCustomerAddress() {
return customerAddress;
}
public void setCustomerAddress(String customerAddress) {
this.customerAddress = customerAddress;
}
public Long getCustomerPoint() {
return customerPoint;
}
public void setCustomerPoint(Long customerPoint) {
this.customerPoint = customerPoint;
}
public Date getRegisterTime() {
return registerTime;
}
public void setRegisterTime(Date registerTime) {
this.registerTime = registerTime;
}
public String getCustomerLevel() {
return customerLevel;
}
public void setCustomerLevel(String customerLevel) {
this.customerLevel = customerLevel;
}
public String getIdentityCard() {
return identityCard;
}
public void setIdentityCard(String identityCard) {
this.identityCard = identityCard;
}
public Date getCreTime() {
return creTime;
}
public void setCreTime(Date creTime) {
this.creTime = creTime;
}
public Date getUptTime() {
return uptTime;
}
public void setUptTime(Date uptTime) {
this.uptTime = uptTime;
}
public String getDelFlag() {
return delFlag;
}
public void setDelFlag(String delFlag) {
this.delFlag = delFlag;
}
}
\ No newline at end of file
package com.jz.dm.mall.moduls.mapper;
import com.jz.common.base.BaseMapper;
import com.jz.common.entity.MallCustomer;
/**
* 商城用户(TMallCustomer)表数据库访问层
*
* @author Bellamy
* @since 2020-12-01 10:41:39
*/
public interface MallCustomerDao extends BaseMapper<MallCustomer> {
}
\ No newline at end of file
package com.jz.dm.mall.moduls.service;
import com.jz.common.entity.MallCustomer;
/**
* 商城用户(TMallCustomer)表服务接口
*
* @author Bellamy
* @since 2020-12-01 10:41:40
*/
public interface MallCustomerService {
/**
* 通过用户账号进行查询
* @param customerAccount
* @return
*/
MallCustomer selectByUsername(String customerAccount);
}
\ No newline at end of file
package com.jz.dm.mall.moduls.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jz.common.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.stereotype.Service;
/**
* 商城用户(TMallCustomer)表服务实现类
*
* @author Bellamy
* @since 2020-12-01 10:41:40
*/
@Service("mallCustomerService")
public class MallCustomerServiceImpl implements MallCustomerService {
@Autowired
private MallCustomerDao tMallCustomerDao;
/**
* 通过用户账号进行查询
*
* @param customerAccount
* @return
*/
@Override
public MallCustomer selectByUsername(String customerAccount) {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("customer_account", customerAccount);
return tMallCustomerDao.selectOne(queryWrapper);
}
}
\ No newline at end of file
<?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.MallCustomerDao">
<resultMap type="com.jz.dm.mall.moduls.entity.MallCustomer" id="TMallCustomerMap">
<result property="customerId" column="customer_id" jdbcType="INTEGER"/>
<result property="departmentId" column="department_id" jdbcType="INTEGER"/>
<result property="password" column="password" jdbcType="VARCHAR"/>
<result property="customerAccount" column="customer_account" jdbcType="VARCHAR"/>
<result property="customerName" column="customer_name" jdbcType="VARCHAR"/>
<result property="customerPhone" column="customer_phone" jdbcType="VARCHAR"/>
<result property="customerEmail" column="customer_email" jdbcType="VARCHAR"/>
<result property="customerAddress" column="customer_address" jdbcType="VARCHAR"/>
<result property="customerPoint" column="customer_point" jdbcType="INTEGER"/>
<result property="registerTime" column="register_time" jdbcType="TIMESTAMP"/>
<result property="customerLevel" column="customer_level" jdbcType="VARCHAR"/>
<result property="identityCard" column="identity_card" jdbcType="VARCHAR"/>
<result property="creTime" column="cre_time" jdbcType="TIMESTAMP"/>
<result property="uptTime" column="upt_time" jdbcType="TIMESTAMP"/>
<result property="delFlag" column="del_flag" jdbcType="VARCHAR"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="TMallCustomerMap">
select
customer_id, department_id, password, customer_account, customer_name, customer_phone, customer_email, customer_address, customer_point, register_time, customer_level, identity_card, cre_time, upt_time, del_flag
from t_mall_customer
where customer_id = #{customerId}
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="TMallCustomerMap">
select
customer_id, department_id, password, customer_account, customer_name, customer_phone, customer_email, customer_address, customer_point, register_time, customer_level, identity_card, cre_time, upt_time, del_flag
from t_mall_customer
limit #{offset}, #{limit}
</select>
<!--通过实体作为筛选条件查询-->
<select id="queryAll" resultMap="TMallCustomerMap">
select
customer_id, department_id, password, customer_account, customer_name, customer_phone, customer_email,
customer_address, customer_point, register_time, customer_level, identity_card, cre_time, upt_time, del_flag
from t_mall_customer
<where>
<if test="customerId != null">
and customer_id = #{customerId}
</if>
<if test="departmentId != null">
and department_id = #{departmentId}
</if>
<if test="password != null and password != ''">
and password = #{password}
</if>
<if test="customerAccount != null and customerAccount != ''">
and customer_account = #{customerAccount}
</if>
<if test="customerName != null and customerName != ''">
and customer_name = #{customerName}
</if>
<if test="customerPhone != null and customerPhone != ''">
and customer_phone = #{customerPhone}
</if>
<if test="customerEmail != null and customerEmail != ''">
and customer_email = #{customerEmail}
</if>
<if test="customerAddress != null and customerAddress != ''">
and customer_address = #{customerAddress}
</if>
<if test="customerPoint != null">
and customer_point = #{customerPoint}
</if>
<if test="registerTime != null">
and register_time = #{registerTime}
</if>
<if test="customerLevel != null and customerLevel != ''">
and customer_level = #{customerLevel}
</if>
<if test="identityCard != null and identityCard != ''">
and identity_card = #{identityCard}
</if>
<if test="creTime != null">
and cre_time = #{creTime}
</if>
<if test="uptTime != null">
and upt_time = #{uptTime}
</if>
<if test="delFlag != null and delFlag != ''">
and del_flag = #{delFlag}
</if>
</where>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="customerId" useGeneratedKeys="true">
insert into t_mall_customer(department_id, password, customer_account, customer_name, customer_phone, customer_email, customer_address, customer_point, register_time, customer_level, identity_card, cre_time, upt_time, del_flag)
values (#{departmentId}, #{password}, #{customerAccount}, #{customerName}, #{customerPhone}, #{customerEmail}, #{customerAddress}, #{customerPoint}, #{registerTime}, #{customerLevel}, #{identityCard}, #{creTime}, #{uptTime}, #{delFlag})
</insert>
<insert id="insertBatch" keyProperty="customerId" useGeneratedKeys="true">
insert into t_mall_customer(department_id, password, customer_account, customer_name,
customer_phone, customer_email, customer_address, customer_point, register_time, customer_level, identity_card,
cre_time, upt_time, del_flag)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.departmentId}, #{entity.password}, #{entity.customerAccount}, #{entity.customerName},
#{entity.customerPhone}, #{entity.customerEmail}, #{entity.customerAddress}, #{entity.customerPoint},
#{entity.registerTime}, #{entity.customerLevel}, #{entity.identityCard}, #{entity.creTime},
#{entity.uptTime}, #{entity.delFlag})
</foreach>
</insert>
<!--通过主键修改数据-->
<update id="update">
update t_mall_customer
<set>
<if test="departmentId != null">
department_id = #{departmentId},
</if>
<if test="password != null and password != ''">
password = #{password},
</if>
<if test="customerAccount != null and customerAccount != ''">
customer_account = #{customerAccount},
</if>
<if test="customerName != null and customerName != ''">
customer_name = #{customerName},
</if>
<if test="customerPhone != null and customerPhone != ''">
customer_phone = #{customerPhone},
</if>
<if test="customerEmail != null and customerEmail != ''">
customer_email = #{customerEmail},
</if>
<if test="customerAddress != null and customerAddress != ''">
customer_address = #{customerAddress},
</if>
<if test="customerPoint != null">
customer_point = #{customerPoint},
</if>
<if test="registerTime != null">
register_time = #{registerTime},
</if>
<if test="customerLevel != null and customerLevel != ''">
customer_level = #{customerLevel},
</if>
<if test="identityCard != null and identityCard != ''">
identity_card = #{identityCard},
</if>
<if test="creTime != null">
cre_time = #{creTime},
</if>
<if test="uptTime != null">
upt_time = #{uptTime},
</if>
<if test="delFlag != null and delFlag != ''">
del_flag = #{delFlag},
</if>
</set>
where customer_id = #{customerId}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from t_mall_customer where customer_id = #{customerId}
</delete>
</mapper>
\ No newline at end of file
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