insert into inventory_cost_link(source_event_id,target_event_id) values(#{sourceId},#{targetId}) insert into stock_info(area_id,product_id,stock_num,create_time,update_time) select #{areaId},#{itemId},coalesce(sum(quantity),0),sysdate(),sysdate() from project_stock_balance where item_id=#{itemId} and area_id=#{areaId} on duplicate key update stock_num=values(stock_num),update_time=sysdate() insert into inventory_cost_event(project_id,item_id,area_id,event_key,event_no,event_type,quantity,receipt_amount,source_id,create_by,business_date,remark) values(#{projectId},#{itemId},#{areaId},#{eventKey},#{eventNo},#{eventType},#{quantity},#{receiptAmount},#{sourceId},#{createBy},#{businessDate},#{remark}) update inventory_cost_event set original_cost=#{amount} where id=#{id} update inventory_cost_event set effective_cost=#{amount} where id=#{id} update inventory_cost_event set active=0,void_reason=#{reason},void_by=#{actor},void_time=sysdate() where id=#{id} and active=1 insert into project_item_cost(project_id,item_id) select #{projectId},#{itemId} where not exists(select 1 from project_item_cost where project_id=#{projectId} and item_id=#{itemId}) update project_item_cost set quantity=#{quantity},amount=#{amount},version=version+1 where project_id=#{projectId} and item_id=#{itemId} insert into project_stock_balance(project_id,item_id,area_id,quantity) values(#{projectId},#{itemId},#{areaId},#{quantity}) on duplicate key update quantity=quantity+#{quantity},version=version+1 update project_stock_balance set quantity=quantity-#{quantity},version=version+1 where project_id=#{projectId} and item_id=#{itemId} and area_id=#{areaId} and quantity >= #{quantity} insert into inventory_cost_revision(revision_key,revision_no,target_event_id,new_amount,expected_version,create_by) values(#{revisionKey},#{revisionNo},#{targetEventId},#{newAmount},#{expectedVersion},#{createBy}) insert into inventory_cost_change(revision_id,event_id,old_amount,new_amount,delta_amount) values(#{revisionId},#{change.eventId},#{change.oldAmount},#{change.newAmount},#{change.delta})