Browse Source

sql优化

hsh 7 months ago
parent
commit
c1c1a80cb5

+ 19 - 27
src/main/java/cn/hnthyy/thmz/mapper/his/yf/YfSpecialMarkMapper.java

@@ -32,7 +32,7 @@ public interface YfSpecialMarkMapper {
                     " jsy_flag_b=max(c.jsy_flag)," +
                     " group_no=max(c.group_no)," +
                     " stock_amount = max(c.stock_amount)," +
-                    " stock_amount_large=(select sum(case when x.serial <![CDATA[<]]> z.serial then x.stock_amount/z.pack_size else x.stock_amount end)" +
+                    " stock_amount_large=(select sum(case when x.serial &lt; z.serial then x.stock_amount/z.pack_size else x.stock_amount end)" +
                     " from  (select a.name,a.code,a.serial,a.specification,a.pack_size" +
                     " from yp_zd_dict a WITH(NOLOCK)," +
                     " (select code,max(serial) serial from yp_zd_dict WITH(NOLOCK) group by code) b" +
@@ -44,30 +44,30 @@ public interface YfSpecialMarkMapper {
                     "   visible_flag_stop = max(c.visible_flag_stop)," +
                     "   stock_amount_virtual2=max(c.stock_amount_virtual2)," +
                     "   open_virtual2 = max(c.open_virtual2)," +
-                    "   three_day_dosage=isnull(round(sum(case when datediff(day,confirm_time,getdate()) <![CDATA[>]]> 3 then 0 else quantity end),2),0)," +
-                    "   seven_day_dosage=isnull(round(sum(case when datediff(day,confirm_time,getdate())  <![CDATA[>]]> 7 then 0 else quantity end),2),0)," +
-                    "   fourteen_day_dosage=isnull(round(sum(case when datediff(day,confirm_time,getdate())  <![CDATA[>]]> 14 then 0 else quantity end),2),0)," +
-                    "   thirty_day_dosage=isnull(round(sum(case when datediff(day,confirm_time,getdate())  <![CDATA[>]]> 30 then 0 else quantity end),2),0)" +
-                    " FROM yp_zd_dict WITH(NOLOCK)," +
-                    "     (select charge_code" +
+                    "   three_day_dosage=isnull(round(sum(case when datediff(day,confirm_time,getdate()) &gt; 3 then 0 else quantity end),2),0)," +
+                    "   seven_day_dosage=isnull(round(sum(case when datediff(day,confirm_time,getdate())  &gt; 7 then 0 else quantity end),2),0)," +
+                    "   fourteen_day_dosage=isnull(round(sum(case when datediff(day,confirm_time,getdate())  &gt; 14 then 0 else quantity end),2),0)," +
+                    "   thirty_day_dosage=isnull(round(sum(case when datediff(day,confirm_time,getdate())  &gt; 30 then 0 else quantity end),2),0)" +
+                    " FROM yp_zd_dict WITH(NOLOCK) " +
+                    "     inner join (select charge_code" +
                     "      from yp_print_name WITH(NOLOCK)" +
                     "      where (py_code like '%${searchText}%' or" +
                     "          d_code  like '%${searchText}%'  or" +
                     "          charge_code  like '%${searchText}%' or" +
                     "          print_name  like '%${searchText}%')" +
-                    "      group by charge_code)b," +
-                    "     yp_base_yf c WITH(NOLOCK) ," +
-                    "     yp_zd_manufactory d WITH(NOLOCK)," +
-                    "     (select" +
+                    "      group by charge_code) b on yp_zd_dict.code = b.charge_code " +
+                    "     inner join yp_base_yf c WITH(NOLOCK) on yp_zd_dict.code=c.charge_code and yp_zd_dict.serial=c.serial and c.group_no =#{groupNo} " +
+                    "     left join yp_zd_manufactory d WITH(NOLOCK) on yp_zd_dict.manu_code =d.code  " +
+                    "     left join (select" +
                     "        c.name," +
                     "        a.charge_item_code code," +
                     "        c.serial," +
-                    "        round(sum(case when a.serial  <![CDATA[<]]> c.serial then quantity*cy_fy/pack_size else quantity*cy_fy end),2) quantity," +
+                    "        round(sum(case when a.serial  &lt; c.serial then quantity*cy_fy/pack_size else quantity*cy_fy end),2) quantity," +
                     "        a.confirm_time" +
                     "      from yp_mz_fytj a WITH(NOLOCK)," +
                     "           (select name =max(name),code,serial =max(serial),specification =max(specification),pack_size=max(pack_size) from yp_zd_dict WITH(NOLOCK) group by code) c" +
                     "      where a.charge_item_code=c.code and" +
-                    "          datediff(day,confirm_time,getdate())  <![CDATA[<]]> 31 and" +
+                    "          datediff(day,confirm_time,getdate())  &lt; 31 and" +
                     "          a.group_no=#{groupNo}" +
                     "      group by c.name,a.charge_item_code,c.serial,a.confirm_time" +
                     "      union all" +
@@ -75,25 +75,17 @@ public interface YfSpecialMarkMapper {
                     "        c.name," +
                     "        a.charge_code code," +
                     "        c.serial," +
-                    "        round(sum(case when a.serial <![CDATA[<]]>  c.serial then amount/pack_size else amount end),2) quantity," +
+                    "        round(sum(case when a.serial &lt;  c.serial then amount/pack_size else amount end),2) quantity," +
                     "        a.confirm_time" +
                     "      from yp_zy_patient a WITH(NOLOCK)," +
                     "      (select name =max(name),code,serial =max(serial),specification =max(specification),pack_size=max(pack_size) from yp_zd_dict WITH(NOLOCK) group by code) c" +
                     "      where a.charge_code=c.code and" +
-                    "          datediff(day,confirm_time,getdate()) <![CDATA[<]]> 31 and" +
+                    "          datediff(day,confirm_time,getdate()) &lt; 31 and" +
                     "          a.group_no=#{groupNo}" +
-                    "      group by c.name,a.charge_code,c.serial,a.confirm_time) cc" +
-                    " where yp_zd_dict.code = b.charge_code and" +
-                    "      yp_zd_dict.code=c.charge_code and" +
-                    "      yp_zd_dict.serial=c.serial and" +
-                    "      yp_zd_dict.manu_code*=d.code and" +
-                    "      c.group_no =#{groupNo} and" +
-                    "      isnull(yp_zd_dict.del_flag,'')  <![CDATA[<>]]> '1' and" +
-                    "      yp_zd_dict.code*=cc.code and" +
-                    "      yp_zd_dict.serial*=cc.serial" +
-                    " group by" +
-                    "  c.charge_code," +
-                    "  c.serial" ,
+                    "      group by c.name,a.charge_code,c.serial,a.confirm_time)  " +
+                    "      yp_zd_dict.code = cc.code and yp_zd_dict.serial = cc.serial " +
+                    " where isnull(yp_zd_dict.del_flag,'')  &lt;&gt; '1' " +
+                    " group by  c.charge_code, c.serial " ,
             " </script>"})
     List<YpZdBaseYfSpecialVo> selectYpSpecialMark(@Param("groupNo")String groupNo, @Param("searchText") String searchText);
 }

+ 40 - 65
src/main/java/cn/hnthyy/thmz/mapper/his/yf/YfSpiritAnestheticPrintMapper.java

@@ -86,7 +86,9 @@ public interface YfSpiritAnestheticPrintMapper {
             " charge_item_code=charge_code," +
             " a.manu_no," +
             " p.exec_unit" +
-            " from yp_zy_patient a WITH(NOLOCK),yp_zd_dict b WITH(NOLOCK),a_patient_mi c WITH(NOLOCK),zy_patient e WITH(NOLOCK),view_yz_all_order p WITH(NOLOCK)" +
+            " from yp_zy_patient a WITH(NOLOCK)" +
+            "      left join view_yz_all_order p WITH(NOLOCK) on a.act_order_no = p.act_order_no," +
+            "      yp_zd_dict b WITH(NOLOCK),a_patient_mi c WITH(NOLOCK),zy_patient e WITH(NOLOCK) " +
             " where a.charge_code=b.code and" +
             "       a.serial=b.serial and" +
             "       b.drug_flag in " +
@@ -95,7 +97,7 @@ public interface YfSpiritAnestheticPrintMapper {
             "       </foreach> and" +
             "       a.inpatient_no=c.inpatient_no and" +
             "       a.inpatient_no=e.inpatient_no and" +
-            "       a.admiss_times*=e.admiss_times  and" +
+            "       a.admiss_times =e.admiss_times and" +
             "       <when test='chargeItemCode!=null'>"+
             "       a.charge_code=#{chargeItemCode} and" +
             "       </when>"+
@@ -103,8 +105,7 @@ public interface YfSpiritAnestheticPrintMapper {
             "       a.dept_code=#{unitCode} and" +
             "       </when>"+
             "       a.confirm_time <![CDATA[>=]]>#{beginDate} and" +
-            "       a.confirm_time <![CDATA[<=]]>#{endDate} and" +
-            "       a.act_order_no*=p.act_order_no" +
+            "       a.confirm_time <![CDATA[<=]]>#{endDate} " +
             "       order by charge_code asc",
     "</script>"})
     List<MzSendMedicineVo> selectZySpiritAnestheticPrint(@Param("beginDate") String beginDate,@Param("endDate") String endDate,
@@ -175,43 +176,32 @@ public interface YfSpiritAnestheticPrintMapper {
             "       a.act_order_no," +
             "       g.exec_unit," +
             "       h2.name as exec_name" +
-            " FROM  yp_zy_patient a WITH(NOLOCK)," +
-            "       zy_patient b WITH(NOLOCK)," +
-            "       a_employee_mi c WITH(NOLOCK)," +
-            "       yp_zd_dict d WITH(NOLOCK)," +
-            "       yp_zd_manufactory e WITH(NOLOCK)," +
-            "       zd_unit_code h WITH(NOLOCK)," +
-            "       zd_unit_code h2 WITH(NOLOCK)," +
-            "       a_patient_mi i WITH(NOLOCK)," +
-            "       view_yz_all_order g WITH(NOLOCK)," +
-            "       yz_supply_type k WITH(NOLOCK)" +
-            " WHERE  a.inpatient_no = b.inpatient_no and" +
-            "       a.admiss_times=b.admiss_times and" +
-            "       case when isnull(g.physician,'')='' then a.doctor_name else g.physician end*= c.code and" +
-            "       a.charge_code = d.code and" +
-            "       a.serial = d.serial and" +
-            "       d.manu_code*= e.code  and" +
-            "       a.inpatient_no*=i.inpatient_no and" +
-            "       b.admiss_dept=h.code and" +
-            "       g.exec_unit=h2.code and" +
-            "       a.act_order_no = g.act_order_no and" +
-            "       g.supply_code *= k.supply_code and" +
+            " FROM  yp_zy_patient a WITH(NOLOCK) " +
+            " INNER JOIN zy_patient b WITH(NOLOCK) ON a.inpatient_no = b.inpatient_no AND a.admiss_times = b.admiss_times " +
+            " INNER JOIN view_yz_all_order g WITH(NOLOCK) ON a.act_order_no = g.act_order_no " +
+            " LEFT JOIN a_employee_mi c WITH(NOLOCK) ON (case when isnull(g.physician,'')='' then a.doctor_name else g.physician end) = c.code " +
+            " INNER JOIN yp_zd_dict d WITH(NOLOCK) ON a.charge_code = d.code AND a.serial = d.serial " +
+            " LEFT JOIN yp_zd_manufactory e WITH(NOLOCK) ON d.manu_code = e.code " +
+            " LEFT JOIN a_patient_mi i WITH(NOLOCK) ON a.inpatient_no = i.inpatient_no " +
+            " INNER JOIN zd_unit_code h WITH(NOLOCK) ON b.admiss_dept = h.code " +
+            " LEFT JOIN yz_supply_type k WITH(NOLOCK) ON g.supply_code = k.supply_code " +
+            " INNER JOIN zd_unit_code h2 WITH(NOLOCK) ON g.exec_unit = h2.code " +
+            " WHERE a.act_order_no &lt;&gt; '3' " +
             "       <when test='sendDrugRecordVo.beginDate != null'>" +
-            "       a.confirm_time<![CDATA[>]]>#{sendDrugRecordVo.beginDate} and" +
+            "       and a.confirm_time &gt; #{sendDrugRecordVo.beginDate} " +
             "       </when>" +
             "       <when test='sendDrugRecordVo.endDate != null'>" +
-            "       a.confirm_time<![CDATA[<=]]>#{sendDrugRecordVo.endDate} and" +
+            "       and a.confirm_time &lt;= #{sendDrugRecordVo.endDate} " +
             "       </when>" +
             "       <when test='sendDrugRecordVo.chargeCode != null'>" +
-            "       a.charge_code = #{sendDrugRecordVo.chargeCode}  and" +
+            "       and a.charge_code = #{sendDrugRecordVo.chargeCode} " +
             "       </when>" +
             "       <when test='sendDrugRecordVo.serial != null'>" +
-            "       a.serial = #{sendDrugRecordVo.serial} and" +
+            "       and a.serial = #{sendDrugRecordVo.serial} " +
             "       </when>" +
             "       <when test='sendDrugRecordVo.warnDept != null'>" +
-            "       h.code = #{sendDrugRecordVo.warnDept} and" +
+            "       and h.code = #{sendDrugRecordVo.warnDept} " +
             "       </when>" +
-            "       a.act_order_no <![CDATA[<>]]> '3'" ,
             " </script>"})
     List<SendDrugRecordVo> selectZyRecord(@Param("sendDrugRecordVo") SendDrugRecordVo sendDrugRecordVo);
 
@@ -230,7 +220,7 @@ public interface YfSpiritAnestheticPrintMapper {
             "       icd_text=isnull(nullif(i.icd_text_new,''), rtrim(i.icd_text))," +
             "       drug_name=d.name," +
             "       abbr_name=e.name," +
-            "       quantity = case when a.serial=d.serial then case when a.receipt_no <![CDATA[<]]> '0' then -abs(a.quantity*isnull(a.cy_fy,1)) else a.quantity*isnull(a.cy_fy,1) end else case when a.receipt_no <![CDATA[<]]> '0' then -abs(a.quantity*isnull(a.cy_fy,1)/d.pack_size) else a.quantity*isnull(a.cy_fy,1)/d.pack_size end end," +
+            "       quantity = case when a.serial=d.serial then case when a.receipt_no &lt; '0' then -abs(a.quantity*isnull(a.cy_fy,1)) else a.quantity*isnull(a.cy_fy,1) end else case when a.receipt_no &lt; '0' then -abs(a.quantity*isnull(a.cy_fy,1)/d.pack_size) else a.quantity*isnull(a.cy_fy,1)/d.pack_size end end," +
             "       d.specification," +
             "       charge_date=a.confirm_time," +
             "       employee_name=c.name," +
@@ -239,49 +229,34 @@ public interface YfSpiritAnestheticPrintMapper {
             "       k.supply_name," +
             "       g.frequency," +
             "       a.manu_no" +
-            " FROM  yp_mz_fytj a WITH(NOLOCK)," +
-            "       mz_patient_mi b WITH(NOLOCK)," +
-            "       a_employee_mi c WITH(NOLOCK)," +
-            "       yp_zd_dict d WITH(NOLOCK)," +
-            "       yp_zd_manufactory e WITH(NOLOCK)," +
-            "       zd_unit_code h WITH(NOLOCK)," +
-            "       mz_visit_table i WITH(NOLOCK)," +
-            "       mz_charge_detail g WITH(NOLOCK)," +
-            "       mz_zd_supply_type k WITH(NOLOCK)" +
-            " WHERE  ( a.patient_id = b.patient_id ) and" +
-            "       ( a.doctor_id*= c.code ) and" +
-            "       ( a.charge_item_code = d.code ) and" +
-            "       ( a.serial = d.serial)  and" +
-            "       ( d.manu_code*= e.code ) and" +
-            "       a.warn_dept=h.code and" +
-            "       a.patient_id*=i.patient_id and" +
-            "       a.times*=i.times and" +
-            "       isnull(a.pay_mark,5)<![CDATA[<>]]> 5 and" +
-            "       a.patient_id = g.patient_id and" +
-            "       a.times = g.times and" +
-            "       a.receipt_no = g.receipt_no and" +
-            "       a.order_no = g.order_no and" +
-            "       a.item_no = g.item_no and" +
-            "       a.charge_item_code = g.charge_item_code and" +
-            "       g.supply_code *= k.supply_code and" +
-            "       isnull(a.confirm_flag,2) != 2 and" +
-            "       a.quantity !=0 and" +
+            " FROM  yp_mz_fytj a WITH(NOLOCK) " +
+            " INNER JOIN mz_patient_mi b WITH(NOLOCK) ON a.patient_id = b.patient_id" +
+            " LEFT JOIN a_employee_mi c WITH(NOLOCK) ON a.doctor_id = c.code" +
+            " INNER JOIN yp_zd_dict d WITH(NOLOCK) ON a.charge_item_code = d.code AND a.serial = d.serial" +
+            " LEFT JOIN yp_zd_manufactory e WITH(NOLOCK) ON d.manu_code = e.code" +
+            " INNER JOIN zd_unit_code h WITH(NOLOCK) ON a.warn_dept = h.code" +
+            " LEFT JOIN mz_visit_table i WITH(NOLOCK) ON a.patient_id = i.patient_id AND a.times = i.times" +
+            " INNER JOIN mz_charge_detail g WITH(NOLOCK) ON a.patient_id = g.patient_id AND a.times = g.times AND a.receipt_no = g.receipt_no AND a.order_no = g.order_no AND a.item_no = g.item_no AND a.charge_item_code = g.charge_item_code" +
+            " LEFT JOIN mz_zd_supply_type k WITH(NOLOCK) ON g.supply_code = k.supply_code" +
+            " WHERE  isnull(a.pay_mark, 5) &lt;&gt; 5 " +
+            "       and isnull(a.confirm_flag, 2) != 2 " +
+            "       and a.quantity != 0 " +
             "       <when test='sendDrugRecordVo.beginDate != null'>" +
-            "       a.confirm_time<![CDATA[>]]>#{sendDrugRecordVo.beginDate} and" +
+            "       and a.confirm_time &gt; #{sendDrugRecordVo.beginDate} " +
             "       </when>" +
             "       <when test='sendDrugRecordVo.endDate != null'>" +
-            "       a.confirm_time<![CDATA[<=]]>#{sendDrugRecordVo.endDate} and" +
+            "       and a.confirm_time &lt;= #{sendDrugRecordVo.endDate} " +
             "       </when>" +
             "       <when test='sendDrugRecordVo.chargeCode != null'>" +
-            "       a.charge_item_code = #{sendDrugRecordVo.chargeCode}  and" +
+            "       and a.charge_item_code = #{sendDrugRecordVo.chargeCode}  " +
             "       </when>" +
             "       <when test='sendDrugRecordVo.serial != null'>" +
-            "       a.serial = #{sendDrugRecordVo.serial} and" +
+            "       and a.serial = #{sendDrugRecordVo.serial} " +
             "       </when>" +
             "       <when test='sendDrugRecordVo.warnDept != null'>" +
-            "       h.code = #{sendDrugRecordVo.warnDept} and" +
+            "       and h.code = #{sendDrugRecordVo.warnDept} " +
             "       </when>" +
-            "       1=1 order by d.code" ,
+            "       order by d.code" ,
             " </script>"})
     List<SendDrugRecordVo> selectMzRecord(@Param("sendDrugRecordVo") SendDrugRecordVo sendDrugRecordVo);