<?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.ProductOrderMapper">
|
|
|
<resultMap id="basicMap" type="com.ruoyi.production.pojo.ProductOrder">
|
<id property="id" column="id"/>
|
<result property="productModelId" column="product_model_id"/>
|
<result property="tenantId" column="tenant_id"/>
|
<result property="salesLedgerId" column="sales_ledger_id"/>
|
<result property="routeId" column="route_id"/>
|
<result property="npsNo" column="nps_no"/>
|
<result property="createTime" column="create_time"/>
|
<result property="updateTime" column="update_time"/>
|
</resultMap>
|
|
<!-- 旧sql-->
|
<!-- <select id="pageProductOrder" resultType="com.ruoyi.production.dto.ProductOrderDto">-->
|
<!-- select po.*,-->
|
<!-- sl.sales_contract_no,-->
|
<!-- sl.customer_name,-->
|
<!-- p.product_name as product_category,-->
|
<!-- pm.model as specification_model,-->
|
<!-- pm.unit,-->
|
<!-- ppr.process_route_code,-->
|
<!-- pb.bom_no,-->
|
<!-- ROUND(po.complete_quantity / po.quantity * 100, 2) AS completionStatus,-->
|
<!-- DATEDIFF(sl.delivery_date, CURDATE()) AS delivery_days_diff,-->
|
<!-- sl.delivery_date,-->
|
<!-- CASE-->
|
<!-- WHEN shipping_status_counts.total_count = 0 THEN false-->
|
<!-- WHEN shipping_status_counts.unshipped_count = 0 THEN true-->
|
<!-- ELSE false-->
|
<!-- END AS is_fh-->
|
<!-- from product_order po-->
|
<!-- left join sales_ledger sl on po.sales_ledger_id = sl.id-->
|
<!-- LEFT JOIN (-->
|
<!-- SELECT sales_ledger_id,-->
|
<!-- COUNT(*) as total_count,-->
|
<!-- SUM(CASE WHEN status != '已发货' THEN 1 ELSE 0 END) as unshipped_count-->
|
<!-- FROM shipping_info-->
|
<!-- GROUP BY sales_ledger_id-->
|
<!-- ) shipping_status_counts ON sl.id = shipping_status_counts.sales_ledger_id-->
|
<!-- left join product_model pm on po.product_model_id = pm.id-->
|
<!-- left join product p on pm.product_id = p.id-->
|
<!-- left join sales_ledger_product slp on po.sale_ledger_product_id = slp.id and slp.type = 1-->
|
<!-- left join (-->
|
<!-- select max(id) as id, product_order_id-->
|
<!-- from product_process_route-->
|
<!-- group by product_order_id-->
|
<!-- ) ppr_latest on po.id = ppr_latest.product_order_id-->
|
<!-- left join product_process_route ppr on ppr.id = ppr_latest.id-->
|
<!-- left join product_bom pb on pb.id = ppr.bom_id-->
|
<!-- <where>-->
|
<!-- <if test="c.npsNo != null and c.npsNo != ''">-->
|
<!-- and po.nps_no like concat('%',#{c.npsNo},'%')-->
|
<!-- </if>-->
|
<!-- <if test="c.salesContractNo != null and c.salesContractNo != ''">-->
|
<!-- and sl.sales_contract_no like concat('%',#{c.salesContractNo},'%')-->
|
<!-- </if>-->
|
<!-- <if test="c.customerName != null and c.customerName != ''">-->
|
<!-- and sl.customer_name like concat('%',#{c.customerName},'%')-->
|
<!-- </if>-->
|
<!-- <if test="c.productCategory != null and c.productCategory != ''">-->
|
<!-- and slp.product_category like concat('%',#{c.productCategory},'%')-->
|
<!-- </if>-->
|
<!-- <if test="c.specificationModel != null and c.specificationModel != ''">-->
|
<!-- and slp.specification_model like concat('%',#{c.specificationModel},'%')-->
|
<!-- </if>-->
|
<!-- <if test="c.startTime != null and c.endTime != null">-->
|
<!-- and po.create_time between #{c.startTime} and #{c.endTime}-->
|
<!-- </if>-->
|
<!-- </where>-->
|
<!-- </select>-->
|
|
<!-- 新sql 用中间表sales_ledger_production_ref进行关联sales_ledger和product_order,查询出所有关联的sales_ledger_no和customer_name。交期,交期偏差,是否发货由于一个生产订单对应多个销售订单,导致无法正常显示,暂时省略-->
|
<select id="pageProductOrder" resultType="com.ruoyi.production.dto.ProductOrderDto">
|
select po.*,
|
GROUP_CONCAT(DISTINCT sl.sales_contract_no SEPARATOR ',') AS sales_contract_no,
|
GROUP_CONCAT(DISTINCT sl.customer_name SEPARATOR ',') AS customer_name,
|
p.product_name as product_category,
|
pm.model as specification_model,
|
pm.unit,
|
ppr.process_route_code,
|
pb.bom_no,
|
ROUND(po.complete_quantity / po.quantity * 100, 2) AS completionStatus
|
|
|
from product_order po
|
left join sales_ledger_production_ref ref on po.id = ref.product_order_id
|
left join sales_ledger sl on ref.sales_ledger_id = sl.id
|
LEFT JOIN (
|
SELECT sales_ledger_id,
|
COUNT(*) as total_count,
|
SUM(CASE WHEN status != '已发货' THEN 1 ELSE 0 END) as unshipped_count
|
FROM shipping_info
|
GROUP BY sales_ledger_id) shipping_status_counts
|
ON sl.id = shipping_status_counts.sales_ledger_id
|
left join product_model pm on po.product_model_id = pm.id
|
left join product p on pm.product_id = p.id
|
left join sales_ledger_product slp on po.sale_ledger_product_id = slp.id and slp.type = 1
|
left join (
|
select max(id) as id, product_order_id
|
from product_process_route
|
group by product_order_id) ppr_latest on po.id = ppr_latest.product_order_id
|
left join product_process_route ppr on ppr.id = ppr_latest.id
|
left join product_bom pb on pb.id = ppr.bom_id
|
<where>
|
<if test="c.npsNo != null and c.npsNo != ''">
|
and po.nps_no like concat('%',#{c.npsNo},'%')
|
</if>
|
<if test="c.salesContractNo != null and c.salesContractNo != ''">
|
and sl.sales_contract_no like concat('%',#{c.salesContractNo},'%')
|
</if>
|
<if test="c.customerName != null and c.customerName != ''">
|
and sl.customer_name like concat('%',#{c.customerName},'%')
|
</if>
|
<if test="c.productCategory != null and c.productCategory != ''">
|
and slp.product_category like concat('%',#{c.productCategory},'%')
|
</if>
|
<if test="c.specificationModel != null and c.specificationModel != ''">
|
and slp.specification_model like concat('%',#{c.specificationModel},'%')
|
</if>
|
<if test="c.startTime != null and c.endTime != null">
|
and po.create_time between #{c.startTime} and #{c.endTime}
|
</if>
|
</where>
|
GROUP BY po.id
|
</select>
|
|
|
<select id="listProcessRoute" resultType="com.ruoyi.production.pojo.ProcessRoute">
|
select pr.*
|
from process_route pr
|
left join product_model pm on pr.product_model_id = pm.id
|
where pm.id = #{productModelId}
|
</select>
|
<select id="listProcessBom" resultType="com.ruoyi.production.dto.ProductStructureDto">
|
select ps.id,
|
ps.product_model_id,
|
ps.process_id,
|
ps.unit_quantity,
|
ps.unit_quantity * po.quantity as demandedQuantity,
|
ps.unit,
|
p.product_name,
|
pp.name as process_name,
|
pm.product_id,
|
pm.model
|
from product_structure ps
|
left join product_model pm on ps.product_model_id = pm.id
|
left join product p on pm.product_id = p.id
|
left join product_process pp on ps.process_id = pp.id
|
left join product_process_route ppr on ps.bom_id = ppr.bom_id
|
left join product_order po on po.id = ppr.product_order_id
|
where ppr.product_order_id = #{orderId}
|
order by ps.id
|
</select>
|
|
|
<select id="countCreated" resultType="java.lang.Integer">
|
SELECT count(1)
|
FROM product_order
|
WHERE create_time >= #{startDate}
|
AND create_time <= #{endDate}
|
</select>
|
|
<select id="countCompleted" resultType="java.lang.Integer">
|
SELECT count(1)
|
FROM product_order
|
WHERE end_time >= #{startDate}
|
AND end_time <= #{endDate}
|
AND complete_quantity >= quantity
|
</select>
|
|
<select id="countPending" resultType="java.lang.Integer">
|
SELECT count(1)
|
FROM product_order
|
WHERE create_time >= #{startDate}
|
AND create_time <= #{endDate}
|
AND complete_quantity < quantity
|
</select>
|
<select id="listByProductModelId" resultType="com.ruoyi.production.dto.ProductOrderDto">
|
select po.*,
|
sl.sales_contract_no,
|
sl.customer_name,
|
p.product_name as product_category,
|
pm.model as specification_model,
|
pm.unit,
|
ppr.process_route_code,
|
pb.bom_no,
|
ROUND(po.complete_quantity / po.quantity * 100, 2) AS completionStatus,
|
DATEDIFF(sl.delivery_date, CURDATE()) AS delivery_days_diff,
|
sl.delivery_date,
|
CASE
|
WHEN shipping_status_counts.total_count = 0 THEN false
|
WHEN shipping_status_counts.unshipped_count = 0 THEN true
|
ELSE false
|
END AS is_fh
|
from product_order po
|
left join sales_ledger sl on po.sales_ledger_id = sl.id
|
LEFT JOIN (SELECT sales_ledger_id,
|
COUNT(*) as total_count,
|
SUM(CASE WHEN status != '已发货' THEN 1 ELSE 0 END) as unshipped_count
|
FROM shipping_info
|
GROUP BY sales_ledger_id) shipping_status_counts
|
ON sl.id = shipping_status_counts.sales_ledger_id
|
left join product_model pm on po.product_model_id = pm.id
|
left join product p on pm.product_id = p.id
|
left join sales_ledger_product slp on po.sale_ledger_product_id = slp.id and slp.type = 1
|
left join (select max(id) as id, product_order_id
|
from product_process_route
|
group by product_order_id) ppr_latest on po.id = ppr_latest.product_order_id
|
left join product_process_route ppr on ppr.id = ppr_latest.id
|
left join product_bom pb on pb.id = ppr.bom_id
|
<where>
|
<if test="productModelIds != null and productModelIds.size() > 0">
|
po.product_model_id IN
|
<foreach collection="productModelIds" open="(" separator="," close=")" item="item">
|
#{item}
|
</foreach>
|
</if>
|
</where>
|
</select>
|
<select id="listByProductOrderId" resultType="com.ruoyi.production.dto.ProductOrderDto">
|
select po.*,
|
sl.sales_contract_no,
|
sl.customer_name,
|
p.product_name as product_category,
|
pm.model as specification_model,
|
pm.unit,
|
ppr.process_route_code,
|
pb.bom_no,
|
ROUND(po.complete_quantity / po.quantity * 100, 2) AS completionStatus,
|
DATEDIFF(sl.delivery_date, CURDATE()) AS delivery_days_diff,
|
sl.delivery_date,
|
CASE
|
WHEN shipping_status_counts.total_count = 0 THEN false
|
WHEN shipping_status_counts.unshipped_count = 0 THEN true
|
ELSE false
|
END AS is_fh
|
from product_order po
|
left join sales_ledger sl on po.sales_ledger_id = sl.id
|
LEFT JOIN (SELECT sales_ledger_id,
|
COUNT(*) as total_count,
|
SUM(CASE WHEN status != '已发货' THEN 1 ELSE 0 END) as unshipped_count
|
FROM shipping_info
|
GROUP BY sales_ledger_id) shipping_status_counts
|
ON sl.id = shipping_status_counts.sales_ledger_id
|
left join product_model pm on po.product_model_id = pm.id
|
left join product p on pm.product_id = p.id
|
left join sales_ledger_product slp on po.sale_ledger_product_id = slp.id and slp.type = 1
|
left join (select max(id) as id, product_order_id
|
from product_process_route
|
group by product_order_id) ppr_latest on po.id = ppr_latest.product_order_id
|
left join product_process_route ppr on ppr.id = ppr_latest.id
|
left join product_bom pb on pb.id = ppr.bom_id
|
<where>
|
<if test="productOrderIds != null and productOrderIds.size() > 0">
|
po.id IN
|
<foreach collection="productOrderIds" open="(" separator="," close=")" item="item">
|
#{item}
|
</foreach>
|
</if>
|
</where>
|
</select>
|
</mapper>
|