|
|
@@ -0,0 +1,297 @@
|
|
|
+package com.uas.search.console.util;
|
|
|
+
|
|
|
+import org.apache.log4j.Logger;
|
|
|
+import org.apache.lucene.document.Document;
|
|
|
+import org.apache.lucene.document.Field.Store;
|
|
|
+import org.apache.lucene.document.StringField;
|
|
|
+import org.apache.lucene.document.TextField;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import com.uas.search.console.model.OrderDetailSimpleInfo;
|
|
|
+import com.uas.search.console.model.OrderInvoiceDetailSimpleInfo;
|
|
|
+import com.uas.search.console.model.OrderInvoiceSimpleInfo;
|
|
|
+import com.uas.search.console.model.OrderSimpleInfo;
|
|
|
+import com.uas.search.console.model.PurchaseDetailSimpleInfo;
|
|
|
+import com.uas.search.console.model.PurchaseInvoiceDetailSimpleInfo;
|
|
|
+import com.uas.search.console.model.PurchaseInvoiceSimpleInfo;
|
|
|
+import com.uas.search.console.model.PurchaseSimpleInfo;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 将对象转换为Document的工具类
|
|
|
+ *
|
|
|
+ * @author sunyj
|
|
|
+ * @since 2016年10月17日 上午11:32:19
|
|
|
+ */
|
|
|
+public class ObjectToDocumentUtils {
|
|
|
+
|
|
|
+ private static Logger logger = Logger.getLogger(ObjectToDocumentUtils.class);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将对象转为Document
|
|
|
+ *
|
|
|
+ * @param object
|
|
|
+ * 对象,可为OrderSimpleInfo、OrderDetailSimpleInfo、
|
|
|
+ * OrderInvoiceSimpleInfo、OrderInvoiceDetailSimpleInfo、
|
|
|
+ * PurchaseSimpleInfo、PurchaseDetailSimpleInfo、
|
|
|
+ * PurchaseInvoiceSimpleInfo、PurchaseInvoiceDetailSimpleInfo
|
|
|
+ * @return 转换的Document
|
|
|
+ */
|
|
|
+ public static Document toDocument(Object object) {
|
|
|
+ if (object == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ logger.info(object);
|
|
|
+ if (object instanceof OrderSimpleInfo) {
|
|
|
+ return toDocument((OrderSimpleInfo) object);
|
|
|
+ } else if (object instanceof OrderDetailSimpleInfo) {
|
|
|
+ return toDocument((OrderDetailSimpleInfo) object);
|
|
|
+ } else if (object instanceof OrderInvoiceSimpleInfo) {
|
|
|
+ return toDocument((OrderInvoiceSimpleInfo) object);
|
|
|
+ } else if (object instanceof OrderInvoiceDetailSimpleInfo) {
|
|
|
+ return toDocument((OrderInvoiceDetailSimpleInfo) object);
|
|
|
+ } else if (object instanceof PurchaseSimpleInfo) {
|
|
|
+ return toDocument((PurchaseSimpleInfo) object);
|
|
|
+ } else if (object instanceof PurchaseDetailSimpleInfo) {
|
|
|
+ return toDocument((PurchaseDetailSimpleInfo) object);
|
|
|
+ } else if (object instanceof PurchaseInvoiceSimpleInfo) {
|
|
|
+ return toDocument((PurchaseInvoiceSimpleInfo) object);
|
|
|
+ } else if (object instanceof PurchaseInvoiceDetailSimpleInfo) {
|
|
|
+ return toDocument((PurchaseInvoiceDetailSimpleInfo) object);
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * OrderSimpleInfo对象转为Document
|
|
|
+ *
|
|
|
+ * @param order
|
|
|
+ * OrderSimpleInfo对象
|
|
|
+ * @return 转换的Document
|
|
|
+ */
|
|
|
+ public static Document toDocument(OrderSimpleInfo order) {
|
|
|
+ if (order == null || order.getId() == null || StringUtils.isEmpty(order.getCode()) || order.getBuyeruu() == null
|
|
|
+ || StringUtils.isEmpty(order.getBuyername()) || order.getBuyerEnterprise() == null
|
|
|
+ || order.getBuyerEnterprise().getUu() == null
|
|
|
+ || StringUtils.isEmpty(order.getBuyerEnterprise().getEnName()) || order.getSellerEnterprise() == null
|
|
|
+ || order.getSellerEnterprise().getUu() == null
|
|
|
+ || StringUtils.isEmpty(order.getSellerEnterprise().getEnName()) || order.getCreatetime() == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Document document = new Document();
|
|
|
+ document.add(new StringField(SearchConstants.ORDER_ID_FIELD, String.valueOf(order.getId()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_CODE_FIELD, order.getCode(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.ORDER_BUYERUSERUU_FIELD, String.valueOf(order.getBuyeruu()),
|
|
|
+ Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_BUYERUSERNAME_FIELD, order.getBuyername(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.ORDER_BUYERENUU_FIELD,
|
|
|
+ String.valueOf(order.getBuyerEnterprise().getUu()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_BUYERENNAME_FIELD, order.getBuyerEnterprise().getEnName(),
|
|
|
+ Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.ORDER_SELLERENUU_FIELD,
|
|
|
+ String.valueOf(order.getSellerEnterprise().getUu()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_SELLERENNAME_FIELD, order.getSellerEnterprise().getEnName(),
|
|
|
+ Store.YES));
|
|
|
+ document.add(
|
|
|
+ new StringField(SearchConstants.ORDER_CREATETIME_FIELD, order.getCreatetime().toString(), Store.YES));
|
|
|
+ return document;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * OrderDetailSimpleInfo对象转为Document
|
|
|
+ *
|
|
|
+ * @param orderDetail
|
|
|
+ * OrderDetailSimpleInfo对象
|
|
|
+ * @return 转换的Document
|
|
|
+ */
|
|
|
+ public static Document toDocument(OrderDetailSimpleInfo orderDetail) {
|
|
|
+ if (orderDetail == null || orderDetail.getId() == null || StringUtils.isEmpty(orderDetail.getCode())
|
|
|
+ || orderDetail.getOrderid() == null || StringUtils.isEmpty(orderDetail.getCmpCode())
|
|
|
+ || StringUtils.isEmpty(orderDetail.getKiName()) || StringUtils.isEmpty(orderDetail.getBrName())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Document document = new Document();
|
|
|
+ document.add(
|
|
|
+ new StringField(SearchConstants.ORDER_DETAIL_ID_FIELD, String.valueOf(orderDetail.getId()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_DETAIL_CODE_FIELD, orderDetail.getCode(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.ORDER_DETAIL_ORDERID_FIELD,
|
|
|
+ String.valueOf(orderDetail.getOrderid()), Store.YES));
|
|
|
+ document.add(
|
|
|
+ new TextField(SearchConstants.ORDER_DETAIL_COMPONENTCODE_FIELD, orderDetail.getCmpCode(), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_DETAIL_KINDNAME_FIELD, orderDetail.getKiName(), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_DETAIL_BRANDNAME_FIELD, orderDetail.getBrName(), Store.YES));
|
|
|
+ return document;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * OrderInvoiceSimpleInfo对象转为Document
|
|
|
+ *
|
|
|
+ * @param orderInvoice
|
|
|
+ * OrderInvoiceSimpleInfo对象
|
|
|
+ * @return 转换的Document
|
|
|
+ */
|
|
|
+ public static Document toDocument(OrderInvoiceSimpleInfo orderInvoice) {
|
|
|
+ if (orderInvoice == null || orderInvoice.getId() == null || StringUtils.isEmpty(orderInvoice.getCode())
|
|
|
+ || orderInvoice.getBuyeruu() == null || StringUtils.isEmpty(orderInvoice.getBuyername())
|
|
|
+ || orderInvoice.getBuyerEnterprise() == null || orderInvoice.getBuyerEnterprise().getUu() == null
|
|
|
+ || StringUtils.isEmpty(orderInvoice.getBuyerEnterprise().getEnName())
|
|
|
+ || orderInvoice.getCreatetime() == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Document document = new Document();
|
|
|
+ document.add(new StringField(SearchConstants.ORDER_INVOICE_ID_FIELD, String.valueOf(orderInvoice.getId()),
|
|
|
+ Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_INVOICE_CODE_FIELD, orderInvoice.getCode(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.ORDER_INVOICE_BUYERUSERUU_FIELD,
|
|
|
+ String.valueOf(orderInvoice.getBuyeruu()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_INVOICE_BUYERUSERNAME_FIELD, orderInvoice.getBuyername(),
|
|
|
+ Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.ORDER_INVOICE_BUYERENUU_FIELD,
|
|
|
+ String.valueOf(orderInvoice.getBuyerEnterprise().getUu()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_INVOICE_BUYERENNAME_FIELD,
|
|
|
+ orderInvoice.getBuyerEnterprise().getEnName(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.ORDER_INVOICE_CREATETIME_FIELD,
|
|
|
+ orderInvoice.getCreatetime().toString(), Store.YES));
|
|
|
+ return document;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * OrderInvoiceDetailSimpleInfo对象转为Document
|
|
|
+ *
|
|
|
+ * @param orderInvoiceDetail
|
|
|
+ * OrderInvoiceDetailSimpleInfo对象
|
|
|
+ * @return 转换的Document
|
|
|
+ */
|
|
|
+ public static Document toDocument(OrderInvoiceDetailSimpleInfo orderInvoiceDetail) {
|
|
|
+ if (orderInvoiceDetail == null || orderInvoiceDetail.getId() == null
|
|
|
+ || StringUtils.isEmpty(orderInvoiceDetail.getCode()) || orderInvoiceDetail.getInvoiceid() == null
|
|
|
+ || StringUtils.isEmpty(orderInvoiceDetail.getCmpCode())
|
|
|
+ || StringUtils.isEmpty(orderInvoiceDetail.getKiName())
|
|
|
+ || StringUtils.isEmpty(orderInvoiceDetail.getBrName())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Document document = new Document();
|
|
|
+ document.add(new StringField(SearchConstants.ORDER_INVOICE_DETAIL_ID_FIELD,
|
|
|
+ String.valueOf(orderInvoiceDetail.getId()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_INVOICE_DETAIL_CODE_FIELD, orderInvoiceDetail.getCode(),
|
|
|
+ Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.ORDER_INVOICE_DETAIL_INVOICEID_FIELD,
|
|
|
+ String.valueOf(orderInvoiceDetail.getInvoiceid()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_INVOICE_DETAIL_COMPONENTCODE_FIELD,
|
|
|
+ orderInvoiceDetail.getCmpCode(), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_INVOICE_DETAIL_KINDNAME_FIELD, orderInvoiceDetail.getKiName(),
|
|
|
+ Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.ORDER_INVOICE_DETAIL_BRANDNAME_FIELD, orderInvoiceDetail.getBrName(),
|
|
|
+ Store.YES));
|
|
|
+ return document;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * PurchaseSimpleInfo对象转为Document
|
|
|
+ *
|
|
|
+ * @param order
|
|
|
+ * PurchaseSimpleInfo对象
|
|
|
+ * @return 转换的Document
|
|
|
+ */
|
|
|
+ public static Document toDocument(PurchaseSimpleInfo purchase) {
|
|
|
+ if (purchase == null || purchase.getId() == null || StringUtils.isEmpty(purchase.getCode())
|
|
|
+ || purchase.getSellerenuu() == null || StringUtils.isEmpty(purchase.getSellerenname())
|
|
|
+ || purchase.getCreatetime() == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Document document = new Document();
|
|
|
+ document.add(new StringField(SearchConstants.PURCHASE_ID_FIELD, String.valueOf(purchase.getId()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.PURCHASE_CODE_FIELD, purchase.getCode(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.PURCHASE_SELLERENUU_FIELD,
|
|
|
+ String.valueOf(purchase.getSellerenuu()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.PURCHASE_SELLERENNAME_FIELD, purchase.getSellerenname(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.PURCHASE_CREATETIME_FIELD, purchase.getCreatetime().toString(),
|
|
|
+ Store.YES));
|
|
|
+ return document;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * PurchaseDetailSimpleInfo对象转为Document
|
|
|
+ *
|
|
|
+ * @param purchaseDetail
|
|
|
+ * PurchaseDetailSimpleInfo对象
|
|
|
+ * @return 转换的Document
|
|
|
+ */
|
|
|
+ public static Document toDocument(PurchaseDetailSimpleInfo purchaseDetail) {
|
|
|
+ if (purchaseDetail == null || purchaseDetail.getId() == null || StringUtils.isEmpty(purchaseDetail.getCode())
|
|
|
+ || purchaseDetail.getPurchaseid() == null || StringUtils.isEmpty(purchaseDetail.getCmpCode())
|
|
|
+ || StringUtils.isEmpty(purchaseDetail.getKiName()) || StringUtils.isEmpty(purchaseDetail.getBrName())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Document document = new Document();
|
|
|
+ document.add(new StringField(SearchConstants.PURCHASE_DETAIL_ID_FIELD, String.valueOf(purchaseDetail.getId()),
|
|
|
+ Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.PURCHASE_DETAIL_CODE_FIELD, purchaseDetail.getCode(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.PURCHASE_DETAIL_PURCHASEID_FIELD,
|
|
|
+ String.valueOf(purchaseDetail.getPurchaseid()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.PURCHASE_DETAIL_COMPONENTCODE_FIELD, purchaseDetail.getCmpCode(),
|
|
|
+ Store.YES));
|
|
|
+ document.add(
|
|
|
+ new TextField(SearchConstants.PURCHASE_DETAIL_KINDNAME_FIELD, purchaseDetail.getKiName(), Store.YES));
|
|
|
+ document.add(
|
|
|
+ new TextField(SearchConstants.PURCHASE_DETAIL_BRANDNAME_FIELD, purchaseDetail.getBrName(), Store.YES));
|
|
|
+ return document;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * PurchaseInvoiceSimpleInfo对象转为Document
|
|
|
+ *
|
|
|
+ * @param purchaseInvoice
|
|
|
+ * PurchaseInvoiceSimpleInfo对象
|
|
|
+ * @return 转换的Document
|
|
|
+ */
|
|
|
+ public static Document toDocument(PurchaseInvoiceSimpleInfo purchaseInvoice) {
|
|
|
+ if (purchaseInvoice == null || purchaseInvoice.getId() == null || StringUtils.isEmpty(purchaseInvoice.getCode())
|
|
|
+ || purchaseInvoice.getSellerenuu() == null || StringUtils.isEmpty(purchaseInvoice.getSellerenname())
|
|
|
+ || purchaseInvoice.getCreatetime() == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Document document = new Document();
|
|
|
+ document.add(new StringField(SearchConstants.PURCHASE_INVOICE_ID_FIELD, String.valueOf(purchaseInvoice.getId()),
|
|
|
+ Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.PURCHASE_INVOICE_CODE_FIELD, purchaseInvoice.getCode(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.PURCHASE_INVOICE_SELLERENUU_FIELD,
|
|
|
+ String.valueOf(purchaseInvoice.getSellerenuu()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.PURCHASE_INVOICE_SELLERENNAME_FIELD,
|
|
|
+ purchaseInvoice.getSellerenname(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.PURCHASE_INVOICE_CREATETIME_FIELD,
|
|
|
+ purchaseInvoice.getCreatetime().toString(), Store.YES));
|
|
|
+ return document;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * PurchaseInvoiceDetailSimpleInfo对象转为Document
|
|
|
+ *
|
|
|
+ * @param purchaseInvoiceDetail
|
|
|
+ * PurchaseInvoiceDetailSimpleInfo对象
|
|
|
+ * @return 转换的Document
|
|
|
+ */
|
|
|
+ public static Document toDocument(PurchaseInvoiceDetailSimpleInfo purchaseInvoiceDetail) {
|
|
|
+ if (purchaseInvoiceDetail == null || purchaseInvoiceDetail.getId() == null
|
|
|
+ || StringUtils.isEmpty(purchaseInvoiceDetail.getCode()) || purchaseInvoiceDetail.getInvoiceid() == null
|
|
|
+ || StringUtils.isEmpty(purchaseInvoiceDetail.getCmpCode())
|
|
|
+ || StringUtils.isEmpty(purchaseInvoiceDetail.getKiName())
|
|
|
+ || StringUtils.isEmpty(purchaseInvoiceDetail.getBrName())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Document document = new Document();
|
|
|
+ document.add(new StringField(SearchConstants.PURCHASE_INVOICE_DETAIL_ID_FIELD,
|
|
|
+ String.valueOf(purchaseInvoiceDetail.getId()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.PURCHASE_INVOICE_DETAIL_CODE_FIELD, purchaseInvoiceDetail.getCode(),
|
|
|
+ Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.PURCHASE_INVOICE_DETAIL_INVOICEID_FIELD,
|
|
|
+ String.valueOf(purchaseInvoiceDetail.getInvoiceid()), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.PURCHASE_INVOICE_DETAIL_COMPONENTCODE_FIELD,
|
|
|
+ purchaseInvoiceDetail.getCmpCode(), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.PURCHASE_INVOICE_DETAIL_KINDNAME_FIELD,
|
|
|
+ purchaseInvoiceDetail.getKiName(), Store.YES));
|
|
|
+ document.add(new TextField(SearchConstants.PURCHASE_INVOICE_DETAIL_BRANDNAME_FIELD,
|
|
|
+ purchaseInvoiceDetail.getBrName(), Store.YES));
|
|
|
+ return document;
|
|
|
+ }
|
|
|
+}
|