| | |
| | | import com.zy.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | |
| | | @Service("mainService") |
| | | public class MainServiceImpl { |
| | | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | |
| | | private ForkLiftAction forkLiftAction; |
| | | @Autowired |
| | | private NotifyUtils notifyUtils; |
| | | @Autowired |
| | | private BasShuttleChargeService basShuttleChargeService; |
| | | |
| | | /** |
| | | * 初始化实时地图 |
| | | */ |
| | | public synchronized void initRealtimeBasMap() { |
| | | try { |
| | | for (int i = 1; i <= 4; i++) {//总共四层楼 |
| | | Object data = redisUtil.get(RedisKeyType.MAP.key + i); |
| | | if (data == null) {//redis地图数据为空,从数据库中获取 |
| | | BasMap basMap = basMapService.selectLatestMap(i); |
| | | if (basMap == null) { |
| | | //数据库中也不存在地图数据,从地图文件中获取 |
| | | //载入地图 |
| | | List<List<MapNode>> lists = navigateMapData.getJsonData(i, -1, null, null);//获取完整地图(包括入库出库) |
| | | |
| | | //存入数据库 |
| | | basMap = new BasMap(); |
| | | basMap.setData(JSON.toJSONString(lists)); |
| | | basMap.setCreateTime(new Date()); |
| | | basMap.setUpdateTime(new Date()); |
| | | basMap.setLev(i); |
| | | List<BasMap> basMaps = basMapService.selectList(new EntityWrapper<BasMap>().orderBy("lev", true)); |
| | | for (BasMap basMap : basMaps) { |
| | | Integer lev = basMap.getLev(); |
| | | Object data = redisUtil.get(RedisKeyType.MAP.key + lev); |
| | | if (data == null) {//redis地图数据为空 |
| | | //载入地图 |
| | | List<List<MapNode>> lists = navigateMapData.getJsonData(lev, -1, null, null);//获取完整地图(包括入库出库) |
| | | |
| | | if (!basMapService.insert(basMap)) { |
| | | log.info("地图数据存储失败"); |
| | | } |
| | | //存入数据库 |
| | | basMap.setData(JSON.toJSONString(lists)); |
| | | basMap.setCreateTime(new Date()); |
| | | basMap.setUpdateTime(new Date()); |
| | | if (!basMapService.updateById(basMap)) { |
| | | log.info("地图数据存储失败"); |
| | | } |
| | | |
| | | //将数据库地图数据存入redis |
| | | redisUtil.set(RedisKeyType.MAP.key + i, JSON.toJSONString(basMap)); |
| | | redisUtil.set(RedisKeyType.MAP.key + lev, JSON.toJSONString(basMap)); |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | */ |
| | | public synchronized void loopShuttleCharge() { |
| | | try { |
| | | |
| | | List<BasShuttleCharge> charges = basShuttleChargeService.selectList(new EntityWrapper<BasShuttleCharge>().orderBy("charge_id", true)); |
| | | if (charges.isEmpty()) { |
| | | return;//无充电桩 |
| | | } |
| | | |
| | | for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { |
| | | //获取四向穿梭车线程 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); |
| | |
| | | |
| | | //小车所在楼层 |
| | | int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo()); |
| | | ShuttleChargeType shuttleCharge = null; |
| | | BasShuttleCharge shuttleCharge = null; |
| | | |
| | | //搜索小车所在楼层有没有充电桩 |
| | | for (ShuttleChargeType chargeType : ShuttleChargeType.values()) { |
| | | if (lev != Utils.getLev(chargeType.locNo)) { |
| | | for (BasShuttleCharge charge : charges) { |
| | | if (lev != Utils.getLev(charge.getLocNo())) { |
| | | continue;//小车和充电桩不在同一层 |
| | | } |
| | | |
| | | //小车和充电桩在同一层 |
| | | if (wrkMastService.selectChargeWorkingByChargeSta(chargeType.id) == null) { |
| | | shuttleCharge = chargeType; |
| | | if (wrkMastService.selectChargeWorkingByChargeSta(charge.getChargeId()) == null) { |
| | | shuttleCharge = charge; |
| | | break; |
| | | } |
| | | } |
| | |
| | | if (shuttleCharge == null) { |
| | | //同楼层没有找到充电桩,找可用充电桩 |
| | | //小车同楼层没有充电桩,只要充电桩可用就生成充电任务 |
| | | for (ShuttleChargeType chargeType : ShuttleChargeType.values()) { |
| | | if (wrkMastService.selectChargeWorkingByChargeSta(chargeType.id) == null) { |
| | | for (BasShuttleCharge charge : charges) { |
| | | if (wrkMastService.selectChargeWorkingByChargeSta(charge.getChargeId()) == null) { |
| | | //判断当前充电桩楼层是否有小车,如有小车,不分配该充电桩 |
| | | int chargeLev = Utils.getLev(chargeType.locNo);//充电桩楼层 |
| | | int chargeLev = Utils.getLev(charge.getLocNo());//充电桩楼层 |
| | | boolean checkLevHasShuttle = Utils.checkLevHasShuttle(chargeLev);//检测楼层是否有穿梭车 |
| | | if (checkLevHasShuttle) { |
| | | //当前充电桩楼层有穿梭车,不分配该充电桩 |
| | | continue; |
| | | } |
| | | |
| | | shuttleCharge = chargeType; |
| | | shuttleCharge = charge; |
| | | break; |
| | | } |
| | | } |
| | |
| | | continue; |
| | | } |
| | | |
| | | String chargeLocNo = shuttleCharge.locNo; |
| | | String chargeLocNo = shuttleCharge.getLocNo(); |
| | | wrkMast = new WrkMast(); |
| | | wrkMast.setMk(String.valueOf(shuttleCharge.id)); |
| | | wrkMast.setMk(String.valueOf(shuttleCharge.getChargeId())); |
| | | wrkMast.setWrkNo(commonService.getWorkNo(WrkIoType.SHUTTLE_CHARGE.id)); |
| | | wrkMast.setWrkSts(WrkStsType.NEW_CHARGE.sts); |
| | | wrkMast.setIoType(WrkIoType.SHUTTLE_CHARGE.id);//300.充电 |
| | |
| | | return false; |
| | | } |
| | | |
| | | ShuttleChargeType chargeType = ShuttleChargeType.get(Integer.parseInt(wrkMast.getMk())); |
| | | if(chargeType == null) { |
| | | BasShuttleCharge basShuttleCharge = basShuttleChargeService.selectOne(new EntityWrapper<BasShuttleCharge>().eq("charge_id", wrkMast.getMk())); |
| | | if(basShuttleCharge == null) { |
| | | return false; |
| | | } |
| | | |
| | | //调度小车去待机位 |
| | | boolean dispatched = shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), chargeType.waitLocNo, wrkMast.getShuttleNo()); |
| | | boolean dispatched = shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), basShuttleCharge.getWaitLocNo(), wrkMast.getShuttleNo()); |
| | | if (!dispatched) { |
| | | return false; |
| | | } |