浏览代码

新增药品进销存统计查询

hsh 1 年之前
父节点
当前提交
4ee995288f

+ 5 - 0
src/main/java/thyyxxk/webserver/controller/yp/YpDictController.java

@@ -203,4 +203,9 @@ public class YpDictController {
         return service.selectYpGroupNameByYfFlag(text, yfFlag);
     }
 
+    @GetMapping("/selectYpGroupNameAll")
+    public ResultVo<List<Map<String, Object>>> selectYpGroupNameAll(@RequestParam("text") String text){
+        return service.selectYpGroupNameAll(text);
+    }
+
 }

+ 46 - 0
src/main/java/thyyxxk/webserver/controller/yp/YpInventoryController.java

@@ -0,0 +1,46 @@
+package thyyxxk.webserver.controller.yp;
+
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.yp.YpInventoryVo;
+import thyyxxk.webserver.service.yp.YpInventoryService;
+
+import java.util.Map;
+
+/**
+ * @ClassName ypInventoryController
+ * @Author hsh
+ * @Date 2024/2/29 11:20
+ * @Version 1.0
+ * @Description 药品库存管理
+ **/
+@RestController
+@RequestMapping("/ypInventory")
+public class YpInventoryController {
+
+    private final YpInventoryService service;
+
+    public YpInventoryController(YpInventoryService service) {
+        this.service = service;
+    }
+
+    @PostMapping("/selectYpUsedQuantity")
+    public ResultVo<Map<String, Object>> selectYpUsedQuantity(@RequestBody @Validated YpInventoryVo vo){
+        return service.selectYpUsedQuantity(vo);
+    }
+
+    @PostMapping("/selectYpUsedMx")
+    public ResultVo<Map<String, Object>> selectYpUsedMx(@RequestBody @Validated YpInventoryVo vo){
+        return service.selectYpUsedMx(vo);
+    }
+
+    @PostMapping("/selectYpOutInStat")
+    public ResultVo<Map<String, Object>> selectYpOutInStat(@RequestBody @Validated YpInventoryVo vo){
+        return service.selectYpOutInStat(vo);
+    }
+
+}

+ 1 - 1
src/main/java/thyyxxk/webserver/dao/his/ybkf/YbUtilDao.java

@@ -91,7 +91,7 @@ public interface YbUtilDao {
     List<Map<String, Object>> selectAllDept(@Param("str") String str);
 
     @Select("<script> " +
-            "select rtrim(name) as label, rtrim(code) as value from mzy_zd_charge_type where 1 = 1 " +
+            "select rtrim(name) as label, rtrim(code) as value from mzy_zd_charge_type where isnull(del_flag, '0') = '0'  " +
             "<if test=\"str != null and str != '' \"> " +
             " and (name like '%${str}%' or code like '%${str}%' or py_code like ('%' + upper(#{str}) + '%') or d_code like ('%' + upper(#{str}) + '%') ) " +
             "</if> " +

+ 1 - 1
src/main/java/thyyxxk/webserver/dao/his/yp/YpDictDao.java

@@ -34,7 +34,7 @@ public interface YpDictDao extends BaseMapper<YpZdDict> {
             " on yf.group_no = ks.group_no, " +
             " yp_zd_dict as zd " +
             " where yf.charge_code = zd.code and yf.serial = zd.serial " +
-            " and (zd.name like '%${text}%' or zd.py_code like ('%' + upper(#{text}) + '%') or zd.d_code like ('%' + upper(#{text}) + '%') ) " +
+            " and (zd.name like '%${text}%' or zd.code like '%${text}%' or zd.py_code like ('%' + upper(#{text}) + '%') or zd.d_code like ('%' + upper(#{text}) + '%') ) " +
             " order by yf.charge_code ")
     List<Map<String, Object>> selectYpVisibleFlag(@Param("text") String text);
 

+ 91 - 0
src/main/java/thyyxxk/webserver/dao/his/yp/YpInventoryDao.java

@@ -0,0 +1,91 @@
+package thyyxxk.webserver.dao.his.yp;
+
+import org.apache.ibatis.annotations.Select;
+import thyyxxk.webserver.entity.yp.YpInventoryVo;
+import thyyxxk.webserver.entity.yp.YpZdDictVo;
+
+import java.util.List;
+import java.util.Map;
+
+public interface YpInventoryDao {
+
+    @Select("<script> " +
+            " select t.charge_code as code, t.serial, t.name, t.pack_retprice as packRetprice, t.pack_size as packSize, t.specification, sum(t.sl) as amount " +
+            " from (select yp.charge_code, yp.serial, zd.name, zd.pack_retprice, zd.pack_size, zd.specification, sum(yp.amount) as sl  " +
+            " from yp_zy_patient yp with(nolock), yp_zd_dict zd with(nolock) " +
+            " where yp.charge_code = zd.code and yp.serial = zd.serial " +
+            "<if test=\"startTime != null and startTime != '' \">" +
+            " and yp.order_date &gt;= #{startTime}  " +
+            "</if>" +
+            "<if test=\"endTime != null and endTime != '' \">" +
+            " and yp.order_date &lt;= #{endTime}  " +
+            "</if>" +
+            "<if test=\"keyCode != null and keyCode != '' \">" +
+            " and (zd.code like '%${keyCode}%' or zd.name like '%${keyCode}%' " +
+            " or zd.py_code like ('%' + upper(#{keyCode}) + '%') or zd.d_code like ('%' + upper(#{keyCode}) + '%')) " +
+            "</if>" +
+            "<if test=\"groupNo != null and groupNo != '' \">" +
+            " and yp.group_no = #{groupNo}  " +
+            "</if>" +
+            " group by yp.charge_code, yp.serial, zd.name, zd.pack_retprice, zd.pack_size, zd.specification " +
+            " union all " +
+            " select yp.charge_item_code as charge_code, yp.serial, zd.name, zd.pack_retprice, zd.pack_size, zd.specification, sum(yp.quantity) as sl  " +
+            " from yp_mz_fytj yp with(nolock), yp_zd_dict zd with(nolock) " +
+            " where yp.charge_item_code = zd.code and yp.serial = zd.serial " +
+            "<if test=\"startTime != null and startTime != '' \">" +
+            " and yp.charge_date &gt;= #{startTime}  " +
+            "</if>" +
+            "<if test=\"endTime != null and endTime != '' \">" +
+            " and yp.charge_date &lt;= #{endTime}  " +
+            "</if>" +
+            "<if test=\"keyCode != null and keyCode != '' \">" +
+            " and (zd.code like '%${keyCode}%' or zd.name like '%${keyCode}%' " +
+            " or zd.py_code like ('%' + upper(#{keyCode}) + '%') or zd.d_code like ('%' + upper(#{keyCode}) + '%')) " +
+            "</if>" +
+            "<if test=\"groupNo != null and groupNo != '' \">" +
+            " and yp.group_no = #{groupNo}  " +
+            "</if>" +
+            " group by yp.charge_item_code, yp.serial, zd.name, zd.pack_retprice, zd.pack_size, zd.specification) t " +
+            " group by t.charge_code, t.serial, t.name, t.pack_retprice, t.pack_size, t.specification " +
+            " order by sum(t.sl) desc " +
+            "</script> ")
+    List<YpZdDictVo> selectYpUsedQuantity(YpInventoryVo vo);
+
+    @Select("<script> " +
+            " select t.* from " +
+            " (select yp.charge_code as code, yp.serial, zd.name, zd.pack_retprice as packRetprice, zd.specification, " +
+            " yp.order_date as sj, yp.inpatient_no as zyh, yp.admiss_times as cs, " +
+            " yp.name as xm, yp.amount, yp.page_no as pageNo, yp.act_order_no as orderNo, " +
+            " yp.group_no as groupNo, ks.group_name as groupName, '' as receiptNo " +
+            " from yp_zy_patient yp with(nolock) left join yp_zd_group_name ks on yp.group_no = ks.group_no, yp_zd_dict zd with(nolock) " +
+            " where yp.charge_code = zd.code and yp.serial = zd.serial and yp.charge_code = #{code} " +
+            "<if test=\"startTime != null and startTime != '' \">" +
+            " and yp.order_date &gt;= #{startTime}  " +
+            "</if>" +
+            "<if test=\"endTime != null and endTime != '' \">" +
+            " and yp.order_date &lt;= #{endTime}  " +
+            "</if>" +
+            "<if test=\"groupNo != null and groupNo != '' \">" +
+            " and yp.group_no = #{groupNo}  " +
+            "</if>" +
+            " union all " +
+            " select yp.charge_item_code as code, yp.serial, zd.name, zd.pack_retprice as packRetprice, zd.specification, " +
+            " yp.charge_date as sj, yp.patient_id as zyh, yp.times as cs, " +
+            " yp.name as xm, yp.quantity as amount, yp.real_no as pageNo, yp.order_no as orderNo, " +
+            " yp.group_no as groupNo, ks.group_name as groupName, yp.receipt_no as receiptNo " +
+            " from yp_mz_fytj yp with(nolock) left join yp_zd_group_name ks on yp.group_no = ks.group_no, yp_zd_dict zd with(nolock) " +
+            " where yp.charge_item_code = zd.code and yp.serial = zd.serial and yp.charge_item_code = #{code} " +
+            "<if test=\"startTime != null and startTime != '' \">" +
+            " and yp.charge_date &gt;= #{startTime}  " +
+            "</if>" +
+            "<if test=\"endTime != null and endTime != '' \">" +
+            " and yp.charge_date &lt;= #{endTime}  " +
+            "</if>" +
+            "<if test=\"groupNo != null and groupNo != '' \">" +
+            " and yp.group_no = #{groupNo}  " +
+            "</if>" +
+            " ) t order by t.sj " +
+            "</script> ")
+    List<Map<String, Object>> selectYpUsedMx(YpInventoryVo vo);
+
+}

+ 7 - 0
src/main/java/thyyxxk/webserver/dao/his/yp/YpZdGroupNameDao.java

@@ -17,4 +17,11 @@ public interface YpZdGroupNameDao extends BaseMapper<YpZdGroupName> {
             " order by gn.group_no ")
     List<CodeName> selectYpGroupNameByYfFlag(String text, String yfFlag);
 
+    @Select(" select gn.group_name as name, gn.group_no as code, gn.yf_flag as statusFlag from yp_zd_group_name as gn " +
+            " where (gn.group_no like '%${text}%' or gn.group_name like '%${text}%' " +
+            " or gn.py_code like ('%' + upper(#{text}) + '%') or gn.d_code like ('%' + upper(#{text}) + '%')) " +
+            " order by gn.group_no ")
+    List<CodeName> selectYpGroupNameAll(String text);
+
+
 }

+ 23 - 0
src/main/java/thyyxxk/webserver/entity/yp/YpInventoryVo.java

@@ -0,0 +1,23 @@
+package thyyxxk.webserver.entity.yp;
+
+import lombok.Data;
+
+/**
+ * @ClassName YpInventoryVo
+ * @Author hsh
+ * @Date 2024/2/29 15:04
+ * @Version 1.0
+ * @Description 查询进销存Vo
+ **/
+@Data
+public class YpInventoryVo {
+
+    private String startTime;
+    private String endTime;
+    private String keyCode;
+    private String groupNo;
+    //
+    private String groupType;
+    private String code;
+
+}

+ 2 - 0
src/main/java/thyyxxk/webserver/entity/yp/YpZdDictVo.java

@@ -108,5 +108,7 @@ public class YpZdDictVo {
     private String operId;
     @TableField(exist = false)
     private String groupNo;
+    @TableField(exist = false)
+    private BigDecimal amount;
 
 }

+ 30 - 1
src/main/java/thyyxxk/webserver/service/yp/YpDictService.java

@@ -34,10 +34,12 @@ import thyyxxk.webserver.utils.ResultVoUtil;
 import thyyxxk.webserver.utils.StringUtil;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @ClassName YpDictService
@@ -942,7 +944,7 @@ public class YpDictService {
     /**
      * @Description 查询药库或者药房
      * @Author hsh
-     * @param text 查询
+     * @param text 关键字
      * @param yfFlag 药库药房标志(0:药库;1:药房)
      * @return list 药库或者药房
      * @Date 2024/2/21 14:56
@@ -952,4 +954,31 @@ public class YpDictService {
         return ResultVoUtil.success(list);
     }
 
+    /**
+     * @Description 查询药库以及药房
+     * @Author hsh
+     * @param text 关键字
+     * @return list 药库以及药房
+     * @Date 2024/2/29 15:19
+     */
+    public ResultVo<List<Map<String, Object>>> selectYpGroupNameAll(String text){
+        List<CodeName> list = ypZdGroupNameDao.selectYpGroupNameAll(text);
+        Map<Integer, List<CodeName>> map = list.stream().collect(Collectors.groupingBy(CodeName::getStatusFlag));
+        List<Map<String, Object>> ll = new ArrayList<>();
+        for(Map.Entry<Integer, List<CodeName>> entry: map.entrySet()){
+            Integer key = entry.getKey();
+            List<CodeName> value = entry.getValue();
+            Map<String, Object> m = new HashMap<>();
+            if(key == 0){
+                m.put("label", "库房");
+            } else if(key == 1){
+                m.put("label", "药房");
+            }
+            m.put("key", key);
+            m.put("options", value);
+            ll.add(m);
+        }
+        return ResultVoUtil.success(ll);
+    }
+
 }

+ 88 - 0
src/main/java/thyyxxk/webserver/service/yp/YpInventoryService.java

@@ -0,0 +1,88 @@
+package thyyxxk.webserver.service.yp;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import thyyxxk.webserver.dao.his.yp.YpInventoryDao;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.yp.YpInventoryVo;
+import thyyxxk.webserver.entity.yp.YpZdDictVo;
+import thyyxxk.webserver.utils.DecimalUtil;
+import thyyxxk.webserver.utils.ResultVoUtil;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @ClassName YpInventoryService
+ * @Author hsh
+ * @Date 2024/2/29 14:59
+ * @Version 1.0
+ * @Description 药品库存管理
+ **/
+@Service
+@Slf4j
+public class YpInventoryService {
+
+    private final YpInventoryDao dao;
+
+    public YpInventoryService(YpInventoryDao dao) {
+        this.dao = dao;
+    }
+
+    public ResultVo<Map<String, Object>> selectYpUsedQuantity(YpInventoryVo vo){
+        Map<String, Object> map = new HashMap<>();
+        List<YpZdDictVo> resultData = new ArrayList<>();
+        List<YpZdDictVo> list = dao.selectYpUsedQuantity(vo);
+        // 药品有拆分的情况  需要合并在一起显示
+        Map<String, List<YpZdDictVo>> mapKey = list.stream().collect(Collectors.groupingBy(YpZdDictVo::getCode));
+        for(Map.Entry<String, List<YpZdDictVo>> entry: mapKey.entrySet()) {
+            String key = entry.getKey();
+            List<YpZdDictVo> value = entry.getValue();
+            if(!value.isEmpty() && value.size() > 1){
+                BigDecimal minSl = BigDecimal.ZERO;
+                BigDecimal packSize = BigDecimal.ZERO;
+                YpZdDictVo ypVo = new YpZdDictVo();
+                for(YpZdDictVo ypZdDictVo : value){
+                    if("01".equals(ypZdDictVo.getSerial())){
+                        minSl = DecimalUtil.add(minSl, ypZdDictVo.getAmount());
+                    } else if("99".equals(ypZdDictVo.getSerial())){
+                        packSize = DecimalUtil.add(packSize, ypZdDictVo.getPackSize());
+                        BeanUtils.copyProperties(ypZdDictVo, ypVo);
+                    }
+                }
+                // 小包装转成大包装数量
+                BigDecimal add = DecimalUtil.divide(minSl, packSize, 0);
+                ypVo.setAmount(DecimalUtil.add(ypVo.getAmount(), add));
+                resultData.add(ypVo);
+            } else {
+                resultData.addAll(value);
+            }
+
+        }
+        map.put("resultData", resultData.stream().sorted(Comparator.comparing(YpZdDictVo::getAmount).reversed()).collect(Collectors.toList()));
+        return ResultVoUtil.success(map);
+    }
+
+    public ResultVo<Map<String, Object>> selectYpUsedMx(YpInventoryVo vo){
+        Map<String, Object> map = new HashMap<>();
+        List<Map<String, Object>> list = dao.selectYpUsedMx(vo);
+        map.put("resultData", list);
+        return ResultVoUtil.success(map);
+    }
+
+    public ResultVo<Map<String, Object>> selectYpOutInStat(YpInventoryVo vo){
+        Map<String, Object> map = new HashMap<>();
+
+
+
+        return ResultVoUtil.success(map);
+    }
+
+
+}