opt:优化成品库存查询导出

This commit is contained in:
DESKTOP-5DIJMF9\admin
2025-02-20 14:25:24 +08:00
parent 5237f12bf1
commit 6bb5ecf316
3 changed files with 331 additions and 374 deletions

View File

@@ -216,20 +216,21 @@ public class StructivtServiceImpl implements StructivtService {
String material = MapUtil.getStr(whereJson, "material");
String struct = MapUtil.getStr(whereJson, "struct");
String stor_id = MapUtil.getStr(whereJson, "stor_id");
String sect_id = MapUtil.getStr(whereJson, "sect_id");
String pcsn = MapUtil.getStr(whereJson, "pcsn");
String sap_pcsn = MapUtil.getStr(whereJson, "sap_pcsn");
String package_box_sn = MapUtil.getStr(whereJson, "package_box_sn");
String sale_order_name = MapUtil.getStr(whereJson, "sale_order_name");
String is_virtual = MapUtil.getStr(whereJson, "is_virtual");
String rein_flag = MapUtil.getStr(whereJson, "rein_flag");
String ivt_status = MapUtil.getStr(whereJson, "ivt_status");
String is_virtual = MapUtil.getStr(whereJson, "is_virtual");
String sub_type = MapUtil.getStr(whereJson, "sub_type");
String quality_scode = MapUtil.getStr(whereJson, "quality_scode");
JSONObject map = new JSONObject();
map.put("flag", "2");
map.put("stor_id", stor_id);
map.put("is_virtual", is_virtual);
map.put("sect_id", sect_id);
map.put("ivt_status", ivt_status);
map.put("is_virtual", is_virtual);
map.put("sub_type", sub_type);
map.put("quality_scode", quality_scode);
if (StrUtil.isNotEmpty(material)) {
@@ -250,7 +251,6 @@ public class StructivtServiceImpl implements StructivtService {
if (StrUtil.isNotEmpty(sale_order_name)) {
map.put("sale_order_name", "%" + sale_order_name + "%");
}
if (ObjectUtil.isNotEmpty(product_area)) {
String areas = "(";
for (int i = 0; i < product_area.length; i++) {
@@ -262,13 +262,6 @@ public class StructivtServiceImpl implements StructivtService {
}
map.put("areas", areas);
}
//获取人员对应的仓库
UserStorServiceImpl userStorService = new UserStorServiceImpl();
String in_stor_id = userStorService.getInStor();
if (ObjectUtil.isNotEmpty(in_stor_id)) {
map.put("in_stor_id", in_stor_id);
}
if (ObjectUtil.isNotNull(ivt_flag)) {
StringJoiner joiner = new StringJoiner(",", "(", ")");
@@ -278,6 +271,14 @@ public class StructivtServiceImpl implements StructivtService {
map.put("rein_flag", joiner.toString());
}
//获取人员对应的仓库
UserStorServiceImpl userStorService = new UserStorServiceImpl();
String in_stor_id = userStorService.getInStor();
if (ObjectUtil.isNotEmpty(in_stor_id)) {
map.put("in_stor_id", in_stor_id);
}
JSONArray resultJSONArray = WQL.getWO("QST_STRUCTIVT001").addParamMap(map).process().getResultJSONArray(0);
List<Map<String, Object>> list = new ArrayList<>();

View File

@@ -54,165 +54,157 @@
IF 输入.flag = "1"
PAGEQUERY
SELECT
a.*
FROM
(
SELECT
ivt.*,
attr.sect_id,
attr.sect_code,
attr.sect_name,
attr.stor_name,
mater.material_code,
mater.material_name,
unit.unit_name,
region.region_name,
sub.sap_pcsn,
sub.package_box_sn,
sub.quanlity_in_box,
sub.sale_order_name,
case when plan.paper_tube_or_FRP = '1' then '纸管' when plan.paper_tube_or_FRP = '2' then 'FRP管' end AS paper_type,
case when plan.paper_tube_or_FRP = '1' then plan.paper_tube_material when plan.paper_tube_or_FRP = '2' then plan.FRP_material end AS paper_code,
case when plan.paper_tube_or_FRP = '1' then plan.paper_tube_description when plan.paper_tube_or_FRP = '2' then plan.FRP_description end AS paper_name,
sub.box_weight,
CASE
WHEN SUBSTRING( sub.container_name, 1, 2 ) = 'BB' THEN
CASE
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '150' AND DATEDIFF( NOW(), sub.date_of_production ) <= '180' THEN '2'
WHEN DATEDIFF( NOW(), sub.date_of_production ) <= '180' THEN '1'
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '180' THEN '3'
END
SELECT
a.*
FROM
(
SELECT
ivt.*,
sub.sap_pcsn,
sub.package_box_sn,
sub.quanlity_in_box,
sub.sale_order_name,
sub.box_weight,
case when plan.paper_tube_or_FRP = '1' then '纸管' when plan.paper_tube_or_FRP = '2' then 'FRP管' end AS paper_type,
case when plan.paper_tube_or_FRP = '1' then plan.paper_tube_material when plan.paper_tube_or_FRP = '2' then plan.FRP_material end AS paper_code,
case when plan.paper_tube_or_FRP = '1' then plan.paper_tube_description when plan.paper_tube_or_FRP = '2' then plan.FRP_description end AS paper_name,
CASE
WHEN SUBSTRING( sub.container_name, 1, 2 ) = 'BB' THEN
CASE
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '150' AND DATEDIFF( NOW(), sub.date_of_production ) <= '180' THEN '2'
WHEN DATEDIFF( NOW(), sub.date_of_production ) <= '180' THEN '1'
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '180' THEN '3'
END
WHEN SUBSTRING( sub.container_name, 1, 2 ) <> 'BB' THEN
CASE
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '60' AND DATEDIFF( NOW(), sub.date_of_production ) <= '90' THEN '2'
WHEN DATEDIFF( NOW(), sub.date_of_production ) <= '90' THEN '1'
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '90' THEN '3'
END
END AS sub_type,
DATEDIFF( NOW(), dis.confirm_time ) AS stock_age,
DATEDIFF( NOW(), sub.date_of_production ) AS produce_age,
sub.joint_type,
dis.confirm_time
FROM
ST_IVT_StructIvt ivt
LEFT JOIN st_ivt_structattr attr ON ivt.struct_id = attr.struct_id
LEFT JOIN st_ivt_sectattr sect ON sect.sect_id =attr.sect_id
LEFT JOIN md_me_materialbase mater ON mater.material_id = ivt.material_id
LEFT JOIN md_pb_measureunit unit ON unit.measure_unit_id = ivt.qty_unit_id
LEFT JOIN SCH_BASE_Region region ON region.region_id = ivt.region_id
LEFT JOIN pdm_bi_subpackagerelation sub ON sub.container_name = ivt.pcsn AND attr.storagevehicle_code = sub.package_box_sn
LEFT JOIN (SELECT
container_name,
MAX(paper_tube_or_FRP) AS paper_tube_or_FRP,
MAX(paper_tube_material) AS paper_tube_material,
MAX(paper_tube_description) AS paper_tube_description,
MAX(paper_tube_model) AS paper_tube_model,
MAX(FRP_material) AS FRP_material,
MAX(FRP_description) AS FRP_description,
MAX(FRP_model) AS FRP_model
WHEN SUBSTRING( sub.container_name, 1, 2 ) <> 'BB' THEN
CASE
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '60' AND DATEDIFF( NOW(), sub.date_of_production ) <= '90' THEN '2'
WHEN DATEDIFF( NOW(), sub.date_of_production ) <= '90' THEN '1'
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '90' THEN '3'
END
END AS sub_type,
DATEDIFF( NOW(), dis.confirm_time ) AS stock_age,
DATEDIFF( NOW(), sub.date_of_production ) AS produce_age,
sub.joint_type,
dis.confirm_time
FROM
pdm_bi_slittingproductionplan plan1
WHERE
plan1.is_delete = '0'
GROUP BY container_name) plan ON plan.container_name = sub.container_name
LEFT JOIN (
(
SELECT
StructIvt.*,
attr.sect_id,
attr.sect_code,
attr.sect_name,
attr.stor_name,
attr.storagevehicle_code,
mater.material_code,
mater.material_name,
unit.unit_name,
region.region_name
FROM
ST_IVT_StructIvt StructIvt
inner JOIN st_ivt_structattr attr ON StructIvt.struct_id = attr.struct_id
inner JOIN st_ivt_sectattr sect ON sect.sect_id = attr.sect_id
inner JOIN md_me_materialbase mater ON mater.material_id = StructIvt.material_id
LEFT JOIN md_pb_measureunit unit ON unit.measure_unit_id = StructIvt.qty_unit_id
LEFT JOIN SCH_BASE_Region region ON region.region_id = StructIvt.region_id
WHERE 1 = 1
and attr.stor_id in 输入.in_stor_id
OPTION 输入.struct <> ""
(
StructIvt.struct_code like 输入.struct or
StructIvt.struct_name like 输入.struct
)
ENDOPTION
OPTION 输入.material <> ""
(
CASE
WHEN MAX(mst.bill_type) = '0001' THEN MIN( mst.confirm_time )
ELSE MAX( mst.confirm_time )
END
) AS confirm_time,
dis.pcsn
mater.material_code like 输入.material or
mater.material_name like 输入.material
)
ENDOPTION
OPTION 输入.pcsn <> ""
StructIvt.pcsn like 输入.pcsn
ENDOPTION
OPTION 输入.quality_scode <> ""
StructIvt.quality_scode = 输入.quality_scode
ENDOPTION
OPTION 输入.is_virtual = "0"
sect.sect_type_attr <> '09'
ENDOPTION
OPTION 输入.is_virtual = "1"
sect.sect_type_attr = '09'
ENDOPTION
OPTION 输入.stor_id <> ""
attr.stor_id = 输入.stor_id
ENDOPTION
OPTION 输入.sect_id <> ""
attr.sect_id = 输入.sect_id
ENDOPTION
OPTION 输入.ivt_status = "canuse_qty"
StructIvt.canuse_qty > 0
ENDOPTION
OPTION 输入.ivt_status = "warehousing_qty"
StructIvt.warehousing_qty > 0
ENDOPTION
OPTION 输入.ivt_status = "frozen_qty"
StructIvt.frozen_qty > 0
ENDOPTION
) ivt
LEFT JOIN pdm_bi_subpackagerelation sub ON sub.container_name = ivt.pcsn AND ivt.storagevehicle_code = sub.package_box_sn
LEFT JOIN (SELECT
container_name,
MAX(paper_tube_or_FRP) AS paper_tube_or_FRP,
MAX(paper_tube_material) AS paper_tube_material,
MAX(paper_tube_description) AS paper_tube_description,
MAX(paper_tube_model) AS paper_tube_model,
MAX(FRP_material) AS FRP_material,
MAX(FRP_description) AS FRP_description,
MAX(FRP_model) AS FRP_model
FROM
st_ivt_iostorinvdis dis
LEFT JOIN st_ivt_iostorinv mst ON mst.iostorinv_id = dis.iostorinv_id
WHERE
mst.io_type = '0'
AND mst.bill_type IN ('0001','0006','0007')
AND mst.is_delete = '0'
GROUP BY
dis.pcsn
) dis ON dis.pcsn = ivt.pcsn
WHERE
1 = 1
and attr.stor_id in 输入.in_stor_id
OPTION 输入.struct <> ""
(
ivt.struct_code like 输入.struct or
ivt.struct_name like 输入.struct
)
ENDOPTION
OPTION 输入.areas <> ""
(LEFT(sub.container_name,2) IN 输入.areas OR SUBSTRING(sub.container_name,2,2) IN 输入.areas)
ENDOPTION
OPTION 输入.material <> ""
(
mater.material_code like 输入.material or
mater.material_name like 输入.material
)
ENDOPTION
OPTION 输入.pcsn <> ""
ivt.pcsn like 输入.pcsn
ENDOPTION
OPTION 输入.quality_scode <> ""
ivt.quality_scode = 输入.quality_scode
ENDOPTION
OPTION 输入.is_virtual = "0"
sect.sect_type_attr <> '09'
ENDOPTION
OPTION 输入.is_virtual = "1"
sect.sect_type_attr = '09'
ENDOPTION
OPTION 输入.sap_pcsn <> ""
sub.sap_pcsn like 输入.sap_pcsn
ENDOPTION
OPTION 输入.stor_id <> ""
attr.stor_id = 输入.stor_id
ENDOPTION
OPTION 输入.sect_id <> ""
attr.sect_id = 输入.sect_id
ENDOPTION
OPTION 输入.package_box_sn <> ""
sub.package_box_sn like 输入.package_box_sn
ENDOPTION
OPTION 输入.sale_order_name <> ""
sub.sale_order_name like 输入.sale_order_name
ENDOPTION
OPTION 输入.ivt_status = "canuse_qty"
ivt.canuse_qty > 0
ENDOPTION
OPTION 输入.ivt_status = "warehousing_qty"
ivt.warehousing_qty > 0
ENDOPTION
OPTION 输入.rein_flag <> ""
IFNULL(sub.sub_type,'') in 输入.rein_flag
ENDOPTION
OPTION 输入.ivt_status = "frozen_qty"
ivt.frozen_qty > 0
ENDOPTION
) a
WHERE 1=1
OPTION 输入.sub_type <> ""
a.sub_type = 输入.sub_type
ENDOPTION
pdm_bi_slittingproductionplan plan1
WHERE
plan1.is_delete = '0'
GROUP BY container_name) plan ON plan.container_name = sub.container_name
LEFT JOIN (
SELECT
(
CASE
WHEN MAX(mst.bill_type) = '0001' THEN MIN( mst.confirm_time )
ELSE MAX( mst.confirm_time )
END
) AS confirm_time,
dis.pcsn
FROM
st_ivt_iostorinvdis dis
LEFT JOIN st_ivt_iostorinv mst ON mst.iostorinv_id = dis.iostorinv_id
WHERE
mst.io_type = '0'
AND mst.bill_type IN ('0001','0006','0007')
AND mst.is_delete = '0'
GROUP BY
dis.pcsn
) dis ON dis.pcsn = ivt.pcsn
WHERE
1 = 1
OPTION 输入.areas <> ""
(LEFT(sub.container_name,2) IN 输入.areas OR SUBSTRING(sub.container_name,2,2) IN 输入.areas)
ENDOPTION
OPTION 输入.sap_pcsn <> ""
sub.sap_pcsn like 输入.sap_pcsn
ENDOPTION
OPTION 输入.package_box_sn <> ""
sub.package_box_sn like 输入.package_box_sn
ENDOPTION
OPTION 输入.sale_order_name <> ""
sub.sale_order_name like 输入.sale_order_name
ENDOPTION
OPTION 输入.rein_flag <> ""
IFNULL(sub.sub_type,'') in 输入.rein_flag
ENDOPTION
) a
WHERE 1=1
OPTION 输入.sub_type <> ""
a.sub_type = 输入.sub_type
ENDOPTION
ENDSELECT
ENDPAGEQUERY
ENDIF
@@ -220,183 +212,171 @@
IF 输入.flag = "2"
QUERY
SELECT
a.*
FROM
(
SELECT
ivt.*,
attr.sect_id,
attr.sect_code,
attr.sect_name,
attr.stor_name,
mater.material_code,
mater.material_name,
unit.unit_name,
region.region_name,
sub.sap_pcsn,
sub.package_box_sn,
sub.sale_order_name,
sub.customer_name,
sub.customer_description,
sub.date_of_production,
sub.width,
sub.thickness,
sub.mass_per_unit_area,
sub.net_weight,
sub.length,
sub.is_un_plan_production,
sub.un_plan_product_property1,
sub.un_plan_product_property2,
sub.un_plan_product_property3,
sub.isUnPackBox,
sub.isRePrintPackageBoxLabel,
sub.width_standard,
case when plan.paper_tube_or_FRP = '1' then '纸管' when plan.paper_tube_or_FRP = '2' then 'FRP管' end AS paper_type,
case when plan.paper_tube_or_FRP = '1' then plan.paper_tube_material when plan.paper_tube_or_FRP = '2' then plan.FRP_material end AS paper_code,
case when plan.paper_tube_or_FRP = '1' then plan.paper_tube_description when plan.paper_tube_or_FRP = '2' then plan.FRP_description end AS paper_name,
sub.thickness_request,
sub.box_weight,
cust.sales_owner,
CASE
WHEN SUBSTRING( sub.container_name, 1, 2 ) = 'BB' THEN
CASE
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '150' AND DATEDIFF( NOW(), sub.date_of_production ) <= '180' THEN '2'
WHEN DATEDIFF( NOW(), sub.date_of_production ) <= '180' THEN '1'
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '180' THEN '3'
END
WHEN SUBSTRING( sub.container_name, 1, 2 ) <> 'BB' THEN
CASE
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '60' AND DATEDIFF( NOW(), sub.date_of_production ) <= '90' THEN '2'
WHEN DATEDIFF( NOW(), sub.date_of_production ) <= '90' THEN '1'
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '90' THEN '3'
END
END AS sub_type,
DATEDIFF( NOW(), dis.confirm_time ) AS stock_age,
DATEDIFF( NOW(), sub.date_of_production ) AS produce_age,
sub.joint_type,
dis.confirm_time
a.*
FROM
ST_IVT_StructIvt ivt
LEFT JOIN st_ivt_structattr attr ON ivt.struct_id = attr.struct_id
LEFT JOIN st_ivt_sectattr sect ON sect.sect_id =attr.sect_id
LEFT JOIN md_me_materialbase mater ON mater.material_id = ivt.material_id
LEFT JOIN md_pb_measureunit unit ON unit.measure_unit_id = ivt.qty_unit_id
LEFT JOIN SCH_BASE_Region region ON region.region_id = ivt.region_id
LEFT JOIN pdm_bi_subpackagerelation sub ON sub.container_name = ivt.pcsn AND attr.storagevehicle_code = sub.package_box_sn
LEFT JOIN md_cs_customerbase cust ON cust.cust_code = sub.customer_name
LEFT JOIN (SELECT
container_name,
MAX(paper_tube_or_FRP) AS paper_tube_or_FRP,
MAX(paper_tube_material) AS paper_tube_material,
MAX(paper_tube_description) AS paper_tube_description,
MAX(paper_tube_model) AS paper_tube_model,
MAX(FRP_material) AS FRP_material,
MAX(FRP_description) AS FRP_description,
MAX(FRP_model) AS FRP_model
FROM
pdm_bi_slittingproductionplan plan1
WHERE
plan1.is_delete = '0'
GROUP BY container_name) plan ON plan.container_name = sub.container_name
LEFT JOIN (
SELECT
(
CASE
WHEN MAX(mst.bill_type) = '0001' THEN MIN( mst.confirm_time )
ELSE MAX( mst.confirm_time )
END
) AS confirm_time,
dis.pcsn
FROM
st_ivt_iostorinvdis dis
LEFT JOIN st_ivt_iostorinv mst ON mst.iostorinv_id = dis.iostorinv_id
WHERE
mst.io_type = '0'
AND mst.bill_type IN ( '0001', '0006', '0007' )
AND mst.is_delete = '0'
GROUP BY
dis.pcsn
) dis ON dis.pcsn = ivt.pcsn
WHERE
1 = 1
and attr.stor_id in 输入.in_stor_id
OPTION 输入.struct <> ""
(
ivt.struct_code like 输入.struct or
ivt.struct_name like 输入.struct
)
ENDOPTION
OPTION 输入.material <> ""
(
mater.material_code like 输入.material or
mater.material_name like 输入.material
)
ENDOPTION
OPTION 输入.pcsn <> ""
ivt.pcsn like 输入.pcsn
ENDOPTION
OPTION 输入.quality_scode <> ""
ivt.quality_scode = 输入.quality_scode
ENDOPTION
OPTION 输入.sap_pcsn <> ""
sub.sap_pcsn like 输入.sap_pcsn
ENDOPTION
OPTION 输入.stor_id <> ""
attr.stor_id = 输入.stor_id
ENDOPTION
OPTION 输入.is_virtual = "0"
sect.sect_type_attr <> '09'
ENDOPTION
OPTION 输入.is_virtual = "1"
sect.sect_type_attr = '09'
ENDOPTION
OPTION 输入.package_box_sn <> ""
sub.package_box_sn like 输入.package_box_sn
ENDOPTION
OPTION 输入.sale_order_name <> ""
sub.sale_order_name like 输入.sale_order_name
ENDOPTION
OPTION 输入.areas <> ""
LEFT(sub.container_name,2) IN 输入.areas
ENDOPTION
OPTION 输入.rein_flag <> ""
IFNULL(sub.sub_type,'') in 输入.rein_flag
ENDOPTION
OPTION 输入.ivt_status = "canuse_qty"
ivt.canuse_qty > 0
ENDOPTION
OPTION 输入.ivt_status = "warehousing_qty"
ivt.warehousing_qty > 0
ENDOPTION
OPTION 输入.ivt_status = "frozen_qty"
ivt.frozen_qty > 0
ENDOPTION
) a
INNER JOIN (
(
SELECT
dis.pcsn,
mst.bill_type
FROM
st_ivt_iostorinvdis dis
INNER JOIN ( SELECT MAX( iostorinvdis_id ) AS iostorinvdis_id, pcsn FROM st_ivt_iostorinvdis GROUP BY pcsn ) a ON a.iostorinvdis_id = dis.iostorinvdis_id
INNER JOIN st_ivt_iostorinv mst ON mst.iostorinv_id = dis.iostorinv_id
) b ON a.pcsn = b.pcsn
ivt.*,
sub.sap_pcsn,
sub.customer_name,
sub.customer_description,
sub.mass_per_unit_area,
sub.package_box_sn,
sub.quanlity_in_box,
sub.net_weight,
sub.length,
sub.sale_order_name,
sub.box_weight,
sub.is_un_plan_production,
sub.un_plan_product_property1,
sub.un_plan_product_property2,
sub.un_plan_product_property3,
cust.sales_owner,
sub.isUnPackBox,
sub.isRePrintPackageBoxLabel,
sub.width_standard,
sub.thickness_request,
case when plan.paper_tube_or_FRP = '1' then '纸管' when plan.paper_tube_or_FRP = '2' then 'FRP管' end AS paper_type,
case when plan.paper_tube_or_FRP = '1' then plan.paper_tube_material when plan.paper_tube_or_FRP = '2' then plan.FRP_material end AS paper_code,
case when plan.paper_tube_or_FRP = '1' then plan.paper_tube_description when plan.paper_tube_or_FRP = '2' then plan.FRP_description end AS paper_name,
CASE
WHEN SUBSTRING( sub.container_name, 1, 2 ) = 'BB' THEN
CASE
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '150' AND DATEDIFF( NOW(), sub.date_of_production ) <= '180' THEN '2'
WHEN DATEDIFF( NOW(), sub.date_of_production ) <= '180' THEN '1'
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '180' THEN '3'
END
WHEN SUBSTRING( sub.container_name, 1, 2 ) <> 'BB' THEN
CASE
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '60' AND DATEDIFF( NOW(), sub.date_of_production ) <= '90' THEN '2'
WHEN DATEDIFF( NOW(), sub.date_of_production ) <= '90' THEN '1'
WHEN DATEDIFF( NOW(), sub.date_of_production ) > '90' THEN '3'
END
END AS sub_type,
DATEDIFF( NOW(), dis.confirm_time ) AS stock_age,
DATEDIFF( NOW(), sub.date_of_production ) AS produce_age,
sub.joint_type,
dis.confirm_time
FROM
(
SELECT
StructIvt.*,
attr.sect_id,
attr.sect_code,
attr.sect_name,
attr.stor_name,
attr.storagevehicle_code,
mater.material_code,
mater.material_name,
unit.unit_name,
region.region_name
FROM
ST_IVT_StructIvt StructIvt
inner JOIN st_ivt_structattr attr ON StructIvt.struct_id = attr.struct_id
inner JOIN st_ivt_sectattr sect ON sect.sect_id = attr.sect_id
inner JOIN md_me_materialbase mater ON mater.material_id = StructIvt.material_id
LEFT JOIN md_pb_measureunit unit ON unit.measure_unit_id = StructIvt.qty_unit_id
LEFT JOIN SCH_BASE_Region region ON region.region_id = StructIvt.region_id
WHERE 1 = 1
and attr.stor_id in 输入.in_stor_id
OPTION 输入.struct <> ""
(
StructIvt.struct_code like 输入.struct or
StructIvt.struct_name like 输入.struct
)
ENDOPTION
OPTION 输入.material <> ""
(
mater.material_code like 输入.material or
mater.material_name like 输入.material
)
ENDOPTION
OPTION 输入.pcsn <> ""
StructIvt.pcsn like 输入.pcsn
ENDOPTION
OPTION 输入.quality_scode <> ""
StructIvt.quality_scode = 输入.quality_scode
ENDOPTION
OPTION 输入.is_virtual = "0"
sect.sect_type_attr <> '09'
ENDOPTION
OPTION 输入.is_virtual = "1"
sect.sect_type_attr = '09'
ENDOPTION
OPTION 输入.stor_id <> ""
attr.stor_id = 输入.stor_id
ENDOPTION
OPTION 输入.sect_id <> ""
attr.sect_id = 输入.sect_id
ENDOPTION
OPTION 输入.ivt_status = "canuse_qty"
StructIvt.canuse_qty > 0
ENDOPTION
OPTION 输入.ivt_status = "warehousing_qty"
StructIvt.warehousing_qty > 0
ENDOPTION
OPTION 输入.ivt_status = "frozen_qty"
StructIvt.frozen_qty > 0
ENDOPTION
) ivt
LEFT JOIN pdm_bi_subpackagerelation sub ON sub.container_name = ivt.pcsn AND ivt.storagevehicle_code = sub.package_box_sn
LEFT JOIN md_cs_customerbase cust ON cust.cust_code = sub.customer_name
LEFT JOIN (SELECT
container_name,
MAX(paper_tube_or_FRP) AS paper_tube_or_FRP,
MAX(paper_tube_material) AS paper_tube_material,
MAX(paper_tube_description) AS paper_tube_description,
MAX(paper_tube_model) AS paper_tube_model,
MAX(FRP_material) AS FRP_material,
MAX(FRP_description) AS FRP_description,
MAX(FRP_model) AS FRP_model
FROM
pdm_bi_slittingproductionplan plan1
WHERE
plan1.is_delete = '0'
GROUP BY container_name) plan ON plan.container_name = sub.container_name
LEFT JOIN (
SELECT
(
CASE
WHEN MAX(mst.bill_type) = '0001' THEN MIN( mst.confirm_time )
ELSE MAX( mst.confirm_time )
END
) AS confirm_time,
dis.pcsn
FROM
st_ivt_iostorinvdis dis
LEFT JOIN st_ivt_iostorinv mst ON mst.iostorinv_id = dis.iostorinv_id
WHERE
mst.io_type = '0'
AND mst.bill_type IN ('0001','0006','0007')
AND mst.is_delete = '0'
GROUP BY
dis.pcsn
) dis ON dis.pcsn = ivt.pcsn
WHERE
1=1
OPTION 输入.sub_type <> ""
a.sub_type = 输入.sub_type
ENDOPTION
1 = 1
OPTION 输入.areas <> ""
(LEFT(sub.container_name,2) IN 输入.areas OR SUBSTRING(sub.container_name,2,2) IN 输入.areas)
ENDOPTION
OPTION 输入.sap_pcsn <> ""
sub.sap_pcsn like 输入.sap_pcsn
ENDOPTION
OPTION 输入.package_box_sn <> ""
sub.package_box_sn like 输入.package_box_sn
ENDOPTION
OPTION 输入.sale_order_name <> ""
sub.sale_order_name like 输入.sale_order_name
ENDOPTION
OPTION 输入.rein_flag <> ""
IFNULL(sub.sub_type,'') in 输入.rein_flag
ENDOPTION
) a
WHERE 1=1
OPTION 输入.sub_type <> ""
a.sub_type = 输入.sub_type
ENDOPTION
order by a.instorage_time desc,a.package_box_sn
ENDSELECT
ENDQUERY