浏览代码

Merge branch 'dev-1.1.4' of https://172.16.32.165/hurugang/thmz_system into dev-1.1.4

hurugang 2 年之前
父节点
当前提交
a1f7c923c1
共有 1 个文件被更改,包括 20 次插入8 次删除
  1. 20 8
      src/main/java/cn/hnthyy/thmz/mapper/his/yf/YfDrugApplyMapper.java

+ 20 - 8
src/main/java/cn/hnthyy/thmz/mapper/his/yf/YfDrugApplyMapper.java

@@ -127,14 +127,25 @@ public interface YfDrugApplyMapper {
      */
     @Select("<script>" +
             "SELECT  top ${pageBean.pageSize} * from " +
-            "(SELECT  row_number() over (order by b.mini_stock_amount-b.stock_amount desc) RowNumber," +
+            "(SELECT  row_number() over (order by b.mini_stock_amount-(b.stock_amount + yf.stock_amount) desc) RowNumber," +
             " b.charge_code,b.drugname as name,b.specification,b.pack_retprice,b.max_stock_amount,b.mini_stock_amount,b.serial," +
-            " (b.stock_amount+ y.yfl) as stock_amount,b.manufactory as manu_code,b.zb_supplyer" +
-            " from yp_base b WITH(NOLOCK)" +
-            " left join (select sum(stock_amount) yfl, charge_code, serial " +
-            " from yp_base_yf WITH ( NOLOCK ) " +
-            " group by charge_code, serial) y" +
-            " on b.charge_code = y.charge_code and b.serial = y.serial " +
+            " (b.stock_amount + yf.stock_amount)as stock_amount,b.manufactory as manu_code,b.zb_supplyer" +
+            " from yp_base b WITH(NOLOCK),\n" +
+            "     (select sum((case\n" +
+            "                when (y.serial='01'\n" +
+            "                  and d.pack_size is not null) then y.stock_amount/d.pack_size\n" +
+            "                else y.stock_amount\n" +
+            "       end)) as stock_amount,y.charge_code\n" +
+            "     from yp_base_yf y WITH(NOLOCK) left join\n" +
+            "           yp_zd_dict d WITH(NOLOCK)\n" +
+            "               on y.charge_code=d.code\n" +
+            "               and d.serial='99' " +
+            "<where>" +
+            "      <when test='chargeCode!=null and chargeCode!=\"\"'>" +
+            "            y.charge_code=#{chargeCode} " +
+            "       </when> " +
+            "</where>" +
+            "       group by y.charge_code)yf" +
             " where" +
             "   <when test='chargeCode!=null and chargeCode!=\"\"'>"+
             "           b.charge_code =#{chargeCode} and " +
@@ -145,6 +156,7 @@ public interface YfDrugApplyMapper {
             "      b.group_no=#{groupNo} and" +
             "      isnull(b.visible_flag,'0')=#{visibleFlag} and" +
             "      isnull(b.del_flag,'0') != '1'" +
+            "       and yf.charge_code = b.charge_code" +
             ") as A WHERE RowNumber >#{pageBean.pageSize}*#{pageBean.pageIndex} order by RowNumber asc" +
             "</script>")
     List<YpBaseBoundVo> selectYpBaseBoundPage(@Param("chargeCode")String chargeCode, @Param("groupNo") String groupNo,
@@ -198,7 +210,7 @@ public interface YfDrugApplyMapper {
             "       left join\n" +
             "     yp_zd_dict d WITH(NOLOCK)\n" +
             "     on p.charge_code=d.code\n" +
-            "       and d.code='99'\n" +
+            "       and d.serial='99'\n" +
             "   where\n" +
             "       p.charge_code=#{chargeCode}\n" +
             "     and datediff(day,confirm_time,getdate()) <![CDATA[<=]]> 60\n" +