Commit fe5309b5 authored by kongfm's avatar kongfm

更新tzs119

parent f8449fec
package com.yeejoin.amos.boot.module.tzs.api.service;
import com.yeejoin.amos.boot.module.tzs.api.dto.VoiceRecordFileDto;
/**
* 通话记录附件接口类
*
......@@ -9,4 +11,6 @@ package com.yeejoin.amos.boot.module.tzs.api.service;
*/
public interface IVoiceRecordFileService {
void publishRecord(VoiceRecordFileDto model);
}
......@@ -15,6 +15,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -54,9 +55,6 @@ public class VoiceRecordFileController extends BaseController {
@Autowired
AlertCalledServiceImpl iAlertCalledService;
@Autowired
ICtiService ctiService;
/**
* 新增通话记录附件
*
......@@ -123,56 +121,15 @@ public class VoiceRecordFileController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/saveRecord")
@ApiOperation(httpMethod = "POST", value = "新增通话记录附件", notes = "新增通话记录附件")
public ResponseModel<VoiceRecordFileDto> saveRecord(@RequestBody VoiceRecordFileDto model) {
public ResponseModel<Boolean> saveRecord(@RequestBody VoiceRecordFileDto model) {
if (ValidationUtil.isEmpty(model.getAlertId())
|| ValidationUtil.isEmpty(model.getConnectId())){
throw new BadRequest("参数校验失败.");
}
// 获取通话人信息
JSONArray recordInfos = ctiService.getCallInfo(model.getConnectId());
if(recordInfos == null || recordInfos.size() == 0) {
throw new BadRequest("未找到通话详单信息");
}
JSONObject recordInfo = recordInfos.getJSONObject(0);
model.setTel(recordInfo.getString("telephone"));
voiceRecordFileServiceImpl.publishRecord(model);
return ResponseHelper.buildResponse(true);
}
Date telStartTime = null;
Date telEndTime = null;
try {
telStartTime = DateUtils.longStr2Date(recordInfo.getString("connectTime"));
telEndTime = DateUtils.longStr2Date(recordInfo.getString("hangupTime"));
} catch (Exception e) {
throw new BadRequest("日期转换错误");
}
model.setTelStartTime(telStartTime);
model.setTelEndTime(telEndTime);
if(1 == recordInfo.getInteger("callType")) {
model.setFileType("客户呼入");
} else if(2 == recordInfo.getInteger("callType")) {
model.setFileType("坐席呼出");
}
// 获取附件 需要延时5S
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Map<String, String> downloadFile = ctiService.downLoadRecordFile(recordInfo.getString("connectionid"));
if(downloadFile.isEmpty()) {
throw new BadRequest("未找到附件文件");
}
for(Map.Entry<String,String> file : downloadFile.entrySet()) {
model.setFilePath(file.getKey());
}
AlertCalledFormDto alertDto = iAlertCalledService.selectAlertCalledByIdNoCache(model.getAlertId());
if(alertDto == null || alertDto.getAlertCalledDto() == null) {
throw new BadRequest("未找到相关警情");
}
model.setAlertStage(alertDto.getAlertCalledDto().getAlertStage());
model.setAlertStageCode(alertDto.getAlertCalledDto().getAlertStageCode());
model.setSourceId(-1l);
model = voiceRecordFileServiceImpl.createWithModel(model);
return ResponseHelper.buildResponse(model);
}
}
package com.yeejoin.amos.boot.module.tzs.biz.core.async;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
@Configuration
public class TaskExecutorPoolConfig {
@Bean("asyncTaskExecutor")
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);//线程池维护线程的最少数量
executor.setMaxPoolSize(100); //线程池维护线程的最大数量
executor.setQueueCapacity(100);
executor.setKeepAliveSeconds(30);//线程池维护线程所允许的空闲时间,TimeUnit.SECONDS
executor.setThreadNamePrefix("asyncTaskExecutor-");
// 线程池对拒绝任务的处理策略: CallerRunsPolicy策略,当线程池没有处理能力的时候,该策略会直接在 execute 方法的调用线程中运行被拒绝的任务;如果执行程序已关闭,则会丢弃该任务
// executor.setRejectedExecutionHandler(ThreadPoolExecutor.CallerRunsPolicy());
return executor;
}
}
package com.yeejoin.amos.boot.module.tzs.biz.core.threadpool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 线程池
*/
public class AmosThreadPool {
/**
* 日志记录器
*/
private static final Logger log = LoggerFactory.getLogger(AmosThreadPool.class);
/**
* 单例
*/
private static AmosThreadPool instance;
/**
* 执行服务
*/
private static ExecutorService executorService;
/**
* 获取单例
*
* @return
*/
public static AmosThreadPool getInstance() {
if (instance == null) {
synchronized (AmosThreadPool.class) {
if (instance == null) {
instance = new AmosThreadPool();
}
}
}
return instance;
}
static {
executorService = Executors
.newFixedThreadPool(20);
}
/**
* 执行线程
*
* @param task
*/
public void execute(Runnable task) {
executorService.execute(task);
}
}
......@@ -121,6 +121,7 @@ public class CtiServiceImpl implements ICtiService {
Map<String,String> header = new HashMap<>();
header.put("accessToken",token);
String responseStr = HttpUtils.doPostWithHeader(url,params.toJSONString(),header);
JSONObject response = null;
try {
response = JSONObject.parseObject(responseStr);
......
package com.yeejoin.amos.boot.module.tzs.biz.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.feign.AmosFeignService;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledFormDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.VoiceRecordFileDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.VoiceRecordFile;
import com.yeejoin.amos.boot.module.tzs.api.mapper.VoiceRecordFileMapper;
import com.yeejoin.amos.boot.module.tzs.api.service.ICtiService;
import com.yeejoin.amos.boot.module.tzs.api.service.IVoiceRecordFileService;
import com.yeejoin.amos.boot.module.tzs.api.dto.VoiceRecordFileDto;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 通话记录附件服务实现类
......@@ -17,6 +31,25 @@ import java.util.List;
*/
@Service
public class VoiceRecordFileServiceImpl extends BaseService<VoiceRecordFileDto,VoiceRecordFile,VoiceRecordFileMapper> implements IVoiceRecordFileService {
@Autowired
private VoiceRecordFileServiceImpl voiceRecordFileServiceImpl;
private final Logger logger = LogManager.getLogger(AmosFeignService.class);
@Autowired
AlertCalledServiceImpl iAlertCalledService;
@Autowired
ICtiService ctiService;
private volatile JSONArray ctiInfos;
@Autowired
EmqKeeper emqKeeper;
private String ctiMessage = "/cti/callphone";
/**
* 分页查询
*/
......@@ -30,4 +63,69 @@ public class VoiceRecordFileServiceImpl extends BaseService<VoiceRecordFileDto,V
public List<VoiceRecordFileDto> queryForVoiceRecordFileList() {
return this.queryForList("" , false);
}
@Override
public void publishRecord(final VoiceRecordFileDto model) {
Long now = System.currentTimeMillis();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Long end = System.currentTimeMillis();
// 获取通话人信息
ctiInfos = ctiService.getCallInfo(model.getConnectId());
if(ctiInfos == null || ctiInfos.size() == 0) {
logger.error("未找到通话详单信息" + (end-now));
}
JSONObject recordInfo = ctiInfos.getJSONObject(0);
model.setTel(recordInfo.getString("telephone"));
Date telStartTime = null;
Date telEndTime = null;
try {
telStartTime = DateUtils.longStr2Date(recordInfo.getString("connectTime"));
telEndTime = DateUtils.longStr2Date(recordInfo.getString("hangupTime"));
} catch (Exception e) {
logger.error("日期转换错误");
}
model.setTelStartTime(telStartTime);
model.setTelEndTime(telEndTime);
if(1 == recordInfo.getInteger("callType")) {
model.setFileType("客户呼入");
} else if(2 == recordInfo.getInteger("callType")) {
model.setFileType("坐席呼出");
}
Map<String, String> downloadFile = ctiService.downLoadRecordFile(recordInfo.getString("connectionid"));
if(downloadFile.isEmpty()) {
logger.error("未找到附件文件");
}
for(Map.Entry<String,String> file : downloadFile.entrySet()) {
model.setFilePath(file.getKey());
}
AlertCalledFormDto alertDto = iAlertCalledService.selectAlertCalledByIdNoCache(model.getAlertId());
if(alertDto == null || alertDto.getAlertCalledDto() == null) {
logger.error("未找到相关警情");
}
model.setAlertStage(alertDto.getAlertCalledDto().getAlertStage());
model.setAlertStageCode(alertDto.getAlertCalledDto().getAlertStageCode());
model.setSourceId(-1l);
voiceRecordFileServiceImpl.createWithModel(model);
JSONObject json = new JSONObject();
json.put("code","1001");
json.put("type","addRecord");
try {
emqKeeper.getMqttClient().publish(ctiMessage, json.toJSONString().getBytes(), 2, false);
} catch (MqttException e) {
logger.error("推送失败");
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment