Browse Source

fix:增加还原出厂配置功能

tags/1.0
白凤吉 4 months ago
parent
commit
c9877a690b
  1. 15
      src/main/java/com/qyft/ms/app/controller/SysSettingsController.java
  2. 35
      src/main/java/com/qyft/ms/app/controller/SystemController.java
  3. 37
      src/main/java/com/qyft/ms/app/core/properties/FactoryResetProperties.java
  4. 10
      src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java
  5. 18
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java
  6. 10
      src/main/java/com/qyft/ms/app/model/entity/Position.java
  7. 7
      src/main/java/com/qyft/ms/app/model/entity/SysSettings.java
  8. 16
      src/main/java/com/qyft/ms/app/service/PositionService.java
  9. 16
      src/main/java/com/qyft/ms/app/service/SysSettingsService.java
  10. 2
      src/main/java/com/qyft/ms/system/common/device/command/CyclicNumberGenerator.java
  11. 6
      src/main/resources/application.yml
  12. 41
      src/main/resources/factory-reset.yml
  13. 16
      src/main/resources/sql/init.sql

15
src/main/java/com/qyft/ms/app/controller/SysSettingsController.java

@ -1,15 +0,0 @@
package com.qyft.ms.app.controller;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "系统配置")
@RestController
@RequestMapping("/api/sys")
@RequiredArgsConstructor
@Slf4j
public class SysSettingsController {
}

35
src/main/java/com/qyft/ms/app/controller/SystemController.java

@ -0,0 +1,35 @@
package com.qyft.ms.app.controller;
import com.qyft.ms.app.service.PositionService;
import com.qyft.ms.app.service.SysSettingsService;
import com.qyft.ms.system.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "系统接口")
@RestController
@RequestMapping("/api/sys")
@RequiredArgsConstructor
@Slf4j
public class SystemController {
private final PositionService positionService;
private final SysSettingsService sysSettingsService;
@Operation(summary = "还原出厂配置")
@PostMapping("/reset")
public Result<?> resetFactorySettings() {
try {
positionService.resetToFactorySettings();
sysSettingsService.resetToFactorySettings();
return Result.success();
} catch (Exception e) {
log.error("还原出厂配置失败", e);
return Result.failed();
}
}
}

37
src/main/java/com/qyft/ms/app/core/properties/FactoryResetProperties.java

@ -0,0 +1,37 @@
package com.qyft.ms.app.core.properties;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.List;
@ConfigurationProperties(prefix = "factory")
@Component
@Data
public class FactoryResetProperties {
private List<SysSettingConfig> settings;
private List<PositionConfig> positions;
@Data
public static class SysSettingConfig {
private Long id;
private Long parentId;
private String name;
private String code;
private String value;
}
@Data
public static class PositionConfig {
private Long id;
private String pointName;
private String pointCode;
private Double x;
private Double y;
private Double z;
}
}

10
src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java

@ -144,9 +144,6 @@ public class SprayTaskExecutor {
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskStep.getIndex(), sprayNum, sprayCount, currentPoint);
webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO);
commandWait(commandFutureArray);
currentStep++;
sprayTask.setCurrentStep(currentStep);//将当前的喷涂进度缓存
//将当前点位缓存
SprayTaskSprayed sprayTaskSprayed = new SprayTaskSprayed();
sprayTaskSprayed.setNumber(sprayNum);
@ -154,13 +151,18 @@ public class SprayTaskExecutor {
sprayTaskSprayed.setSprayCount(sprayCount);
sprayTaskSprayed.setSprayedPoints(new Point2D(Double.parseDouble(df.format(aXPoint - slideArr[sprayTaskStep.getIndex()][0])), Double.parseDouble(df.format(75.5 - aYPoint))));
sprayTask.addSprayTaskSprayed(sprayTaskSprayed);
commandWait(commandFutureArray);
currentStep++;
sprayTask.setCurrentStep(currentStep);//将当前的喷涂进度缓存
}
sprayTask.setSuspendable(false);//不可暂停
deviceStatus.setSuspendable(false);
if (currentStep >= reCurrentStep) {
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵
CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand);
commandWait(syringePumpStopCommandFuture);
}
sprayCount++;
sprayNum++;
}

18
src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java

@ -69,6 +69,13 @@ public class MatrixSprayChangeParam extends BaseCommandHandler {
}
}
//3.z轴高度
SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper<SysSettings>().eq(SysSettings::getCode, "slide_height"));
Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue());
Double height = slideHeight - motorZHeight;
DeviceCommand smotorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(height, sprayTask.getSprayParams().getMovingSpeed());//移动z轴到指定位置
CommandFuture smotorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), smotorZPositionSetCommand);
//1.速度
DeviceCommand motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(movingSpeed);//x轴电机速度设置
DeviceCommand motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(movingSpeed);//y轴电机速度设置
@ -76,19 +83,12 @@ public class MatrixSprayChangeParam extends BaseCommandHandler {
CommandFuture motorXSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXSpeedSetCmdToDeviceCommand);
CommandFuture motorYSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYSpeedSetCmdToDeviceCommand);
CommandFuture motorZSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZSpeedSetCmdToDeviceCommand);
commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture);
//2.流速
DeviceCommand syringePumpVolumeSetCommand = DeviceCommandGenerator.syringePumpVolumeSet(volume);//注射泵流速设置
CommandFuture syringePumpVolumeSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpVolumeSetCommand);
commandWait(syringePumpVolumeSetCommandFuture);
//3.z轴高度
SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper<SysSettings>().eq(SysSettings::getCode, "slide_height"));
Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue());
Double height = slideHeight - motorZHeight;
DeviceCommand smotorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(height, sprayTask.getSprayParams().getMovingSpeed());//移动z轴到指定位置
CommandFuture smotorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), smotorZPositionSetCommand);
commandWait(smotorZPositionSetCommandFuture);
commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture,smotorZPositionSetCommandFuture,syringePumpVolumeSetCommandFuture);
});

10
src/main/java/com/qyft/ms/app/model/entity/Position.java

@ -32,5 +32,13 @@ public class Position extends BaseEntity {
@Schema(description = "z")
private Double z;
public Position(Long id, String pointName, String pointCode, Double x, Double y, Double z) {
super();
this.setId(id);
this.pointName = pointName;
this.pointCode = pointCode;
this.x = x;
this.y = y;
this.z = z;
}
}

7
src/main/java/com/qyft/ms/app/model/entity/SysSettings.java

@ -34,4 +34,11 @@ public class SysSettings {
@Schema(description = "配置值")
private String value;
public SysSettings(Long id, Long parentId, String name, String code, String value) {
this.id = id;
this.parentId = parentId;
this.name = name;
this.code = code;
this.value = value;
}
}

16
src/main/java/com/qyft/ms/app/service/PositionService.java

@ -1,10 +1,12 @@
package com.qyft.ms.app.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qyft.ms.app.core.properties.FactoryResetProperties;
import com.qyft.ms.app.mapper.PositionMapper;
import com.qyft.ms.app.model.entity.Position;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
@ -17,6 +19,8 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class PositionService extends ServiceImpl<PositionMapper, Position> {
private final FactoryResetProperties factoryResetProperties;
public Boolean delete(String ids) {
List<Long> idsArr = Arrays.stream(ids.split(","))
.map(Long::parseLong)
@ -24,5 +28,17 @@ public class PositionService extends ServiceImpl<PositionMapper, Position> {
return this.removeByIds(idsArr);
}
/**
* 恢复出厂设置
*/
@Transactional(rollbackFor = Exception.class)
public void resetToFactorySettings() {
this.remove(null);
List<Position> positions = factoryResetProperties.getPositions().stream()
.map(config -> new Position(config.getId(), config.getPointName(), config.getPointCode(), config.getX(), config.getY(), config.getZ()))
.collect(Collectors.toList());
this.saveBatch(positions);
}
}

16
src/main/java/com/qyft/ms/app/service/SysSettingsService.java

@ -2,14 +2,17 @@ package com.qyft.ms.app.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qyft.ms.app.core.properties.FactoryResetProperties;
import com.qyft.ms.app.mapper.SysSettingsMapper;
import com.qyft.ms.app.model.entity.SysSettings;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 系统配置实现类
@ -18,6 +21,7 @@ import java.util.Map;
@RequiredArgsConstructor
public class SysSettingsService extends ServiceImpl<SysSettingsMapper, SysSettings> {
private final SysSettingsMapper sysSettingsMapper;
private final FactoryResetProperties factoryResetProperties;
// 玻片位置
@Getter
List<SysSettings> slidePositionList;
@ -68,4 +72,16 @@ public class SysSettingsService extends ServiceImpl<SysSettingsMapper, SysSettin
public void updateSelfCheckStatus(boolean status) {
selfCheckStatus = status;
}
/**
* 恢复出厂设置
*/
@Transactional(rollbackFor = Exception.class)
public void resetToFactorySettings() {
this.remove(null);
List<SysSettings> settings = factoryResetProperties.getSettings().stream()
.map(config -> new SysSettings(config.getId(), config.getParentId(), config.getName(), config.getCode(), config.getValue()))
.collect(Collectors.toList());
this.saveBatch(settings);
}
}

2
src/main/java/com/qyft/ms/system/common/device/command/CyclicNumberGenerator.java

@ -33,7 +33,7 @@ public class CyclicNumberGenerator {
// 每次生成后将当前数字加 1
currentNumber++;
// 如果当前数字超过 255将其重置为 1
if (currentNumber > 255) {
if (currentNumber > 4000) {
currentNumber = 1;
}
return result;

6
src/main/resources/application.yml

@ -6,6 +6,8 @@ server:
spring:
application:
name: matrix-spray
config:
import: "classpath:factory-reset.yml"
datasource:
url: jdbc:sqlite:../db/matrix-spray.db
driver-class-name: org.sqlite.JDBC
@ -38,7 +40,9 @@ jwt:
tcp:
enable: true # 是否开启 TCP 连接
server-enable: true # 是否开启 TCP 连接
host: 127.0.0.1
# host: 127.0.0.1
# host: 192.168.1.106
host: 192.168.1.140
# host: 192.168.100.168
port: 9080
reconnect: 5000 # 断线重连间隔(单位:毫秒)

41
src/main/resources/factory-reset.yml

@ -0,0 +1,41 @@
factory:
settings:
- id: 1
name: "玻片高度"
code: "slide_height"
value: 101.2
- id: 2
name: "z轴安全高度"
code: "safe_z_height"
value: 80
positions:
- id: 1
pointName: "玻片1位置"
pointCode: "slide_position1"
x: 18.08
y: 0
z: 101.2
- id: 2
pointName: "玻片2位置"
pointCode: "slide_position2"
x: 45.08
y: 0
z: 101.2
- id: 3
pointName: "玻片3位置"
pointCode: "slide_position3"
x: 72.08
y: 0
z: 101.2
- id: 4
pointName: "玻片4位置"
pointCode: "slide_position4"
x: 99.08
y: 0
z: 101.2
- id: 5
pointName: "废液桶位置"
pointCode: "waste_liquor"
x: 173.08
y: 75
z: 70

16
src/main/resources/sql/init.sql

@ -57,16 +57,8 @@ CREATE TABLE IF NOT EXISTS sys_settings
-- 插入 sys_settings 表数据
INSERT OR IGNORE INTO sys_settings (id, parent_id, name, code, value)
VALUES (1, NULL, '电机电流', 'current', NULL),
(2, 1, 'x轴电流', 'x_current', 2),
(3, 1, 'y轴电流', 'y_current', 3),
(4, 1, 'z轴电流', 'z_current', 4),
(5, NULL, '电机运行速度', 'speed', NULL),
(6, 5, 'x轴速度', 'x_speed', 10),
(7, 5, 'y轴速度', 'y_speed', 10),
(8, 5, 'z轴速度', 'z_speed', 10),
(9, NULL, '玻片高度', 'slide_height', 101.2),
(10, NULL, 'z轴安全高度', 'safe_z_height', 80);
VALUES (1, NULL, '玻片高度', 'slide_height', 101.2),
(2, NULL, 'z轴安全高度', 'safe_z_height', 80);
@ -83,8 +75,8 @@ CREATE TABLE IF NOT EXISTS position
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT OR IGNORE INTO position (id, point_name, point_code, x, y, z)
VALUES (1,'玻片1位置', 'slide_position1', 18.08, 0, 101.2),
INSERT OR IGNORE INTO position (id, point_name, point_code, x, y, z)
VALUES (1,'玻片1位置', 'slide_position1', 18.08, 0, 101.2),
(2,'玻片2位置', 'slide_position2', 45.08, 0, 101.2),
(3,'玻片3位置', 'slide_position3', 72.08, 0, 101.2),
(4,'玻片4位置', 'slide_position4', 99.08, 0, 101.2),

Loading…
Cancel
Save