java OpCode.Login_Result.getValue() 转换成string
时间: 2023-11-28 19:47:38 浏览: 42
你可以使用Java中枚举类的name()方法来获取枚举常量的名称,然后将其转换为字符串。
假设Login_Result是一个枚举类型,你可以使用以下代码将其转换为字符串:
```
String result = Login_Result.getValue().name();
```
其中,Login_Result.getValue()是获取枚举常量的方式,name()是枚举常量的名称。
相关问题
代码优化 public Result phmOperate(Operation<PhmOperation,PhmCause> operation) { HlwExmMessage msg = messageService.queryMsgById(operation.getMsgId()); if (msg!=null){ if (msg.getOperateMsgId()!=null){ return new Result<>(Status.UN_ACCESS_OPERATION,"消息已处置,重复处置无效!"); } HlwExmMessage<DocOperateMsg> msg2 = messageService.queryDocToPhmMsg(msg.getTaskId()); Integer msgId2 = msg2==null?null:msg2.getMsgId(); if (!Objects.equals(msg.getMsgId(),msgId2)){ //当前被处置消息与任务最后一条消息不是同一条消息, //原因:第一次审查通过后,药师正准备提交审方结果时,医生重新修改医嘱提交,造成药师审核的医嘱信息已过期。 // 最终会形成一个审方任务干预记录中有两个及以上药师审核通过,也有可能药师不通过,造成审方流程错乱 return new Result(Status.UN_ACCESS_OPERATION,"被处置消息已过期,处置无效,医生已修改医嘱,请刷新任务!"); } Integer forward = msg.getForward(); if (HlwExmMessage.FORWARD_DOC_TO_PHM.equals(forward)){ List<String> operations = msg.getOperations(); //处置代码 PhmOperation opCode = operation.getOperation(); if (operations.contains(opCode.name())){//校验操作是否合法。每个消息可处置方式不同: return operate(operation, msg, opCode)? Result.SUCCESS: new Result<>(Status.UN_ACCESS_OPERATION, "当次就诊已作废,处置失败!"); }else { return new Result<>(Status.ERROR,"非法处置:当前消息可选择的处置方式"+operations.toString()); } } } return new Result<>(Status.ERROR,"被处置消息无效!"); }
可以考虑对代码进行以下优化:
1. 使用早期返回,避免嵌套过深
将代码中的嵌套if语句改为使用早期返回,可以减少代码的嵌套深度,提高代码可读性。
```java
public Result phmOperate(Operation<PhmOperation,PhmCause> operation) {
HlwExmMessage msg = messageService.queryMsgById(operation.getMsgId());
if (msg == null) {
return new Result<>(Status.ERROR, "被处置消息无效!");
}
if (msg.getOperateMsgId() != null) {
return new Result<>(Status.UN_ACCESS_OPERATION, "消息已处置,重复处置无效!");
}
HlwExmMessage<DocOperateMsg> msg2 = messageService.queryDocToPhmMsg(msg.getTaskId());
Integer msgId2 = msg2 == null ? null : msg2.getMsgId();
if (!Objects.equals(msg.getMsgId(), msgId2)) {
return new Result(Status.UN_ACCESS_OPERATION, "被处置消息已过期,处置无效,医生已修改医嘱,请刷新任务!");
}
Integer forward = msg.getForward();
if (!HlwExmMessage.FORWARD_DOC_TO_PHM.equals(forward)) {
return new Result<>(Status.ERROR, "被处置消息无效!");
}
List<String> operations = msg.getOperations();
PhmOperation opCode = operation.getOperation();
if (!operations.contains(opCode.name())) {
return new Result<>(Status.ERROR, "非法处置:当前消息可选择的处置方式" + operations.toString());
}
return operate(operation, msg, opCode) ? Result.SUCCESS : new Result<>(Status.UN_ACCESS_OPERATION, "当次就诊已作废,处置失败!");
}
```
2. 封装判断逻辑
将判断消息是否有效、是否已被处理、是否过期等逻辑封装为一个方法,提高代码可读性。
```java
private boolean isValidMsg(HlwExmMessage msg) {
if (msg == null) {
return false;
}
if (msg.getOperateMsgId() != null) {
return false;
}
HlwExmMessage<DocOperateMsg> msg2 = messageService.queryDocToPhmMsg(msg.getTaskId());
Integer msgId2 = msg2 == null ? null : msg2.getMsgId();
if (!Objects.equals(msg.getMsgId(), msgId2)) {
return false;
}
Integer forward = msg.getForward();
if (!HlwExmMessage.FORWARD_DOC_TO_PHM.equals(forward)) {
return false;
}
return true;
}
public Result phmOperate(Operation<PhmOperation,PhmCause> operation) {
HlwExmMessage msg = messageService.queryMsgById(operation.getMsgId());
if (!isValidMsg(msg)) {
return new Result<>(Status.ERROR, "被处置消息无效!");
}
List<String> operations = msg.getOperations();
PhmOperation opCode = operation.getOperation();
if (!operations.contains(opCode.name())) {
return new Result<>(Status.ERROR, "非法处置:当前消息可选择的处置方式" + operations.toString());
}
return operate(operation, msg, opCode) ? Result.SUCCESS : new Result<>(Status.UN_ACCESS_OPERATION, "当次就诊已作废,处置失败!");
}
```
3. 方法命名规范化
为了代码的可维护性,建议将方法命名规范化,比如将phmOperate改为operatePhm。
```java
private boolean isValidMsg(HlwExmMessage msg) {
...
}
public Result operatePhm(Operation<PhmOperation,PhmCause> operation) {
HlwExmMessage msg = messageService.queryMsgById(operation.getMsgId());
if (!isValidMsg(msg)) {
return new Result<>(Status.ERROR, "被处置消息无效!");
}
List<String> operations = msg.getOperations();
PhmOperation opCode = operation.getOperation();
if (!operations.contains(opCode.name())) {
return new Result<>(Status.ERROR, "非法处置:当前消息可选择的处置方式" + operations.toString());
}
return operate(operation, msg, opCode) ? Result.SUCCESS : new Result<>(Status.UN_ACCESS_OPERATION, "当次就诊已作废,处置失败!");
}
```
write6的scsi命令,ucd_req_ptr->header.dword_2怎么配
对于 `write6` SCSI 命令,需要将 `ucd_req_ptr->header.dword_2` 的值设置为 `0x0`。这是因为 `write6` 命令是一个简单的写入命令,不需要设置传输类型、数据方向、命令类型等参数。
下面是一个示例代码,展示了如何构造一个 `write6` 命令的命令描述符结构体:
```
struct ufs_cmd_descriptor desc = {
.header.dword_0 = UFS_CMD_DESC_HEADER_DWORD_0(UFS_OPCODE_WRITE6, UFS_CMD_DESC_REQ_UPIU, 0, 0),
.header.dword_1 = UFS_CMD_DESC_HEADER_DWORD_1(0, 0, 0),
.header.dword_2 = 0x0, // 设置为0,表示简单的写入命令
.data_segment_len = 0,
.data_transfer_req = NULL,
.task_tag = 0,
.expected_data_len = 0,
.expected_data_transfer_req = NULL,
.expected_data_dir = UFS_EXPECTED_DATA_DIR_NONE,
.expected_data_buffer = NULL
};
```
在上面的示例代码中,我们通过将 `header.dword_2` 设置为 `0x0` 来表示该命令是一个简单的写入命令。其他的命令描述符成员根据具体需求进行配置即可。
需要注意的是,上面的示例代码仅供参考,具体的命令描述符配置方法还需要根据具体的应用场景和硬件实现来确定。同时,在实际使用中,还需要对命令描述符进行错误检查和处理,以保证命令的正确执行。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)