<?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.jeeplus.test.garbageClearance.mapper.LookOverMapper">
    <select id="getUserInfoByOffId" resultType="com.jeeplus.sys.service.dto.UserDTO">
        select su.id, su.name, su.mobile from sys_user su
        left join sys_office so on su.office_id = so.id
        left join sys_user_role sur on su.id = sur.user_id
        left join sys_role sr on sur.role_id = sr.id
        where su.office_id = #{officeId} and sr.name = '村负责人'
    </select>
    <select id="getOfficeOnHamlet" resultType="com.jeeplus.sys.service.dto.UserDTO">
        select su.id, su.name, so.id as "officeId", so.name as "officeName", su.mobile from sys_user su
        left join sys_office so on su.office_id = so.id
        left join sys_user_role sur on su.id = sur.user_id
        left join sys_role sr on sur.role_id = sr.id
        where sr.name = '村负责人'
    </select>

    <select id="findPage" resultType="com.jeeplus.test.garbageClearance.domain.LookOver">
        SELECT
        a.id,
        a.create_by_id,
        a.create_time,
        DATE_FORMAT(create_time, '%m-%d') AS showCreateTime,
        a.update_by_id,
        a.update_time,
        a.del_flag,
        a.remarks,
        a.no,
        a.processing_unit,
        a.`urls`,
        a.`status`,
        a.`year`,
        a.`number`,
        a.office_code,
        a.proc_ins_id,
        a.dispose_status
        FROM
        garbage_clearance_look_over a
        ${ew.customSqlSegment}
        ORDER BY a.update_time DESC
    </select>
    <select id="selectByID" resultType="com.jeeplus.test.garbageClearance.domain.LookOver">
        select
        a.id,
        a.create_by_id,
        a.create_time,
        a.update_by_id,
        a.update_time,
        a.del_flag,
        a.clear_user_id,
        a.remarks,
        a.no,
        a.processing_unit,
        a.`urls`,
        a.`status`,
        a.`year`,
        a.`number`,
        a.office_code,
        a.proc_ins_id,
        a.dispose_status,
        so.name as processingUnitName, su.name as clearUserName, su.mobile as clearUserMobile
        from garbage_clearance_look_over a
        left join sys_office so on a.processing_unit = so.id
        left join sys_user su on a.clear_user_id = su.id
        where a.id = #{id} and a.del_flag = 0
    </select>
    <select id="getByAttachmentId" resultType="com.jeeplus.test.oss.domain.WorkAttachmentInfo">
        SELECT
            url,
            type,
            attachment_name as name,
            file_size as size
		FROM
			work_attachment
		WHERE
			del_flag = 0
			AND attachment_id = #{id}
    </select>
    <select id="getByAttachmentIdAndFlag" resultType="com.jeeplus.test.oss.domain.WorkAttachmentInfo">
        SELECT
            url,
            type,
            attachment_name as name,
            file_size as size
		FROM
			work_attachment
		WHERE
			del_flag = 0
			AND attachment_id = #{id}
			AND attachment_flag = #{flag}
    </select>

    <update id="updateStatus">
        update garbage_clearance_look_over set
        status = #{status}
        where id = #{id}
    </update>

    <update id="updateDisposeStatus">
        update garbage_clearance_look_over set
        dispose_status = #{disposeStatus}
        where id = #{id}
    </update>

    <select id="getListByIdList" resultType="com.jeeplus.test.garbageClearance.domain.LookOver">
        select
        a.id,
        a.create_by_id,
        a.create_time,
        a.update_by_id,
        a.update_time,
        a.del_flag,
        a.clear_user_id,
        a.remarks,
        a.no,
        a.processing_unit,
        a.`urls`,
        a.`status`,
        a.`year`,
        a.`number`,
        a.office_code,
        a.proc_ins_id,
        a.dispose_status
        from garbage_clearance_look_over a
        <where>
            <if test="idList != null">
                a.id in
                <foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            and a.del_flag = 0
        </where>
    </select>
</mapper>
