| | |
| | | package com.zy.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.api.controller.params.ReceviceTaskParams; |
| | | import com.zy.api.controller.params.WorkTaskParams; |
| | | import com.zy.api.service.WcsApiService; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.service.impl.LocDetlServiceImpl; |
| | | import com.zy.asrs.service.impl.MatServiceImpl; |
| | | import com.zy.asrs.service.impl.WrkDetlServiceImpl; |
| | | import com.zy.common.constant.MesConstant; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class WcsApiServiceImpl implements WcsApiService { |
| | | |
| | | @Autowired |
| | | private BasDeviceService basDeviceService; |
| | | @Autowired |
| | | private LocAroundBindService locAroundBindService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private WorkService workService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private MatService matService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | |
| | | /** |
| | | * 通知WCS锁定库位,及禁止当前库位的一切操作 |
| | |
| | | * @return com.core.common.R |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R lockLocs(ReceviceTaskParams params) { |
| | | BasDevice basDevice = basDeviceService.selectOne(new EntityWrapper<BasDevice>() |
| | | .eq("status", 1) |
| | | .eq("dev_no", params.getDeviceNo())); |
| | | if (Objects.isNull(basDevice)) { |
| | | throw new CoolException("机台信息不存在或已禁用!!"); |
| | | } |
| | | List<LocAroundBind> binds = locAroundBindService.selectList(new EntityWrapper<LocAroundBind>().eq("dev_no", basDevice.getDevNo())); |
| | | if (Objects.isNull(binds) || binds.isEmpty()) { |
| | | throw new CoolException("机台未绑定工作站台!!"); |
| | | } |
| | | Set<String> locs = binds.stream().map(LocAroundBind::getBlocNo).collect(Collectors.toSet()); |
| | | |
| | | reportLockLocs(locs, "lock"); |
| | | |
| | | return R.ok("上报成功!!"); |
| | | } |
| | | |
| | | /** |
| | | * 余料回库 (搬运余料回库) |
| | | * @author Ryan |
| | | * @date 2026/1/10 13:19 |
| | | * @param params |
| | | * @return com.core.common.R |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R backLocs(WorkTaskParams params) { |
| | | if (Objects.isNull(params.getWrkNo())) { |
| | | throw new CoolException("工作号不能为空!!"); |
| | | } |
| | | // String wrkCode = params.getTaskNo(); |
| | | // if (wrkCode.contains("-1")) { |
| | | // throw new CoolException("配对任务编码错误,请检查后重新上传!!"); |
| | | // } |
| | | WrkMast mast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", params.getWrkNo())); |
| | | if (Objects.isNull(mast)) { |
| | | throw new CoolException("任务不存在!!"); |
| | | } |
| | | // if (!mast.getWrkSts().equals(103L)) { |
| | | // throw new CoolException("当前任务并非余料出库任务!!"); |
| | | // } |
| | | // if (params.getIsSuplus() == 1) { |
| | | // mast.setIsSuplus(1); |
| | | // } |
| | | // |
| | | // if (!wrkMastService.updateById(mast)) { |
| | | // throw new CoolException("任务状态更新失败!!"); |
| | | // } |
| | | workService.backLocOperation(mast.getWrkNo() + "", mast.getAppeUser()); |
| | | |
| | | return R.ok("接收成功,执行回库中..."); |
| | | } |
| | | |
| | | /** |
| | | * 下发任务至WCS |
| | | * @author Ryan |
| | | * @date 2026/1/10 13:58 |
| | | * @param params |
| | | * @return com.core.common.R |
| | | */ |
| | | @Override |
| | | public R pubWrkToWcs(WorkTaskParams params) { |
| | | if (Objects.isNull(params.getTaskNo())) { |
| | | return R.error("任务号不能为空!!"); |
| | | } |
| | | if (Objects.isNull(params.getBarcode())) { |
| | | return R.error("托盘码不能为空!!"); |
| | | } |
| | | if (Objects.isNull(params.getLocNo())) { |
| | | return R.error("目标库位不能为空!!"); |
| | | } |
| | | String url = MesConstant.PUB_TASK_IN; |
| | | if (Objects.isNull(params.getType()) && params.getType().equals("out")) { |
| | | url = MesConstant.PUB_TASK_OUT; |
| | | } |
| | | String response; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(MesConstant.URL) |
| | | .setPath(url) |
| | | .setJson(JSON.toJSONString(params)) |
| | | .build() |
| | | .doPost(); |
| | | R result = JSON.parseObject(response, R.class); |
| | | |
| | | if (result.get("code").equals("200")) { |
| | | //TODO 上报是否成功 |
| | | } |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 上报锁定/释放库位信息 |
| | | * @author Ryan |
| | | * @date 2026/1/10 12:50 |
| | | * @param locs |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void reportLockLocs(Set<String> locs, String type) { |
| | | String url = MesConstant.LOCK_LOCS_URL; |
| | | if (!Objects.isNull(type)) { |
| | | if (type.equals("release")) { |
| | | url = MesConstant.RELEASE_LOCS_URL; |
| | | } |
| | | } |
| | | String response; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(MesConstant.URL) |
| | | .setPath(url) |
| | | .setJson(JSON.toJSONString(locs)) |
| | | .build() |
| | | .doPost(); |
| | | R result = JSON.parseObject(response, R.class); |
| | | |
| | | if (result.get("code").equals("200")) { |
| | | //TODO 上报是否成功 |
| | | } |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 堆垛机执行状态上报 |
| | | * @author Ryan |
| | | * @date 2026/1/10 16:30 |
| | | * @param params |
| | | * @return com.core.common.R |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R receviceTaskFromWcs(ReceviceTaskParams params) { |
| | | if (Objects.isNull(params.getWrkNo())) { |
| | | throw new CoolException("WMS任务号不能为空!!"); |
| | | } |
| | | if (Objects.isNull(params.getNotifyType())) { |
| | | throw new CoolException("动作类型不能为空!!"); |
| | | } |
| | | WrkMast mast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", params.getWrkNo())); |
| | | if (Objects.isNull(mast)) { |
| | | throw new CoolException("任务档不存在!!"); |
| | | } |
| | | if ( params.getNotifyType().equals("task")) { |
| | | //任务 |
| | | if (params.getMsgType().equals("task_complete")) { |
| | | mast.setWrkSts(4L); |
| | | if (!wrkMastService.updateById(mast)) { |
| | | throw new CoolException("任务状态修改失败!!"); |
| | | } |
| | | } else if (params.getMsgType().equals("task_cancel")){ |
| | | |
| | | } |
| | | } else if (params.getNotifyType().equals("weight")) { |
| | | //称重 |
| | | if (mast.getWrkSts() == 2) { |
| | | if (mast.getIoType() == 10) { |
| | | //空板入库任务档 |
| | | LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", mast.getSourceLocNo())); |
| | | if (Objects.isNull(locDetl)) { |
| | | throw new CoolException("明细数据不存在!!"); |
| | | } |
| | | Mat matnr = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", locDetl.getMatnr())); |
| | | if (Objects.isNull(matnr)) { |
| | | throw new CoolException("物料基础信息不存在!!"); |
| | | } |
| | | Double val = Math.round((params.getWeight() - matnr.getSafeQty()) * 10000) / 10000.0; |
| | | if (val.compareTo(0.0) > 0) { |
| | | WrkDetl wrkDetl = new WrkDetl(); |
| | | BeanUtils.copyProperties(locDetl, wrkDetl); |
| | | wrkDetl.setWrkNo(mast.getWrkNo()); |
| | | wrkDetl.setIoTime(new Date()); |
| | | wrkDetl.setWeight(params.getWeight()); |
| | | //余料长度 |
| | | wrkDetl.setRealQty(val * matnr.getVolume()); |
| | | mast.setIoType(1); |
| | | mast.setIsSuplus(1); |
| | | if (!wrkMastService.updateById(mast)) { |
| | | throw new CoolException("主档状态修改失败"); |
| | | } |
| | | if (!wrkDetlService.insert(wrkDetl)) { |
| | | throw new CoolException("明细保存失败!!"); |
| | | } |
| | | } |
| | | } else { |
| | | WrkDetl wrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", mast.getWrkNo())); |
| | | if (Objects.isNull(wrkDetl)) { |
| | | throw new CoolException("数据错误,任务明细不存在!!"); |
| | | } |
| | | Mat matnr = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", wrkDetl.getMatnr())); |
| | | if (Objects.isNull(matnr)) { |
| | | throw new CoolException("物料基础信息不存在!!"); |
| | | } |
| | | Double val = Math.round((params.getWeight() - matnr.getSafeQty()) * 10000) / 10000.0; |
| | | if (val.compareTo(0.0) > 0) { |
| | | //余料长度 |
| | | wrkDetl.setRealQty(val * matnr.getVolume()); |
| | | |
| | | } else { |
| | | //空板 |
| | | wrkDetl.setRealQty(0.0); |
| | | } |
| | | |
| | | wrkDetl.setWeight(params.getWeight()); |
| | | if (!wrkDetlService.update(wrkDetl, new EntityWrapper<WrkDetl>().eq("wrk_no", mast.getWrkNo()).eq("matnr", wrkDetl.getMatnr()).eq("barcode", wrkDetl.getBarcode()))) { |
| | | throw new CoolException("任务档明细修改失败!!"); |
| | | } |
| | | } |
| | | } else { |
| | | throw new CoolException("数据错误,当前任务状态有误 !"); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |