P15GEN2\59518
2024-05-29 d4210c7c4b04abde20037ea8aa0f54ef8a2649aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package foundation.ai.logic;
 
import java.util.ArrayList;
import java.util.List;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
 
import foundation.ai.dao.InvoiceStatus;
import foundation.ai.dao.InvoiceVerificationDao;
import foundation.util.Util;
 
public class OCRResultKingDee {
    private boolean isSuccess;
    private String errcode;
    private String description;
    private String traceId;
    private JSONArray data;
    private List<InvoiceVerificationDao> invoiceVerificationList;
    
    public static OCRResultKingDee parseOne(String result) throws Exception {
        OCRResultKingDee ocrResultKingDee = new OCRResultKingDee();
        JSONArray jsonArray = new JSONArray();
        List<InvoiceVerificationDao> invoiceVerificationList = new ArrayList<InvoiceVerificationDao>();
        InvoiceVerificationDao invoiceVerification = new InvoiceVerificationDao(InvoiceStatus.notKnow);
        
        if(Util.isEmpty(result)) {
            ocrResultKingDee.setSuccess(false);
            return ocrResultKingDee;
        }
        
        JSONObject resultJson = JSONObject.parseObject(result);        
        
        JSONObject jsonObject = resultJson.getJSONObject("data");
        jsonArray.add(jsonObject);
        ocrResultKingDee.setData(jsonArray);
        
        if(jsonObject != null ) {            
            invoiceVerification.parse(jsonObject);            
        }
        
        if("0000".equalsIgnoreCase(resultJson.getString("errcode")) ) {
            ocrResultKingDee.setSuccess(true);
            invoiceVerification.setBill(true);
        }else {
            ocrResultKingDee.setSuccess(false);
            invoiceVerification.setBill(false);
            invoiceVerification.setReal(false);
        }
        
        invoiceVerificationList.add(invoiceVerification);    
        ocrResultKingDee.setInvoiceVerificationList(invoiceVerificationList);
        
        ocrResultKingDee.setErrcode(resultJson.getString("errcode"));
        ocrResultKingDee.setDescription(resultJson.getString("description"));
        ocrResultKingDee.setTraceId(resultJson.getString(resultJson.getString("traceId")));
        
        return ocrResultKingDee;
    }
    
    public static OCRResultKingDee parseBatch(String result) throws Exception {
        OCRResultKingDee ocrResultKingDee = new OCRResultKingDee();
        JSONArray jsonArray = new JSONArray();
        List<InvoiceVerificationDao> invoiceVerificationList = new ArrayList<InvoiceVerificationDao>();
        InvoiceVerificationDao invoiceVerification = new InvoiceVerificationDao(InvoiceStatus.notKnow);
        
        if(Util.isEmpty(result)) {
            ocrResultKingDee.setSuccess(false);
            return ocrResultKingDee;
        }
        
        JSONObject resultJson = JSONObject.parseObject(result);
        
        if("0000".equalsIgnoreCase(resultJson.getString("errcode")) ) {
            ocrResultKingDee.setSuccess(true);
        }else {
            ocrResultKingDee.setSuccess(false);
        }
                
        jsonArray = resultJson.getJSONArray("data");        
        ocrResultKingDee.setData(jsonArray);
                
        if(jsonArray.size() > 0 ) {
            for (int index = 0; index < jsonArray.size(); index++) {
                invoiceVerification.parse(jsonArray.getJSONObject(index));
                invoiceVerificationList.add(invoiceVerification);
            }
        }            
 
        ocrResultKingDee.setErrcode(resultJson.getString("errcode"));
        ocrResultKingDee.setDescription(resultJson.getString("description"));
        ocrResultKingDee.setTraceId(resultJson.getString(resultJson.getString("traceId")));
        ocrResultKingDee.setInvoiceVerificationList(invoiceVerificationList);
        return ocrResultKingDee;
    }
 
    public String getErrcode() {
        return errcode;
    }
 
    public void setErrcode(String errcode) {
        this.errcode = errcode;
    }
 
    public boolean isSuccess() {
        return isSuccess;
    }
 
    public void setSuccess(boolean isSuccess) {
        this.isSuccess = isSuccess;
    }
 
    public String getDescription() {
        return description;
    }
 
    public void setDescription(String description) {
        this.description = description;
    }
 
    public String getTraceId() {
        return traceId;
    }
 
    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }
 
    public JSONArray getData() {
        return data;
    }
 
    public void setData(JSONArray data) {
        this.data = data;
    }
 
    public List<InvoiceVerificationDao> getInvoiceVerificationList() {
        return invoiceVerificationList;
    }
 
    public void setInvoiceVerificationList(List<InvoiceVerificationDao> invoiceVerificationList) {
        this.invoiceVerificationList = invoiceVerificationList;
    }
    
    
 
}