| | |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.domain.enums.CrnStatusType; |
| | | import com.zy.asrs.domain.param.SystemSwitchParam; |
| | | import com.zy.asrs.entity.BasMap; |
| | | import com.zy.asrs.domain.vo.CrnDetailVo; |
| | | import com.zy.asrs.domain.vo.CrnLatestDataVo; |
| | | import com.zy.asrs.entity.BasCrnpErr; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasMapService; |
| | | import com.zy.asrs.service.BasCrnpErrService; |
| | | import com.zy.asrs.service.DeviceConfigService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.common.model.MapNode; |
| | | import com.zy.common.model.enums.NavigationMapType; |
| | | import com.zy.common.utils.NavigateMapData; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.common.CodeRes; |
| | | import com.zy.core.Slave; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.CrnModeType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.ForkLiftSlave; |
| | | import com.zy.core.model.ShuttleSlave; |
| | | import com.zy.core.model.protocol.ForkLiftProtocol; |
| | | import com.zy.core.model.protocol.ShuttleProtocol; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.model.protocol.CrnProtocol; |
| | | import com.zy.core.properties.SystemProperties; |
| | | import com.zy.core.thread.ForkLiftThread; |
| | | import com.zy.core.thread.ShuttleThread; |
| | | import com.zy.core.thread.CrnThread; |
| | | import com.zy.core.thread.impl.ZySiemensCrnThread; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | public class ConsoleController { |
| | | |
| | | @Autowired |
| | | private BasMapService basMapService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private NavigateMapData navigateMapData; |
| | | private DeviceConfigService deviceConfigService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | private BasCrnpErrService basCrnpErrService; |
| | | |
| | | @PostMapping("/system/running/status") |
| | | @ManagerAuth(memo = "系统运行状态") |
| | |
| | | return R.ok().add(Cools.add("status", SystemProperties.WCS_RUNNING_STATUS.get())); |
| | | } |
| | | |
| | | /** |
| | | * 获取地图楼层数据 |
| | | */ |
| | | @GetMapping("/map/lev/list") |
| | | @ManagerAuth |
| | | public R getMapLevList() { |
| | | List<BasMap> basMaps = basMapService.selectList(new EntityWrapper<BasMap>().orderBy("lev", true)); |
| | | ArrayList<Integer> levList = new ArrayList<>(); |
| | | for (BasMap basMap : basMaps) { |
| | | levList.add(basMap.getLev()); |
| | | } |
| | | return R.ok().add(levList); |
| | | } |
| | | // @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 (Map.Entry<Integer, StaProtocol> entry : stations.entrySet()) { |
| | | // SiteLatestDataVo vo = new SiteLatestDataVo(); |
| | | // StaProtocol staProtocol = entry.getValue(); |
| | | // vo.setSiteId(String.valueOf(entry.getKey())); // 站点编号 |
| | | // vo.setWorkNo(staProtocol.getWorkNo()); // 工作号 |
| | | // vo.setSiteStatus(SiteStatusType.process(staProtocol)); // 状态 |
| | | // vos.add(vo); |
| | | // } |
| | | // return R.ok().add(vos); |
| | | // } |
| | | |
| | | /** |
| | | * 获取地图数据 |
| | | */ |
| | | @GetMapping("/map/{lev}/auth") |
| | | @ManagerAuth |
| | | public R getMapFromRedis(@PathVariable Integer lev) { |
| | | Object data = redisUtil.get(RedisKeyType.MAP.key + lev); |
| | | if (data == null) { |
| | | return R.error(); |
| | | } |
| | | @PostMapping("/latest/data/crn") |
| | | @ManagerAuth(memo = "堆垛机实时数据") |
| | | public R crnLatestData(){ |
| | | List<CrnLatestDataVo> vos = new ArrayList<>(); |
| | | |
| | | BasMap basMap = JSON.parseObject(data.toString(), BasMap.class); |
| | | //解析json地图数据 |
| | | ArrayList arrayList = JSON.parseObject(basMap.getData(), ArrayList.class); |
| | | List<List<MapNode>> lists = navigateMapData.filterMap(NavigationMapType.NONE.id, arrayList, lev, null, null);//过滤地图数据 |
| | | return R.ok().add(lists); |
| | | } |
| | | |
| | | /** |
| | | * 重置redis中的地图,将占用的库位全部解除 |
| | | */ |
| | | @GetMapping("/map/resetMap/auth") |
| | | @ManagerAuth |
| | | public R resetMapToRedis() { |
| | | for (int i = 1; i <= 10; i++) {//总共10层楼 |
| | | redisUtil.del(RedisKeyType.MAP.key + i); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 重置redis中的地图,将占用的库位全部解除 |
| | | */ |
| | | @GetMapping("/map/resetMap/{lev}") |
| | | @ManagerAuth(memo = "重置Redis地图") |
| | | public R resetMapToRedisByLev(@PathVariable Integer lev, HttpServletRequest request) { |
| | | redisUtil.del(RedisKeyType.MAP.key + lev); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 任务检测 |
| | | */ |
| | | @GetMapping("/checkTask") |
| | | @ManagerAuth(memo = "任务检测") |
| | | public R checkTask() { |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<>()); |
| | | if (!wrkMasts.isEmpty()) { |
| | | return R.error("存在未结束任务"); |
| | | } |
| | | |
| | | for (ShuttleSlave slave : slaveProperties.getShuttle()) { |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId()); |
| | | if (shuttleThread == null) { |
| | | continue; |
| | | } |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null) { |
| | | List<DeviceConfig> crnList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Crn))); |
| | | for (DeviceConfig deviceConfig : crnList) { |
| | | // 获取堆垛机信息 |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, deviceConfig.getDeviceNo()); |
| | | if (crnThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (shuttleProtocol.getTaskNo() > 0) { |
| | | return R.error(slave.getId() + "号小车存在工作号"); |
| | | } |
| | | } |
| | | |
| | | for (ForkLiftSlave slave : slaveProperties.getForkLift()) { |
| | | ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, slave.getId()); |
| | | if (forkLiftThread == null) { |
| | | CrnProtocol crnProtocol = crnThread.getStatus(); |
| | | if (crnProtocol == null) { |
| | | continue; |
| | | } |
| | | ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus(); |
| | | if (forkLiftProtocol == null) { |
| | | continue; |
| | | } |
| | | CrnLatestDataVo vo = new CrnLatestDataVo(); |
| | | vo.setCrnId(crnProtocol.getCrnNo()); // 堆垛机编号 |
| | | |
| | | if (forkLiftProtocol.getTaskNo() > 0) { |
| | | return R.error(slave.getId() + "号货叉提升机存在工作号"); |
| | | vo.setOffset((double) new Random().nextInt(560)); // 堆垛机偏移量 |
| | | vo.setBay(crnProtocol.getBay()); // 当前列 |
| | | /** |
| | | * 堆垛机状态判断 |
| | | */ |
| | | if (crnProtocol.getAlarm() > 0) { |
| | | vo.setCrnStatus(CrnStatusType.MACHINE_ERROR); |
| | | } else { |
| | | if (crnProtocol.getTaskNo()>0) { |
| | | WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo()); |
| | | if (wrkMast != null) { |
| | | vo.setCrnStatus(CrnStatusType.process(wrkMast.getIoType())); |
| | | } else { |
| | | vo.setCrnStatus(crnProtocol.modeType.equals(CrnModeType.AUTO)? CrnStatusType.MACHINE_AUTO: CrnStatusType.MACHINE_UN_AUTO); |
| | | } |
| | | } else { |
| | | vo.setCrnStatus(crnProtocol.modeType.equals(CrnModeType.AUTO)? CrnStatusType.MACHINE_AUTO: CrnStatusType.MACHINE_UN_AUTO); |
| | | } |
| | | } |
| | | vos.add(vo); |
| | | } |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | // @PostMapping("/latest/data/rgv") |
| | | // @ManagerAuth(memo = "RGV实时数据") |
| | | // public R rgvLatestData(){ |
| | | // List<RgvLatestDataVo> vos = new ArrayList<>(); |
| | | // for (RgvSlave rgvSlave : slaveProperties.getRgv()) { |
| | | // // 获取堆垛机信息 |
| | | // RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId()); |
| | | // if (rgvThread == null) { |
| | | // continue; |
| | | // } |
| | | // RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); |
| | | // if (rgvProtocol == null) { |
| | | // continue; |
| | | // } |
| | | // RgvLatestDataVo vo = new RgvLatestDataVo(); |
| | | // vo.setRgvId(rgvProtocol.getRgvNo()); // RGV编号 |
| | | // vo.setTrackSiteNo(String.valueOf(rgvProtocol.getRgvPos())); |
| | | // vo.setRgvStatus(rgvProtocol.getStatusType()); |
| | | // vos.add(vo); |
| | | // |
| | | // } |
| | | // Object object = redisUtil.get("rgvLatestData"); |
| | | // List<Object> siteLatestDataVos = JSON.parseArray(object.toString()); |
| | | // return R.ok().add(siteLatestDataVos); |
| | | // } |
| | | |
| | | // @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("/crn/detail") |
| | | @ManagerAuth(memo = "堆垛机设备数据详情") |
| | | public R crnDetail(@RequestParam Integer crnNo){ |
| | | if (Cools.isEmpty(crnNo)){ |
| | | return R.parse(CodeRes.EMPTY); |
| | | } |
| | | CrnDetailVo vo = new CrnDetailVo(); |
| | | |
| | | DeviceConfig deviceConfig = deviceConfigService.selectOne(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Crn)) |
| | | .eq("device_no", crnNo) |
| | | ); |
| | | |
| | | if (deviceConfig == null) { |
| | | return R.error("设备不存在"); |
| | | } |
| | | |
| | | return R.ok(); |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnNo); |
| | | CrnProtocol crnProtocol = crnThread.getStatus(); |
| | | vo.setCrnNo(crnNo); |
| | | vo.setWorkNo(crnProtocol.getTaskNo()); |
| | | vo.setCrnStatus(crnProtocol.getStatusType().desc); |
| | | |
| | | if (crnProtocol.getAlarm() > 0) { |
| | | BasCrnpErr crnError = basCrnpErrService.selectById(crnProtocol.getAlarm()); |
| | | vo.setError(crnError == null ? "未知异常" : crnError.getErrName()); |
| | | } |
| | | |
| | | if (crnProtocol.getTaskNo() > 0) { |
| | | WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo()); |
| | | if (wrkMast != null) { |
| | | vo.setSourceStaNo(String.valueOf(wrkMast.getSourceStaNo())); |
| | | vo.setStaNo(String.valueOf(wrkMast.getStaNo())); |
| | | vo.setWrkSts(wrkMast.getWrkSts$()); // 工作状态 |
| | | vo.setIoType(wrkMast.getIoType$()); // 入出库类型 |
| | | vo.setSourceLocNo(wrkMast.getSourceLocNo$()); |
| | | vo.setLocNo(wrkMast.getLocNo$()); |
| | | vo.setCrnStatus(crnProtocol.getStatusType().desc); |
| | | vo.setError(""); // todo |
| | | } |
| | | } |
| | | return R.ok().add(vo); |
| | | } |
| | | |
| | | } |