feat: 添加BaseEntity初始化方法并优化CabinetCellController逻辑
在BaseEntity中添加initBaseEntity方法用于初始化实体字段,优化CabinetCellController中的openCabinet方法,增加操作日志记录功能,并调整日志输出格式。
This commit is contained in:
parent
9da261afca
commit
365d7dfc11
|
@ -1,16 +1,25 @@
|
||||||
package com.agileboot.api.controller;
|
package com.agileboot.api.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.agileboot.common.core.dto.ResponseDTO;
|
import com.agileboot.common.core.dto.ResponseDTO;
|
||||||
import com.agileboot.common.exception.ApiException;
|
import com.agileboot.common.exception.ApiException;
|
||||||
import com.agileboot.common.exception.error.ErrorCode;
|
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.SmartCabinetApplicationService;
|
||||||
import com.agileboot.domain.cabinet.smartCabinet.dto.CabinetDetailDTO;
|
import com.agileboot.domain.cabinet.smartCabinet.dto.CabinetDetailDTO;
|
||||||
import com.agileboot.domain.mqtt.MqttService;
|
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.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -21,6 +30,9 @@ import java.util.List;
|
||||||
public class CabinetCellController {
|
public class CabinetCellController {
|
||||||
private final SmartCabinetApplicationService smartCabinetApplicationService;
|
private final SmartCabinetApplicationService smartCabinetApplicationService;
|
||||||
private final MqttService mqttService;
|
private final MqttService mqttService;
|
||||||
|
private final CabinetCellOperationModelFactory cabinetCellOperationModelFactory;
|
||||||
|
private final CabinetCellModelFactory cabinetCellModelFactory;
|
||||||
|
private final GoodsModelFactory goodsModelFactory;
|
||||||
|
|
||||||
@GetMapping("/detail")
|
@GetMapping("/detail")
|
||||||
public ResponseDTO<List<CabinetDetailDTO>> getCabinetDetail() {
|
public ResponseDTO<List<CabinetDetailDTO>> getCabinetDetail() {
|
||||||
|
@ -28,7 +40,15 @@ public class CabinetCellController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/openCabinet/{lockControlNo}/{pinNo}")
|
@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";
|
String mqttDate = "8A";
|
||||||
mqttDate += String.format("%02X", lockControlNo);
|
mqttDate += String.format("%02X", lockControlNo);
|
||||||
|
@ -38,7 +58,28 @@ public class CabinetCellController {
|
||||||
mqttService.publish(mqttDate);
|
mqttService.publish(mqttDate);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("mqtt publish error", e);
|
log.error("mqtt publish error", e);
|
||||||
|
operationCommand.setStatus(2);
|
||||||
throw new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "发送指令失败");
|
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();
|
return ResponseDTO.ok();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,4 +43,11 @@ public class BaseEntity<T extends Model<?>> extends Model<T> {
|
||||||
@TableLogic
|
@TableLogic
|
||||||
private Boolean deleted;
|
private Boolean deleted;
|
||||||
|
|
||||||
|
public void initBaseEntity() {
|
||||||
|
this.creatorId = 0L;
|
||||||
|
this.createTime = new Date();
|
||||||
|
this.updaterId = 0L;
|
||||||
|
this.updateTime = new Date();
|
||||||
|
this.deleted = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,8 @@ public class MethodLogAspect {
|
||||||
@Around("dbService()")
|
@Around("dbService()")
|
||||||
public Object aroundDbService(ProceedingJoinPoint joinPoint) throws Throwable {
|
public Object aroundDbService(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
Object proceed = joinPoint.proceed();
|
Object proceed = joinPoint.proceed();
|
||||||
log.info("DB SERVICE : {} ; REQUEST:{} ; RESPONSE : {}", joinPoint.getSignature().toShortString(),
|
/*log.info("DB SERVICE : {} ; REQUEST:{} ; RESPONSE : {}", joinPoint.getSignature().toShortString(),
|
||||||
safeToJson(joinPoint.getArgs()), safeToJson(proceed));
|
safeToJson(joinPoint.getArgs()), safeToJson(proceed));*/
|
||||||
return proceed;
|
return proceed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ public class MethodLogAspect {
|
||||||
@Around("applicationServiceLog()")
|
@Around("applicationServiceLog()")
|
||||||
public Object aroundApplicationService(ProceedingJoinPoint joinPoint) throws Throwable {
|
public Object aroundApplicationService(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
Object proceed = joinPoint.proceed();
|
Object proceed = joinPoint.proceed();
|
||||||
log.info("APPLICATION SERVICE : {} ; REQUEST:{} ; RESPONSE : {}", joinPoint.getSignature().toShortString(),
|
/*log.info("APPLICATION SERVICE : {} ; REQUEST:{} ; RESPONSE : {}", joinPoint.getSignature().toShortString(),
|
||||||
safeToJson(joinPoint.getArgs()), safeToJson(proceed));
|
safeToJson(joinPoint.getArgs()), safeToJson(proceed));*/
|
||||||
return proceed;
|
return proceed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue