diff --git a/agileboot-api/src/main/java/com/agileboot/api/controller/CabinetCellController.java b/agileboot-api/src/main/java/com/agileboot/api/controller/CabinetCellController.java index 764d6c4..4ae16fa 100644 --- a/agileboot-api/src/main/java/com/agileboot/api/controller/CabinetCellController.java +++ b/agileboot-api/src/main/java/com/agileboot/api/controller/CabinetCellController.java @@ -1,16 +1,25 @@ package com.agileboot.api.controller; +import cn.hutool.json.JSONUtil; import com.agileboot.common.core.dto.ResponseDTO; import com.agileboot.common.exception.ApiException; import com.agileboot.common.exception.error.ErrorCode; +import com.agileboot.domain.cabinet.cell.model.CabinetCellModel; +import com.agileboot.domain.cabinet.cell.model.CabinetCellModelFactory; +import com.agileboot.domain.cabinet.operation.command.AddCabinetCellOperationCommand; +import com.agileboot.domain.cabinet.operation.model.CabinetCellOperationModel; +import com.agileboot.domain.cabinet.operation.model.CabinetCellOperationModelFactory; import com.agileboot.domain.cabinet.smartCabinet.SmartCabinetApplicationService; import com.agileboot.domain.cabinet.smartCabinet.dto.CabinetDetailDTO; import com.agileboot.domain.mqtt.MqttService; +import com.agileboot.domain.shop.goods.model.GoodsModel; +import com.agileboot.domain.shop.goods.model.GoodsModelFactory; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; +import java.util.Date; import java.util.List; @Slf4j @@ -21,6 +30,9 @@ import java.util.List; public class CabinetCellController { private final SmartCabinetApplicationService smartCabinetApplicationService; private final MqttService mqttService; + private final CabinetCellOperationModelFactory cabinetCellOperationModelFactory; + private final CabinetCellModelFactory cabinetCellModelFactory; + private final GoodsModelFactory goodsModelFactory; @GetMapping("/detail") public ResponseDTO> getCabinetDetail() { @@ -28,7 +40,15 @@ public class CabinetCellController { } @PostMapping("/openCabinet/{lockControlNo}/{pinNo}") - public ResponseDTO openCabinet(@PathVariable Integer lockControlNo, @PathVariable Integer pinNo) { + public ResponseDTO openCabinet(@PathVariable Integer lockControlNo, @PathVariable Integer pinNo, + @RequestBody AddCabinetCellOperationCommand operationCommand) { + if (null == operationCommand){ + operationCommand = new AddCabinetCellOperationCommand(); + } + operationCommand.setOperationType(2); + operationCommand.setStatus(1); + + CabinetCellOperationModel cellOperationModel = cabinetCellOperationModelFactory.create(); // 发送指令 String mqttDate = "8A"; mqttDate += String.format("%02X", lockControlNo); @@ -38,7 +58,28 @@ public class CabinetCellController { mqttService.publish(mqttDate); } catch (Exception e) { log.error("mqtt publish error", e); + operationCommand.setStatus(2); throw new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "发送指令失败"); + } finally { + // 记录操作日志 + operationCommand.initBaseEntity(); + if (operationCommand.getCellId() == null) { + log.error("openCabinet 格口ID为空"); + } else { + CabinetCellModel cabinetCellModel = cabinetCellModelFactory.loadById(operationCommand.getCellId()); + operationCommand.setGoodsId(cabinetCellModel.getGoodsId()); + operationCommand.setGoodsName(""); + + if (cabinetCellModel.getGoodsId() != null) { + GoodsModel goodsModel = goodsModelFactory.loadById(cabinetCellModel.getGoodsId()); + operationCommand.setGoodsName(goodsModel.getGoodsName()); + } + + log.info("openCabinet lockControlNo: {}, pinNo: {}, operationCommand: {}", lockControlNo, pinNo, JSONUtil.toJsonStr(operationCommand)); + cellOperationModel.loadAddCommand(operationCommand); + cellOperationModel.insert(); + } + } return ResponseDTO.ok(); } diff --git a/agileboot-common/src/main/java/com/agileboot/common/core/base/BaseEntity.java b/agileboot-common/src/main/java/com/agileboot/common/core/base/BaseEntity.java index 127fc97..a76bcb8 100644 --- a/agileboot-common/src/main/java/com/agileboot/common/core/base/BaseEntity.java +++ b/agileboot-common/src/main/java/com/agileboot/common/core/base/BaseEntity.java @@ -43,4 +43,11 @@ public class BaseEntity> extends Model { @TableLogic private Boolean deleted; + public void initBaseEntity() { + this.creatorId = 0L; + this.createTime = new Date(); + this.updaterId = 0L; + this.updateTime = new Date(); + this.deleted = false; + } } diff --git a/agileboot-infrastructure/src/main/java/com/agileboot/infrastructure/log/MethodLogAspect.java b/agileboot-infrastructure/src/main/java/com/agileboot/infrastructure/log/MethodLogAspect.java index 65587aa..7e6c968 100644 --- a/agileboot-infrastructure/src/main/java/com/agileboot/infrastructure/log/MethodLogAspect.java +++ b/agileboot-infrastructure/src/main/java/com/agileboot/infrastructure/log/MethodLogAspect.java @@ -27,8 +27,8 @@ public class MethodLogAspect { @Around("dbService()") public Object aroundDbService(ProceedingJoinPoint joinPoint) throws Throwable { Object proceed = joinPoint.proceed(); - log.info("DB SERVICE : {} ; REQUEST:{} ; RESPONSE : {}", joinPoint.getSignature().toShortString(), - safeToJson(joinPoint.getArgs()), safeToJson(proceed)); + /*log.info("DB SERVICE : {} ; REQUEST:{} ; RESPONSE : {}", joinPoint.getSignature().toShortString(), + safeToJson(joinPoint.getArgs()), safeToJson(proceed));*/ return proceed; } @@ -46,8 +46,8 @@ public class MethodLogAspect { @Around("applicationServiceLog()") public Object aroundApplicationService(ProceedingJoinPoint joinPoint) throws Throwable { Object proceed = joinPoint.proceed(); - log.info("APPLICATION SERVICE : {} ; REQUEST:{} ; RESPONSE : {}", joinPoint.getSignature().toShortString(), - safeToJson(joinPoint.getArgs()), safeToJson(proceed)); + /*log.info("APPLICATION SERVICE : {} ; REQUEST:{} ; RESPONSE : {}", joinPoint.getSignature().toShortString(), + safeToJson(joinPoint.getArgs()), safeToJson(proceed));*/ return proceed; }