<?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.workreimbursementcount.dao.WorkReimbursementCompanyDao">
	<select id="findCompanyList" resultType="WorkReimbursementCompany" >
		select
		  a.id AS "id",
		  a.top_company AS "officeName",
		  a.type as "type",
		  ifnull(sum(t6.money),0) AS "money"
		from sys_office a
		left join sys_office t2 on (t2.parent_ids like concat('%',a.id,'%') and t2.type='2')
		left join (select i.* from work_reimbursement i where i.del_flag = '0' and i.status=5
		<if test="date != '' and date != null">
		      AND YEAR(i.submitter_date) = #{date}
	    </if>
		<if test="ext != '' and ext != null">
			AND i.ext = #{ext}
		</if> ) t6 on t6.office_id = t2.id
		where a.type in('1','3') and ( a.parent_id = #{companyId} or a.id = #{companyId})
		<if test="officeId != null and officeId != ''">
			AND a.office_id = #{officeId}
		</if>
		group by a.id
		order by a.create_date ASC
	</select>
	<!--<select id="get" resultType="WorkReimbursementCompany" >
		select * from (select
		a.id AS "id",
		a.name AS "officeName",
		ifnull(sum(DISTINCT t6.money),0) AS "money"
		from sys_office a
		left join sys_office t2 on (t2.parent_ids like concat('%',a.id,'%') and t2.type='2')
		left join (select i.* from work_reimbursement i where i.del_flag = '0' and i.status=5
		 ) t6 on t6.office_id = t2.id
		where a.type in('1','3') and ( a.parent_ids like concat('%',#{companyId},'%') or a.id = #{companyId})
		group by a.id) info
		WHERE info.id = #{id}
	</select>-->
</mapper>