You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.9 KiB
XML

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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="cn.iocoder.yudao.module.mes.dal.mysql.plan.PlanMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<select id="getLastSevenDaysCompletedCount" resultType="java.util.Map">
SELECT
DATE(end_time) as date,
IFNULL(SUM(wangong_number), 0) as totalWangong
FROM mes_plan
WHERE end_time >= CURDATE() - INTERVAL 6 DAY
GROUP BY DATE(end_time)
</select>
<select id="selectQualityOverviewSummary"
resultType="cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanQualityOverviewRespVO">
SELECT
IFNULL(SUM(wangong_number), 0) AS totalWangongNumber,
IFNULL(SUM(pass_number), 0) AS totalPassNumber,
IFNULL(SUM(no_pass_number), 0) AS totalNoPassNumber
FROM mes_plan
WHERE deleted = b'0'
AND create_time <![CDATA[ >= ]]> #{startTime}
AND create_time <![CDATA[ < ]]> #{endTime}
</select>
<select id="selectQualityOverviewProductStats"
resultType="cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanQualityOverviewRespVO$ProductPassRateItem">
SELECT
product_id AS productId,
IFNULL(SUM(wangong_number), 0) AS wangongNumber,
IFNULL(SUM(pass_number), 0) AS passNumber,
IFNULL(SUM(no_pass_number), 0) AS noPassNumber
FROM mes_plan
WHERE deleted = b'0'
AND create_time <![CDATA[ >= ]]> #{startTime}
AND create_time <![CDATA[ < ]]> #{endTime}
AND product_id IS NOT NULL
GROUP BY product_id
</select>
<select id="selectQualityOverviewTrendStats"
resultType="cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanQualityOverviewRespVO$TrendItem">
SELECT
DATE(create_time) AS day,
IFNULL(SUM(pass_number), 0) AS passNumber,
IFNULL(SUM(no_pass_number), 0) AS noPassNumber
FROM mes_plan
WHERE deleted = b'0'
AND create_time <![CDATA[ >= ]]> #{startTime}
AND create_time <![CDATA[ < ]]> #{endTime}
GROUP BY DATE(create_time)
ORDER BY DATE(create_time)
</select>
<select id="selectProductCapacityPage"
resultType="cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanProductCapacityRespVO">
SELECT
pr.bar_code AS productCode,
pr.name AS productName,
SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)) AS baogongTotal,
CAST(ROUND(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)) / #{statDays}, 0) AS SIGNED) AS avgCapacity
FROM mes_baogong_record r
INNER JOIN mes_plan p ON p.id = r.plan_id AND p.deleted = b'0'
LEFT JOIN erp_product pr ON pr.id = p.product_id AND pr.deleted = b'0'
WHERE r.deleted = b'0'
AND p.device_id = #{reqVO.deviceId}
<if test="beginTime != null">
AND r.baogong_time &gt;= #{beginTime}
</if>
<if test="endTime != null">
AND r.baogong_time &lt; #{endTime}
</if>
<if test="reqVO.productCode != null and reqVO.productCode != ''">
AND pr.bar_code LIKE CONCAT('%', #{reqVO.productCode}, '%')
</if>
<if test="reqVO.productName != null and reqVO.productName != ''">
AND pr.name LIKE CONCAT('%', #{reqVO.productName}, '%')
</if>
GROUP BY p.product_id, pr.bar_code, pr.name
ORDER BY baogongTotal DESC, pr.bar_code ASC
</select>
</mapper>