修改月报表
This commit is contained in:
parent
4fe61d5c4c
commit
d45a8140c0
@ -37,7 +37,7 @@ class CardController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$cards = $this->cardService->index($conditions);
|
$cards = $this->cardService->index($conditions);
|
||||||
|
|
||||||
return res($cards, '卡列表', 201);
|
return res($cards, '卡列表', 201);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ trait OrderCardConcern
|
|||||||
|
|
||||||
if (isset($conditions['month'])) {
|
if (isset($conditions['month'])) {
|
||||||
$conditions['month'] = (int)Carbon::parse($conditions['month'])->format('Ym');
|
$conditions['month'] = (int)Carbon::parse($conditions['month'])->format('Ym');
|
||||||
$query->whereRaw("timelines_array(sim) @> '{{$conditions['month']}}'");
|
$query->whereRaw("timelines_index(id, sim) @> '{{$conditions['month']}}'");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ BEGIN
|
|||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
query := 'SELECT
|
query := 'SELECT
|
||||||
|
virtual_order_cards_partition.id,
|
||||||
virtual_order_cards_partition.type,
|
virtual_order_cards_partition.type,
|
||||||
virtual_order_cards_partition.package_id,
|
virtual_order_cards_partition.package_id,
|
||||||
virtual_order_cards_partition.created_at,
|
virtual_order_cards_partition.created_at,
|
||||||
@ -61,7 +62,7 @@ BEGIN
|
|||||||
temp_service_end_at := temp_service_start_at + (order_row.service_months || ' month')::INTERVAL + (order_row.delay_months || ' month')::INTERVAL - '1 second'::INTERVAL;
|
temp_service_end_at := temp_service_start_at + (order_row.service_months || ' month')::INTERVAL + (order_row.delay_months || ' month')::INTERVAL - '1 second'::INTERVAL;
|
||||||
END CASE;
|
END CASE;
|
||||||
|
|
||||||
temp_text := format('{"sim": %s, "type": %s, "package_id": %s, "service_start_at": "%s", "service_end_at": "%s"}', sim, order_row.type, order_row.package_id, temp_service_start_at, temp_service_end_at);
|
temp_text := format('{"id": %s, "sim": %s, "type": %s, "package_id": %s, "service_start_at": "%s", "service_end_at": "%s"}', order_row.id, sim, order_row.type, order_row.package_id, temp_service_start_at, temp_service_end_at);
|
||||||
timelines := timelines::JSONB || temp_text::JSONB;
|
timelines := timelines::JSONB || temp_text::JSONB;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
RETURN timelines;
|
RETURN timelines;
|
||||||
@ -99,40 +100,7 @@ END;
|
|||||||
$$
|
$$
|
||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION TIMELINES_ARRAY (sim INT8, activated_at TIMESTAMP)
|
CREATE OR REPLACE FUNCTION TIMELINES_INDEX (id INT, sim INT8)
|
||||||
RETURNS INT[]
|
|
||||||
AS $$
|
|
||||||
DECLARE
|
|
||||||
timelines INT[] := '{}';
|
|
||||||
timelines_json JSONB;
|
|
||||||
item JSONB;
|
|
||||||
temp_months INT;
|
|
||||||
i INT;
|
|
||||||
BEGIN
|
|
||||||
IF activated_at IS NULL THEN
|
|
||||||
RETURN timelines;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
timelines_json := vd.TIMELINES_JSON(sim, activated_at);
|
|
||||||
|
|
||||||
FOR item IN SELECT * FROM json_array_elements(timelines_json::JSON) LOOP
|
|
||||||
temp_months = (TO_CHAR((item->>'service_end_at')::TIMESTAMP, 'YYYY')::INT - TO_CHAR((item->>'service_start_at')::TIMESTAMP, 'YYYY')::INT) * 12
|
|
||||||
+ (TO_CHAR((item->>'service_end_at')::TIMESTAMP, 'MM')::INT - TO_CHAR((item->>'service_start_at')::TIMESTAMP, 'MM')::INT);
|
|
||||||
i := 0;
|
|
||||||
|
|
||||||
RAISE NOTICE 'TIMELINES_ARRAY: % - % - %', item->>'sim', item->>'package_id', temp_months;
|
|
||||||
|
|
||||||
WHILE i <= temp_months LOOP
|
|
||||||
timelines := timelines || TO_CHAR((item->>'service_start_at')::TIMESTAMP + (i || ' month')::INTERVAL, 'YYYYMM')::INT;
|
|
||||||
i := i + 1;
|
|
||||||
END LOOP;
|
|
||||||
END LOOP;
|
|
||||||
RETURN timelines;
|
|
||||||
END;
|
|
||||||
$$
|
|
||||||
LANGUAGE plpgsql IMMUTABLE;
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION TIMELINES_ARRAY (sim INT8)
|
|
||||||
RETURNS INT[]
|
RETURNS INT[]
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -143,18 +111,19 @@ DECLARE
|
|||||||
i INT;
|
i INT;
|
||||||
BEGIN
|
BEGIN
|
||||||
timelines_json := vd.TIMELINES_JSON(sim);
|
timelines_json := vd.TIMELINES_JSON(sim);
|
||||||
|
|
||||||
FOR item IN SELECT * FROM json_array_elements(timelines_json::JSON) LOOP
|
FOR item IN SELECT * FROM json_array_elements(timelines_json::JSON) LOOP
|
||||||
temp_months = (TO_CHAR((item->>'service_end_at')::TIMESTAMP, 'YYYY')::INT - TO_CHAR((item->>'service_start_at')::TIMESTAMP, 'YYYY')::INT) * 12
|
IF item->>'id'::INT = id THEN
|
||||||
+ (TO_CHAR((item->>'service_end_at')::TIMESTAMP, 'MM')::INT - TO_CHAR((item->>'service_start_at')::TIMESTAMP, 'MM')::INT);
|
temp_months = (TO_CHAR((item->>'service_end_at')::TIMESTAMP, 'YYYY')::INT - TO_CHAR((item->>'service_start_at')::TIMESTAMP, 'YYYY')::INT) * 12
|
||||||
i := 0;
|
+ (TO_CHAR((item->>'service_end_at')::TIMESTAMP, 'MM')::INT - TO_CHAR((item->>'service_start_at')::TIMESTAMP, 'MM')::INT);
|
||||||
|
i := 0;
|
||||||
|
|
||||||
RAISE NOTICE 'TIMELINES_ARRAY: % - % - %', item->>'sim', item->>'package_id', temp_months;
|
RAISE NOTICE 'TIMELINES_INDEX: % - % - %', item->>'sim', item->>'package_id', temp_months;
|
||||||
|
|
||||||
WHILE i <= temp_months LOOP
|
WHILE i <= temp_months LOOP
|
||||||
timelines := timelines || TO_CHAR((item->>'service_start_at')::TIMESTAMP + (i || ' month')::INTERVAL, 'YYYYMM')::INT;
|
timelines := timelines || TO_CHAR((item->>'service_start_at')::TIMESTAMP + (i || ' month')::INTERVAL, 'YYYYMM')::INT;
|
||||||
i := i + 1;
|
i := i + 1;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
|
END IF;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
RETURN timelines;
|
RETURN timelines;
|
||||||
END;
|
END;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
-- 服务周期索引
|
-- 服务周期索引
|
||||||
CREATE INDEX "virtual_order_cards_timelines_index" ON "virtual_order_cards" USING GIN (timelines_array(sim));
|
CREATE INDEX "virtual_order_cards_timelines_index" ON "virtual_order_cards" USING GIN (TIMELINES_INDEX(id, sim));
|
||||||
CREATE INDEX "virtual_order_renewal_cards_timelines_index" ON "virtual_order_renewal_cards" USING GIN (timelines_array(sim));
|
CREATE INDEX "virtual_order_renewal_cards_timelines_index" ON "virtual_order_renewal_cards" USING GIN (TIMELINES_INDEX(id, sim));
|
||||||
CREATE INDEX "virtual_order_renewal_package_cards_timelines_index" ON "virtual_order_renewal_package_cards" USING GIN (timelines_array(sim));
|
CREATE INDEX "virtual_order_renewal_package_cards_timelines_index" ON "virtual_order_renewal_package_cards" USING GIN (TIMELINES_INDEX(id, sim));
|
||||||
CREATE INDEX "virtual_order_flows_package_cards_index" ON "virtual_order_flows_package_cards" USING GIN (timelines_array(sim));
|
CREATE INDEX "virtual_order_flows_package_cards_index" ON "virtual_order_flows_package_cards" USING GIN (TIMELINES_INDEX(id, sim));
|
||||||
|
|
||||||
-- 增删改卡表时更新索引
|
-- 增删改卡表时更新索引
|
||||||
CREATE OR REPLACE FUNCTION REINDEX_TIMELINES ()
|
CREATE OR REPLACE FUNCTION REINDEX_TIMELINES ()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user