NoticebillAction:
package com.xushuai.bos.web.action;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.xushuai.bos.entity.Noticebill;
import com.xushuai.bos.service.NoticebillService;
import com.xushuai.bos.utils.BOSUtils;
import com.xushuai.crm.Customer;
import com.xushuai.crm.CustomerService;
@Controller("noticebillAction")
@Scope("prototype")
public class NoticebillAction extends BaseAction<Noticebill> {
@Autowired
@Qualifier("crmService")
private CustomerService proxyCustomerService;
public void setProxyCustomerService(CustomerService proxyCustomerService) {
this.proxyCustomerService = proxyCustomerService;
}
@Autowired
@Qualifier("noticebillService")
private NoticebillService noticebillService;
public void setNoticebillService(NoticebillService noticebillService) {
this.noticebillService = noticebillService;
}
//Receive customer parameter
private Customer customer;
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
/**
* Load customer information by mobile number
* @return
*/
public String findCustomerByTelephone(){
Customer customer = proxyCustomerService.findByTelephone(model.getTelephone());
BOSUtils.writerJson(customer, null);
return NONE;
}
/**
* Add business notification
* @return
*/
public String add(){
//Call service#save(model)
noticebillService.save(model);
return "noticebill_add";
}
/**
* Add customer information
* @return
*/
public String addCustomer(){
proxyCustomerService.addCustomer(customer);
return NONE;
}
}
NoticebillService、NoticebillServiceImpl:
package com.xushuai.bos.service;
import com.xushuai.bos.entity.Noticebill;
public interface NoticebillService {
/**
* Save the new business notification
* @param model
*/
void save(Noticebill model);
}
package com.xushuai.bos.service.impl;
import java.sql.Timestamp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.xushuai.bos.dao.DecidedzoneDao;
import com.xushuai.bos.dao.NoticebillDao;
import com.xushuai.bos.dao.WorkbillDao;
import com.xushuai.bos.entity.Decidedzone;
import com.xushuai.bos.entity.Noticebill;
import com.xushuai.bos.entity.Staff;
import com.xushuai.bos.entity.Workbill;
import com.xushuai.bos.service.NoticebillService;
import com.xushuai.bos.utils.BOSUtils;
import com.xushuai.crm.CustomerService;
@Service("noticebillService")
@Transactional
public class NoticebillServiceImpl implements NoticebillService {
@Autowired
@Qualifier("noticebillDao")
private NoticebillDao noticebillDao;
public void setNoticebillDao(NoticebillDao noticebillDao) {
this.noticebillDao = noticebillDao;
}
@Autowired
@Qualifier("decidedzoneDao")
private DecidedzoneDao decidedzoneDao;
public void setDecidedzoneDao(DecidedzoneDao decidedzoneDao) {
this.decidedzoneDao = decidedzoneDao;
}
@Autowired
@Qualifier("workbillDao")
private WorkbillDao workbillDao;
public void setWorkbillDao(WorkbillDao workbillDao) {
this.workbillDao = workbillDao;
}
@Autowired
@Qualifier("crmService")
private CustomerService proxyCustomerService;
public void setProxyCustomerService(CustomerService proxyCustomerService) {
this.proxyCustomerService = proxyCustomerService;
}
@Override
public void save(Noticebill model) {
//Set the user who generated this notification
model.setUser(BOSUtils.getLoginUser());
noticebillDao.save(model);
/*
* Order split operation
*/
//Get the pickup address
String pickaddress = model.getPickaddress();
String decidedzoneidId = null;
Decidedzone decidedzone = null;
try {
//Call crm to query the ID of the fixed area
decidedzoneidId = proxyCustomerService.findDecidedzoneidByAddress(pickaddress);
//Call DecidedzoneDao#findById to query the fixed zone
decidedzone = decidedzoneDao.findById(decidedzoneidId);
} catch (Exception e) {
}
/ / Check whether the query to the fixed area
if(decidedzone != null){
//Not empty, automatic order splitting
Staff staff = decidedzone.getStaff();
model.setStaff(staff);
//Set the order split type to: automatic order split
model.setOrdertype(Noticebill.ORDERTYPE_AUTO);
//Generate a work order for this dispatcher
Workbill workbill = new Workbill();
workbill.setAttachbilltimes(0);//The number of chasing orders, the new order is: 0
workbill.setBuildtime(new Timestamp(System.currentTimeMillis()));//Work order creation time: current system time
workbill.setNoticebill(model);
workbill.setPickstate(Workbill.PICKSTATE_NO);//Pickup status, the new order is: not picked up
workbill.setRemark(model.getRemark());//Remarks
workbill.setStaff(staff);//Set the dispatcher
workbill.setType(Workbill.TYPE_NEW);//Work order type, new order is: new order
// save the work order
workbillDao.save(workbill);
}else{
//If the fixed area is not queried, automatic order distribution cannot be performed, and manual order distribution is required
model.setOrdertype(Noticebill.ORDERTYPE_MAN);
}
}
}
Struts.xml:
<!-- Business Notice Module-->
<action name="NoticebillAction_*" class="noticebillAction" method="{1}">
<result name="noticebill_add">/WEB-INF/pages/qupai/noticebill_add.jsp</result>
</action>
page:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Add business receipt</title>
<!-- Import jquery core class library -->
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- Import easyui class library -->
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath }/css/default.css">
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("body").css({visibility:"visible"});
// Conditional click event for save button
$('#save').click(function(){
// Validate the form
if($('#noticebillForm').form('validate')){
var customerId = $("input[name=customerId]").val();
if(customerId == "" || customerId == undefined){
//If the customer information is not queried according to the mobile phone number, save the new customer information to crm
$.post('NoticebillAction_addCustomer.action',
{'customer.name':$("input[name=customerName]").val(),
'customer.telephone':$("input[name=telephone]").val(),
'customer.address':$("input[name=pickaddress]").val()},
function(data){
});
}
$('#noticebillForm').submit();
}
});
//Bind the lost focus event for the phone number input box
$("input[name=telephone]").blur(function(){
//Send an ajax request to load customer data
$.post('NoticebillAction_findCustomerByTelephone.action',{'telephone':this.value},function(data){
//Determine whether the data is queried
if(data != null){
//Load customer data to the page
$("input[name=customerId]").val(data.id);
$("input[name=customerName]").val(data.name);
$("input[name=delegater]").val(data.name);
$("input[name=pickaddress]").val(data.address);
}else{
//Clear page data
$("input[name=customerId]").val("");
$("input[name=customerName]").val("");
$("input[name=delegater]").val("");
$("input[name=pickaddress]").val("");
}
});
});
});
</script>
</head>
<body class="easyui-layout" style="visibility:hidden;">
<div region="north" style="height:31px;overflow:hidden;" split="false"
border="false">
<div class="datagrid-toolbar">
<a id="save" icon="icon-save" href="#" class="easyui-linkbutton"
plain="true">新单</a>
<a id="edit" icon="icon-edit" href="${pageContext.request.contextPath }/page_qupai_noticebill.action" class="easyui-linkbutton"
plain="true">Ticket operation</a>
</div>
</div>
<div region="center" style="overflow:auto;padding:5px;" border="false">
<form id="noticebillForm" action="NoticebillAction_add.action" method="post">
<table class="table-edit" width="95%" align="center">
<tr class="title">
<td colspan="4">Customer Information</td>
</tr>
<tr>
<td>Caller ID:</td>
<td><input type="text" class="easyui-validatebox" name="telephone"
required="true" /></td>
<td>Customer ID:</td>
<td><input type="text" class="easyui-validatebox" readonly="readonly" name="customerId"/></td>
</tr>
<tr>
<td>Customer Name:</td>
<td><input type="text" class="easyui-validatebox" name="customerName" required="true"/></td>
<td>Contact:</td>
<td><input type="text" class="easyui-validatebox" name="delegater"/></td>
</tr>
<tr class="title">
<td colspan="4">Cargo Information</td>
</tr>
<tr>
<td>Product Name:</td>
<td><input type="text" class="easyui-validatebox" name="product"/></td>
<td>件数:</td>
<td><input type="text" class="easyui-numberbox" name="num"/></td>
</tr>
<tr>
<td>重量:</td>
<td><input type="text" class="easyui-numberbox" name="weight"/></td>
<td>Volume:</td>
<td><input type="text" class="easyui-validatebox" name="volume"/></td>
</tr>
<tr>
<td>Pickup address</td>
<td colspan="3"><input type="text" class="easyui-validatebox" name="pickaddress"
required="true" size="144"/></td>
</tr>
<tr>
<td>Arrival City:</td>
<td><input type="text" class="easyui-validatebox" name="arrivecity"/></td>
<td>Appointment pickup time:</td>
<td><input type="text" class="easyui-datebox" name="pickdate"
data-options="editable:false" /></td>
</tr>
<tr>
<td>Note:</td>
<td colspan="3"><textarea rows="5" cols="80" type="text" class="easyui-validatebox" name="remark"></textarea></td>
</tr>
</table>
</form>
</div>
</body>
</html>
crm_webservice (CustomerService, CustomerServiceImpl new method and its implementation):
/**
* Query customer information by phone number
* @param telephone
* @return
*/
public Customer findByTelephone(String telephone);
/**
* Query the fixed area according to the customer's address
* @param address
* @return
*/
public String findDecidedzoneidByAddress(String address);
/**
* Add new customers
* @param customer
* @return
*/
public void addCustomer(Customer customer);
@Override
public Customer findByTelephone(String telephone) {
String sql = "SELECT * FROM t_customer WHERE telephone = ?";
List<Customer> list = jdbcTemplate.query(sql, new RowMapper<Customer>(){
public Customer mapRow(ResultSet rs, int arg1) throws SQLException {
int id = rs.getInt("id");
String name = rs.getString("name");
String station = rs.getString("station");
String telephone = rs.getString("telephone");
String address = rs.getString("address");
String decidedzone_id = rs.getString("decidedzone_id");
return new Customer(id,name,station,telephone,address, decidedzone_id);
}
},telephone);
if(list != null && list.size() > 0)
return list.get(0);
return null;
}
@Override
public String findDecidedzoneidByAddress(String address) {
String sql = "SELECT decidedzone_id FROM t_customer WHERE address = ?";
return jdbcTemplate.queryForObject(sql, String.class, address);
}
@Override
public void addCustomer(Customer customer) {
String sql = "INSERT INTO t_customer(name,telephone,address) VALUES(?,?,?)";
jdbcTemplate.update(sql, customer.getName(),customer.getTelephone(),customer.getAddress());
}