| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.CommandInfo; |
| | | import com.zy.asrs.entity.TaskWrk; |
| | | import com.zy.asrs.entity.param.taskCreateParam; |
| | | import com.zy.asrs.service.CommandInfoService; |
| | | import com.zy.asrs.service.OpenService; |
| | | import com.zy.asrs.service.TaskWrkService; |
| | | import com.zy.asrs.domain.param.ApplyInDevpDto; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.CrnStatusParam; |
| | | import com.zy.asrs.entity.param.TaskCreateParam; |
| | | import com.zy.asrs.entity.param.WMSAndAGVInterfaceParam; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | @RequestMapping("/open") |
| | | public class OpenController extends BaseController { |
| | | |
| | | public static final ArrayList<String> APP_KEY_LIST = new ArrayList<String>() {{ |
| | | add("ea1f0459efc02a79f046f982767939ae"); |
| | | }}; |
| | | private static final boolean auth = true; |
| | | @Autowired |
| | | private OpenService openService; |
| | | @Autowired |
| | | private TaskWrkService taskWrkService; |
| | | @Autowired |
| | | private CommandInfoService commandInfoService; |
| | | |
| | | public static final ArrayList<String> APP_KEY_LIST = new ArrayList<String>() {{ |
| | | add("ea1f0459efc02a79f046f982767939ae"); |
| | | }}; |
| | | @Autowired |
| | | private TaskWrkController taskWrkController; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private BasCrnErrorService basCrnErrorService; |
| | | |
| | | //创建任务 |
| | | @PostMapping("/taskCreate") |
| | | @Transactional |
| | | public R taskCreate(@RequestHeader String appkey, |
| | | @RequestBody taskCreateParam param, |
| | | HttpServletRequest request) { |
| | | @RequestBody List<TaskCreateParam> param1, |
| | | HttpServletRequest request) { |
| | | auth(appkey, param1, request); |
| | | try { |
| | | List<TaskCreateParam> paramList = new ArrayList<>(); |
| | | List<String> locNoList = new ArrayList<>(); |
| | | for (TaskCreateParam param : param1) { |
| | | if (Cools.isEmpty(param)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | } |
| | | if (Cools.isEmpty(param.getTaskNo())) { |
| | | return R.error("任务号[taskNo]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getIoType())) { |
| | | return R.error("任务类型[ioType]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getBarcode())) { |
| | | return R.error("条码[barcode]不能为空"); |
| | | } |
| | | String locNo = null; |
| | | if (param.getIoType() == 1) { |
| | | locNo = param.getTargetPoint(); |
| | | } else { |
| | | locNo = param.getStartPoint(); |
| | | } |
| | | try { |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no", locNo).ne("loc_sts", "X")); |
| | | if (Cools.isEmpty(locMast)) { |
| | | log.error("库位号不存在" + locNo); |
| | | return R.error("库位号不存在" + locNo).add("库位号不存在" + locNo); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("库位号检测程序异常==》异常信息" + e); |
| | | return R.error("库位号检测程序异常").add("库位号检测程序异常==》异常信息" + e); |
| | | } |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts", "F") |
| | | .eq("loc_no", locNo) |
| | | .eq("barcode", param.getBarcode())); |
| | | if (Cools.isEmpty(locMast)) { |
| | | return R.error("该库位不满足出库条件" + param.getTargetPoint()); |
| | | } |
| | | if (!locNoList.contains(locMast.getLocNo())) { |
| | | locNoList.add(locMast.getLocNo()); |
| | | paramList.add(param); |
| | | } else { |
| | | return R.error("该库位不能同时下发两笔任务" + locMast.getLocNo()); |
| | | } |
| | | } |
| | | for (TaskCreateParam param : paramList) { |
| | | openService.taskCreate(param); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("任务下发异常" + e); |
| | | return R.error(); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | //任务取消接口 |
| | | @PostMapping("/taskCancel") |
| | | public R taskCancel(@RequestHeader String appkey, |
| | | @RequestBody WMSAndAGVInterfaceParam param, |
| | | HttpServletRequest request) { |
| | | auth(appkey, param, request); |
| | | if (Cools.isEmpty(param)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | return R.error("参数为空!"); |
| | | } else if (Cools.isEmpty(param.getTaskNo())) { |
| | | return R.error("工作号为空!"); |
| | | } else if (Cools.isEmpty(param.getIoType())) { |
| | | return R.error("操作类型为空!"); |
| | | } else if (Cools.isEmpty(param.getBarcode())) { |
| | | return R.error("托盘码不能为空!"); |
| | | } |
| | | if (Cools.isEmpty(param.getTaskNo())) { |
| | | return R.error("任务号[taskNo]不能为空"); |
| | | |
| | | TaskWrk taskWrk = taskWrkService.selectOne(new EntityWrapper<TaskWrk>() |
| | | .eq("task_no", param.getTaskNo()) |
| | | .eq("io_type", param.getIoType()) |
| | | .eq("barcode", param.getBarcode())); |
| | | if (Cools.isEmpty(taskWrk)) { |
| | | return R.error("未查到当前任务---" + param); |
| | | } |
| | | if (Cools.isEmpty(param.getIoType())) { |
| | | return R.error("任务类型[ioType]不能为空"); |
| | | boolean sign = false; |
| | | switch (param.getTaskStatus()) { |
| | | case 1://正常取消 |
| | | if (taskWrk.getStatus() > 1) { |
| | | return R.error("任务已开始执行"); |
| | | } |
| | | break; |
| | | case 2://正常完成 |
| | | if (taskWrk.getStatus() > 1) { |
| | | return R.error("任务已开始执行"); |
| | | } |
| | | sign = true; |
| | | break; |
| | | default: |
| | | return R.error("未知操作"); |
| | | } |
| | | if (Cools.isEmpty(param.getBarcode())) { |
| | | return R.error("条码[barcode]不能为空"); |
| | | return taskWrkOperate(taskWrk, sign); |
| | | } |
| | | |
| | | //任务操作 |
| | | private R taskWrkOperate(TaskWrk taskWrk, boolean sign) { |
| | | try { |
| | | if (sign) {//完成 |
| | | return taskWrkController.complete(taskWrk.getTaskNo()); |
| | | } else {//取消 |
| | | return taskWrkController.cancel(taskWrk.getTaskNo()); |
| | | } |
| | | } catch (Exception e) { |
| | | return R.error(); |
| | | } |
| | | openService.taskCreate(param); |
| | | return R.ok(); |
| | | } |
| | | |
| | | //设备状态查询接口 |
| | | @GetMapping("/deviceStatus") |
| | | @Transactional |
| | | public R deviceStatus() { |
| | | List<CrnStatusParam> crnStatusParams = new ArrayList<>(); |
| | | List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>()); |
| | | for (BasCrnp basCrnp : basCrnps) { |
| | | CrnStatusParam crnStatusParam = new CrnStatusParam(); |
| | | crnStatusParam.setCrnNo(basCrnp.getCrnNo()); |
| | | crnStatusParam.setCrnSts(basCrnp.getCrnSts()); |
| | | crnStatusParam.setErrorCode(basCrnp.getCrnErr()); |
| | | BasCrnError error = basCrnErrorService.selectOne(new EntityWrapper<BasCrnError>().eq("error_code", basCrnp.getCrnErr())); |
| | | if (Cools.isEmpty(error)) { |
| | | crnStatusParam.setErrorMsg(""); |
| | | } else { |
| | | crnStatusParam.setErrorMsg(error.getErrName()); |
| | | } |
| | | crnStatusParams.add(crnStatusParam); |
| | | } |
| | | return R.ok(crnStatusParams); |
| | | } |
| | | |
| | | private void auth(String appkey, Object obj, HttpServletRequest request) { |
| | | log.info("{}接口被访问;appkey:{};请求数据:{}", request.getServletPath(), appkey, JSON.toJSONString(obj)); |
| | | request.setAttribute("cache", obj); |
| | | if (Cools.isEmpty(appkey)) { |
| | | throw new CoolException("认证失败,请确认appkey无误!"); |
| | | } |
| | | if (!APP_KEY_LIST.contains(appkey)) { |
| | | throw new CoolException("认证失败,请确认appkey无误!"); |
| | | } |
| | | } |
| | | |
| | | //查询任务详情 |
| | |
| | | @GetMapping("/queryTaskCommand") |
| | | public R queryTaskCommand(@RequestHeader String appkey, |
| | | @RequestParam String taskNo, |
| | | |
| | | HttpServletRequest request) { |
| | | auth(appkey, taskNo, request); |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(taskNo); |
| | |
| | | return R.ok().add(commandInfos); |
| | | } |
| | | |
| | | private void auth(String appkey, Object obj, HttpServletRequest request) { |
| | | log.info("{}接口被访问;appkey:{};请求数据:{}", request.getServletPath(), appkey, JSON.toJSONString(obj)); |
| | | request.setAttribute("cache", obj); |
| | | if (Cools.isEmpty(appkey)) { |
| | | throw new CoolException("认证失败,请确认appkey无误!"); |
| | | } |
| | | if (!APP_KEY_LIST.contains(appkey)) { |
| | | throw new CoolException("认证失败,请确认appkey无误!"); |
| | | } |
| | | // 外置输送线wms通知输送线流动,上报时候上报站点即可 |
| | | @PostMapping("/applyInDevp") |
| | | public R applyInDevp(@RequestHeader String appkey, |
| | | @RequestBody ApplyInDevpDto param, |
| | | HttpServletRequest request) { |
| | | auth(appkey, param, request); |
| | | return openService.applyInDevp(param); |
| | | } |
| | | |
| | | } |