package com.zy.asrs.controller;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.core.annotations.ManagerAuth;
|
import com.core.common.Arith;
|
import com.core.common.Cools;
|
import com.core.common.DateUtils;
|
import com.core.common.R;
|
import com.zy.asrs.domain.enums.SiteStatusType;
|
import com.zy.asrs.domain.param.SystemSwitchParam;
|
import com.zy.asrs.domain.vo.*;
|
import com.zy.asrs.entity.BasDevp;
|
import com.zy.asrs.entity.WrkMast;
|
import com.zy.asrs.service.BasDevpService;
|
import com.zy.asrs.service.WrkMastService;
|
import com.zy.common.CodeRes;
|
import com.zy.core.DevpThread;
|
import com.zy.core.Slave;
|
import com.zy.core.cache.OutputQueue;
|
import com.zy.core.cache.SlaveConnection;
|
import com.zy.core.enums.SlaveType;
|
import com.zy.core.model.DevpSlave;
|
import com.zy.core.model.RgvSlave;
|
import com.zy.core.model.protocol.StaProtocol;
|
import com.zy.core.properties.SlaveProperties;
|
import com.zy.core.properties.SystemProperties;
|
import com.zy.core.thread.*;
|
import com.zy.system.entity.license.LicenseVerify;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.*;
|
|
/**
|
* 主控图接口
|
* Created by vincent on 2020-06-01
|
*/
|
@Slf4j
|
@RestController
|
@RequestMapping("/console")
|
public class ConsoleController {
|
|
@Autowired
|
private SlaveProperties slaveProperties;
|
@Autowired
|
private WrkMastService wrkMastService;
|
@Autowired
|
private BasDevpService basDevpService;
|
|
@PostMapping("/system/running/status")
|
// @ManagerAuth(memo = "系统运行状态")
|
public R systemRunningStatus(){
|
return R.ok().add(Cools.add("status", SystemProperties.WCS_RUNNING_STATUS.get()));
|
}
|
|
@PostMapping("/system/switch")
|
// @ManagerAuth(memo = "系统运行开关操作")
|
public R systemSwitch(SystemSwitchParam param) throws InterruptedException {
|
if (Cools.isEmpty(param.getOperatorType())){
|
return R.error();
|
}
|
if (param.getOperatorType() == 0) {
|
if (Cools.isEmpty(param.getPassword())){
|
return R.error("请输入口令");
|
}
|
if (!param.getPassword().equals(SystemProperties.WCS_PASSWORD)){
|
return R.error("口令错误");
|
}
|
}
|
Thread.sleep(200L);
|
//验证许可证是否有效
|
try{
|
if (new LicenseVerify().verify()){
|
SystemProperties.WCS_RUNNING_STATUS.set(param.getOperatorType()==1?Boolean.TRUE:Boolean.FALSE);
|
return R.ok().add(Cools.add("status", SystemProperties.WCS_RUNNING_STATUS.get()));
|
}
|
} catch (Exception e){
|
log.error("许可证验证失败!!异常:{}",e.getMessage());
|
}
|
SystemProperties.WCS_RUNNING_STATUS.set(Boolean.FALSE);
|
return R.ok().add(Cools.add("status", SystemProperties.WCS_RUNNING_STATUS.get()));
|
}
|
|
/****************************************************************/
|
/************************** 实时数据 ******************************/
|
/****************************************************************/
|
|
@PostMapping("/latest/data/site")
|
@ManagerAuth(memo = "站点实时数据")
|
public R siteLatestData(){
|
List<SiteLatestDataVo> vos = new ArrayList<>();
|
Map<Integer, StaProtocol> stations = new HashMap<>();
|
for (DevpSlave devp : slaveProperties.getDevp()) {
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
|
if (null != devpThread) {
|
stations.putAll(devpThread.getStation());
|
}
|
}
|
|
for (RgvSlave rgv : slaveProperties.getRgv()) {
|
RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgv.getId());
|
if (null != rgvThread) {
|
// stations.putAll(rgvThread.getStation());
|
}
|
}
|
for (Map.Entry<Integer, StaProtocol> entry : stations.entrySet()) {
|
SiteLatestDataVo vo = new SiteLatestDataVo();
|
StaProtocol staProtocol = entry.getValue();
|
if (entry.getKey() < 100){
|
if (entry.getKey() < 10){
|
vo.setSiteId("00" + entry.getKey()); //如果站点编号是1,2,3,4 改为 001,002 ,003
|
}else {
|
vo.setSiteId("0" + entry.getKey()); //如果站点编号是23,59,67,81 改为 023, 059, 067, 081
|
}
|
}else {
|
vo.setSiteId(String.valueOf(entry.getKey())); // 站点编号
|
|
}
|
vo.setWorkNo(staProtocol.getWorkNo()); // 工作号
|
vo.setSiteStatus(SiteStatusType.process(staProtocol)); // 状态
|
vo.setNearbySta(staProtocol.getNearbySta()); //RGV位置
|
vos.add(vo);
|
}
|
return R.ok().add(vos);
|
}
|
|
@PostMapping("/latest/data/barcode")
|
@ManagerAuth(memo = "条码扫描仪实时数据")
|
public R barcodeLatestData(){
|
List<BarcodeDataVo> list = new ArrayList<>();
|
for (Slave barcode : slaveProperties.getBarcode()) {
|
BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcode.getId());
|
if (null == barcodeThread) {
|
continue;
|
}
|
BarcodeDataVo vo = new BarcodeDataVo();
|
vo.setBarcodeId(barcode.getId());
|
vo.setCodeValue(barcodeThread.getBarcode());
|
list.add(vo);
|
}
|
return R.ok().add(list);
|
}
|
|
@PostMapping("/latest/data/scale")
|
@ManagerAuth(memo = "磅秤实时数据")
|
public R scaleLatestData(){
|
List<ScaleDataVo> list = new ArrayList<>();
|
for (Slave scale : slaveProperties.getScale()) {
|
ScaleThread scaleThread = (ScaleThread) SlaveConnection.get(SlaveType.Scale, scale.getId());
|
if (null == scaleThread) {
|
continue;
|
}
|
ScaleDataVo vo = new ScaleDataVo();
|
vo.setScaleId(scale.getId());
|
vo.setValue(String.valueOf(Arith.multiplys(1, scaleThread.getScale(), 1)));
|
list.add(vo);
|
}
|
return R.ok().add(list);
|
}
|
|
/****************************************************************/
|
/************************** 详情操作 ******************************/
|
/****************************************************************/
|
|
@PostMapping("/site/detail")
|
@ManagerAuth(memo = "输送设备数据详情")
|
public R siteDetail(@RequestParam Integer siteId){
|
if (Cools.isEmpty(siteId)){
|
return R.parse(CodeRes.EMPTY);
|
}
|
SiteDetailVo vo = new SiteDetailVo();
|
for (DevpSlave devp : slaveProperties.getDevp()) {
|
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
|
if (null != devpThread) {
|
StaProtocol staProtocol = devpThread.getStation().get(siteId);
|
if (staProtocol != null) {
|
BasDevp basDevp = basDevpService.selectById(siteId);
|
if (basDevp == null) {
|
return R.error("数据库维护异常");
|
}
|
vo.setSiteId(siteId); // 站点编号
|
vo.setWorkNo(staProtocol.getWorkNo()); // 工作号
|
|
if (staProtocol.getWorkNo() > 0) {
|
WrkMast wrkMast = wrkMastService.selectById(staProtocol.getWorkNo());
|
if (wrkMast != null) {
|
vo.setWrkSts(wrkMast.getWrkSts$()); // 工作状态
|
vo.setIoType(wrkMast.getIoType$()); // 入出库类型
|
vo.setSourceStaNo(wrkMast.getSourceStaNo$());
|
vo.setStaNo(wrkMast.getStaNo$());
|
}
|
}
|
|
vo.setAutoing(staProtocol.isAutoing()?"Y":"N"); // 自动
|
vo.setLoading(staProtocol.isLoading()?"Y":"N"); // 有物
|
|
vo.setCanining(basDevp.getCanining()); // 能入
|
vo.setCanouting(basDevp.getCanouting()); // 能出
|
|
return R.ok().add(vo);
|
}
|
}
|
}
|
return R.error();
|
|
}
|
|
@Deprecated
|
@PostMapping("/site/update")
|
@ManagerAuth(memo = "输送设备数据修改")
|
public R updateSite(){
|
return R.ok();
|
}
|
|
@Deprecated
|
@PostMapping("/crn/update")
|
@ManagerAuth(memo = "堆垛机数据修改")
|
public R updateCrn(){
|
return R.ok();
|
}
|
|
@GetMapping("/barcode/output/site")
|
public R crnOutput(){
|
ArrayList<JSONObject> jsonObjects = new ArrayList<>(OutputQueue.BARCODE);
|
jsonObjects.sort(new Comparator<JSONObject>() {
|
@Override
|
public int compare(JSONObject o1, JSONObject o2) {
|
Date o1Time = DateUtils.convert(o1.getString("time"), DateUtils.yyyyMMddHHmmss_F);
|
Date o2Time = DateUtils.convert(o2.getString("time"), DateUtils.yyyyMMddHHmmss_F);
|
return (int) (o2Time.getTime() - o1Time.getTime());
|
}
|
});
|
return R.ok().add(JSON.toJSONString(jsonObjects));
|
}
|
|
}
|