diff --git a/README.md b/README.md index 4c9d9e1..551c83b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,12 @@ ``` + TODO: + 1. 数据库文件是否被破坏检查 + 2. 数据库文件如果被破坏,自动恢复默认配置 + + +``` + +``` ==========================模块参数-维护=========================== 参数类型,模块参数: diff --git a/src/main/java/a8k/appbean/AppErrorCode.java b/src/main/java/a8k/appbean/AppErrorCode.java deleted file mode 100644 index ca6b0a9..0000000 --- a/src/main/java/a8k/appbean/AppErrorCode.java +++ /dev/null @@ -1,31 +0,0 @@ -package a8k.appbean; - -public enum AppErrorCode { - Success("Success", "成功", 0), //成功 - TubeNotHasHat("TubeNotHasHat", "全血试管未盖帽", 1), //试管没有帽子 - SampleLiquidLevelWasNotDetected("SampleLiquidLevelWasNotDetected", "取样时未探测到液面", 2),//未探测到液面 - LargeBufferNotEnough("LargeBufferNotEnough", "大瓶缓冲液不足", 3); //未探测到液面 - - - final private String name; - final private String chName; - final private int errorIndex; - - public int mid; - - private AppErrorCode(String name, String chname, int errorIndex) { - this.name = name; - this.chName = chname; - this.errorIndex = errorIndex; - } - - - public String toString() { - return name; - } - - public int getErrorIndex() { - return errorIndex; - } - -} diff --git a/src/main/java/a8k/appbean/Appecode.java b/src/main/java/a8k/appbean/Appecode.java new file mode 100644 index 0000000..935cc6b --- /dev/null +++ b/src/main/java/a8k/appbean/Appecode.java @@ -0,0 +1,37 @@ +package a8k.appbean; + +public enum Appecode { + Success("Success", "成功", 0), // + TubeNotHasHat("TubeNotHasHat", "全血试管未盖帽", 1), // + SampleLiquidLevelWasNotDetected("SampleLiquidLevelWasNotDetected", "取样时未探测到液面", 2),// + LargeBufferNotEnough("LargeBufferNotEnough", "大瓶缓冲液不足", 3), // + PasswdError("PasswdError", "密码错误", 4), // + UserDoesNotExist("UserDoesNotExist", "用户不存在", 5), // + ; + + final private String name; + final private String chName; + final private int errorIndex; + + public int mid; + + private Appecode(String name, String chname, int errorIndex) { + this.name = name; + this.chName = chname; + this.errorIndex = errorIndex; + } + + + public String toString() { + return name; + } + + public String getChName() { + return chName; + } + + public int getErrorCode() { + return errorIndex; + } + +} diff --git a/src/main/java/a8k/controller/TmpTestController.java b/src/main/java/a8k/controller/TmpTestController.java index 9e54831..9ab4a01 100644 --- a/src/main/java/a8k/controller/TmpTestController.java +++ b/src/main/java/a8k/controller/TmpTestController.java @@ -1,9 +1,12 @@ package a8k.controller; + import a8k.a8k_can_protocol.CmdId; import a8k.a8k_can_protocol.ModuleId; +import a8k.appbean.Appecode; import a8k.appbean.HardwareException; import a8k.base_hardware.A8kCanBusService; import a8k.service.A8kDebugTaskExecutorService; +import a8k.service.ctrl_service.DeviceInitializationCtrlService; import a8k.service.hardware.MotorTubeRackMoveCtrlService; import com.iflytop.uf.util.UfClassHelper; import jakarta.annotation.Resource; @@ -12,30 +15,35 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.ResponseBody; + import java.util.List; import java.util.Map; + @Controller public class TmpTestController { @Resource - private A8kCanBusService a8kCanBusService; + private A8kCanBusService a8kCanBusService; @Resource private MotorTubeRackMoveCtrlService motorTubeRackMoveCtrlService; @Resource - private A8kDebugTaskExecutorService a8kDebugTaskExecutorService; + private A8kDebugTaskExecutorService a8kDebugTaskExecutorService; + + @Resource + private DeviceInitializationCtrlService deviceInitializationCtrlService; @PostMapping("/api/tmp-test/execute-service-method") @ResponseBody - public String executeServiceMethod( @RequestBody Map params ) throws NoSuchMethodException { - Object service = this.motorTubeRackMoveCtrlService; - String methodName = (String)params.get("method"); - List methodArgs = (List)params.get("params"); - Object result = UfClassHelper.invokeMethod(service, methodName, methodArgs); + public String executeServiceMethod(@RequestBody Map params) throws NoSuchMethodException { + Object service = this.motorTubeRackMoveCtrlService; + String methodName = (String) params.get("method"); + List methodArgs = (List) params.get("params"); + Object result = UfClassHelper.invokeMethod(service, methodName, methodArgs); return "OK"; } @PostMapping("/api/tmp-test/update-service-params") @ResponseBody - public String updateServiceParams( @RequestBody Map params ) { + public String updateServiceParams(@RequestBody Map params) { return "OK"; } @@ -48,17 +56,13 @@ public class TmpTestController { @GetMapping("/tmp-test/a8k-can-bus-service-call") @ResponseBody public String a8kCanBusServiceCall() throws HardwareException, InterruptedException { - this.a8kCanBusService.callcmd( - ModuleId.ServoTubeRackTubeRotateModule, - CmdId.kmini_servo_enable, - new Integer[]{1} - ); - this.a8kCanBusService.callblockcmd( - ModuleId.MotorTubeRackFeedModule, - CmdId.kstep_motor_easy_move_by, - new Integer[]{5000}, - 20000 - ); + this.a8kCanBusService.callcmd(ModuleId.ServoTubeRackTubeRotateModule, CmdId.kmini_servo_enable, new Integer[]{1}); + this.a8kCanBusService.callblockcmd(ModuleId.MotorTubeRackFeedModule, CmdId.kstep_motor_easy_move_by, new Integer[]{5000}, 20000); return "OK"; } + + @PostMapping("/api/zhaohe_test/initialize_device") + public Appecode initialize_device() { + return deviceInitializationCtrlService.initializeDevice(); + } } diff --git a/src/main/java/a8k/service/A8kStateMgrService.java b/src/main/java/a8k/service/A8kStateMgrService.java deleted file mode 100644 index 74eb508..0000000 --- a/src/main/java/a8k/service/A8kStateMgrService.java +++ /dev/null @@ -1,9 +0,0 @@ -package a8k.service; - -import org.springframework.stereotype.Component; - -@Component -public class A8kStateMgrService { - - -} diff --git a/src/main/java/a8k/service/appdb/dao/AppUsrDao.java b/src/main/java/a8k/service/appdb/dao/AppUsrDao.java new file mode 100644 index 0000000..a9b8b6a --- /dev/null +++ b/src/main/java/a8k/service/appdb/dao/AppUsrDao.java @@ -0,0 +1,18 @@ +package a8k.service.appdb.dao; + +import a8k.service.appdb.entity.AppUsr; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class AppUsrDao { + List getAllUsr() { + return null; + } + + AppUsr getAppUsr() { + return null; + } +} diff --git a/src/main/java/a8k/service/appdb/entity/AppSettingIterm.java b/src/main/java/a8k/service/appdb/entity/AppSettingIterm.java index 3c5a0ae..77616e3 100644 --- a/src/main/java/a8k/service/appdb/entity/AppSettingIterm.java +++ b/src/main/java/a8k/service/appdb/entity/AppSettingIterm.java @@ -1,4 +1,17 @@ package a8k.service.appdb.entity; +import com.iflytop.uf.UfActiveRecordField; public class AppSettingIterm { + @UfActiveRecordField + public String key; + @UfActiveRecordField + public String serviceName; //常量"AppSetting" + @UfActiveRecordField + public String valType; + @UfActiveRecordField + public String val; + + public static String getTableName() { + return "HardwareServiceSetting" + "Table"; + } } diff --git a/src/main/java/a8k/service/appdb/entity/AppUsr.java b/src/main/java/a8k/service/appdb/entity/AppUsr.java new file mode 100644 index 0000000..2aa2bca --- /dev/null +++ b/src/main/java/a8k/service/appdb/entity/AppUsr.java @@ -0,0 +1,37 @@ +package a8k.service.appdb.entity; + +import com.iflytop.uf.UfActiveRecordField; + +public class AppUsr { + + /* + * + * 内置用户有两个 + * admin + * + * + * isMgr: + * 可以删除其他用户 + * 允许打开设备调试页面,用户通过电脑访问设备调试网页,需要登录,且此时只有isMgr用户可以登录。 + * + */ + + @UfActiveRecordField + public String name; + + @UfActiveRecordField + public String passwd; + + @UfActiveRecordField + public Boolean builtInSser; //如果为true,该用户不允许被删除,不允许被修改名字 + + @UfActiveRecordField + public Boolean isMgr; //如果为true, 该用户为管理员权限 + + @UfActiveRecordField + public Boolean isDisplay; //是否显示在前端 + + public static String getTableName() { + return "AppUsr" + "Table"; + } +} diff --git a/src/main/java/a8k/service/ConsumableLoadingService.java b/src/main/java/a8k/service/ctrl_service/ConsumableLoadingService.java similarity index 70% rename from src/main/java/a8k/service/ConsumableLoadingService.java rename to src/main/java/a8k/service/ctrl_service/ConsumableLoadingService.java index 1d64092..a585435 100644 --- a/src/main/java/a8k/service/ConsumableLoadingService.java +++ b/src/main/java/a8k/service/ctrl_service/ConsumableLoadingService.java @@ -1,6 +1,5 @@ -package a8k.service; +package a8k.service.ctrl_service; -import com.iflytop.a800.device.Pipette; import jakarta.annotation.PostConstruct; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,11 +14,9 @@ public class ConsumableLoadingService implements Runnable { } - @PostConstruct public void init(){ //启动线程实例 - LOG.error("Hello................................................................................................"); } } diff --git a/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java b/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java new file mode 100644 index 0000000..d123c00 --- /dev/null +++ b/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java @@ -0,0 +1,31 @@ +package a8k.service.ctrl_service; + +import a8k.appbean.Appecode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class DeviceInitializationCtrlService { + public static final Logger logger = LoggerFactory.getLogger(DeviceInitializationCtrlService.class); + + /* + * + * 初始化设备: + * 1. 检查试管转移通道是否畅通 + * 2. 检查摇匀模组的各个组件是否在指定位置 + * 1.抓手升降 + * 2.试管夹紧 + * 3.抓手平移 + * 4.抓手 + * + */ + + + public Appecode initializeDevice() { + logger.info("Initializing device ..."); + return Appecode.Success; + } + + +} diff --git a/src/main/java/a8k/service/ctrl_service/DeviceShutdowCtrlService.java b/src/main/java/a8k/service/ctrl_service/DeviceShutdowCtrlService.java new file mode 100644 index 0000000..c210612 --- /dev/null +++ b/src/main/java/a8k/service/ctrl_service/DeviceShutdowCtrlService.java @@ -0,0 +1,8 @@ +package a8k.service.ctrl_service; + +import org.springframework.stereotype.Component; + +@Component +public class DeviceShutdowCtrlService { + +} diff --git a/src/main/java/a8k/service/data_service/AppSettingService.java b/src/main/java/a8k/service/data_service/AppSettingService.java new file mode 100644 index 0000000..3590c74 --- /dev/null +++ b/src/main/java/a8k/service/data_service/AppSettingService.java @@ -0,0 +1,9 @@ +package a8k.service.data_service; + +import org.springframework.stereotype.Component; + +@Component +public class AppSettingService { + + +} diff --git a/src/main/java/a8k/service/data_service/UsrMgrService.java b/src/main/java/a8k/service/data_service/UsrMgrService.java new file mode 100644 index 0000000..e4fefef --- /dev/null +++ b/src/main/java/a8k/service/data_service/UsrMgrService.java @@ -0,0 +1,76 @@ +package a8k.service.data_service; + +import a8k.appbean.Appecode; +import a8k.service.appdb.dao.AppUsrDao; +import a8k.service.appdb.entity.AppUsr; +import a8k.service.state_service.A8kStateMgrService; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class UsrMgrService { + + + static final int LOGIN_TYPE_APP = 1; //正常页面,用户登录 + static final int LOGIN_TYPE_DEBUG_PAGE = 2; //调试页面,用户登录 + + @Resource + AppUsrDao appUsrDao; + + @Resource + A8kStateMgrService state; + + /* + * 数据库更删改查 + */ + + //TODO + public List getUsr() { + return null; + } + + //TODO + public Appecode addUsr(AppUsr usr) { + return Appecode.Success; + } + + //TODO + public Appecode updateUsr(String uname, String passwd) { + return Appecode.Success; + } + + + /** + * + * @param loginType 登录类型 LOGIN_TYPE_APP,LOGIN_TYPE_DEBUG_PAGE + * @param uname 用户名称 + * @param passwd 密码 + * @return Success or PasswdError or UserDoesNotExist + * + * + */ + public Appecode verifyAndLoginAppUsr(Integer loginType, String uname, String passwd) { + /* + *TODO + * 实现描述: + * 1. 校验成功,则调用A8kStateMgrService.loginAppUsr 或者 A8kStateMgrService.loginDebugPageUsr + */ + return Appecode.UserDoesNotExist; + } + + + /** + * @param loginType 登录类型 LOGIN_TYPE_APP,LOGIN_TYPE_DEBUG_PAGE + */ + public void unloginAppUsr(Integer loginType) { + if (loginType == LOGIN_TYPE_APP) { + state.unloginAppUsr(); + } else if (loginType == LOGIN_TYPE_DEBUG_PAGE) { + state.unloginAppUsr(); + } + } + + +} diff --git a/src/main/java/a8k/service/db/dao/SamplesPreProcessModuleCtrlParamsService.java b/src/main/java/a8k/service/db/dao/SamplesPreProcessModuleCtrlParamsService.java index ce8ab1f..97d412f 100644 --- a/src/main/java/a8k/service/db/dao/SamplesPreProcessModuleCtrlParamsService.java +++ b/src/main/java/a8k/service/db/dao/SamplesPreProcessModuleCtrlParamsService.java @@ -52,8 +52,6 @@ public class SamplesPreProcessModuleCtrlParamsService { return 0; } - - /* * 平移电机相关参数 */ diff --git a/src/main/java/a8k/service/hardware/HbotControlService.java b/src/main/java/a8k/service/hardware/HbotControlService.java index c992ad8..d9d508e 100644 --- a/src/main/java/a8k/service/hardware/HbotControlService.java +++ b/src/main/java/a8k/service/hardware/HbotControlService.java @@ -1,6 +1,6 @@ package a8k.service.hardware; -import a8k.appbean.AppErrorCode; +import a8k.appbean.Appecode; /** * Hbot控制服务 @@ -26,8 +26,8 @@ public class HbotControlService { } //丢tip - public AppErrorCode dropTip() { - return AppErrorCode.Success; + public Appecode dropTip() { + return Appecode.Success; } //扫描板夹仓二维码 diff --git a/src/main/java/a8k/service/hardware/ReactionPlatesTransmitCtrlService.java b/src/main/java/a8k/service/hardware/ReactionPlatesTransmitCtrlService.java index f20e647..08c83da 100644 --- a/src/main/java/a8k/service/hardware/ReactionPlatesTransmitCtrlService.java +++ b/src/main/java/a8k/service/hardware/ReactionPlatesTransmitCtrlService.java @@ -1,6 +1,5 @@ package a8k.service.hardware; -import a8k.appbean.AppErrorCode; import org.springframework.stereotype.Component; diff --git a/src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java b/src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java index 539bd86..d661c99 100644 --- a/src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java +++ b/src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java @@ -1,7 +1,6 @@ package a8k.service.hardware; -import a8k.appbean.AppErrorCode; -import a8k.appbean.SampleTubeState; +import a8k.appbean.Appecode; import org.springframework.stereotype.Component; @Component @@ -49,7 +48,7 @@ public class SamplesPreProcessModuleCtrlService { * @param tubeType TubeType_HighBlood,TubeType_ShortBlood,TubeType_Mini,TubeType_MiniBlood,TubeType_BulletTube1P5,TubeType_BulletTube0P5 * @param judgeCapExist 是否判断试管帽子存在与否 */ - public AppErrorCode takeTube(String tubeType,boolean judgeCapExist) { + public Appecode takeTube(String tubeType,boolean judgeCapExist) { /* 注意事项: 1. 取试管并将试管放在试管夹紧位置,同时升降电机和平移电机移动到待机位 @@ -59,19 +58,19 @@ public class SamplesPreProcessModuleCtrlService { */ - return AppErrorCode.Success; + return Appecode.Success; } /** * 取试管帽 */ - public AppErrorCode takeTubeCap() { + public Appecode takeTubeCap() { // // // // - return AppErrorCode.Success; + return Appecode.Success; } /** diff --git a/src/main/java/a8k/service/state_service/A8kState.java b/src/main/java/a8k/service/state_service/A8kState.java new file mode 100644 index 0000000..dea242a --- /dev/null +++ b/src/main/java/a8k/service/state_service/A8kState.java @@ -0,0 +1,5 @@ +package a8k.service.state_service; + +public class A8kState { + public Boolean devicePoweredOffNormally = false; //设备是否正常关机 +} diff --git a/src/main/java/a8k/service/state_service/A8kStateDB.java b/src/main/java/a8k/service/state_service/A8kStateDB.java new file mode 100644 index 0000000..2fe0dbe --- /dev/null +++ b/src/main/java/a8k/service/state_service/A8kStateDB.java @@ -0,0 +1,19 @@ +package a8k.service.state_service; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.iflytop.uf.UfActiveRecord; +import com.iflytop.uf.UfActiveRecordField; + +public class A8kStateDB extends UfActiveRecord { + + @UfActiveRecordField + public String stateJson; //A8k状态Json + + public static String getTableName() { + return "A8kStateDB" + "Table"; + } + + + +} diff --git a/src/main/java/a8k/service/state_service/A8kStateMgrService.java b/src/main/java/a8k/service/state_service/A8kStateMgrService.java new file mode 100644 index 0000000..faee6ad --- /dev/null +++ b/src/main/java/a8k/service/state_service/A8kStateMgrService.java @@ -0,0 +1,140 @@ +package a8k.service.state_service; + +import a8k.service.appdb.entity.AppUsr; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.iflytop.uf.UfActiveRecord; +import com.iflytop.uf.util.UfJsonHelper; +import jakarta.annotation.PostConstruct; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.json.JacksonJsonParser; +import org.springframework.stereotype.Component; + +@Component +public class A8kStateMgrService { + /* + * 该服务约定: + * 1. 前端只能读取该服务中的状态,不能设置,设置只能通过其他服务进行设置 + * + * + */ + + public static final Logger logger = LoggerFactory.getLogger(A8kStateMgrService.class); + + + AppUsr appusr; //用户是否登录 + AppUsr debugPageUsr; //调试页面用户是否登录 + + Boolean deviceInited = false; //设备是否初始化过 + Boolean devicePoweredOffNormally = false; //设备是否正常关机 + + @PostConstruct + public void init() { + var one = UfActiveRecord.find(A8kStateDB.class).get(0); + if (one == null) { + updateA8kState(new A8kState()); + } + } + + // + // 用户状态 + // + public void loginAppUsr(@NotNull AppUsr appusr) { + this.appusr = appusr; + } + + public void unloginAppUsr() { + this.appusr = null; + } + + public boolean isAppUsrLogin() { + return appusr != null; + } + + + public void loginDebugPageUsr(@NotNull AppUsr debugPageUsr) { + this.debugPageUsr = debugPageUsr; + } + + public void unloginDebugPageUsr() { + this.debugPageUsr = null; + } + + public boolean isDebugPageUsrLogin() { + return debugPageUsr != null; + } + + // + // 设备初始化状态 + // + + /** + * 机器是否初始化过 + * @return 机器是否初始化过 + */ + public boolean isDeviceInited() { + return deviceInited; + } + + /** + * @return 返回上一次设备是否正常关机 + */ + public boolean isTheDevicePoweredOffNormally() { + return devicePoweredOffNormally; + } + + /** + * 设备初始化完成,开机后设备初始化完成时候,调用该方法 + */ + public void setDeviceInited() { + this.deviceInited = true; + this.devicePoweredOffNormally = false; + + A8kState state = getA8kState(); + state.devicePoweredOffNormally = false; + updateA8kState(state); + } + + public void setDevicePoweredOffNormally() { + this.devicePoweredOffNormally = true; + + A8kState state = getA8kState(); + state.devicePoweredOffNormally = true; + updateA8kState(state); + } + + + A8kState getA8kState() { + var one = UfActiveRecord.find(A8kStateDB.class).get(0); + assert one != null; + + ObjectMapper mapper = new ObjectMapper(); + try { + return mapper.readValue(one.stateJson, A8kState.class); + } catch (JsonProcessingException e) { + assert false; + return null; + } + } + + void updateA8kState(A8kState state) { + var one = UfActiveRecord.find(A8kStateDB.class).get(0); + + if (one == null) { + one = new A8kStateDB(); + } + + ObjectMapper mapper = new ObjectMapper(); + + try { + one.stateJson = mapper.writeValueAsString(state); + one.save(); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + +}