How to organize the history of cash flow? There is some interesting problem that I haven’t been able to solve beautifully for a very long time. This is the implementation of the structure of financial accounting in the project.

Let's imagine what needs to be done in the "Cash flow history" section, where the list of financial movements will be displayed with more or less detailed information, for example:

  • User Vasya transferred $ 10 to Pete User User Vasya
  • brought $ 100 through the system "Privat Bank" User Peter transferred you
  • $ 15 Activation in the "Start" tariff plan for $ 25 Pay $ 15 for the service
  • "Change of login" Payment of $ 100 for the service "Raise ad to the top."
  • Apartment for day # 1, Apartment for day # 2, Apartment for day # 3,
  • Apartment for day №4

The most basic problem is that this information needs to be stored not statically, but taken from other tables, so that if Vasya or Petya change their login, everyone in the stories will change this. (Examples are taken from the head, so do not pay much attention to specifics).

Now for a more detailed example.

For example, there are the following types of services:

  • Raise ads to the top
  • Change login
  • Buy a subscription to the "tariff plan"
  • Pay for the order of goods

Task: fix the identifiers of the entities that appear in the order and display from.

Consider the example of "Raise ads in the top" and "Buy a subscription to the 'tariff plan'". Our task is to write somewhere a list of id from the ad table and id from the table of tariff plans to get the necessary data for the render.

The problem is that a single query does not collect the history of money turnover, since, based on the type of service, you need to know which table contains the recorded id. From here it comes out that we can only get a list of all operations, and then for each operation in the cycle, based on the condition, make a request to the necessary tables to get information with which we work at all.

Ie, if we have a task to display 100 records, then each record will have 1 request and this leaves more than 100 requests in the database for rendering the page. Somehow not good.

Actually share please advice on implementation ...

    1 answer 1

    And if the login is stored in an array? Those. Vasya from the very beginning in Name [0] is standard, if he changed the index will be 1,2,3.4, ...., n Ie, create an array or ArrayList and assume that this user has such a name before Null elements. Prmer Vasya (0), Vasily (1), Null, null, null, null, ...., null

    • And it is obvious that this new name is Vasily, because then comes the null elements - Dmitry Berezhnoy
    • there is a key point in the sampling of data. What if we, for example, raised to the top 10 or 100 ads? - Nepster