mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 15:51:52 +08:00
完成短信模板的模块
This commit is contained in:
parent
73a2f4d84c
commit
fdc60fbc90
@ -43,6 +43,15 @@ export function getSmsTemplatePage(query) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建短信模板
|
||||||
|
export function sendSms(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/sms-template/send-sms',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 导出短信模板 Excel
|
// 导出短信模板 Excel
|
||||||
export function exportSmsTemplateExcel(query) {
|
export function exportSmsTemplateExcel(query) {
|
||||||
return request({
|
return request({
|
||||||
@ -52,3 +61,4 @@ export function exportSmsTemplateExcel(query) {
|
|||||||
responseType: 'blob'
|
responseType: 'blob'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,8 +81,8 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button size="mini" type="text" icon="el-icon-share" @click="handleUpdate(scope.row)"
|
<el-button size="mini" type="text" icon="el-icon-share" @click="handleSendSms(scope.row)"
|
||||||
v-hasPermi="['system:sms-template:update']">测试</el-button>
|
v-hasPermi="['system:sms-template:send-sms']">测试</el-button>
|
||||||
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
|
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
|
||||||
v-hasPermi="['system:sms-template:update']">修改</el-button>
|
v-hasPermi="['system:sms-template:update']">修改</el-button>
|
||||||
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
|
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
|
||||||
@ -137,11 +137,32 @@
|
|||||||
<el-button @click="cancel">取 消</el-button>
|
<el-button @click="cancel">取 消</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
|
<!-- 对话框(发送短信) -->
|
||||||
|
<el-dialog title="测试发送短信" :visible.sync="sendSmsOpen" width="500px" append-to-body>
|
||||||
|
<el-form ref="sendSmsForm" :model="sendSmsForm" :rules="sendSmsRules" label-width="140px">
|
||||||
|
<el-form-item label="模板内容" prop="content">
|
||||||
|
<el-input v-model="sendSmsForm.content" type="textarea" placeholder="请输入模板内容" readonly />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="手机号" prop="mobile">
|
||||||
|
<el-input v-model="sendSmsForm.mobile" placeholder="请输入手机号" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item v-for="param in sendSmsForm.params" :label="'参数 {' + param + '}'" :prop="'templateParams.' + param">
|
||||||
|
<el-input v-model="sendSmsForm.templateParams[param]" :placeholder="'请输入 ' + param + ' 参数'" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<div slot="footer" class="dialog-footer">
|
||||||
|
<el-button type="primary" @click="submitSendSmsForm">确 定</el-button>
|
||||||
|
<el-button @click="cancelSendSms">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { createSmsTemplate, updateSmsTemplate, deleteSmsTemplate, getSmsTemplate, getSmsTemplatePage, exportSmsTemplateExcel } from "@/api/system/sms/smsTemplate";
|
import { createSmsTemplate, updateSmsTemplate, deleteSmsTemplate, getSmsTemplate, getSmsTemplatePage,
|
||||||
|
exportSmsTemplateExcel, sendSms } from "@/api/system/sms/smsTemplate";
|
||||||
import { getSimpleSmsChannels } from "@/api/system/sms/smsChannel";
|
import { getSimpleSmsChannels } from "@/api/system/sms/smsChannel";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -186,6 +207,16 @@ export default {
|
|||||||
},
|
},
|
||||||
// 短信渠道
|
// 短信渠道
|
||||||
channelOptions: [],
|
channelOptions: [],
|
||||||
|
// 发送短信
|
||||||
|
sendSmsOpen: false,
|
||||||
|
sendSmsForm: {
|
||||||
|
params: [], // 模板的参数列表
|
||||||
|
},
|
||||||
|
sendSmsRules: {
|
||||||
|
mobile: [{ required: true, message: "手机不能为空", trigger: "blur" }],
|
||||||
|
templateCode: [{ required: true, message: "手机不能为空", trigger: "blur" }],
|
||||||
|
templateParams: { }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
@ -311,6 +342,55 @@ export default {
|
|||||||
this.downloadExcel(response, '短信模板.xls');
|
this.downloadExcel(response, '短信模板.xls');
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
/** 发送短息按钮 */
|
||||||
|
handleSendSms(row) {
|
||||||
|
this.resetSendSms(row);
|
||||||
|
// 设置参数
|
||||||
|
this.sendSmsForm.content = row.content;
|
||||||
|
this.sendSmsForm.params = row.params;
|
||||||
|
this.sendSmsForm.templateCode = row.code;
|
||||||
|
this.sendSmsForm.templateParams = row.params.reduce(function(obj, item) {
|
||||||
|
obj[item] = undefined;
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
// 根据 row 重置 rules
|
||||||
|
this.sendSmsRules.templateParams = row.params.reduce(function(obj, item) {
|
||||||
|
obj[item] = { required: true, message: '参数 ' + item + " 不能为空", trigger: "change" };
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
// 设置打开
|
||||||
|
this.sendSmsOpen = true;
|
||||||
|
},
|
||||||
|
/** 重置发送短信的表单 */
|
||||||
|
resetSendSms() {
|
||||||
|
// 根据 row 重置表单
|
||||||
|
this.sendSmsForm = {
|
||||||
|
content: undefined,
|
||||||
|
params: undefined,
|
||||||
|
mobile: undefined,
|
||||||
|
templateCode: undefined,
|
||||||
|
templateParams: {}
|
||||||
|
};
|
||||||
|
this.resetForm("sendSmsForm");
|
||||||
|
},
|
||||||
|
/** 取消发送短信 */
|
||||||
|
cancelSendSms() {
|
||||||
|
this.sendSmsOpen = false;
|
||||||
|
this.resetSendSms();
|
||||||
|
},
|
||||||
|
/** 提交按钮 */
|
||||||
|
submitSendSmsForm() {
|
||||||
|
this.$refs["sendSmsForm"].validate(valid => {
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 添加的提交
|
||||||
|
sendSms(this.sendSmsForm).then(response => {
|
||||||
|
this.msgSuccess("提交发送成功!发送结果,见发送日志编号:" + response.data);
|
||||||
|
this.sendSmsOpen = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
/** 格式化短信渠道 */
|
/** 格式化短信渠道 */
|
||||||
formatChannelSignature(channelId) {
|
formatChannelSignature(channelId) {
|
||||||
for (const channel of this.channelOptions) {
|
for (const channel of this.channelOptions) {
|
||||||
|
@ -7,6 +7,7 @@ import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.Operate
|
|||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.*;
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.template.*;
|
||||||
import cn.iocoder.dashboard.modules.system.convert.sms.SysSmsTemplateConvert;
|
import cn.iocoder.dashboard.modules.system.convert.sms.SysSmsTemplateConvert;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO;
|
import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.service.sms.SysSmsService;
|
||||||
import cn.iocoder.dashboard.modules.system.service.sms.SysSmsTemplateService;
|
import cn.iocoder.dashboard.modules.system.service.sms.SysSmsTemplateService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
@ -30,6 +31,8 @@ public class SysSmsTemplateController {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SysSmsTemplateService smsTemplateService;
|
private SysSmsTemplateService smsTemplateService;
|
||||||
|
@Resource
|
||||||
|
private SysSmsService smsService;
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@ApiOperation("创建短信模板")
|
@ApiOperation("创建短信模板")
|
||||||
@ -85,10 +88,11 @@ public class SysSmsTemplateController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/send-sms")
|
@PostMapping("/send-sms")
|
||||||
@ApiOperation("导出短信模板 Excel")
|
@ApiOperation("发送短信")
|
||||||
@PreAuthorize("@ss.hasPermission('system:sms-template:send-sms')")
|
@PreAuthorize("@ss.hasPermission('system:sms-template:send-sms')")
|
||||||
public CommonResult<Boolean> sendSms(@Valid @RequestBody SysSmsTemplateSendReqVO sendReqVO) {
|
public CommonResult<Long> sendSms(@Valid @RequestBody SysSmsTemplateSendReqVO sendReqVO) {
|
||||||
return success(true);
|
return success(smsService.sendSingleSms(sendReqVO.getMobile(), null, null,
|
||||||
|
sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@ApiModel("短信模板 Response VO")
|
@ApiModel("短信模板 Response VO")
|
||||||
@Data
|
@Data
|
||||||
@ -20,6 +21,9 @@ public class SysSmsTemplateRespVO extends SysSmsTemplateBaseVO {
|
|||||||
@ApiModelProperty(value = "短信渠道编码", required = true, example = "ALIYUN")
|
@ApiModelProperty(value = "短信渠道编码", required = true, example = "ALIYUN")
|
||||||
private String channelCode;
|
private String channelCode;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "参数数组", example = "name,code")
|
||||||
|
private List<String> params;
|
||||||
|
|
||||||
@ApiModelProperty(value = "创建时间", required = true)
|
@ApiModelProperty(value = "创建时间", required = true)
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
|
@ -11,11 +11,15 @@ import java.util.Map;
|
|||||||
@Data
|
@Data
|
||||||
public class SysSmsTemplateSendReqVO {
|
public class SysSmsTemplateSendReqVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
|
||||||
|
@NotNull(message = "手机号不能为空")
|
||||||
|
private String mobile;
|
||||||
|
|
||||||
@ApiModelProperty(value = "模板编码", required = true, example = "test_01")
|
@ApiModelProperty(value = "模板编码", required = true, example = "test_01")
|
||||||
@NotNull(message = "模板编码不能为空")
|
@NotNull(message = "模板编码不能为空")
|
||||||
private String code;
|
private String templateCode;
|
||||||
|
|
||||||
@ApiModelProperty(value = "模板参数")
|
@ApiModelProperty(value = "模板参数")
|
||||||
private Map<String, Object> params;
|
private Map<String, Object> templateParams;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public interface SysSmsService {
|
public interface SysSmsService {
|
||||||
|
|
||||||
void sendSingleSms(String mobile, Long userId, Integer userType,
|
Long sendSingleSms(String mobile, Long userId, Integer userType,
|
||||||
String templateCode, Map<String, Object> templateParams);
|
String templateCode, Map<String, Object> templateParams);
|
||||||
|
|
||||||
void sendBatchSms(List<String> mobiles, List<Long> userIds, Integer userType,
|
void sendBatchSms(List<String> mobiles, List<Long> userIds, Integer userType,
|
||||||
|
@ -54,7 +54,7 @@ public class SysSmsServiceImpl implements SysSmsService {
|
|||||||
private SysUserService userService;
|
private SysUserService userService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendSingleSms(String mobile, Long userId, Integer userType,
|
public Long sendSingleSms(String mobile, Long userId, Integer userType,
|
||||||
String templateCode, Map<String, Object> templateParams) {
|
String templateCode, Map<String, Object> templateParams) {
|
||||||
// 校验短信模板是否合法
|
// 校验短信模板是否合法
|
||||||
SysSmsTemplateDO template = this.checkSmsTemplateValid(templateCode);
|
SysSmsTemplateDO template = this.checkSmsTemplateValid(templateCode);
|
||||||
@ -67,12 +67,12 @@ public class SysSmsServiceImpl implements SysSmsService {
|
|||||||
Long sendLogId = smsLogService.createSmsLog(mobile, userId, userType, isSend, template, content, templateParams);
|
Long sendLogId = smsLogService.createSmsLog(mobile, userId, userType, isSend, template, content, templateParams);
|
||||||
|
|
||||||
// 发送 MQ 消息,异步执行发送短信
|
// 发送 MQ 消息,异步执行发送短信
|
||||||
if (!isSend) {
|
if (isSend) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<KeyValue<String, Object>> newTemplateParams = this.buildTemplateParams(template, templateParams);
|
List<KeyValue<String, Object>> newTemplateParams = this.buildTemplateParams(template, templateParams);
|
||||||
smsProducer.sendSmsSendMessage(sendLogId, mobile, template.getChannelId(), template.getApiTemplateId(), newTemplateParams);
|
smsProducer.sendSmsSendMessage(sendLogId, mobile, template.getChannelId(), template.getApiTemplateId(), newTemplateParams);
|
||||||
}
|
}
|
||||||
|
return sendLogId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendBatchSms(List<String> mobiles, List<Long> userIds, Integer userType,
|
public void sendBatchSms(List<String> mobiles, List<Long> userIds, Integer userType,
|
||||||
|
Loading…
Reference in New Issue
Block a user