diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/invoice/InvoiceUseService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/invoice/InvoiceUseService.java index 9d896c0..dd9101e 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/invoice/InvoiceUseService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/invoice/InvoiceUseService.java @@ -10,7 +10,9 @@ import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class InvoiceUseService { private static Log log = Log.getLog(InvoiceUseService.class); @@ -131,44 +133,49 @@ public class InvoiceUseService { paramord.add(invoice_type); } + if (order_state != null) { + logsql += " and o.state = ? \n"; + ordsql += " and t.state = ? \n"; + paramlog.add(order_state); + paramord.add(order_state); + } + List list = new ArrayList<>(); - if (order_state != null) { - if (order_state == 9) { - logsql += " and o.state = ? \n"; - paramlog.add(order_state); - + if (invoice_state != null) { + if (invoice_state == 9) { list = Db.find(logsql + " order by t.create_time", paramlog.toArray()); - } else { - logsql += " and o.state = ? \n"; - ordsql += " and t.state = ? \n"; - paramlog.add(order_state); - paramord.add(order_state); + } else if (invoice_state == 5) { + list = Db.find(ordsql + " order by t.create_time", paramord.toArray()); + } + } else { + paramlog.addAll(paramord); - if (invoice_state != null) { - if (invoice_state == 9) { - list = Db.find(logsql + " order by t.create_time", paramlog.toArray()); - } else if (invoice_state == 5) { - list = Db.find(ordsql + " order by t.create_time", paramord.toArray()); - } - } else { - paramlog.addAll(paramord); + List l1 = Db.find(logsql + " order by t.create_time", paramlog.toArray()); + List l2 = Db.find(ordsql + " order by t.create_time", paramord.toArray()); - list = Db.find("select * from (" + logsql + "\n union \n " + ordsql + ") a order by a.create_time ", paramlog.toArray()); + Map map1 = new HashMap<>(); + Map map2 = new HashMap<>(); + + for(Record record : l1){ + String key = record.getStr("order_sn") + "_" +record.getStr("invoice_number") + "_" +record.getStr("invoice_code"); + map1.put(key, record); + } + + for(Record record : l2){ + String key = record.getStr("order_sn") + "_" +record.getStr("invoice_number") + "_" +record.getStr("invoice_code"); + map2.put(key, record); + } + + for(Map.Entry entry : map2.entrySet()){ + if(map1.containsKey(entry.getKey())){ + map1.remove(entry.getKey()); // 从 map1 中移除相同的 } } - }else { - if (invoice_state != null) { - if (invoice_state == 9) { - list = Db.find(logsql + " order by t.create_time", paramlog.toArray()); - } else if (invoice_state == 5) { - list = Db.find(ordsql + " order by t.create_time", paramord.toArray()); - } - } else { - paramlog.addAll(paramord); - list = Db.find("select * from (" + logsql + "\n union \n " + ordsql + ") a order by a.create_time ", paramlog.toArray()); - } + map2.putAll(map1); // 剩下的不同的全部加到 map2 中 + + list = new ArrayList<>(map2.values()); } Record out = new Record();