|
@@ -5,7 +5,11 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import javassist.Loader;
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
import kd.bos.script.annotations.KSObject;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
@@ -15,6 +19,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
@@ -29,7 +34,7 @@ import java.util.Iterator;
|
|
|
@KSObject
|
|
|
public class ApiHttpUtils {
|
|
|
|
|
|
- public static String Posthttp(String url, String Params) throws Exception {
|
|
|
+ public static String Posthttp(String url, String Params){
|
|
|
// 获得Http客户端
|
|
|
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
// 创建Post请求
|
|
@@ -65,20 +70,38 @@ public class ApiHttpUtils {
|
|
|
StringEntity entity = new StringEntity(object.toString(), ContentType.APPLICATION_JSON);
|
|
|
httpPost.setEntity(entity);
|
|
|
// 响应模型(发送post请求)
|
|
|
- CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
+ try {
|
|
|
+ response = httpClient.execute(httpPost);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
// 从响应模型中获取响应实体
|
|
|
HttpEntity responseEntity = response.getEntity();
|
|
|
- com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
if (responseEntity != null) {
|
|
|
- jsonObject = JSON.parseObject(EntityUtils.toString(response.getEntity()));
|
|
|
- return jsonObject.toJSONString();
|
|
|
+ try {
|
|
|
+ jsonObject = JSON.parseObject(EntityUtils.toString(response.getEntity()));
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONObject("boby").getJSONArray("object_list");
|
|
|
+ return jsonArray.toJSONString();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
// 释放资源
|
|
|
if (httpClient != null) {
|
|
|
- httpClient.close();
|
|
|
+ try {
|
|
|
+ httpClient.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
if (response != null) {
|
|
|
- response.close();
|
|
|
+ try {
|
|
|
+ response.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
@@ -111,6 +134,14 @@ public class ApiHttpUtils {
|
|
|
return null;
|
|
|
}
|
|
|
public static String toFiledata(String Params) throws Exception {
|
|
|
+ //组装发票数据结构 !
|
|
|
+ JSONObject json = new JSONObject();//返回最外层json
|
|
|
+ json.put("errcode","0000");
|
|
|
+ json.put("traceId","");
|
|
|
+ json.put("description","操作成功");
|
|
|
+ JSONObject data = new JSONObject();//数据层json
|
|
|
+ json.put("batchNo","");
|
|
|
+ JSONArray recoginitionData = new JSONArray();//数据层数组
|
|
|
if("".equals(Params)){return null;};
|
|
|
JSONArray objects = JSONArray.parseArray(Params);
|
|
|
for(int a=0;a<objects.size();a++){
|
|
@@ -127,95 +158,32 @@ public class ApiHttpUtils {
|
|
|
String value = respenjsons.get("value").toString();// 获得value
|
|
|
item_list.put(key,value);
|
|
|
}
|
|
|
- if("增值税电子普通发票".equals(type_description)){
|
|
|
- String zzsdzptfp = zzsdzptfp(item_list);
|
|
|
- return zzsdzptfp;
|
|
|
- }else if("行程单".equals(type_description)){
|
|
|
- String jpxcd = jpxcd(item_list);
|
|
|
- return jpxcd;
|
|
|
- } else if ("火车票".equals(type_description)) {
|
|
|
- String hcp = hcp(item_list);
|
|
|
- return hcp;
|
|
|
- } else if ("通用定额发票".equals(type_description)) {
|
|
|
- String tydefp = tydefp(item_list);
|
|
|
- return tydefp;
|
|
|
- }
|
|
|
+ QFilter nckd_File = new QFilter("nckd_filetype", QCP.equals, type_description);
|
|
|
+ DynamicObject nckd_FileData = BusinessDataServiceHelper.loadSingle("nckd_filedataconvert", "id,nckd_filetype", new QFilter[]{nckd_File});
|
|
|
+ JSONObject Filedata = FileData(nckd_FileData,item_list);
|
|
|
+ recoginitionData.add(Filedata);
|
|
|
}
|
|
|
-
|
|
|
- return null;
|
|
|
+ data.put("recoginitionData",recoginitionData);
|
|
|
+ json.put("data",data);
|
|
|
+ return json.toString();
|
|
|
}
|
|
|
|
|
|
//增值税电子普通发票
|
|
|
- public static String zzsdzptfp(JSONObject item_list) throws Exception {
|
|
|
- //组装发票数据结构 !
|
|
|
- JSONObject json = new JSONObject();//返回最外层json
|
|
|
- json.put("errcode","0000");
|
|
|
- json.put("traceId","");
|
|
|
- json.put("description","操作成功");
|
|
|
- JSONObject data = new JSONObject();//数据层json
|
|
|
- json.put("batchNo","");
|
|
|
- JSONArray recoginitionData = new JSONArray();//数据层数组
|
|
|
+ public static JSONObject FileData(DynamicObject nckd_FileData,JSONObject item_list) throws Exception {
|
|
|
JSONObject fileObj = new JSONObject();//实际数据json
|
|
|
- fileObj.put("canBeDeduction","");//0
|
|
|
- fileObj.put("salerName",item_list.getString("vat_invoice_seller_name"));//销售方名称 ocr字段:vat_invoice_seller_name
|
|
|
- fileObj.put("invoiceMoney",item_list.getString("vat_invoice_price_list"));//金额明细 ocr字段:vat_invoice_price_list
|
|
|
- fileObj.put("signStatus","");//0
|
|
|
- fileObj.put("downloadUrl","");//下载地址链接
|
|
|
- fileObj.put("fileHash","");//文件哈希值
|
|
|
- fileObj.put("invoiceAmount",item_list.getString("vat_invoice_total"));//合计金额 ocr字段:vat_invoice_total
|
|
|
- fileObj.put("localUrl","");//预览链接
|
|
|
- fileObj.put("deductionStatus",1);//扣除
|
|
|
- fileObj.put("salerTaxNo",item_list.getString("vat_invoice_seller_id_seal"));//纳税人识别号 ocr字段:vat_invoice_seller_id_seal
|
|
|
-
|
|
|
- fileObj.put("invoiceType",1);//发票类型 ocr字段:type 1="增值税发票"
|
|
|
-
|
|
|
- fileObj.put("invoiceNo",item_list.getString("vat_invoice_haoma_large_size"));//发票号码 ocr字段:vat_invoice_haoma_large_size
|
|
|
- fileObj.put("isRepeat",false);//是否重复
|
|
|
- fileObj.put("pixel","");//3962978 未知字段
|
|
|
- fileObj.put("oriImageSize","");//base64编码长度
|
|
|
- fileObj.put("pdfToImgSnapshotUrl","");//空
|
|
|
- fileObj.put("orientation","0");//0
|
|
|
- fileObj.put("batchNo",null);//null
|
|
|
- fileObj.put("clientId","Vfz636yVhmk9HEu1QTAp");//客户端id
|
|
|
- fileObj.put("buyerTaxNo",item_list.getString("vat_invoice_rate_payer_id"));//购买方纳税人识别号 ocr字段:vat_invoice_rate_payer_id
|
|
|
- fileObj.put("warningCode","");//警告数量
|
|
|
- fileObj.put("originalState",0);//原始状态0
|
|
|
- fileObj.put("companySeal","1");//未知字段
|
|
|
- fileObj.put("originalUrl","");//地址链接
|
|
|
- fileObj.put("invoiceDate",item_list.getString("vat_invoice_issue_date"));//开票日期 ocr字段:vat_invoice_issue_date
|
|
|
- fileObj.put("buyerName",item_list.getString("vat_invoice_payer_name"));//购买方名称 ocr字段:vat_invoice_payer_name
|
|
|
- fileObj.put("invoiceCode",item_list.getString("vat_invoice_daima"));//发票代码 ocr字段: vat_invoice_daima
|
|
|
- fileObj.put("serialNo","");//未知字段
|
|
|
- fileObj.put("totalAmount",item_list.getString("vat_invoice_total_cover_tax_digits"));//价税合计 ocr字段: vat_invoice_total_cover_tax_digits
|
|
|
- fileObj.put("taxRate",item_list.getString("vat_invoice_tax_rate"));//税率 ocr字段 vat_invoice_tax_rate
|
|
|
- fileObj.put("oriOrientation","0");//未知字段
|
|
|
- fileObj.put("oriRegion","");//什么地区....
|
|
|
- fileObj.put("rotationAngle","0");//未知字段
|
|
|
- fileObj.put("snapshotUrl","");//图片地址
|
|
|
- fileObj.put("imageSerialNo","");//图片编码?
|
|
|
- fileObj.put("recognitionSerialNo","");//未知字段
|
|
|
- fileObj.put("totalTaxAmount",item_list.getString("vat_invoice_tax_total"));//税额合计 ocr字段 vat_invoice_tax_total
|
|
|
- fileObj.put("taxAmount",item_list.getString("vat_invoice_tax_list"));//税额 ocr字段 vat_invoice_tax_list
|
|
|
- fileObj.put("region","");//未知字段
|
|
|
- fileObj.put("isExpend","");//""
|
|
|
- fileObj.put("expendStatus",null);//null
|
|
|
- fileObj.put("fileType",1);//附件类型
|
|
|
- JSONArray items = new JSONArray();//数据明细层数组
|
|
|
- JSONObject mxFileObj = new JSONObject();//明细数据json
|
|
|
- mxFileObj.put("unitPrice",item_list.getString("vat_invoice_total"));//合计金额 oct字段: vat_invoice_total
|
|
|
- mxFileObj.put("taxRate",item_list.getString("vat_invoice_tax_rate_list"));//税率明细 vat_invoice_tax_rate_list
|
|
|
- mxFileObj.put("unit","");
|
|
|
- mxFileObj.put("num","1");
|
|
|
- mxFileObj.put("detailAmount",item_list.getString("vat_invoice_price_list"));//金额明细 ocr字段:vat_invoice_price_list
|
|
|
- mxFileObj.put("taxAmount",item_list.getString("vat_invoice_tax_list"));//税额明细 ocr字段 vat_invoice_tax_list
|
|
|
- mxFileObj.put("goodsName",item_list.getString("vat_invoice_goods_list"));//服务名称/项目名称 ocr字段 vat_invoice_goods_list
|
|
|
- //值拼接完成后开始set数据结构
|
|
|
- items.add(mxFileObj);
|
|
|
- fileObj.put("items",items);
|
|
|
- recoginitionData.add(fileObj);
|
|
|
- data.put("recoginitionData",recoginitionData);
|
|
|
- json.put("data",data);
|
|
|
- return json.toJSONString();
|
|
|
+ for (DynamicObject entryentity : nckd_FileData.getDynamicObjectCollection("nckd_treeentryentity")) {
|
|
|
+ String nckd_keingde = entryentity.getString("nckd_keingde");
|
|
|
+ String nckd_ocr = entryentity.getString("nckd_ocr");
|
|
|
+ String nckd_acquiesce = entryentity.getString("nckd_acquiesce");
|
|
|
+ if(!"".equals(nckd_ocr) && nckd_ocr!=null){
|
|
|
+ fileObj.put(nckd_keingde,item_list.getString(nckd_ocr));
|
|
|
+ }else if(!"".equals(nckd_acquiesce) && nckd_ocr!=null){
|
|
|
+ fileObj.put(nckd_keingde,nckd_acquiesce);
|
|
|
+ }else {
|
|
|
+ fileObj.put(nckd_keingde,"");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fileObj;
|
|
|
}
|
|
|
//机票行程单
|
|
|
public static String jpxcd(JSONObject item_list) throws Exception {
|