|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.zy.asrs.domain.vo.PlcErrorTableVo; | 
|---|
|  |  |  | import com.zy.asrs.domain.vo.SiteTableVo; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasDevp; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasSte; | 
|---|
|  |  |  | import com.zy.asrs.entity.WrkCharge; | 
|---|
|  |  |  | import com.zy.asrs.service.BasDevpService; | 
|---|
|  |  |  | import com.zy.asrs.service.BasSteService; | 
|---|
|  |  |  | import com.zy.asrs.service.WrkChargeService; | 
|---|
|  |  |  | import com.zy.common.model.enums.WrkChargeType; | 
|---|
|  |  |  | import com.zy.common.service.CommonService; | 
|---|
|  |  |  | import com.zy.core.DevpThread; | 
|---|
|  |  |  | import com.zy.core.cache.MessageQueue; | 
|---|
|  |  |  | import com.zy.core.cache.OutputQueue; | 
|---|
|  |  |  | import com.zy.core.cache.SlaveConnection; | 
|---|
|  |  |  | import com.zy.core.enums.SlaveType; | 
|---|
|  |  |  | import com.zy.core.enums.SteTaskModeType; | 
|---|
|  |  |  | import com.zy.core.enums.SteChargeType; | 
|---|
|  |  |  | import com.zy.core.enums.SteStatusType; | 
|---|
|  |  |  | import com.zy.core.model.DevpSlave; | 
|---|
|  |  |  | import com.zy.core.model.Task; | 
|---|
|  |  |  | import com.zy.core.model.command.SteCommand; | 
|---|
|  |  |  | import com.zy.core.model.protocol.StaProtocol; | 
|---|
|  |  |  | import com.zy.core.model.protocol.SteProtocol; | 
|---|
|  |  |  | import com.zy.core.properties.SlaveProperties; | 
|---|
|  |  |  | import com.zy.core.DevpThread; | 
|---|
|  |  |  | import com.zy.core.thread.SiemensDevpThread; | 
|---|
|  |  |  | import com.zy.core.thread.SteThread; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 输送设备接口 | 
|---|
|  |  |  | 
|---|
|  |  |  | private SlaveProperties slaveProperties; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BasDevpService basDevpService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WrkChargeService wrkChargeService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BasSteService basSteService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CommonService commonService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/io/mode/info/site") | 
|---|
|  |  |  | @ManagerAuth(memo = "充电模式") | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping("/io/mode/action/site") | 
|---|
|  |  |  | @ManagerAuth(memo = "充电控制") | 
|---|
|  |  |  | public R ioModeAction(@RequestParam("floor") Integer floor, @RequestParam("charge") Boolean charge){ | 
|---|
|  |  |  | for (DevpSlave devp : slaveProperties.getDevp()) { | 
|---|
|  |  |  | // 输送线充电命令下发区 -------------------------------------------------------------------------- | 
|---|
|  |  |  | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); | 
|---|
|  |  |  | boolean res = devpThread.charge(floor - 1, charge); | 
|---|
|  |  |  | if (!charge && res) { | 
|---|
|  |  |  | // 穿梭车充电命令下发区 -------------------------------------------------------------------------- | 
|---|
|  |  |  | int steNo = floor; | 
|---|
|  |  |  | SteCommand steCommand = new SteCommand(); | 
|---|
|  |  |  | steCommand.setSteNo(steNo); // 穿梭车编号 | 
|---|
|  |  |  | steCommand.setTaskNo(9999); // 工作号 | 
|---|
|  |  |  | steCommand.setTaskMode(SteTaskModeType.CLOSE_CHARGE); | 
|---|
|  |  |  | if (!MessageQueue.offer(SlaveType.Ste, steNo, new Task(2, steCommand))) { | 
|---|
|  |  |  | log.error("穿梭车命令下发失败,穿梭车号={},任务数据={}", steNo, JSON.toJSON(steCommand)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return res?R.ok():R.error(); | 
|---|
|  |  |  | if (null != wrkChargeService.selectWorking(null, WrkChargeType.charge)) { | 
|---|
|  |  |  | return R.error("目前存在小车充电任务,请稍后再试"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | if (null != wrkChargeService.selectWorking(null, WrkChargeType.reset)) { | 
|---|
|  |  |  | return R.error("目前存在小车复位任务,请稍后再试"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (charge) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SteChargeType steCharge = SteChargeType.get(floor); | 
|---|
|  |  |  | assert steCharge != null; | 
|---|
|  |  |  | Integer steNo = basSteService.hasCarOfLocNo(steCharge.locNo); | 
|---|
|  |  |  | if (Cools.isEmpty(steNo)) { | 
|---|
|  |  |  | return R.error(steNo + "号小车不在" + floor + "号充电桩,请检查小车定位"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, steNo); | 
|---|
|  |  |  | SteProtocol steProtocol = steThread.getSteProtocol(); | 
|---|
|  |  |  | BasSte basSte = basSteService.selectById(steNo); | 
|---|
|  |  |  | if (steProtocol.getMode() == 0) { | 
|---|
|  |  |  | return R.error(steNo + "号小车离线,无法操作"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!steProtocol.getStatusType().equals(SteStatusType.IDLE)) { | 
|---|
|  |  |  | return R.error(steNo + "号小车不是空闲,无法操作"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WrkCharge wrkCharge = wrkChargeService.selectWorking(steNo, WrkChargeType.reset); | 
|---|
|  |  |  | if (wrkCharge == null) { | 
|---|
|  |  |  | // 开始穿梭车复位任务 | 
|---|
|  |  |  | wrkCharge = new WrkCharge(); | 
|---|
|  |  |  | wrkCharge.setSteNo(steNo); | 
|---|
|  |  |  | wrkCharge.setWrkNo(commonService.getChargeWorkNo(6)); | 
|---|
|  |  |  | wrkCharge.setWrkSts(41L);   // 41.小车准备复位 | 
|---|
|  |  |  | wrkCharge.setCrnNo(2);  // 固定2号堆垛机 | 
|---|
|  |  |  | wrkCharge.setIoPri((double) 10); | 
|---|
|  |  |  | wrkCharge.setSourceLocNo(steCharge.locNo); | 
|---|
|  |  |  | wrkCharge.setLocNo(basSte.getIdleLoc()); | 
|---|
|  |  |  | wrkCharge.setMemo("reset"); | 
|---|
|  |  |  | wrkCharge.setAppeTime(new Date()); | 
|---|
|  |  |  | if (!wrkChargeService.insert(wrkCharge)) { | 
|---|
|  |  |  | log.error("保存{}号穿梭车复位任务失败!!!", steNo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(steNo + "号小车准备离开" + floor + "号充电桩"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/table/site") | 
|---|