Kaynağa Gözat

新增上锁解锁时的作业票关联锁的数据更新

车车 11 ay önce
ebeveyn
işleme
2cf85a10e8

+ 44 - 0
ktg-iscs/src/main/java/com/ktg/iscs/controller/HardwareApiController.java

@@ -0,0 +1,44 @@
+package com.ktg.iscs.controller;
+
+import com.ktg.common.annotation.Log;
+import com.ktg.common.core.controller.BaseController;
+import com.ktg.common.enums.BusinessType;
+import com.ktg.common.pojo.CommonResult;
+import com.ktg.iscs.domain.dto.hardwareApi.UpdateKeyStatusDTO;
+import com.ktg.iscs.service.HardwareApiService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.v3.oas.annotations.Parameter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 硬件调用接口
+ *
+ * @author cgj
+ * @date 2024-10-16
+ */
+@Api(tags = "硬件调用接口")
+@RestController
+@RequestMapping("/iscs/hardware-api")
+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)
+    {
+        return CommonResult.success(hardwareApiService.updateTicketKetStatus(dto));
+    }
+
+
+
+
+
+}

+ 1 - 1
ktg-iscs/src/main/java/com/ktg/iscs/domain/IsJobTicket.java

@@ -64,7 +64,7 @@ public class IsJobTicket extends BaseBean
     private String ticketContent;
 
     /** 作业票状态 */
-    @ApiModelProperty(value = "作业票状态")
+    @ApiModelProperty(value = "作业票状态(0未开始 1待上锁 2进行中 3待解锁 4已结束)")
     @Excel(name = "作业票状态")
     private String ticketStatus;
 

+ 2 - 2
ktg-iscs/src/main/java/com/ktg/iscs/domain/IsJobTicketKey.java

@@ -53,8 +53,8 @@ public class IsJobTicketKey extends BaseBean
     @Excel(name = "归还时间", width = 30, dateFormat = "yyyy-MM-dd")
     private Date giveBackTime;
 
-    @ApiModelProperty(value = "钥匙状态")
-    @Excel(name = "钥匙状态")
+    @ApiModelProperty(value = "钥匙状态(0-待取出 1-已取出 2-已归还)")
+    @Excel(name = "钥匙状态(0-待取出 1-已取出 2-已归还)")
     private String keyStatus;
 
     @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)")

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

@@ -0,0 +1,27 @@
+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 UpdateKeyStatusDTO {
+
+    @ApiModelProperty(value = "作业票ID")
+    private Long ticketId;
+
+    @ApiModelProperty(value = "钥匙NFC")
+    private String keyNfc;
+
+    @ApiModelProperty(value = "取出硬件ID")
+    private Long fromHardwareId;
+
+    @ApiModelProperty(value = "归还硬件ID")
+    private Long toHardwareId;
+
+}

+ 15 - 0
ktg-iscs/src/main/java/com/ktg/iscs/service/HardwareApiService.java

@@ -0,0 +1,15 @@
+package com.ktg.iscs.service;
+
+import com.ktg.iscs.domain.dto.hardwareApi.UpdateKeyStatusDTO;
+
+/**
+ * 硬件调用接口
+ *
+ * @author cgj
+ * @date 2024-10-16
+ */
+public interface HardwareApiService {
+
+    Boolean updateTicketKetStatus(UpdateKeyStatusDTO dto);
+
+}

+ 77 - 0
ktg-iscs/src/main/java/com/ktg/iscs/service/impl/HardwareApiServiceImpl.java

@@ -0,0 +1,77 @@
+package com.ktg.iscs.service.impl;
+
+import cn.hutool.core.lang.Assert;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.ktg.iscs.domain.IsJobTicket;
+import com.ktg.iscs.domain.IsJobTicketKey;
+import com.ktg.iscs.domain.IsKey;
+import com.ktg.iscs.domain.dto.hardwareApi.UpdateKeyStatusDTO;
+import com.ktg.iscs.service.HardwareApiService;
+import com.ktg.iscs.service.IIsJobTicketKeyService;
+import com.ktg.iscs.service.IIsJobTicketService;
+import com.ktg.iscs.service.IIsKeyService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+
+/**
+ * 硬件Service业务层处理
+ *
+ * @author cgj
+ * @date 2024-10-16
+ */
+@Service
+public class HardwareApiServiceImpl implements HardwareApiService {
+    @Autowired
+    private IIsJobTicketService isJobTicketService;
+    @Autowired
+    private IIsKeyService isKeyService;
+    @Autowired
+    private IIsJobTicketKeyService iIsJobTicketKeyService;
+
+    @Override
+    public Boolean updateTicketKetStatus(UpdateKeyStatusDTO dto) {
+        Assert.notNull(dto.getTicketId(), "请告诉我关于哪个作业票!");
+        Assert.notBlank(dto.getKeyNfc(), "请告诉我钥匙的NFC!");
+        // 1.获取作业票数据
+        IsJobTicket jobTicket = isJobTicketService.getById(dto.getTicketId());
+        Assert.notNull(jobTicket, "作业票数据丢失啦!");
+        // 1.1初始化时间参数
+        Date date = new Date();
+        // 1.2获取上锁时的数据
+        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.1获取上锁时取出的锁的信息
+            IsKey startKey = isKeyService.getOne(Wrappers.<IsKey>lambdaQuery().eq(IsKey::getKeyNfc, dto.getKeyNfc()));
+            Assert.notNull(startKey, "钥匙数据丢失啦!");
+            // 3.2上锁阶段
+            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.getToHardwareId() != null, IsJobTicketKey::getToHardwareId, dto.getToHardwareId())
+                    .set(dto.getToHardwareId() != null, IsJobTicketKey::getGiveBackTime, date));
+
+        } else {
+            // 4.1获取解锁时取出的锁的信息
+            IsKey startKey = isKeyService.getOne(Wrappers.<IsKey>lambdaQuery().eq(IsKey::getKeyNfc, dto.getKeyNfc()));
+            Assert.notNull(startKey, "钥匙数据丢失啦!");
+            // 4.2解锁阶段
+            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.getToHardwareId() != null, IsJobTicketKey::getToHardwareId, dto.getToHardwareId())
+                    .set(dto.getToHardwareId() != null, IsJobTicketKey::getGiveBackTime, date));
+        }
+        return true;
+    }
+}

+ 2 - 0
ktg-iscs/src/main/java/com/ktg/iscs/service/impl/IsJobTicketServiceImpl.java

@@ -166,10 +166,12 @@ public class IsJobTicketServiceImpl extends ServiceImpl<IsJobTicketMapper, IsJob
     private boolean saveJobTicketKet(Long ticketId) {
         IsJobTicketKey isJobTicketKey = new IsJobTicketKey();
         isJobTicketKey.setTicketId(ticketId);
+        isJobTicketKey.setKeyStatus("0");
         isJobTicketKey.setTicketType(0);
 
         IsJobTicketKey jobTicketKey = new IsJobTicketKey();
         jobTicketKey.setTicketId(ticketId);
+        jobTicketKey.setKeyStatus("0");
         jobTicketKey.setTicketType(1);
 
         List<IsJobTicketKey> isJobTicketKeys = new ArrayList<>();