From 784c60d5baad7edceab2f1668ed9116e5b5e5e89 Mon Sep 17 00:00:00 2001
From: eight <641137800@qq.com>
Date: 星期四, 31 十月 2024 16:22:50 +0800
Subject: [PATCH] update

---
 jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/DevRentStateEnum.java                             |    3 +
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/devrent/DevRentMapper.java                    |   19 +++++++++
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/AppointmentController.java |   34 ++++++----------
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentService.java             |   16 +++++--
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/devrent/DevRentServiceImpl.java                 |   16 +++++--
 jh-module-ecg/jh-module-ecg-biz/src/main/resources/mapper/devrent/DevRentMapper.xml                                         |   20 ----------
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java         |    8 +++
 7 files changed, 63 insertions(+), 53 deletions(-)

diff --git a/jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/DevRentStateEnum.java b/jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/DevRentStateEnum.java
index 93ffab2..d240527 100644
--- a/jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/DevRentStateEnum.java
+++ b/jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/DevRentStateEnum.java
@@ -8,7 +8,7 @@
 import java.util.Arrays;
 
 /**
- * 閫氱敤鐘舵�佹灇涓�
+ * 妫�鏌ョ姸鎬佹灇涓�
  *
  * @author 鑺嬮亾婧愮爜
  */
@@ -23,6 +23,7 @@
     READY_CANCELLED(30, "棰嗙敤鏀惧純"),
     INSTALL_CANCELLED(35, "瀹夎鏀惧純"),
     LOST(40, "宸查仐澶�"),
+    DAMAGED(42, "宸叉崯姣�"),
     ROUTINE_CANCELLED(50, "甯歌妫�鏌ユ斁寮�"),
     ROUTINE_FINISH( 60, "甯歌妫�鏌ュ畬鎴�");
 
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/AppointmentController.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/AppointmentController.java
index b496554..012c5e6 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/AppointmentController.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/AppointmentController.java
@@ -1,20 +1,9 @@
 package cn.lihu.jh.module.ecg.controller.admin.appointment;
 
-import cn.hutool.core.bean.BeanUtil;
-import cn.lihu.jh.framework.common.exception.ErrorCode;
-import cn.lihu.jh.framework.common.util.date.DateUtils;
-import cn.lihu.jh.module.ecg.controller.admin.devrent.vo.DevRentSaveReqVO;
-import cn.lihu.jh.module.ecg.controller.admin.queue.vo.QueueSaveReqVO;
-import cn.lihu.jh.module.ecg.enums.QueueStatusEnum;
-import cn.lihu.jh.module.ecg.feign.RemoteDataService;
-import cn.lihu.jh.module.ecg.feign.RestApiReqBodyVo;
-import cn.lihu.jh.module.ecg.feign.RestApiResult;
-import cn.lihu.jh.module.ecg.feign.dto.AppointmentExternal;
 import cn.lihu.jh.module.ecg.service.devrent.DevRentService;
 import cn.lihu.jh.module.ecg.service.queue.QueueService;
 import cn.lihu.jh.module.ecg.service.room.RoomService;
 import cn.lihu.jh.module.system.api.dept.DeptApi;
-import org.springframework.dao.DuplicateKeyException;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -22,12 +11,8 @@
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.Operation;
 
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.time.format.DateTimeFormatterBuilder;
 import java.util.*;
 import java.io.IOException;
-import java.util.stream.Collectors;
 
 import cn.lihu.jh.framework.common.pojo.PageParam;
 import cn.lihu.jh.framework.common.pojo.PageResult;
@@ -42,8 +27,6 @@
 import cn.lihu.jh.framework.apilog.core.annotation.ApiAccessLog;
 import static cn.lihu.jh.framework.apilog.core.enums.OperateTypeEnum.*;
 import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
-import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
-import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME;
 
 import cn.lihu.jh.module.ecg.controller.admin.appointment.vo.*;
 import cn.lihu.jh.module.ecg.dal.dataobject.appointment.AppointmentDO;
@@ -107,12 +90,21 @@
         return success(BeanUtils.toBean(appointment, AppointmentRespVO.class));
     }
 
-    @GetMapping("/get-by-patient")
-    @Operation(summary = "鏍规嵁鎮h�呯紪鍙�.鑾峰緱棰勭害")
+    @GetMapping("/get-current-by-patient")
+    @Operation(summary = "鏍规嵁鎮h�呯紪鍙�.鏌ヨ褰撳ぉ棰勭害")
     @Parameter(name = "id", description = "缂栧彿", required = true, example = "1024")
     @PreAuthorize("@ss.hasPermission('ecg:appointment:query')")
-    public CommonResult<AppointmentRespVO> getAppointmentByPatient(@RequestParam("patId") String patId) {
-        AppointmentDO appointment = appointmentService.getAppointmentByPatId( patId );
+    public CommonResult<AppointmentRespVO> getCurAppointmentByPatId(@RequestParam("patId") String patId) {
+        AppointmentDO appointment = appointmentService.getCurAppointmentByPatId( patId );
+        return success(BeanUtils.toBean(appointment, AppointmentRespVO.class));
+    }
+
+    @GetMapping("/query-and-create-by-patient")
+    @Operation(summary = "鏍规嵁鎮h�呯紪鍙�.鑾峰緱棰勭害.骞跺唴閮ㄥ垱寤洪绾�")
+    @Parameter(name = "id", description = "缂栧彿", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('ecg:appointment:query')")
+    public CommonResult<AppointmentRespVO> queryAndCreateAppointmentByPatId(@RequestParam("patId") String patId) {
+        AppointmentDO appointment = appointmentService.queryAndCreateAppointmentByPatId( patId );
         return success(BeanUtils.toBean(appointment, AppointmentRespVO.class));
     }
 
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/devrent/DevRentMapper.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/devrent/DevRentMapper.java
index 854f2c3..cbe70ec 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/devrent/DevRentMapper.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/devrent/DevRentMapper.java
@@ -36,6 +36,25 @@
                 .orderByDesc(DevRentDO::getId));
     }
 
+    @Select("<script> " +
+            "SELECT * FROM lihu.dev_rent " +
+            "<where> " +
+            "  <if test='stateList != null'> " +
+            "    and state in ( " +
+            "      <foreach collection='stateList' separator=',' item='state'> " +
+            "        #{state} " +
+            "      </foreach> ) " +
+            "  </if> " +
+            "  <if test=\"devId != null and devId != ''\"> " +
+            "    and dev_id = #{devId} " +
+            "  </if> " +
+            "  <if test=\"patId != null and patId != ''\"> " +
+            "    and pat_id = #{patId} " +
+            "  </if> " +
+            "</where> " +
+            "order by create_time desc " +
+            "limit 1 " +
+            "</script>")
     DevRentDO getRentByState(DevRentSearchReqVO reqVO );
 
     @Select("select * from lihu.dev_rent where state=#{state} and pat_id=#{patId} and to_days(create_time)=to_days(now())")
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentService.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentService.java
index 24c35fc..279bfe1 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentService.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentService.java
@@ -3,8 +3,6 @@
 import cn.lihu.jh.module.ecg.controller.admin.appointment.vo.*;
 import cn.lihu.jh.module.ecg.dal.dataobject.appointment.AppointmentDO;
 import cn.lihu.jh.framework.common.pojo.PageResult;
-import cn.lihu.jh.framework.common.pojo.PageParam;
-import cn.lihu.jh.module.ecg.feign.dto.AppointmentExternal;
 
 import javax.validation.Valid;
 
@@ -46,12 +44,20 @@
     AppointmentDO getAppointment(Long id);
 
     /**
-     * 鑾峰緱棰勭害
+     * 鑾峰緱褰撳ぉ鐨勯绾� 鏍规嵁PatID
      *
-     * @param id 缂栧彿
+     * @param patId 缂栧彿
      * @return 棰勭害
      */
-    AppointmentDO getAppointmentByPatId(String patId);
+    AppointmentDO getCurAppointmentByPatId(String patId);
+
+    /**
+     * 鑾峰緱棰勭害
+     *
+     * @param patId 缂栧彿
+     * @return 棰勭害
+     */
+    AppointmentDO queryAndCreateAppointmentByPatId(String patId);
 
     /**
      * 鑾峰緱棰勭害鍒嗛〉
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java
index 782f1a9..7ce9921 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java
@@ -95,7 +95,13 @@
     }
 
     @Override
-    public AppointmentDO getAppointmentByPatId(String patId) {
+    public AppointmentDO getCurAppointmentByPatId(String patId) {
+        AppointmentDO appointmentDO = appointmentMapper.getCurrentPatId( patId );
+        return appointmentDO;
+    }
+
+    @Override
+    public AppointmentDO queryAndCreateAppointmentByPatId(String patId) {
         // 鍏堜粠鍖婚櫌骞冲彴鏌ヨ
         AppointmentDO appointmentExtermal = getAppointmentExtermal( patId );
         if (null != appointmentExtermal && null != appointmentExtermal.getBookDate() && appointmentExtermal.getBookDate().isEqual(LocalDate.now()) ) {
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 abbdbea..4d11472 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
@@ -521,23 +521,29 @@
     @Transactional(rollbackFor = Exception.class)
     public CommonResult<Long> dismantleExceptionOperation(DevRentSaveReqVO updateReqVO) {
         DevStateEnum devStateEnum = null;
-        if (updateReqVO.getState() == DevStateEnum.DAMAGED.getState())
+        DevRentStateEnum devRentStateEnum = null;
+        if (updateReqVO.getState() == DevStateEnum.DAMAGED.getState()) {
             devStateEnum = DevStateEnum.DAMAGED;
-        else if (updateReqVO.getState() == DevStateEnum.LOST.getState())
+            devRentStateEnum = DevRentStateEnum.DAMAGED;
+        }
+        else if (updateReqVO.getState() == DevStateEnum.LOST.getState()) {
             devStateEnum = DevStateEnum.LOST;
+            devRentStateEnum = DevRentStateEnum.LOST;
+        }
         else
             throw exception(DEV_DISMANTLE_EXCEPTION);
 
         // 璁惧閬楀け鏃�, 鏍囨敞閬楀け
         markDevDismantleException( updateReqVO.getDevId(), updateReqVO.getId(), updateReqVO.getReturnTime().toLocalDate(), devStateEnum );
 
-        updateReqVO.setState( DevRentStateEnum.LOST.getState() );
+        updateReqVO.setState( devRentStateEnum.getState() );
         updateDevRent( updateReqVO );
 
         Long userId = SecurityFrameworkUtils.getLoginUserId();
         String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
 
         List<Integer> jobTypeList = new ArrayList<Integer>();
+        jobTypeList.add( DevRentStateEnum.DAMAGED.getState());
         jobTypeList.add( DevRentStateEnum.LOST.getState());
         JobRecordDO jobRecordDO = jobRecordMapper.selectByRentIdDocId(updateReqVO.getId(), userId, jobTypeList);
         if (null == jobRecordDO) {
@@ -549,13 +555,13 @@
             jobRecordSaveReqVO.setPatId( updateReqVO.getPatId() );
             jobRecordSaveReqVO.setPatName( updateReqVO.getPatName() );
             jobRecordSaveReqVO.setJobTime( updateReqVO.getReturnTime() );
-            jobRecordSaveReqVO.setJobType( DevRentStateEnum.LOST.getState() );
+            jobRecordSaveReqVO.setJobType( devRentStateEnum.getState() );
             jobRecordSaveReqVO.setRemark( updateReqVO.getRemark() );
             jobRecordSaveReqVO.setSummary( updateReqVO.getInterference() + " " + updateReqVO.getBaseline() + " " + updateReqVO.getDetachment() );
             JobRecordDO jobRecord = BeanUtils.toBean(jobRecordSaveReqVO, JobRecordDO.class);
             jobRecordMapper.insert(jobRecord);
         } else {
-            jobRecordDO.setJobType( DevRentStateEnum.LOST.getState() );
+            jobRecordDO.setJobType( devRentStateEnum.getState() );
             jobRecordDO.setJobTime( updateReqVO.getReturnTime() );
             jobRecordDO.setRemark( updateReqVO.getRemark() );
             jobRecordDO.setSummary( updateReqVO.getInterference() + " " + updateReqVO.getBaseline() + " " + updateReqVO.getDetachment() );
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/resources/mapper/devrent/DevRentMapper.xml b/jh-module-ecg/jh-module-ecg-biz/src/main/resources/mapper/devrent/DevRentMapper.xml
index c0a35b5..cf9a770 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/resources/mapper/devrent/DevRentMapper.xml
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/resources/mapper/devrent/DevRentMapper.xml
@@ -9,24 +9,4 @@
         鏂囨。鍙锛歨ttps://www.iocoder.cn/MyBatis/x-plugins/
      -->
 
-    <select id="getRentByState" resultType="cn.lihu.jh.module.ecg.dal.dataobject.devrent.DevRentDO">
-        select * from lihu.dev_rent
-        <where>
-            <if test="stateList != null">
-                and state in (
-                  <foreach collection='stateList' separator=',' item='state'>
-                    #{state}
-                  </foreach> )
-            </if>
-            <if test="devId != null and devId != ''">
-             and dev_id = #{devId}
-            </if>
-            <if test="patId != null and patId != ''">
-             and pat_id = #{patId}
-            </if>
-            and TO_DAYS(create_time) = TO_DAYS(NOW())
-        </where>
-        limit 1
-    </select>
-
 </mapper>

--
Gitblit v1.9.3