⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 discountparse.java

📁 SAP这个系统的一个转换器
💻 JAVA
字号:
package com.idoc.logic;

import com.idoc.face.InterfaceParse;
import java.io.File;

/**
 * <p>Title: IDOC Interface</p>
 * <p>Description: IDOC 转换器</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: SiChuan XinHua</p>
 * @author Richary
 * @version 1.0
 */

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Vector;
import com.idoc.util.Operate;
import com.idoc.util.FieldData;
import com.idoc.file.ReadData;
import com.idoc.logic.TempTableDispose;
import javax.swing.JOptionPane;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

public class DiscountParse
    implements InterfaceParse {

  private String type = ""; // 段类型
  private String t_temp = "";
  private Vector vec = new Vector();
  String  KONDART = "";
  public DiscountParse() {
  }

  public boolean parseData(File file) {
    Operate operate = new Operate();
    String m_text = "";
    String sql = "";
    String t_text = "";
    boolean flag = false;
    BufferedReader br = null;
    InputStream bin = null;
    InputStreamReader ir = null;
    FileInputStream fis = null;
    boolean f_flag = true;
    int recCount = 0;
    try {
      fis = new FileInputStream(file);
      byte[] buff = new byte[ (int) file.length()];
      int len = 0, pos = 0;

      while ( (len = fis.read(buff, pos, buff.length - pos)) > -1 &&
             pos < buff.length) {
        pos += len;
      }
      bin = new java.io.ByteArrayInputStream(buff);
      ir = new InputStreamReader(bin);
      br = new BufferedReader(ir);
      sql = "insert into T_SAPIN_SY_MASTER_CATE_DISCOUNT (STORECODE,CANUSE_Flag,Promotion_CODE,REBATE_LEVEL,CATE_CODE,DISCOUNT_TYPE,Begin_Date,End_Date,VORZEICHEN,KONDSATZ,KONDWERT) VALUES (";
      String record = new String();
      while ( (record = br.readLine()) != null) {

        recCount++;
        if (recCount == 1) { // 处理第一行数据
          type = record.substring(39, 69).trim();
          if (!type.equalsIgnoreCase("WPDREB01")) {
            if (br != null)
              br.close();
            if (ir != null)
              ir.close();
            if (bin != null)
              bin.close();
            if (fis != null)
              fis.close();
            flag = false;
            break;
          }
        }
        else {
          // 解析数据
          if (operate.getsubString(record, 55, 61).equalsIgnoreCase("000000") &&
              record.substring(0, 30).trim().equalsIgnoreCase("E2WPREB01000")) { // 一个促销单号
            if (recCount != 2) {
              vec.add(sql + m_text + "," + t_text);
              m_text = "";
              t_text = "";
              f_flag = false;
            }
            // 一个促销单号
            m_text = getStringData(record);

          }
          else {
            // 如果是第E2WPREB02000,开始往VECTOR写INSERT语句
            if (record.substring(0, 30).trim().equalsIgnoreCase("E2WPREB02000")) {
              if (!t_text.equals(""))
                vec.add(sql + m_text + "," + t_text);
              t_text = "";
            }
            if (t_text.equalsIgnoreCase(""))
              t_text = getStringData(record);
            else
              t_text += "," + getStringData(record);
          }
        }
      }
      vec.add(sql + m_text + "," + t_text);
      flag = true;
    }
    catch (Exception ex) {
      System.out.println("Discount's parseData is Error!");
      ex.printStackTrace();
    }
    finally {
      try {
        if (br != null)
          br.close();
        if (ir != null)
          ir.close();
        if (bin != null)
          bin.close();
        if (fis != null)
          fis.close();
        return flag;
      }
      catch (Exception ex) {
        ex.printStackTrace();
        return false;
      }
    }
  }

  public String getStringData(String str) {
    Operate operate = new Operate();

    String rt = "";
    if (str == null) {
      return "";
    }
    type = operate.getsubString(str, 0, 30);
    if (type.equalsIgnoreCase("E2WPREB01000")) {

      // 门店地址  -- 门店地址从63开始,但是前面有5位0,所以多取5位
      t_temp = operate.getsubString(str, 69, 73);
      if (rt == null || rt.equals("")) {
        rt = "'" + t_temp + "'";
      }
      else {
        rt = rt + ",'" + t_temp + "'";
      }

      // 修改标识
      t_temp = operate.getsubString(str, 73, 77);
      if (t_temp.equalsIgnoreCase("MODI")) {
        rt += ",0";
      }
      else {
        rt += ",1";

        // 促销编码
      }
      t_temp = operate.getsubString(str, 103, 118);
      rt += ",'" + t_temp + "'";

    }

    if (type.equalsIgnoreCase("E2WPREB02000")) {

      // 促销折扣等级
      t_temp = operate.getsubString(str, 63, 65);
      if (rt == null || rt.equals("")) {
        rt = "'" + t_temp + "'";
      }
      else {
        rt = rt + ",'" + t_temp + "'";
      }

      // 商品组
      t_temp = operate.getsubString(str, 65, 85);
      rt += ",'" + t_temp + "'";
    }

    if (type.equalsIgnoreCase("E2WPREB03000")) {

      // 促销类型
      t_temp = operate.getsubString(str, 63, 67);
      if (rt == null || rt.equals("")) {
        rt = "'" + t_temp + "'";
      }
      else {
        rt = rt + ",'" + t_temp + "'";
      }
     KONDART = t_temp;
      // 条件开始日期
      t_temp = operate.getsubString(str, 67, 75);
      rt += ",'" + operate.formatDate(t_temp) + "'";

      // 条件结束日期
      t_temp = operate.getsubString(str, 79, 87);
      rt += ",'" + operate.formatDate(t_temp) + "'";
    }

    if (type.equalsIgnoreCase("E2WPREB04000")) {

      // +/- 条件符号
      t_temp = operate.getsubString(str, 63, 64);
      if (rt == null || rt.equals("")) {
        rt = "'" + t_temp + "'";
      }
      else {
        rt = rt + ",'" + t_temp + "'";
      }
if(KONDART.equalsIgnoreCase("Z001"))
      // 条件比率,百分比条件
   {   t_temp = operate.getsubString(str, 64, 74);
      if (t_temp.equalsIgnoreCase("") || t_temp == null)
        t_temp = "0";
      rt += "," + t_temp ;
      rt += "," + 0 + ")";
   }
   if(KONDART.equalsIgnoreCase("Z002"))
      // 金额
  {    t_temp = operate.getsubString(str, 74, 84);
      if (t_temp == null || t_temp.equalsIgnoreCase(""))
        t_temp = "0";
      rt +=  ","+0+"," + t_temp + ")";
  }
  KONDART = "";
    }
    return rt;
  }

  public boolean disposeData(File file) {
    TempTableDispose discount = new TempTableDispose();
    boolean flag = false;
    flag = parseData(file);
    if (flag) {
      flag = discount.disposeData(vec, file, "discount");
    }
    else {
      return false;
    }
    return flag;
  }

}

⌨️ 快捷键说明

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