<?xml version="1.0" encoding="UTF-8"?>
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<mapper namespace="com.ruoyi.production.mapper.MaterialConsumptionMapper">
|
|
<select id="listOrders" resultType="com.ruoyi.production.bean.vo.MaterialConsumptionOrderVo">
|
select po.id as productionOrderId,
|
po.nps_no as npsNo,
|
po.product_model_id as productModelId,
|
concat(ifnull(p.product_name, ''), '/', ifnull(pm.model, '')) as finishedProduct,
|
ifnull(po.complete_quantity, 0) as completeQty,
|
ifnull(po.quantity, 0) as planQty
|
from production_order po
|
left join product_model pm on pm.id = po.product_model_id
|
left join product p on p.id = pm.product_id
|
<where>
|
<!-- 订单日期取 create_time,历史数据未回填时回退 start_time,避免筛选丢单 -->
|
<if test="startDate != null">and date(coalesce(po.create_time, po.start_time)) >= #{startDate}</if>
|
<if test="endDate != null">and date(coalesce(po.create_time, po.start_time)) <= #{endDate}</if>
|
<if test="npsNo != null and npsNo != ''">and po.nps_no like concat('%', #{npsNo}, '%')</if>
|
<if test="productName != null and productName != ''">
|
and (p.product_name like concat('%', #{productName}, '%')
|
or pm.model like concat('%', #{productName}, '%'))
|
</if>
|
</where>
|
order by po.id desc
|
</select>
|
|
<select id="listStructures" resultType="com.ruoyi.production.bean.vo.MaterialConsumptionStructureVo">
|
select pbs.production_order_id as productionOrderId,
|
pbs.id as id,
|
pbs.parent_id as parentId,
|
pbs.product_model_id as productModelId,
|
ifnull(pbs.unit_quantity, 0) as unitQuantity
|
from production_bom_structure pbs
|
where pbs.production_order_id in
|
<foreach collection="orderIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
order by pbs.id
|
</select>
|
|
<select id="listActualInputs" resultType="com.ruoyi.production.bean.vo.MaterialConsumptionActualVo">
|
select pot.production_order_id as productionOrderId,
|
ppi.product_model_id as productModelId,
|
sum(ifnull(ppi.input_quantity, 0)) as actualQty
|
from production_product_input ppi
|
join production_product_main ppm on ppm.id = ppi.production_product_main_id
|
join production_operation_task pot on pot.id = ppm.production_operation_task_id
|
where pot.production_order_id in
|
<foreach collection="orderIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
group by pot.production_order_id, ppi.product_model_id
|
</select>
|
</mapper>
|