exportservlet.java.svn-base

来自「公司CRM部分原代码,采用的是java技术.」· SVN-BASE 代码 · 共 158 行

SVN-BASE
158
字号
package GDPE.reports;

import javax.servlet.*;
import javax.servlet.http.*;

import portal.sa.auditor.EnAuditor;
import portal.sa.auditorrole.EnAuditorRole;

import java.io.*;
import GDPE.customer.enterprise.*;
import levin.UserInfo;
import levin.base.DAOBase;
import levin.util.DbAccess;
/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class ExportServlet extends HttpServlet
{
    private static final String CONTENT_TYPE = "application/vnd.ms-excel; charset=gb2312";

    public void init() throws ServletException {}

    public void doPost(HttpServletRequest request, HttpServletResponse response)  throws ServletException, IOException
    {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        StringBuffer resultdata=new StringBuffer();
        ///
        HttpSession session = request.getSession(false);
		UserInfo userInfor = (UserInfo) session.getAttribute("UserInfo_Object");
		String idstr = userInfor.getId();
		String flag = "";
		String chStationCode;
		//System.out.println("--idstr=------------"+idstr);
		EnEnt_Customer_Enterprise aEnEnt_Customer_Enterprise[];
        ///
       try
        {
    	   flag = checkFlag(idstr);
        	if (flag.equals("isAdmin")) {
    			aEnEnt_Customer_Enterprise = (EnEnt_Customer_Enterprise[])(DAOBase.findByCondition(new DbAccess(),EnEnt_Customer_Enterprise.class.getName()," chIsAudited like '%1%' ",""));
    		} else if (flag.equals("isStation")) {
    			EnAuditor cEnAuditor = (EnAuditor) DAOBase.findByPK(new DbAccess(),
    					EnAuditor.class.getName(), idstr);
    			chStationCode = cEnAuditor.getChDeptCode();
    			String where = "chStationCode = '" + chStationCode + "'";
    			String order = "id desc";
    			//System.out.println("where -------"+where);
    			aEnEnt_Customer_Enterprise = (EnEnt_Customer_Enterprise[]) (DAOBase
    					.findByCondition(new DbAccess(),
    							EnEnt_Customer_Enterprise.class.getName(), where,
    							order));
    		} else {
    			String where = "chCommitCode = '" + userInfor.getId() + "'";
    			// System.out.println("+------------>"+userInfor.);
    			String order = "id desc";
    			aEnEnt_Customer_Enterprise = (EnEnt_Customer_Enterprise[]) (DAOBase
    					.findByCondition(new DbAccess(),
    							EnEnt_Customer_Enterprise.class.getName(), where,
    							 order));

    		}
        	resultdata.append("<table border=1>");
            for(int i=0;i<aEnEnt_Customer_Enterprise.length;i++)
            {
                resultdata.append("<tr>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getChEnterpriseFullName()+"</td>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getChEnterprisePhone()+"</td>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getChEnterpriseFax()+"</td>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getChEnterpriseEmail()+"</td>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getChEnterprisePost()+"</td>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getChEnterpriseAddress()+"</td>");
                
                
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getDtCommitTime()+"</td>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getDtOpenAccout()+"</td>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getChSeatCode()+"</td>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getChCorporateName()+"</td>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getChCommitName()+"</td>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getChCommitUserName()+"</td>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getChEnterpriseCityName()+"</td>");
                resultdata.append("<td>"+aEnEnt_Customer_Enterprise[i].getChEnterpriseGrade()+"</td>");
                
                
                resultdata.append("</tr>");
            }
            resultdata.append("</table>");
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

        
        String serverpath = this.getServletConfig().getServletContext().getRealPath("");
        
        String phyfilename = serverpath + "/template/EnterpriseInfo.htm";
        //String phyfilename = serverpath + "/template/daochu.htm";
        //System.out.println("--------"+phyfilename);
        // 设置tempexcel的物理路径
        response.setHeader("Content-disposition", "attachment;filename=Enterprise.xls");

        // 开始将模板以servlet的形式输出浏览器上
        StringBuffer buffer = new StringBuffer();
        try
        {
            InputStream is = new FileInputStream(phyfilename);
            Util.readToBuffer(buffer, is);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        String templatebody = buffer.toString();
        // 对真正的数据区域进行替换 把Data 摸班中的标记为data 替换成真正的数据
        templatebody = Util.Replaceall(templatebody, resultdata.toString(), "[#Data#]");
        out.print(templatebody);
        out.close();

    }
    public String checkFlag(String chAuditorcode) throws Exception {
    	String flag = "";

		EnAuditorRole[] cEnAuditorRole = (EnAuditorRole[]) DAOBase
				.findByCondition(new DbAccess(), EnAuditorRole.class.getName(),
						"chAuditorCode='" + chAuditorcode + "'", "");
		
		for (int i = 0; i < cEnAuditorRole.length; i++) {
			String src = cEnAuditorRole[i].getChRoleCode();
			if (src.equals("0000")//系统管理员
					||src.equals("0004")||src.equals("0006")//客户服务
					) {//发展部主管
				flag = "isAdmin";
				break;
			} else if (cEnAuditorRole[i].getChRoleCode().equals("0002")) {//登陆站长
				flag = "isStation";
			}
		}
		return flag;
	}
    public void destroy() {}

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    {
        doPost(request, response);
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?