Browse Source

优化代码修复bug

xiaochan 2 years ago
parent
commit
aecd990f4f

+ 10 - 1
src/main/java/thyyxxk/webserver/dao/his/zhuyuanyisheng/CaoYaoYiZhuDao.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
 import org.apache.ibatis.annotations.*;
 import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
+import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
 import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzActOrderCy;
 import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzActOrderCyDetail;
 import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzOrderPatternCy;
@@ -160,7 +161,7 @@ public interface CaoYaoYiZhuDao {
             "values (#{cy.inpatientNo}, #{cy.admissTimes}, #{cy.orderNo}, '1', #{cy.orderName}, " +
             "        cast(#{cy.orderJe,jdbcType=DECIMAL} as decimal(10,2)), " +
             "        cast(#{cy.orderJeDj,jdbcType=DECIMAL} as decimal(10,2)), #{cy.quantity}, #{cy.quantityDj}, " +
-            "        (select charge_code_zydj from yz_sequence), #{cy.inputId}, #{cy.inputId}, getdate(), #{cy.pageNo}, '3', " +
+            "        (select charge_code_zydj from yz_sequence), #{cy.inputId}, #{cy.inputId}, getdate(), #{cy.pageNo}, '2', " +
             "        #{deptCode}, " +
             "        #{wardCode}, #{cy.cyMtjs}, #{cy.cyJsl}, #{cy.cyZql}, #{cy.cyFj}, " +
             "        #{cy.cyFfcs}, #{cy.cyFysm}, #{cy.cyJssm}, #{execDept}, #{cy.groupNo}, 1)")
@@ -227,4 +228,12 @@ public interface CaoYaoYiZhuDao {
     void shanChuYiZhu(@Param("orderNo") BigDecimal orderNo);
 
 
+    @Select("select * from zy_detail_charge where inpatient_no = #{cy.inpatientNo} and admiss_times = #{cy.admissTimes} and order_no = #{cy.orderNo} and charge_fee > 0")
+    List<ZyDetailCharge> caoYaoFeiYong(@Param("cy") YzActOrderCy cy);
+
+
+    @Update("update zy_detail_charge " +
+            "set ori_detail_sn = -1 where inpatient_no = #{cy.inpatientNo} and admiss_times = #{cy.admissTimes} and order_no = #{cy.orderNo} and ori_detail_sn is null ")
+    void modifyTheExpenseFlag(@Param("cy") YzActOrderCy cy);
+
 }

+ 39 - 8
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/CaoYaoYiZhuService.java

@@ -6,14 +6,17 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.ListUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.constants.GetDateFormat;
+import thyyxxk.webserver.dao.his.inpatient.XiangMuLuRuDao;
 import thyyxxk.webserver.dao.his.zhuyuanyisheng.CaoYaoYiZhuDao;
 import thyyxxk.webserver.dao.his.zhuyuanyisheng.YiZhuLuRuDao;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
+import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
 import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.CaoYaoChaXunTiaoJian;
 import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzActOrderCy;
 import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzActOrderCyDetail;
@@ -43,12 +46,14 @@ public class CaoYaoYiZhuService {
     private final PublicServer publicServer;
     private final YiZhuLuRuDao yiZhuLuRuDao;
     private final YiZhuLuRuServer yiZhuLuRuServer;
+    private final XiangMuLuRuDao xiangMuLuRuDao;
 
-    public CaoYaoYiZhuService(CaoYaoYiZhuDao dao, PublicServer publicServer, YiZhuLuRuDao yiZhuLuRuDao, YiZhuLuRuServer yiZhuLuRuServer) {
+    public CaoYaoYiZhuService(CaoYaoYiZhuDao dao, PublicServer publicServer, YiZhuLuRuDao yiZhuLuRuDao, YiZhuLuRuServer yiZhuLuRuServer, XiangMuLuRuDao xiangMuLuRuDao) {
         this.dao = dao;
         this.publicServer = publicServer;
         this.yiZhuLuRuDao = yiZhuLuRuDao;
         this.yiZhuLuRuServer = yiZhuLuRuServer;
+        this.xiangMuLuRuDao = xiangMuLuRuDao;
     }
 
     private CaoYaoYiZhuService getThis() {
@@ -241,15 +246,15 @@ public class CaoYaoYiZhuService {
      */
     public ResultVo<String> shanChuMuBan(String name, String deptCode) {
         YzOrderPatternCy mb = dao.caoYaoMuBanXiangQing(name);
-        List<Integer> rolse = publicServer.getRoleCode().getData();
         // 如果有这个权限直接删除
-        if (publicServer.noNeedRule(rolse, YiZhuPublicService.MU_BAN_BIAN_JI_QUAN_XIAN)) {
+
+        if (publicServer.needRule(YiZhuPublicService.MU_BAN_BIAN_JI_QUAN_XIAN)) {
             // 本人创建的也可以直接删除
             if (mb.getCreateId().equals(TokenUtil.getTokenUserId())) {
                 return shanChuCaoYaoMuBan(name);
             }
             // 科主任 可以删除自己科室的模板
-            if (publicServer.needRule(rolse, YiZhuPublicService.KE_ZHU_REN_BIAN_MA)) {
+            if (publicServer.needRule(YiZhuPublicService.KE_ZHU_REN_BIAN_MA)) {
                 if (mb.getDeptCode().trim().equals(deptCode)) {
                     return shanChuCaoYaoMuBan(name);
                 }
@@ -265,19 +270,45 @@ public class CaoYaoYiZhuService {
         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
     }
 
+    @Transactional(rollbackFor = Exception.class)
     public ResultVo<String> shanChuCaoYao(String patNo, Integer times, BigDecimal orderNo) {
         YzActOrderCy cy = dao.caoYaoXinXi(patNo, times, orderNo);
         if (cy == null) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有查询到原来的信息。");
         }
-        if (!"2".equals(cy.getStatusFlag().trim())) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该草药无法删除。");
-        }
-
         log.info("删除草药==》操作人:{},数据:{}", TokenUtil.getTokenUserId(), JSON.toJSONStringWithDateFormat(cy, GetDateFormat.DATE_TIME));
         dao.genXingCaoYaoShanChuBiaoZhi(patNo, times, orderNo);
         dao.shanChuYiZhu(orderNo);
+        feeRefunds(cy);
         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
     }
 
+    /**
+     * 草药退费
+     *
+     * @param cy 草药信息
+     */
+    private void feeRefunds(YzActOrderCy cy) {
+        List<ZyDetailCharge> cyList = dao.caoYaoFeiYong(cy);
+        int maxDetailSn = publicServer.getMaxDetailSn(cy.getInpatientNo(), cy.getAdmissTimes());
+        String userCode = TokenUtil.getTokenUserId();
+        if (ListUtil.notBlank(cyList)) {
+            List<ZyDetailCharge> refundArray = new ArrayList<>(cyList.size());
+            for (ZyDetailCharge item : cyList) {
+                item.setChargeFee(item.getChargeFee().negate());
+                item.setChargeAmount(item.getChargeAmount().negate());
+                item.setOpIdCode(userCode);
+                item.setOriDetailSn(item.getDetailSn());
+                // 设置 流水号
+                item.setDetailSn(maxDetailSn += 1);
+                item.setOrderNo(new BigDecimal(0));
+                item.setNewOrderNo(new BigDecimal(0));
+                refundArray.add(item);
+            }
+            List<List<ZyDetailCharge>> fenGe = ListUtils.partition(refundArray, 20);
+            fenGe.forEach(xiangMuLuRuDao::xiangMuTuiFei);
+            dao.modifyTheExpenseFlag(cy);
+        }
+    }
+
 }

+ 1 - 1
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/YiZhuLuRuServer.java

@@ -299,7 +299,7 @@ public class YiZhuLuRuServer {
 
         Repel repel = checkData.getRepel();
 
-        if (repel != null) {
+        if (repel != null && repel.getCount() > 0) {
             int count = dao.thereAreUnexecutedOrders(param.getInpatientNo(), param.getAdmissTimes(), repel.getOrderNo());
             if (count > 0) {
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "有未确认和未执行的长期医嘱,无法确认全排斥医嘱,请先确认其他医嘱。");

+ 4 - 1
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/emr/EmrServer.java

@@ -827,7 +827,10 @@ public class EmrServer {
             }
             return false;
         });
-        EmrWebSocketServiceV2.close(documentId);
+        if (StringUtil.notBlank(documentId)) {
+            EmrWebSocketServiceV2.close(documentId);
+        }
+
         return ResultVoUtil.success();
     }