{"id":492166,"date":"2026-08-25T13:25:15","date_gmt":"2026-08-25T13:25:15","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=492166"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=492166","title":{"rendered":"\u0421\u0432\u0435\u0436\u0438\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0430\u00a0\u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0439\u043c\u2011\u0441\u043b\u043e\u0442\u043e\u0432, \u0438\u043b\u0438\u00a0\u043a\u0430\u043a\u00a0\u044f \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b \u043d\u0430\u00a0Spring boot, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0435\u0441\u0441\u0438\u043c\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, \u0425\u0430\u0431\u0440\u043e\u0432\u0447\u0430\u043d\u0435! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u043c\u0438\u0442\u0440\u0438\u0439, \u044f \u0431\u044d\u043a\u0435\u043d\u0434 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a Java. \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430\u00a0\u0437\u0430\u0434\u0430\u0447\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u043d\u0435 \u043a\u043e\u043f\u0435\u0435\u0447\u043d\u043e\u0439, \u0430\u00a0\u043f\u043e\u0442\u043e\u043c \u0441\u043e\u0436\u0440\u0430\u043b\u0430 \u043d\u0435\u0434\u0435\u043b\u044e \u0432\u0435\u0447\u0435\u0440\u043e\u0432 \u0438 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043b\u0430 \u0437\u0430\u043b\u0435\u0437\u0442\u044c \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u0432\u00a0\u0434\u0435\u0431\u0440\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 PostgreSQL.<\/p>\n<p>\u0412\u0441\u0451 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0441\u00a0\u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0434\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u043d\u043e\u0439 \u043a\u043b\u0438\u043d\u0438\u043a\u0438. \u041f\u043e\u043d\u0430\u0447\u0430\u043b\u0443 \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e\u00a0\u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439: \u043f\u0430\u0446\u0438\u0435\u043d\u0442 \u0445\u043e\u0447\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u00a0\u041c\u0420\u0422 \u0441\u00a0\u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0442\u043e\u043c. \u041e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u044c \u0437\u0430\u043f\u0438\u0441\u0438 (\u0432\u0440\u043e\u0434\u0435 Calendly \u0438\u043b\u0438\u00a0\u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 YClients) \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043c\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 \u0432\u0440\u0435\u043c\u044f. \u041d\u043e\u00a0\u043d\u0430\u00a0\u0434\u0435\u043b\u0435 \u0432\u0441\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u0435\u00a0\u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e&#8230; \u0427\u0442\u043e\u0431\u044b \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043b\u0430\u0441\u044c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0437\u0430\u043d\u044f\u0442\u044c \u043d\u0430\u00a0\u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442\u00a0\u0436\u0435 \u0447\u0430\u0441 \u0442\u0440\u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ol>\n<li>\n<p>\u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0432\u0440\u0430\u0447\u0430\u2011\u0440\u0430\u0434\u0438\u043e\u043b\u043e\u0433\u0430 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043c\u0435\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u0438 \u0441\u043d\u0438\u043c\u043a\u0438).<\/p>\n<\/li>\n<li>\n<p>\u0421\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439 \u043a\u0430\u0431\u0438\u043d\u0435\u0442, \u0433\u0434\u0435 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0442\u043e\u0438\u0442 \u0442\u043e\u043c\u043e\u0433\u0440\u0430\u0444.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0443 \u0438 \u0441\u0430\u043c\u044b\u0439 \u0434\u043e\u0440\u043e\u0433\u043e\u0439 \u0440\u0435\u0441\u0443\u0440\u0441\u00a0\u2014 \u044d\u0442\u043e \u0442\u043e\u043c\u043e\u0433\u0440\u0430\u0444, \u043a\u043e\u0442\u043e\u0440\u044b\u0439\u00a0\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u00a0\u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u0442\u044c \u043d\u0438 \u043c\u0438\u043d\u0443\u0442\u044b!<\/p>\n<\/li>\n<\/ol>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437\u00a0\u044d\u0442\u0438\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0437\u0430\u043d\u044f\u0442, \u0438\u043b\u0438\u00a0\u0433\u0440\u0430\u0444\u0438\u043a \u0443\u00a0\u0432\u0440\u0430\u0447\u0430 \u043d\u0435\u00a0\u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441\u00a0\u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c, \u0442\u043e \u0432\u0441\u0435, \u0441\u043b\u043e\u0442\u0430 \u043d\u0435\u0442. \u0413\u043e\u0442\u043e\u0432\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430\u00a0\u0440\u044b\u043d\u043a\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043f\u043e\u00a0\u0441\u0445\u0435\u043c\u0435 \u00ab\u043e\u0434\u0438\u043d \u043a\u043b\u0438\u0435\u043d\u0442\u00a0\u2014 \u043e\u0434\u0438\u043d \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u00bb, \u0430\u00a0\u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0435 \u00ab\u043c\u0443\u043b\u044c\u0442\u0438\u2011\u0440\u0435\u0441\u0443\u0440\u0441\u043d\u043e\u0435 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u00bb \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0434\u043a\u043e, \u044f \u0441\u0445\u043e\u0434\u0443 \u043d\u0435\u00a0\u043d\u0430\u0448\u0435\u043b. <\/p>\n<p>\u0418 \u0432\u043e\u0442 \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043b\u0435\u0433\u043a\u0438\u0439 b2b\u2011\u0434\u0432\u0438\u0436\u043e\u043a \u0442\u0430\u0439\u043c\u2011\u0441\u043b\u043e\u0442\u043e\u0432 \u043d\u0430 <strong>Java 17\u00a0\u0438 Spring Boot 3<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f\u00a0\u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u0438\u0437\u043e\u043b\u0438\u0440\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439 (SaaS) \u0438 \u043d\u0430\u043c\u0435\u0440\u0442\u0432\u043e \u0437\u0430\u0449\u0438\u0449\u0435\u043d \u043e\u0442\u00a0\u043e\u0432\u0435\u0440\u0431\u0443\u043a\u0438\u043d\u0433\u0430. \u0420\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e, \u043a\u0430\u043a\u00a0\u044f \u044d\u0442\u043e \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0438 \u043d\u0430\u00a0\u043a\u0430\u043a\u0438\u0435 \u0433\u0440\u0430\u0431\u043b\u0438 \u043d\u0430\u0441\u0442\u0443\u043f\u0438\u043b \u0432\u00a0\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435. <\/p>\n<h2>\u0413\u0440\u0430\u0431\u043b\u0438 \u2116\u00a01: \u041a\u0430\u043a\u00a0\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435? <\/h2>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u0433\u0434\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u044c <code>start_time<\/code> \u0438 <code>end_time<\/code> \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u044f\u043c\u043e \u0432\u00a0\u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0440\u0430\u0447\u0430), \u043d\u0435\u0442 \u044d\u0442\u043e \u043d\u0435\u00a0\u0433\u043e\u0434\u0438\u0442\u0441\u044f&#8230; \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u0438\u0437\u043d\u0435\u0441\u0430\u00a0\u2014 \u044d\u0442\u043e \u0445\u0430\u043e\u0441. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0440\u0430\u0447 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 9\u00a0\u0434\u043e 13, \u043f\u043e\u0442\u043e\u043c \u0443\u00a0\u043d\u0435\u0433\u043e \u043e\u0431\u0435\u0434, \u043f\u043e\u0442\u043e\u043c \u0432\u0442\u043e\u0440\u0430\u044f \u0441\u043c\u0435\u043d\u0430 \u0441 16\u00a0\u0434\u043e 20. \u0410\u00a0\u0432\u00a0\u043f\u044f\u0442\u043d\u0438\u0446\u0443 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u043e\u0447\u043d\u043e\u0435 \u0434\u0435\u0436\u0443\u0440\u0441\u0442\u0432\u043e.<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u044f \u0441\u0440\u0430\u0437\u0443 \u0432\u044b\u043d\u0435\u0441 \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0432\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 (<code>resource_availability_intervals<\/code>). \u0410\u00a0\u0441\u0430\u043c\u043e \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0430\u043b \u0441\u00a0\u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e Many\u2011to\u2011Many \u0432\u00a0Spring Data Entities.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a\u00a0\u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u0445\u0435\u043c\u0430 \u0442\u0430\u0431\u043b\u0438\u0446 \u0432\u00a0SQL:<\/p>\n<pre><code class=\"sql\">CREATE TABLE resources (  id BIGSERIAL PRIMARY KEY,   name VARCHAR(255) NOT NULL,   type VARCHAR(50) NOT NULL,  timezone VARCHAR(100) NOT NULL DEFAULT 'UTC');CREATE TABLE resource_availability_intervals (  id BIGSERIAL PRIMARY KEY,   resource_id BIGINT NOT NULL REFERENCES resources(id) ON DELETE CASCADE,   day_of_week VARCHAR(15) NOT NULL,   start_time TIME NOT NULL,   end_time TIME NOT NULL);CREATE TABLE bookings (    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),    company_id BIGINT NOT NULL REFERENCES companies(id) ON DELETE CASCADE,    status VARCHAR(50) NOT NULL DEFAULT 'CONFIRMED',    start_time TIMESTAMP WITH TIME ZONE NOT NULL,    end_time TIMESTAMP WITH TIME ZONE NOT NULL);-- \u041c\u043e\u0441\u0442 Many-to-ManyCREATE TABLE booking_resources (    booking_id UUID NOT NULL REFERENCES bookings(id) ON DELETE CASCADE,    resource_id BIGINT NOT NULL REFERENCES resources(id) ON DELETE CASCADE,    PRIMARY KEY (booking_id, resource_id));<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0421\u00a0\u0442\u0430\u043a\u043e\u0439 \u0441\u0445\u0435\u043c\u043e\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043f\u043e\u0434\u00a0\u043e\u0434\u043d\u0438\u043c UUID \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0445\u043e\u0442\u044c \u0432\u0440\u0430\u0447\u0430, \u0445\u043e\u0442\u044c \u0442\u043e\u043c\u043e\u0433\u0440\u0430\u0444, \u0445\u043e\u0442\u044c \u043f\u0430\u0440\u043a\u043e\u0432\u043e\u0447\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f\u00a0\u043a\u0443\u0440\u044c\u0435\u0440\u0430. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0432\u00a0\u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u043b \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0449\u0435\u0433\u043e \u0441\u043b\u043e\u0442\u0430 \u0434\u043b\u044f\u00a0\u0432\u0441\u0435\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 (resource_availability_intervals) \u0437\u0430\u00a0\u0432\u044b\u0447\u0435\u0442\u043e\u043c \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0431\u0440\u043e\u043d\u0435\u0439 \u0432\u0441\u0435\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0446\u0435\u043f\u043e\u0447\u043a\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0435\u0441\u0442\u044c (bookings). <\/p>\n<h2>\u0413\u0440\u0430\u0431\u043b\u0438 \u2116\u00a02: \u0414\u0432\u043e\u0439\u043d\u044b\u0435 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 Race Condition <\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 \u0432\u044b\u0441\u043e\u043a\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0446\u0435\u043d\u0442\u0440, \u043a\u0443\u0434\u0430 \u043b\u043e\u043c\u0438\u0442\u0441\u044f 100\u00a0\u0444\u0443\u0440 \u043d\u0430\u00a0\u0440\u0430\u0437\u0433\u0440\u0443\u0437\u043a\u0443), \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u0430\u0441 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0442. \u0427\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043a\u043e\u0433\u0434\u0430 \u0434\u043b\u044f\u00a0\u0434\u0432\u0443\u0445 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0434\u0432\u0430 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u00ab\u0417\u0430\u043d\u044f\u0442\u044c \u043d\u0430 14:00\u00bb, \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442 \u043e\u0431\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u043e\u0432\u0435\u0440\u0431\u0443\u043a\u0438\u043d\u0433, \u0438 \u043d\u0430\u0447\u043d\u0443\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u043e\u0440\u043a\u0438 \u043a\u0442\u043e \u0432\u0438\u043d\u043e\u0432\u0430\u0442 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0427\u0442\u043e\u00a0\u0436\u0435 \u0434\u0435\u043b\u0430\u0442\u044c? <\/p>\n<p>\u0421\u0430\u043c\u043e\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u00a0\u0433\u043e\u043b\u043e\u0432\u0443\u00a0\u2014 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 <strong>\u043f\u0435\u0441\u0441\u0438\u043c\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u043d\u0430\u00a0\u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0442\u0440\u043e\u043a \u0421\u0423\u0411\u0414 (Pessimistic Write Lock)<\/strong>. \u0427\u0442\u043e\u00a0\u0436 \u0434\u0435\u043b\u0430\u0435\u043c \u0438\u0445 \u043c\u043e\u0434\u043d\u043e \u0432\u00a0JPA \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438: <\/p>\n<pre><code class=\"java\">public interface ResourceRepository extends JpaRepository&lt;Resource, Long&gt; {  @Lock(LockModeType.PESSIMISTIC_WRITE)  List&lt;Resource&gt; findByIdInAndCompanyId(Set&lt;Long&gt; ids, Long companyId);  ...}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u043c\u0435\u0442\u043e\u0434 findByIdInAndCompanyId \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, Hibernate \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 SQL\u2011\u0437\u0430\u043f\u0440\u043e\u0441 <code>SELECT ... FOR UPDATE<\/code>. PostgreSQL \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u00a0\u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438. \u0418 \u0442\u043e\u0433\u0434\u0430 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a\u00a0\u044d\u0442\u0438\u043c\u00a0\u0436\u0435 IDs \u0432\u0441\u0442\u0430\u0435\u0442 \u0432\u00a0\u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438 \u043a\u0443\u0440\u0438\u0442 \u0431\u0430\u043c\u0431\u0443\u043a, \u043f\u043e\u043a\u0430 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043d\u0435\u00a0\u0441\u0434\u0435\u043b\u0430\u0435\u0442 <code>COMMIT<\/code> \u0438\u043b\u0438 <code>ROLLBACK<\/code>. \u0422.\u043e. \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u0442\u0430\u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443, \u0443\u0440\u0430, \u0432\u0441\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0435\u0434\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435!<\/p>\n<h2>\u0413\u0440\u0430\u0431\u043b\u0438 \u2116\u00a03: \u041d\u043e\u0447\u043d\u044b\u0435 \u0441\u043c\u0435\u043d\u044b \u0438 \u0445\u0430\u043e\u0441 \u0441\u00a0\u0447\u0430\u0441\u043e\u0432\u044b\u043c\u0438 \u043f\u043e\u044f\u0441\u0430\u043c\u0438<\/h2>\n<p>\u041d\u0443 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0432\u0441\u0442\u0430\u043b \u0432\u043e\u043f\u0440\u043e\u0441 \u043a\u0430\u043a\u00a0\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u043a\u0430\u043a\u00a0\u0443\u0447\u0435\u0441\u0442\u044c \u0442\u0430\u0439\u043c\u0437\u043e\u043d\u044b? \u041d\u043e\u00a0\u044d\u0442\u043e \u043f\u043e\u043b \u0431\u0435\u0434\u044b, \u0435\u0441\u0442\u044c\u00a0\u0436\u0435 \u0435\u0449\u0435 \u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441\u00a0\u0442\u0435\u043c, \u0447\u0442\u043e\u00a0\u0433\u0440\u0430\u0444\u0438\u043a \u0440\u0435\u0441\u0443\u0440\u0441\u0430 \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u043d\u043e\u0447\u043d\u044b\u043c \u0438\u043b\u0438 \u00ab\u0440\u0432\u0430\u043d\u044b\u043c\u00bb. \u042f \u0432\u0432\u0435\u043b\u00a0\u0436\u0435\u0441\u0442\u043a\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0437\u043e\u043d \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438:<\/p>\n<ul>\n<li>\n<p><strong>\u0420\u0430\u0431\u043e\u0447\u0438\u0435 \u0433\u0440\u0430\u0444\u0438\u043a\u0438 (\u0418\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438)<\/strong> \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u00a0\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0412\u00a0\u0431\u0430\u0437\u0435 \u043b\u0435\u0436\u0430\u0442 \u0447\u0438\u0441\u0442\u044b\u0435 <code>LocalTime<\/code> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>09:00:00<\/code>\u00a0\u2014 <code>18:00:00<\/code>) \u043f\u043b\u044e\u0441 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0447\u0430\u0441\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u044f\u0441\u0430 (IANA ID, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>Europe\/Moscow<\/code>), \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u00a0\u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>C\u0435\u0442\u043a\u0430 \u0441\u043b\u043e\u0442\u043e\u0432<\/strong> \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u0433\u043e \u0432\u00a0\u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0448\u043a\u0430\u043b\u044b\u00a0\u2014 <code>OffsetDateTime<\/code> (UTC \u0441\u00a0\u043d\u0443\u043b\u0435\u0432\u044b\u043c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435\u043c <code>Z<\/code>).<\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0442\u043e\u00a0\u0436\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u00a0\u043d\u043e\u0447\u043d\u044b\u043c\u0438 \u0441\u043c\u0435\u043d\u0430\u043c\u0438? <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0443\u00a0\u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430 \u0441\u043c\u0435\u043d\u0430 \u0441 22:00\u00a0\u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a\u0430 \u0434\u043e 06:00\u00a0\u0443\u0442\u0440\u0430 \u0432\u0442\u043e\u0440\u043d\u0438\u043a\u0430&#8230; \u0411\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u044f\u0436\u0435\u043b\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u0447\u0442\u043e <code>06:00<\/code>\u00a0\u2014 \u044d\u0442\u043e \u043f\u043e\u0437\u0436\u0435, \u0447\u0435\u043c <code>22:00<\/code>. \u0418 \u0442\u0443\u0442 \u043f\u043e\u0438\u0441\u043a\u0430\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u043f\u0430\u0442\u0442\u0435\u0440\u043d <strong>Midnight Splitting<\/strong> (\u0434\u0440\u043e\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u00a0\u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u0441\u0443\u0442\u043e\u043a). \u0412\u00a0\u0438\u0442\u043e\u0433\u0435 \u043f\u0440\u0438\u00a0\u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0432\u044b\u0448\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432:<\/p>\n<p>\u0417\u0430\u043f\u0438\u0441\u044c 1: <code>day_of_week: MONDAY, start_time: 22:00:00, end_time: 23:59:59<\/code><\/p>\n<p>\u0417\u0430\u043f\u0438\u0441\u044c 2: <code>day_of_week: TUESDAY, start_time: 00:00:00, end_time: 06:00:00<\/code><\/p>\n<pre><code class=\"java\">private boolean isResourceAvailableInItsSchedule(Resource resource, OffsetDateTime startUtc, OffsetDateTime endUtc) {    ZoneId resourceZone = ZoneId.of(resource.getTimezone());        \/\/ \u041f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043c \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0435 UTC \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u044f\u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430    ZonedDateTime localStart = startUtc.atZoneSameInstant(resourceZone);    ZonedDateTime localEnd = endUtc.atZoneSameInstant(resourceZone);        DayOfWeek startDay = localStart.getDayOfWeek();    LocalTime startTime = localStart.toLocalTime();    LocalTime endTime = localEnd.toLocalTime();    \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0441\u0443\u0442\u043e\u043a \u043d\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e    return resource.getAvailabilityIntervals().stream()            .filter(i -&gt; i.getDayOfWeek() == startDay)            .anyMatch(i -&gt; !startTime.isBefore(i.getStartTime()) &amp;&amp; !endTime.isAfter(i.getEndTime()));}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0422.\u043e. \u0438\u0449\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0438 \u043f\u043e\u00a0\u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a\u0443 \u0438 \u043f\u043e\u00a0\u0432\u0442\u043e\u0440\u043d\u0438\u043a\u0443, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043e\u0434\u043d\u0430 \u0441\u043c\u0435\u043d\u0430. \u0414\u0430\u00a0\u0438 \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0431\u043b\u0430\u0433\u043e\u043f\u0440\u0438\u044f\u0442\u043d\u043e \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u00a0SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043f\u043e\u00a0\u043f\u043e\u043b\u044f\u043c \u0434\u0430\u0442 \u043d\u0430\u0447\u0430\u043b\u0430 \u0438 \u043a\u043e\u043d\u0446\u0430 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0447\u0442\u043e\u00a0\u0432\u00a0\u0431\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043b\u044f\u00a0\u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043e\u0442\u0447\u0435\u0442\u043e\u0432 \u0438 \u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435<\/p>\n<h2>\u041d\u0435\u00a0\u0413\u0440\u0430\u0431\u043b\u0438 4: \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c\u00a0\u2014 \u0438\u0437\u043e\u043b\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u043f\u043e\u00a0API \u043a\u043b\u044e\u0447\u0430\u043c<\/h2>\n<p>\u0427\u0442\u043e\u00a0\u0431\u044b API \u043c\u043e\u0433\u043b\u043e \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u0442\u044b\u0441\u044f\u0447\u0438 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u043d\u0435\u00a0\u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044f \u0443\u0442\u0435\u0447\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u044f \u0432\u0432\u0435\u043b \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u00a0company_id. \u041a\u043e\u043d\u0435\u0447\u043d\u043e,\u00a0\u0431\u044b\u043b\u043e\u00a0\u0431\u044b \u043f\u0440\u043e\u0449\u0435, \u0435\u0441\u043b\u0438 \u0432\u00a0\u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u00a0\u0431\u044b \u044d\u0442\u043e\u0442 company_id, \u0432\u00a0\u043a\u043e\u0434\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0448\u044c \u043f\u043e\u00a0\u043d\u0435\u043c\u0443 \u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u0445\u043e\u0440\u043e\u0448\u043e. \u041d\u043e\u00a0\u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0442\u0430\u043a \u043d\u0435\u043b\u044c\u0437\u044f, \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043d\u0435\u00a0\u0434\u043e\u043b\u0436\u043d\u044b \u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435\u2011\u043b\u0438\u0431\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437\u00a0\u0411\u0414, \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 IDs. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 company_id \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e \u043d\u0430\u00a0\u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (<code>Authorization: Bearer Token<\/code>) <\/p>\n<p>\u0414\u043b\u044f\u00a0\u044d\u0442\u043e\u0433\u043e \u043f\u0438\u0448\u0435\u043c <code>HandlerInterceptor<\/code> \u0438\u0437\u00a0\u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b Spring MVC, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 REST \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430\u00a0\u0432\u0445\u043e\u0434\u0435, \u0438 \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u0442 <code>company_id<\/code> \u043f\u043e\u00a0\u0442\u043e\u043a\u0435\u043d\u0443, \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u0442 \u0435\u0433\u043e \u0432\u00a0\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0447\u0435\u0440\u0435\u0437 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430: <\/p>\n<pre><code class=\"java\">@Componentpublic class ApiKeyInterceptor implements HandlerInterceptor {    private final ApiKeyRepository apiKeyRepository;    public ApiKeyInterceptor(ApiKeyRepository apiKeyRepository) {        this.apiKeyRepository = apiKeyRepository;    }    @Override    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {        String authHeader = request.getHeader(\"Authorization\");        if (authHeader == null || !authHeader.startsWith(\"Bearer \")) {            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);            response.getWriter().write(\"Missing or invalid Authorization header\");            return false;        }        String token = authHeader.substring(7);        Optional&lt;Long&gt; companyIdOpt = apiKeyRepository.findCompanyIdByToken(token);        if (companyIdOpt.isEmpty()) {            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);            response.getWriter().write(\"Invalid or inactive API key\");            return false;        }        \/\/ \u041f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c ID \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430        request.setAttribute(\"CURRENT_COMPANY_ID\", companyIdOpt.get());        return true;    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041a\u0430\u043a\u00a0\u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0442\u0443\u0442 \u044d\u0442\u043e \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0442\u043e\u043a\u0435\u043d String token = authHeader.substring(7);, \u043d\u0430\u0439\u0442\u0438 \u043f\u043e\u00a0\u043d\u0435\u043c\u0443 <code>company_id \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u043f\u0443  <\/code>apiKeyRepository.findCompanyIdByToken(token) \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0435\u0433\u043e \u0432\u00a0\u0440\u0435\u043a\u0432\u0435\u0441\u0442 \u0443\u0436\u0435 \u043d\u0430\u00a0\u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0431\u044d\u043a\u0435\u043d\u0434\u0430 request.setAttribute(\u201cCURRENT_COMPANY_ID\u201d, companyIdOpt.get()); \u0412\u043e\u0442 \u0438 \u0432\u0441\u0435, \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0437\u043d\u0430\u044e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e \u0447\u0442\u043e\u00a0\u0438\u043c \u043d\u0443\u0436\u043d\u043e\u00a0\u2014 \u0441\u0432\u043e\u0439 API Key \u0438 \u043d\u0438\u0447\u0435\u0433\u043e\u00a0\u043b\u0438\u0448\u043d\u0435\u0433\u043e!<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435:<\/h2>\n<p>\u0412\u00a0\u0438\u0442\u043e\u0433\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u0433\u043e\u0442\u043e\u0432 \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d, \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430\u00a0Github\u00a0\u2014 <a href=\"https:\/\/github.com\/Razzhivin\/slots-api\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/Razzhivin\/slots\u2011api<\/a><\/p>\n<p>\u0412\u00a0readme \u044f \u043e\u043f\u0438\u0441\u0430\u043b \u043a\u0430\u043a\u00a0\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u00a0\u043f\u0430\u0440\u0443 \u043c\u0438\u043d\u0443\u0442 \u043a\u0430\u043a\u00a0Docker\u2011\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0432\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0441\u00a0\u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c API Key \u0442\u0430\u043c\u00a0\u0436\u0435!<\/p>\n<h2>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c \u0432\u0430\u0448\u0435 \u043c\u043d\u0435\u043d\u0438\u0435:<\/h2>\n<ul>\n<li>\n<p>\u041a\u0430\u043a\u00a0\u0431\u044b \u0432\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0442\u043e\u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430\u00a0\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\u0445 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438\u00a0\u043f\u043e\u0438\u0441\u043a\u0435 \u0441\u043b\u043e\u0442\u043e\u0432 \u043d\u0430\u00a0\u0433\u043e\u0434 \u0432\u043f\u0435\u0440\u0435\u0434)? \u0421\u0442\u043e\u0438\u0442\u00a0\u043b\u0438 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0443\u044e \u0441\u0435\u0442\u043a\u0443 \u0432\u00a0Redis?<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u0442\u044c\u00a0\u043b\u0438 \u0441\u043c\u044b\u0441\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 (<code>@Version<\/code>) \u0434\u043b\u044f\u00a0\u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430\u00a0\u043f\u0443\u043b\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0421\u0423\u0411\u0414, \u0438\u043b\u0438\u00a0\u0432\u00a0\u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u00a0\u0436\u0435\u0441\u0442\u043a\u0438\u0439 <code>FOR UPDATE<\/code>?<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u043b\u044e\u0431\u044b\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c! <\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1074366\/\">https:\/\/habr.com\/ru\/articles\/1074366\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, \u0425\u0430\u0431\u0440\u043e\u0432\u0447\u0430\u043d\u0435! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u043c\u0438\u0442\u0440\u0438\u0439, \u044f \u0431\u044d\u043a\u0435\u043d\u0434 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a Java. \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430\u00a0\u0437\u0430\u0434\u0430\u0447\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u043d\u0435 \u043a\u043e\u043f\u0435\u0435\u0447\u043d\u043e\u0439, \u0430\u00a0\u043f\u043e\u0442\u043e\u043c \u0441\u043e\u0436\u0440\u0430\u043b\u0430 \u043d\u0435\u0434\u0435\u043b\u044e \u0432\u0435\u0447\u0435\u0440\u043e\u0432 \u0438 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043b\u0430 \u0437\u0430\u043b\u0435\u0437\u0442\u044c \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u0432\u00a0\u0434\u0435\u0431\u0440\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 PostgreSQL.\u0412\u0441\u0451 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0441\u00a0\u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0434\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u043d\u043e\u0439 \u043a\u043b\u0438\u043d\u0438\u043a\u0438. \u041f\u043e\u043d\u0430\u0447\u0430\u043b\u0443 \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e\u00a0\u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439: \u043f\u0430\u0446\u0438\u0435\u043d\u0442 \u0445\u043e\u0447\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u00a0\u041c\u0420\u0422 \u0441\u00a0\u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0442\u043e\u043c. \u041e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u044c \u0437\u0430\u043f\u0438\u0441\u0438 (\u0432\u0440\u043e\u0434\u0435 Calendly \u0438\u043b\u0438\u00a0\u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 YClients) \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043c\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 \u0432\u0440\u0435\u043c\u044f. \u041d\u043e\u00a0\u043d\u0430\u00a0\u0434\u0435\u043b\u0435 \u0432\u0441\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u0435\u00a0\u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e&#8230; \u0427\u0442\u043e\u0431\u044b \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043b\u0430\u0441\u044c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0437\u0430\u043d\u044f\u0442\u044c \u043d\u0430\u00a0\u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442\u00a0\u0436\u0435 \u0447\u0430\u0441 \u0442\u0440\u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:\u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0432\u0440\u0430\u0447\u0430\u2011\u0440\u0430\u0434\u0438\u043e\u043b\u043e\u0433\u0430 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043c\u0435\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u0438 \u0441\u043d\u0438\u043c\u043a\u0438).\u0421\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439 \u043a\u0430\u0431\u0438\u043d\u0435\u0442, \u0433\u0434\u0435 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0442\u043e\u0438\u0442 \u0442\u043e\u043c\u043e\u0433\u0440\u0430\u0444.\u041d\u0443 \u0438 \u0441\u0430\u043c\u044b\u0439 \u0434\u043e\u0440\u043e\u0433\u043e\u0439 \u0440\u0435\u0441\u0443\u0440\u0441\u00a0\u2014 \u044d\u0442\u043e \u0442\u043e\u043c\u043e\u0433\u0440\u0430\u0444, \u043a\u043e\u0442\u043e\u0440\u044b\u0439\u00a0\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u00a0\u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u0442\u044c \u043d\u0438 \u043c\u0438\u043d\u0443\u0442\u044b!\u0415\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437\u00a0\u044d\u0442\u0438\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0437\u0430\u043d\u044f\u0442, \u0438\u043b\u0438\u00a0\u0433\u0440\u0430\u0444\u0438\u043a \u0443\u00a0\u0432\u0440\u0430\u0447\u0430 \u043d\u0435\u00a0\u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441\u00a0\u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c, \u0442\u043e \u0432\u0441\u0435, \u0441\u043b\u043e\u0442\u0430 \u043d\u0435\u0442. \u0413\u043e\u0442\u043e\u0432\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430\u00a0\u0440\u044b\u043d\u043a\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043f\u043e\u00a0\u0441\u0445\u0435\u043c\u0435 \u00ab\u043e\u0434\u0438\u043d \u043a\u043b\u0438\u0435\u043d\u0442\u00a0\u2014 \u043e\u0434\u0438\u043d \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u00bb, \u0430\u00a0\u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0435 \u00ab\u043c\u0443\u043b\u044c\u0442\u0438\u2011\u0440\u0435\u0441\u0443\u0440\u0441\u043d\u043e\u0435 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u00bb \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0434\u043a\u043e, \u044f \u0441\u0445\u043e\u0434\u0443 \u043d\u0435\u00a0\u043d\u0430\u0448\u0435\u043b. \u0418 \u0432\u043e\u0442 \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043b\u0435\u0433\u043a\u0438\u0439 b2b\u2011\u0434\u0432\u0438\u0436\u043e\u043a \u0442\u0430\u0439\u043c\u2011\u0441\u043b\u043e\u0442\u043e\u0432 \u043d\u0430 Java 17\u00a0\u0438 Spring Boot 3, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f\u00a0\u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u0438\u0437\u043e\u043b\u0438\u0440\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439 (SaaS) \u0438 \u043d\u0430\u043c\u0435\u0440\u0442\u0432\u043e \u0437\u0430\u0449\u0438\u0449\u0435\u043d \u043e\u0442\u00a0\u043e\u0432\u0435\u0440\u0431\u0443\u043a\u0438\u043d\u0433\u0430. \u0420\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e, \u043a\u0430\u043a\u00a0\u044f \u044d\u0442\u043e \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0438 \u043d\u0430\u00a0\u043a\u0430\u043a\u0438\u0435 \u0433\u0440\u0430\u0431\u043b\u0438 \u043d\u0430\u0441\u0442\u0443\u043f\u0438\u043b \u0432\u00a0\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435. \u0413\u0440\u0430\u0431\u043b\u0438 \u2116\u00a01: \u041a\u0430\u043a\u00a0\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435? \u041f\u0435\u0440\u0432\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u0433\u0434\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u044c start_time \u0438 end_time \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u044f\u043c\u043e \u0432\u00a0\u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0440\u0430\u0447\u0430), \u043d\u0435\u0442 \u044d\u0442\u043e \u043d\u0435\u00a0\u0433\u043e\u0434\u0438\u0442\u0441\u044f&#8230; \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u0438\u0437\u043d\u0435\u0441\u0430\u00a0\u2014 \u044d\u0442\u043e \u0445\u0430\u043e\u0441. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0440\u0430\u0447 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 9\u00a0\u0434\u043e 13, \u043f\u043e\u0442\u043e\u043c \u0443\u00a0\u043d\u0435\u0433\u043e \u043e\u0431\u0435\u0434, \u043f\u043e\u0442\u043e\u043c \u0432\u0442\u043e\u0440\u0430\u044f \u0441\u043c\u0435\u043d\u0430 \u0441 16\u00a0\u0434\u043e 20. \u0410\u00a0\u0432\u00a0\u043f\u044f\u0442\u043d\u0438\u0446\u0443 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u043e\u0447\u043d\u043e\u0435 \u0434\u0435\u0436\u0443\u0440\u0441\u0442\u0432\u043e.\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u044f \u0441\u0440\u0430\u0437\u0443 \u0432\u044b\u043d\u0435\u0441 \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0432\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 (resource_availability_intervals). \u0410\u00a0\u0441\u0430\u043c\u043e \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0430\u043b \u0441\u00a0\u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e Many\u2011to\u2011Many \u0432\u00a0Spring Data Entities.\u0412\u043e\u0442 \u043a\u0430\u043a\u00a0\u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u0445\u0435\u043c\u0430 \u0442\u0430\u0431\u043b\u0438\u0446 \u0432\u00a0SQL:CREATE TABLE resources (  id BIGSERIAL PRIMARY KEY,   name VARCHAR(255) NOT NULL,   type VARCHAR(50) NOT NULL,  timezone VARCHAR(100) NOT NULL DEFAULT &#8216;UTC&#8217;);CREATE TABLE resource_availability_intervals (  id BIGSERIAL PRIMARY KEY,   resource_id BIGINT NOT NULL REFERENCES resources(id) ON DELETE CASCADE,   day_of_week VARCHAR(15) NOT NULL,   start_time TIME NOT NULL,   end_time TIME NOT NULL);CREATE TABLE bookings (    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),    company_id BIGINT NOT NULL REFERENCES companies(id) ON DELETE CASCADE,    status VARCHAR(50) NOT NULL DEFAULT &#8216;CONFIRMED&#8217;,    start_time TIMESTAMP WITH TIME ZONE NOT NULL,    end_time TIMESTAMP WITH TIME ZONE NOT NULL);&#8212; \u041c\u043e\u0441\u0442 Many-to-ManyCREATE TABLE booking_resources (    booking_id UUID NOT NULL REFERENCES bookings(id) ON DELETE CASCADE,    resource_id BIGINT NOT NULL REFERENCES resources(id) ON DELETE CASCADE,    PRIMARY KEY (booking_id, resource_id));\u0421\u00a0\u0442\u0430\u043a\u043e\u0439 \u0441\u0445\u0435\u043c\u043e\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043f\u043e\u0434\u00a0\u043e\u0434\u043d\u0438\u043c UUID \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0445\u043e\u0442\u044c \u0432\u0440\u0430\u0447\u0430, \u0445\u043e\u0442\u044c \u0442\u043e\u043c\u043e\u0433\u0440\u0430\u0444, \u0445\u043e\u0442\u044c \u043f\u0430\u0440\u043a\u043e\u0432\u043e\u0447\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f\u00a0\u043a\u0443\u0440\u044c\u0435\u0440\u0430. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0432\u00a0\u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u043b \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0449\u0435\u0433\u043e \u0441\u043b\u043e\u0442\u0430 \u0434\u043b\u044f\u00a0\u0432\u0441\u0435\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 (resource_availability_intervals) \u0437\u0430\u00a0\u0432\u044b\u0447\u0435\u0442\u043e\u043c \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0431\u0440\u043e\u043d\u0435\u0439 \u0432\u0441\u0435\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0446\u0435\u043f\u043e\u0447\u043a\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0435\u0441\u0442\u044c (bookings). \u0413\u0440\u0430\u0431\u043b\u0438 \u2116\u00a02: \u0414\u0432\u043e\u0439\u043d\u044b\u0435 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 Race Condition \u0415\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 \u0432\u044b\u0441\u043e\u043a\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0446\u0435\u043d\u0442\u0440, \u043a\u0443\u0434\u0430 \u043b\u043e\u043c\u0438\u0442\u0441\u044f 100\u00a0\u0444\u0443\u0440 \u043d\u0430\u00a0\u0440\u0430\u0437\u0433\u0440\u0443\u0437\u043a\u0443), \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u0430\u0441 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0442. \u0427\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043a\u043e\u0433\u0434\u0430 \u0434\u043b\u044f\u00a0\u0434\u0432\u0443\u0445 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0434\u0432\u0430 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u00ab\u0417\u0430\u043d\u044f\u0442\u044c \u043d\u0430 14:00\u00bb, \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442 \u043e\u0431\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u043e\u0432\u0435\u0440\u0431\u0443\u043a\u0438\u043d\u0433, \u0438 \u043d\u0430\u0447\u043d\u0443\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u043e\u0440\u043a\u0438 \u043a\u0442\u043e \u0432\u0438\u043d\u043e\u0432\u0430\u0442 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0427\u0442\u043e\u00a0\u0436\u0435 \u0434\u0435\u043b\u0430\u0442\u044c? \u0421\u0430\u043c\u043e\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u00a0\u0433\u043e\u043b\u043e\u0432\u0443\u00a0\u2014 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u0435\u0441\u0441\u0438\u043c\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u043d\u0430\u00a0\u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0442\u0440\u043e\u043a \u0421\u0423\u0411\u0414 (Pessimistic Write Lock). \u0427\u0442\u043e\u00a0\u0436 \u0434\u0435\u043b\u0430\u0435\u043c \u0438\u0445 \u043c\u043e\u0434\u043d\u043e \u0432\u00a0JPA \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438: public interface ResourceRepository extends JpaRepository&lt;Resource, Long&gt; {  @Lock(LockModeType.PESSIMISTIC_WRITE)  List&lt;Resource&gt; findByIdInAndCompanyId(Set&lt;Long&gt; ids, Long companyId);  &#8230;}\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u043c\u0435\u0442\u043e\u0434 findByIdInAndCompanyId \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, Hibernate \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 SQL\u2011\u0437\u0430\u043f\u0440\u043e\u0441 SELECT &#8230; FOR UPDATE. PostgreSQL \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u00a0\u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438. \u0418 \u0442\u043e\u0433\u0434\u0430 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a\u00a0\u044d\u0442\u0438\u043c\u00a0\u0436\u0435 IDs \u0432\u0441\u0442\u0430\u0435\u0442 \u0432\u00a0\u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438 \u043a\u0443\u0440\u0438\u0442 \u0431\u0430\u043c\u0431\u0443\u043a, \u043f\u043e\u043a\u0430 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043d\u0435\u00a0\u0441\u0434\u0435\u043b\u0430\u0435\u0442 COMMIT \u0438\u043b\u0438 ROLLBACK. \u0422.\u043e. \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u0442\u0430\u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443, \u0443\u0440\u0430, \u0432\u0441\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0435\u0434\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435!\u0413\u0440\u0430\u0431\u043b\u0438 \u2116\u00a03: \u041d\u043e\u0447\u043d\u044b\u0435 \u0441\u043c\u0435\u043d\u044b \u0438 \u0445\u0430\u043e\u0441 \u0441\u00a0\u0447\u0430\u0441\u043e\u0432\u044b\u043c\u0438 \u043f\u043e\u044f\u0441\u0430\u043c\u0438\u041d\u0443 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0432\u0441\u0442\u0430\u043b \u0432\u043e\u043f\u0440\u043e\u0441 \u043a\u0430\u043a\u00a0\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u043a\u0430\u043a\u00a0\u0443\u0447\u0435\u0441\u0442\u044c \u0442\u0430\u0439\u043c\u0437\u043e\u043d\u044b? \u041d\u043e\u00a0\u044d\u0442\u043e \u043f\u043e\u043b \u0431\u0435\u0434\u044b, \u0435\u0441\u0442\u044c\u00a0\u0436\u0435 \u0435\u0449\u0435 \u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441\u00a0\u0442\u0435\u043c, \u0447\u0442\u043e\u00a0\u0433\u0440\u0430\u0444\u0438\u043a \u0440\u0435\u0441\u0443\u0440\u0441\u0430 \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u043d\u043e\u0447\u043d\u044b\u043c \u0438\u043b\u0438 \u00ab\u0440\u0432\u0430\u043d\u044b\u043c\u00bb. \u042f \u0432\u0432\u0435\u043b\u00a0\u0436\u0435\u0441\u0442\u043a\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0437\u043e\u043d \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438:\u0420\u0430\u0431\u043e\u0447\u0438\u0435 \u0433\u0440\u0430\u0444\u0438\u043a\u0438 (\u0418\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438) \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u00a0\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0412\u00a0\u0431\u0430\u0437\u0435 \u043b\u0435\u0436\u0430\u0442 \u0447\u0438\u0441\u0442\u044b\u0435 LocalTime (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 09:00:00\u00a0\u2014 18:00:00) \u043f\u043b\u044e\u0441 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0447\u0430\u0441\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u044f\u0441\u0430 (IANA ID, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Europe\/Moscow), \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u00a0\u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c.C\u0435\u0442\u043a\u0430 \u0441\u043b\u043e\u0442\u043e\u0432 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u0433\u043e \u0432\u00a0\u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0448\u043a\u0430\u043b\u044b\u00a0\u2014 OffsetDateTime (UTC \u0441\u00a0\u043d\u0443\u043b\u0435\u0432\u044b\u043c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435\u043c Z).\u0427\u0442\u043e\u00a0\u0436\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u00a0\u043d\u043e\u0447\u043d\u044b\u043c\u0438 \u0441\u043c\u0435\u043d\u0430\u043c\u0438? \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0443\u00a0\u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430 \u0441\u043c\u0435\u043d\u0430 \u0441 22:00\u00a0\u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a\u0430 \u0434\u043e 06:00\u00a0\u0443\u0442\u0440\u0430 \u0432\u0442\u043e\u0440\u043d\u0438\u043a\u0430&#8230; \u0411\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u044f\u0436\u0435\u043b\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u0447\u0442\u043e 06:00\u00a0\u2014 \u044d\u0442\u043e \u043f\u043e\u0437\u0436\u0435, \u0447\u0435\u043c 22:00. \u0418 \u0442\u0443\u0442 \u043f\u043e\u0438\u0441\u043a\u0430\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u043f\u0430\u0442\u0442\u0435\u0440\u043d Midnight Splitting (\u0434\u0440\u043e\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u00a0\u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u0441\u0443\u0442\u043e\u043a). \u0412\u00a0\u0438\u0442\u043e\u0433\u0435 \u043f\u0440\u0438\u00a0\u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0432\u044b\u0448\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432:\u0417\u0430\u043f\u0438\u0441\u044c 1: day_of_week: MONDAY, start_time: 22:00:00, end_time: 23:59:59\u0417\u0430\u043f\u0438\u0441\u044c 2: day_of_week: TUESDAY, start_time: 00:00:00, end_time: 06:00:00private boolean isResourceAvailableInItsSchedule(Resource resource, OffsetDateTime startUtc, OffsetDateTime endUtc) {    ZoneId resourceZone = ZoneId.of(resource.getTimezone());        \/\/ \u041f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043c \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0435 UTC \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u044f\u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430    ZonedDateTime localStart = startUtc.atZoneSameInstant(resourceZone);    ZonedDateTime localEnd = endUtc.atZoneSameInstant(resourceZone);        DayOfWeek startDay = localStart.getDayOfWeek();    LocalTime startTime = localStart.toLocalTime();    LocalTime endTime = localEnd.toLocalTime();    \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0441\u0443\u0442\u043e\u043a \u043d\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e    return resource.getAvailabilityIntervals().stream()            .filter(i -&gt; i.getDayOfWeek() == startDay)            .anyMatch(i -&gt; !startTime.isBefore(i.getStartTime()) &amp;&amp; !endTime.isAfter(i.getEndTime()));}\u0422.\u043e. \u0438\u0449\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0438 \u043f\u043e\u00a0\u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a\u0443 \u0438 \u043f\u043e\u00a0\u0432\u0442\u043e\u0440\u043d\u0438\u043a\u0443, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043e\u0434\u043d\u0430 \u0441\u043c\u0435\u043d\u0430. \u0414\u0430\u00a0\u0438 \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0431\u043b\u0430\u0433\u043e\u043f\u0440\u0438\u044f\u0442\u043d\u043e \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u00a0SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043f\u043e\u00a0\u043f\u043e\u043b\u044f\u043c \u0434\u0430\u0442 \u043d\u0430\u0447\u0430\u043b\u0430 \u0438 \u043a\u043e\u043d\u0446\u0430 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0447\u0442\u043e\u00a0\u0432\u00a0\u0431\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043b\u044f\u00a0\u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043e\u0442\u0447\u0435\u0442\u043e\u0432 \u0438 \u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435\u041d\u0435\u00a0\u0413\u0440\u0430\u0431\u043b\u0438 4: \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c\u00a0\u2014 \u0438\u0437\u043e\u043b\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u043f\u043e\u00a0API \u043a\u043b\u044e\u0447\u0430\u043c\u0427\u0442\u043e\u00a0\u0431\u044b API \u043c\u043e\u0433\u043b\u043e \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u0442\u044b\u0441\u044f\u0447\u0438 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u043d\u0435\u00a0\u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044f \u0443\u0442\u0435\u0447\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u044f \u0432\u0432\u0435\u043b \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u00a0company_id. \u041a\u043e\u043d\u0435\u0447\u043d\u043e,\u00a0\u0431\u044b\u043b\u043e\u00a0\u0431\u044b \u043f\u0440\u043e\u0449\u0435, \u0435\u0441\u043b\u0438 \u0432\u00a0\u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u00a0\u0431\u044b \u044d\u0442\u043e\u0442 company_id, \u0432\u00a0\u043a\u043e\u0434\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0448\u044c \u043f\u043e\u00a0\u043d\u0435\u043c\u0443 \u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u0445\u043e\u0440\u043e\u0448\u043e. \u041d\u043e\u00a0\u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0442\u0430\u043a \u043d\u0435\u043b\u044c\u0437\u044f, \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043d\u0435\u00a0\u0434\u043e\u043b\u0436\u043d\u044b \u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435\u2011\u043b\u0438\u0431\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437\u00a0\u0411\u0414, \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 IDs. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 company_id \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e \u043d\u0430\u00a0\u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (Authorization: Bearer Token) \u0414\u043b\u044f\u00a0\u044d\u0442\u043e\u0433\u043e \u043f\u0438\u0448\u0435\u043c HandlerInterceptor \u0438\u0437\u00a0\u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b Spring MVC, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 REST \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430\u00a0\u0432\u0445\u043e\u0434\u0435, \u0438 \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u0442 company_id \u043f\u043e\u00a0\u0442\u043e\u043a\u0435\u043d\u0443, \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u0442 \u0435\u0433\u043e \u0432\u00a0\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0447\u0435\u0440\u0435\u0437 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430: @Componentpublic class ApiKeyInterceptor implements HandlerInterceptor {    private final ApiKeyRepository apiKeyRepository;    public ApiKeyInterceptor(ApiKeyRepository apiKeyRepository) {        this.apiKeyRepository = apiKeyRepository;    }    @Override    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {        String authHeader = request.getHeader(&#171;Authorization&#187;);        if (authHeader == null || !authHeader.startsWith(&#171;Bearer &#171;)) {            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);            response.getWriter().write(&#171;Missing or invalid Authorization header&#187;);            return false;        }        String token = authHeader.substring(7);        Optional&lt;Long&gt; companyIdOpt = apiKeyRepository.findCompanyIdByToken(token);        if (companyIdOpt.isEmpty()) {            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);            response.getWriter().write(&#171;Invalid or inactive API key&#187;);            return false;        }        \/\/ \u041f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c ID \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430        request.setAttribute(&#171;CURRENT_COMPANY_ID&#187;, companyIdOpt.get());        return true;    }}\u041a\u0430\u043a\u00a0\u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0442\u0443\u0442 \u044d\u0442\u043e \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0442\u043e\u043a\u0435\u043d String token = authHeader.substring(7);, \u043d\u0430\u0439\u0442\u0438 \u043f\u043e\u00a0\u043d\u0435\u043c\u0443 company_id \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u043f\u0443  apiKeyRepository.findCompanyIdByToken(token) \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0435\u0433\u043e \u0432\u00a0\u0440\u0435\u043a\u0432\u0435\u0441\u0442 \u0443\u0436\u0435 \u043d\u0430\u00a0\u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0431\u044d\u043a\u0435\u043d\u0434\u0430 request.setAttribute(\u201cCURRENT_COMPANY_ID\u201d, companyIdOpt.get()); \u0412\u043e\u0442 \u0438 \u0432\u0441\u0435, \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0437\u043d\u0430\u044e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e \u0447\u0442\u043e\u00a0\u0438\u043c \u043d\u0443\u0436\u043d\u043e\u00a0\u2014 \u0441\u0432\u043e\u0439 API Key \u0438 \u043d\u0438\u0447\u0435\u0433\u043e\u00a0\u043b\u0438\u0448\u043d\u0435\u0433\u043e!\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435:\u0412\u00a0\u0438\u0442\u043e\u0433\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u0433\u043e\u0442\u043e\u0432 \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d, \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430\u00a0Github\u00a0\u2014 https:\/\/github.com\/Razzhivin\/slots\u2011api\u0412\u00a0readme \u044f \u043e\u043f\u0438\u0441\u0430\u043b \u043a\u0430\u043a\u00a0\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u00a0\u043f\u0430\u0440\u0443 \u043c\u0438\u043d\u0443\u0442 \u043a\u0430\u043a\u00a0Docker\u2011\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0432\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0441\u00a0\u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c API Key \u0442\u0430\u043c\u00a0\u0436\u0435!\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c \u0432\u0430\u0448\u0435 \u043c\u043d\u0435\u043d\u0438\u0435:\u041a\u0430\u043a\u00a0\u0431\u044b \u0432\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0442\u043e\u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430\u00a0\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\u0445 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438\u00a0\u043f\u043e\u0438\u0441\u043a\u0435 \u0441\u043b\u043e\u0442\u043e\u0432 \u043d\u0430\u00a0\u0433\u043e\u0434 \u0432\u043f\u0435\u0440\u0435\u0434)? \u0421\u0442\u043e\u0438\u0442\u00a0\u043b\u0438 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0443\u044e \u0441\u0435\u0442\u043a\u0443 \u0432\u00a0Redis?\u0415\u0441\u0442\u044c\u00a0\u043b\u0438 \u0441\u043c\u044b\u0441\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 (@Version) \u0434\u043b\u044f\u00a0\u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430\u00a0\u043f\u0443\u043b\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0421\u0423\u0411\u0414, \u0438\u043b\u0438\u00a0\u0432\u00a0\u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u00a0\u0436\u0435\u0441\u0442\u043a\u0438\u0439 FOR UPDATE?\u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u043b\u044e\u0431\u044b\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c! \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1074366\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-492166","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/492166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=492166"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/492166\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=492166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=492166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=492166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}