<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: DJ  
    $Date: 2013-9-16 上午11:10:27  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
    			select t1.*,
				       (case
				         when t1.total_votes = 0 then
				          0
				         else
				          round(t1.agree_votes / t1.total_votes, 4) * 100
				       end) || '%' as agree_rate,
				       (case
				         when t1.total_votes = 0 then
				          0
				         else
				          round(t1.reject_votes / t1.total_votes, 4) * 100
				       end) || '%' as reject_rate,
				       (case
				         when t1.total_votes = 0 then
				          0
				         else
				          round(t1.half_votes / t1.total_votes, 4) * 100
				       end) || '%' as half_rate
				  from (select t.approval_id,
				               (select count(1)
				                  from prj_project_approver a
				                 where a.approval_id = t.approval_id) total_votes,
				               (select count(1)
				                  from prj_project_approver a
				                 where a.approval_id = t.approval_id
				                   and a.approve_status = 'APPROVE') as agree_votes,
				               (select count(1)
				                  from prj_project_approver a
				                 where a.approval_id = t.approval_id
				                   and a.approve_status = 'REJECT') as reject_votes,
				               (select count(1)
				                  from prj_project_approver a
				                 where a.approval_id = t.approval_id
				                   and a.approve_status = 'HALF_APPROVE') as half_votes
				          from prj_project_approval t) t1
				 #WHERE_CLAUSE#
    		]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
