<?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.cpms.project.sems.mapper.TSpecdevAqfMapper">

    <resultMap type="TSpecdevAqf" id="TSpecdevAqfResult">
        <result property="id"    column="id"    />
        <result property="mainId"    column="main_id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="devno"    column="devno"    />
        <result property="pidNo"    column="pid_no"    />
        <result property="describe"    column="describe"    />
        <result property="medium"    column="medium"    />
        <result property="mediumPhase"    column="medium_phase"    />
        <result property="starting"    column="starting"    />
        <result property="arrive"    column="arrive"    />
        <result property="manufacturer"    column="manufacturer"    />
        <result property="model"    column="model"    />
        <result property="factoryNo"    column="factory_no"    />
        <result property="valveType"    column="valve_type"    />
        <result property="datasheet"    column="datasheet"    />
        <result property="calculationBook"    column="calculation_book"    />
        <result property="selectedArea"    column="selected_area"    />
        <result property="senarios"    column="senarios"    />
        <result property="requiredRelieving"    column="required_relieving"    />
        <result property="ratedRelieving"    column="rated_relieving"    />
        <result property="inletSize"    column="inlet_size"    />
        <result property="pressureRating"    column="pressure_rating"    />
        <result property="outSize"    column="out_size"    />
        <result property="outPressureRating"    column="out_pressure_rating"    />
        <result property="setPressure"    column="set_pressure"    />
        <result property="backPressure"    column="back_pressure"    />
        <result property="isInspection"    column="is_inspection"    />
        <result property="warnDate"    column="warn_date"    />
        <result property="nextWarnDate"    column="next_warn_date"    />
        <result property="needScaffold"    column="need_scaffold"    />
        <result property="keepWarm"    column="keep_warm"    />
        <result property="crane"    column="crane"    />
        <result property="submitdate"    column="submitdate"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="approveStatus"    column="approve_status"    />
        <result property="approveTime"    column="approve_time"    />
        <result property="changeTime"    column="change_time"    />
        <result property="deptName" column="dept_name" />
        <result property="devName" column="dev_name"/>
        <result property="devEnname" column="dev_enname"/>
        <result property="isPid" column="is_pid"/>
        <result property="installPosition" column="install_position"/>
        <result property="funcPosition" column="func_position"/>
        <result property="assetNo" column="asset_no"/>
        <result property="securityRelevant" column="security_relevant"/>
        <result property="securityRelevantFrom" column="security_relevant_from"/>
        <result property="productionYear" column="production_year"/>
        <result property="mainSpecifications" column="main_specifications"/>
        <result property="dataPlate" column="data_plate"/>
        <result property="dataPlate" column="data_plate"/>
    </resultMap>

    <sql id="selectTSpecdevAqfVo">
        select d.id,d.main_id, d.plant_code, d.devno, d.pid_no, d.describe, d.medium, d.medium_phase, d.starting, d.arrive, d.manufacturer, d.model, d.factory_no, d.valve_type, d.datasheet, d.calculation_book, d.selected_area, d.senarios, d.required_relieving, d.rated_relieving, d.inlet_size, d.pressure_rating, d.out_size, d.out_pressure_rating, d.set_pressure, d.back_pressure, d.is_inspection, d.warn_date, d.next_warn_date, d.need_scaffold, d.keep_warm, d.crane, d.submitdate, d.status, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks, d.approve_status, d.approve_time, d.change_time ,
               d.dev_name,d.dev_enname,d.is_pid,d.install_position,d.func_position,d.asset_no,d.security_relevant,d.security_relevant_from,d.production_year,d.main_specifications,d.data_plate,s.dept_name from t_specdev_aqf d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTSpecdevAqfList" parameterType="TSpecdevAqf" resultMap="TSpecdevAqfResult">
        <include refid="selectTSpecdevAqfVo"/>
        <where>
            <if test="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="mainId != null  and mainId != ''"> and main_id = #{mainId}</if>
            <if test="devno != null  and devno != ''"> and devno = #{devno}</if>
            <if test="pidNo != null  and pidNo != ''"> and pid_no = #{pidNo}</if>
            <if test="describe != null  and describe != ''"> and describe = #{describe}</if>
            <if test="medium != null  and medium != ''"> and medium = #{medium}</if>
            <if test="mediumPhase != null  and mediumPhase != ''"> and medium_phase = #{mediumPhase}</if>
            <if test="starting != null  and starting != ''"> and starting = #{starting}</if>
            <if test="arrive != null  and arrive != ''"> and arrive = #{arrive}</if>
            <if test="manufacturer != null  and manufacturer != ''"> and manufacturer = #{manufacturer}</if>
            <if test="model != null  and model != ''"> and model = #{model}</if>
            <if test="factoryNo != null  and factoryNo != ''"> and factory_no = #{factoryNo}</if>
            <if test="valveType != null  and valveType != ''"> and valve_type = #{valveType}</if>
            <if test="datasheet != null  and datasheet != ''"> and datasheet = #{datasheet}</if>
            <if test="calculationBook != null  and calculationBook != ''"> and calculation_book = #{calculationBook}</if>
            <if test="selectedArea != null  and selectedArea != ''"> and selected_area = #{selectedArea}</if>
            <if test="senarios != null  and senarios != ''"> and senarios = #{senarios}</if>
            <if test="requiredRelieving != null  and requiredRelieving != ''"> and required_relieving = #{requiredRelieving}</if>
            <if test="ratedRelieving != null  and ratedRelieving != ''"> and rated_relieving = #{ratedRelieving}</if>
            <if test="inletSize != null  and inletSize != ''"> and inlet_size = #{inletSize}</if>
            <if test="pressureRating != null  and pressureRating != ''"> and pressure_rating = #{pressureRating}</if>
            <if test="outSize != null  and outSize != ''"> and out_size = #{outSize}</if>
            <if test="outPressureRating != null  and outPressureRating != ''"> and out_pressure_rating = #{outPressureRating}</if>
            <if test="setPressure != null  and setPressure != ''"> and set_pressure =  #{setPressure}</if>
            <if test="backPressure != null  and backPressure != ''"> and back_pressure = #{backPressure}</if>
            <if test="isInspection != null  and isInspection != ''"> and is_inspection = #{isInspection}</if>
            <if test="warnDate != null  and warnDate != ''"> and warn_date = #{warnDate}</if>
            <if test="nextWarnDate != null  and nextWarnDate != ''"> and next_warn_date = #{nextWarnDate}</if>
            <if test="needScaffold != null  and needScaffold != ''"> and need_scaffold = #{needScaffold}</if>
            <if test="keepWarm != null  and keepWarm != ''"> and keep_warm = #{keepWarm}</if>
            <if test="crane != null  and crane != ''"> and crane = #{crane}</if>
            <if test="submitdate != null "> and submitdate = #{submitdate}</if>
            <if test="status != null "> and d.status = #{status}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="approveStatus != null "> and approve_status = #{approveStatus}</if>
            <if test="approveTime != null "> and approve_time = #{approveTime}</if>
            <if test="changeTime != null "> and change_time = #{changeTime}</if>
            <if test="fuzzy != null and fuzzy!=''"> and (plant_code like concat('%',#{fuzzy},'%')
                or devno like concat('%',#{fuzzy},'%')
                or pid_no like concat('%',#{fuzzy},'%')
                or `describe` like concat('%',#{fuzzy},'%')
                or `medium` like concat('%',#{fuzzy},'%')
                or medium_phase like concat('%',#{fuzzy},'%')
                or `starting` like concat('%',#{fuzzy},'%')
                or arrive like concat('%',#{fuzzy},'%')
                or manufacturer like concat('%',#{fuzzy},'%')
                or model like concat('%',#{fuzzy},'%')
                or factory_no like concat('%',#{fuzzy},'%')
                or valve_type like concat('%',#{fuzzy},'%')
                or datasheet like concat('%',#{fuzzy},'%')
                or calculation_book like concat('%',#{fuzzy},'%')
                or selected_area like concat('%',#{fuzzy},'%')
                or senarios like concat('%',#{fuzzy},'%')
                or required_relieving like concat('%',#{fuzzy},'%')
                or rated_relieving like concat('%',#{fuzzy},'%')
                or inlet_size like concat('%',#{fuzzy},'%')
                or pressure_rating like concat('%',#{fuzzy},'%')
                or out_size like concat('%',#{fuzzy},'%')
                or out_pressure_rating like concat('%',#{fuzzy},'%')
                or set_pressure like concat('%',#{fuzzy},'%')
                or back_pressure like concat('%',#{fuzzy},'%')
                or is_inspection like concat('%',#{fuzzy},'%')
                or warn_date like concat('%',#{fuzzy},'%')
                or next_warn_date like concat('%',#{fuzzy},'%')
                or need_scaffold like concat('%',#{fuzzy},'%')
                or keep_warm like concat('%',#{fuzzy},'%')
                or crane like concat('%',#{fuzzy},'%')
                or submitdate like concat('%',#{fuzzy},'%')
                or remarks like concat('%',#{fuzzy},'%')
                )</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTSpecdevAqfById" parameterType="Long" resultMap="TSpecdevAqfResult">
        <include refid="selectTSpecdevAqfVo"/>
        where id = #{id}
    </select>

    <insert id="insertTSpecdevAqf" parameterType="TSpecdevAqf" useGeneratedKeys="true" keyProperty="id">
        insert into t_specdev_aqf
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="devno != null">devno,</if>
            <if test="pidNo != null">pid_no,</if>
            <if test="describe != null">`describe`,</if>
            <if test="medium != null">`medium`,</if>
            <if test="mediumPhase != null">medium_phase,</if>
            <if test="starting != null">`starting`,</if>
            <if test="arrive != null">arrive,</if>
            <if test="manufacturer != null">manufacturer,</if>
            <if test="model != null">model,</if>
            <if test="factoryNo != null">factory_no,</if>
            <if test="valveType != null">valve_type,</if>
            <if test="datasheet != null">datasheet,</if>
            <if test="calculationBook != null">calculation_book,</if>
            <if test="selectedArea != null">selected_area,</if>
            <if test="senarios != null">senarios,</if>
            <if test="requiredRelieving != null">required_relieving,</if>
            <if test="ratedRelieving != null">rated_relieving,</if>
            <if test="inletSize != null">inlet_size,</if>
            <if test="pressureRating != null">pressure_rating,</if>
            <if test="outSize != null">out_size,</if>
            <if test="outPressureRating != null">out_pressure_rating,</if>
            <if test="setPressure != null">set_pressure,</if>
            <if test="backPressure != null">back_pressure,</if>
            <if test="isInspection != null">is_inspection,</if>
            <if test="warnDate != null">warn_date,</if>
            <if test="nextWarnDate != null">next_warn_date,</if>
            <if test="needScaffold != null">need_scaffold,</if>
            <if test="keepWarm != null">keep_warm,</if>
            <if test="crane != null">crane,</if>
            <if test="submitdate != null">submitdate,</if>
            <if test="status != null">`status`,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
            <if test="approveStatus != null">approve_status,</if>
            <if test="approveTime != null">approve_time,</if>
            <if test="changeTime != null">change_time,</if>
            <if test="devName != null">dev_name,</if>
            <if test="devEnname != null">dev_enname,</if>
            <if test="isPid != null">is_pid,</if>
            <if test="installPosition != null">install_position,</if>
            <if test="funcPosition != null">func_position,</if>
            <if test="assetNo != null">asset_no,</if>
            <if test="securityRelevant != null">security_relevant,</if>
            <if test="securityRelevantFrom != null">security_relevant_from,</if>
            <if test="productionYear != null">production_year,</if>
            <if test="mainSpecifications != null">main_specifications,</if>
            <if test="dataPlate != null">data_plate,</if>
            <if test="mainId != null">main_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="devno != null">#{devno},</if>
            <if test="pidNo != null">#{pidNo},</if>
            <if test="describe != null">#{describe},</if>
            <if test="medium != null">#{medium},</if>
            <if test="mediumPhase != null">#{mediumPhase},</if>
            <if test="starting != null">#{starting},</if>
            <if test="arrive != null">#{arrive},</if>
            <if test="manufacturer != null">#{manufacturer},</if>
            <if test="model != null">#{model},</if>
            <if test="factoryNo != null">#{factoryNo},</if>
            <if test="valveType != null">#{valveType},</if>
            <if test="datasheet != null">#{datasheet},</if>
            <if test="calculationBook != null">#{calculationBook},</if>
            <if test="selectedArea != null">#{selectedArea},</if>
            <if test="senarios != null">#{senarios},</if>
            <if test="requiredRelieving != null">#{requiredRelieving},</if>
            <if test="ratedRelieving != null">#{ratedRelieving},</if>
            <if test="inletSize != null">#{inletSize},</if>
            <if test="pressureRating != null">#{pressureRating},</if>
            <if test="outSize != null">#{outSize},</if>
            <if test="outPressureRating != null">#{outPressureRating},</if>
            <if test="setPressure != null">#{setPressure},</if>
            <if test="backPressure != null">#{backPressure},</if>
            <if test="isInspection != null">#{isInspection},</if>
            <if test="warnDate != null">#{warnDate},</if>
            <if test="nextWarnDate != null">#{nextWarnDate},</if>
            <if test="needScaffold != null">#{needScaffold},</if>
            <if test="keepWarm != null">#{keepWarm},</if>
            <if test="crane != null">#{crane},</if>
            <if test="submitdate != null">#{submitdate},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="approveStatus != null">#{approveStatus},</if>
            <if test="approveTime != null">#{approveTime},</if>
            <if test="changeTime != null">#{changeTime},</if>
            <if test="devName != null">#{devName},</if>
            <if test="devEnname != null">#{devEnname},</if>
            <if test="isPid != null">#{isPid},</if>
            <if test="installPosition != null">#{installPosition},</if>
            <if test="funcPosition != null">#{funcPosition},</if>
            <if test="assetNo != null">#{assetNo},</if>
            <if test="securityRelevant != null">#{securityRelevant},</if>
            <if test="securityRelevantFrom != null">#{securityRelevantFrom},</if>
            <if test="productionYear != null">#{productionYear},</if>
            <if test="mainSpecifications != null">#{mainSpecifications},</if>
            <if test="dataPlate != null">#{dataPlate},</if>
            <if test="dataPlate != null">#{dataPlate},</if>
            <if test="mainId != null">#{mainId},</if>
         </trim>
    </insert>

    <update id="updateTSpecdevAqf" parameterType="TSpecdevAqf">
        update t_specdev_aqf
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="devno != null">devno = #{devno},</if>
            <if test="pidNo != null">pid_no = #{pidNo},</if>
            <if test="describe != null">`describe` = #{describe},</if>
            <if test="medium != null">`medium` = #{medium},</if>
            <if test="mediumPhase != null">medium_phase = #{mediumPhase},</if>
            <if test="starting != null">`starting` = #{starting},</if>
            <if test="arrive != null">arrive = #{arrive},</if>
            <if test="manufacturer != null">manufacturer = #{manufacturer},</if>
            <if test="model != null">model = #{model},</if>
            <if test="factoryNo != null">factory_no = #{factoryNo},</if>
            <if test="valveType != null">valve_type = #{valveType},</if>
            <if test="datasheet != null">datasheet = #{datasheet},</if>
            <if test="calculationBook != null">calculation_book = #{calculationBook},</if>
            <if test="selectedArea != null">selected_area = #{selectedArea},</if>
            <if test="senarios != null">senarios = #{senarios},</if>
            <if test="requiredRelieving != null">required_relieving = #{requiredRelieving},</if>
            <if test="ratedRelieving != null">rated_relieving = #{ratedRelieving},</if>
            <if test="inletSize != null">inlet_size = #{inletSize},</if>
            <if test="pressureRating != null">pressure_rating = #{pressureRating},</if>
            <if test="outSize != null">out_size = #{outSize},</if>
            <if test="outPressureRating != null">out_pressure_rating = #{outPressureRating},</if>
            <if test="setPressure != null">set_pressure = #{setPressure},</if>
            <if test="backPressure != null">back_pressure = #{backPressure},</if>
            <if test="isInspection != null">is_inspection = #{isInspection},</if>
            <if test="warnDate != null">warn_date = #{warnDate},</if>
            <if test="nextWarnDate != null">next_warn_date = #{nextWarnDate},</if>
            <if test="needScaffold != null">need_scaffold = #{needScaffold},</if>
            <if test="keepWarm != null">keep_warm = #{keepWarm},</if>
            <if test="crane != null">crane = #{crane},</if>
            <if test="submitdate != null">submitdate = #{submitdate},</if>
            <if test="status != null">`status` = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="approveStatus != null">approve_status = #{approveStatus},</if>
            <if test="approveTime != null">approve_time = #{approveTime},</if>
            <if test="changeTime != null">change_time = #{changeTime},</if>
            <if test="devName != null">dev_name = #{devName},</if>
            <if test="devEnname != null">dev_enname = #{devEnname},</if>
            <if test="isPid != null">is_pid = #{isPid},</if>
            <if test="installPosition != null">install_position = #{installPosition},</if>
            <if test="funcPosition != null">func_position = #{funcPosition},</if>
            <if test="assetNo != null">asset_no = #{assetNo},</if>
            <if test="securityRelevant != null">security_relevant = #{securityRelevant},</if>
            <if test="securityRelevantFrom != null">security_relevant_from = #{securityRelevantFrom},</if>
            <if test="productionYear != null">production_year = #{productionYear},</if>
            <if test="mainSpecifications != null">main_specifications = #{mainSpecifications},</if>
            <if test="dataPlate != null">data_plate = #{dataPlate},</if>
        </trim>
        <where>
            <if test="id != null">and id = #{id}</if>
        </where>
    </update>

    <update id="deleteTSpecdevAqfById" parameterType="Long">
        update t_specdev_aqf set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTSpecdevAqfByMainId" parameterType="Long">
        update t_specdev_aqf set del_flag = 2 where main_id = #{mainId}
    </update>

    <update id="deleteTSpecdevAqfByIds" parameterType="String">
        update t_specdev_aqf set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
