| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.vincent.rsf.framework.common.SpringUtils; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.manager.entity.DeviceSite; |
| | | import com.vincent.rsf.server.manager.entity.Loc; |
| | | import com.vincent.rsf.server.manager.service.DeviceSiteService; |
| | | import com.vincent.rsf.server.manager.service.LocService; |
| | | import com.vincent.rsf.server.system.enums.LocStsType; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import com.vincent.rsf.server.api.utils.LocUtils; |
| | | import com.vincent.rsf.server.manager.controller.dto.ExistDto; |
| | | import com.vincent.rsf.server.manager.controller.dto.OrderOutItemDto; |
| | | import com.vincent.rsf.server.manager.controller.params.WaveToLocParams; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.TaskType; |
| | | import com.vincent.rsf.server.manager.enums.WaveRuleType; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import com.vincent.rsf.server.manager.enums.LocStsType; |
| | | |
| | | import java.util.Objects; |
| | | import javax.swing.*; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | public class LocManageUtil { |
| | | |
| | |
| | | |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>() |
| | | .eq(Loc::getAreaId, areaId) |
| | | .orderByAsc(Loc::getLev) |
| | | .orderByAsc(Loc::getCol) |
| | | .orderByAsc(Loc::getRow) |
| | | .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type), false |
| | | ); |
| | | |
| | |
| | | DeviceSite loc = deviceSite.getOne(new LambdaQueryWrapper<DeviceSite>().eq(DeviceSite::getStatus, 1), false); |
| | | return !Objects.isNull(loc) ? loc.getSite() : null; |
| | | } |
| | | |
| | | /** |
| | | * 出库策略:--〈效率优化〉 |
| | | * @param matnrCode |
| | | * @param splrBatch |
| | | * @param anfme |
| | | * @return |
| | | */ |
| | | public static List<LocItem> getEfficiencyFirstItemList(String matnrCode, String splrBatch, Double anfme) { |
| | | LambdaQueryWrapper<LocItem> locItemQueryWrapper = new LambdaQueryWrapper<>(); |
| | | locItemQueryWrapper.eq(LocItem::getMatnrCode, matnrCode); |
| | | locItemQueryWrapper.eq(LocItem::getBatch, splrBatch); |
| | | String applySql = String.format( |
| | | "EXISTS (SELECT 1 FROM man_loc ml " + |
| | | "WHERE ml.use_status = '%s'" + |
| | | "AND ml.id = man_loc_item.loc_id " + |
| | | ")", |
| | | LocStsType.LOC_STS_TYPE_F.type |
| | | ); |
| | | locItemQueryWrapper.apply(applySql); |
| | | LocItemService locItemService = SpringUtils.getBean(LocItemService.class); |
| | | List<LocItem> locItems = locItemService.list(locItemQueryWrapper); |
| | | locItems.sort(Comparator.comparing((LocItem item) -> !LocUtils.isShallowLoc(item.getLocCode()))); |
| | | List<LocItem> locsSet = locItems.stream().filter(locItem -> locItem.getAnfme().compareTo(anfme) == 0.0).collect(Collectors.toList()); |
| | | if (!locsSet.isEmpty()) { |
| | | return locsSet; |
| | | } |
| | | return locItems; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 出库策略:--<先进先出> |
| | | * @param matnrCode |
| | | * @param splrBatch |
| | | * @param anfme |
| | | * @return |
| | | */ |
| | | public static List<LocItem> getFirstInFirstOutItemList(String matnrCode, String splrBatch, Double anfme) { |
| | | LambdaQueryWrapper<LocItem> locItemQueryWrapper = new LambdaQueryWrapper<>(); |
| | | locItemQueryWrapper.eq(LocItem::getMatnrCode, matnrCode); |
| | | locItemQueryWrapper.eq(LocItem::getBatch, splrBatch); |
| | | locItemQueryWrapper.orderByAsc(LocItem::getCreateTime); |
| | | String applySql = String.format( |
| | | "EXISTS (SELECT 1 FROM man_loc ml " + |
| | | "WHERE ml.use_status = '%s'" + |
| | | "AND ml.id = man_loc_item.loc_id " + |
| | | ")", |
| | | LocStsType.LOC_STS_TYPE_F.type |
| | | ); |
| | | locItemQueryWrapper.apply(applySql); |
| | | LocItemService locItemService = SpringUtils.getBean(LocItemService.class); |
| | | List<LocItem> locItems = locItemService.list(locItemQueryWrapper); |
| | | return locItems; |
| | | } |
| | | |
| | | /** |
| | | * 获取出库库位信息 |
| | | * @param params |
| | | * @param waveRule |
| | | * @return |
| | | */ |
| | | public static List<OrderOutItemDto> getOutOrderList(List<WaveToLocParams> params, WaveRule waveRule) { |
| | | LocService locService = SpringUtils.getBean(LocService.class); |
| | | LocItemService locItemService = SpringUtils.getBean(LocItemService.class); |
| | | DeviceSiteService deviceSiteService = SpringUtils.getBean(DeviceSiteService.class); |
| | | |
| | | List<OrderOutItemDto> list = new ArrayList<>(); |
| | | Set<ExistDto> existDtos = new HashSet<>(); |
| | | for (WaveToLocParams item : params) { |
| | | BigDecimal issued = new BigDecimal(item.getAnfme().toString()) |
| | | .subtract(new BigDecimal(item.getWorkQty().toString())); |
| | | if (issued.doubleValue() <= 0) { |
| | | continue; |
| | | } |
| | | List<LocItem> locItems; |
| | | if (Objects.isNull(waveRule)) { |
| | | locItems = LocManageUtil.getFirstInFirstOutItemList(item.getMatnrCode(), item.getBatch(), item.getAnfme()); |
| | | } else { |
| | | if (WaveRuleType.Efficiency_First.type.equals(waveRule.getType())) { |
| | | locItems = LocManageUtil.getEfficiencyFirstItemList(item.getMatnrCode(), item.getBatch(), item.getAnfme()); |
| | | } else if (WaveRuleType.First_In_First_Out.type.equals(waveRule.getType())) { |
| | | locItems = LocManageUtil.getFirstInFirstOutItemList(item.getMatnrCode(), item.getBatch(), item.getAnfme()); |
| | | } else { |
| | | locItems = LocManageUtil.getFirstInFirstOutItemList(item.getMatnrCode(), item.getBatch(), item.getAnfme()); |
| | | } |
| | | } |
| | | |
| | | for (LocItem locItem : locItems) { |
| | | Loc loc = locService.getById(locItem.getLocId()); |
| | | List<LocItem> itemList = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocCode, locItem.getLocCode())); |
| | | if (issued.doubleValue() > 0) { |
| | | ExistDto existDto = new ExistDto().setBatch(locItem.getBatch()).setMatnr(locItem.getMatnrCode()).setLocNo(locItem.getLocCode()); |
| | | if (existDtos.add(existDto)) { |
| | | locItem.setOutQty(issued.doubleValue() >= locItem.getAnfme() ? locItem.getAnfme() : issued.doubleValue()); |
| | | locItem.setBarcode(loc.getBarcode()) |
| | | .setSourceId(item.getWaveId()) |
| | | .setSource(item.getItemId()); |
| | | OrderOutItemDto orderOutItemDto = new OrderOutItemDto(); |
| | | orderOutItemDto.setLocItem(locItem); |
| | | |
| | | List<DeviceSite> deviceSites = deviceSiteService.list(new LambdaQueryWrapper<DeviceSite>() |
| | | .eq(DeviceSite::getChannel, loc.getChannel()) |
| | | .eq(DeviceSite::getType, issued.doubleValue() >= locItem.getAnfme() && itemList.size() == 1 ? TaskType.TASK_TYPE_OUT.type : TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) |
| | | ); |
| | | |
| | | if (!deviceSites.isEmpty()) { |
| | | List<OrderOutItemDto.staListDto> maps = new ArrayList<>(); |
| | | for (DeviceSite sta : deviceSites) { |
| | | OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto(); |
| | | staListDto.setStaNo(sta.getSite()); |
| | | staListDto.setStaName(sta.getSite()); |
| | | maps.add(staListDto); |
| | | } |
| | | orderOutItemDto.setStaNos(maps); |
| | | //默认获取第一站点 |
| | | DeviceSite deviceSite = deviceSites.stream().findFirst().get(); |
| | | orderOutItemDto.setSiteNo(deviceSite.getSite()); |
| | | } |
| | | |
| | | orderOutItemDto.setSource(item.getItemId()).setSource(item.getWaveId()); |
| | | |
| | | list.add(orderOutItemDto); |
| | | |
| | | issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString())); |
| | | } |
| | | } |
| | | } |
| | | // if (issued.doubleValue() > 0) { |
| | | // LocItem locItem = new LocItem() |
| | | // .setId(new Random().nextLong()) |
| | | // .setMatnrCode(item.getMatnrCode()) |
| | | // .setMaktx(item.getMaktx()) |
| | | // .setAnfme(0.00) |
| | | // .setWorkQty(issued.doubleValue()) |
| | | // .setOutQty(issued.doubleValue()) |
| | | // .setUnit(item.getUnit()) |
| | | // .setBatch(item.getBatch()); |
| | | // OrderOutItemDto orderOutItemDto = new OrderOutItemDto(); |
| | | // orderOutItemDto.setLocItem(locItem); |
| | | // list.add(orderOutItemDto); |
| | | // } |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | } |