|
|
@@ -0,0 +1,168 @@
|
|
|
+package me.zhengjie.modules.system.domain.order.parser.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.NoArgsConstructor;
|
|
|
+import me.zhengjie.modules.system.domain.order.BorrowerDomain;
|
|
|
+import me.zhengjie.modules.system.domain.order.GuaranteeDomain;
|
|
|
+import me.zhengjie.modules.system.domain.order.MortgageDomain;
|
|
|
+import me.zhengjie.modules.system.domain.order.parser.OrderOCRParser;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 邮政储蓄银行订单OCR解析器
|
|
|
+ */
|
|
|
+@NoArgsConstructor
|
|
|
+@Component
|
|
|
+public class YZBankOrderOCRParserImpl implements OrderOCRParser {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BorrowerDomain parseBorrower(String content) {
|
|
|
+ Map<String, String> map = toBorrowerMap(content);
|
|
|
+ BorrowerDomain borrower = new BorrowerDomain();
|
|
|
+ borrower.setContractNo(map.get("contractNo"));
|
|
|
+ borrower.setBirth(map.get("birth"));
|
|
|
+ borrower.setIdCard(map.get("idCard"));
|
|
|
+ borrower.setPhone(map.get("phone"));
|
|
|
+ borrower.setResidence(map.get("residence"));
|
|
|
+ borrower.setSex(map.get("sex"));
|
|
|
+ borrower.setSumMoney(map.get("sumMoney"));
|
|
|
+ borrower.setUsername(map.get("username"));
|
|
|
+ return borrower;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MortgageDomain parseMortgage(String content) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GuaranteeDomain parseGuarantee(String content) {
|
|
|
+ Map<String, String> map = toGuaranteeMap(content);
|
|
|
+ GuaranteeDomain guarantee = new GuaranteeDomain();
|
|
|
+ guarantee.setContractNo(map.get("contractNo"));
|
|
|
+ guarantee.setBirth(map.get("birth"));
|
|
|
+ guarantee.setIdCard(map.get("idCard"));
|
|
|
+ guarantee.setPhone(map.get("phone"));
|
|
|
+ guarantee.setResidence(map.get("residence"));
|
|
|
+ guarantee.setSex(map.get("sex"));
|
|
|
+ guarantee.setUsername(map.get("username"));
|
|
|
+ guarantee.setStartDate(map.get("startDate"));
|
|
|
+ guarantee.setEndDate(map.get("endDate"));
|
|
|
+ return guarantee;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析借款人合同字段
|
|
|
+ * @param content
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, String> toBorrowerMap(String content) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ JSONObject jsonObj = JSONObject.parseObject(content);
|
|
|
+ JSONArray structuralItems = jsonObj.getJSONArray("StructuralItems");
|
|
|
+ // 获取借款人信息起始定位
|
|
|
+ int borrowerStartIndex = 0;
|
|
|
+ for (Object obj : structuralItems) {
|
|
|
+ JSONObject json = (JSONObject) obj;
|
|
|
+ String key = json.getString("name");
|
|
|
+ if ("借款人(乙方)".equals(key)) {
|
|
|
+ JSONObject itemCoord = json.getJSONObject("itemCoord");
|
|
|
+ borrowerStartIndex = itemCoord.getInteger("Y");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 解析对应的值
|
|
|
+ try {
|
|
|
+ for (Object obj : structuralItems) {
|
|
|
+ JSONObject json = (JSONObject) obj;
|
|
|
+ String key = json.getString("name");
|
|
|
+ int currentIndex = json.getJSONObject("itemCoord").getInteger("Y");
|
|
|
+ if ("借款人(乙方)".equals(key)) {
|
|
|
+ map.put("username", json.getString("value"));
|
|
|
+ } else if ("证件号码".equals(key) && currentIndex > borrowerStartIndex) {
|
|
|
+ SimpleDateFormat daySrcFormatter = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ SimpleDateFormat dayDestFormatter = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
+ String idCard = json.getString("value");
|
|
|
+ String birth = dayDestFormatter.format(daySrcFormatter.parse(idCard.substring(6, 8)));
|
|
|
+ map.put("sex", String.valueOf(Integer.parseInt(idCard.substring(16, 1)) / 2));
|
|
|
+ map.put("birth", birth);
|
|
|
+ map.put("idCard", idCard);
|
|
|
+ } else if ("住所(地址)".equals(key) && currentIndex > borrowerStartIndex) {
|
|
|
+ map.put("residence", json.getString("value"));
|
|
|
+ } else if ("电话".equals("key") && currentIndex > borrowerStartIndex) {
|
|
|
+ map.put("phone", json.getString("value"));
|
|
|
+ } else if ("本合同为甲乙双方签订的编号为".equals(key)) {
|
|
|
+ map.put("contractNo", json.getString("value"));
|
|
|
+ } else if ("小写)".equals(key)) {
|
|
|
+ map.put("sumMoney", json.getString("value"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ //
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析担保人合同字段
|
|
|
+ * @param content
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, String> toGuaranteeMap(String content) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ JSONObject jsonObj = JSONObject.parseObject(content);
|
|
|
+ JSONArray structuralItems = jsonObj.getJSONArray("StructuralItems");
|
|
|
+ // 获取借款人信息起始定位
|
|
|
+ int guaranteeStartIndex = 0;
|
|
|
+ for (Object obj : structuralItems) {
|
|
|
+ JSONObject json = (JSONObject) obj;
|
|
|
+ String key = json.getString("name");
|
|
|
+ if ("保证人(乙方)".equals(key)) {
|
|
|
+ JSONObject itemCoord = json.getJSONObject("itemCoord");
|
|
|
+ guaranteeStartIndex = itemCoord.getInteger("Y");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 解析对应的值
|
|
|
+ try {
|
|
|
+ for (Object obj : structuralItems) {
|
|
|
+ JSONObject json = (JSONObject) obj;
|
|
|
+ String key = json.getString("name");
|
|
|
+ int currentIndex = json.getJSONObject("itemCoord").getInteger("Y");
|
|
|
+ if ("保证人(乙方)".equals(key)) {
|
|
|
+ map.put("username", json.getString("value"));
|
|
|
+ } else if ("证件号码".equals(key) && currentIndex > guaranteeStartIndex) {
|
|
|
+ SimpleDateFormat daySrcFormatter = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ SimpleDateFormat dayDestFormatter = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
+ String idCard = json.getString("value");
|
|
|
+ String birth = dayDestFormatter.format(daySrcFormatter.parse(idCard.substring(6, 8)));
|
|
|
+ map.put("sex", String.valueOf(Integer.parseInt(idCard.substring(16, 1)) / 2));
|
|
|
+ map.put("birth", birth);
|
|
|
+ map.put("idCard", idCard);
|
|
|
+ } else if ("住所(地址)".equals(key) && currentIndex > guaranteeStartIndex) {
|
|
|
+ map.put("residence", json.getString("value"));
|
|
|
+ } else if ("电话".equals("key") && currentIndex > guaranteeStartIndex) {
|
|
|
+ map.put("phone", json.getString("value"));
|
|
|
+ } else if (key.indexOf("签订的编号为") > -1) {
|
|
|
+ map.put("contractNo", json.getString("value"));
|
|
|
+ } else if (key.indexOf("担保债权确定的期间为") > -1) {
|
|
|
+ SimpleDateFormat daySrcFormatter = new SimpleDateFormat("yyyy年MM月dd日");
|
|
|
+ SimpleDateFormat dayDestFormatter = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
+ String duration[] = json.getString("value").replace("_", "").split("至");
|
|
|
+ String startDate = dayDestFormatter.format(daySrcFormatter.parse(duration[0]));
|
|
|
+ String endDate = dayDestFormatter.format(daySrcFormatter.parse(duration[1]));
|
|
|
+ map.put("startDate", startDate);
|
|
|
+ map.put("endDate", endDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ //
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+}
|