| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Arith; |
| | | import com.core.common.Cools; |
| | |
| | | import com.zy.asrs.service.BasShuttleErrService; |
| | | import com.zy.asrs.service.BasShuttleService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.common.model.MatDto; |
| | | import com.zy.common.model.SearchLocParam; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.LedSlave; |
| | | import com.zy.core.model.ShuttleSlave; |
| | | import com.zy.core.model.command.LedCommand; |
| | | import com.zy.core.model.protocol.ShuttleProtocol; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.LedThread; |
| | | import com.zy.core.thread.ShuttleThread; |
| | | import com.zy.core.thread.impl.NormalLedThread; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.io.IOException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private BasShuttleErrService basShuttleErrService; |
| | | @Value("${asrs.wmsUrl}") |
| | | private String wmsUrl; |
| | | |
| | | /** |
| | | * 获取当前时间 |
| | |
| | | /** |
| | | * 获取其他信息 |
| | | */ |
| | | // @GetMapping("/led") |
| | | // public R monitorLed(@RequestParam("ledId") Integer ledId) { |
| | | // BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no", ledId)); |
| | | // if (Cools.isEmpty(basDevp)) { |
| | | // return R.ok(); |
| | | // } |
| | | // WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", basDevp.getWrkNo())); |
| | | // if (Cools.isEmpty(wrkMast)) { |
| | | // return R.ok(); |
| | | // } |
| | | // List<LedCommand> commands = new ArrayList<>(); |
| | | // |
| | | // // 组装命令 |
| | | // LedCommand ledCommand = new LedCommand(); |
| | | // ledCommand.setWorkNo(wrkMast.getWrkNo()); |
| | | // ledCommand.setIoType(wrkMast.getIoType()); |
| | | // // 出库模式 |
| | | // switch (wrkMast.getIoType()) { |
| | | // case 1: |
| | | // ledCommand.setTitle("全板入库"); |
| | | // break; |
| | | // case 10: |
| | | // ledCommand.setTitle("空板入库"); |
| | | // break; |
| | | // case 101: |
| | | // ledCommand.setTitle("全板出库"); |
| | | // break; |
| | | // case 103: |
| | | // ledCommand.setTitle("拣料出库"); |
| | | // break; |
| | | // case 104: |
| | | // ledCommand.setTitle("并板出库"); |
| | | // break; |
| | | // case 107: |
| | | // ledCommand.setTitle("盘点出库"); |
| | | // break; |
| | | // case 110: |
| | | // ledCommand.setTitle("空板出库"); |
| | | // ledCommand.setEmptyMk(true); |
| | | // break; |
| | | // case 53: |
| | | // ledCommand.setTitle("拣料入库"); |
| | | // break; |
| | | // case 57: |
| | | // ledCommand.setTitle("盘点入库"); |
| | | // break; |
| | | // case 54: |
| | | // ledCommand.setTitle("并板入库"); |
| | | // break; |
| | | // default: |
| | | // break; |
| | | // } |
| | | // ledCommand.setSourceLocNo(wrkMast.getSourceLocNo()); |
| | | // ledCommand.setLocNo(wrkMast.getLocNo()); |
| | | // ledCommand.setStaNo(wrkMast.getStaNo()); |
| | | //// ledCommand.setSourceStaNo(wrkMast.getSourceStaNo()); |
| | | // if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) { |
| | | // List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()); |
| | | // try { |
| | | // if (wrkMast.getIoType() > 100) { |
| | | // for (WrkDetl wrkDetl : wrkDetls) { |
| | | // LocDetl locDetl = locDetlService.selectMatnrSpecs(wrkDetl.getMatnr(), wrkDetl.getSpecs(), wrkMast.getSourceLocNo()); |
| | | // wrkDetl.setWeight(locDetl.getAnfme()); |
| | | // } |
| | | // } else { |
| | | // for (WrkDetl wrkDetl : wrkDetls) { |
| | | // wrkDetl.setWeight(wrkDetl.getAnfme()); |
| | | // } |
| | | // } |
| | | // } catch (Exception e) { |
| | | //// log.error("工作档案明细输入电视机失败1:异常信息==》"+e); |
| | | // } |
| | | // wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), wrkDetl.getWeight(), wrkDetl.getSpecs(), wrkDetl.getModel()))); |
| | | // } |
| | | // commands.add(ledCommand); |
| | | // return R.ok().add(commands); |
| | | // } |
| | | @GetMapping("/led") |
| | | public R monitorLed(@RequestParam("ledId") Integer ledId) { |
| | | int dev_no = 1011; |
| | | if (ledId == 1) { |
| | | dev_no = 1011; |
| | | } else if (ledId == 2) { |
| | | dev_no = 1014; |
| | | } else if (ledId == 3) { |
| | | dev_no = 1021; |
| | | } else if (ledId == 4) { |
| | | dev_no = 1025; |
| | | } |
| | | BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no", dev_no)); |
| | | if (Cools.isEmpty(basDevp)) { |
| | | return R.ok(); |
| | | } |
| | | if (Cools.isEmpty(basDevp.getWrkNo1())) { |
| | | return R.ok(); |
| | | } |
| | | List<LedCommand> commands = new ArrayList<>(); |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("taskNo", basDevp.getWrkNo1()); |
| | | String response = null; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath("/rpc/led/getTask2") |
| | | .setJson(JSON.toJSONString(param)) |
| | | .build() |
| | | .doPost(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | Integer code = jsonObject.getInteger("code"); |
| | | if (code.equals(200)) { |
| | | String data = jsonObject.getString("data"); |
| | | List<LedCommand> wrkDetls = JSONArray.parseArray(data, LedCommand.class); |
| | | commands.addAll(wrkDetls); |
| | | } |
| | | return R.ok().add(commands); |
| | | } |
| | | |
| | | /** |
| | | * 异常通知 |
| | | */ |
| | | @GetMapping("/led/error") |
| | | public R monitorLedError(@RequestParam("ledId") Integer ledId) { |
| | | BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no", ledId)); |
| | | if (Cools.isEmpty(basDevp)) { |
| | | return R.ok(); |
| | | String errorMsg = ""; |
| | | for (LedSlave slave : slaveProperties.getLed()) { |
| | | if (slave.getId() == ledId) { |
| | | NormalLedThread ledThread = (NormalLedThread) SlaveConnection.get(SlaveType.Led, slave.getId()); |
| | | if (null != ledThread) { |
| | | errorMsg = ledThread.getErrorMsg().toString(); |
| | | } |
| | | } |
| | | } |
| | | if (Cools.isEmpty(basDevp.getArea())) { |
| | | return R.ok(); |
| | | } |
| | | if (basDevp.getLoading().equals("N")) { |
| | | basDevp.setArea(""); |
| | | basDevpService.updateById(basDevp); |
| | | return R.ok(); |
| | | } |
| | | String errorMsg = basDevp.getArea(); |
| | | |
| | | return R.ok().add(errorMsg); |
| | | } |
| | | /** |
| | | * 异常通知 |
| | | */ |
| | | // @GetMapping("/led/error") |
| | | // public R monitorLedError(@RequestParam("ledId") Integer ledId) { |
| | | // int dev_no = 1012; |
| | | // if (ledId == 1) { |
| | | // dev_no = 1012; |
| | | // } else if (ledId == 2) { |
| | | // dev_no = 1014; |
| | | // } else if (ledId == 3) { |
| | | // dev_no = 1022; |
| | | // } else if (ledId == 4) { |
| | | // dev_no = 1025; |
| | | // } |
| | | // BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no", dev_no)); |
| | | // if (Cools.isEmpty(basDevp)) { |
| | | // return R.ok(); |
| | | // } |
| | | // if (Cools.isEmpty(basDevp.getArea())) { |
| | | // return R.ok(); |
| | | // } |
| | | // if (basDevp.getLoading().equals("N")) { |
| | | // basDevp.setArea(""); |
| | | // basDevpService.updateById(basDevp); |
| | | // return R.ok(); |
| | | // } |
| | | // String errorMsg = basDevp.getArea(); |
| | | // |
| | | // return R.ok().add(errorMsg); |
| | | // } |
| | | |
| | | /** |
| | | * 设备异常通知 |
| | |
| | | @GetMapping("/device/error") |
| | | public R monitorDeviceError() { |
| | | ArrayList<HashMap<String, Object>> list = new ArrayList<>(); |
| | | List<BasShuttle> basCrnpLiset = shuttleService.selectList(new EntityWrapper<BasShuttle>()); |
| | | |
| | | for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) { |
| | | // 获取四向穿梭车信息 |
| | |
| | | continue; |
| | | } |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | if (Cools.isEmpty(shuttleProtocol.getErrorCode())) { |
| | | continue; |
| | | } |
| | | int i = Integer.parseInt(shuttleProtocol.getErrorCode()); |
| | | if (i > 0) { |
| | | BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(i); |