<?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.project.zcustom.mapper.unit.LargeIssueMapper">

    <resultMap type="com.project.zcustom.domain.addional.LargeIssue" id="LargeIssueResult">
        <result property="id"    column="id"    />
        <result property="description"    column="description"    />
        <result property="person"    column="person"    />
        <result property="projectId"    column="project_id"    />
        <result property="projectName"    column="project_name"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="createDate"    column="create_date"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectLargeIssueVo">
        select id, description, project_id, status, del_flag, create_by, create_time, update_by, update_time from large_plat_issue
    </sql>

    <select id="selectLargeIssueList" parameterType="LargeIssue" resultMap="LargeIssueResult">
        select a.*, b.project_name
        from large_plat_issue a
        left join large_plat_project b
        on a.project_id = b.id
        <where>
               a.del_flag = '0' AND b.del_flag = '0'
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="projectId != null "> and a.project_id = #{projectId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
        order by a.create_time desc
    </select>

    <select id="selectLargeIssueById" parameterType="Long" resultMap="LargeIssueResult">
        select a.*, b.project_name
        from large_plat_issue a
        left join large_plat_project b
        on a.project_id = b.id
        where a.id = #{id}
    </select>

    <insert id="insertLargeIssue" parameterType="LargeIssue">
        insert into large_plat_issue
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="description != null">description,</if>
            <if test="projectId != null">project_id,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="description != null">#{description},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</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>
         </trim>
    </insert>

    <update id="updateLargeIssue" parameterType="LargeIssue">
        update large_plat_issue
        <trim prefix="SET" suffixOverrides=",">
            <if test="description != null">description = #{description},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLargeIssueById" parameterType="Long">
        delete from large_plat_issue where id = #{id}
    </delete>

    <delete id="deleteLargeIssueByIds" parameterType="String">
        delete from large_plat_issue where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="reallyDeleteByWrapper">
        DELETE FROM large_plat_issue ${ew.customSqlSegment}
    </delete>

    <select id="getIssueNum" parameterType="String" resultType="int">
        SELECT
            COUNT(a.id)
        FROM
            large_plat_issue a
                LEFT JOIN large_plat_project b ON a.project_id = b.id
                LEFT JOIN large_plat_app_org c ON b.app_org = c.app_org
        WHERE
            a.del_flag = 0
          AND b.del_flag = 0
          AND c.del_flag = '0'
        <if test="appOrg != '10001'">AND ( c.app_parent_org = #{appOrg} OR c.app_org = #{appOrg} )</if>
    </select>

    <select id="getOverIssueNum" parameterType="String" resultType="int">
        SELECT
            COUNT(a.id)
        FROM
            large_plat_issue a
                LEFT JOIN large_plat_project b ON a.project_id = b.id
                LEFT JOIN large_plat_app_org c ON b.app_org = c.app_org
        WHERE
            a.del_flag = 0 and a.status = 1
          AND b.del_flag = 0
          AND c.del_flag = '0'
        <if test="appOrg != '10001'">AND ( c.app_parent_org = #{appOrg} OR c.app_org = #{appOrg} )</if>
    </select>

    <select id="getIssueListLastWeek" parameterType="String" resultMap="LargeIssueResult">
        SELECT
            a.id,
            title,description,person,
            `status`,
            a.create_time,
            DATE(a.create_time) AS create_date
        FROM
            large_plat_issue a
                LEFT JOIN large_plat_project b ON a.project_id = b.id
                LEFT JOIN large_plat_app_org c ON b.app_org = c.app_org
        WHERE
        a.del_flag = 0
        AND b.del_flag = 0
        AND c.del_flag = '0'
        AND (
        DATE( a.create_time ) BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE()
        )
        <if test="appOrg != '10001'">AND ( c.app_parent_org = #{appOrg} OR c.app_org = #{appOrg} )</if>
        order by a.create_time desc
    </select>

    <select id="getIssueList" resultMap="LargeIssueResult">
        SELECT
        a.id,
        title,description,person,
        `status`,
        a.create_time,
        DATE(a.create_time) AS create_date
        FROM
        large_plat_issue a
        LEFT JOIN large_plat_project b ON a.project_id = b.id
        LEFT JOIN large_plat_app_org c ON b.app_org = c.app_org
        WHERE
        a.del_flag = 0
        AND b.del_flag = 0
        AND c.del_flag = '0'
        AND (
        DATE( a.create_time ) BETWEEN DATE( #{arg1} )
        AND CURDATE()
        )
        <if test="arg0 != '10001'">AND ( c.app_parent_org = #{arg0} OR c.app_org = #{arg0} )</if>
        order by a.create_time desc
    </select>
</mapper>
