SSH-BOS项目:工单操作模块

WorkbillAction:

package com.xushuai.bos.web.action;

import static org.hamcrest.CoreMatchers.not;

import java.io.IOException;
import java.sql.Timestamp;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
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.entity.Staff;
import com.xushuai.bos.entity.Workbill;
import com.xushuai.bos.service.WorkbillService;
import com.xushuai.bos.utils.BOSUtils;

@Controller("workbillAction")
@Scope("prototype")
public class WorkbillAction extends BaseAction<Workbill> {

	@Autowired
	@Qualifier("workbillService")
	private WorkbillService workbillService;
	public void setWorkbillService(WorkbillService workbillService) {
		this.workbillService = workbillService;
	}
	
	/**
	 * 分页查询工单
	 * @return
	 */
	public String pageQuery(){
		//获取离线查询条件
		DetachedCriteria dc = pageBean.getCriteria();
		
		//获取受理时间
		Timestamp buildtime = model.getBuildtime();
		if(buildtime != null){
			//获取起毫秒值,并计算同一天的毫秒值
			long time = buildtime.getTime();
			time = time + 86400000;
			//用计算后的毫秒值构造Timestamp
			Timestamp timestamp2 = new Timestamp(time);
			dc.add(Restrictions.between("buildtime", buildtime, timestamp2));
		}
		
		//关联查询noticebill
		Noticebill noticebill = model.getNoticebill();
		if(noticebill != null){
			String telephone = noticebill.getTelephone();
			dc.createAlias("noticebill", "n");
			if(StringUtils.isNotBlank(telephone)){
				//添加查询条件
				dc.add(Restrictions.like("n.telephone", "%"+telephone+"%"));
			}
		}
		
		//关联查询staff
		Staff staff = model.getStaff();
		if(staff != null){
			String name = staff.getName();
			dc.createAlias("staff", "s");
			if(StringUtils.isNotBlank(name)){
				//添加查询条件
				dc.add(Restrictions.like("s.name", "%"+name+"%"));
			}
		}
		
		workbillService.pageQuery(pageBean);
		BOSUtils.writerJson(pageBean, new String[]{"currentPage","pageSize","criteria",
				"noticebill","decidedzones"});
		
		return NONE;
	}
	
	/**
	 * 追单
	 * @return
	 */
	public String repeat(){
		workbillService.repeat(model);
		return NONE;
	}
	
	/**
	 * 确认收货
	 * @return
	 * @throws IOException 
	 */
	public String pick() throws IOException{
		String flag = "1";
		try {
			workbillService.pick(model);
		} catch (Exception e) {
			e.printStackTrace();
			flag = "0";
		}
		HttpServletResponse response = BOSUtils.getResponse();
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().print(flag);
		
		return NONE;
	}
	
	/**
	 * 销单
	 * @return
	 * @throws IOException 
	 */
	public String cancel() throws IOException{
		String flag = "1";
		try {
			workbillService.cancel(model);
		} catch (Exception e) {
			e.printStackTrace();
			flag = "0";
		}
		HttpServletResponse response = BOSUtils.getResponse();
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().print(flag);
		
		return NONE;
	}
	
}

WorkbillService、WorkbillServiceImpl:

package com.xushuai.bos.service;

import com.xushuai.bos.entity.Workbill;
import com.xushuai.bos.utils.PageBean;

public interface WorkbillService {

	/**
	 * 分页查询工单
	 * @param pageBean
	 */
	void pageQuery(PageBean pageBean);
	
	/**
	 * 追单
	 */
	void repeat(Workbill model);

	/**
	 * 确认取货
	 * @param model
	 */
	void pick(Workbill model);

	/**
	 * 销单
	 * @param model
	 */
	void cancel(Workbill model);

}
package com.xushuai.bos.service.impl;

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.WorkbillDao;
import com.xushuai.bos.entity.Workbill;
import com.xushuai.bos.service.WorkbillService;
import com.xushuai.bos.utils.PageBean;

@Service("workbillService")
@Transactional
public class WorkbillServiceImpl implements WorkbillService {
	
	@Autowired
	@Qualifier("workbillDao")
	private WorkbillDao workbillDao;
	public void setWorkbillDao(WorkbillDao workbillDao) {
		this.workbillDao = workbillDao;
	}


	@Override
	public void pageQuery(PageBean pageBean) {
		workbillDao.findByPage(pageBean);
	}


	@Override
	public void repeat(Workbill model) {
		//查询出要追单的工单
		Workbill _workbill = workbillDao.findById(model.getId());
		//判断是否有工单对象对应该ID,且取货状态为'已取货',且工单状态不为销单
		if(_workbill != null && _workbill.getPickstate().equals(Workbill.PICKSTATE_YES) && !_workbill.getPickstate().equals(Workbill.TYPE_CANCEL)){
			//追单次数 +1
			_workbill.setAttachbilltimes(_workbill.getAttachbilltimes() + 1);
			String type = _workbill.getType();
			//将工单状态改为'追单'并保存
			if(type == Workbill.TYPE_NEW){
				_workbill.setType(Workbill.TYPE_TRACE);
			}
			workbillDao.update(_workbill);
		}
		
	}


	@Override
	public void pick(Workbill model) {
		//查询出要确认取货的工单
		Workbill _workbill = workbillDao.findById(model.getId());
		//判断是否有工单对象对应该ID,且取货状态为'未取货'
		if(_workbill != null && _workbill.getPickstate().equals(Workbill.PICKSTATE_NO)){
			//修改取货状态为已取货并保存
			_workbill.setPickstate(Workbill.PICKSTATE_YES);
			workbillDao.update(_workbill);
		}
	}


	@Override
	public void cancel(Workbill model) {
		//查询出要确认取货的工单
		Workbill _workbill = workbillDao.findById(model.getId());
		//判断是否有工单对象对应该ID,且工单状态不能为'销单'
		if(_workbill != null && !_workbill.getPickstate().equals(Workbill.TYPE_CANCEL)){
			//将工单状态修改为'销单'并保存
			_workbill.setType(Workbill.TYPE_CANCEL);
			workbillDao.update(_workbill);
		}
	}

}

struts.xml(新增配置):

<!-- 工作单模块 -->
		<action name="WorkbillAction_*" class="workbillAction" method="{1}">
			
		</action>

页面(noticebill.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>
<style type="text/css">
#repeatTable td{
	font-size:15px;
	padding-top: 10px;
	padding-bottom: 10px
}

</style>
<script type="text/javascript">
	
	function doRepeat(){
		var rows = $("#grid").datagrid('getSelections');
		if(rows.length == 0){
			$.messager.alert('提示信息','请选择您要追单的工单!','warning');
		}else{
			var rowData = rows[0];
			if(rowData.pickstate == '已取件'){
				if(rowData.type != '销单'){
					$.post('WorkbillAction_repeat.action',{'id':rowData.id},function(data){
						$('#repeatWindow').window("open");
						$("#grid").datagrid('reload');
					});
				}else{
					$.messager.alert('提示信息','需要追单的工单不能为销单状态!','warning');
				}
			}else{
				$.messager.alert('提示信息','需要追单的工单必须为已取件状态!','warning');
			}
		}
	}
	
	function doOk(){
		var rows = $("#grid").datagrid('getSelections');
		if(rows.length == 0){
			$.messager.alert('提示信息','请选择您要确认取货的工单!','warning');
		}else{
			$.messager.confirm('提示信息', '确认已经成功取货?', function(r){
				if (r){
					var rowData = rows[0];
					if(rowData.pickstate == '未取件'){
						$.post('WorkbillAction_pick.action',{'id':rowData.id},function(data){
							if(data == '0'){
								$.messager.alert('提示信息','确认取货失败!','error');
							}
							$("#grid").datagrid('reload');
						});
					}else{
						$.messager.alert('提示信息','需要追单的工单必须为未取件状态!','warning');
					}
				} 
			});
			
			
		}
	}
	
	function doCancel(){
		var rows = $("#grid").datagrid('getSelections');
		if(rows.length == 0){
			$.messager.alert('提示信息','请选择您要销单的工单!','warning');
		}else{
			var rowData = rows[0];
			if(rowData.pickstate != '销单'){
				$.post('WorkbillAction_cancel.action',{'id':rowData.id},function(data){
					if(data == '0'){
						$.messager.alert('提示信息','销单失败!','error');
					}
					$("#grid").datagrid('reload');
				});
			}else{
				$.messager.alert('提示信息','需要销单的工单不能为销单状态!','warning');
			}
		}
	}
	
	function doSearch(){
		$('#searchWindow').window("open");
	}
	
	//工具栏
	var toolbar = [ 
		{
		id : 'button-search',	
		text : '查询',
		iconCls : 'icon-search',
		handler : doSearch
		}, 
		{
			id : 'button-ok',	
			text : '确认取货',
			iconCls : 'icon-ok',
			handler : doOk
			}, 
		{
			id : 'button-repeat',
			text : '追单',
			iconCls : 'icon-redo',
			handler : doRepeat
		}, 
		{
			id : 'button-cancel',	
			text : '销单',
			iconCls : 'icon-cancel',
			handler : doCancel
		}
	];
	// 定义列
	var columns = [ [ {
		field : 'id',
		checkbox : true,
	}, {
		field : 'noticebill_id',
		title : '通知单号',
		width : 240,
		align : 'center'
	},{
		field : 'type',
		title : '工单类型',
		width : 120,
		align : 'center'
	}, {
		field : 'pickstate',
		title : '取件状态',
		width : 120,
		align : 'center'
	}, {
		field : 'buildtimeStr',
		title : '工单生成时间',
		width : 140,
		align : 'center'
	}, {
		field : 'attachbilltimes',
		title : '追单次数',
		width : 120,
		align : 'center'
	},{
		field : 'staff.id',
		title : '取派员ID',
		width : 240,
		align : 'center',
		formatter : function(data,row ,index){
			return row.staff.id;
		}
	}, {
		field : 'staff.name',
		title : '取派员姓名',
		width : 120,
		align : 'center',
		formatter : function(data,row ,index){
			return row.staff.name;
		}
	}, {
		field : 'staff.telephone',
		title : '联系方式',
		width : 100,
		align : 'center',
		formatter : function(data,row ,index){
			return row.staff.telephone;
		}
	} ] ];
	
	$(function(){
		// 先将body隐藏,再显示,不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		// 收派标准数据表格
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : true,
			rownumbers : true,
			striped : true,
			pageList: [15,20,25],
			pageSize:25,
			pagination : true,
			toolbar : toolbar,
			url :  "WorkbillAction_pageQuery.action",
			idField : 'id',
			columns : columns,
			singleSelect : true
		});
		
		// 查询分区
		$('#searchWindow').window({
	        title: '查询工单',
	        width: 400,
	        modal: true,
	        shadow: true,
	        closed: true,
	        height: 400,
	        resizable:false
	    });
		$("#btn").click(function(){
			//将form中的表单数据转换为json,用于提交
			var params = $("#searchForm").serializeJson();
			//console.info(params);
			//提交参数,加载数据,关闭查询窗口
			$("#grid").datagrid('load',params);
			
			$("#searchForm").form('reset');// 重置查询表单
			$("#searchWindow").window("close"); // 关闭窗口
		});
		
		//追单结果
		$('#repeatWindow').window({
	        title: '追单',
	        width: 700,
	        modal: true,
	        shadow: true,
	        closed: true,
	        height: 500,
	        resizable:false
	    });
	});

</script>	
</head>
<body class="easyui-layout" style="visibility:hidden;">
	<div region="center" border="false">
    	<table id="grid"></table>
	</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" method="post" action="WorkbillAction_search.action">
				<table class="table-edit" width="80%" align="center">
					<tr class="title">
						<td colspan="2">查询条件</td>
					</tr>
					<tr>
						<td>客户电话</td>
						<td><input name="noticebill.telephone" type="text" class="easyui-validatebox"/></td>
					</tr>
					<tr>
						<td>取派员</td>
						<td><input name="staff.name" type="text" class="easyui-validatebox"/></td>
					</tr>
					<tr>
						<td>受理时间</td>
						<td><input name="buildtime" type="text" class="easyui-datebox"/></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 class="easyui-window" title="追单" id="repeatWindow" collapsible="false" minimizable="false" maximizable="false" style="top:20px;left:200px">
		<div style="overflow:auto;padding:5px;" border="false">
				<table id="repeatTable" width="80%" align="center">
					<tr class="title">
						<td colspan="2">物流信息</td>
					</tr>
					<tr>
						<td>xxxx年x月x日 xx:xx:xx</td>
						<td>商品已经到达成都分拣中心</td>
					</tr>
					<tr>
						<td>xxxx年x月x日 xx:xx:xx</td>
						<td>商品已经到达南充分拣中心</td>
					</tr>
					<tr>
						<td>xxxx年x月x日 xx:xx:xx</td>
						<td>商品已经到达内江</td>
					</tr>
					<tr>
						<td>xxxx年x月x日 xx:xx:xx</td>
						<td>派送员:xx正在派件。电话:xxxxxxxx</td>
					</tr>
				</table>
		</div>
	</div>
</body>
</html>

注意:其中追单只完成了逻辑上的追单,并没有实际的返回工单的信息。

猜你喜欢

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