Procházet zdrojové kódy

新增按药性分类统计出入库数据

WANGJIALIANG před 2 roky
rodič
revize
7a348cfa48

+ 23 - 1
src/main/java/cn/hnthyy/thmz/mapper/his/yp/YpInDetlMapper.java

@@ -500,7 +500,8 @@ public interface YpInDetlMapper {
             "select  a.group_no as groupNo,\n" +
             "        left(convert(varchar(12),in_date,111),7) as countDate,\n" +
             "        sum(round(convert(decimal(18,3),(convert(decimal(18,3),a.buy_price )* a.buy_amt)),2)) as inMoneyBuy,\n" +
-            "        sum(round(convert(decimal(18,3),(convert(decimal(18,3),a.pack_retprice )* a.buy_amt)),2)) as inMoneyRet\n" +
+            "        sum(round(convert(decimal(18,3),(convert(decimal(18,3),a.pack_retprice )* a.buy_amt)),2)) as inMoneyRet,\n" +
+            "        outMoneyRet=0\n" +
             "   from yp_in_detl a WITH(NOLOCK)\n" +
             "   where  datediff(day,in_date,#{beginDate}) <![CDATA[<=]]> 0 and\n" +
             "   datediff(day,in_date,#{endDate}) <![CDATA[>]]> 0 and\n" +
@@ -523,4 +524,25 @@ public interface YpInDetlMapper {
             "  group by c.code,c.name" +
             "</script>")
     List<Map<String,Object>> selectDrugKindInMoneyCount(Map map);
+
+    /**
+     * 按药性分类统计入库金额
+     * @param map
+     * @return
+     */
+    @Select("<script>"+
+            "select\n" +
+            "  inMoneyBuy = sum(a.buy_price * a.buy_amt),\n" +
+            "  inMoneyRet = sum(a.pack_retprice * a.buy_amt),\n" +
+            "  outMoneyRet = 0,\n" +
+            "  classCode = c.class_code\n" +
+            "from yp_in_detl a,yp_zd_dict c\n" +
+            "where in_date <![CDATA[>=]]>#{beginDate} and\n" +
+            "    in_date <![CDATA[<=]]>#{endDate} and\n" +
+            "    a.group_no=#{groupNo} and\n" +
+            "    a.charge_code=c.code and\n" +
+            "    a.serial=c.serial\n" +
+            "group by c.class_code" +
+            "</script>")
+    List<Map<String,Object>> selectDrugClassInMoneyCount(Map map);
 }

+ 24 - 1
src/main/java/cn/hnthyy/thmz/mapper/his/yp/YpOutDetlMapper.java

@@ -285,7 +285,9 @@ public interface YpOutDetlMapper {
     @Select("<script>"+
             "select  a.group_no_out as group_no," +
             "        left(convert(varchar(12),out_date,111),7)as countDate," +
-            "        sum(round(convert(decimal(18,3),(convert(decimal(18,3),a.pack_retprice )* out_amt)),2)) as outMoneyRet" +
+            "        sum(round(convert(decimal(18,3),(convert(decimal(18,3),a.pack_retprice )* out_amt)),2)) as outMoneyRet," +
+            "        inMoneyBuy=0," +
+            "        inMoneyRet=0" +
             "   from yp_out_detl a" +
             "   where  datediff(day,in_date,#{beginDate}) <![CDATA[<=]]> 0 and" +
             "   datediff(day,in_date,#{endDate}) <![CDATA[>]]> 0 and" +
@@ -319,4 +321,25 @@ public interface YpOutDetlMapper {
             "order by dept_code" +
             "</script>")
     List<Map<String,Object>> selectDrugByDeptAndKind(Map map);
+
+    /**
+     * 按药性分类统计出库金额
+     * @param map
+     * @return
+     */
+    @Select("<script>"+
+            "select\n" +
+            "   inMoneyBuy = 0,\n" +
+            "   inMoneyRet = 0,\n" +
+            "   outMoneyRet = sum(a.pack_retprice * out_amt),\n" +
+            "   classCode = c.class_code\n" +
+            "from yp_out_detl a,yp_zd_dict c\n" +
+            "where out_date <![CDATA[>=]]> #{beginDate} and\n" +
+            "    out_date <![CDATA[<=]]> #{endDate} and\n" +
+            "    a.group_no=#{groupNo} and\n" +
+            "    a.charge_code=c.code and\n" +
+            "    a.serial=c.serial\n" +
+            "group by c.class_code" +
+            "</script>")
+    List<Map<String,Object>> selectDrugClassOutMoneyCount(Map map);
 }

+ 45 - 21
src/main/java/cn/hnthyy/thmz/service/impl/his/yp/YpInDetlServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hnthyy.thmz.entity.his.mz.Employee;
 import cn.hnthyy.thmz.entity.his.yp.*;
 import cn.hnthyy.thmz.enums.InTypeEnum;
 import cn.hnthyy.thmz.mapper.his.mz.EmployeeMapper;
+import cn.hnthyy.thmz.mapper.his.mz.YpZdClassMapper;
 import cn.hnthyy.thmz.mapper.his.yp.*;
 import cn.hnthyy.thmz.service.his.yp.YpConfigService;
 import cn.hnthyy.thmz.service.his.yp.YpInDetlService;
@@ -20,10 +21,8 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @description:
@@ -65,6 +64,9 @@ public class YpInDetlServiceImpl implements YpInDetlService {
     @SuppressWarnings("all")
     @Autowired
     private YpConfigService ypConfigService;
+    @SuppressWarnings("all")
+    @Autowired
+    private YpZdClassMapper ypZdClassMapper;
 
     @Override
     public List<YpInDetlVo> queryYpInDetl(YpInDetl ypInDetl) {
@@ -346,25 +348,47 @@ public class YpInDetlServiceImpl implements YpInDetlService {
 
     @Override
     public List<Map<String, Object>> queryDrugMoneyCount(Map map) {
+        List<Map<String, Object>> list = new ArrayList<>();
+        List<Map<String, Object>> listIn;
+        List<Map<String, Object>> listOut;
         if(map.get("flag").equals("1")){
             return ypInDetlMapper.selectDrugKindInMoneyCount(map);
+        }else if(map.get("flag").equals("2")){
+            listIn = ypInDetlMapper.selectDrugClassInMoneyCount(map);
+            listOut = ypOutDetlMapper.selectDrugClassOutMoneyCount(map);
+            listIn.addAll(listOut);
+            Map<String, List<Map<String, Object>>> classSumlist = listIn.stream().collect(Collectors.groupingBy(e -> e.get("classCode").toString()));
+            classSumlist.forEach((k, slist) -> {
+                Map<String, Object> nmap = new HashMap<>();
+                DoubleSummaryStatistics inMoneyBuy = slist.stream().collect(Collectors.summarizingDouble(e -> Double.valueOf(e.get("inMoneyBuy").toString())));
+                DoubleSummaryStatistics inMoneyRet = slist.stream().collect(Collectors.summarizingDouble(e -> Double.valueOf(e.get("inMoneyRet").toString())));
+                DoubleSummaryStatistics outMoneyRet = slist.stream().collect(Collectors.summarizingDouble(e -> Double.valueOf(e.get("outMoneyRet").toString())));
+                nmap.put("inMoneyBuy", inMoneyBuy.getSum());
+                nmap.put("inMoneyRet", inMoneyRet.getSum());
+                nmap.put("outMoneyRet", outMoneyRet.getSum());
+                nmap.put("classCode", slist.get(0).get("classCode"));
+                nmap.put("kindName", ypZdClassMapper.selectYpZdClassesByCode(nmap.get("classCode").toString()).get(0).getName());
+                list.add(nmap);
+                list.sort(Comparator.comparing(o -> String.valueOf(o.get("classCode"))));
+            });
+        }else{
+            listIn = ypInDetlMapper.selectDrugInMoneyCount(map);
+            listOut = ypOutDetlMapper.selectDrugOutMoneyCount(map);
+            listIn.addAll(listOut);
+            Map<String, List<Map<String, Object>>> countDateSumlist = listIn.stream().collect(Collectors.groupingBy(e -> e.get("countDate").toString()));
+            countDateSumlist.forEach((k, slist) -> {
+                Map<String, Object> nmap = new HashMap<>();
+                DoubleSummaryStatistics inMoneyBuy = slist.stream().collect(Collectors.summarizingDouble(e -> Double.valueOf(e.get("inMoneyBuy").toString())));
+                DoubleSummaryStatistics inMoneyRet = slist.stream().collect(Collectors.summarizingDouble(e -> Double.valueOf(e.get("inMoneyRet").toString())));
+                DoubleSummaryStatistics outMoneyRet = slist.stream().collect(Collectors.summarizingDouble(e -> Double.valueOf(e.get("outMoneyRet").toString())));
+                nmap.put("inMoneyBuy", inMoneyBuy.getSum());
+                nmap.put("inMoneyRet", inMoneyRet.getSum());
+                nmap.put("outMoneyRet", outMoneyRet.getSum());
+                nmap.put("countDate", slist.get(0).get("countDate"));
+                list.add(nmap);
+                list.sort(Comparator.comparing(o -> String.valueOf(o.get("countDate"))));
+            });
         }
-        List<Map<String, Object>> listIn = ypInDetlMapper.selectDrugInMoneyCount(map);
-        List<Map<String, Object>> listOut = new ArrayList<>();
-        for (int i = 0; i < listIn.size(); i++) {
-            Map<String, Object> stringObjectMap = listIn.get(i);
-            String countDate = stringObjectMap.get("countDate").toString();
-            for (int j = 0; j < listOut.size(); j++) {
-                Map<String, Object> stringObjectMapOut = listIn.get(i);
-                String countDateOut = stringObjectMapOut.get("countDate").toString();
-                if(countDate.equals(countDateOut)){
-                    stringObjectMap.put("outMoneyRet",stringObjectMapOut.get("outMoneyRet"));
-                }
-            }
-        }
-        if(listIn.size() == 0){
-            return listOut;
-        }
-        return listIn;
+        return list;
     }
 }

+ 51 - 22
src/main/resources/static/js/yk/drug_in_out_count.js

@@ -9,7 +9,8 @@ $(function () {
     setTimeout(function () {
         getLodop();
     }, 800);
-    $("#class_table").hide();
+    $("#kind_table").hide();
+    $("#class_sum_table").hide();
     $(".selectpicker").selectpicker({
         dropuAuto: false
     });
@@ -30,8 +31,10 @@ $(function () {
         let id = "";
         if (statisticalMethod === "0") {
             id = 'sum_table';
+        } else if (statisticalMethod === "2") {
+            id = 'class_sum_table';
         } else {
-            id = 'class_table';
+            id = 'kind_table';
         }
         $("#" + id).table2excel({
             exclude: ".exclHide",
@@ -42,10 +45,16 @@ $(function () {
         let statisticalMethod = $("#statisticalMethod").val();
         if (statisticalMethod === "0") {
             $("#sum_table").show();
-            $("#class_table").hide();
+            $("#kind_table").hide();
+            $("#class_sum_table").hide();
+        }else if (statisticalMethod === "2") {
+            $("#sum_table").hide();
+            $("#kind_table").hide();
+            $("#class_sum_table").show();
         } else {
-            $("#class_table").show();
+            $("#kind_table").show();
             $("#sum_table").hide();
+            $("#class_sum_table").hide();
         }
         $(".dateRange").html($('#reportrange span').html());
         $(".printDate").html(format(new Date(), "yyyy-MM-dd HH:mm"));
@@ -84,50 +93,69 @@ function getRecordData() {
             }
             if (res.code == 0) {
                 let html = '';
+                let totalInMoneyBuy = 0;
                 let totalInMoneyRet = 0;
                 let totalOutMoneyRet = 0;
                 for (var i = 0; i < res.data.length; i++) {
                     let data = res.data[i];
+                    let inMoneyBuy = isEmpty(data.inMoneyBuy)?0:keepTwoDecimal(data.inMoneyBuy);
+                    let inMoneyRet = isEmpty(data.inMoneyRet)?0:keepTwoDecimal(data.inMoneyRet);
+                    let outMoneyRet = isEmpty(data.outMoneyRet)?0:keepTwoDecimal(data.outMoneyRet);
                     if (statisticalMethod == 0) {
-                        let inMoneyRet = isEmpty(data.inMoneyRet)?0:keepTwoDecimal(data.inMoneyRet);
-                        let outMoneyRet = isEmpty(data.outMoneyRet)?0:keepTwoDecimal(data.outMoneyRet);
                         html += '<tr class="sjh">';
                         html += '<td class="xtd" style="text-align: center;">' + (i + 1) + '</td>';
                         html += '<td class="xtd" style="text-align: center;">' + data.countDate + '</td>';
-                        html += '<td class="xtd" style="text-align: center;">' + data.inMoneyBuy + '</td>';
-                        html += '<td class="xtd" style="text-align: center;">' + inMoneyRet + '</td>';
-                        html += '<td class="xtd" style="text-align: center;">' + outMoneyRet + '</td>';
+                        html += '<td class="xtd" style="text-align: right;">' + inMoneyBuy + '</td>';
+                        html += '<td class="xtd" style="text-align: right;">' + inMoneyRet + '</td>';
+                        html += '<td class="xtd" style="text-align: right;">' + outMoneyRet + '</td>';
+                        html += '</tr>';
+                        totalInMoneyBuy += inMoneyBuy;
+                        totalInMoneyRet += inMoneyRet;
+                        totalOutMoneyRet += outMoneyRet;
+                    }else if (statisticalMethod == 2) {
+                        let inMoneyBuy = isEmpty(data.inMoneyBuy)?0:keepTwoDecimal(data.inMoneyBuy);
+                        let inMoneyRet = isEmpty(data.inMoneyRet)?0:keepTwoDecimal(data.inMoneyRet);
+                        let outMoneyRet = isEmpty(data.outMoneyRet)?0:keepTwoDecimal(data.outMoneyRet);
+                        html += '<tr class="sjh">';
+                        html += '<td colspan="2" class="xtd" style="text-align: left;">' + data.kindName + '</td>';
+                        html += '<td class="xtd" style="text-align: right;">' + inMoneyBuy + '</td>';
+                        html += '<td class="xtd" style="text-align: right;">' + inMoneyRet + '</td>';
+                        html += '<td class="xtd" style="text-align: right;">' + outMoneyRet + '</td>';
                         html += '</tr>';
+                        totalInMoneyBuy += inMoneyBuy;
                         totalInMoneyRet += inMoneyRet;
                         totalOutMoneyRet += outMoneyRet
                     } else {
                         let inMoneyBuy = isEmpty(data.inMoneyBuy)?0:keepTwoDecimal(data.inMoneyBuy);
                         let inMoneyRet = isEmpty(data.inMoneyRet)?0:keepTwoDecimal(data.inMoneyRet);
                         html += '<tr class="sjh">';
-                        html += '<td class="xtd" style="text-align: center;">' + data.name + '</td>';
-                        html += '<td class="xtd" style="text-align: center;">' + inMoneyBuy + '</td>';
-                        html += '<td class="xtd" style="text-align: center;">' + inMoneyRet + '</td>';
+                        html += '<td class="xtd" style="text-align: left;">' + data.name + '</td>';
+                        html += '<td class="xtd" style="text-align: right;">' + inMoneyBuy + '</td>';
+                        html += '<td class="xtd" style="text-align: right;">' + inMoneyRet + '</td>';
                         totalInMoneyRet += inMoneyBuy;
                         totalOutMoneyRet += inMoneyRet
                     }
                 }
-                if (statisticalMethod == 0) {
+                if (statisticalMethod == 0 || statisticalMethod == 2) {
                     html += '<tr class="sjh">';
-                    html += '<td colspan="3" style="text-align: right;font-weight: 700;">总计:</td>';
-                    html += '<td style="text-align: center;">' + keepTwoDecimal(totalInMoneyRet) + '</td>';
-                    html += '<td style="text-align: center;">' + keepTwoDecimal(totalOutMoneyRet) + '</td>';
+                    html += '<td colspan="2" style="text-align: right;font-weight: 700;">总计:</td>';
+                    html += '<td style="text-align: right;">' + keepTwoDecimal(totalInMoneyBuy) + '</td>';
+                    html += '<td style="text-align: right;">' + keepTwoDecimal(totalInMoneyRet) + '</td>';
+                    html += '<td style="text-align: right;">' + keepTwoDecimal(totalOutMoneyRet) + '</td>';
                     html += '</tr>';
                 }else{
                     html += '<tr class="sjh">';
                     html += '<td style="text-align: right;font-weight: 700;">总计:</td>';
-                    html += '<td style="text-align: center;">' + keepTwoDecimal(totalInMoneyRet) + '</td>';
-                    html += '<td style="text-align: center;">' + keepTwoDecimal(totalOutMoneyRet) + '</td>';
+                    html += '<td style="text-align: right;">' + keepTwoDecimal(totalInMoneyRet) + '</td>';
+                    html += '<td style="text-align: right;">' + keepTwoDecimal(totalOutMoneyRet) + '</td>';
                     html += '</tr>';
                 }
                 if (statisticalMethod == 0) {
                     $("#sum_table").append(html);
-                } else {
-                    $("#class_table").append(html);
+                }else if (statisticalMethod == 2) {
+                    $("#class_sum_table").append(html);
+                }else {
+                    $("#kind_table").append(html);
                 }
             } else if (res.code == -1) {
                 new PNotify({
@@ -160,7 +188,8 @@ function cleanParams() {
     $('#statisticalMethod').selectpicker('refresh');
     $('#reportrange span').html(moment().subtract(1, 'days').format("YYYY-MM-DD") + ' - ' + moment().subtract(1, 'days').format("YYYY-MM-DD"));
     $('#sum_table').show();
-    $('#class_table').hide();
+    $('#kind_table').hide();
+    $('#class_sum_table').hide();
     $('.sjh').remove();
 }
 
@@ -178,7 +207,7 @@ function print() {
     LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
     //设置默认打印机
     LODOP.SET_PRINTER_INDEX(defaultPrintIndex);
-    LODOP.ADD_PRINT_TEXT('280mm', '100mm', '40mm', '40mm', '第#页/共&页');
+    LODOP.ADD_PRINT_TEXT('285mm', '100mm', '40mm', '40mm', '第#页/共&页');
     LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
     var strStyle = "<style>table,td,th {border-width: 1px;" +
         "border-style: solid;border-collapse: collapse;table-layout:fixed;word-wrap:break-word;font-size: 14px}</style>";

+ 21 - 4
src/main/resources/templates/yk/drug_in_out_count.html

@@ -34,6 +34,7 @@
                                         id="statisticalMethod">
                                     <option value="0" selected>按日期</option>
                                     <option value="1">按分类</option>
+                                    <option value="2">按药性</option>
                                 </select>
                             </div>
                         </div>
@@ -66,12 +67,12 @@
             <div id="report_table"
                  style="width:920px;height: calc(100% - 160px);margin:0 auto;border: 1px solid #337ab7;font-size: 14px;padding: 40px 10px 40px 10px;overflow: scroll">
                 <div id="report_table_1">
-                    <table id="sum_table" class="table table-striped table-bordered" style="margin-top: 0px;">
+                    <table id="sum_table" class="table table-striped table-bordered" style="margin-top: 0px;border: 0px;">
                         <tr style="font-weight: 700;background-color: #EBEBE4">
                             <td colspan="6" style="font-size: 21px;text-align: center;border: transparent !important;"><span class="title">药库药品入/出库数据分析</span></td>
                         </tr>
                         <tr style="font-weight: 700;background-color: #EBEBE4">
-                            <td colspan="2" style="text-align: left;border: transparent !important;">统计日期:<span class="dateRange"></span></td>
+                            <td colspan="2" style="text-align: left;border: transparent !important;">统计日期:<span class="dateRange"></span><br>&nbsp;</td>
                             <td colspan="1" style="text-align: right;border: transparent !important;">库房名称:<span class="groupName"></span></td>
                             <td colspan="3" style="text-align: right;border: transparent !important;">打印日期:<span class="printDate"></span></td>
                         </tr>
@@ -83,9 +84,9 @@
                             <td class="xtd" style="text-align: center;width: 200px;">出库金额(零售价)</td>
                         </tr>
                     </table>
-                    <table id="class_table" class="table table-striped table-bordered" style="margin-top: 0px;">
+                    <table id="kind_table" class="table table-striped table-bordered" style="margin-top: 0px;border: 0px;">
                         <tr style="font-weight: 700;background-color: #EBEBE4">
-                            <td colspan="3" style="font-size: 21px;text-align: center;border: transparent !important;"><span class="title">药品类型入库统计表</span></td>
+                            <td colspan="3" style="font-size: 21px;text-align: center;border: transparent !important;"><span class="title">药品类型入库统计表</span><br>&nbsp;</td>
                         </tr>
                         <tr style="font-weight: 700;background-color: #EBEBE4">
                             <td style="text-align: left;border: transparent !important;">统计日期:<span class="dateRange"></span></td>
@@ -98,6 +99,22 @@
                             <td class="xtd" style="text-align: center;width: 200px;">入库金额(零售价)</td>
                         </tr>
                     </table>
+                    <table id="class_sum_table" class="table table-striped table-bordered" style="margin-top: 0px;border: 0px;">
+                        <tr style="font-weight: 700;background-color: #EBEBE4">
+                            <td colspan="6" style="font-size: 21px;text-align: center;border: transparent !important;"><span class="title">药品出/入库药性分类统计</span><br>&nbsp;</td>
+                        </tr>
+                        <tr style="font-weight: 700;background-color: #EBEBE4">
+                            <td colspan="2" style="text-align: left;border: transparent !important;">统计日期:<span class="dateRange"></span></td>
+                            <td colspan="1" style="text-align: right;border: transparent !important;">库房名称:<span class="groupName"></span></td>
+                            <td colspan="3" style="text-align: right;border: transparent !important;">打印日期:<span class="printDate"></span></td>
+                        </tr>
+                        <tr>
+                            <td colspan="2" class="xtd" style="text-align: center;width: 200px;">药性</td>
+                            <td class="xtd" style="text-align: center;width: 200px;">入库金额(购入价)</td>
+                            <td class="xtd" style="text-align: center;width: 200px;">入库金额(零售价)</td>
+                            <td class="xtd" style="text-align: center;width: 200px;">出库金额(零售价)</td>
+                        </tr>
+                    </table>
                 </div>
             </div>
         </div>