From fdc1034997607adbe8da9939c45bd48c3cb03b98 Mon Sep 17 00:00:00 2001
From: eight <641137800@qq.com>
Date: 星期二, 08 四月 2025 23:09:13 +0800
Subject: [PATCH] refactor - rename

---
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/devrent/DevRentServiceImpl.java |  137 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 125 insertions(+), 12 deletions(-)

diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/devrent/DevRentServiceImpl.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/devrent/DevRentServiceImpl.java
index f1ddcc6..f43f465 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/devrent/DevRentServiceImpl.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/devrent/DevRentServiceImpl.java
@@ -6,14 +6,18 @@
 import cn.lihu.jh.module.ecg.dal.dataobject.checktype.CheckTypeDO;
 import cn.lihu.jh.module.ecg.dal.dataobject.devmanage.DeviceDO;
 import cn.lihu.jh.module.ecg.dal.dataobject.jobrecord.JobRecordDO;
+import cn.lihu.jh.module.ecg.dal.dataobject.patient.PatDetails;
 import cn.lihu.jh.module.ecg.dal.dataobject.queue.QueueDO;
+import cn.lihu.jh.module.ecg.dal.mysql.checktype.CheckTypeMapper;
 import cn.lihu.jh.module.ecg.dal.mysql.devmanage.DeviceMapper;
 import cn.lihu.jh.module.ecg.dal.mysql.jobrecord.JobRecordMapper;
 import cn.lihu.jh.module.ecg.dal.mysql.queue.QueueMapper;
 import cn.lihu.jh.module.ecg.enums.DevRentStateEnum;
 import cn.lihu.jh.module.ecg.enums.DevStateEnum;
 import cn.lihu.jh.module.ecg.enums.QueueStatusEnum;
+import cn.lihu.jh.module.ecg.feign.*;
 import cn.lihu.jh.module.ecg.service.queue.QueueServiceTxFunctions;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.transaction.annotation.Transactional;
@@ -33,6 +37,7 @@
 import javax.annotation.Resource;
 
 import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.lihu.jh.framework.common.util.date.DateUtils.getCurTimeString;
 import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
 
 /**
@@ -42,10 +47,14 @@
  */
 @Service
 @Validated
+@Slf4j
 public class DevRentServiceImpl implements DevRentService {
 
     @Resource
     QueueServiceTxFunctions queueServiceTxFunctions;
+
+    @Resource
+    private FeeConfirmFeignService feeConfirmFeignService;
 
     @Resource
     private DevRentMapper devRentMapper;
@@ -58,6 +67,9 @@
 
     @Resource
     QueueMapper queueMapper;
+
+    @Resource
+    CheckTypeMapper checkTypeMapper;
 
     @Override
     public CommonResult<Long> registerOperation(DevRentSaveReqVO createReqVO) {
@@ -72,8 +84,9 @@
 
         Long userId = SecurityFrameworkUtils.getLoginUserId();
         String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
+        String userHisId = SecurityFrameworkUtils.getLoginUserHisId();
 
-        // 鍚屾牱 鍦ㄩ绾︾‘瀹炴椂 灏辫繘鍏� [dev_rent] 琛ㄤ簡
+        // 鍦ㄩ绾︾‘璁ゆ椂 灏辫繘鍏� [dev_rent] 琛ㄤ簡
         Long rent_id = createReqVO.getId();
 
         List<Integer> jobTypeList = new ArrayList<Integer>();
@@ -152,10 +165,12 @@
     public CommonResult<Long> readyOperation(DevRentSaveReqVO createReqVO) {
         Long userId = SecurityFrameworkUtils.getLoginUserId();
         String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
+
+        // 鍦ㄩ绾︾‘璁ゆ椂 灏辫繘鍏� [dev_rent] 琛ㄤ簡
         Long rent_id = createReqVO.getId();  // dev_rent 琛ㄧ殑ID
 
         // 鏍囨敞璁惧 宸查鍙�
-        Integer ret = markDevRecieved(createReqVO.getDevId(), rent_id);
+        Integer ret = markDevRecieved(createReqVO.getDevId(), rent_id, createReqVO.getPatDetails());
         if (null == ret || 0 == ret) {
             throw exception(DEVICE_NOT_FREE);
         }
@@ -233,10 +248,11 @@
         String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
         Long rent_id = createReqVO.getId();
 
-        // 瀵逛簬宸叉湁棰嗙敤锛屼絾鏄鏈烘椂浣跨敤鐨勪笉鏄凡棰嗙敤璁惧锛岄渶閲婃斁 婧愰鐢� 璁惧
         DevRentDO devRentDO = getDevRent(rent_id);
+
+        // 瀵逛簬宸叉湁棰嗙敤锛屼絾鏄鏈烘椂浣跨敤鐨勪笉鏄凡棰嗙敤璁惧锛屾姤閿�
         if ( null != devRentDO.getDevId() && !createReqVO.getDevId().equals(devRentDO.getDevId()) ) {
-            markDevFree( devRentDO.getDevId(), rent_id);
+            throw exception(DEVICE_NOT_PAT_RECEIVED);
         }
 
         // 璁剧疆璁惧 浣跨敤涓�
@@ -705,14 +721,58 @@
         return devRentMapper.getRentByState(searchReqVO);
     }
 
+    // 纭垂澶勭悊
+    // 杩斿洖鍊�:  0 鎴愬姛  1 澶辫触  2 涓嶇敤纭垂
+    @Override
+    public Integer feeConfirm(Long rentId, String hisId, String userNickname, Boolean isFeeConfirmOrCancel) {
+        DevRentDO devRentDO = devRentMapper.selectById(rentId);
+
+        // 鏌ヨ妫�鏌ョ被鍨嬶紝纭畾鏄惁闇�瑕佺‘璐�
+        CheckTypeDO checkTypeDO = checkTypeMapper.getCheckTypeByValue(devRentDO.getCheckType());
+        if (0 == checkTypeDO.getExpenseRecognition()) {
+            return 2;
+        }
+
+        PatDetails patDetails = devRentDO.getPatDetails();
+        HisFeeConfirmReqBody hisFeeConfirmReqBody = new HisFeeConfirmReqBody();
+        MsgHeader msgHeader = new MsgHeader();
+        msgHeader.setMsgType("ODS_2212");
+        msgHeader.setMsgVersion("3.0");
+        msgHeader.setSender("ECG");
+        hisFeeConfirmReqBody.setMsgHeader(msgHeader);
+        Item item = new Item();
+        item.setItemCode( getHisCheckCode(devRentDO.getCheckType()) ); //
+        item.setItemStatus( isFeeConfirmOrCancel? "5" : "6" ); // 5 纭垂 6 鍙栨秷纭垂
+        item.setExeOrganization("47162057-2");
+        item.setExeDeptName("蹇冪數绉�");
+        item.setExeDept("蹇冪數绉�");
+        item.setExeDoctor( hisId ); //
+        item.setExeDoctorName( userNickname ); //
+        item.setExeDateTime( getCurTimeString() ); //
+        ExmRequest exmRequest = new ExmRequest();
+        exmRequest.setAuthorOrganization("47162057-2");
+        exmRequest.setRequestId( devRentDO.getApplyNo() );  //
+        exmRequest.setPatientType( getPatientType(patDetails.getSource()) ); //
+        exmRequest.setItem(item);
+        hisFeeConfirmReqBody.setExmRequest(exmRequest);
+        HisFeeConfirmRespResult result = feeConfirmFeignService.httpFeeApi("UpdateExmRequestStatus", "ECG", "ECG", hisFeeConfirmReqBody);
+        log.info( result.getMsgHeader().getStatus() );
+        Integer returnValue = result.getMsgHeader().getStatus().equals("true") ? 0 : 1;
+        if (0 == returnValue) {
+            devRentMapper.setPaid(rentId, isFeeConfirmOrCancel ? 1 : 0);
+        }
+        return returnValue;  // 0 鎴愬姛  1 澶辫触  2 涓嶇敤纭垂
+    }
+
     // 鏍囪 璁惧宸茶棰嗗彇
-    private Integer markDevRecieved(String devId, Long rentId) {
+    private Integer markDevRecieved(String devId, Long rentId, PatDetails patDetails) {
         // 璁惧鏍囨敞 宸查鍙�
         DeviceDO deviceDO = deviceMapper.getDeviceByDevId(devId);
         if (null != deviceDO && DevStateEnum.FREE.isEqual(deviceDO.getState())) {
             deviceDO.setState( DevStateEnum.RECEIVED.getState() );
             deviceDO.setRentId( rentId );
             deviceDO.setStateDate( LocalDate.now() );
+            deviceDO.setPatDetails( patDetails );
             return deviceMapper.updateById(deviceDO);
         }
 
@@ -760,6 +820,7 @@
             deviceDO.setState( DevStateEnum.FREE.getState() );
             deviceDO.setStateDate( LocalDate.now() );
             deviceDO.setRentId(null);
+            deviceDO.setPatDetails(null);
             return deviceMapper.updateById(deviceDO);
         }
         
@@ -769,7 +830,7 @@
     private void procAffinityWhenRoutineFinish(String patId, Integer[] affinityCheckTypes) {
         // 濡傛灉瀛樺湪 [浜插拰-鎺掗槦] 浜插拰椤癸紝鍒欓�夋嫨 鍏朵腑涓�涓翰鍜岄」 鎺ユ浛鍏� 澶勪簬 [灏辫瘖涓璢
         List<QueueDO> affinityAffinityWaitingItems = queueMapper.getCurPatGivenCheckTypesAndStatus(
-                                patId, affinityCheckTypes, QueueStatusEnum.AFFINITY_WAITING.getStatus());
+                                patId, affinityCheckTypes, QueueStatusEnum.AFFINITY.getStatus());
         if (!affinityAffinityWaitingItems.isEmpty()) {
             QueueDO tmpQueueDO = affinityAffinityWaitingItems.get(0);
             tmpQueueDO.setStatus(QueueStatusEnum.ONSTAGE.getStatus());
@@ -777,20 +838,25 @@
         }
     }
 
+    /**
+     * 棰嗙敤瀹屾垚锛屼富鍔ㄥ姹備緷闄�
+     */
     private void procAffinityWhenReadyFinish(/*IN,OUT*/QueueDO bedOnStageQueueItem, Integer[] affinityCheckTypes) {
-        // 濡傛灉瀛樺湪 [瀹夎涓璢 浜插拰椤癸紝鍒欒窡闅忓叾涓竴涓翰鍜岄」
-        List<QueueDO> affinityInstallingItems = queueMapper.getCurPatGivenCheckTypesAndStatus(
-                bedOnStageQueueItem.getPatId(), affinityCheckTypes, QueueStatusEnum.INSTALLING.getStatus());
+        // 濡傛灉瀛樺湪 [瀹夎涓璢 [瀹夎杩囧彿] [瀹夎鍙洖] 鑳借渚濋檮鐨勬鏌ラ」锛屽垯渚濋檮鍒板叾涓竴涓鏌ラ」
+        List<QueueDO> affinityInstallingItems = queueMapper.getCurPatGivenCheckTypesAndStatusList(
+                bedOnStageQueueItem.getPatId(), affinityCheckTypes,
+                List.of(QueueStatusEnum.INSTALLING.getStatus(), QueueStatusEnum.PASSED_INSTALL.getStatus(),
+                        QueueStatusEnum.RECALLED_INSTALL.getStatus()));
         if (!affinityInstallingItems.isEmpty()) {
             QueueDO affinityInstallingItem = affinityInstallingItems.get(0);
-            bedOnStageQueueItem.setStatus(QueueStatusEnum.AFFINITY_RECEIVED.getStatus()); // 浜插拰-棰嗙敤
+            bedOnStageQueueItem.setStatus(QueueStatusEnum.AFFINITY_INSTALL.getStatus()); // 浜插拰-棰嗙敤
             bedOnStageQueueItem.setRoomId( affinityInstallingItem.getRoomId() );
             bedOnStageQueueItem.setBedNo( affinityInstallingItem.getBedNo() );  // 棰嗙敤 鍒� 瀹夎 鍙兘浼氬湪涓嶅悓宸ヤ綅
         }
 
         // 濡傛灉瀛樺湪 [浜插拰-鎺掗槦] 浜插拰椤癸紝鍒欓�夋嫨 鍏朵腑涓�涓翰鍜岄」 鎺ユ浛鍏� 澶勪簬 [灏辫瘖涓璢
         List<QueueDO> affinityAffinityWaitingItems = queueMapper.getCurPatGivenCheckTypesAndStatus(
-                bedOnStageQueueItem.getPatId(), affinityCheckTypes, QueueStatusEnum.AFFINITY_WAITING.getStatus());
+                bedOnStageQueueItem.getPatId(), affinityCheckTypes, QueueStatusEnum.AFFINITY.getStatus());
         if (!affinityAffinityWaitingItems.isEmpty()) {
             QueueDO tmpQueueDO = affinityAffinityWaitingItems.get(0);
             tmpQueueDO.setStatus(QueueStatusEnum.ONSTAGE.getStatus());
@@ -798,9 +864,10 @@
         }
     }
 
+    // 濡傛灉瀛樺湪 [浜插拰-棰嗙敤] 浜插拰椤癸紝鍒欓�夋嫨 鍏朵腑涓�涓翰鍜岄」 鎺ユ浛鍏� 澶勪簬 [瀹夎涓璢
     private void procAffinityWhenInstallFinish(QueueDO bedInstallingQueueItem, Integer[] affinityCheckTypes) {
         List<QueueDO> affinityAffinityReceivedItems = queueMapper.getCurPatGivenCheckTypesAndStatus(
-                bedInstallingQueueItem.getPatId(), affinityCheckTypes, QueueStatusEnum.AFFINITY_RECEIVED.getStatus());
+                bedInstallingQueueItem.getPatId(), affinityCheckTypes, QueueStatusEnum.AFFINITY_INSTALL.getStatus());
         if (!affinityAffinityReceivedItems.isEmpty()) {
             QueueDO tmpQueueDO = affinityAffinityReceivedItems.get(0);
             tmpQueueDO.setStatus(QueueStatusEnum.INSTALLING.getStatus());
@@ -810,5 +877,51 @@
         }
     }
 
+    private String getHisCheckCode(Integer checkType) {
+        if (100 == checkType)
+            return "691133607";
+        else if (200 == checkType)
+            return "201605";
+        else if (300 == checkType)
+            return "200327";
+        else if (400 == checkType)
+            return "201652";
+        else if (500 == checkType)
+            return "502490914";
+        else if (600 == checkType)
+            return "419562119";
+        else if (700 == checkType)
+            return "201604";
+        else if (800 == checkType)
+            return "1202042";
+        else if (900 == checkType)
+            return "1202058";
+        else if (1000 == checkType)
+            return "1202065";
+        else if (1100 == checkType)
+            return "559542128";
+        else if (1200 == checkType)
+            return "590244511";
+        else if (1300 == checkType)
+            return "666454217";
+        else if (1400 == checkType)
+            return "720791490";
+        else if (1500 == checkType)
+            return "720792077";
+
+        return "691133607";
+    }
+
+    String getPatientType( Integer patientSource ) {
+        if (1 == patientSource || 2 == patientSource)
+            return "01";
+        else if (3 == patientSource)
+            return "03";
+        else if (4 == patientSource)
+            return "04";
+
+        return "01";
+    }
+
 }
 

--
Gitblit v1.9.3