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;
|
import java.util.Map;
|
|
/**
|
* 上报事件类型(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任务回调",
|
"/phyzwms/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<AgvWrkMast>().eq("wrk_no", wrkNo));
|
if(Cools.isEmpty(agvWrkMast)){
|
agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("barcode",param.getPodCode()));
|
if (Cools.isEmpty(agvWrkMast)){
|
return R.error("任务编号错误");
|
}
|
}
|
|
if(agvWrkMast.getWrkSts() >= 205){
|
return R.error("当前任务已完成");
|
}
|
|
AgvTask agvTask = AgvTask.valueOf(param.getMethod());
|
Class<AgvTask> clz = AgvTask.class;
|
try {
|
Method method = clz.getDeclaredMethod("success", 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();
|
}
|
|
@PostMapping("/conveyor/loadContainerFinish ")
|
@AppAuth(memo = "取货架完成通知")
|
public R loadContainerFinish(@RequestBody Map<String,Object> params){
|
|
return R.ok();
|
}
|
}
|
|
enum AgvTask{
|
|
/**
|
* 上报任务完成
|
*/
|
end{
|
@Transactional
|
public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) {
|
//修改AGV工作档的工作状态为205.工作完成
|
agvWrkMast.setWrkSts(205L);
|
|
//出库任务 101.出库 || 103.拣料出库 || 107.盘点出库
|
if(agvWrkMast.getIoType() == 101 || agvWrkMast.getIoType() == 103 || agvWrkMast.getIoType() == 107){
|
//修改出库站点状态
|
agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getLocNo(),"F",agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue());
|
}
|
//出库任务 110.空板出库
|
if(agvWrkMast.getIoType() == 110){
|
agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getLocNo(),"F",agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue());
|
agvWrkMast.setWrkSts(206L);
|
}
|
agvWrkMastService.updateById(agvWrkMast);
|
}
|
},
|
/**
|
* 任务开始
|
*/
|
start{
|
@Transactional
|
public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) {
|
//修改AGV工作档的工作状态为203.任务开始
|
agvWrkMast.setWrkSts(203L);
|
agvWrkMastService.updateById(agvWrkMast);
|
}
|
},
|
/**
|
* 走出储位状态
|
*/
|
outbin{
|
@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","",null);
|
}
|
|
//修改AGV工作档的工作状态为203.RCS放货中
|
agvWrkMastService.updateWrkStsByWrkNo(agvWrkMast.getWrkNo(),204);
|
|
}
|
|
},
|
/**
|
* 上报放箱状态
|
*/
|
cancel{
|
@Transactional
|
public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) {
|
|
|
}
|
|
},
|
apply{
|
@Transactional
|
public void success(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);
|
}
|
}
|
|
}
|
}
|