package com.cattsoft.newbill.centerstat.struts.fixedvoice;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.upload.FormFile;
import org.apache.struts.util.LabelValueBean;
import com.cattsoft.newbill.citystatistics.overcall.OverCallStatisticsForm;
import com.cattsoft.newbill.pub.err.AppException;
import com.cattsoft.newbill.pub.err.SysException;
import com.cattsoft.newbill.pub.util.JdbcServiceUtil;
import com.cattsoft.newbill.pub.util.PagInfo;
import com.cattsoft.newbill.pub.util.PagUtil;
import com.cattsoft.newbill.pub.util.PagView;
import com.cattsoft.newbill.sm.ejb.vo.SysUserVOExtended;
import com.cattsoft.newbill.webpub.util.ExcelUtil;
import com.cattsoft.newbill.webpub.util.TotalUtil;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;
public class FixedVoiceStatisticsAction extends DispatchAction{
public static final String RELATION_SELECT = "relationSelect";
public ActionForward gotoMain(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest req, HttpServletResponse rep)
{
List billingCycle =new ArrayList();
List userType=new ArrayList();
try {
billingCycle = searchBillingCycle();
userType=this.searchUserTypeList();
} catch (AppException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SysException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//
List billingCycleList = this.getBillingCycle(req, billingCycle);
List userTypeList=this.getUserTypeList(userType);
req.setAttribute("exchList", startExch(req));
req.setAttribute("userTypeList", userTypeList);
req.setAttribute("billingCycleList", billingCycleList);
return actionMapping.findForward("main");
}
public List searchBillingCycle() throws AppException, SysException {
StringBuffer sql = new StringBuffer(
"select billing_cycle_id from billing_cycle where sts='E' order by billing_cycle_id desc");
return JdbcServiceUtil.select(sql.toString());
}
public ActionForward getFile(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest req, HttpServletResponse servletResponse)
throws Exception {
StringBuffer errorInfo = new StringBuffer(""); // 在验证导入文件的格式时得到的错误信息
FixedVoiceStatisticsForm form = (FixedVoiceStatisticsForm) actionForm;
FormFile file = form.getFileTxt();
String fileName = file.getFileName(); // 文件名称
int fileSize = file.getFileSize(); // 如果导入的文件为空,则报错返回
if (fileSize == 0) {
errorInfo.append("导入文件是空文件!");
}
int nameIndex = fileName.indexOf(".");
if (nameIndex == -1) {
errorInfo.append(" 导入的文件格式不对!");
}
String nameExt = fileName.substring(nameIndex + 1, fileName.length());
if (!nameExt.toLowerCase().equals("txt")) { // 如果导入的文件格式不是txt文件,则报错返回
errorInfo.append(" 导入文件不是txt格式的文件!");
}
if (errorInfo.length() != 0) {
req.setAttribute("errorInfohh", "错误信息:" + errorInfo.toString()); // 如果导入的文件是空文件或者不是txt格式的文件,则返回原页面
return actionMapping.findForward("listAll");
}
InputStream is = file.getInputStream();
InputStreamReader isr = new InputStreamReader(is, "GBK");
BufferedReader reader = new BufferedReader(isr);
String fileText = reader.readLine();
StringBuffer erro = new StringBuffer("");
ArrayList v = new ArrayList();
int count = 1;// 成功 i 失败 j 格式不正确 k 号码不存在
String billing_cycle_id = ((Map)(((ArrayList)JdbcServiceUtil.select(" select max(billing_cycle_id) bill_cycle from billing_cycle bc where bc.sts = 'E' ")).get(0))).get("BILL_CYCLE").toString();
while ((fileText != null) && (!fileText.equals("")))
{
String[] infos = fileText.split("\\|");
/// 本地网、 局向ID、序号、 话单类型、 通话时长、用户类别(1为预付费 2为卡类)
if (infos.length != 6) {///0310 40 20091201 guonei 526 1
erro.append("第"+count+"行格式不正确,正确格式是:0310|40|20091201|guonei|526|1");
req.setAttribute("errorInfohh", erro.toString());
return actionMapping.findForward("listAll");
}
if (infos[0] == null || "".equals(infos[0].trim())) {
erro.append("第"+count+"行本地网字段为空");
req.setAttribute("errorInfohh", erro.toString());
return actionMapping.findForward("listAll");
}
if (infos[1] == null || "".equals(infos[1].trim())) {
erro.append("第"+count+"行局向字段为空");
req.setAttribute("errorInfohh", erro.toString());
return actionMapping.findForward("listAll");
}
if (infos[2] == null || "".equals(infos[2].trim())) {
erro.append("第"+count+"行序号字段为空");
req.setAttribute("errorInfohh", erro.toString());
return actionMapping.findForward("listAll");
}
if (infos[3] == null || "".equals(infos[3].trim())) {
erro.append("第"+count+"行话单类型字段为空");
req.setAttribute("errorInfohh", erro.toString());
return actionMapping.findForward("listAll");
}
if (infos[4] == null || "".equals(infos[4].trim())) {
erro.append("第"+count+"行通话时长字段为空");
req.setAttribute("errorInfohh", erro.toString());
return actionMapping.findForward("listAll");
}
if (infos[5] == null || "".equals(infos[5].trim())) {
erro.append("第"+count+"行用户类别字段为空");
req.setAttribute("errorInfohh", erro.toString());
return actionMapping.findForward("listAll");
}
if((infos[0]!=null)&&(!infos[0].equals("")))
{
if(("0".equals(infos[0].substring(0, 1))))
{
infos[0] = infos[0].substring(1,infos[0].length());
}
}
dist_NbrVo infoVo = new dist_NbrVo(
billing_cycle_id,
infos[0], //local
infos[1], //seq
infos[2], ///exchId
"",///exchNAME
infos[4], //durtion
infos[5], ///payModel 1 预付费 2 卡类
"", //pricetype
"", //pricetypename
infos[3], //tkid
""// tkname
);
v.add(infoVo);
fileText = reader.readLine();
count ++;
}
Connection connect = null;
CallableStatement proc = null;
connect = JdbcServiceUtil.getConnection();
proc = connect.prepareCall("{ call fixed_voice_insert_pro(?,?) }");
ARRAY array_ = getArray_bak(connect, "FIXED_VOICE_STRUCT", "ALIST", v);
proc.setArray(1, array_);
proc.registerOutParameter(2, java.sql.Types.VARCHAR);
proc.execute();
String returnStr = (String) proc.getObject(2);
req.setAttribute("returninfo", returnStr);
this.toSearch( actionMapping, actionForm, req, servletResponse);
return actionMapping.findForward("listAll");
}
private static ARRAY getArray_bak(Connection con, String OracleObj,
String Oraclelist, ArrayList listData) throws Exception {
ARRAY list = null;
if (listData != null && listData.size() > 0)
{
StructDescriptor structdesc = new StructDescriptor(OracleObj, con);
ArrayDescriptor desc = ArrayDescriptor.createDescriptor(Oraclelist,con);
STRUCT[] structs = new
评论2
最新资源