<?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.nantian.cloud.dbcapp.carbon.mapper.InstrumentEquipmentDao">

    <select id="findByCategoryCode" resultType="com.nantian.cloud.dbcapp.carbon.domain.ent.InstrumentEquipment">
        SELECT *
        FROM instrucment_equipment tq
        WHERE tq.CATEGORY_CODE = #{categoryCode}
        and tq.ENT_ID = (select ent_id from ent_info where ent_code = #{entCode})
    </select>

    <delete id="deleteByInsId">
        delete from instrucment_equipment
        where ID = #{id}
        and ENT_ID = #{entId}
    </delete>

    <delete id="updateByInsId">
        update instrucment_equipment
        <set>
            <if test="require != null and require != ''">REQUIRE_NUM = #{require},</if>
            <if test="actual != null and actual != ''">ACTUAL = #{actual},</if>
            <if test="inspect != null and inspect != ''">INSPECT = #{inspect},</if>
            <if test="categoryCode != null and categoryCode != ''">CATEGORY_CODE = #{categoryCode}</if>
        </set>
        where ID = #{id}
        and ENT_ID = #{entId}
    </delete>

    <select id="getList" resultType="com.nantian.cloud.dbcapp.carbon.domain.ent.InstrumentEquipment">
        SELECT  `ID`,`REQUIRE_NUM` as `require`,`ACTUAL`,`INSPECT`,`CATEGORY_CODE`,`ENT_ID`
        FROM instrucment_equipment
        WHERE ENT_ID = (select ent_id from ent_info where ent_code = #{entCode})
    </select>

    <select id="getListAll" resultType="com.nantian.cloud.dbcapp.carbon.domain.ent.InstrumentEquipment">
        SELECT  `ID`,`REQUIRE_NUM` as `require`,`ACTUAL`,`INSPECT`,`CATEGORY_CODE`,`ENT_ID`
        FROM instrucment_equipment
        WHERE ENT_ID = #{entId}
    </select>

    <select id="getEntId" resultType="String">
        select ent_id from ent_info where ent_code = #{entCode}
    </select>
</mapper>
