|
|
@@ -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;
|
|
|
- }
|
|
|
- }
|
|
|
}
|