diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/PlatformSmsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/PlatformSmsController.java new file mode 100644 index 0000000..9dff94a --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/PlatformSmsController.java @@ -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()))); + } +} diff --git a/ruoyi-admin/src/main/resources/logback.xml b/ruoyi-admin/src/main/resources/logback.xml index d69a572..b230530 100644 --- a/ruoyi-admin/src/main/resources/logback.xml +++ b/ruoyi-admin/src/main/resources/logback.xml @@ -11,7 +11,7 @@ ${log.pattern} - + ${log.path}/sys-info.log @@ -34,8 +34,8 @@ DENY - - + + ${log.path}/sys-error.log @@ -56,8 +56,8 @@ DENY - - + + ${log.path}/sys-user.log @@ -70,24 +70,26 @@ ${log.pattern} - - - - - - - - - - + + + + + + + - - + - - + + + + + + + + - \ No newline at end of file + diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index f0af627..81fffbd 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -117,6 +117,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() //平台设置 .antMatchers("/platform/config/**").permitAll() + //平台短信发送 + .antMatchers("/platform/public/sms/send").permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated() .and() diff --git a/sql/ttsbg.sql b/sql/ttsbg.sql index 67d17c9..6a92e95 100644 --- a/sql/ttsbg.sql +++ b/sql/ttsbg.sql @@ -1,16 +1,32 @@ -alter table sys_user - add wechat_nick_name varchar(30) null comment '微信昵称'; -alter table sys_user - add balance float null comment '账户余额'; -alter table sys_user - add referrer_id bigint null comment '推荐人ID'; -alter table sys_user - add constraint sys_user_sys_user_user_id_fk - foreign key (referrer_id) references sys_user (user_id); -alter table sys_user - modify user_name varchar(30) null comment '用户账号'; -# 收货地址表 -create table ttsbg.platform_address +CREATE TABLE IF NOT EXISTS `platform_sms` +( + `id` INTEGER NOT NULL auto_increment COMMENT '主键', + `mobile` VARCHAR(255) NOT NULL COMMENT '中国大陆手机号', + `code` VARCHAR(255) NOT NULL COMMENT '6位数字', + `sendTime` datetime COMMENT '未发送或发送失败为空', + `deadTime` datetime COMMENT '未发送或发送失败为空', + `error` VARCHAR(255), + `remark` VARCHAR(255) COMMENT '注册|修改手机号', + PRIMARY KEY (`id`) +) ENGINE = InnoDB COMMENT '短信验证码表'; + +CREATE TABLE IF NOT EXISTS `platform_store_account` +( + `storeId` INTEGER NOT NULL auto_increment, + `mobile` VARCHAR(255) NOT NULL COMMENT '中国大陆手机号', + `password` VARCHAR(255) NOT NULL COMMENT 'HS512 加密', + `status` INTEGER NOT NULL COMMENT '枚举值、详看数据字典编码', + `registerDate` VARCHAR(255) NOT NULL COMMENT 'yyyy-MM-dd', + `nickname` VARCHAR(255) NOT NULL COMMENT '待确定格式', + `sex` INTEGER NOT NULL COMMENT '枚举值、详看数据字典编码', + `avatar` VARCHAR(255) NOT NULL COMMENT '待确定存储格式', + `loginDate` VARCHAR(255) NOT NULL COMMENT 'yyyy-MM-dd', + PRIMARY KEY (`storeId`) +) ENGINE = InnoDB COMMENT '店家账号表'; + + +# TODO:熟悉框架建立的表,后面可能要再调整 +create table platform_address ( id bigint auto_increment primary key, @@ -28,12 +44,12 @@ create table ttsbg.platform_address update_time datetime null, user_id bigint null comment '关联用户', constraint platform_address_sys_user_user_id_fk - foreign key (user_id) references ttsbg.sys_user (user_id) + foreign key (user_id) references sys_user (user_id) ) comment '收货地址表'; - +# TODO:熟悉框架建立的表,后面可能要再调整 create table platform_follower ( id bigint auto_increment @@ -49,4 +65,5 @@ create table platform_follower comment '粉丝表'; - +select max(deadTime) +from platform_sms; diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/domain/PlatformSms.java b/ttsbg-platform/src/main/java/com/ruoyi/platform/domain/PlatformSms.java new file mode 100644 index 0000000..61c6b2e --- /dev/null +++ b/ttsbg-platform/src/main/java/com/ruoyi/platform/domain/PlatformSms.java @@ -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(); + } +} diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/mapper/PlatformSmsMapper.java b/ttsbg-platform/src/main/java/com/ruoyi/platform/mapper/PlatformSmsMapper.java new file mode 100644 index 0000000..f62f354 --- /dev/null +++ b/ttsbg-platform/src/main/java/com/ruoyi/platform/mapper/PlatformSmsMapper.java @@ -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 { + /** + * 查询短信验证码 + * + * @param id 短信验证码主键 + * @return 短信验证码 + */ + public PlatformSms selectPlatformSmsById(Long id); + + /** + * 查询短信验证码列表 + * + * @param platformSms 短信验证码 + * @return 短信验证码集合 + */ + public List 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); +} diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/service/IPlatformSmsService.java b/ttsbg-platform/src/main/java/com/ruoyi/platform/service/IPlatformSmsService.java new file mode 100644 index 0000000..f307c89 --- /dev/null +++ b/ttsbg-platform/src/main/java/com/ruoyi/platform/service/IPlatformSmsService.java @@ -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 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); +} diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/service/impl/PlatformSmsServiceImpl.java b/ttsbg-platform/src/main/java/com/ruoyi/platform/service/impl/PlatformSmsServiceImpl.java new file mode 100644 index 0000000..7e8787d --- /dev/null +++ b/ttsbg-platform/src/main/java/com/ruoyi/platform/service/impl/PlatformSmsServiceImpl.java @@ -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 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 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 "短信验证码发送成功"; + } + } +} diff --git a/ttsbg-platform/src/main/resources/mapper/platform/PlatformSmsMapper.xml b/ttsbg-platform/src/main/resources/mapper/platform/PlatformSmsMapper.xml new file mode 100644 index 0000000..4d9f32b --- /dev/null +++ b/ttsbg-platform/src/main/resources/mapper/platform/PlatformSmsMapper.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + select id, mobile, code, sendTime, deadTime, error, remark + from platform_sms + + + + + + + + insert into platform_sms + + id, + mobile, + code, + sendTime, + deadTime, + error, + remark, + + + #{id}, + #{mobile}, + #{code}, + #{sendtime}, + #{deadtime}, + #{error}, + #{remark}, + + + + + update platform_sms + + mobile = #{mobile}, + code = #{code}, + sendTime = #{sendtime}, + deadTime = #{deadtime}, + error = #{error}, + remark = #{remark}, + + where id = #{id} + + + + delete + from platform_sms + where id = #{id} + + + + delete from platform_sms where id in + + #{id} + + +