Colleagues, thought about this problem: how to make a different order status at one time for different users?

The task can be as follows: a) the order is transmitted along a chain of users, where at every stage something happens to it. User P1 creates the Order, he receives the status A. Then sends it to the user P2, the Order changes the status to A1. User P2 performs an action on the application, the status changes to B1 and it moves further along the chain. For the previous P1 user, the status remains unchanged - A1. User P3 receives the application and sees it with the status B1.

b) the task can be simplified by throwing the transmission along the chain, leaving only the essence: at one point in time N users should see "their" status. Probably, it is even more correct to set the task, because the implementation of the chain can be considered as a separate task.

It is logical to assume that initially there should be a certain register of possible statuses:

table status N | key ----------------- 1 | draft 2 | new 3 | processing N | .... 

The second. It is necessary to determine the number of different users ("roles") for which there may be different statuses. Well, suppose there are three of them: Coward, Balbes and Experienced.

Here the paths diverge. It is necessary to determine in which logic the statuses work. If the development of events occurs linearly, you can write down a similar table:

 N | key | Trus | Balbes | Byvaly | ----------------------------------------------------------- 1 | draft | Черновик | Черновик | Неизвестный | 2 | new | Новый | Черновик | Неизвестный | 3 | processing | Обработка | Обработка | Неизвестный | 4 | finish | Готово | Обработка | Неизвестный | N | .... | | | | 

Where each status should have a text designation for each role. Thus, each sees his own status name, depending on the role / user.

But it is not interesting. After all, events can flow nonlinearly. And here I am stalled. The only solution that comes to mind is to have its own order status matrix for each user role.

The situation is aggravated if it is assumed that someone from the users can see their orders and others. But in the logic of the order processing chain, this list may also contain “your own”, something must also be done with this “shizoy”.

Another consequence of this logic is how, say, to make a selection from the database of all new orders of all users, if each has its own set of statuses (and identifiers, respectively). No, you can do it ... but will this decision be beautiful?

In short, there were a lot of questions. It is interesting to hear those who have come across or have an idea how problems of this type are solved.

I supplement the question:

We are interested in non-linear order processing:

So.

1) There are users (P1, P2, P3), each user has a certain role. For simplicity, specifying a user with a buoy implies that they are all in different roles.

2) Imagine the life cycle of the application:

  • P1 creates an application, it is sent to P2;
  • П2 performs actions on it and thereby changes its status;
  • P2 returns the application P1 or her P3;

(While the application from P1 is at P2 / P3, he sees one single status “at work”, while relations of P2 and P3 are regulated by their own statuses, but P1 should not soar)

Then the fork: - received an application (returned back) P1; - application received P3

The logic remains the same. The user conjures over the application and sends it back or forth along the chain. Those. There is no strict order processing sequence in the sense that it must pass from P1 to P3 “without turning off the path”. This plug can be repeated N times again between P1 and P2, and between P2 and P3.

In other words, the sequence of processing looks like a trace. in the following way:

P1 ← → P2 ← → P3

While I here see two registries of statuses:

  • P2 and P3 (this is a classic case)
  • for P1

and maybe for each role separately.

Why two status registries? Because the business logic for each user role can be different. P1 can work within, say, four statuses (new, processing, denied, confirmed), whereas in relations P2 and P3, the statuses can reflect a more detailed picture of the processes taking place.

But several registries will lead to crap in implementation. As a compromise, I see the ability to store the available statuses for each role based on a single registry. Those. we have a table with all possible statuses (above, Fig. 1), and we have a pivot table for each role with statuses only available to it (well, or to add columns to the order table is a secondary issue).

What we have in the end: the order must store its own status index for the user (ie, the role). But all the statuses, as I noted in the previous paragraph, will be from a single registry, thereby removing the crap in implementation.

Those. at the output we have something like this:

 id | order_id | role1 | Role2 | role3 | ----------------------------------------------------------- 1 | 1 | 1 | 2 | 3 | 
  • Strange. In the first part of the question, it seems that there is a general set of statuses and for a particular user, the status that was just when the order left him was fixed. This is solved by the order id table, user id, status. And in the second part of your question, it turns out that the status on the order is the same (with one id), but users see it differently. moreover, they are globally on all orders status 1 is seen by user P1 as “ABC”, and user P2 as “XYZ”. So which part of your question reflects what should be? - Mike
  • In the first case, events develop linearly and, yes, this is solved simply, as you rightly noted. But the question in the process was developed - how to build a system of different statuses for different users with non-linear development of events? Say, at some stages, users can transfer each other an order for some processing, a refusal or a transition to another state can be received. I think we should add the main text of the question. - Stanislav
  • All the same, I do not understand how nonlinear events differ from linear ones in terms of storage. statuses in theory should be stored in the same form. only complicates the logic of status changes for specific users. where does “ID status = 1 stupid see as Draft, and Experienced as Unknown” - Mike
  • Entirely and completely agree. Technically possible, but not rational. This is just a reasoning search. The question has updated, I think the issue of storing statuses in one table should be removed. - Stanislav
  • You are in the examples of signs in the horizontal I hope for clarity, deploy. they will be stored vertically. And I think you have solved the problem already. The table of statuses and acceptable statuses for a role looks good. however, some kind of status conversion table may be required, if suddenly the status that was set by P1 is unavailable for P2, what will he see when he receives the order. - Mike

1 answer 1

If I understand correctly, you need to get the status for the order at the required time (not necessarily at the moment) by a number of parameters: - by initiator (your / someone else's) - at the time - for the role

If something similar, then: - for the order, set the initiator ID - for the status by key (order ID + time of status + role ID) set the status ID.

And we have: - the order ID has an order from the order who is the author (your / someone else's); - by the time of the status - we get the status at the required time or the last status according to the required parameters; - by role ID - we get the required status for the user for a specific role.

Offhand, something like that ...

  • Did not catch the thought - "moment of status" here what role plays? Why is the time involved in the sample? - Stanislav
  • When this status was assigned. Having this timestamp, we can find out how the status has changed over time for different users. By MAX () we can have the current status and when it was installed. - Anatoly