一、在CRM中扩展方法:根据手机号查询客户信息以及根据客户的取件地址查询定区ID
1.实现代码如下
@Override
public Customer findCustomerByTelephone(String telephone) {
String sql = "select * from t_customer where telephone = ?";
List<Customer> customerList = jdbcTemplate.query(sql, new CustomerRowMapper(), telephone);
if(customerList != null && customerList.size() > 0){
return customerList.get(0);
}
return null;
}
@Override
public String findDecidedzoneIdByAddress(String address) {
String sql = "select decidedzone_id from t_customer where telephone = ?";
String decidedzoneId = jdbcTemplate.queryForObject(sql, String.class, address);
return decidedzoneId;
}
2.重新生成客户端调用类
wsimport -s . -p com.hao.crm.service http://localhost:8080/CRM/service/customer?wsdl
二、页面完善
1.为手机号输入框绑定失焦事件
$(function(){
//页面加载完成后为手机输入框绑定失焦事件
$("input[name=telephone]").blur(function(){
var telephone = this.value;
//发送ajax请求,在Action中调用crm服务获取客户信息,用于页面回显
$.ajax({
"url":"noticebillAction_findCustomerByTelephone.action",
"data":{"telephone":telephone},
"success":function(resp, textStatus, xmlHttp){
if(resp != null){
//查询到了客户信息,可以进行页面回显
var customerId = resp.id;
var customerName = resp.name;
var address = resp.address;
$("input[name=customerId]").val(customerId);
$("input[name=customerName]").val(customerName);
$("input[name=delegater]").val(customerName);
$("input[name=pickaddress]").val(address);
}else{
//没有查询到客户信息,清空已经回显的数据
$("input[name=customerId]").val("");
$("input[name=customerName]").val("");
$("input[name=delegater]").val("");
$("input[name=pickaddress]").val("");
}
},
"error":function(xmlHttp, testStatus, exception){
alert(textStatus);
}
});
});
});
2.创建NoticebillAction,注入crm代理对象,提供方法根据手机号查询客户
/**
* 调用crm根据电话查询客户信息
* @return
*/
public String findCustomerByTelephone(){
Customer customer = customerService.findCustomerByTelephone(model.getTelephone());
object2JsonAndWriteToResponse(customer);
return NONE;
}
三、服务端实现业务单受理以及自动分单功能
1.NoticebillAction.add实现
/**
* 添加新的业务通知单,并尝试自动分单
*/
public String add(){
noticebillService.save(model);
return LIST;
}
2.NoticebillService.save实现
/**
* 保存业务通知单并尝试自动分单
*/
@Override
public void save(Noticebill model) {
User user = BOSUtils.getLoginUser();
model.setUser(user);//设置当前登录的用户
noticebillDao.save(model);
//获取客户的取件地址
String pickaddress = model.getPickaddress();
//远程调用crm服务,根据取件地址查询定区ID
String decidedzoneId = customerService.findDecidedzoneIdByAddress(pickaddress);
if(decidedzoneId != null){
//匹配到了定区ID,可以进行自动分单
Decidedzone decidedzone = decidedzoneDao.findById(decidedzoneId);
Staff staff = decidedzone.getStaff();
model.setStaff(staff);// 业务通知关联取派员对象
//设置分单类型为自动分单
model.setOrdertype(Noticebill.ORDERTYPE_AUTO);
//为取派员产生一个工单
Workbill workbill = new Workbill();
workbill.setAttachbilltimes(0);
workbill.setBuildtime(new Timestamp(System.currentTimeMillis())); //创建时间,当前提供时间
workbill.setNoticebill(model); //工单关联业务通知单
workbill.setPickstate(Workbill.PICKSTATE_NO); //设置取件状态为未取件
workbill.setRemark(model.getRemark()); //备注信息
workbill.setStaff(staff);//工单关联取派员
workbill.setType(Workbill.TYPE_NEW); //新单
//保存工单
workbillDao.save(workbill);
//保存后调用短信平台发送短信
}else{
//没有查询到定区ID,不能进行自动分单
model.setOrdertype(Noticebill.ORDERTYPE_MAN);
}
}