优化通过uid查询视频会议信息接口

This commit is contained in:
wangqiong
2024-04-18 18:36:45 +08:00
parent 5e544e6d4e
commit 918c1a8bad
3 changed files with 85 additions and 40 deletions
@@ -4,15 +4,23 @@ import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.common.annotation.Anonymous; import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.entity.shortmessage.MeetingInfo;
import com.ruoyi.system.domain.entity.sms.MsSmsSendRecordParam; import com.ruoyi.system.domain.entity.sms.MsSmsSendRecordParam;
import com.ruoyi.system.domain.entity.sms.MsSmsTemplateParam; import com.ruoyi.system.domain.entity.sms.MsSmsTemplateParam;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.shortmessage.MeetingInfoMapper;
import com.ruoyi.system.mapper.sms.MsSmsSendHistoryRecordParamMapper; import com.ruoyi.system.mapper.sms.MsSmsSendHistoryRecordParamMapper;
import com.ruoyi.system.mapper.sms.MsSmsSendRecordParamMapper; import com.ruoyi.system.mapper.sms.MsSmsSendRecordParamMapper;
import com.ruoyi.wisdomarbitrate.domain.dto.sendrecord.SmsSendRecord; import com.ruoyi.wisdomarbitrate.domain.dto.sendrecord.SmsSendRecord;
import com.ruoyi.wisdomarbitrate.domain.vo.shortmessage.MeetingInfoVO;
import com.ruoyi.wisdomarbitrate.domain.vo.shortmessage.ReSendMessageVO; import com.ruoyi.wisdomarbitrate.domain.vo.shortmessage.ReSendMessageVO;
import com.ruoyi.wisdomarbitrate.mapper.sendrecord.SmsRecordMapper; import com.ruoyi.wisdomarbitrate.mapper.sendrecord.SmsRecordMapper;
import com.ruoyi.wisdomarbitrate.service.shortmessage.ShortMessageService; import com.ruoyi.wisdomarbitrate.service.shortmessage.ShortMessageService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
@@ -32,13 +40,15 @@ public class ShortMessageController extends BaseController {
MsSmsSendRecordParamMapper recordParamMapper; MsSmsSendRecordParamMapper recordParamMapper;
@Autowired @Autowired
MsSmsSendHistoryRecordParamMapper historyRecordParamMapper; MsSmsSendHistoryRecordParamMapper historyRecordParamMapper;
/** /**
* 查询短信发送记录 * 查询短信发送记录
*
* @param smsSendRecord * @param smsSendRecord
* @return * @return
*/ */
@GetMapping("/recordList") @GetMapping("/recordList")
public TableDataInfo smsSendRecordList( SmsSendRecord smsSendRecord){ public TableDataInfo smsSendRecordList(SmsSendRecord smsSendRecord) {
startPage(); startPage();
List<SmsSendRecord> list = shortMessageService.smsSendRecordList(smsSendRecord); List<SmsSendRecord> list = shortMessageService.smsSendRecordList(smsSendRecord);
return getDataTable(list); return getDataTable(list);
@@ -47,7 +57,7 @@ public class ShortMessageController extends BaseController {
@Anonymous @Anonymous
@PostMapping("/updateSendContent") @PostMapping("/updateSendContent")
public AjaxResult update(@RequestBody SmsSendRecord smsSendRecord) { public AjaxResult update(@RequestBody SmsSendRecord smsSendRecord) {
if(smsSendRecord == null|| smsSendRecord.getId() == null || CollectionUtil.isEmpty(smsSendRecord.getTemplateParams())){ if (smsSendRecord == null || smsSendRecord.getId() == null || CollectionUtil.isEmpty(smsSendRecord.getTemplateParams())) {
return AjaxResult.error("参数校验失败"); return AjaxResult.error("参数校验失败");
} }
// 查询当前版本记录 // 查询当前版本记录
@@ -66,7 +76,7 @@ public class ShortMessageController extends BaseController {
recordParams.add(recordParam); recordParams.add(recordParam);
} }
recordParamMapper.batchInsert(recordParams); recordParamMapper.batchInsert(recordParams);
shortMessageService.insertShortMessageHistoryRecord(oldSendRecord,recordParams); shortMessageService.insertShortMessageHistoryRecord(oldSendRecord, recordParams);
return AjaxResult.success(); return AjaxResult.success();
} }
@@ -84,14 +94,32 @@ public class ShortMessageController extends BaseController {
return AjaxResult.error("参数缺失"); return AjaxResult.error("参数缺失");
} }
@Autowired
MeetingInfoMapper meetingInfoMapper;
@Autowired
SysUserMapper sysUserMapper;
@Autowired
private TokenService tokenService;
/** /**
* 查询UID好的密钥 * 查询UID好的密钥
*/ */
@Anonymous @Anonymous
@GetMapping("/getMeetingInfo") @GetMapping("/getMeetingInfo")
public Object getEncryptInfoByUid(@RequestParam(name = "authId", required = true) String authId) { public Object getEncryptInfoByUid(@RequestParam(name = "authId", required = true) String authId) {
MeetingInfoVO result = new MeetingInfoVO();
if (authId != null) { if (authId != null) {
Object result = shortMessageService.getMeetingInfo(authId); MeetingInfo meetingInfo = meetingInfoMapper.selectByPrimaryKey(authId);
if (meetingInfo != null && meetingInfo.getUserId() != null) {
BeanUtils.copyProperties(meetingInfo, result);
SysUser sysUser = sysUserMapper.selectUserById(meetingInfo.getUserId());
LoginUser loginUser = new LoginUser();
loginUser.setUserId(sysUser.getUserId());
loginUser.setUser(sysUser);
String token = tokenService.createVideoToken(loginUser, 120);
// String createToken = createToken(claims);
result.setToken(token);
}
return result; return result;
} }
return AjaxResult.error("查询失败"); return AjaxResult.error("查询失败");
@@ -127,7 +127,20 @@ public class TokenService
redisCache.setCacheObject(CacheConstants.LOGIN_USERNAME_TOKEN_KEY+loginUser.getUsername(),createToken, expireTime, TimeUnit.MINUTES); redisCache.setCacheObject(CacheConstants.LOGIN_USERNAME_TOKEN_KEY+loginUser.getUsername(),createToken, expireTime, TimeUnit.MINUTES);
return createToken; return createToken;
} }
public String createVideoToken(LoginUser loginUser,int expireTime)
{
String token = IdUtils.fastUUID();
loginUser.setToken(token);
setUserAgent(loginUser);
refreshToken(loginUser);
Map<String, Object> claims = new HashMap<>();
claims.put("userName",loginUser.getUsername());
claims.put("userId",loginUser.getUserId());
claims.put(Constants.LOGIN_USER_KEY, token);
String createToken = createToken(claims);
redisCache.setCacheObject(CacheConstants.LOGIN_USERNAME_TOKEN_KEY+loginUser.getUsername(),createToken, expireTime, TimeUnit.MINUTES);
return createToken;
}
/** /**
* 验证令牌有效期,相差不足20分钟,自动刷新缓存 * 验证令牌有效期,相差不足20分钟,自动刷新缓存
* *
@@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.enums.SMSStatusEnum; import com.ruoyi.common.enums.SMSStatusEnum;
import com.ruoyi.system.domain.entity.shortmessage.MeetingInfo; import com.ruoyi.system.domain.entity.shortmessage.MeetingInfo;
import com.ruoyi.system.domain.entity.shortmessage.MsSmsSendHistoryRecord; import com.ruoyi.system.domain.entity.shortmessage.MsSmsSendHistoryRecord;
@@ -11,6 +13,7 @@ import com.ruoyi.system.domain.entity.sms.MsSmsSendHistoryRecordParam;
import com.ruoyi.system.domain.entity.sms.MsSmsSendRecordParam; import com.ruoyi.system.domain.entity.sms.MsSmsSendRecordParam;
import com.ruoyi.system.domain.entity.sms.MsSmsTemplate; import com.ruoyi.system.domain.entity.sms.MsSmsTemplate;
import com.ruoyi.system.domain.entity.sms.MsSmsTemplateParam; import com.ruoyi.system.domain.entity.sms.MsSmsTemplateParam;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.shortmessage.MeetingInfoMapper; import com.ruoyi.system.mapper.shortmessage.MeetingInfoMapper;
import com.ruoyi.system.mapper.shortmessage.MsSmsSendHistoryRecordMapper; import com.ruoyi.system.mapper.shortmessage.MsSmsSendHistoryRecordMapper;
import com.ruoyi.system.mapper.sms.MsSmsSendHistoryRecordParamMapper; import com.ruoyi.system.mapper.sms.MsSmsSendHistoryRecordParamMapper;
@@ -56,11 +59,11 @@ public class ShortMessageServiceImpl implements ShortMessageService {
@Override @Override
public List<SmsSendRecord> smsSendRecordList(SmsSendRecord smsSendRecord) { public List<SmsSendRecord> smsSendRecordList(SmsSendRecord smsSendRecord) {
List<SmsSendRecord> records = smsRecordMapper.getSmsSendRecord(smsSendRecord); List<SmsSendRecord> records = smsRecordMapper.getSmsSendRecord(smsSendRecord);
if(CollectionUtil.isEmpty(records)){ if (CollectionUtil.isEmpty(records)) {
return null; return null;
} }
List<Long> templateIds = records.stream().map(SmsSendRecord::getMsSmsTemplateId).collect(Collectors.toList()); List<Long> templateIds = records.stream().map(SmsSendRecord::getMsSmsTemplateId).collect(Collectors.toList());
if(CollectionUtil.isEmpty(templateIds)){ if (CollectionUtil.isEmpty(templateIds)) {
return records; return records;
} }
List<Long> ids = records.stream().map(SmsSendRecord::getId).collect(Collectors.toList()); List<Long> ids = records.stream().map(SmsSendRecord::getId).collect(Collectors.toList());
@@ -68,14 +71,14 @@ public class ShortMessageServiceImpl implements ShortMessageService {
Example recordParamExam = new Example(MsSmsSendRecordParam.class); Example recordParamExam = new Example(MsSmsSendRecordParam.class);
recordParamExam.createCriteria().andIn("smsRecordId", ids); recordParamExam.createCriteria().andIn("smsRecordId", ids);
List<MsSmsSendRecordParam> recordParams = recordParamMapper.selectByExample(recordParamExam); List<MsSmsSendRecordParam> recordParams = recordParamMapper.selectByExample(recordParamExam);
if(CollectionUtil.isEmpty(recordParams)){ if (CollectionUtil.isEmpty(recordParams)) {
return records; return records;
} }
// 根据模板id查询模板参数 // 根据模板id查询模板参数
Example templateParamExam = new Example(MsSmsTemplateParam.class); Example templateParamExam = new Example(MsSmsTemplateParam.class);
templateParamExam.createCriteria().andIn("smsTemplateId", templateIds); templateParamExam.createCriteria().andIn("smsTemplateId", templateIds);
List<MsSmsTemplateParam> templateParams = templateParamMapper.selectByExample(templateParamExam); List<MsSmsTemplateParam> templateParams = templateParamMapper.selectByExample(templateParamExam);
if(CollectionUtil.isEmpty(templateParams)){ if (CollectionUtil.isEmpty(templateParams)) {
return records; return records;
} }
// 根据模板id对模板参数分组 // 根据模板id对模板参数分组
@@ -85,17 +88,17 @@ public class ShortMessageServiceImpl implements ShortMessageService {
Map<Long, List<String>> recordParamContentMap = new HashMap<>(); Map<Long, List<String>> recordParamContentMap = new HashMap<>();
for (MsSmsSendRecordParam recordParam : recordParams) { for (MsSmsSendRecordParam recordParam : recordParams) {
List<String> list = recordParamContentMap.get(recordParam.getSmsRecordId()); List<String> list = recordParamContentMap.get(recordParam.getSmsRecordId());
if(CollectionUtil.isEmpty(list)){ if (CollectionUtil.isEmpty(list)) {
list=new ArrayList<>(); list = new ArrayList<>();
} }
list.add(recordParam.getParamValue()); list.add(recordParam.getParamValue());
recordParamContentMap.put(recordParam.getSmsRecordId(),list); recordParamContentMap.put(recordParam.getSmsRecordId(), list);
} }
// 根据模板id查询模板 // 根据模板id查询模板
Example templateExam = new Example(MsSmsTemplate.class); Example templateExam = new Example(MsSmsTemplate.class);
templateExam.createCriteria().andIn("id", templateIds); templateExam.createCriteria().andIn("id", templateIds);
List<MsSmsTemplate> templates = templateMapper.selectByExample(templateExam); List<MsSmsTemplate> templates = templateMapper.selectByExample(templateExam);
if(CollectionUtil.isEmpty(templates)){ if (CollectionUtil.isEmpty(templates)) {
return records; return records;
} }
// 根据主键id获取模板内容 // 根据主键id获取模板内容
@@ -103,28 +106,28 @@ public class ShortMessageServiceImpl implements ShortMessageService {
Map<Long, String> templateIdMap = templates.stream().collect(Collectors.toMap(MsSmsTemplate::getId, MsSmsTemplate::getTemplateId, (k1, k2) -> k2)); Map<Long, String> templateIdMap = templates.stream().collect(Collectors.toMap(MsSmsTemplate::getId, MsSmsTemplate::getTemplateId, (k1, k2) -> k2));
// 组装模板内容 // 组装模板内容
for (SmsSendRecord record : records) { for (SmsSendRecord record : records) {
if(record.getMsSmsTemplateId()==null){ if (record.getMsSmsTemplateId() == null) {
continue; continue;
} }
if(!templateMap.containsKey(record.getMsSmsTemplateId())){ if (!templateMap.containsKey(record.getMsSmsTemplateId())) {
continue; continue;
} }
if(!recordParamContentMap.containsKey(record.getId())){ if (!recordParamContentMap.containsKey(record.getId())) {
continue; continue;
} }
if(templateIdMap.containsKey(record.getMsSmsTemplateId())){ if (templateIdMap.containsKey(record.getMsSmsTemplateId())) {
record.setTemplateId(templateIdMap.get(record.getMsSmsTemplateId())); record.setTemplateId(templateIdMap.get(record.getMsSmsTemplateId()));
} }
String templateContent = templateMap.get(record.getMsSmsTemplateId()); String templateContent = templateMap.get(record.getMsSmsTemplateId());
record.setTemplateContent(templateContent); record.setTemplateContent(templateContent);
List<String> recordParamList = recordParamContentMap.get(record.getId()); List<String> recordParamList = recordParamContentMap.get(record.getId());
if(recordParamContentMap.containsKey(record.getId()) && templateParamMap.containsKey(record.getMsSmsTemplateId())){ if (recordParamContentMap.containsKey(record.getId()) && templateParamMap.containsKey(record.getMsSmsTemplateId())) {
List<MsSmsTemplateParam> templateParamList = templateParamMap.get(record.getMsSmsTemplateId()); List<MsSmsTemplateParam> templateParamList = templateParamMap.get(record.getMsSmsTemplateId());
ArrayList<MsSmsTemplateParam> copyParamList = new ArrayList<>(); ArrayList<MsSmsTemplateParam> copyParamList = new ArrayList<>();
for (int i = 0; i < templateParamList.size(); i++) { for (int i = 0; i < templateParamList.size(); i++) {
MsSmsTemplateParam templateParam = templateParamList.get(i); MsSmsTemplateParam templateParam = templateParamList.get(i);
MsSmsTemplateParam msSmsTemplateParam =new MsSmsTemplateParam(); MsSmsTemplateParam msSmsTemplateParam = new MsSmsTemplateParam();
msSmsTemplateParam.setParam(templateParam.getParam()); msSmsTemplateParam.setParam(templateParam.getParam());
msSmsTemplateParam.setSmsTemplateId(templateParam.getSmsTemplateId()); msSmsTemplateParam.setSmsTemplateId(templateParam.getSmsTemplateId());
msSmsTemplateParam.setParamName(templateParam.getParamName()); msSmsTemplateParam.setParamName(templateParam.getParamName());
@@ -136,8 +139,8 @@ public class ShortMessageServiceImpl implements ShortMessageService {
} }
// 按顺序替换占位符 // 按顺序替换占位符
if(CollectionUtil.isNotEmpty(recordParamList)){ if (CollectionUtil.isNotEmpty(recordParamList)) {
recordParamList.add(0,"0"); recordParamList.add(0, "0");
// 将List<String>转换为String[]数组 // 将List<String>转换为String[]数组
String[] paramArray = recordParamList.toArray(new String[recordParamList.size()]); String[] paramArray = recordParamList.toArray(new String[recordParamList.size()]);
@@ -150,6 +153,7 @@ public class ShortMessageServiceImpl implements ShortMessageService {
return records; return records;
} }
/** /**
* 新增发送历史记录 * 新增发送历史记录
* *
@@ -157,19 +161,19 @@ public class ShortMessageServiceImpl implements ShortMessageService {
*/ */
@Transactional @Transactional
@Override @Override
public void insertShortMessageHistoryRecord(SmsSendRecord smsSendRecord,List<MsSmsSendRecordParam> recordParams) { public void insertShortMessageHistoryRecord(SmsSendRecord smsSendRecord, List<MsSmsSendRecordParam> recordParams) {
if(smsSendRecord!=null){ if (smsSendRecord != null) {
MsSmsSendHistoryRecord historyRecord=new MsSmsSendHistoryRecord(); MsSmsSendHistoryRecord historyRecord = new MsSmsSendHistoryRecord();
BeanUtils.copyProperties(smsSendRecord,historyRecord); BeanUtils.copyProperties(smsSendRecord, historyRecord);
historyRecord.setId(null); historyRecord.setId(null);
historyRecord.setParentId(smsSendRecord.getId()); historyRecord.setParentId(smsSendRecord.getId());
int i = msSmsSendHistoryRecordMapper.insert(historyRecord); int i = msSmsSendHistoryRecordMapper.insert(historyRecord);
if(i>0 && CollectionUtil.isNotEmpty(recordParams)){ if (i > 0 && CollectionUtil.isNotEmpty(recordParams)) {
// 新增参数表 // 新增参数表
List<MsSmsSendHistoryRecordParam> historyRecordParams = new ArrayList<>(); List<MsSmsSendHistoryRecordParam> historyRecordParams = new ArrayList<>();
for (MsSmsSendRecordParam templateParam : recordParams) { for (MsSmsSendRecordParam templateParam : recordParams) {
MsSmsSendHistoryRecordParam recordParam = new MsSmsSendHistoryRecordParam(); MsSmsSendHistoryRecordParam recordParam = new MsSmsSendHistoryRecordParam();
BeanUtils.copyProperties(templateParam,recordParam); BeanUtils.copyProperties(templateParam, recordParam);
recordParam.setId(null); recordParam.setId(null);
recordParam.setSmsRecordHistoryId(historyRecord.getId()); recordParam.setSmsRecordHistoryId(historyRecord.getId());
historyRecordParams.add(recordParam); historyRecordParams.add(recordParam);
@@ -189,7 +193,7 @@ public class ShortMessageServiceImpl implements ShortMessageService {
if (reSendMessageVO != null && reSendMessageVO.getTemplateId() != null && reSendMessageVO.getPhone() != null && reSendMessageVO.getTemplateParams() != null && reSendMessageVO.getTemplateParams().size() > 0 && reSendMessageVO.getId() != null) { if (reSendMessageVO != null && reSendMessageVO.getTemplateId() != null && reSendMessageVO.getPhone() != null && reSendMessageVO.getTemplateParams() != null && reSendMessageVO.getTemplateParams().size() > 0 && reSendMessageVO.getId() != null) {
// 根据id查询短信记录 // 根据id查询短信记录
SmsSendRecord smsSendRecord = smsRecordMapper.selectById(reSendMessageVO.getId()); SmsSendRecord smsSendRecord = smsRecordMapper.selectById(reSendMessageVO.getId());
if(smsSendRecord == null){ if (smsSendRecord == null) {
return AjaxResult.warn("短信记录不存在"); return AjaxResult.warn("短信记录不存在");
} }
@@ -204,16 +208,16 @@ public class ShortMessageServiceImpl implements ShortMessageService {
// 修改sid和状态 // 修改sid和状态
if (resultObj.get("status") != null && !resultObj.get("status").equals(SMSStatusEnum.FAIL.getCode())) { if (resultObj.get("status") != null && !resultObj.get("status").equals(SMSStatusEnum.FAIL.getCode())) {
smsSendRecord.setSendStatus(SMSStatusEnum.SENDING.getCode()); smsSendRecord.setSendStatus(SMSStatusEnum.SENDING.getCode());
smsSendRecord.setSid(resultObj.get("sid")==null?null:resultObj.get("sid").toString()); smsSendRecord.setSid(resultObj.get("sid") == null ? null : resultObj.get("sid").toString());
smsSendRecord.setReason(null); smsSendRecord.setReason(null);
// 修改 // 修改
smsRecordMapper.update(smsSendRecord); smsRecordMapper.update(smsSendRecord);
return AjaxResult.success("重新发送成功"); return AjaxResult.success("重新发送成功");
} else { } else {
smsSendRecord.setSid(resultObj.get("sid")==null?null:resultObj.get("sid").toString()); smsSendRecord.setSid(resultObj.get("sid") == null ? null : resultObj.get("sid").toString());
smsSendRecord.setSendStatus(SMSStatusEnum.FAIL.getCode()); smsSendRecord.setSendStatus(SMSStatusEnum.FAIL.getCode());
smsSendRecord.setSid(resultObj.get("reason")==null?null:resultObj.get("reason").toString()); smsSendRecord.setSid(resultObj.get("reason") == null ? null : resultObj.get("reason").toString());
// 修改 // 修改
smsRecordMapper.update(smsSendRecord); smsRecordMapper.update(smsSendRecord);
return AjaxResult.warn("重新发送失败"); return AjaxResult.warn("重新发送失败");