koul 5 years ago
parent
commit
fba14e03cb

BIN
lib/fastjson-1.2.73.jar


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

@@ -0,0 +1,207 @@
+package com.uas.entity;
+
+/**
+ * @author koul
+ * @email koul@usoftchina.com
+ * @date 2020-09-29 17:22
+ */
+public class PosDetail {
+    private String pd_osa;
+    private String pd_distributorname;
+    private String pd_custcode;
+    private String pd_vendname;
+    private String pd_endcustname;
+    private String pd_endcustcountry;
+    private String pd_custpartno;
+    private String pd_mpn;
+    private String pd_application;
+    private String pd_month;
+    private Double pd_neworderqty;
+    private Double pd_salesqty;
+    private Double pd_backlogqty;
+    private Double pd_stockqty;
+    private Double pd_purchaseqty;
+    private Double pd_price;
+    private String pd_currency;
+    private Double pd_vmistockqty;
+    private Double pd_stockexhaeplusqty;
+    private Double pd_stockexchaeminusqty;
+    private String pd_warehouselocation;
+    private String pd_version;
+
+    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_vendname() {
+        return pd_vendname;
+    }
+
+    public void setPd_vendname(String pd_vendname) {
+        this.pd_vendname = pd_vendname;
+    }
+
+    public String getPd_endcustname() {
+        return pd_endcustname;
+    }
+
+    public void setPd_endcustname(String pd_endcustname) {
+        this.pd_endcustname = pd_endcustname;
+    }
+
+    public String getPd_endcustcountry() {
+        return pd_endcustcountry;
+    }
+
+    public void setPd_endcustcountry(String pd_endcustcountry) {
+        this.pd_endcustcountry = pd_endcustcountry;
+    }
+
+    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_application() {
+        return pd_application;
+    }
+
+    public void setPd_application(String pd_application) {
+        this.pd_application = pd_application;
+    }
+
+    public String getPd_month() {
+        return pd_month;
+    }
+
+    public void setPd_month(String pd_month) {
+        this.pd_month = pd_month;
+    }
+
+    public Double getPd_neworderqty() {
+        return pd_neworderqty;
+    }
+
+    public void setPd_neworderqty(Double pd_neworderqty) {
+        this.pd_neworderqty = pd_neworderqty;
+    }
+
+    public Double getPd_salesqty() {
+        return pd_salesqty;
+    }
+
+    public void setPd_salesqty(Double pd_salesqty) {
+        this.pd_salesqty = pd_salesqty;
+    }
+
+    public Double getPd_backlogqty() {
+        return pd_backlogqty;
+    }
+
+    public void setPd_backlogqty(Double pd_backlogqty) {
+        this.pd_backlogqty = pd_backlogqty;
+    }
+
+    public Double getPd_stockqty() {
+        return pd_stockqty;
+    }
+
+    public void setPd_stockqty(Double pd_stockqty) {
+        this.pd_stockqty = pd_stockqty;
+    }
+
+    public Double getPd_purchaseqty() {
+        return pd_purchaseqty;
+    }
+
+    public void setPd_purchaseqty(Double pd_purchaseqty) {
+        this.pd_purchaseqty = pd_purchaseqty;
+    }
+
+    public Double getPd_price() {
+        return pd_price;
+    }
+
+    public void setPd_price(Double pd_price) {
+        this.pd_price = pd_price;
+    }
+
+    public String getPd_currency() {
+        return pd_currency;
+    }
+
+    public void setPd_currency(String pd_currency) {
+        this.pd_currency = pd_currency;
+    }
+
+    public Double getPd_vmistockqty() {
+        return pd_vmistockqty;
+    }
+
+    public void setPd_vmistockqty(Double pd_vmistockqty) {
+        this.pd_vmistockqty = pd_vmistockqty;
+    }
+
+    public Double getPd_stockexhaeplusqty() {
+        return pd_stockexhaeplusqty;
+    }
+
+    public void setPd_stockexhaeplusqty(Double pd_stockexhaeplusqty) {
+        this.pd_stockexhaeplusqty = pd_stockexhaeplusqty;
+    }
+
+    public Double getPd_stockexchaeminusqty() {
+        return pd_stockexchaeminusqty;
+    }
+
+    public void setPd_stockexchaeminusqty(Double pd_stockexchaeminusqty) {
+        this.pd_stockexchaeminusqty = pd_stockexchaeminusqty;
+    }
+
+    public String getPd_warehouselocation() {
+        return pd_warehouselocation;
+    }
+
+    public void setPd_warehouselocation(String pd_warehouselocation) {
+        this.pd_warehouselocation = pd_warehouselocation;
+    }
+
+    public String getPd_version() {
+        return pd_version;
+    }
+
+    public void setPd_version(String pd_version) {
+        this.pd_version = pd_version;
+    }
+}

+ 105 - 15
src/com/uas/main/CsvParse.java

@@ -1,30 +1,22 @@
 package com.uas.main;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.Reader;
+import java.io.*;
 import java.sql.Connection;
+import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
+import java.sql.Statement;
+import java.util.*;
 
+import com.alibaba.fastjson.JSON;
+import com.uas.entity.PosDetail;
 import org.apache.commons.csv.CSVFormat;
 import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVRecord;
-import org.apache.commons.net.ftp.FTPClient;
 
 import com.uas.util.BaseUtil;
-import com.uas.util.FtpUtil;
 import com.uas.util.JdbcUtil;
 import com.uas.util.PraseCsvUtil;
+import org.apache.commons.net.ftp.FTPClient;
 
 public class CsvParse{
 	
@@ -293,6 +285,7 @@ public class CsvParse{
 	
 	@SuppressWarnings({"unused" })
     public static void main(String[] args){
+		exportCsv("HK");
 		FTPClient client = null;
 		String filePath = "C:\\mendelson\\opensource\\as2\\messages\\Mantech\\inbox";
 		String backupPath = "C:\\mendelson\\opensource\\as2\\messages\\Mantech\\inbox_bak\\in\\";
@@ -381,4 +374,101 @@ public class CsvParse{
 			}
 		}
     }
+
+    public static void exportCsv(String sob){
+		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);
+				if (result){
+					statement.execute("update pos set pos_sendstatus='已上传' where pos_id="+posId);
+				}
+
+			}
+		} catch (SQLException e) {
+			e.printStackTrace();
+			if(statement!=null){
+				try {
+					statement.close();
+				} catch (SQLException e1) {
+					BaseUtil.getLogger().error(e1.toString());
+					e1.printStackTrace();
+				}
+				statement = null;
+			}
+			if (connect!=null) {
+				try {
+					connect.close();
+				} catch (SQLException e1) {
+					e1.printStackTrace();
+				}
+				connect =null;
+			}
+		}
+
+
+	}
+
+	public static Boolean getPOSData(Statement statement,int id){
+		Boolean result=false;
+		long time = System.currentTimeMillis();
+		String outPath ="D:\\"+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");
+			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");
+			List<String> propertys = new ArrayList<>();
+			while (rs.next()) {
+				propertys.add(rs.getString("dg_field"));
+			}
+			List<PosDetail> datas = new ArrayList<>();
+			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));
+					}
+					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);
+			}
+		}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;
+		}
+	}
  }

+ 67 - 4
src/com/uas/util/PraseCsvUtil.java

@@ -1,9 +1,7 @@
 package com.uas.util;
 
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.Reader;
+import java.io.*;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -78,4 +76,69 @@ public class PraseCsvUtil {
 		}
 		return value;
 	}
+
+	public static String listToString(List<String> list){
+		if(null ==list && list.size()<=0){
+			System.out.println("list内容为空!");
+			return null;
+		}else{
+			StringBuilder sb = new StringBuilder();
+			String resultString = "";
+
+			for(int i=0;i<list.size();i++){
+				if(i<list.size()-1){
+					sb.append(list.get(i));
+					sb.append(",");
+				}else{
+					sb.append(list.get(i));
+				}
+			}
+			resultString = sb.toString();
+			System.out.println("最后拼接的字符串结果:" + resultString);
+			return resultString;
+		}
+	}
+
+	public static <T> Boolean exportCsv(String out,String outPath,List<String> titles,List<String> propertys, List<T> list){
+		Boolean result=false;
+		try {
+			File file = new File(outPath);
+			//构建输出流,同时指定编码
+			OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(file), "gbk");
+			//csv文件是逗号分隔,除第一个外,每次写入一个单元格数据后需要输入逗号
+			ow.write(out);
+			ow.write("\r\n");
+			for(String title : titles){
+				ow.write(title);
+				ow.write(",");
+			}
+			//写完文件头后换行
+			ow.write("\r\n");
+			//写内容
+			for(Object obj : list){
+				//利用反射获取所有字段
+				Field[] fields = obj.getClass().getDeclaredFields();
+				for(String property : propertys){
+					for(Field field : fields){
+						//设置字段可见性
+						field.setAccessible(true);
+						if(property.equals(field.getName())){
+							String s = field.get(obj) == null ? "" : field.get(obj).toString().replace(",","");
+							ow.write(s);
+							ow.write(",");
+							continue;
+						}
+					}
+				}
+				//写完一行换行
+				ow.write("\r\n");
+			}
+			ow.flush();
+			ow.close();
+			result=true;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return result;
+	}
 }

+ 0 - 49
src/properties/ftpconfig.properties.r22716

@@ -1,49 +0,0 @@
-{
-	"local":{
-		"ip":"192.168.253.97",
-		"port":21,
-		"user":"luhg",
-		"password":"342521",
-		"downloadpath":"TEST"
-	},
-	"1":{
-		"ip":"ftp.eascs.com",
-		"port":21,
-		"user":"hi-mantech",
-		"password":"Ders8744",
-		"downloadpath":"HND_RECWMSRELS_2",
-		"in":"HND_WMSRECV",
-		"out":"HND_WMSRELS",
-		"remark":"怡亚通"
-	},
-	"2":{
-		"ip":"sz.hi-mantech.com",
-		"port":46688,
-		"user":"user",
-		"password":"user_123456",
-		"downloadpath":"WMSANS",
-		"in":"WMSRECV",
-		"out":"WMSRELS",
-		"remark":"上海仓库"
-	},
-	"7":{
-		"ip":"112.74.205.182",
-		"port":21,
-		"user":"YHND02",
-		"password":"Yhnd*$@2017",
-		"downloadpath":"reply",
-		"in":"appointment_in",
-		"out":"distribute_in",
-		"remark":"旗丰"
-	},
-	"2_old":{
-		"ip":"218.255.13.107",
-		"port":21,
-		"user":"mantech",
-		"password":"mantech",
-		"downloadpath":"WMSANS",
-		"in":"WMSRECV",
-		"out":"WMSRELS",
-		"remark":"上海WGQ"
-	}
-}

+ 1 - 0
yhnd_csv.iml

@@ -106,5 +106,6 @@
     <orderEntry type="library" name="commons-io-1.3.2" level="project" />
     <orderEntry type="library" name="commons-io-2.4" level="project" />
     <orderEntry type="library" name="commons-csv-1.4" level="project" />
+    <orderEntry type="library" name="fastjson-1.2.73" level="project" />
   </component>
 </module>