<?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.ruoyi.project.cui.mapper.TProblemsMapper">
    
    <resultMap type="TProblems" id="TProblemsResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="serialnumber"    column="serialnumber"    />
        <result property="unit"    column="unit"    />
        <result property="lineno"    column="lineno"    />
        <result property="cuiproblem"    column="cuiproblem"    />
        <result property="analysis"    column="analysis"    />
        <result property="measures"    column="measures"    />
        <result property="plancost"    column="plancost"    />
        <result property="isfinish"    column="isfinish"    />
        <result property="finishdate"    column="finishdate"    />
        <result property="ismeasure"    column="ismeasure"    />
        <result property="responsible"    column="responsible"    />
        <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="remarks"    column="remarks"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTProblemsVo">
        select d.id, d.plant_code, d.serialnumber, d.unit, d.lineno, d.cuiproblem, d.analysis, d.measures, d.plancost, d.isfinish, d.finishdate, d.ismeasure, d.responsible, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id ,s.dept_name from t_problems d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTProblemsList" parameterType="TProblems" resultMap="TProblemsResult">
        <include refid="selectTProblemsVo"/>
        <where>  
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="lineno != null  and lineno != ''"> and lineno like concat(concat('%', #{lineno}), '%')</if>
            <if test="cuiproblem != null  and cuiproblem != ''"> and cuiproblem like concat(concat('%', #{cuiproblem}), '%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>
    
    <select id="selectTProblemsById" parameterType="Long" resultMap="TProblemsResult">
        <include refid="selectTProblemsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTProblems" parameterType="TProblems">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_problems.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_problems
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="serialnumber != null">serialnumber,</if>
            <if test="unit != null">unit,</if>
            <if test="lineno != null and lineno != ''">lineno,</if>
            <if test="cuiproblem != null">cuiproblem,</if>
            <if test="analysis != null">analysis,</if>
            <if test="measures != null">measures,</if>
            <if test="plancost != null">plancost,</if>
            <if test="isfinish == 'true'">isfinish,</if>
            <if test="finishdate != null">finishdate,</if>
            <if test="ismeasure != null">ismeasure,</if>
            <if test="responsible != null">responsible,</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="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="serialnumber != null">#{serialnumber},</if>
            <if test="unit != null">#{unit},</if>
            <if test="lineno != null and lineno != ''">#{lineno},</if>
            <if test="cuiproblem != null">#{cuiproblem},</if>
            <if test="analysis != null">#{analysis},</if>
            <if test="measures != null">#{measures},</if>
            <if test="plancost != null">#{plancost},</if>
            <if test="isfinish == 'true'">1,</if>
            <if test="finishdate != null">#{finishdate},</if>
            <if test="ismeasure != null">#{ismeasure},</if>
            <if test="responsible != null">#{responsible},</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="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTProblems" parameterType="TProblems">
        update t_problems
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="serialnumber != null">serialnumber = #{serialnumber},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="lineno != null and lineno != ''">lineno = #{lineno},</if>
            <if test="cuiproblem != null">cuiproblem = #{cuiproblem},</if>
            <if test="analysis != null">analysis = #{analysis},</if>
            <if test="measures != null">measures = #{measures},</if>
            <if test="plancost != null">plancost = #{plancost},</if>
            <if test="isfinish == 'true'">isfinish = 1,</if>
            <if test="isfinish == 'false'">isfinish = NULL,</if>
            <if test="finishdate != null">finishdate = #{finishdate},</if>
            <if test="ismeasure != null">ismeasure = #{ismeasure},</if>
            <if test="responsible != null">responsible = #{responsible},</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="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

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

    <update id="deleteTProblemsByIds" parameterType="String">
        update t_problems set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <select id="selectStatusData" resultType="com.ruoyi.project.common.domain.DataEntity">
        SELECT count(1) as dataNum,d.isfinish as dataName FROM t_problems d
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        GROUP BY isfinish
        order by dataName
    </select>

</mapper>