浏览代码

新增读取手机号。模板,签名(数据库fireproof_data表)中数据,下发不带参数的短信定时任务

Administrator 1 年之前
父节点
当前提交
2acdfb4e31

+ 11 - 0
boman-web-core/src/main/java/com/boman/web/core/controller/TaskController.java

@@ -35,6 +35,17 @@ public class TaskController {
         System.out.println(DateUtils.getNowDate() +"定时任务结束");
     }
 
+
+    /**
+     * 数据局2024年春节防火短信下发
+     */
+    @Scheduled(cron = "5 0 0 1 * ?")
+    private void fireproof() {
+        System.out.println(DateUtils.getNowDate() +"开始执行(数据局2024年春节防火短信)下发定时任务");
+        taskService.fireproof();
+        System.out.println(DateUtils.getNowDate() +"定时任务(数据局2024年春节防火短信)结束");
+    }
+
     @GetMapping("/execute")
     private void execute() {
         taskService.execute();

+ 60 - 0
boman-web-core/src/main/java/com/boman/web/core/domain/FireproofData.java

@@ -0,0 +1,60 @@
+package com.boman.web.core.domain;
+
+import com.boman.domain.BaseEntity;
+
+/**
+ * @Author: tjf
+ * @Date: 2024/2/1 16:06
+ * @Describe:
+ */
+public class FireproofData extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /** id */
+    private Long fireproofDataId;
+    private String phone;
+    private String templateCode;
+    private String signName;
+
+    public String getSignName() {
+        return signName;
+    }
+
+    public void setSignName(String signName) {
+        this.signName = signName;
+    }
+
+    public Long getFireproofDataId() {
+        return fireproofDataId;
+    }
+
+    public void setFireproofDataId(Long fireproofDataId) {
+        this.fireproofDataId = fireproofDataId;
+    }
+
+    public String getPhone() {
+        return phone;
+    }
+
+    public void setPhone(String phone) {
+        this.phone = phone;
+    }
+
+    public String getTemplateCode() {
+        return templateCode;
+    }
+
+    public void setTemplateCode(String templateCode) {
+        this.templateCode = templateCode;
+    }
+
+    @Override
+    public String toString() {
+        return "FireproofData{" +
+                "fireproofDataId=" + fireproofDataId +
+                ", phone='" + phone + '\'' +
+                ", templateCode='" + templateCode + '\'' +
+                ", signName='" + signName + '\'' +
+                '}';
+    }
+}

+ 15 - 0
boman-web-core/src/main/java/com/boman/web/core/mapper/FireproofDataMapper.java

@@ -0,0 +1,15 @@
+package com.boman.web.core.mapper;
+
+import com.boman.domain.Fxry;
+import com.boman.web.core.domain.FireproofData;
+
+import java.util.List;
+
+/**
+ * @Author: tjf
+ * @Date: 2024/2/1 16:08
+ * @Describe:
+ */
+public interface FireproofDataMapper {
+    List<FireproofData> selectList();
+}

+ 111 - 15
boman-web-core/src/main/java/com/boman/web/core/service/TaskService.java

@@ -6,7 +6,10 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
 import com.alibaba.nacos.common.http.HttpUtils;
+import com.aliyun.dysmsapi20170525.models.SendBatchSmsRequest;
+import com.aliyun.dysmsapi20170525.models.SendBatchSmsResponse;
 import com.aliyuncs.http.HttpRequest;
+import com.boman.common.core.exception.CustomException;
 import com.boman.common.core.utils.DateUtils;
 import com.boman.common.core.utils.IdUtils;
 import com.boman.common.core.utils.StringUtils;
@@ -20,13 +23,11 @@ import com.boman.domain.dto.AjaxResult;
 import com.boman.domain.dto.FormDataDto;
 import com.boman.system.api.RemoteDeptService;
 import com.boman.system.api.RemoteUserService;
-import com.boman.web.core.domain.AccountingData;
-import com.boman.web.core.domain.BirthRecords;
-import com.boman.web.core.domain.TSampling514;
-import com.boman.web.core.domain.ToQianshanPersonner;
+import com.boman.web.core.domain.*;
 import com.boman.web.core.domain.vo.AccountingDataVo;
 import com.boman.web.core.mapper.AccountingDataMapper;
 import com.boman.web.core.mapper.CzrkMapper;
+import com.boman.web.core.mapper.FireproofDataMapper;
 import com.boman.web.core.mapper.GridInfoMapper;
 import com.boman.web.core.service.accounting.IAccountingDataService;
 import com.boman.web.core.service.birth.BirthRecordsService;
@@ -35,9 +36,7 @@ import com.boman.web.core.service.czrk.CzrkServiceImpl;
 import com.boman.web.core.service.czrk.ICzrkJzdzService;
 import com.boman.web.core.service.ip.IpTimesService;
 import com.boman.web.core.service.toQianShan.ToQianshanPersonnerService;
-import com.boman.web.core.utils.AESUtil;
-import com.boman.web.core.utils.AuthUtils;
-import com.boman.web.core.utils.HttpClientUtils;
+import com.boman.web.core.utils.*;
 import lombok.SneakyThrows;
 import org.apache.commons.lang3.BooleanUtils;
 import org.apache.ibatis.session.ExecutorType;
@@ -107,6 +106,9 @@ public class TaskService {
     @Resource
     private SqlSessionFactory sqlSessionFactory;
 
+    @Resource
+    private FireproofDataMapper fireproofDataMapper;
+
     private static final String tableName = "attendance_table";
 
     /**
@@ -154,6 +156,102 @@ public class TaskService {
         }
     }
 
+    /**
+     * 数据局2024年春节防火短信下发
+     */
+    public void fireproof() {
+        //读取手机号
+        List<FireproofData> fireproofData = fireproofDataMapper.selectList();
+        if (fireproofData != null && fireproofData.size() > 0) {
+            int maxNums = 100; //每次最多发送100条,我们一次批量发100条
+            int times = 0;// 循环几个100  用List的长度 除 100
+            int size = fireproofData.size(); // 数据数量
+            //模板id
+            String templateCode = fireproofData.get(0).getTemplateCode();
+            //签名
+            String SignName = fireproofData.get(0).getSignName();
+            List<String> phoneList = new ArrayList<>();
+            //List<String> templateList = new ArrayList<>();
+            List<String> signNameList = new ArrayList<>();
+            StringBuffer signNameJson;
+            StringBuffer phoneNumberJson;
+            //StringBuffer templateParamJson;
+            //返回提示
+            String backResult = "";
+            if (size < maxNums) {
+                times = 1;
+            } else {
+                times = (size - 1) / maxNums + 1; //为什么要-1 因为如果是200的时候,理论上次数应该是2,而不是3,如果是101,那么次数也是2,这样就保证次数准确。
+            }
+
+            for (int j = 0; j < times; j++) {
+                if (j > 0 && (j * maxNums + 1 > size)) { //边界判定,如果刚好是100条,那么times的值为2,这时候j 为1的时候 101 大于100结束循环,100条以内不生效
+                    break;
+                } else {
+                    phoneNumberJson = new StringBuffer();
+                    signNameJson = new StringBuffer();
+                    //templateParamJson = new StringBuffer();
+                    phoneNumberJson.append("[");
+                    signNameJson.append("[");
+                    //templateParamJson.append("[");
+                    for (int k = j * maxNums; k < size && k < (j + 1) * maxNums; k++) {
+                        // 防止有空行,手机号是必须要有的
+                        String phone = fireproofData.get(k).getPhone();
+                        if (StringUtils.isEmpty(phone)) {
+                            continue;
+                        }
+                        phoneNumberJson.append("\"" + fireproofData.get(k).getPhone() + "\",");
+                        signNameJson.append(SignName+",");
+                        //templateParamJson.append("{\"ticketId\":\"" + smsList.get(k).getTicketId() + "\",\"name\":\"" + smsList.get(k).getName() + "\",\"result\":\"" + smsList.get(k).getResult() + "\"},");
+
+                    }
+                    phoneNumberJson.deleteCharAt(phoneNumberJson.length() - 1);//移除最后一个逗号字符,
+                    signNameJson.deleteCharAt(signNameJson.length() - 1);
+                    //templateParamJson.deleteCharAt(templateParamJson.length() - 1);//移除最后一个逗号字符
+                    phoneNumberJson.append("]");
+                    signNameJson.append("]");
+                    //templateParamJson.append("]");
+                    phoneList.add(phoneNumberJson.toString());
+                    signNameList.add(signNameJson.toString());
+                    //templateList.add(templateParamJson.toString());
+                }
+                //组装请求对象
+                if (times == phoneList.size()) {
+                    for (int i = 0; i < times; i++) {
+                        long startTimeSql = System.currentTimeMillis();
+                        SendBatchSmsRequest sendBatchSmsRequest = new SendBatchSmsRequest();
+                        //组装电话号码
+                        sendBatchSmsRequest.setPhoneNumberJson(phoneList.get(i));
+                        //签名名称
+                        sendBatchSmsRequest.setSignNameJson(signNameList.get(i));
+                        //替换参数
+                        //sendBatchSmsRequest.setTemplateParamJson(templateList.get(i));
+                        //固定的模板名称
+                        sendBatchSmsRequest.setTemplateCode(templateCode);
+                        long endTimeSql = System.currentTimeMillis() - startTimeSql;
+                        System.out.println("线程" + Thread.currentThread().getId() + "执行批量下发短信通知计算:" + (i + 1) + "次,时间" + endTimeSql + "ms");
+                        long startTimeSend = System.currentTimeMillis();
+                        SendBatchSmsResponse sendBatchSmsResponse = SendBatchSmsUtils.sendBatchSms(sendBatchSmsRequest);
+                        long endTimeSend = System.currentTimeMillis() - startTimeSend;
+                        System.out.println("线程" + Thread.currentThread().getId() + "执行批量下发短信通知接口请求:" + (i + 1) + "次,时间" + endTimeSend + "ms");
+                        SendSms sendSms = new SendSms();
+                        if (sendBatchSmsResponse != null) {
+                            String code = sendBatchSmsResponse.getBody().getCode();
+                            if (sendBatchSmsResponse.getBody().getCode() != null && "OK".equals(code)) {
+                                //批量请求发送短信成功
+                                System.out.println("批量短信发送成功:" + phoneList.get(i).split(",").length + "条");
+                                backResult = backResult + "第" + i + "次批量成功  ";
+                            } else {
+                                System.out.println("批量短信发送失败!");
+                                backResult = backResult + "第" + i + "次批量失败  ";
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
     /***
      * 定时执行首页数据任务(每天凌晨1点执行)
      * (cron = "0 0 1 * * ?")
@@ -612,8 +710,8 @@ public class TaskService {
                 //保存
                 for (BirthRecords birthRecords : birthRecordsList) {
                     //判断数据库是否存在数据
-                    int num =  birthRecordsService.selectBirthRecordsByCsyxzmbh(birthRecords.getCsyxzmbh());
-                    if(num<1){
+                    int num = birthRecordsService.selectBirthRecordsByCsyxzmbh(birthRecords.getCsyxzmbh());
+                    if (num < 1) {
                         birthRecordsService.insertBirthRecords(birthRecords);
                     }
                 }
@@ -628,7 +726,7 @@ public class TaskService {
      * 新生儿(手动跑数据,时间间隔一个月)
      *
      */
-    public void getNewbornS(String startTime,String endTime) {
+    public void getNewbornS(String startTime, String endTime) {
 
         String token = getToken();
 
@@ -657,8 +755,8 @@ public class TaskService {
                 //保存
                 for (BirthRecords birthRecords : birthRecordsList) {
                     //判断数据库是否存在数据
-                    int num =  birthRecordsService.selectBirthRecordsByCsyxzmbh(birthRecords.getCsyxzmbh());
-                    if(num<1){
+                    int num = birthRecordsService.selectBirthRecordsByCsyxzmbh(birthRecords.getCsyxzmbh());
+                    if (num < 1) {
                         birthRecordsService.insertBirthRecords(birthRecords);
                     }
                 }
@@ -670,8 +768,6 @@ public class TaskService {
     }
 
 
-
-
     /**
      * 获取政务网token
      */
@@ -1138,7 +1234,7 @@ public class TaskService {
             }
             //先查询库里是否有相同数据
             int num = accountingDataMapper.selectRepeat(accountingData);
-            if(num>0){
+            if (num > 0) {
                 continue;
             }
             int result = mapper.selectById(accountingData);

+ 20 - 0
boman-web-core/src/main/resources/mapper/FireproofDataMapper.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.boman.web.core.mapper.FireproofDataMapper">
+
+
+    <resultMap id="FireproofData" type="com.boman.web.core.domain.FireproofData">
+        <id     property="fireproofDataId"       column="fireproof_data_id"        />
+        <result property="phone"     column="phone"      />
+        <result property="templateCode"      column="template_code"       />
+        <result property="signName"      column="sign_name"       />
+    </resultMap>
+
+
+    <select id="selectList" resultMap="FireproofData">
+               select fireproof_data_id,phone, template_code,sign_name from fireproof_data
+    </select>
+
+</mapper>