<?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.asset.mapper.TSpecdevMainMapper">

    <resultMap type="TSpecdevMain" id="TSpecdevMainResult">
        <result property="id"    column="id"    />
        <result property="devName"    column="dev_name"    />
        <result property="devEnname"    column="dev_enname"    />
        <result property="devno"    column="devno"    />
        <result property="isPid"    column="is_pid"    />
        <result property="pidNo"    column="pid_no"    />
        <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="manufacturer"    column="manufacturer"    />
        <result property="productionYear"    column="production_year"    />
        <result property="model"    column="model"    />
        <result property="mainSpecifications"    column="main_specifications"    />
        <result property="dataPlate"    column="data_plate"    />
        <result property="maintenanceRisk"    column="maintenance_risk"    />
        <result property="productionRisk"    column="production_risk"    />
        <result property="devGrade"    column="dev_grade"    />
        <result property="devFrom"    column="dev_from"    />
        <result property="devType1"    column="dev_type1"    />
        <result property="devType2"    column="dev_type2"    />
        <result property="assetStatus"    column="asset_status"    />
        <result property="dataIntegrity"    column="data_integrity"    />
        <result property="pmStatus"    column="pm_status"    />
        <result property="assetResidueLifeAssess"    column="asset_residue_life_assess"    />
        <result property="overallAssetStatus"    column="overall_asset_status"    />
        <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="deptName" column="dept_name" />
        <result property="subId" column="sub_id" />
    </resultMap>

    <sql id="selectTSpecdevMainVo">
        select d.sub_id,d.id, d.dev_name, d.dev_enname, d.devno, d.is_pid, d.pid_no, d.install_position, d.func_position, d.asset_no, d.security_relevant, d.security_relevant_from, d.manufacturer, d.production_year, d.model, d.main_specifications, d.data_plate, d.maintenance_risk, d.production_risk, d.dev_grade, d.dev_from, d.dev_type1, d.dev_type2, d.asset_status, d.data_integrity, d.pm_status, d.asset_residue_life_assess, d.overall_asset_status, d.status, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_specdev_main d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTSpecdevMainList" parameterType="TSpecdevMain" resultMap="TSpecdevMainResult">
        <include refid="selectTSpecdevMainVo"/>
        <where>
            <if test="devName != null  and devName != ''"> and dev_name like concat(concat('%', #{devName}), '%')</if>
            <if test="devEnname != null  and devEnname != ''"> and dev_enname like concat(concat('%', #{devEnname}), '%')</if>
            <if test="devno != null  and devno != ''"> and devno = #{devno}</if>
            <if test="isPid != null  and isPid != ''"> and is_pid = #{isPid}</if>
            <if test="pidNo != null  and pidNo != ''"> and pid_no = #{pidNo}</if>
            <if test="installPosition != null  and installPosition != ''"> and install_position = #{installPosition}</if>
            <if test="funcPosition != null  and funcPosition != ''"> and func_position = #{funcPosition}</if>
            <if test="assetNo != null  and assetNo != ''"> and asset_no = #{assetNo}</if>
            <if test="securityRelevant != null  and securityRelevant != ''"> and security_relevant = #{securityRelevant}</if>
            <if test="securityRelevantFrom != null  and securityRelevantFrom != ''"> and security_relevant_from = #{securityRelevantFrom}</if>
            <if test="manufacturer != null  and manufacturer != ''"> and manufacturer = #{manufacturer}</if>
            <if test="productionYear != null  and productionYear != ''"> and production_year = #{productionYear}</if>
            <if test="model != null  and model != ''"> and model = #{model}</if>
            <if test="mainSpecifications != null  and mainSpecifications != ''"> and main_specifications = #{mainSpecifications}</if>
            <if test="dataPlate != null  and dataPlate != ''"> and data_plate = #{dataPlate}</if>
            <if test="maintenanceRisk != null  and maintenanceRisk != ''"> and maintenance_risk = #{maintenanceRisk}</if>
            <if test="productionRisk != null  and productionRisk != ''"> and production_risk = #{productionRisk}</if>
            <if test="devGrade != null  and devGrade != ''"> and dev_grade = #{devGrade}</if>
            <if test="devFrom != null  and devFrom != ''"> and dev_from = #{devFrom}</if>
            <if test="devType1 != null  and devType1 != ''"> and dev_type1 = #{devType1}</if>
            <if test="devType2 != null  and devType2 != ''"> and dev_type2 = #{devType2}</if>
            <if test="assetStatus != null  and assetStatus != ''"> and asset_status = #{assetStatus}</if>
            <if test="dataIntegrity != null  and dataIntegrity != ''"> and data_integrity = #{dataIntegrity}</if>
            <if test="pmStatus != null  and pmStatus != ''"> and pm_status = #{pmStatus}</if>
            <if test="assetResidueLifeAssess != null  and assetResidueLifeAssess != ''"> and asset_residue_life_assess = #{assetResidueLifeAssess}</if>
            <if test="overallAssetStatus != null  and overallAssetStatus != ''"> and overall_asset_status = #{overallAssetStatus}</if>
            <if test="status != null "> and 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="fuzzy != null  and fuzzy != ''"> and (
                dev_name like concat('%',#{fuzzy},'%') or
                dev_enname like concat('%',#{fuzzy},'%') or
                devno like concat('%',#{fuzzy},'%') or
                pid_no like concat('%',#{fuzzy},'%') or
                install_position like concat('%',#{fuzzy},'%') or
                func_position like concat('%',#{fuzzy},'%') or
                asset_no like concat('%',#{fuzzy},'%') or
                security_relevant like concat('%',#{fuzzy},'%') or
                security_relevant_from like concat('%',#{fuzzy},'%') or
                manufacturer like concat('%',#{fuzzy},'%') or
                production_year like concat('%',#{fuzzy},'%') or
                model like concat('%',#{fuzzy},'%') or
                main_specifications like concat('%',#{fuzzy},'%') or
                data_plate like concat('%',#{fuzzy},'%') or
                maintenance_risk like concat('%',#{fuzzy},'%') or
                production_risk like concat('%',#{fuzzy},'%') or
                dev_grade like concat('%',#{fuzzy},'%') or
                dev_from like concat('%',#{fuzzy},'%') or
                remarks like concat('%',#{fuzzy},'%')
                )</if>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTSpecdevMainById" parameterType="Long" resultMap="TSpecdevMainResult">
        <include refid="selectTSpecdevMainVo"/>
        where id = #{id}
    </select>

    <insert id="insertTSpecdevMain" parameterType="TSpecdevMain" useGeneratedKeys="true" keyProperty="id">
        insert into t_specdev_main
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="devName != null">dev_name,</if>
            <if test="devEnname != null">dev_enname,</if>
            <if test="devno != null">devno,</if>
            <if test="isPid != null">is_pid,</if>
            <if test="pidNo != null">pid_no,</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="manufacturer != null">manufacturer,</if>
            <if test="productionYear != null">production_year,</if>
            <if test="model != null">model,</if>
            <if test="mainSpecifications != null">main_specifications,</if>
            <if test="dataPlate != null">data_plate,</if>
            <if test="maintenanceRisk != null">maintenance_risk,</if>
            <if test="productionRisk != null">production_risk,</if>
            <if test="devGrade != null">dev_grade,</if>
            <if test="devFrom != null">dev_from,</if>
            <if test="devType1 != null">dev_type1,</if>
            <if test="devType2 != null">dev_type2,</if>
            <if test="assetStatus != null">asset_status,</if>
            <if test="dataIntegrity != null">data_integrity,</if>
            <if test="pmStatus != null">pm_status,</if>
            <if test="assetResidueLifeAssess != null">asset_residue_life_assess,</if>
            <if test="overallAssetStatus != null">overall_asset_status,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</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="subId != null">sub_id,</if>
            createdate,
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="devName != null">#{devName},</if>
            <if test="devEnname != null">#{devEnname},</if>
            <if test="devno != null">#{devno},</if>
            <if test="isPid != null">#{isPid},</if>
            <if test="pidNo != null">#{pidNo},</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="manufacturer != null">#{manufacturer},</if>
            <if test="productionYear != null">#{productionYear},</if>
            <if test="model != null">#{model},</if>
            <if test="mainSpecifications != null">#{mainSpecifications},</if>
            <if test="dataPlate != null">#{dataPlate},</if>
            <if test="maintenanceRisk != null">#{maintenanceRisk},</if>
            <if test="productionRisk != null">#{productionRisk},</if>
            <if test="devGrade != null">#{devGrade},</if>
            <if test="devFrom != null">#{devFrom},</if>
            <if test="devType1 != null">#{devType1},</if>
            <if test="devType2 != null">#{devType2},</if>
            <if test="assetStatus != null">#{assetStatus},</if>
            <if test="dataIntegrity != null">#{dataIntegrity},</if>
            <if test="pmStatus != null">#{pmStatus},</if>
            <if test="assetResidueLifeAssess != null">#{assetResidueLifeAssess},</if>
            <if test="overallAssetStatus != null">#{overallAssetStatus},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</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="subId != null">#{subId},</if>
            now(),
         </trim>
    </insert>

    <update id="updateTSpecdevMain" parameterType="TSpecdevMain">
        update t_specdev_main
        <trim prefix="SET" suffixOverrides=",">
            <if test="devName != null">dev_name = #{devName},</if>
            <if test="devEnname != null">dev_enname = #{devEnname},</if>
            <if test="devno != null">devno = #{devno},</if>
            <if test="isPid != null">is_pid = #{isPid},</if>
            <if test="pidNo != null">pid_no = #{pidNo},</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="manufacturer != null">manufacturer = #{manufacturer},</if>
            <if test="productionYear != null">production_year = #{productionYear},</if>
            <if test="model != null">model = #{model},</if>
            <if test="mainSpecifications != null">main_specifications = #{mainSpecifications},</if>
            <if test="dataPlate != null">data_plate = #{dataPlate},</if>
            <if test="maintenanceRisk != null">maintenance_risk = #{maintenanceRisk},</if>
            <if test="productionRisk != null">production_risk = #{productionRisk},</if>
            <if test="devGrade != null">dev_grade = #{devGrade},</if>
            <if test="devFrom != null">dev_from = #{devFrom},</if>
            <if test="devType1 != null">dev_type1 = #{devType1},</if>
            <if test="devType2 != null">dev_type2 = #{devType2},</if>
            <if test="assetStatus != null">asset_status = #{assetStatus},</if>
            <if test="dataIntegrity != null">data_integrity = #{dataIntegrity},</if>
            <if test="pmStatus != null">pm_status = #{pmStatus},</if>
            <if test="assetResidueLifeAssess != null">asset_residue_life_assess = #{assetResidueLifeAssess},</if>
            <if test="overallAssetStatus != null">overall_asset_status = #{overallAssetStatus},</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="subId != null">sub_id = #{subId},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
