Class ImportPendingDAO

java.lang.Object
ru.bgcrm.dao.CommonDAO
org.bgerp.plugin.inventory.sync1c.dao.ImportPendingDAO

public class ImportPendingDAO extends CommonDAO
DAO for inventory_sync1c_import_pending — pending stock balance imports from 1C.
  • Constructor Details

    • ImportPendingDAO

      public ImportPendingDAO(Connection con)
  • Method Details

    • upsert

      public void upsert(int instanceId, int ewId, int storeId, int itemId, BigDecimal quantity) throws SQLException
      Upserts a pending record by (ew_id, item_id). If a record already exists (any status), it is reset to pending with the new quantity.
      Throws:
      SQLException
    • get

      public ImportPending get(int id) throws SQLException
      Returns a single pending record by id, or null — used to check store access before apply/reject (the record's own store_id, not the caller-supplied one).
      Throws:
      SQLException
    • getListForStores

      public List<ImportPending> getListForStores(Set<Integer> storeIds) throws SQLException
      Returns pending records for stores the caller may manage — owner, individual StoreAccess grant, or edit_group_id membership (see UserImportPendingAction.getAccessibleStoreIds).
      Throws:
      SQLException
    • getListForInstance

      public List<ImportPending> getListForInstance(int instanceId) throws SQLException
      Returns all pending records for the given 1C instance (admin view).
      Throws:
      SQLException
    • apply

      public void apply(int id, int userId) throws SQLException
      Applies a pending record: upserts inventory_balance.quantity and marks as applied. Uses a single INSERT...SELECT to avoid an extra round-trip. Also appends an 'adjustment' row to inventory_movement (before→after, who applied it) so the change shows up in the store's existing "Движения ТМЦ" audit trail — otherwise a CSV/1C sync silently overwrites the balance with no visible history at all.
      Throws:
      SQLException
    • applyAll

      public int applyAll(List<ImportPending> list, int userId) throws SQLException
      Applies all pending records from the given list.
      Throws:
      SQLException
    • getKnownItemIds

      public Set<Integer> getKnownItemIds(int ewId, int storeId) throws SQLException
      Returns item ids currently believed to have stock at this store — either confirmed in inventory_balance (quantity>0) or still awaiting confirmation from a previous import (status='pending'). Used to detect items that dropped out of a new import batch: per the 1C API contract, an exhausted (qty=0) item is omitted from the response entirely rather than sent with quantity=0 — so its disappearance from the batch is the only signal ERP gets that it should be proposed as zeroed out.
      Throws:
      SQLException
    • reject

      public void reject(int id) throws SQLException
      Rejects a pending record — atomic claim (same reasoning as apply()), so an already applied/rejected record can't be silently flipped by a stale/duplicate request.
      Throws:
      SQLException