Browse Source

修改取钥匙换钥匙接口

车车 11 tháng trước cách đây
mục cha
commit
9ec224ef09

+ 13 - 5
ktg-iscs/src/main/java/com/ktg/iscs/controller/HardwareApiController.java

@@ -31,12 +31,20 @@ public class HardwareApiController extends BaseController
     @Autowired
     private HardwareApiService hardwareApiService;
 
-    @ApiOperation("修改钥匙状态(上锁时取出和归还 / 解锁时取出和归还)")
-    @Log(title = "修改钥匙状态", businessType = BusinessType.UPDATE)
-    @PostMapping("/updateTicketKetStatus")
-    public CommonResult<Boolean> updateTicketKetStatus(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") UpdateKeyStatusDTO dto)
+    @ApiOperation("取出钥匙")
+    @Log(title = "取出钥匙", businessType = BusinessType.UPDATE)
+    @PostMapping("/updateTakeOutKey")
+    public CommonResult<Boolean> updateTakeOutKey(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") TakeOutKeyDTO dto)
     {
-        return CommonResult.success(hardwareApiService.updateTicketKetStatus(dto));
+        return CommonResult.success(hardwareApiService.updateTakeOutKey(dto));
+    }
+
+    @ApiOperation("归还钥匙")
+    @Log(title = "归还钥匙", businessType = BusinessType.UPDATE)
+    @PostMapping("/updateReturnKey")
+    public CommonResult<Boolean> updateReturnKey(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") ReturnKeyDTO dto)
+    {
+        return CommonResult.success(hardwareApiService.updateReturnKey(dto));
     }
 
     @ApiOperation("取出挂锁时更新数据")

+ 24 - 0
ktg-iscs/src/main/java/com/ktg/iscs/domain/dto/hardwareApi/ReturnKeyDTO.java

@@ -0,0 +1,24 @@
+package com.ktg.iscs.domain.dto.hardwareApi;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 硬件对象 is_hardware
+ *
+ * @author cgj
+ * @date 2024-10-16
+ */
+@Data
+public class ReturnKeyDTO {
+
+    @ApiModelProperty(value = "作业票ID")
+    private Long ticketId;
+
+    @ApiModelProperty(value = "钥匙NFC")
+    private String keyNfc;
+
+    @ApiModelProperty(value = "序列号-取出硬件ID")
+    private String serialNumber;
+
+}

+ 24 - 0
ktg-iscs/src/main/java/com/ktg/iscs/domain/dto/hardwareApi/TakeOutKeyDTO.java

@@ -0,0 +1,24 @@
+package com.ktg.iscs.domain.dto.hardwareApi;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 硬件对象 is_hardware
+ *
+ * @author cgj
+ * @date 2024-10-16
+ */
+@Data
+public class TakeOutKeyDTO {
+
+    @ApiModelProperty(value = "作业票ID")
+    private Long ticketId;
+
+    @ApiModelProperty(value = "钥匙NFC")
+    private String keyNfc;
+
+    @ApiModelProperty(value = "序列号-取出硬件ID")
+    private String serialNumber;
+
+}

+ 4 - 4
ktg-iscs/src/main/java/com/ktg/iscs/domain/dto/hardwareApi/UpdateKeyStatusDTO.java

@@ -18,10 +18,10 @@ public class UpdateKeyStatusDTO {
     @ApiModelProperty(value = "钥匙NFC")
     private String keyNfc;
 
-    @ApiModelProperty(value = "取出硬件ID")
-    private Long fromHardwareId;
+    @ApiModelProperty(value = "序列号-取出硬件ID(和归还序列号不可同时有值)")
+    private String fromSerialNumber;
 
-    @ApiModelProperty(value = "归还硬件ID")
-    private Long toHardwareId;
+    @ApiModelProperty(value = "序列号-归还硬件ID")
+    private Long toSerialNumber;
 
 }

+ 23 - 0
ktg-iscs/src/main/java/com/ktg/iscs/domain/enums/KeyStatusEnum.java

@@ -0,0 +1,23 @@
+package com.ktg.iscs.domain.enums;
+
+import lombok.AllArgsConstructor;
+
+@AllArgsConstructor
+public enum KeyStatusEnum {
+    /**
+     * 上锁人包含0-5,共锁人包含0、4、5
+     */
+    WAIT_TAKE(0, "待取出"),
+    TAKED(1, "已取出"),
+    RETURNED(2, "已归还");
+
+    /**
+     * 状态编号
+     */
+    public final Integer status;
+
+    /**
+     * 描述
+     */
+    public final String desc;
+}

+ 9 - 2
ktg-iscs/src/main/java/com/ktg/iscs/service/HardwareApiService.java

@@ -13,11 +13,18 @@ import java.util.List;
 public interface HardwareApiService {
 
     /**
-     * 修改钥匙状态(上锁时取出和归还 / 解锁时取出和归还)
+     * 取出钥匙
      * @param dto
      * @return
      */
-    Boolean updateTicketKetStatus(UpdateKeyStatusDTO dto);
+    Boolean updateTakeOutKey(TakeOutKeyDTO dto);
+
+    /**
+     * 归还钥匙
+     * @param dto
+     * @return
+     */
+    Boolean updateReturnKey(ReturnKeyDTO dto);
 
     /**
      * 取出挂锁时更新数据

+ 67 - 24
ktg-iscs/src/main/java/com/ktg/iscs/service/impl/HardwareApiServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.lang.Assert;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ktg.iscs.domain.*;
 import com.ktg.iscs.domain.dto.hardwareApi.*;
+import com.ktg.iscs.domain.enums.KeyStatusEnum;
 import com.ktg.iscs.domain.enums.LockStatusEnum;
 import com.ktg.iscs.domain.enums.LocksetStatusEnum;
 import com.ktg.iscs.service.*;
@@ -42,51 +43,93 @@ public class HardwareApiServiceImpl implements HardwareApiService {
     @Autowired
     private IIsHardwareService isHardwareService;
 
+
+    @Override
+    public Boolean updateTakeOutKey(TakeOutKeyDTO dto) {
+        Assert.notNull(dto.getTicketId(), "请告诉我关于哪个作业票!");
+        Assert.notBlank(dto.getKeyNfc(), "请告诉我钥匙的NFC!");
+        Assert.notBlank(dto.getSerialNumber(), "请告知归还到哪里!");
+        // 1.获取作业票数据
+        IsJobTicket jobTicket = isJobTicketService.getById(dto.getTicketId());
+        Assert.notNull(jobTicket, "作业票数据丢失啦!");
+        // 1.1获取上锁时取出的锁的信息
+        IsKey startKey = isKeyService.getOne(Wrappers.<IsKey>lambdaQuery().eq(IsKey::getKeyNfc, dto.getKeyNfc()));
+        Assert.notNull(startKey, "钥匙数据丢失啦!");
+        // 1.2通过序列号查询柜子信息
+        IsHardware isHardware = isHardwareService.getOne(Wrappers.<IsHardware>lambdaQuery()
+                .eq(IsHardware::getSerialNumber, dto.getSerialNumber()));
+        Assert.notNull(isHardware, "该序列号无对应的硬件信息!");
+        // 1.3初始化时间参数
+        Date date = new Date();
+        // 1.4获取上锁时的数据
+        IsJobTicketKey jobTicketKey = iIsJobTicketKeyService.getOne(Wrappers.<IsJobTicketKey>lambdaUpdate()
+                .eq(IsJobTicketKey::getTicketId, dto.getTicketId())
+                .eq(IsJobTicketKey::getTicketType, "0"));
+        // 2.根据作业票判断到了哪一阶段了,如果上锁数据中这两个数据有空的,那肯定是上锁阶段还没有完成
+        if (jobTicketKey.getCollectTime() == null || jobTicketKey.getGiveBackTime() == null) {
+            // 3.上锁阶段
+            iIsJobTicketKeyService.update(Wrappers.<IsJobTicketKey>lambdaUpdate()
+                    .eq(IsJobTicketKey::getTicketId, dto.getTicketId())
+                    .eq(IsJobTicketKey::getTicketType, "0")
+                    .set(IsJobTicketKey::getKeyId, startKey.getKeyId())
+                    .set(IsJobTicketKey::getFromHardwareId, isHardware.getId())
+                    .set(IsJobTicketKey::getCollectTime, date)
+                    .set(IsJobTicketKey::getKeyStatus, KeyStatusEnum.TAKED.status));
+
+        } else {
+            // 3.1解锁阶段
+            iIsJobTicketKeyService.update(Wrappers.<IsJobTicketKey>lambdaUpdate()
+                    .eq(IsJobTicketKey::getTicketId, dto.getTicketId())
+                    .eq(IsJobTicketKey::getTicketType, "1")
+                    .set(IsJobTicketKey::getKeyId, startKey.getKeyId())
+                    .set(IsJobTicketKey::getFromHardwareId, isHardware.getId())
+                    .set(IsJobTicketKey::getCollectTime, date)
+                    .set(IsJobTicketKey::getKeyStatus, KeyStatusEnum.TAKED.status));
+        }
+        return true;
+    }
+
     @Override
-    public Boolean updateTicketKetStatus(UpdateKeyStatusDTO dto) {
+    public Boolean updateReturnKey(ReturnKeyDTO dto) {
         Assert.notNull(dto.getTicketId(), "请告诉我关于哪个作业票!");
         Assert.notBlank(dto.getKeyNfc(), "请告诉我钥匙的NFC!");
+        Assert.notBlank(dto.getSerialNumber(), "请告知归还到哪里!");
         // 1.获取作业票数据
         IsJobTicket jobTicket = isJobTicketService.getById(dto.getTicketId());
         Assert.notNull(jobTicket, "作业票数据丢失啦!");
-        // 1.1初始化时间参数
+        // 1.1获取上锁时取出的锁的信息
+        IsKey startKey = isKeyService.getOne(Wrappers.<IsKey>lambdaQuery().eq(IsKey::getKeyNfc, dto.getKeyNfc()));
+        Assert.notNull(startKey, "钥匙数据丢失啦!");
+        // 1.2通过序列号查询柜子信息
+        IsHardware isHardware = isHardwareService.getOne(Wrappers.<IsHardware>lambdaQuery()
+                .eq(IsHardware::getSerialNumber, dto.getSerialNumber()));
+        Assert.notNull(isHardware, "该序列号无对应的硬件信息!");
+        // 1.3初始化时间参数
         Date date = new Date();
-        // 1.2获取上锁时的数据
+        // 1.4获取上锁时的数据
         IsJobTicketKey jobTicketKey = iIsJobTicketKeyService.getOne(Wrappers.<IsJobTicketKey>lambdaUpdate()
                 .eq(IsJobTicketKey::getTicketId, dto.getTicketId())
                 .eq(IsJobTicketKey::getTicketType, "0"));
-        // 2.根据作业票判断到了哪一阶段了
+        // 2.根据作业票判断到了哪一阶段了,如果上锁数据中这两个数据有空的,那肯定是上锁阶段还没有完成
         if (jobTicketKey.getCollectTime() == null || jobTicketKey.getGiveBackTime() == null) {
-            // 3.1获取上锁时取出的锁的信息
-            IsKey startKey = isKeyService.getOne(Wrappers.<IsKey>lambdaQuery().eq(IsKey::getKeyNfc, dto.getKeyNfc()));
-            Assert.notNull(startKey, "钥匙数据丢失啦!");
-            // 3.2上锁阶段
+            // 3.上锁阶段
             iIsJobTicketKeyService.update(Wrappers.<IsJobTicketKey>lambdaUpdate()
                     .eq(IsJobTicketKey::getTicketId, dto.getTicketId())
                     .eq(IsJobTicketKey::getTicketType, "0")
                     .set(IsJobTicketKey::getKeyId, startKey.getKeyId())
-                    .set(dto.getFromHardwareId() != null, IsJobTicketKey::getFromHardwareId, dto.getFromHardwareId())
-                    .set(dto.getFromHardwareId() != null, IsJobTicketKey::getCollectTime, date)
-                    .set(dto.getFromHardwareId() != null, IsJobTicketKey::getKeyStatus, "1")
-                    .set(dto.getToHardwareId() != null, IsJobTicketKey::getToHardwareId, dto.getToHardwareId())
-                    .set(dto.getToHardwareId() != null, IsJobTicketKey::getGiveBackTime, date)
-                    .set(dto.getToHardwareId() != null, IsJobTicketKey::getKeyStatus, "2"));
+                    .set(IsJobTicketKey::getToHardwareId, isHardware.getId())
+                    .set(IsJobTicketKey::getGiveBackTime, date)
+                    .set(IsJobTicketKey::getKeyStatus, KeyStatusEnum.RETURNED.status));
 
         } else {
-            // 4.1获取解锁时取出的锁的信息
-            IsKey startKey = isKeyService.getOne(Wrappers.<IsKey>lambdaQuery().eq(IsKey::getKeyNfc, dto.getKeyNfc()));
-            Assert.notNull(startKey, "钥匙数据丢失啦!");
-            // 4.2解锁阶段
+            // 3.1解锁阶段
             iIsJobTicketKeyService.update(Wrappers.<IsJobTicketKey>lambdaUpdate()
                     .eq(IsJobTicketKey::getTicketId, dto.getTicketId())
                     .eq(IsJobTicketKey::getTicketType, "1")
                     .set(IsJobTicketKey::getKeyId, startKey.getKeyId())
-                    .set(dto.getFromHardwareId() != null, IsJobTicketKey::getFromHardwareId, dto.getFromHardwareId())
-                    .set(dto.getFromHardwareId() != null, IsJobTicketKey::getCollectTime, date)
-                    .set(dto.getFromHardwareId() != null, IsJobTicketKey::getKeyStatus, "1")
-                    .set(dto.getToHardwareId() != null, IsJobTicketKey::getToHardwareId, dto.getToHardwareId())
-                    .set(dto.getToHardwareId() != null, IsJobTicketKey::getGiveBackTime, date)
-                    .set(dto.getToHardwareId() != null, IsJobTicketKey::getKeyStatus, "2"));
+                    .set(IsJobTicketKey::getToHardwareId, isHardware.getId())
+                    .set(IsJobTicketKey::getGiveBackTime, date)
+                    .set(IsJobTicketKey::getKeyStatus, KeyStatusEnum.RETURNED.status));
         }
         return true;
     }