Browse Source

新增药库盘点

hsh 3 months ago
parent
commit
f5575d8d61

+ 5 - 0
src/main/java/cn/hnthyy/thmz/common/Constants.java

@@ -378,6 +378,11 @@ public class Constants {
      */
     public static final String KL_GROUP_NO = "83";
 
+    /**
+     * 西药库药品组
+     */
+    public static final String XYK_GROUP_NO = "11";
+
     /**
      * 医材的药品组
      */

+ 118 - 30
src/main/java/cn/hnthyy/thmz/controller/yf/YfInventoryController.java

@@ -2,12 +2,15 @@ package cn.hnthyy.thmz.controller.yf;
 
 import cn.hnthyy.thmz.Utils.TokenUtil;
 import cn.hnthyy.thmz.comment.UserLoginToken;
+import cn.hnthyy.thmz.common.Constants;
 import cn.hnthyy.thmz.entity.MzException;
+import cn.hnthyy.thmz.entity.his.yp.YpOutDetl;
 import cn.hnthyy.thmz.entity.his.yp.YpOutDetlYf;
 import cn.hnthyy.thmz.entity.his.mz.Employee;
 import cn.hnthyy.thmz.entity.thmz.User;
 import cn.hnthyy.thmz.service.his.mz.EmployeeService;
 import cn.hnthyy.thmz.service.his.yf.YfInventoryService;
+import cn.hnthyy.thmz.vo.YpBaseVo;
 import cn.hnthyy.thmz.vo.YpBaseYfVo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -49,13 +52,23 @@ public class YfInventoryController {
         try {
             if(StringUtils.isBlank(groupNo)){
                 resultMap.put("code", -1);
-                resultMap.put("message", "生成失败,药房编码为空");
+                resultMap.put("message", "生成失败,药库或者药房编码为空");
                 return resultMap;
             }
-            List<YpBaseYfVo> list = yfInventoryService.queryYpInventoryData(groupNo, infusionFlag, visibleFlag, drugText);
-            resultMap.put("code", 0);
-            resultMap.put("message", "生成药品盘点成功");
-            resultMap.put("data", list);
+            // 暂时
+            if(!Constants.XYK_GROUP_NO.equals(groupNo)){
+                List<YpBaseYfVo> list = yfInventoryService.queryYpInventoryData(groupNo, infusionFlag, visibleFlag, drugText);
+                resultMap.put("code", 0);
+                resultMap.put("message", "生成药品盘点成功");
+                resultMap.put("data", list);
+            } else {
+                // 西药库盘点
+                List<YpBaseVo> list = yfInventoryService.queryYpInventoryKfData(groupNo, infusionFlag, visibleFlag, drugText);
+                resultMap.put("code", 0);
+                resultMap.put("message", "生成药品盘点成功");
+                resultMap.put("data", list);
+            }
+
             return resultMap;
         } catch (Exception e) {
             log.error(e.toString());
@@ -93,6 +106,34 @@ public class YfInventoryController {
         }
     }
 
+    /**
+     * 保存药库盘点药品数据
+     * @param ypOutDetlYfs
+     * @return
+     */
+    @UserLoginToken
+    @RequestMapping(value = "/saveYpInventoryYkData",method = {RequestMethod.POST})
+    public Map<String,Object> saveYpInventoryYkData(@RequestBody List<YpOutDetlYf> ypOutDetlYfs, HttpServletRequest httpServletRequest)throws MzException {
+        User tokenUser = TokenUtil.getUser(httpServletRequest);
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            if(ypOutDetlYfs==null || ypOutDetlYfs.size()==0){
+                resultMap.put("code", -1);
+                resultMap.put("message", "提交失败,药品为空");
+                return resultMap;
+            }
+            yfInventoryService.saveYpInventoryYkData(ypOutDetlYfs,tokenUser.getUserIdCode());
+            resultMap.put("code", 0);
+            resultMap.put("message", "提交盘点药品数据成功");
+            return resultMap;
+        } catch (Exception e) {
+            log.error(e.toString());
+            resultMap.put("code", -1);
+            resultMap.put("message", "提交盘点药品数据失败");
+            return resultMap;
+        }
+    }
+
     /**
      * 获取盘点记录
      * @param beginDate
@@ -109,16 +150,23 @@ public class YfInventoryController {
         try {
             if(StringUtils.isBlank(groupNo)){
                 resultMap.put("code", -1);
-                resultMap.put("message", "查询盘点记录失败,药房编码为空");
+                resultMap.put("message", "查询盘点记录失败,药库或者药房编码为空");
                 return resultMap;
             }
             if(StringUtils.isBlank(confirmFlag)){
                 confirmFlag = "";
             }
-            List<YpOutDetlYf> ypOutDetlYfs = yfInventoryService.queryYpInventoryRecord(beginDate, endDate, groupNo, confirmFlag);
-            resultMap.put("code", 0);
-            resultMap.put("data", ypOutDetlYfs);
-            resultMap.put("message", "查询盘点记录成功");
+            if(!Constants.XYK_GROUP_NO.equals(groupNo)){
+                List<YpOutDetlYf> ypOutDetlYfs = yfInventoryService.queryYpInventoryRecord(beginDate, endDate, groupNo, confirmFlag);
+                resultMap.put("code", 0);
+                resultMap.put("data", ypOutDetlYfs);
+                resultMap.put("message", "查询盘点记录成功");
+            } else {
+                List<YpOutDetl> ypOutDetls = yfInventoryService.queryYpInventoryKfRecord(beginDate, endDate, groupNo, confirmFlag);
+                resultMap.put("code", 0);
+                resultMap.put("data", ypOutDetls);
+                resultMap.put("message", "查询盘点记录成功");
+            }
             return resultMap;
         } catch (Exception e) {
             log.error(e.toString());
@@ -135,25 +183,44 @@ public class YfInventoryController {
      */
     @UserLoginToken
     @RequestMapping(value = "/getYpInventoryPrintData",method = {RequestMethod.GET})
-    public Map<String,Object> getYpInventoryPrintData(@RequestParam("drawNo") String drawNo){
+    public Map<String,Object> getYpInventoryPrintData(@RequestParam("groupNo") String groupNo, @RequestParam("drawNo") String drawNo){
         Map<String, Object> resultMap = new HashMap<>();
         try {
+            if(StringUtils.isBlank(groupNo)){
+                resultMap.put("code", -1);
+                resultMap.put("message", "获取盘点数据失败,药库或者药房为空");
+                return resultMap;
+            }
             if(StringUtils.isBlank(drawNo)){
                 resultMap.put("code", -1);
                 resultMap.put("message", "获取盘点数据失败,盘点单号为空");
                 return resultMap;
             }
-            List<YpBaseYfVo> list = yfInventoryService.queryYpInventoryPrintData(drawNo);
-            if(list.size()>0){
-                Employee cofEmployee = employeeService.queryByUserCode(list.get(0).getConfirmId());
-                if(cofEmployee != null){
-                    resultMap.put("confirmName", cofEmployee.getEmployeeName());
+            if(!Constants.XYK_GROUP_NO.equals(groupNo)){
+                List<YpBaseYfVo> list = yfInventoryService.queryYpInventoryPrintData(drawNo);
+                if(!list.isEmpty()){
+                    Employee cofEmployee = employeeService.queryByUserCode(list.get(0).getConfirmId());
+                    if(cofEmployee != null){
+                        resultMap.put("confirmName", cofEmployee.getEmployeeName());
+                    }
+                    Employee inEmployee = employeeService.queryByUserCode(list.get(0).getInputId());
+                    resultMap.put("inputName", inEmployee.getEmployeeName());
                 }
-                Employee inEmployee = employeeService.queryByUserCode(list.get(0).getInputId());
-                resultMap.put("inputName", inEmployee.getEmployeeName());
+
+                resultMap.put("data", list);
+            } else {
+                List<YpBaseVo> list = yfInventoryService.queryYpInventoryYkPrintData(drawNo);
+                if(!list.isEmpty()){
+                    Employee cofEmployee = employeeService.queryByUserCode(list.get(0).getConfirmId());
+                    if(cofEmployee != null){
+                        resultMap.put("confirmName", cofEmployee.getEmployeeName());
+                    }
+                    Employee inEmployee = employeeService.queryByUserCode(list.get(0).getInputId());
+                    resultMap.put("inputName", inEmployee.getEmployeeName());
+                }
+                resultMap.put("data", list);
             }
             resultMap.put("code", 0);
-            resultMap.put("data", list);
             return resultMap;
         } catch (Exception e) {
             log.error(e.toString());
@@ -165,31 +232,52 @@ public class YfInventoryController {
 
     /**
      * 审核盘点记录
+     * @param groupNo
      * @param drawNo
      * @return
      */
     @UserLoginToken
     @RequestMapping(value = "/auditYpInventory",method = {RequestMethod.GET})
-    public Map<String,Object> auditYpInventory(@RequestParam("drawNo") String drawNo,HttpServletRequest httpServletRequest)throws MzException {
+    public Map<String,Object> auditYpInventory(@RequestParam("groupNo") String groupNo,@RequestParam("drawNo") String drawNo,HttpServletRequest httpServletRequest)throws MzException {
         User tokenUser = TokenUtil.getUser(httpServletRequest);
         Map<String, Object> resultMap = new HashMap<>();
         try {
-            if(StringUtils.isBlank(drawNo)){
+            if(StringUtils.isBlank(groupNo)){
                 resultMap.put("code", -1);
-                resultMap.put("message", "审核盘点失败,盘点单号为空");
+                resultMap.put("message", "审核盘点失败,药库或者药房为空");
                 return resultMap;
             }
-            String ypOutDetlYfConfirmFlag = yfInventoryService.getYpOutDetlYfConfirmFlag(drawNo);
-            if(ypOutDetlYfConfirmFlag.equals("1")){
+            if(StringUtils.isBlank(drawNo)){
                 resultMap.put("code", -1);
-                resultMap.put("message", "盘点单号【"+drawNo+"】已审核通过,请勿重复审核!");
+                resultMap.put("message", "审核盘点失败,盘点单号为空");
                 return resultMap;
             }
-            YpOutDetlYf ypOutDetlYf = new YpOutDetlYf();
-            ypOutDetlYf.setConfirmFlag("1");
-            ypOutDetlYf.setDrawNo(drawNo);
-            ypOutDetlYf.setConfirmId(tokenUser.getUserIdCode());
-            yfInventoryService.auditYpInventory(ypOutDetlYf);
+            if(!Constants.XYK_GROUP_NO.equals(groupNo)){
+                String ypOutDetlYfConfirmFlag = yfInventoryService.getYpOutDetlYfConfirmFlag(drawNo);
+                if(ypOutDetlYfConfirmFlag.equals("1")){
+                    resultMap.put("code", -1);
+                    resultMap.put("message", "盘点单号【"+drawNo+"】已审核通过,请勿重复审核!");
+                    return resultMap;
+                }
+                YpOutDetlYf ypOutDetlYf = new YpOutDetlYf();
+                ypOutDetlYf.setConfirmFlag("1");
+                ypOutDetlYf.setDrawNo(drawNo);
+                ypOutDetlYf.setConfirmId(tokenUser.getUserIdCode());
+                yfInventoryService.auditYpInventory(ypOutDetlYf);
+            } else {
+                String ypOutDetlConfirmFlag = yfInventoryService.getYpOutDetlConfirmFlag(drawNo);
+                if(ypOutDetlConfirmFlag.equals("1")){
+                    resultMap.put("code", -1);
+                    resultMap.put("message", "盘点单号【"+drawNo+"】已审核通过,请勿重复审核!");
+                    return resultMap;
+                }
+                YpOutDetl ypOutDetl = new YpOutDetl();
+                ypOutDetl.setConfirmFlag("1");
+                ypOutDetl.setGroupNo(groupNo);
+                ypOutDetl.setDrawNo(drawNo);
+                ypOutDetl.setConfirmId(tokenUser.getUserIdCode());
+                yfInventoryService.auditYpInventoryYk(ypOutDetl);
+            }
             resultMap.put("code", 0);
             resultMap.put("message", "审核盘点记录成功");
             resultMap.put("data", drawNo);

+ 2 - 0
src/main/java/cn/hnthyy/thmz/entity/his/yp/YpOutDetl.java

@@ -100,4 +100,6 @@ public class YpOutDetl extends PageBean {
   private String nationalCode;
   //药品追溯码(整箱的集装箱外追溯码)
   private String drugTracCodg;
+  // 实盘数量 (药房盘点用)
+  private Double currStockAmount;
 }

+ 45 - 0
src/main/java/cn/hnthyy/thmz/mapper/his/yp/YpBaseMapper.java

@@ -2,12 +2,15 @@ package cn.hnthyy.thmz.mapper.his.yp;
 
 import cn.hnthyy.thmz.entity.his.yp.YpBase;
 import cn.hnthyy.thmz.pageDto.PageBean;
+import cn.hnthyy.thmz.vo.YpBaseVo;
+import cn.hnthyy.thmz.vo.YpBaseYfVo;
 import cn.hnthyy.thmz.vo.YpZdBaseVo;
 import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -104,6 +107,21 @@ public interface YpBaseMapper {
     int updateYpBaseStock(@Param("stockAmount") double stockAmount, @Param("stockValue") double stockValue, @Param("chargeCode") String chargeCode,
                           @Param("serial") String serial, @Param("groupNo") String groupNo);
 
+    /**
+     * 更新库存(覆盖)
+     *
+     * @param chargeCode
+     * @param serial
+     * @param groupNo
+     * @param stockAmount
+     * @param stockValue
+     * @return
+     */
+    @Update("update yp_base set stock_amount =#{stockAmount,jdbcType=DECIMAL}, stock_value =#{stockValue,jdbcType=DECIMAL} " +
+            " where charge_code =#{chargeCode} and serial =#{serial} and group_no =#{groupNo}")
+    int updateStockAmountCover(@Param("chargeCode") String chargeCode, @Param("serial") String serial, @Param("groupNo") String groupNo,
+                               @Param("stockAmount") Double stockAmount, @Param("stockValue") BigDecimal stockValue);
+
     /**
      * 药品字典数据同步更新到药库
      *
@@ -378,4 +396,31 @@ public interface YpBaseMapper {
             "  a.visible_flag, a.manu_code, b.stock_amount, b.location",
             " </script>"})
     List<YpZdBaseVo> selectYpZdBase(@Param("groupNo")String groupNo);
+
+
+    @Select("SELECT distinct " +
+            "   rtrim(a.code) as charge_code," +
+            "   a.name," +
+            "   a.serial," +
+            "   a.specification," +
+            "   isnull(b.pack_retprice,a.pack_retprice) as pack_retprice," +
+            "   a.manu_code," +
+            "   b.stock_amount," +
+            "   isnull(b.pack_retprice,a.pack_retprice) * b.stock_amount as stock_value," +
+            "   b.location," +
+            "   a.py_code," +
+            "   b.group_no," +
+            "   m.name as manufactoryName" +
+            " FROM yp_zd_dict a WITH(NOLOCK) left join yp_zd_manufactory m WITH(NOLOCK) on a.manu_code = m.code" +
+            ",yp_print_name c WITH(NOLOCK),yp_base b WITH(NOLOCK)" +
+            " where a.code=b.charge_code and" +
+            "    a.serial=b.serial and" +
+            "    a.code  =c.charge_code and" +
+            "    b.group_no=#{groupNo} and " +
+            "    (a.code like '${drugText}%' or a.name like '${drugText}%' or a.py_code like '${drugText}%' or a.d_code like '${drugText}%' ) and " +
+            "    isnull(a.infusion_flag,'0') like '${infusionFlag}%'" +
+            "    and ((isnull(a.del_flag,'0') <>'1') or ( b.stock_amount <> 0))" +
+            "   order by location")
+    List<YpBaseVo> selectYpInventoryData(@Param("groupNo") String groupNo, @Param("infusionFlag") String infusionFlag, @Param("visibleFlag") String visibleFlag, @Param("drugText") String drugText);
+
 }

+ 123 - 0
src/main/java/cn/hnthyy/thmz/mapper/his/yp/YpOutDetlMapper.java

@@ -1,9 +1,13 @@
 package cn.hnthyy.thmz.mapper.his.yp;
 
 import cn.hnthyy.thmz.entity.his.yp.YpOutDetl;
+import cn.hnthyy.thmz.entity.his.yp.YpOutDetlYf;
+import cn.hnthyy.thmz.vo.YpBaseVo;
+import cn.hnthyy.thmz.vo.YpBaseYfVo;
 import cn.hnthyy.thmz.vo.YpOutDetlVo;
 import org.apache.ibatis.annotations.*;
 
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -237,6 +241,14 @@ public interface YpOutDetlMapper {
     @Delete("delete from yp_out_detl where draw_yf=#{drawYf,jdbcType=VARCHAR}")
     int deleteByDrawYf(@Param("drawYf") String drawYf);
 
+    /**
+     * 删除药库出库记录
+     * @param drawNo
+     * @return
+     */
+    @Delete("delete yp_out_detl where draw_no=#{drawNo}")
+    int deleteYpOutDetlByDrawNo(@Param("drawNo") String drawNo);
+
     /**
      * 删除出库单药品确认记录
      *
@@ -440,4 +452,115 @@ public interface YpOutDetlMapper {
             "group by c.class_code" +
             "</script>")
     List<Map<String,Object>> selectDrugClassOutMoneyCount(Map map);
+
+    @Select("select draw_no from yp_out_detl WITH(NOLOCK) where out_type >= '6' and out_type <= '8' and datediff ( mm , out_date , GETDATE() ) =0 and isnull ( confirm_flag , '0' ) ='0' and group_no =#{groupNo} group by draw_no")
+    String selectInventoryDrawNo(@Param("groupNo") String groupNo);
+
+    @Select("select distinct" +
+            "  a.draw_no," +
+            "  a.group_no," +
+            "  a.out_date," +
+            "  c.location," +
+            "  rtrim(a.charge_code) as charge_code," +
+            "  a.serial," +
+            "  b.name," +
+            "  b.specification," +
+            "  a.pack_retprice," +
+            "  a.stock_amount," +
+            "  a.confirm_date," +
+            "  case when isnull(a.buy_price,0)=0 then b.buy_price else a.buy_price end as buy_price," +
+            "  a.stock_amount-a.out_amt as curr_stock_amount," +
+            "  -a.out_amt as profit_lossprofit_loss," +
+            "  -a.out_amt*a.pack_retprice as profit_lossprofit_money," +
+            "  b.py_code," +
+            "  m.name as manufactoryName" +
+            " from yp_out_detl a WITH(NOLOCK),yp_zd_dict b WITH(NOLOCK)" +
+            " left join" +
+            "  yp_zd_manufactory m WITH(NOLOCK) on b.manu_code = m.code" +
+            " ,yp_base c WITH(NOLOCK) " +
+            " where" +
+            "    a.draw_no= #{drawNo} and" +
+            "    a.charge_code = b.code and" +
+            "    a.serial= b.serial and" +
+            "    a.charge_code = c.charge_code and" +
+            "    a.serial= c.serial and" +
+            "    a.group_no = c.group_no and" +
+            "    (b.code like '${drugText}%' or b.name like '${drugText}%' or b.py_code like '${drugText}%' or b.d_code like '${drugText}%' ) and " +
+            "    out_type>=6 and" +
+            "    out_type<=8 order by c.location" )
+    List<YpBaseVo> selectYpInventoryData(@Param("drawNo") String drawNo, @Param("drugText") String drugText);
+
+
+    @Select("select distinct draw_no,out_date, isnull(confirm_flag,'0') as confirm_flag " +
+            " from yp_out_detl WITH(NOLOCK) " +
+            " where out_type>='6'and" +
+            "    out_type<='8'and" +
+            "    out_date >= #{beginDate} and" +
+            "    out_date <= #{endDate} and" +
+            "    group_no =#{groupNo} and" +
+            "    confirm_flag like '${confirmFlag}%'")
+    List<YpOutDetl> selectYpInventoryKfRecord(@Param("beginDate") Date beginDate, @Param("endDate") Date endDate,
+                                              @Param("groupNo") String groupNo, @Param("confirmFlag") String confirmFlag);
+
+    /**
+     * 查询药库盘点记录药品导出打印信息
+     * @param drawNo
+     * @return
+     */
+    @Select("select distinct" +
+            "  a.draw_no," +
+            "  a.group_no," +
+            "  a.out_date," +
+            "  c.location," +
+            "  rtrim(a.charge_code) as charge_code," +
+            "  a.serial," +
+            "  b.name," +
+            "  b.specification as specification," +
+            "  a.pack_retprice as pack_retprice," +
+            "  a.stock_amount," +
+            "  a.confirm_id," +
+            "  a.input_id," +
+            "  a.confirm_date," +
+            "  case when isnull(a.buy_price,0)=0 then b.buy_price else a.buy_price end as buy_price," +
+            "  a.stock_amount-a.out_amt as curr_stock_amount," +
+            "  -a.out_amt as profit_lossprofit_loss," +
+            "  -a.out_amt*a.pack_retprice as profit_lossprofit_money," +
+            "  b.py_code," +
+            "  b.drug_kind," +
+            "  k.name as kind_name," +
+            "  m.name as manufactory_name" +
+            " from yp_out_detl a WITH(NOLOCK) " +
+            " inner join yp_zd_dict b WITH(NOLOCK) on a.charge_code = b.code and a.serial= b.serial " +
+            " left join yp_zd_manufactory m WITH(NOLOCK) on b.manu_code = m.code" +
+            " inner join yp_base c WITH(NOLOCK) on a.charge_code = c.charge_code and a.serial= c.serial and a.group_no = c.group_no " +
+            " inner join yp_zd_drug_kind k WITH(NOLOCK) on b.drug_kind = k.code " +
+            " where a.draw_no= #{drawNo} " +
+            " and a.out_type between 6 and 8 " +
+            " order by b.drug_kind, c.location " )
+    List<YpBaseVo> selectYpInventoryYkPrintData(@Param("drawNo") String drawNo);
+
+    /**
+     * 查询单号是否已确认
+     * @param drawNo
+     * @return
+     */
+    @Select("select top 1 isnull(confirm_flag, 0) from yp_out_detl WITH(NOLOCK) where draw_no = #{drawNo}")
+    String selectYpOutDetlConfirmFlag(@Param("drawNo") String drawNo);
+
+    /**
+     * 查询药库盘点记录有差异的药品
+     * @param drawNo
+     * @return
+     */
+    @Select("select out_amt,stock_amount,group_no,charge_code,serial,draw_no,pack_retprice from yp_out_detl WITH(NOLOCK) where draw_no=#{drawNo} and out_amt !=0 " )
+    List<YpOutDetl> selectDifferenceData(@Param("drawNo") String drawNo);
+
+    /**
+     * 修改药房药品出库记录
+     * @param ypOutDetl
+     * @return
+     */
+    @Update("UPDATE yp_out_detl SET confirm_date = GETDATE(), confirm_flag = #{confirmFlag}, group_no_out = #{groupNo}, confirm_id = #{confirmId} WHERE draw_no = #{drawNo}")
+    int updateYpOutDetlByGroupNo(YpOutDetl ypOutDetl);
+
 }

+ 2 - 1
src/main/java/cn/hnthyy/thmz/mapper/his/yp/YpOutDetlYfMapper.java

@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
 
 import java.util.Date;
 import java.util.List;
@@ -31,7 +32,7 @@ public interface YpOutDetlYfMapper {
      * @param ypOutDetlYf
      * @return
      */
-    @Insert("UPDATE yp_out_detl_yf SET confirm_date = GETDATE(), confirm_flag = #{confirmFlag}, confirm_id = #{confirmId} WHERE draw_no = #{drawNo}")
+    @Update("UPDATE yp_out_detl_yf SET confirm_date = GETDATE(), confirm_flag = #{confirmFlag}, confirm_id = #{confirmId} WHERE draw_no = #{drawNo}")
     int updateYpOutDetlYf(YpOutDetlYf ypOutDetlYf);
 
     /**

+ 50 - 0
src/main/java/cn/hnthyy/thmz/service/his/yf/YfInventoryService.java

@@ -1,7 +1,9 @@
 package cn.hnthyy.thmz.service.his.yf;
 
 import cn.hnthyy.thmz.entity.MzException;
+import cn.hnthyy.thmz.entity.his.yp.YpOutDetl;
 import cn.hnthyy.thmz.entity.his.yp.YpOutDetlYf;
+import cn.hnthyy.thmz.vo.YpBaseVo;
 import cn.hnthyy.thmz.vo.YpBaseYfVo;
 
 import java.util.Date;
@@ -31,6 +33,14 @@ public interface YfInventoryService {
      */
     int saveYpInventoryData(List<YpOutDetlYf> ypOutDetlYfs,String userId);
 
+    /**
+     * 保存盘点药品数据
+     * @param ypOutDetlYfs
+     * @param userId
+     * @return
+     */
+    int saveYpInventoryYkData(List<YpOutDetlYf> ypOutDetlYfs,String userId);
+
     /**
      * 查询盘点记录
      * @param beginDate
@@ -48,6 +58,13 @@ public interface YfInventoryService {
      */
     List<YpBaseYfVo> queryYpInventoryPrintData(String drawNo);
 
+    /**
+     * 查询药库盘点记录药品导出打印信息
+     * @param drawNo
+     * @return
+     */
+    List<YpBaseVo> queryYpInventoryYkPrintData(String drawNo);
+
     /**
      * 审核盘点
      * @param ypOutDetlYf
@@ -55,10 +72,43 @@ public interface YfInventoryService {
      */
     int auditYpInventory(YpOutDetlYf ypOutDetlYf) throws MzException;
 
+    /**
+     * 审核药库盘点
+     * @param ypOutDetl
+     * @return
+     */
+    int auditYpInventoryYk(YpOutDetl ypOutDetl) throws MzException;
+
     /**
      * 查询单号是否已确认
      * @param drawNo
      * @return
      */
     String getYpOutDetlYfConfirmFlag(String drawNo);
+
+    /**
+     * 查询药库单号是否已确认
+     * @param drawNo
+     * @return
+     */
+    String getYpOutDetlConfirmFlag(String drawNo);
+
+    /**
+     * 生成药库盘点药品数据
+     * @param groupNo
+     * @param infusionFlag
+     * @param visibleFlag
+     * @return
+     */
+    List<YpBaseVo> queryYpInventoryKfData(String groupNo, String infusionFlag, String visibleFlag, String drugText);
+
+    /**
+     * 查询药库盘点记录
+     * @param beginDate
+     * @param endDate
+     * @param groupNo
+     * @param confirmFlag
+     * @return
+     */
+    List<YpOutDetl> queryYpInventoryKfRecord(Date beginDate, Date endDate, String groupNo, String confirmFlag);
 }

+ 108 - 3
src/main/java/cn/hnthyy/thmz/service/impl/his/yf/YfInventoryServiceImpl.java

@@ -1,15 +1,21 @@
 package cn.hnthyy.thmz.service.impl.his.yf;
 
+import cn.hnthyy.thmz.common.Constants;
 import cn.hnthyy.thmz.entity.MzException;
 import cn.hnthyy.thmz.entity.his.yp.YpConfig;
+import cn.hnthyy.thmz.entity.his.yp.YpOutDetl;
 import cn.hnthyy.thmz.entity.his.yp.YpOutDetlYf;
+import cn.hnthyy.thmz.mapper.his.yp.YpBaseMapper;
 import cn.hnthyy.thmz.mapper.his.yp.YpBaseYfMapper;
 import cn.hnthyy.thmz.mapper.his.yp.YpConfigMapper;
+import cn.hnthyy.thmz.mapper.his.yp.YpOutDetlMapper;
 import cn.hnthyy.thmz.mapper.his.yp.YpOutDetlYfMapper;
 import cn.hnthyy.thmz.service.his.yf.YfInventoryService;
+import cn.hnthyy.thmz.vo.YpBaseVo;
 import cn.hnthyy.thmz.vo.YpBaseYfVo;
 import cn.hutool.core.convert.Convert;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Isolation;
@@ -38,6 +44,12 @@ public class YfInventoryServiceImpl implements YfInventoryService {
     @SuppressWarnings("all")
     @Autowired
     private YpConfigMapper ypConfigMapper;
+    @SuppressWarnings("all")
+    @Autowired
+    private YpOutDetlMapper ypOutDetlMapper;
+    @SuppressWarnings("all")
+    @Autowired
+    private YpBaseMapper ypBaseMapper;
 
     @Override
     public List<YpBaseYfVo> queryYpInventoryData(String groupNo,String infusionFlag,String visibleFlag,String drugText) {
@@ -63,14 +75,14 @@ public class YfInventoryServiceImpl implements YfInventoryService {
             YpConfig ypConfig=ypConfigMapper.selectYpConfig();
             ypConfig.setYfOutNo(ypConfig.getYfOutNo()+1);
             SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
-            if(ypConfig.getYfOutNo() < 1000){
+            if(ypConfig.getYfOutNo() < 1000 && ypConfig.getYfOutNo() >= 100){
                 yfOutNo = "P"+sdf.format(new Date())+"0"+ypConfig.getYfOutNo();
-            }else if(ypConfig.getYfOutNo() < 100){
+            }else if(ypConfig.getYfOutNo() < 100 && ypConfig.getYfOutNo() >= 10){
                 yfOutNo = "P"+sdf.format(new Date())+"00"+ypConfig.getYfOutNo();
             }else if(ypConfig.getYfOutNo() < 10){
                 yfOutNo = "P"+sdf.format(new Date())+"000"+ypConfig.getYfOutNo();
             }else{
-                yfOutNo = "P"+ypConfig.getYfOutNo()+"";
+                yfOutNo = "P"+ypConfig.getYfOutNo();
             }
             ypConfigMapper.updateYpConfig(ypConfig);
         }
@@ -102,6 +114,57 @@ public class YfInventoryServiceImpl implements YfInventoryService {
         return 0;
     }
 
+    @Override
+    public int saveYpInventoryYkData(List<YpOutDetlYf> ypOutDetlYfs, String userId) {
+        String yfOutNo;
+        if(StringUtils.isNotBlank(ypOutDetlYfs.get(0).getDrawNo())){//删除原有盘点数据
+            yfOutNo = ypOutDetlYfs.get(0).getDrawNo();
+            ypOutDetlMapper.deleteYpOutDetlByDrawNo(yfOutNo);
+        }else{
+            YpConfig ypConfig=ypConfigMapper.selectYpConfig();
+            ypConfig.setYfOutNo(ypConfig.getYfOutNo()+1);
+            SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
+            if(ypConfig.getYfOutNo() < 1000 && ypConfig.getYfOutNo() >= 100){
+                yfOutNo = "P"+sdf.format(new Date())+"0"+ypConfig.getYfOutNo();
+            }else if(ypConfig.getYfOutNo() < 100 && ypConfig.getYfOutNo() >= 10){
+                yfOutNo = "P"+sdf.format(new Date())+"00"+ypConfig.getYfOutNo();
+            }else if(ypConfig.getYfOutNo() < 10){
+                yfOutNo = "P"+sdf.format(new Date())+"000"+ypConfig.getYfOutNo();
+            }else{
+                yfOutNo = "P"+ypConfig.getYfOutNo();
+            }
+            ypConfigMapper.updateYpConfig(ypConfig);
+        }
+        Date date = new Date();
+        for (int i = 0; i < ypOutDetlYfs.size(); i++) {
+            YpOutDetlYf ypOutDetlYf = ypOutDetlYfs.get(i);
+            YpOutDetl ypOutDetl = new YpOutDetl();
+            BeanUtils.copyProperties(ypOutDetlYf, ypOutDetl);
+            ypOutDetl.setOutDate(date);
+            ypOutDetl.setOutSeri(i+1);
+            ypOutDetl.setInSeri(0);
+            ypOutDetl.setDrawNo(yfOutNo);
+
+            // 处理提交盘点报错
+            String code = ypOutDetlYf.getChargeCode()  == null ? "" : ypOutDetlYf.getChargeCode().replace("&nbsp;","");
+            ypOutDetl.setChargeCode(code);
+
+            if(ypOutDetlYf.getGroupNo().equals(Constants.XYK_GROUP_NO)){
+                ypOutDetl.setDeptCode("2060100");
+            }else{
+                ypOutDetl.setDeptCode("2060200");
+            }
+            ypOutDetl.setOutAmt(ypOutDetl.getStockAmount()-ypOutDetl.getCurrStockAmount());
+            ypOutDetl.setDrawer(userId);
+            ypOutDetl.setKeeper(userId);
+            ypOutDetl.setOutType("8");
+            ypOutDetl.setInputId(userId);
+            ypOutDetl.setConfirmFlag("0");
+            ypOutDetlMapper.insertYpOutDetl(ypOutDetl);
+        }
+        return 0;
+    }
+
     @Override
     public List<YpOutDetlYf> queryYpInventoryRecord(Date beginDate, Date endDate, String groupNo, String confirmFlag) {
         return ypOutDetlYfMapper.selectYpInventoryRecord(beginDate, endDate, groupNo, confirmFlag);
@@ -112,6 +175,11 @@ public class YfInventoryServiceImpl implements YfInventoryService {
         return ypOutDetlYfMapper.selectYpInventoryPrintData(drawNo);
     }
 
+    @Override
+    public List<YpBaseVo> queryYpInventoryYkPrintData(String drawNo) {
+        return ypOutDetlMapper.selectYpInventoryYkPrintData(drawNo);
+    }
+
     @Override
     @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
     public int auditYpInventory(YpOutDetlYf ypOutDetlYf) throws MzException{
@@ -127,8 +195,45 @@ public class YfInventoryServiceImpl implements YfInventoryService {
         return ypOutDetlYfMapper.updateYpOutDetlYf(ypOutDetlYf);
     }
 
+    @Override
+    public int auditYpInventoryYk(YpOutDetl ypOutDetl) throws MzException {
+        List<YpOutDetl> ypOutDetls = ypOutDetlMapper.selectDifferenceData(ypOutDetl.getDrawNo());
+        for (int i = 0; i < ypOutDetls.size(); i++) {
+            YpOutDetl yp = ypOutDetls.get(i);
+            double stockAmount = yp.getStockAmount() - yp.getOutAmt();
+            if(1 != ypBaseMapper.updateStockAmountCover(yp.getChargeCode(), yp.getSerial(), yp.getGroupNo(), stockAmount,
+                    yp.getPackRetprice().multiply(BigDecimal.valueOf(stockAmount)))){
+                throw new MzException("药品编码:"+yp.getChargeCode()+"更新库存异常");
+            }
+        }
+        return ypOutDetlMapper.updateYpOutDetlByGroupNo(ypOutDetl);
+    }
+
     @Override
     public String getYpOutDetlYfConfirmFlag(String drawNo){
         return ypOutDetlYfMapper.selectYpOutDetlYfConfirmFlag(drawNo);
     }
+
+    @Override
+    public String getYpOutDetlConfirmFlag(String drawNo){
+        return ypOutDetlMapper.selectYpOutDetlConfirmFlag(drawNo);
+    }
+
+    @Override
+    public List<YpBaseVo> queryYpInventoryKfData(String groupNo, String infusionFlag, String visibleFlag, String drugText) {
+        List<YpBaseVo> ypBaseVos;
+        String drawNo = ypOutDetlMapper.selectInventoryDrawNo(groupNo);
+        drugText = Convert.toStr(drugText, "").toUpperCase();
+        if(StringUtils.isNotBlank(drawNo)){//当月已含有未审核盘点记录,查出修改
+            ypBaseVos = ypOutDetlMapper.selectYpInventoryData(drawNo, drugText);
+        }else{
+            ypBaseVos = ypBaseMapper.selectYpInventoryData(groupNo, infusionFlag, visibleFlag, drugText);
+        }
+        return ypBaseVos;
+    }
+
+    @Override
+    public List<YpOutDetl> queryYpInventoryKfRecord(Date beginDate, Date endDate, String groupNo, String confirmFlag) {
+        return ypOutDetlMapper.selectYpInventoryKfRecord(beginDate, endDate, groupNo, confirmFlag);
+    }
 }

+ 25 - 0
src/main/java/cn/hnthyy/thmz/vo/YpBaseVo.java

@@ -4,6 +4,7 @@ package cn.hnthyy.thmz.vo;
 import lombok.Data;
 
 import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * 药库库存
@@ -81,5 +82,29 @@ public class YpBaseVo {
   private String ybComment;
   private String hzylFlag;
 
+  //药品名称
+  private String name;
+  //厂家名称
+  private String manufactoryName;
+  //实盘数量
+  private Double currStockAmount;
+  //盈亏数量
+  private Double profitLossprofitLoss;
+  //盈亏金额
+  private BigDecimal profitLossprofitMoney;
+  //盘点单号
+  private String drawNo;
+  //盘点时间
+  private Date outDate;
+  //购入价
+  private BigDecimal buyPrice;
+  //审核日期(盘点用)
+  private Date confirmDate;
+  //类型名称
+  private String kindName;
+  //输入人ID
+  private String inputId;
+  //审核人ID
+  private String confirmId;
 
 }

+ 11 - 3
src/main/resources/static/js/yf/yf_inventory.js

@@ -1,12 +1,12 @@
 //@ sourceURL=yf_inventory.js
 var LODOP; //声明为全局变量
-var pharmacyGroupNo = window.localStorage["groupNo"];//药房编码
+var pharmacyGroupNo = isEmpty(window.localStorage["groupYk"])?window.localStorage["groupNo"]:window.localStorage["groupYk"];//药房or药库编码
 var lastrow;//最后编辑单元格的行
 var lastcell;//最后编辑单元格的列
 $(function () {
     init_daterangepicker();
     if(pharmacyGroupNo == null){
-        return errorMesageSimaple('药房参数未设置,请在发药参数设置中设置');
+        return errorMesageSimaple('药库或者药房参数未设置,请在发药参数设置中设置');
     }
     initTbAdd();
     $("#btn_query").click(function (t) {
@@ -160,10 +160,16 @@ function saveTbTable() {
     if (!confirm("为避免药品筛选导致药品不全,请检查表格筛选行是否已清空并重新刷新表格!是否已确认?")) {
         return;
     }
+    let urlStr
+    if("11" === pharmacyGroupNo ){
+        urlStr = '/thmz/saveYpInventoryYkData';
+    } else {
+        urlStr = '/thmz/saveYpInventoryData';
+    }
     $("#btn_save").attr("disabled",true);
     $.ajax({
         type: "POST",
-        url: '/thmz/saveYpInventoryData',
+        url: urlStr,
         contentType: "application/json;charset=UTF-8",
         dataType: "json",
         headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
@@ -352,6 +358,7 @@ function getTbAddRecordPrintData(drawNo) {
         dataType: "json",
         headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
         data: {
+            groupNo: pharmacyGroupNo,
             drawNo:drawNo
         },
         success: function (res) {
@@ -513,6 +520,7 @@ function audit(){
         dataType: "json",
         headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
         data: {
+            groupNo: pharmacyGroupNo,
             drawNo:drawNo
         },
         success: function (res) {