package com.zy.asrs.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.annotations.AppAuth; import com.core.common.Cools; import com.core.common.R; import com.zy.asrs.entity.AgvWrkMast; import com.zy.asrs.entity.param.AgvTaskCallBackParam; import com.zy.asrs.service.*; import com.zy.asrs.utils.AppAuthUtil; import com.zy.common.web.BaseController; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.PostConstruct; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.EnumSet; /** * 上报事件类型(eventType): *  task:上报任务状态。 *  task_allocated: 上报任务分配给机器人。 *  tote_load:上报取箱状态。 *  tote_unload:上报放箱状态。 *  robot_reach:机器人到达工作站。 *  weight:称重事件回调。 *  rfid:RFID识别事件回调。 * * 任务状态(status): *  success:成功。 *  fail:失败。 *  cancel:取消。 *  suspend:挂起。 */ @Slf4j @RestController @RequestMapping("/agv") public class AgvOpenController extends BaseController { @Autowired AgvWrkMastService agvWrkMastService; @Autowired ApiLogService apiLogService; @PostMapping("/task/event/status") @AppAuth(memo = "ESS任务回调") public R taskEventStaus(@RequestBody AgvTaskCallBackParam param, HttpServletRequest request){ apiLogService.save( "ESS任务回调", "/tzskwms/agv/task/event/status", null, null, JSON.toJSONString(JSONObject.toJSONString(param)), null, true ); //save api log (appkey 后续添加) AppAuthUtil.auth("",param, request); int wrkNo = Integer.parseInt(param.getTaskCode()); if(wrkNo < 0){ wrkNo = -wrkNo; } AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper().eq("wrk_no", wrkNo)); if(Cools.isEmpty(agvWrkMast)){ return R.error("任务编号错误"); } AgvTask agvTask = AgvTask.valueOf(param.getEventType()); Class clz = AgvTask.class; try { Method method = clz.getDeclaredMethod(param.getStatus(), AgvWrkMast.class, AgvTaskCallBackParam.class); method.invoke(agvTask,agvWrkMast,param); } catch (NoSuchMethodException e) { return R.error("任务状态status参数有误"); } catch (InvocationTargetException e) { log.error(e.getMessage()); return R.error(); } catch (IllegalAccessException e) { log.error(e.getMessage()); return R.error(); } return R.ok(); } } enum AgvTask{ /** * 上报任务状态 */ task{ @Transactional public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { //修改AGV工作档的工作状态为205.工作完成 agvWrkMastService.updateWrkStsByWrkNo(agvWrkMast.getWrkNo(),205); //出库任务 101.出库 || 103.拣料出库 || 107.盘点出库 if(agvWrkMast.getIoType() == 101 || agvWrkMast.getIoType() == 103 || agvWrkMast.getIoType() == 107){ //修改出库站点状态 agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getLocNo(),"F",agvWrkMast.getBarcode()); } //出库任务 110.空板出库 if(agvWrkMast.getIoType() == 110){ agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getLocNo(),"F",agvWrkMast.getBarcode()); } } public void fail(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void cancel(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void suspend(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } }, /** * 上报任务分配给机器人 */ task_allocated{ @Transactional public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void fail(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void cancel(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void suspend(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } }, /** * 上报取箱状态 */ tote_load{ @Transactional public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { //入库任务 || 拣料入库任务 ||盘点再入库 ||空板入库 if(agvWrkMast.getIoType() == 1 || agvWrkMast.getIoType() == 53 || agvWrkMast.getIoType() == 57 || agvWrkMast.getIoType() == 10){ //修改源站点状态为O.空,以及解绑托盘条码 agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getSourceLocNo(),"O",""); } //修改AGV工作档的工作状态为203.RCS放货中 agvWrkMastService.updateWrkStsByWrkNo(agvWrkMast.getWrkNo(),203); } public void fail(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void cancel(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void suspend(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } }, /** * 上报放箱状态 */ tote_unload{ @Transactional public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { //修改工作档状态为204.放货完成 agvWrkMastService.updateWrkStsByWrkNo(agvWrkMast.getWrkNo(),204); } public void fail(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void cancel(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void suspend(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } }, robot_reach{ @Transactional public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void fail(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void cancel(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void suspend(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } }, weight{ @Transactional public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void fail(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void cancel(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void suspend(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } }, rfid{ @Transactional public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void fail(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void cancel(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } public void suspend(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) { } }; //任务状态为成功 public abstract void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param); //任务状态为失败 public abstract void fail(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param); //任务状态为取消 public abstract void cancel(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param); //任务状态为挂起 public abstract void suspend(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param); @Setter AgvBasDevpService agvBasDevpService; @Setter AgvLocMastService agvLocMastService; @Setter AgvLocDetlService agvLocDetlService; @Setter AgvWrkMastService agvWrkMastService; @Setter AgvWrkDetlService agvWrkDetlService; @Setter AgvWaitPakinService agvWaitPakinService; @Setter AgvWaitPakinLogService agvWaitPakinLogService; @Setter AgvWrkMastLogService agvWrkMastLogService; @Setter AgvWrkDetlLogService agvWrkDetlLogService; @Component public static class ReportTypeServiceInjector { @Autowired AgvBasDevpService agvBasDevpService; @Autowired AgvLocMastService agvLocMastService; @Autowired AgvLocDetlService agvLocDetlService; @Autowired AgvWrkMastService agvWrkMastService; @Autowired AgvWrkDetlService agvWrkDetlService; @Autowired AgvWaitPakinService agvWaitPakinService; @Autowired AgvWaitPakinLogService agvWaitPakinLogService; @Autowired AgvWrkMastLogService agvWrkMastLogService; @Autowired AgvWrkDetlLogService agvWrkDetlLogService; @PostConstruct public void postConstruct(){ for(AgvTask task : EnumSet.allOf(AgvTask.class)){ task.setAgvBasDevpService(agvBasDevpService); task.setAgvLocDetlService(agvLocDetlService); task.setAgvLocMastService(agvLocMastService); task.setAgvWrkMastService(agvWrkMastService); task.setAgvWaitPakinService(agvWaitPakinService); task.setAgvWaitPakinLogService(agvWaitPakinLogService); task.setAgvWrkMastLogService(agvWrkMastLogService); task.setAgvWrkDetlLogService(agvWrkDetlLogService); task.setAgvWrkDetlService(agvWrkDetlService); } } } }