(1)、创建用户
(2)、指定用户的角色
(3)、赋予用户权限
crm
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:applicationContext.xml
cxf
org.apache.cxf.transport.servlet.CXFServlet
cxf
/webservice/*
package com.itheima.crm.domain;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* @description:客户信息表
*
*/
@Entity
@Table(name = "T_CUSTOMER")
public class Customer {
@Id
@GeneratedValue()
@Column(name = "C_ID")
private Integer id; // 主键id
@Column(name = "C_USERNAME")
private String username; // 用户名
@Column(name = "C_PASSWORD")
private String password; // 密码
@Column(name = "C_TYPE")
private Integer type; // 类型
@Column(name = "C_BRITHDAY")
@Temporal(TemporalType.DATE)
private Date birthday; // 生日
@Column(name = "C_SEX")
private Integer sex; // 性别
@Column(name = "C_TELEPHONE")
private String telephone; // 手机
@Column(name = "C_COMPANY")
private String company; // 公司
@Column(name = "C_DEPARTMENT")
private String department; // 部门
@Column(name = "C_POSITION")
private String position; // 职位
@Column(name = "C_ADDRESS")
private String address; // 地址
@Column(name = "C_MOBILEPHONE")
private String mobilePhone; // 座机
@Column(name = "C_EMAIL")
private String email; // 邮箱
@Column(name = "C_Fixed_AREA_ID")
private String fixedAreaId; // 定区编码
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getMobilePhone() {
return mobilePhone;
}
public void setMobilePhone(String mobilePhone) {
this.mobilePhone = mobilePhone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFixedAreaId() {
return fixedAreaId;
}
public void setFixedAreaId(String fixedAreaId) {
this.fixedAreaId = fixedAreaId;
}
}
insert into T_CUSTOMER
(C_ID,
C_ADDRESS,
C_BRITHDAY,
C_COMPANY,
C_DEPARTMENT,
C_EMAIL,
C_FIXED_AREA_ID,
C_MOBILEPHONE,
C_PASSWORD,
C_POSITION,
C_SEX,
C_TELEPHONE,
C_TYPE,
C_USERNAME)
values
(1,
'北京市海淀区建材城西路金燕龙办公楼一层',
to_date('01-07-1998', 'dd-mm-yyyy'),
'A公司',
'A部门',
'[email protected]',
'dq001',
'01012345671',
'123456',
'经理',
1,
'13112345678',
1,
'张三');
insert into T_CUSTOMER
(C_ID,
C_ADDRESS,
C_BRITHDAY,
C_COMPANY,
C_DEPARTMENT,
C_EMAIL,
C_FIXED_AREA_ID,
C_MOBILEPHONE,
C_PASSWORD,
C_POSITION,
C_SEX,
C_TELEPHONE,
C_TYPE,
C_USERNAME)
values
(2,
'北京市海淀区建材城西路育新花园9号楼111',
to_date('01-07-1998', 'dd-mm-yyyy'),
'B公司',
'B部门',
'[email protected]',
'dq002',
'01012345672',
'123456',
'经理',
1,
'13212345678',
1,
'李四');
insert into T_CUSTOMER
(C_ID,
C_ADDRESS,
C_BRITHDAY,
C_COMPANY,
C_DEPARTMENT,
C_EMAIL,
C_FIXED_AREA_ID,
C_MOBILEPHONE,
C_PASSWORD,
C_POSITION,
C_SEX,
C_TELEPHONE,
C_TYPE,
C_USERNAME)
values
(3,
'北京市海淀区中关村海龙大厦1111',
to_date('01-07-1998', 'dd-mm-yyyy'),
'C公司',
'C部门',
'[email protected]',
'dq001',
'01012345673',
'123456',
'经理',
1,
'13312345678',
1,
'王五');
insert into T_CUSTOMER
(C_ID,
C_ADDRESS,
C_BRITHDAY,
C_COMPANY,
C_DEPARTMENT,
C_EMAIL,
C_FIXED_AREA_ID,
C_MOBILEPHONE,
C_PASSWORD,
C_POSITION,
C_SEX,
C_TELEPHONE,
C_TYPE,
C_USERNAME)
values
(4,
'北京市海淀区中关村软件园国际软件大厦112',
to_date('01-07-1998', 'dd-mm-yyyy'),
'D公司',
'D部门',
'[email protected]',
null,
'01012345674',
'123456',
'经理',
1,
'3412345678',
1,
'赵六');
package com.itheima.crm.service;
import java.util.List;
import javax.jws.WebService;
import com.itheima.crm.domain.Customer;
/**
* webService服务接口
* @author Administrator
*
*/
@WebService
public interface CustomerService {
/**
* 查询所有客户
* @return
*/
public List findAll();
/**
* 查询未关联到定区的客户数据
* @return
*/
public List findCustomerNotAssociation();
/**
* 查询已经关联到指定定区的客户数据
* @param fixedAreaId
* @return
*/
public List findCustomersHasAssociation(String fixedAreaId);
}
package com.itheima.crm.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.itheima.crm.dao.CustomerDao;
import com.itheima.crm.domain.Customer;
import com.itheima.crm.service.CustomerService;
/**
* webService服务实现类
*
* @author Administrator
*
*/
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {
@Autowired
private CustomerDao dao;
/**
* 查询所有客户
*
* @return
*/
public List findAll() {
return dao.findAll();
}
/**
* 查询未关联到定区的客户数据
*
* @return
*/
public List findCustomerNotAssociation() {
return dao.findByFixedAreaIdIsNull();
}
/**
* 查询已经关联到指定定区的客户数据
*
* @param fixedAreaId
* @return
*/
public List findCustomersHasAssociation(String fixedAreaId) {
return dao.findByFixedAreaId(fixedAreaId);
}
}
package com.itheima.crm.dao;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import com.itheima.crm.domain.Customer;
public interface CustomerDao extends JpaRepository {
/**
* 查询未关联到定区的客户数据
* @return
*/
public List findByFixedAreaIdIsNull();
/**
* 查询已经关联到指定定区的客户数据
*
* @param fixedAreaId
* @return
*/
public List findByFixedAreaId(String fixedAreaId);
}
G:\apache-cxf-3.0.3\apache-cxf-3.0.3\bin>wsimport -s . http://localhost:8081/crm/webservice/customer?wsdl
(1)、点击关联客户按钮弹出的事件
function doAssociations(){
//获取当前数据表格选中的行
var rows = $("#grid").datagrid("getSelections");
if(rows.length != 1){
//弹出提示
$.messager.alert("提示信息","请选择一个定区来进行操作","warning");
}else{
$('#customerWindow').window('open');
//清空下拉框中的客户数据
$("#noassociationSelect").empty();
$("#associationSelect").empty();
/**
* 发送ajax请求,请求后台系统的Action,在Action中注入CRM代理对象,调用代理对象
* 实现访问CRM服务获取客户信息,在Action中将获取的客户数据转为json并写回当前浏览器
*/
//加载左侧未关联定区的客户
$.post("../../fixedAreaAction_findCustomersNoAssociation.action",function(data){
//解析服务器响应的json数据,展示到下拉框中
for(var i = 0; i < data.length; i++){
var json = data[i];
var id = json.id;
var tel = json.telephone;
var username = json.username + "[ " + tel + " ]";
$("#noassociationSelect").append("");
}
},'json');
//加载右侧已经关联到当前定区的客户列表
$.post("../../fixedAreaAction_findCustomersHasAssociation.action",{"id":rows[0].id},function(data){
//解析服务器响应的json数据,展示到下拉框中
for(var i = 0; i < data.length; i++){
var json = data[i];
var id = json.id;
var tel = json.telephone;
var username = json.username + "[ " + tel + " ]";
$("#associationSelect").append("");
}
},'json');
}
}
(2)、编写FixedAreaAction中代码
//注入CRM服务的客户端代理对象
@Autowired
private CustomerService crmProxy;
/**
* 查询未关联到定区的客户数据
*/
@Action(value="fixedAreaAction_findCustomersNoAssociation")
public String findCustomersNoAssociation(){
List listNo = crmProxy.findCustomerNotAssociation();
this.list2json(listNo, new String[]{});
return NONE;
}
/**
* 查询已经关联到指定定区的客户数据
* @return
*/
@Action(value="fixedAreaAction_findCustomersHasAssociation")
public String findCustomersHasAssociation(){
List listHas = crmProxy.findCustomersHasAssociation(model.getId());
this.list2json(listHas, new String[]{});
return NONE;
}
(3)、页面效果图
(1)、为窗口中“关联客户”按钮绑定点击事件,提交表单
关联客户
(2)、编写Action中关联客户的代码
/**
* 将客户关联到定区
*/
@Action(value="fixedAreaAction_assignCustomers2FixedArea",results={
@Result(name="success", type="redirect", location="/pages/base/fixed_area.html")
})
public String assignCustomers2FixedArea(){
//获取当前定区id
String fixedId = model.getId();
crmProxy.assingCustomers2FixedArea(fixedId, customerIds);
return SUCCESS;
}
(3)、扩展CRM项目中Service层代码
/**
* 关联客户到指定定区
* @param fixedAreaId
*/
public void assingCustomers2FixedArea(String fixedAreaId, Integer[] customerIds){
//将当前定区关联的所有客户的逻辑外键改为null
dao.setFixedAreaIdIsNull(fixedAreaId);
//重新建立关联,即将当前选中的客户添加到当前的分区中
if(customerIds != null && customerIds.length > 0){
for (Integer id : customerIds) {
dao.assignCustomer2FixedArea(fixedAreaId, id);
}
}
}
(4)、扩展CRM项目中的dao层代码
/**
* 将客户关联的定区为指定id的定区置空
* @param fixedAreaId
*/
@Query("update Customer set fixedAreaId = null where fixedAreaId = ?")
@Modifying
public void setFixedAreaIdIsNull(String fixedAreaId);
/**
* 关联客户到指定的定区
* @param fixedAreaId
* @param customerId
*/
@Query("update Customer set fixedAreaId = ? where id = ?")
@Modifying
public void assignCustomer2FixedArea(String fixedAreaId, Integer customerId);
(5)、重新使用wsimport命令生成客户端的接口代码
注意:服务端代码更新之后,必须重新生成客户端的服务端接口