| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.domain.param.SystemSwitchParam; |
| | | import com.zy.asrs.entity.BasMap; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasMapService; |
| | | 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.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | 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.properties.SystemProperties; |
| | | import com.zy.core.thread.ForkLiftThread; |
| | | import com.zy.core.thread.ShuttleThread; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | public class ConsoleController { |
| | | |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private BasMapService basMapService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Value("${super.pwd}") |
| | | private String superPwd; |
| | | @Autowired |
| | | private NavigateMapData navigateMapData; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | |
| | | @PostMapping("/system/running/status") |
| | | @ManagerAuth(memo = "系统运行状态") |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取地图楼层数据 |
| | | */ |
| | | @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); |
| | | } |
| | | |
| | | /** |
| | | * 获取地图数据 |
| | | */ |
| | | @GetMapping("/map/{lev}/auth") |
| | |
| | | @ManagerAuth |
| | | public R resetMapToRedis() { |
| | | for (int i = 1; i <= 10; i++) {//总共10层楼 |
| | | BasMap basMap = basMapService.selectLatestMap(i); |
| | | //载入地图 |
| | | List<List<MapNode>> lists = navigateMapData.getJsonData(i, -1, null, null);//获取完整地图(包括入库出库) |
| | | if (basMap == null) { |
| | | //数据库中也不存在地图数据,从地图文件中获取 |
| | | //存入数据库 |
| | | basMap = new BasMap(); |
| | | basMap.setData(JSON.toJSONString(lists)); |
| | | basMap.setCreateTime(new Date()); |
| | | basMap.setUpdateTime(new Date()); |
| | | basMap.setLev(i); |
| | | |
| | | if (!basMapService.insert(basMap)) { |
| | | log.info("地图数据存储失败"); |
| | | } |
| | | }else { |
| | | basMap.setData(JSON.toJSONString(lists)); |
| | | basMap.setUpdateTime(new Date()); |
| | | if (!basMapService.updateById(basMap)) { |
| | | log.info("地图数据存储失败"); |
| | | } |
| | | } |
| | | |
| | | //将数据库地图数据存入redis |
| | | redisUtil.set(RedisKeyType.MAP.key + i, JSON.toJSONString(basMap)); |
| | | redisUtil.del(RedisKeyType.MAP.key + i); |
| | | } |
| | | return R.ok(); |
| | | } |
| | |
| | | @GetMapping("/map/resetMap/{lev}") |
| | | @ManagerAuth(memo = "重置Redis地图") |
| | | public R resetMapToRedisByLev(@PathVariable Integer lev, HttpServletRequest request) { |
| | | // super账号 |
| | | String token = request.getHeader("token"); |
| | | if (token == null) { |
| | | return R.error(); |
| | | } |
| | | String deToken = Cools.deTokn(token, superPwd); |
| | | if (deToken == null) { |
| | | return R.error("权限不足"); |
| | | } |
| | | if (!"super".equals(deToken.substring(13))) { |
| | | return R.error("权限不足"); |
| | | 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("存在未结束任务"); |
| | | } |
| | | |
| | | BasMap basMap = basMapService.selectLatestMap(lev); |
| | | //载入地图 |
| | | List<List<MapNode>> lists = navigateMapData.getJsonData(lev, -1, null, null);//获取完整地图(包括入库出库) |
| | | if (basMap == null) { |
| | | //数据库中也不存在地图数据,从地图文件中获取 |
| | | //存入数据库 |
| | | basMap = new BasMap(); |
| | | basMap.setData(JSON.toJSONString(lists)); |
| | | basMap.setCreateTime(new Date()); |
| | | basMap.setUpdateTime(new Date()); |
| | | basMap.setLev(lev); |
| | | |
| | | if (!basMapService.insert(basMap)) { |
| | | log.info("地图数据存储失败"); |
| | | for (ShuttleSlave slave : slaveProperties.getShuttle()) { |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId()); |
| | | if (shuttleThread == null) { |
| | | continue; |
| | | } |
| | | } else { |
| | | basMap.setData(JSON.toJSONString(lists)); |
| | | basMap.setUpdateTime(new Date()); |
| | | if (!basMapService.updateById(basMap)) { |
| | | log.info("地图数据存储失败"); |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (shuttleProtocol.getTaskNo() > 0) { |
| | | return R.error(slave.getId() + "号小车存在工作号"); |
| | | } |
| | | } |
| | | |
| | | //将数据库地图数据存入redis |
| | | redisUtil.set(RedisKeyType.MAP.key + lev, JSON.toJSONString(basMap)); |
| | | for (ForkLiftSlave slave : slaveProperties.getForkLift()) { |
| | | ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, slave.getId()); |
| | | if (forkLiftThread == null) { |
| | | continue; |
| | | } |
| | | ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus(); |
| | | if (forkLiftProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (forkLiftProtocol.getTaskNo() > 0) { |
| | | return R.error(slave.getId() + "号货叉提升机存在工作号"); |
| | | } |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |