Class ImportPendingDAO
java.lang.Object
ru.bgcrm.dao.CommonDAO
org.bgerp.plugin.inventory.sync1c.dao.ImportPendingDAO
DAO for inventory_sync1c_import_pending — pending stock balance imports from 1C.
-
Nested Class Summary
Nested classes/interfaces inherited from class CommonDAO
CommonDAO.ObjectExtractor<T>, CommonDAO.RecordUpdater<T> -
Field Summary
Fields inherited from class CommonDAO
con, log, SQL_AND, SQL_DELETE, SQL_DELETE_FROM, SQL_DESC, SQL_DISTINCT, SQL_FROM, SQL_GROUP_BY, SQL_INNER_JOIN, SQL_INSERT_IGNORE_INTO, SQL_INSERT_INTO, SQL_LEFT_JOIN, SQL_LIMIT, SQL_ON_DUP_KEY_UPDATE, SQL_ORDER_BY, SQL_REPLACE, SQL_SELECT, SQL_SELECT_ALL_FROM, SQL_SELECT_COUNT_ROWS, SQL_SET, SQL_UNION_ALL, SQL_UPDATE, SQL_VALUES, SQL_VALUES_1, SQL_VALUES_2, SQL_VALUES_3, SQL_VALUES_4, SQL_VALUES_5, SQL_WHERE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapply(int id, int userId) Applies a pending record: upserts inventory_balance.quantity and marks as applied.intapplyAll(List<ImportPending> list, int userId) Applies all pending records from the given list.get(int id) Returns a single pending record by id, ornull— used to check store access before apply/reject (the record's own store_id, not the caller-supplied one).getKnownItemIds(int ewId, int storeId) 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').getListForInstance(int instanceId) Returns all pending records for the given 1C instance (admin view).getListForStores(Set<Integer> storeIds) Returns pending records for stores the caller may manage — owner, individual StoreAccess grant, or edit_group_id membership (seeUserImportPendingAction.getAccessibleStoreIds).voidreject(int id) 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.voidupsert(int instanceId, int ewId, int storeId, int itemId, BigDecimal quantity) Upserts a pending record by (ew_id, item_id).Methods inherited from class CommonDAO
deleteById, foundRows, getById, getGroupedIds, getGroupedIds, getIds, getIds, getPageLimit, getPeriodSql, lastInsertId, setPeriodParamValue, setRecordCount, update, updateColumn, updateIds, updateIds, updateOrInsert
-
Constructor Details
-
ImportPendingDAO
-
-
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
Returns a single pending record by id, ornull— used to check store access before apply/reject (the record's own store_id, not the caller-supplied one).- Throws:
SQLException
-
getListForStores
Returns pending records for stores the caller may manage — owner, individual StoreAccess grant, or edit_group_id membership (seeUserImportPendingAction.getAccessibleStoreIds).- Throws:
SQLException
-
getListForInstance
Returns all pending records for the given 1C instance (admin view).- Throws:
SQLException
-
apply
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
Applies all pending records from the given list.- Throws:
SQLException
-
getKnownItemIds
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
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
-