| | |
| | | package com.zy.asrs.wms.asrs.manage;
|
| | |
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
| | | import com.fasterxml.jackson.datatype.jsr310.DecimalUtils;
|
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
| | | import com.mysql.cj.util.StringUtils;
|
| | | import com.zy.asrs.wms.asrs.entity.param.StockOutParam;
|
| | | import com.zy.asrs.framework.exception.CoolException;
|
| | | import com.zy.asrs.wms.asrs.entity.*;
|
| | | import com.zy.asrs.wms.asrs.entity.dto.*;
|
| | | import com.zy.asrs.wms.asrs.entity.dto.OrderOutMergeDto;
|
| | | import com.zy.asrs.wms.asrs.entity.enums.*;
|
| | | import com.zy.asrs.wms.asrs.entity.param.*;
|
| | | import com.zy.asrs.wms.asrs.entity.*;
|
| | | import com.zy.asrs.wms.asrs.service.*;
|
| | | import com.zy.asrs.wms.utils.OrderUtils;
|
| | | import com.zy.asrs.wms.utils.OutUtils;
|
| | |
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.text.DecimalFormat;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.*;
|
| | | import java.util.stream.Collectors;
|
| | | import java.util.stream.Stream;
|
| | |
|
| | | /**
|
| | | * 出库管理
|
| | |
| | | return mergePreviewDtos;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 波次出库预览
|
| | | *
|
| | | * @param param
|
| | | * @return
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public List<MergePreviewResultDto> orderOutMergeLocPreview(List<MergePreviewDto> param) {
|
| | | if (param == null) {
|
| | |
| | | //查询平库中符合条件的库存
|
| | | List<LocDetl> locs = locDetlService.queryFlatStock(pars.getMatnr(), pars.getBatch(), pars.getFieldParams());
|
| | | if (!locs.isEmpty()) {
|
| | | double anfme = pars.getAnfme() - pars.getWorkQty();
|
| | | Double anfme = pars.getAnfme() - pars.getWorkQty();
|
| | | for (LocDetl detl : locs) {
|
| | | Loc loc = locService.getById(detl.getLocId());
|
| | | if (loc == null) {
|
| | |
| | | locDto.setLocNo(detl.getLocNo());
|
| | | locDto.setTypeId(LocAreaTypeSts.LOC_AREA_TYPE_FLAT.id);
|
| | | locDto.setLocDetlId(detl.getId());
|
| | | locDto.setAnfme(detl.getAnfme());
|
| | | locDto.setAnfme(detl.getAnfme() - detl.getWorkQty());
|
| | | locDto.setWorkQty(detl.getWorkQty());
|
| | | locDtos.add(locDto);
|
| | | //库位实际可用数量
|
| | | double surplusQty = detl.getAnfme() - detl.getWorkQty();
|
| | | Double surplusQty = Math.round((detl.getAnfme() - detl.getWorkQty()) * 10000) / 10000.0;
|
| | | if (surplusQty <= 0) {
|
| | | continue;
|
| | | }
|
| | | //波次数量减去库位可用数量后,盈余数量
|
| | | anfme = anfme - surplusQty;
|
| | | if (anfme > 0) {
|
| | | anfme = Math.round((anfme - surplusQty) * 10000) / 10000.0;
|
| | | if (anfme.compareTo(0.0) > 0) {
|
| | | //当前可使用数量
|
| | | resultDto.setFetchQty(surplusQty);
|
| | | //余下需求数量
|
| | |
| | |
|
| | | /**
|
| | | * 波次合并出库
|
| | | * 1. 判断是平库还TCU库
|
| | | * 1. 判断是平库还CTU库
|
| | | * 2. 平库生成拣货单
|
| | | * 3. TCU库生成任务单
|
| | | * 3. CTU库生成任务单
|
| | | */
|
| | | outStockByArea(dto, wave);
|
| | |
|
| | |
| | | * 根据不同库位类型生成出库拣货单或CTU任务档
|
| | | *
|
| | | * @param dto
|
| | | * @param wave
|
| | | * @param
|
| | | */
|
| | | private void outStockByArea(OrderOutMergeParamDto dto, Wave wave) {
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void outStockByArea(OrderOutMergeParamDto dto, Wave wave) {
|
| | | List<OrderOutMergeParam> params = dto.getList();
|
| | | if (params.isEmpty()) {
|
| | | throw new CoolException("参数不能为空");
|
| | |
| | | //平库出库
|
| | | outStockByFlat(flatOrders, wave);
|
| | | }
|
| | |
|
| | | if (!tucOrders.isEmpty()) {
|
| | | //CTU出库
|
| | | outStockByTUC(tucOrders, wave);
|
| | | outStockByCTU(tucOrders, wave);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param tucOrders
|
| | | * @param wave
|
| | | */
|
| | | private void outStockByTUC(List<OrderOutMergeParam> tucOrders, Wave wave) {
|
| | | private void outStockByCTU(List<OrderOutMergeParam> tucOrders, Wave wave) {
|
| | | Map<Long, List<OrderOutMergeDto>> map = checkLoc(tucOrders, wave);
|
| | |
|
| | | for (Map.Entry<Long, List<OrderOutMergeDto>> entry : map.entrySet()) {
|
| | |
| | | task.setTaskType(taskType);
|
| | | task.setIoPri(workService.generateIoPri(taskType));
|
| | | task.setOriginLoc(loc.getLocNo());
|
| | | task.setTargetSite(operationPort.getMemo());
|
| | | task.setTargetSite(operationPort.getFlag());
|
| | | task.setBarcode(loc.getBarcode());
|
| | | boolean res = taskService.save(task);
|
| | | if (!res) {
|
| | | throw new CoolException("保存工作档失败");
|
| | | }
|
| | |
|
| | | wave.setSite(operationPort.getFlag());
|
| | | if (!waveService.updateById(wave)) {
|
| | | throw new CoolException("波次站口状态更新失败!!");
|
| | | }
|
| | |
|
| | | for (OrderOutMergeDto merge : list) {
|
| | |
| | | }
|
| | |
|
| | | String matUniqueKey = Utils.getMatUniqueKey(taskDetl.getMatnr(), taskDetl.getBatch(), taskDetl.getUniqueField());
|
| | | WaveDetl waveDetl = waveDetlService.getOne(new LambdaQueryWrapper<WaveDetl>().eq(WaveDetl::getStockIndex, matUniqueKey).eq(WaveDetl::getWaveId, wave.getId()));
|
| | | logger.error("Matnr------>{}", taskDetl.getMatnr());
|
| | | WaveDetl waveDetl = waveDetlService.getOne(new LambdaQueryWrapper<WaveDetl>()
|
| | | .eq(WaveDetl::getStockIndex, matUniqueKey)
|
| | | .eq(WaveDetl::getWaveId, wave.getId()));
|
| | | if (waveDetl == null) {
|
| | | throw new CoolException("波次数据不存在");
|
| | | throw new CoolException("waveId:" + wave.getId() + "物料:" + taskDetl.getMatnr() + "波次数据不存在");
|
| | | }
|
| | | waveDetl.setWorkQty(waveDetl.getWorkQty() + taskDetl.getAnfme());
|
| | | waveDetl.setUpdateTime(new Date());
|
| | |
| | | throw new CoolException("当前波次订单不存在!!");
|
| | | }
|
| | |
|
| | | List<CacheSite> cacheSites = cacheSiteService.list(new LambdaQueryWrapper<CacheSite>().eq(CacheSite::getSiteStatus, CacheSiteStatusType.O.id).orderByAsc(CacheSite::getChannel));
|
| | |
|
| | | if (cacheSites.isEmpty()) {
|
| | | throw new CoolException("缓存站空间不足,请稍后再试");
|
| | | }
|
| | | // List<CacheSite> cacheSites = cacheSiteService.list(new LambdaQueryWrapper<CacheSite>()
|
| | | // .eq(CacheSite::getSiteStatus, CacheSiteStatusType.O.id).eq(CacheSite::getChannel, task.getTargetSite()));
|
| | | //
|
| | | // if (cacheSites.isEmpty()) {
|
| | | // throw new CoolException("缓存站空间不足,请稍后再试");
|
| | | // }
|
| | | //
|
| | | // if (cacheSites.size() < orders.size()) {
|
| | | // throw new CoolException("缓存站空间不足,请稍后再试");
|
| | | // }
|
| | |
|
| | | if (cacheSites.size() < orders.size()) {
|
| | | throw new CoolException("缓存站空间不足,请稍后再试");
|
| | | }
|
| | |
|
| | | for (int i = 0; i < orders.size(); i++) {
|
| | | CacheSite cacheSite = cacheSites.get(i);
|
| | | cacheSite.setOrderId(orders.get(i).getId());
|
| | | cacheSite.setOrderNo(orders.get(i).getOrderNo());
|
| | | cacheSite.setSiteStatus(CacheSiteStatusType.R.id);
|
| | | cacheSite.setUpdateTime(new Date());
|
| | | if (!cacheSiteService.updateById(cacheSite)) {
|
| | | throw new CoolException("缓存站更新失败");
|
| | | }
|
| | | }
|
| | | // for (int i = 0; i < orders.size(); i++) {
|
| | | // CacheSite cacheSite = cacheSiteService.getOne(new LambdaQueryWrapper<CacheSite>().eq(CacheSite::getOrderId, orders.get(i).getId()));
|
| | | // if (Objects.isNull(cacheSite)) {
|
| | | // cacheSite.setOrderId(orders.get(i).getId());
|
| | | // cacheSite.setOrderNo(orders.get(i).getOrderNo());
|
| | | // cacheSite.setSiteStatus(CacheSiteStatusType.R.id);
|
| | | // cacheSite.setBarcode(loc.getBarcode());
|
| | | // cacheSite.setUpdateTime(new Date());
|
| | | // if (!cacheSiteService.updateById(cacheSite)) {
|
| | | // throw new CoolException("缓存站更新失败");
|
| | | // }
|
| | | // }
|
| | | // }
|
| | |
|
| | | //库位F => R
|
| | | loc.setLocStsId(LocStsType.R.val());
|
| | |
| | |
|
| | | //根据库位ID分组
|
| | | Map<Long, List<OrderOutMergeParam>> listMap = flatOrders.stream().collect(Collectors.groupingBy(OrderOutMergeParam::getLocId));
|
| | |
|
| | | genPickSheet(listMap, pickSheet);
|
| | | }
|
| | |
|
| | | /**
|
| | | * @author Ryan
|
| | | * @date 2025/7/4
|
| | | * @description: 生成拣货明细
|
| | | * @version 1.0
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void genPickSheet(Map<Long, List<OrderOutMergeParam>> listMap, PickSheet pickSheet) {
|
| | | //生成拣货明细
|
| | | listMap.keySet().forEach(key -> {
|
| | | Loc curLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getId, key));
|
| | |
| | | throw new CoolException("库存加锁失败!!");
|
| | | }
|
| | |
|
| | | orderDetlService.update(new LambdaUpdateWrapper<OrderDetl>()
|
| | | .set(OrderDetl::getWareType, 2)
|
| | | .eq(OrderDetl::getMatId, mat.getId())
|
| | | .eq(StringUtils.isNullOrEmpty(outOder.getBatch()), OrderDetl::getBatch, outOder.getBatch())
|
| | | .in(OrderDetl::getOrderId, outOder.getOrderIds()));
|
| | | });
|
| | |
|
| | | });
|
| | | curLoc.setLocStsId(LocStsType.R.val());
|
| | |
|
| | | if (!locService.updateById(curLoc)) {
|
| | | throw new CoolException("库位状态修改失败!!");
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | if (param == null) {
|
| | | throw new CoolException("参数不能为空");
|
| | | }
|
| | |
|
| | | List<String> channels = param.getChannels();
|
| | | if (channels == null) {
|
| | | throw new CoolException("通道参数不能为空");
|
| | | }
|
| | |
|
| | | if (channels.isEmpty()) {
|
| | | throw new CoolException("通道参数不能为空");
|
| | | }
|
| | |
|
| | | // for (String channel : channels) {
|
| | | // long count = cacheSiteService.count(new LambdaQueryWrapper<CacheSite>().eq(CacheSite::getChannel, channel).ne(CacheSite::getSiteStatus, 0));
|
| | | // if (count > 0) {
|
| | | // throw new CoolException(channel + "通道已经分配波次");
|
| | | // }
|
| | | // }
|
| | |
|
| | |
|
| | | List<Long> orderIds = param.getOrderIds();
|
| | | if (orderIds == null) {
|
| | | throw new CoolException("订单参数不能为空");
|
| | |
| | | }
|
| | |
|
| | | CacheSite cacheSite = cacheSiteService.getOne(new LambdaQueryWrapper<CacheSite>().eq(CacheSite::getOrderId, order.getId()));
|
| | | if (cacheSite == null) {
|
| | | throw new CoolException("缓存站不存在");
|
| | | }
|
| | | cacheSite.setSiteStatus(CacheSiteStatusType.O.id);
|
| | | cacheSite.setOrderId(null);
|
| | | cacheSite.setOrderNo(null);
|
| | | cacheSite.setUpdateTime(new Date());
|
| | | if (!cacheSiteService.updateById(cacheSite)) {
|
| | | throw new CoolException("缓存站清空失败");
|
| | | if (cacheSite != null) {
|
| | | cacheSite.setSiteStatus(CacheSiteStatusType.O.id);
|
| | | cacheSite.setOrderId(null);
|
| | | cacheSite.setOrderNo(null);
|
| | | cacheSite.setBarcode(null);
|
| | | cacheSite.setUpdateTime(new Date());
|
| | | if (!cacheSiteService.updateById(cacheSite)) {
|
| | | throw new CoolException("缓存站清空失败");
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | |
|
| | | waveService.removeById(wave.getId());
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | | * @author Ryan
|
| | | * @date 2025/7/3
|
| | | * @description: 库存出库信息
|
| | | * @version 1.0
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void outLocStock(StockOutParam param) {
|
| | | System.out.println(JSONObject.toJSONString(param));
|
| | | if (param.getOutType().equals(1)) {
|
| | | //拣货单
|
| | | outFlatStock(param);
|
| | | } else {
|
| | | //生成任务档
|
| | | generateTask(param);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * @author Ryan
|
| | | * @param: []
|
| | | * @return: void
|
| | | * @date: 2025/7/4
|
| | | * @description: 手动出库生成任务
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void generateTask(StockOutParam outParam) {
|
| | | for (LocDetl outLocDetl : outParam.getLocDetls()) {
|
| | | List<OrderOutMergeDto> orders = new ArrayList<>();
|
| | | LocDetl detl = locDetlService.getOne(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getId, outLocDetl.getId()));
|
| | | if (Objects.isNull(detl)) {
|
| | | continue;
|
| | | }
|
| | | OrderOutMergeDto outMergeParam = new OrderOutMergeDto();
|
| | | outMergeParam.setAnfme(outLocDetl.getAnfme());
|
| | | outMergeParam.setLocNo(outLocDetl.getLocNo());
|
| | | outMergeParam.setLocDetlId(detl.getId());
|
| | | outMergeParam.setLocId(detl.getLocId());
|
| | | outMergeParam.setMatnr(outLocDetl.getMatnr());
|
| | | outMergeParam.setBatch(detl.getBatch());
|
| | | orders.add(outMergeParam);
|
| | |
|
| | | //根据库位ID分组
|
| | | Map<Long, List<OrderOutMergeDto>> listMap = orders.stream().collect(Collectors.groupingBy(OrderOutMergeDto::getLocId));
|
| | | //生成拣货单明细
|
| | | for (Map.Entry<Long, List<OrderOutMergeDto>> entry : listMap.entrySet()) {
|
| | | Long locId = entry.getKey();
|
| | | List<OrderOutMergeDto> list = entry.getValue();
|
| | | //判断是否全仓出库
|
| | | Boolean all = outUtils.isAllForMerge(locId, list);
|
| | | OrderOutMergeDto param = list.stream().findFirst().get();
|
| | |
|
| | | List<CacheSite> sites = cacheSiteService.list(new LambdaQueryWrapper<CacheSite>()
|
| | | .isNotNull(CacheSite::getOrderId));
|
| | | if (!sites.isEmpty()) {
|
| | | Map<String, Long> longMap = sites.stream().collect(Collectors.groupingBy(CacheSite::getChannel, Collectors.counting()));
|
| | | Map.Entry<String, Long> entry1 = longMap.entrySet().stream().min(Map.Entry.comparingByValue()).get();
|
| | | param.setPortSite(entry1.getKey());
|
| | | } else {
|
| | | CacheSite cacheSite = cacheSiteService.getOne(new LambdaQueryWrapper<CacheSite>().last("limit 1"));
|
| | | param.setPortSite(cacheSite.getChannel());
|
| | | }
|
| | | Loc loc = locService.getById(locId);
|
| | | if (loc == null) {
|
| | | throw new CoolException("库位不存在");
|
| | | }
|
| | |
|
| | | if (!loc.getLocStsId().equals(LocStsType.F.val())) {
|
| | | throw new CoolException(loc.getLocNo() + "库位状态异常");
|
| | | }
|
| | |
|
| | | OperationPort operationPort = operationPortService
|
| | | .getOne(new LambdaQueryWrapper<OperationPort>()
|
| | | .eq(OperationPort::getFlag, param.getPortSite()));
|
| | | if (Objects.isNull(operationPort)) {
|
| | | throw new CoolException("作业口不存在");
|
| | | }
|
| | | //101 全拖出库 103 拣货出库
|
| | | long taskType = all ? 101L : 103L;
|
| | |
|
| | | Task task = new Task();
|
| | | task.setTaskNo(workService.generateTaskNo(taskType));
|
| | | task.setTaskSts(TaskStsType.GENERATE_OUT.id);
|
| | | task.setTaskType(taskType);
|
| | | task.setIoPri(workService.generateIoPri(taskType));
|
| | | task.setOriginLoc(loc.getLocNo());
|
| | | task.setTargetSite(operationPort.getFlag());
|
| | | task.setBarcode(loc.getBarcode());
|
| | | boolean res = taskService.save(task);
|
| | | if (!res) {
|
| | | throw new CoolException("保存工作档失败");
|
| | | }
|
| | |
|
| | | for (OrderOutMergeDto merge : list) {
|
| | | LocDetl locDetl = locDetlService.getById(merge.getLocDetlId());
|
| | | if (locDetl == null) {
|
| | | throw new CoolException("明细不存在");
|
| | | }
|
| | |
|
| | | TaskDetl taskDetl = new TaskDetl();
|
| | | taskDetl.sync(locDetl);
|
| | | taskDetl.setId(null);
|
| | | taskDetl.setTaskId(task.getId());
|
| | | taskDetl.setTaskNo(task.getTaskNo());
|
| | | taskDetl.setAnfme(merge.getAnfme());
|
| | | taskDetl.setStock(locDetl.getAnfme());
|
| | | taskDetl.setOrderId(null);
|
| | | taskDetl.setOrderNo(null);
|
| | | if (!taskDetlService.save(taskDetl)) {
|
| | | throw new CoolException("保存工作档明细失败");
|
| | | }
|
| | |
|
| | | List<LocDetlField> locDetlFields = locDetlFieldService
|
| | | .list(new LambdaQueryWrapper<LocDetlField>()
|
| | | .eq(LocDetlField::getDetlId, locDetl.getId()));
|
| | | for (LocDetlField locDetlField : locDetlFields) {
|
| | | TaskDetlField taskDetlField = new TaskDetlField();
|
| | | taskDetlField.sync(locDetlField);
|
| | | taskDetlField.setId(null);
|
| | | taskDetlField.setDetlId(taskDetl.getId());
|
| | | boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField);
|
| | | if (!taskDetlFieldSave) {
|
| | | throw new CoolException("明细扩展生成失败");
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | //库位F => R
|
| | | loc.setLocStsId(LocStsType.R.val());
|
| | | loc.setUpdateTime(new Date());
|
| | | boolean locUpdate = locService.updateById(loc);
|
| | | if (!locUpdate) {
|
| | | throw new CoolException("库位状态更新失败");
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * @author Ryan
|
| | | * @date 2025/7/4
|
| | | * @description: 平库库存出库
|
| | | * @version 1.0
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void outFlatStock(StockOutParam param) {
|
| | | //生成拣货单
|
| | | PickSheet pickSheet = new PickSheet();
|
| | | //波次数量汇总
|
| | | Double sum = param.getLocDetls().stream().mapToDouble(LocDetl::getAnfme).sum();
|
| | | //生成拣货单号
|
| | | String pickNo = generatePickNO();
|
| | | pickSheet.setId(null)
|
| | | .setPickNo(pickNo)
|
| | | .setMemo("库存出库")
|
| | | .setAnfme(sum)
|
| | | .setType(2);
|
| | |
|
| | | if (!pickSheetService.save(pickSheet)) {
|
| | | throw new CoolException("拣货单写入失败!!");
|
| | | }
|
| | |
|
| | | for (LocDetl locDetl : param.getLocDetls()) {
|
| | | List<OrderOutMergeParam> orders = new ArrayList<>();
|
| | | LocDetl detl = locDetlService.getOne(new LambdaQueryWrapper<LocDetl>()
|
| | | .eq(LocDetl::getMatId, locDetl.getMatId())
|
| | | .eq(LocDetl::getBatch, locDetl.getBatch())
|
| | | .eq(LocDetl::getLocNo, locDetl.getLocNo()));
|
| | | if (Objects.isNull(detl)) {
|
| | | continue;
|
| | | }
|
| | | OrderOutMergeParam outMergeParam = new OrderOutMergeParam();
|
| | | outMergeParam.setAnfme(locDetl.getAnfme())
|
| | | .setLocNo(locDetl.getLocNo())
|
| | | .setLocId(detl.getLocId())
|
| | | .setLocDetlId(detl.getId())
|
| | | .setMatnr(locDetl.getMatnr())
|
| | | .setBatch(detl.getBatch());
|
| | | orders.add(outMergeParam);
|
| | |
|
| | | //根据库位ID分组
|
| | | Map<Long, List<OrderOutMergeParam>> listMap = orders.stream().collect(Collectors.groupingBy(OrderOutMergeParam::getLocId));
|
| | | //生成拣货单明细
|
| | | genPickSheet(listMap, pickSheet);
|
| | | }
|
| | | }
|
| | | }
|