|  |  | 
 |  |  | package com.zy.asrs.controller; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson.JSON; | 
 |  |  | import com.core.annotations.ManagerAuth; | 
 |  |  | import com.core.common.Arith; | 
 |  |  | import com.core.common.Cools; | 
 |  |  | import com.core.common.R; | 
 |  |  | import com.zy.asrs.domain.enums.CrnStatusType; | 
 |  |  | 
 |  |  | import com.zy.asrs.domain.param.SystemSwitchParam; | 
 |  |  | import com.zy.asrs.domain.vo.*; | 
 |  |  | import com.zy.asrs.entity.BasDevp; | 
 |  |  | import com.zy.asrs.entity.BasMap; | 
 |  |  | import com.zy.asrs.entity.WrkMast; | 
 |  |  | import com.zy.asrs.mapper.LocMastMapper; | 
 |  |  | import com.zy.asrs.service.BasDevpService; | 
 |  |  | import com.zy.asrs.service.BasMapService; | 
 |  |  | import com.zy.asrs.service.WrkMastService; | 
 |  |  | import com.zy.common.CodeRes; | 
 |  |  | import com.zy.common.model.MapNode; | 
 |  |  | import com.zy.common.utils.NavigateMapData; | 
 |  |  | import com.zy.common.utils.RedisUtil; | 
 |  |  | import com.zy.core.CrnThread; | 
 |  |  | 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.CrnModeType; | 
 |  |  | import com.zy.core.enums.SlaveType; | 
 |  |  | 
 |  |  | import com.zy.core.properties.SlaveProperties; | 
 |  |  | import com.zy.core.properties.SystemProperties; | 
 |  |  | import com.zy.core.thread.BarcodeThread; | 
 |  |  | import com.zy.core.thread.ScaleThread; | 
 |  |  | import com.zy.core.thread.SiemensCrnThread; | 
 |  |  | import com.zy.core.DevpThread; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.web.bind.annotation.PostMapping; | 
 |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
 |  |  | import org.springframework.web.bind.annotation.RequestParam; | 
 |  |  | import org.springframework.web.bind.annotation.RestController; | 
 |  |  | import org.springframework.web.bind.annotation.*; | 
 |  |  |  | 
 |  |  | import java.util.*; | 
 |  |  |  | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private BasDevpService basDevpService; | 
 |  |  |     @Autowired | 
 |  |  |     private BasMapService basMapService; | 
 |  |  |     @Autowired | 
 |  |  |     private LocMastMapper locMastMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private RedisUtil redisUtil; | 
 |  |  |  | 
 |  |  |     @PostMapping("/system/running/status") | 
 |  |  |     @ManagerAuth(memo = "系统运行状态") | 
 |  |  | 
 |  |  |             vo.setSiteId(String.valueOf(entry.getKey())); // 站点编号 | 
 |  |  |             vo.setWorkNo(staProtocol.getWorkNo()); // 工作号 | 
 |  |  |             vo.setSiteStatus(SiteStatusType.process(staProtocol));  // 状态 | 
 |  |  |             vo.setNearbySta(String.valueOf(staProtocol.getPosition())); // 台车位置 | 
 |  |  |             vos.add(vo); | 
 |  |  |         } | 
 |  |  |         return R.ok().add(vos); | 
 |  |  | 
 |  |  |             /** | 
 |  |  |              * 堆垛机状态判断 | 
 |  |  |              */ | 
 |  |  |             if (crnProtocol.getAlarm1() > 0) { | 
 |  |  |             if (crn.getId() == 1 && crnProtocol.getAlarm() > 0) { | 
 |  |  |                 vo.setCrnStatus(CrnStatusType.MACHINE_ERROR); | 
 |  |  |             } else { | 
 |  |  |                 if (crnProtocol.getTaskNo()>0) { | 
 |  |  | 
 |  |  |             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); | 
 |  |  | 
 |  |  |         return R.ok(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @GetMapping("/barcode/output/site") | 
 |  |  |     public R crnOutput(){ | 
 |  |  | //        StringBuilder str = new StringBuilder(); | 
 |  |  | //        String s; | 
 |  |  | //        int i = 0; | 
 |  |  | //        while((s = OutputQueue.CRN.poll()) != null && i <=32) { | 
 |  |  | //            str.append("\n").append(s); | 
 |  |  | //            i++; | 
 |  |  | //        } | 
 |  |  | //        return R.ok().add(str.toString()); | 
 |  |  |         return R.ok().add(JSON.toJSONString(new ArrayList<>(OutputQueue.BARCODE))); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获取地图数据 | 
 |  |  |      */ | 
 |  |  |     @GetMapping("/map/{lev}/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R getMapFromRedis(@PathVariable Integer lev) { | 
 |  |  |         Object data = redisUtil.get("realtimeBasMap_" + lev); | 
 |  |  |         if (data == null) { | 
 |  |  |             return R.error(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         BasMap basMap = JSON.parseObject(data.toString(), BasMap.class); | 
 |  |  |         //解析json地图数据 | 
 |  |  |         ArrayList arrayList = JSON.parseObject(basMap.getData(), ArrayList.class); | 
 |  |  |         NavigateMapData navigateMapData = new NavigateMapData(lev); | 
 |  |  |         List<List<MapNode>> lists = navigateMapData.filterMap(-1, arrayList);//过滤地图数据 | 
 |  |  |         return R.ok().add(lists); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 重置redis中的地图,将占用的库位全部解除 | 
 |  |  |      */ | 
 |  |  |     @GetMapping("/map/resetMap/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R resetMapToRedis() { | 
 |  |  |         for (int i = 1; i <= 4; i++) { | 
 |  |  |             Object data = redisUtil.get("realtimeBasMap_" + i); | 
 |  |  |             if (data == null) { | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             redisUtil.del("realtimeBasMap_" + i); | 
 |  |  |             basMapService.deleteByLev(i); | 
 |  |  |         } | 
 |  |  |         return R.ok(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |