|  |  | 
 |  |  | 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.service.BasDevpService; | 
 |  |  | import com.zy.asrs.service.WrkMastService; | 
 |  |  | import com.zy.common.CodeRes; | 
 |  |  | 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.CrnThread; | 
 |  |  | import com.zy.core.thread.DevpThread; | 
 |  |  | import com.zy.core.thread.MelsecCrnThread; | 
 |  |  | import com.zy.core.thread.ScaleThread; | 
 |  |  | 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.*; | 
 |  |  |  | 
 |  |  | 
 |  |  |             /** | 
 |  |  |              * 堆垛机状态判断 | 
 |  |  |              */ | 
 |  |  |             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); | 
 |  |  | 
 |  |  |         CrnDetailVo vo = new CrnDetailVo(); | 
 |  |  |         for (CrnSlave crnSlave : slaveProperties.getCrn()) { | 
 |  |  |             if (crnSlave.getId().equals(crnNo)) { | 
 |  |  |                 CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnSlave.getId()); | 
 |  |  |                 MelsecCrnThread crnThread = (MelsecCrnThread) SlaveConnection.get(SlaveType.Crn, crnSlave.getId()); | 
 |  |  |                 CrnProtocol crnProtocol = crnThread.getCrnProtocol(); | 
 |  |  |                 vo.setCrnNo(crnNo); | 
 |  |  |                 vo.setWorkNo(crnProtocol.getTaskNo()); | 
 |  |  | 
 |  |  |         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))); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |