| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | |
| | | import com.zy.asrs.utils.OrderInAndOutUtil; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.common.utils.NodeUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.rmi.CORBA.Util; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Created by vincent on 2022/4/9 |
| | |
| | | private BasArmMastService basArmMastService; |
| | | @Autowired |
| | | private BasArmMastSignService basArmMastSignService; |
| | | |
| | | @Autowired |
| | | private BasAgvMastService basAgvMastService; |
| | | @Autowired |
| | | private LocOwnerService locOwnerService; |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | @Override |
| | | @Transactional |
| | | public void pakinOrderCreate(OpenOrderPakinParam param) { |
| | |
| | | } |
| | | DocType docType = docTypeService.selectOrAdd(param.getOrderType(), Boolean.TRUE); |
| | | Date now = new Date(); |
| | | LocOwner locOwner = null; |
| | | if (!Cools.isEmpty(param.getOwnerId())) { |
| | | locOwner = locOwnerService.selectById(param.getOwnerId()); |
| | | } else { |
| | | locOwner = locOwnerService.selectById(1); |
| | | } |
| | | // 单据主档 |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | |
| | | DateUtils.convert(now), // 单据日期 |
| | | docType.getDocId(), // 单据类型 |
| | | null, // 项目编号 |
| | | null, // |
| | | param.getStandby1(), //项目名称 客户PO号 |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | null, // 客户编号 |
| | | null, // 客户 |
| | | locOwner.getOwner(), // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | |
| | | orderDetl.setStandby1(detlDto.getStandby1()); |
| | | orderDetl.setStandby2(detlDto.getStandby2()); |
| | | orderDetl.setStandby3(detlDto.getStandby3()); |
| | | orderDetl.setBoxType1(detlDto.getBoxType1()); |
| | | orderDetl.setBoxType2(detlDto.getBoxType2()); |
| | | orderDetl.setBoxType3(detlDto.getBoxType3()); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setCreateBy(9527L); |
| | |
| | | } |
| | | DocType docType = docTypeService.selectOrAdd(param.getOrderType(), Boolean.FALSE); |
| | | Date now = new Date(); |
| | | LocOwner locOwner = null; |
| | | if (!Cools.isEmpty(param.getOwnerId())) { |
| | | locOwner = locOwnerService.selectById(param.getOwnerId()); |
| | | } else { |
| | | locOwner = locOwnerService.selectById(1); |
| | | } |
| | | // 单据主档 |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | |
| | | DateUtils.convert(now), // 单据日期 |
| | | docType.getDocId(), // 单据类型 |
| | | null, // 项目编号 |
| | | null, // |
| | | param.getStandby1(), //项目名称 客户PO号 |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | null, // 客户编号 |
| | | null, // 客户 |
| | | locOwner.getOwner(), // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | |
| | | orderDetl.setStandby1(detlDto.getStandby1()); |
| | | orderDetl.setStandby2(detlDto.getStandby2()); |
| | | orderDetl.setStandby3(detlDto.getStandby3()); |
| | | orderDetl.setBoxType1(detlDto.getBoxType1()); |
| | | orderDetl.setBoxType2(detlDto.getBoxType2()); |
| | | orderDetl.setBoxType3(detlDto.getBoxType3()); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setCreateBy(9527L); |
| | |
| | | } |
| | | |
| | | for(MatSyncParam.MatParam matParam : param.getMatDetails()){ |
| | | if(Cools.isEmpty(matParam.getMatnr())){ |
| | | if(Cools.isEmpty(matParam.getMatNr())){ |
| | | throw new CoolException("商品编码不能为空"); |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | Mat mat = matService.selectByMatnr(matParam.getMatnr()); |
| | | Mat mat = matService.selectByMatnr(matParam.getMatNr()); |
| | | if (mat == null) { |
| | | mat = new Mat(); |
| | | // 分类 |
| | |
| | | } |
| | | } else { |
| | | mat.sync(matParam); |
| | | if (!matService.update(mat, new EntityWrapper<Mat>().eq("matnr",matParam.getMatnr()))) { |
| | | if (!matService.update(mat, new EntityWrapper<Mat>().eq("matnr",matParam.getMatNr()))) { |
| | | throw new CoolException("更新已存在商品信息失败,请联系管理员"); |
| | | } |
| | | } |
| | |
| | | if (Cools.isEmpty(basArmMastOld)){ |
| | | basArmMastService.insert(basArmMast); |
| | | } else { |
| | | throw new CoolException("未查询到相关机械臂拆码垛任务!!!"+ JSON.toJSONString(param)); |
| | | throw new CoolException("等待前边货物抓取!!!"+ JSON.toJSONString(param)); |
| | | } |
| | | } |
| | | |
| | |
| | | public void taskArmCycleResult(TaskArmCycleResultParam param) { |
| | | BasArm basArm = basArmService.selectOne(new EntityWrapper<BasArm>() |
| | | .eq("arm_no", param.getArm_no()) |
| | | .eq("sta_no", Integer.parseInt(param.getStaNo())) |
| | | .eq("sorting_line", Integer.parseInt(param.getStaNo())) |
| | | .eq("status", 1) |
| | | ); |
| | | if (Cools.isEmpty(basArm)){ |
| | | throw new CoolException("机械臂配置异常,查询不到机械臂数据!!!"+ JSON.toJSONString(param)); |
| | | } |
| | | |
| | | try{ |
| | | BasArmMastSign basArmMastSign = basArmMastSignService.selectOne( |
| | | new EntityWrapper<BasArmMastSign>() |
| | | .eq("matnr", param.getSku()) |
| | | .eq("order_no", param.getOrderNo()) |
| | | .eq("create_time", param.getBindingTags()) |
| | | ); |
| | | if (!Cools.isEmpty(basArmMastSign)){ |
| | | basArmMastSign.setStatus(1); |
| | | basArmMastSignService.updateById(basArmMastSign); |
| | | } |
| | | } catch (Exception e){ |
| | | } |
| | | |
| | | BasArmMast basArmMastListError = basArmMastService.selectOne( |
| | | new EntityWrapper<BasArmMast>() |
| | | .eq("sorting_line", basArm.getSortingLineSou()) |
| | | .eq("arm_no", param.getArm_no()) |
| | | .eq("status", 9) |
| | | ); |
| | | if (!Cools.isEmpty(basArmMastListError)){ |
| | | if (Integer.parseInt(param.getPick_num()) ==1){ |
| | | basArmMastListError.setStatus(2); |
| | | basArmMastService.updateById(basArmMastListError); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | |
| | | BasArmMast basArmMast = basArmMastService.selectOne( |
| | | new EntityWrapper<BasArmMast>() |
| | | .eq("sorting_line", basArm.getSortingLineSou()) |
| | |
| | | if (Cools.isEmpty(basArmMast)){ |
| | | throw new CoolException("未查询到相关机械臂拆码垛任务!!!"+ JSON.toJSONString(param)); |
| | | } |
| | | |
| | | basArmMast.setStatus(2); |
| | | basArmMastService.updateById(basArmMast); |
| | | if (Integer.parseInt(param.getPick_num()) !=1){ |
| | | basArmMast.setStatus(9); |
| | | basArmMastService.updateById(basArmMast); |
| | | } else { |
| | | basArmMast.setStatus(2); |
| | | basArmMastService.updateById(basArmMast); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | public void taskArmWorkOrderStatus(OrderArmEndParam param) { |
| | | BasArm basArm = basArmService.selectOne(new EntityWrapper<BasArm>() |
| | | .eq("arm_no", param.getArm_no()) |
| | | .eq("sta_no", Integer.parseInt(param.getStaNo())) |
| | | .eq("sorting_line", Integer.parseInt(param.getStaNo())) |
| | | .eq("status", 1) |
| | | ); |
| | | if (Cools.isEmpty(basArm)){ |
| | |
| | | @Override |
| | | @Transactional |
| | | public boolean TaskArmWorkOrderSign(OrderArmEndParam param) { |
| | | BasArmMastSign basArmMastSign = basArmMastSignService.selectOne( |
| | | new EntityWrapper<BasArmMastSign>() |
| | | .eq("matnr", param.getSku()) |
| | | .eq("order_no", param.getOrderNo()) |
| | | ); |
| | | if (Cools.isEmpty(basArmMastSign)){ |
| | | // throw new CoolException("未查询到相关机械臂拆码垛任务!!!"+ JSON.toJSONString(param)); |
| | | return false; |
| | | } |
| | | BasArmMastSign basArmMastSignNew = basArmMastSignService.selectOne( |
| | | new EntityWrapper<BasArmMastSign>() |
| | | .eq("matnr", param.getSku()) |
| | | .eq("order_no", param.getOrderNo()) |
| | | .eq("create_time", basArmMastSign.getCreateTime()) |
| | | .eq("create_time", param.getBindingTags()) |
| | | .eq("status", 0) |
| | | ); |
| | | if (Cools.isEmpty(basArmMastSignNew)){ |
| | |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public boolean TaskAgvReport(TaskAgvReportParam param) { |
| | | BasAgvMast basAgvMast = basAgvMastService.selectOne(new EntityWrapper<BasAgvMast>().eq("task_no", param.getTaskNo())); |
| | | if (Cools.isEmpty(basAgvMast)){ |
| | | return false; |
| | | } |
| | | basAgvMast.setStatus(2); |
| | | basAgvMastService.updateById(basAgvMast); |
| | | return true; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public boolean reportTaskStatus(String taskNo, Integer status, Integer ioType, String barcode) { |
| | | try { |
| | | TaskStatusFeedbackParam param = new TaskStatusFeedbackParam(); |
| | | param.setTaskNo(taskNo); |
| | | param.setStatus(status); |
| | | param.setIoType(ioType); |
| | | param.setBarcode(barcode); |
| | | param.setReportTime(new Date()); |
| | | |
| | | Map<String, Object> headers = new HashMap<>(); |
| | | headers.put("appkey", "ea1f0459efc02a79f046f982767939ae"); |
| | | |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath("/taskStatusFeedback") |
| | | .setJson(JSON.toJSONString(param)) |
| | | .setHeaders(headers) |
| | | .build() |
| | | .doPost(); |
| | | |
| | | boolean success = false; |
| | | log.info("任务状态反馈上报结果:{}", response); |
| | | if (response != null) { |
| | | try { |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | // 假设返回code为200表示成功 |
| | | if (jsonObject != null && jsonObject.containsKey("code") && jsonObject.getInteger("code") == 200) { |
| | | success = true; |
| | | } |
| | | } catch (Exception e) { |
| | | log.warn("解析响应失败", e); |
| | | } |
| | | } |
| | | |
| | | // 记录日志 |
| | | try { |
| | | apiLogService.save("任务状态反馈上报", |
| | | "/taskStatusFeedback", |
| | | "ea1f0459efc02a79f046f982767939ae", |
| | | wmsUrl, |
| | | JSON.toJSONString(param), |
| | | response, |
| | | success); |
| | | } catch (Exception e) { |
| | | log.error("保存API日志异常", e); |
| | | } |
| | | |
| | | return success; |
| | | } catch (Exception e) { |
| | | log.error("任务状态反馈上报异常", e); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |