opt store CDR
This commit is contained in:
parent
dcfd38c756
commit
f84695eb5f
@ -8,6 +8,11 @@ import java.util.Map;
|
||||
*/
|
||||
public interface CommonCallDataService {
|
||||
|
||||
/**
|
||||
* reset all data
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* save call data
|
||||
*
|
||||
|
@ -37,12 +37,17 @@ public interface CommonCampaignService {
|
||||
void start(String campaignKey);
|
||||
|
||||
/**
|
||||
* start campaign
|
||||
* stop campaign
|
||||
*
|
||||
* @param campaignKey campaign key
|
||||
*/
|
||||
void stop(String campaignKey);
|
||||
|
||||
/**
|
||||
* stop all campaign
|
||||
*/
|
||||
void stopAll();
|
||||
|
||||
/**
|
||||
* update campaign status
|
||||
*
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.pudonghot.yo.service.impl;
|
||||
|
||||
import lombok.val;
|
||||
import java.util.Map;
|
||||
import com.wacai.tigon.json.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -31,6 +32,16 @@ public class CommonCallDataServiceImpl implements CommonCallDataService {
|
||||
this.CAMPAIGN_DATA = redisson.getMapCache("CAMPAIGN_DATA", IntegerCodec.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
log.info("Reset call data.");
|
||||
CACHE.clear();
|
||||
CAMPAIGN_DATA.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@ -64,7 +75,7 @@ public class CommonCallDataServiceImpl implements CommonCallDataService {
|
||||
@Override
|
||||
public Map<String, Object> getCampaignCallData(final String callUuid) {
|
||||
log.debug("Get campaign call data [{}].", callUuid);
|
||||
final String data = CACHE.get(callUuid);
|
||||
val data = CACHE.get(callUuid);
|
||||
return StringUtils.isNotBlank(data) ? json.parse(data, Map.class) : null;
|
||||
}
|
||||
|
||||
@ -73,7 +84,7 @@ public class CommonCallDataServiceImpl implements CommonCallDataService {
|
||||
*/
|
||||
@Override
|
||||
public Integer getCampaignChannel(final Integer campaignId) {
|
||||
final Integer val = CAMPAIGN_DATA.getOrDefault(channelKey(campaignId), 0);
|
||||
val val = CAMPAIGN_DATA.getOrDefault(channelKey(campaignId), 0);
|
||||
log.debug("Get campaign [{}] channel [{}].", campaignId, val);
|
||||
return val;
|
||||
}
|
||||
@ -83,7 +94,7 @@ public class CommonCallDataServiceImpl implements CommonCallDataService {
|
||||
*/
|
||||
@Override
|
||||
public Integer incrCampaignChannel(final Integer campaignId) {
|
||||
final Integer val = CAMPAIGN_DATA.addAndGet(channelKey(campaignId), 1);
|
||||
val val = CAMPAIGN_DATA.addAndGet(channelKey(campaignId), 1);
|
||||
log.info("Increase campaign [{}] channel [{}].", campaignId, val);
|
||||
return val;
|
||||
}
|
||||
@ -93,8 +104,13 @@ public class CommonCallDataServiceImpl implements CommonCallDataService {
|
||||
*/
|
||||
@Override
|
||||
public Integer decrCampaignChannel(final Integer campaignId) {
|
||||
final Integer val = CAMPAIGN_DATA.addAndGet(channelKey(campaignId), -1);
|
||||
val channelKey = channelKey(campaignId);
|
||||
val val = CAMPAIGN_DATA.addAndGet(channelKey, -1);
|
||||
log.info("Decrease campaign [{}] channel [{}].", campaignId, val);
|
||||
if (val < 0) {
|
||||
log.warn("Campaign [{}] negative channel [{}].", campaignId, val);
|
||||
CAMPAIGN_DATA.put(channelKey, 0);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
@ -103,7 +119,7 @@ public class CommonCallDataServiceImpl implements CommonCallDataService {
|
||||
*/
|
||||
@Override
|
||||
public Integer resetCampaignChannel(final Integer campaignId) {
|
||||
final Integer val = CAMPAIGN_DATA.remove(channelKey(campaignId));
|
||||
val val = CAMPAIGN_DATA.remove(channelKey(campaignId));
|
||||
log.info("Reset campaign [{}] channel [{}].", campaignId, val);
|
||||
return val;
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.pudonghot.yo.service.impl;
|
||||
|
||||
import lombok.val;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chyxion.tigon.mybatis.Search;
|
||||
import org.springframework.util.Assert;
|
||||
@ -100,6 +103,20 @@ public class CommonCampaignServiceImpl
|
||||
updateStatus(findValid(campaignKey), Campaign.Status.STOPPED);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void stopAll() {
|
||||
log.info("Stop all campaigns.");
|
||||
val update = new HashMap<String, Object>(4);
|
||||
update.put(Campaign.STATUS, Campaign.Status.STOPPED);
|
||||
update.put(Campaign.UPDATED_BY, "SYSTEM");
|
||||
update.put(Campaign.UPDATED_TIME, new Date());
|
||||
mapper.update(update, new Search()
|
||||
.eq(Campaign.STATUS, Campaign.Status.RUNNING));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -0,0 +1,8 @@
|
||||
package com.pudonghot.yo.campaign.service;
|
||||
|
||||
/**
|
||||
* @author Donghuang
|
||||
* @date Sep 14, 2021 19:22:27
|
||||
*/
|
||||
public interface CampaignStatusScheduleService {
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.pudonghot.yo.campaign.service.impl;
|
||||
|
||||
import com.pudonghot.yo.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.pudonghot.yo.campaign.service.CampaignStatusScheduleService;
|
||||
|
||||
/**
|
||||
* @author Donghuang
|
||||
* @date Sep 14, 2021 19:24:15
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CampaignStatusScheduleServiceImpl implements CampaignStatusScheduleService {
|
||||
|
||||
@Autowired
|
||||
private CommonCampaignService commonCampaignService;
|
||||
@Autowired
|
||||
private CommonCallDataService commonCallDataService;
|
||||
@Autowired
|
||||
private LeaderElectionService leaderElectionService;
|
||||
|
||||
@Scheduled(cron = "${yo.campaign.reset.cron:1 1 1 * * *}")
|
||||
public void resetCampaign() {
|
||||
if (!leaderElectionService.isLeader()) {
|
||||
log.debug("Server is not leader, ignore campaign reset scheduler task.");
|
||||
return;
|
||||
}
|
||||
|
||||
commonCampaignService.stopAll();
|
||||
commonCallDataService.reset();
|
||||
}
|
||||
}
|
@ -29,6 +29,6 @@ public class CallDetailRecordServiceImpl
|
||||
public void insert(final CallDetailRecordBase req) {
|
||||
log.debug("Insert call detail [{}].", req);
|
||||
callDetailRecordAllMapper.insert(req);
|
||||
// callDetailRecordMapper.insert(req);
|
||||
callDetailRecordMapper.insert(req);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user