From 9bf88d9f5fd5a51b46437f9b40a96e616c696abf Mon Sep 17 00:00:00 2001 From: Donghuang Date: Fri, 8 Oct 2021 17:32:46 +0800 Subject: [PATCH] add call recording time --- .../yo/model/domain/CallRecording.java | 3 + .../service/impl/RecordingServiceImpl.java | 49 ++++++--- .../impl}/RecordingServiceTest.java | 16 ++- .../com/pudonghot/yo/state/TestDriver.java | 16 +++ server/src/test/resources/application.yml | 102 ++++++++++++++++++ 5 files changed, 169 insertions(+), 17 deletions(-) rename server/src/test/java/com/pudonghot/yo/fsagent/{ => service/impl}/RecordingServiceTest.java (66%) create mode 100644 server/src/test/resources/application.yml diff --git a/lib/model/src/main/java/com/pudonghot/yo/model/domain/CallRecording.java b/lib/model/src/main/java/com/pudonghot/yo/model/domain/CallRecording.java index 7c2a4d1d..325395b5 100644 --- a/lib/model/src/main/java/com/pudonghot/yo/model/domain/CallRecording.java +++ b/lib/model/src/main/java/com/pudonghot/yo/model/domain/CallRecording.java @@ -2,6 +2,7 @@ package com.pudonghot.yo.model.domain; import lombok.Getter; import lombok.Setter; +import java.util.Date; import me.chyxion.tigon.mybatis.Table; import me.chyxion.tigon.mybatis.Transient; import me.chyxion.tigon.mybatis.NotUpdate; @@ -24,6 +25,8 @@ public class CallRecording extends BaseDomain { private String connId; @NotUpdate private String path; + @NotUpdate + private Date callTime; @Transient private String url; } diff --git a/server/src/main/java/com/pudonghot/yo/fsagent/service/impl/RecordingServiceImpl.java b/server/src/main/java/com/pudonghot/yo/fsagent/service/impl/RecordingServiceImpl.java index 3d711c97..00a5194a 100644 --- a/server/src/main/java/com/pudonghot/yo/fsagent/service/impl/RecordingServiceImpl.java +++ b/server/src/main/java/com/pudonghot/yo/fsagent/service/impl/RecordingServiceImpl.java @@ -1,14 +1,18 @@ package com.pudonghot.yo.fsagent.service.impl; +import lombok.val; import java.io.File; +import java.util.Date; import java.util.Map; import java.util.HashMap; +import lombok.SneakyThrows; +import java.util.regex.Pattern; import lombok.extern.slf4j.Slf4j; import org.springframework.util.Assert; import com.pudonghot.yo.mapper.TenantMapper; -import com.pudonghot.yo.model.domain.Tenant; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.apache.commons.lang3.time.DateUtils; import com.pudonghot.yo.mapper.CallRecordingMapper; import com.pudonghot.yo.model.domain.CallRecording; import com.pudonghot.yo.common.httpclient.HttpClient; @@ -17,7 +21,6 @@ import org.springframework.scheduling.annotation.Async; import com.pudonghot.yo.fsagent.service.RecordingService; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Value; -import com.pudonghot.yo.common.httpclient.HttpRequestResult; import com.pudonghot.yo.common.httpclient.RequestBodyParams; import org.springframework.beans.factory.annotation.Autowired; @@ -47,6 +50,10 @@ public class RecordingServiceImpl @Value("${yo.fsagent.recording.file-ext:.ogg}") private String recordingFileExt; + private final Pattern PATTERN_REC_LOC = + Pattern.compile("^\\w+_(\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2})_\\w+-\\w+\\.\\w+$"); + private final String REC_CALL_TIME_PATTERN = "yyyy-MM-dd_HH-mm-ss"; + /** * {@inheritDoc} */ @@ -54,7 +61,7 @@ public class RecordingServiceImpl @Override public void postRecording(final Integer tenantId, final String location) { log.info("Post recording file [{}].", location); - final File file = new File(location); + val file = new File(location); if (!file.exists()) { log.warn("Recording file [{}] does not exist.", file); @@ -63,19 +70,21 @@ public class RecordingServiceImpl uploadRec(file); - final String name = file.getName(); + val name = file.getName(); + val connId = name.substring(0, name.indexOf("_")); - final String connId = name.substring(0, name.indexOf("_")); if (StringUtils.isNotBlank(connId)) { - final Tenant tenant = tenantMapper.find(tenantId); + val tenant = tenantMapper.find(tenantId); Assert.state(tenant != null, () -> "No tenant [" + tenantId + "] found"); - final CallRecording callRec = new CallRecording(); + val callRec = new CallRecording(); callRec.setTenantId(tenantId); callRec.setTenantCode(tenant.getCode()); callRec.setConnId(connId); + callRec.setCallTime(getCallTime(name)); callRec.setPath(name); + log.info("Insert call [{}] recording [{}].", connId, callRec); callRecordingMapper.insert(callRec); } @@ -92,10 +101,10 @@ public class RecordingServiceImpl final String callerNumber, final String calledNumber) { - final long now = System.currentTimeMillis(); + val now = System.currentTimeMillis(); return recDir + DateFormatUtils.format(now, "/yyyy/MM/dd/HH/") + connId + "_" + - DateFormatUtils.format(now, "yyyy-MM-dd_HH-mm-ss") + "_" + + DateFormatUtils.format(now, REC_CALL_TIME_PATTERN) + "_" + callerNumber + "-" + calledNumber + recordingFileExt; @@ -115,16 +124,28 @@ public class RecordingServiceImpl return; } - final String url = fileServerBasePath + file.getName(); - final RequestBodyParams params = - new RequestBodyParams<>(file); + val url = fileServerBasePath + file.getName(); + val params = new RequestBodyParams(file); params.setHeaders(REQ_HEADERS); - final HttpRequestResult result = httpClient.put(url, params); - final int status = result.getStatus(); + val result = httpClient.put(url, params); + val status = result.getStatus(); log.info("Upload recording file [{}] result [{}]", url, status); if (status >= 200 && status < 300) { log.info("Upload recording file [{}] successfully, delete file.", file); file.delete(); } } + + @SneakyThrows + Date getCallTime(final String recName) { + val m = PATTERN_REC_LOC.matcher(recName); + if (m.matches()) { + val callTime = m.group(1); + log.debug("Rec [{}] call time [{}] parsed.", recName, callTime); + return DateUtils.parseDate(callTime, REC_CALL_TIME_PATTERN); + } + + log.debug("Rec [{}] no call time parsed, use now.", recName); + return new Date(); + } } diff --git a/server/src/test/java/com/pudonghot/yo/fsagent/RecordingServiceTest.java b/server/src/test/java/com/pudonghot/yo/fsagent/service/impl/RecordingServiceTest.java similarity index 66% rename from server/src/test/java/com/pudonghot/yo/fsagent/RecordingServiceTest.java rename to server/src/test/java/com/pudonghot/yo/fsagent/service/impl/RecordingServiceTest.java index a386d927..d65d8378 100644 --- a/server/src/test/java/com/pudonghot/yo/fsagent/RecordingServiceTest.java +++ b/server/src/test/java/com/pudonghot/yo/fsagent/service/impl/RecordingServiceTest.java @@ -1,14 +1,17 @@ -package com.pudonghot.yo.fsagent; +package com.pudonghot.yo.fsagent.service.impl; -import com.pudonghot.yo.YoServer; +import lombok.val; import org.junit.Test; import org.junit.runner.RunWith; import lombok.extern.slf4j.Slf4j; +import com.pudonghot.yo.YoServer; import com.pudonghot.yo.fsagent.service.RecordingService; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.util.Date; + /** * @author Donghuang * @date Jul 24, 2020 15:38:41 @@ -19,11 +22,18 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; public class RecordingServiceTest { @Autowired - private RecordingService recordingService; + private RecordingServiceImpl recordingService; @Test public void testRecordingLoc() { log.info("Rec location [{}].", recordingService.recLoc("AAA", "donghuang", "bingpo")); } + + @Test + public void testCallTime() { + val name = "615ff67285301479ccb256d7_2021-10-08_15-43-01_800435-0ee07e1711b367df06796327c05b7ec7.mp3"; + val callTime = recordingService.getCallTime(name); + log.info("Call time [{}].", callTime); + } } diff --git a/server/src/test/java/com/pudonghot/yo/state/TestDriver.java b/server/src/test/java/com/pudonghot/yo/state/TestDriver.java index f0fd1a96..d1b2980e 100644 --- a/server/src/test/java/com/pudonghot/yo/state/TestDriver.java +++ b/server/src/test/java/com/pudonghot/yo/state/TestDriver.java @@ -2,8 +2,13 @@ package com.pudonghot.yo.state; import java.util.Date; import java.util.UUID; + +import lombok.val; import org.junit.Test; import java.util.Calendar; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.time.DateUtils; @@ -31,4 +36,15 @@ public class TestDriver { log.info("Yesterday [{}].", DateUtils.addDays( DateUtils.truncate(new Date(), Calendar.DATE), -1)); } + + @Test + public void testRecLoc() { + val name = "615ff67285301479ccb256d7_2021-10-08_15-43-01_800435-0ee07e1711b367df06796327c05b7ec7.mp3"; + val pattern = Pattern.compile("^\\w+_(\\d{4}-\\d{2}-\\d{2})_(\\d{2})-(\\d{2})-(\\d{2})_\\w+-\\w+\\.\\w+$"); + val m = pattern.matcher(name); + if (m.matches()) { + log.info("Date: {}.", m.group(1)); + log.info("Time: {}:{}:{}.", m.group(2), m.group(3), m.group(4)); + } + } } diff --git a/server/src/test/resources/application.yml b/server/src/test/resources/application.yml new file mode 100644 index 00000000..d81c7d8f --- /dev/null +++ b/server/src/test/resources/application.yml @@ -0,0 +1,102 @@ +server: + port: 8083 + error: + include-stacktrace: ALWAYS + shutdown: GRACEFUL + +tigon: + web: + jsonview: + success-key: success + code-key: retcode + code-type: string + message-key: message + data-key: + +spring: + application: + name: yo-server + lifecycle: + # Allow grace timeout period for 42 seconds + timeout-per-shutdown-phase: 42s + freemarker: + cache: false + settings: + number_format: computer + suffix: '' + template-loader-path: classpath:/templates + jackson: + serialization: + fail-on-empty-beans: false + write-dates-as-timestamps: true + time-zone: GMT+8 + redis: + host: localhost + port: 6379 + password: 123456 + redisson: + lock-watchdog-timeout: 5000 + +dubbo: + application: + qos-accept-foreign-ip: false + qos-enable: true + qos-port: 22222 + protocol: + name: dubbo + port: -1 + provider: + retries: 0 + timeout: 24000 + registry: + address: zookeeper://localhost:2181 + file: ${user.home}/dubbo-cache/${spring.application.name}/dubbo.cache + scan: + base-packages: com.pudonghot.yo + +yo: + datasource: + url: jdbc:mysql://localhost/yoqw?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai + username: yoqw + password: yoqw_query! + esl: + client: + host: 192.168.3.7 + freeswitch: + datasource: + url: jdbc:mysql://localhost/fs_dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai + username: freeswitch + password: RR!h5IpirsnJ + fsagent: + agent-status: + audio: + not-ready: + ok: http://172.16.46.35/voice/20191126/5ddcd2ca82745b00016922d1.wav + err: http://172.16.46.35/voice/20191126/5ddcfef282745b00016922d9.wav + ready: + ok: http://172.16.46.35/voice/20191126/5ddcd2c882745b00016922cd.wav + err: http://172.16.46.35/voice/20191126/5ddcfef182745b00016922d5.wav + dubbo: + service: + version: 1.0.0 + recording-server: + base-path: http://172.16.52.80/fs/rec/ + campaign: + task-scheduler: + fixed-rate: 8000 + dial-batch: 36 + calling-list: + task-scheduler: + fixed-rate: 240000 + batch-cron: 12 12 0 * * * + citic: + feign: + # base-url: http://stsl.wldmz.cc/stsl-web-partner + base-url: http://e.test.bank.ecitic.com/citiccard/stsl-web-partner + path: + calling-list: /call-data/taskdata/dx-hzqw + black-list-verify: /resource/black-list/verify + black-list-batch-verify: /resource/black-list/batch-verify + black-list: + verify: true + batch-verify: true