예제 #1
0
  public SolrInputDocument toContactSolrDocument(
      ContactDTO contactDTO, String docType, SolrIdPrefix solrIdPrefix) throws Exception {
    PingyinInfo pingyinInfo = null;
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", solrIdPrefix + "_" + contactDTO.getId());
    doc.addField("doc_type", docType);
    doc.addField("shop_id", this.shop_id);
    doc.addField("customer_or_supplier_id", this.id);

    String name = this.name;
    if (StringUtils.isBlank(name)) {
      name = contactDTO.getName();
    }
    doc.addField("name", name);
    if (StringUtils.isNotBlank(name)) {
      pingyinInfo = PinyinUtil.getPingyinInfo(name);
      this.name_fl = pingyinInfo.firstLetters;
      this.name_py = pingyinInfo.pingyin;
      this.name_fl_sort = pingyinInfo.firstLetter;
      doc.addField("name_fl", name_fl);
      doc.addField("name_py", name_py);
      doc.addField("name_fl_sort", name_fl_sort);
    }

    if (StringUtils.isNotBlank(contactDTO.getName())) {
      doc.addField("contact", contactDTO.getName());
      pingyinInfo = PinyinUtil.getPingyinInfo(contactDTO.getName());
      String contact_fl = pingyinInfo.firstLetters;
      String contact_py = pingyinInfo.pingyin;
      doc.addField("contact_fl", contact_fl);
      doc.addField("contact_py", contact_py);
    }
    if (StringUtils.isNotBlank(contactDTO.getMobile())) {
      doc.addField("mobile", contactDTO.getMobile());
    }
    List<ContactGroupType> contactGroupTypeList = new ArrayList<ContactGroupType>();
    if ("customer".equals(this.getCustomer_or_supplier())) {
      contactGroupTypeList.add(ContactGroupType.CUSTOMER);
    }
    if ("supplier".equals(this.getCustomer_or_supplier())) {
      contactGroupTypeList.add(ContactGroupType.SUPPLIER);
    }
    if (StringUtils.isNotBlank(this.getMember_no())) {
      contactGroupTypeList.add(ContactGroupType.MEMBER);
    }
    if (Boolean.TRUE.equals(contactDTO.getApp())) {
      contactGroupTypeList.add(ContactGroupType.APP_CUSTOMER);
    }
    if (CollectionUtils.isNotEmpty(contactGroupTypeList)) {
      for (ContactGroupType contactGroupType : contactGroupTypeList) {
        doc.addField("contact_group_type", contactGroupType);
      }
    } else {
      doc.addField("contact_group_type", ContactGroupType.OTHERS);
    }
    return doc;
  }
예제 #2
0
  /**
   * 客户 供应商 名称 联系人 车牌号 用左右模糊 词的意义不大 不做分词 所以对应的拼音也不做分词
   *
   * @return
   * @throws Exception
   */
  public SolrInputDocument toSolrDocument() throws Exception {
    SolrInputDocument doc = null;
    PingyinInfo pingyinInfo = null;
    try {
      doc = new SolrInputDocument();
      if (shop_id == null) throw new Exception("shopId is null");

      doc.addField("id", this.id);
      doc.addField("doc_type", this.doc_type);
      doc.addField("shop_id", this.shop_id);

      if (StringUtils.isNotBlank(land_line)) {
        doc.addField("land_line", this.land_line);
      }
      doc.addField("customer_or_supplier", this.customer_or_supplier);
      doc.addField("customer_or_supplier_shop_id", this.customer_or_supplier_shop_id);

      if (StringUtils.isNotBlank(name)) {
        doc.addField("name", this.name);
      } else {
        doc.addField("name", "未填写");
        LOG.warn("[{}-id:{}] name is null.", this.customer_or_supplier, this.id);
      }
      if (CollectionUtils.isNotEmpty(getContactDTOList())) {
        for (ContactDTO contactDTO : getContactDTOList()) {
          if (contactDTO.getId() == null
              || (StringUtils.isBlank(contactDTO.getName())
                  && StringUtils.isBlank(contactDTO.getMobile()))) continue;

          doc.addField("contact_id", contactDTO.getId());
          if (StringUtils.isNotBlank(contactDTO.getName())) {
            doc.addField("contact", contactDTO.getName());
            pingyinInfo = PinyinUtil.getPingyinInfo(contactDTO.getName());
            String contact_fl = pingyinInfo.firstLetters;
            String contact_py = pingyinInfo.pingyin;
            doc.addField("contact_fl", contact_fl);
            doc.addField("contact_py", contact_py);
          } else {
            doc.addField("contact", StringUtil.SOLR_PLACEHOLDER_STRING);
            doc.addField("contact_fl", StringUtil.SOLR_PLACEHOLDER_STRING);
            doc.addField("contact_py", StringUtil.SOLR_PLACEHOLDER_STRING);
          }
          if (!isContactMobileEmpty()) {
            if (StringUtils.isNotBlank(contactDTO.getMobile())) {
              doc.addField("mobile", contactDTO.getMobile());
            } else {
              doc.addField("mobile", StringUtil.SOLR_PLACEHOLDER_STRING);
            }
          }
        }
      }

      if (StringUtils.isNotBlank(address)) {
        doc.addField("address", this.address);
      }
      if (StringUtils.isNotBlank(business_scope)) {
        doc.addField("business_scope", this.business_scope);
      }
      doc.addField("total_amount", this.total_amount == null ? 0d : this.total_amount);
      if ("customer".equals(customer_or_supplier)) {
        doc.addField("last_expense_time", this.last_expense_time);
        if (StringUtils.isNotBlank(member_no)) {
          doc.addField("member_no", member_no);
          doc.addField("member_no_fl", PinyinUtil.converterToFirstSpell(member_no));
          doc.addField("member_no_py", PinyinUtil.converterToPingyin(member_no));
        }
        doc.addField(
            "member_type", StringUtils.isNotBlank(this.member_type) ? this.member_type : "非会员");
        doc.addField("total_deposit", this.total_deposit);
        doc.addField("total_balance", this.balance);
      } else {
        doc.addField("last_inventory_time", this.last_inventory_time);
        doc.addField("total_deposit", this.total_deposit);
      }
      doc.addField("total_debt", (this.total_debt == null || total_debt < 0) ? 0d : total_debt);
      if (NumberUtil.doubleVal(total_debt) < 0) {
        LOG.warn("id:{},debt is illegal{}", id, total_debt);
      }
      doc.addField("created_time", this.created_time);
      if (!StringUtils.isBlank(name)) {
        pingyinInfo = PinyinUtil.getPingyinInfo(this.name);
        this.name_fl = pingyinInfo.firstLetters;
        this.name_py = pingyinInfo.pingyin;
        this.name_fl_sort = pingyinInfo.firstLetter;
        doc.addField("name_fl", name_fl);
        doc.addField("name_py", name_py);
        doc.addField("name_fl_sort", name_fl_sort);
      }
      if (CollectionUtils.isNotEmpty(license_nos)) {
        for (String license_no : license_nos) {
          if (StringUtils.isNotBlank(license_no)) {
            doc.addField("license_no", license_no);
            doc.addField("license_no_fl", PinyinUtil.converterToFirstSpell(license_no));
            doc.addField("license_no_py", PinyinUtil.converterToPingyin(license_no));
          }
        }
      }
      if (CollectionUtils.isNotEmpty(vehicle_brands)) {
        for (String vehicle_brand : vehicle_brands) {
          if (StringUtils.isNotBlank(vehicle_brand)) {
            doc.addField("vehicle_brand", vehicle_brand);
          }
        }
      }
      if (CollectionUtils.isNotEmpty(vehicle_models)) {
        for (String vehicle_model : vehicle_models) {
          if (StringUtils.isNotBlank(vehicle_model)) {
            doc.addField("vehicle_model", vehicle_model);
          }
        }
      }
      if (CollectionUtils.isNotEmpty(vehicle_colors)) {
        for (String vehicle_color : vehicle_colors) {
          if (StringUtils.isNotBlank(vehicle_color)) {
            doc.addField("vehicle_color", vehicle_color);
          }
        }
      }
      if (CollectionUtils.isNotEmpty(vehicle_details)) {
        for (String vehicle_detail : vehicle_details) {
          if (StringUtils.isNotBlank(vehicle_detail)) {
            doc.addField("vehicle_detail", vehicle_detail);
          }
        }
      }
      if (CollectionUtils.isNotEmpty(getArea_ids())) {
        for (Long area_id : getArea_ids()) {
          if (area_id != null) {
            doc.addField("area_ids", area_id);
          }
        }
      }
      doc.addField("area_info", this.area_info);

      doc.addField("status", null == this.status ? CustomerStatus.ENABLED : this.status.toString());
      doc.addField("total_return_debt", NumberUtil.doubleVal(total_return_debt));
      doc.addField("total_return_amount", NumberUtil.doubleVal(total_return_amount));
      doc.addField("total_trade_amount", NumberUtil.doubleVal(total_trade_amount));
      doc.addField("relation_type", this.relationType);
      doc.addField("dual_identity_id", this.dual_identity_id);
      doc.addField("is_obd", this.is_obd);
      doc.addField("is_app", this.isAppUser());
    } catch (IOException e) {
      LOG.error(e.getMessage(), e);
    }
    return doc;
  }