定区关联快递员
需求:
- 显示快递员列表
- 显示收派时间列表
- 实现定区关联快递员
分析:
给关联快递员绑定点击事件
- 只能勾选一条定区
显示未删除的快递员列表
- 发送AJAX请求获取快递员的数据,并展示到下拉框中courierAction_listajax.action
- 在CourierAction中提供listajax方法, 并完善service和dao的编写
- 显示收派时间列表
- 在收派时间表中提供模拟数据
- 修改关联快递员窗口中收派时间的URL地址(takeTime_listajax.action)
- 创建收派时间对应的Action,Service, Dao
- 实现定区关联快递员,提交定区id, 快递员id, 收派时间id
- 注意在保存的时候的逻辑
- 快递员和收派时间的关系是多对一的关系, 由定区来管理关系
- 为窗口中”关联快递员”按钮绑定事件, 提交表单
- 在定区Action中提供方法和属性
- 在定区service中扩展方式, 实现定区关联快递员, 快递员关联时间
前端页面:
<input type="hidden" name="id"
id="takeTimeId" /> <input
data-options="ditable:false, url:'../../takeTimeAction_listajax.action',valueField:'id',textField:'name'"
type="text" name="takeTimeId" class="easyui-combobox"
required="true" />
<td>
<!-- 存放定区编号 --> <input type="hidden" name="fixedAreaId"
id="courierFixedAreaId" /> <input
data-options="ditable:false, url:'../../courierAction_listajax.action',valueField:'id',textField:'name'"
type="text" name="courierId" class="easyui-combobox"
required="true" />
</td>
<script type="text/javascript">
$(function() {
$("#associationCourierBtn").click(function() {
var rows = $("#grid").datagrid("getSelections");
$("#courierFixedAreaId").val(rows[0].id);
$("#courierForm").submit();
});
})
</script>
FixedAreaAction
@Action(value="fixedAreaAction_findByFixedAreaId")
public String findByFixedAreaId() throws IOException{
List<Customer> list = customerService.findByFixedAreaId(fixedAreaId);
this.list2Json(list, new String[] {});
return NONE;
}
@Action(value="fixedAreaAction_assignCustomers2FixedArea",
results={
@Result(name="success",location="/pages/base/fixed_area.html",type="redirect"),
})
public String fixedAreaAction_assignCustomers2FixedArea(){
customerService.setFixedAreaIdIsNull(fixedAreaId);
if(customerIds != null && customerIds.size()>0){
for (Integer integer : customerIds) {
System.out.println("cusid"+integer);
customerService.assignCustomers2FixedArea(fixedAreaId, integer);
}
}
return SUCCESS;
}
@Action(value="fixedAreaAction_associationCourierToFixedArea",
results={
@Result(name="success",location="/pages/base/fixed_area.html",type="redirect"),
})
public String associationCourierToFixedArea(){
fixedAreaService.associationCourierToFixedArea(courierId,fixedAreaId,takeTimeId);
return SUCCESS;
}
前台项目bos_fore导入
分析:
- 创建前台系统工程, 继承common_parent
- 将静态资源文件添加到前台中
- 配置web.xml
- 指定spring配置文件的位置
- 配置spring框架的监听器
- 配置struts2框架的过滤器
- 配置applicationContext.xml和log4j.properties文件
- 创建包结构
前台系统客户注册功能
需求
- 客户注册页面验证码60秒倒计时效果实现并发送请求
- 吉信通短信平台简介并测试发送短信
- 基于吉信通短信平台发送短信
- 客户注册页面调整并提交表单
- bos_fore服务端接收表单参数并校验手机验证码
- 在CRM服务中提供客户注册方法
- bos_fore中远程调用CRM实现客户注册
步骤:
- 注册页面验证码60秒倒计时效果分析
- 注册页面手机号码校验再显示倒计时
- 吉信通webservice简介和开发文档介绍
- SmsService代码分析
- 基于吉信通短信平台发送短信
- 客户注册页面调整并提交表单
- 注册流程分析
- 1、 客户在页面中输入手机号,点击获取验证码按钮
- 2、 验证手机号是否正确,如果正确,发送ajax请求,请求前台Action
- 3、 前台Action调用SmSUtils工具,通过Webservice方式调用吉信通短信服务
- 4、 生成随机的4位数字验证码,将验证码存入session
- 5、 客户在注册页面输入收到的验证码,点击注册按钮,提交表单,请求前台Action
- 6、 在前台Action中调用CRM服务完成客户信息的保存操作
- 7、 为客户邮箱发送激活邮件,邮件的内容中含有一个激活码,我们需要将激活码保存到redis,存放24小时
- 发送ajax短信验证码请求
- 在Action提供方法, 调用短信服务
- 为注册按钮绑定事件, 提交表单
- 在bos_fore服务端扩展regist方法
- 在CRM服务中国提供客户regist方法
- 在CRM项目中Service节后中扩展方法
- 在crm_fore项目中调用crm系统
- bos_fore找那个远程调用crm实现客户注册
前端页面
<script type="text/javascript">
var clock = '';
var nums = 60;
var btn;
function sendCode(thisBtn) {
var flag = $("#jsForm").validate().element($("#telephone"));
if(flag){
var url = "customerAction_sendMsg.action";
$.post(url,{"telephone":$("#telephone").val()},function(data){
if(data=="success"){
alert("短信发送成功");
}
if(data=="false"){
alert("短信发送失败");
}
})
btn = thisBtn;
btn.disabled = true; //将按钮置为不可点击
btn.value = nums + '秒后重新获取';
clock = setInterval(doLoop, 1000); //一秒执行一次
}
}
function doLoop() {
nums--;
if (nums > 0) {
btn.value = nums + '秒后重新获取';
} else {
clearInterval(clock); //清除js定时器
btn.disabled = false;
btn.value = '重新获取验证码';
nums = 60; //重置时间
}
}
</script>
web.xml(bos_fore)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>bos_fore</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 指定spring配置文件的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 配置spring框架的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置struts2框架的过滤器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
applicationContext.xml(bos_fore)
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://cxf.apache.org/core
http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 组件扫描 @Service @Controller @Repository -->
<context:component-scan base-package="com.lyric.bos_fore.web"/>
<jaxws:client id="customerService" address="http://localhost:8889/crm/cxf/customer?wsdl" serviceClass="com.lyric.bos_fore.utils.CustomerServiceImpl"></jaxws:client>
</beans>
CustomerAction(bos_fore)
package com.lyric.bos_fore.web.action;
import java.io.IOException;
import javax.annotation.Resource;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.lyric.bos_fore.utils.Customer;
import com.lyric.bos_fore.utils.CustomerServiceImpl;
import com.lyric.bos_fore.utils.SmsUtils;
@Namespace("/")
@ParentPackage("struts-default")
@Controller
@Scope("prototype")
public class CustomerAction extends CommonAction<Customer>{
@Resource
private CustomerServiceImpl customerService;
private String checkcode;
public void setCheckcode(String checkcode) {
this.checkcode = checkcode;
}
@Action(value="customerAction_sendMsg")
public String sendMsg(){
String randomNumeric = RandomStringUtils.randomNumeric(4);
ServletActionContext.getRequest().getSession().setAttribute(getModel().getTelephone(), randomNumeric);
String msg = "您的验证码是"+ randomNumeric;
String num = "1111111111111111";//SmsUtils.sendSmsByWebService(getModel().getTelephone(), msg);
//System.out.println(num);
System.out.println(msg);
ServletActionContext.getResponse().setContentType("text/html; charset=UTF-8");
try {
if(StringUtils.isNotBlank(num)&&num.length()==16){
ServletActionContext.getResponse().getWriter().println("success");
}else{
ServletActionContext.getResponse().getWriter().println("false");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return NONE;
}
@Action(value="customerAction_regist",results={
@Result(name = "success", location = "/signup-success.html", type = "redirect"),
@Result(name = "error", location = "/signup-fail.html", type = "redirect") }
)
public String regist(){
String code = (String) ServletActionContext.getRequest().getSession().getAttribute(getModel().getTelephone());
if(StringUtils.isNotBlank(code)&&StringUtils.isNotBlank(checkcode)&&checkcode.equals(code)){
customerService.save(getModel());
return SUCCESS;
}else{
return ERROR;
}
}
}
Customer(crm的实体–注意主键)
package com.lyric.crm.domain;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* @description:客户信息表
*
*/
@Entity
@Table(name = "T_CUSTOMER")
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator="myseq")
@SequenceGenerator(name="myseq",sequenceName="customer_seq",initialValue=50,allocationSize=10)
@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;
}
}