| | |
| | | import cn.gistack.alerts.sms.entity.SmsResult; |
| | | import cn.gistack.alerts.sms.entity.SmsTemplate; |
| | | import cn.gistack.alerts.sms.excel.SendRainSmsExcel; |
| | | import cn.gistack.alerts.sms.excel.SendSmsExcel; |
| | | import cn.gistack.alerts.sms.service.ISmsRecordService; |
| | | import cn.gistack.alerts.sms.service.ISmsResultService; |
| | | import cn.gistack.alerts.sms.service.ISmsTemplateService; |
| | |
| | | import cn.gistack.alerts.sms.vo.SmsResponseVO; |
| | | import cn.gistack.alerts.sms.vo.Temp; |
| | | import cn.gistack.sm.intelligentCall.entity.CallNotFillRecord; |
| | | import cn.gistack.sm.intelligentCall.excel.CallExcel; |
| | | import cn.gistack.sm.intelligentCall.feign.OutCallClient; |
| | | import cn.gistack.sm.message.entity.MessageRecord; |
| | | import cn.gistack.sm.sjztmd.feign.IAttResManagePersonClient; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
| | | import com.google.common.collect.Lists; |
| | | import com.google.common.collect.Sets; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | |
| | | // 返回 |
| | | return batchSendSmsMap; |
| | | } |
| | | |
| | | /** |
| | | * 导入表格发送预警短信 |
| | | * @param list 集合数据 |
| | | * @param templateId 模板id |
| | | * @param param 通用参数 |
| | | * @param content 发送内容 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Object importSendSms(List<SendSmsExcel> list,String templateId,String param, String content) { |
| | | // 查询短信模板 |
| | | SmsTemplate smsTemplate = smsTemplateService.getOne(new QueryWrapper<SmsTemplate>().eq("template_id", templateId)); |
| | | // 判断模板是否为具名变量模板(目前已筛选出都是具名变量模板) |
| | | // 判断模板中是否包含参数,如果无参数,对比是否传参数 |
| | | boolean validate = validatorParam(smsTemplate,param); |
| | | if (!validate){ |
| | | return R.data(400,"参数个数不对应,请检查后修改导入!",null); |
| | | } |
| | | // 转换 |
| | | List<String> stringList = list.stream().map(SendSmsExcel::getPhone).collect(Collectors.toList()); |
| | | // 获取水库个数 |
| | | List<String> errPhones = new ArrayList<>(); |
| | | // 去重 |
| | | Set<String> hashSet = new HashSet<>(stringList); |
| | | // 拼接短信标题数组 |
| | | String [] titleArr = getSmsTitleArr(smsTemplate); |
| | | // 批量发送不能超过1000 个号码,需分组发送 |
| | | List<String> arrayList = new ArrayList<>(hashSet); |
| | | List<List<String>> partition = Lists.partition(arrayList, 1000); |
| | | int i = 0; |
| | | String errMsg = ""; |
| | | for (List<String> phoneList : partition) { |
| | | HashSet<String> sets = new HashSet<>(phoneList); |
| | | // 批量发送短信 |
| | | Map<String, Object> batchSendSmsMap = batchSendSms(sets, titleArr, param, smsTemplate,errPhones); |
| | | // 取出发送结果 |
| | | ComResult<DynSMSSendDataResult> resultComResult = (ComResult<DynSMSSendDataResult>) batchSendSmsMap.get("resultComResult"); |
| | | // |
| | | if(!resultComResult.getCode().equals(0)){ |
| | | i++; |
| | | errMsg = resultComResult.getMsg(); |
| | | break; |
| | | } |
| | | } |
| | | if (i>0){ |
| | | // 返回resultComResult |
| | | return R.data(400,"发送失败!" + errMsg,null); |
| | | } |
| | | // 返回resultComResult |
| | | return R.data(200,"发送成功!",null); |
| | | } |
| | | |
| | | /** |
| | | * 校验参数 |
| | | * @param smsTemplate |
| | | * @param param |
| | | */ |
| | | private boolean validatorParam(SmsTemplate smsTemplate, String param) { |
| | | int length = 0; |
| | | if (null!= param && !param.equals("")) { |
| | | length = Arrays.asList(param.split(",")).size(); |
| | | } |
| | | // 解析模板 |
| | | String str = smsTemplate.getContent().replaceAll("\\{.+?\\}", "%s"); |
| | | int countChar = countChar(str, '%'); |
| | | if (length==countChar){ |
| | | return true; |
| | | }else { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 计算某个字符在字符串中的个数 |
| | | * @param str 字符串 |
| | | * @param target 字符 |
| | | * @return |
| | | */ |
| | | public int countChar(String str, char target) { |
| | | String targetStr = String.valueOf(target); |
| | | String replacedStr = str.replaceAll(targetStr, ""); |
| | | return str.length() - replacedStr.length(); |
| | | } |
| | | } |