SSH-BOS项目:业务通知单模块

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;
	}

	//接收customer参数
	private Customer customer;
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	/**
	 * 按手机号加载客户信息
	 * @return
	 */
	public String findCustomerByTelephone(){
		Customer customer = proxyCustomerService.findByTelephone(model.getTelephone());
		BOSUtils.writerJson(customer, null);
		
		return NONE;
	}
	
	/**
	 * 添加业务通知单
	 * @return
	 */
	public String add(){
		//调用service#save(model)
		noticebillService.save(model);
		
		return "noticebill_add";
	}
	
	/**
	 * 新增客户信息
	 * @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 {

	/**
	 * 保存新增业务通知单
	 * @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) {
		//设置生成此通知单的用户
		model.setUser(BOSUtils.getLoginUser());
		noticebillDao.save(model);
		
		/*
		 * 分单操作
		 */
		//获取取件地址
		String pickaddress = model.getPickaddress();
		String decidedzoneidId = null;
		Decidedzone decidedzone = null;
		try {
			//调用crm查询定区ID
			decidedzoneidId = proxyCustomerService.findDecidedzoneidByAddress(pickaddress);
			//调用DecidedzoneDao#findById查询定区
			decidedzone = decidedzoneDao.findById(decidedzoneidId);
		} catch (Exception e) {
			
		}
		//校验是否查询到定区
		if(decidedzone != null){
			//不为空,进行自动分单
			Staff staff = decidedzone.getStaff();
			model.setStaff(staff);
			//设置分单类型为:自动分单
			model.setOrdertype(Noticebill.ORDERTYPE_AUTO);
			
			//为此取派员生成工单
			Workbill workbill = new Workbill();
			workbill.setAttachbilltimes(0);//追单次数,新单为: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{
			//未查询到定区,不能进行自动分单,需要进行手动分单
			model.setOrdertype(Noticebill.ORDERTYPE_MAN);
		}
		
	}

}

Struts.xml:

		<!-- 业务通知单模块 -->
		<action name="NoticebillAction_*" class="noticebillAction" method="{1}">
			<result name="noticebill_add">/WEB-INF/pages/qupai/noticebill_add.jsp</result>
		</action>

页面:

<%@ 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">
	$(function(){
		$("body").css({visibility:"visible"});
		
		// 对save按钮条件 点击事件
		$('#save').click(function(){
			// 对form 进行校验
			if($('#noticebillForm').form('validate')){
				var customerId = $("input[name=customerId]").val();
				if(customerId == "" || customerId == undefined){
					//如果未根据手机号查询到客户信息,保存新客户信息到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();
			}
		});
		
		//为电话号码输入框绑定失去焦点事件
		$("input[name=telephone]").blur(function(){
			//发送ajax请求,加载客户数据
			$.post('NoticebillAction_findCustomerByTelephone.action',{'telephone':this.value},function(data){
				//判断是否查询到数据
				if(data != null){
					//加载客户数据到页面
					$("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{
					//清空页面数据
					$("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">工单操作</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">客户信息</td>
				</tr>
				<tr>
					<td>来电号码:</td>
					<td><input type="text" class="easyui-validatebox" name="telephone"
						required="true" /></td>
					<td>客户编号:</td>
					<td><input type="text" class="easyui-validatebox" readonly="readonly" name="customerId"/></td>
				</tr>
				<tr>
					<td>客户姓名:</td>
					<td><input type="text" class="easyui-validatebox" name="customerName" required="true"/></td>
					<td>联系人:</td>
					<td><input type="text" class="easyui-validatebox" name="delegater"/></td>
				</tr>
				<tr class="title">
					<td colspan="4">货物信息</td>
				</tr>
				<tr>
					<td>品名:</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>体积:</td>
					<td><input type="text" class="easyui-validatebox" name="volume"/></td>
				</tr>
				<tr>
					<td>取件地址</td>
					<td colspan="3"><input type="text" class="easyui-validatebox" name="pickaddress"
						required="true" size="144"/></td>
				</tr>
				<tr>
					<td>到达城市:</td>
					<td><input type="text" class="easyui-validatebox" name="arrivecity"/></td>
					<td>预约取件时间:</td>
					<td><input type="text" class="easyui-datebox" name="pickdate"
						data-options="editable:false" /></td>
				</tr>
				<tr>
					<td>备注:</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新增方法及其实现):

	/**
	 * 按电话号码查询客户信息
	 * @param telephone
	 * @return
	 */
	public Customer findByTelephone(String telephone);
	
	/**
	 * 按客户地址查询所在定区
	 * @param address
	 * @return
	 */
	public String findDecidedzoneidByAddress(String address);
	
	/**
	 * 新增客户
	 * @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());
	}


猜你喜欢

转载自blog.csdn.net/qq1031893936/article/details/79933000