Commit f06b450c zshaohui

1.版本回退

2.提交指令功能代码
1 个父辈 d552d15a
package com.myproject.bean;
public class Command {
private String cid;
private String name;
private Integer value;
@Override
public String toString() {
return "Command{" +
"cid='" + cid + '\'' +
", name='" + name + '\'' +
", value=" + value +
'}';
}
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
}
...@@ -220,6 +220,10 @@ public class StatusBean { ...@@ -220,6 +220,10 @@ public class StatusBean {
public void addOp(Map<String, String> opMap){ public void addOp(Map<String, String> opMap){
if(opMap != null && !opMap.isEmpty()){ if(opMap != null && !opMap.isEmpty()){
for (Map.Entry<String, String> op : opMap.entrySet()) { for (Map.Entry<String, String> op : opMap.entrySet()) {
if ("NEED_EMPTY".equals(op.getKey()) || "TAKE_STATUS".equals(op.getKey())
|| "OUT_STATUS".equals(op.getKey()) || "IN_STATUS".equals(op.getKey())) {
continue;
}
data.put(op.getKey(), op.getValue()); data.put(op.getKey(), op.getValue());
} }
} }
......
package com.myproject.webapp.controller;
import com.myproject.bean.Command;
import com.myproject.bean.json.ResultBean;
import com.myproject.bean.utils.StatusBean;
import com.myproject.webapp.controller.webService.ITaskService;
import com.myproject.webapp.controller.webService.StorageDataController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Map;
@RequestMapping("/smf/rest/api")
public class CommandController {
@Autowired
private ITaskService taskService;
protected final transient Logger log = LogManager.getLogger(getClass());
/**
* 接收指令
*
* @param command
* @return
*/
@RequestMapping(value = "/opDeviceIo")
public ResultBean opDeviceIo(@RequestBody Command command) {
String cid = command.getCid();
String name = command.getName();
Integer value = command.getValue();
log.info("{}收到数据为:{}", "opDeviceIo", cid + "--" + "--" + name + "--" + value);
if ("NEED_EMPTY".equals(name) || "TAKE_STATUS".equals(name)
|| "OUT_STATUS".equals(name) || "IN_STATUS".equals(name)) {
return ResultBean.newErrorResult(-1,"No Implementation");
}
String opValue = "";
if (value == 0) {
opValue = "close";
} else if (value == 1) {
opValue = "open";
}
StorageDataController.addOp(cid, name, opValue);
return ResultBean.newOkResult("");
}
/**
* 获取指定
*
* @param params
* @return
*/
@RequestMapping(value = "/getStatus")
public ResultBean getStatus(@RequestBody Map<String, String> params) {
String cid = params.get("cid");
String name = params.get("name");
log.info("{}收到数据为:{}", "getStatus", cid + "--" + "--" + name);
if ("NEED_EMPTY".equals(name) || "TAKE_STATUS".equals(name)
|| "OUT_STATUS".equals(name) || "IN_STATUS".equals(name)) {
return ResultBean.newErrorResult(-1, "No Implementation");
}
StatusBean statusBean = taskService.getStatus(cid);
log.info("是否存在为:" + statusBean == null);
if (statusBean != null) {
String value = statusBean.getFromData(name);
Integer opValue = null;
if ("open".equals(value) || "1".equals(value)) {
opValue = 1;
} else if ("close".equals(value) || "0".equals(value)) {
opValue = 0;
}
if (opValue != null) {
return ResultBean.newOkResult(opValue);
}
}
return ResultBean.newErrorResult(-1, "Not Found");
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!