| | |
| | | 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.BasStation; |
| | |
| | | import com.zy.asrs.service.BasStationService; |
| | | import com.zy.asrs.service.MesService; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @RestController |
| | | @Slf4j |
| | | public class MesController extends BaseController { |
| | | |
| | | @Resource |
| | | private MesService mesService; |
| | | |
| | | private void auth(String appkey, Object obj, HttpServletRequest request) { |
| | | log.info("{}接口被访问;appkey:{};请求数据:{}", request.getRequestURI(), appkey, JSON.toJSONString(obj)); |
| | | request.setAttribute("cache", obj); |
| | | } |
| | | |
| | | // 物料信息同步 |
| | | @PostMapping("/api/mes/synMatInfo") |
| | | public MesReturn synMatInfo(@RequestBody MesMatInfo param){ |
| | | |
| | | @AppAuth(memo = "物料信息同步") |
| | | public MesReturn synMatInfo(@RequestHeader(required = false) String appkey,@RequestBody MesMatInfo param,HttpServletRequest request){ |
| | | auth(appkey, param, request); |
| | | MesReturn mesReturn = new MesReturn(); |
| | | mesReturn.setSuccess(mesService.synMatInfo(param) == 1 ? "1" : "2"); |
| | | return mesReturn; |
| | | } |
| | | |
| | | @PostMapping("/api/tms/queryStock") |
| | | @AppAuth(memo = "TMS查询库存") |
| | | public R queryStock(@RequestHeader(required = false) String appkey,@RequestBody JSONObject param,HttpServletRequest request){ |
| | | auth(appkey, param, request); |
| | | String matnr = param.getString("matnr"); |
| | | return mesService.queryStock(matnr); |
| | | } |
| | | |
| | | // 出库申请 |
| | | @PostMapping("/api/mes/outBoundOrder") |
| | | public MesReturn outBoundOrder(@RequestBody MesInApply param){ |
| | | MesReturn mesReturn = new MesReturn(); |
| | | // 终点为空,计算接驳位 |
| | | BasStation basStation = null; |
| | | if (Cools.isEmpty(param.getNextStationId())) { |
| | | List<BasStation> basStations = basStationService.selectList(new EntityWrapper<BasStation>().eq("loc_sts", "O")); |
| | | if(basStations.isEmpty()) { |
| | | mesReturn.setSuccess("2"); |
| | | mesReturn.setMessage("无空接驳位,请稍后再试!"); |
| | | return mesReturn; |
| | | } |
| | | // 接驳点 |
| | | basStation = basStations.get(0); |
| | | param.setNextStationId(basStation.getDevNo()); |
| | | |
| | | // 先更新接驳点状态 |
| | | basStation.setModiTime(new Date()); |
| | | basStation.setLocSts("S"); |
| | | basStation.setBarcode(param.getDjNo()); |
| | | basStationService.updateById(basStation); |
| | | } |
| | | int i = mesService.outBoundOrder(param); |
| | | if(i == 1) { |
| | | mesReturn.setSuccess("1"); |
| | | } else { |
| | | // 释放接驳点 |
| | | if(basStation != null) { |
| | | basStation.setModiTime(new Date()); |
| | | basStation.setLocSts("O"); |
| | | basStation.setBarcode(""); |
| | | basStationService.updateById(basStation); |
| | | } |
| | | @AppAuth(memo = "出库申请(TMS调用)") |
| | | public MesReturn outBoundOrder(@RequestHeader(required = false) String appkey,@RequestBody MesInApply param,HttpServletRequest request){ |
| | | auth(appkey, param, request); |
| | | if(Cools.isEmpty(param.getTaskNo(),param.getOrderNo(),param.getStationId())) { |
| | | MesReturn mesReturn = new MesReturn(); |
| | | mesReturn.setSuccess("2"); |
| | | mesReturn.setMessage("参数不能为空:" + JSONObject.toJSONString(param)); |
| | | return mesReturn; |
| | | } |
| | | return mesReturn; |
| | | |
| | | return mesService.outBoundOrder(param); |
| | | } |
| | | |
| | | // // 出库申请(叫料),装配库、滑块库 |
| | |
| | | return mesReturn; |
| | | } |
| | | |
| | | // 入站允许 |
| | | @PostMapping("/api/mes/allowInStation") |
| | | public MesReturn allowInStation(@RequestBody TransInOutStationAllow param){ |
| | | |
| | | @AppAuth(memo = "入站允许") |
| | | public MesReturn allowInStation(@RequestHeader(required = false) String appkey,@RequestBody TransInOutStationAllow param,HttpServletRequest request){ |
| | | auth(appkey, param, request); |
| | | return mesService.allowInStation(param); |
| | | } |
| | | |
| | |
| | | // 下发运输任务,mes调用下刀06(呼叫agv搬运) |
| | | @PostMapping("/api/mes/submitTask") |
| | | public JSONObject submitTask(@RequestBody TransTask param){ |
| | | log.info("下刀(退刀):{}",JSONObject.toJSONString(param)); |
| | | // 终点为空,计算接驳位 |
| | | BasStation basStation = null; |
| | | if (Cools.isEmpty(param.getNextStationId())) { |
| | |
| | | basStation.setBarcode(param.getDjNo()); |
| | | basStationService.updateById(basStation); |
| | | } |
| | | |
| | | JSONObject sendAgvTask; |
| | | param.setAgvFactory(1); // 海康 |
| | | param.setNextStationId("A1"); |
| | | JSONObject sendAgvTask = mesService.submitTask(param); |
| | | if (!"1".equals(sendAgvTask.getString("Success"))) { |
| | | try { |
| | | sendAgvTask = mesService.submitTask(param); |
| | | if (!"1".equals(sendAgvTask.getString("Success"))) { |
| | | // 释放接驳点 |
| | | if(basStation != null) { |
| | | basStation.setModiTime(new Date()); |
| | | basStation.setLocSts("O"); |
| | | basStation.setBarcode(""); |
| | | basStationService.updateById(basStation); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | // 释放接驳点 |
| | | if(basStation != null) { |
| | | basStation.setModiTime(new Date()); |
| | |
| | | basStation.setBarcode(""); |
| | | basStationService.updateById(basStation); |
| | | } |
| | | throw e; |
| | | } |
| | | return sendAgvTask; |
| | | } |
| | |
| | | return mesReturn; |
| | | } |
| | | |
| | | |
| | | // region 测试 |
| | | @GetMapping("/api/mes/transDj") |
| | | public int transDj(@RequestParam String taskNo,@RequestParam String djNo){ |
| | | |
| | | return mesService.transDj(taskNo,djNo); |
| | | } |
| | | |
| | | // 退空托盘返回产线 pda上操作空托返回产线 |
| | | @GetMapping("/tkt") |
| | | public R tkt(@RequestParam String taskNo){ |
| | | return mesService.tkt(taskNo); |
| | | } |
| | | // endregion |
| | | |
| | | } |