Commit 781dcd7e by Java-金吉宝

修复录音重复记录bug

parent 6b00ddb1
package com.ejweb.modules.call.dao;
import java.util.List;
import com.ejweb.core.base.BaseDao;
import com.ejweb.modules.call.bean.CallFindPhoneInfoBean;
import com.ejweb.modules.call.bean.CallPhoneBean;
import com.ejweb.modules.call.bean.CallRecordListBean;
import com.ejweb.modules.call.entity.CallPhoneAreaEntity;
import com.ejweb.modules.call.entity.CallPhoneInfoListEntity;
import com.ejweb.modules.call.entity.CallRecordEntity;
import com.ejweb.modules.call.entity.CallRecordListEntity;
import com.ejweb.modules.call.entity.CallSoundRecordBean;
import com.ejweb.modules.call.entity.HuaweiNumListEntity;
import com.ejweb.modules.call.entity.MemberEntity;
public interface CallDao extends BaseDao {
public Integer createCallRecord(CallRecordEntity entity);
public Integer updateCallRecord(CallRecordEntity entity);
public Integer addCallPhoneList(List<CallPhoneBean> phoneList);
public List<CallRecordListEntity> getCallRecordList(CallRecordListBean bean);
public List<CallRecordListEntity> getCallSoundList(CallRecordListBean bean);
public List<CallPhoneInfoListEntity> findUserByCallPhone(CallFindPhoneInfoBean bean);
public List<CallPhoneInfoListEntity> findUserByCallRecord(CallFindPhoneInfoBean bean);
public List<CallPhoneInfoListEntity> findSeatListByCallPhone(CallFindPhoneInfoBean bean);
public CallPhoneInfoListEntity findUserInfoByNumOrId(CallFindPhoneInfoBean bean);
public CallPhoneAreaEntity getPhoneAreaByAreaCode(CallPhoneAreaEntity areaCode);
public CallPhoneAreaEntity getPhoneAreaByMobile(CallPhoneAreaEntity mobile);
public Integer addPhoneAreaRecord(CallPhoneAreaEntity entity);
public Integer addPhoneAreaCode(CallPhoneAreaEntity entity);
public Integer addSoundRecord(CallSoundRecordBean entity);
public List<CallPhoneInfoListEntity> findPhneListByHuaweiNum(HuaweiNumListEntity entity);
public String GetPhoneById(String id);
public List<MemberEntity> getMemberList(String recordId);
public String getNameByPhone(String mobileNubmer);
public String getNameByPhoneFromSeat(String createPhone);
public String getIdByPhoneFromSeat(String createPhone);
public String getIdByPhone(String mobileNubmer);
}
package com.ejweb.modules.call.dao;
import java.util.List;
import com.ejweb.core.base.BaseDao;
import com.ejweb.modules.call.bean.CallFindPhoneInfoBean;
import com.ejweb.modules.call.bean.CallPhoneBean;
import com.ejweb.modules.call.bean.CallRecordListBean;
import com.ejweb.modules.call.entity.CallPhoneAreaEntity;
import com.ejweb.modules.call.entity.CallPhoneInfoListEntity;
import com.ejweb.modules.call.entity.CallRecordEntity;
import com.ejweb.modules.call.entity.CallRecordListEntity;
import com.ejweb.modules.call.entity.CallSoundRecordBean;
import com.ejweb.modules.call.entity.HuaweiNumListEntity;
import com.ejweb.modules.call.entity.MemberEntity;
public interface CallDao extends BaseDao {
public Integer createCallRecord(CallRecordEntity entity);
public Integer updateCallRecord(CallRecordEntity entity);
public Integer addCallPhoneList(List<CallPhoneBean> phoneList);
public List<CallRecordListEntity> getCallRecordList(CallRecordListBean bean);
public List<CallRecordListEntity> getCallSoundList(CallRecordListBean bean);
public List<CallPhoneInfoListEntity> findUserByCallPhone(CallFindPhoneInfoBean bean);
public List<CallPhoneInfoListEntity> findUserByCallRecord(CallFindPhoneInfoBean bean);
public List<CallPhoneInfoListEntity> findSeatListByCallPhone(CallFindPhoneInfoBean bean);
public CallPhoneInfoListEntity findUserInfoByNumOrId(CallFindPhoneInfoBean bean);
public CallPhoneAreaEntity getPhoneAreaByAreaCode(CallPhoneAreaEntity areaCode);
public CallPhoneAreaEntity getPhoneAreaByMobile(CallPhoneAreaEntity mobile);
public Integer addPhoneAreaRecord(CallPhoneAreaEntity entity);
public Integer addPhoneAreaCode(CallPhoneAreaEntity entity);
public Integer addSoundRecord(CallSoundRecordBean entity);
public List<CallPhoneInfoListEntity> findPhneListByHuaweiNum(HuaweiNumListEntity entity);
public String GetPhoneById(String id);
public List<MemberEntity> getMemberList(String recordId);
public String getNameByPhone(String mobileNubmer);
public String getNameByPhoneFromSeat(String createPhone);
public String getIdByPhoneFromSeat(String createPhone);
public String getIdByPhone(String mobileNubmer);
public CallRecordListEntity get(CallRecordListEntity callRecordListEntity);
public List<CallRecordListEntity> getList(CallRecordListEntity callRecordListEntity);
}
package com.ejweb.modules.call.service;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sound.midi.VoiceStatus;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ejweb.core.base.BaseService;
import com.ejweb.core.base.PageEntity;
import com.ejweb.core.util.IdWorker;
import com.ejweb.core.util.Util;
import com.ejweb.modules.call.bean.CallFindPhoneInfoBean;
import com.ejweb.modules.call.bean.CallPhoneBean;
import com.ejweb.modules.call.bean.CallRecordListBean;
import com.ejweb.modules.call.dao.CallDao;
import com.ejweb.modules.call.entity.CallPhoneAreaEntity;
import com.ejweb.modules.call.entity.CallPhoneInfoListEntity;
import com.ejweb.modules.call.entity.CallRecordEntity;
import com.ejweb.modules.call.entity.CallRecordListEntity;
import com.ejweb.modules.call.entity.CallSoundRecordBean;
import com.ejweb.modules.call.entity.HuaweiNumListEntity;
import com.ejweb.modules.call.entity.MemberEntity;
import com.ejweb.modules.call.util.PhoneAreaEntity;
import com.ejweb.modules.call.util.PhoneAreaUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service
@Transactional(readOnly = true)
public class CallService extends BaseService<CallDao> {
public void createCallRecord(CallRecordEntity entity){
dao.createCallRecord(entity);
}
public void updateCallRecord(CallRecordEntity entity){
dao.updateCallRecord(entity);
}
public Integer addCallPhoneList(List<CallPhoneBean> phoneList){
return dao.addCallPhoneList(phoneList);
}
/**
* 获取通话记录列表
*
* @author renmb
* @time 2016年12月6日
* @param bean
* @return
*/
public PageEntity<CallRecordListEntity> getCallRecordList(CallRecordListBean bean){
// return dao.getCallRecordList(bean);
PageInfo<CallRecordListEntity> pageInfo = null;
Date current = new Date();
Date startTime = DateUtils.addDays(current, -3);
bean.setStartTime(DateFormatUtils.format(startTime, "yyyy-MM-dd 00:00:00"));
bean.setEndTime(DateFormatUtils.format(current, "yyyy-MM-dd 23:59:59"));
// 必须紧贴dao的查询方法
PageHelper.startPage(bean.getPageNo(), bean.getPageSize());
pageInfo = new PageInfo<CallRecordListEntity>(dao.getCallRecordList(bean));
if(pageInfo.getPages()<bean.getPageNo()){// 页码大于总页数,则返回NULL
return null;
}
List<CallRecordListEntity> list = pageInfo.getList();
if (list == null || list.size() == 0) {// 如果没有数据则返回NULL
return null;
}
PageEntity<CallRecordListEntity> page = new PageEntity<CallRecordListEntity>();
page.setPageNo(pageInfo.getPageNum());
page.setPageSize(pageInfo.getPageSize());
page.setCount(pageInfo.getTotal());
page.setTotalPage(pageInfo.getPages());
page.setList(pageInfo.getList());
return page;
}
public PageEntity<CallRecordListEntity> getCallSoundList(CallRecordListBean bean){
// return dao.getCallRecordList(bean);
PageInfo<CallRecordListEntity> pageInfo = null;
Date current = new Date();
Date startTime = DateUtils.addDays(current, -6);
bean.setStartTime(DateFormatUtils.format(startTime, "yyyy-MM-dd 00:00:00"));
bean.setEndTime(DateFormatUtils.format(current, "yyyy-MM-dd 23:59:59"));
// 必须紧贴dao的查询方法
PageHelper.startPage(bean.getPageNo(), bean.getPageSize());
pageInfo = new PageInfo<CallRecordListEntity>(dao.getCallSoundList(bean));
if(pageInfo.getPages()<bean.getPageNo()){// 页码大于总页数,则返回NULL
return null;
}
List<CallRecordListEntity> list = pageInfo.getList();
if (list == null || list.size() == 0) {// 如果没有数据则返回NULL
return null;
}
PageEntity<CallRecordListEntity> page = new PageEntity<CallRecordListEntity>();
page.setPageNo(pageInfo.getPageNum());
page.setPageSize(pageInfo.getPageSize());
page.setCount(pageInfo.getTotal());
page.setTotalPage(pageInfo.getPages());
page.setList(pageInfo.getList());
return page;
}
/**
* 根据电话号码查询,通话来电号码查询用户信息
*
* 1、席位优先
* 2、查询最近通话记录
* 3、查询用户表,如果有多个用户就展示用户手机号或者座机号
*
* @author renmb
* @time 2017年1月5日
* @param bean
* @return
*/
public List<CallPhoneInfoListEntity> findUserByCallPhone(CallFindPhoneInfoBean bean, boolean isOnlySearch){
// CallFindPhoneInfoBean bean = new CallFindPhoneInfoBean();
// bean.setPhoneNumer(phoneNumer);
bean.setMobileNubmer0("0"+bean.getPhoneNumer());
bean.setMobileNubmer00("00"+bean.getPhoneNumer());
List<CallPhoneInfoListEntity> callList = dao.findUserByCallRecord(bean);
// List<CallPhoneInfoListEntity> seatList = dao.findSeatListByCallPhone(bean);
if(callList == null || callList.size() == 0){// 没有匹配到席位信息
// List<CallPhoneInfoListEntity> callList = dao.findUserByCallRecord(bean);
List<CallPhoneInfoListEntity> seatList = dao.findSeatListByCallPhone(bean);
if(seatList == null || seatList.size() == 0){// 没有匹配到通话记录信息
List<CallPhoneInfoListEntity> userList = dao.findUserByCallPhone(bean);
if(userList == null || userList.size() == 0 || userList.size() > 1){// 没有匹配到用户信息,或者匹配个数大于1
CallPhoneInfoListEntity entity = new CallPhoneInfoListEntity();
entity.setType("PHONE");
entity.setUserId("");
entity.setName(bean.getPhoneNumer());
entity.setPhone(bean.getPhoneNumer());
List<CallPhoneInfoListEntity> phoneList = new ArrayList<CallPhoneInfoListEntity>(1);
phoneList.add(entity);
return phoneList;
} else{// 有用户信息直接返回
return userList;
}
} else {// 有通话记录信息,直接返回
return seatList;
}
} else{// 有席位信息直接返回
return callList;
}
}
/**
* 被叫方添加通话记录
*
* @author renmb
* @time 2017年3月17日
* @param bean
* @param fromUser
*/
public void addCallRecordByCalled(CallFindPhoneInfoBean bean, CallPhoneInfoListEntity fromUser){
if("RECORD".equals(fromUser.getFromType())){// 记录是从通话记录里面获取的
return ;
}
CallPhoneInfoListEntity calledUser = dao.findUserInfoByNumOrId(bean);// 被拨打方用户信息
if(calledUser == null){
return ;
}
CallRecordEntity record = new CallRecordEntity();
record.setCallType("USER");
record.setEndStatus("CALLING");
record.setId(IdWorker.getNextId());
record.setChannelType("APP");
record.setStartTime(new Date());
record.setAppCode(bean.getAppCode());
record.setPlatform(bean.getPlatform());
record.setVersionName(bean.getVersionName());
record.setUserCount(1);
if(StringUtils.isEmpty(fromUser.getUserId())){
record.setCreateBy("");
record.setCreateName(bean.getPhoneNumer());
record.setCreatePhone(bean.getPhoneNumer());
record.setCreateShowPhone(bean.getPhoneNumer());
record.setPhoneType(Util.getPhoneType(bean.getPhoneNumer()));
} else{
record.setCreateBy(fromUser.getUserId());
record.setCreateName(fromUser.getName());
record.setCreatePhone(fromUser.getHuaweiNum());
record.setCreateShowPhone(bean.getPhoneNumer());
record.setPhoneType(Util.getPhoneType(fromUser.getHuaweiNum()));
}
this.createCallRecord(record);// 添加主记录
CallPhoneBean calledPhone = new CallPhoneBean();
calledPhone.setId(IdWorker.getNextId());
calledPhone.setPhoneType(Util.getPhoneType(bean.getPhoneNumer()));
calledPhone.setRecordId(record.getId());
calledPhone.setTitle(bean.getPhoneNumer());
calledPhone.setFlow("CALLED");
calledPhone.setUsername(calledUser.getName());
calledPhone.setUserId(calledUser.getUserId());
List<CallPhoneBean> phoneList = new ArrayList<CallPhoneBean>(1);
phoneList.add(calledPhone);
this.addCallPhoneList(phoneList);// 添加电话列表
}
/**
* 综合查询手机号的归属地信息
*
* @author renmb
* @time 2017年1月22日
* @param mobile
* @return
*/
@Transactional(readOnly = false)
public CallPhoneAreaEntity addPhoneArea(String mobile){
if(StringUtils.isEmpty(mobile) || mobile.length()<7){
return null;
}
String src = new String(mobile);
CallPhoneAreaEntity phoneArea = null;
mobile = mobile.replaceAll("^0+", "");// 去掉手机号前面的0
if(mobile.length()>7){
CallPhoneAreaEntity searchMobile = new CallPhoneAreaEntity();
// 第一步:通过查询记录获取手机归属地信息,暂时注释掉不适用,主要用于控制特殊号码的归宿地查询
/*
searchMobile.setMobileNubmer0("0"+mobile);
searchMobile.setMobileNubmer00("00"+mobile);
searchMobile.setMobileNubmer000("000"+mobile);
phoneArea = dao.getPhoneAreaByMobile(searchMobile);// 到记录表里面查询
if(phoneArea != null && StringUtils.isNotEmpty(phoneArea.getPremobile())){
phoneArea.setMobileNubmer(phoneArea.getPremobile()+mobile);
return phoneArea;
}
*/
// 第二步: 通过地区码查询手机归宿地信息
searchMobile.setAreaCode(mobile.substring(0, 7));
searchMobile.setMobile(mobile);
phoneArea = dao.getPhoneAreaByAreaCode(searchMobile);
if(phoneArea != null && StringUtils.isNotEmpty(phoneArea.getPremobile())){
phoneArea.setMobileNubmer(phoneArea.getPremobile()+mobile);
return phoneArea;
}
// 第三步:通过360接口获取归属地信息
phoneArea = this.getCallPhoneAreaBy360(mobile);
if(phoneArea != null){
if(StringUtils.isNotEmpty(phoneArea.getPremobile())){// 手机类型进行缓存数据库
phoneArea.setId(IdWorker.getNextId());
phoneArea.setUpdateDate(new Date());
if(phoneArea.getMobile().length()>=7){
phoneArea.setAreaCode(phoneArea.getMobile().substring(0, 7));
dao.addPhoneAreaCode(phoneArea);
}
dao.addPhoneAreaRecord(phoneArea);
} else{// 非手机号,按座机号处理
phoneArea.setShowPhone(src);
phoneArea.setPhone(Util.formatedWorkPhone(src));
phoneArea.setType("PHONE");
}
return phoneArea;
}
}
phoneArea = new CallPhoneAreaEntity();
phoneArea.setShowPhone(src);
phoneArea.setPhone(Util.formatedWorkPhone(src));
phoneArea.setType("PHONE");
return phoneArea;
}
@Transactional(readOnly = false)
public CallPhoneAreaEntity getCallPhoneAreaBy360(String mobile){
CallPhoneAreaEntity callPhone = new CallPhoneAreaEntity();
callPhone.setMobile(mobile);
if(StringUtils.isNotBlank(mobile)){// 格式化手机号
if(mobile.startsWith("+")){// 国外手机号,前面加拨3个0
callPhone.setType("MOBILE");
callPhone.setPremobile("000");
callPhone.setMobileNubmer("000"+mobile.replace("+", ""));
return callPhone;
} else if(mobile.startsWith("0") == false){// 可能是手机号
PhoneAreaEntity area = PhoneAreaUtil.get360PhoneArea(mobile);
if(area == null){
area = PhoneAreaUtil.get360PhoneArea(mobile);
}
if(area != null && StringUtils.isNotBlank(area.getProvince())){// 能够查到省份信息
if(area.getProvince().contains("北京")
|| (StringUtils.isNotBlank(area.getCity()) && area.getCity().contains("北京"))){// 北京前面加拨一个0
callPhone.setType("MOBILE");
callPhone.setMobileNubmer("0"+mobile);// 加拨1个0
callPhone.setPremobile("0");
callPhone.setMobileProvince("北京");
callPhone.setMobileCity("北京");
callPhone.setMobileSp(StringUtils.isBlank(area.getSp()) ? "" : area.getSp());
return callPhone;
} else {// 非北京号码加拨两个0
callPhone.setType("MOBILE");
callPhone.setMobileNubmer("00"+mobile);// 加拨2个0
callPhone.setPremobile("00");
callPhone.setMobileProvince(area.getProvince());
callPhone.setMobileCity(StringUtils.isBlank(area.getCity()) ? "" : area.getCity());
callPhone.setMobileSp(StringUtils.isBlank(area.getSp()) ? "" : area.getSp());
return callPhone;
}
}
}
}
// 非手机号,按座机号处理
callPhone.setShowPhone(mobile);
callPhone.setPhone(Util.formatedWorkPhone(mobile));
callPhone.setType("PHONE");
return callPhone;
}
/**
* 添加安科同步过来的数据
*
* @author renmb
* @time 2017年2月28日
* @param entity
* @return
*/
public boolean addSoundRecord(CallSoundRecordBean entity,List<CallPhoneBean> phoneList,CallRecordEntity record){
dao.createCallRecord(record);
dao.addCallPhoneList(phoneList);
Integer count = dao.addSoundRecord(entity);
return count != null && count > 0;
}
public Map<String, String> findPhneByHuaweiNum(List<String> huweiNumList){
HuaweiNumListEntity entity = new HuaweiNumListEntity();
entity.setHuweiNumList(huweiNumList);
List<CallPhoneInfoListEntity> list = dao.findPhneListByHuaweiNum(entity);
if(list == null || list.size() == 0){
return null;
}
Map<String, String> map = new HashMap<String, String>();
for(CallPhoneInfoListEntity p:list){
map.put(p.getHuaweiNum(), p.getPhone());
}
return map;
}
public String GetPhoneById(String id){
return dao. GetPhoneById( id);
}
public List<MemberEntity> getMemberList(String id) {
return dao.getMemberList( id);
}
// public static void main(String[] args){
// Date current = new Date();
// Date startTime = DateUtils.addDays(current, -6);
// System.out.println(DateFormatUtils.format(startTime, "yyyy-MM-dd 00:00:00"));
// System.out.println(DateFormatUtils.format(current, "yyyy-MM-dd 23:59:59"));
// }
public String getNameByPhone(String createPhone) {
// TODO Auto-generated method stub
return dao.getNameByPhone(createPhone);
}
public String getNameByPhoneFromSeat(String createPhone) {
// TODO Auto-generated method stub
return dao.getNameByPhoneFromSeat(createPhone);
}
public String getIdByPhoneFromSeat(String callNo) {
// TODO Auto-generated method stub
return dao.getIdByPhoneFromSeat(callNo);
}
public String getIdByPhone(String callNo) {
// TODO Auto-generated method stub
return dao.getIdByPhone(callNo);
}
}
package com.ejweb.modules.call.service;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sound.midi.VoiceStatus;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ejweb.core.base.BaseService;
import com.ejweb.core.base.PageEntity;
import com.ejweb.core.util.IdWorker;
import com.ejweb.core.util.Util;
import com.ejweb.modules.call.bean.CallFindPhoneInfoBean;
import com.ejweb.modules.call.bean.CallPhoneBean;
import com.ejweb.modules.call.bean.CallRecordListBean;
import com.ejweb.modules.call.dao.CallDao;
import com.ejweb.modules.call.entity.CallPhoneAreaEntity;
import com.ejweb.modules.call.entity.CallPhoneInfoListEntity;
import com.ejweb.modules.call.entity.CallRecordEntity;
import com.ejweb.modules.call.entity.CallRecordListEntity;
import com.ejweb.modules.call.entity.CallSoundRecordBean;
import com.ejweb.modules.call.entity.HuaweiNumListEntity;
import com.ejweb.modules.call.entity.MemberEntity;
import com.ejweb.modules.call.util.PhoneAreaEntity;
import com.ejweb.modules.call.util.PhoneAreaUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service
@Transactional(readOnly = true)
public class CallService extends BaseService<CallDao> {
public void createCallRecord(CallRecordEntity entity){
dao.createCallRecord(entity);
}
public void updateCallRecord(CallRecordEntity entity){
dao.updateCallRecord(entity);
}
public Integer addCallPhoneList(List<CallPhoneBean> phoneList){
return dao.addCallPhoneList(phoneList);
}
/**
* 获取通话记录列表
*
* @author renmb
* @time 2016年12月6日
* @param bean
* @return
*/
public PageEntity<CallRecordListEntity> getCallRecordList(CallRecordListBean bean){
// return dao.getCallRecordList(bean);
PageInfo<CallRecordListEntity> pageInfo = null;
Date current = new Date();
Date startTime = DateUtils.addDays(current, -3);
bean.setStartTime(DateFormatUtils.format(startTime, "yyyy-MM-dd 00:00:00"));
bean.setEndTime(DateFormatUtils.format(current, "yyyy-MM-dd 23:59:59"));
// 必须紧贴dao的查询方法
PageHelper.startPage(bean.getPageNo(), bean.getPageSize());
pageInfo = new PageInfo<CallRecordListEntity>(dao.getCallRecordList(bean));
if(pageInfo.getPages()<bean.getPageNo()){// 页码大于总页数,则返回NULL
return null;
}
List<CallRecordListEntity> list = pageInfo.getList();
if (list == null || list.size() == 0) {// 如果没有数据则返回NULL
return null;
}
//过滤重复记录
List<CallRecordListEntity> templist = new ArrayList<CallRecordListEntity>();
for (CallRecordListEntity callRecordListEntity : list) {
CallRecordListEntity entity = dao.get(callRecordListEntity);
if(entity!=null){
templist.add(callRecordListEntity);
}
}
if(templist.size()>0){
list.removeAll(templist);
}
PageEntity<CallRecordListEntity> page = new PageEntity<CallRecordListEntity>();
page.setPageNo(pageInfo.getPageNum());
page.setPageSize(pageInfo.getPageSize());
page.setCount(pageInfo.getTotal());
page.setTotalPage(pageInfo.getPages());
page.setList(pageInfo.getList());
return page;
}
public PageEntity<CallRecordListEntity> getCallSoundList(CallRecordListBean bean){
// return dao.getCallRecordList(bean);
PageInfo<CallRecordListEntity> pageInfo = null;
Date current = new Date();
Date startTime = DateUtils.addDays(current, -6);
bean.setStartTime(DateFormatUtils.format(startTime, "yyyy-MM-dd 00:00:00"));
bean.setEndTime(DateFormatUtils.format(current, "yyyy-MM-dd 23:59:59"));
// 必须紧贴dao的查询方法
PageHelper.startPage(bean.getPageNo(), bean.getPageSize());
pageInfo = new PageInfo<CallRecordListEntity>(dao.getCallSoundList(bean));
if(pageInfo.getPages()<bean.getPageNo()){// 页码大于总页数,则返回NULL
return null;
}
List<CallRecordListEntity> list = pageInfo.getList();
if (list == null || list.size() == 0) {// 如果没有数据则返回NULL
return null;
}
PageEntity<CallRecordListEntity> page = new PageEntity<CallRecordListEntity>();
page.setPageNo(pageInfo.getPageNum());
page.setPageSize(pageInfo.getPageSize());
page.setCount(pageInfo.getTotal());
page.setTotalPage(pageInfo.getPages());
page.setList(pageInfo.getList());
return page;
}
/**
* 根据电话号码查询,通话来电号码查询用户信息
*
* 1、席位优先
* 2、查询最近通话记录
* 3、查询用户表,如果有多个用户就展示用户手机号或者座机号
*
* @author renmb
* @time 2017年1月5日
* @param bean
* @return
*/
public List<CallPhoneInfoListEntity> findUserByCallPhone(CallFindPhoneInfoBean bean, boolean isOnlySearch){
// CallFindPhoneInfoBean bean = new CallFindPhoneInfoBean();
// bean.setPhoneNumer(phoneNumer);
bean.setMobileNubmer0("0"+bean.getPhoneNumer());
bean.setMobileNubmer00("00"+bean.getPhoneNumer());
List<CallPhoneInfoListEntity> callList = dao.findUserByCallRecord(bean);
// List<CallPhoneInfoListEntity> seatList = dao.findSeatListByCallPhone(bean);
if(callList == null || callList.size() == 0){// 没有匹配到席位信息
// List<CallPhoneInfoListEntity> callList = dao.findUserByCallRecord(bean);
List<CallPhoneInfoListEntity> seatList = dao.findSeatListByCallPhone(bean);
if(seatList == null || seatList.size() == 0){// 没有匹配到通话记录信息
List<CallPhoneInfoListEntity> userList = dao.findUserByCallPhone(bean);
if(userList == null || userList.size() == 0 || userList.size() > 1){// 没有匹配到用户信息,或者匹配个数大于1
CallPhoneInfoListEntity entity = new CallPhoneInfoListEntity();
entity.setType("PHONE");
entity.setUserId("");
entity.setName(bean.getPhoneNumer());
entity.setPhone(bean.getPhoneNumer());
List<CallPhoneInfoListEntity> phoneList = new ArrayList<CallPhoneInfoListEntity>(1);
phoneList.add(entity);
return phoneList;
} else{// 有用户信息直接返回
return userList;
}
} else {// 有通话记录信息,直接返回
return seatList;
}
} else{// 有席位信息直接返回
return callList;
}
}
/**
* 被叫方添加通话记录
*
* @author renmb
* @time 2017年3月17日
* @param bean
* @param fromUser
*/
public void addCallRecordByCalled(CallFindPhoneInfoBean bean, CallPhoneInfoListEntity fromUser){
if("RECORD".equals(fromUser.getFromType())){// 记录是从通话记录里面获取的
return ;
}
CallPhoneInfoListEntity calledUser = dao.findUserInfoByNumOrId(bean);// 被拨打方用户信息
if(calledUser == null){
return ;
}
CallRecordEntity record = new CallRecordEntity();
record.setCallType("USER");
record.setEndStatus("CALLING");
record.setId(IdWorker.getNextId());
record.setChannelType("APP");
record.setStartTime(new Date());
record.setAppCode(bean.getAppCode());
record.setPlatform(bean.getPlatform());
record.setVersionName(bean.getVersionName());
record.setUserCount(1);
if(StringUtils.isEmpty(fromUser.getUserId())){
record.setCreateBy("");
record.setCreateName(bean.getPhoneNumer());
record.setCreatePhone(bean.getPhoneNumer());
record.setCreateShowPhone(bean.getPhoneNumer());
record.setPhoneType(Util.getPhoneType(bean.getPhoneNumer()));
} else{
record.setCreateBy(fromUser.getUserId());
record.setCreateName(fromUser.getName());
record.setCreatePhone(fromUser.getHuaweiNum());
record.setCreateShowPhone(bean.getPhoneNumer());
record.setPhoneType(Util.getPhoneType(fromUser.getHuaweiNum()));
}
this.createCallRecord(record);// 添加主记录
CallPhoneBean calledPhone = new CallPhoneBean();
calledPhone.setId(IdWorker.getNextId());
calledPhone.setPhoneType(Util.getPhoneType(bean.getPhoneNumer()));
calledPhone.setRecordId(record.getId());
calledPhone.setTitle(bean.getPhoneNumer());
calledPhone.setFlow("CALLED");
calledPhone.setUsername(calledUser.getName());
calledPhone.setUserId(calledUser.getUserId());
List<CallPhoneBean> phoneList = new ArrayList<CallPhoneBean>(1);
phoneList.add(calledPhone);
this.addCallPhoneList(phoneList);// 添加电话列表
}
/**
* 综合查询手机号的归属地信息
*
* @author renmb
* @time 2017年1月22日
* @param mobile
* @return
*/
@Transactional(readOnly = false)
public CallPhoneAreaEntity addPhoneArea(String mobile){
if(StringUtils.isEmpty(mobile) || mobile.length()<7){
return null;
}
String src = new String(mobile);
CallPhoneAreaEntity phoneArea = null;
mobile = mobile.replaceAll("^0+", "");// 去掉手机号前面的0
if(mobile.length()>7){
CallPhoneAreaEntity searchMobile = new CallPhoneAreaEntity();
// 第一步:通过查询记录获取手机归属地信息,暂时注释掉不适用,主要用于控制特殊号码的归宿地查询
/*
searchMobile.setMobileNubmer0("0"+mobile);
searchMobile.setMobileNubmer00("00"+mobile);
searchMobile.setMobileNubmer000("000"+mobile);
phoneArea = dao.getPhoneAreaByMobile(searchMobile);// 到记录表里面查询
if(phoneArea != null && StringUtils.isNotEmpty(phoneArea.getPremobile())){
phoneArea.setMobileNubmer(phoneArea.getPremobile()+mobile);
return phoneArea;
}
*/
// 第二步: 通过地区码查询手机归宿地信息
searchMobile.setAreaCode(mobile.substring(0, 7));
searchMobile.setMobile(mobile);
phoneArea = dao.getPhoneAreaByAreaCode(searchMobile);
if(phoneArea != null && StringUtils.isNotEmpty(phoneArea.getPremobile())){
phoneArea.setMobileNubmer(phoneArea.getPremobile()+mobile);
return phoneArea;
}
// 第三步:通过360接口获取归属地信息
phoneArea = this.getCallPhoneAreaBy360(mobile);
if(phoneArea != null){
if(StringUtils.isNotEmpty(phoneArea.getPremobile())){// 手机类型进行缓存数据库
phoneArea.setId(IdWorker.getNextId());
phoneArea.setUpdateDate(new Date());
if(phoneArea.getMobile().length()>=7){
phoneArea.setAreaCode(phoneArea.getMobile().substring(0, 7));
dao.addPhoneAreaCode(phoneArea);
}
dao.addPhoneAreaRecord(phoneArea);
} else{// 非手机号,按座机号处理
phoneArea.setShowPhone(src);
phoneArea.setPhone(Util.formatedWorkPhone(src));
phoneArea.setType("PHONE");
}
return phoneArea;
}
}
phoneArea = new CallPhoneAreaEntity();
phoneArea.setShowPhone(src);
phoneArea.setPhone(Util.formatedWorkPhone(src));
phoneArea.setType("PHONE");
return phoneArea;
}
@Transactional(readOnly = false)
public CallPhoneAreaEntity getCallPhoneAreaBy360(String mobile){
CallPhoneAreaEntity callPhone = new CallPhoneAreaEntity();
callPhone.setMobile(mobile);
if(StringUtils.isNotBlank(mobile)){// 格式化手机号
if(mobile.startsWith("+")){// 国外手机号,前面加拨3个0
callPhone.setType("MOBILE");
callPhone.setPremobile("000");
callPhone.setMobileNubmer("000"+mobile.replace("+", ""));
return callPhone;
} else if(mobile.startsWith("0") == false){// 可能是手机号
PhoneAreaEntity area = PhoneAreaUtil.get360PhoneArea(mobile);
if(area == null){
area = PhoneAreaUtil.get360PhoneArea(mobile);
}
if(area != null && StringUtils.isNotBlank(area.getProvince())){// 能够查到省份信息
if(area.getProvince().contains("北京")
|| (StringUtils.isNotBlank(area.getCity()) && area.getCity().contains("北京"))){// 北京前面加拨一个0
callPhone.setType("MOBILE");
callPhone.setMobileNubmer("0"+mobile);// 加拨1个0
callPhone.setPremobile("0");
callPhone.setMobileProvince("北京");
callPhone.setMobileCity("北京");
callPhone.setMobileSp(StringUtils.isBlank(area.getSp()) ? "" : area.getSp());
return callPhone;
} else {// 非北京号码加拨两个0
callPhone.setType("MOBILE");
callPhone.setMobileNubmer("00"+mobile);// 加拨2个0
callPhone.setPremobile("00");
callPhone.setMobileProvince(area.getProvince());
callPhone.setMobileCity(StringUtils.isBlank(area.getCity()) ? "" : area.getCity());
callPhone.setMobileSp(StringUtils.isBlank(area.getSp()) ? "" : area.getSp());
return callPhone;
}
}
}
}
// 非手机号,按座机号处理
callPhone.setShowPhone(mobile);
callPhone.setPhone(Util.formatedWorkPhone(mobile));
callPhone.setType("PHONE");
return callPhone;
}
/**
* 添加安科同步过来的数据
*
* @author renmb
* @time 2017年2月28日
* @param entity
* @return
*/
public boolean addSoundRecord(CallSoundRecordBean entity,List<CallPhoneBean> phoneList,CallRecordEntity record){
dao.createCallRecord(record);
dao.addCallPhoneList(phoneList);
Integer count = dao.addSoundRecord(entity);
return count != null && count > 0;
}
public Map<String, String> findPhneByHuaweiNum(List<String> huweiNumList){
HuaweiNumListEntity entity = new HuaweiNumListEntity();
entity.setHuweiNumList(huweiNumList);
List<CallPhoneInfoListEntity> list = dao.findPhneListByHuaweiNum(entity);
if(list == null || list.size() == 0){
return null;
}
Map<String, String> map = new HashMap<String, String>();
for(CallPhoneInfoListEntity p:list){
map.put(p.getHuaweiNum(), p.getPhone());
}
return map;
}
public String GetPhoneById(String id){
return dao. GetPhoneById( id);
}
public List<MemberEntity> getMemberList(String id) {
return dao.getMemberList( id);
}
// public static void main(String[] args){
// Date current = new Date();
// Date startTime = DateUtils.addDays(current, -6);
// System.out.println(DateFormatUtils.format(startTime, "yyyy-MM-dd 00:00:00"));
// System.out.println(DateFormatUtils.format(current, "yyyy-MM-dd 23:59:59"));
// }
public String getNameByPhone(String createPhone) {
// TODO Auto-generated method stub
return dao.getNameByPhone(createPhone);
}
public String getNameByPhoneFromSeat(String createPhone) {
// TODO Auto-generated method stub
return dao.getNameByPhoneFromSeat(createPhone);
}
public String getIdByPhoneFromSeat(String callNo) {
// TODO Auto-generated method stub
return dao.getIdByPhoneFromSeat(callNo);
}
public String getIdByPhone(String callNo) {
// TODO Auto-generated method stub
return dao.getIdByPhone(callNo);
}
}
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