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 invoiceVerificationList; public static OCRResultKingDee parseOne(String result) throws Exception { OCRResultKingDee ocrResultKingDee = new OCRResultKingDee(); JSONArray jsonArray = new JSONArray(); List invoiceVerificationList = new ArrayList(); 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 invoiceVerificationList = new ArrayList(); 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 getInvoiceVerificationList() { return invoiceVerificationList; } public void setInvoiceVerificationList(List invoiceVerificationList) { this.invoiceVerificationList = invoiceVerificationList; } }