| | |
| | | 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.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.api.controller.params.ReceviceTaskParams; |
| | | import com.zy.api.controller.params.WorkTaskParams; |
| | | import com.zy.api.entity.CrnProtocol; |
| | | import com.zy.api.entity.DeviceStatusVo; |
| | | import com.zy.api.entity.StationProtocol; |
| | | 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.asrs.utils.Utils; |
| | | import com.zy.common.constant.MesConstant; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | 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 java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class WcsApiServiceImpl implements WcsApiService { |
| | | |
| | | private static final Long WCS_SYNC_USER = 9999L; |
| | | private static final String YES = "Y"; |
| | | private static final String NO = "N"; |
| | | |
| | | @Autowired |
| | | private BasDeviceService basDeviceService; |
| | |
| | | private MatService matService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Value("${wcs.address.URL}") |
| | | private String wcs_address; |
| | | |
| | | @Value("${wcs.address.createOutTask}") |
| | | private String getWcs_address; |
| | | |
| | | @Value("${wcs.address.createInTask}") |
| | | private String createInTask; |
| | | |
| | | @Value("${wcs.address.createLocMoveTask}") |
| | | private String createLocMoveTask; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | |
| | | @Value("${wcs.address.getDeviceStatus:/openapi/getDeviceStatus}") |
| | | private String getDeviceStatus; |
| | | @Value("${wcs.status-sync.method:GET}") |
| | | private String deviceStatusMethod; |
| | | @Value("${wcs.switch}") |
| | | private String switchValue; |
| | | |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | | |
| | | /** |
| | | * 通知WCS锁定库位,及禁止当前库位的一切操作 |
| | |
| | | public R lockLocs(ReceviceTaskParams params) { |
| | | BasDevice basDevice = basDeviceService.selectOne(new EntityWrapper<BasDevice>() |
| | | .eq("status", 1) |
| | | .eq("dev_no", params.getDeviceNo())); |
| | | .eq("dev_no", params.getDevNo())); |
| | | if (Objects.isNull(basDevice)) { |
| | | throw new CoolException("机台信息不存在或已禁用!!"); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R backLocs(WorkTaskParams params) { |
| | | if (Objects.isNull(params.getWrkNo())) { |
| | | throw new CoolException("工作号不能为空!!"); |
| | | } |
| | | public R backLocs(String 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())); |
| | | WrkMast mast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", params)); |
| | | if (Objects.isNull(mast)) { |
| | | throw new CoolException("任务不存在!!"); |
| | | } |
| | |
| | | // if (!wrkMastService.updateById(mast)) { |
| | | // throw new CoolException("任务状态更新失败!!"); |
| | | // } |
| | | workService.backLocOperation(mast.getWrkNo() + "", mast.getAppeUser()); |
| | | |
| | | return R.ok("接收成功,执行回库中..."); |
| | | return workService.backLocOperation(mast.getWrkNo() + "", mast.getAppeUser()); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | 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 url = createInTask; |
| | | if (!Objects.isNull(params.getType()) && params.getType().equals("out")) { |
| | | url = getWcs_address; |
| | | }else if (!Objects.isNull(params.getType()) && params.getType().equals("move")) { |
| | | url = createLocMoveTask; |
| | | } |
| | | String response; |
| | | String response = null; |
| | | R r = R.ok(); |
| | | try { |
| | | log.info("下发搬运任务给wcs="+JSON.toJSONString(params)); |
| | | response = new HttpHandler.Builder() |
| | | .setUri(MesConstant.URL) |
| | | .setUri(wcs_address) |
| | | .setPath(url) |
| | | .setJson(JSON.toJSONString(params)) |
| | | .build() |
| | | .doPost(); |
| | | R result = JSON.parseObject(response, R.class); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | log.info("下发任务给wcs的返回值="+response); |
| | | Integer code = jsonObject.getInteger("code"); |
| | | |
| | | if (result.get("code").equals("200")) { |
| | | if (code==200) { |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", params.getTaskNo())); |
| | | if (!Objects.isNull(wrkMast)) { |
| | | if (wrkMast.getIoType()==1 || wrkMast.getIoType()==10) { |
| | | wrkMast.setWrkSts(2L); |
| | | wrkMast.setModiTime(new Date()); |
| | | wrkMastService.updateById(wrkMast); |
| | | }else if(wrkMast.getIoType()==2){ |
| | | wrkMast.setWrkSts(2L); |
| | | wrkMast.setModiTime(new Date()); |
| | | wrkMastService.updateById(wrkMast); |
| | | String s = Utils.convertLocFormat(params.getLocNo()); |
| | | LocAroundBind bind = locAroundBindService.selectOne(new EntityWrapper<LocAroundBind>() |
| | | .eq("b_loc_no", s)); |
| | | if (!Objects.isNull(bind)) { |
| | | bind.setFreeze(1); |
| | | locAroundBindService.updateById(bind); |
| | | //冻结相邻库位 |
| | | Integer[] aroundIds = freezeLocAround(bind.getOrderNo()); |
| | | if (aroundIds != null) { |
| | | for (Integer id : aroundIds) { |
| | | if (id != null && id > 0) { |
| | | LocAroundBind aroundBind = locAroundBindService.selectOne( |
| | | new EntityWrapper<LocAroundBind>() |
| | | .eq("dev_id", bind.getDevId()) |
| | | .eq("order_no", id)); |
| | | if (aroundBind != null) { |
| | | aroundBind.setFreeze(1); |
| | | locAroundBindService.updateById(aroundBind); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }else if (wrkMast.getIoType()==101 || wrkMast.getIoType()==110) { |
| | | wrkMast.setWrkSts(12L); |
| | | wrkMast.setModiTime(new Date()); |
| | | wrkMastService.updateById(wrkMast); |
| | | //出库为机台工位时,冻结相对有的库位,及相邻库位 |
| | | String s = Utils.convertLocFormat(params.getLocNo()); |
| | | if(Cools.isEmpty(wrkMast.getLocNo())){ |
| | | LocAroundBind bind = locAroundBindService.selectOne(new EntityWrapper<LocAroundBind>() |
| | | .eq("b_loc_no", s)); |
| | | if (!Objects.isNull(bind)) { |
| | | bind.setFreeze(1); |
| | | locAroundBindService.updateById(bind); |
| | | //冻结相邻库位 |
| | | Integer[] aroundIds = freezeLocAround(bind.getOrderNo()); |
| | | if (aroundIds != null) { |
| | | for (Integer id : aroundIds) { |
| | | if (id != null && id > 0) { |
| | | LocAroundBind aroundBind = locAroundBindService.selectOne( |
| | | new EntityWrapper<LocAroundBind>() |
| | | .eq("dev_id", bind.getDevId()) |
| | | .eq("order_no", id)); |
| | | if (aroundBind != null) { |
| | | aroundBind.setFreeze(1); |
| | | locAroundBindService.updateById(aroundBind); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //TODO 上报是否成功 |
| | | }else { |
| | | String msg = jsonObject.getString("msg"); |
| | | if (Cools.isEmpty(msg)) { |
| | | msg = jsonObject.getString("message"); |
| | | } |
| | | r = R.error(Cools.isEmpty(msg) ? "下发任务失败" : msg); |
| | | } |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | log.error("下发任务给wcs异常, request={}", JSON.toJSONString(params), e); |
| | | return R.error("调用WCS接口失败:" + e.getMessage()); |
| | | } catch (Exception e) { |
| | | log.error("解析WCS下发结果异常, request={}, response={}", JSON.toJSONString(params), response, e); |
| | | return R.error("WCS返回结果异常:" + e.getMessage()); |
| | | } |
| | | return null; |
| | | return r; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 上报锁定/释放库位信息 |
| | | * |
| | |
| | | url = MesConstant.RELEASE_LOCS_URL; |
| | | } |
| | | } |
| | | String response; |
| | | String response = null; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(MesConstant.URL) |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R receviceTaskFromWcs(ReceviceTaskParams params) { |
| | | if (Objects.isNull(params.getWrkNo())) { |
| | | log.info("wcs任务反馈="+JSON.toJSONString(params)); |
| | | if (Objects.isNull(params.getSuperTaskNo())) { |
| | | throw new CoolException("WMS任务号不能为空!!"); |
| | | } |
| | | if (Objects.isNull(params.getNotifyType())) { |
| | | throw new CoolException("动作类型不能为空!!"); |
| | | } |
| | | WrkMast mast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", params.getWrkNo())); |
| | | WrkMast mast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", params.getSuperTaskNo())); |
| | | if (Objects.isNull(mast)) { |
| | | throw new CoolException("任务档不存在!!"); |
| | | } |
| | | |
| | | |
| | | if (params.getNotifyType().equals("task")) { |
| | | //任务 |
| | | if (params.getMsgType().equals("task_complete")) { |
| | | mast.setWrkSts(4L); |
| | | //称重 |
| | | if ((mast.getIoType()==1||mast.getIoType()==10)&&mast.getWrkSts() == 2 && Cools.isEmpty(mast.getStaNo())) { |
| | | Double weight = 0.0; |
| | | if (!Cools.isEmpty(params.getData())){ |
| | | JSONObject jsonObject = JSONObject.parseObject(params.getData()); |
| | | weight=jsonObject.getDouble("weight"); |
| | | } |
| | | if (mast.getIoType() == 10) { |
| | | //空板入库任务档 |
| | | LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>() |
| | | .eq("zpallet", mast.getBarcode()) |
| | | .eq("loc_no", mast.getSourceLocNo())); |
| | | WrkDetl mainWrkDetl = null; |
| | | if (Objects.isNull(locDetl) && !Cools.isEmpty(mast.getWrkCode())) { |
| | | mainWrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>() |
| | | .eq("wrk_no", mast.getWrkCode()) |
| | | .eq("zpallet", mast.getBarcode())); |
| | | if (Objects.isNull(mainWrkDetl)) { |
| | | mainWrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>() |
| | | .eq("wrk_no", mast.getWrkCode())); |
| | | } |
| | | if (!Objects.isNull(mainWrkDetl)) { |
| | | log.info("locDetl为空,回退查询主任务明细,wrkNo={}, mainWrkNo={}, barcode={}", |
| | | mast.getWrkNo(), mast.getWrkCode(), mast.getBarcode()); |
| | | } |
| | | } |
| | | if (Objects.isNull(locDetl) && Objects.isNull(mainWrkDetl)) { |
| | | throw new CoolException("明细数据不存在!!"); |
| | | } |
| | | String matnrNo = Objects.isNull(locDetl) ? mainWrkDetl.getMatnr() : locDetl.getMatnr(); |
| | | Mat matnr = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", matnrNo)); |
| | | if (Objects.isNull(matnr)) { |
| | | throw new CoolException("物料基础信息不存在!!"); |
| | | } |
| | | if (!Cools.isEmpty(weight)) { |
| | | Double val = Math.round((weight - matnr.getSafeQty()) * 10000) / 10000.0; |
| | | if (val.compareTo(0.0) > 0) { |
| | | WrkDetl wrkDetl = new WrkDetl(); |
| | | if (Objects.isNull(locDetl)) { |
| | | BeanUtils.copyProperties(mainWrkDetl, wrkDetl); |
| | | wrkDetl.setStockQty(Cools.isEmpty(mainWrkDetl.getStockQty()) ? mainWrkDetl.getAnfme() : mainWrkDetl.getStockQty()); |
| | | wrkDetl.setZpallet(mast.getBarcode()); |
| | | } else { |
| | | BeanUtils.copyProperties(locDetl, wrkDetl); |
| | | wrkDetl.setStockQty(locDetl.getAnfme()); |
| | | } |
| | | wrkDetl.setWrkNo(mast.getWrkNo()); |
| | | wrkDetl.setIoTime(new Date()); |
| | | wrkDetl.setWeight(weight); |
| | | wrkDetl.setIoTime(mast.getIoTime()); |
| | | //余料长度 |
| | | wrkDetl.setAnfme(val * matnr.getVolume()); |
| | | if (!wrkDetlService.insert(wrkDetl)){ |
| | | throw new CoolException("无法新增明细!!"); |
| | | } |
| | | mast.setIoType(1); |
| | | mast.setIsSuplus(1); |
| | | mast.setOveMk("Y"); |
| | | if (!wrkMastService.updateById(mast)) { |
| | | throw new CoolException("任务档修改失败!!"); |
| | | } |
| | | // 更新原出库单 |
| | | |
| | | if (!Cools.isEmpty(mast.getWrkCode())) { |
| | | String wrkNo = mast.getWrkCode(); |
| | | WrkMast orgWrk = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", wrkNo)); |
| | | if (Objects.isNull(orgWrk)) { |
| | | throw new CoolException("数据错误,主任务档不存在或已删除!!"); |
| | | } |
| | | orgWrk.setOveMk("Y"); |
| | | if (!wrkMastService.updateById(orgWrk)) { |
| | | throw new CoolException("任务档修改失败!!"); |
| | | } |
| | | WrkDetl detl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo)); |
| | | if (Objects.isNull(detl)) { |
| | | throw new CoolException("子任务档明细不存在!!"); |
| | | } |
| | | // //库存减去称重长度 |
| | | // Double v = Math.round((wrkDetl.getStockQty() - realQty) * 10000) / 10000.0; |
| | | // //原出为数量与真实数量互换,保持一致性 |
| | | // detl.setAnfme(v); |
| | | // detl.setWeight(weight); |
| | | if (!wrkDetlService.update(detl, new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo).eq("matnr", detl.getMatnr()).eq("barcode", detl.getBarcode()))) { |
| | | throw new CoolException("原任务档明细修改失败!!"); |
| | | } |
| | | } else { |
| | | throw new CoolException("任务号截取失败,请检查主任务档任档wrkCode字段"); |
| | | } |
| | | }else{ |
| | | String wrkNo = mast.getWrkCode(); |
| | | WrkMast orgWrk = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", wrkNo)); |
| | | if (Objects.isNull(orgWrk)) { |
| | | throw new CoolException("数据错误,主任务档不存在或已删除!!"); |
| | | } |
| | | mast.setOveMk("Y"); |
| | | orgWrk.setOveMk("Y"); |
| | | if (!wrkMastService.updateById(orgWrk)) { |
| | | 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 realQty = Math.round((wrkDetl.getStockQty() - wrkDetl.getAnfme()) * 10000) / 10000.0; |
| | | if (!Cools.isEmpty(weight)) { |
| | | Double val = Math.round((weight - 2.5) * 10000) / 10000.0; |
| | | //称重后,计算出真实长度 |
| | | realQty = val * matnr.getVolume(); |
| | | if (realQty<matnr.getSafeQty()){ |
| | | wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkDetl.getWrkNo())); |
| | | mast.setIoType(10); |
| | | mast.setEmptyMk("Y"); |
| | | }else{ |
| | | wrkDetl.setAnfme(realQty); |
| | | wrkDetl.setWeight(weight); |
| | | if (!wrkDetlService.update(wrkDetl, new EntityWrapper<WrkDetl>().eq("wrk_no", mast.getWrkNo()).eq("matnr", wrkDetl.getMatnr()).eq("barcode", wrkDetl.getBarcode()))) { |
| | | throw new CoolException("任务档明细修改失败!!"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | mast.setOveMk("Y"); |
| | | if (!wrkMastService.updateById(mast)) { |
| | | throw new CoolException("任务档修改失败!!"); |
| | | } |
| | | |
| | | // 更新原出库单 |
| | | // int indexOf = mast.getWrkCode().indexOf("-1"); |
| | | if (!Cools.isEmpty(mast.getWrkCode())) { |
| | | String wrkNo = mast.getWrkCode(); |
| | | WrkMast orgWrk = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", wrkNo)); |
| | | if (Objects.isNull(orgWrk)) { |
| | | throw new CoolException("数据错误,主任务档不存在或已删除!!"); |
| | | } |
| | | orgWrk.setOveMk("Y"); |
| | | if (!wrkMastService.updateById(orgWrk)) { |
| | | throw new CoolException("任务档修改失败!!"); |
| | | } |
| | | WrkDetl detl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo)); |
| | | if (Objects.isNull(detl)) { |
| | | throw new CoolException("子任务档明细不存在!!"); |
| | | } |
| | | //库存减去称重长度 |
| | | Double v = Math.round((wrkDetl.getStockQty() - realQty) * 10000) / 10000.0; |
| | | //原出为数量与真实数量互换,保持一致性 |
| | | detl.setAnfme(v); |
| | | detl.setWeight(weight); |
| | | if (!wrkDetlService.update(detl, new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo).eq("matnr", detl.getMatnr()).eq("barcode", detl.getBarcode()))) { |
| | | throw new CoolException("原任务档明细修改失败!!"); |
| | | } |
| | | } else { |
| | | throw new CoolException("任务号截取失败,请检查主任务档任档wrkCode字段"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!Objects.isNull(mast.getWrkCode())) { |
| | | if (mast.getOveMk().equals("N") && !Cools.isEmpty(mast.getIsSuplus())) { |
| | | throw new CoolException("任务未上报重量,无法完结任务!!"); |
| | | } |
| | | } |
| | | if (mast.getIoType() == 1 || mast.getIoType() == 2 ||mast.getIoType() == 10) { |
| | | mast.setWrkSts(4L); |
| | | } else if ((mast.getIoType() == 101||mast.getIoType()==110) && mast.getWrkSts()<14) { |
| | | mast.setWrkSts(14L); |
| | | if(Cools.isEmpty(mast.getStaNo())){ |
| | | mast.setOveMk("Y"); |
| | | } |
| | | } |
| | | if (!wrkMastService.updateById(mast)) { |
| | | throw new CoolException("任务状态修改失败!!"); |
| | | } |
| | | } else if (params.getMsgType().equals("task_cancel")) { |
| | | |
| | | //todo 取消任务 |
| | | }else if (params.getMsgType().equals("task_arrive")) { |
| | | //到达目的地 |
| | | //如果出库任务是跨区则需要生成新的入库任务入库 |
| | | if(!Cools.isEmpty(mast.getLocNo())){ |
| | | mast.setOnlineYn("N");//等待生成跨区入库任务 |
| | | } |
| | | mast.setWrkSts(14L); |
| | | if(Cools.isEmpty(mast.getStaNo())){ |
| | | mast.setOveMk("Y"); |
| | | } |
| | | mast.setModiTime(new Date()); |
| | | if (!wrkMastService.updateById(mast)) { |
| | | throw new CoolException("任务状态修改失败!!"); |
| | | } |
| | | } |
| | | } 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; |
| | | Double realQty = val * matnr.getVolume(); |
| | | // if (val.compareTo(0.0) > 0) { |
| | | // //余料长度 |
| | | // wrkDetl.setRealQty(realQty); |
| | | // } else { |
| | | // //空板 |
| | | // wrkDetl.setRealQty(0.0); |
| | | // } |
| | | wrkDetl.setAnfme(realQty); |
| | | 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("任务档明细修改失败!!"); |
| | | } |
| | | // 更新原出库单 |
| | | int indexOf = mast.getWrkCode().indexOf("-1"); |
| | | if (indexOf != -1) { |
| | | String wrkNo = mast.getWrkCode().substring(0, indexOf); |
| | | WrkMast orgWrk = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", wrkNo)); |
| | | if (Objects.isNull(orgWrk)) { |
| | | throw new CoolException("数据错误,主任务档不存在或已删除!!"); |
| | | } |
| | | WrkDetl detl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo)); |
| | | if (Objects.isNull(detl)) { |
| | | throw new CoolException("子任务档明细不存在!!"); |
| | | } |
| | | Double v = Math.round((wrkDetl.getStockQty() - realQty) * 10000) / 10000.0; |
| | | detl.setRealQty(v); |
| | | detl.setWeight(params.getWeight()); |
| | | if (!wrkDetlService.update(detl, new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo).eq("matnr", detl.getMatnr()).eq("barcode", detl.getBarcode()))) { |
| | | throw new CoolException("原任务档明细修改失败!!"); |
| | | } |
| | | } else { |
| | | throw new CoolException("任务号截取失败,请检查主任务档任档wrkCode字段"); |
| | | } |
| | | } |
| | | } else { |
| | | throw new CoolException("数据错误,当前任务状态有误 !"); |
| | | } |
| | | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | //输入库位自动冻结算出相邻库位序号 |
| | | @Override |
| | | public Integer[] freezeLocAround(Integer locId) { |
| | | Integer[] locAround = new Integer[3]; |
| | | if (Objects.isNull(locId)) { |
| | | throw new CoolException("库位ID不能为空!!"); |
| | | }else if (locId==1){ |
| | | locAround[0] = 2; |
| | | locAround[1] = 3; |
| | | locAround[2] = 5; |
| | | }else if (locId==2){ |
| | | locAround[0] = 1; |
| | | locAround[1] = 6; |
| | | locAround[2] = 0; |
| | | }else if (locId==3){ |
| | | locAround[0] = 1; |
| | | locAround[1] = 4; |
| | | locAround[2] = 0; |
| | | }else if (locId==4){ |
| | | locAround[0] = 5; |
| | | locAround[1] = 3; |
| | | locAround[2] = 0; |
| | | }else if (locId==5){ |
| | | locAround[0] = 4; |
| | | locAround[1] = 1; |
| | | locAround[2] = 6; |
| | | }else if (locId==6){ |
| | | locAround[0] = 2; |
| | | locAround[1] = 5; |
| | | locAround[2] = 0; |
| | | } |
| | | return locAround; |
| | | } |
| | | |
| | | @Override |
| | | public R syncDeviceStatusFromWcs() { |
| | | if (!Boolean.parseBoolean(String.valueOf(switchValue))) { |
| | | return R.ok("WCS开关关闭"); |
| | | } |
| | | String response = null; |
| | | try { |
| | | response = requestDeviceStatusFromWcs(); |
| | | JSONObject jsonObject = JSON.parseObject(response == null ? "{}" : response); |
| | | Integer code = jsonObject.getInteger("code"); |
| | | if (!Objects.equals(code, 200)) { |
| | | String msg = jsonObject.getString("msg"); |
| | | return R.error(Cools.isEmpty(msg) ? "获取WCS设备状态失败" : msg); |
| | | } |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | DeviceStatusVo deviceStatusVo = data == null |
| | | ? new DeviceStatusVo() |
| | | : JSON.parseObject(data.toJSONString(), DeviceStatusVo.class); |
| | | |
| | | int stationCount = syncStationStatus(deviceStatusVo.getStationList()); |
| | | int crnCount = syncCrnStatus(deviceStatusVo.getCrnList()); |
| | | |
| | | Map<String, Object> result = new LinkedHashMap<>(); |
| | | result.put("stationCount", stationCount); |
| | | result.put("crnCount", crnCount); |
| | | log.info("同步WCS设备状态成功, stationCount={}, crnCount={}", stationCount, crnCount); |
| | | return R.ok("同步成功").add(result); |
| | | } catch (Exception e) { |
| | | log.error("同步WCS设备状态异常, response={}", response, e); |
| | | return R.error("同步WCS设备状态失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private String requestDeviceStatusFromWcs() throws IOException { |
| | | HttpHandler.Builder builder = new HttpHandler.Builder() |
| | | .setUri(wcs_address) |
| | | .setPath(getDeviceStatus) |
| | | .setTimeout(10, TimeUnit.SECONDS); |
| | | String method = Cools.isEmpty(deviceStatusMethod) ? "POST" : deviceStatusMethod.trim().toUpperCase(Locale.ROOT); |
| | | if ("POST".equals(method)) { |
| | | return builder.setJson("{}").build().doPost(); |
| | | } |
| | | return builder.build().doGet(); |
| | | } |
| | | |
| | | private int syncStationStatus(List<StationProtocol> stationList) { |
| | | if (stationList == null || stationList.isEmpty()) { |
| | | return 0; |
| | | } |
| | | int count = 0; |
| | | Date now = new Date(); |
| | | for (StationProtocol stationProtocol : stationList) { |
| | | if (stationProtocol == null || stationProtocol.getStationId() == null) { |
| | | continue; |
| | | } |
| | | BasDevp basDevp = basDevpService.selectById(stationProtocol.getStationId()); |
| | | boolean isNew = Objects.isNull(basDevp); |
| | | if (isNew) { |
| | | basDevp = new BasDevp(); |
| | | basDevp.setDevNo(stationProtocol.getStationId()); |
| | | basDevp.setAppeUser(WCS_SYNC_USER); |
| | | basDevp.setAppeTime(now); |
| | | } |
| | | basDevp.setInEnable(toFlag(stationProtocol.isInEnable())); |
| | | basDevp.setOutEnable(toFlag(stationProtocol.isOutEnable())); |
| | | basDevp.setAutoing(toFlag(stationProtocol.isAutoing())); |
| | | basDevp.setLoading(toFlag(stationProtocol.isLoading())); |
| | | basDevp.setCanining(toFlag(stationProtocol.isEnableIn())); |
| | | basDevp.setCanouting(toFlag(!stationProtocol.isRunBlock())); |
| | | basDevp.setWrkNo(defaultZero(stationProtocol.getTaskNo())); |
| | | basDevp.setBarcode(normalizeText(stationProtocol.getBarcode())); |
| | | basDevp.setGrossWt(stationProtocol.getWeight() == null ? 0D : stationProtocol.getWeight()); |
| | | basDevp.setModiUser(WCS_SYNC_USER); |
| | | basDevp.setModiTime(now); |
| | | if (isNew) { |
| | | if (!basDevpService.insert(basDevp)) { |
| | | throw new CoolException("新增站点状态失败, stationId=" + stationProtocol.getStationId()); |
| | | } |
| | | } else if (!basDevpService.updateById(basDevp)) { |
| | | throw new CoolException("更新站点状态失败, stationId=" + stationProtocol.getStationId()); |
| | | } |
| | | count++; |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | private int syncCrnStatus(List<CrnProtocol> crnList) { |
| | | if (crnList == null || crnList.isEmpty()) { |
| | | return 0; |
| | | } |
| | | int count = 0; |
| | | Date now = new Date(); |
| | | for (CrnProtocol crnProtocol : crnList) { |
| | | if (crnProtocol == null || crnProtocol.getCrnNo() == null) { |
| | | continue; |
| | | } |
| | | BasCrnp basCrnp = basCrnpService.selectById(crnProtocol.getCrnNo()); |
| | | boolean isNew = Objects.isNull(basCrnp); |
| | | if (isNew) { |
| | | basCrnp = new BasCrnp(); |
| | | basCrnp.setCrnNo(crnProtocol.getCrnNo()); |
| | | basCrnp.setInEnable(YES); |
| | | basCrnp.setOutEnable(YES); |
| | | basCrnp.setAppeUser(WCS_SYNC_USER); |
| | | basCrnp.setAppeTime(now); |
| | | } |
| | | // crn_sts 本地表存的是“堆垛机模式(手动/自动/电脑)”,因此必须写 mode,不能写 status。 |
| | | basCrnp.setCrnSts(defaultZero(crnProtocol.getMode())); |
| | | basCrnp.setWrkNo(defaultZero(crnProtocol.getTaskNo())); |
| | | basCrnp.setCrnErr(crnProtocol.getAlarm() == null ? 0L : Long.valueOf(crnProtocol.getAlarm())); |
| | | basCrnp.setModiUser(WCS_SYNC_USER); |
| | | basCrnp.setModiTime(now); |
| | | if (isNew) { |
| | | if (!basCrnpService.insert(basCrnp)) { |
| | | throw new CoolException("新增堆垛机状态失败, crnNo=" + crnProtocol.getCrnNo()); |
| | | } |
| | | } else if (!basCrnpService.updateById(basCrnp)) { |
| | | throw new CoolException("更新堆垛机状态失败, crnNo=" + crnProtocol.getCrnNo()); |
| | | } |
| | | count++; |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | private Integer defaultZero(Integer value) { |
| | | return value == null ? 0 : value; |
| | | } |
| | | |
| | | private String normalizeText(String value) { |
| | | return Cools.isEmpty(value) ? "" : value; |
| | | } |
| | | |
| | | private String toFlag(boolean value) { |
| | | return value ? YES : NO; |
| | | } |
| | | } |
| | | |
| | | |