Browse Source

recode some code

tags/v0
zhaohe 10 months ago
parent
commit
b63c15dbae
  1. 8
      src/main/java/a8k/service/appdata/AppFrontEndEventRouter.java
  2. 11
      src/main/java/a8k/service/appdata/AppProjInfoMgrService.java
  3. 29
      src/main/java/a8k/service/appdata/AppSettingsMgr.java
  4. 35
      src/main/java/a8k/service/appdata/AppUserMgrService.java
  5. 14
      src/main/java/a8k/service/appdevicectrl/MainFlowCtrlService.java
  6. 24
      src/main/java/a8k/service/devicedriver/calibration/PositionCalibration.java
  7. 36
      src/main/java/a8k/service/devicedriver/commonctrl/HardwareCommonCtrl.java
  8. 26
      src/main/java/a8k/service/devicedriver/ctrl/ReactionPlatesTransmitCtrl.java
  9. 4
      src/main/java/a8k/service/devicedriver/ctrl/SamplesPreProcesCtrl.java
  10. 4
      src/main/java/a8k/service/devicedriver/testscript/TestScript.java
  11. 84
      src/main/java/a8k/type/appret/AppRet.java
  12. 6
      src/main/java/a8k/type/ecode/AppEcode.java

8
src/main/java/a8k/service/appdata/AppFrontEndEventRouter.java

@ -77,15 +77,15 @@ public class AppFrontEndEventRouter implements AppEventListener {
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@ExtApiFn(name = "取出第一个事件")
public AppRet<AppEvent> pollAppEvent() {
public AppEvent pollAppEvent() {
AppEvent event = pollAppEventFromQueue();
return AppRet.success(event);
return (event);
}
@ExtApiFn(name = "读取所有事件(不清空)")
public AppRet<List<AppEvent>> readAllAppEvents() {
public List<AppEvent> readAllAppEvents() {
List<AppEvent> events = new java.util.ArrayList<>(appEventQueue);
return AppRet.success(events);
return (events);
}

11
src/main/java/a8k/service/appdata/AppProjInfoMgrService.java

@ -113,11 +113,11 @@ public class AppProjInfoMgrService implements AppEventListener {
// ID卡管理
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@ExtApiFn(name = "读取当前挂载的ID卡信息", order = ORDER.readIDCardInfo)
public AppRet<A8kIdCardInfo> readMountedIDCardInfo() {
public A8kIdCardInfo readMountedIDCardInfo() throws AppException {
if (mountedIdCardInfo == null) {
return AppRet.fail(A8kEcode.A8kIdCardNotMounted.index);
throw new AppException(A8kEcode.A8kIdCardNotMounted.index);
}
return AppRet.success(mountedIdCardInfo);
return mountedIdCardInfo;
}
@ExtApiFn(name = "保存挂载ID卡信息", order = ORDER.saveIDCardInfo)
@ -126,10 +126,9 @@ public class AppProjInfoMgrService implements AppEventListener {
}
@ExtApiFn(name = "获取ID卡信息列表", order = ORDER.getProjectInfoList)
public AppRet<List<A8kIdCardInfo>> getProjectInfoList() {
return AppRet.success(a8kProjIdCardDBService.getAllIdCards());
public List<A8kIdCardInfo> getProjectInfoList() {
return a8kProjIdCardDBService.getAllIdCards();
}
//TODO: 删除
@ExtApiFn(name = "获取预设项目信息", group = "预设项目信息")

29
src/main/java/a8k/service/appdata/AppSettingsMgr.java

@ -12,6 +12,7 @@ import a8k.controler.extapi.pagecontrol.ExtApiTabConfig;
import a8k.dbservice.type.appsetting.AppSettingTab;
import a8k.dbservice.type.appsetting.AppSettingName;
import a8k.hardware.type.a8kcanprotocol.A8kEcode;
import a8k.type.exception.AppException;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
@ -75,41 +76,41 @@ public class AppSettingsMgr {
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@ExtApiFn(name = "getAppSettings", order = ORDER.getAppSettings)
public AppRet<List<AppSetting>> getAppSettings() {
return AppRet.success(appSettingDBService.getAllSettings());
public List<AppSetting> getAppSettings() {
return (appSettingDBService.getAllSettings());
}
@ExtApiFn(name = "getAppSettingByName", order = ORDER.getAppSettingByName)
public AppRet<AppSetting> getAppSettingByName(AppSettingName name) {
return AppRet.success(appSettingDBService.getSettingByName(name));
public AppSetting getAppSettingByName(AppSettingName name) {
return (appSettingDBService.getSettingByName(name));
}
@ExtApiFn(name = "getAppSettingByTab", order = ORDER.getAppSettingByTab)
public AppRet<List<AppSetting>> getAppSettingByTab(AppSettingTab tab) {
return AppRet.success(appSettingDBService.getSettingsByTab(tab));
public List<AppSetting> getAppSettingByTab(AppSettingTab tab) {
return (appSettingDBService.getSettingsByTab(tab));
}
@ExtApiFn(name = "getTabs", order = ORDER.getTabs)
public AppRet<AppSettingTab[]> getTabs() {
return AppRet.success(AppSettingTab.values());
public AppSettingTab[] getTabs() {
return (AppSettingTab.values());
}
@ExtApiFn(name = "getAppSettingTypesRange", order = ORDER.getAppSettingTypesRange)
public AppRet<AppSettingType[]> getAppSettingTypesRange() {
return AppRet.success(AppSettingType.values());
public AppSettingType[] getAppSettingTypesRange() {
return (AppSettingType.values());
}
@ExtApiFn(name = "getAppSettingNamesRange", order = ORDER.getAppSettingNamesRange)
public AppRet<AppSettingName[]> getAppSettingNamesRange() {
return AppRet.success(AppSettingName.values());
public AppSettingName[] getAppSettingNamesRange() {
return (AppSettingName.values());
}
@ExtApiFn(name = "setOptionVal", order = ORDER.setOptionVal)
public AppRet<AppSetting> setOptionVal(AppSettingName optionName, String val) {
public AppSetting setOptionVal(AppSettingName optionName, String val) throws AppException {
logger.info("setOptionVal {}={}", optionName, val);
if (!isOptionLegal(optionName, val)) {
return AppRet.fail(A8kEcode.FrontendParamTypeError.index);
throw new AppException(A8kEcode.FrontendParamTypeError.index);
}
appSettingDBService.updateSetting(optionName, val);
return getAppSettingByName(optionName);

35
src/main/java/a8k/service/appdata/AppUserMgrService.java

@ -8,6 +8,7 @@ import a8k.dbservice.type.UsrRole;
import a8k.type.appret.AppRet;
import a8k.controler.extapi.utils.ExtApiFn;
import a8k.hardware.type.a8kcanprotocol.A8kEcode;
import a8k.type.exception.AppException;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.springframework.stereotype.Component;
@ -44,16 +45,16 @@ public class AppUserMgrService {
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@ExtApiFn(name = "用户登录", order = ORDER.login)
public AppRet<AppUser> login(String account, String password) {
public AppUser login(String account, String password) throws AppException {
var usr = appUsrDBService.getUsrByAccount(account);
if (usr == null)
return AppRet.fail(A8kEcode.UsrNotExitError.index);
throw new AppException(A8kEcode.UsrNotExitError.index);
if (!usr.password.equals(password)) {
return AppRet.fail(A8kEcode.UsrPasswdError.index);
throw new AppException(A8kEcode.UsrPasswdError.index);
}
loginUsr = usr;
return AppRet.success(usr);
return (usr);
}
@ExtApiFn(name = "用户登出", order = ORDER.unlogin)
@ -62,21 +63,21 @@ public class AppUserMgrService {
}
@ExtApiFn(name = "获取当前用户", order = ORDER.getLoginUsr)
public AppRet<AppUser> getLoginUsr() {
return AppRet.success(loginUsr);
public AppUser getLoginUsr() {
return (loginUsr);
}
@ExtApiFn(name = "获取用户列表", order = ORDER.getUsrlist)
public AppRet<List<AppUser>> getUsrlist() {
return AppRet.success(appUsrDBService.getAllUsr());
public List<AppUser> getUsrlist() {
return (appUsrDBService.getAllUsr());
}
@ExtApiFn(name = "用户添加", order = ORDER.addUser)
public AppRet<List<AppUser>> addUser(String account, String password, UsrRole type) {
public List<AppUser> addUser(String account, String password, UsrRole type) throws AppException {
var user = appUsrDBService.getUsrByAccount(account);
if (user != null) {
return AppRet.fail(A8kEcode.UsrAlreadyExistError.index);
throw new AppException(A8kEcode.UsrAlreadyExistError.index);
}
user = new AppUser(account, password, type);
appUsrDBService.addUser(user);
@ -84,16 +85,16 @@ public class AppUserMgrService {
}
@ExtApiFn(name = "删除用户", order = ORDER.delUser)
public AppRet<List<AppUser>> delUser(String account) {
public List<AppUser> delUser(String account) {
appUsrDBService.deleteUserByAccount(account);
return getUsrlist();
}
@ExtApiFn(name = "修改用户密码", order = ORDER.modifyUsrPwd)
public AppRet<List<AppUser>> modifyUsrPwd(String account, String password) {
public List<AppUser> modifyUsrPwd(String account, String password) throws AppException {
var user = appUsrDBService.getUsrByAccount(account);
if (user == null) {
return AppRet.fail(A8kEcode.UsrNotExitError.index);
throw new AppException(A8kEcode.UsrNotExitError.index);
}
user.password = password;
appUsrDBService.updateUser(user);
@ -101,10 +102,10 @@ public class AppUserMgrService {
}
@ExtApiFn(name = "修改用户权限", order = ORDER.modifyUsrRole)
public AppRet<List<AppUser>> modifyUsrRole(String account, UsrRole usrRole) {
public List<AppUser> modifyUsrRole(String account, UsrRole usrRole) throws AppException {
var user = appUsrDBService.getUsrByAccount(account);
if (user == null) {
return AppRet.fail(A8kEcode.UsrNotExitError.index);
throw new AppException(A8kEcode.UsrNotExitError.index);
}
user.usrRole = usrRole;
appUsrDBService.updateUser(user);
@ -112,10 +113,10 @@ public class AppUserMgrService {
}
@ExtApiFn(name = "修改用户名称", order = ORDER.modifyUsrAccount)
public AppRet<List<AppUser>> modifyUsrAccount(String account, String newaccount) {
public List<AppUser> modifyUsrAccount(String account, String newaccount) throws AppException {
var user = appUsrDBService.getUsrByAccount(account);
if (user == null) {
return AppRet.fail(A8kEcode.UsrNotExitError.index);
throw new AppException(A8kEcode.UsrNotExitError.index);
}
user.account = newaccount;
appUsrDBService.updateUser(user);

14
src/main/java/a8k/service/appdevicectrl/MainFlowCtrlService.java

@ -46,13 +46,13 @@ public class MainFlowCtrlService {
logger.info("className {}",DO_STOP.class.getName());
for (A8kActionStepType actionType : A8kActionStepType.values()) {
if (actionType.equals(A8kActionStepType.DO_CLEAR_ERROR)) {
continue;
}
A8kStepAction action = SpringBootBeanUtil.getBean(actionType.name(), A8kStepAction.class);
scheduler.regFn(action);
}
// for (A8kActionStepType actionType : A8kActionStepType.values()) {
// if (actionType.equals(A8kActionStepType.DO_CLEAR_ERROR)) {
// continue;
// }
// A8kStepAction action = SpringBootBeanUtil.getBean(actionType.name(), A8kStepAction.class);
// scheduler.regFn(action);
// }
//启动调度
scheduler.startScheduler();

24
src/main/java/a8k/service/devicedriver/calibration/PositionCalibration.java

@ -59,34 +59,34 @@ public class PositionCalibration {
@ExtApiFn(name = "试管夹平移电机-读取位置", group = "通过归零测量位置")
public AppRet<Integer> readXPosByMoveZero() throws AppException {
return AppRet.success(canBus.stepMotorReadPosByMoveToZeroBlock(MId.FeedingModXM, timep.getActionOvertime()));
public Integer readXPosByMoveZero() throws AppException {
return (canBus.stepMotorReadPosByMoveToZeroBlock(MId.FeedingModXM, timep.getActionOvertime()));
}
@ExtApiFn(name = "通过归零读取<板夹仓>位置", group = "通过归零测量位置")
public AppRet<Integer> readPlatesBoxYMPosByMoveToZero() throws AppException {
return AppRet.success(canBus.stepMotorReadPosByMoveToZeroBlock(MId.PlatesBoxYM, timep.getActionOvertime()));
public Integer readPlatesBoxYMPosByMoveToZero() throws AppException {
return (canBus.stepMotorReadPosByMoveToZeroBlock(MId.PlatesBoxYM, timep.getActionOvertime()));
}
@ExtApiFn(name = "通过归零读取<推杆>位置", group = "通过归零测量位置")
public AppRet<Integer> readPlatesBoxPusherMPosByMoveToZero() throws AppException {
return AppRet.success(canBus.stepMotorReadPosByMoveToZeroBlock(MId.PlatesBoxPusherM, timep.getActionOvertime()));
public Integer readPlatesBoxPusherMPosByMoveToZero() throws AppException {
return (canBus.stepMotorReadPosByMoveToZeroBlock(MId.PlatesBoxPusherM, timep.getActionOvertime()));
}
@ExtApiFn(name = "通过归零读取<拉杆>位置", group = "通过归零测量位置")
public AppRet<Integer> readOptModPullMPosByMoveToZero() throws AppException {
return AppRet.success(canBus.stepMotorReadPosByMoveToZeroBlock(MId.OptModPullM, timep.getActionOvertime()));
public Integer readOptModPullMPosByMoveToZero() throws AppException {
return (canBus.stepMotorReadPosByMoveToZeroBlock(MId.OptModPullM, timep.getActionOvertime()));
}
@ExtApiFn(name = "通过归零读取<光学模组扫描器>位置", group = "通过归零测量位置")
public AppRet<Integer> readOptModScannerMPosByMoveToZero() throws AppException {
return AppRet.success(canBus.stepMotorReadPosByMoveToZeroBlock(MId.OptModScannerM, timep.getActionOvertime()));
public Integer readOptModScannerMPosByMoveToZero() throws AppException {
return (canBus.stepMotorReadPosByMoveToZeroBlock(MId.OptModScannerM, timep.getActionOvertime()));
}
@ExtApiFn(name = "通过归零读取<摇匀模组Z轴>位置", group = "通过归零测量位置")
public AppRet<Integer> readShakeModGripperZMPosByMoveToZero() throws AppException {
return AppRet.success(canBus.stepMotorReadPosByMoveToZeroBlock(MId.ShakeModGripperZM, timep.getActionOvertime()));
public Integer readShakeModGripperZMPosByMoveToZero() throws AppException {
return (canBus.stepMotorReadPosByMoveToZeroBlock(MId.ShakeModGripperZM, timep.getActionOvertime()));
}

36
src/main/java/a8k/service/devicedriver/commonctrl/HardwareCommonCtrl.java

@ -44,43 +44,41 @@ public class HardwareCommonCtrl {
// CHECK
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
private AppRet<Object> checkDeviceStateBeforeRunToZero() throws AppException {
private void checkDeviceStateBeforeRunToZero() throws AppException {
logger.info("checkDeviceStateBeforeRunToZero");
//试管平移通道是否有障碍
if (canBus.getIOState(IOId.THChInterPPS) || canBus.getIOState(IOId.THChOuterPPS)) {
logger.warn("THChInterPPS or THChOuterPPS is trigger");
return AppRet.fail(A8kEcode.TubeXChannelIsNotEmpty.index);
throw new AppException(A8kEcode.TubeXChannelIsNotEmpty.index);
}
//板夹仓盖子是否盖上
if (!canBus.getIOState(IOId.PlateBoxCoverClosurePPS)) {
return AppRet.fail(A8kEcode.PlateBoxNotCover.index);
throw new AppException(A8kEcode.PlateBoxNotCover.index);
}
//板夹仓卡板检测
if (canBus.getIOState(IOId.PlateBoxPlateStuckPPS)) {
return AppRet.fail(A8kEcode.PlateStuckDetectorSensorTrigger.index);
throw new AppException(A8kEcode.PlateStuckDetectorSensorTrigger.index);
}
//检查钩板电机是否处于终点位置
if (!canBus.getIOState(IOId.PullerMZeroPPS)) {
return AppRet.fail(A8kEcode.PullerMInitPosError.index);
throw new AppException(A8kEcode.PullerMInitPosError.index);
}
//检查板夹仓光电是否处于起点位置
if (!canBus.getIOState(IOId.PusherMZeroPPS)) {
return AppRet.fail(A8kEcode.PusherMInitPosError.index);
throw new AppException(A8kEcode.PusherMInitPosError.index);
}
//板夹仓光电
if (canBus.getIOState(IOId.RecycleBinOverflowPPS)) {
return AppRet.fail(A8kEcode.RecycleBinOverflow.index);
throw new AppException(A8kEcode.RecycleBinOverflow.index);
}
return AppRet.success();
}
private AppRet<Object> moveMotorToZero() throws AppException {
private void moveMotorToZero() throws AppException {
//进出料初始化
canBus.stepMotorEasyMoveToZeroBlock(MId.FeedingModXM, timep.getRuntoZeroActionOvertime());
@ -110,16 +108,13 @@ public class HardwareCommonCtrl {
// TODO canBus.stepMotorEasyMoveToZeroBlock(MId.PipetteModZM, timep.getRuntoZeroActionOvertime());
//转盘归零
canBus.stepMotorEasyMoveToZeroBlock(MId.IncubatorRotateCtrlM, timep.getRuntoZeroActionOvertime());
return AppRet.success();
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Expose API
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@ExtApiFn(name = "设备初始化", order = ORDER.initializeDevice)
public AppRet<String> initializeDevice() throws AppException {
public void initializeDevice() throws AppException {
logger.info("Initializing device ...");
boolean initSuc = false;
workState = true;
@ -129,16 +124,12 @@ public class HardwareCommonCtrl {
canBus.setIOState(IOId.RecycleBinOverflowPPSPowerCtrl, true);
//检查设备状态
ecode = checkDeviceStateBeforeRunToZero();
if (!ecode.isSuccess()) {
return AppRet.fail(ecode);
}
checkDeviceStateBeforeRunToZero();
// 复位设备
logger.info("moveMotorToZero");
ecode = moveMotorToZero();
if (!ecode.isSuccess()) {
return AppRet.fail(ecode);
}
moveMotorToZero();
initSuc = true;
logger.info("Device initialization completed");
@ -154,7 +145,6 @@ public class HardwareCommonCtrl {
}
}
}
return AppRet.success("初始化完成");
}

26
src/main/java/a8k/service/devicedriver/ctrl/ReactionPlatesTransmitCtrl.java

@ -128,13 +128,13 @@ public class ReactionPlatesTransmitCtrl {
@ExtApiFn(name = "推板", group = "单步")
public AppRet<PlateInfo> pushPlate(ConsumableGroup PBCh, IncubatorPos turntablePosIndex) throws AppException {
public PlateInfo pushPlate(ConsumableGroup PBCh, IncubatorPos turntablePosIndex) throws AppException {
trunableMoveToPushPos(turntablePosIndex);
canBus.stepMotorEasyMoveToBlock(MId.PlatesBoxYM, pp.getPBCh0Pos() + PBCh.off * pp.getPBChSpacing(), timep.getActionOvertime());
canBus.plateCodeScanerPushCardAndScanBlock(MId.PlatesBoxScanner, pp.getPusherEndPos(), 10000);
canBus.stepMotorEasyMoveToZeroPointQuickBlock(MId.PlatesBoxPusherM, timep.getActionOvertime());
canBus.stepMotorEasyMoveToZeroPointQuickBlock(MId.PlatesBoxYM, timep.getActionOvertime());
return AppRet.success(canBus.plateCodeScannerReadCode(MId.PlatesBoxScanner));
return (canBus.plateCodeScannerReadCode(MId.PlatesBoxScanner));
}
public void pushPlateQuick(ConsumableGroup PBCh, IncubatorPos turntablePosIndex) throws AppException {
@ -175,7 +175,7 @@ public class ReactionPlatesTransmitCtrl {
// return AppRet.success(new A8kScanCurve(scanDataCurve, refLine));
// }
private AppRet<A8kScanCurve> packetOptDisplayScanCurve(List<Integer> scanDataCurve) {
private A8kScanCurve packetOptDisplayScanCurve(List<Integer> scanDataCurve) {
A8kScanCurve scanCurve = new A8kScanCurve();
logger.info("pointNum: " + scanDataCurve.size());
scanCurve.scanDataCurve = A8kOptAlgo.preProcessOptData(scanDataCurve);
@ -185,20 +185,20 @@ public class ReactionPlatesTransmitCtrl {
for (int i = 1; i < 6; i++) {
scanCurve.refLine.add(40 * i);
}
return AppRet.success(scanCurve);
return scanCurve;
}
@ExtApiFn(name = "T光学扫码", group = "光学调试")
public AppRet<A8kScanCurve> optTScan(OptScanDirection direction, Integer scanerGain) throws AppException {
// canBus.moduleSetReg(MId.OptMod, RegIndex.kreg_a8k_opt_t_pos_offset, getTOptPosOffset());
// canBus.moduleSetReg(MId.OptMod, RegIndex.kreg_a8k_opt_t_reverse_scan_pos_offset,getTOptPosOffset()-1200);
// canBus.optTStartScanBlock(MId.OptMod, direction, getOptTLasterGain(), scanerGain, getOptScanOvertime());
// return packetOptDisplayScanCurve(canBus.optReadRaw(MId.OptMod));
return AppRet.fail(A8kEcode.CmdNotSupport.index);
}
// @ExtApiFn(name = "T光学扫码", group = "光学调试")
// public A8kScanCurve optTScan(OptScanDirection direction, Integer scanerGain) throws AppException {
// // canBus.moduleSetReg(MId.OptMod, RegIndex.kreg_a8k_opt_t_pos_offset, getTOptPosOffset());
// // canBus.moduleSetReg(MId.OptMod, RegIndex.kreg_a8k_opt_t_reverse_scan_pos_offset,getTOptPosOffset()-1200);
// // canBus.optTStartScanBlock(MId.OptMod, direction, getOptTLasterGain(), scanerGain, getOptScanOvertime());
// // return packetOptDisplayScanCurve(canBus.optReadRaw(MId.OptMod));
// return A8kEcode.CmdNotSupport.index;
// }
@ExtApiFn(name = "F光学扫码", group = "光学调试")
public AppRet<A8kScanCurve> optFScan(OptScanDirection direction, Integer scanerGain) throws AppException {
public A8kScanCurve optFScan(OptScanDirection direction, Integer scanerGain) throws AppException {
//getFOptPosOffset
canBus.moduleSetReg(MId.OptMod, RegIndex.kreg_a8k_opt_f_pos_offset, pp.getFOptPosOffset());
canBus.moduleSetReg(MId.OptMod, RegIndex.kreg_a8k_opt_f_reverse_scan_pos_offset, pp.getFOptPosOffset() - 1200);

4
src/main/java/a8k/service/devicedriver/ctrl/SamplesPreProcesCtrl.java

@ -112,7 +112,7 @@ public class SamplesPreProcesCtrl {
* @param highTube true/false
*/
@ExtApiFn(name = "取试管", group = "单步", order = ORDER.takeTubeAndJudgeTubeExist)
public AppRet<Boolean> takeTubeAndJudgeTubeExist(Boolean highTube) throws AppException {
public Boolean takeTubeAndJudgeTubeExist(Boolean highTube) throws AppException {
/*
* 校验:
* 1.当前摇匀模组设计到的电机是否都处于待机位
@ -194,7 +194,7 @@ public class SamplesPreProcesCtrl {
} else {
modGroupMoveToZeroQuick();
}
return AppRet.success(tubeCapExist);
return tubeCapExist;
}
@ExtApiFn(name = "摇匀", group = "单步", order = ORDER.shakeTube)

4
src/main/java/a8k/service/devicedriver/testscript/TestScript.java

@ -197,7 +197,7 @@ public class TestScript {
}
@ExtApiFn(name = "测试摇匀模组", group = "摇匀模组测试", order = ORDER.testSamplePreProcessModule)
public AppRet<Object> testSamplePreProcessModule() throws AppException {
public Object testSamplePreProcessModule() throws AppException {
// checkTestScriptWorkFlag();
// testScriptWorkFlag = true;
@ -236,7 +236,7 @@ public class TestScript {
// testScriptWorkFlag = false;
// }
return AppRet.message("测试完成", null);
return null;
}

84
src/main/java/a8k/type/appret/AppRet.java

@ -1,6 +1,6 @@
package a8k.type.appret;
import a8k.type.ecode.ErrorContext;
import a8k.type.ecode.AppEcode;
import a8k.hardware.type.a8kcanprotocol.CmdId;
import a8k.hardware.type.a8kcanprotocol.MId;
import a8k.hardware.type.a8kcanprotocol.A8kEcode;
@ -8,26 +8,16 @@ import a8k.type.exception.AppException;
import lombok.Getter;
public class AppRet<T> {
AppRetType appRetType = AppRetType.SUCCESS;
public AppRetType appRetType = AppRetType.SUCCESS;
// 错误信息
@Getter
ErrorContext ecode = null;
public AppEcode ecode = null;
// 显示给用户的内容
@Getter
String message = null;
public String message = null;
//异常触发上下文
@Getter
String traceInfo = null;
public String traceInfo = null;
// 携带的对象
@Getter
String dataType;
@Getter
T data;
public String dataType;
public T data;
// 接口请求时间
@Getter
@ -41,19 +31,10 @@ public class AppRet<T> {
return !AppRetType.FAILURE.equals(appRetType);
}
public static <T> AppRet<T> message(String message, T data) {
AppRet<T> r = new AppRet<>();
r.appRetType = AppRetType.SUCCESS;
r.message = message;
r.dataType = null == data ? null : data.getClass().getSimpleName();
return r;
}
public static <T> AppRet<T> success(T data) {
AppRet<T> r = new AppRet<>();
r.data = data;
r.appRetType = AppRetType.SUCCESS;
r.dataType = null == data ? null : data.getClass().getSimpleName();
r.data = data;
return r;
}
@ -63,51 +44,6 @@ public class AppRet<T> {
return r;
}
public static <T> AppRet<T> fail(Integer errorCode, MId mid, CmdId cmd) {
AppRet<T> r = new AppRet<>();
r.appRetType = AppRetType.FAILURE;
r.ecode = new ErrorContext(errorCode, mid, cmd);
r.message = r.ecode.toDisPlayString();
return r;
}
public static <T> AppRet<T> fail(Integer errorCode, MId mid) {
AppRet<T> r = new AppRet<>();
r.appRetType = AppRetType.FAILURE;
r.ecode = new ErrorContext(errorCode, mid, null);
r.message = r.ecode.toDisPlayString();
return r;
}
public static <T> AppRet<T> fail(Integer errorCode) {
AppRet<T> r = new AppRet<>();
r.appRetType = AppRetType.FAILURE;
r.ecode = new ErrorContext(errorCode, null, null);
r.message = r.ecode.toDisPlayString();
return r;
}
public static <T> AppRet<T> fail(Integer errorCode,String message) {
AppRet<T> r = new AppRet<>();
r.appRetType = AppRetType.FAILURE;
r.ecode = new ErrorContext(errorCode, null, null);
r.message = message;
return r;
}
public static <T> AppRet<T> fail(AppRet<Object> ret) {
AppRet<T> r = new AppRet<>();
r.appRetType = AppRetType.FAILURE;
r.ecode = new ErrorContext(ret.getEcode().code, ret.getEcode().relateMid, ret.getEcode().relateCmd);
r.data = null;
r.message = r.ecode.toDisPlayString();
return r;
}
public static <T> AppRet<T> fail(Exception e) {
StringBuilder traceSb = new StringBuilder();
for (var trace : e.getStackTrace()) {
@ -118,7 +54,7 @@ public class AppRet<T> {
r.appRetType = AppRetType.FAILURE;
if (e instanceof AppException hexcep) {
r.ecode = new ErrorContext(hexcep.getErrorCode(), hexcep.getModuleId(), hexcep.getCmdId());
r.ecode = new AppEcode(hexcep.getErrorCode(), hexcep.getModuleId(), hexcep.getCmdId());
r.traceInfo = trace;
r.message = r.ecode.toDisPlayString();
if (hexcep.getExtmessage() != null) {
@ -126,7 +62,7 @@ public class AppRet<T> {
}
} else {
r.ecode = new ErrorContext(A8kEcode.CodeError.index, null, null);
r.ecode = new AppEcode(A8kEcode.CodeError.index, null, null);
r.traceInfo = trace;
r.message = e.getMessage();
}

6
src/main/java/a8k/type/ecode/ErrorContext.java → src/main/java/a8k/type/ecode/AppEcode.java

@ -4,13 +4,13 @@ import a8k.hardware.type.a8kcanprotocol.A8kEcode;
import a8k.hardware.type.a8kcanprotocol.CmdId;
import a8k.hardware.type.a8kcanprotocol.MId;
public class ErrorContext {
public class AppEcode {
public Integer code;
public String codeName;
public MId relateMid;
public CmdId relateCmd;
public ErrorContext(Integer errorCode, MId mid, CmdId cmd) {
public AppEcode(Integer errorCode, MId mid, CmdId cmd) {
this.code = errorCode;
this.codeName = A8kEcode.toDisPlayString(errorCode);
this.relateMid = mid;
@ -28,4 +28,4 @@ public class ErrorContext {
}
return info;
}
}
}
Loading…
Cancel
Save