zhongrj
2023-06-17 3e27630f0102a9fa590ce029df0994535eb86bd6
skjcmanager/skjcmanager-service/skjcmanager-alerts/src/main/java/cn/gistack/alerts/sms/service/impl/SmsServiceImpl.java
@@ -18,6 +18,8 @@
import cn.gistack.alerts.sms.util.SmsUtils;
import cn.gistack.alerts.sms.vo.SmsRequestTemplate;
import cn.gistack.common.cache.CacheNames;
import cn.gistack.sm.intelligentCall.entity.CallNotFillRecord;
import cn.gistack.sm.intelligentCall.feign.OutCallClient;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.springblade.core.redis.cache.BladeRedis;
@@ -26,6 +28,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -52,6 +56,9 @@
   @Autowired
   private BladeRedis bladeRedis;
   @Autowired
   private OutCallClient outCallClient;
   /**
    * 发送 xx 变量模板短信
@@ -350,8 +357,8 @@
         List<Map<String, Object>> newList = new ArrayList<>();
         // 比对
         for (Map<String, Object> map : list) {
            // 获取验证码
            String redisByTaskId = bladeRedis.get(MinConstant.is_send_prefix + map.get("userPhone").toString() + ":" + map.get("waterCode").toString());
            // 获取任务id
            String redisByTaskId = bladeRedis.get(MinConstant.is_send_prefix + map.get("callId").toString());
            // 如果为null,并且不能匹配,加入发送短信集合
            if (redisByTaskId == null || !StringUtil.equalsIgnoreCase(redisByTaskId, taskId)) {
               newList.add(map);
@@ -362,14 +369,20 @@
            StringBuilder builder = new StringBuilder();
            // 遍历
            for (Map<String, Object> map : newList) {
//               String callId = null;
//               try {
//                  callId = URLEncoder.encode("callId=" + map.get("callId"), "UTF-8");
//               } catch (UnsupportedEncodingException e) {
//                  e.printStackTrace();
//               }
               builder.append(map.get("userPhone") + ",")
                  .append(time + ",")
                  .append(MinConstant.fillWaterInfoUrl + ",")
                  .append(map.get("waterName"))
                  .append(MinConstant.fillWaterInfoUrl +"?" + "callId=" + map.get("callId") + ",")
                  .append(";");
            }
            String datas = builder.toString();
            String title = "手机号码,时间范围,链接地址,水库名称";
            String title = "手机号码,时间范围,水库名称,访问链接";
            String[] titleArr = title.split(",");
            String[] rows = datas.split(";");
            String[][] dyns = new String[rows.length + 1][titleArr.length];
@@ -402,10 +415,18 @@
                  SmsRecord smsRecord = new SmsRecord();
                  smsRecord.setId(IdWorker.getId());
                  smsRecord.setTel(map.get("userPhone").toString());
                  String callId = null;
//                  try {
//                     callId = URLEncoder.encode("callId=" + map.get("callId"), "UTF-8");
//                  } catch (UnsupportedEncodingException e) {
//                     e.printStackTrace();
//                  }
                  // 内容处理
                  String s = smsTemplate.getContent().replaceAll("\\{.+?\\}", "%s");
                  // 拼接内容
                  String arrString = time + "," + MinConstant.fillWaterInfoUrl + "," + map.get("waterName").toString();
                  String arrString = time + "," +
                     map.get("waterName").toString() + "," +
                     MinConstant.fillWaterInfoUrl + "?" + "callId=" + map.get("callId") ;
                  // 格式转换
                  String format = String.format(s, arrString.split(","));
                  smsRecord.setContent(format);
@@ -414,8 +435,8 @@
                  smsRecord.setResponseStatus(resultComResult.getCode().toString());
                  smsRecord.setResponseMsg(resultComResult.getMsg());
                  // 保存redis
                  bladeRedis.setEx(MinConstant.is_send_prefix + map.get("userPhone").toString() + ":" + map.get("waterCode").toString(), taskId, 2 * 60 * 60L);
                  bladeRedis.setEx(MinConstant.fill_info_prefix + map.get("userPhone").toString(), taskId, validTime);
                  bladeRedis.setEx(MinConstant.is_send_prefix + map.get("callId").toString(), taskId, 2 * 60 * 60L);
                  bladeRedis.setEx(MinConstant.fill_info_prefix + map.get("callId").toString(), taskId, validTime);
                  // 加入集合
                  smsRecordList.add(smsRecord);
               }
@@ -449,22 +470,32 @@
   /**
    * 通过手机号获取外呼未接通已发短信通知的人员水库信息
    * @param phone 手机号码
    * @param callId 呼叫id
    * @return
    */
   @Override
   public Object getCallNotConnectSmsNoticeInfo(String phone) {
   public Object getCallNotConnectSmsNoticeInfo(String callId) {
      Map<String, Object> map = new HashMap<>(2);
      boolean flag = false;
      List<Map<String, Object>> list = new ArrayList<>();
      // 通过手机号查询外呼任务id
      String taskId = bladeRedis.get(MinConstant.fill_info_prefix + phone);
      String taskId = bladeRedis.get(MinConstant.fill_info_prefix + callId);
      // 判断
      if (null!=taskId && !taskId.equals("")){
         // 通过手机号和外呼任务id 查询水库人员信息
         list = smsTemplateService.getNotConnectPatrolPersonList(taskId,phone);
         list = smsTemplateService.getNotConnectPatrolPersonList(taskId,callId);
         // 查询是否填报
         CallNotFillRecord callNotFillRecordInfo = outCallClient.getCallNotFillRecordInfo(callId);
         if (callNotFillRecordInfo != null){
            flag = true;
         }
         // 封装数据
         map.put("list",list);
         map.put("isFill",flag);
         // 返回
         return list;
         return map;
      }
      // 没有,已过期
      return list;
      return map;
   }
}