|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.TaskStatusType; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.WorkNoType; | 
|---|
|  |  |  | import com.zy.asrs.domain.param.ApplyInDevpDto; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasDevp; | 
|---|
|  |  |  | import com.zy.asrs.entity.LocMast; | 
|---|
|  |  |  | import com.zy.asrs.entity.TaskWrk; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.taskCreateParam; | 
|---|
|  |  |  | import com.zy.asrs.service.OpenService; | 
|---|
|  |  |  | import com.zy.asrs.service.TaskWrkService; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.TaskCreateParam; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.asrs.utils.Utils; | 
|---|
|  |  |  | import com.zy.common.service.CommonService; | 
|---|
|  |  |  | import com.zy.core.DevpThread; | 
|---|
|  |  |  | import com.zy.core.cache.MessageQueue; | 
|---|
|  |  |  | import com.zy.core.cache.SlaveConnection; | 
|---|
|  |  |  | import com.zy.core.enums.SlaveType; | 
|---|
|  |  |  | import com.zy.core.model.Task; | 
|---|
|  |  |  | import com.zy.core.model.protocol.StaProtocol; | 
|---|
|  |  |  | import com.zy.core.properties.SlaveProperties; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class OpenServiceImpl implements OpenService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskWrkService taskWrkService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SlaveProperties slaveProperties; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ApiLogService apiLogService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private StaDescService staDescService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CommonService commonService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocMastService locMastService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BasDevpService basDevpService; | 
|---|
|  |  |  | @Value("${wms.url}") | 
|---|
|  |  |  | private String wmsUrl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 工装类型 WMS下发 N65/N87/G4X/B10 WCS转换为4,N74/PPE 转换为3 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static short getGzlx(String lx) { | 
|---|
|  |  |  | if (Cools.isEmpty(lx)) { | 
|---|
|  |  |  | return 0; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | switch (lx) { | 
|---|
|  |  |  | case "N74": | 
|---|
|  |  |  | case "PPE": | 
|---|
|  |  |  | return 3; | 
|---|
|  |  |  | case "N65": | 
|---|
|  |  |  | case "N87": | 
|---|
|  |  |  | case "B10": | 
|---|
|  |  |  | return 4; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | return 0; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void taskCreate(taskCreateParam param) { | 
|---|
|  |  |  | public HashMap<String, Object> taskCreate(TaskCreateParam param) { | 
|---|
|  |  |  | HashMap<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo()); | 
|---|
|  |  |  | if (taskWrk != null) { | 
|---|
|  |  |  | throw new CoolException(param.getTaskNo() + "任务已存在,请勿重复提交"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (param.getIoType().equals(0)){ | 
|---|
|  |  |  | throw new CoolException("生成任务失败,任务类型不存在!"); | 
|---|
|  |  |  | map.put("Code", "0"); | 
|---|
|  |  |  | map.put("Msg", param.getTaskNo() + "任务已经生成!"); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | taskWrk = new TaskWrk(); | 
|---|
|  |  |  | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", param.getStartPoint())); | 
|---|
|  |  |  | if (locMast == null) { | 
|---|
|  |  |  | map.put("Code", "0"); | 
|---|
|  |  |  | map.put("Msg", param.getStartPoint() + "库位号有误"); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int workNoType = WorkNoType.PAKOUT.type; | 
|---|
|  |  |  | // 2,3号堆垛机出库,需要通过条码区分大小托盘,16开头小托盘,18开头大托盘,任务号3001-6000为小托盘 | 
|---|
|  |  |  | if (param.getIoType() == 2 && (locMast.getCrnNo() == 3 || locMast.getCrnNo() == 2) && locMast.getBarcode().startsWith("16")) { | 
|---|
|  |  |  | workNoType = WorkNoType.PICK.type; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int workNo1 = commonService.getWorkNo(workNoType);//获取入库工作号 | 
|---|
|  |  |  | taskWrk.setTaskNo(param.getTaskNo());//任务号 | 
|---|
|  |  |  | taskWrk.setWrkNo(workNo1); | 
|---|
|  |  |  | taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收 | 
|---|
|  |  |  | taskWrk.setCreateTime(now); | 
|---|
|  |  |  | taskWrk.setAssignTime(now); | 
|---|
|  |  |  | taskWrk.setIoType(param.getIoType());//任务类型 | 
|---|
|  |  |  | taskWrk.setIoPri(param.getTaskPriority());//优先级 | 
|---|
|  |  |  | taskWrk.setBarcode(param.getBarcode());//条码 | 
|---|
|  |  |  | taskWrk.setWrkSts(1); | 
|---|
|  |  |  | if (!Cools.isEmpty(param.getStartPoint())) { | 
|---|
|  |  |  | taskWrk.setCrnNo(locMast.getCrnNo()); | 
|---|
|  |  |  | taskWrk.setType(param.getType()); | 
|---|
|  |  |  | taskWrk.setMp((short) (param.getLev() > 1 ? 1 : 2)); | 
|---|
|  |  |  | taskWrk.setLx(getGzlx(param.getLx())); | 
|---|
|  |  |  | taskWrk.setLev(param.getLev()); | 
|---|
|  |  |  | if (param.getIoType() == 1) { | 
|---|
|  |  |  | taskWrk.setWrkSts(1); | 
|---|
|  |  |  | if (!Cools.isEmpty(param.getTargetPoint())) { | 
|---|
|  |  |  | taskWrk.setTargetPoint(Utils.getWcsLocNo(param.getTargetPoint()));//终点 | 
|---|
|  |  |  | taskWrk.setOriginTargetPoint(param.getTargetPoint()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else if (param.getIoType() == 2) { | 
|---|
|  |  |  | taskWrk.setWrkSts(11); | 
|---|
|  |  |  | //            if (!Cools.isEmpty(param.getStartPoint())) { | 
|---|
|  |  |  | taskWrk.setStartPoint(param.getStartPoint());//起点 | 
|---|
|  |  |  | if (Integer.parseInt(param.getTargetPoint()) == 211 || Integer.parseInt(param.getTargetPoint()) == 206 || Integer.parseInt(param.getTargetPoint()) == 202) { | 
|---|
|  |  |  | taskWrk.setTargetPoint(String.valueOf(Integer.parseInt(param.getTargetPoint()) + 1)); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | taskWrk.setTargetPoint(String.valueOf(Integer.parseInt(param.getTargetPoint()) - 1)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //            taskWrk.setTargetPoint(param.getTargetPoint()); | 
|---|
|  |  |  | } else if (param.getIoType() == 3) { | 
|---|
|  |  |  | taskWrk.setWrkSts(11); | 
|---|
|  |  |  | if (!Cools.isEmpty(param.getStartPoint())) { | 
|---|
|  |  |  | taskWrk.setStartPoint(param.getStartPoint());//起点 | 
|---|
|  |  |  | taskWrk.setTargetPoint(param.getTargetPoint()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(param.getTargetPoint())) { | 
|---|
|  |  |  | taskWrk.setTargetPoint(param.getTargetPoint());//终点 | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!Cools.isEmpty(param.getMemo())) { | 
|---|
|  |  |  | taskWrk.setMemo(param.getMemo());//备注 | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!taskWrkService.insert(taskWrk)) { | 
|---|
|  |  |  | throw new CoolException("生成任务失败,请联系管理员"); | 
|---|
|  |  |  | map.put("Code", "0"); | 
|---|
|  |  |  | map.put("Msg", param.getTaskNo() + "创建任务失败!"); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("Code", "1"); | 
|---|
|  |  |  | map.put("Msg", "ok"); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R applyInDevp(ApplyInDevpDto param) { | 
|---|
|  |  |  | Integer sourceSite = param.getSourceSite(); | 
|---|
|  |  |  | BasDevp basDevp = basDevpService.selectById(sourceSite); | 
|---|
|  |  |  | if (basDevp == null) { | 
|---|
|  |  |  | return R.error("源站点不存在:" + param); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 2); | 
|---|
|  |  |  | StaProtocol staProtocol = devpThread.getStation().get(sourceSite); | 
|---|
|  |  |  | if (staProtocol == null) { | 
|---|
|  |  |  | return R.parse(sourceSite + "线程为空!"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | staProtocol = staProtocol.clone(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | StaProtocol staProtocol1 = devpThread.getStation().get(param.getTargetSite()); | 
|---|
|  |  |  | if (staProtocol1 == null) { | 
|---|
|  |  |  | return R.parse(param.getTargetSite() + "线程为空!"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | staProtocol1 = staProtocol1.clone(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        if (staProtocol1.isLoading()) { | 
|---|
|  |  |  | //            return R.error(staProtocol1.getSiteId() + "站点有物!"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!staProtocol.isAutoing()) { | 
|---|
|  |  |  | return R.error(staProtocol.getSiteId() + "站点fei自动"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | staProtocol.setWorkNo((short) commonService.getWorkNo(param.getFlag())); | 
|---|
|  |  |  | staProtocol.setStaNo(param.getTargetSite().shortValue()); | 
|---|
|  |  |  | basDevpService.updateById(basDevp); | 
|---|
|  |  |  | boolean result = MessageQueue.offer(SlaveType.Devp, 2, new Task(2, staProtocol)); | 
|---|
|  |  |  | if (result) { | 
|---|
|  |  |  | return R.ok("成功"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return R.error("下发命令失败:" + param); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|