struts-config.xml配置action
Java action类
package com.anlai.ticket.action;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.anlai.ticket.service.WorkFlowGroupTaskService;
import com.anlai.tools.data.IRecordSet;
import com.anlai.tools.data.Pageable;
import com.anlai.tools.data.Table;
import net.sf.json.JSONArray;
public class ServiceQualityAction extends Action {
String customerId = null;
String customerLevel = null;
String customerType = null;
String ticketType = null;
String contractLocation = null;
String startDate = null;
String endDate = null;
String companyName = null;
String noOfTicket = null;
String noOfServiceID = null;
String noOfTicketDivideNoOfSericeID = null;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
if (request.getParameter("query").equals("getReport")) {
try {
this.getReport(mapping, form, request, response);
return null;
} catch (Exception e) {
e.printStackTrace();
}
}else if (request.getParameter("query").equals("selectAllContractLocation")){
try {
this.selectAllContractLocation(mapping, form, request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public void selectAllContractLocation(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("utf-8");
List list = ServiceQualityAction.selectAllContractLocation();
response.getWriter().write(JSONArray.fromObject(list).toString());
response.getWriter().flush();
response.getWriter().close();
}
private static List selectAllContractLocation() {
StringBuffer sql = new StringBuffer();
sql.append(" select display_value FROM t_dropmenu_manager WHERE name='contract_location' order by object_name,name,display_value");
Table t = new Table(sql.toString());
IRecordSet rs = t.getRecordSet();
List result = new ArrayList();
while (rs.next()){
Object[] obj = {rs.getString("display_value")};
result.add(obj);
}
rs.close();
return result;
}
public void getReport(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("utf-8");
this.customerId = request.getParameter("customerId");
this.customerLevel = request.getParameter("customerLevel");
this.customerType = request.getParameter("customerType");
this.ticketType = request.getParameter("ticketType");
Map parameterMap = request.getParameterMap();
String[] contractLocations =(String[]) parameterMap.get("contractLocation[]");
this.startDate = request.getParameter("startTime");
this.endDate = request.getParameter("endTime");
StringBuffer sql = new StringBuffer();
sql.append(" select v1.customer_id, ");
sql.append(" v1.companynamechn companyName, ");
sql.append(" v1.customer_level customer_level, ");
sql.append(" v1.customer_type customer_type, ");
sql.append(" v1.contractlocation contractLocation, ");
sql.append(" v1.ticketnum noOfTicket, ");
sql.append(" v1.servicenum noOfServiceID, ");
sql.append(" decode(v1.servicenum, ");
sql.append(" 0, ");
sql.append(" 0, ");
sql.append(" trunc((v1.ticketnum / v1.servicenum) * 100, 2)) || '%' noOfTicketDivideNoOfSericeID ");
sql.append(" from (select v.customer_id, ");
sql.append(" v.companynamechn, ");
sql.append(" v.customer_level, ");
sql.append(" v.customer_type, ");
sql.append(" (select wm_concat(distinct r.shortname) ");
sql.append(" from cascontract@me_to_ccis cas, region@me_to_ccis r ");
sql.append(" where cas.regionid = r.id ");
sql.append(" and cas.companyid = v.companyid) contractlocation, ");
sql.append(" (select count(*) ");
sql.append(" from t_ticket_info i ");
sql.append(" where i.customer_id = v.customer_id ");
if (!ticketType.equals(null) && !ticketType.equals("All")) {
sql.append(" and i.type=" + "'" + ticketType + "'");
}
if (!startDate.equals(null) && !startDate.equals("")) {
sql.append(" and i.create_date>=to_date('" + startDate + "','yyyy-mm-dd')");
}
if (!endDate.equals(null) && !endDate.equals("")) {
sql.append(" and i.create_date<=to_date('" + endDate + "','yyyy-mm-dd')");
}
sql.append(" ) ticketnum, ");
sql.append(" (select count(*) ");
sql.append(" from service2@me_to_ccis s ");
sql.append(" where s.companyid = v.companyid) servicenum ");
sql.append(" ");
sql.append(" from (select distinct a.customer_id, ");
sql.append(" d.companyid, ");
sql.append(" d.companynamechn, ");
sql.append(" decode(e.customer_level, ");
sql.append(" 1, ");
sql.append(" 'vip', ");
sql.append(" 2, ");
sql.append(" 'svip', ");
sql.append(" 3, ");
sql.append(" 'trial', ");
sql.append(" 'normal') customer_level, ");
sql.append(" decode(e.customer_type, ");
sql.append(" 1, ");
sql.append(" 'IB', ");
sql.append(" 2, ");
sql.append(" 'Call Center', ");
sql.append(" 'Normal') customer_type ");
sql.append(" from t_customer_info a, ");
sql.append(" t_ticket_info b, ");
sql.append(" customercompany@me_to_ccis d, ");
sql.append(" t_customer_background c, ");
sql.append(" t_customer_tag e ");
sql.append(" where a.customer_id = b.customer_id ");
sql.append(" and a.customer_id = d.customerid ");
sql.append(" and a.customer_id = c.customer_id(+) ");
sql.append(" and a.customer_id = e.customer_id(+) ");
if (!customerId.equals(null) && !customerId.equals("")) {
sql.append(" and a.customer_id=" + customerId);
}
if (!customerLevel.equals(null) && !customerLevel.equals("All")) {
sql.append(" and e.customer_level=" + customerLevel);
}
if (!customerType.equals(null) && !customerType.equals("All")) {
sql.append(" and e.customer_type=" + customerType);
}
sql.append(" ) v) v1 ");
if(contractLocations!=null&&contractLocations.length > 0) {
String strValue = " where v1.contractlocation like ";
for(int i=0;i<contractLocations.length;i++){
strValue = strValue+"'%"+contractLocations[i]+"%' ";
if(contractLocations.length>1&&i<contractLocations.length-1){
strValue =strValue+"or v1.contractlocation like";
}
}
sql.append(strValue);
}
sql.append(" order by v1.customer_id asc ");
/*sql.append("select t.customer_id,t.companynamechn companyName,decode(t.customer_level, 1, 'vip', 2, 'svip', 3, 'trial', 'normal') customer_level,decode(t.customer_type, 1, 'IB', 2, 'Call Center', 'Normal') customer_type,t.contractlocation contractLocation,t.ticketnum noOfTicket,t.servicenum noOfServiceID,decode(t.servicenum, 0, 0, trunc(t.ticketnum / t.servicenum, 2)) noOfTicketDivideNoOfSericeID from" +
"(select v.customer_id,v.companynamechn,v.customer_level,v.customer_type,v.contractlocation,(select count(*)from t_ticket_info i where i.customer_id = v.customer_id");
if (!ticketType.equals(null) && !ticketType.equals("All")) {
sql.append(" and i.type=" + "'" + ticketType + "'");
}
if (!startDate.equals(null) && !startDate.equals("")) {
sql.append(" and i.create_date>=to_date('" + startDate + "','yyyy-mm-dd')");
}
if (!endDate.equals(null) && !endDate.equals("")) {
sql.append(" and i.create_date<=to_date('" + endDate + "','yyyy-mm-dd')");
}
sql.append(") ticketnum,(select count(*) from service2@me_to_ccis s where s.companyid = v.companyid) servicenum from (select distinct a.customer_id, d.companyid,d.companynamechn,e.customer_level,"+
"e.customer_type,g.shortname contractlocation from t_customer_info a, customercompany@me_to_ccis d,t_customer_background c,t_customer_tag e,cascontract@me_to_ccis f, region@me_to_ccis g "+
"where a.customer_id = c.customer_id(+) and a.customer_id = e.customer_id(+) and a.customer_id = d.customerid and d.companyid = f.companyid(+) and f.regionid = g.id(+)) v) t where 1=1");
//"select t.customer_id,t.companyNamechn companyName,decode(t.customer_level, 1, 'vip', 2, 'svip', 3, 'trial', 'normal') customer_level,decode(t.customer_type, 1, 'IB', 2, 'Call Center', 'Normal') customer_type,t.contract_location contractLocation,t.ticket_id noOfTicket,t.serviceno noOfServiceID,null as noOfTicketDivideNoOfSericeID from view_main_info t where 1=1 ");
if (!customerId.equals(null) && !customerId.equals("")) {
sql.append(" and t.customer_id=" + customerId);
}
if (!customerLevel.equals(null) && !customerLevel.equals("All")) {
sql.append(" and t.customer_level=" + customerLevel);
}
if (!customerType.equals(null) && !customerType.equals("All")) {
sql.append(" and t.customer_type=" + customerType);
}
if(contractLocations!=null&&contractLocations.length > 0) {
String strValue = " and t.contractlocation in(";
for(int i=0;i<contractLocations.length;i++){
strValue = strValue+"'"+contractLocations[i]+"'";
if(contractLocations.length>1&&i<contractLocations.length-1){
strValue =strValue+",";
}
}
strValue = strValue+") ";
sql.append(strValue);
}
*/
Table t = new Table(sql.toString());
IRecordSet rs = t.getRecordSet();
List report = new ArrayList();
while (rs.next()) {
ServiceQualityAction ServiceQuality = new ServiceQualityAction();
ServiceQuality.setCustomerId(rs.getString(1));
ServiceQuality.setcompanyName(rs.getString(2));
ServiceQuality.setCustomerLevel(rs.getString(3));
ServiceQuality.setCustomerType(rs.getString(4));
ServiceQuality.setContractLocation(rs.getString(5));
ServiceQuality.setnoOfTicket(rs.getString(6));
ServiceQuality.setnoOfServiceID(rs.getString(7));
ServiceQuality.setnoOfTicketDivideNoOfSericeID(rs.getString(8));
report.add(ServiceQuality);
}
rs.close();
request.getSession().setAttribute("reportData", report);
response.getWriter().write(JSONArray.fromObject(report).toString());
response.getWriter().flush();
response.getWriter().close();
}
public String getnoOfTicketDivideNoOfSericeID() {
return noOfTicketDivideNoOfSericeID;
}
private void setnoOfTicketDivideNoOfSericeID(String noOfTicketDivideNoOfSericeID) {
this.noOfTicketDivideNoOfSericeID=noOfTicketDivideNoOfSericeID;
}
public String getnoOfServiceID() {
return noOfServiceID;
}
private void setnoOfServiceID(String noOfServiceID) {
this.noOfServiceID=noOfServiceID;
}
public String getnoOfTicket() {
return noOfTicket;
}
private void setnoOfTicket(String noOfTicket) {
this.noOfTicket=noOfTicket;
}
public String getcontractLocation() {
return contractLocation;
}
private void setContractLocation(String contractLocation) {
this.contractLocation=contractLocation;
}
public String getcustomerType() {
return customerType;
}
private void setCustomerType(String customerType) {
this.customerType=customerType;
}
public String getcustomerLevel() {
return customerLevel;
}
private void setCustomerLevel(String customerLevel) {
this.customerLevel=customerLevel;
}
public String getcompanyName() {
return companyName;
}
private void setcompanyName(String companyName) {
this.companyName = companyName;
}
public String getCustomerId() {
return customerId;
}
private void setCustomerId(String customerId) {
this.customerId = customerId;
}
}
jsp前端显示代码:
<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
<title>Ticket Report</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="nocache" content="no-cache">
<script language="JavaScript" type="text/javascript" src="../inc/calendar.js"></script>
<script language="JavaScript" type="text/javascript" src="../inc/server.js"></script>
<script language="JavaScript" type="text/javascript" src="../inc/CommonFunction.js"></script>
<script type="text/javascript" src="../inc/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../inc/My97DatePicker/WdatePicker.js"></script>
<link rel="stylesheet" href="../inc/tickets.css" type="text/css"/>
<script type="text/javascript">
function servicequality(currentpage){
var createDateFlag = checkCreateDate();
if (createDateFlag == false){
return false;
}
if (checkAllValue() == false){
alert('Pls. Input Search Time Value!');
return false;
}
$('#data_body').html('');
$('#data_body').html('<tr id="p"><td colspan="10" id="photo" align="center"></br></br><img src="../inc/My97DatePicker/loading.gif"/></td></tr>');;
var url = '<%=basePath%>serviceQuality.ticket?query=getReport';
var data = {"customerId":$('#customerId').val(),"customerLevel" : $('#customerLevel').val(),"customerType" : $('#customerType').val(),"ticketType" : $('#ticketType').val(),"contractLocation" : $('#contractLocation').val(),"startTime" : $('#startTime').val(),"endTime" : $('#endTime').val()};
$.post(url,data,function(data){
var data = eval('(' + data + ')');
var dataCount=data.length;
var pagesize =30;//每页显示数
var pageNum;//分页总数
//var showPageNum = 6;//显示多少个页码
//计算分页总数
if (dataCount % pagesize == 0) {
pageNum = parseInt(dataCount / pagesize);
} else {
pageNum = parseInt(dataCount / pagesize) + 1;
}
//本页起始用户序号
var beginIndex = (currentpage - 1) * pagesize;
//本页末尾用户序号的下一个
var endIndex = beginIndex + pagesize;
//
if (endIndex > dataCount){
endIndex = dataCount;
}
//控制是否显示
var isshowlast;
var isshownext;
if(currentpage > 1) {
isshowlast='href="#" οnclick="servicequality('+(currentpage - 1)+')"';
}
if (currentpage < pageNum) {
isshownext='href="#" οnclick="servicequality('+(currentpage + 1)+')"';
}
if(currentpage == 1){
isshowlast='style="color: #E3E3E3"';
}
if(currentpage == pageNum){
isshownext='style="color: #E3E3E3"';
}
//只有一页内容
if (pageNum <= 1) {
for (var i = 0 ; i < endIndex ; i++ ) {
$('#data_body').append('<tr><td>'+ (i+1) +'</td><td>'+data[i].customerId+'</td><td>'+ data[i].companyName +'</td>' +
'<td>'+ data[i].customerLevel+'</td><td>'+ data[i].customerType+'</td><td>'+ data[i].contractLocation +'</td>'
+'<td>'+ data[i].noOfTicket+'</td><td>'+ data[i].noOfServiceID+'</td><td>'+ data[i].noOfTicketDivideNoOfSericeID+'</td></tr>');
}
}
//大于一页内容
if (pageNum > 1) {
//判断当前页数
for (var i = beginIndex ; i < endIndex ; i++ ) {
$('#data_body').append('<tr><td>'+ (i+1) +'</td><td>'+data[i].customerId+'</td><td>'+ data[i].companyName +'</td>' +
'<td>'+ data[i].customerLevel+'</td><td>'+ data[i].customerType+'</td><td>'+ data[i].contractLocation +'</td>'
+'<td>'+ data[i].noOfTicket+'</td><td>'+ data[i].noOfServiceID+'</td><td>'+ data[i].noOfTicketDivideNoOfSericeID+'</td></tr>');
}
$('#data_body').append('<tr></tr>');
$('#data_body').append('<tr align="center" width="800"><td rowspan="8" colspan="8"><a href="#" οnclick="servicequality(1)"> 首页 </a> '+
' <a '+isshowlast+'> 上一页 </a> '+' 第'+currentpage+'页 '+
' <a '+isshownext+'> 下一页 </a> '+
' <a href="#" οnclick="servicequality('+pageNum+')"> 尾页 </a></td>'+'</tr>');
}
$('#photo').html('');;
$('#p').remove();
});
}
function checkAllValue(){
var startTime = $('#startTime').val();
var endTime = $('#endTime').val();
if (startTime =="" || endTime == ""){
return false;
}
}
var eastLocationArray = ["TY","NJ","QD","L2","F2","R2","SH","D2","SU"];
var northLocationArray = ["D1","R1","BJ","I1","L1"];
var southLocationArray = ["D7","L7","F7","R7","DG","L3","GZ","D3","R3","L4","SZ","D4","R4"];
var twLocationArray = ["TD","TW","L6","R6","TA","D6"];
var hkLocationArray = ["HK","D8","D5","L8","L5","R5"];
function changeContractLocation(obj){
var objValue = obj.value;
var objIsChecked = obj.checked;
var selectElt = document.getElementsByName("contractLocation")[0];
if(1 == objValue){
getSelectValues(selectElt, eastLocationArray, objIsChecked);
}
if(2 == objValue){
getSelectValues(selectElt, northLocationArray, objIsChecked);
}
if(3 == objValue){
getSelectValues(selectElt, southLocationArray, objIsChecked);
}
if(4 == objValue){
getSelectValues(selectElt, twLocationArray, objIsChecked);
}
if(5 == objValue){
getSelectValues(selectElt, hkLocationArray, objIsChecked);
}
}
function getSelectValues(selectElt, targetValues, objIsChecked) {
var result = [];
var options = selectElt && selectElt.options;
var opt;
for (var i=0, iLen=options.length; i<iLen; i++) {
opt = options[i];
for(var j=0; j<targetValues.length; j++){
if(opt.value == targetValues[j]){
if(objIsChecked){
opt.selected = true;
}else{
opt.selected = false;
}
}
}
}
}
$(function(){
selectAllTicketType();
selectAllContractLocation();
});
function selectAllTicketType(){
var url = '<%=basePath%>groupDetails.ticket?query=selectAllTicketType';
var data = {};
$.post(url,data,function(data){
var data = eval('(' + data + ')');
for (var i = 0 ; i < data.length ; i ++) {
$('#ticketType').append('<option>'+ data[i][0] +'</option>');
}
});
}
function selectAllContractLocation(){
var url = '<%=basePath%>serviceQuality.ticket?query=selectAllContractLocation';
var data = {};
$.post(url,data,function(data){
var data = eval('(' + data + ')');
for (var i = 0 ; i < data.length ; i ++) {
$('#contractLocation').append('<option value=\"'+ data[i][0] +'\">'+ data[i][0] +'</option>');
}
});
}
function checkCreateDate(){
var d1 =document.getElementById('startTime').value;
var d2 =document.getElementById('endTime').value;
if(!compareDate(d1,d2)){
alert('CreateDate的第二个日期比第一日期小');
return false;
}
}
function compareDate(d1,d2){
var arrayD1 = d1.split("-");
var date1 = new Date(arrayD1[0],arrayD1[1],arrayD1[2]);
var arrayD2 =d2.split("-");
var date2 = new Date(arrayD2[0],arrayD2[1],arrayD2[2]);
if(date1 > date2) return false;
return true;
}
function output(){
//alert("start ... ");
//拷贝
var elTable = document.getElementById("data_table");
var oRangeRef = document.body.createTextRange();
oRangeRef.moveToElementText( elTable );
oRangeRef.execCommand( "Copy" );
//粘贴
try{
var appExcel = new ActiveXObject( "Excel.Application" );
appExcel.Visible = true;
appExcel.Workbooks.Add().Worksheets.Item(1).Paste();
//appExcel = null;
}catch(e){
alert("使用此功能必须在浏览器中设置:Internet选项->安全->将本站加入'受信任的站点'");
}
}
</script>
</head>
<body>
<form name="reportForm" method="post" action="">
</br></br>
<fieldset style="width: 800px;margin:0 auto;margin-left: 400px; ">
<legend><font style="font-weight: bolder;font-size: 14px;">Search Condition</font></legend>
<br>
<table width="800" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="25%" align="right" >Customer ID: </td>
<td width="25%"><input type="text" id="customerId"/> </td>
<td width="25%" align="right" nowrap>Customer Level: </td>
<td width="25%"><select name="customerLevel" id="customerLevel" style="width: 180px;">
<option value="All">All</option>
<option value="1">VIP</option>
<option value="2">Svip</option>
<option value="3">trial</option>
<option value="0">Normal</option>
</select>
</td>
</tr>
<tr>
<td width="25%" align="right" >
Customer Type : </td>
<td width="25%"><select id="customerType" style="width: 150px;">
<option value="All">All</option>
<option value="IB">IB</option>
<option value="Call Center">Call Center</option>
<option value="Normal">Normal</option>
</select></td>
<td width="25%" align="right">
Ticket Type : </td>
<td width="25%"><select id="ticketType" style="width: 150px;">
<option>All</option>
</select>
</td>
</tr>
<tr>
<td align="right" width="30%" nowrap>Contract Location:</td>
<td align="left" width="70%" nowrap>
<input type="checkbox" name="eastRegion" οnclick="changeContractLocation(this)" value="1"/>华东
<input type="checkbox" name="northRegion" οnclick="changeContractLocation(this);" value="2"/>华北
<input type="checkbox" name="southRegion" οnclick="changeContractLocation(this);" value="3"/>华南
<input type="checkbox" name="twRegion" οnclick="changeContractLocation(this);" value="4"/>台湾
<input type="checkbox" name="hkRegion" οnclick="changeContractLocation(this);" value="5"/>香港
<br/>
<select name="contractLocation" id="contractLocation" style="width: 150px;" size="3" multiple="true">
</select>
</td>
</tr>
<tr>
<td width="25%">Create at : From : </td>
<td width="25%"><input type="text" name="startTime" id="startTime" class="txt-100-22 Wdate" onClick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true,isShowClear:false})" />
</td>
<td width="25%"> TO : </td>
<td width="25%"> <input type="text" name="endTime" id="endTime" class="txt-100-22 Wdate" onClick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true,isShowClear:false})" >
</td>
</tr>
<tr>
<td colspan="10" rowspan="10" align="center">
<input type="button" value="Generate" class="button8" onClick="servicequality(1);" >
<input type="button" name="generate2" value="Exp Data" class="button8" οnclick="output();">
</td>
</tr>
</table>
</fieldset>
</form>
<table id="data_table" align="center" width="80%" border="0">
<thead bgcolor="#0099FF">
<td width="8%" ><font color="#000000"> INDEX</font></td>
<td><font color="#000000"> CID</font></td>
<td width="12%"><font color="#000000"> Company Name</font></td>
<td width="12%"><font color="#000000"> Customer Level</font></td>
<td width="12%"><font color="#000000"> Customer Type</font></td>
<td width="12%"><font color="#000000"> Contract Location</font></td>
<td width="12%"><font color="#000000"> No.of Ticket</font></td>
<td width="12%"><font color="#000000"> No.of Service ID</font></td>
<td width="12%"><font color="#000000"> No.of Ticket / No.of Serice ID</font></td>
</thead>
<tbody id="data_body">
</tbody>
</table>
</body>
</html>