Chinaunix首页 | 论坛 | 博客
  • 博客访问: 240471
  • 博文数量: 49
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 530
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-06 08:57
文章分类

全部博文(49)

文章存档

2009年(5)

2008年(44)

我的朋友

分类: WINDOWS

2008-12-29 17:48:08

package com.uniwin.webkey.model.smp;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import com.uniwin.util.Config;
import com.uniwin.util.FileUtil;
import com.uniwin.util.GTime;
import com.uniwin.util.StringUtil;
import com.uniwin.webkey.control.WebkeyActionUtil;
import com.uniwin.webkey.control.manager.bean.WKFunFactory;
import com.uniwin.webkey.itf.IWkFun;
import com.uniwin.webkey.itf.base.WKResultList;
import com.uniwin.webkey.itf.base.WKResultTree;
import com.uniwin.webkey.itf.smp.ISv;
import com.uniwin.webkey.model.util.DAO;
import com.uniwin.webkey.model.util.PubFun;
public class Copy_2_of_Sv implements ISv
{
 private DAO dao = DAO.getDAOInstance();
    public int getList(String sCondition, WKResultList list)
    {
     //返回订购关系分页数据
  String sql = "";
  sql = "SELECT " + list.getBeanFactory().getSql() + "  FROM SM_T_SVALL ";
  if (!sCondition.equals("")) {
   sql = sql + "WHERE "+sCondition ;
  }
  if (dao.select(sql, StringUtil.split(list.getBeanFactory().getSql(),
    ",").length, list) == 1) {
   if (list.getMydata() != null && list.dataSize() != 0) {
    PubFun.processToResultList(list);
   }
   return 1;
  }
  return -1;
    }
   
    public int fetchClientTree(WKResultTree rootTree, String sCondition, String URL)
    {
        // 取出对应权限的业务类型,遍历类型,一一加入到rootTree子节点下。
        String sql = "";
        sql = "SELECT ST_ID,ST_NAME FROM SM_T_TYPE ";
        if (!sCondition.equals(""))
        {
            sql = sql + sCondition;
        }
        Vector vecType = dao.selectEx(sql, 0);
        for (int i = 0; i < vecType.size(); i++)
        {
            Map map = (Map) vecType.get(i);
            int id = Integer.parseInt(map.get("ST_ID").toString());// id 你的类别ID
            String name = map.get("ST_NAME").toString();// name 类别名称
            // URL 是定义的URL地址
            WKResultTree node = new WKResultTree(id, name, URL + "?TypeId=" + id + "", rootTree
                .getBeanFactory());
            rootTree.addChildren(node);
        }
        return 1;
    }
 public int CahCellService(String id,String st_id,String ss_etime)
 {
  //订购关系退订
  String sql = "UPDATE SM_T_SVALL  SET SS_STATUS = '1', SS_ETIME = '"+ss_etime+"'" +
    " WHERE ST_ID='"+st_id+"' AND SS_ID IN ("+id+")";
  return dao.update(sql);
 }
 
    public int updateService(String id,String st_id,String ss_etime)
    {
        String sql = "UPDATE SM_T_SVALL  SET SS_LTIME = '"+ss_etime+"'" +
                " WHERE ST_ID='"+st_id+"' AND SS_ID IN ("+id+")";
        return dao.update(sql);
    }
    public int updateImpTabTmp(String tmp_tab,String ss_status_tmp,String ss_moble_tmp,String st_code_tmp)
    {
     //更新临时表中的状态位
        String sql = "UPDATE "+tmp_tab+"  SET SS_STATUS_TMP = '"+ss_status_tmp+"'" +
          " WHERE SS_MOBILE_TMP = '"+ss_moble_tmp+"' " +
          " AND ST_CODE_TMP = '"+st_code_tmp+"'" ;
        return dao.update(sql);
    }
   
    public int delImpTabTmp(String tmp_tab)
    {
     //清空临时表数据
     String sql = "DELETE FROM "+tmp_tab+"";
     return dao.update(sql);
    }
   
    public int dropImpTabTmp(String tmp_tab)
    {
     //删除临时表
     String sql = "DROP TABLE "+tmp_tab+"";
     return dao.update(sql);
    }
   
    public int createImpTabTmp(String iuserId)
    {
     //检查表是否存在
     boolean b = SmpOrder.existOrnot("IMPORD_TMP"+"_"+iuserId+"","webkey1");
     if(b == true)
     {
      delImpTabTmp("IMPORD_TMP"+"_"+iuserId+"");
      //SvFactory.getSv().dropImpTabTmp("IMPORD_TMP"+"_"+iuserId+"");
      return 1;
     }
     else
     {
      //针对当前登录用户创建临时表
         String sql = "CREATE TABLE `IMPORD_TMP"+"_"+iuserId+"` (" +
           "`SS_MOBILE_TMP` varchar (20) ," +
           "`ST_CODE_TMP` varchar (30) ," +
           "`SS_STIME_TMP` varchar (20) ," +
           "`SS_STATUS_TMP` varchar (2)) " +
           "TYPE=MyISAM;";
         return dao.update(sql);
     }
    }
   
    public String getTmpPath()
    {
     //配置临时文件路径
     String contmpPath = "";
     try
     {
      contmpPath = Config.getParam("smp.smp.sv.tmppath");
        
     }catch(Exception e)
     {
         contmpPath = "/apps/smp/impord";
     }
     return contmpPath;
    }
   
 public void SetLastSendTime() {
  // TODO 自动生成方法存根
  
 }
 public int addService(String tbname,Map map)
 {
  //smp_svid为各个短信类别发布后统一使用的键值
  IWkFun fun = WKFunFactory.getFun();
     if(fun.insert(tbname, map, "SS_ID", "smp_svid")==-1)
  {
       return -1;
  }
     return 1;
 }
 
 public Vector countImpOrdRecord(Vector vec_count,String tmp_tab,String ss_status_tmp)
 {
  //按订购代码统计导入记录
  //查询无重复业务代码
  String sqlcode = "SELECT DISTINCT ST_CODE_TMP FROM "+tmp_tab+"";
  Vector veccode = dao.selectEx(sqlcode, 0);
  for(int i=0;i  {
   //统计某个业务的导入条数
   HashMap map = (HashMap) veccode.get(i);
   String sql_code_count = "SELECT COUNT(*) AS CON_CODE FROM "+tmp_tab+"" +
     " WHERE ST_CODE_TMP='"+map.get("ST_CODE_TMP")+"'";
   if(!ss_status_tmp.equals(""))
   {
    sql_code_count = sql_code_count + "AND SS_STATUS_TMP = '"+ss_status_tmp+"'";
   }
   Vector vec_code_count = dao.selectEx(sql_code_count, 0);
   HashMap mapcnt = (HashMap) vec_code_count.get(0);
   //将业务代码和统计值分别存入map2中
   HashMap map2 = new HashMap();
   map2.put("ST_CODE_TMP", map.get("ST_CODE_TMP"));
   map2.put("CON_CODE", mapcnt.get("CON_CODE"));
   vec_count.add(map2);
  }
  return vec_count;
 }
 
 public Vector getListImp(String tmp_tab,String st_code,String ss_status)
 {
  //确认导入类别表后,统计临时表中导入成功、失败、未执行导入的记录
  String sql = "SELECT SS_MOBILE_TMP,ST_CODE_TMP FROM "+tmp_tab+"" +
  " WHERE ST_CODE_TMP = '"+st_code+"' " +
  " AND SS_STATUS_TMP = '"+ss_status+"'";
  return dao.selectEx(sql, 0);
 }
 
 public boolean ImportOrdRecord(File file,String tmp_tab,String filepath,String iUserId) throws Exception
 {
  //读取文本文件且放入到临时表中
  BufferedReader br = new BufferedReader(new FileReader(file));
  String[] arrLine;
  String strLine = br.readLine();
  Map mapRead = new HashMap();
  while (strLine != null)
  {
   mapRead = new HashMap();// 匹配上的字段及其值,每处理一条记录就应重新初始化一次。
   try
   {
    arrLine = splitTXT(strLine);
    //向临时表中插入记录前,把读取到的记录和临时表中已存在的记录作比较;
    //若临时表中含有相同记录,则不向临时表插记录,继续读取下一行。
    if(arrLine.length>=2)
    {
     //取数组中的前两个值arrLine[0][1]
     //查询临时表中的前两个字段
     String sqltmp2 = "SELECT SS_MOBILE_TMP,ST_CODE_TMP FROM "+tmp_tab+" " +
       " WHERE ST_CODE_TMP = '"+arrLine[1]+"' " +
       " AND SS_MOBILE_TMP = '"+arrLine[0]+"'";
     Vector vectmp2 = dao.selectEx(sqltmp2, 0);
     if(vectmp2.size() == 0 && vectmp2 != null)
     {
      //当临时表中的数据为空时,则直接向临时表中插记录
      //将该行的每个字段封装到map中
      //判断数组长度是否小于3,若长度为2则时间取系统时间;若长度为3则把时间放入map中,把时间格式转换为14位
      if(arrLine.length<3)
      {
       mapRead.put("SS_MOBILE_TMP", "'"+arrLine[0]+"'");
       mapRead.put("ST_CODE_TMP", "'"+arrLine[1]+"'");
       mapRead.put("SS_STIME_TMP", "'"+GTime.getTime(GTime.YYYYMMDDhhmmss)+"'");
       mapRead.put("SS_STATUS_TMP", "0");
      }
      else
      {
       mapRead.put("SS_MOBILE_TMP", "'"+arrLine[0]+"'");
       mapRead.put("ST_CODE_TMP", "'"+arrLine[1]+"'");
       mapRead.put("SS_STIME_TMP", "'"+arrLine[2]+"'");
       WebkeyActionUtil.createDate(mapRead, "SS_STIME_TMP");
       mapRead.put("SS_STATUS_TMP", "0");
      }
      
      IWkFun fun = WKFunFactory.getFun();
         if(fun.insert(tmp_tab, mapRead)==-1)
         {
          System.out.println("数据库操作失败!");
         }
     }
     else
     {
      boolean flag = false;
//      for(int i=0;i//      {
//       //将临时表中查询到的记录放入map中
//       HashMap maptmp2 = (HashMap) vectmp2.get(i);
//       if(maptmp2.get("SS_MOBILE_TMP").equals(arrLine[0]) && maptmp2.get("ST_CODE_TMP").equals(arrLine[1]))
//       {
//        flag = true;
//        break;//跳出for循环
//       }
//       else
//       {
//        flag = false;
//       }
//      }
//      if(flag == false)
//      {
//       //将该行的每个字段封装到map中
//       //判断数组长度是否小于3,若长度为2则时间取系统时间;若长度为3则把时间放入map中,把时间格式转换为14位
//       if(arrLine.length<3)
//       {
//        mapRead.put("SS_MOBILE_TMP", "'"+arrLine[0]+"'");
//        mapRead.put("ST_CODE_TMP", "'"+arrLine[1]+"'");
//        mapRead.put("SS_STIME_TMP", "'"+GTime.getTime(GTime.YYYYMMDDhhmmss)+"'");
//        mapRead.put("SS_STATUS_TMP", "0");
//       }
//       else
//       {
//        mapRead.put("SS_MOBILE_TMP", "'"+arrLine[0]+"'");
//        mapRead.put("ST_CODE_TMP", "'"+arrLine[1]+"'");
//        mapRead.put("SS_STIME_TMP", "'"+arrLine[2]+"'");
//        WebkeyActionUtil.createDate(mapRead, "SS_STIME_TMP");
//        mapRead.put("SS_STATUS_TMP", "0");
//       }
//       IWkFun fun = WKFunFactory.getFun();
//          if(fun.insert(tmp_tab, mapRead)==-1)
//          {
//           System.out.println("数据库操作失败!");
//          }
//      }
     }
    }
    //读取下一行记录
       strLine = br.readLine();
   }
   catch (Exception e)
   {
    e.printStackTrace();
   }
  }
  br.close();
  FileUtil.delFile(filepath+"/"+iUserId+".txt");
  return true;
 }
 
 public boolean ImportOrdTaRecord(String[] arrdesc,String tmp_tab)
 {
  Map mapRead = new HashMap();
  String[] arrLine;
  for(int j=0;j  {
   try
   {
    arrLine = splitTXT(arrdesc[j]);
    //向临时表中插入记录前,把读取到的记录和临时表中已存在的记录作比较;
    //若临时表中含有相同记录,则不向临时表插记录,继续读取下一行。
    if(arrLine.length>=2)
    {
     //取数组中的前两个值arrLine[0][1]
     //查询临时表中的前两个字段
     String sqltmp2 = "SELECT SS_MOBILE_TMP,ST_CODE_TMP FROM "+tmp_tab+"";
     Vector vectmp2 = dao.selectEx(sqltmp2, 0);
     if(vectmp2.size() == 0 && vectmp2 != null)
     {
      //当临时表中的数据为空时,则直接向临时表中插记录
      //将该行的每个字段封装到map中
      //判断数组长度是否小于3,若长度为2则时间取系统时间;若长度为3则把时间放入map中,把时间格式转换为14位
      if(arrLine.length<3)
      {
       mapRead.put("SS_MOBILE_TMP", "'"+arrLine[0]+"'");
       mapRead.put("ST_CODE_TMP", "'"+arrLine[1]+"'");
       mapRead.put("SS_STIME_TMP", "'"+GTime.getTime(GTime.YYYYMMDDhhmmss)+"'");
       mapRead.put("SS_STATUS_TMP", "'0'");
      }
      else
      {
       mapRead.put("SS_MOBILE_TMP", "'"+arrLine[0]+"'");
       mapRead.put("ST_CODE_TMP", "'"+arrLine[1]+"'");
       mapRead.put("SS_STIME_TMP", "'"+arrLine[2]+"'");
       WebkeyActionUtil.createDate(mapRead, "SS_STIME_TMP");
       mapRead.put("SS_STATUS_TMP", "'0'");
      }
      
      IWkFun fun = WKFunFactory.getFun();
         if(fun.insert(tmp_tab, mapRead)==-1)
         {
          System.out.println("数据库操作失败!");
         }
     }
     else
     {
      boolean flag = false;
      for(int i=0;i      {
       //将临时表中查询到的记录放入map中
       HashMap maptmp2 = (HashMap) vectmp2.get(i);
       if(maptmp2.get("SS_MOBILE_TMP").equals(arrLine[0]) && maptmp2.get("ST_CODE_TMP").equals(arrLine[1]))
       {
        flag = true;
        break;//跳出for循环
       }
       else
       {
        flag = false;
       }
      }
      if(flag == false)
      {
       //将该行的每个字段封装到map中
       //判断数组长度是否小于3,若长度为2则时间取系统时间;若长度为3则把时间放入map中,把时间格式转换为14位
       if(arrLine.length<3)
       {
        mapRead.put("SS_MOBILE_TMP", "'"+arrLine[0]+"'");
        mapRead.put("ST_CODE_TMP", "'"+arrLine[1]+"'");
        mapRead.put("SS_STIME_TMP", "'"+GTime.getTime(GTime.YYYYMMDDhhmmss)+"'");
        mapRead.put("SS_STATUS_TMP", "'0'");
       }
       else
       {
        mapRead.put("SS_MOBILE_TMP", "'"+arrLine[0]+"'");
        mapRead.put("ST_CODE_TMP", "'"+arrLine[1]+"'");
        mapRead.put("SS_STIME_TMP", "'"+arrLine[2]+"'");
        WebkeyActionUtil.createDate(mapRead, "SS_STIME_TMP");
        mapRead.put("SS_STATUS_TMP", "'0'");
       }
       IWkFun fun = WKFunFactory.getFun();
          if(fun.insert(tmp_tab, mapRead)==-1)
          {
           System.out.println("数据库操作失败!");
          }
      }
     }
    }
   }
   catch (Exception e)
   {
    e.printStackTrace();
   }
  }
  return true;
 }
 
    public String[] splitTXT(String src) throws Exception
    {
     //对读取的每行数据进行字符串处理
        if (src == null || src.equals(""))
            return new String[0];
        StringBuffer st = new StringBuffer();
        Vector result = new Vector();
        boolean beginWithQuote = false;
        for (int i = 0; i < src.length(); i++)
        {
            char ch = src.charAt(i);
            if (ch == '\"')
            {
                if (beginWithQuote)
                {
                    i++;
                    if (i >= src.length())
                    {
                        result.addElement(st.toString());
                        st = new StringBuffer();
                        beginWithQuote = false;
                    } else
                    {
                        ch = src.charAt(i);
                        if (ch == '\"')
                        {
                            st.append(ch);
                        } else if (ch == ',')
                        {
                            result.addElement(st.toString());
                            st = new StringBuffer();
                            beginWithQuote = false;
                        } else
                        {
                            throw new Exception("Single double-quote char mustn't exist in filed "
                                + (result.size() + 1) + " while it is begined with quote\nchar at:"
                                + i);
                        }
                    }
                } else if (st.length() == 0)
                {
                    beginWithQuote = true;
                } else
                {
                    throw new Exception(
                        "Quote cannot exist in a filed which doesn't begin with quote!\nfield:"
                            + (result.size() + 1));
                }
            } else if (ch == ',')
            {
                if (beginWithQuote)
                {
                    st.append(ch);
                } else
                {
                    result.addElement(st.toString());
                    st = new StringBuffer();
                    beginWithQuote = false;
                }
            } else
            {
                st.append(ch);
            }
        }
        if (st.length() != 0)
        {
            if (beginWithQuote)
            {
                throw new Exception("last field is begin with but not end with double quote");
            } else
            {
                result.addElement(st.toString());
            }
        }
        if (src.lastIndexOf(",") == src.length() - 1)
            result.addElement(st.toString());
        String rs[] = new String[result.size()];
        for (int i = 0; i < rs.length; i++)
        {
            rs[i] = (String) result.elementAt(i);
        }
        return rs;
    }
    public int updateService(String id,String st_id,String ss_etime,String tablename)
    {
        String sql = "UPDATE "+tablename+"  SET SS_LTIME = '"+ss_etime+"'" +
                " WHERE ST_ID='"+st_id+"' AND SS_ID IN ("+id+")";
        System.out.println("指标值位:"+sql);
        return dao.update(sql);
       
    }
    public int getTotalSv(String sCondition ,String tablename)
    {
        String sql = "SELECT COUNT(*) CNT FROM "+tablename+"  WHERE " + sCondition;
        //System.out.println("sql=================="+sql);
        List list = dao.selectEx(sql, 0);
        Map hashmap = (HashMap) list.get(0);
        return Integer.parseInt(String.valueOf(hashmap.get("CNT")));
    }
   
    public int getList(String sCondition, WKResultList list,String tablename)
    {
        String sql = "";
   
        sql = "SELECT " + list.getBeanFactory().getSql() + "  FROM "+tablename+" ";
        if (!sCondition.equals("")) {
            sql = sql + "WHERE "+sCondition ;
        }
        if (dao.select(sql, StringUtil.split(list.getBeanFactory().getSql(),
                ",").length, list) == 1) {
            if (list.getMydata() != null && list.dataSize() != 0) {
                PubFun.processToResultList(list);
            }
            return 1;
        }
        return -1;
    }
}
阅读(1967) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~