| | |
| | | package com.hxzkmonitor.controller; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.hxzkmonitor.mapper.TbDuanxinMapper; |
| | | import com.hxzkmonitor.pojo.TbDuanxin; |
| | | import com.hxzkmonitor.pojo.TbDuanxinlog; |
| | | import com.hxzkmonitor.pojo.TbEquipment; |
| | | import com.hxzkmonitor.pojo.TbSystem; |
| | | import com.hxzkmonitor.service.TbDuanxinlogService; |
| | | import com.hxzkmonitor.service.TbSystemService; |
| | | import com.hxzkmonitor.util.R; |
| | | 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 io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/") |
| | | @Component |
| | | public class TbSystemController { |
| | | |
| | | @Autowired |
| | | com.hxzkmonitor.service.TbSystemService TbSystemService; |
| | | |
| | | |
| | | @Autowired |
| | | TbDuanxinMapper tbDuanxinMapper; |
| | | private String SecretId = "AKIDrjZOI4e6KLZu9FAsSRN8eOwSt52lbMBz"; |
| | | private String SecretKey = "xnRtHUL3YqdMyOLVSBjKkz1pQoxujS4d"; |
| | | @Autowired |
| | | TbDuanxinlogService tbDuanxinlogService; |
| | | Integer st = -1; |
| | | |
| | | @ApiOperation(value = "分页查询", notes = "分页查询") |
| | | @GetMapping("/api/getSystemPage") |
| | |
| | | |
| | | @GetMapping("/api/getSystemOne") |
| | | public R getSystemOne() { |
| | | List<TbSystem> list1 = TbSystemService.list(); |
| | | |
| | | List<TbSystem> list1 = TbSystemService.findsystem(); |
| | | return R.ok(list1); |
| | | } |
| | | |
| | | public static boolean isDifferenceGreaterThan60Seconds(String timeStr) { |
| | | // 定义日期时间格式 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | // 将字符串时间解析为 LocalDateTime 对象 |
| | | LocalDateTime givenTime = LocalDateTime.parse(timeStr, formatter); |
| | | // 获取当前时间 |
| | | LocalDateTime currentTime = LocalDateTime.now(); |
| | | // 计算两个时间之间的差值 |
| | | Duration duration = Duration.between(givenTime, currentTime); |
| | | // 判断差值是否大于 60 秒 |
| | | return duration.getSeconds() > 60; |
| | | } |
| | | |
| | | // @Scheduled(cron = "0 24 15 * * ?") |
| | | @Scheduled(cron = "*/10 * * * * ?")//测试10一次 |
| | | // @Scheduled(cron = "0 0/10 8-22 * * ?")//8点到10点每10分钟执行一次 |
| | | public void sms() throws Exception { |
| | | System.out.println("短信定时器执行============》》》》》》》》》》》》》》》》"); |
| | | //查询数据库中所有的公司数据 |
| | | List<TbSystem> list1 = TbSystemService.list(); |
| | | |
| | | System.out.println(list1.get(0).getAlerttime());//当前时间-获取时间大于60 |
| | | boolean result = isDifferenceGreaterThan60Seconds(list1.get(0).getAlerttime()); |
| | | System.out.println("时间差是否大于 60 秒: " + result); |
| | | //获取当前年月日时间 |
| | | if (result) { |
| | | if (st == 1){ |
| | | try { |
| | | Credential cred = new Credential(this.SecretId, this.SecretKey); |
| | | HttpProfile httpProfile = new HttpProfile(); |
| | | httpProfile.setEndpoint("sms.tencentcloudapi.com"); |
| | | ClientProfile clientProfile = new ClientProfile(); |
| | | clientProfile.setHttpProfile(httpProfile); |
| | | SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile); |
| | | SendSmsRequest req = new SendSmsRequest(); |
| | | // String[] phoneNumberSet1 = new String[]{GsPhone.split("[,,]")[p]}; |
| | | QueryWrapper sms = new QueryWrapper(); |
| | | sms.eq("type", "引擎离线报警"); |
| | | List<TbDuanxin> managerList = tbDuanxinMapper.selectList(sms); |
| | | for (int s = 0; s < managerList.size(); s++) { |
| | | // System.out.println(managerList.get(s).getPhone()); |
| | | // phoneNumberSet1[s] = managerList.get(s).getPhone(); |
| | | String[] phoneNumberSet12 = {managerList.get(s).getPhone()}; |
| | | System.out.println(phoneNumberSet12); |
| | | req.setPhoneNumberSet(phoneNumberSet12); |
| | | |
| | | req.setSmsSdkAppId("1400838975"); |
| | | req.setSignName("北京华星北斗智控"); |
| | | req.setTemplateId("2082020"); |
| | | |
| | | // String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)}; |
| | | String[] templateParamSet1 = new String[]{managerList.get(s).getDuanxin()}; |
| | | req.setTemplateParamSet(templateParamSet1); |
| | | // 返回的resp是一个SendSmsResponse的实例,与请求对象对应 |
| | | SendSmsResponse resp = client.SendSms(req); |
| | | TbDuanxinlog duanxinlog = new TbDuanxinlog(); |
| | | duanxinlog.setName(managerList.get(s).getManager()); |
| | | duanxinlog.setPhone(managerList.get(s).getPhone()); |
| | | |
| | | duanxinlog.setMsg("告警提示:" + managerList.get(s).getDuanxin() + ",请尽快处理,如已处理请忽略该提示信息,如需退订短信可联系管理员删除"); |
| | | tbDuanxinlogService.addorupDuanxinlog(duanxinlog); |
| | | } |
| | | // req.setPhoneNumberSet(phoneNumberSet1); |
| | | // req.setSmsSdkAppId("1400838975"); |
| | | // req.setSignName("北京华星北斗智控"); |
| | | // req.setTemplateId("1908206"); |
| | | // String[] templateParamSet1 = new String[]{cardNum, "150MB"}; |
| | | // req.setTemplateParamSet(templateParamSet1); |
| | | // SendSmsResponse resp = client.SendSms(req); |
| | | // System.out.println(SendSmsResponse.toJsonString(resp)); |
| | | } catch (TencentCloudSDKException var15) { |
| | | System.out.println(var15.toString()); |
| | | } |
| | | st = 0; |
| | | } |
| | | |
| | | |
| | | }else{ |
| | | st=1; |
| | | } |
| | | } |
| | | } |
| | | |