Commit 168bdb36 zshaohui

1.1562亮灯接口开发

1 个父辈 bed2ce24
package com.neotel.smfcore.custom.Inventec1562.bean;
import lombok.Data;
@Data
public class AllLightsTurnOff {
private String ledBoard;
private String color;
private String reelShelfIp;
}
package com.neotel.smfcore.custom.Inventec1562.bean;
import lombok.Data;
@Data
public class AllLightsTurnOn {
private String ledBoard;
private String color;
private String reelShelfIp;
}
package com.neotel.smfcore.custom.Inventec1562.bean;
import lombok.Data;
@Data
public class LighthouseControl {
/**
* Return value:True/False
* Parameters:
* LedBoard:Shelf number, take the first 3 digits of the Storage location number , do not accept arrays.
* Color:R/Y -red,G/P-green,B/C-blue
* On the side of shelf location 1-700: R-red,G-green,B-blue
* On the side of shelf location 701-1400: Y-red,P-green,C-blue
* Action: 0 - off, 1 - on
* ReelShelfIP: Server IP connected to the material rack
*/
private String ledBoard;
private String color;
private Integer action;
private String reelShelfIp;
}
package com.neotel.smfcore.custom.Inventec1562.bean;
import lombok.Data;
@Data
public class MultiLight {
private String phwCode;
private String color;
private String reelShelfIp;
}
package com.neotel.smfcore.custom.Inventec1562.bean;
import lombok.Data;
@Data
public class SingleLight {
/**
* pHW_Code:Storage location number
* Color:R-red,G-green,B-blue
* Action: 0 – off, 1 – on, 2 - flashing
* Cycle:Each unit flashes for 1 second
* ReelShelfIP: Server IP connected to the material rack
*/
private String phwCode;
private String color;
private Integer action;
private Integer cycle;
private String reelShelfIp;
}
package com.neotel.smfcore.custom.Inventec1562.controller;
import com.alibaba.fastjson.JSON;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager;
import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.storage.service.po.StoragePos;
import com.neotel.smfcore.core.system.util.DevicesStatusUtil;
import com.neotel.smfcore.custom.Inventec1562.bean.*;
import com.neotel.smfcore.custom.Inventec1562.enums.LightAction;
import com.neotel.smfcore.custom.Inventec1562.enums.LightColor;
import com.neotel.smfcore.security.annotation.AnonymousAccess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@Api(tags = "亮灯")
@Slf4j
@RestController
@RequestMapping("/light")
public class InventecLightController {
@Autowired
private IStoragePosManager storagePosManager;
@Autowired
private DataCache dataCache;
@ApiOperation("单个亮灯")
@RequestMapping("/singleLight/command")
@AnonymousAccess
public ResultBean singleLightCommand(SingleLight singleLight) {
log.info("收到单个亮灯指令:" + JSON.toJSONString(singleLight));
String phwCode = singleLight.getPhwCode();
if (StringUtils.isEmpty(phwCode)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"phwCode"});
}
String color = singleLight.getColor();
if (StringUtils.isEmpty(color)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"color"});
}
Integer action = singleLight.getAction();
if (action == null) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"action"});
}
Integer cycle = singleLight.getCycle();
if (cycle == null) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"cycle"});
}
String reelShelfIp = singleLight.getReelShelfIp();
//判断库位是否存在
StoragePos pos = storagePosManager.getByPosName(phwCode);
if (pos == null) {
return ResultBean.newErrorResult(-1, "smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{"phwCode", phwCode});
}
//判断料架是否存在
Storage storage = dataCache.getStorageById(pos.getStorageId());
if (storage == null) {
return ResultBean.newErrorResult(-1, "smfcore.shelfNotExist", "{0}对应的料架不存在", new String[]{phwCode});
}
//获取到指令
String cid = storage.getCid();
String opKey = LightAction.getOpName(action);
String smfColor = LightColor.getColor(color);
if (action == 2){
//秒转成毫秒
cycle = cycle * 1000;
String opValue = pos.getPosName() + "=" + smfColor + "=" + cycle;
log.info(cid+"对应的key为:"+opKey+"value为:"+opValue);
DevicesStatusUtil.appendOp(cid,opKey,opValue);
} else {
String opValue = pos.getPosName() + "=" + smfColor;
log.info(cid+"对应的key为:"+opKey+"value为:"+opValue);
DevicesStatusUtil.appendOp(cid,opKey,opValue);
}
return ResultBean.newOkResult("");
}
@ApiOperation("批量亮灯")
@RequestMapping("/multi-light/command")
@AnonymousAccess
public ResultBean multiLightCommand(MultiLight multiLight) {
log.info("收到批量亮灯指令为" + JSON.toJSONString(multiLight));
String phwCode = multiLight.getPhwCode();
if (StringUtils.isEmpty(phwCode)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"phwCode"});
}
String color = multiLight.getColor();
if (StringUtils.isEmpty(color)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"color"});
}
List<StoragePos> storagePosList = new ArrayList<>();
//判断库位是否存在
String[] posNameSpl = phwCode.split(",");
for (String posName : posNameSpl) {
StoragePos pos = storagePosManager.getByPosName(posName);
if (pos == null){
return ResultBean.newErrorResult(-1, "smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{"phwCode", phwCode});
}
storagePosList.add(pos);
}
String smfColor = LightColor.getColor(color);
for (StoragePos pos : storagePosList) {
Storage storage = dataCache.getStorageById(pos.getStorageId());
String cid = storage.getCid();
String opKey = LightAction.getOpName(1);
String opValue = pos.getPosName() + "=" + smfColor;
log.info(cid+"对应的key为:"+opKey+"value为:"+opValue);
DevicesStatusUtil.appendOp(cid,opKey,opValue);
}
return ResultBean.newOkResult("");
}
@ApiOperation("所有灯亮")
@RequestMapping("allLights/turnOn")
@AnonymousAccess
public ResultBean allLightsTurnOn(AllLightsTurnOn allLightsTurnOn) {
log.info("收到全部亮灯指令:" + JSON.toJSONString(allLightsTurnOn));
String ledBoard = allLightsTurnOn.getLedBoard();
if (StringUtils.isEmpty(ledBoard)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"ledBoard"});
}
String color = allLightsTurnOn.getColor();
if (StringUtils.isEmpty(color)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"color"});
}
List<Storage> storageList = new ArrayList<>();
String[] ledBoardSpl = ledBoard.split(",");
for (String cid : ledBoardSpl) {
Storage storage = dataCache.getStorage(cid);
if (storage == null){
return ResultBean.newErrorResult(-1, "smfcore.shelfNotExist", "{0}对应的料架不存在", new String[]{cid});
}
storageList.add(storage);
}
String smfColor = LightColor.getColor(color);
//开始执行亮灯指令
for (Storage storage : storageList) {
String cid = storage.getCid();
String opKey = LightAction.getOpName(3);
String opValue = smfColor;
log.info(cid+"对应的key为:"+opKey+"value为:"+opValue);
DevicesStatusUtil.clearOp(cid,opKey,opValue);
DevicesStatusUtil.appendOp(cid,opKey,opValue);
}
return ResultBean.newOkResult("");
}
@ApiOperation("所有灯灭")
@RequestMapping("allLights/turnOff")
@AnonymousAccess
public ResultBean allLightsTurnOff(AllLightsTurnOff allLightsTurnOff) {
log.info("收到全部亮灯指令:" + JSON.toJSONString(allLightsTurnOff));
String ledBoard = allLightsTurnOff.getLedBoard();
if (StringUtils.isEmpty(ledBoard)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"ledBoard"});
}
String color = allLightsTurnOff.getColor();
if (StringUtils.isEmpty(color)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"color"});
}
List<Storage> storageList = new ArrayList<>();
String[] ledBoardSpl = ledBoard.split(",");
for (String cid : ledBoardSpl) {
Storage storage = dataCache.getStorage(cid);
if (storage == null) {
return ResultBean.newErrorResult(-1, "smfcore.shelfNotExist", "{0}对应的料架不存在", new String[]{cid});
}
storageList.add(storage);
}
String smfColor = LightColor.getColor(color);
//开始执行亮灯指令
for (Storage storage : storageList) {
String cid = storage.getCid();
String opKey = LightAction.getOpName(4);
String opValue = smfColor;
log.info(cid + "对应的key为:" + opKey + "value为:" + opValue);
DevicesStatusUtil.clearOp(cid, opKey, opValue);
DevicesStatusUtil.appendOp(cid, opKey, opValue);
}
return ResultBean.newOkResult("");
}
@ApiOperation("亮灯控制")
@RequestMapping("lighthouse/control")
@AnonymousAccess
public ResultBean lighthouseControl(LighthouseControl lighthouseControl) {
log.info("收到亮灯控制指令:" + JSON.toJSONString(lighthouseControl));
String ledBoard = lighthouseControl.getLedBoard();
if (StringUtils.isEmpty(ledBoard)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"ledBoard"});
}
Integer action = lighthouseControl.getAction();
if (action == null) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"action"});
}
String color = lighthouseControl.getColor();
if (StringUtils.isEmpty(color)) {
return ResultBean.newErrorResult(-1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"color"});
}
//判断料架是否存在
Storage storage = dataCache.getStorage(ledBoard);
if (storage == null){
return ResultBean.newErrorResult(-1, "smfcore.shelfNotExist", "{0}对应的料架不存在", new String[]{ledBoard});
}
//获取smf颜色
String smfColor = LightColor.getColor(color);
String side = "";
if ("R".equals(color) || "G".equals(color) || "B".equals(color)){
side = "A";
} else if ("Y".equals(color) || "P".equals(color) || "C".equals(color)){
side = "B";
}
String opName = LightAction.getOpName(action);
String cid = storage.getCid();
String opKey = "lightHouseOpenOrClose";
String opValue = opName+"="+side+"="+smfColor;
DevicesStatusUtil.clearOp(cid, opKey, opValue);
DevicesStatusUtil.appendOp(cid, opKey, opValue);
return ResultBean.newOkResult("");
}
}
package com.neotel.smfcore.custom.Inventec1562.enums;
public enum LightAction {
close(0),
open(1),
flashing(2),
openAll(3),
closeAll(4);
private final int stateCode;
LightAction(int stateCode) {
this.stateCode = stateCode;
}
public static String getOpName(int stateCode) {
if (stateCode == 2) {
stateCode = 1;
}
for (LightAction action : LightAction.values()) {
if (action.stateCode == stateCode) {
return action.name();
}
}
return "";
}
}
package com.neotel.smfcore.custom.Inventec1562.enums;
public enum LightColor {
R("red"),
G("green"),
B("blue"),
Y("red"),
P("green"),
C("blue");
private final String blue;
LightColor(String blue) {
this.blue = blue;
}
public static String getColor(String name){
for (LightColor color : LightColor.values()) {
if (color.name().equals(name)){
return color.blue;
}
}
return "";
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!