<?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.system.mapper.projectV2.ZsyzLcjlMapper">
    
    <resultMap type="ZsyzLcjl" id="ZsyzLcjlResult">
        <result property="id"    column="id"    />
        <result property="xmId"    column="xm_id"    />
        <result property="xmbh"    column="xmbh"    />
        <result property="xmmc"    column="xmmc"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="clTime"    column="cl_time"    />
        <result property="progress"    column="progress"    />
        <result property="xmStatus"    column="xm_status"    />
        <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"    />
    </resultMap>

    <sql id="selectZsyzLcjlVo">
        select id, xm_id, xmbh, xmmc, dept_id, dept_name, cl_time, progress,xm_status, create_by, create_time, update_by, update_time, remark from zsyz_lcjl
    </sql>

    <select id="selectZsyzLcjlList" parameterType="ZsyzLcjl" resultMap="ZsyzLcjlResult">
        <include refid="selectZsyzLcjlVo"/>
        <where>  
            <if test="xmId != null "> and xm_id = #{xmId}</if>
            <if test="xmbh != null  and xmbh != ''"> and xmbh = #{xmbh}</if>
            <if test="xmmc != null  and xmmc != ''"> and xmmc = #{xmmc}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="clTime != null "> and cl_time = #{clTime}</if>
            <if test="progress != null  and progress != ''"> and progress = #{progress}</if>
            <if test="xmStatus != null  and xmStatus != ''"> and xm_status = #{xmStatus}</if>
        </where>
    </select>
    
    <select id="selectZsyzLcjlById" parameterType="Long" resultMap="ZsyzLcjlResult">
        <include refid="selectZsyzLcjlVo"/>
        where id = #{id}
    </select>

    <select id="selectZsyzLcjlListQc" parameterType="ZsyzLcjl" resultMap="ZsyzLcjlResult">
        select ANY_VALUE(a.id) as id, ANY_VALUE(a.xm_id) as xm_id, ANY_VALUE(a.xmbh) as xmbh, ANY_VALUE(a.xmmc)as xmmc,
               ANY_VALUE(a.dept_id) as dept_id, ANY_VALUE(a.dept_name) as dept_name, ANY_VALUE(MAX(a.cl_time)) as cl_time, ANY_VALUE(a.progress) as progress, ANY_VALUE(a.xm_status) as xm_status
        from (select id, xm_id, xmbh, xmmc, dept_id, dept_name, cl_time, progress, xm_status
        from zsyz_lcjl order by xm_id, cl_time desc) a group by xm_id
    </select>

    <!--<select id="selectZsyzLcjlListQc" resultType="com.ruoyi.system.domain.projectV2.ZsyzLcjl">
        select id, xm_id, xmbh, xmmc,dept_id, dept_name, MAX(cl_time) as cl_time, progress, xm_status
        from (select id, xm_id, xmbh, xmmc, dept_id, dept_name, cl_time , progress, xm_status
        from zsyz_lcjl order by xm_id, cl_time desc) a group by xm_id
    </select>-->

    <insert id="insertZsyzLcjl" parameterType="ZsyzLcjl" useGeneratedKeys="true" keyProperty="id">
        insert into zsyz_lcjl
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="xmId != null">xm_id,</if>
            <if test="xmbh != null">xmbh,</if>
            <if test="xmmc != null and xmmc != ''">xmmc,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null and deptName != ''">dept_name,</if>
            <if test="progress != null">progress,</if>
            <if test="xmStatus != null">xm_status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            cl_time,
            create_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="xmId != null">#{xmId},</if>
            <if test="xmbh != null">#{xmbh},</if>
            <if test="xmmc != null and xmmc != ''">#{xmmc},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null and deptName != ''">#{deptName},</if>
            <if test="progress != null">#{progress},</if>
            <if test="xmStatus != null">#{xmStatus},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            sysdate(),
            sysdate()
         </trim>
    </insert>

    <update id="updateZsyzLcjl" parameterType="ZsyzLcjl">
        update zsyz_lcjl
        <trim prefix="SET" suffixOverrides=",">
            <if test="xmId != null">xm_id = #{xmId},</if>
            <if test="xmbh != null">xmbh = #{xmbh},</if>
            <if test="xmmc != null and xmmc != ''">xmmc = #{xmmc},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
            <if test="clTime != null">cl_time = #{clTime},</if>
            <if test="progress != null">progress = #{progress},</if>
            <if test="xmStatus != null">xm_status = #{xmStatus},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteZsyzLcjlById" parameterType="Long">
        delete from zsyz_lcjl where id = #{id}
    </delete>

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