<?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.InstrumentInfoDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.dbcapp.carbon.domain.ent.InstrumentInfo">
        <result column="ID" property="id" />
        <result column="CODE" property="code" />
        <result column="NAME" property="name" />
        <result column="MODEL" property="model" />
        <result column="GRADE" property="grade" />
        <result column="RANGE" property="range" />
        <result column="MANUFACTURER" property="manufacturer" />
        <result column="ADDRESS" property="address" />
        <result column="VERIFY_UNIT" property="verifyUnit" />
        <result column="VERIFY_DATE" property="verifyDate" />
        <result column="VALIDATE_DATE" property="validateDate" />
        <result column="ENT_ID" property="entId" />
        <result column="CHECKDAY" property="checkDay" />
    </resultMap>

    <select id="selectByEntId" resultMap="BaseResultMap">
        SELECT  ID,`CODE`,`NAME`,`MODEL`,`GRADE`,`RANGE`,MANUFACTURER,ADDRESS,VERIFY_UNIT,VERIFY_DATE,VALIDATE_DATE,LEVEL,CATEGORY,ENT_ID,FRE_MESSURE,FRE_RECORD,FRE_TARGET,STATUS,REMARK,CHECKDAY
        FROM instrument_info
        WHERE ENT_ID = (select ent_id from ent_info where ent_code = #{entCode})
    </select>

    <select id="selectById" resultMap="BaseResultMap">
        SELECT  ID,`CODE`,`NAME`,`MODEL`,`GRADE`,`RANGE`,MANUFACTURER,ADDRESS,VERIFY_UNIT,VERIFY_DATE,VALIDATE_DATE,LEVEL,CATEGORY,ENT_ID,FRE_MESSURE,FRE_RECORD,FRE_TARGET,STATUS,REMARK,CHECKDAY
        FROM instrument_info
        WHERE ENT_ID = (select ent_id from ent_info where ent_code = #{entCode})
        <if test="id != null">
            and id = #{id}
        </if>

    </select>

    <select id="getList" resultMap="BaseResultMap">
        SELECT  ID,`CODE`,`NAME`,`MODEL`,`GRADE`,`RANGE`,MANUFACTURER,ADDRESS,VERIFY_UNIT,VERIFY_DATE,VALIDATE_DATE,LEVEL,CATEGORY,ENT_ID,FRE_MESSURE,FRE_RECORD,FRE_TARGET,STATUS,REMARK,CHECKDAY
        FROM instrument_info
        <where>
            <if test="instrumentInfo.id != null">
                and id = #{instrumentInfo.id}
            </if>
            <if test="instrumentInfo.code != null and instrumentInfo.code != ''">
                and code = #{instrumentInfo.code}
            </if>
            <if test="instrumentInfo.name != null and instrumentInfo.name != ''">
                and name like concat('%',#{instrumentInfo.name},'%')
            </if>
            <if test="instrumentInfo.model != null and instrumentInfo.model != ''">
                and model = #{model}
            </if>
            <if test="instrumentInfo.grade != null and instrumentInfo.grade != ''">
                and grade = #{instrumentInfo.grade}
            </if>
            <if test="instrumentInfo.range != null and instrumentInfo.range != ''">
                and `range` = #{instrumentInfo.range}
            </if>
            <if test="instrumentInfo.manufacturer != null and instrumentInfo.manufacturer != ''">
                and manufacturer = #{instrumentInfo.manufacturer}
            </if>
            <if test="instrumentInfo.address != null and instrumentInfo.address != ''">
                and address = #{instrumentInfo.address}
            </if>
            <if test="instrumentInfo.verifyUnit != null and instrumentInfo.verifyUnit != ''">
                and verify_unit = #{instrumentInfo.verifyUnit}
            </if>
            <if test="instrumentInfo.verifyDate != null">
                and verify_date = #{instrumentInfo.verifyDate}
            </if>
            <if test="instrumentInfo.validateDate != null">
                and validate_date = #{instrumentInfo.validateDate}
            </if>
            <if test="instrumentInfo.entId != null and instrumentInfo.entId != ''">
                and ent_id = #{instrumentInfo.entId}
            </if>
            <if test="instrumentInfo.entCode != null and instrumentInfo.entCode != ''">
                and ent_id = (select ent_id from ent_info where ent_code = #{instrumentInfo.entCode})
            </if>
            <if test="instrumentInfo.freMessure != null and instrumentInfo.freMessure != ''">
                and fre_messure = #{instrumentInfo.freMessure}
            </if>
            <if test="instrumentInfo.freRecord != null and instrumentInfo.freRecord != ''">
                and fre_record = #{instrumentInfo.freRecord}
            </if>
            <if test="instrumentInfo.freTarget != null and instrumentInfo.freTarget != ''">
                and fre_target = #{instrumentInfo.freTarget}
            </if>
            <if test="instrumentInfo.status != null">
                and status = #{instrumentInfo.status}
            </if>
            <if test="instrumentInfo.level != null">
                and `level` = #{instrumentInfo.level}
            </if>
            <if test="instrumentInfo.category != null">
                and category = #{instrumentInfo.category}
            </if>
            <if test="instrumentInfo.checkDay != null">
                and checkday = #{instrumentInfo.checkDay}
            </if>
        </where>
    </select>

    <select id="listAll" resultMap="BaseResultMap">
        SELECT  ID,`CODE`,`NAME`,`MODEL`,`GRADE`,`RANGE`,MANUFACTURER,ADDRESS,VERIFY_UNIT,VERIFY_DATE,VALIDATE_DATE,LEVEL,CATEGORY,ENT_ID,FRE_MESSURE,FRE_RECORD,FRE_TARGET,STATUS,REMARK,CHECKDAY
        FROM instrument_info
        <where>
            <if test="instrumentInfo.id != null">
                and id = #{instrumentInfo.id}
            </if>
            <if test="instrumentInfo.code != null and instrumentInfo.code != ''">
                and code = #{instrumentInfo.code}
            </if>
            <if test="instrumentInfo.name != null and instrumentInfo.name != ''">
                and name like concat('%',#{instrumentInfo.name},'%')
            </if>
            <if test="instrumentInfo.model != null and instrumentInfo.model != ''">
                and model = #{model}
            </if>
            <if test="instrumentInfo.grade != null and instrumentInfo.grade != ''">
                and grade = #{instrumentInfo.grade}
            </if>
            <if test="instrumentInfo.range != null and instrumentInfo.range != ''">
                and `range` = #{instrumentInfo.range}
            </if>
            <if test="instrumentInfo.manufacturer != null and instrumentInfo.manufacturer != ''">
                and manufacturer = #{instrumentInfo.manufacturer}
            </if>
            <if test="instrumentInfo.address != null and instrumentInfo.address != ''">
                and address = #{instrumentInfo.address}
            </if>
            <if test="instrumentInfo.verifyUnit != null and instrumentInfo.verifyUnit != ''">
                and verify_unit = #{instrumentInfo.verifyUnit}
            </if>
            <if test="instrumentInfo.verifyDate != null">
                and verify_date = #{instrumentInfo.verifyDate}
            </if>
            <if test="instrumentInfo.validateDate != null">
                and validate_date = #{instrumentInfo.validateDate}
            </if>
            <if test="instrumentInfo.entId != null and instrumentInfo.entId != ''">
                and ent_id = #{instrumentInfo.entId}
            </if>
            <if test="instrumentInfo.freMessure != null and instrumentInfo.freMessure != ''">
                and fre_messure = #{instrumentInfo.freMessure}
            </if>
            <if test="instrumentInfo.freRecord != null and instrumentInfo.freRecord != ''">
                and fre_record = #{instrumentInfo.freRecord}
            </if>
            <if test="instrumentInfo.freTarget != null and instrumentInfo.freTarget != ''">
                and fre_target = #{instrumentInfo.freTarget}
            </if>
            <if test="instrumentInfo.status != null">
                and status = #{instrumentInfo.status}
            </if>
            <if test="instrumentInfo.level != null">
                and `level` = #{instrumentInfo.level}
            </if>
            <if test="instrumentInfo.category != null">
                and category = #{instrumentInfo.category}
            </if>
            <if test="instrumentInfo.checkDay != null">
                and checkday = #{instrumentInfo.checkDay}
            </if>
        </where>
    </select>

    <insert id="saveInfo" keyProperty="id" keyColumn="id" useGeneratedKeys="true">
        insert into instrument_info(code,name,model,grade,`range`,manufacturer,address,verify_unit,verify_date,validate_date,create_date,ent_id,fre_messure,fre_record,fre_target,status,remark,level,category,checkday)
        values (#{instrumentInfo.code},#{instrumentInfo.name},#{instrumentInfo.model},#{instrumentInfo.grade},
                #{instrumentInfo.range},#{instrumentInfo.manufacturer},#{instrumentInfo.address},
                #{instrumentInfo.verifyUnit},#{instrumentInfo.verifyDate},#{instrumentInfo.validateDate},
                now(),#{instrumentInfo.entId},#{instrumentInfo.freMessure},#{instrumentInfo.freRecord},
                #{instrumentInfo.freTarget},#{instrumentInfo.status},#{instrumentInfo.remark},
                #{instrumentInfo.level},#{instrumentInfo.category},#{instrumentInfo.checkDay})
    </insert>

    <update id="updateInfoById">
        update instrument_info
        <set>
            <if test="instrumentInfo.code != null and instrumentInfo.code != ''">
                 code = #{instrumentInfo.code},
            </if>
            <if test="instrumentInfo.name != null and instrumentInfo.name != ''">
                 `name` = #{instrumentInfo.name},
            </if>
            <if test="instrumentInfo.grade != null and instrumentInfo.grade != ''">
                 grade = #{instrumentInfo.grade},
            </if>
            <if test="instrumentInfo.range != null and instrumentInfo.range != ''">
                 `range` = #{instrumentInfo.range},
            </if>
            <if test="instrumentInfo.manufacturer != null and instrumentInfo.manufacturer != ''">
                 manufacturer = #{instrumentInfo.manufacturer},
            </if>
            <if test="instrumentInfo.address != null and instrumentInfo.address != ''">
                 address = #{instrumentInfo.address},
            </if>
            <if test="instrumentInfo.verifyUnit != null and instrumentInfo.verifyUnit != ''">
                 verify_unit = #{instrumentInfo.verifyUnit},
            </if>
            <if test="instrumentInfo.verifyDate != null">
                 verify_date = #{instrumentInfo.verifyDate},
            </if>
            <if test="instrumentInfo.validateDate != null">
                 validate_date = #{instrumentInfo.validateDate},
            </if>
            <if test="instrumentInfo.entId != null and instrumentInfo.entId != ''">
                 ent_id = #{instrumentInfo.entId},
            </if>
            <if test="instrumentInfo.freMessure != null and instrumentInfo.freMessure != ''">
                 fre_messure = #{instrumentInfo.freMessure},
            </if>
            <if test="instrumentInfo.freRecord != null and instrumentInfo.freRecord != ''">
                 fre_record = #{instrumentInfo.freRecord},
            </if>
            <if test="instrumentInfo.freTarget != null and instrumentInfo.freTarget != ''">
                 fre_target = #{instrumentInfo.freTarget},
            </if>
            <if test="instrumentInfo.status != null">
                 status = #{instrumentInfo.status},
            </if>
            <if test="instrumentInfo.level != null">
                 `level` = #{instrumentInfo.level},
            </if>
            <if test="instrumentInfo.category != null">
                 category = #{instrumentInfo.category},
            </if>
            <if test="instrumentInfo.checkDay != null">
                 checkday = #{instrumentInfo.checkDay},
            </if>
        </set>
        where id = #{instrumentInfo.id}
    </update>



</mapper>
