|
|
@@ -6,15 +6,23 @@ import com.fs.aiSipCall.RemoteCommon;
|
|
|
import com.fs.aiSipCall.domain.AiSipCallUser;
|
|
|
import com.fs.aiSipCall.mapper.AiSipCallUserMapper;
|
|
|
import com.fs.aiSipCall.service.IAiSipCallUserService;
|
|
|
+import com.fs.aiSipCall.vo.CcExtNumVo;
|
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
|
+import com.fs.common.core.page.TableDataInfo;
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
+import com.fs.company.domain.Company;
|
|
|
+import com.fs.company.mapper.CompanyMapper;
|
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
|
+import com.fs.system.mapper.SysUserMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* sip用户信息Service业务层处理
|
|
|
@@ -26,12 +34,34 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class AiSipCallUserServiceImpl extends ServiceImpl<AiSipCallUserMapper, AiSipCallUser> implements IAiSipCallUserService {
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
|
private CompanyUserMapper companyUserMapper;
|
|
|
+ @Autowired
|
|
|
+ private CompanyMapper companyMapper;
|
|
|
+ /** 是否使用自己线路 */
|
|
|
+ @Value(value = "${sip.call.myGateway:false}")
|
|
|
+ private boolean isMyGateway;
|
|
|
+ /** 使用手动线路前缀 */
|
|
|
+ @Value(value = "${sip.call.manualGatewayPrefix:weizhi}")
|
|
|
+ private String manualGatewayPrefix;
|
|
|
+ /** 使用公共线路前缀 */
|
|
|
+ @Value(value = "${sip.call.publicGatewayPrefix:outbound}")
|
|
|
+ private String publicGatewayPrefix;
|
|
|
+
|
|
|
+ /** 总后台用户前缀 */
|
|
|
+ @Value(value = "${sip.call.adminUserPrefix:hdt_zt}")
|
|
|
+ private String adminUserPrefix;
|
|
|
+ /** 销售公司前缀 */
|
|
|
+ @Value(value = "${sip.call.companyPrefix:hdt_xg}")
|
|
|
+ private String companyPrefix;
|
|
|
+ /** 销售前缀 */
|
|
|
+ @Value(value = "${sip.call.companyUserPrefix:hdt_xs}")
|
|
|
+ private String companyUserPrefix;
|
|
|
|
|
|
/**
|
|
|
* 查询sip用户信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param userId sip用户信息主键
|
|
|
* @return sip用户信息
|
|
|
*/
|
|
|
@@ -43,7 +73,7 @@ public class AiSipCallUserServiceImpl extends ServiceImpl<AiSipCallUserMapper, A
|
|
|
|
|
|
/**
|
|
|
* 查询sip用户信息列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param aiSipCallUser sip用户信息
|
|
|
* @return sip用户信息
|
|
|
*/
|
|
|
@@ -55,19 +85,29 @@ public class AiSipCallUserServiceImpl extends ServiceImpl<AiSipCallUserMapper, A
|
|
|
|
|
|
/**
|
|
|
* 新增sip用户信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param aiSipCallUser sip用户信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
public int insertAiSipCallUser(AiSipCallUser aiSipCallUser)
|
|
|
{
|
|
|
+ String namePrefix;
|
|
|
+ if(aiSipCallUser.getUserSource().equals("0")){
|
|
|
+ namePrefix= manualGatewayPrefix+"_"+companyUserPrefix+"_";
|
|
|
+ }else{
|
|
|
+ namePrefix = manualGatewayPrefix+"_"+adminUserPrefix+"_";
|
|
|
+ }
|
|
|
+ if(!aiSipCallUser.getLoginName().startsWith(namePrefix)){
|
|
|
+ aiSipCallUser.setLoginName(namePrefix+aiSipCallUser.getLoginName());
|
|
|
+ }
|
|
|
//同步新增远程接口
|
|
|
String result = RemoteCommon.sendPost(RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.ADD_USER_OR_BIND_EXTNUM_API, JSONObject.toJSONString(aiSipCallUser));
|
|
|
|
|
|
if(StringUtils.isNotBlank(result)){
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- if(jsonObject.getInteger("code") == 0){
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if(code == 0){
|
|
|
String data = jsonObject.getString("data");
|
|
|
AiSipCallUser remoteAiSipCallUser = JSONObject.parseObject(data, AiSipCallUser.class);
|
|
|
if(remoteAiSipCallUser != null){
|
|
|
@@ -76,70 +116,144 @@ public class AiSipCallUserServiceImpl extends ServiceImpl<AiSipCallUserMapper, A
|
|
|
if(StringUtils.isNotBlank(remoteAiSipCallUser.getPhonenumber())){
|
|
|
aiSipCallUser.setPhonenumber(remoteAiSipCallUser.getPhonenumber());
|
|
|
}
|
|
|
- if(StringUtils.isNotBlank(remoteAiSipCallUser.getPassword())){
|
|
|
- aiSipCallUser.setPassword(remoteAiSipCallUser.getPassword());
|
|
|
- }
|
|
|
if(remoteAiSipCallUser.getCreateTime() != null){
|
|
|
aiSipCallUser.setCreateTime(remoteAiSipCallUser.getCreateTime());
|
|
|
}
|
|
|
- int i = baseMapper.insertAiSipCallUser(aiSipCallUser);
|
|
|
- if( i> 0){
|
|
|
+ if(StringUtils.isNotBlank(remoteAiSipCallUser.getExtPass())){
|
|
|
+ aiSipCallUser.setExtPass(remoteAiSipCallUser.getExtPass());
|
|
|
+ }
|
|
|
+ int i;
|
|
|
+ if(aiSipCallUser.getUserSource().equals("0")){
|
|
|
//绑定companyUser的aiSIP外呼用户
|
|
|
- return companyUserMapper.updateCompanyUserByAiSipCall(aiSipCallUser.getCompanyUserId(),remoteAiSipCallUser.getUserId());
|
|
|
- }else{
|
|
|
- log.error("绑定aiSIP外呼用户失败");
|
|
|
+ i = companyUserMapper.updateCompanyUserByAiSipCall(aiSipCallUser.getCompanyUserId(),remoteAiSipCallUser.getUserId());
|
|
|
+ if( i> 0){
|
|
|
+ return baseMapper.insertAiSipCallUser(aiSipCallUser);
|
|
|
+ }else{
|
|
|
+ log.error("新增aiSIP外呼用户失败");
|
|
|
+ }
|
|
|
}
|
|
|
}else{
|
|
|
log.error("新增时解析aiSIP外呼用户数据为空");
|
|
|
}
|
|
|
}else{
|
|
|
- log.error("新增aiSIP外呼任务失败:{}", jsonObject.getString("msg"));
|
|
|
+ log.error("新增aiSIP外呼用户返回code:{},失败原因:{}",code, jsonObject.getString("msg"));
|
|
|
+ throw new CustomException(jsonObject.getString("msg"));
|
|
|
}
|
|
|
}else{
|
|
|
- log.error("新增aiSIP外呼任务失败:{}", "接口返回为空");
|
|
|
+ log.error("新增aiSIP外呼用户失败:接口返回为空");
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 修改sip用户信息
|
|
|
- *
|
|
|
+ * 修改sip用户信息(总后台随便修改,销售后台的需要归还公司)
|
|
|
+ *
|
|
|
* @param aiSipCallUser sip用户信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
public int updateAiSipCallUser(AiSipCallUser aiSipCallUser)
|
|
|
{
|
|
|
- //同步修改远程接口
|
|
|
- String result = RemoteCommon.sendPost(RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.EDIT_USER_OR_UNBING_EXTNUM_API, JSONObject.toJSONString(aiSipCallUser));
|
|
|
+ String result;
|
|
|
+ if(aiSipCallUser.getUserSource().equals("0")){
|
|
|
+ //查询拼接销售公司
|
|
|
+ if(aiSipCallUser.getCompanyId() == null){
|
|
|
+ log.error("销售修改时公司ID为空");
|
|
|
+ return 0;
|
|
|
+ }else{
|
|
|
+ String companyName;
|
|
|
+ Company company = companyMapper.selectCompanyById(aiSipCallUser.getCompanyId());
|
|
|
+ if(company != null){
|
|
|
+ companyName = company.getCompanyName();
|
|
|
+ }else{
|
|
|
+ log.error("删除aiSIP外呼用户失败:当前员工未绑定销售公司");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ companyName = manualGatewayPrefix + "_"+companyPrefix+"_"+companyName;
|
|
|
+ aiSipCallUser.setCompanyName(companyName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result = RemoteCommon.sendPost(RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.EDIT_USER_OR_UNBING_EXTNUM_API, JSONObject.toJSONString(aiSipCallUser));
|
|
|
if(StringUtils.isNotBlank(result)){
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- if(jsonObject.getInteger("code") == 0){
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if(code == 0){
|
|
|
+ if(StringUtils.isBlank(aiSipCallUser.getGatewayIds())){
|
|
|
+ //处理不选网关的情况
|
|
|
+ aiSipCallUser.setGatewayIds("");
|
|
|
+ }
|
|
|
+ AiSipCallUser remoteUser = JSONObject.parseObject(jsonObject.getString("data"), AiSipCallUser.class);
|
|
|
+ if(remoteUser != null){
|
|
|
+ aiSipCallUser.setExtPass(remoteUser.getExtPass());
|
|
|
+ }
|
|
|
return baseMapper.updateAiSipCallUser(aiSipCallUser);
|
|
|
}else{
|
|
|
- log.error("修改aiSIP外呼任务失败:{}", jsonObject.getString("msg"));
|
|
|
+ log.error("修改aiSIP外呼任务返回code:{},失败原因:{}",code, jsonObject.getString("msg"));
|
|
|
}
|
|
|
}else{
|
|
|
- log.error("修改aiSIP外呼任务失败:{}", "接口返回为空");
|
|
|
+ log.error("修改aiSIP外呼任务失败:接口返回为空");
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 批量删除sip用户信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param userIds 需要删除的sip用户信息主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
public int deleteAiSipCallUserByUserIds(Long[] userIds)
|
|
|
{
|
|
|
- return baseMapper.deleteAiSipCallUserByUserIds(userIds);
|
|
|
+ AiSipCallUser aiSipCallUser = this.selectAiSipCallUserByUserId(userIds[0]);
|
|
|
+ if(aiSipCallUser == null){
|
|
|
+ log.error("删除aiSIP外呼用户失败:aiSIP外呼用户不存在,用户id:" + userIds[0]);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ //销售绑定的坐席需要归还给公司,总后台绑定的直接释放坐席
|
|
|
+ if(aiSipCallUser.getUserSource().equals("0")){
|
|
|
+ String companyName;
|
|
|
+ Company company = companyMapper.selectCompanyById(aiSipCallUser.getCompanyId());
|
|
|
+ if(company != null){
|
|
|
+ companyName = company.getCompanyName();
|
|
|
+ }else{
|
|
|
+ log.error("删除aiSIP外呼用户失败:当前员工未绑定销售公司");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ companyName = manualGatewayPrefix + "_"+companyPrefix+"_"+companyName;
|
|
|
+ aiSipCallUser.setUserCode(companyName);
|
|
|
+ }else{
|
|
|
+ aiSipCallUser.setUserCode("");
|
|
|
+ }
|
|
|
+ String result = RemoteCommon.sendPost(RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.DELETE_USER_OR_UNBING_EXTNUM_API, JSONObject.toJSONString(aiSipCallUser));
|
|
|
+ if(StringUtils.isNotBlank(result)){
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ int i;
|
|
|
+ if(code == 0){
|
|
|
+ if(aiSipCallUser.getUserSource().equals("0")){
|
|
|
+ //删除companyUser的aiSIP外呼用户
|
|
|
+ i = companyUserMapper.updateCompanyUserByAiSipCall(aiSipCallUser.getCompanyUserId(),null);
|
|
|
+ if( i> 0){
|
|
|
+ //删除aiSIP外呼用户
|
|
|
+ return baseMapper.deleteAiSipCallUserByUserId(userIds[0]);
|
|
|
+ }else{
|
|
|
+ log.error("删除aiSIP外呼用户失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return baseMapper.updateAiSipCallUser(aiSipCallUser);
|
|
|
+ }else{
|
|
|
+ log.error("删除aiSIP外呼用户返回code:{},失败原因:{}",code, jsonObject.getString("msg"));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.error("删除aiSIP外呼用户失败:接口返回为空");
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除sip用户信息信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param userId sip用户信息主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@@ -153,32 +267,500 @@ public class AiSipCallUserServiceImpl extends ServiceImpl<AiSipCallUserMapper, A
|
|
|
public AjaxResult getUnBindExtnum() {
|
|
|
//获取未使用的分机号远程接口
|
|
|
String result = RemoteCommon.sendGet(RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.QUERY_UN_BIND_EXTNUM_API);
|
|
|
+ String msg;
|
|
|
if(StringUtils.isNotBlank(result)){
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- if(jsonObject.getInteger("code") == 0){
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if(code == 0){
|
|
|
return JSONObject.parseObject(result, AjaxResult.class);
|
|
|
}else{
|
|
|
- log.error("查询aiSIP外呼未绑定分机失败:{}", jsonObject.getString("msg"));
|
|
|
+ msg = jsonObject.getString("msg");
|
|
|
}
|
|
|
}else{
|
|
|
- log.error("查询aiSIP外呼未绑定分机失败:{}", "接口返回为空");
|
|
|
+ msg = "查询aiSIP外呼未绑定分机失败:接口返回为空";
|
|
|
}
|
|
|
- return AjaxResult.error();
|
|
|
+ return AjaxResult.error(msg);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public AjaxResult getToolbarBasicParam(Map<String,String> param) {
|
|
|
+ String myGateway = param.get("myGateway");
|
|
|
+ //没有配置网关
|
|
|
+ if(StringUtils.isBlank(myGateway)){
|
|
|
+ //查找自己项目的网关
|
|
|
+ if(isMyGateway){
|
|
|
+ //自己线路处理
|
|
|
+ param.put("wgName", manualGatewayPrefix);
|
|
|
+ }else{
|
|
|
+ //没有给默认线路
|
|
|
+ param.put("wgName", publicGatewayPrefix);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//先使用远程网关
|
|
|
String result = RemoteCommon.sendPost(RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.PHONEBAR_PARAMS_API,JSONObject.toJSONString(param));
|
|
|
+ String msg;
|
|
|
if(StringUtils.isNotBlank(result)){
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- if(jsonObject.getInteger("code") == 0){
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if(code == 0){
|
|
|
+ return JSONObject.parseObject(result, AjaxResult.class);
|
|
|
+ }else{
|
|
|
+ msg= jsonObject.getString("msg");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ msg= "获取电话工具条的网关列表接口失败:接口返回为空";
|
|
|
+ }
|
|
|
+ return AjaxResult.error(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult agentLogin(Map<String, Object> param) {
|
|
|
+ String result = RemoteCommon.sendPostForm(RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.AI_CALL_LOGIN_API, param);
|
|
|
+ String msg;
|
|
|
+ if (StringUtils.isNotBlank(result)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
return JSONObject.parseObject(result, AjaxResult.class);
|
|
|
+ } else {
|
|
|
+ msg= jsonObject.getString("msg");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg= "登录外呼平台接口失败:接口返回为空";
|
|
|
+ }
|
|
|
+ return AjaxResult.error(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo getUnBindExtnumPage(CcExtNumVo ccExtNum) {
|
|
|
+ //获取未使用的分机号远程接口
|
|
|
+ String result = RemoteCommon.sendPost(RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.QUERY_UN_BIND_EXTNUM_PAGE_API, JSONObject.toJSONString(ccExtNum));
|
|
|
+ TableDataInfo tableDataInfo = new TableDataInfo();
|
|
|
+ if(StringUtils.isNotBlank(result)){
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if(code == 0){
|
|
|
+ tableDataInfo = JSONObject.parseObject(result, TableDataInfo.class);
|
|
|
}else{
|
|
|
- log.error("获取电话工具条的网关列表接口失败:{}", jsonObject.getString("msg"));
|
|
|
+ tableDataInfo.setCode(code);
|
|
|
+ tableDataInfo.setMsg(jsonObject.getString("msg"));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ tableDataInfo.setCode(500);
|
|
|
+ tableDataInfo.setMsg("查询aiSIP外呼未绑定分机分页失败:接口返回为空");
|
|
|
+ }
|
|
|
+ return tableDataInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult companyBindExtNum(String companyName,String sipExtNumIds) {
|
|
|
+ Map<String, String> param = new HashMap<>();
|
|
|
+ param.put("companyName", manualGatewayPrefix + "_"+companyPrefix+"_"+companyName);
|
|
|
+ param.put("sipExtNumIds", sipExtNumIds);
|
|
|
+ String result = RemoteCommon.sendPost(RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.QUERY_UN_BIND_EXTNUM_COMPANY_API, JSONObject.toJSONString(param));
|
|
|
+ String msg;
|
|
|
+ if (StringUtils.isNotBlank(result)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ return JSONObject.parseObject(result, AjaxResult.class);
|
|
|
+ } else {
|
|
|
+ msg = jsonObject.getString("msg");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg = "公司绑定分机号接口失败:接口返回为空";
|
|
|
+ }
|
|
|
+ return AjaxResult.error(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo getSipExtDetail(CcExtNumVo ccExtNum) {
|
|
|
+ // 保存原始的sipExtNumList用于后续过滤,并转换为Set提升查询性能
|
|
|
+ List<Long> sipExtNumList = ccExtNum.getSipExtNumList();
|
|
|
+ Set<Long> extNumSet = (sipExtNumList != null && !sipExtNumList.isEmpty())
|
|
|
+ ? new HashSet<>(sipExtNumList)
|
|
|
+ : null;
|
|
|
+
|
|
|
+ // 如果有userCode,查询时不传sipExtNumList
|
|
|
+ if(StringUtils.isNotBlank(ccExtNum.getUserCode())){
|
|
|
+ ccExtNum.setSipExtNumList(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用远程接口查询
|
|
|
+ String result = RemoteCommon.sendPost(RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.QUERY_EXTNUM_PAGE_API, JSONObject.toJSONString(ccExtNum));
|
|
|
+
|
|
|
+ // 处理接口返回为空的情况
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
+ return createErrorResult("查询分机详细信息接口失败:接口返回为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析返回结果
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+
|
|
|
+ // 处理接口调用失败的情况
|
|
|
+ if (code == null || code != 0) {
|
|
|
+ String msg = jsonObject.getString("msg");
|
|
|
+ return createErrorResult(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析成功结果
|
|
|
+ TableDataInfo dataInfo = JSONObject.parseObject(result, TableDataInfo.class);
|
|
|
+
|
|
|
+ // 如果有userCode且提供了分机号列表,则进行过滤
|
|
|
+ if(StringUtils.isNotBlank(ccExtNum.getUserCode()) && extNumSet != null && !extNumSet.isEmpty()){
|
|
|
+ List<?> rows = dataInfo.getRows();
|
|
|
+ if(rows != null && !rows.isEmpty()){
|
|
|
+ // 使用Stream过滤出属于sipExtNumList的数据
|
|
|
+ List<Object> filteredRows = rows.stream()
|
|
|
+ .filter(row -> {
|
|
|
+ Long extNum = extractExtNum(row);
|
|
|
+ return extNum != null && extNumSet.contains(extNum);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 重新组装数据
|
|
|
+ dataInfo.setRows(filteredRows);
|
|
|
+ dataInfo.setTotal(filteredRows.size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return dataInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult getCompanyUnBindExtnum(Long companyId) {
|
|
|
+ String companyName;
|
|
|
+ Company company = companyMapper.selectCompanyById(companyId);
|
|
|
+ if(company != null){
|
|
|
+ companyName = company.getCompanyName();
|
|
|
+ }else{
|
|
|
+ return AjaxResult.error("当前员工未绑定销售公司");
|
|
|
+ }
|
|
|
+ companyName = manualGatewayPrefix + "_"+companyPrefix+"_"+companyName;
|
|
|
+ CcExtNumVo ccExtNum = new CcExtNumVo();
|
|
|
+ ccExtNum.setUserCode(companyName);
|
|
|
+ // 调用远程接口查询
|
|
|
+ String result = RemoteCommon.sendPost(RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.QUERY_COMPANY_UN_BIND_EXTNUM_API, JSONObject.toJSONString(ccExtNum));
|
|
|
+ String msg;
|
|
|
+ if (StringUtils.isNotBlank(result)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ return JSONObject.parseObject(result, AjaxResult.class);
|
|
|
+ } else {
|
|
|
+ msg= jsonObject.getString("msg");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg= "查询公司分机号接口失败:接口返回为空";
|
|
|
+ }
|
|
|
+ return AjaxResult.error(msg);
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public AjaxResult companyUnbindExtNum(List<Company> companyList) {
|
|
|
+ if (CollectionUtils.isEmpty(companyList)) {
|
|
|
+ log.error("批量解绑分机:公司列表为空");
|
|
|
+ return AjaxResult.error("公司列表不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> successResults = new ArrayList<>();
|
|
|
+ List<String> failedCompanies = new ArrayList<>();
|
|
|
+ int totalExtNumCount = 0;
|
|
|
+
|
|
|
+ log.info("开始批量解绑分机,共 {} 家公司", companyList.size());
|
|
|
+
|
|
|
+ for (Company company : companyList) {
|
|
|
+ String companyName = company.getCompanyName();
|
|
|
+ Long companyId = company.getCompanyId();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 跳过未绑定分机的公司
|
|
|
+ if (StringUtils.isBlank(company.getSipExtNumIds())) {
|
|
|
+ log.info("公司 [{}] (ID:{}) 未绑定分机号,跳过", companyName, companyId);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析分机号集合
|
|
|
+ Set<Long> extNumSet = parseExtNumIds(company.getSipExtNumIds());
|
|
|
+ if (extNumSet.isEmpty()) {
|
|
|
+ log.info("公司 [{}] (ID:{}) 没有有效的分机号", companyName, companyId);
|
|
|
+ failedCompanies.add(companyName + "(无有效分机号)");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("处理公司 [{}] (ID:{}),待解绑分机数: {}", companyName, companyId, extNumSet.size());
|
|
|
+
|
|
|
+ // 调用远程接口释放分机
|
|
|
+ String result = RemoteCommon.sendPost(
|
|
|
+ RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.CONPANY_BATCH_UNBING_EXTNUM_API,
|
|
|
+ JSONObject.toJSONString(extNumSet)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
+ log.info("公司 [{}] (ID:{}) 解绑分机失败:远程接口返回为空", companyName, companyId);
|
|
|
+ failedCompanies.add(companyName + "(接口返回为空)");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+
|
|
|
+ if (code == null || code != 0) {
|
|
|
+ String errorMsg = jsonObject.getString("msg");
|
|
|
+ log.info("公司 [{}] (ID:{}) 解绑分机失败:{}", companyName, companyId, errorMsg);
|
|
|
+ failedCompanies.add(companyName + "(" + errorMsg + ")");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理销售坐席解绑
|
|
|
+ List<Long> companyUserExtNums = baseMapper.selectByExtNumList(extNumSet);
|
|
|
+ if (!CollectionUtils.isEmpty(companyUserExtNums)) {
|
|
|
+ log.info("公司 [{}] (ID:{}) 发现 {} 个销售绑定的分机,开始清理", companyName, companyId, companyUserExtNums.size());
|
|
|
+ handleSalesUnbind(new HashSet<>(companyUserExtNums));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新公司分机号信息
|
|
|
+ AjaxResult updateResult = updateCompanyExtNums(companyId, company.getSipExtNumIds(), extNumSet);
|
|
|
+ Integer updateCode = (Integer) updateResult.get(AjaxResult.CODE_TAG);
|
|
|
+
|
|
|
+ if (updateCode != null && updateCode == 0) {
|
|
|
+ Map<String, Object> successInfo = new HashMap<>();
|
|
|
+ successInfo.put("companyName", companyName);
|
|
|
+ successInfo.put("companyId", companyId);
|
|
|
+ successInfo.put("removedCount", extNumSet.size());
|
|
|
+ successResults.add(successInfo);
|
|
|
+ totalExtNumCount += extNumSet.size();
|
|
|
+ log.info("公司 [{}] (ID:{}) 解绑成功,移除 {} 个分机", companyName, companyId, extNumSet.size());
|
|
|
+ } else {
|
|
|
+ String msg = (String) updateResult.get(AjaxResult.MSG_TAG);
|
|
|
+ log.info("公司 [{}] (ID:{}) 更新数据库失败:{}", companyName, companyId, msg);
|
|
|
+ failedCompanies.add(companyName + "(更新数据库失败)");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("公司 [{}] (ID:{}) 解绑分机时发生异常", companyName, companyId, e);
|
|
|
+ failedCompanies.add(companyName + "(异常: " + e.getMessage() + ")");
|
|
|
}
|
|
|
}
|
|
|
- return AjaxResult.error();
|
|
|
+
|
|
|
+ // 构建返回结果
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("successResults", successResults);
|
|
|
+ resultMap.put("failedCompanies", failedCompanies);
|
|
|
+ resultMap.put("totalProcessed", companyList.size());
|
|
|
+ resultMap.put("successCount", successResults.size());
|
|
|
+ resultMap.put("failedCount", failedCompanies.size());
|
|
|
+ resultMap.put("totalRemovedExtNums", totalExtNumCount);
|
|
|
+
|
|
|
+ String summary = String.format("批量解绑完成:总计%d家,成功%d家(共移除%d个分机),失败%d家",
|
|
|
+ companyList.size(), successResults.size(), totalExtNumCount, failedCompanies.size());
|
|
|
+ log.info(summary);
|
|
|
+
|
|
|
+ return failedCompanies.isEmpty()
|
|
|
+ ? AjaxResult.success("所有公司解绑成功", resultMap)
|
|
|
+ : AjaxResult.success(summary, resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult companyBatchUnbindSipExt(Long companyId, List<CcExtNumVo> ccExtNums) {
|
|
|
+ // 参数校验
|
|
|
+ if (companyId == null) {
|
|
|
+ log.error("批量解绑分机:公司ID为空");
|
|
|
+ return AjaxResult.error("公司ID不能为空");
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(ccExtNums)) {
|
|
|
+ log.error("批量解绑分机:公司ID={},分机列表为空", companyId);
|
|
|
+ return AjaxResult.error("分机列表不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("开始批量解绑分机:公司ID={},待处理分机数={}", companyId, ccExtNums.size());
|
|
|
+
|
|
|
+ // 获取公司信息并验证
|
|
|
+ Company company = companyMapper.selectCompanyById(companyId);
|
|
|
+ if (company == null) {
|
|
|
+ log.error("批量解绑分机失败:公司ID={} 不存在", companyId);
|
|
|
+ return AjaxResult.error("公司不存在");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(company.getSipExtNumIds())) {
|
|
|
+ log.error("批量解绑分机失败:公司 [{}] (ID:{}) 未绑定分机", company.getCompanyName(), companyId);
|
|
|
+ return AjaxResult.error("公司未绑定分机");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 收集所有待解绑的分机号(去重)
|
|
|
+ Set<Long> extNumSet = ccExtNums.stream()
|
|
|
+ .filter(vo -> vo != null && vo.getExtNum() != null)
|
|
|
+ .map(CcExtNumVo::getExtNum)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ if (extNumSet.isEmpty()) {
|
|
|
+ log.error("批量解绑分机:公司 [{}] (ID:{}) 没有有效的分机号", company.getCompanyName(), companyId);
|
|
|
+ return AjaxResult.error("没有有效的分机号");
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("公司 [{}] (ID:{}) 待解绑分机数:{},分机列表:{}",
|
|
|
+ company.getCompanyName(), companyId, extNumSet.size(), extNumSet);
|
|
|
+
|
|
|
+ // 调用远程接口释放公司分机
|
|
|
+ String result = RemoteCommon.sendPost(
|
|
|
+ RemoteCommon.REMOTE_ADDERSS_PREFIX + RemoteCommon.CONPANY_BATCH_UNBING_EXTNUM_API,
|
|
|
+ JSONObject.toJSONString(extNumSet)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
+ log.error("公司 [{}] (ID:{}) 解绑分机失败:远程接口返回为空", company.getCompanyName(), companyId);
|
|
|
+ return AjaxResult.error("解绑分机失败:接口返回为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+
|
|
|
+ if (code == null || code != 0) {
|
|
|
+ String errorMsg = jsonObject.getString("msg");
|
|
|
+ log.error("公司 [{}] (ID:{}) 解绑分机失败:{}", company.getCompanyName(), companyId, errorMsg);
|
|
|
+ return AjaxResult.error("解绑分机失败:" + errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("公司 [{}] (ID:{}) 远程接口解绑成功", company.getCompanyName(), companyId);
|
|
|
+
|
|
|
+ // 处理销售坐席解绑
|
|
|
+ Set<Long> salesExtNums = ccExtNums.stream()
|
|
|
+ .filter(vo -> vo != null && StringUtils.isNotBlank(vo.getUserCode()))
|
|
|
+ .map(CcExtNumVo::getExtNum)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ if (!salesExtNums.isEmpty()) {
|
|
|
+ log.info("公司 [{}] (ID:{}) 发现 {} 个销售绑定的分机,开始清理",
|
|
|
+ company.getCompanyName(), companyId, salesExtNums.size());
|
|
|
+ handleSalesUnbind(salesExtNums);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新公司分机号信息
|
|
|
+ AjaxResult updateResult = updateCompanyExtNums(companyId, company.getSipExtNumIds(), extNumSet);
|
|
|
+ Integer updateCode = (Integer) updateResult.get(AjaxResult.CODE_TAG);
|
|
|
+
|
|
|
+ if (updateCode != null && updateCode == 200) {
|
|
|
+ log.info("公司 [{}] (ID:{}) 批量解绑成功,共移除 {} 个分机",
|
|
|
+ company.getCompanyName(), companyId, extNumSet.size());
|
|
|
+ return AjaxResult.success("批量解绑成功,共移除 " + extNumSet.size() + " 个分机");
|
|
|
+ } else {
|
|
|
+ String msg = (String) updateResult.get(AjaxResult.MSG_TAG);
|
|
|
+ log.info("公司 [{}] (ID:{}) 更新数据库失败:{}", company.getCompanyName(), companyId, msg);
|
|
|
+ return AjaxResult.error("更新分机信息失败:" + msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理销售坐席解绑
|
|
|
+ */
|
|
|
+ private void handleSalesUnbind(Set<Long> salesExtNums) {
|
|
|
+ // 查询销售绑定的坐席ID列表
|
|
|
+ List<Long> aiSipCallUserIds = baseMapper.selectByExtNumList(salesExtNums);
|
|
|
+ if (CollectionUtils.isEmpty(aiSipCallUserIds)) {
|
|
|
+ log.error("未找到销售绑定的分机号对应的坐席id");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清空companyUser的坐席字段
|
|
|
+ int cleanCount = companyUserMapper.cleanBindAiSipCallUserId(aiSipCallUserIds);
|
|
|
+ if (cleanCount <= 0) {
|
|
|
+ log.error("清空销售坐席绑定关系失败");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除销售坐席
|
|
|
+ Long[] userIdsArray = aiSipCallUserIds.toArray(new Long[0]);
|
|
|
+ int deleteCount = baseMapper.deleteAiSipCallUserByUserIds(userIdsArray);
|
|
|
+ if (deleteCount <= 0) {
|
|
|
+ log.error("删除销售坐席失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新公司分机号信息
|
|
|
+ */
|
|
|
+ private AjaxResult updateCompanyExtNums(Long companyId, String currentExtNumIds, Set<Long> unbindExtNums) {
|
|
|
+ if (companyId == null) {
|
|
|
+ log.error("更新公司分机号失败:公司ID为空");
|
|
|
+ return AjaxResult.error("公司ID不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(currentExtNumIds)) {
|
|
|
+ log.error("更新公司分机号:公司ID={} 当前未绑定分机", companyId);
|
|
|
+ return AjaxResult.success("公司未绑定分机,无需更新");
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(unbindExtNums)) {
|
|
|
+ log.error("更新公司分机号:公司ID={} 待解绑分机集合为空", companyId);
|
|
|
+ return AjaxResult.success("没有需要解绑的分机");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析当前公司分机号
|
|
|
+ Set<Long> companyExtNumSet = parseExtNumIds(currentExtNumIds);
|
|
|
+
|
|
|
+ // 过滤出剩余的分机号并排序
|
|
|
+ List<Long> remainingExtNums = companyExtNumSet.stream()
|
|
|
+ .filter(extNum -> !unbindExtNums.contains(extNum))
|
|
|
+ .sorted()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 构建更新后的分机号字符串
|
|
|
+ String remainingExtNumIds = remainingExtNums.isEmpty()
|
|
|
+ ? null
|
|
|
+ : remainingExtNums.stream()
|
|
|
+ .map(String::valueOf)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ log.info("公司ID={} 更新分机号:原{}个,解绑{}个,剩余{}个",
|
|
|
+ companyId, companyExtNumSet.size(), unbindExtNums.size(), remainingExtNums.size());
|
|
|
+
|
|
|
+ // 更新数据库
|
|
|
+ int updateCount = companyMapper.updateCompanyBindSipExtNum(companyId, remainingExtNumIds);
|
|
|
+ if (updateCount > 0) {
|
|
|
+ log.info("公司ID={} 更新分机号成功,剩余分机:{}", companyId, remainingExtNumIds);
|
|
|
+ return AjaxResult.success("批量解绑公司分机成功");
|
|
|
+ } else {
|
|
|
+ log.info("公司ID={} 更新分机号失败,SQL影响行数为0", companyId);
|
|
|
+ return AjaxResult.error("批量解绑公司分机号失败");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析分机号ID字符串为Set集合
|
|
|
+ */
|
|
|
+ private Set<Long> parseExtNumIds(String extNumIds) {
|
|
|
+ if (StringUtils.isBlank(extNumIds)) {
|
|
|
+ return Collections.emptySet();
|
|
|
+ }
|
|
|
+ return Arrays.stream(extNumIds.split(","))
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
+ .map(String::trim)
|
|
|
+ .map(Long::parseLong)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从行对象中提取分机号
|
|
|
+ */
|
|
|
+ private Long extractExtNum(Object row) {
|
|
|
+ if(row instanceof JSONObject){
|
|
|
+ return ((JSONObject) row).getLong("extNum");
|
|
|
+ } else if(row instanceof CcExtNumVo){
|
|
|
+ return ((CcExtNumVo) row).getExtNum();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建错误结果
|
|
|
+ */
|
|
|
+ private TableDataInfo createErrorResult(String msg) {
|
|
|
+ TableDataInfo tableDataInfo = new TableDataInfo();
|
|
|
+ tableDataInfo.setTotal(0);
|
|
|
+ tableDataInfo.setCode(500);
|
|
|
+ tableDataInfo.setMsg(msg);
|
|
|
+ return tableDataInfo;
|
|
|
+ }
|
|
|
}
|