parent
466798d1aa
commit
c375ffeb5d
@ -0,0 +1,30 @@ |
||||
package com.ruoyi.web.controller.platform; |
||||
|
||||
import com.ruoyi.common.core.controller.BaseController; |
||||
import com.ruoyi.common.core.domain.AjaxResult; |
||||
import com.ruoyi.common.enums.PlatformConfig; |
||||
import com.ruoyi.platform.domain.PlatformSms; |
||||
import com.ruoyi.platform.service.IPlatformSmsService; |
||||
import com.ruoyi.system.service.ISysConfigService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
@RestController |
||||
@RequestMapping("/platform/public/sms") |
||||
public class PlatformSmsController extends BaseController { |
||||
|
||||
@Autowired |
||||
private IPlatformSmsService platformSmsService; |
||||
|
||||
@Autowired |
||||
private ISysConfigService sysConfigService; |
||||
|
||||
@PostMapping("send") |
||||
public AjaxResult send(@Validated @RequestBody PlatformSms sms) { |
||||
return success(platformSmsService.send(sms.getMobile(), Integer.valueOf(sysConfigService.selectConfigById(PlatformConfig.smsTime.getConfigId()).getConfigValue()))); |
||||
} |
||||
} |
@ -0,0 +1,122 @@ |
||||
package com.ruoyi.platform.domain; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.ruoyi.common.annotation.Excel; |
||||
import com.ruoyi.common.core.domain.BaseEntity; |
||||
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||
import org.apache.commons.lang3.builder.ToStringStyle; |
||||
|
||||
import javax.validation.constraints.NotBlank; |
||||
import javax.validation.constraints.Pattern; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 短信验证码对象 platform_sms |
||||
* |
||||
* @author ruoyi |
||||
* @date 2023-02-09 |
||||
*/ |
||||
public class PlatformSms extends BaseEntity { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 主键 |
||||
*/ |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
private Long id; |
||||
|
||||
/** |
||||
* 中国大陆手机号 |
||||
*/ |
||||
@Excel(name = "中国大陆手机号") |
||||
@NotBlank(message = "手机号不能为空") |
||||
@Pattern(message = "手机号不合法", regexp = "^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$") |
||||
private String mobile; |
||||
|
||||
/** |
||||
* 6位数字 |
||||
*/ |
||||
@Excel(name = "6位数字") |
||||
private String code; |
||||
|
||||
/** |
||||
* 未发送或发送失败为空 |
||||
*/ |
||||
@Excel(name = "未发送或发送失败为空") |
||||
private Date sendtime; |
||||
|
||||
/** |
||||
* 未发送或发送失败为空 |
||||
*/ |
||||
@Excel(name = "未发送或发送失败为空") |
||||
private Date deadtime; |
||||
|
||||
/** |
||||
* $column.columnComment |
||||
*/ |
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") |
||||
private String error; |
||||
|
||||
public void setId(Long id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public Long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setMobile(String mobile) { |
||||
this.mobile = mobile; |
||||
} |
||||
|
||||
public String getMobile() { |
||||
return mobile; |
||||
} |
||||
|
||||
public void setCode(String code) { |
||||
this.code = code; |
||||
} |
||||
|
||||
public String getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public void setSendtime(Date sendtime) { |
||||
this.sendtime = sendtime; |
||||
} |
||||
|
||||
public Date getSendtime() { |
||||
return sendtime; |
||||
} |
||||
|
||||
public void setDeadtime(Date deadtime) { |
||||
this.deadtime = deadtime; |
||||
} |
||||
|
||||
public Date getDeadtime() { |
||||
return deadtime; |
||||
} |
||||
|
||||
public void setError(String error) { |
||||
this.error = error; |
||||
} |
||||
|
||||
public String getError() { |
||||
return error; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) |
||||
.append("id", getId()) |
||||
.append("mobile", getMobile()) |
||||
.append("code", getCode()) |
||||
.append("sendtime", getSendtime()) |
||||
.append("deadtime", getDeadtime()) |
||||
.append("error", getError()) |
||||
.append("remark", getRemark()) |
||||
.toString(); |
||||
} |
||||
} |
@ -0,0 +1,62 @@ |
||||
package com.ruoyi.platform.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.ruoyi.platform.domain.PlatformSms; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 短信验证码Mapper接口 |
||||
* |
||||
* @author ruoyi |
||||
* @date 2023-02-09 |
||||
*/ |
||||
public interface PlatformSmsMapper extends BaseMapper<PlatformSms> { |
||||
/** |
||||
* 查询短信验证码 |
||||
* |
||||
* @param id 短信验证码主键 |
||||
* @return 短信验证码 |
||||
*/ |
||||
public PlatformSms selectPlatformSmsById(Long id); |
||||
|
||||
/** |
||||
* 查询短信验证码列表 |
||||
* |
||||
* @param platformSms 短信验证码 |
||||
* @return 短信验证码集合 |
||||
*/ |
||||
public List<PlatformSms> selectPlatformSmsList(PlatformSms platformSms); |
||||
|
||||
/** |
||||
* 新增短信验证码 |
||||
* |
||||
* @param platformSms 短信验证码 |
||||
* @return 结果 |
||||
*/ |
||||
public int insertPlatformSms(PlatformSms platformSms); |
||||
|
||||
/** |
||||
* 修改短信验证码 |
||||
* |
||||
* @param platformSms 短信验证码 |
||||
* @return 结果 |
||||
*/ |
||||
public int updatePlatformSms(PlatformSms platformSms); |
||||
|
||||
/** |
||||
* 删除短信验证码 |
||||
* |
||||
* @param id 短信验证码主键 |
||||
* @return 结果 |
||||
*/ |
||||
public int deletePlatformSmsById(Long id); |
||||
|
||||
/** |
||||
* 批量删除短信验证码 |
||||
* |
||||
* @param ids 需要删除的数据主键集合 |
||||
* @return 结果 |
||||
*/ |
||||
public int deletePlatformSmsByIds(Long[] ids); |
||||
} |
@ -0,0 +1,70 @@ |
||||
package com.ruoyi.platform.service; |
||||
|
||||
import com.ruoyi.platform.domain.PlatformSms; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 短信验证码Service接口 |
||||
* |
||||
* @author ruoyi |
||||
* @date 2023-02-09 |
||||
*/ |
||||
public interface IPlatformSmsService { |
||||
/** |
||||
* 查询短信验证码 |
||||
* |
||||
* @param id 短信验证码主键 |
||||
* @return 短信验证码 |
||||
*/ |
||||
public PlatformSms selectPlatformSmsById(Long id); |
||||
|
||||
/** |
||||
* 查询短信验证码列表 |
||||
* |
||||
* @param platformSms 短信验证码 |
||||
* @return 短信验证码集合 |
||||
*/ |
||||
public List<PlatformSms> selectPlatformSmsList(PlatformSms platformSms); |
||||
|
||||
/** |
||||
* 新增短信验证码 |
||||
* |
||||
* @param platformSms 短信验证码 |
||||
* @return 结果 |
||||
*/ |
||||
public int insertPlatformSms(PlatformSms platformSms); |
||||
|
||||
/** |
||||
* 修改短信验证码 |
||||
* |
||||
* @param platformSms 短信验证码 |
||||
* @return 结果 |
||||
*/ |
||||
public int updatePlatformSms(PlatformSms platformSms); |
||||
|
||||
/** |
||||
* 批量删除短信验证码 |
||||
* |
||||
* @param ids 需要删除的短信验证码主键集合 |
||||
* @return 结果 |
||||
*/ |
||||
public int deletePlatformSmsByIds(Long[] ids); |
||||
|
||||
/** |
||||
* 删除短信验证码信息 |
||||
* |
||||
* @param id 短信验证码主键 |
||||
* @return 结果 |
||||
*/ |
||||
public int deletePlatformSmsById(Long id); |
||||
|
||||
/** |
||||
* 发送短信验证码 |
||||
* |
||||
* @param mobile 手机号 |
||||
* @param integer |
||||
* @return 结果 |
||||
*/ |
||||
String send(String mobile, Integer integer); |
||||
} |
@ -0,0 +1,114 @@ |
||||
package com.ruoyi.platform.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.ruoyi.common.utils.DateUtils; |
||||
import com.ruoyi.platform.domain.PlatformSms; |
||||
import com.ruoyi.platform.mapper.PlatformSmsMapper; |
||||
import com.ruoyi.platform.service.IPlatformSmsService; |
||||
import org.apache.commons.lang3.RandomStringUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 短信验证码Service业务层处理 |
||||
* |
||||
* @author ruoyi |
||||
* @date 2023-02-09 |
||||
*/ |
||||
@Service |
||||
public class PlatformSmsServiceImpl implements IPlatformSmsService { |
||||
@Autowired |
||||
private PlatformSmsMapper platformSmsMapper; |
||||
|
||||
/** |
||||
* 查询短信验证码 |
||||
* |
||||
* @param id 短信验证码主键 |
||||
* @return 短信验证码 |
||||
*/ |
||||
@Override |
||||
public PlatformSms selectPlatformSmsById(Long id) { |
||||
return platformSmsMapper.selectPlatformSmsById(id); |
||||
} |
||||
|
||||
/** |
||||
* 查询短信验证码列表 |
||||
* |
||||
* @param platformSms 短信验证码 |
||||
* @return 短信验证码 |
||||
*/ |
||||
@Override |
||||
public List<PlatformSms> selectPlatformSmsList(PlatformSms platformSms) { |
||||
return platformSmsMapper.selectPlatformSmsList(platformSms); |
||||
} |
||||
|
||||
/** |
||||
* 新增短信验证码 |
||||
* |
||||
* @param platformSms 短信验证码 |
||||
* @return 结果 |
||||
*/ |
||||
@Override |
||||
public int insertPlatformSms(PlatformSms platformSms) { |
||||
return platformSmsMapper.insertPlatformSms(platformSms); |
||||
} |
||||
|
||||
/** |
||||
* 修改短信验证码 |
||||
* |
||||
* @param platformSms 短信验证码 |
||||
* @return 结果 |
||||
*/ |
||||
@Override |
||||
public int updatePlatformSms(PlatformSms platformSms) { |
||||
return platformSmsMapper.updatePlatformSms(platformSms); |
||||
} |
||||
|
||||
/** |
||||
* 批量删除短信验证码 |
||||
* |
||||
* @param ids 需要删除的短信验证码主键 |
||||
* @return 结果 |
||||
*/ |
||||
@Override |
||||
public int deletePlatformSmsByIds(Long[] ids) { |
||||
return platformSmsMapper.deletePlatformSmsByIds(ids); |
||||
} |
||||
|
||||
/** |
||||
* 删除短信验证码信息 |
||||
* |
||||
* @param id 短信验证码主键 |
||||
* @return 结果 |
||||
*/ |
||||
@Override |
||||
public int deletePlatformSmsById(Long id) { |
||||
return platformSmsMapper.deletePlatformSmsById(id); |
||||
} |
||||
|
||||
@Override |
||||
public String send(String mobile, Integer smsTime) { |
||||
LambdaQueryWrapper<PlatformSms> wrapper = new LambdaQueryWrapper<>(); |
||||
Date d = new Date(); |
||||
wrapper.select(PlatformSms::getId).eq(PlatformSms::getMobile, mobile).le(PlatformSms::getSendtime, d).ge(PlatformSms::getDeadtime, d); |
||||
|
||||
PlatformSms sms = platformSmsMapper.selectOne(wrapper); |
||||
if (sms != null) { |
||||
return "短信发送过于频繁"; |
||||
} else { |
||||
String code = RandomStringUtils.randomNumeric(6); |
||||
PlatformSms newSms = new PlatformSms(); |
||||
newSms.setMobile(mobile); |
||||
newSms.setCode(code); |
||||
//TODO 发送验证码成功
|
||||
|
||||
newSms.setSendtime(new Date()); |
||||
newSms.setDeadtime(DateUtils.addSeconds(newSms.getSendtime(), smsTime)); |
||||
platformSmsMapper.insert(newSms); |
||||
return "短信验证码发送成功"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,85 @@ |
||||
<?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.ruoyi.system.mapper.PlatformSmsMapper"> |
||||
|
||||
<resultMap type="PlatformSms" id="PlatformSmsResult"> |
||||
<result property="id" column="id"/> |
||||
<result property="mobile" column="mobile"/> |
||||
<result property="code" column="code"/> |
||||
<result property="sendtime" column="sendTime"/> |
||||
<result property="deadtime" column="deadTime"/> |
||||
<result property="error" column="error"/> |
||||
<result property="remark" column="remark"/> |
||||
</resultMap> |
||||
|
||||
<sql id="selectPlatformSmsVo"> |
||||
select id, mobile, code, sendTime, deadTime, error, remark |
||||
from platform_sms |
||||
</sql> |
||||
|
||||
<select id="selectPlatformSmsList" parameterType="PlatformSms" resultMap="PlatformSmsResult"> |
||||
<include refid="selectPlatformSmsVo"/> |
||||
<where> |
||||
<if test="mobile != null and mobile != ''">and mobile = #{mobile}</if> |
||||
<if test="code != null and code != ''">and code = #{code}</if> |
||||
<if test="sendtime != null ">and sendTime = #{sendtime}</if> |
||||
<if test="deadtime != null ">and deadTime = #{deadtime}</if> |
||||
<if test="error != null and error != ''">and error = #{error}</if> |
||||
</where> |
||||
</select> |
||||
|
||||
<select id="selectPlatformSmsById" parameterType="Long" resultMap="PlatformSmsResult"> |
||||
<include refid="selectPlatformSmsVo"/> |
||||
where id = #{id} |
||||
</select> |
||||
|
||||
<insert id="insertPlatformSms" parameterType="PlatformSms"> |
||||
insert into platform_sms |
||||
<trim prefix="(" suffix=")" suffixOverrides=","> |
||||
<if test="id != null">id,</if> |
||||
<if test="mobile != null and mobile != ''">mobile,</if> |
||||
<if test="code != null and code != ''">code,</if> |
||||
<if test="sendtime != null">sendTime,</if> |
||||
<if test="deadtime != null">deadTime,</if> |
||||
<if test="error != null and error != ''">error,</if> |
||||
<if test="remark != null and remark != ''">remark,</if> |
||||
</trim> |
||||
<trim prefix="values (" suffix=")" suffixOverrides=","> |
||||
<if test="id != null">#{id},</if> |
||||
<if test="mobile != null and mobile != ''">#{mobile},</if> |
||||
<if test="code != null and code != ''">#{code},</if> |
||||
<if test="sendtime != null">#{sendtime},</if> |
||||
<if test="deadtime != null">#{deadtime},</if> |
||||
<if test="error != null and error != ''">#{error},</if> |
||||
<if test="remark != null and remark != ''">#{remark},</if> |
||||
</trim> |
||||
</insert> |
||||
|
||||
<update id="updatePlatformSms" parameterType="PlatformSms"> |
||||
update platform_sms |
||||
<trim prefix="SET" suffixOverrides=","> |
||||
<if test="mobile != null and mobile != ''">mobile = #{mobile},</if> |
||||
<if test="code != null and code != ''">code = #{code},</if> |
||||
<if test="sendtime != null">sendTime = #{sendtime},</if> |
||||
<if test="deadtime != null">deadTime = #{deadtime},</if> |
||||
<if test="error != null and error != ''">error = #{error},</if> |
||||
<if test="remark != null and remark != ''">remark = #{remark},</if> |
||||
</trim> |
||||
where id = #{id} |
||||
</update> |
||||
|
||||
<delete id="deletePlatformSmsById" parameterType="Long"> |
||||
delete |
||||
from platform_sms |
||||
where id = #{id} |
||||
</delete> |
||||
|
||||
<delete id="deletePlatformSmsByIds" parameterType="String"> |
||||
delete from platform_sms where id in |
||||
<foreach item="id" collection="array" open="(" separator="," close=")"> |
||||
#{id} |
||||
</foreach> |
||||
</delete> |
||||
</mapper> |
Loading…
Reference in new issue