<?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.modules.projectcontentinfo.dao.ProjectReportDataOfficeDao">


	<select id="findList" resultType="ProjectReportDataOffice" >
		select
		a.id AS "id",
		a.top_company AS "name",
		count(DISTINCT d.id) AS "reportCount"
		from sys_office a
		left join project_report_data d on d.del_flag = '0' and d.status  = '5' and d.office_id = a.id
		<if test="date!=null and date !=''">
			AND YEAR(d.report_date) = #{date}
		</if>
		where a.del_flag = '0' and  a.type = '2'
		<if test="officeId != null and officeId != ''">
			AND a.id = #{officeId}
		</if>
		and a.parent_id=#{companyId}
		group by a.id
		order by a.create_date ASC;
	</select>
	<select id="findOfficeListSum" resultType="ProjectReportDataOffice" >
		select
		a.id AS "id",
		a.top_company AS "name",
		count(DISTINCT d.id) AS "reportCount"
		from sys_office a
		left join project_report_data d on d.del_flag = '0' and d.status  = '5' and d.office_id = a.id
		<if test="date!=null and date !=''">
			AND YEAR(d.report_date) = #{date}
		</if>
		where a.del_flag = '0' and  a.type = '2'
		<if test="officeId != null and officeId != ''">
			AND a.id = #{officeId}
		</if>
		and a.parent_ids like concat('%', #{companyId},'%')
	</select>
</mapper>