cleanup dial number

This commit is contained in:
东煌 2020-08-24 11:29:27 +08:00
parent dc956c5ff1
commit 5801bb591b
10 changed files with 34 additions and 12 deletions

View File

@ -4,6 +4,7 @@ import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.tuple.Pair;
import com.pudonghot.yo.util.PhoneNumberUtils;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -50,7 +51,7 @@ public class RespCallingList {
* @return pair
*/
public Pair<String, String> toPair() {
return Pair.of(phone, id);
return Pair.of(PhoneNumberUtils.cleanupMobile(phone), id);
}
}
}

View File

@ -5,7 +5,7 @@ if [ -z "$1" ]; then
exit 1
fi
url="http://localhost:8082/agent-event/fetch/$1"
url="http://localhost:8082/dev/agent-event/fetch/$1"
echo "Listen URL: $url"
count=0

View File

@ -13,14 +13,18 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import com.pudonghot.yo.fsagent.api.request.ReqCampaignDial;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 仅供开发测试验证用
*
* @author Donghuang
* @date Jun 12, 2020 10:04:20
*/
@Slf4j
@Controller
@RequestMapping("/dev")
public class DialController {
@Autowired
private DialService dialService;

View File

@ -57,7 +57,7 @@ public class DialplanService20CampaignToIdAndType extends BaseDialplanService {
String otherDn = params.getCalledNumber();
if (StringUtils.isBlank(otherDn)) {
otherDn = PhoneNumberUtils.cleanupMobile(
otherDn = PhoneNumberUtils.extractMobile(
call.getCallerChannel().getNumber());
}

View File

@ -131,7 +131,7 @@ public class TrunkServiceImpl
if (trunk != null) {
return Pair.of(trunk,
PhoneNumberUtils.cleanupMobile(
PhoneNumberUtils.extractMobile(
calledNumber.substring(prefixLength)));
}
}

View File

@ -28,12 +28,13 @@ public class PhoneNumberUtils {
}
/**
* cleanup mobile
* extract mobile
*
* 01378888666 -> 1378888666
* @param mobile mobile number
* @return mobile cleaned
*/
public static String cleanupMobile(final String mobile) {
public static String extractMobile(final String mobile) {
if (mobile.length() > MOBILE_LENGTH
&& PATTERN_CONTAINS_MOBILE.matcher(mobile).find()) {
return mobile.substring(
@ -42,4 +43,16 @@ public class PhoneNumberUtils {
return mobile;
}
/**
* clean mobile, remove none-number chars then extract mobile
*
* 01378888666; -> 1378888666
* 901378888666; -> 1378888666
* @param mobile mobile number
* @return mobile cleaned
*/
public static String cleanupMobile(final String mobile) {
return extractMobile(mobile.replaceAll("[^\\d]", ""));
}
}

View File

@ -18,7 +18,8 @@ public class PhoneNumberUtilsTest {
log.info("val [{}].", PhoneNumberUtils.isMobile("13164268809"));
log.info("val [{}].", PhoneNumberUtils.isMobile("14164268809"));
log.info("val [{}].", PhoneNumberUtils.isMobile("12164268809"));
log.info("val [{}].", PhoneNumberUtils.cleanupMobile("013564268809"));
log.info("val [{}].", PhoneNumberUtils.cleanupMobile("9010013564268809"));
log.info("val [{}].", PhoneNumberUtils.extractMobile("013564268809"));
log.info("val [{}].", PhoneNumberUtils.extractMobile("9010013564268809"));
log.info("val clean up [{}].", PhoneNumberUtils.cleanupMobile("0100135642-688A9;"));
}
}

View File

@ -62,7 +62,7 @@ public class AgentEventController implements SessionAbility {
*
* @param agentId agent id
*/
@PostMapping("/agent-event/publish/{agentId}")
@PostMapping("/dev/agent-event/publish/{agentId}")
public void publish(
@PathVariable("agentId")
final Integer agentId,
@ -82,7 +82,7 @@ public class AgentEventController implements SessionAbility {
*
* @param agentId agent id
*/
@GetMapping("/agent-event/fetch/{agentId}")
@GetMapping("/dev/agent-event/fetch/{agentId}")
public DeferredResult<RespAgentEvent> fetch(
@PathVariable("agentId")
final Integer agentId) {

View File

@ -5,6 +5,7 @@ import com.wacai.tigon.mybatis.Search;
import com.pudonghot.yo.model.domain.Agent;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.StringUtils;
import com.pudonghot.yo.util.PhoneNumberUtils;
import com.pudonghot.yo.fs.model.domain.Channel;
import com.pudonghot.yo.fsagent.api.DialService;
import org.springframework.stereotype.Controller;
@ -73,6 +74,7 @@ public class CallController implements SessionAbility {
@RequestBody
final ReqAgentDialout args) {
log.info("Dial out [{}].", args);
final Pair<Agent, Channel> agentChannel = find(account);
final Channel channel = agentChannel.getRight();
@ -82,7 +84,8 @@ public class CallController implements SessionAbility {
final ReqAgentDial reqAgentDial = new ReqAgentDial();
reqAgentDial.setTenantId(getTenantId());
reqAgentDial.setAccount(account);
reqAgentDial.setCalledNumber(args.getCalled());
reqAgentDial.setCalledNumber(
PhoneNumberUtils.cleanupMobile(args.getCalled()));
return new RespAgentDialout(dialService.agentDial(reqAgentDial).getUuid());
}

View File

@ -5,7 +5,7 @@ if [ -z "$1" ]; then
exit 1
fi
url="http://localhost:8082/agent-event/publish/$1"
url="http://localhost:8082/dev/agent-event/publish/$1"
echo "Publish URL: $url"
count=0