307 lines
8.6 KiB
Java
307 lines
8.6 KiB
Java
package com.tenwa.invoice;
|
||
|
||
import java.rmi.RemoteException;
|
||
import java.sql.Connection;
|
||
import java.sql.PreparedStatement;
|
||
import java.sql.SQLException;
|
||
import java.util.ArrayList;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.Map.Entry;
|
||
|
||
import javax.xml.rpc.ServiceException;
|
||
|
||
import org.dom4j.Document;
|
||
import org.dom4j.Element;
|
||
|
||
import com.alibaba.fastjson.JSON;
|
||
import com.alibaba.fastjson.JSONArray;
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.amarsoft.are.ARE;
|
||
import com.amarsoft.are.jbo.JBOTransaction;
|
||
import com.amarsoft.are.util.StringFunction;
|
||
import com.amarsoft.awe.util.SqlObject;
|
||
import com.amarsoft.awe.util.Transaction;
|
||
import com.amarsoft.dict.als.cache.CacheLoaderFactory;
|
||
|
||
public class IAutokpDo {
|
||
//参数
|
||
private String invoiceParam;
|
||
//00=专票;02=普票
|
||
private String fpzl;
|
||
//00为正票;01为负票
|
||
private String fpzf;
|
||
private String sid;
|
||
private String fpdm;
|
||
private String fphm;
|
||
|
||
public String invoice() {
|
||
|
||
String invoiceParam = this.invoiceParam.replaceAll("@", ",");
|
||
String requestParam = "";
|
||
Document doc;
|
||
IAutokpXML ivoiceXML = new IAutokpXML();
|
||
//根据合同号进行分组
|
||
Map<String,List<Map<String,String>>> map = ivoiceXML.getParam(invoiceParam,fpzf);
|
||
for(Map.Entry<String, List<Map<String, String>>> lsm: map.entrySet()){
|
||
String contract_no=lsm.getKey();
|
||
String responseParam="";
|
||
doc = ivoiceXML.createInvoiceXML(lsm,fpzl,fpzf);
|
||
requestParam = doc.asXML();
|
||
try {
|
||
if(!requestParam.startsWith("error")&&requestParam!=null&&!"".equals(requestParam)){
|
||
IAutokpUtils.saveFile(requestParam, contract_no);
|
||
IAutokpserviceLocator kpl = new IAutokpserviceLocator();
|
||
IAutokp autoKP = kpl.getIAutokpPort();
|
||
responseParam = autoKP.invoice(requestParam);
|
||
System.out.println("返回结果:"+responseParam);
|
||
}
|
||
|
||
} catch (RemoteException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
} catch (ServiceException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
|
||
//开票成功
|
||
if(!"".endsWith(responseParam)){
|
||
IAutokpUtils.saveFile(responseParam, contract_no+"_rnt");
|
||
Map<String,String> responseResult = IAutokpUtils.getResponseResult(responseParam);
|
||
if("4011".equals(responseResult.get("fl"))){
|
||
insertInvoiceTable(lsm,contract_no,doc,responseResult);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
* 发票打印
|
||
* @return
|
||
*/
|
||
public String invoice_pr(){
|
||
String requestParam="";
|
||
String responseParam="";
|
||
String SID = "Invoice_getfph";
|
||
IAutokpXML ivoiceXML = new IAutokpXML();
|
||
try {
|
||
IAutokpserviceLocator kpl = new IAutokpserviceLocator();
|
||
IAutokp autoKP = kpl.getIAutokpPort();
|
||
responseParam = autoKP.invoice_pr(requestParam);
|
||
} catch (ServiceException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
} catch (RemoteException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
|
||
return null;
|
||
}
|
||
/**
|
||
* 发票作废
|
||
* @return
|
||
*/
|
||
public String invoice_fpzf(){
|
||
String requestParam="";
|
||
String responseParam="";
|
||
String sid = "Invoice_getfph";
|
||
IAutokpXML ivoiceXML = new IAutokpXML();
|
||
requestParam = ivoiceXML.createInvoiceOthersXML(sid,fpzl,fpdm,fphm);
|
||
try {
|
||
IAutokpserviceLocator kpl = new IAutokpserviceLocator();
|
||
IAutokp autoKP = kpl.getIAutokpPort();
|
||
responseParam = autoKP.invoice_fpzf(requestParam);
|
||
} catch (ServiceException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
} catch (RemoteException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
if(!"".endsWith(responseParam)){
|
||
IAutokpUtils.saveFile(responseParam, fpdm+"-"+fphm+"_rnt");
|
||
Map<String,String> responseResult = IAutokpUtils.getResponseResult(responseParam);
|
||
if("6011".equals(responseResult.get("fl"))){
|
||
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
/**
|
||
* 获取待开发票号
|
||
* @return
|
||
*/
|
||
public String getfph(){
|
||
String requestParam="";
|
||
String responseParam="";
|
||
String SID = "Invoice_getfph";
|
||
try {
|
||
IAutokpserviceLocator kpl = new IAutokpserviceLocator();
|
||
IAutokp autoKP = kpl.getIAutokpPort();
|
||
responseParam = autoKP.getfph(requestParam);
|
||
} catch (ServiceException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
} catch (RemoteException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
|
||
return null;
|
||
}
|
||
/**
|
||
* 发票清单打印
|
||
* @return
|
||
*/
|
||
public String invoice_qdpr(){
|
||
String requestParam="";
|
||
String responseParam="";
|
||
String SID = "Invoice_qdpr";
|
||
try {
|
||
IAutokpserviceLocator kpl = new IAutokpserviceLocator();
|
||
IAutokp autoKP = kpl.getIAutokpPort();
|
||
responseParam = autoKP.invoice_qdpr(requestParam);
|
||
} catch (ServiceException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
} catch (RemoteException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
|
||
return null;
|
||
}
|
||
public String getFpzl() {
|
||
return fpzl;
|
||
}
|
||
public void setFpzl(String fpzl) {
|
||
this.fpzl = fpzl;
|
||
}
|
||
public String getFpzf() {
|
||
return fpzf;
|
||
}
|
||
public void setFpzf(String fpzf) {
|
||
this.fpzf = fpzf;
|
||
}
|
||
public String getInvoiceParam() {
|
||
return invoiceParam;
|
||
}
|
||
public void setInvoiceParam(String invoiceParam) {
|
||
this.invoiceParam = invoiceParam;
|
||
}
|
||
public String getFpdm() {
|
||
return fpdm;
|
||
}
|
||
public void setFpdm(String fpdm) {
|
||
this.fpdm = fpdm;
|
||
}
|
||
public String getFphm() {
|
||
return fphm;
|
||
}
|
||
public void setFphm(String fphm) {
|
||
this.fphm = fphm;
|
||
}
|
||
public String getSid() {
|
||
return sid;
|
||
}
|
||
|
||
public void setSid(String sid) {
|
||
this.sid = sid;
|
||
}
|
||
public void insertInvoiceTable(Map.Entry<String, List<Map<String, String>>> lsm,String contractNo,Document doc,Map<String,String> responseResult){
|
||
String insertSql = "insert into li_invoice_tj_info(id,contract_no,plan_list,fpzl,fpzf,invoice_money,tax_type,tax_ratio,tax_money,sw_spbm,fpdm,fphm,hztzdh,status,inputuserid,inputtime)values"
|
||
+"(REPLACE(UUID(),'-',''),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||
PreparedStatement ps = null;
|
||
Transaction Sqlca = null;
|
||
Sqlca = Transaction.createTransaction(CacheLoaderFactory.getDataSource());
|
||
Connection con;
|
||
try {
|
||
con = Sqlca.getConnection();
|
||
boolean autoCom = con.getAutoCommit();
|
||
if(autoCom){
|
||
con.setAutoCommit(false);
|
||
}
|
||
ps = con.prepareStatement(insertSql);
|
||
Element ele_order = doc.getRootElement().element("DataArea").element("Data").element("Order");
|
||
Element ele_head = ele_order.element("Head");
|
||
Element ele_items = ele_order.element("Items");
|
||
String hztzdh = "N";
|
||
String status = "Y";
|
||
String fpdm = responseResult.get("fpdm");
|
||
String fphm = responseResult.get("fphm");
|
||
if("01".equals(fpzf)){
|
||
status = "R";
|
||
fpdm = ele_head.element("HCFPDM").getText();
|
||
fphm = ele_head.element("HCFPHM").getText();
|
||
hztzdh = ele_head.element("HZTZDH").getText();
|
||
}
|
||
List<Element> listItems = ele_items.elements();
|
||
for(Element item : listItems){
|
||
String mxxh = item.element("MXXH").getText();
|
||
String planList = "";
|
||
for(Map<String,String> map :lsm.getValue()){
|
||
if(mxxh.equals(map.get("MXXH"))){
|
||
planList = map.get("planList");
|
||
break;
|
||
}
|
||
}
|
||
|
||
String invoice_money = item.element("JE").getText();
|
||
String taxType = item.element("GGXH").getText();
|
||
String taxRatio = item.element("SLV").getText();
|
||
String taxMoney = item.element("shuier").getText();
|
||
String sw_spbm = item.element("sw_spbm").getText();
|
||
String inputuserid = "system";
|
||
String inputtime = StringFunction.getNow();
|
||
|
||
ps.setString(1,contractNo);
|
||
ps.setString(2,planList);
|
||
ps.setString(3,fpzl);
|
||
ps.setString(4,fpzf);
|
||
ps.setString(5,invoice_money);
|
||
ps.setString(6,taxType);
|
||
ps.setString(7,taxRatio);
|
||
ps.setString(8,taxMoney);
|
||
ps.setString(9,sw_spbm);
|
||
ps.setString(10,fpdm);
|
||
ps.setString(11,fphm);
|
||
ps.setString(12,hztzdh);
|
||
ps.setString(13,status);
|
||
ps.setString(14,inputuserid);
|
||
ps.setString(15,inputtime);
|
||
ps.addBatch();
|
||
}
|
||
ps.executeBatch();
|
||
con.commit();
|
||
con.setAutoCommit(autoCom);
|
||
ps.close();
|
||
ps = null;
|
||
System.out.println("==========开票完毕==========");
|
||
} catch (SQLException e) {
|
||
ARE.getLog().debug("插入天津发票信息表:"+contractNo+"出错,出错消息"+e.getMessage(),e);
|
||
e.printStackTrace();
|
||
}finally{
|
||
if(ps != null){
|
||
try {
|
||
ps.close();
|
||
ps = null;
|
||
} catch (SQLException e) {
|
||
ARE.getLog().debug("数据库关闭异常:" + e);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
}
|