Kaynağa Gözat

增加POS和PurInvoice单据封装csv文件,暂发送至D盘下

koul 5 yıl önce
ebeveyn
işleme
166ff8360b

+ 65 - 0
src/com/uas/entity/PosDetail.java

@@ -1,11 +1,20 @@
 package com.uas.entity;
 
+import java.util.Date;
+
 /**
  * @author koul
  * @email koul@usoftchina.com
  * @date 2020-09-29 17:22
  */
 public class PosDetail {
+    private int pd_id;
+    private int pd_posid;
+    private String pd_code;
+    private Date pd_date;
+    private int pd_detno;
+    private String pd_region;
+    private String pd_sendpos;
     private String pd_osa;
     private String pd_distributorname;
     private String pd_custcode;
@@ -29,6 +38,62 @@ public class PosDetail {
     private String pd_warehouselocation;
     private String pd_version;
 
+    public int getPd_id() {
+        return pd_id;
+    }
+
+    public void setPd_id(int pd_id) {
+        this.pd_id = pd_id;
+    }
+
+    public int getPd_posid() {
+        return pd_posid;
+    }
+
+    public void setPd_posid(int pd_posid) {
+        this.pd_posid = pd_posid;
+    }
+
+    public String getPd_code() {
+        return pd_code;
+    }
+
+    public void setPd_code(String pd_code) {
+        this.pd_code = pd_code;
+    }
+
+    public Date getPd_date() {
+        return pd_date;
+    }
+
+    public void setPd_date(Date pd_date) {
+        this.pd_date = pd_date;
+    }
+
+    public int getPd_detno() {
+        return pd_detno;
+    }
+
+    public void setPd_detno(int pd_detno) {
+        this.pd_detno = pd_detno;
+    }
+
+    public String getPd_region() {
+        return pd_region;
+    }
+
+    public void setPd_region(String pd_region) {
+        this.pd_region = pd_region;
+    }
+
+    public String getPd_sendpos() {
+        return pd_sendpos;
+    }
+
+    public void setPd_sendpos(String pd_sendpos) {
+        this.pd_sendpos = pd_sendpos;
+    }
+
     public String getPd_osa() {
         return pd_osa;
     }

+ 172 - 0
src/com/uas/entity/PurInvoiceDetail.java

@@ -0,0 +1,172 @@
+package com.uas.entity;
+
+/**
+ * @author koul
+ * @email koul@usoftchina.com
+ * @date 2020-10-12 11:46
+ */
+public class PurInvoiceDetail {
+
+    private int pd_id;
+    private int pd_purid;
+    private String pd_code;
+    private int pd_date;
+    private String pd_osa;
+    private String pd_distributorname;
+    private String pd_custcode;
+    private String pd_custname;
+    private String pd_custpartno;
+    private String pd_mpn;
+    private String pd_month;
+    private String pd_invoicenumber;
+    private String pd_yyyymmdd;
+    private Double pd_inqty;
+    private String pd_vendname;
+    private int pd_detno;
+    private String pd_region;
+    private String pd_sendpos;
+
+    public int getPd_id() {
+        return pd_id;
+    }
+
+    public void setPd_id(int pd_id) {
+        this.pd_id = pd_id;
+    }
+
+    public int getPd_purid() {
+        return pd_purid;
+    }
+
+    public void setPd_purid(int pd_purid) {
+        this.pd_purid = pd_purid;
+    }
+
+    public String getPd_code() {
+        return pd_code;
+    }
+
+    public void setPd_code(String pd_code) {
+        this.pd_code = pd_code;
+    }
+
+    public int getPd_date() {
+        return pd_date;
+    }
+
+    public void setPd_date(int pd_date) {
+        this.pd_date = pd_date;
+    }
+
+    public String getPd_osa() {
+        return pd_osa;
+    }
+
+    public void setPd_osa(String pd_osa) {
+        this.pd_osa = pd_osa;
+    }
+
+    public String getPd_distributorname() {
+        return pd_distributorname;
+    }
+
+    public void setPd_distributorname(String pd_distributorname) {
+        this.pd_distributorname = pd_distributorname;
+    }
+
+    public String getPd_custcode() {
+        return pd_custcode;
+    }
+
+    public void setPd_custcode(String pd_custcode) {
+        this.pd_custcode = pd_custcode;
+    }
+
+    public String getPd_custname() {
+        return pd_custname;
+    }
+
+    public void setPd_custname(String pd_custname) {
+        this.pd_custname = pd_custname;
+    }
+
+    public String getPd_custpartno() {
+        return pd_custpartno;
+    }
+
+    public void setPd_custpartno(String pd_custpartno) {
+        this.pd_custpartno = pd_custpartno;
+    }
+
+    public String getPd_mpn() {
+        return pd_mpn;
+    }
+
+    public void setPd_mpn(String pd_mpn) {
+        this.pd_mpn = pd_mpn;
+    }
+
+    public String getPd_month() {
+        return pd_month;
+    }
+
+    public void setPd_month(String pd_month) {
+        this.pd_month = pd_month;
+    }
+
+    public String getPd_invoicenumber() {
+        return pd_invoicenumber;
+    }
+
+    public void setPd_invoicenumber(String pd_invoicenumber) {
+        this.pd_invoicenumber = pd_invoicenumber;
+    }
+
+    public String getPd_yyyymmdd() {
+        return pd_yyyymmdd;
+    }
+
+    public void setPd_yyyymmdd(String pd_yyyymmdd) {
+        this.pd_yyyymmdd = pd_yyyymmdd;
+    }
+
+    public Double getPd_inqty() {
+        return pd_inqty;
+    }
+
+    public void setPd_inqty(Double pd_inqty) {
+        this.pd_inqty = pd_inqty;
+    }
+
+    public String getPd_vendname() {
+        return pd_vendname;
+    }
+
+    public void setPd_vendname(String pd_vendname) {
+        this.pd_vendname = pd_vendname;
+    }
+
+    public int getPd_detno() {
+        return pd_detno;
+    }
+
+    public void setPd_detno(int pd_detno) {
+        this.pd_detno = pd_detno;
+    }
+
+    public String getPd_region() {
+        return pd_region;
+    }
+
+    public void setPd_region(String pd_region) {
+        this.pd_region = pd_region;
+    }
+
+    public String getPd_sendpos() {
+        return pd_sendpos;
+    }
+
+    public void setPd_sendpos(String pd_sendpos) {
+        this.pd_sendpos = pd_sendpos;
+    }
+}

+ 57 - 51
src/com/uas/main/CsvParse.java

@@ -1,14 +1,12 @@
 package com.uas.main;
 
 import java.io.*;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
+import java.sql.*;
 import java.util.*;
 
 import com.alibaba.fastjson.JSON;
 import com.uas.entity.PosDetail;
+import com.uas.entity.PurInvoiceDetail;
 import org.apache.commons.csv.CSVFormat;
 import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVRecord;
@@ -282,13 +280,19 @@ public class CsvParse{
 		}
 		return value;
 	}
-	
+
 	@SuppressWarnings({"unused" })
-    public static void main(String[] args){
-		exportCsv("HK");
+	public static void main(String[] args){
+		//导出
+		exportCsv("HK","D:\\","POS","POS data");
+		exportCsv("HK","D:\\","PurInvoice","PurInvoice Data");
+		//导入
+		importCsv("HK","C:\\mendelson\\opensource\\as2\\messages\\Mantech\\inbox","C:\\mendelson\\opensource\\as2\\messages\\Mantech\\inbox_bak\\in\\");
+	}
+	
+
+    public static void importCsv(String sob,String filePath,String backupPath){
 		FTPClient client = null;
-		String filePath = "C:\\mendelson\\opensource\\as2\\messages\\Mantech\\inbox";
-		String backupPath = "C:\\mendelson\\opensource\\as2\\messages\\Mantech\\inbox_bak\\in\\";
 		List<String> filePaths = new ArrayList<String>();
 		Connection connect = null;
 		boolean execute = false;
@@ -298,7 +302,7 @@ public class CsvParse{
 				File[] files = inbox.listFiles();
 				String fileName = "";
 				if(files!=null&&files.length>0){
-					connect = JdbcUtil.getConnectBySob("HK");
+					connect = JdbcUtil.getConnectBySob(sob);
 					for(File file:files){
 						if(file.isDirectory()){
 							continue;
@@ -375,22 +379,27 @@ public class CsvParse{
 		}
     }
 
-    public static void exportCsv(String sob){
+    public static void exportCsv(String sob,String outPath,String caller,String out){
 		Connection connect =null;
 		Statement statement =null;
 		try {
 			connect=JdbcUtil.getConnectBySob(sob);
 			statement = connect.createStatement();
-			ResultSet resultSet = statement.executeQuery("select * from pos where pos_statuscode='ENTERING' and pos_sendstatus='待上传'");
-			while(resultSet.next()){
-				int posId = resultSet.getInt("pos_id");
-				Boolean result = getPOSData(statement, posId);
+			ResultSet res = statement.executeQuery("select * from posedidata where status_=0 and caller_='"+caller+"'" +
+					" order by date_");
+			List<Integer> ints = new ArrayList<Integer>();
+			while(res.next()){
+				int posId = res.getInt("specfield_");
+				ints.add(posId);
+			}
+			for (int posId:ints) {
+				Boolean result = getData(statement, posId,outPath,caller,out);
 				if (result){
-					statement.execute("update pos set pos_sendstatus='已上传' where pos_id="+posId);
+					statement.execute("update posedidata set status_=-1 where specfield_="+posId);
 				}
-
 			}
 		} catch (SQLException e) {
+			System.err.println(e.getMessage());
 			e.printStackTrace();
 			if(statement!=null){
 				try {
@@ -414,61 +423,58 @@ public class CsvParse{
 
 	}
 
-	public static Boolean getPOSData(Statement statement,int id){
+	public static Boolean getData(Statement statement,int id,String outPath,String caller,String out){
 		Boolean result=false;
 		long time = System.currentTimeMillis();
-		String outPath ="D:\\"+time+".csv";
+		String filePath =outPath+caller+time+".csv";
 		try {
-			ResultSet resultSet = statement.executeQuery("select dg_caption from detailgrid where dg_caller = 'POS' and " +
-					"dg_sequence>=(select dg_sequence from detailgrid where dg_caller = 'POS' and dg_caption='OSA') order by dg_sequence");
+			ResultSet resultSet =
+					statement.executeQuery("select dg_caption from detailgrid where dg_caller = '"+caller+"' and dg_sendedi=-1 " +
+							"order by dg_sequence");
 			List<String> titles = new ArrayList<>();
 			while (resultSet.next()) {
 				titles.add(resultSet.getString("dg_caption"));
 			}
-			ResultSet rs = statement.executeQuery("select dg_field from detailgrid where dg_caller = 'POS' and " +
-					"dg_sequence>=(select dg_sequence from detailgrid where dg_caller = 'POS' and dg_caption='OSA') order by dg_sequence");
+			ResultSet rs = statement.executeQuery("select dg_field from detailgrid where dg_caller = '"+caller+"' and" +
+					" dg_sendedi=-1 order by dg_sequence");
 			List<String> propertys = new ArrayList<>();
 			while (rs.next()) {
 				propertys.add(rs.getString("dg_field"));
 			}
-			List<PosDetail> datas = new ArrayList<>();
+			List<Object> datas = new ArrayList<Object>();
 			if (propertys != null && propertys.size() > 0) {
 				String s = PraseCsvUtil.listToString(propertys);
-				ResultSet set = null;
-				if (id != 0) {
-					set = statement.executeQuery("select " + s + " from posdetail where pd_posid=" + id);
-				} else {
-					set = statement.executeQuery("select " + s + " from posdetail left join pos on pos_id=pd_posid where pos_statuscode='ENTERING' and pos_sendstatus='待上传'");
-				}
-				while (set.next()) {
-					Map<String, Object> map = new HashMap<>();
-					for (String property : propertys) {
-						map.put(property, set.getObject(property));
+				if ("POS".equals(caller)) {
+					ResultSet set = statement.executeQuery("select " + s + " from posdetail where pd_posid=" + id);
+					while (set.next()) {
+						Map<String, Object> map = new HashMap<>();
+						for (String property : propertys) {
+							map.put(property, set.getObject(property));
+						}
+						PosDetail posDetail = JSON.parseObject(JSON.toJSONString(map), PosDetail.class);
+						datas.add(posDetail);
+					}
+				}else if ("PurInvoice".equals(caller)){
+					ResultSet set =
+							statement.executeQuery("select " + s + " from purinvoicedetail where pd_purid=" + id);
+					while (set.next()) {
+						Map<String, Object> map = new HashMap<>();
+						for (String property : propertys) {
+							map.put(property, set.getObject(property));
+						}
+						PurInvoiceDetail purInvoiceDetail = JSON.parseObject(JSON.toJSONString(map),
+								PurInvoiceDetail.class);
+						datas.add(purInvoiceDetail);
 					}
-					PosDetail posDetail = JSON.parseObject(JSON.toJSONString(map), PosDetail.class);
-					datas.add(posDetail);
 				}
+
 			}
 			if (titles != null && titles.size() > 0 && propertys != null && propertys.size() > 0 && datas != null && datas.size() > 0) {
-				result = PraseCsvUtil.exportCsv("POS data", outPath, titles, propertys, datas);
+				result = PraseCsvUtil.exportCsv(out, filePath, titles, propertys, datas);
 			}
 		}catch (Exception e){
 			e.printStackTrace();
 		}
 		return result;
 	}
-	private List<String> getPropertys(Statement statement){
-		try {
-			ResultSet rs = statement.executeQuery("select dg_field from detailgrid where dg_caller = 'POS' and " +
-					"dg_sequence>=(select dg_sequence from detailgrid where dg_caller = 'POS' and dg_caption='OSA') order by dg_sequence");
-			List<String> propertys = new ArrayList<>();
-			while (rs.next()) {
-				propertys.add(rs.getString("dg_field"));
-			}
-			return propertys;
-		} catch (SQLException e) {
-			e.printStackTrace();
-			return null;
-		}
-	}
  }

+ 5 - 3
src/com/uas/util/PraseCsvUtil.java

@@ -106,8 +106,10 @@ public class PraseCsvUtil {
 			//构建输出流,同时指定编码
 			OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(file), "gbk");
 			//csv文件是逗号分隔,除第一个外,每次写入一个单元格数据后需要输入逗号
-			ow.write(out);
-			ow.write("\r\n");
+			if (out!=null){
+				ow.write(out);
+				ow.write("\r\n");
+			}
 			for(String title : titles){
 				ow.write(title);
 				ow.write(",");
@@ -123,7 +125,7 @@ public class PraseCsvUtil {
 						//设置字段可见性
 						field.setAccessible(true);
 						if(property.equals(field.getName())){
-							String s = field.get(obj) == null ? "" : field.get(obj).toString().replace(",","");
+							String s = field.get(obj) == null ? "" : field.get(obj).toString();
 							ow.write(s);
 							ow.write(",");
 							continue;