fixconflict
This commit is contained in:
commit
3753a0695a
|
|
@ -31,4 +31,8 @@ public class DevInfoVo extends DevInfo {
|
||||||
private Long searchNum;
|
private Long searchNum;
|
||||||
private String examinationPdf;
|
private String examinationPdf;
|
||||||
private String insurancePdf;
|
private String insurancePdf;
|
||||||
|
/** 1上架,2下架*/
|
||||||
|
private String type;
|
||||||
|
/**上下架id*/
|
||||||
|
private int upId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import com.bonus.zlpt.common.security.annotation.RequiresPermissions;
|
||||||
|
|
||||||
import com.bonus.zlpt.equip.api.domain.UpOff;
|
import com.bonus.zlpt.equip.api.domain.UpOff;
|
||||||
import com.bonus.zlpt.equip.api.domain.dto.UpOffDto;
|
import com.bonus.zlpt.equip.api.domain.dto.UpOffDto;
|
||||||
|
import com.bonus.zlpt.equip.api.domain.vo.DevInfoVo;
|
||||||
import com.bonus.zlpt.equip.api.domain.vo.MaDevInfoVo;
|
import com.bonus.zlpt.equip.api.domain.vo.MaDevInfoVo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
@ -107,12 +108,15 @@ public class UpOffController extends BaseController
|
||||||
* 新增设备上下架管理
|
* 新增设备上下架管理
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("equip:off:add")
|
// @RequiresPermissions("equip:off:add")
|
||||||
@Log(title = "设备上下架管理", businessType = BusinessType.INSERT)
|
@Log(title = "设备上下架管理", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@RequestBody UpOff upOff)
|
public AjaxResult add(@RequestBody List<UpOff> upOffList)
|
||||||
{
|
{
|
||||||
return toAjax(upOffService.insertUpOff(upOff));
|
if (upOffList.size()==0){
|
||||||
|
return warn("传入参数为空!");
|
||||||
|
}
|
||||||
|
return toAjax(upOffService.insertUpOff(upOffList));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -122,27 +126,37 @@ public class UpOffController extends BaseController
|
||||||
//@RequiresPermissions("equip:off:edit")
|
//@RequiresPermissions("equip:off:edit")
|
||||||
@Log(title = "设备上下架管理", businessType = BusinessType.UPDATE)
|
@Log(title = "设备上下架管理", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@RequestBody List<UpOff> upOffList)
|
public AjaxResult edit(@RequestBody UpOff upOff)
|
||||||
{
|
{
|
||||||
if (upOffList.size()==0){
|
return toAjax(upOffService.updateUpOff(upOff));
|
||||||
return warn("传入参数为空!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return toAjax(upOffService.updateUpOff(upOffList));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除设备上下架管理
|
* 删除设备上下架管理
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("equip:off:remove")
|
// @RequiresPermissions("equip:off:remove")
|
||||||
@Log(title = "设备上下架管理", businessType = BusinessType.DELETE)
|
@Log(title = "设备上下架管理", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{ids}")
|
@PostMapping("/remove")
|
||||||
public AjaxResult remove(@PathVariable Long[] ids)
|
public AjaxResult remove(@RequestBody Long[] ids)
|
||||||
{
|
{
|
||||||
return toAjax(upOffService.deleteUpOffByIds(ids));
|
return toAjax(upOffService.deleteUpOffByIds(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品批量上下架
|
||||||
|
* @param upOffList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Log(title = "设备上下架管理", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping("/upOffList")
|
||||||
|
public AjaxResult upOffList(@RequestBody List<UpOff> upOffList)
|
||||||
|
{
|
||||||
|
if (upOffList.size()==0){
|
||||||
|
return warn("传入参数为空!");
|
||||||
|
}
|
||||||
|
return toAjax(upOffService.UpdateUpOffLIst(upOffList));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,4 +82,6 @@ public interface UpOffMapper
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<MaDevInfoVo> selectList(UpOffDto upOffDto);
|
List<MaDevInfoVo> selectList(UpOffDto upOffDto);
|
||||||
|
|
||||||
|
void UpdateUpOffLIst(UpOff upOff);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,21 +42,21 @@ public interface IUpOffService
|
||||||
* 新增设备上下架管理
|
* 新增设备上下架管理
|
||||||
|
|
||||||
*
|
*
|
||||||
* @param upOff 设备上下架管理
|
* @param upOffList 设备上下架管理
|
||||||
|
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int insertUpOff(UpOff upOff);
|
public int insertUpOff(List<UpOff> upOffList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改设备上下架管理
|
* 修改设备上下架管理
|
||||||
|
|
||||||
*
|
*
|
||||||
* @param upOffList 设备上下架管理
|
* @param upOff 设备上下架管理
|
||||||
|
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int updateUpOff(List<UpOff> upOffList);
|
public int updateUpOff(UpOff upOff);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除设备上下架管理
|
* 批量删除设备上下架管理
|
||||||
|
|
@ -86,4 +86,6 @@ public interface IUpOffService
|
||||||
List<MaDevInfoVo> selectList(UpOffDto upOffDto);
|
List<MaDevInfoVo> selectList(UpOffDto upOffDto);
|
||||||
|
|
||||||
List<MaDevInfoVo> selectInfo(List<Long> ids);
|
List<MaDevInfoVo> selectInfo(List<Long> ids);
|
||||||
|
|
||||||
|
int UpdateUpOffLIst(List<UpOff> upOffList);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
import com.bonus.zlpt.common.security.utils.SecurityUtils;
|
||||||
import com.bonus.zlpt.equip.api.domain.SysFileInfo;
|
import com.bonus.zlpt.equip.api.domain.SysFileInfo;
|
||||||
import com.bonus.zlpt.equip.api.domain.TypeInfo;
|
import com.bonus.zlpt.equip.api.domain.TypeInfo;
|
||||||
import com.bonus.zlpt.equip.api.domain.UpOff;
|
import com.bonus.zlpt.equip.api.domain.UpOff;
|
||||||
|
|
@ -17,6 +18,8 @@ import org.springframework.stereotype.Service;
|
||||||
import com.bonus.zlpt.equip.mapper.UpOffMapper;
|
import com.bonus.zlpt.equip.mapper.UpOffMapper;
|
||||||
import com.bonus.zlpt.equip.service.IUpOffService;
|
import com.bonus.zlpt.equip.service.IUpOffService;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备上下架管理
|
* 设备上下架管理
|
||||||
Service业务层处理
|
Service业务层处理
|
||||||
|
|
@ -27,16 +30,13 @@ Service业务层处理
|
||||||
@Service
|
@Service
|
||||||
public class UpOffServiceImpl implements IUpOffService
|
public class UpOffServiceImpl implements IUpOffService
|
||||||
{
|
{
|
||||||
@Autowired
|
@Resource
|
||||||
private UpOffMapper upOffMapper;
|
private UpOffMapper upOffMapper;
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private TypeInfoMapper typeInfoMapper;
|
private TypeInfoMapper typeInfoMapper;
|
||||||
|
|
||||||
// @Autowired
|
@Resource
|
||||||
// private FileInfoMapper fileInfoMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SysFileInfoMapper sysFileInfoMapper;
|
private SysFileInfoMapper sysFileInfoMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -73,31 +73,35 @@ public class UpOffServiceImpl implements IUpOffService
|
||||||
* 新增设备上下架管理
|
* 新增设备上下架管理
|
||||||
|
|
||||||
*
|
*
|
||||||
* @param upOff 设备上下架管理
|
* @param upOffList 设备上下架管理
|
||||||
|
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int insertUpOff(UpOff upOff)
|
public int insertUpOff(List<UpOff> upOffList)
|
||||||
{
|
{
|
||||||
return upOffMapper.insertUpOff(upOff);
|
String name = SecurityUtils.getUsername();
|
||||||
|
|
||||||
|
for (int i = 0; i < upOffList.size(); i++) {
|
||||||
|
UpOff UpOff = upOffList.get(i);
|
||||||
|
UpOff.setApplyUser(name);
|
||||||
|
upOffMapper.insertUpOff(UpOff);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改设备上下架管理
|
* 修改设备上下架管理
|
||||||
|
|
||||||
*
|
*
|
||||||
* @param upOffList 设备上下架管理
|
* @param upOff 设备上下架管理
|
||||||
|
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int updateUpOff(List<UpOff> upOffList)
|
public int updateUpOff(UpOff upOff)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < upOffList.size(); i++) {
|
return upOffMapper.updateUpOff(upOff);
|
||||||
upOffMapper.updateUpOff(upOffList.get(i));
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -180,4 +184,14 @@ public class UpOffServiceImpl implements IUpOffService
|
||||||
return devInfoVos;
|
return devInfoVos;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int UpdateUpOffLIst(List<UpOff> upOffList) {
|
||||||
|
|
||||||
|
for (int i = 0; i < upOffList.size(); i++) {
|
||||||
|
UpOff UpOff = upOffList.get(i);
|
||||||
|
upOffMapper.UpdateUpOffLIst(UpOff);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectDevInfoList" parameterType="com.bonus.zlpt.equip.api.domain.vo.DevInfoVo" resultType="com.bonus.zlpt.equip.api.domain.vo.DevInfoVo">
|
<select id="selectDevInfoList" parameterType="com.bonus.zlpt.equip.api.domain.vo.DevInfoVo" resultType="com.bonus.zlpt.equip.api.domain.vo.DevInfoVo">
|
||||||
select d.*,t.type_name,c.company_name
|
select d.*,t.type_name,c.company_name ,u.type, u.id as up_id
|
||||||
from ma_dev_info d
|
from ma_dev_info d
|
||||||
left join ma_type_info t on d.type_id = t.type_id
|
left join ma_type_info t on d.type_id = t.type_id
|
||||||
left join bm_company_info c on d.own_co = c.company_id
|
left join bm_company_info c on d.own_co = c.company_id
|
||||||
|
left join ma_up_off u on d.ma_id = u.ma_id
|
||||||
<where>
|
<where>
|
||||||
<if test="maId != null "> and d.ma_id = #{maId}</if>
|
<if test="maId != null "> and d.ma_id = #{maId}</if>
|
||||||
<if test="code != null and code != ''"> and d.code = #{code}</if>
|
<if test="code != null and code != ''"> and d.code = #{code}</if>
|
||||||
|
|
|
||||||
|
|
@ -60,24 +60,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<if test="id != null">id,</if>
|
<if test="id != null">id,</if>
|
||||||
<if test="maId != null">ma_id,</if>
|
<if test="maId != null">ma_id,</if>
|
||||||
<if test="applyTime != null">apply_time,</if>
|
|
||||||
<if test="applyUser != null">apply_user,</if>
|
<if test="applyUser != null">apply_user,</if>
|
||||||
<if test="applyCompany != null">apply_company,</if>
|
<if test="applyCompany != null">apply_company,</if>
|
||||||
<if test="type != null">type,</if>
|
<if test="type != null">type,</if>
|
||||||
<if test="auditUser != null">audit_user,</if>
|
<if test="auditUser != null">audit_user,</if>
|
||||||
<if test="auditTime != null">audit_time,</if>
|
<if test="auditTime != null">audit_time,</if>
|
||||||
<if test="status != null">status,</if>
|
<if test="status != null">status,</if>
|
||||||
|
apply_time
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="id != null">#{id},</if>
|
<if test="id != null">#{id},</if>
|
||||||
<if test="maId != null">#{maId},</if>
|
<if test="maId != null">#{maId},</if>
|
||||||
<if test="applyTime != null">#{applyTime},</if>
|
|
||||||
<if test="applyUser != null">#{applyUser},</if>
|
<if test="applyUser != null">#{applyUser},</if>
|
||||||
<if test="applyCompany != null">#{applyCompany},</if>
|
<if test="applyCompany != null">#{applyCompany},</if>
|
||||||
<if test="type != null">#{type},</if>
|
<if test="type != null">#{type},</if>
|
||||||
<if test="auditUser != null">#{auditUser},</if>
|
<if test="auditUser != null">#{auditUser},</if>
|
||||||
<if test="auditTime != null">#{auditTime},</if>
|
<if test="auditTime != null">#{auditTime},</if>
|
||||||
<if test="status != null">#{status},</if>
|
<if test="status != null">#{status},</if>
|
||||||
|
sysdate()
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
|
@ -106,4 +106,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<update id="UpdateUpOffLIst" parameterType="com.bonus.zlpt.equip.api.domain.UpOff">
|
||||||
|
update ma_up_off set type = #{type} where ma_id = #{maId}
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
server:
|
server:
|
||||||
port: 9301
|
port: 9301
|
||||||
|
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,13 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- 腾讯云短信 SMS -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.tencentcloudapi</groupId>
|
||||||
|
<artifactId>tencentcloud-sdk-java</artifactId>
|
||||||
|
<version>3.1.918</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos -->
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
package com.bonus.zlpt.system.config;
|
||||||
|
|
||||||
|
import com.tencentcloudapi.common.Credential;
|
||||||
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
||||||
|
import com.tencentcloudapi.common.profile.ClientProfile;
|
||||||
|
import com.tencentcloudapi.common.profile.HttpProfile;
|
||||||
|
import com.tencentcloudapi.sms.v20210111.SmsClient;
|
||||||
|
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
|
||||||
|
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description: 腾讯云短信配置
|
||||||
|
*
|
||||||
|
* @Author 阮世耀
|
||||||
|
* @Create 2023/12/6 14:56
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@ToString
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class SmsComponent {
|
||||||
|
|
||||||
|
@Value("${sms.sdkAppId}") // 注入参数值
|
||||||
|
private String sdkAppId;
|
||||||
|
|
||||||
|
@Value("${sms.secretId}")
|
||||||
|
private String secretId;
|
||||||
|
|
||||||
|
@Value("${sms.secretKey}")
|
||||||
|
private String secretKey;
|
||||||
|
|
||||||
|
@Value("${sms.signName}")
|
||||||
|
private String signName;
|
||||||
|
|
||||||
|
@Value("${sms.templateCodeId}")
|
||||||
|
private String templateCodeId;
|
||||||
|
|
||||||
|
@Value("${sms.timeout}")
|
||||||
|
private Integer timeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取SmsClient客户端
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public SmsClient getClient() {
|
||||||
|
|
||||||
|
// 实例化认证对象,入参需要传入腾讯云账户secretId,secretKey
|
||||||
|
Credential cred = new Credential(secretId, secretKey);
|
||||||
|
// 实例化http选项
|
||||||
|
HttpProfile httpProfile = new HttpProfile();
|
||||||
|
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||||
|
// 实例化client选项
|
||||||
|
ClientProfile clientProfile = new ClientProfile();
|
||||||
|
clientProfile.setHttpProfile(httpProfile);
|
||||||
|
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||||
|
return new SmsClient(cred, "ap-beijing", clientProfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取req请求 2个参数,可根据具体情况改变
|
||||||
|
*
|
||||||
|
* @param phone 手机号
|
||||||
|
* @param code 参数1,这里是验证码,param2为参数2这里为分钟
|
||||||
|
* @param templateId 短信模板id
|
||||||
|
* @return 请求参数对象
|
||||||
|
*/
|
||||||
|
public SendSmsRequest getReqTwo(String phone, String code, String param2, String templateId) {
|
||||||
|
SendSmsRequest req = new SendSmsRequest();
|
||||||
|
String[] phoneNumberSet = {"+86" + phone};
|
||||||
|
req.setSmsSdkAppId(sdkAppId); // 设置参数
|
||||||
|
req.setPhoneNumberSet(phoneNumberSet);
|
||||||
|
req.setSignName(signName);
|
||||||
|
req.setTemplateId(templateId);
|
||||||
|
//模板内容的参数有几个就设置几个,我这里是两个
|
||||||
|
String[] templateParamSetOne = {code};
|
||||||
|
String[] templateParamSetTwo = {code,param2};
|
||||||
|
req.setTemplateParamSet(templateParamSetOne);
|
||||||
|
return req; // 返回请求参数内容
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送验证码
|
||||||
|
*
|
||||||
|
* @param phone 手机号码
|
||||||
|
* @param code 验证码
|
||||||
|
* @param param2 分钟参数(可为空)
|
||||||
|
*/
|
||||||
|
public void sendCode(String phone, String code, String param2) {
|
||||||
|
// 返回的resp是一个SendSmsResponse的实例,与请求对象对应
|
||||||
|
SendSmsResponse resp;
|
||||||
|
try {
|
||||||
|
resp = getClient().SendSms(getReqTwo(phone, code,param2 ,templateCodeId)); // 模板id是自己设置好的
|
||||||
|
log.info(SendSmsResponse.toJsonString(resp)); // 把返回信息输入到日志中
|
||||||
|
} catch (TencentCloudSDKException e) {
|
||||||
|
log.error("腾讯云短信发送失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.bonus.zlpt.system.controller;
|
||||||
|
|
||||||
|
import com.bonus.zlpt.common.core.web.controller.BaseController;
|
||||||
|
import com.bonus.zlpt.common.core.web.domain.AjaxResult;
|
||||||
|
import com.bonus.zlpt.system.service.ISmsService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description: 短信发送接口
|
||||||
|
*
|
||||||
|
* @Author 阮世耀
|
||||||
|
* @Create 2023/12/6 15:13
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/sms")
|
||||||
|
public class SmsSendController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISmsService smsService;
|
||||||
|
|
||||||
|
@RequestMapping("/send")
|
||||||
|
public AjaxResult send(@RequestParam("phone") String phone){
|
||||||
|
try {
|
||||||
|
String msg = smsService.sendCode(phone, 5 * 60 * 1000);
|
||||||
|
return success(msg);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.bonus.zlpt.system.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description: 短信发送接口
|
||||||
|
*
|
||||||
|
* @Author 阮世耀
|
||||||
|
* @Create 2023/12/6 15:04
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
public interface ISmsService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param phone 给手机号发送验证码
|
||||||
|
* @param leastTime 短信有效时间
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public String sendCode( String phone,int leastTime);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验验证码
|
||||||
|
*/
|
||||||
|
boolean checkCode(String phone, String code);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,87 @@
|
||||||
|
package com.bonus.zlpt.system.service.impl;
|
||||||
|
|
||||||
|
import com.bonus.zlpt.common.core.exception.ServiceException;
|
||||||
|
import com.bonus.zlpt.system.config.SmsComponent;
|
||||||
|
import com.bonus.zlpt.system.service.ISmsService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description: 短信发送接口实现
|
||||||
|
*
|
||||||
|
* @Author 阮世耀
|
||||||
|
* @Create 2023/12/6 15:05
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ISmsServiceImpl implements ISmsService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
SmsComponent smsComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param phone 给手机号发送验证码
|
||||||
|
* @param leastTime 短信有效时间
|
||||||
|
* @return 消息
|
||||||
|
* @throws ServiceException 异常信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String sendCode(String phone, int leastTime) {
|
||||||
|
if (phone == null || phone.isEmpty()) {
|
||||||
|
throw new ServiceException("手机号为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断是否已经发送过 (需要从Redis缓存中获取记录来进行判断,此处暂时去除)
|
||||||
|
// if (!StringUtils.isEmpty(redisCode)) {
|
||||||
|
// long time = Long.parseLong(redisCode.split("_")[1]);
|
||||||
|
// if (System.currentTimeMillis() - time < leastTime) {
|
||||||
|
// throw new ServiceException("发送频率过高");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
String code = getSixBitCode(); // 生成新的验证码
|
||||||
|
//存储 phone -> code到Redis中
|
||||||
|
// redisCache.setCacheObject(Constants.HEAD + phone, code + "_" + System.currentTimeMillis(), smsComponent.getTimeout(), TimeUnit.MINUTES);
|
||||||
|
int minute = leastTime / 60 / 1000; //分钟
|
||||||
|
smsComponent.sendCode(phone, code, Integer.toString(minute));
|
||||||
|
return "已发送验证码 " + phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机生成6位验证码
|
||||||
|
*/
|
||||||
|
private String getSixBitCode() {
|
||||||
|
//随机数
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
Random rand = new Random();
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
sb.append(rand.nextInt(10));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断验证码是否存在Redis中
|
||||||
|
*
|
||||||
|
* @param phone 手机号码
|
||||||
|
* @param code 验证码
|
||||||
|
* @return 校验结果
|
||||||
|
* @throws ServiceException 异常信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean checkCode(String phone, String code) {
|
||||||
|
// String redisCode = redisCache.getCacheObject(Constants.HEAD + phone);
|
||||||
|
// if (StringUtils.isEmpty(redisCode)) {
|
||||||
|
// throw new ServiceException("验证码失效");
|
||||||
|
// }
|
||||||
|
// if (!StringUtils.equals(redisCode.split("_")[0], code)) {
|
||||||
|
// throw new ServiceException("验证码错误");
|
||||||
|
// } else {
|
||||||
|
// redisCache.deleteObject(Constants.HEAD + phone);
|
||||||
|
return true;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,19 @@
|
||||||
server:
|
server:
|
||||||
port: 9201
|
port: 9201
|
||||||
|
|
||||||
|
# 腾讯云短信
|
||||||
|
tencent:
|
||||||
|
sms:
|
||||||
|
# 腾讯云账户API访问密钥
|
||||||
|
secretId: AKIDbF1pTyU6iHn6EH9uc9O6kJgrrfI2rV04
|
||||||
|
keysecret: zGPRJ9z68AGZVMAoHYyDFDAxhR2Xs0Qf
|
||||||
|
# 短信应用ID
|
||||||
|
smsSdkAppId: 564559
|
||||||
|
# 短信签名内容
|
||||||
|
signName: 作业智慧管控系统小程序
|
||||||
|
# 正文模板ID
|
||||||
|
templateId: 2010811
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue