|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.DateUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.asrs.utils.MatUtils; | 
|---|
|  |  |  | import com.zy.asrs.utils.OrderInAndOutUtil; | 
|---|
|  |  |  | import com.zy.asrs.utils.Utils; | 
|---|
|  |  |  | import com.zy.common.model.DetlDto; | 
|---|
|  |  |  | import com.zy.common.utils.NodeUtils; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | private TagService tagService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TagMapper tagMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BasArmService basArmService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BasArmMastService basArmMastService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BasArmMastSignService basArmMastSignService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | 
|---|
|  |  |  | now,    // 添加时间 | 
|---|
|  |  |  | 9527L,    // 修改人员 | 
|---|
|  |  |  | now,    // 修改时间 | 
|---|
|  |  |  | null    // 备注 | 
|---|
|  |  |  | null,   // 备注 | 
|---|
|  |  |  | 1 | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | order.setPakinPakoutStatus(1); | 
|---|
|  |  |  | if (!orderService.insert(order)) { | 
|---|
|  |  |  | throw new CoolException("生成单据主档失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | orderDetl.setUpdateTime(now); | 
|---|
|  |  |  | orderDetl.setStatus(1); | 
|---|
|  |  |  | orderDetl.setQty(0.0D); | 
|---|
|  |  |  | orderDetl.setPakinPakoutStatus(1); | 
|---|
|  |  |  | if (!orderDetlService.insert(orderDetl)) { | 
|---|
|  |  |  | throw new CoolException("生成单据明细失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | now,    // 添加时间 | 
|---|
|  |  |  | 9527L,    // 修改人员 | 
|---|
|  |  |  | now,    // 修改时间 | 
|---|
|  |  |  | null    // 备注 | 
|---|
|  |  |  | null,    // 备注 | 
|---|
|  |  |  | 2 | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | order.setPakinPakoutStatus(2); | 
|---|
|  |  |  | if (!orderService.insert(order)) { | 
|---|
|  |  |  | throw new CoolException("生成单据主档失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | orderDetl.setUpdateTime(now); | 
|---|
|  |  |  | orderDetl.setStatus(1); | 
|---|
|  |  |  | orderDetl.setQty(0.0D); | 
|---|
|  |  |  | orderDetl.setPakinPakoutStatus(2); | 
|---|
|  |  |  | if (!orderDetlService.insert(orderDetl)) { | 
|---|
|  |  |  | throw new CoolException("生成单据明细失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | tagId = tagService.getTop().getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mat.sync(param); | 
|---|
|  |  |  | mat.sync(matParam); | 
|---|
|  |  |  | //            mat.setMatnr(param.getMatnr()); | 
|---|
|  |  |  | //            mat.setMaktx(param.getMaktx()); | 
|---|
|  |  |  | //            mat.setSpecs(param.getSpecs()); | 
|---|
|  |  |  | 
|---|
|  |  |  | log.info("同步新物料[商品编号:{}]", mat.getMatnr()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | mat.sync(param); | 
|---|
|  |  |  | mat.sync(matParam); | 
|---|
|  |  |  | if (!matService.update(mat, new EntityWrapper<Mat>().eq("matnr",matParam.getMatnr()))) { | 
|---|
|  |  |  | throw new CoolException("更新已存在商品信息失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void taskArmReport(TaskArmReportParam param) { | 
|---|
|  |  |  | BasArmMast basArmMast = new BasArmMast(param); | 
|---|
|  |  |  | List<BasArm> basArmList = basArmService.selectList(new EntityWrapper<BasArm>().eq("sorting_line_sou", basArmMast.getSortingLine())); | 
|---|
|  |  |  | for (BasArm basArm : basArmList) { | 
|---|
|  |  |  | if (basArm.getStatus()!=1){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | basArmMast.setArmNo(basArm.getArmNo()); | 
|---|
|  |  |  | basArmMast.setStaNo(basArm.getStaNoSou()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BasArmMast basArmMastOld = basArmMastService.selectOne( | 
|---|
|  |  |  | new EntityWrapper<BasArmMast>() | 
|---|
|  |  |  | .eq("sorting_line", basArmMast.getSortingLine()) | 
|---|
|  |  |  | .eq("arm_no", basArmMast.getArmNo()) | 
|---|
|  |  |  | .eq("status", 0) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (Cools.isEmpty(basArmMastOld)){ | 
|---|
|  |  |  | basArmMastService.insert(basArmMast); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException("等待前边货物抓取!!!"+ JSON.toJSONString(param)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void taskArmCycleResult(TaskArmCycleResultParam param) { | 
|---|
|  |  |  | BasArm basArm = basArmService.selectOne(new EntityWrapper<BasArm>() | 
|---|
|  |  |  | .eq("arm_no", param.getArm_no()) | 
|---|
|  |  |  | .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()) | 
|---|
|  |  |  | .eq("arm_no", param.getArm_no()) | 
|---|
|  |  |  | .eq("status", 1) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (Cools.isEmpty(basArmMast)){ | 
|---|
|  |  |  | throw new CoolException("未查询到相关机械臂拆码垛任务!!!"+ JSON.toJSONString(param)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Integer.parseInt(param.getPick_num()) !=1){ | 
|---|
|  |  |  | basArmMast.setStatus(9); | 
|---|
|  |  |  | basArmMastService.updateById(basArmMast); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | basArmMast.setStatus(2); | 
|---|
|  |  |  | basArmMastService.updateById(basArmMast); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void taskArmWorkspaceStatus(TaskArmWorkspaceStatusParam param) { | 
|---|
|  |  |  | BasArm basArm = basArmService.selectOne(new EntityWrapper<BasArm>() | 
|---|
|  |  |  | .eq("arm_no", param.getArm_no()) | 
|---|
|  |  |  | .eq("sta_no", Integer.parseInt(param.getId())) | 
|---|
|  |  |  | .eq("status", 1) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (Cools.isEmpty(basArm)){ | 
|---|
|  |  |  | throw new CoolException("机械臂配置异常,查询不到机械臂数据!!!"+ JSON.toJSONString(param)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BasArmMast basArmMast = basArmMastService.selectOne( | 
|---|
|  |  |  | new EntityWrapper<BasArmMast>() | 
|---|
|  |  |  | .eq("sta_no", basArm.getStaNoSou()) | 
|---|
|  |  |  | .eq("arm_no", param.getArm_no()) | 
|---|
|  |  |  | .eq("status", 2) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (Cools.isEmpty(basArmMast)){ | 
|---|
|  |  |  | throw new CoolException("未查询到相关机械臂拆码垛任务!!!"+ JSON.toJSONString(param)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | basArmMastService.updateArmMastStatus(param.getArm_no(),basArmMast.getSortingLine(),2,3); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void taskArmWorkOrderStatus(OrderArmEndParam param) { | 
|---|
|  |  |  | BasArm basArm = basArmService.selectOne(new EntityWrapper<BasArm>() | 
|---|
|  |  |  | .eq("arm_no", param.getArm_no()) | 
|---|
|  |  |  | .eq("sorting_line", Integer.parseInt(param.getStaNo())) | 
|---|
|  |  |  | .eq("status", 1) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (Cools.isEmpty(basArm)){ | 
|---|
|  |  |  | throw new CoolException("机械臂配置异常,查询不到机械臂数据!!!"+ JSON.toJSONString(param)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BasArmMast basArmMast = basArmMastService.selectOne( | 
|---|
|  |  |  | new EntityWrapper<BasArmMast>() | 
|---|
|  |  |  | .eq("sorting_line",basArm.getSortingLineSou()) | 
|---|
|  |  |  | .eq("arm_no", param.getArm_no()) | 
|---|
|  |  |  | .eq("status", 5) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (!Cools.isEmpty(basArmMast)){ | 
|---|
|  |  |  | basArmMastService.updateArmMastStatus(param.getArm_no(),basArmMast.getSortingLine(), 5,6); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public boolean TaskArmWorkOrderSign(OrderArmEndParam param) { | 
|---|
|  |  |  | BasArmMastSign basArmMastSignNew = basArmMastSignService.selectOne( | 
|---|
|  |  |  | new EntityWrapper<BasArmMastSign>() | 
|---|
|  |  |  | .eq("order_no", param.getOrderNo()) | 
|---|
|  |  |  | .eq("create_time", param.getBindingTags()) | 
|---|
|  |  |  | .eq("status", 0) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (Cools.isEmpty(basArmMastSignNew)){ | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|