xxxDto dto = new xxxDto();
Map<String, String> map = getOpenIdAndCompanyId(ticket);
String openId = String.valueOf(map.get("openId"));
String companyId = String.valueOf(map.get("companyId"));
List<String> cusIds = dto.getUserIds();
cusGroupModeService.send(map,cusIds);
//send方法为短信发送的方法
@Override
public int send(Map<String,String> map, List<String> cusIds){
{
int count = 0;
Map<String,List<MpCusContacts>> contactsMap = null;
List<MpCusContacts> contactsList = null;
SendBo bo = null;
JSONObject param = null;
Map<String, String> sendContent = getxxxContent(map,cusIds);
// getxxxContent方法为获取短信内容的方法,可以自己设定短信模板,动态读取部分数据替换模板中的响应位置。
String content = sendContent.get("content");
List<Future<Integer>> futures = new ArrayList<>();
List<MpCusContacts> list = mpCusContactsDao.selectByCustIds(map.get("companyId"),cusIds,null,null);
if(list != null && list.size() > 0){
contactsMap = list.stream().collect(Collectors.groupingBy(MpCusContacts::getCustId));
}
for(String id:cusIds) {
contactsList = contactsMap == null ? null : contactsMap.get(id);
if (contactsList == null) {
continue;
}
for (MpCusContacts contacts : contactsList) {
param = new JSONObject();
param.put("company", map.get("officeName"));
bo = new SendBo();
bo.setCompanyId(map.get("companyId"));
bo.setContent(content);
bo.setType(type);
bo.setSendType("JSXX");//类型自己定义,我用的是首字母拼音
bo.setUserId(map.get("userId"));
bo.setTelephone(contacts.getTelephone());
bo.setParam(param);
futures.add(smsService.send(bo));
}
}
try {
for (Future future : futures) {
count = count + (Integer) future.get();
}
}catch (ExecutionException e){
e.printStackTrace();
log.error("xxxSend:{}",e);
return count;
}catch (InterruptedException e){
e.printStackTrace();
log.error("xxxSend:{}",e);
return count;
}
return count;
}
}
@Async
@Override
public Future<Integer> send(SendBo bo) {
// 发送短信
JSONObject object = new JSONObject();
object.put("mobile",bo.getTelephone());
object.put("param",bo.getParam());
object.put("signName",signName);
object.put("type",bo.getType());
log.info("发送短信,参数:{}",object.toJSONString());
JSONObject result = smsService.MessageSend(object);
log.info("返回参数:{}",result.toJSONString());
// 短信记录
if(result.getIntValue("code") == 200) {
MpShortMsgRecord record = new MpShortMsgRecord();
record.preInsert();
record.setCompanyId(bo.getCompanyId());
record.setAddresseeTelephone(bo.getTelephone());
record.setAddresseeContent(bo.getContent());
record.setSendType(bo.getSendType());
record.setCreator(bo.getUserId());
record.setUpdater(bo.getUserId());
return new AsyncResult<>(mpShortMsgRecordDao.insertSelective(record));
}
return new AsyncResult<>(0);
}
@Data
public class SendBo {
private Long type; // 模板id
private String sendType; // 类型
private String companyId; //公司id
private String telephone; //手机号
private String userId; //操作人
private JSONObject param; // 模板替换参数 JSON格式
private String content; // 内容
}