|
|
@@ -152,12 +152,15 @@
|
|
|
sum( trade_number ) AS allNumber,
|
|
|
b.collect_number AS borrowNumber,
|
|
|
loss.loss_number AS lossNumber,
|
|
|
- a.current_inventory AS tradeNumber,
|
|
|
+ sum(a.current_inventory) AS tradeNumber,
|
|
|
a.warn_num,
|
|
|
a.warn_flag,
|
|
|
a.produce_date,
|
|
|
a.shelf_life,
|
|
|
- a.shelf_life_unit
|
|
|
+ a.shelf_life_unit,
|
|
|
+ a.spec,
|
|
|
+ pmcdra.returned_num as returnedNum,
|
|
|
+ pmcdra.not_surplus_stock as notSurplusStock
|
|
|
FROM
|
|
|
psi_management_warehouse_detailed a
|
|
|
left join
|
|
|
@@ -168,7 +171,7 @@
|
|
|
status
|
|
|
from psi_management_collect_detailed e
|
|
|
left join psi_management_collect_basics f on e.basic_id = f.id and f.del_flag = 0
|
|
|
- WHERE f.`status` = 5 and e.del_flag = 0
|
|
|
+ WHERE f.`status` = 5 and e.del_flag = 0 and e.is_return = '0'
|
|
|
GROUP BY e.goods_name
|
|
|
) b
|
|
|
on a.trade_name = b.goods_name
|
|
|
@@ -184,6 +187,20 @@
|
|
|
GROUP BY e.goods_name
|
|
|
) loss
|
|
|
on a.trade_name = loss.goods_name
|
|
|
+ left join
|
|
|
+ (
|
|
|
+ select
|
|
|
+ sum(returned_num) AS returned_num,
|
|
|
+ sum(not_surplus_stock) AS not_surplus_stock,
|
|
|
+ inventory_id,
|
|
|
+ goods_name,
|
|
|
+ status
|
|
|
+ from psi_management_collect_detailed_record e
|
|
|
+ left join psi_management_collect_basics pmcba on e.basic_id = pmcba.id and pmcba.del_flag = 0
|
|
|
+ WHERE pmcba.`status` = 5 and e.del_flag = 0
|
|
|
+ group BY e.goods_name
|
|
|
+ ) pmcdra
|
|
|
+ on a.trade_name = pmcdra.goods_name
|
|
|
LEFT JOIN psi_management_warehouse_basics bas on a.basic_id = bas.id
|
|
|
left join psi_management_type c on a.ware_house_type = c.id
|
|
|
${ew.customSqlSegment}
|
|
|
@@ -256,110 +273,16 @@
|
|
|
|
|
|
<select id="nearExpiryList"
|
|
|
resultType="com.jeeplus.psimanage.psiWareHouse.service.dto.PsiWareHouseDto">
|
|
|
- SELECT
|
|
|
- t.id,
|
|
|
- t.basic_id AS basicId,
|
|
|
- t.ware_house_type,
|
|
|
- t.trade_name,
|
|
|
- t.spec,
|
|
|
- t.company,
|
|
|
- t.current_inventory AS currentInventory,
|
|
|
- t.current_inventory AS tradeNumber,
|
|
|
- t.produce_date,
|
|
|
- t.shelf_life,
|
|
|
- t.shelf_life_unit,
|
|
|
- t.expiryDate AS expiryDate,
|
|
|
- CAST(t.remainingDays AS SIGNED) AS remainingDays,
|
|
|
- CAST(t.warnDays AS SIGNED) AS warnDays,
|
|
|
- t.ware_house_number,
|
|
|
- t.ware_house_name,
|
|
|
- t.ware_house_date,
|
|
|
- tp.name AS wareHouseTypeName
|
|
|
- FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
- src.*,
|
|
|
- DATEDIFF(src.expiryDate, CURDATE()) AS remainingDays,
|
|
|
- CASE
|
|
|
- WHEN src.totalShelfDays <= 30 THEN CAST(GREATEST(1, CEILING(src.totalShelfDays / 3)) AS SIGNED)
|
|
|
- ELSE CAST(GREATEST(1, CEILING(src.totalShelfDays / 4)) AS SIGNED)
|
|
|
- END AS warnDays
|
|
|
- FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
- a.id,
|
|
|
- a.basic_id,
|
|
|
- a.ware_house_type,
|
|
|
- a.trade_name,
|
|
|
- a.spec,
|
|
|
- a.company,
|
|
|
- a.current_inventory,
|
|
|
- a.produce_date,
|
|
|
- a.shelf_life,
|
|
|
- a.shelf_life_unit,
|
|
|
- a.supplier_id,
|
|
|
- bas.ware_house_number,
|
|
|
- bas.ware_house_name,
|
|
|
- bas.ware_house_date,
|
|
|
- CASE
|
|
|
- WHEN TRIM(a.shelf_life_unit) = '年' THEN DATE_ADD(a.produce_date, INTERVAL CAST(a.shelf_life AS UNSIGNED) YEAR)
|
|
|
- WHEN TRIM(a.shelf_life_unit) = '月' THEN DATE_ADD(a.produce_date, INTERVAL CAST(a.shelf_life AS UNSIGNED) MONTH)
|
|
|
- WHEN TRIM(a.shelf_life_unit) = '天' OR TRIM(a.shelf_life_unit) = '日' THEN DATE_ADD(a.produce_date, INTERVAL CAST(a.shelf_life AS UNSIGNED) DAY)
|
|
|
- ELSE NULL
|
|
|
- END AS expiryDate,
|
|
|
- CASE
|
|
|
- WHEN TRIM(a.shelf_life_unit) = '年' THEN CAST(a.shelf_life AS DECIMAL(10, 2)) * 365
|
|
|
- WHEN TRIM(a.shelf_life_unit) = '月' THEN CAST(a.shelf_life AS DECIMAL(10, 2)) * 30
|
|
|
- WHEN TRIM(a.shelf_life_unit) = '天' OR TRIM(a.shelf_life_unit) = '日' THEN CAST(a.shelf_life AS DECIMAL(10, 2))
|
|
|
- ELSE NULL
|
|
|
- END AS totalShelfDays
|
|
|
- FROM
|
|
|
- psi_management_warehouse_detailed a
|
|
|
- LEFT JOIN psi_management_warehouse_basics bas ON a.basic_id = bas.id
|
|
|
- WHERE
|
|
|
- a.del_flag = '0'
|
|
|
- AND bas.del_flag = '0'
|
|
|
- AND (bas.`status` = '0' OR bas.`status` = '5')
|
|
|
- AND a.produce_date IS NOT NULL
|
|
|
- AND a.shelf_life IS NOT NULL
|
|
|
- AND a.shelf_life <> ''
|
|
|
- AND a.shelf_life REGEXP '^[0-9]+([.][0-9]+)?$'
|
|
|
- AND a.shelf_life_unit IS NOT NULL
|
|
|
- AND a.shelf_life_unit <> ''
|
|
|
- AND CAST(IFNULL(NULLIF(a.current_inventory, ''), '0') AS DECIMAL(18, 6)) > 0
|
|
|
- <if test="dto.tradeName != null and dto.tradeName != ''">
|
|
|
- AND a.trade_name LIKE concat('%', #{dto.tradeName}, '%')
|
|
|
- </if>
|
|
|
- <if test="dto.wareHouseType != null and dto.wareHouseType != ''">
|
|
|
- AND a.ware_house_type = #{dto.wareHouseType}
|
|
|
- </if>
|
|
|
- <if test="dto.produceDate != null">
|
|
|
- AND a.produce_date = #{dto.produceDate}
|
|
|
- </if>
|
|
|
- <if test="dto.supplierId != null and dto.supplierId != ''">
|
|
|
- AND a.supplier_id = #{dto.supplierId}
|
|
|
- </if>
|
|
|
- <if test="dto.spec != null and dto.spec != ''">
|
|
|
- AND a.spec LIKE concat('%', #{dto.spec}, '%')
|
|
|
- </if>
|
|
|
- <if test="dto.wareHouseNumber != null and dto.wareHouseNumber != ''">
|
|
|
- AND bas.ware_house_number LIKE concat('%', #{dto.wareHouseNumber}, '%')
|
|
|
- </if>
|
|
|
- <if test="dto.wareHouseName != null and dto.wareHouseName != ''">
|
|
|
- AND bas.ware_house_name LIKE concat('%', #{dto.wareHouseName}, '%')
|
|
|
- </if>
|
|
|
- ) src
|
|
|
- WHERE
|
|
|
- src.expiryDate IS NOT NULL
|
|
|
- ) t
|
|
|
- LEFT JOIN psi_management_type tp ON t.ware_house_type = tp.id
|
|
|
- WHERE
|
|
|
- t.remainingDays >= 0
|
|
|
- AND (
|
|
|
- t.remainingDays <= t.warnDays
|
|
|
- OR t.remainingDays IN (30, 60, 90)
|
|
|
- )
|
|
|
- ORDER BY t.remainingDays ASC, t.expiryDate ASC, t.trade_name ASC
|
|
|
+ select
|
|
|
+ a.trade_name,
|
|
|
+ a.produce_date,
|
|
|
+ a.shelf_life,
|
|
|
+ a.spec,
|
|
|
+ a.shelf_life_unit,
|
|
|
+ a.current_inventory
|
|
|
+ from psi_management_warehouse_detailed a
|
|
|
+ left join psi_management_warehouse_basics pmwb on pmwb.id = a.basic_id and pmwb.del_flag= '0'
|
|
|
+ where a.del_flag = '0'
|
|
|
</select>
|
|
|
|
|
|
<select id="findRequestId" resultType="java.lang.String">
|