Merge branch 'bgy' of SH-Arbitrate/Mediation-Backend into dev

This commit was merged in pull request #145.
This commit is contained in:
bgy
2024-04-18 18:37:41 +08:00
committed by Gitea
5 changed files with 92 additions and 44 deletions
@@ -4,15 +4,23 @@ import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
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.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.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.MsSmsSendRecordParamMapper;
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.mapper.sendrecord.SmsRecordMapper;
import com.ruoyi.wisdomarbitrate.service.shortmessage.ShortMessageService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Example;
@@ -32,13 +40,15 @@ public class ShortMessageController extends BaseController {
MsSmsSendRecordParamMapper recordParamMapper;
@Autowired
MsSmsSendHistoryRecordParamMapper historyRecordParamMapper;
/**
* 查询短信发送记录
*
* @param smsSendRecord
* @return
*/
@GetMapping("/recordList")
public TableDataInfo smsSendRecordList( SmsSendRecord smsSendRecord){
public TableDataInfo smsSendRecordList(SmsSendRecord smsSendRecord) {
startPage();
List<SmsSendRecord> list = shortMessageService.smsSendRecordList(smsSendRecord);
return getDataTable(list);
@@ -47,17 +57,17 @@ public class ShortMessageController extends BaseController {
@Anonymous
@PostMapping("/updateSendContent")
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("参数校验失败");
}
// 查询当前版本记录
// 查询当前版本记录
SmsSendRecord oldSendRecord = smsRecordMapper.selectById(smsSendRecord.getId());
smsSendRecord.setUpdateTime(new Date());
// 更新短信内容,先删除短信记录参数表
Example recordParamExam = new Example(MsSmsSendRecordParam.class);
recordParamExam.createCriteria().andEqualTo("smsRecordId", smsSendRecord.getId());
recordParamMapper.deleteByExample(recordParamExam);
// 新增短信记录参数表
// 更新短信内容,先删除短信记录参数表
Example recordParamExam = new Example(MsSmsSendRecordParam.class);
recordParamExam.createCriteria().andEqualTo("smsRecordId", smsSendRecord.getId());
recordParamMapper.deleteByExample(recordParamExam);
// 新增短信记录参数表
List<MsSmsSendRecordParam> recordParams = new ArrayList<>();
for (MsSmsTemplateParam templateParam : smsSendRecord.getTemplateParams()) {
MsSmsSendRecordParam recordParam = new MsSmsSendRecordParam();
@@ -65,9 +75,9 @@ public class ShortMessageController extends BaseController {
recordParam.setParamValue(templateParam.getParamValue());
recordParams.add(recordParam);
}
recordParamMapper.batchInsert(recordParams);
shortMessageService.insertShortMessageHistoryRecord(oldSendRecord,recordParams);
return AjaxResult.success();
recordParamMapper.batchInsert(recordParams);
shortMessageService.insertShortMessageHistoryRecord(oldSendRecord, recordParams);
return AjaxResult.success();
}
@@ -84,14 +94,32 @@ public class ShortMessageController extends BaseController {
return AjaxResult.error("参数缺失");
}
@Autowired
MeetingInfoMapper meetingInfoMapper;
@Autowired
SysUserMapper sysUserMapper;
@Autowired
private TokenService tokenService;
/**
* 查询UID好的密钥
*/
@Anonymous
@GetMapping("/getMeetingInfo")
public Object getEncryptInfoByUid(@RequestParam(name = "authId", required = true) String authId) {
MeetingInfoVO result = new MeetingInfoVO();
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 AjaxResult.error("查询失败");
@@ -127,7 +127,20 @@ public class TokenService
redisCache.setCacheObject(CacheConstants.LOGIN_USERNAME_TOKEN_KEY+loginUser.getUsername(),createToken, expireTime, TimeUnit.MINUTES);
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分钟,自动刷新缓存
*
@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.Date;
import java.util.List;
@Service
@@ -46,6 +47,7 @@ public class SendMailRecordServiceImpl implements ISendMailRecordService {
msSendMailHistoryRecord.setParentId(old.getId());
msSendMailHistoryRecord.setId(null);
msSendMailHistoryRecordMapper.insertSelective(msSendMailHistoryRecord);
sendMailRecord.setUpdateTime(new Date());
sendMailRecordMapper.updateSendMailRecord(sendMailRecord);
return AjaxResult.success("编辑成功");
} else {
@@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONObject;
import com.ruoyi.common.constant.Constants;
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.system.domain.entity.shortmessage.MeetingInfo;
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.MsSmsTemplate;
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.MsSmsSendHistoryRecordMapper;
import com.ruoyi.system.mapper.sms.MsSmsSendHistoryRecordParamMapper;
@@ -56,11 +59,11 @@ public class ShortMessageServiceImpl implements ShortMessageService {
@Override
public List<SmsSendRecord> smsSendRecordList(SmsSendRecord smsSendRecord) {
List<SmsSendRecord> records = smsRecordMapper.getSmsSendRecord(smsSendRecord);
if(CollectionUtil.isEmpty(records)){
if (CollectionUtil.isEmpty(records)) {
return null;
}
List<Long> templateIds = records.stream().map(SmsSendRecord::getMsSmsTemplateId).collect(Collectors.toList());
if(CollectionUtil.isEmpty(templateIds)){
if (CollectionUtil.isEmpty(templateIds)) {
return records;
}
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);
recordParamExam.createCriteria().andIn("smsRecordId", ids);
List<MsSmsSendRecordParam> recordParams = recordParamMapper.selectByExample(recordParamExam);
if(CollectionUtil.isEmpty(recordParams)){
if (CollectionUtil.isEmpty(recordParams)) {
return records;
}
// 根据模板id查询模板参数
Example templateParamExam = new Example(MsSmsTemplateParam.class);
templateParamExam.createCriteria().andIn("smsTemplateId", templateIds);
List<MsSmsTemplateParam> templateParams = templateParamMapper.selectByExample(templateParamExam);
if(CollectionUtil.isEmpty(templateParams)){
if (CollectionUtil.isEmpty(templateParams)) {
return records;
}
// 根据模板id对模板参数分组
@@ -85,17 +88,17 @@ public class ShortMessageServiceImpl implements ShortMessageService {
Map<Long, List<String>> recordParamContentMap = new HashMap<>();
for (MsSmsSendRecordParam recordParam : recordParams) {
List<String> list = recordParamContentMap.get(recordParam.getSmsRecordId());
if(CollectionUtil.isEmpty(list)){
list=new ArrayList<>();
if (CollectionUtil.isEmpty(list)) {
list = new ArrayList<>();
}
list.add(recordParam.getParamValue());
recordParamContentMap.put(recordParam.getSmsRecordId(),list);
recordParamContentMap.put(recordParam.getSmsRecordId(), list);
}
// 根据模板id查询模板
Example templateExam = new Example(MsSmsTemplate.class);
templateExam.createCriteria().andIn("id", templateIds);
List<MsSmsTemplate> templates = templateMapper.selectByExample(templateExam);
if(CollectionUtil.isEmpty(templates)){
if (CollectionUtil.isEmpty(templates)) {
return records;
}
// 根据主键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));
// 组装模板内容
for (SmsSendRecord record : records) {
if(record.getMsSmsTemplateId()==null){
if (record.getMsSmsTemplateId() == null) {
continue;
}
if(!templateMap.containsKey(record.getMsSmsTemplateId())){
if (!templateMap.containsKey(record.getMsSmsTemplateId())) {
continue;
}
if(!recordParamContentMap.containsKey(record.getId())){
if (!recordParamContentMap.containsKey(record.getId())) {
continue;
}
if(templateIdMap.containsKey(record.getMsSmsTemplateId())){
record.setTemplateId(templateIdMap.get(record.getMsSmsTemplateId()));
if (templateIdMap.containsKey(record.getMsSmsTemplateId())) {
record.setTemplateId(templateIdMap.get(record.getMsSmsTemplateId()));
}
String templateContent = templateMap.get(record.getMsSmsTemplateId());
record.setTemplateContent(templateContent);
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());
ArrayList<MsSmsTemplateParam> copyParamList = new ArrayList<>();
for (int i = 0; i < templateParamList.size(); i++) {
MsSmsTemplateParam templateParam = templateParamList.get(i);
MsSmsTemplateParam msSmsTemplateParam =new MsSmsTemplateParam();
MsSmsTemplateParam msSmsTemplateParam = new MsSmsTemplateParam();
msSmsTemplateParam.setParam(templateParam.getParam());
msSmsTemplateParam.setSmsTemplateId(templateParam.getSmsTemplateId());
msSmsTemplateParam.setParamName(templateParam.getParamName());
@@ -136,8 +139,8 @@ public class ShortMessageServiceImpl implements ShortMessageService {
}
// 按顺序替换占位符
if(CollectionUtil.isNotEmpty(recordParamList)){
recordParamList.add(0,"0");
if (CollectionUtil.isNotEmpty(recordParamList)) {
recordParamList.add(0, "0");
// 将List<String>转换为String[]数组
String[] paramArray = recordParamList.toArray(new String[recordParamList.size()]);
@@ -150,6 +153,7 @@ public class ShortMessageServiceImpl implements ShortMessageService {
return records;
}
/**
* 新增发送历史记录
*
@@ -157,19 +161,19 @@ public class ShortMessageServiceImpl implements ShortMessageService {
*/
@Transactional
@Override
public void insertShortMessageHistoryRecord(SmsSendRecord smsSendRecord,List<MsSmsSendRecordParam> recordParams) {
if(smsSendRecord!=null){
MsSmsSendHistoryRecord historyRecord=new MsSmsSendHistoryRecord();
BeanUtils.copyProperties(smsSendRecord,historyRecord);
public void insertShortMessageHistoryRecord(SmsSendRecord smsSendRecord, List<MsSmsSendRecordParam> recordParams) {
if (smsSendRecord != null) {
MsSmsSendHistoryRecord historyRecord = new MsSmsSendHistoryRecord();
BeanUtils.copyProperties(smsSendRecord, historyRecord);
historyRecord.setId(null);
historyRecord.setParentId(smsSendRecord.getId());
int i = msSmsSendHistoryRecordMapper.insert(historyRecord);
if(i>0 && CollectionUtil.isNotEmpty(recordParams)){
if (i > 0 && CollectionUtil.isNotEmpty(recordParams)) {
// 新增参数表
List<MsSmsSendHistoryRecordParam> historyRecordParams = new ArrayList<>();
for (MsSmsSendRecordParam templateParam : recordParams) {
MsSmsSendHistoryRecordParam recordParam = new MsSmsSendHistoryRecordParam();
BeanUtils.copyProperties(templateParam,recordParam);
BeanUtils.copyProperties(templateParam, recordParam);
recordParam.setId(null);
recordParam.setSmsRecordHistoryId(historyRecord.getId());
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) {
// 根据id查询短信记录
SmsSendRecord smsSendRecord = smsRecordMapper.selectById(reSendMessageVO.getId());
if(smsSendRecord == null){
if (smsSendRecord == null) {
return AjaxResult.warn("短信记录不存在");
}
@@ -204,16 +208,16 @@ public class ShortMessageServiceImpl implements ShortMessageService {
// 修改sid和状态
if (resultObj.get("status") != null && !resultObj.get("status").equals(SMSStatusEnum.FAIL.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);
// 修改
smsRecordMapper.update(smsSendRecord);
return AjaxResult.success("重新发送成功");
} 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.setSid(resultObj.get("reason")==null?null:resultObj.get("reason").toString());
smsSendRecord.setSid(resultObj.get("reason") == null ? null : resultObj.get("reason").toString());
// 修改
smsRecordMapper.update(smsSendRecord);
return AjaxResult.warn("重新发送失败");
@@ -62,10 +62,11 @@
</insert>
<update id="updateSendMailRecord">
update ms_send_mail_record
set mail_content= #{mailContent},
update_time=#{updateTime},
send_time=#{sendTime},
send_status=#{sendStatus}
set
<if test="mailContent != null ">mail_content= #{mailContent}</if>
<if test="updateTime != null ">,update_time=#{updateTime}</if>
<if test="sendTime != null ">,send_time=#{sendTime}</if>
<if test="sendStatus != null ">,send_status=#{sendStatus}</if>
where id = #{id}
</update>
<select id="querySendMailRecordById" resultMap="SendMailRecordResult">