<?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.tcZz.mapper.TcCyMapper">
    
    <resultMap type="TcCy" id="TcCyResult">
        <result property="id"    column="id"    />
        <result property="cyName"    column="cy_name"    />
        <result property="cyCount"    column="cy_count"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="areaId"    column="area_id"    />
    </resultMap>

    <sql id="selectTcCyVo">
        select id, cy_name, cy_count, create_by, create_time, update_by, update_time, remark, area_id from tc_cy
    </sql>

    <select id="selectTcCyList" parameterType="TcCy" resultMap="TcCyResult">
        <include refid="selectTcCyVo"/>
        <where>  
            <if test="cyName != null  and cyName != ''"> and cy_name like concat('%', #{cyName}, '%')</if>
            <if test="cyCount != null "> and cy_count = #{cyCount}</if>
            <if test="areaId != null  and areaId != ''"> and area_id = #{areaId}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectTcCyById" parameterType="Long" resultMap="TcCyResult">
        <include refid="selectTcCyVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTcCy" parameterType="TcCy" useGeneratedKeys="true" keyProperty="id">
        insert into tc_cy
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cyName != null">cy_name,</if>
            <if test="cyCount != null">cy_count,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="areaId != null">area_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cyName != null">#{cyName},</if>
            <if test="cyCount != null">#{cyCount},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="areaId != null">#{areaId},</if>
         </trim>
    </insert>

    <update id="updateTcCy" parameterType="TcCy">
        update tc_cy
        <trim prefix="SET" suffixOverrides=",">
            <if test="cyName != null">cy_name = #{cyName},</if>
            <if test="cyCount != null">cy_count = #{cyCount},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="areaId != null">area_id = #{areaId},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateByisStatus">
        UPDATE tc_cy
        SET isStatus = #{isStatus}
        WHERE id IN
        <foreach collection="ids" item="item" index="index" separator="," open="(" close=")">
            #{item}
        </foreach>
    </update>

    <delete id="deleteTcCyById" parameterType="Long">
        delete from tc_cy where id = #{id}
    </delete>

    <delete id="deleteTcCyByIds" parameterType="String">
        delete from tc_cy where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>