|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.Arith; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.DateUtils; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.CrnStatusType; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.SiteStatusType; | 
|---|
|  |  |  | import com.zy.asrs.domain.param.SystemSwitchParam; | 
|---|
|  |  |  | import com.zy.asrs.domain.vo.*; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasCrnError; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasDevp; | 
|---|
|  |  |  | import com.zy.asrs.entity.WrkMast; | 
|---|
|  |  |  | import com.zy.asrs.mapper.BasCrnErrorMapper; | 
|---|
|  |  |  | import com.zy.asrs.mapper.LocMastMapper; | 
|---|
|  |  |  | 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.ScaleThread; | 
|---|
|  |  |  | import com.zy.core.thread.SiemensCrnThread; | 
|---|
|  |  |  | 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.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | private BasDevpService basDevpService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocMastMapper locMastMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BasCrnErrorMapper basCrnErrorMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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())); // 台车位置 | 
|---|
|  |  |  | vo.setNearbySta(staProtocol.getNearbySta());  //RGV位置 | 
|---|
|  |  |  | vos.add(vo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(vos); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | SiemensCrnThread crnThread = (SiemensCrnThread) SlaveConnection.get(SlaveType.Crn, crnSlave.getId()); | 
|---|
|  |  |  | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); | 
|---|
|  |  |  | vo.setCrnNo(crnNo); | 
|---|
|  |  |  | vo.setWorkNo(crnProtocol.getTaskNo()); | 
|---|
|  |  |  | vo.setCrnStatus(crnProtocol.getStatusType().desc); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (crnProtocol.getAlarm1() > 0) { | 
|---|
|  |  |  | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm1()); | 
|---|
|  |  |  | vo.setError(crnError == null ? "未知异常" : crnError.getErrName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (crnProtocol.getTaskNo() > 0) { | 
|---|
|  |  |  | WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo()); | 
|---|
|  |  |  | if (wrkMast != null) { | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/barcode/output/site") | 
|---|
|  |  |  | public R crnOutput(){ | 
|---|
|  |  |  | ArrayList<JSONObject> jsonObjects = new ArrayList<>(OutputQueue.BARCODE); | 
|---|
|  |  |  | jsonObjects.sort(new Comparator<JSONObject>() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int compare(JSONObject o1, JSONObject o2) { | 
|---|
|  |  |  | Date o1Time = DateUtils.convert(o1.getString("time"), DateUtils.yyyyMMddHHmmss_F); | 
|---|
|  |  |  | Date o2Time = DateUtils.convert(o2.getString("time"), DateUtils.yyyyMMddHHmmss_F); | 
|---|
|  |  |  | return (int) (o2Time.getTime() - o1Time.getTime()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return R.ok().add(JSON.toJSONString(jsonObjects)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|