parent
9957bc97d7
commit
9f9c22e8a8
6 changed files with 168 additions and 5 deletions
@ -0,0 +1,62 @@ |
|||||||
|
package org.springblade.lims.capital.controller; |
||||||
|
|
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.apache.poi.ss.formula.functions.T; |
||||||
|
import org.springblade.core.boot.ctrl.BladeController; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.SpringUtil; |
||||||
|
import org.springblade.core.tool.utils.StringUtil; |
||||||
|
import org.springblade.lims.commands.Command; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
import java.util.concurrent.ConcurrentHashMap; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Description 扫描枪扫描执行命令相关 |
||||||
|
* @Author ytl |
||||||
|
* @Date 2022/9/23 0023 14:29 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@AllArgsConstructor |
||||||
|
@RequestMapping("/command") |
||||||
|
@Api(value = "扫描枪扫描执行命令相关", tags = "扫描枪扫描执行命令相关") |
||||||
|
public class CommandController extends BladeController { |
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/execute") |
||||||
|
@ApiOperation(value = "执行命令", notes = "传入扫描枪扫描的命令字符串,里面必然携带要执行的命令的名称") |
||||||
|
public R execute(String commandStr){ |
||||||
|
boolean result = false; |
||||||
|
//解析commandStr
|
||||||
|
Map<String,Object> params = this.commandAnalysis(commandStr); |
||||||
|
|
||||||
|
Object bean = SpringUtil.getBean("command_" + String.valueOf(params.get("name"))); |
||||||
|
if(bean instanceof Command){ |
||||||
|
result = executeCommand((Command) bean, params); |
||||||
|
} |
||||||
|
|
||||||
|
if(result){ |
||||||
|
return R.success("命令执行成功"); |
||||||
|
}else{ |
||||||
|
return R.fail("命令执行失败,没有找到相关命令"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private boolean executeCommand(Command c, Map<String,Object> s){ |
||||||
|
return c.execute(s); |
||||||
|
} |
||||||
|
|
||||||
|
private Map<String,Object> commandAnalysis(String s){ |
||||||
|
Map<String,Object> map = new ConcurrentHashMap<>(); |
||||||
|
|
||||||
|
//通过某种格式解析指令
|
||||||
|
|
||||||
|
map.put("name","test"); |
||||||
|
return map; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
package org.springblade.lims.commands; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Description 命令的抽象类 |
||||||
|
* @Author ytl |
||||||
|
* @Date 2022/9/23 0023 14:16 |
||||||
|
*/ |
||||||
|
public abstract class Command { |
||||||
|
/** |
||||||
|
* 命令的名称 |
||||||
|
*/ |
||||||
|
String name; |
||||||
|
|
||||||
|
/** |
||||||
|
* 命令的执行 |
||||||
|
* @param params 命令的参数 |
||||||
|
* @return true命令执行成功,false命令执行失败 |
||||||
|
*/ |
||||||
|
public abstract boolean execute(Map<String,Object> params); |
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
package org.springblade.lims.commands.commandutils; |
||||||
|
|
||||||
|
import org.springblade.lims.commands.Command; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Description 测试命令 |
||||||
|
* @Author ytl |
||||||
|
* @Date 2022/9/23 0023 14:24 |
||||||
|
*/ |
||||||
|
@Component("command_test") |
||||||
|
public class CommandTest extends Command { |
||||||
|
|
||||||
|
private String name; |
||||||
|
|
||||||
|
public CommandTest(){ |
||||||
|
this.name = "CommandTest"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean execute(Map<String,Object> params){ |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue