<?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.zcloud.mapper.datasource.safetyMeeting.SafetyMeetingMapper">

    <!--表名 -->
    <sql id="tableName">
        SAFETY_MEETING
    </sql>
    <!-- 字段 -->
    <sql id="Field">
        f.SAFETY_MEETING_ID,
		f.SAFETY_MEETING_TITLE,
		f.SAFETY_MEETING_CONTENT,
		f.CORPINFO_ID,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.ISDELETE
    </sql>
    <!-- 字段用于新增 -->
    <sql id="Field2">
        SAFETY_MEETING_ID,
		SAFETY_MEETING_TITLE,
		SAFETY_MEETING_CONTENT,
		CORPINFO_ID,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		ISDELETE
    </sql>

    <!-- 字段值 -->
    <sql id="FieldValue">
        #{SAFETY_MEETING_ID},
        #{SAFETY_MEETING_TITLE},
        #{SAFETY_MEETING_CONTENT},
        #{CORPINFO_ID},
        #{CREATOR},
        #{CREATTIME},
        #{OPERATOR},
        #{OPERATTIME},
        #{ISDELETE}
    </sql>
    <insert id="save">
        insert into
        <include refid="tableName"></include>
        (
        <include refid="Field2"></include>
        ) values (
        <include refid="FieldValue"></include>
        )
    </insert>

    <update id="removeById">
        update
        <include refid="tableName"></include>
        set
        ISDELETE = '1',
        OPERATOR=#{OPERATOR},
        OPERATTIME=#{OPERATTIME}
        where
        SAFETY_MEETING_ID = #{SAFETY_MEETING_ID}
    </update>
    <update id="edit">
        update
        <include refid="tableName"></include>
        set
        SAFETY_MEETING_TITLE=#{SAFETY_MEETING_TITLE},
        SAFETY_MEETING_CONTENT=#{SAFETY_MEETING_CONTENT},
        OPERATOR=#{OPERATOR},
        OPERATTIME=#{OPERATTIME}
        where
        SAFETY_MEETING_ID = #{SAFETY_MEETING_ID}
    </update>
    <update id="confirmMeetingPeople">
        update
            safety_meeting_people
        set
        FEED_BACK = #{FEED_BACK},
        OPERATOR=#{OPERATOR},
        OPERATTIME=#{OPERATTIME}
        where
        SAFETY_MEETING_ID = #{SAFETY_MEETING_ID} and
        USER_ID = #{USER_ID}
    </update>
    <select id="datalistPage" resultType="com.zcloud.entity.PageData">
        SELECT
        t.*,
        (select count(*) from safety_meeting_people m where m.SAFETY_MEETING_ID = t.SAFETY_MEETING_ID and m.ISDELETE = 0) ALL_SIGNATURES,
        COUNT(distinct p.FEED_BACK) SIGNATURES,
        GROUP_CONCAT( distinct i.FILEPATH ) imgs
        FROM
        `safety_meeting` t
        LEFT JOIN bus_imgfiles i ON t.SAFETY_MEETING_ID = i.FOREIGN_KEY
        LEFT JOIN safety_meeting_people p ON t.SAFETY_MEETING_ID = p.SAFETY_MEETING_ID and p.ISDELETE = 0
        where t.ISDELETE = '0' and t.CORPINFO_ID = #{pd.CORPINFO_ID}
        <if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
            and t.SAFETY_MEETING_TITLE like '%${pd.KEYWORDS}%'
        </if>
        GROUP BY
        t.SAFETY_MEETING_ID
        ORDER BY t.OPERATTIME desc
    </select>
    <select id="findById" resultType="com.zcloud.entity.PageData">
        select * from <include refid="tableName"></include> where ISDELETE = '0'
            and SAFETY_MEETING_ID = #{SAFETY_MEETING_ID}
    </select>
    <select id="saftPersonList" resultType="com.zcloud.entity.PageData">
        SELECT
            s.*,
            p.`NAME` POST_NAME,
            d.`NAME` DEPARTMENT_NAME,
            u.`NAME` NAME
        FROM
            `safety_meeting_people` s
                LEFT JOIN sys_post p ON s.post_id = p.POST_ID
                LEFT JOIN oa_department d ON s.DEPARTMENT_ID = d.DEPARTMENT_ID
                LEFT JOIN sys_user u ON s.USER_ID = u.USER_ID
        WHERE
            SAFETY_MEETING_ID =  #{SAFETY_MEETING_ID}
          AND s.ISDELETE = 0
    </select>
    <select id="appdatalistPage" resultType="com.zcloud.entity.PageData">
        SELECT
            s.*,
            u.`NAME`
        FROM
            safety_meeting s

                LEFT JOIN sys_user u on s.CREATOR = u.USER_ID
        WHERE
                s.SAFETY_MEETING_ID IN (
                SELECT
                    SAFETY_MEETING_ID
                FROM
                    safety_meeting_people p
                WHERE
                    p.USER_ID = #{pd.USER_ID}
                  AND p.ISDELETE = 0
                and p.FEED_BACK is
                <if test="pd.selectType == '1'.toString()">
                      not
                </if>
                null
            )  and s.ISDELETE = 0
    </select>
    <select id="findMeetPeopleByUId" resultType="com.zcloud.entity.PageData">
        select * from safety_meeting_people where USER_ID = #{USER_ID} and SAFETY_MEETING_ID = #{SAFETY_MEETING_ID} and ISDELETE = 0
    </select>
    <select id="getfeedbackList" resultType="com.zcloud.entity.PageData">
        SELECT
            p.*,
            i.FILEPATH,
            u.NAME
        FROM
            safety_meeting_people p
                LEFT JOIN bus_imgfiles i on p.SAFETY_MEETING_PEOPLE_ID = i.FOREIGN_KEY
                LEFT JOIN sys_user u on u.USER_ID = p.USER_ID
        where SAFETY_MEETING_ID = #{SAFETY_MEETING_ID} and p.ISDELETE = 0
    </select>


</mapper>
