Skip to content

Commit

Permalink
added new column to big order table view (#1577)
Browse files Browse the repository at this point in the history
  • Loading branch information
KizerovDmitriy authored Jan 6, 2025
1 parent 4aa31f5 commit d984f6b
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class BigOrderTableViews {
private Long textileWaste60;
@Column(name = "textile_waste_20")
private Long textileWaste20;
@Column(name = "other_packages")
private String otherPackages;
private Long totalOrderSum;
private String orderCertificateCode;
private Long generalDiscount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class TableColumnWidthForEmployee {
private Integer textileWaste60L = DEFAULT_WIDTH_FOR_WASTE;
@Column(name = "textile_waste_20l")
private Integer textileWaste20L = DEFAULT_WIDTH_FOR_WASTE;
@Column(name = "other_packages")
private Integer otherPackages = DEFAULT_WIDTH_FOR_WASTE;
@Column
private Integer blockedBy = DEFAULT_WIDTH;
@Column
Expand Down
5 changes: 4 additions & 1 deletion dao/src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,8 @@
<include file="db/changelog/logs/2024-11-28-change-add-column-isTableFreeze-to-column_width_for_employee-Warded120.xml"/>
<include file="db/changelog/logs/2024-12-18-update-column_width_for_employee-Kizerov.xml"/>
<include file="db/changelog/logs/ch-add-column-reason-into-change-of-points-table-Chernenko.xml"/>
<include file="db/changelog/logs/2024-12-18-add-new-column-to-user-table-Kizerov.xml"/>
<include file="db/changelog/logs/2024-12-18-add-new-column-to-user-table-Kizerov.xml"/>
<include file="db/changelog/logs/add-other-packages-to-column_width_for_employee-table.xml"/>
<include file="db/changelog/logs/add-new-column-to-big_order_table-view.xml"/>
<include file="db/changelog/logs/update-custom_table_view-table.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<changeSet id="2025-01-04-delete-big-order-table-view" author="Kizerov Dmytro">
<dropView viewName="big_order_table"/>
</changeSet>

<changeSet id="2025-01-04-add-new-column-to-big_order_table" author="Kizerov Dmytro">
<createView viewName="big_order_table" replaceIfExists="true">
WITH group_capacity AS (
SELECT
obm.order_id,
SUM(CASE
WHEN bag.capacity = 120 AND bag.name_eng = 'Mix waste' THEN
CASE
WHEN (SELECT SUM(obm1.confirmed_quantity)
FROM order_bag_mapping obm1
WHERE obm1.order_id = obm.order_id) IS NULL
AND (SELECT SUM(obm2.exported_quantity)
FROM order_bag_mapping obm2
WHERE obm2.order_id = obm.order_id) IS NULL
THEN obm.amount
WHEN (SELECT SUM(obm2.exported_quantity)
FROM order_bag_mapping obm2
WHERE obm2.order_id = obm.order_id) IS NULL
THEN obm.confirmed_quantity
ELSE obm.exported_quantity
END
ELSE 0
END) AS mixed_waste_120,
SUM(CASE
WHEN bag.capacity = 60 AND bag.name_eng = 'Textile waste' THEN
CASE
WHEN (SELECT SUM(obm1.confirmed_quantity)
FROM order_bag_mapping obm1
WHERE obm1.order_id = obm.order_id) IS NULL
AND (SELECT SUM(obm2.exported_quantity)
FROM order_bag_mapping obm2
WHERE obm2.order_id = obm.order_id) IS NULL
THEN obm.amount
WHEN (SELECT SUM(obm2.exported_quantity)
FROM order_bag_mapping obm2
WHERE obm2.order_id = obm.order_id) IS NULL
THEN obm.confirmed_quantity
ELSE obm.exported_quantity
END
ELSE 0
END) AS textile_waste_60,
SUM(CASE
WHEN bag.capacity = 20 AND bag.name_eng = 'Textile waste' THEN
CASE
WHEN (SELECT SUM(obm1.confirmed_quantity)
FROM order_bag_mapping obm1
WHERE obm1.order_id = obm.order_id) IS NULL
AND (SELECT SUM(obm2.exported_quantity)
FROM order_bag_mapping obm2
WHERE obm2.order_id = obm.order_id) IS NULL
THEN obm.amount
WHEN (SELECT SUM(obm2.exported_quantity)
FROM order_bag_mapping obm2
WHERE obm2.order_id = obm.order_id) IS NULL
THEN obm.confirmed_quantity
ELSE obm.exported_quantity
END
ELSE 0
END) AS textile_waste_20,
STRING_AGG(
CASE
WHEN bag.name_eng NOT IN ('Mix waste', 'Textile waste') THEN
CASE
WHEN (SELECT SUM(obm1.confirmed_quantity)
FROM order_bag_mapping obm1
WHERE obm1.order_id = obm.order_id) IS NULL
AND (SELECT SUM(obm2.exported_quantity)
FROM order_bag_mapping obm2
WHERE obm2.order_id = obm.order_id) IS NULL
THEN CONCAT(bag.name, ' ', bag.capacity, 'л - ', obm.amount, 'шт')
WHEN (SELECT SUM(obm2.exported_quantity)
FROM order_bag_mapping obm2
WHERE obm2.order_id = obm.order_id) IS NULL
THEN CONCAT(bag.name, ' ', bag.capacity, 'л - ', obm.confirmed_quantity, 'шт')
ELSE CONCAT(bag.name, ' ', bag.capacity, 'л - ', obm.exported_quantity, 'шт')
END
END,
', '
) AS other_packages
FROM
order_bag_mapping obm
LEFT JOIN
bag ON obm.bag_id = bag.id
GROUP BY
obm.order_id
)
SELECT
o.id AS id,
o.order_status AS order_status,
o.order_payment_status AS order_payment_status,
CAST(o.order_date AS DATE) AS order_date,
CAST((SELECT MAX(CAST(p.settlement_date AS DATE))
FROM payment p
WHERE p.order_id = o.id AND o.order_payment_status = 'PAID') AS DATE) AS payment_date,
CONCAT_WS(' ', uu.first_name, uu.last_name) AS client_name,
uu.phone_number AS client_phone_number,
uu.email AS client_email,
CONCAT_WS(' ', uu.sender_first_name, uu.sender_last_name) AS sender_name,
uu.sender_phone_number AS sender_phone,
uu.sender_email AS sender_email,
u.violations AS violations_amount,
a.region AS region,
a.city AS city,
a.district AS district,
CONCAT_WS(', ',
CONCAT(a.street, ' ', a.house_number),
CASE WHEN a.house_corpus IS NOT NULL AND a.house_corpus != '' THEN CONCAT('корп.', a.house_corpus) ELSE 'корп.- ' END,
CASE WHEN a.entrance_number IS NOT NULL AND a.entrance_number != '' THEN CONCAT('п.', a.entrance_number) ELSE 'п.- ' END
) AS address,
a.address_comment AS comment_to_address_for_client,
gc.mixed_waste_120,
gc.textile_waste_60,
gc.textile_waste_20,
gc.other_packages,
o.sum_total_amount_without_discounts AS total_order_sum,
(select string_agg(c.code,', ') from certificate c where c.order_id=o.id) as order_certificate_code,
cast(coalesce((select sum(c.points) from certificate c where c.order_id=o.id), 0)
+ coalesce(o.points_to_use, 0) as bigint) as general_discount,
cast(coalesce(o.sum_total_amount_without_discounts, 0)
- (coalesce((select sum(p.amount) from payment p where p.order_id=o.id and p.payment_status='PAID'), 0)
+ (coalesce((select sum(c.points) from certificate c where c.order_id=o.id), 0) * 100
+ coalesce(o.points_to_use, 0) * 100)) as bigint ) as amount_due,
o.comment as comment_for_order_by_client,
cast(coalesce((select sum(p.amount) from payment p where p.order_id=o.id and p.payment_status='PAID'), 0)
+ (coalesce((select sum(c.points) from certificate c where c.order_id=o.id), 0) * 100 + coalesce(o.points_to_use, 0) * 100) as bigint) as total_payment,
o.date_of_export as date_of_export,
concat_ws('-', cast(o.deliver_from as time), cast (o.deliver_to as time)) as time_of_export,
(select string_agg(oe.additional_order, '; ') from order_additional oe where oe.orders_id = o.id) as id_order_from_shop,
r.name as receiving_station,
r.id as receiving_station_id,

(select concat_ws(', ',e.first_name,e.last_name) from employee_order_position eop
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=3 ) as responsible_logic_man,
(select e.id from employee_order_position eop
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=3 ) as responsible_logic_man_id,

(select concat_ws(', ',e.first_name,e.last_name) from employee_order_position eop
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=5 ) as responsible_driver,
(select e.id from employee_order_position eop
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=5 ) as responsible_driver_id,

(select concat_ws(', ',e.first_name,e.last_name) from employee_order_position eop
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=2 ) as responsible_caller,
(select e.id from employee_order_position eop
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=2 ) as responsible_caller_id,

(select concat_ws(', ',e.first_name,e.last_name) from employee_order_position eop
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=4 ) as responsible_navigator,
(select e.id from employee_order_position eop
left join employees e on eop.employee_id = e.id where order_id =o.id and eop.position_id=4 ) as responsible_navigator_id,
o.blocked as is_blocked,
concat_ws(', ',e.first_name,e.last_name) as blocked_by,
a.region_en as region_en,
a.city_en as city_en,
a.district_en as district_en,
a.region_id as region_id,
a.city_id as city_id,
a.district_id as district_id,
concat_ws(', ',concat(a.street_en , ' ' , a.house_number),
case when (a.house_corpus) is not null and a.house_corpus != '' then concat('b.',a.house_corpus) else 'b.- ' end ,
case when (a.entrance_number) is not null and a.entrance_number != '' then concat('e.', a.entrance_number) else 'e.- ' end)
as address_en,
o.tariffs_info_id as tariffs_info_id,
o.admin_comment as comment_for_order_by_admin

from orders o
left join group_capacity gc ON o.id = gc.order_id
left join employees e on o.employee_id = e.id
left join receiving_stations r on o.receiving_station_id = r.id
left join ubs_user uu on o.ubs_user_id = uu.id
left join order_address a on uu.id = a.id
left join users u on o.users_id = u.id;
</createView>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<changeSet id="2025-01-04-add-other-packages-to-column_width_for_employee" author="Kizerov Dmytro">
<addColumn tableName="column_width_for_employee">
<column name="other_packages" type="INT"/>
</addColumn>
</changeSet>

<changeSet id="2025-01-04-update-column_width_for_employee" author="Kizerov Dmytro">
<sql>
UPDATE column_width_for_employee
SET address = 165,
amount_due = 165,
blocked_by = 165,
city = 165,
client_email = 165,
client_name = 165,
client_phone = 165,
comment_for_order_by_client = 165,
comment_to_address_for_client = 165,
comments_for_order = 165,
date_of_export = 165,
district = 165,
general_discount = 165,
order_id = 165,
id_order_from_shop = 165,
order_certificate_code = 165,
order_date = 165,
order_payment_status = 165,
order_status = 165,
payment_date = 165,
receiving_status = 165,
region = 165,
responsible_caller = 165,
responsible_driver = 165,
responsible_logic_man = 165,
responsible_navigator = 165,
sender_email = 165,
sender_name = 165,
sender_phone = 165,
time_of_export = 165,
total_order_sum = 165,
total_payment = 165,
violations_amount = 165,
mixed_waste_120l = 106,
textile_waste_60l = 106,
textile_waste_20l = 106,
other_packages = 106;
</sql>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<changeSet id="2025-01-04-update-custom_table_view" author="Kizerov Dmytro">
<sql>
UPDATE custom_table_view
SET titles = 'select,id,orderStatus,orderPaymentStatus,orderDate,paymentDate,commentsForOrder,clientName,clientPhone,clientEmail,senderName,senderPhone,senderEmail,violationsAmount,region,city,district,address,commentToAddressForClient,mixedWaste120L,textileWaste60L,textileWaste20L,otherPackages,totalOrderSum,orderCertificateCode,generalDiscount,amountDue,commentForOrderByClient,totalPayment,dateOfExport,timeOfExport,idOrderFromShop,receivingStation,responsibleCaller,responsibleLogicMan,responsibleDriver,responsibleNavigator,blockedBy';
</sql>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class BigOrderTableDTO {
private String mixedWaste120L;
private String textileWaste60L;
private String textileWaste20L;
private String otherPackages;
private Double totalOrderSum;
private String orderCertificateCode;
private Long generalDiscount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ protected BigOrderTableDTO convert(BigOrderTableViews bigViews) {
.filter(value -> value != 0)
.map(String::valueOf)
.orElse("-"))
.setOtherPackages(Optional.ofNullable(bigViews.getOtherPackages())
.orElse("-"))
.setTotalOrderSum(convertCoinsIntoBills(bigViews.getTotalOrderSum()))
.setOrderCertificateCode(bigViews.getOrderCertificateCode())
.setGeneralDiscount(bigViews.getGeneralDiscount())
Expand Down
Loading

0 comments on commit d984f6b

Please sign in to comment.