| 
					
				 | 
			
			
				@@ -830,50 +830,111 @@ public interface MzChargeDetailMapper { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Select({"<script>", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "SELECT " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "  exec_dept= z.name," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "       charge_bill_code= case a.charge_bill_code when 'BILL10' then 'BILL01' when 'BILL11' then 'BILL28' when 'BILL12' then 'BILL02' else a.charge_bill_code end," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "         parent=max( d.parent_code )," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "         total_charge= isnull(sum(round(convert(decimal(18,2),((case when convert(decimal(18,2),unit_price)=0.00 then 0.01 else convert(decimal(18,2),unit_price) end) * (quantity * isnull(drug_win,1)))),2)),0) ," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "         audit_code=case when isnull(a.group_no,'00')='71' then max(d.name)+'(门诊)' when isnull(a.group_no,'00')='72' then max(d.name)+'(急诊)' else max(d.name) end," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    " charge_dcount_date=b.charge_dcount_date  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "    FROM ${firstTableName} a(nolock),   " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "         (select distinct patient_id,times,receipt_no, serial_no,receipt_sn,charge_dcount_date,pay_id from ${secondTableName} " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "          where (case 1 when '0' then charge_date " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "                 else charge_dcount_date end) <![CDATA[>=]]> #{beginDate} and " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "                (case 1 when '0' then charge_date " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "                 else charge_dcount_date end) <![CDATA[<=]]> #{endDate} and " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    " (fp_flag <![CDATA[<>]]> 'Y' or fp_flag is null) and " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "                (case 1 when '0' then isnull(dcount_no,0) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "                 else 1 end) = isnull(dcount_no,0) ) as b, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "         zd_charge_item c," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "         zy_zd_audit_item d, zd_unit_code  z " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "   WHERE ( a.patient_id = b.patient_id )    and  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "           a.times=b.times and " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "           a.receipt_no=b.receipt_no and   " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "           case a.charge_bill_code when 'BILL10' then 'BILL01' when 'BILL11' then 'BILL28' when 'BILL12' then 'BILL02' else a.charge_bill_code end*=c.code and " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "           isnull(c.audit_code,d.code)=d.code and " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "           a.serial_no=b.serial_no and " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "           a.real_no=b.receipt_sn and " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "            a.bill_item_code <![CDATA[<>]]> 'TC'  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "  and ( case 1 when #{caseType} then " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "      case when isnull(a.warn_dept,'')='' then  a.exec_dept else a.warn_dept end " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "      else  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "     case when isnull(a.exec_dept,'') ='' then a.warn_dept else a.exec_dept end " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "  end )*=z.code " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    "          and isnull(a.dept_no,'') like '%' " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " exec_dept = (" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " CASE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " 1 " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN ${caseType} THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " CASE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN isnull( a.warn_dept, '' ) = '' THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " a.exec_dept ELSE a.warn_dept " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " END ELSE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " CASE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN isnull( a.exec_dept, '' ) = '' THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " a.warn_dept ELSE a.exec_dept " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " END " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " END " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " )," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " charge_bill_code = " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " CASE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " a.charge_bill_code " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN 'BILL10' THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " 'BILL01' " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN 'BILL11' THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " 'BILL28' " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN 'BILL12' THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " 'BILL02' ELSE a.charge_bill_code " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " END, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " total_charge = isnull(" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "SUM(" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " round( " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " CONVERT (" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "DECIMAL ( 18, 2 )," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ( " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ( " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " CASE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN CONVERT ( DECIMAL ( 18, 2 ), unit_price ) = 0.00 THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " 0.01 ELSE CONVERT ( DECIMAL ( 18, 2 ), unit_price ) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " END  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ) * ( quantity * isnull( drug_win, 1 ) )  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " )  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ), " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " 2  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " )  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ), " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " 0  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ), " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " charge_dcount_date = b.charge_dcount_date  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " FROM " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ${firstTableName} a ( nolock ), " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ( " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " SELECT DISTINCT " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " patient_id, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " times, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " receipt_no, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " serial_no, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " receipt_sn, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " charge_dcount_date, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " pay_id  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " FROM " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ${secondTableName} " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHERE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ( CASE 1 WHEN 0 THEN charge_date ELSE charge_dcount_date END ) <![CDATA[>=]]> #{beginDate}  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " AND ( CASE 1 WHEN 0 THEN charge_date ELSE charge_dcount_date END ) <![CDATA[<=]]> #{endDate}  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " AND ( fp_flag  <![CDATA[<>]]> 'Y' OR fp_flag IS NULL )  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " AND ( CASE 1 WHEN 0 THEN isnull( charge_dcount_no, 0 ) ELSE 1 END ) = isnull( charge_dcount_no, 0 )  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ) AS b  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHERE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ( a.patient_id = b.patient_id )  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " AND a.times = b.times  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " AND a.receipt_no = b.receipt_no  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " AND a.serial_no = b.serial_no " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " AND a.real_no = b.receipt_sn  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " AND a.bill_item_code <![CDATA[<>]]> 'TC'  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "<when test='execDept!=null'>", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            "          and ( case '1' when #{caseType} then " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "          and ( case '1' when #{caseType} then " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "      case when isnull(a.warn_dept,'')='' then  a.exec_dept else a.warn_dept end " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "      else  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "     case when isnull(a.exec_dept,'') ='' then a.warn_dept else a.exec_dept end " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "  end " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ") =#{execDept} " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "</when>" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    " group by " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "z.name,c.audit_code,isnull(a.group_no,'00')," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    " case a.charge_bill_code when 'BILL10' then 'BILL01' when 'BILL11' then 'BILL28' when 'BILL12' then 'BILL02' else a.charge_bill_code end" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    ",b.charge_dcount_date,b.pay_id ", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " GROUP BY " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " isnull( a.group_no, '00' ), " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " CASE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " a.charge_bill_code  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN 'BILL10' THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " 'BILL01'  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN 'BILL11' THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " 'BILL28'  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN 'BILL12' THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " 'BILL02' ELSE a.charge_bill_code  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " END, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " b.charge_dcount_date, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " b.pay_id, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " ( " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " CASE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " 1  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN ${caseType} THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " CASE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN isnull( a.warn_dept, '' ) = '' THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " a.exec_dept ELSE a.warn_dept  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " END ELSE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " CASE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " WHEN isnull( a.exec_dept, '' ) = '' THEN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " a.warn_dept ELSE a.exec_dept " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " END  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    " END  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    ")", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "</script>"}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     List<Map<String, Object>> selectDepetBusinessReport(ThmzmxsrParamsVo thmzmxsrParamsVo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |