<?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.production.mapper.TAlarmstatisticsMonthMapper">

    <resultMap type="TAlarmstatisticsMonth" id="TAlarmstatisticsMonthResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="modulename"    column="modulename"    />
        <result property="levelname"    column="levelname"    />
        <result property="count"    column="count"    />
        <result property="inputdate"    column="inputdate"    />
        <result property="analysis"    column="analysis"    />
        <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="selectTAlarmstatisticsMonthVo">
        select d.id, d.plant_code, d.modulename, d.levelname, d.count, d.inputdate, d.analysis, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id ,s.dept_name from t_alarmstatistics_month d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTAlarmstatisticsMonthList" parameterType="TAlarmstatisticsMonth" resultMap="TAlarmstatisticsMonthResult">
        <include refid="selectTAlarmstatisticsMonthVo"/>
        <where>
            <if test="modulename != null  and modulename != ''"> and modulename like concat(concat('%', #{modulename}), '%')</if>
            <if test="levelname != null  and levelname != ''"> and levelname like concat(concat('%', #{levelname}), '%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>

    <select id="selectTAlarmstatisticsMonthById" parameterType="Long" resultMap="TAlarmstatisticsMonthResult">
        <include refid="selectTAlarmstatisticsMonthVo"/>
        where id = #{id}
    </select>

    <insert id="insertTAlarmstatisticsMonth" parameterType="TAlarmstatisticsMonth">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_alarmstatistics_month.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_alarmstatistics_month
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="modulename != null">modulename,</if>
            <if test="levelname != null">levelname,</if>
            <if test="count != null">count,</if>
            <if test="inputdate != null">inputdate,</if>
            <if test="analysis != null">analysis,</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="modulename != null">#{modulename},</if>
            <if test="levelname != null">#{levelname},</if>
            <if test="count != null">#{count},</if>
            <if test="inputdate != null">#{inputdate},</if>
            <if test="analysis != null">#{analysis},</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="updateTAlarmstatisticsMonth" parameterType="TAlarmstatisticsMonth">
        update t_alarmstatistics_month
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="modulename != null">modulename = #{modulename},</if>
            <if test="levelname != null">levelname = #{levelname},</if>
            <if test="count != null">count = #{count},</if>
            <if test="inputdate != null">inputdate = #{inputdate},</if>
            <if test="analysis != null">analysis = #{analysis},</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="deleteTAlarmstatisticsMonthById" parameterType="Long">
        update t_alarmstatistics_month set del_flag = 2 where id = #{id}
    </update>

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

    <select id="selectMonthData" resultType="com.ruoyi.project.common.domain.DataEntity">
        SELECT SUM(d.COUNT) as dataNum,TO_CHAR(d.INPUTDATE,'YYYY-MM')as dataName FROM T_ALARMSTATISTICS_MONTH d
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        GROUP BY TO_CHAR(d.INPUTDATE,'YYYY-MM')
        order by dataName
    </select>

</mapper>
