crm部分:
CustomerSerivce:
package com.xushuai.service;
import java.util.List;
import javax.jws.WebService;
import com.xushuai.entity.Customer;
@WebService
public interface CustomerService {
/**
* 查询所有客户信息
* @return
*/
public List<Customer> findAll();
/**
* 查询未关联定区的客户信息
* @return
*/
public List<Customer> findListNotAssociation();
/**
* 按定区ID查询该定区所关联的客户信息
* @param decidedzoneId
* @return
*/
public List<Customer> findListHasAssociation(String decidedzoneId);
/**
* 将客户关联到指定定区
*/
public void assignCustomersToDecidedzone(String decidedzoneId, Integer[] customerIds);
}
CustomerServiceImpl:
package com.xushuai.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.transaction.annotation.Transactional;
import com.xushuai.entity.Customer;
@Transactional
public class CustomerServiceImpl implements CustomerService {
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public List<Customer> findAll() {
String sql = "SELECT * FROM t_customer";
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);
}
});
return list;
}
@Override
public List<Customer> findListNotAssociation() {
String sql = "SELECT * FROM t_customer WHERE decidedzone_id IS NULL";
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);
}
});
return list;
}
@Override
public List<Customer> findListHasAssociation(String decidedzoneId) {
String sql = "SELECT * FROM t_customer WHERE decidedzone_id = ?";
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);
}
},decidedzoneId);
return list;
}
@Override
public void assignCustomersToDecidedzone(String decidedzoneId, Integer[] customerIds) {
//先将指定定区的客户清空
String sql = "UPDATE t_customer SET decidedzone_id = null WHERE decidedzone_id = ?";
jdbcTemplate.update(sql, decidedzoneId);
sql = "UPDATE t_customer SET decidedzone_id = ? WHERE id = ?";
for (Integer id : customerIds) {
jdbcTemplate.update(sql, decidedzoneId,id);
}
}
}
cxf.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<!-- 配置DataSource -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql:///crm_service"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
</bean>
<!-- 配置事务管理器 -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 开启注解配置事务 -->
<tx:annotation-driven transaction-manager="txManager"/>
<!-- jdbc模板 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置service -->
<bean id="customerService" class="com.xushuai.service.CustomerServiceImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
</bean>
<!-- 注册webserviece -->
<jaxws:server id="cstService" address="/customer">
<jaxws:serviceBean>
<ref bean="customerService"/>
</jaxws:serviceBean>
</jaxws:server>
</beans>
BOS部分:
DecidedzoneAction(新增方法):
@Autowired
@Qualifier("crmService")
private CustomerService proxyCustomerService;
public void setProxyCustomerService(CustomerService proxyCustomerService) {
this.proxyCustomerService = proxyCustomerService;
}
/**
* 调用WebService获取未关联定区的客户信息
* @return
*/
public String findListNotAssociation(){
List<Customer> list = proxyCustomerService.findListNotAssociation();
BOSUtils.writerJson(list, null);
return NONE;
}
/**
* 调用WebService获取未关联定区的客户信息
* @return
*/
public String findListHasAssociation(){
List<Customer> list = proxyCustomerService.findListHasAssociation(model.getId());
BOSUtils.writerJson(list, null);
return NONE;
}
/**
* 调用WebService修改定区所关联的客户
* @return
*/
public String assigncustomerstodecidedzone(){
proxyCustomerService.assignCustomersToDecidedzone(model.getId(), customerIds);
return LIST;
}
applicationContext.xml(新增配置):
<!-- 配置crm项目服务 -->
<jaxws:client id="crmService" serviceClass="com.xushuai.crm.CustomerService" address="http://localhost:8080/crm_webs ervice/service/customer"/>
新decidedzone.jsp:
<%@ 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>管理定区/调度排班</title>
<!-- 导入jquery核心类库 -->
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 导入easyui类库 -->
<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"
src="${pageContext.request.contextPath }/js/jquery.formToJson.js"></script>
<script type="text/javascript">
function doClear(){
$("#grid").datagrid('clearSelections');
}
function doAdd(){
$('#addDecidedzoneWindow').window("open");
}
function doEdit(){
//获取被选中的行
var row = $("#grid").datagrid('getSelections')[0];
if(row == undefined){
$.messager.alert('提示信息','请选中您要修改的定区','warning');
}else{
$('#editDecidedzoneWindow').window("open");
console.info(row);
//回显取派员信息
$('#editDecidedzoneWindow').form("load",row);
$("#editStaff").combobox('setValue',row.staff.id);
$("#editStaff").combobox('setText',row.staff.name);
$("#subareaGrid2").datagrid('reload');
}
}
//删除按钮
function doDelete(){
//获取被选中的行
var rows = $("#grid").datagrid('getSelections');
//判断是否有行被选中
if(rows.length == 0){
$.messager.alert('提示信息','请选中您要删除的定区','warning');
}else{
$.messager.confirm('提示信息', '确定要执行删除操作吗?', function(r){
if (r){
location.href = "DecidedzoneAction_delete.action?id=" + rows[0].id;
}
});
}
}
function doSearch(){
$('#searchWindow').window("open");
}
function doAssociations(){
var rows = $("#grid").datagrid('getSelections');
if(rows.length == 0){
$.messager.alert('提示信息','请选择你要关联客户的定区','warning');
}else{
$('#customerWindow').window('open');
$("#noassociationSelect").empty();
$("#associationSelect").empty();
//异步加载未关联定区的客户
$.post('DecidedzoneAction_findListNotAssociation.action',function(data){
for(var i = 0; i < data.length; i++){
$("#noassociationSelect").append("<option value='"+data[i].id+"'>"+data[i].name +"("+data[i].telephone+")"
+"</option>");
}
});
//异步加载选中定区所关联的客户
$.post('DecidedzoneAction_findListHasAssociation.action',{'id':rows[0].id},function(data){
for(var i = 0; i < data.length; i++){
$("#associationSelect").append("<option value='"+data[i].id+"'>"+data[i].name +"("+data[i].telephone+")"
+"</option>");
}
});
}
}
function subareaDelete(){
var row = $("#association_subarea").datagrid('getSelections')[0];
if(row == undefined){
$.messager.alert('提示信息','请选中您要删除的分区','warning');
}else{
$.post('SubareaAction_ajaxDecidedzoneDelete.action',{'id':row.id},function(data){
$("#association_subarea").datagrid('reload');
});
}
}
//工具栏
var toolbar = [ {
id : 'button-search',
text : '查询',
iconCls : 'icon-search',
handler : doSearch
}, {
id : 'button-add',
text : '增加',
iconCls : 'icon-add',
handler : doAdd
}, {
id : 'button-edit',
text : '修改',
iconCls : 'icon-edit',
handler : doEdit
},{
id : 'button-delete',
text : '删除',
iconCls : 'icon-cancel',
handler : doDelete
},{
id : 'button-association',
text : '关联客户',
iconCls : 'icon-sum',
handler : doAssociations
}, {
id : 'button-clearSel',
text : '取消选中',
handler : doClear
}];
// 定义列
var columns = [ [ {
field : 'id',
title : '定区编号',
width : 120,
align : 'center'
},{
field : 'name',
title : '定区名称',
width : 120,
align : 'center'
}, {
field : 'staff.name',
title : '取派员',
width : 120,
align : 'center',
formatter : function(data,row ,index){
return row.staff.name;
}
}, {
field : 'staff.telephone',
title : '联系电话',
width : 120,
align : 'center',
formatter : function(data,row ,index){
return row.staff.telephone;
}
}, {
field : 'staff.station',
title : '所属公司',
width : 120,
align : 'center',
formatter : function(data,row ,index){
return row.staff.station;
}
} ] ];
$(function(){
// 先将body隐藏,再显示,不会出现页面刷新效果
$("body").css({visibility:"visible"});
// 收派标准数据表格
$('#grid').datagrid( {
iconCls : 'icon-forward',
fit : true,
border : true,
rownumbers : true,
striped : true,
singleSelect:true,
pageList: [15,20,28],
pageSize:28,
pagination : true,
toolbar : toolbar,
url : "DecidedzoneAction_pageQuery.action",
idField : 'id',
columns : columns,
onDblClickRow : doDblClickRow
});
// 添加、修改定区
$('#addDecidedzoneWindow').window({
title: '添加定区',
width: 800,
modal: true,
shadow: true,
closed: true,
height: 400,
resizable:false
});
$("#save").click(function(){
var formFlag = $("#addDecidedzoneWindow").form('validate');
if(formFlag){
$("#addDecidedzoneForm").submit();
}
});
//修改定区
$('#editDecidedzoneWindow').window({
title: '修改定区',
width: 800,
modal: true,
shadow: true,
closed: true,
height: 400,
resizable:false
});
$("#edit").click(function(){
$("#editDecidedzoneForm").submit();
});
// 查询定区
$('#searchWindow').window({
title: '查询定区',
width: 400,
modal: true,
shadow: true,
closed: true,
height: 300,
resizable:false
});
$("#btn").click(function(){
//将form中的表单数据转换为json,用于提交
var params = $("#searchForm").serializeJson();
//console.info(params);
//提交参数,加载数据,关闭查询窗口
$("#grid").datagrid('load',params);
$("#searchWindow").window('close');
});
////////////////
//为关联客户窗口中的左右移动添加点击事件
$("#toRight").click(function(){
$("#associationSelect").append($("#noassociationSelect option:selected"));
});
$("#toLeft").click(function(){
$("#noassociationSelect").append($("#associationSelect option:selected"));
});
//为关联客户窗口中的关联客户按钮添加单击事件
$("#associationBtn").click(function(){
var rows = $("#grid").datagrid('getSelections');
$("#customerDecidedZoneId").val(rows[0].id);
//设置所有需要被关联的客户项为选中状态
$("#associationSelect option").attr('selected','selected');
$("#customerForm").submit();
});
});
//加载关联信息
function doDblClickRow(rowIndex, rowData){
$('#association_subarea').datagrid( {
fit : true,
border : true,
rownumbers : true,
striped : true,
method:'get',
singleSelect:true,
url : "SubareaAction_ajaxFindByDecidedzone.action?decidedzone.id=" + rowData.id,
toolbar:[{
id : 'subarea-delete',
text : '删除分区',
iconCls : 'icon-cancel',
handler : subareaDelete
}],
columns : [ [{
field : 'id',
title : '分区编号',
width : 235,
align : 'center'
},{
field : 'province',
title : '省',
width : 120,
align : 'center',
formatter : function(data,row ,index){
return row.region.province;
}
}, {
field : 'city',
title : '市',
width : 120,
align : 'center',
formatter : function(data,row ,index){
return row.region.city;
}
}, {
field : 'district',
title : '区',
width : 120,
align : 'center',
formatter : function(data,row ,index){
return row.region.district;
}
}, {
field : 'addresskey',
title : '关键字',
width : 120,
align : 'center'
}, {
field : 'startnum',
title : '起始号',
width : 100,
align : 'center'
}, {
field : 'endnum',
title : '终止号',
width : 100,
align : 'center'
} , {
field : 'single',
title : '单双号',
width : 100,
align : 'center'
} , {
field : 'position',
title : '位置',
width : 250,
align : 'center'
} ] ]
});
$('#association_customer').datagrid( {
fit : true,
border : true,
rownumbers : true,
striped : true,
singleSelect:true,
url : "DecidedzoneAction_findListHasAssociation.action?id=" + rowData.id,
method:'get',
columns : [[{
field : 'id',
title : '客户编号',
width : 120,
align : 'center'
},{
field : 'name',
title : '客户名称',
width : 120,
align : 'center'
}, {
field : 'station',
title : '所属单位',
width : 120,
align : 'center'
}]]
});
}
</script>
</head>
<body class="easyui-layout" style="visibility:hidden;">
<div region="center" border="false">
<table id="grid"></table>
</div>
<div region="south" border="false" style="height:150px">
<div id="tabs" fit="true" class="easyui-tabs">
<div title="关联分区" id="subArea"
style="width:100%;height:100%;overflow:hidden">
<table id="association_subarea"></table>
</div>
<div title="关联客户" id="customers"
style="width:100%;height:100%;overflow:hidden">
<table id="association_customer"></table>
</div>
</div>
</div>
<!-- 添加分区 -->
<div class="easyui-window" title="定区添加" id="addDecidedzoneWindow" collapsible="false" minimizable="false" maximizable="false" style="top:20px;left:200px">
<div 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>
</div>
</div>
<div style="overflow:auto;padding:5px;" border="false">
<form id="addDecidedzoneForm" action="DecidedzoneAction_add.action" method="post">
<table class="table-edit" width="80%" align="center">
<tr class="title">
<td colspan="2">定区信息</td>
</tr>
<tr>
<td>定区编码</td>
<td><input type="text" name="id" class="easyui-validatebox" required="true"/></td>
</tr>
<tr>
<td>定区名称</td>
<td><input type="text" name="name" class="easyui-validatebox" required="true"/></td>
</tr>
<tr>
<td>选择取派员</td>
<td>
<input class="easyui-combobox" name="staff.id"
data-options="valueField:'id',textField:'name',url:'StaffAction_ajaxList.action'" />
</td>
</tr>
<tr height="300">
<td valign="top">关联分区</td>
<td>
<table id="subareaGrid" class="easyui-datagrid" border="false" style="width:500px;height:300px" data-options="url:'SubareaAction_ajaxList.action',fitColumns:true,singleSelect:false">
<thead>
<tr>
<th data-options="field:'subareaId',width:30,checkbox:true">编号</th>
<th data-options="field:'addresskey',width:150">关键字</th>
<th data-options="field:'position',width:200,align:'right'">位置</th>
</tr>
</thead>
</table>
</td>
</tr>
</table>
</form>
</div>
</div>
<!-- 修改分区 -->
<div class="easyui-window" title="定区添加" id="editDecidedzoneWindow" collapsible="false" minimizable="false" maximizable="false" style="top:20px;left:200px">
<div style="height:31px;overflow:hidden;" split="false" border="false" >
<div class="datagrid-toolbar">
<a id="edit" icon="icon-edit" href="#" class="easyui-linkbutton" plain="true" >修改</a>
</div>
</div>
<div style="overflow:auto;padding:5px;" border="false">
<form id="editDecidedzoneForm" action="DecidedzoneAction_edit.action" method="post">
<input type="hidden" name="id">
<table class="table-edit" width="80%" align="center">
<tr class="title">
<td colspan="2">定区信息</td>
</tr>
<tr>
<td>定区名称</td>
<td><input type="text" name="name" class="easyui-validatebox" required="true"/></td>
</tr>
<tr>
<td>选择取派员</td>
<td>
<input id="editStaff" class="easyui-combobox" name="staff.id"
data-options="valueField:'id',textField:'name',url:'StaffAction_ajaxList.action'" />
</td>
</tr>
<tr height="300">
<td valign="top">关联分区</td>
<td>
<table id="subareaGrid2" class="easyui-datagrid" border="false" style="width:500px;height:300px" data-options="url:'SubareaAction_ajaxList.action',fitColumns:true,singleSelect:false">
<thead>
<tr>
<th data-options="field:'subareaId',width:30,checkbox:true">编号</th>
<th data-options="field:'addresskey',width:150">关键字</th>
<th data-options="field:'position',width:200,align:'right'">位置</th>
</tr>
</thead>
</table>
</td>
</tr>
</table>
</form>
</div>
</div>
<!-- 查询定区 -->
<div class="easyui-window" title="查询定区窗口" id="searchWindow" collapsible="false" minimizable="false" maximizable="false" style="top:20px;left:200px">
<div style="overflow:auto;padding:5px;" border="false">
<form id="searchForm">
<table class="table-edit" width="80%" align="center">
<tr class="title">
<td colspan="2">查询条件</td>
</tr>
<tr>
<td>定区名称</td>
<td><input type="text" name="name" class="easyui-validatebox"/></td>
</tr>
<tr>
<td>取派员姓名</td>
<td><input type="text" name="staff.name" class="easyui-validatebox"/></td>
</tr>
<tr>
<td colspan="2"><a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a> </td>
</tr>
</table>
</form>
</div>
</div>
<!-- 关联客户窗口 -->
<div modal=true class="easyui-window" title="关联客户窗口" id="customerWindow" collapsible="false" closed="true" minimizable="false" maximizable="false" style="top:20px;left:200px;width: 400px;height: 300px;">
<div style="overflow:auto;padding:5px;" border="false">
<form id="customerForm" action="${pageContext.request.contextPath }/DecidedzoneAction_assigncustomerstodecidedzone.action" method="post">
<table class="table-edit" width="80%" align="center">
<tr class="title">
<td colspan="3">关联客户</td>
</tr>
<tr>
<td>
<input type="hidden" name="id" id="customerDecidedZoneId" />
<select id="noassociationSelect" multiple="multiple" size="10"></select>
</td>
<td>
<input type="button" value=">>" id="toRight"><br/>
<input type="button" value="<<" id="toLeft">
</td>
<td>
<select id="associationSelect" name="customerIds" multiple="multiple" size="10"></select>
</td>
</tr>
<tr>
<td colspan="3"><a id="associationBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'">关联客户</a> </td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>