|
@@ -1,30 +1,22 @@
|
|
|
package com.uas.main;
|
|
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.Connection;
|
|
|
|
|
+import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
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.CSVFormat;
|
|
|
import org.apache.commons.csv.CSVParser;
|
|
import org.apache.commons.csv.CSVParser;
|
|
|
import org.apache.commons.csv.CSVRecord;
|
|
import org.apache.commons.csv.CSVRecord;
|
|
|
-import org.apache.commons.net.ftp.FTPClient;
|
|
|
|
|
|
|
|
|
|
import com.uas.util.BaseUtil;
|
|
import com.uas.util.BaseUtil;
|
|
|
-import com.uas.util.FtpUtil;
|
|
|
|
|
import com.uas.util.JdbcUtil;
|
|
import com.uas.util.JdbcUtil;
|
|
|
import com.uas.util.PraseCsvUtil;
|
|
import com.uas.util.PraseCsvUtil;
|
|
|
|
|
+import org.apache.commons.net.ftp.FTPClient;
|
|
|
|
|
|
|
|
public class CsvParse{
|
|
public class CsvParse{
|
|
|
|
|
|
|
@@ -293,6 +285,7 @@ public class CsvParse{
|
|
|
|
|
|
|
|
@SuppressWarnings({"unused" })
|
|
@SuppressWarnings({"unused" })
|
|
|
public static void main(String[] args){
|
|
public static void main(String[] args){
|
|
|
|
|
+ exportCsv("HK");
|
|
|
FTPClient client = null;
|
|
FTPClient client = null;
|
|
|
String filePath = "C:\\mendelson\\opensource\\as2\\messages\\Mantech\\inbox";
|
|
String filePath = "C:\\mendelson\\opensource\\as2\\messages\\Mantech\\inbox";
|
|
|
String backupPath = "C:\\mendelson\\opensource\\as2\\messages\\Mantech\\inbox_bak\\in\\";
|
|
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;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|