维保短信提醒

master
薛宏祥 1 year ago
parent 1a348c5560
commit 6c7fb48b83
  1. 6
      src/main/java/org/springblade/modules/business/contraller/MaintenanceController.java
  2. 66
      src/main/java/org/springblade/modules/business/sms/SmsService.java
  3. 13
      src/main/resources/application-dev.yml

@ -1,5 +1,6 @@
package org.springblade.modules.business.contraller; package org.springblade.modules.business.contraller;
import com.aliyuncs.exceptions.ClientException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@ -21,6 +22,7 @@ import org.springblade.modules.business.pojo.entity.maintenance.MaintenanceTaskD
import org.springblade.modules.business.service.IMaintenancePlanService; import org.springblade.modules.business.service.IMaintenancePlanService;
import org.springblade.modules.business.service.IMaintenanceTaskDetailService; import org.springblade.modules.business.service.IMaintenanceTaskDetailService;
import org.springblade.modules.business.service.IMaintenanceTaskService; import org.springblade.modules.business.service.IMaintenanceTaskService;
import org.springblade.modules.business.sms.SmsService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.LocalDate; import java.time.LocalDate;
@ -120,13 +122,13 @@ public class MaintenanceController extends BladeController {
@PostMapping("/task-supervisor-confirm") @PostMapping("/task-supervisor-confirm")
@Operation(summary = "主管审核并指定维修人员", description = "主管审核并指定维修人员") @Operation(summary = "主管审核并指定维修人员", description = "主管审核并指定维修人员")
public R taskSupervisorConfirm(@RequestBody MaintenanceTask task) { public R taskSupervisorConfirm(@RequestBody MaintenanceTask task) throws ClientException {
MaintenanceTask taskOld = taskService.getById(task.getId()); MaintenanceTask taskOld = taskService.getById(task.getId());
taskOld.setServicemanId(task.getServicemanId()); taskOld.setServicemanId(task.getServicemanId());
taskOld.setServicemanName(task.getServicemanName()); taskOld.setServicemanName(task.getServicemanName());
taskOld.setTaskStatus(MaintenanceStatusEnum.TASK_SUPERVISOR_CONFIRM.getValue()); taskOld.setTaskStatus(MaintenanceStatusEnum.TASK_SUPERVISOR_CONFIRM.getValue());
taskService.updateById(taskOld); taskService.updateById(taskOld);
SmsService.sendSms("13553032083", "阿祥");
return R.success(); return R.success();
} }

@ -0,0 +1,66 @@
package org.springblade.modules.business.sms;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
public class SmsService {
// 阿里云的Access Key ID和Access Key Secret
@Value("${sms.access-key}")
private static String ACCESS_KEY_ID;
@Value("${sms.secret-key}")
private static String ACCESS_KEY_SECRET;
// 短信签名和模板ID
// 短信签名,替换成你在阿里云控制台设置的签名
@Value("${sms.sign-name}")
private static String SIGN_NAME;
@Value("${sms.template-id1}")
private static String TEMPLATE_CODE; // 短信模板ID,替换成你在阿里云控制台设置的模板ID
public static void sendSms(String phoneNumber, String name) throws ClientException {
try {
// 设置发送短信的相关参数
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", ACCESS_KEY_ID, ACCESS_KEY_SECRET);
DefaultAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
// 设置短信模板的参数
Map<String, String> templateParam = new HashMap<>();
templateParam.put("name", name); // 这里的 "code" 是短信模板中的占位符
request.putQueryParameter("PhoneNumbers", phoneNumber); //手机号
request.putQueryParameter("SignName", ""); //申请的签名名称
request.putQueryParameter("TemplateCode", ""); //模板名称
request.putQueryParameter("TemplateParam", JSONObject.toJSONString(templateParam)); //验证码
// 发送短信请求
CommonResponse response = client.getCommonResponse(request);
if (response.getHttpResponse().isSuccess()) {
System.out.println("短信发送成功!");
} else {
System.out.println("短信发送失败.");
}
} catch (ClientException e) {
e.printStackTrace();
System.out.println("短信发送异常: " + e.getMessage());
}
}
}

@ -21,6 +21,7 @@ sms:
name: aliyun name: aliyun
# sms审核通过的短信模板 # sms审核通过的短信模板
template-id: SMS_154950909 template-id: SMS_154950909
template-id1: SMS_476455177
# sms审核通过的短信签名 # sms审核通过的短信签名
sign-name: 阿里云短信测试 sign-name: 阿里云短信测试
# sms提供的accesskey # sms提供的accesskey
@ -29,12 +30,12 @@ sms:
secret-key: PWFmEByyD5YrjMlAyioZZqLtMGxZLu secret-key: PWFmEByyD5YrjMlAyioZZqLtMGxZLu
# 地域,主要由阿里云配置 # 地域,主要由阿里云配置
region-id: cn-hangzhou region-id: cn-hangzhou
aliyun: # aliyun:
accessKeyId: 111 # accessKeyId: 111
accessKeySecret: 111 # accessKeySecret: 111
signName: 111 # signName: 111
isPushSms: true # isPushSms: true
templateCode: 111 # templateCode: 111
#blade配置 #blade配置
#blade: #blade:

Loading…
Cancel
Save