Browse Source

feat:初始化设备状态

master
白凤吉 6 days ago
parent
commit
0a46f1b1be
  1. 5
      src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java
  2. 3
      src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java
  3. 10
      src/main/java/com/iflytop/handacid/app/model/bo/ChannelSolution.java
  4. 17
      src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java
  5. 2
      src/main/java/com/iflytop/handacid/common/model/entity/Channel.java

5
src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java

@ -29,4 +29,9 @@ public class ChannelState {
@Schema(description = "通道配置的溶液") @Schema(description = "通道配置的溶液")
private ChannelSolution solution; private ChannelSolution solution;
public ChannelState(ChannelCode channelCode, Double remainingVolume, ChannelSolution solution) {
this.channelCode = channelCode;
this.remainingVolume = remainingVolume;
this.solution = solution;
}
} }

3
src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java

@ -1,6 +1,7 @@
package com.iflytop.handacid.app.core.state; package com.iflytop.handacid.app.core.state;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import com.iflytop.handacid.app.common.enums.ChannelCode;
import com.iflytop.handacid.common.model.entity.User; import com.iflytop.handacid.common.model.entity.User;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -15,7 +16,7 @@ import java.util.Map;
@Component @Component
public class DeviceState { public class DeviceState {
@Schema(description = "通道状态") @Schema(description = "通道状态")
private final Map<Integer, ChannelState> channelStateMap = new HashMap<>();
private final Map<ChannelCode, ChannelState> channelStateMap = new HashMap<>();
@Schema(description = "虚拟模式,true为虚拟") @Schema(description = "虚拟模式,true为虚拟")
private volatile boolean virtual = false; private volatile boolean virtual = false;

10
src/main/java/com/iflytop/handacid/app/model/bo/ChannelSolution.java

@ -6,11 +6,17 @@ import lombok.Data;
@Data @Data
public class ChannelSolution { public class ChannelSolution {
private Long id;
private Long solutionId;
@Schema(description = "溶液名称") @Schema(description = "溶液名称")
private String name;
private String solutionName;
@Schema(description = "溶液浓度") @Schema(description = "溶液浓度")
private String concentration; private String concentration;
public ChannelSolution(Long solutionId, String solutionName, String concentration) {
this.solutionId = solutionId;
this.solutionName = solutionName;
this.concentration = concentration;
}
} }

17
src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java

@ -1,12 +1,19 @@
package com.iflytop.handacid.app.service; package com.iflytop.handacid.app.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.iflytop.handacid.app.common.enums.ChannelCode;
import com.iflytop.handacid.app.core.state.ChannelState;
import com.iflytop.handacid.app.core.state.DeviceState; import com.iflytop.handacid.app.core.state.DeviceState;
import com.iflytop.handacid.app.model.bo.ChannelSolution;
import com.iflytop.handacid.common.model.entity.Channel;
import com.iflytop.handacid.common.service.ChannelService;
import com.iflytop.handacid.hardware.service.AppEventBusService; import com.iflytop.handacid.hardware.service.AppEventBusService;
import com.iflytop.handacid.hardware.type.appevent.A8kCanBusOnConnectEvent; import com.iflytop.handacid.hardware.type.appevent.A8kCanBusOnConnectEvent;
import com.iflytop.handacid.hardware.type.appevent.AppEvent; import com.iflytop.handacid.hardware.type.appevent.AppEvent;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@ -16,6 +23,8 @@ public class DeviceInitService {
private final AppEventBusService eventBus; private final AppEventBusService eventBus;
private boolean isLink = false; private boolean isLink = false;
private final DeviceState deviceState; private final DeviceState deviceState;
private final ObjectProvider<ChannelState> channelStateObjectProvider;
private final ChannelService channelService;
@PostConstruct @PostConstruct
public void init() { public void init() {
@ -39,8 +48,16 @@ public class DeviceInitService {
} }
} }
public void initDeviceState() { public void initDeviceState() {
log.info("初始化 initDeviceState"); log.info("初始化 initDeviceState");
for (ChannelCode code : ChannelCode.values()) {
//初始化通道
Channel channel = channelService.getOne(new LambdaQueryWrapper<>(new Channel()).eq(Channel::getCode, code));
ChannelSolution channelSolution = new ChannelSolution(channel.getSolutionId(), channel.getSolutionName(), channel.getConcentration());
ChannelState channelState = channelStateObjectProvider.getObject(code, channel.getVolume(), channelSolution);
deviceState.getChannelStateMap().put(code, channelState);
}
log.info("初始化 initDeviceState完毕"); log.info("初始化 initDeviceState完毕");
} }

2
src/main/java/com/iflytop/handacid/common/model/entity/Channel.java

@ -17,7 +17,7 @@ public class Channel extends BaseEntity {
@Schema(description = "酸液ID") @Schema(description = "酸液ID")
private Long solutionId; private Long solutionId;
@Schema(description = "酸液名称") @Schema(description = "酸液名称")
private Long solutionName;
private String solutionName;
@Schema(description = "酸液浓度") @Schema(description = "酸液浓度")
private String concentration; private String concentration;
@Schema(description = "通道code") @Schema(description = "通道code")

Loading…
Cancel
Save