<?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.moldrepairtems.MoldRepairTemsMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->

    <select id="getMoldRepairTemsPage"
            resultType="cn.iocoder.yudao.module.mes.controller.admin.moldrepairtems.vo.MoldRepairTemsRespVO">
        SELECT
        mrt.id,
        mrt.subject_code,
        mrt.subject_name,
        mrt.mold_id,
        mrt.is_enable,
        mrt.creator,
        mrt.create_time,
        mrt.updater,
        mrt.update_time,
        mrt.deleted,
        mrt.tenant_id,
        mrt.project_content,
        mml.name as moldName,  <!-- device_name 改为 mold_name，别名对应修改 -->
        CONCAT('(', su.username, ')', su.nickname) as creatorName
        FROM besure.mes_mold_repair_tems mrt
        left join besure.erp_mold mml on mml.id = mrt.mold_id  <!-- device_ledger 改为 mold_ledger，关联字段改为 mold_id -->
        left join besure.system_users su on su.id = mrt.creator
        WHERE 1=1
        AND mrt.deleted = 0
        <if test="pageReqVO.subjectCode != null and pageReqVO.subjectCode != ''">
            AND mrt.subject_code = #{pageReqVO.subjectCode}
        </if>
        <if test="pageReqVO.subjectName != null and pageReqVO.subjectName != ''">
            AND mrt.subject_name LIKE CONCAT('%', #{pageReqVO.subjectName}, '%')
        </if>
        <if test="pageReqVO.moldId != null">  <!-- deviceId 改为 moldId -->
            AND mrt.mold_id = #{pageReqVO.moldId}
        </if>
        <if test="pageReqVO.inspectionMethod != null and pageReqVO.inspectionMethod != ''">
            AND mrt.inspection_method = #{pageReqVO.inspectionMethod}
        </if>
        <if test="pageReqVO.valueType != null and pageReqVO.valueType != ''">
            AND mrt.value_type = #{pageReqVO.valueType}
        </if>
        <if test="pageReqVO.judgmentCriteria != null and pageReqVO.judgmentCriteria != ''">
            AND mrt.judgment_criteria = #{pageReqVO.judgmentCriteria}
        </if>
        <if test="pageReqVO.isEnable != null">
            AND mrt.is_enable = #{pageReqVO.isEnable}
        </if>
        <if test="pageReqVO.projectContent != null and pageReqVO.projectContent != ''">
            AND mrt.project_content LIKE CONCAT('%', #{pageReqVO.projectContent}, '%')
        </if>
        <!-- 添加 ids 过滤条件 -->
        <if test="pageReqVO.ids != null and pageReqVO.ids != ''">
            AND FIND_IN_SET(mrt.id, #{pageReqVO.ids})
        </if>
    </select>

    <select id="getMoldRepairTemsList"
            resultType="cn.iocoder.yudao.module.mes.controller.admin.moldrepairtems.vo.MoldRepairTemsRespVO">
        SELECT
        mrt.id,
        mrt.subject_code,
        mrt.subject_name,
        mrt.mold_id,
        mrt.is_enable,
        mrt.creator,
        mrt.create_time,
        mrt.updater,
        mrt.update_time,
        mrt.deleted,
        mrt.tenant_id,
        mml.name as moldName,  <!-- device_name 改为 mold_name，别名对应修改 -->
        CONCAT('(', su.username, ')', su.nickname) as creatorName
        FROM besure.mes_mold_repair_tems mrt
        left join besure.erp_mold mml on mml.id = mrt.mold_id  <!-- device_ledger 改为 mold_ledger，关联字段改为 mold_id -->
        left join besure.system_users su on su.id = mrt.creator
        WHERE mrt.deleted = 0
        <if test="pageReqVO.subjectCode != null and pageReqVO.subjectCode != ''">
            AND mrt.subject_code = #{pageReqVO.subjectCode}
        </if>
        <if test="pageReqVO.subjectName != null and pageReqVO.subjectName != ''">
            AND mrt.subject_name LIKE CONCAT('%', #{pageReqVO.subjectName}, '%')
        </if>
        <if test="pageReqVO.moldId != null">  <!-- deviceId 改为 moldId -->
            AND mrt.mold_id = #{pageReqVO.moldId}
        </if>
        <if test="pageReqVO.inspectionMethod != null and pageReqVO.inspectionMethod != ''">
            AND mrt.inspection_method = #{pageReqVO.inspectionMethod}
        </if>
        <if test="pageReqVO.valueType != null and pageReqVO.valueType != ''">
            AND mrt.value_type = #{pageReqVO.valueType}
        </if>
        <if test="pageReqVO.judgmentCriteria != null and pageReqVO.judgmentCriteria != ''">
            AND mrt.judgment_criteria = #{pageReqVO.judgmentCriteria}
        </if>
        <if test="pageReqVO.isEnable != null">
            AND mrt.is_enable = #{pageReqVO.isEnable}
        </if>
        <if test="pageReqVO.projectContent != null and pageReqVO.projectContent != ''">
            AND mrt.project_content LIKE CONCAT('%', #{pageReqVO.projectContent}, '%')
        </if>
        <!-- 添加 ids 过滤条件 -->
        <if test="pageReqVO.ids != null and pageReqVO.ids != ''">
            AND FIND_IN_SET(mrt.id, #{pageReqVO.ids})
        </if>
    </select>
</mapper>