| | |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.*; |
| | | import com.zy.asrs.enums.CommonEnum; |
| | | import com.zy.asrs.enums.LocStsType; |
| | | import com.zy.asrs.enums.TaskIOType; |
| | | import com.zy.asrs.mapper.BasDevpMapper; |
| | | import com.zy.asrs.mapper.BasStationMapper; |
| | | import com.zy.asrs.mapper.LocMastMapper; |
| | | import com.zy.asrs.mapper.ManLocDetlMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.asrs.utils.MatUtils; |
| | | import com.zy.asrs.utils.OrderInAndOutUtil; |
| | | import com.zy.common.constant.ApiInterfaceConstant; |
| | | import com.zy.common.constant.MesConstant; |
| | | import com.zy.common.entity.Parameter; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.model.MesCombParam; |
| | | import com.zy.common.model.enums.WorkNoType; |
| | | import com.zy.common.properties.AgvProperties; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private MatService matService; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | |
| | | private BasStationService basStationService; |
| | | @Autowired |
| | | private BasContainerService basContainerService; |
| | | |
| | | @Resource |
| | | private BasStationMapper basStationMapper; |
| | | |
| | | @Resource |
| | | private BasDevpMapper basDevpMapper; |
| | | |
| | | @Resource |
| | | private AgvProperties agvProperties; |
| | | |
| | | /** |
| | | * 站点轮询计数器,用于平均分配站点 |
| | | * Key: 站点组标识(如 "east" 或 "west"),Value: 当前轮询索引 |
| | | */ |
| | | private final Map<String, AtomicInteger> siteRoundRobinCounters = new ConcurrentHashMap<>(); |
| | | |
| | | @Override |
| | | public R inLocCallAgv(CallAgvParam param,Long userId) { |
| | | int type = param.getType(); |
| | | String sourceSite = param.getSourceSite(); |
| | | String barcode = param.getBarcode(); |
| | | int ioType; |
| | | LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>().eq("loc_no", sourceSite)); |
| | | if (null == locCache) { |
| | | throw new CoolException("站点不存在:" + sourceSite); |
| | | } |
| | | switch (type) { |
| | | case 1: |
| | | // 判断有没有组托 |
| | | int count = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", barcode)); |
| | | if (count == 0) { |
| | | throw new CoolException("条码未组托:" + barcode); |
| | | } |
| | | ioType = 101; |
| | | |
| | | locCache.setLocSts(LocStsType.LOC_STS_TYPE_R.type); |
| | | locCacheService.updateById(locCache); |
| | | break; |
| | | case 2: |
| | | // 判断是拣选回库托盘 |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", barcode)); |
| | | if (wrkMast == null) { |
| | | throw new CoolException("条码不存在:" + barcode); |
| | | } |
| | | if (wrkMast.getIoType() != 103 && wrkMast.getIoType() != 107) { |
| | | throw new CoolException("条码不需要回库:" + barcode); |
| | | } |
| | | ioType = wrkMast.getIoType() - 50; |
| | | |
| | | locCache.setLocSts(LocStsType.LOC_STS_TYPE_R.type); |
| | | locCacheService.updateById(locCache); |
| | | break; |
| | | case 3: |
| | | // 判断是否为空托入库:检查条码在wms中不存在,确认为空托盘 |
| | | log.info("开始判断是否为空托入库,条码:{}", barcode); |
| | | |
| | | // 检查是否已组托 |
| | | int waitPakInCount = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", barcode)); |
| | | if (waitPakInCount != 0) { |
| | | log.warn("条码组托档已存在,不是空托盘:{}", barcode); |
| | | throw new CoolException("条码组托档已存在:" + barcode); |
| | | } |
| | | |
| | | // 检查是否有任务 |
| | | int wrkMastCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("barcode", barcode)); |
| | | if (wrkMastCount != 0) { |
| | | log.warn("条码任务档已存在,不是空托盘:{}", barcode); |
| | | throw new CoolException("条码任务档已存在:" + barcode); |
| | | } |
| | | |
| | | // 检查是否有库存 |
| | | int locDetlCount = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", barcode)); |
| | | if (locDetlCount != 0) { |
| | | log.warn("条码库存已存在,不是空托盘:{}", barcode); |
| | | throw new CoolException("条码库存已存在:" + barcode); |
| | | } |
| | | |
| | | // 通过所有检查,确认为空托盘,设置为空托入库 |
| | | ioType = 10; |
| | | log.info("确认为空托盘,设置为空托入库,条码:{},ioType:{}", barcode, ioType); |
| | | break; |
| | | default: |
| | | throw new CoolException("入库类型错误,type:" + type); |
| | | } |
| | | // 条码存在agv任务 |
| | | int count = taskService.selectCount(new EntityWrapper<Task>().eq("barcode", barcode)); |
| | | if (count > 0) { |
| | | throw new CoolException(barcode+ ":条码存在agv搬运任务!"); |
| | | } |
| | | |
| | | // 根据whs_type选择站点和机器人组 |
| | | Long whsType = locCache.getWhsType(); |
| | | List<String> targetStations; |
| | | String robotGroup; |
| | | |
| | | if (whsType != null && whsType.equals(agvProperties.getWhsTypeMapping().getInboundArea())) { |
| | | // whs_type = 1: 入库区,使用东侧站点和Group-001 |
| | | targetStations = agvProperties.getEastStations(); |
| | | robotGroup = agvProperties.getRobotGroupEast(); |
| | | log.info("库位whs_type={},使用入库区配置(东侧站点和Group-001)", whsType); |
| | | } else if (whsType != null && whsType.equals(agvProperties.getWhsTypeMapping().getCacheArea())) { |
| | | // whs_type = 2: 缓存区,使用西侧站点和Group-002 |
| | | targetStations = agvProperties.getWestStations(); |
| | | robotGroup = agvProperties.getRobotGroupWest(); |
| | | log.info("库位whs_type={},使用缓存区配置(西侧站点和Group-002)", whsType); |
| | | } else { |
| | | // whs_type为空或其他值,根据type判断(兼容旧逻辑) |
| | | if (type == 1) { |
| | | targetStations = agvProperties.getEastStations(); |
| | | robotGroup = agvProperties.getRobotGroupEast(); |
| | | } else { |
| | | targetStations = agvProperties.getWestStations(); |
| | | robotGroup = agvProperties.getRobotGroupWest(); |
| | | } |
| | | log.warn("库位whs_type={}未配置或不在映射范围内,使用type={}的默认逻辑", whsType, type); |
| | | } |
| | | |
| | | // 将站点字符串列表转换为整数列表 |
| | | List<Integer> siteIntList = targetStations.stream() |
| | | .map(Integer::parseInt) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 判断能入站点(in_enable="Y"表示能入) |
| | | List<Integer> sites = basDevpMapper.selectList( |
| | | new EntityWrapper<BasDevp>() |
| | | .eq("in_enable", "Y") // in_enable是能入 |
| | | .in("dev_no", siteIntList) |
| | | ).stream().map(BasDevp::getDevNo).collect(Collectors.toList()); |
| | | |
| | | if (sites.isEmpty()) { |
| | | throw new CoolException("没有能入站点,whs_type:" + whsType + ",type:" + type); |
| | | } |
| | | |
| | | // 获取没有出库任务的站点 |
| | | List<Integer> canInSites = basDevpMapper.getCanInSites(sites); |
| | | if (canInSites.isEmpty()) { |
| | | throw new CoolException("请等待出库完成,type:" + type); |
| | | } |
| | | |
| | | // 检查站点是否有未完成的AGV任务 |
| | | // 规则:当某个站点有未完成的AGV任务时,不分配该站点;只从没有未完成任务的站点中选择 |
| | | // 将站点列表转换为字符串列表(Task表的sta_no是String类型) |
| | | List<String> siteStrList = canInSites.stream() |
| | | .map(String::valueOf) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 查询这些站点中有未完成AGV任务的站点(wrk_sts不在5和15之间表示未完成) |
| | | List<Task> unfinishedTasks = taskService.selectList(new EntityWrapper<Task>() |
| | | .in("sta_no", siteStrList) |
| | | .eq("task_type", "agv") // 只查询AGV任务 |
| | | .last("AND wrk_sts NOT IN (5, 15)") // 排除已完成状态(5和15表示已完成) |
| | | ); |
| | | |
| | | // 获取有未完成任务的站点集合(这些站点将被排除,不参与分配) |
| | | Set<String> sitesWithUnfinishedTasks = unfinishedTasks.stream() |
| | | .map(Task::getStaNo) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | // 从可用站点中排除有未完成任务的站点,只保留没有未完成任务的站点 |
| | | List<Integer> availableSites = canInSites.stream() |
| | | .filter(site -> !sitesWithUnfinishedTasks.contains(String.valueOf(site))) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 如果所有站点都有未完成任务,则没有可用站点,不分配 |
| | | if (availableSites.isEmpty()) { |
| | | String groupName = (whsType != null && whsType.equals(agvProperties.getWhsTypeMapping().getInboundArea())) |
| | | ? "东侧" : "西侧"; |
| | | log.warn("{}所有站点({})都有未完成的AGV任务,无法分配站点,请等待任务完成", groupName, canInSites); |
| | | throw new CoolException(groupName + "所有站点都有未完成的AGV任务,请等待任务完成后再试"); |
| | | } |
| | | |
| | | // 记录站点分配信息 |
| | | if (!sitesWithUnfinishedTasks.isEmpty()) { |
| | | log.info("站点分配检查:总站点数={},有未完成任务的站点={}(已排除),可用站点数={},可用站点={}", |
| | | canInSites.size(), sitesWithUnfinishedTasks, availableSites.size(), availableSites); |
| | | } else { |
| | | log.info("站点分配检查:所有站点({})都没有未完成任务,全部可用", canInSites); |
| | | } |
| | | |
| | | // 寻找入库任务最少的站点(只从可用站点中选择,且必须in_enable="Y"能入 和 canining="Y"可入) |
| | | List<BasDevp> devList = basDevpMapper.selectList(new EntityWrapper<BasDevp>() |
| | | .in("dev_no", availableSites) |
| | | .eq("in_enable", "Y") // in_enable是能入 |
| | | .eq("canining", "Y") // canining是可入 |
| | | ); |
| | | |
| | | // 如果查询结果为空,说明没有可入的站点 |
| | | if (devList.isEmpty()) { |
| | | String groupName = (whsType != null && whsType.equals(agvProperties.getWhsTypeMapping().getInboundArea())) |
| | | ? "东侧" : "西侧"; |
| | | log.warn("{}可用站点({})中没有可入站点(in_enable='Y'且canining='Y'),无法分配", groupName, availableSites); |
| | | throw new CoolException(groupName + "可用站点中没有可入站点,请检查站点配置"); |
| | | } |
| | | |
| | | // 入库任务数排序 |
| | | devList.sort(Comparator.comparing(BasDevp::getInQty)); |
| | | |
| | | // 选择站点 |
| | | BasDevp basDevp; |
| | | int endSite; |
| | | |
| | | // 获取最少任务数 |
| | | int minInQty = devList.get(0).getInQty(); |
| | | |
| | | // 筛选出任务数最少的站点列表 |
| | | List<BasDevp> minTaskSites = devList.stream() |
| | | .filter(dev -> dev.getInQty() == minInQty) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 根据配置选择分配策略 |
| | | String strategy = agvProperties.getSiteAllocation().getStrategy(); |
| | | boolean enableRoundRobin = agvProperties.getSiteAllocation().isEnableRoundRobin(); |
| | | |
| | | if (minTaskSites.size() > 1 && enableRoundRobin && "round-robin".equals(strategy)) { |
| | | // 轮询分配:当多个站点任务数相同时,使用轮询 |
| | | String groupKey = (whsType != null && whsType.equals(agvProperties.getWhsTypeMapping().getInboundArea())) |
| | | ? "east" : "west"; |
| | | AtomicInteger counter = siteRoundRobinCounters.computeIfAbsent(groupKey, k -> new AtomicInteger(0)); |
| | | int index = counter.getAndIncrement() % minTaskSites.size(); |
| | | basDevp = minTaskSites.get(index); |
| | | log.info("使用轮询分配策略,站点组:{},轮询索引:{},选中站点:{}", groupKey, index, basDevp.getDevNo()); |
| | | } else if (minTaskSites.size() > 1 && enableRoundRobin && "random".equals(strategy)) { |
| | | // 随机分配 |
| | | Random random = new Random(); |
| | | int index = random.nextInt(minTaskSites.size()); |
| | | basDevp = minTaskSites.get(index); |
| | | log.info("使用随机分配策略,选中站点:{}", basDevp.getDevNo()); |
| | | } else { |
| | | // 默认:选择第一个(任务最少的) |
| | | basDevp = devList.get(0); |
| | | if (minTaskSites.size() > 1) { |
| | | log.info("多个站点任务数相同({}),但未启用轮询,选择第一个站点:{}", minInQty, basDevp.getDevNo()); |
| | | } |
| | | } |
| | | |
| | | endSite = basDevp.getDevNo(); |
| | | |
| | | // 入库暂存+1 |
| | | basDevpMapper.incrementInQty(endSite); |
| | | |
| | | |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(WorkNoType.PICK.type); |
| | | // 保存工作档 |
| | | Task task = new Task(); |
| | | Date now = new Date(); |
| | | task.setWrkNo(workNo) |
| | | .setIoTime(now) |
| | | .setWrkSts(7L) // 工作状态:11.生成出库ID |
| | | .setIoType(ioType) // 入出库状态: 1.入库 |
| | | .setTaskType("agv") |
| | | .setIoPri(10D) |
| | | .setStaNo(String.valueOf(endSite)) |
| | | .setSourceStaNo(sourceSite) // 设置源站点 |
| | | .setInvWh(robotGroup) // 根据whs_type设置机器人组 |
| | | .setFullPlt(ioType != 10 ? "N" : "Y")// 满板:Y |
| | | .setPicking("N") // 拣料 |
| | | .setExitMk("N")// 退出 |
| | | .setSourceLocNo(locCache.getLocNo()) // 设置源库位编号,用于AGV fromBin |
| | | .setEmptyMk(ioType == 10 ? "Y" : "N")// 空板 |
| | | .setBarcode(barcode)// 托盘码 |
| | | .setLinkMis("N") |
| | | .setAppeTime(now) |
| | | .setModiTime(now); |
| | | if (!taskService.insert(task)) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | |
| | | // 更新暂存位状态为 R.出库预约 |
| | | basStationMapper.updateLocStsBatch( Collections.singletonList(String.valueOf(sourceSite)), "R"); |
| | | return R.ok("agv任务生成成功!"); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | continue; |
| | | } |
| | | if (orderPakout.getSettle() == 1) { |
| | | OrderInAndOutUtil.updateOrder(false, orderPakout.getId(), 2L, 9527L); |
| | | orderPakoutService.updateSettle(orderPakout.getId(), 2L, 9527L); |
| | | } |
| | | OrderDetlPakout orderDetlPakout = orderDetlPakoutService.selectItem(orderPakout.getId(), combMat.getMatnr(), combMat.getBatch(), |
| | | combMat.getBrand(), combMat.getStandby1(), combMat.getStandby2(), combMat.getStandby3(), combMat.getBoxType1(), combMat.getBoxType2(), combMat.getBoxType3()); |
| | |
| | | typeList.add(docType.getDocId()); |
| | | } |
| | | |
| | | Wrapper<Order> wrapper = new EntityWrapper<>(); |
| | | Wrapper<OrderPakin> wrapper = new EntityWrapper<>(); |
| | | wrapper.eq("status", 1); |
| | | wrapper.in("doc_type", typeList); |
| | | List<Order> orders = orderService.selectList(wrapper); |
| | | List<OrderPakin> orders = orderPakinService.selectList(wrapper); |
| | | |
| | | ArrayList<Long> orderIds = new ArrayList<>(); |
| | | for (Order order : orders) { |
| | | for (OrderPakin order : orders) { |
| | | orderIds.add(order.getId()); |
| | | } |
| | | |
| | | //搜索明细 |
| | | Wrapper<OrderDetl> wrapper1 = new EntityWrapper<>(); |
| | | Wrapper<OrderDetlPakin> wrapper1 = new EntityWrapper<>(); |
| | | wrapper1.eq("status", 1); |
| | | wrapper1.in("order_id", orderIds); |
| | | wrapper1.orderBy("create_time", false); |
| | |
| | | if (!Cools.isEmpty(orderNo)) { |
| | | wrapper1.like("order_no", orderNo); |
| | | } |
| | | List<OrderDetl> list = orderDetlService.selectList(wrapper1); |
| | | List<OrderDetlPakin> list = orderDetlPakinService.selectList(wrapper1); |
| | | |
| | | ArrayList<PickMatParam> maps = new ArrayList<>(); |
| | | for (OrderDetl orderDetl : list) { |
| | | for (OrderDetlPakin orderDetl : list) { |
| | | //剩余可用数量 |
| | | double count = orderDetl.getAnfme() - orderDetl.getWorkQty(); |
| | | if (count <= 0) { |
| | |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | if (mat.getUpQty().compareTo(detlDto.getAnfme()) < 0) { |
| | | throw new CoolException("物料:" + detlDto.getMatnr() + "单次最大组托上限为:" + mat.getUpQty()); |
| | | } |
| | | // if (mat.getUpQty().compareTo(detlDto.getAnfme()) < 0) { |
| | | // throw new CoolException("物料:" + detlDto.getMatnr() + "单次最大组托上限为:" + mat.getUpQty()); |
| | | // } |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | BeanUtils.copyProperties(mat, waitPakin); |
| | | waitPakin.setBatch(detlDto.getBatch()); |
| | |
| | | } |
| | | // 关联组托 |
| | | } else { |
| | | // Order order = orderService.selectByNo(param.getOrderNo()); |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | | param.getCombMats().forEach(elem -> { |
| | | Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, elem.getOrderNo()); |
| | | OrderPakin order = orderPakinService.selectByNo(elem.getOrderNo()); |
| | | if (Cools.isEmpty(order) || order.getSettle() > 2) { |
| | | throw new CoolException("单据编号已过期"); |
| | | throw new CoolException("单据正在作业中"); |
| | | } |
| | | // 订单明细数量校验 |
| | | // OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(), |
| | | // elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3()); |
| | | OrderDetlPakin detls = orderDetlPakinService.selectOne(new EntityWrapper<OrderDetlPakin>() |
| | | .eq("order_id", order.getId()) |
| | | .eq("matnr", elem.getMatnr())); |
| | |
| | | if (elem.getAnfme() > detls.getEnableQty()) { |
| | | throw new CoolException(detls.getMatnr() + "入库数量不合法"); |
| | | } |
| | | OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(), |
| | | orderDetlPakinService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(), |
| | | elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme()); |
| | | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(), |
| | | elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme()); |
| | |
| | | } |
| | | }); |
| | | |
| | | BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode())); |
| | | if (Objects.isNull(container)) { |
| | | throw new CoolException("数据错误:容器码不存在!!"); |
| | | } |
| | | if (container.getMixMax() < detlDtos.size()) { |
| | | throw new CoolException("超出容器最大混装数量,当前容器最大数量为:" + container.getMixMax() + "!!"); |
| | | } |
| | | Set<String> matnrs = detlDtos.stream().map(DetlDto::getMatnr).collect(Collectors.toSet()); |
| | | List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr", matnrs)); |
| | | Set<Long> tagIds = mats.stream().map(Mat::getTagId).collect(Collectors.toSet()); |
| | | if (tagIds.size() > 1) { |
| | | throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!"); |
| | | } |
| | | //还可以放入多少种物料 |
| | | Integer suplus = container.getMixMax(); |
| | | // BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode())); |
| | | // if (Objects.isNull(container)) { |
| | | // throw new CoolException("数据错误:容器码不存在!!"); |
| | | // } |
| | | // if (container.getMixMax() < detlDtos.size()) { |
| | | // throw new CoolException("超出容器最大混装数量,当前容器最大数量为:" + container.getMixMax() + "!!"); |
| | | // } |
| | | // Set<String> matnrs = detlDtos.stream().map(DetlDto::getMatnr).collect(Collectors.toSet()); |
| | | // List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr", matnrs)); |
| | | // Set<Long> tagIds = mats.stream().map(Mat::getTagId).collect(Collectors.toSet()); |
| | | // if (tagIds.size() > 1) { |
| | | // throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!"); |
| | | // } |
| | | // //还可以放入多少种物料 |
| | | // Integer suplus = container.getMixMax(); |
| | | for (DetlDto detlDto : detlDtos) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | //最多可放数量 |
| | | Double singleMax = mat.getUpQty() * suplus; |
| | | if (singleMax.compareTo(detlDto.getAnfme()) < 0) { |
| | | throw new CoolException("物料:" + detlDto.getMatnr() + "单次组托上限为:" + mat.getUpQty() + ",当前总量超出托盘装载上限!!"); |
| | | } |
| | | BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty()); |
| | | //当前物料需要占用料箱格数 |
| | | Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue(); |
| | | suplus = suplus - curr; |
| | | if (suplus < 0) { |
| | | throw new CoolException("物料:" + detlDto.getMatnr() + ", 超出当前托盘装载上限!!"); |
| | | } |
| | | // //最多可放数量 |
| | | // Double singleMax = mat.getUpQty() * suplus; |
| | | // if (singleMax.compareTo(detlDto.getAnfme()) < 0) { |
| | | // throw new CoolException("物料:" + detlDto.getMatnr() + "单次组托上限为:" + mat.getUpQty() + ",当前总量超出托盘装载上限!!"); |
| | | // } |
| | | // BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty()); |
| | | // //当前物料需要占用料箱格数 |
| | | // Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue(); |
| | | // suplus = suplus - curr; |
| | | // if (suplus < 0) { |
| | | // throw new CoolException("物料:" + detlDto.getMatnr() + ", 超出当前托盘装载上限!!"); |
| | | // } |
| | | |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | BeanUtils.copyProperties(mat, waitPakin); |
| | |
| | | |
| | | Set<String> stringSet = param.getCombMats().stream().map(CombParam.CombMat::getOrderNo).collect(Collectors.toSet()); |
| | | stringSet.forEach(orderNo -> { |
| | | Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, orderNo); |
| | | OrderInAndOutUtil.updateOrder(Boolean.TRUE, order.getId(), 2L, userId); |
| | | OrderPakin order = orderPakinService.selectByNo(orderNo); |
| | | orderPakinService.updateSettle(order.getId(), 2L, userId); |
| | | }); |
| | | } |
| | | |
| | |
| | | boolean success = false; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(MesConstant.URL) |
| | | .setUri(MesConstant.URI) |
| | | .setPath(MesConstant.PACK_DOWN_URL) |
| | | .setJson(JSON.toJSONString(mesCombParam)) |
| | | .build() |
| | |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | success = true; |
| | | } else if (jsonObject.getInteger("code").equals(500)) { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URI + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); |
| | | throw new CoolException(jsonObject.getString("msg")); |
| | | } else { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URI + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); |
| | | throw new CoolException("上报mes系统失败"); |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | // 保存接口日志 |
| | | apiLogService.save( |
| | | "打包下线帮托上报", |
| | | MesConstant.URL + MesConstant.PACK_DOWN_URL, |
| | | MesConstant.URI + MesConstant.PACK_DOWN_URL, |
| | | null, |
| | | "127.0.0.1", |
| | | JSON.toJSONString(mesCombParam), |
| | |
| | | openParam.setOrderType("打包入库单"); |
| | | openParam.setOrderDetails(detlDtos); |
| | | openService.pakinOrderCreate(openParam); |
| | | // Order order = orderService.selectByNo(orderNo); |
| | | Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, param.getOrderNo()); |
| | | OrderPakin order = orderPakinService.selectByNo(param.getOrderNo()); |
| | | |
| | | if (null == order) { |
| | | throw new CoolException("生成单据失败"); |
| | | } |
| | | // if (!orderService.updateSettle(order.getId(), 2L, userId)) { |
| | | // throw new CoolException("修改单据状态失败"); |
| | | // } |
| | | OrderInAndOutUtil.updateOrder(Boolean.TRUE, order.getId(), 2L, userId); |
| | | |
| | | if (!orderPakinService.updateSettle(order.getId(), 2L, userId)) { |
| | | throw new CoolException("修改单据状态失败"); |
| | | } |
| | | // 生成入库通知档 |
| | | for (DetlDto detlDto : detlDtos) { |
| | | |
| | | // 修改作业数量 ---------------------------------------- |
| | | // 订单明细数量校验 |
| | | // OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch()); |
| | | OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3() |
| | | OrderDetlPakin orderDetlPakin = orderDetlPakinService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3() |
| | | , detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3()); |
| | | if (detlDto.getAnfme() > orderDetl.getEnableQty()) { |
| | | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); |
| | | if (detlDto.getAnfme() > orderDetlPakin.getEnableQty()) { |
| | | throw new CoolException(orderDetlPakin.getMatnr() + "入库数量不合法"); |
| | | } |
| | | // 修改订单作业数量 |
| | | // if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) { |
| | | // throw new CoolException("修改单据作业数量失败"); |
| | | // } |
| | | OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3() |
| | | , detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3(), detlDto.getAnfme()); |
| | | if (!orderDetlPakinService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3() |
| | | , detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3(), detlDto.getAnfme())) { |
| | | throw new CoolException("修改单据作业数量失败"); |
| | | } |
| | | // 保存入库通知档 |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | |
| | | |
| | | BasDevp sta = basDevpService.checkSiteStatus(staNo); |
| | | //根据订单号生成出库任务工作档 |
| | | Order order = OrderInAndOutUtil.selectByNo(Boolean.FALSE, orderNo); |
| | | // Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderNo)); |
| | | OrderPakout order = orderPakoutService.selectOne(new EntityWrapper<OrderPakout>().eq("order_no", orderNo)); |
| | | if (order.getSettle() != 1 && order.getSettle() != 2) { |
| | | throw new CoolException("该订单已处理"); |
| | | } |
| | | |
| | | // List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo)); |
| | | List<OrderDetl> orderDetls = OrderInAndOutUtil.selectByOrderId(Boolean.FALSE, order.getId()); |
| | | List<OrderDetlPakout> orderDetls = orderDetlPakoutService.selectByOrderId(order.getId()); |
| | | |
| | | Date now = new Date(); |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | for (OrderDetlPakout orderDetl : orderDetls) { |
| | | //查询所有库位状态为F的库位信息 |
| | | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null, null); |
| | | if (locDetls.size() == 0) { |
| | |
| | | order.setSettle(2L); |
| | | order.setUpdateBy(userId); |
| | | order.setUpdateTime(now); |
| | | // if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){ |
| | | // throw new CoolException("更新订单状态失败"); |
| | | // } |
| | | OrderInAndOutUtil.updateOrder(order.getPakinPakoutStatus$(), order.getId(), 2L, userId); |
| | | if (!orderPakoutService.update(order, new EntityWrapper<OrderPakout>().eq("order_no", orderNo))) { |
| | | throw new CoolException("更新订单状态失败"); |
| | | } |
| | | orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty); |
| | | orderDetl.setUpdateBy(userId); |
| | | orderDetl.setUpdateTime(now); |
| | |
| | | if (!Cools.isEmpty(orderDetl.getBatch())) { |
| | | wrapper.eq("batch", orderDetl.getBatch()); |
| | | } |
| | | // if(!orderDetlService.update(orderDetl, wrapper)){ |
| | | // throw new CoolException("更新订单明细失败"); |
| | | // } |
| | | OrderInAndOutUtil.updateOrderDetl(order.getPakinPakoutStatus$(), order, orderDetl); |
| | | if (!orderDetlPakoutService.update(orderDetl, wrapper)) { |
| | | throw new CoolException("更新订单明细失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void stockOut(OrderDetl orderDetl, BasDevp staNo, LocDetl locDetl, |
| | | public void stockOut(OrderDetlPakout orderDetl, BasDevp staNo, LocDetl locDetl, |
| | | Double curOutQty, Integer ioType, Long userId, Date now) { |
| | | // 获取库位 |
| | | LocMast locMast = locMastService.selectById(locDetl.getLocNo()); |