033 業務受理自動分單 - bos
一、在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);
}
}
033 業務受理自動分單 - bos