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

    <resultMap type="TWsgl" id="TWsglResult">
        <result property="id"    column="id"    />
        <result property="macharea"    column="macharea"    />
        <result property="wsno"    column="wsno"    />
        <result property="owner"    column="owner"    />
        <result property="year"    column="year"    />
        <result property="jan"    column="jan"    />
        <result property="feb"    column="feb"    />
        <result property="mar"    column="mar"    />
        <result property="apr"    column="apr"    />
        <result property="may"    column="may"    />
        <result property="jun"    column="jun"    />
        <result property="jul"    column="jul"    />
        <result property="aug"    column="aug"    />
        <result property="sep"    column="sep"    />
        <result property="oct"    column="oct"    />
        <result property="nov"    column="nov"    />
        <result property="dec"    column="dec"    />
        <result property="average"    column="average"    />
        <result property="item"    column="item"    />
        <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="team"    column="team"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTWsglVo">
        select d.id, d.macharea, d.wsno, d.owner, d.year, d.jan, d.feb, d.mar, d.apr, d.may, d.jun, d.jul, d.aug, d.sep, d.oct, d.nov, d.dec, d.average, d.item, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.team, d.dept_id ,s.dept_name from t_wsgl d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTWsglList" parameterType="TWsgl" resultMap="TWsglResult">
        <include refid="selectTWsglVo"/>
        <where>
            <if test="macharea != null  and macharea != ''"> and macharea like concat(concat('%', #{macharea}), '%')</if>
            <if test="owner != null  and owner != ''"> and owner like concat(concat('%', #{owner}), '%')</if>
            <if test="year != null "> and year = #{year}</if>
            <if test="team != null  and team != ''"> and team = #{team}</if>
            <if test="teams != null  and teams != ''">
                and
                d.team in
                <foreach collection="teams.split(',')" item="item" index="index"
                         open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="item != null  and item != ''"> and item = #{item}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        <if test="order == 'desc'"> ORDER BY average desc</if>
        <if test="order == 'asc'"> ORDER BY average asc</if>
    </select>

    <select id="selectTWsglById" parameterType="Long" resultMap="TWsglResult">
        <include refid="selectTWsglVo"/>
        where id = #{id}
    </select>

    <insert id="insertTWsgl" parameterType="TWsgl">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_wsgl.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_wsgl
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="macharea != null and macharea != ''">macharea,</if>
            <if test="wsno != null and wsno != ''">wsno,</if>
            <if test="owner != null">owner,</if>
            <if test="year != null">year,</if>
            <if test="jan != null">jan,</if>
            <if test="feb != null">feb,</if>
            <if test="mar != null">mar,</if>
            <if test="apr != null">apr,</if>
            <if test="may != null">may,</if>
            <if test="jun != null">jun,</if>
            <if test="jul != null">jul,</if>
            <if test="aug != null">aug,</if>
            <if test="sep != null">sep,</if>
            <if test="oct != null">oct,</if>
            <if test="nov != null">nov,</if>
            <if test="dec != null">dec,</if>
            <if test="average != null">average,</if>
            <if test="item != null">item,</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="team != null">team,</if>
            <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="macharea != null and macharea != ''">#{macharea},</if>
            <if test="wsno != null and wsno != ''">#{wsno},</if>
            <if test="owner != null">#{owner},</if>
            <if test="year != null">#{year},</if>
            <if test="jan != null">#{jan},</if>
            <if test="feb != null">#{feb},</if>
            <if test="mar != null">#{mar},</if>
            <if test="apr != null">#{apr},</if>
            <if test="may != null">#{may},</if>
            <if test="jun != null">#{jun},</if>
            <if test="jul != null">#{jul},</if>
            <if test="aug != null">#{aug},</if>
            <if test="sep != null">#{sep},</if>
            <if test="oct != null">#{oct},</if>
            <if test="nov != null">#{nov},</if>
            <if test="dec != null">#{dec},</if>
            <if test="average != null">#{average},</if>
            <if test="item != null">#{item},</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="team != null">#{team},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateTWsgl" parameterType="TWsgl">
        update t_wsgl
        <trim prefix="SET" suffixOverrides=",">
            <if test="macharea != null and macharea != ''">macharea = #{macharea},</if>
            <if test="wsno != null and wsno != ''">wsno = #{wsno},</if>
            <if test="owner != null">owner = #{owner},</if>
            <if test="year != null">year = #{year},</if>
            <if test="jan != null">jan = #{jan},</if>
            <if test="feb != null">feb = #{feb},</if>
            <if test="mar != null">mar = #{mar},</if>
            <if test="apr != null">apr = #{apr},</if>
            <if test="may != null">may = #{may},</if>
            <if test="jun != null">jun = #{jun},</if>
            <if test="jul != null">jul = #{jul},</if>
            <if test="aug != null">aug = #{aug},</if>
            <if test="sep != null">sep = #{sep},</if>
            <if test="oct != null">oct = #{oct},</if>
            <if test="nov != null">nov = #{nov},</if>
            <if test="dec != null">dec = #{dec},</if>
            <if test="average != null">average = #{average},</if>
            <if test="item != null">item = #{item},</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="team != null">team = #{team},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
