|
@@ -5,16 +5,13 @@ import java.util.List;
|
|
|
|
|
|
import com.aliyun.dysmsapi20170525.models.SendBatchSmsRequest;
|
|
|
import com.aliyun.dysmsapi20170525.models.SendBatchSmsResponse;
|
|
|
-import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse;
|
|
|
-import com.aliyuncs.exceptions.ClientException;
|
|
|
import com.boman.common.core.exception.CustomException;
|
|
|
import com.boman.common.core.utils.DateUtils;
|
|
|
import com.boman.common.core.utils.StringUtils;
|
|
|
-import com.boman.domain.dto.AjaxResult;
|
|
|
+import com.boman.web.core.Thread.BranchThreadUtils;
|
|
|
import com.boman.web.core.service.sendSms.ISendSmsService;
|
|
|
+import com.boman.web.core.Thread.SmsThread;
|
|
|
import com.boman.web.core.utils.SendBatchSmsUtils;
|
|
|
-import com.boman.web.core.utils.SendSmsUtils;
|
|
|
-import org.checkerframework.checker.units.qual.A;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.boman.web.core.mapper.SendSmsMapper;
|
|
@@ -35,6 +32,7 @@ public class SendSmsServiceImpl implements ISendSmsService {
|
|
|
* todo 短信模板名称,需要替换
|
|
|
*/
|
|
|
static final String TEMPLATE_CODE = "SMS_245245018";
|
|
|
+ static final String TEMPLATE_CODE_NOTICE = "SMS_245705093";
|
|
|
|
|
|
/**
|
|
|
* 查询中考下发短信日志
|
|
@@ -118,7 +116,7 @@ public class SendSmsServiceImpl implements ISendSmsService {
|
|
|
if (StringUtils.isNull(smsList) || smsList.size() == 0) {
|
|
|
throw new CustomException("导入数据不能为空!");
|
|
|
}
|
|
|
- int maxNums = 2; //每次最多发送100条,我们一次批量发100条
|
|
|
+ int maxNums = 100; //每次最多发送100条,我们一次批量发100条
|
|
|
int times = 0;// 循环几个100 用List的长度 除 100
|
|
|
int size = 0; //
|
|
|
|
|
@@ -131,7 +129,7 @@ public class SendSmsServiceImpl implements ISendSmsService {
|
|
|
//返回提示
|
|
|
String backResult = "";
|
|
|
size = smsList.size();
|
|
|
- if (size < 2) {
|
|
|
+ if (size < 100) {
|
|
|
times = 1;
|
|
|
} else {
|
|
|
times = (size - 1) / maxNums + 1; //为什么要-1 因为如果是200的时候,理论上次数应该是2,而不是3,如果是101,那么次数也是2,这样就保证次数准确。
|
|
@@ -211,4 +209,123 @@ public class SendSmsServiceImpl implements ISendSmsService {
|
|
|
}
|
|
|
return backResult;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入下发中考身份信息修改通知
|
|
|
+ * @param smsList
|
|
|
+ * @param isUpdateSupport
|
|
|
+ * @param operName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String importUserNotice(List<SendSms> smsList, Boolean isUpdateSupport, String operName) {
|
|
|
+ if (StringUtils.isNull(smsList) || smsList.size() == 0) {
|
|
|
+ throw new CustomException("导入数据不能为空!");
|
|
|
+ }
|
|
|
+ int maxNums = 100; //每次最多发送100条,我们一次批量发100条
|
|
|
+ int times = 0;// 循环几个100 用List的长度 除 100
|
|
|
+ int size = 0; //
|
|
|
+
|
|
|
+ List<String> phoneList = new ArrayList<>();
|
|
|
+ List<String> signNameList = new ArrayList<>();
|
|
|
+ StringBuffer signNameJson;
|
|
|
+ StringBuffer phoneNumberJson;
|
|
|
+ //返回提示
|
|
|
+ String backResult = "";
|
|
|
+ size = smsList.size();
|
|
|
+ if (size < 100) {
|
|
|
+ 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();
|
|
|
+ phoneNumberJson.append("[");
|
|
|
+ signNameJson.append("[");
|
|
|
+ for (int k = j * maxNums; k < size && k < (j + 1) * maxNums; k++) {
|
|
|
+ // 防止有空行,手机号是必须要有的
|
|
|
+ String phone = smsList.get(k).getPhone();
|
|
|
+ if (StringUtils.isEmpty(phone)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ phoneNumberJson.append("\"" + smsList.get(k).getPhone() + "\",");
|
|
|
+ signNameJson.append("\"潜山市数据资源局\",");
|
|
|
+ }
|
|
|
+ phoneNumberJson.deleteCharAt(phoneNumberJson.length() - 1);//移除最后一个逗号字符,
|
|
|
+ signNameJson.deleteCharAt(signNameJson.length() - 1);
|
|
|
+ phoneNumberJson.append("]");
|
|
|
+ signNameJson.append("]");
|
|
|
+ phoneList.add(phoneNumberJson.toString());
|
|
|
+ signNameList.add(signNameJson.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.setTemplateCode(TEMPLATE_CODE_NOTICE);
|
|
|
+ long endTimeSql = System.currentTimeMillis() - startTimeSql;
|
|
|
+ System.out.println("执行批量下发短信通知计算:"+i+"次,时间" + endTimeSql + "ms");
|
|
|
+ long startTimeSend = System.currentTimeMillis();
|
|
|
+ SendBatchSmsResponse sendBatchSmsResponse = SendBatchSmsUtils.sendBatchSms(sendBatchSmsRequest);
|
|
|
+ long endTimeSend = System.currentTimeMillis() - startTimeSend;
|
|
|
+ System.out.println("执行批量下发短信通知接口请求:" + endTimeSend + "ms");
|
|
|
+ SendSms sendSms = new SendSms();
|
|
|
+ if (sendBatchSmsResponse != null) {
|
|
|
+ String code = sendBatchSmsResponse.getBody().getCode();
|
|
|
+ if (sendBatchSmsResponse.getBody().getCode() != null && "OK".equals(code)) {
|
|
|
+ sendSms.setStatus("发送成功");
|
|
|
+ sendSms.setPhone(String.join(",", phoneList));
|
|
|
+ sendSms.setCreateBy(operName);
|
|
|
+ sendSmsMapper.insertSendSms(sendSms);
|
|
|
+ //批量请求发送短信成功
|
|
|
+ System.out.println("批量短信发送成功:" + phoneList.get(i).split(",").length + "条");
|
|
|
+ backResult = backResult +"第"+i+"次批量成功 ";
|
|
|
+ } else {
|
|
|
+ sendSms.setPhone(String.join(",", phoneList));
|
|
|
+ sendSms.setStatus("发送失败");
|
|
|
+ sendSms.setCreateBy(operName);
|
|
|
+ sendSmsMapper.insertSendSms(sendSms);
|
|
|
+ System.out.println("批量短信发送失败!");
|
|
|
+ backResult = backResult +"第"+i+"次批量失败 ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return backResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入下发中考身份信息修改通知 多线程
|
|
|
+ * @param smsList
|
|
|
+ * @param isUpdateSupport
|
|
|
+ * @param operName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String importUserNoticeMore(List<SendSms> smsList, Boolean isUpdateSupport, String operName) {
|
|
|
+ //定义每个线程处理多少用户
|
|
|
+ Integer count = 650;
|
|
|
+ //根据用户数确定需要多少个线程
|
|
|
+ List<List<SendSms>> lists = BranchThreadUtils.splitList(smsList, count);
|
|
|
+ //将用户传每个线程执行
|
|
|
+ for (List<SendSms> list : lists) {
|
|
|
+ SmsThread smsThread = new SmsThread(list);
|
|
|
+ //启动线程
|
|
|
+ smsThread.start();
|
|
|
+ System.out.println("线程" + Thread.currentThread().getId()+"启动");
|
|
|
+ }
|
|
|
+ return "发送成功";
|
|
|
+ }
|
|
|
}
|