diff --git a/src/main/java/com/dev/swms/server/service/picking/allocate/AutoAllocator1.java b/src/main/java/com/dev/swms/server/service/picking/allocate/AutoAllocator1.java deleted file mode 100644 index 0563693..0000000 --- a/src/main/java/com/dev/swms/server/service/picking/allocate/AutoAllocator1.java +++ /dev/null @@ -1,210 +0,0 @@ -package com.dev.swms.server.service.picking.allocate; - -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.springframework.transaction.annotation.Transactional; - -import com.dev.swms.server.model.abstractEntity.AbstractMoveDoc; -import com.dev.swms.server.model.abstractEntity.AbstractMoveDocDetail; -import com.dev.swms.server.model.base.BillType; -import com.dev.swms.server.model.base.Item; -import com.dev.swms.server.model.base.LotInfo; -import com.dev.swms.server.model.base.Structure; -import com.dev.swms.server.model.base.PackageUnit; -import com.dev.swms.server.model.inventory.AgvTask; -import com.dev.swms.server.model.inventory.ProcessDocBOMDetail; -import com.dev.swms.server.model.inventory.Task; -import com.dev.swms.server.model.rules.PickItemRule; -import com.dev.swms.server.model.shipping.PickTicket; -import com.dev.swms.server.model.shipping.PickTicketDetail; -import com.dev.energy.server.service.BaseManager; - -/** - * @author dev - */ -@Transactional(readOnly = true) -public interface AutoAllocator1 extends BaseManager { - /** - * 预分配 - * @param pickTicketDetails - */ - @Transactional - String preAllocate(List pickTicketId); - - @Transactional(readOnly = false) - String preAllocatePO(List pickTicketId); - @Transactional(readOnly = false) - String preAllocateDate(Date beginDate,Date endDate); - /** - * 预分配 - * @param pickTicketDetails - */ - @Transactional - void preAllocate(Collection pickTicketDetails); - - - /** - * 取消预分配 - * @param pickTicketDetails - */ - @Transactional - void unPreAllocate(Collection pickTicketDetails); - - /** - * 取消预分配 - * @param detail 发货单明细 - * @param quantity 待取消预分配数量 - */ - @Transactional - void unPreAllocate(PickTicketDetail detail, Double quantity); - - /** - * 查找拣货规则 - * @param company - * @param billType - * @param itemPickType - * @param item - * @param packageUnit - * @param lotInfo - * @param quantity - * @param abcType - * @return - */ - List getPickItemRules(Structure company,BillType billType,String itemPickType, - Item item,PackageUnit packageUnit,LotInfo lotInfo,double quantity,String abcType); - - /** - * 反激活补货计划 - * @param moveDoc - * @return - */ - @Transactional - void unallocate(AbstractMoveDoc moveDoc); - - @Transactional - void unallocate(AbstractMoveDoc moveDoc,List details); - - - /** - * 库内加工作为单子件明细预分配 - * @param bomDetail - * @param quantity - */ - @Transactional - void preAllocate(ProcessDocBOMDetail bomDetail, Double quantity); - - /** - * 库内加工作为单子件明细取消预分配 - * @param bomDetail - * @param quantity - */ - @Transactional - void unPreAllocate(ProcessDocBOMDetail bomDetail, Double quantity); - - /** - * 手工拣货分配 - * @param pickTicketDetail - * @param inventories - */ - @Transactional - void manualAllocate(AbstractMoveDocDetail moveDocDetail, Map inventories); - - /** - * 根据类型自动拣货分配(确保同一仓库单进程) - * @param ids - * @param type - */ - @Transactional - String allocate(Long pickTicketId, Long waveDocId, Long moveDocId, Collection details); - - /** - * 根据类型自动拣货分配(确保同一仓库单进程) - * @param ids - * @param type - */ - @Transactional - String allocateDetail(AbstractMoveDocDetail detail); - - //波次分配 - @Transactional - void allocateWaveDoc(List WaveDocIds); - //波次分配 - @Transactional - void allocatePlanAll(List WaveDocIds); - //波次分配 - @Transactional - void newallocateWaveDoc(List WaveDocIds); - - //订单明细分配 - //自动创波,ddq1=3#不良品区,ddq2=3#焊接件区,ddq3=3#货架区,ddq4=3#料箱区,ddq5=7#3楼普通库, - //ddq6=7#4楼普通库,ddq7=7#地堆区,ddq8=#堆垛库,ddq9=8#化学品区 - @Transactional - List allocatePickticketDetail(List ids,int qty,boolean ddq,boolean ddq1, - boolean ddq2,boolean ddq3,boolean ddq4,boolean ddq5,boolean ddq6,boolean ddq7, - boolean ddq8,boolean ddq9,String noLoc); - //按明细分配 - @Transactional - void allocatePickticketDetail(List ids); - - //取消分配 - @Transactional - void cancelallocate(List WaveDocIds); - - @Transactional - void cancelallocateTaskAgv(List WaveDocIds); - - @Transactional - void cancelPickticket(List pickIds); - @Transactional - void cancelPickticketDetail(List pickIds); - //按task取消分配 - @Transactional - void cancelTask(List pickIds); - - @Transactional - void shuaxinPick(PickTicket pt); - - //料箱出库回传 - @Transactional - void returnAGV(List robotJobIds,String containerCode); - @Transactional - void returnAGV(String code,Boolean takeAwayFlag,List robotJobIds); - - //人工呼叫AGV - @Transactional - void artificialAGV(List ids); - - @Transactional - void initializationLabel(long waveDocId); - - @Transactional - void callAGV(long waveDocId); - - @Transactional - void allautoWaveDetail(List ids); - - @Transactional - String allocatePickticket(PickTicket pt); - - //自动下发创波任务 - void initiandcallAGV(long waveDocId,List lxq,List hjq,List lkq); - - //杂单下发AGV任务 - @Transactional - void issueAGV0(); - - //生成AGV任务平均分配到工作站 - @Transactional - void issuedAgvTask(List ids); - - //刷新波次 - void shuaXinWaveDoc(long waveDocId); - @Transactional - void taskIssuedAgv(List ids); - //加急单生成出库任务 - @Transactional - void addPickTicketTask(Long asnid,Long userId); -} diff --git a/src/main/java/com/dev/swms/server/service/picking/allocate/DefaultAutoAllocator1.java b/src/main/java/com/dev/swms/server/service/picking/allocate/DefaultAutoAllocator1.java deleted file mode 100644 index 8a3dcc1..0000000 --- a/src/main/java/com/dev/swms/server/service/picking/allocate/DefaultAutoAllocator1.java +++ /dev/null @@ -1,3789 +0,0 @@ -package com.dev.swms.server.service.picking.allocate; - -import java.io.IOException; -import java.io.InputStream; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.stream.Collectors; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -import org.apache.commons.beanutils.BeanComparator; -import org.apache.commons.collections.comparators.ComparatorChain; -import org.apache.commons.collections.comparators.ReverseComparator; -import org.apache.commons.lang.StringUtils; - -import com.dev.swms.server.model.abstractEntity.AbstractMoveDoc; -import com.dev.swms.server.model.abstractEntity.AbstractMoveDocDetail; -import com.dev.swms.server.model.base.BillType; -import com.dev.swms.server.model.base.BillTypeConfig; -import com.dev.swms.server.model.base.CompanyCode; -import com.dev.swms.server.model.base.Item; -import com.dev.swms.server.model.base.ItemKey; -import com.dev.swms.server.model.base.Location; -import com.dev.swms.server.model.base.LocationStorage; -import com.dev.swms.server.model.base.LotInfo; -import com.dev.swms.server.model.base.NewLotInfo; -import com.dev.swms.server.model.base.Structure; -import com.dev.swms.server.model.base.PackageUnit; -import com.dev.swms.server.model.base.ShiXiao; -import com.dev.swms.server.model.base.TurnOverMode; -import com.dev.swms.server.model.base.Warehouse; -import com.dev.swms.server.model.base.WarehouseArea; -import com.dev.swms.server.model.base.WarehouseAreaStatus; -import com.dev.swms.server.model.base.Worker; -import com.dev.swms.server.model.delivery.UrgentOrder; -import com.dev.swms.server.model.inventory.AgvTask; -import com.dev.swms.server.model.inventory.Configuration; -import com.dev.swms.server.model.inventory.Inventory; -import com.dev.swms.server.model.inventory.InventoryLogType; -import com.dev.swms.server.model.inventory.ItemKeyInventory; -import com.dev.swms.server.model.inventory.ProcessDoc; -import com.dev.swms.server.model.inventory.ProcessDocBOMDetail; -import com.dev.swms.server.model.inventory.Stock; -import com.dev.swms.server.model.inventory.Task; -import com.dev.swms.server.model.inventory.TaskType; -import com.dev.swms.server.model.receiving.ASN; -import com.dev.swms.server.model.receiving.ASNDetail; -import com.dev.swms.server.model.receiving.InterWMStask; -import com.dev.swms.server.model.receiving.MoveDoc; -import com.dev.swms.server.model.receiving.MoveDocDetail; -import com.dev.swms.server.model.receiving.MoveDocStatus; -import com.dev.swms.server.model.receiving.ReceivedRecord; -import com.dev.swms.server.model.receiving.STATUS; -import com.dev.swms.server.model.rules.ItemStorageRule; -import com.dev.swms.server.model.rules.PickItemRule; -import com.dev.swms.server.model.rules.PickMethod; -import com.dev.swms.server.model.rules.SortRule; -import com.dev.swms.server.model.shipping.LotQuantity; -import com.dev.swms.server.model.shipping.PickTicket; -import com.dev.swms.server.model.shipping.PickTicketDetail; -import com.dev.swms.server.model.shipping.PickTicketStatus; -import com.dev.swms.server.model.shipping.PreAllocate; -import com.dev.swms.server.model.shipping.SeedWall; -import com.dev.swms.server.model.shipping.WaveDoc; -import com.dev.swms.server.model.shipping.WaveDocDetail; -import com.dev.swms.server.model.shipping.WaveDocStatus; -import com.dev.swms.server.service.GlobalParamUtils; -import com.dev.swms.server.service.base.AgvTaskManager; -import com.dev.swms.server.service.base.ItemManager; -import com.dev.swms.server.service.interfaceLog.ApiURL; -import com.dev.swms.server.service.interfaceLog.InterfaceManager; -import com.dev.swms.server.service.interfaceLog.InterfaceReqManager; -import com.dev.swms.server.service.interfaceLog.JdbcManager; -import com.dev.swms.server.service.interfaceLog.WcsCSDCode; -import com.dev.swms.server.service.inventory.InventoryManager; -import com.dev.swms.server.service.receiving.PutawayAllocator; -import com.dev.swms.server.service.sequence.BussinessCodeManager; -import com.dev.swms.server.utils.DateUtil; -import com.dev.swms.server.utils.DoubleUtils; -import com.dev.swms.server.utils.NewLotInfoParser; -import com.dev.swms.server.utils.TimeNumberUtils; -import com.dev.swms.server.web.filter.WarehouseHolder; -import com.dev.energy.server.exception.BusinessException; -import com.dev.energy.server.model.EntityFactory; -import com.dev.energy.server.service.pojo.DefaultBaseManager; -import com.dev.energy.server.util.LocalizedMessage; -import com.dev.energy.server.web.security.UserHolder; - -import org.apache.log4j.Logger; -/** - * @author dev - * - */ -public class DefaultAutoAllocator1 extends DefaultBaseManager implements AutoAllocator1 { - protected final ItemManager itemManager; - protected final InventoryManager inventoryManager; - protected final BussinessCodeManager bussinessCodeManager; - protected final PutawayAllocator putawayAllocator; - private Long warehouseId; - protected final InterfaceManager interfaceManager; - protected final JdbcManager jdbcManager; - protected final AgvTaskManager agvTaskManager; - protected final InterfaceReqManager interfaceReqManager; - private static Logger logger = Logger.getLogger(DefaultAutoAllocator.class); - - - public DefaultAutoAllocator1(ItemManager manager,InventoryManager manager1, - BussinessCodeManager manager2, PutawayAllocator allocator,InterfaceManager interfaceManager2,JdbcManager jdbcManager2,AgvTaskManager agvTaskManager, - InterfaceReqManager interfaceReqManager) { - itemManager = manager; - inventoryManager = manager1; - bussinessCodeManager = manager2; - putawayAllocator = allocator; - interfaceManager=interfaceManager2; - jdbcManager=jdbcManager2; - this.agvTaskManager=agvTaskManager; - this.interfaceReqManager=interfaceReqManager; - } - - /** - * 拣货分配过程 - * @param moveDocDetails - */ - @SuppressWarnings("unchecked") - private String allocateInventoryForPickItemRule(Collection moveDocDetails) { - String errmsg = ""; - Structure company = null; - BillType billType = null; - Warehouse warehouse = null; - List replDetails = new ArrayList(); - boolean isPickingAllocate = Boolean.FALSE; - for(AbstractMoveDocDetail moveDocDetail : moveDocDetails){ - if (!isPickingAllocate && (moveDocDetail instanceof PickTicketDetail - || moveDocDetail instanceof WaveDocDetail)) { - isPickingAllocate = Boolean.TRUE; - } - String loc_code=null; - String loc="'STORAGE','TRANSIT','存货','料箱','备货'"; - if(moveDocDetail instanceof WaveDocDetail){//补货明细都需要补货 - //loc="'STORAGE'"; - } - if(moveDocDetail instanceof PickTicketDetail){//当货品补货位不为空,且零散数量只能从拣货位出 - PickTicketDetail d=(PickTicketDetail)moveDocDetail; - if(d.isOldRecord()){ - if(!d.getItem().getCompany().getCode().equals(CompanyCode.WP)){ - loc="'TRANSIT'"; - if(d.getItem().getLocation()!=null){ - loc_code=d.getItem().getLocation().getCode(); - } - } - } -// if(d.getItem().getLocation()!=null&&d.getCaCoefficient()>0){ -// loc="'STORAGE'"; -// } - } - if (moveDocDetail.getAbstractMoveDoc() != null && moveDocDetail.getAbstractMoveDoc().getCompany()!=null) { -// company = moveDocDetail.getItem().getCompany(); - company =moveDocDetail.getAbstractMoveDoc().getCompany(); - } - Boolean bh=Boolean.FALSE; - if(moveDocDetail.getItem().getLocation()!=null){ - bh=Boolean.TRUE; - } - if (billType == null) { - billType = moveDocDetail.getAbstractMoveDoc().getBillType(); - } - if (warehouse == null) { - warehouse = moveDocDetail.getAbstractMoveDoc().getWarehouse(); - } - ItemStorageRule isr = moveDocDetail.getItem().getWarehouseItemStorageRule(); - - Location dstLoc = moveDocDetail.getAllocateDstLoc(); - //如果发货单明细无未分配数量,则忽略 - if (moveDocDetail.getUnallocateQuantity() <= 0) { - continue; - } - - String itemPickType = null; - if(isr != null && isr.getItemPickType() != null){ - itemPickType = isr.getItemPickType(); - } - String abcType = null; - if(isr != null && isr.getAbcType() != null) { - abcType = isr.getAbcType().getAbcType(); - } - - //根据单据明细获取对应货品的分配规则 - List pickItemRules = getPickItemRules(company, billType, itemPickType, - moveDocDetail.getItem(),moveDocDetail.getPackageUnit(),moveDocDetail.getLotInfo(), - moveDocDetail.getPreAllocatedQuantity(), abcType); - if (pickItemRules == null || pickItemRules.size() == 0) { - errmsg += moveDocDetail.getItem().getCode()+"货品无匹配拣货规则;"; - } - List tempInventories = new ArrayList(); - double totalQty = 0.0; - for(PickItemRule pickItemRule:pickItemRules){ - Item item = moveDocDetail.getItem(); - NewLotInfo lotInfo = moveDocDetail.getNewLotInfo() == null ? new NewLotInfo() : moveDocDetail.getNewLotInfo(); - //按库位或库位分类过滤库存 - String locHql = ""; - if (pickItemRule.getPickLocation() != null) { - locHql += " AND inventory.location.id = " + pickItemRule.getPickLocation().getId(); - } -// else { -// locHql += " AND inventory.location.positionIds like '%<" + pickItemRule.getPosition().getId() + ">%' "; -// } - //不包含目标库位库存 - if (dstLoc != null) { - locHql += " AND inventory.location.id <> " + dstLoc.getId(); - } - //按包装分配库存 - if (pickItemRule.getPackageLineNo() != 0) { - locHql += " AND inventory.packageUnit.lineNO = " + pickItemRule.getPackageLineNo(); - } - //按SOI分配库存 - if (!StringUtils.isEmpty(moveDocDetail.getSOI())) { - locHql += " AND inventory.SOI = '" + moveDocDetail.getSOI() + "'"; - } - - StringBuffer sb = new StringBuffer(); - String hql =sb.append("SELECT new com.dev.swms.server.service.picking.allocate.InventoryWrap(inventory) FROM Inventory inventory ") - .append("WHERE inventory.itemKeyInventory.warehouse.id=:warehouseId ") - .append("AND inventory.itemKeyInventory.itemKey.item.id = :itemId") -// .append(" AND (") -// .append(NewLotInfoParser.decryptStringOfLot("propC1",lotInfo.getPropC1())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC2",lotInfo.getPropC2())) - .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC3",lotInfo.getPropC3())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC4",lotInfo.getPropC4())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC5",lotInfo.getPropC5())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC6",lotInfo.getPropC6())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC7",lotInfo.getPropC7())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC8",lotInfo.getPropC8())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC9",lotInfo.getPropC9())) -// .append(" AND ").append(NewLotInfoParser.decryptDoubleOfLot("propN1",lotInfo.getPropN1())) -// .append(" AND ").append(NewLotInfoParser.decryptDoubleOfLot("propN2",lotInfo.getPropN2())) -// .append(" AND ").append(NewLotInfoParser.decryptDoubleOfLot("propN3",lotInfo.getPropN3())) -// .append(" AND ").append(NewLotInfoParser.decryptDateOfLot("propD1",lotInfo.getPropD1())) -// .append(" AND ").append(NewLotInfoParser.decryptDateOfLot("propD2",lotInfo.getPropD2())) -// .append(" AND ").append(NewLotInfoParser.decryptDateOfLot("propD3",lotInfo.getPropD3())) -// .append(" AND ").append(NewLotInfoParser.decryptLongStringOfLot("propLC1",lotInfo.getPropL1())) -// .append(" AND ").append(NewLotInfoParser.decryptLongStringOfLot("propLC2",lotInfo.getPropL2())) -// .append(" AND ").append(NewLotInfoParser.decryptLongStringOfLot("propLC3",lotInfo.getPropL3())) -// .append(" ) ") - .append(" AND (inventory.status is null or inventory.status = '' or inventory.status = '非破损')") - .append(" AND (inventory.location.countLock is null or inventory.location.countLock = '')") - .append(" AND (inventory.location.outLock is null or inventory.location.outLock = '')") - .append(" AND (inventory.qtyOfMasterPack - inventory.queuedQuantity) > 0") - .append(" AND inventory.location.type in ("+loc+")") - .append(locHql) - .toString(); - - if(lotInfo.getPropD1()!=null&& !lotInfo.getPropD1().equals("")){ - hql+=" and CONVERT(varchar(100), inventory.itemKeyInventory.itemKey.lotInfo.propD1, 23)='"+lotInfo.getPropD1()+"'"; - } - if(loc_code!=null){ - hql+=" and inventory.location.code ='"+loc_code+"'"; - } - if(moveDocDetail instanceof WaveDocDetail){ - hql+=" and inventory.location.code !='"+moveDocDetail.getItem().getLocation().getCode()+"'"; - } - hql+=" order by inventory.location.type desc"; - tempInventories.addAll(this.commonDao.findByQuery(hql, - new String[] {"warehouseId", "itemId"}, - new Object[] {warehouse.getId(), item.getId()})); - String turnOverMode = null; //库存周转方式 - if(moveDocDetail instanceof WaveDocDetail){ - if(((WaveDocDetail)moveDocDetail).getWaveDoc().getTurnOverMode()!= null){ - turnOverMode = ((WaveDocDetail)moveDocDetail).getWaveDoc().getTurnOverMode(); - } - }else if(moveDocDetail instanceof PickTicketDetail){ - Structure customer = ((PickTicketDetail)moveDocDetail).getPickTicket().getCustomer(); - if(customer!=null&&customer.getCustomerTurnOverMode()!= null){ - turnOverMode = customer.getCustomerTurnOverMode(); - } - } - if(turnOverMode==null && company.getCompanyTurnOverMode() != null){ - turnOverMode = company.getCompanyTurnOverMode(); - } - - if (tempInventories.size()>0) { - Map> map=sortByRule(tempInventories,moveDocDetail.getItem().getWarehouseItemStorageRule(), pickItemRule,turnOverMode); - List inventories = map.get("CA"); -// List inventorieBHs = map.get("BH");// - //List inventories =sortByRule(tempInventories,moveDocDetail.getItem().getWarehouseItemStorageRule(), pickItemRule,turnOverMode); - //tempInventories.clear(); -// for(Inventory inv:inventories){ -// logger.info(inv.getId()+"===="+inv.getAvaliableQuantity()); -// } - //拣货分配,累加已分配数量 - totalQty += allocateInventory(inventories, moveDocDetail); - - - - }else{ - errmsg += "[" + pickItemRule.getSortIndex() + "]拣货规则无匹配库存;"; - } - - if((moveDocDetail.getPreAllocatedQuantity()-moveDocDetail.getAllocatedQuantity())<=0){ - break; - }else{ - logger.info(moveDocDetail.getItem()+"===="+moveDocDetail.getAllocatedQuantity()); - } - } - - if (moveDocDetail.getUnallocateQuantity() > 0 - && moveDocDetail.getItem().getPackageUnitByLineNo(2) != null - && moveDocDetail.getPackageUnit().getLineNO() == 1 - && company.isBatchPickingSupply()) { - //货主允许批量拣货补货,分配数量不足,货品有大包装,且发货单明细中的包装为基本包装时,自动产生补货计划 - replDetails.add(moveDocDetail); - } - } - -// if (isPickingAllocate && replDetails.size() > 0) { -// createSupplyDoc(warehouse, company, replDetails); -// } - - return errmsg; - } - - - /** - * 拣货分配过程 - * @param moveDocDetails - */ - @SuppressWarnings("unchecked") - private String allocateInventoryForPick(AbstractMoveDocDetail moveDocDetail) { - String errmsg = ""; - Warehouse warehouse = null; -// for(AbstractMoveDocDetail moveDocDetail : moveDocDetails){ - String loc="'RECEIVE','SHIP','收货','发货'"; - if (warehouse == null) { - warehouse = moveDocDetail.getAbstractMoveDoc().getWarehouse(); - } - //如果发货单明细无未分配数量,则忽略 - if (moveDocDetail.getUnallocateQuantity() <= 0) { - return null; - } - List tempInventories = new ArrayList(); - double totalQty = 0.0; - Item item = moveDocDetail.getItem(); - NewLotInfo lotInfo = moveDocDetail.getNewLotInfo() == null ? new NewLotInfo() : moveDocDetail.getNewLotInfo(); - StringBuffer sb = new StringBuffer(); - String hql =sb.append("SELECT new com.dev.swms.server.service.picking.allocate.InventoryWrap(inventory) FROM Inventory inventory ") - .append("WHERE inventory.itemKey.item.id = :itemId") -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC1",lotInfo.getPropC1())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC2",lotInfo.getPropC2())) -// .append(" AND ").append(NewLotInfoParser.decryptDateOfLot("propD1",lotInfo.getPropD1())) -// .append(" AND ").append(NewLotInfoParser.decryptLongStringOfLot("propLC1",lotInfo.getPropL1())) -// .append(" ) ") - .append(" AND (inventory.status is null or inventory.status = '' or inventory.status = '已入库')") - .append(" AND (inventory.location.countLock is null or inventory.location.countLock = '')") - .append(" AND (inventory.location.outLock is null or inventory.location.outLock = '')") - .append(" AND (inventory.qtyOfMasterPack - inventory.queuedQuantity) > 0") - .append(" AND (inventory.counPlan is null or inventory.counPlan = '')") - .append(" AND inventory.location.type not in ("+loc+")") - .toString(); - if(lotInfo!=null) { - if(lotInfo.getPropC2()!=null&&!lotInfo.getPropC2().equals("")) { - hql+=" and inventory.itemKey.lotInfo.propC2='"+lotInfo.getPropC2()+"'"; - } - if(lotInfo.getPropC3()!=null&&!lotInfo.getPropC3().equals("")) { - hql+=" and inventory.itemKey.lotInfo.propC3='"+lotInfo.getPropC3()+"'"; - } - if(lotInfo.getPropC5()!=null&&!lotInfo.getPropC5().equals("")) { - hql+=" and inventory.itemKey.lotInfo.propC5='"+lotInfo.getPropC5()+"'"; - } - } - hql+=" order by inventory.itemKey.lotInfo.propD2 asc, "; - if(item.isSingleItem()) { - hql+=" inventory.itemKey.lotInfo.propC3 asc,"; - } - hql+=" inventory.storageDate asc ,inventory.location.zone.code asc,inventory.location.code asc,(inventory.quantity -inventory.queuedQuantity) asc"; - tempInventories.addAll(this.commonDao.findByQuery(hql, - new String[] {"itemId"}, new Object[] {item.getId()})); - if (tempInventories.size()>0) { - List inventories=new ArrayList(); - for(InventoryWrap inv:tempInventories){ - inventories.add(inv.getInventory()); - } - //拣货分配,累加已分配数量 - totalQty += allocateInventory(inventories, moveDocDetail); - } - if((DoubleUtils.format4F(moveDocDetail.getPreAllocatedQuantity())-DoubleUtils.format4F(moveDocDetail.getAllocatedQuantity()))<=0){ - return null; - }else{ - logger.info(moveDocDetail.getItem()+"===="+moveDocDetail.getAllocatedQuantity()); - } -// } - return errmsg; - } - - /** - * getPickItemRuleForPickTicket需要传入的参数中,pickQuantityMinPU是最小单位数量,pickQuantity为当前包装单位数量 - * 筛选捡货规则的时候,如果规则和包装单位有关,则规则的最小最大捡货数量是对应规则相关包装单位的数量; - * 如果规则和包装单位无关,则规则的最小最大捡货数量对应最小包装数量 - */ - @SuppressWarnings("unchecked") - public List getPickItemRules(Structure company,BillType billType,String itemPickType, - Item item,PackageUnit packageUnit,LotInfo lotInfo,double quantity,String abcType){ - Long billTypeId = null; - if(billType!=null) - billTypeId = billType.getId(); - - List pickItemRules = this.commonDao.findByNamedQuery("getPickItemRuleForPickTicket", - new String[]{"warehouseId","companyId","billTypeId","itemPickType","itemId","packageLineNo", - "itemBigType","itemMiddleType","itemLittleType","pickQuantityMinPU","pickQuantity","abcType"}, - new Object[]{WarehouseHolder.getWarehouse().getId(),company.getId(), - billTypeId, - itemPickType, - item.getId(), - packageUnit.getLineNO(), - item.getLargeClass(), - item.getCenterClass(), - item.getSmallClass(), - quantity, - DoubleUtils.formatByPrecision(quantity/packageUnit.getConvertFigure(), packageUnit.getPrecision()), - abcType}); - - return pickItemRules; - } - - /** - * @param inventories - * @param relateProperties - * @return - */ - @SuppressWarnings("unchecked") - private Map> sortByRule(List inventoryWraps, ItemStorageRule storageRule, PickItemRule pickItemRule,String turnOverMode) { - //收集排序规则 - List sortRules = new ArrayList(); - sortRules.add(new SortRule(1, "locationType", "desc")); - //先按照库存周转排序 - if(turnOverMode != null){ - if (TurnOverMode.FIFO_STORAGEDATE.equals(turnOverMode)) { - sortRules.add(new SortRule(2, "storageDate", "ASC")); - } else if (TurnOverMode.LIFO_STORAGEDATE.equals(turnOverMode)) { - sortRules.add(new SortRule(2, "storageDate", "DESC")); - } else if (TurnOverMode.FIFO_VALIDDATE.equals(turnOverMode)) { - sortRules.add(new SortRule(2, "expireDate", "ASC")); - } else if (TurnOverMode.LIFO_VALIDDATE.equals(turnOverMode)) { - sortRules.add(new SortRule(2, "expireDate", "DESC")); - } - } - - //按照库位状态排序,拣、空、存 - if(PickMethod.PICK_STORE.equals(pickItemRule.getPickMethod())){ - sortRules.add(new SortRule(3, "locationStatus", "DESC")); - }else{ - sortRules.add(new SortRule(3, "locationStatus", "ASC")); - } - //如果货主允许拆托分配,则分配托盘库存时托盘库存数量从小到大分配(托盘被过多的拆托);如果不允许拆托,则数量从大到小排列(避免错误的分配不足) - if(pickItemRule.getCompany().isBeAllowedSplitLPForAllocate()){ - sortRules.add(new SortRule(4, "avaliableQuantity", "ASC")); - }else{ - sortRules.add(new SortRule(4, "avaliableQuantity", "DESC")); - } - //参考库位编号顺序排列,保证一个库位的库存在一起 - sortRules.add(new SortRule(5, "locationCode", "ASC")); - //将托盘库存和非托盘库存分开排序,由于lpIndex为字符串,排序结果是:'','1','2','3',...[非托盘在前,托盘在后,托盘按照排序号依次排列] - sortRules.add(new SortRule(6, "lpIndex", "ASC")); - //将大包装放前面 - sortRules.add(new SortRule(7, "convertFigure", "DESC")); - - //构造排序Chain - ComparatorChain chain = new ComparatorChain(); - for (SortRule sortRule : sortRules) { - if (sortRule.getSortMethod().equals("DESC")) { - chain.addComparator(new ReverseComparator(new BeanComparator(sortRule.getSortKey()))); - } else { - chain.addComparator(new BeanComparator(sortRule.getSortKey())); - } - } - - //排序处理 - Collections.sort(inventoryWraps,chain); - - /** - * a、库位上有整托和非整托时,如果待拣数量大于整托,则先分配整托; - * b、库位上有非整托时,如果待拣数量不够整托,先分配非整托; - * c、库位上托盘分配后,如果分配数量仍不足,则查找非托盘散货(inventory中lp为''的库存记录),按包装大小顺序分配; - */ - //将托盘库存排到非托盘库存前 - List tempInvs1 = new ArrayList(); - List tempInvs2 = new ArrayList(); - - List tempInvsBH1 = new ArrayList(); - List tempInvsBH2 = new ArrayList(); - for(InventoryWrap inventoryWrap : inventoryWraps){ - if(inventoryWrap.getInventory().getLP() == null){ -// if(bh&&inventoryWrap.getInventory().getLocation().getType().equals(LocationType.TRANSIT)){ -// tempInvsBH2.add(inventoryWrap.getInventory()); -// }else{ - tempInvs2.add(inventoryWrap.getInventory()); -// } - }else{ -// if(bh&&inventoryWrap.getInventory().getLocation().getType().equals(LocationType.TRANSIT)){ -// tempInvsBH1.add(inventoryWrap.getInventory()); -// }else{ - tempInvs1.add(inventoryWrap.getInventory()); -// } - } - } - tempInvs1.addAll(tempInvs2); - tempInvsBH1.addAll(tempInvsBH2); - Map> maps=new HashMap>(); - maps.put("CA", tempInvs1); - maps.put("BH", tempInvsBH1); - return maps; - } - - public String preAllocatePO(List pickTicketId) { - Collection pickTicketDetails=new ArrayList(); - /*pickTicketDetails=commonDao.findByQuery(" from PickTicketDetail ptd where CONVERT(VARCHAR(10),ptd.pickTicket.orderDate,120)='"+DateUtil.formatDateYMDToStr(new Date())+"' " - + "and ptd.pickTicket.billType.code='GD' order by ptd.pickTicket.id,ptd.id");*/ - pickTicketDetails=commonDao.findByQuery(" from PickTicketDetail ptd where ptd.pickTicket.id in ("+StringUtils.strip(pickTicketId.toString(),"[]")+") " - + "and ptd.pickTicket.billType.code in('GPUTPTC') order by ptd.pickTicket.id,ptd.id"); - if(pickTicketDetails.size()>0) { - logger.info(pickTicketDetails.size()+" 行数!"); - preAllocate(pickTicketDetails); - }else { - logger.info("今天无工单出库出库信息!"); - } - return ""; - } - public void preAllocate(Collection pickTicketDetails) { - for(PickTicketDetail pickTicketDetail : pickTicketDetails){ - if (pickTicketDetail.getOrderQuantity()- pickTicketDetail.getAllocatedQuantity()> 0) { - preAllocate(pickTicketDetail, pickTicketDetail.getOrderQuantity()- pickTicketDetail.getAllocatedQuantity(),"3"); - } - } - } - - - @SuppressWarnings("unchecked") - public void preAllocate(PickTicketDetail pickTicketDetail, Double quantity,String type) { - Warehouse warehouse = pickTicketDetail.getAbstractMoveDoc().getWarehouse(); - Item item = pickTicketDetail.getItem(); - NewLotInfo lotInfo = pickTicketDetail.getNewLotInfo() == null ? new NewLotInfo() : pickTicketDetail.getNewLotInfo(); - itemManager.formatNewLotInfo(lotInfo); - String lot = ""; - String code = pickTicketDetail.getCode(); - String loc=""; - Long zone=null; - if(type.equals("1")){ - loc="'TRANSIT'"; - }else if(type.equals("2")){ - loc="'STORAGE','TRANSIT'"; - }else if(type.equals("3")){ - loc="'STORAGE','TRANSIT','READY','存货','料箱','备货'"; - } - //批次属性匹配(是否按照批次属性严格匹配) - StringBuffer sb = new StringBuffer(); - String hql =sb.append("SELECT new com.dev.swms.server.model.shipping.LotQuantity(inventory.itemKey.lot,") - .append("SUM(inventory.qtyOfMasterPack),inventory.warehouseArea.id ) ") - .append("FROM Inventory inventory ") - .append("WHERE inventory.warehouse.id = :warehouseId ") - .append(" AND inventory.itemKey.item.id = :itemId") -// .append(" AND (" ) -// .append(NewLotInfoParser.decryptStringOfLot("propC1",lotInfo.getPropC1())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC2",lotInfo.getPropC2())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC3",lotInfo.getPropC3())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC4",lotInfo.getPropC4())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC5",lotInfo.getPropC5())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC6",lotInfo.getPropC6())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC7",lotInfo.getPropC7())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC8",lotInfo.getPropC8())) -// .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC9",lotInfo.getPropC9())) -// .append(" AND ").append(NewLotInfoParser.decryptDoubleOfLot("propN1",lotInfo.getPropN1())) -// .append(" AND ").append(NewLotInfoParser.decryptDoubleOfLot("propN2",lotInfo.getPropN2())) -// .append(" AND ").append(NewLotInfoParser.decryptDoubleOfLot("propN3",lotInfo.getPropN3())) -// .append(" AND ").append(NewLotInfoParser.decryptDateOfLot("propD1",lotInfo.getPropD1())) -// .append(" AND ").append(NewLotInfoParser.decryptDateOfLot("propD2",lotInfo.getPropD2())) -// .append(" AND ").append(NewLotInfoParser.decryptDateOfLot("propD3",lotInfo.getPropD3())) -// .append(" AND ").append(NewLotInfoParser.decryptLongStringOfLot("propLC1",lotInfo.getPropL1())) -// .append(" AND ").append(NewLotInfoParser.decryptLongStringOfLot("propLC2",lotInfo.getPropL2())) -// .append(" AND ").append(NewLotInfoParser.decryptLongStringOfLot("propLC3",lotInfo.getPropL3())) -// .append(" ) ") - .append(" AND (inventory.status is null or inventory.status = '' or inventory.status = '已入库') ") - .append(" AND (inventory.location.countLock is null or inventory.location.countLock = '')") - .append(" AND (inventory.location.outLock is null or inventory.location.outLock = '')") - .append(" AND inventory.location.type IN ("+loc+") ") - .append(" GROUP BY inventory.itemKey.lot,inventory.warehouseArea.id") - .append(" ORDER BY SUM(inventory.qtyOfMasterPack) DESC").toString(); - - List results = this.commonDao.findByQuery(hql, - new String[] {"warehouseId", "itemId"}, - new Object[] {warehouse.getId(), item.getId()}); - - Double inventoryQty = 0D; - if (results != null && results.size() > 0) { - //提取批次号并计算可预分配库存总数量 - for (int i=0;i inventoryQty) { - quantity = (inventoryQty - preAllocatedQty); - //如果可预分配数量小于0,返回错误信息 - if (quantity <= 0) { - return; - } - } - //检查预分配数量 - - //检查是否有重复的预分配记录 - PreAllocate preAllocate = (PreAllocate) this.commonDao.findByNamedQueryUniqueResult("getPreAllocateByUK", new String[] {"code", "warehouseId", "itemId", "lot","zoneId"}, new Object[] {code, warehouse.getId(), item.getId(), lot,zone}); - if (preAllocate == null) { - preAllocate = EntityFactory.getEntity(PreAllocate.class); - preAllocate.setCode(code); - preAllocate.setWarehouse(warehouse); - preAllocate.setItem(pickTicketDetail.getItem()); - preAllocate.setLot(lot); - preAllocate.setZone(commonDao.load(WarehouseArea.class, zone)); - preAllocate.setOrderDate(pickTicketDetail.getPickTicket().getOrderDate()); - } - preAllocate.preAllocate(quantity); - this.commonDao.store(preAllocate); - -// pickTicketDetail.preAllocate(lot, quantity); - } - - - public void unPreAllocate(Collection pickTicketDetails) { - for(PickTicketDetail pickTicketDetail : pickTicketDetails){ - unPreAllocate(pickTicketDetail, pickTicketDetail.getUnallocateQuantity()); - } - } - - public void unPreAllocate(PickTicketDetail pickTicketDetail, Double quantity) { - Warehouse warehouse = pickTicketDetail.getAbstractMoveDoc().getWarehouse(); - Item item = pickTicketDetail.getItem(); - String lot = pickTicketDetail.getPreAllocatedLot(); - String code = pickTicketDetail.getCode(); - Double unPreAllocateQty = (pickTicketDetail.getPreAllocatedQuantity() - pickTicketDetail.getAllocatedQuantity()); - if (quantity == 0) { - return; - } - if (quantity > unPreAllocateQty) { - throw new BusinessException("unPreAlloate.quantity.error"); - } - //发货单明细取消预分配 - pickTicketDetail.unPreAllocate(quantity); - //修改预分配表 - PreAllocate preAllocate = (PreAllocate) this.commonDao.findByNamedQueryUniqueResult("getPreAllocateByUK", new String[] {"code", "warehouseId", "itemId", "lot"}, new Object[] {code, warehouse.getId(), item.getId(), lot}); - if (preAllocate == null) { - throw new BusinessException("preAllocate.match.none"); - } else { - //如果取消预分配后记录的预分配数量为0,则删除该预分配记录 - preAllocate.unPreAllocate(quantity); - if (preAllocate.getPreAllocatedQuantity() == 0) { - this.commonDao.delete(preAllocate); - } - } - } - - public void unallocate(AbstractMoveDoc moveDoc) { - warehouseId = WarehouseHolder.getWarehouse().getId().longValue(); - synchronized (warehouseId) { - for(AbstractMoveDocDetail detail : moveDoc.getAbstractMoveDocDetails()){ - String barCode=null; - List ts = new ArrayList(); - for (Task task: detail.getTasks()) { - if(TaskType.MV_CROSS.equals(task.getType())){ - continue; - } -// barCode=task.getItemKey().getLotInfo().getPropC9(); - double quantity = task.getPlanQuantityMU() - task.getMovedQuantityMU(); - if (quantity == 0) { - ts.add(task); - continue; - } - if (moveDoc instanceof PickTicket) { - task.unallocatePick(quantity); - } else if(moveDoc instanceof WaveDoc){ - task.unallocateWaveDoc(quantity); - }else if(moveDoc instanceof ProcessDoc){ - task.unallocateProcessDoc(quantity); - }else{ - task.unallocateMove(quantity); - } - - ItemKey ik = task.getItemKey(); - Inventory inventory = ik.getInventory(task.getSrcLoc(),ik.getItem(), task.getPackageUnit(), task.getSrcLP(), - barCode, task.getStorageDate(), task.getSOI(),task.getWarehouseArea(),task.getBarCode()); - if (inventory == null) { - throw new BusinessException("inventory.not.found"); - } - inventory.unallocate(quantity, null, null); - if (task.getPlanQuantityMU()== 0) { - ts.add(task); - } - } - detail.getTasks().removeAll(ts); - } - } - } - - - @SuppressWarnings("unchecked") - public void preAllocate(ProcessDocBOMDetail bomDetail, Double quantity) { - Warehouse warehouse = bomDetail.getAbstractMoveDoc().getWarehouse(); - Item item = bomDetail.getItem(); - NewLotInfo lotInfo = bomDetail.getNewLotInfo() == null ? new NewLotInfo() : bomDetail.getNewLotInfo(); - itemManager.formatNewLotInfo(lotInfo); - String lot = ""; - String code = bomDetail.getAbstractMoveDoc().getCode(); - - //批次属性匹配(是否按照批次属性严格匹配) - - StringBuffer sb = new StringBuffer(); - String hql =sb.append("SELECT new com.dev.swms.server.model.shipping.LotQuantity(inventory.itemKeyInventory.itemKey.lot,") - .append("SUM(inventory.qtyOfMasterPack)) ") - .append("FROM Inventory inventory ") - .append("WHERE inventory.itemKeyInventory.warehouse.id = :warehouseId ") - .append(" AND inventory.itemKeyInventory.itemKey.item.id = :itemId") - .append(" AND (" ) - .append(NewLotInfoParser.decryptStringOfLot("propC1",lotInfo.getPropC1())) - .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC2",lotInfo.getPropC2())) - .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC3",lotInfo.getPropC3())) - .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC4",lotInfo.getPropC4())) - .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC5",lotInfo.getPropC5())) - .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC6",lotInfo.getPropC6())) - .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC7",lotInfo.getPropC7())) - .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC8",lotInfo.getPropC8())) - .append(" AND ").append(NewLotInfoParser.decryptStringOfLot("propC9",lotInfo.getPropC9())) - .append(" AND ").append(NewLotInfoParser.decryptDoubleOfLot("propN1",lotInfo.getPropN1())) - .append(" AND ").append(NewLotInfoParser.decryptDoubleOfLot("propN2",lotInfo.getPropN2())) - .append(" AND ").append(NewLotInfoParser.decryptDoubleOfLot("propN3",lotInfo.getPropN3())) - .append(" AND ").append(NewLotInfoParser.decryptDateOfLot("propD1",lotInfo.getPropD1())) - .append(" AND ").append(NewLotInfoParser.decryptDateOfLot("propD2",lotInfo.getPropD2())) - .append(" AND ").append(NewLotInfoParser.decryptDateOfLot("propD3",lotInfo.getPropD3())) - .append(" AND ").append(NewLotInfoParser.decryptLongStringOfLot("propLC1",lotInfo.getPropL1())) - .append(" AND ").append(NewLotInfoParser.decryptLongStringOfLot("propLC2",lotInfo.getPropL2())) - .append(" AND ").append(NewLotInfoParser.decryptLongStringOfLot("propLC3",lotInfo.getPropL3())) - .append(" ) ") - .append(" AND (inventory.status is null or inventory.status = '')") - .append(" AND (inventory.location.countLock is null or inventory.location.countLock = '')") - .append(" AND (inventory.location.outLock is null or inventory.location.outLock = '')") - .append(" AND inventory.location.type IN ('STORAGE','SHIP','READY') ") - .append(" GROUP BY inventory.itemKeyInventory.itemKey.lot") - .append(" ORDER BY SUM(inventory.qtyOfMasterPack) DESC").toString(); - - List results = this.commonDao.findByQuery(hql, - new String[] {"warehouseId", "itemId"}, - new Object[] {warehouse.getId(), item.getId()}); - - Double inventoryQty = 0D; - if (results != null && results.size() > 0) { - //提取批次号并计算可预分配库存总数量 - for (int i=0;i inventoryQty) { - quantity = (inventoryQty - preAllocatedQty); - //如果可预分配数量小于0,返回错误信息 - if (quantity <= 0) { - return; - } - } - //检查预分配数量 - - //检查是否有重复的预分配记录 - PreAllocate preAllocate = (PreAllocate) this.commonDao.findByNamedQueryUniqueResult("getPreAllocateByUK", new String[] {"code", "warehouseId", "itemId", "lot"}, new Object[] {code, warehouse.getId(), item.getId(), lot}); - if (preAllocate == null) { - preAllocate = EntityFactory.getEntity(PreAllocate.class); - preAllocate.setCode(code); - preAllocate.setWarehouse(warehouse); - preAllocate.setItem(bomDetail.getItem()); - preAllocate.setLot(lot); - } - preAllocate.preAllocate(quantity); - this.commonDao.store(preAllocate); - - bomDetail.preAllocate(lot, quantity); - } - - - public void unPreAllocate(ProcessDocBOMDetail bomDetail, Double quantity) { - Warehouse warehouse = bomDetail.getAbstractMoveDoc().getWarehouse(); - Item item = bomDetail.getItem(); - String lot = bomDetail.getPreAllocatedLot(); - String code = bomDetail.getCode(); - Double unPreAllocateQty = (bomDetail.getPreAllocatedQuantity() - bomDetail.getAllocatedQuantity()); - if (quantity == 0) { - return; - } - if (quantity > unPreAllocateQty) { - throw new BusinessException("unPreAlloate.quantity.error"); - } - //发货单明细取消预分配 - bomDetail.unPreAllocate(quantity); - //修改预分配表 - PreAllocate preAllocate = (PreAllocate) this.commonDao.findByNamedQueryUniqueResult("getPreAllocateByUK", new String[] {"code", "warehouseId", "itemId", "lot"}, new Object[] {code, warehouse.getId(), item.getId(), lot}); - if (preAllocate == null) { - throw new BusinessException("preAllocate.match.none"); - } else { - //如果取消预分配后记录的预分配数量为0,则删除该预分配记录 - preAllocate.unPreAllocate(quantity); - if (preAllocate.getPreAllocatedQuantity() == 0) { - this.commonDao.delete(preAllocate); - } - } - } - - @SuppressWarnings("unchecked") - public void manualAllocate(AbstractMoveDocDetail moveDocDetail, Map inventories) { - AbstractMoveDoc pickTicket = moveDocDetail.getAbstractMoveDoc(); - Double unallocateQty = moveDocDetail.getUnallocateQuantity(); - if (unallocateQty <= 0) { - return; - } - for (Object obj : inventories.keySet()) { - Inventory inventory = commonDao.load(Inventory.class, (Long) obj); - Double quantity = Double.valueOf(inventories.get(obj).toString()); - if(quantity <= 0){ - continue; - } - - //待分配数量(转换为基本单位数量) - quantity = quantity*inventory.getPackageUnit().getConvertFigure(); - if (quantity > inventory.getAvaliableQuantity()) { - quantity = inventory.getAvaliableQuantity(); - } - - if (quantity > unallocateQty) { - quantity = unallocateQty; - } - unallocateQty -= quantity; - - - pickTicket.allocate(moveDocDetail, inventory, quantity); - inventory.allocate(quantity, null, null); - - if (unallocateQty <= 0) { - return; - } - } - } - - public String allocate(Long pickTicketId, Long waveDocId, Long moveDocId, - Collection details) { - warehouseId = WarehouseHolder.getWarehouse().getId().longValue(); - synchronized (warehouseId) { - String errorMsg = ""; - if (pickTicketId != null) { - String applyCode = ""; - Structure company = null; - PickTicket pickTicket = commonDao.load(PickTicket.class, pickTicketId); - if ((PickTicketStatus.PREALLOCATE.equals(pickTicket.getStatus()) - || (PickTicketStatus.OPEN.equals(pickTicket.getStatus()))// && !pickTicket.getCompany().getCompanyWorkRule().isInvSubscribe()) - || PickTicketStatus.ALLOCATE.equals(pickTicket.getStatus()) - || PickTicketStatus.PICKUP.equals(pickTicket.getStatus()) - || PickTicketStatus.SHIP_PART.equals(pickTicket.getStatus())) - && pickTicket.getOrderQuantity() > pickTicket.getAllocatedQuantity()) { - errorMsg += allocate(pickTicket); - if (StringUtils.isEmpty(applyCode)) { - applyCode = pickTicket.getApplyDoc() == null ? "" : pickTicket.getApplyDoc(); - } - if (company == null) { - company = pickTicket.getCompany(); - } - } - if (StringUtils.isEmpty(applyCode)) { - updateMoveDocQuantiy(applyCode, warehouseId, company.getId()); - } - } else if (waveDocId != null) { - WaveDoc waveDoc = commonDao.load(WaveDoc.class, waveDocId); - if (WaveDocStatus.ACTIVE.equals(waveDoc.getStatus())||WaveDocStatus.ALLOCATE.equals(waveDoc.getStatus())||WaveDocStatus.OPEN.equals(waveDoc.getStatus())) { - if (waveDoc.getWaveDocDetails() != null || waveDoc.getWaveDocDetails().size() > 0) { - errorMsg += allocate(waveDoc); - } - } - } else if (moveDocId != null) { - MoveDoc moveDoc = commonDao.load(MoveDoc.class, moveDocId); - if (MoveDocStatus.OPEN.equals(moveDoc.getStatus())) { - errorMsg += allocate(moveDoc); - } - } else if (details != null) { - errorMsg += allocateInventoryForPickItemRule(details); - } - - return errorMsg; - } - } - - - public String allocateDetail(AbstractMoveDocDetail detail) { - String errorMsg = ""; - Long pickTicketId=detail.getAbstractMoveDoc().getId(); - if (pickTicketId != null) { - PickTicket pickTicket = commonDao.load(PickTicket.class, pickTicketId); - if ((PickTicketStatus.OPEN.equals(pickTicket.getStatus()) - || (PickTicketStatus.PREALLOCATE.equals(pickTicket.getStatus())) - || (PickTicketStatus.OPEN.equals(pickTicket.getStatus()))// && !pickTicket.getCompany().getCompanyWorkRule().isInvSubscribe()) - || PickTicketStatus.ALLOCATE.equals(pickTicket.getStatus()) - || PickTicketStatus.PICKUP.equals(pickTicket.getStatus()) - || PickTicketStatus.SHIP_PART.equals(pickTicket.getStatus())) - && pickTicket.getOrderQuantity() > pickTicket.getAllocatedQuantity()) { - String allocateInfo = allocateInventoryForPick(detail); - if (detail.getOrderQuantity() <= detail.getAllocatedQuantity()) { - //errorMsg += moveDoc.getCode() + "整单分配成功;"; - } else if (detail.getAllocatedQuantity()-detail.getPickedQuantity() > 0) { - errorMsg += pickTicket.getCode() + "部分分配成功[" + allocateInfo + "];"; - } else { - errorMsg += pickTicket.getCode() + "分配失败[" + allocateInfo + "];"; - } - } - } - return errorMsg; - } - - public String preAllocate(List pickTicketIds) { - String errorMsg = ""; - for(Long pickTicketId:pickTicketIds){ - if (pickTicketId != null) { - PickTicket pickTicket = commonDao.load(PickTicket.class, pickTicketId); - if (PickTicketStatus.OPEN.equals(pickTicket.getStatus()) - || PickTicketStatus.SHIP_PART.equals(pickTicket.getStatus())){ - //如果发货单的货主作业规则中是否预约发货=false,则不进行预分配,直接自动填写预分配数量 - if(!pickTicket.getCompany().getCompanyWorkRule().isInvSubscribe()){ - for(PickTicketDetail detail : pickTicket.getPickTicketDetails()){ - detail.setPreAllocatedQuantity(detail.getOrderQtyOfMasterUnit()); - } - }else{ - if (pickTicket.getPreAllocatedQuantity() 0) { - errorMsg += moveDoc.getCode() + "部分分配成功[" + allocateInfo + "];"; - } else { - errorMsg += moveDoc.getCode() + "分配失败[" + allocateInfo + "];"; - } - //}catch(Exception e){ - // e.printStackTrace(); - // errorMsg += moveDoc.getCode() + " 分配失败[" + e.getMessage() + "];"; - //} - return errorMsg; - } - - @SuppressWarnings("unchecked") - private void createSupplyDoc(Warehouse warehouse, Structure company, - List details) { - String hql = "FROM MoveDoc moveDoc WHERE moveDoc.status = 'OPEN' " + - "AND moveDoc.billType.code = '" + MoveDoc.MV_SUPPLY + - "' AND moveDoc.warehouse.id = " + - warehouse.getId()+" AND moveDoc.company.id = " + company.getId(); - - List moveDocs = commonDao.findByQuery(hql); - MoveDoc moveDoc = null; - if (moveDocs != null && moveDocs.size() > 0) { - moveDoc = moveDocs.get(0); - } else { - BillType billType = (BillType) this.commonDao - .findByNamedQueryUniqueResult("getBillTypeByCompanyAndCode", - new String[] { "companyId", "code" }, - new Object[] {company.getId(), MoveDoc.MV_SUPPLY }); - - moveDoc = new MoveDoc(); - moveDoc.setWarehouse(warehouse); - moveDoc.setStatus(MoveDocStatus.OPEN); - moveDoc.setCreateDate(new Date()); - moveDoc.setUserTracking(); - moveDoc.setCompany(company); - moveDoc.setCode(bussinessCodeManager.getCodeByBillType(billType,WarehouseHolder.getWarehouse().getId())); - //设置单据类型 - moveDoc.setBillType(billType); - } - - for (AbstractMoveDocDetail detail : details) { - // 得到具体商品的批次属性 - ItemKey itemKey = itemManager.getItemKey(new ItemKey( - "", detail.getItem(), new LotInfo(), null, null), Boolean.FALSE); - double quantity = detail.getUnallocateQuantity(); - - if (moveDoc.getDetails() == null) { - moveDoc.setDetails(new HashSet()); - } - - MoveDocDetail mdd = this.generateMoveDocDetail(moveDoc, null, null, - null, null, itemKey, detail.getNewLotInfo(), - itemKey.getItem().getPackageUnitByLineNo(2), quantity, - Inventory.STATUS_VALID, null, ""); - //更新单据及其明细上的补货标识(对应补货单号) - detail.setApplyDoc(moveDoc.getCode()); - detail.setApplyDocDetailId(mdd.getId()); - detail.getAbstractMoveDoc().setApplyDoc(moveDoc.getCode()); - } - commonDao.store(moveDoc); - } - - private MoveDocDetail generateMoveDocDetail(MoveDoc moveDoc, Location srcLoc, - Stock srcLP, Location dstLoc, Stock dstLP, ItemKey itemKey, NewLotInfo newLotInfo, - PackageUnit packageUnit, double quantity, String status, Date storageDate, String SOI) { - MoveDocDetail detail = EntityFactory.getEntity(MoveDocDetail.class); - detail.setMoveDoc(moveDoc); - detail.setItemKey(itemKey); - detail.setNewLotInfo(newLotInfo); - detail.setPackageUnit(packageUnit); - detail.setSrcLoc(srcLoc); - detail.setSrcLP(srcLP); - detail.setSrcLPCode(srcLP==null?null:srcLP.getLP()); - detail.setDstLoc(dstLoc); - detail.setDstLP(dstLP); - detail.setDstLPCode(dstLP==null?null:dstLP.getLP()); - detail.setInventoryStatus(status); - detail.setStorageDate(storageDate); - detail.setSOI(SOI); - for (MoveDocDetail o : moveDoc.getDetails()) { - if (o.equals(detail)) { - o.add(quantity); - return o; - } - } - - moveDoc.getDetails().add(detail); - detail.add(quantity); - commonDao.store(moveDoc); - commonDao.store(detail); - return detail; - } - - //------------------------------------------------------------------------------------------------------ - /**拣货分配算法: - * 1、未定义货主和收货人规则时,默认是不允许多发、允许拆托盘和包装; - 如果是混托且不拆托,不参与分配 - * 3、要整托、整包装、允许多发: - 直接分配,直到分配足够(不拆托、不拆包装) - * 4、要整托、整包装、不允许多发: - 检查待分配数量是否大于整托或者整包装数,只有大于等于的时候才分配; - * 5、整托、非整包装、允许多发 - 托盘整托直接分配;托盘分配不足时,对散货分配,允许拆包装分配,分够数量为止; - * 6、整托、非整包装、不允许多发 - 分配托盘库存数量小于等于待分配数量; - 托盘分配不足时,对散货分配,允许拆包装分配,分够数量为止 ------------------------------------------- - 先找整托数量小于等于待分配数量的托盘,数量不足时找散货,散货也不足时再拆托盘 - * 7、非整托、整包装、允许多发: - 如果整包装数量大于等于待分配数量,则允许分配整包装(不拆包装) - * 8、非整托、整包装、不允许多发 - 如果整包装数量小于等于待分配数量才分配,不允许拆包装 - * 9、非整托、非整包装、允许多发/不允许多发: - 分够为止 - - * 如果托盘是混托,且不允许拆托盘,则不能分配该库存 - * 如果是波次分配,则不允许多发 - */ - @SuppressWarnings("unchecked") - public double allocateInventory(Collection inventories, AbstractMoveDocDetail moveDocDetail) { - AbstractMoveDoc moveDoc = moveDocDetail.getAbstractMoveDoc(); - double totalPickQty = 0.0; - boolean isShipLimit = false;//是否允许多发 - -// if(moveDocDetail instanceof PickTicketDetail){ -// PickTicketDetail detail = (PickTicketDetail)moveDocDetail; -// if(detail.getPickTicket().getCustomer()!=null){ -// isShipLimit = detail.getPickTicket().getCustomer().isBeShipLimit(); -// } -// } else if (moveDocDetail instanceof ProcessDocBOMDetail) { -// //加工单允许多拣 -// isShipLimit = true; -// } - -// //不能拆托分配、不能拆包装分配 -// if(!moveDocDetail.getItem().getCompany().isBeAllowedSplitLPForAllocate() && !moveDocDetail.getItem().getCompany().isBeAllowedSplitPUForAllocate()){ -// totalPickQty = allocateInventoryYesYes(inventories,moveDocDetail,isShipLimit); -// } -// //不能拆托分配、能拆包装分配 -// if(!moveDocDetail.getItem().getCompany().isBeAllowedSplitLPForAllocate() && moveDocDetail.getItem().getCompany().isBeAllowedSplitPUForAllocate()){ -// totalPickQty = allocateInventoryYesNo(inventories,moveDocDetail,isShipLimit); -// } -// //能拆托分配、不能拆包装分配 -// if(moveDocDetail.getItem().getCompany().isBeAllowedSplitLPForAllocate() && !moveDocDetail.getItem().getCompany().isBeAllowedSplitPUForAllocate()){ - totalPickQty = allocateInventoryNoYes(inventories,moveDocDetail,isShipLimit); -// } -// //能拆托分配、能拆包装分配 -// if(moveDocDetail.getItem().getCompany().isBeAllowedSplitLPForAllocate() && moveDocDetail.getItem().getCompany().isBeAllowedSplitPUForAllocate()){ -// totalPickQty = allocateInventoryNoNo(inventories,moveDocDetail); -// } - - return totalPickQty; - } - - /** - * 3、要整托、整包装、允许多发: - 直接分配,直到分配足够(不拆托、不拆包装) - * 4、要整托、整包装、不允许多发: - 检查待分配数量是否大于整托或者整包装数,只有大于等于的时候才分配; - 如果允许多发,则先保存因为托盘数量大于待分配数量而跳过的托盘库存,在最后仍然没有分配完的情况下,在对跳过的库存进行分配 - * @param inventories - * @param moveDocDetail - * @param isShipLimit:是否允许多发 - * @return - */ - public double allocateInventoryYesYes(Collection inventories, AbstractMoveDocDetail moveDocDetail,boolean isShipLimit) { - AbstractMoveDoc moveDoc = moveDocDetail.getAbstractMoveDoc(); - double totalPickQty = 0.0; - List skipInventorys = new ArrayList(); - for(Inventory inventory : inventories){ - String errmsg = ""; - //TODO: 如果库存对应库位不是普通货架,当第一个托盘分配失败时,不能提取后面的托盘进行分配 - - if (inventory.getAvaliableQuantity() <= 0.0) { - continue; - } - if ((!StringUtils.isEmpty(inventory.getStatus())&&!inventory.getStatus().equals("非破损")) - || inventory.getLocation().bePickLock()) { - continue; - } - //判断库存包装与单据明细包装是否匹配 - //double quantity = 0; - //计算要分配的整包装数量 - //发货单 --- 是否允许多发 - double pickedQuantity = 0.0; - pickedQuantity = moveDocDetail.getUnallocateQuantity(); - if (pickedQuantity > 0) { - if (moveDocDetail instanceof MoveDocDetail - && ((MoveDocDetail) moveDocDetail).getDstLoc() == null) { - //如果补货计划没有指定目标库位,则需要同时做上架分配 - errmsg += putawayAllocator.allocateByDetailAndInventory((MoveDocDetail) moveDocDetail, inventory, pickedQuantity); - } else { -// if(inventory.getLP()!=null){ -// if(!isMixLP(inventories,inventory)){//如果不是混托,则任意拣货. -// if(pickedQuantity>=inventory.getAvaliableQuantity()){ -// pickedQuantity = inventory.getAvaliableQuantity();//如果拣货数量不满整托或者整个包装,则分配整托或者整个包装 -// inventory.allocate(pickedQuantity, null, null); -// moveDoc.allocate(moveDocDetail, inventory, pickedQuantity); -// totalPickQty += pickedQuantity; -// }else{ -// if(isShipLimit)//如果允许多发,则保存因为托盘数量过大而跳过的库存,用于再分配 -// skipInventorys.add(inventory); -// } -// } -// }else{ - pickedQuantity = getQuantityForPkg(pickedQuantity,inventory.getAvaliableQuantity()/inventory.getPackageUnit().getConvertFigure(),inventory.getPackageUnit(), isShipLimit); - if (moveDocDetail instanceof WaveDocDetail ){ - Item item=moveDocDetail.getItem(); - if(item.getSuggest()>0||item.getCompany().getCode().equals(CompanyCode.HLX)){ - double ca=moveDocDetail.getItem().getCAcoefficient()==null?1:moveDocDetail.getItem().getCAcoefficient(); - if(!item.getCompany().getCode().equals(CompanyCode.HLX)){ - ca=ca*item.getSuggest(); - } - if(inventory.getAvaliableQuantity()>ca){ - int xs=(int) Math.ceil(pickedQuantity/ca); - pickedQuantity=ca*xs; - if(pickedQuantity>inventory.getAvaliableQuantity()){ - pickedQuantity=inventory.getAvaliableQuantity(); - } - }else{ - pickedQuantity=inventory.getAvaliableQuantity(); - } - }else{ - pickedQuantity=inventory.getAvaliableQuantity(); - } - } - inventory.allocate(pickedQuantity, null, null); - moveDoc.allocate(moveDocDetail, inventory, pickedQuantity); - totalPickQty += pickedQuantity; -// } - } - } - if(moveDocDetail.getUnallocateQuantity() <= 0){ - return totalPickQty; - } - } - //如果允许多发,而且有库存跳过没有分配,并且没有分配够,则对跳过的库存进行再分配,必须是整托分配 - if(isShipLimit){ - for(Inventory inv:skipInventorys){ - double alloQty = 0.0; - alloQty = inv.getAvaliableQuantity(); - inv.allocate(alloQty, null, null); - moveDoc.allocate(moveDocDetail, inv, alloQty); - totalPickQty += alloQty; - if(moveDocDetail.getUnallocateQuantity() <= 0){ - return totalPickQty; - } - } - } - return totalPickQty; - } - /** - * 5、整托、非整包装、允许多发 - 托盘整托直接分配;托盘分配不足时,对散货分配,允许拆包装分配,分够数量为止; - * 6、整托、非整包装、不允许多发 - 分配托盘库存数量小于等于待分配数量; - 托盘分配不足时,对散货分配,允许拆包装分配,分够数量为止 - - 如果允许多发,则先保存因为托盘数量大于待分配数量而跳过的托盘库存,在最后仍然没有分配完的情况下,在对跳过的库存进行分配 - * @param inventories - * @param moveDocDetail - * @param isShipLimit:是否允许多发 - * @return - */ - public double allocateInventoryYesNo(Collection inventories, AbstractMoveDocDetail moveDocDetail,boolean isShipLimit) { - AbstractMoveDoc moveDoc = moveDocDetail.getAbstractMoveDoc(); - double totalPickQty = 0.0; - List skipInventorys = new ArrayList(); - String errmsg = ""; - for(Inventory inventory : inventories){ - //TODO: 如果库存对应库位不是普通货架,当第一个托盘分配失败时,不能提取后面的托盘进行分配 - double pickedQuantity = 0.0; - if (inventory.getAvaliableQuantity() <= 0.0) { - continue; - } - if (!StringUtils.isEmpty(inventory.getStatus()) - || inventory.getLocation().bePickLock()) { - continue; - } - //判断库存包装与单据明细包装是否匹配 - //double quantity = 0; - //计算要分配的整包装数量 - //发货单 --- 是否允许多发 - pickedQuantity = moveDocDetail.getUnallocateQuantity(); - - if (pickedQuantity > 0) { - if (moveDocDetail instanceof MoveDocDetail - && ((MoveDocDetail) moveDocDetail).getDstLoc() == null) { - //如果补货计划没有指定目标库位,则需要同时做上架分配 - errmsg += putawayAllocator.allocateByDetailAndInventory((MoveDocDetail) moveDocDetail, inventory, pickedQuantity); - } else { - if(inventory.getLP()!=null){ - if(!isMixLP(inventories,inventory)){//如果不是混托,则任意拣货. - if(inventory.getAvaliableQuantity()<=pickedQuantity){ - pickedQuantity = inventory.getAvaliableQuantity();//如果拣货数量不满整托或者整个包装,则分配整托或者整个包装 - inventory.allocate(pickedQuantity, null, null); - moveDoc.allocate(moveDocDetail, inventory, pickedQuantity); - totalPickQty += pickedQuantity; - }else{ - if(isShipLimit)//如果允许多发,则保存因为托盘数量过大而跳过的库存,用于再分配 - skipInventorys.add(inventory); - } - } - }else{ - if(pickedQuantity>=inventory.getAvaliableQuantity()){ - pickedQuantity = inventory.getAvaliableQuantity(); - } - inventory.allocate(pickedQuantity, null, null); - moveDoc.allocate(moveDocDetail, inventory, pickedQuantity); - totalPickQty += pickedQuantity; - } - } - } - if(moveDocDetail.getUnallocateQuantity() <= 0){ - return totalPickQty; - } - } - -// 如果允许多发,而且有库存跳过没有分配,并且没有分配够,则对跳过的库存进行再分配,必须是整托分配 - if(isShipLimit){ - for(Inventory inv:skipInventorys){ - inv.allocate(inv.getAvaliableQuantity(), null, null); - moveDoc.allocate(moveDocDetail, inv, inv.getAvaliableQuantity()); - totalPickQty += inv.getAvaliableQuantity(); - if(moveDocDetail.getUnallocateQuantity() <= 0){ - return totalPickQty; - } - } - } - return totalPickQty; - } - /** - *7、非整托、整包装、允许多发: - 如果整包装数量大于等于待分配数量,则允许分配整包装(不拆包装) - *8、非整托、整包装、不允许多发 - 如果整包装数量小于等于待分配数量才分配,不允许拆包装 - * @param inventories - * @param moveDocDetail - * @param isShipLimit:是否允许多发 - * @return - */ - public double allocateInventoryNoYes(Collection inventories, AbstractMoveDocDetail moveDocDetail, boolean isShipLimit) { - AbstractMoveDoc moveDoc = moveDocDetail.getAbstractMoveDoc(); - double totalPickQty = 0.0; - String errmsg = ""; - for(Inventory inventory : inventories){ - //TODO: 如果库存对应库位不是普通货架,当第一个托盘分配失败时,不能提取后面的托盘进行分配 - double pickedQuantity = 0.0; - if (inventory.getAvaliableQuantity() <= 0.0) { - continue; - } -// if (!StringUtils.isEmpty(inventory.getStatus()) -// || inventory.getLocation().isPickLock()) { -// continue; -// } - //判断库存包装与单据明细包装是否匹配 - //double quantity = 0; - //计算要分配的整包装数量 - //发货单 --- 是否允许多发 - pickedQuantity = moveDocDetail.getUnallocateQuantity(); - - if (pickedQuantity > 0) { - if (moveDocDetail instanceof MoveDocDetail - && ((MoveDocDetail) moveDocDetail).getDstLoc() == null) { - //如果补货计划没有指定目标库位,则需要同时做上架分配 - errmsg += putawayAllocator.allocateByDetailAndInventory((MoveDocDetail) moveDocDetail, inventory, pickedQuantity); - } else { - if(inventory.getLP()!=null){ - if(pickedQuantity>=inventory.getAvaliableQuantity()){ - pickedQuantity = inventory.getAvaliableQuantity(); - } - inventory.allocate(pickedQuantity, null, null); - moveDoc.allocate(moveDocDetail, inventory, pickedQuantity); - totalPickQty += pickedQuantity; - }else{ - pickedQuantity = getQuantityForPkg(pickedQuantity,inventory.getAvaliableQuantity(),inventory.getPackageUnit(), isShipLimit); - inventory.allocate(pickedQuantity, null, null); - moveDoc.allocate(moveDocDetail, inventory, pickedQuantity); - totalPickQty += pickedQuantity; - } - } - } - if(moveDocDetail.getUnallocateQuantity() <= 0){ - return totalPickQty; - } - } - return totalPickQty; - } - /** - *9、非整托、非整包装、允许多发/不允许多发: - 分够为止 - * @param inventories - * @param moveDocDetail - * @return - */ - public double allocateInventoryNoNo(Collection inventories, AbstractMoveDocDetail moveDocDetail) { - AbstractMoveDoc moveDoc = moveDocDetail.getAbstractMoveDoc(); - double totalPickQty = 0.0; - String errmsg = ""; - for(Inventory inventory : inventories){ - //TODO: 如果库存对应库位不是普通货架,当第一个托盘分配失败时,不能提取后面的托盘进行分配 - double pickedQuantity = 0.0; - if (inventory.getAvaliableQuantity() <= 0.0) { - continue; - } - if (!StringUtils.isEmpty(inventory.getStatus()) - || inventory.getLocation().bePickLock()) { - continue; - } - //判断库存包装与单据明细包装是否匹配 - //double quantity = 0; - //计算要分配的整包装数量 - //发货单 --- 是否允许多发 - pickedQuantity = moveDocDetail.getUnallocateQuantity(); - - if (pickedQuantity > 0) { - if (moveDocDetail instanceof MoveDocDetail - && ((MoveDocDetail) moveDocDetail).getDstLoc() == null) { - //如果补货计划没有指定目标库位,则需要同时做上架分配 - errmsg += putawayAllocator.allocateByDetailAndInventory((MoveDocDetail) moveDocDetail, inventory, pickedQuantity); - } else { - if(pickedQuantity>=inventory.getAvaliableQuantity()){ - pickedQuantity = inventory.getAvaliableQuantity(); - } - inventory.allocate(pickedQuantity, null, null); - moveDoc.allocate(moveDocDetail, inventory, pickedQuantity); - totalPickQty += pickedQuantity; - } - } - if(moveDocDetail.getUnallocateQuantity() <= 0){ - return totalPickQty; - } - } - return totalPickQty; - } - /** - * 检查库存inv的托盘是否是混托 - * @param inventories - * @param inv - * @return - */ - private boolean isMixLP(Collection inventories,Inventory inv){ - if(inv.getLP()==null) - return false; - for(Inventory tinv:inventories){ - if(inv.getId()!=tinv.getId() - && (tinv.getLP()!=null && inv.getLP().getId()==tinv.getLP().getId())){ - return true; - } - } - return false; - } - /** - * 当不允许拆包装的时候,取得库存上应该分配的数量; - * 例如:计划分配数量为85,单位为“个”,库存数量100,单位“箱”;每箱10个;则应该分配90个(9箱) - * @param orderQty:待分配数量(最小包装单位数量) - * @param invQty - * @param newUnit - * @param isSplit:true:允许多发;false: 不允许多发 - * @return - */ - private double getQuantityForPkg(double orderQty,double invQty,PackageUnit invUnit,boolean isSplit){ - if(isSplit){ - if(orderQty<=invQty){ - return orderQty; - }else{ - return invQty; - } - }else{ - if(orderQty<=invQty){ - return orderQty; - }else{ - return invQty; - } - } - } - public void unallocate(AbstractMoveDoc moveDoc,List details) { - warehouseId = WarehouseHolder.getWarehouse().getId().longValue(); - synchronized (warehouseId) { - for(AbstractMoveDocDetail detail : details){ - List ts = new ArrayList(); - for (Task task: detail.getTasks()) { - if(TaskType.MV_CROSS.equals(task.getType())){ - continue; - } - double quantity = task.getPlanQuantityMU() - task.getMovedQuantityMU(); - if (quantity == 0) { - ts.add(task); - continue; - } - - if (moveDoc instanceof PickTicket) { - task.unallocatePick(quantity); - } else if(moveDoc instanceof WaveDoc){ - task.unallocateWaveDoc(quantity); - }else if(moveDoc instanceof ProcessDoc){ - task.unallocateProcessDoc(quantity); - }else{ - task.unallocateMove(quantity); - } - ItemKeyInventory itemKeyInventory = inventoryManager.getItemKeyInventory( - task.getSrcLoc().getWarehouse(), task.getItemKey()); - Inventory inventory = itemKeyInventory.getInventoryWithException(task.getSrcLoc(), - task.getPackageUnit(), task.getSrcLP(),null, task.getInventoryStatus(), - task.getStorageDate(), task.getSOI()); - inventory.unallocate(quantity, null, null); - if (task.getPlanQuantityMU()== 0) { - ts.add(task); - } - } - detail.getTasks().removeAll(ts); - } - } - } - @Override - public void allocateWaveDoc(List WaveDocIds) {} - public void allocatePlanAll(List WaveDocIds) { - - //根据出库明细生成TASK任务 - List PickTicketDetails = commonDao.findByQuery(" from PickTicketDetail ptd where ptd.pickTicket.orderDate<=:id ", - new String[] { "id"},new Object[] {new Date()}); - if(PickTicketDetails.size()>0){ - for(PickTicketDetail ptd :PickTicketDetails){ - //分配库存 - List Inventorys = commonDao.findByQuery( - " from Inventory i where i.itemKey.item.id=:id and i.location.type='STORAGE' and i.quantity-i.queuedQuantity>0 " - +" order by i.itemKey.lotInfo.propC3,i.itemKey.lotInfo.propC1,i.quantity", - new String[] { "id" },new Object[] { ptd.getItem().getId() }); - if (Inventorys.size() > 0) { - double allocatedQuantity = 0; - double unQty = ptd.getOrderQuantity()- ptd.getAllocatedQuantity();//未分配数量 - double allocateQty=0; - for (Inventory inventory : Inventorys) { - int j = 0; - if (unQty == 0) { - break; - } - allocateQty = inventory.getQuantity()- inventory.getQueuedQuantity();//可分配数量 - if (allocateQty == 0) { - continue; - } - if (unQty < allocateQty) { - allocateQty = unQty; - } - j++; - inventory.setQueuedQuantity(inventory.getQueuedQuantity()+ allocateQty); - inventory.setVersion(inventory.getVersion()); - commonDao.store(inventory); - allocatedQuantity += allocateQty; - unQty -= allocateQty; - ptd.setAllocatedQuantity(ptd.getAllocatedQuantity()+ allocateQty); - commonDao.store(ptd); - - Task task = EntityFactory.getEntity(Task.class); - task.setPickTicketDetail(ptd); - - Item item=commonDao.load(Item.class, ptd.getItem().getId()); - task.setBillCode(getSubWorkOrer(ptd.getPickTicket().getCode(),inventory.getLocation().getZone(),item)); - - task.setCode(TimeNumberUtils.getTaskCode()); - task.setType(TaskType.MV_PICKTICKET); - task.setItemKey(inventory.getItemKey()); - task.setStorageDate(inventory.getStorageDate()); - task.setSrcLoc(inventory.getLocation()); - task.setSOI(inventory.getSOI()); - task.setPlanQuantity(allocateQty); - task.setPlanQuantityMU(allocateQty); - task.setInventoryStatus(inventory.getStatus()); - task.setCreateTime(new Date()); - task.setWarehouseArea(inventory.getWarehouseArea()); - commonDao.store(task); - } - - } else { - continue; - } - } - } - - - - } - public String getSubWorkOrer(String picktickCode,WarehouseArea warehouseArea,Item item){ - String code=""; - if(warehouseArea.getId()==1765) { - if(item.getGoodType()!=null&&item.getGoodType().equals("大件")) { - Long count= (Long) commonDao.findByQuery(" select max(t.id) from Task t where t.billCode like '"+picktickCode+"-%' and t.srcLoc.zone.id="+warehouseArea.getId()+ - " and t.planQuantity>t.movedQuantityMU and t.itemKey.item.goodType='大件' ").get(0); - if(count!=null&&count.longValue()>0){ - Task t=this.load(Task.class,count); - code=t.getBillCode(); - }else{ - code=bussinessCodeManager.getCodeForYmd(picktickCode+"-", 2); - } - }else { - Long count= (Long) commonDao.findByQuery(" select max(t.id) from Task t where t.billCode like '"+picktickCode+"-%' and t.srcLoc.zone.id="+warehouseArea.getId()+ - " and t.planQuantity>t.movedQuantityMU and t.itemKey.item.goodType<>'大件' ").get(0); - if(count!=null&&count.longValue()>0){ - Task t=this.load(Task.class,count); - code=t.getBillCode(); - }else{ - - code=bussinessCodeManager.getCodeForYmd(picktickCode+"-", 2); - } - } - }else { - Long count= (Long) commonDao.findByQuery(" select max(t.id) from Task t where t.billCode like '"+picktickCode+"-%' and t.srcLoc.zone.id="+warehouseArea.getId()+ - " and t.planQuantity>t.movedQuantityMU ").get(0); - if(count!=null&&count.longValue()>0){ - Task t=this.load(Task.class,count); - code=t.getBillCode(); - }else{ - - code=bussinessCodeManager.getCodeForYmd(picktickCode+"-", 2); - } - } - - return code; - } - - public void shauxinInvQty(long itemId){ - Item item=this.load(Item.class, itemId); - Double qty= (Double) commonDao.findByQuery("select COALESCE(sum(inv.quantity-inv.queuedQuantity),0) from Inventory inv where inv.itemKey.item.id=:id and inv.location.id!=42483 ", - new String[] { "id"},new Object[] {itemId}).get(0);//总数量 - Double mxqty= (Double) commonDao.findByQuery("select COALESCE(sum(ptd.orderQuantity-ptd.allocatedQuantity),0) from PickTicketDetail ptd where ptd.item.id=:id and ptd.orderQuantity!=ptd.allocatedQuantity ", - new String[] { "id"},new Object[] {itemId}).get(0); - double sjQty=qty-mxqty; - item.setMinimumStock(sjQty); - commonDao.store(item); - } - - - //电子标签初始化 - @Override - public void initializationLabel(long waveDocId){ - WaveDoc wd=commonDao.load(WaveDoc.class, waveDocId); - if(wd.isBePopular()==true){ - List bigTasks = commonDao.findByQuery(" from Task t where t.waveDocDetail.waveDoc.id=:id ", - new String[] { "id"},new Object[] {waveDocId}); - if(bigTasks.size()>0){ - for(Task t:bigTasks){ - InterWMStask iwt=EntityFactory.getEntity(InterWMStask.class); - iwt.setTaskid(t.getCode()); - iwt.setAddre(wd.getWorkModel()); - iwt.setSsjport(wd.getCode()); - iwt.setPalno_v(t.getSrcLoc().getCode()); - iwt.setQuant((int)t.getPlanQuantity()); - iwt.setSenddat(new Date()); - iwt.setStartDate(new Date()); - iwt.setFlag("0"); - commonDao.store(iwt); - } - } - }else{ - List Tasks = commonDao.findByQuery(" from Task t where t.pickTicketDetail.pickTicket.waveDoc.id=:id and t.planQuantity>t.movedQuantityMU ", - new String[] { "id"},new Object[] {waveDocId}); - if(Tasks.size()>0){ - for(Task t:Tasks){ - InterWMStask iwt=EntityFactory.getEntity(InterWMStask.class); - iwt.setTaskid(t.getCode()); - iwt.setAddre(t.getPickTicketDetail().getPickTicket().getSeedWall().getCode()); - iwt.setSsjport(t.getPickTicketDetail().getPickTicket().getCode()); - iwt.setPalno_v(t.getSrcLoc().getCode()); - iwt.setQuant((int)t.getPlanQuantity()); - iwt.setSenddat(new Date()); - iwt.setStartDate(new Date()); - iwt.setFlag("0"); - commonDao.store(iwt); - } - } - } - } - - //呼叫AGV - @Override - public void callAGV(long waveDocId){ - List Tasks = commonDao.findByQuery(" from Task t where t.waveDocDetail.waveDoc.id=:id and t.planQuantity>t.movedQuantityMU and t.waveDocDetail.id is not null ", - new String[] { "id"},new Object[] {waveDocId}); - if(Tasks.size()>0){ - for(Task t:Tasks){ - WaveDocDetail wdd = t.getWaveDocDetail(); - SeedWall sw = wdd.getSeedWall(); - LocationStorage ls = sw.getLocationStorage();//工作站 - logger.info("任务:"+t.getCode()+"\n"); - String outsueAGVJSON = interfaceManager.outsueAGVJSON("kckq", ls.getDescription(), "QP_OUTBOUND", "", 1,0, "SI_QUICK_PICK", true, t.getCode(), 1, t.getSrcLoc().getCode(), 0); - String result = interfaceManager.doSslPost(ApiURL.issueAGV,outsueAGVJSON); - JSONObject json = JSONObject.fromObject(result); - String code = json.has("code") ? json.getString("code") : ""; - if (!code.equals("SUCCESS")) { - String message = json.has("message") ? json.getString("message") : ""; - jdbcManager.saveExceptionLog(message + ",任务编号:"+ t.getCode() + "," + t.getSrcLoc().getCode()); - } - } - } - } - - - //呼叫货架 - public void CallAGV(Long LocationStorageId,Long id){ -// WaveDoc wd =this.load(WaveDoc.class, id);//波次单 - //料箱号编码 1获取出库商品代码(波次明细——WaveDocDetail) 2查询对应的料箱编码(容器入库——ReceivedRecord) - List wdds = commonDao.findByQuery(" from WaveDocDetail wdd where wdd.waveDoc.id=:id ", - new String[] { "id"},new Object[] {id}); - LocationStorage ls =this.load(LocationStorage.class, LocationStorageId);//工作站 - String robotJobId=this.bussinessCodeManager.getCodeForYm("AGV",6); - for(WaveDocDetail wdd :wdds){ - List inv = commonDao.findByQuery(" from Inventory inv where inv.itemKey.item.code=:code order by inv.storageDate asc", - new String[] { "code"},new Object[] {wdd.getItem().getCode()}); - int sum=(int) wdd.getOrderQuantity(); - for (int i = 0; i < inv.size(); i++) { - int waveSum=(int) (inv.get(i).getQtyOfMasterPack()-inv.get(i).getQueuedQuantity()); - - if (sum-waveSum>=0) { - logger.info("料箱整箱:"+inv.get(i).getLocation().getCode()); - String outsueAGVJSON=interfaceManager.outsueAGVJSON("kckq", ls.getDescription(), "QP_OUTBOUND", "", 1, 0, "SI_QUICK_PICK", true, robotJobId, 1l,inv.get(i).getLocation().getCode(),0); - - interfaceManager.doSslPost(ApiURL.issueAGV, outsueAGVJSON); - } - else{ - logger.info("料箱单拣:"+inv.get(i).getLocation().getCode()); - String outsueAGVJSON=interfaceManager.outsueAGVJSON("kckq", ls.getDescription(), "QP_OUTBOUND", "", 1, 0, "SI_QUICK_PICK", true, robotJobId, 1,inv.get(i).getLocation().getCode(),0); - interfaceManager.doSslPost(ApiURL.issueAGV, outsueAGVJSON); - } - sum=sum-waveSum; - if (sum<=0) { - logger.info("呼叫完成:"); - return; - } - } - - } - } - //料箱 出库回传任务 - @Override - public void returnAGV(List waveDocDetailIds,String containerCode) { - /*for(Long waveDocDetailId:waveDocDetailIds){ - WaveDocDetail wd =this.load(WaveDocDetail.class, waveDocDetailId);//波次单 -// .getPickTicket().getLx().getCode() - List robotJobIds=new ArrayList(); - String returnAGVJSON=interfaceManager.returnAGVJSON(robotJobIds,1l,"", false,"RETURN_WAREHOUSE"); - logger.info("json:"+returnAGVJSON); - }*/ -// logger.info("回传入库:"+inv.get(i).getLocation().getCode()); - List robotJobIds=new ArrayList(); - String returnAGVJSON=interfaceManager.returnAGVJSON(robotJobIds,1L,containerCode, false,"RETURN_WAREHOUSE"); - interfaceManager.doSslPost(ApiURL.returnAGV, returnAGVJSON); - } - @Override - public void returnAGV(String code,Boolean takeAwayFlag,List robotJobIds) { - - String returnAGVJSON=interfaceManager.returnAGVJSON(robotJobIds,1L,code, takeAwayFlag,"RETURN_WAREHOUSE"); - interfaceManager.doSslPost(ApiURL.returnAGV, returnAGVJSON); - } - - public void shuaXinWaveDocDetail(long waveDocDetailId){ - double allocatedQuantity=0; - WaveDocDetail wdd=this.load(WaveDocDetail.class, waveDocDetailId); - List Tasks = commonDao.findByQuery(" from Task t where t.waveDocDetail.id=:waveDocDetailId ", - new String[] { "waveDocDetailId"},new Object[] {waveDocDetailId}); - if(Tasks.size()>0){ - for(Task t:Tasks){ - allocatedQuantity+=t.getPlanQuantity(); - } - wdd.setAllocatedQuantity(allocatedQuantity); - commonDao.store(wdd); - } - - } - - public void shuaXinWaveDoc(long waveDocId){ - - - - - } - - - @Override - public void artificialAGV(List ids) { - for(Long id:ids){ - WaveDoc w=this.load(WaveDoc.class, id); - if(w.getPrintCount()==0&&w.getOrderQuantity()==w.getAllocatedQuantity()&&w.getPickedQuantity()==0&&w.getBillAllocatedQuantity()==0){ - initializationLabel(w.getId());//电子标签初始化 - callAGV(w.getId());//调用agv - w.setPrintCount(1); - commonDao.store(w); - } - } - } - - @Override - public void cancelallocate(List WaveDocIds) { - - for(Long id:WaveDocIds){ - long stime = System.currentTimeMillis(); - WaveDoc wd =this.load(WaveDoc.class, id);//波次单 - //波次明细 - long etime = System.currentTimeMillis(); - List PickIds = commonDao.findByQuery(" select t.pickTicketDetail.pickTicket.id from Task t where t.waveDoc.id="+wd.getId()+" group by t.pickTicketDetail.pickTicket.id "); -// for(Long pdid:PickIds) { -// List pdids=commonDao.findByQuery(" select t.pickTicketDetail.id from Task t where t.pickTicketDetail.pickTicket.id="+pdid); -// interfaceReqManager.wmsSapZhuantaihuichuang(pdids, 0,"X");//状态回传 -// } - cancelPickticket(PickIds); -// for(Long pick:PickIds){ -// PickTicket pt=this.load(PickTicket.class, pick); -// shuaxinPick(pt);//刷新出库单 -// } - Map map= new HashMap(); - map.put("waveDoc.id", id); - getQuantityMap(map); - logger.info("取消分配执行时长:"+(etime - stime)+"\n"); - jdbcManager.saveExceptionLog(UserHolder.getUser().getName()+"取消分配!"); - } - } - - public void getQuantityMap(Map map) { - Long id=(Long) map.get("waveDoc.id"); - long quantity=0; - if(id!=null&&id.longValue()>0){ - WaveDoc wd=this.load(WaveDoc.class, id); - List Tasks = commonDao.findByQuery(" from Task t where t.waveDoc.id=:id ", - new String[] { "id"},new Object[] {id}); - quantity=Tasks.size(); - wd.setQuantity(quantity); - if(quantity==0) { - wd.setStatus("OPEN"); - commonDao.delete(wd); - }else { - wd.setStatus("PICK_ALL"); - commonDao.store(wd); - } - - } - } - - @Override - public void cancelPickticket(List pickIds) { - for(Long id:pickIds){ - long stime = System.currentTimeMillis(); - PickTicket pt =this.load(PickTicket.class, id);//出库单 - List pds = commonDao.findByQuery(" from Task t where t.pickTicketDetail.pickTicket.id=:id and t.pickTicketDetail.pickedQuantity=0 ", - new String[] { "id"},new Object[] {pt.getId()}); - if(pt != null&&pt.getCode().indexOf("CP")==-1 - &&pt.getBillType().getName().indexOf("工单")>=0) { - interfaceReqManager.wmsSapZhuantaihuichuang(pds, 0,"X",0);//状态回传 - } - //出库明细 - List PickTicketDetails = commonDao.findByQuery(" from PickTicketDetail ptd where ptd.pickTicket.id=:id ", - new String[] { "id"},new Object[] {pt.getId()}); - - if(PickTicketDetails.size()>0){ - for(PickTicketDetail ptd :PickTicketDetails){ - Item item=ptd.getItem(); - ////根据出库明细z=找到TASK任务 - List Tasks = commonDao.findByQuery(" from Task t where t.pickTicketDetail.id=:id and t.movedQuantityMU=0 " , - new String[] { "id"},new Object[] {ptd.getId()}); - if(Tasks.size()>0){ - for(Task t:Tasks){ - //根据小task找到库存,并把占用数量退回。 - Inventory inventory=null; - String hql ="from Inventory i where i.queuedQuantity>0 and i.location.id="+t.getSrcLoc().getId()+" and i.itemKey.id="+t.getItemKey().getId(); - if(t.getBarCode()!=null&&!t.getBillCode().equals("")) { - hql+=" and i.barCode='"+t.getBarCode()+"'"; - } - List Inventorys = commonDao.findByQuery(hql); - if(Inventorys.size()>0){ - inventory=Inventorys.get(0); - inventory.setQueuedQuantity(inventory.getQueuedQuantity()-t.getPlanQuantity()); - inventory.setVersion(inventory.getVersion()); - commonDao.store(inventory); - } - ptd.setAllocatedQuantity(ptd.getAllocatedQuantity()-t.getPlanQuantity()); - ptd.setWaveDoc(null); - if(ptd.getStrBill15()!=null&&ptd.getStrBill15().equals("1")) { - ptd.setStrBill14(null); - ptd.setStrBill15(null); - } - commonDao.store(ptd); - SeedWall sw=t.getSeedWall(); - if(sw!=null){ - t.setSeedWall(null); - commonDao.store(t); - sw.setStatus(WarehouseAreaStatus.FREE); - sw.setTaskCode(null); - commonDao.store(sw); - } - commonDao.delete(t); - } - } - } - - } - shuaxinPick(pt);//刷新出库单 - long etime = System.currentTimeMillis(); - logger.info("取消分配执行时长:"+(etime - stime)+"\n"); - } - } - - @Override - public void cancelPickticketDetail(List pickIds) { - for (int i = 0; i < pickIds.size(); i++) { - Long id=Long.valueOf(pickIds.get(i)+""); - - long stime = System.currentTimeMillis(); - PickTicketDetail ptd =this.load(PickTicketDetail.class, id);//出库单明细 - PickTicket pt =this.load(PickTicket.class, ptd.getPickTicket().getId());//出库单 -// Item item=ptd.getItem(); - - - ////根据出库明细z=找到TASK任务 - List Tasks = commonDao.findByQuery(" from Task t where t.pickTicketDetail.id=:id ", - new String[] { "id"},new Object[] {ptd.getId()}); - if(Tasks.size()>0){ - for(Task t:Tasks){ - if (t.getPlanQuantity()>t.getMovedQuantityMU()) { - //根据小task找到库存,并把占用数量退回。 - Inventory inventory=null; - List Inventorys = commonDao.findByQuery(" from Inventory i where i.quantity>0 and i.queuedQuantity>0 and i.location.id=:locationId and i.itemKey.id=:itemKeyId ", - new String[] { "locationId","itemKeyId"},new Object[] {t.getSrcLoc().getId(),t.getItemKey().getId()}); - if(Inventorys.size()>0){ - inventory=Inventorys.get(0); - inventory.setQueuedQuantity(inventory.getQueuedQuantity()-t.getPlanQuantity()); - inventory.setVersion(inventory.getVersion()); - commonDao.store(inventory); - } - - //清空电子标签记录 - InterWMStask iw=null; - List InterWMStasks = commonDao.findByQuery(" from InterWMStask iw where iw.taskid=:code ", - new String[] { "code"},new Object[] {t.getCode()}); - if(InterWMStasks.size()>0){ - iw=InterWMStasks.get(0); - iw.setFlag("5"); - commonDao.store(iw); - } - - ptd.setAllocatedQuantity(ptd.getAllocatedQuantity()-t.getPlanQuantity()); - commonDao.store(ptd); - if(t.getAgvTask()!=null) { - AgvTask agv=commonDao.load(AgvTask.class, t.getAgvTask().getId()); - - if(agv.isBeIssue()) { - - }else { - commonDao.delete(t); - } - }else { - commonDao.delete(t); - } - - } - } - } - -// shauxinInvQty(item.getId());//刷新item的库存数量 - - -// SeedWall sw=pt.getSeedWall(); -// if(sw!=null){ -// pt.setSeedWall(null); -// commonDao.store(pt); -// sw.setStatus(WarehouseAreaStatus.FREE); -// commonDao.store(sw); -// } - shuaxinPick(pt);//刷新出库单 - long etime = System.currentTimeMillis(); - logger.info("取消分配执行时长:"+(etime - stime)+"\n"); - - } - } - - @Override - public void allautoWaveDetail(List ids) { - /*for(Long id:ids){ - WaveDocDetail wdd=this.load(WaveDocDetail.class, id); - WaveDoc wd=this.load(WaveDoc.class, wdd.getWaveDoc().getId()); - List PickTicketDetails = commonDao.findByQuery(" from PickTicketDetail ptd where ptd.waveDocDetail.id=:id and ptd.orderQuantity!=ptd.allocatedQuantity ", - new String[] { "id"},new Object[] {id}); - for(PickTicketDetail ptd : PickTicketDetails){ - List Inventorys = commonDao.findByQuery(" from Inventory i where i.itemKey.item.id=:id and i.location.type='LOC' and i.quantity-i.queuedQuantity>0 ", - new String[] { "id"},new Object[] {ptd.getItem().getId()}); - double allocatedQuantity=0; - double unQty=ptd.getOrderQuantity()-ptd.getAllocatedQuantity();//未分配数量 - if(Inventorys.size()>0){ - for(Inventory inventory:Inventorys){ - int j=0; - if(unQty==0){ - break; - } - double allocateQty=inventory.getQuantity()-inventory.getQueuedQuantity();//可分配数量 - if(allocateQty==0){ - continue; - } - if(unQty Tasks = commonDao.findByQuery(" from Task t where t.pickTicketDetail.id=:id and t.srcLoc.id=:srcLocId ", - new String[] { "id","srcLocId"},new Object[] {ptd.getId(),inventory.getLocation().getId()}); - if(Tasks.size()>0){ - task=Tasks.get(0); - task.setPlanQuantity(task.getPlanQuantity()+allocateQty); - task.setPlanQuantityMU(task.getPlanQuantity()); - task.setVersion(task.getVersion()); - commonDao.store(task); - }else{ - task=EntityFactory.getEntity(Task.class); - task.setPickTicketDetail(ptd); - task.setBillCode(ptd.getPickTicket().getCode()); - task.setPickTicketDetail(ptd); - task.setType(TaskType.MV_PICKTICKET); - task.setItemKey(inventory.getItemKey()); - task.setStorageDate(inventory.getStorageDate()); - task.setSrcLoc(inventory.getLocation()); - task.setSOI(inventory.getSOI()); - task.setPlanQuantity(allocateQty); - task.setPlanQuantityMU(allocateQty); - task.setInventoryStatus(inventory.getStatus()); - task.setCreateTime(new Date()); - task.setCode(TimeNumberUtils.getTaskCode()); - commonDao.store(task); - } - //根据出库明细生成的小Task 合并成大Task--- - Task bigTask=null; - List bigTasks = commonDao.findByQuery(" from Task t where t.waveDocDetail.id=:waveDocDetailId and t.srcLoc.id=:srcLocId ", - new String[] { "waveDocDetailId","srcLocId"},new Object[] {wdd.getId(),inventory.getLocation().getId()}); - if(bigTasks.size()>0){ - bigTask=bigTasks.get(0); - bigTask.setPlanQuantity(bigTask.getPlanQuantity()+allocateQty); - bigTask.setPlanQuantityMU(bigTask.getPlanQuantity()); - bigTask.setTaskids(bigTask.getTaskids()+","+task.getId().toString()); - bigTask.setVersion(bigTask.getVersion()); - commonDao.store(bigTask); - }else{ - bigTask=EntityFactory.getEntity(Task.class); - bigTask.setWaveDocDetail(wdd); - bigTask.setBillCode(wd.getCode()); - bigTask.setType(TaskType.MV_PICKTICKET); - bigTask.setItemKey(task.getItemKey()); - bigTask.setTaskids(task.getId().toString()); - bigTask.setStorageDate(task.getStorageDate()); - bigTask.setSrcLoc(task.getSrcLoc()); - bigTask.setPlanQuantity(allocateQty); - bigTask.setPlanQuantityMU(allocateQty); - bigTask.setInventoryStatus(task.getInventoryStatus()); - bigTask.setCreateTime(new Date()); - bigTask.setCode(TimeNumberUtils.getBigTaskCode()); - if(wd.isBePopular()){ - bigTask.setPopular(1); - } - commonDao.store(bigTask); - } - - } - - }else{ - continue; - } - } - shuaXinWaveDoc(wd.getId());//刷新波次单 - }*/ - for(Long id:ids){ - WaveDocDetail wdd=this.load(WaveDocDetail.class, id); - WaveDoc wd=this.load(WaveDoc.class, wdd.getWaveDoc().getId()); - //根据出库明细生成TASK任务 - List PickTicketDetails = commonDao.findByQuery(" from PickTicketDetail ptd where ptd.waveDocDetail.id=:id and ptd.orderQuantity!=ptd.allocatedQuantity and ptd.pickedQuantity=0 and ptd.shippedQuantity=0 ", - new String[] { "id"},new Object[] {wdd.getId()}); - if(PickTicketDetails.size()>0){ - for(PickTicketDetail ptd :PickTicketDetails){ - Item item = ptd.getItem(); - //是赠品,则无需分配库存 - if (item.isBeMarkWeight() == true) { - ptd.setAllocatedQuantity(ptd.getOrderQuantity()); - ptd.setPickedQuantity(ptd.getOrderQuantity()); - ptd.setShippedQuantity(ptd.getOrderQuantity()); - commonDao.store(ptd); - } else { - //分配库存 - List Inventorys = commonDao.findByQuery( - " from Inventory i where i.itemKey.item.id=:id and i.location.type='LOC' and i.quantity-i.queuedQuantity>0 order by i.storageDate ", - new String[] { "id" },new Object[] { item.getId() }); - if (Inventorys.size() > 0) { - double allocatedQuantity = 0; - double unQty = ptd.getOrderQuantity()- ptd.getAllocatedQuantity();//未分配数量 - double allocateQty=0; - for (Inventory inventory : Inventorys) { - int j = 0; - if (unQty == 0) { - break; - } - allocateQty = inventory.getQuantity()- inventory.getQueuedQuantity();//可分配数量 - if (allocateQty == 0) { - continue; - } - if (unQty < allocateQty) { - allocateQty = unQty; - } - j++; - inventory.setQueuedQuantity(inventory.getQueuedQuantity()+ allocateQty); - inventory.setVersion(inventory.getVersion()); - commonDao.store(inventory); - allocatedQuantity += allocateQty; - unQty -= allocateQty; - //更新库存数量 - ptd.setAllocatedQuantity(ptd.getAllocatedQuantity()+ allocateQty); - - //更新出库明细分配数量 - commonDao.store(ptd); - - //生成搬运任务 - AgvTask agvTask=null; - List AGVTasks = commonDao.findByQuery(" from AGVTask agv where agv.waveDocDetail.id=:id and agv.containerCode=:containerCode and agv.targetArea=:targetArea and agv.status=:status ", - new String[] {"id","containerCode","targetArea","status"},new Object[] {wdd.getId(),inventory.getLocation().getCode(),ptd.getPickTicket().getShipToName(),STATUS.ATCALL}); - if(AGVTasks.size()>0){ - agvTask=AGVTasks.get(0); - agvTask.setPlanQuantity(agvTask.getPlanQuantity()+allocateQty); - commonDao.store(agvTask); - }else{ - agvTask = EntityFactory.getEntity(AgvTask.class); - agvTask.setZoneCode("kckq"); - agvTask.setTargetArea(ptd.getPickTicket().getShipToName()); - agvTask.setWorkMode("QP_OUTBOUND"); - agvTask.setInboundTotal(1L); - agvTask.setJobPriority(1L); - agvTask.setJobPriorityType(null); - agvTask.setJobType("SI_QUICK_PICK"); - agvTask.setNeedOperation(true); - agvTask.setRobotJobId(TimeNumberUtils.getBigTaskCode()); - agvTask.setWarehouseId(1L); - agvTask.setContainerCode(inventory.getLocation().getCode()); - agvTask.setPutDown("0"); - agvTask.setPlanQuantity(allocateQty); - agvTask.setCreateTime(new Date()); - agvTask.setStatus(STATUS.ATCALL); - agvTask.setBeIssue(false); - agvTask.setPopular(true); - agvTask.setWaveDocDetail(wdd); - agvTask.setType("拣货"); - commonDao.store(agvTask); - } - Task task = EntityFactory.getEntity(Task.class); - task.setPickTicketDetail(ptd); - task.setBillCode(ptd.getPickTicket().getCode()); - task.setType(TaskType.MV_PICKTICKET); - task.setItemKey(inventory.getItemKey()); - task.setStorageDate(inventory.getStorageDate()); - task.setSrcLoc(inventory.getLocation()); - task.setSOI(inventory.getSOI()); - task.setPlanQuantity(allocateQty); - task.setPlanQuantityMU(allocateQty); - task.setInventoryStatus(inventory.getStatus()); - task.setCreateTime(new Date()); - task.setCode(TimeNumberUtils.getTaskCode()); - task.setWarehouseArea(inventory.getWarehouseArea()); - task.setAgvTask(agvTask); - commonDao.store(task); - } - - } else { - continue; - } - } - } - Item wdditem=wdd.getItem(); - if(wdditem.isBeMarkWeight()==true){ - wdd.setAllocatedQuantity(wdd.getOrderQuantity()); - wdd.setPickedQuantity(wdd.getOrderQuantity()); - wdd.setBillAllocatedQuantity(wdd.getOrderQuantity()); - commonDao.store(wdd); - } - } - shuaXinWaveDoc(wd.getId());//刷新波次单 - } - - } - - @Override - public String allocatePickticket(PickTicket pt) { - //根据出库明细生成TASK任务 - String hql=" from PickTicketDetail ptd where ptd.pickTicket.id="+pt.getId()+ - " and ptd.orderQuantity>ptd.allocatedQuantity " - + " and (ptd.strBill6 is null or ptd.strBill6='' ) order by ptd.strBill14 desc "; - List PickTicketDetails = commonDao.findByQuery(hql); - String meg="操作成功";//提示 - List tasks=new ArrayList(); - if(PickTicketDetails.size()>0){ - - for(PickTicketDetail ptd :PickTicketDetails){ - //无分配数量 - if(ptd.getOrderQuantity()- ptd.getAllocatedQuantity()<=0) { - continue; - } - //分配库存 - String hql1=" from Inventory i where i.itemKey.item.id=:id and i.location.type in('存货','不良品') " - + "and i.status='已入库' and i.quantity-i.queuedQuantity>0 and i.counPlan is null " - + " "; - - //指定序列号 - if(ptd.getStrBill14()!=null&&!ptd.getStrBill14().equals("")) { - hql1+=" and i.barCode='"+ptd.getStrBill14()+"'"; - } - if(ptd.getNewLotInfo()!=null) { - if(ptd.getNewLotInfo().getPropC1()!=null&&!ptd.getNewLotInfo().getPropC1().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC1='"+ptd.getNewLotInfo().getPropC1()+"'"; - } - - if(ptd.getNewLotInfo().getPropC3()!=null&&!ptd.getNewLotInfo().getPropC3().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC3='"+ptd.getNewLotInfo().getPropC3()+"'"; - }else { - if(pt.getSourceType()!=null&&(pt.getSourceType().equals("411"))) { - hql1+=" and i.itemKey.lotInfo.propC3='K' "; - } - } - - if(ptd.getNewLotInfo().getPropC4()!=null&&!ptd.getNewLotInfo().getPropC4().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC4='"+ptd.getNewLotInfo().getPropC4()+"'"; - } - if(ptd.getNewLotInfo().getPropC5()!=null&&!ptd.getNewLotInfo().getPropC5().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC5='"+ptd.getNewLotInfo().getPropC5()+"'"; - } - if(ptd.getNewLotInfo().getPropC6()!=null&&!ptd.getNewLotInfo().getPropC6().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC6='"+ptd.getNewLotInfo().getPropC6()+"'"; - } - if(ptd.getNewLotInfo().getPropC7()!=null&&!ptd.getNewLotInfo().getPropC7().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC7='"+ptd.getNewLotInfo().getPropC7()+"'"; - } - if(ptd.getNewLotInfo().getPropC8()!=null&&!ptd.getNewLotInfo().getPropC8().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC8='"+ptd.getNewLotInfo().getPropC8()+"'"; - } - if(ptd.getNewLotInfo().getPropC9()!=null&&!ptd.getNewLotInfo().getPropC9().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC9='"+ptd.getNewLotInfo().getPropC9()+"'"; - } - - }else { - - } - String hql2=" order by i.itemKey.lotInfo.propD2,i.itemKey.lotInfo.propC3,i.itemKey.lotInfo.propC1,i.statuss desc,i.storageDate,i.quantity"; - //排序 - String lcs = new String(); - if(pt.getBillType()!=null&&pt.getBillType().getName().indexOf("工单")>=0 - &&ptd.getStrBill12()!=null&&(!ptd.getStrBill12().equals("881")&& - !ptd.getStrBill12().equals("981"))) { - String hqlmaveloc=" ";//优先入波的LOC - List hqllist1=commonDao.findByQuery("select pl.code from PlantLocation pl where pl.disabled=0 and pl.bePriorityWave=1"); - if(hqllist1.size()>0) { - hqlmaveloc=" CASE i.itemKey.lotInfo.propC2 "; - for(String sh:hqllist1) { - hqlmaveloc=hqlmaveloc+" WHEN '"+sh+"' THEN 1 "; - lcs=lcs+"'"+sh + "',"; - } - hqlmaveloc=hqlmaveloc+" ELSE 99 " + - " END ASC " ; - lcs=lcs.substring(0, lcs.length()-1); - hql2=" order by i.itemKey.lotInfo.propD2,i.itemKey.lotInfo.propC3,i.itemKey.lotInfo.propC1,"+hqlmaveloc+",i.statuss desc,i.storageDate,i.quantity"; - } - } - - - if(pt.getBillType()!=null&&(pt.getBillType().getName().indexOf("其它")>=0 - ||pt.getBillType().getName().indexOf("转库单")>=0) - &&!pt.getSourceType().equals("643")) { - List cs=commonDao.findByQuery(" from Configuration c where c.configuration1='"+ - ptd.getNewLotInfo().getPropC2()+"' or c.configuration2='"+ptd.getNewLotInfo().getPropC2()+"' " ); - if(cs.size()>0) { - Configuration c=cs.get(0); - StringBuffer sb = new StringBuffer(); - if(c.getConfiguration1().length()>0) { - sb.append("'"+c.getConfiguration1() + "', "); - sb.append("'"+c.getConfiguration2() + "' "); - hql1+=" and i.itemKey.lotInfo.propC2 in("+sb.toString()+")"; - } - }else { - if(ptd.getNewLotInfo().getPropC2()!=null&&!ptd.getNewLotInfo().getPropC2().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; - } - } - }else if(pt.getBillType()!=null&&pt.getBillType().getName().indexOf("工单")>=0) { - if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC2()!=null - &&(!ptd.getNewLotInfo().getPropC2().equals("SL12")&&!ptd.getNewLotInfo().getPropC2().equals("")&& - !ptd.getNewLotInfo().getPropC2().equals("SL02") - &&!ptd.getNewLotInfo().getPropC2().equals("SL34"))) { - - hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; - - }else { - String bsql=" from BillTypeConfig b where b.billType.id="+pt.getBillType().getId(); - if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC9()!=null&&!ptd.getNewLotInfo().getPropC9().equals("")) { - bsql+=" and b.plantCode='"+ptd.getNewLotInfo().getPropC9()+"'"; - } - List bts=commonDao.findByQuery(bsql); - - if(bts.size()>0) { - StringBuffer sb = new StringBuffer(); - for(int i=0;i<=bts.size()-1;i++){ - BillTypeConfig bt=bts.get(i); - if(i0) { - sb.append(","+lcs); - } - hql1+=" and i.itemKey.lotInfo.propC2 in("+sb.toString()+") "; - }else { - if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC2()!=null&&ptd.getNewLotInfo().getPropC2().length()>0) { - hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; - } - } - } - }else { - if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC2()!=null&&ptd.getNewLotInfo().getPropC2().length()>0) { - hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; - } - } - - //料号有效期管理 - if(ptd.getItem().getIsBOM()) { - hql1+=" and CONVERT(varchar(100), i.itemKey.lotInfo.propD2, 23)>='"+DateUtil.formatDateYMDToStr(new Date())+"' "; - } - //排序 - - List Inventorys = commonDao.findByQuery( - hql1+hql2,new String[] { "id" },new Object[] { ptd.getItem().getId() }); - if (Inventorys.size() > 0) { - double allocatedQuantity = 0; - double unQty = ptd.getOrderQuantity()- ptd.getAllocatedQuantity();//未分配数量 - double allocateQty=0; - List addInventorys1 =new ArrayList();//指定LOC方前面 - List addInventorys2 =new ArrayList();//指定可以协同的LOC - if(pt.getBillType()!=null&&(pt.getBillType().getName().indexOf("其它")>=0 - ||pt.getBillType().getName().indexOf("转库单")>=0) - &&!pt.getSourceType().equals("643")) { - if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC2()!=null&&ptd.getNewLotInfo().getPropC2().length()>0) { - for(Inventory inventory1 : Inventorys) { - ItemKey ik=commonDao.load(ItemKey.class, inventory1.getItemKey().getId()); - if(ik.getLotInfo()!=null&&ik.getLotInfo().getPropC2().equals(ptd.getNewLotInfo().getPropC2())) { - addInventorys1.add(inventory1); - }else { - addInventorys2.add(inventory1); - } - } - if(addInventorys1.size()>0) { - Inventorys=addInventorys1; - }else { - Inventorys=addInventorys2; - } - if(addInventorys1.size()>0&&addInventorys2.size()>0) { - Inventorys=addInventorys1; - Inventorys.addAll(addInventorys2); - } - } - } - for (Inventory inventory : Inventorys) { - int j = 0; - if (unQty == 0) { - break; - } - allocateQty = inventory.getQuantity()- inventory.getQueuedQuantity();//可分配数量 - if (allocateQty == 0) { - continue; - } - if (unQty < allocateQty) { - allocateQty = unQty; - } - j++; - inventory.setQueuedQuantity(inventory.getQueuedQuantity()+ allocateQty); - inventory.setVersion(inventory.getVersion()); - commonDao.store(inventory); - allocatedQuantity += allocateQty; - unQty -= allocateQty; - ptd.setAllocatedQuantity(ptd.getAllocatedQuantity()+ allocateQty); - commonDao.store(ptd); - - Task task = EntityFactory.getEntity(Task.class); - task.setPickTicketDetail(ptd); - - Item item=commonDao.load(Item.class, ptd.getItem().getId()); - task.setBillCode(getSubWorkOrer(ptd.getPickTicket().getCode(),inventory.getLocation().getZone(),item)); - - task.setCode(TimeNumberUtils.getTaskCode()); - task.setType(TaskType.MV_PICKTICKET); - task.setItemKey(inventory.getItemKey()); - task.setStorageDate(inventory.getStorageDate()); - task.setSrcLoc(inventory.getLocation()); - task.setSOI(inventory.getSOI()); - task.setPlanQuantity(allocateQty); - task.setPlanQuantityMU(allocateQty); - task.setInventoryStatus(inventory.getStatus()); - task.setCreateTime(new Date()); - task.setWarehouseArea(inventory.getWarehouseArea()); - task.setBarCode(inventory.getBarCode()); - task.setSrcLP(inventory.getLocation().getStock()); - if(UserHolder.getUser()!=null) { - task.setOperator(UserHolder.getUser().getName()); - task.setStrBill3(UserHolder.getUser().getName()); - } - tasks.add(task); - commonDao.store(task); - - } - if(unQty>0) { - meg=meg+ptd.getItem().getCode()+",库存不足! "; - }else{ - - } - - } else { - meg=meg+ptd.getItem().getCode()+",无匹配库存 "; - continue; - } - } - } - //拣货任务 -// List listtask=commonDao.findByQuery(" from Task t where t.planQuantity>0 and " -// + " t.pickTicketDetail.pickTicket.id="+pt.getId()); -// if(listtask.size()>0) { -// //SAP下发的工单出库才需要回传状态 -// if(pt.getCode().indexOf("CP")==-1 -// &&pt.getBillType().getId()==1094) { -// interfaceReqManager.wmsSapZhuantaihuichuang(listtask, 0,"",1);//状态回传 -// } -// }else { -// logger.info(pt.getCode()+"自动分配,无回传状态"); -// } -// -// shuaxinPick(pt);//刷新订单 - return meg; - } - - - - public void shuaxinPick(PickTicket pt){ - double allocatedQty=0; - if(!pt.getStatus().equals("JIAODAN")) { - - List PickTicketDetails = commonDao.findByQuery(" from PickTicketDetail ptd where ptd.pickTicket.id=:id ", - new String[] { "id"},new Object[] {pt.getId()}); - if(PickTicketDetails.size()>0){ - for(PickTicketDetail ptd:PickTicketDetails){ - allocatedQty+=ptd.getAllocatedQuantity(); - } - } - pt.setReceivedDate(new Date()); - pt.setAllocatedQuantity(allocatedQty); - commonDao.store(pt); - if(pt.getAllocatedQuantity()==0){ - pt.setStatus(PickTicketStatus.OPEN); - } - if((pt.getOrderQuantity()>0 && pt.getPickedQuantity()==0&&pt.getShippedQuantity()==0) && (pt.getAllocatedQuantity()>0) ){ - pt.setStatus(PickTicketStatus.ALLOCATE); - } - if((pt.getOrderQuantity()>0 && pt.getPickedQuantity()>0 && pt.getPickedQuantity()!=pt.getAllocatedQuantity())){ - pt.setStatus(PickTicketStatus.PICKUP); - } - if(pt.getAllocatedQuantity()==pt.getPickedQuantity()&&pt.getPickedQuantity()>0){ - BillType bt=commonDao.load(BillType.class, pt.getBillType().getId()); - if(bt.getName().equals("工单出库")) { - pt.setStatus(PickTicketStatus.PICK_ALL); - }else { - pt.setStatus(PickTicketStatus.SHIP_PART); - } - } - if(pt.getOrderQuantity()==pt.getPickedQuantity()&&pt.getPickedQuantity()>0){ - pt.setStatus(PickTicketStatus.PICK_ALL); - } - if(pt.getOrderQuantity()==pt.getShippedQuantity()){ - pt.setStatus(PickTicketStatus.CLOSE); - } - try { - commonDao.store(pt); - }catch(Exception e){ - logger.info(pt.getId()+"保存失败"); - } - } - } - - @Override - public void newallocateWaveDoc(List WaveDocIds) { - for(Long id:WaveDocIds){ - WaveDoc wd =this.load(WaveDoc.class, id);//波次单 - if(wd.getAllocatedQuantity()==0){ - //波次明细 - List WaveDocDetails = commonDao.findByQuery(" from WaveDocDetail wdd where wdd.waveDoc.id=:id ", - new String[] { "id"},new Object[] {id}); - for(WaveDocDetail wdd :WaveDocDetails){ - //根据出库明细生成TASK任务 - List PickTicketDetails = commonDao.findByQuery(" from PickTicketDetail ptd where ptd.waveDocDetail.id=:id ", - new String[] { "id"},new Object[] {wdd.getId()}); - if(PickTicketDetails.size()>0){ - for(PickTicketDetail ptd :PickTicketDetails){ - //是赠品,则无需分配库存 - synchronized (ptd) { - if (ptd.getItem().isBeMarkWeight() == true) { - ptd.setAllocatedQuantity(ptd.getOrderQuantity()); - ptd.setPickedQuantity(ptd.getOrderQuantity()); - ptd.setShippedQuantity(ptd.getOrderQuantity()); - commonDao.store(ptd); - } else { - //分配库存 - List Inventorys = commonDao.findByQuery( - " from Inventory i where i.itemKey.item.id=:id and i.location.type='LOC' and i.quantity-i.queuedQuantity>0 order by i.storageDate ", - new String[] { "id" },new Object[] {ptd.getItem().getId()}); - if (Inventorys.size() > 0) { - double allocatedQuantity = 0; - double unQty = ptd.getOrderQuantity()- ptd.getAllocatedQuantity();//未分配数量 - double allocateQty=0; - for (Inventory inventory : Inventorys) { - int j = 0; - if (unQty == 0) { - break; - } - allocateQty = inventory.getQuantity()- inventory.getQueuedQuantity();//可分配数量 - if (allocateQty == 0) { - continue; - } - if (unQty < allocateQty) { - allocateQty = unQty; - } - j++; - inventory.setQueuedQuantity(inventory.getQueuedQuantity()+ allocateQty); - inventory.setVersion(inventory.getVersion()); - commonDao.store(inventory); - allocatedQuantity += allocateQty; - unQty -= allocateQty; - //更新库存数量 - ptd.setAllocatedQuantity(ptd.getAllocatedQuantity()+ allocateQty); - //更新出库明细分配数量 - commonDao.store(ptd); - //生成搬运任务 - AgvTask agvTask=null; - List AGVTasks = commonDao.findByQuery(" from AGVTask agv where agv.waveDocDetail.id=:id and agv.containerCode=:containerCode and agv.targetArea=:targetArea and agv.status=:status ", - new String[] {"id","containerCode","targetArea","status"},new Object[] {wdd.getId(),inventory.getLocation().getCode(),ptd.getPickTicket().getShipToName(),STATUS.ATCALL}); - if(AGVTasks.size()>0){ - agvTask=AGVTasks.get(0); - agvTask.setPlanQuantity(agvTask.getPlanQuantity()+allocateQty); - commonDao.store(agvTask); - }else{ - agvTask = EntityFactory.getEntity(AgvTask.class); - agvTask.setZoneCode("kckq"); - agvTask.setTargetArea(ptd.getPickTicket().getShipToName()); - agvTask.setWorkMode("QP_OUTBOUND"); - agvTask.setInboundTotal(1L); - agvTask.setJobPriority(1L); - agvTask.setJobPriorityType(null); - agvTask.setJobType("SI_QUICK_PICK"); - agvTask.setNeedOperation(true); - agvTask.setRobotJobId(TimeNumberUtils.getBigTaskCode()); - agvTask.setWarehouseId(1L); - agvTask.setContainerCode(inventory.getLocation().getCode()); - agvTask.setPutDown("0"); - agvTask.setPlanQuantity(allocateQty); - agvTask.setStatus(STATUS.ATCALL); - agvTask.setBeIssue(false); - agvTask.setPopular(true); - agvTask.setWaveDocDetail(wdd); - commonDao.store(agvTask); - } - - Task task = EntityFactory.getEntity(Task.class); - task.setPickTicketDetail(ptd); - task.setBillCode(ptd.getPickTicket().getCode()); - task.setType(TaskType.MV_PICKTICKET); - task.setItemKey(inventory.getItemKey()); - task.setStorageDate(inventory.getStorageDate()); - task.setSrcLoc(inventory.getLocation()); - task.setSOI(inventory.getSOI()); - task.setPlanQuantity(allocateQty); - task.setPlanQuantityMU(allocateQty); - task.setInventoryStatus(inventory.getStatus()); - task.setCreateTime(new Date()); - task.setCode(TimeNumberUtils.getTaskCode()); - task.setAgvTask(agvTask); - commonDao.store(task); - } - - } else { - continue; - } - } - } - Item wdditem=wdd.getItem(); - if(wdditem.isBeMarkWeight()==true){ - wdd.setAllocatedQuantity(wdd.getOrderQuantity()); - wdd.setPickedQuantity(wdd.getOrderQuantity()); - wdd.setBillAllocatedQuantity(wdd.getOrderQuantity()); - commonDao.store(wdd); - } - } - } - - } - shuaXinWaveDoc(id);//刷新波次单 - }else{ - logger.info("无波次任务!"+"\n"); - } - } - - } - - - - @Override - public void initiandcallAGV(long waveDocId,List lxq,List hjq,List lkq) { - synchronized ("pickTask") { - WaveDoc wd=commonDao.load(WaveDoc.class, waveDocId); - //料箱库 - if(lxq.size()>0){ - int i=0; - int num=0;//下发任务数 - int cunt=0;//平均任务数 - int cunt1=0;//最大 - int cunt2=0;//小于 - //子任务号 -// List lxqTasks = commonDao.findByQuery(" select t.billCode from Task t where t.waveDoc.id="+waveDocId+ -// " and t.srcLoc.zone.id=1763 and t.agvStatus=0 and t.planQuantity>0 and t.movedQuantityMU=0 " -// + " group by t.billCode,t.pickTicketDetail.pickTicket.relatedBill3 " -// + "order by count(t.id) desc,t.pickTicketDetail.pickTicket.relatedBill3,min(t.pickTicketDetail.item.code),t.billCode desc "); - List lxqTasks=commonDao.findByQuery("select t.billcode from PickTicketTaskView t where t.zid=1763 " - + " and t.waveDocId="+waveDocId+" order by t.hs desc,t.iCode,t.relatedBill3 "); - //查询所有任务 -// List tds=commonDao.findByQuery(" from Task t where t.waveDoc.id="+waveDocId+" and t.srcLoc.zone.id=1763 and t.agvStatus=0 " -// + "order by t.pickTicketDetail.pickTicket.relatedBill3 desc "); - //查询总共拣货次数 - List tas=commonDao.findByQuery("select sum(t.hs) from PickTicketTaskView t where t.zid=1763 " - + " and t.waveDocId="+waveDocId+" "); - int countqty=0;//tds.size(); - if(tas.size()>0) { - countqty=tas.get(0).intValue(); - } - if(wd.getLongtiem()>0) { - List sl=commonDao.findByQuery(" from ShiXiao s where s.warehouseArea.id=1763"); - if(sl.size()>0) { - ShiXiao s1=sl.get(0); - cunt=(int)Math.floor(s1.getNumber()*wd.getLongtiem()); - } - }else { - cunt=(int)Math.ceil(countqty/lxq.size()); - } - cunt1=(int)Math.ceil(cunt*1.1); - cunt2=(int)Math.ceil(cunt*0.9); - Long y=0L; - - for(String billCode :lxqTasks){ - - List Tasks = commonDao.findByQuery(" from Task t where t.billCode='"+billCode+"' and t.agvStatus=0 and t.srcLoc.zone.id=1763 "); - //是否大于平均 - if(num+Tasks.size()>=cunt) { -// //是否大于平均110% - num=0; - if(i+1>lxq.size()){ - i=0; - y=lxq.get(i); - }else { - y=lxq.get(i); - i=i+1; - } - - }else { - num+=Tasks.size(); - if(i+1>lxq.size()){ - i=0; - y=lxq.get(i); - }else { - y=lxq.get(i); - } - } - for(Task task:Tasks){ - LocationStorage ls=this.load(LocationStorage.class, y); - task.setEndRegion(ls.getName()); -// task.setAgvStatus(1);//1=可以分配分拨墙并下发AGV - task.setYc_qty(task.getPlanQuantityMU()); - commonDao.store(task); - } - - } - } - //货架区 - if(hjq.size()>0){ - int i=0; - int num=0; - int cunt=0;//平均任务数 - List hjqTasks = commonDao.findByQuery("select t.billCode from Task t where t.waveDoc.id="+waveDocId+" and t.srcLoc.zone.id=1765 and t.agvStatus=0 group by t.billCode,t.pickTicketDetail.pickTicket.relatedBill3 order by count(t.id) desc,min(t.itemKey.item.code),t.pickTicketDetail.pickTicket.relatedBill3,t.billCode desc "); - List tds=commonDao.findByQuery(" from Task t where t.waveDoc.id="+waveDocId+" and t.srcLoc.zone.id=1765 and t.agvStatus=0 order by t.pickTicketDetail.pickTicket.relatedBill3 desc "); - cunt=(int)Math.ceil(tds.size()/hjq.size()); - for(String billCode :hjqTasks){ - List Tasks = commonDao.findByQuery("from Task t where t.billCode='"+billCode+"' "); - - for(Task task:Tasks){ - LocationStorage ls=this.load(LocationStorage.class, hjq.get(i)); - task.setEndRegion(ls.getName()); -// task.setAgvStatus(1);//1=可以分配分拨墙并下发AGV - task.setYc_qty(task.getPlanQuantityMU()); - commonDao.store(task); - } - if(num+Tasks.size()>=cunt) { - num=0; - if(i+1>=hjq.size()){ - i=0; - }else { - i=i+1; - } - }else { - num+=Tasks.size(); - } - - } - } - //立库 - if(lkq.size()>0){ - int i=0; - List lkqTasks = commonDao.findByQuery("select t.billCode from Task t where t.waveDoc.id="+waveDocId+" and t.srcLoc.zone.id=1766 and t.agvStatus=0 group by t.billCode,t.pickTicketDetail.pickTicket.relatedBill3 order by t.pickTicketDetail.pickTicket.relatedBill3 desc "); - for(String billCode :lkqTasks){ - int ys=i%lkq.size(); - List Tasks = commonDao.findByQuery("from Task t where t.billCode='"+billCode+"' "); - for(Task task:Tasks){ - LocationStorage ls=this.load(LocationStorage.class, lkq.get(ys)); - task.setEndRegion(ls.getName()); -// task.setAgvStatus(1); - task.setYc_qty(task.getPlanQuantityMU()); - commonDao.store(task); - } - i++; - } - } - - if(wd!=null) { - wd.setStatus("ACTIVE"); - commonDao.store(wd); -// List tasks = commonDao.findByQuery(" from Task t where t.waveDoc.id="+waveDocId+" and t.agvStatus=0 order by t.id desc "); -// for(Task t:tasks) { -// t.setAgvStatus(1); -// t.setYc_qty(t.getPlanQuantityMU()); -// commonDao.store(t); -// } - } - } - //波次状态回传,按工单回传 -// List ptids = commonDao.findByQuery("select t.pickTicketDetail.pickTicket.id from Task t where t.waveDoc.id="+waveDocId -// +" and t.agvStatus=1 and t.movedQuantityMU=0 group by t.pickTicketDetail.pickTicket.id "); -// for(Long pid:ptids) { -// List ptdids =commonDao.findByQuery("select t.id from PickTicketDetail t where t.pickTicket.id="+pid+" and t.pickedQuantity=0" -// +" "); -// interfaceReqManager.wmsSapZhuantaihuichuang(ptdids, 0,"");//状态回传 -// } - } - - @Override - public synchronized void issueAGV0() { - List AGVTasks = commonDao.findByQuery(" from AGVTask agv where agv.beIssue=0 and agv.popular=0 and agv.status='ATCALL' "); - if(AGVTasks.size()>0){ - for(AgvTask agvTask:AGVTasks){ - String outsueAGVJSON = interfaceManager.outsueAGVJSON(agvTask.getZoneCode(),agvTask.getTargetArea(),agvTask.getWorkMode(), - "", 1,0, agvTask.getJobType(), true, agvTask.getRobotJobId(), 1, agvTask.getContainerCode(), 0); - String result = interfaceManager.doBoxPost(ApiURL.issueAGV,outsueAGVJSON); - JSONObject json = JSONObject.fromObject(result); - String code = json.has("code") ? json.getString("code") : ""; - if (!code.equals("SUCCESS")) { - String message = json.has("message") ? json.getString("message") : ""; - jdbcManager.saveExceptionLog(message + ",任务编号:"+ agvTask.getRobotJobId() + "," + agvTask.getContainerCode()); - }else{ - agvTask.setBeIssue(true); - agvTask.setCreateTime(new Date()); - commonDao.store(agvTask); - } - - } - } - } - public void allocatePickticketDetail(List ids) { - List list= allocatePickticketDetail( ids, 0, true,true,true,true, - true,true,true,true,true,true,""); - if(list.size()>0) { - interfaceReqManager.wmsSapZhuantaihuichuang(list, 0,"",1);//状态回传 - } - } - /** 输送线上的库存*/ - private static List invIds =new ArrayList(); - //自动创波,ddq1=3#不良品区,ddq2=3#焊接件区,ddq3=3#货架区,ddq4=3#料箱区,ddq5=7#3楼普通库, - //ddq6=7#4楼普通库,ddq7=7#地堆区,ddq8=#堆垛库,ddq9=8#化学品区 - @Override - public List allocatePickticketDetail(List ids,int qty,boolean ddq,boolean ddq1,boolean ddq2,boolean ddq3, - boolean ddq4,boolean ddq5,boolean ddq6,boolean ddq7,boolean ddq8,boolean ddq9,String noLoc) { - if (invIds.size()==0) { - invIds=inventoryManager.selectSSXInventory(); - } - String msg=""; - List tasks=new ArrayList(); - for (int i = 0; i < ids.size(); i++) { - Long id=Long.valueOf(ids.get(i)+""); - - PickTicketDetail ptd= commonDao.load(PickTicketDetail.class, id); - if(ptd.getOrderQuantity()- ptd.getAllocatedQuantity()<=0) { - continue; - } - Date date=new Date(); - /** - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - - String dateString=sdf.format(date); - Date date3=new Date(); - try { - date3=sdf.parse(dateString); - } catch (ParseException e) { - // TODO 自动生成的 catch 块 -// e.printStackTrace(); - } - **/ - if(ptd.getStrBill6()==null||ptd.getStrBill6().length()<=0){ - PickTicket pt=ptd.getPickTicket(); - //分配库存 - String hql1=" from Inventory i where i.itemKey.item.id=:id and i.location.type='存货'" - + "and i.status='已入库' and i.quantity-i.queuedQuantity>0 and i.counPlan is null " - + " "; - //不能入波的LOC - if(noLoc!=null&&!noLoc.equals("")) { - hql1+=" and i.itemKey.lotInfo.propC2 not in("+noLoc+")"; - } - //指定序列号 -// if(ptd.getApplyDoc()!=null&&!ptd.getApplyDoc().equals("")) { -// hql1+=" and i.barCode='"+ptd.getApplyDoc()+"'"; -// } - //自动创波,ddq1=3#不良品区,ddq2=3#焊接件区,ddq3=3#货架区,ddq4=3#料箱区,ddq5=7#3楼普通库, - //ddq6=7#4楼普通库,ddq7=7#地堆区,ddq8=7#堆垛库,ddq9=8#化学品区 - String kqno=""; - if(!ddq1) { - kqno+="1798,"; - } - if(!ddq2) { - kqno+="1773,"; - } - if(!ddq3) { - kqno+="1765,"; - } - if(!ddq4) { - kqno+="1763,"; - } - if(!ddq5) { - kqno+="1768,"; - } - if(!ddq6) { - kqno+="1783,"; - } - if(!ddq7) { - kqno+="1808,"; - } - if(!ddq8) { - kqno+="1766,"; - } - if(!ddq9) { - kqno+="1799,"; - } - if(kqno.length()>0) { - kqno=kqno.substring(0, kqno.length()-1); - hql1+=" and i.location.zone.id not in("+kqno+") "; - } - if(ddq&&ptd.getPickTicket().getOrderDate().getTime()>=date.getTime()) { - hql1+=" and i.location.zone.id not in(1808) "; - } - - if(ptd.getNewLotInfo()!=null) { - if(ptd.getNewLotInfo().getPropC1()!=null&&!ptd.getNewLotInfo().getPropC1().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC1='"+ptd.getNewLotInfo().getPropC1()+"'"; - } - -// if(ptd.getNewLotInfo().getPropC2()!=null&&!ptd.getNewLotInfo().getPropC2().equals("")) { -// hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; -// }else { -// -// } - if(ptd.getNewLotInfo().getPropC3()!=null&&!ptd.getNewLotInfo().getPropC3().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC3='"+ptd.getNewLotInfo().getPropC3()+"'"; - }else { - if(ptd.getStrExtend2()!=null&&(ptd.getStrExtend2().equals("TRUE")||ptd.getStrExtend2().equals("true"))) { - hql1+=" and i.itemKey.lotInfo.propC3='K' "; - } - } - if(ptd.getNewLotInfo().getPropC4()!=null&&!ptd.getNewLotInfo().getPropC4().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC4='"+ptd.getNewLotInfo().getPropC4()+"'"; - } - if(ptd.getNewLotInfo().getPropC4()!=null&&!ptd.getNewLotInfo().getPropC4().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC4='"+ptd.getNewLotInfo().getPropC4()+"'"; - } - if(ptd.getNewLotInfo().getPropC5()!=null&&!ptd.getNewLotInfo().getPropC5().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC5='"+ptd.getNewLotInfo().getPropC5()+"'"; - } - if(ptd.getNewLotInfo().getPropC6()!=null&&!ptd.getNewLotInfo().getPropC6().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC6='"+ptd.getNewLotInfo().getPropC6()+"'"; - } - if(ptd.getNewLotInfo().getPropC7()!=null&&!ptd.getNewLotInfo().getPropC7().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC7='"+ptd.getNewLotInfo().getPropC7()+"'"; - } - if(ptd.getNewLotInfo().getPropC8()!=null&&!ptd.getNewLotInfo().getPropC8().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC8='"+ptd.getNewLotInfo().getPropC8()+"'"; - } - if(ptd.getNewLotInfo().getPropC9()!=null&&!ptd.getNewLotInfo().getPropC9().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC9='"+ptd.getNewLotInfo().getPropC9()+"'"; - } - }else { - - } - StringBuffer sqlBuffer=new StringBuffer(); - sqlBuffer.append(" order by "); - if (invIds.size()>0) { - StringBuilder sb = new StringBuilder(); - for (int k = 0; k < invIds.size(); k++) { - sb.append(invIds.get(k)); - if (k < invIds.size() - 1) { - sb.append(","); - } - } - sqlBuffer.append(" CASE " - +" WHEN i.id IN (" - + sb.toString() - +") THEN 1 " - +" ELSE 0 " - +" END, "); - } - sqlBuffer.append(" i.itemKey.lotInfo.propD2,i.itemKey.lotInfo.propC3,i.itemKey.lotInfo.propC1,i.statuss desc,i.storageDate,i.quantity,inv.id"); - String hql2=sqlBuffer.toString(); - //排序 - String lcs = new String(); - if(pt.getBillType()!=null&&pt.getBillType().getName().indexOf("工单")>=0 - &&ptd.getStrBill12()!=null&&(!ptd.getStrBill12().equals("881")&& - !ptd.getStrBill12().equals("981"))) { - String hqlmaveloc=" ";//优先入波的LOC - List hqllist1=commonDao.findByQuery("select pl.code from PlantLocation pl where pl.disabled=0 and pl.bePriorityWave=1"); - if(hqllist1.size()>0) { - hqlmaveloc=" CASE i.itemKey.lotInfo.propC2 "; - for(String sh:hqllist1) { - hqlmaveloc=hqlmaveloc+" WHEN '"+sh+"' THEN 1 "; - lcs=lcs+"'"+sh + "',"; - } - hqlmaveloc=hqlmaveloc+" ELSE 99 " + - " END ASC " ; - lcs=lcs.substring(0, lcs.length()-1); - - hql2=" order by i.itemKey.lotInfo.propD2,i.itemKey.lotInfo.propC3,i.itemKey.lotInfo.propC1,"+hqlmaveloc+",i.statuss desc,i.storageDate,i.quantity"; - } - } - - if(pt.getBillType()!=null&&pt.getBillType().getName().indexOf("其它")>=0) { - List cs=commonDao.findByQuery(" from Configuration c where c.configuration1='"+ - ptd.getNewLotInfo().getPropC2()+"' or c.configuration2='"+ptd.getNewLotInfo().getPropC2()+"' " ); - if(cs.size()>0) { - Configuration c=cs.get(0); - StringBuffer sb = new StringBuffer(); - if(c.getConfiguration1().length()>0) { - sb.append("'"+c.getConfiguration1() + "', "); - sb.append("'"+c.getConfiguration2() + "' "); - hql1+=" and i.itemKey.lotInfo.propC2 in("+sb.toString()+")"; - } - }else { - hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; - } - }else if(pt.getBillType()!=null&&pt.getBillType().getName().indexOf("工单")>=0) { - - if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC2()!=null - &&(!ptd.getNewLotInfo().getPropC2().equals("SL12")&&!ptd.getNewLotInfo().getPropC2().equals("")&& - !ptd.getNewLotInfo().getPropC2().equals("SL02") - &&!ptd.getNewLotInfo().getPropC2().equals("SL34"))) { - - hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; - - }else { - String bsql=" from BillTypeConfig b where b.billType.id="+pt.getBillType().getId(); - if(ptd.getNewLotInfo().getPropC9()!=null&&!ptd.getNewLotInfo().getPropC9().equals("")) { - bsql+=" and b.plantCode='"+ptd.getNewLotInfo().getPropC9()+"'"; - } - List bts=commonDao.findByQuery(bsql); - if(bts.size()>0) { - StringBuffer sb = new StringBuffer(); - for(int y1=0;y1<=bts.size()-1;y1++){ - BillTypeConfig bt=bts.get(y1); - if(y10) { - sb.append(","+lcs); - } - hql1+=" and i.itemKey.lotInfo.propC2 in("+sb.toString()+") "; - }else { - if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC2()!=null&&ptd.getNewLotInfo().getPropC2().length()>0) { - hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; - } - } - } - }else { - if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC2()!=null&&ptd.getNewLotInfo().getPropC2().length()>0) { - hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; - } - } - //指定序列号 -// if(ptd.getApplyDoc()!=null&&!ptd.getApplyDoc().equals("")) { -// hql1+=" and i.barCode='"+ptd.getApplyDoc()+"'"; -// } - //有限期 - if(ptd.getItem().getIsBOM()) { - hql1+=" and CONVERT(varchar(100), i.itemKey.lotInfo.propD2, 23)>='"+DateUtil.formatDateYMDToStr(new Date())+"'"; - } - - List Inventorys = commonDao.findByQuery( - hql1+hql2,new String[] { "id" },new Object[] { ptd.getItem().getId() }); - if (Inventorys.size() > 0) { - double allocatedQuantity = 0; - double unQty = ptd.getOrderQuantity()- ptd.getAllocatedQuantity();//未分配数量 - double allocateQty=0; - for (Inventory inventory : Inventorys) { - int j = 0; - if (unQty == 0) { - break; - } - allocateQty = inventory.getQuantity()- inventory.getQueuedQuantity();//可分配数量 - if (allocateQty == 0) { - continue; - } - if (unQty < allocateQty) { - allocateQty = unQty; - } - j++; - inventory.setQueuedQuantity(inventory.getQueuedQuantity()+ allocateQty); - inventory.setVersion(inventory.getVersion()); - commonDao.store(inventory); - allocatedQuantity += allocateQty; - unQty -= allocateQty; - ptd.setAllocatedQuantity(ptd.getAllocatedQuantity()+ allocateQty); - commonDao.store(ptd); - - Task task = EntityFactory.getEntity(Task.class); - task.setPickTicketDetail(ptd); - Item item=commonDao.load(Item.class, ptd.getItem().getId()); - task.setBillCode(getSubWorkOrer(ptd.getPickTicket().getCode(),inventory.getLocation().getZone(),item)); - //单个子任务数量 - if(qty>0) { - List tas=commonDao.findByQuery("select t.hs from PickTicketTaskView t where t.pickTicket.id="+ptd.getPickTicket().getId() - +" and t.billcode='"+task.getBillCode()+"' "); - if(tas.size()>0) { - //单个子任务数量 - if(tas.get(0)>=qty) { - task.setBillCode(bussinessCodeManager.getCodeForYmd(ptd.getPickTicket().getCode()+"-", 2)); - } - } - } - if (inventory.getLocation().getStock()!=null) { - task.setStrBill7(inventory.getLocation().getStock().getLP()); - } - String tItemCode=item.getCode().substring(0, 9); - String ptCode = ptd.getPickTicket().getCode(); - char lastChar = ptCode.charAt(ptCode.length() - 1); - if (Character.isUpperCase(lastChar)) { - //System.out.println("最后一位是大写字母"); - task.setStrBill8(tItemCode+lastChar); - } - task.setCode(TimeNumberUtils.getTaskCode()); - task.setType(TaskType.MV_PICKTICKET); - task.setItemKey(inventory.getItemKey()); - task.setStorageDate(inventory.getStorageDate()); - task.setSrcLoc(inventory.getLocation()); - task.setSOI(inventory.getSOI()); - task.setPlanQuantity(allocateQty); - task.setPlanQuantityMU(allocateQty); - task.setInventoryStatus(inventory.getStatus()); - task.setCreateTime(new Date()); - task.setWarehouseArea(inventory.getWarehouseArea()); - task.setBarCode(inventory.getBarCode()); - task.setSrcLP(inventory.getLocation().getStock()); - if(UserHolder.getUser()!=null) { - task.setOperator(UserHolder.getUser().getName()); - task.setStrBill3(UserHolder.getUser().getName()); - } - commonDao.store(task); - tasks.add(task); - } - if(unQty>0) { - msg=msg+ptd.getItem().getCode()+",库存不足! "; - } - - //修改为下发的回传状态 -// List pdids=new ArrayList(); -// pdids.add(ptd.getId()); -// interfaceReqManager.wmsSapZhuantaihuichuang(pdids, 0,"",1);//状态回传 - }else { - msg=msg+ptd.getItem().getCode()+",无匹配库存! "; - } -// shuaxinPick(pt);//刷新订单 - - }else{ - throw new BusinessException("任务状态错误!"); - } - } - invIds =new ArrayList(); - return tasks; - } - - @Override - public String preAllocateDate(Date beginDate, Date endDate) { - DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//日期格式 - List pickTickets=jdbcManager.getList(" select *from PICK_TICKET pt " - + "where CONVERT(VARCHAR(10),pt.ORDER_DATE,120)>='"+sdf.format(beginDate)+"' and CONVERT(VARCHAR(10),pt.ORDER_DATE,120)<='"+sdf.format(endDate)+"' "); - List ids=new ArrayList(); - for (Object[] pickTicket : pickTickets) { - ids.add(Long.valueOf(pickTicket[0]+"")); - } - if (ids.size()>0) { - preAllocatePO(ids); - }else { - throw new BusinessException("没有需要生成的预分配任务"); - } - return null; - } - - @Override - public void issuedAgvTask(List ids) { - /* for(Long id:ids){ - List Tasks = commonDao.findByQuery(" from Task t where t.waveDoc.id="+id+" "); - if(Tasks.size()>0){ - long qty= Tasks.size();//总订单数 - long lxQty=2;//料箱工作站 - long hjQty=2;//货架工作站 - int ave= Math.round(qty/(lxQty+hjQty));//平均值 - List Objects=jdbcManager.quertyGroupTask(pickTicketDetailIds);//每个库区有多少任务 - if(Objects.size()>0){ - for(int i=0;i Tasks = commonDao.findByQuery(" from Task t where t.agvTask.id=:id ", - new String[] { "id"},new Object[] {agvTask.getId()}); - if(Tasks.size()>0){ - for(Task t:Tasks){ - planQuantity+=t.getPlanQuantity(); - } - } - agvTask.setPlanQuantity(planQuantity); - commonDao.store(agvTask); - } - //波次下发AGV任务 - public void taskIssuedAgv(List ids) { - for(Long id:ids) { - WaveDoc w= commonDao.load(WaveDoc.class, id); - List tids=commonDao.findByQuery(" from Task t where t.agvStatus=0 and t.waveDoc.id= "+id); - Boolean beEnd=false; - for(Task t:tids) { - - PickTicketDetail ptd=commonDao.load(PickTicketDetail.class, t.getPickTicketDetail().getId()); - PickTicket pt=commonDao.load(PickTicket.class, ptd.getPickTicket().getId()); - pt.setStatus(PickTicketStatus.CHECK); - commonDao.store(pt); - t.setStrBill1(UserHolder.getUser().getName()); - t.setDateBill1(new Date()); - t.setAgvStatus(1);//1=可以分配分拨墙并下发AGV - t.setYc_qty(t.getPlanQuantityMU()); - commonDao.store(t); - w.setStatus("ALLOCATE"); - beEnd=true; - } - if(tids.size()==0) { - w.setStatus("ALLOCATE"); - } - //关闭未入波的数据 -// if(beEnd) { -// -// List list= commonDao.findByQuery("select p.id from PickTicket p where" -// + " p.pickedQuantity=0 and p.billType.code='GPUTPTC' and p.sourceType='261' " -// + " and p.status='OPEN' and p.id>=34797 "); -// if(list.size()>0) { -// wmsSapstatus(list, "",3) ; -// } -// -// } - commonDao.store(w); - } - } - - //加急单子生成料号信息 - public void UrgentOrderinfo(List list) { - //查询关闭的加急工单明细 - String ptdhql=" select ptd.id from PickTicketDetail ptd where ptd.pickTicket.id in("+list+")" - + " and ptd.SOI is not null and ptd.orderQuantity>0 "; - List ptdids=commonDao.findByQuery(ptdhql); - List ulist=commonDao.findByQuery(" from UrgentOrder "); - for(UrgentOrder u:ulist ) { - commonDao.delete(u); - } - if(ptdids.size()>0) { - //查询关闭的料号 - String hql=" select ptd.item.id from PickTicketDetail ptd where ptd.id in("+ptdids+")" - + " and ptd.SOI is not null and ptd.orderQuantity>0 " - + " group by ptd.item.id "; - List itemids=commonDao.findByQuery(hql); - - //查询关闭的料号是不否有库存 - String invhql="select inv.itemKey.item.id from Inventory inv where inv.itemKey.item.id in("+itemids+") " - +" and inv.quantity>inv.queuedQuantity and inv.quantity>0 " - + " and inv.itemKey.lotInfo.propC2 in(select bt.code from BillTypeConfig bt where bt.billType.id=1094)" - + " group by inv.itemKey.item.id "; - List invids=commonDao.findByQuery(invhql); - itemids.remove(invids); - if(itemids.size()>0) { - UrgentOrder uo=new UrgentOrder(); - for(Long id :itemids) { - Item item= commonDao.load(Item.class, id); - uo.setCode(item.getCode()); - uo.setStorageDate(new Date()); - commonDao.store(uo); - } - - } - } - } - - - - public void wmsSapstatus(List taskids,String TKST3,int status) { - JSONObject jsonobj = new JSONObject(); - JSONObject jsonobj1 = new JSONObject(); - jsonobj1.put("BIZTRANSACTIONID", ""); - jsonobj1.put("NAME", "PP009");//正式PP001 UAT测试PP009, - jsonobj1.put("COUNT", ""); - jsonobj1.put("CONSUMER", ""); - jsonobj1.put("ACCOUNT", ""); - jsonobj1.put("PASSWORD", ""); - jsonobj1.put("PAGENUM", ""); - jsonobj1.put("PAGESIZE", ""); - jsonobj1.put("MODULE", ""); - jsonobj.put("HEAD", jsonobj1); - if(taskids.size()>0) { - for (Long pid : taskids) { - PickTicket pt=commonDao.load(PickTicket.class, pid); - List ptds=commonDao.findByQuery(" from PickTicketDetail ptd where ptd.pickTicket.id="+pid); - PickTicketDetail ptd=null; - if(ptds.size()>0) { - ptd=ptds.get(0); - } - JSONArray array = new JSONArray(); - JSONObject jsonobj2 = new JSONObject(); - jsonobj2.put("TKIT1", ptd.getLineNumber() == null ? "" : ptd.getLineNumber() ); - jsonobj2.put("TKAL1", pt.getRelatedBill1() == null ? "" : pt.getRelatedBill1() ); - jsonobj2.put("TKFIQ", ptd.getOrderQuantity()); - jsonobj2.put("TKST3", TKST3);//取消分配传X - jsonobj2.put("TKNUM", "" ); - jsonobj2.put("WMSID", pt.getId()); - - if(status==0) { - jsonobj2.put("TKST1", "Active"); - }else if(status==1) { - jsonobj2.put("TKST1", "in process"); - }else if(status==2) { - jsonobj2.put("TKST1", "Finished-T"); - }else if(status==3) { - jsonobj2.put("TKST1", "Finished"); - } - jsonobj2.put("TKST2", ""); - array.add(jsonobj2); - jsonobj.put("INPUT", array); - - if(pt!=null&&pt.getCode().indexOf("CP")==-1&& - pt.getBillType().getId()==1094) { - String str= interfaceReqManager.doWmsReqSap(getPropertiesParm("ldxt.SAP")+ApiURL.doWmsReqSap, jsonobj.toString(),"状态"+pt.getCode()); - if(RESPONSE(str)) { - pt.setPrintCount(3); - pt.setStatus(PickTicketStatus.CLOSE); - commonDao.store(pt); - }else { - LocalizedMessage.addLocalizedMessage(pt.getCode()+"关闭失败"); - } - - } - } - - }else { - logger.info("无出库单明细"); - } - - } - public String getPropertiesParm(String obj) { - String parm = ""; - Properties prop = new Properties(); - InputStream in = this.getClass().getResourceAsStream("/hibernate.properties"); - try { - prop.load(in); - parm = prop.getProperty(obj).trim(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return parm; - } - - public boolean RESPONSE(String str) { - if(str!=null&&!str.equals("")) { - JSONObject json = JSONObject.fromObject(str); - String RESPONSE = json.has("RESPONSE") ? json.getString("RESPONSE") : ""; - JSONObject json2 = JSONObject.fromObject(RESPONSE); - String MSGTYPE = json2.has("MSGTYPE") ? json2.getString("MSGTYPE") : ""; - String MSGTEXT = json2.has("MSGTEXT") ? json2.getString("MSGTEXT") : ""; - if(MSGTYPE!=null&&(MSGTYPE.equals("S"))) { - return true; - }else { - return false; - } - } - - return false; - } - - - public void cancelallocateTaskAgv(List WaveDocIds) { - for(Long waveDocId:WaveDocIds) { - List lists=commonDao.findByQuery(" from Task t where t.waveDoc.id="+waveDocId); - for(Task t:lists) { - String billCode=""; - billCode=t.getBillCode(); - Location srcLocation=commonDao.load(Location.class, t.getSrcLoc().getId()); -// WarehouseArea zone=commonDao.load(WarehouseArea.class, srcLocation.getZone().getId()); - double quantity=t.getPlanQuantity()-t.getMovedQuantityMU();//退回数量 - PickTicketDetail ptd=commonDao.load(PickTicketDetail.class, t.getPickTicketDetail().getId()); - PickTicket pt=commonDao.load(PickTicket.class, ptd.getPickTicket().getId()); - //根据小task找到库存,并把占用数量退回。 - Inventory inventory=null; - String Inventory_Sql=" from Inventory i " - + " where 1=1 " - + " and i.location.id="+t.getSrcLoc().getId()+" " - + " and i.itemKey.id="+t.getItemKey().getId()+" " - + " and i.queuedQuantity>0 " - + " and i.status='已入库' "; - if(t.getBarCode()!=null&&t.getBarCode().length()>0){ - Inventory_Sql+=" and i.barCode='"+t.getBarCode()+"' "; - } - List Inventorys = commonDao.findByQuery(Inventory_Sql); - if(Inventorys.size()>0){ - inventory=Inventorys.get(0); - inventory.setQueuedQuantity(inventory.getQueuedQuantity()-quantity); - commonDao.store(inventory); - } - - t.setPlanQuantity(t.getPlanQuantity()-quantity); - t.setPlanQuantityMU(t.getPlanQuantity()); - t.setMovedQuantityMU(t.getPlanQuantity()); - commonDao.store(t); - ptd.setAllocatedQuantity(ptd.getAllocatedQuantity()-quantity); - commonDao.store(ptd); - //取消电子标签任务 - List InterWMStasks = commonDao.findByQuery(" from InterWMStask i where i.taskid='"+t.getCode()+"' "); - if(InterWMStasks.size()>0){ - InterWMStask iw=InterWMStasks.get(0); - List Itaskas = commonDao.findByQuery(" from InterWMStask i where i.addre='"+iw.getAddre()+"' "); - if(Itaskas.size()<=1) { - iw.setFlag("2"); - }else { - iw.setFlag("5"); - } - commonDao.store(iw); - } - /* - if(zone.getId()==1763) { - //容器返库 - if(srcLocation.getStock()!=null) { - logger.info("容器返库1"); - Stock stock= commonDao.load(Stock.class, srcLocation.getStock().getId()); - List tsks=commonDao.findByQuery(" from Task t where 1=1 " - + " and t.endRegion='"+t.getEndRegion()+"'" - + " and t.seedWall.id>0 " - + " and t.planQuantity>t.movedQuantityMU " - + " and t.agvTask.status='ATPICK' " - + " and t.srcLoc.stock.id="+stock.getId()+" "); - if(tsks.size()==0) { - Stock s=commonDao.load(Stock.class, srcLocation.getStock().getId()); - AgvTask agv=commonDao.load(AgvTask.class, t.getAgvTask().getId()); - if(agv.getStatus().equals("ATPICK")) { - interfaceReqManager.wcsNextPT(agv.getRobotJobId(), s.getLP(), WcsCSDCode.getWcsCSDCode(t.getEndRegion())); - logger.info("容器返库2"); - } - } - } - }else if(zone.getId()==1765){ - Stock stock= commonDao.load(Stock.class, srcLocation.getStock().getId()); - List tsks=commonDao.findByQuery(" from Task t where 1=1 " - + " and t.endRegion='"+t.getEndRegion()+"'" - + " and t.seedWall.id>0 " - + " and t.planQuantity>t.movedQuantityMU " - + " and t.agvTask.status='ATPICK' " - + " and t.srcLoc.stock.id="+stock.getId()); - if(tsks.size()==0) { - AgvTask agv=commonDao.load(AgvTask.class, t.getAgvTask().getId()); - agv.setType("货架返库"); - commonDao.store(agv); - interfaceReqManager.sendAgvTask(agv); - } - } - **/ - if(t.getPlanQuantity()==0){ - if( t.getSeedWall()!=null){ - SeedWall sw=commonDao.load(SeedWall.class, t.getSeedWall().getId()); - if (sw != null) { - sw.setTaskCode(null); - commonDao.store(sw); - } - } - commonDao.delete(t); - } - shuaxinPick(pt);//刷新出库单 - if(inventory!=null){ - ItemKey ik=commonDao.load(ItemKey.class,inventory.getItemKey().getId()); - BillType bt=commonDao.load(BillType.class,pt.getBillType().getId()); - Location loc=commonDao.load(Location.class,inventory.getLocation().getId()); - inventoryManager.addInventoryLog(InventoryLogType.COMPANY_TRANS_IN, 1, pt.getCode(), loc, null, - ik, inventory.getStorageDate(), inventory.getSOI(), quantity, null, - inventory.getStatus(), inventory.getId(), "取消分配", bt, UserHolder.getUser().getId(), inventory.getBarCode(), - loc,pt.getSourceType()); - } - - //回传SAP - if(true) { - if (pt.getCode().indexOf("CP") == -1&&((pt.getSourceId()!=null&&pt.getSourceId().indexOf("OT")== -1) - || pt.getSourceId()==null )) { - //已经拣货完成的 - List tasks1 = commonDao.findByQuery( - "select p.id from Task p where p.movedQuantityMU>0 and p.movedQuantityMU=p.planQuantity and p.popular=0 " - + " and p.pickTicketDetail.pickTicket.id=" + pt.getId() + " and p.billCode='" - + billCode + "'"); - //未回传的 - List tasks2 = commonDao.findByQuery("select p.id from Task p where p.billCode='" + billCode - + "' and p.popular=0 " + " and p.pickTicketDetail.pickTicket.id=" + pt.getId()); - logger.info(tasks1.size() + "-----" + tasks2.size()); - // 是否回传SAP,其他出库不出WMS仓,出库完成不用回传,自动生成入库单,入库完成后在回传。 - BillType bt = commonDao.load(BillType.class, pt.getBillType().getId()); - if (tasks1.size() > 0 && tasks1.size() == tasks2.size()) { - - if (bt.getCode().equals("YINVENTORY")) { - // 是否转库出库 - if (ptd.getStrBill8() != null && ptd.getStrBill8().equals("X")) { - interfaceReqManager.wmsSapFaliaohuichuang(tasks1); - } - } else if(bt.getCode().equals("OAPUTPTC")){ - - boolean dl= interfaceReqManager.wmsOaFaliaohuichuang(tasks1); - - }else{ - boolean dl= interfaceReqManager.wmsSapFaliaohuichuang(tasks1); - if(bt.getCode().equals("GPUTPTC")&&dl) { - interfaceReqManager.wmsSapTaskStatus(tasks1, "", 2); - - } - } - } - //所有子任务 - List tasks4 = commonDao.findByQuery( - "select p.id from Task p where " - + " p.pickTicketDetail.pickTicket.id=" + pt.getId() + " and p.billCode='" - + billCode + "'"); - if(tasks4.size()==0) { - if(bt.getCode().equals("GPUTPTC")) { - interfaceReqManager.wmsSapCancelStatus(ptd.getSourceId() == null ? "" : ptd.getSourceId(), ptd.getStrBill1() == null ? "" : ptd.getStrBill1(), - "0", billCode, "", 2); - List tasks3 = commonDao.findByQuery("select p.id from Task p where p.pickTicketDetail.pickTicket.id=" + pt.getId()); - if(tasks3.size()==0) { - interfaceReqManager.wmsSapCancelStatus(ptd.getSourceId() == null ? "" : ptd.getSourceId(), ptd.getStrBill1() == null ? "" : ptd.getStrBill1(), - "0", billCode, "", 3); - - pt.setPrintCount(3); - commonDao.store(pt); - } - }else if(bt.getCode().equals("OAPUTPTC")){ - List ptdds=new ArrayList(); - ptdds.add(pt.getId()); - boolean dl= interfaceReqManager.wmsOaFaliaoStatus(ptdds); - if(dl) { - pt.setPrintCount(3); - commonDao.store(pt); - } - } - } - - } - } - if(t!=null&&t.getWaveDoc()!=null) { - String shy="select t.id from Task t where t.waveDoc.id=" +t.getWaveDoc().getId() - +" and t.planQuantityMU>0 and t.planQuantity>0 and t.movedQuantityMU=0 "; - List tlist=commonDao.findByQuery(shy); - if(tlist.size()==0) { - WaveDoc wd=commonDao.load(WaveDoc.class, t.getWaveDoc().getId()); - wd.setStatus(WaveDocStatus.PICK_ALL);//拣货完成 - commonDao.store(wd); - } - } - - } - - } - } - - @Override - public void cancelTask(List taskIds) { - - for(Long id:taskIds){ - - Task t=commonDao.load(Task.class, id); - PickTicketDetail ptd=commonDao.load(PickTicketDetail.class, t.getPickTicketDetail().getId()); - - if (t.getPlanQuantity()>t.getMovedQuantityMU()) { - //根据小task找到库存,并把占用数量退回。 - Inventory inventory=null; - List Inventorys = commonDao.findByQuery(" from Inventory i where i.quantity>0 and i.queuedQuantity>0 and i.location.id=:locationId and i.itemKey.id=:itemKeyId ", - new String[] { "locationId","itemKeyId"},new Object[] {t.getSrcLoc().getId(),t.getItemKey().getId()}); - if(Inventorys.size()>0){ - inventory=Inventorys.get(0); - inventory.setQueuedQuantity(inventory.getQueuedQuantity()-t.getPlanQuantity()); - inventory.setVersion(inventory.getVersion()); - commonDao.store(inventory); - } - - //清空电子标签记录 - InterWMStask iw=null; - List InterWMStasks = commonDao.findByQuery(" from InterWMStask iw where iw.taskid=:code ", - new String[] { "code"},new Object[] {t.getCode()}); - if(InterWMStasks.size()>0){ - iw=InterWMStasks.get(0); - iw.setFlag("5"); - commonDao.store(iw); - } - - ptd.setAllocatedQuantity(ptd.getAllocatedQuantity()-t.getPlanQuantity()); - commonDao.store(ptd); - if(t.getAgvTask()!=null) { - AgvTask agv=commonDao.load(AgvTask.class, t.getAgvTask().getId()); - - if(agv.isBeIssue()) { - - }else { - commonDao.delete(t); - } - }else { - commonDao.delete(t); - } - - } - - shuaxinPick(ptd.getPickTicket());//刷新出库单 - } - - } - - //加急出库无库存的流程 - public void addPickTicketTask(Long asnid,Long userId) { - ASNDetail ad=commonDao.load(ASNDetail.class, asnid); - if(ad!=null&&ad.getStrBill11()!=null&&ad.getStrBill11().equals("1")) { - if(ad.getStrBill12()!=null&&!ad.getStrBill12().equals("")) { - PickTicketDetail ptd=commonDao.load(PickTicketDetail.class, Long.parseLong(ad.getStrBill12())); - if(ptd!=null) { - String msg=""; - List tasks=new ArrayList(); - PickTicket pt=ptd.getPickTicket(); - //分配库存 - String hql1=" from Inventory i where i.itemKey.item.id=:id and i.location.type='存货'" - + "and i.status='已入库' and i.quantity-i.queuedQuantity>0 and i.counPlan is null " - + " and i.location.zone.carrierType.type='人工' "; - - //自动创波,ddq1=3#不良品区,ddq2=3#焊接件区,ddq3=3#货架区,ddq4=3#料箱区,ddq5=7#3楼普通库, - //ddq6=7#4楼普通库,ddq7=7#地堆区,ddq8=7#堆垛库,ddq9=8#化学品区 - - - if(ptd.getNewLotInfo()!=null) { - if(ptd.getNewLotInfo().getPropC1()!=null&&!ptd.getNewLotInfo().getPropC1().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC1='"+ptd.getNewLotInfo().getPropC1()+"'"; - } -// if(ptd.getNewLotInfo().getPropC2()!=null&&!ptd.getNewLotInfo().getPropC2().equals("")) { -// hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; -// }else { -// -// } - if(ptd.getNewLotInfo().getPropC3()!=null&&!ptd.getNewLotInfo().getPropC3().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC3='"+ptd.getNewLotInfo().getPropC3()+"'"; - }else { - if(ptd.getStrExtend2()!=null&&(ptd.getStrExtend2().equals("TRUE")||ptd.getStrExtend2().equals("true"))) { - hql1+=" and i.itemKey.lotInfo.propC3='K' "; - } - } - if(ptd.getNewLotInfo().getPropC4()!=null&&!ptd.getNewLotInfo().getPropC4().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC4='"+ptd.getNewLotInfo().getPropC4()+"'"; - } - if(ptd.getNewLotInfo().getPropC4()!=null&&!ptd.getNewLotInfo().getPropC4().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC4='"+ptd.getNewLotInfo().getPropC4()+"'"; - } - if(ptd.getNewLotInfo().getPropC5()!=null&&!ptd.getNewLotInfo().getPropC5().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC5='"+ptd.getNewLotInfo().getPropC5()+"'"; - } - if(ptd.getNewLotInfo().getPropC6()!=null&&!ptd.getNewLotInfo().getPropC6().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC6='"+ptd.getNewLotInfo().getPropC6()+"'"; - } - if(ptd.getNewLotInfo().getPropC7()!=null&&!ptd.getNewLotInfo().getPropC7().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC7='"+ptd.getNewLotInfo().getPropC7()+"'"; - } - if(ptd.getNewLotInfo().getPropC8()!=null&&!ptd.getNewLotInfo().getPropC8().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC8='"+ptd.getNewLotInfo().getPropC8()+"'"; - } - if(ptd.getNewLotInfo().getPropC9()!=null&&!ptd.getNewLotInfo().getPropC9().equals("")) { - hql1+=" and i.itemKey.lotInfo.propC9='"+ptd.getNewLotInfo().getPropC9()+"'"; - } - }else { - - } - if(pt.getBillType()!=null&&pt.getBillType().getName().indexOf("其它")>=0) { - List cs=commonDao.findByQuery(" from Configuration c where c.configuration1='"+ - ptd.getNewLotInfo().getPropC2()+"' or c.configuration2='"+ptd.getNewLotInfo().getPropC2()+"' " ); - if(cs.size()>0) { - Configuration c=cs.get(0); - StringBuffer sb = new StringBuffer(); - if(c.getConfiguration1().length()>0) { - sb.append("'"+c.getConfiguration1() + "', "); - sb.append("'"+c.getConfiguration2() + "' "); - hql1+=" and i.itemKey.lotInfo.propC2 in("+sb.toString()+")"; - } - }else { - hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; - } - }else if(pt.getBillType()!=null&&pt.getBillType().getName().indexOf("工单")>=0) { - - if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC2()!=null - &&(!ptd.getNewLotInfo().getPropC2().equals("SL12")&&!ptd.getNewLotInfo().getPropC2().equals("")&& - !ptd.getNewLotInfo().getPropC2().equals("SL02") - &&!ptd.getNewLotInfo().getPropC2().equals("SL34"))) { - - hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; - - }else { - String shq=" from BillTypeConfig b where b.billType.id="+pt.getBillType().getId(); - if(ptd.getNewLotInfo().getPropC9()!=null&&!ptd.getNewLotInfo().getPropC9().equals("")) { - shq+=" and b.plantCode='"+ptd.getNewLotInfo().getPropC9()+"'"; - } - List bts=commonDao.findByQuery(shq); - if(bts.size()>0) { - StringBuffer sb = new StringBuffer(); - for(int i=0;i<=bts.size()-1;i++){ - BillTypeConfig bt=bts.get(i); - if(i0) { - hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; - } - } - } - }else { - if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC2()!=null&&ptd.getNewLotInfo().getPropC2().length()>0) { - hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; - } - } - - //料号有效期管理 - if(ptd.getItem().getIsBOM()) { - hql1+=" and CONVERT(varchar(100), i.itemKey.lotInfo.propD2, 23)>='"+DateUtil.formatDateYMDToStr(new Date())+"'"; - } - - hql1+=" order by i.itemKey.lotInfo.propD2,i.itemKey.lotInfo.propC3,i.itemKey.lotInfo.propC1,i.statuss desc,i.storageDate,i.quantity"; - - List Inventorys = commonDao.findByQuery( - hql1,new String[] { "id" },new Object[] { ptd.getItem().getId() }); - if (Inventorys.size() > 0) { - double allocatedQuantity = 0; - double unQty = ptd.getOrderQuantity()- ptd.getAllocatedQuantity();//未分配数量 - double allocateQty=0; - for (Inventory inventory : Inventorys) { - int j = 0; - if (unQty <= 0) { - break; - } - allocateQty = inventory.getQuantity()- inventory.getQueuedQuantity();//可分配数量 - if (allocateQty == 0) { - continue; - } - if (unQty < allocateQty) { - allocateQty = unQty; - } - j++; - inventory.setQueuedQuantity(inventory.getQueuedQuantity()+ allocateQty); - inventory.setVersion(inventory.getVersion()); - commonDao.store(inventory); - allocatedQuantity += allocateQty; - unQty -= allocateQty; - ptd.setAllocatedQuantity(ptd.getAllocatedQuantity()+ allocateQty); - commonDao.store(ptd); - - Task task = EntityFactory.getEntity(Task.class); - task.setPickTicketDetail(ptd); - Item item=commonDao.load(Item.class, ptd.getItem().getId()); - task.setBillCode(getSubWorkOrer(ptd.getPickTicket().getCode(),inventory.getLocation().getZone(),item)); - - task.setCode(TimeNumberUtils.getTaskCode()); - task.setType(TaskType.MV_PICKTICKET); - task.setItemKey(inventory.getItemKey()); - task.setStorageDate(inventory.getStorageDate()); - task.setSrcLoc(inventory.getLocation()); - task.setSOI(inventory.getSOI()); - task.setPlanQuantity(allocateQty); - task.setPlanQuantityMU(allocateQty); - task.setInventoryStatus(inventory.getStatus()); - task.setCreateTime(new Date()); - task.setWarehouseArea(inventory.getWarehouseArea()); - task.setBarCode(inventory.getBarCode()); - task.setSrcLP(inventory.getLocation().getStock()); - task.setAgvStatus(1); - Worker w=commonDao.load(Worker.class, userId); - if(w!=null) { - task.setOperator(w.getName()); - task.setStrBill3(w.getName()); - task.setWorker1(w); - if(task.getAgvStatus()==0) { - task.setAgvStatus(1); - } - } - commonDao.store(task); - tasks.add(task); - } - if(unQty>0) { - msg=msg+ptd.getItem().getCode()+",库存不足! "; - } - - }else { - msg=msg+ptd.getItem().getCode()+",无匹配库存! "; - } - //修改为下发的回传状态 - if(tasks.size()>0) { - interfaceReqManager.wmsSapZhuantaihuichuang(tasks, 0,"",1);//状态回传 - } - shuaxinPick(pt);//刷新订单 - } - } - } - } - - - - - -} - - diff --git a/src/main/java/com/dev/swms/server/service/picking/allocate/NewAutoAllocator.java b/src/main/java/com/dev/swms/server/service/picking/allocate/NewAutoAllocator.java new file mode 100644 index 0000000..04c74d8 --- /dev/null +++ b/src/main/java/com/dev/swms/server/service/picking/allocate/NewAutoAllocator.java @@ -0,0 +1,37 @@ +package com.dev.swms.server.service.picking.allocate; + +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import org.springframework.transaction.annotation.Transactional; + +import com.dev.swms.server.model.abstractEntity.AbstractMoveDoc; +import com.dev.swms.server.model.abstractEntity.AbstractMoveDocDetail; +import com.dev.swms.server.model.base.BillType; +import com.dev.swms.server.model.base.Item; +import com.dev.swms.server.model.base.LotInfo; +import com.dev.swms.server.model.base.Structure; +import com.dev.swms.server.model.base.PackageUnit; +import com.dev.swms.server.model.inventory.AgvTask; +import com.dev.swms.server.model.inventory.ProcessDocBOMDetail; +import com.dev.swms.server.model.inventory.Task; +import com.dev.swms.server.model.rules.PickItemRule; +import com.dev.swms.server.model.shipping.PickTicket; +import com.dev.swms.server.model.shipping.PickTicketDetail; +import com.dev.energy.server.service.BaseManager; + +/** + * @author dev + */ +@Transactional(readOnly = true) +public interface NewAutoAllocator extends BaseManager { + //订单明细分配 + //自动创波,ddq1=3#不良品区,ddq2=3#焊接件区,ddq3=3#货架区,ddq4=3#料箱区,ddq5=7#3楼普通库, + //ddq6=7#4楼普通库,ddq7=7#地堆区,ddq8=#堆垛库,ddq9=8#化学品区 + @Transactional + List allocatePickticketDetail(List ids,int qty,boolean ddq,boolean ddq1, + boolean ddq2,boolean ddq3,boolean ddq4,boolean ddq5,boolean ddq6,boolean ddq7, + boolean ddq8,boolean ddq9,String noLoc); +} diff --git a/src/main/java/com/dev/swms/server/service/picking/allocate/NewDefaultAutoAllocator.java b/src/main/java/com/dev/swms/server/service/picking/allocate/NewDefaultAutoAllocator.java new file mode 100644 index 0000000..9c7a83a --- /dev/null +++ b/src/main/java/com/dev/swms/server/service/picking/allocate/NewDefaultAutoAllocator.java @@ -0,0 +1,459 @@ +package com.dev.swms.server.service.picking.allocate; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +import org.apache.commons.beanutils.BeanComparator; +import org.apache.commons.collections.comparators.ComparatorChain; +import org.apache.commons.collections.comparators.ReverseComparator; +import org.apache.commons.lang.StringUtils; + +import com.dev.swms.server.model.abstractEntity.AbstractMoveDoc; +import com.dev.swms.server.model.abstractEntity.AbstractMoveDocDetail; +import com.dev.swms.server.model.base.BillType; +import com.dev.swms.server.model.base.BillTypeConfig; +import com.dev.swms.server.model.base.CompanyCode; +import com.dev.swms.server.model.base.Item; +import com.dev.swms.server.model.base.ItemKey; +import com.dev.swms.server.model.base.Location; +import com.dev.swms.server.model.base.LocationStorage; +import com.dev.swms.server.model.base.LotInfo; +import com.dev.swms.server.model.base.NewLotInfo; +import com.dev.swms.server.model.base.Structure; +import com.dev.swms.server.model.base.PackageUnit; +import com.dev.swms.server.model.base.ShiXiao; +import com.dev.swms.server.model.base.TurnOverMode; +import com.dev.swms.server.model.base.Warehouse; +import com.dev.swms.server.model.base.WarehouseArea; +import com.dev.swms.server.model.base.WarehouseAreaStatus; +import com.dev.swms.server.model.base.Worker; +import com.dev.swms.server.model.delivery.UrgentOrder; +import com.dev.swms.server.model.inventory.AgvTask; +import com.dev.swms.server.model.inventory.Configuration; +import com.dev.swms.server.model.inventory.Inventory; +import com.dev.swms.server.model.inventory.InventoryLogType; +import com.dev.swms.server.model.inventory.ItemKeyInventory; +import com.dev.swms.server.model.inventory.ProcessDoc; +import com.dev.swms.server.model.inventory.ProcessDocBOMDetail; +import com.dev.swms.server.model.inventory.Stock; +import com.dev.swms.server.model.inventory.Task; +import com.dev.swms.server.model.inventory.TaskType; +import com.dev.swms.server.model.receiving.ASN; +import com.dev.swms.server.model.receiving.ASNDetail; +import com.dev.swms.server.model.receiving.InterWMStask; +import com.dev.swms.server.model.receiving.MoveDoc; +import com.dev.swms.server.model.receiving.MoveDocDetail; +import com.dev.swms.server.model.receiving.MoveDocStatus; +import com.dev.swms.server.model.receiving.ReceivedRecord; +import com.dev.swms.server.model.receiving.STATUS; +import com.dev.swms.server.model.rules.ItemStorageRule; +import com.dev.swms.server.model.rules.PickItemRule; +import com.dev.swms.server.model.rules.PickMethod; +import com.dev.swms.server.model.rules.SortRule; +import com.dev.swms.server.model.shipping.LotQuantity; +import com.dev.swms.server.model.shipping.PickTicket; +import com.dev.swms.server.model.shipping.PickTicketDetail; +import com.dev.swms.server.model.shipping.PickTicketStatus; +import com.dev.swms.server.model.shipping.PreAllocate; +import com.dev.swms.server.model.shipping.SeedWall; +import com.dev.swms.server.model.shipping.WaveDoc; +import com.dev.swms.server.model.shipping.WaveDocDetail; +import com.dev.swms.server.model.shipping.WaveDocStatus; +import com.dev.swms.server.service.GlobalParamUtils; +import com.dev.swms.server.service.base.AgvTaskManager; +import com.dev.swms.server.service.base.ItemManager; +import com.dev.swms.server.service.interfaceLog.ApiURL; +import com.dev.swms.server.service.interfaceLog.InterfaceManager; +import com.dev.swms.server.service.interfaceLog.InterfaceReqManager; +import com.dev.swms.server.service.interfaceLog.JdbcManager; +import com.dev.swms.server.service.interfaceLog.WcsCSDCode; +import com.dev.swms.server.service.inventory.InventoryManager; +import com.dev.swms.server.service.receiving.PutawayAllocator; +import com.dev.swms.server.service.sequence.BussinessCodeManager; +import com.dev.swms.server.utils.DateUtil; +import com.dev.swms.server.utils.DoubleUtils; +import com.dev.swms.server.utils.NewLotInfoParser; +import com.dev.swms.server.utils.TimeNumberUtils; +import com.dev.swms.server.web.filter.WarehouseHolder; +import com.dev.energy.server.exception.BusinessException; +import com.dev.energy.server.model.EntityFactory; +import com.dev.energy.server.service.pojo.DefaultBaseManager; +import com.dev.energy.server.util.LocalizedMessage; +import com.dev.energy.server.web.security.UserHolder; + +import org.apache.log4j.Logger; +/** + * @author dev + * + */ +public class NewDefaultAutoAllocator extends DefaultBaseManager implements NewAutoAllocator { + protected final ItemManager itemManager; + protected final InventoryManager inventoryManager; + protected final BussinessCodeManager bussinessCodeManager; + protected final PutawayAllocator putawayAllocator; + private Long warehouseId; + protected final InterfaceManager interfaceManager; + protected final JdbcManager jdbcManager; + protected final AgvTaskManager agvTaskManager; + protected final InterfaceReqManager interfaceReqManager; + private static Logger logger = Logger.getLogger(DefaultAutoAllocator.class); + + + public NewDefaultAutoAllocator(ItemManager manager,InventoryManager manager1, + BussinessCodeManager manager2, PutawayAllocator allocator,InterfaceManager interfaceManager2,JdbcManager jdbcManager2,AgvTaskManager agvTaskManager, + InterfaceReqManager interfaceReqManager) { + itemManager = manager; + inventoryManager = manager1; + bussinessCodeManager = manager2; + putawayAllocator = allocator; + interfaceManager=interfaceManager2; + jdbcManager=jdbcManager2; + this.agvTaskManager=agvTaskManager; + this.interfaceReqManager=interfaceReqManager; + } + /** 当前输送线库存*/ + private List invIds=new ArrayList(); + @Override + public List allocatePickticketDetail(List ids,int qty,boolean ddq,boolean ddq1,boolean ddq2,boolean ddq3, + boolean ddq4,boolean ddq5,boolean ddq6,boolean ddq7,boolean ddq8,boolean ddq9,String noLoc) { + if (invIds.size()==0) { + invIds=inventoryManager.selectSSXInventory(); + } + String msg=""; + List tasks=new ArrayList(); + for (int i = 0; i < ids.size(); i++) { + Long id=Long.valueOf(ids.get(i)+""); + + PickTicketDetail ptd= commonDao.load(PickTicketDetail.class, id); + if(ptd.getOrderQuantity()- ptd.getAllocatedQuantity()<=0) { + continue; + } + Date date=new Date(); + if(ptd.getStrBill6()==null||ptd.getStrBill6().length()<=0){ + PickTicket pt=ptd.getPickTicket(); + //分配库存 + String hql1=" from Inventory i where i.itemKey.item.id=:id and i.location.type='存货'" + + "and i.status='已入库' and i.quantity-i.queuedQuantity>0 and i.counPlan is null " + + " "; + //不能入波的LOC + if(noLoc!=null&&!noLoc.equals("")) { + hql1+=" and i.itemKey.lotInfo.propC2 not in("+noLoc+")"; + } + //自动创波,ddq1=3#不良品区,ddq2=3#焊接件区,ddq3=3#货架区,ddq4=3#料箱区,ddq5=7#3楼普通库, + //ddq6=7#4楼普通库,ddq7=7#地堆区,ddq8=7#堆垛库,ddq9=8#化学品区 + String kqno=""; + if(!ddq1) { + kqno+="1798,"; + } + if(!ddq2) { + kqno+="1773,"; + } + if(!ddq3) { + kqno+="1765,"; + } + if(!ddq4) { + kqno+="1763,"; + } + if(!ddq5) { + kqno+="1768,"; + } + if(!ddq6) { + kqno+="1783,"; + } + if(!ddq7) { + kqno+="1808,"; + } + if(!ddq8) { + kqno+="1766,"; + } + if(!ddq9) { + kqno+="1799,"; + } + if(kqno.length()>0) { + kqno=kqno.substring(0, kqno.length()-1); + hql1+=" and i.location.zone.id not in("+kqno+") "; + } + if(ddq&&ptd.getPickTicket().getOrderDate().getTime()>=date.getTime()) { + hql1+=" and i.location.zone.id not in(1808) "; + } + + if(ptd.getNewLotInfo()!=null) { + if(ptd.getNewLotInfo().getPropC1()!=null&&!ptd.getNewLotInfo().getPropC1().equals("")) { + hql1+=" and i.itemKey.lotInfo.propC1='"+ptd.getNewLotInfo().getPropC1()+"'"; + } + +// if(ptd.getNewLotInfo().getPropC2()!=null&&!ptd.getNewLotInfo().getPropC2().equals("")) { +// hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; +// }else { +// +// } + if(ptd.getNewLotInfo().getPropC3()!=null&&!ptd.getNewLotInfo().getPropC3().equals("")) { + hql1+=" and i.itemKey.lotInfo.propC3='"+ptd.getNewLotInfo().getPropC3()+"'"; + }else { + if(ptd.getStrExtend2()!=null&&(ptd.getStrExtend2().equals("TRUE")||ptd.getStrExtend2().equals("true"))) { + hql1+=" and i.itemKey.lotInfo.propC3='K' "; + } + } + if(ptd.getNewLotInfo().getPropC4()!=null&&!ptd.getNewLotInfo().getPropC4().equals("")) { + hql1+=" and i.itemKey.lotInfo.propC4='"+ptd.getNewLotInfo().getPropC4()+"'"; + } + if(ptd.getNewLotInfo().getPropC4()!=null&&!ptd.getNewLotInfo().getPropC4().equals("")) { + hql1+=" and i.itemKey.lotInfo.propC4='"+ptd.getNewLotInfo().getPropC4()+"'"; + } + if(ptd.getNewLotInfo().getPropC5()!=null&&!ptd.getNewLotInfo().getPropC5().equals("")) { + hql1+=" and i.itemKey.lotInfo.propC5='"+ptd.getNewLotInfo().getPropC5()+"'"; + } + if(ptd.getNewLotInfo().getPropC6()!=null&&!ptd.getNewLotInfo().getPropC6().equals("")) { + hql1+=" and i.itemKey.lotInfo.propC6='"+ptd.getNewLotInfo().getPropC6()+"'"; + } + if(ptd.getNewLotInfo().getPropC7()!=null&&!ptd.getNewLotInfo().getPropC7().equals("")) { + hql1+=" and i.itemKey.lotInfo.propC7='"+ptd.getNewLotInfo().getPropC7()+"'"; + } + if(ptd.getNewLotInfo().getPropC8()!=null&&!ptd.getNewLotInfo().getPropC8().equals("")) { + hql1+=" and i.itemKey.lotInfo.propC8='"+ptd.getNewLotInfo().getPropC8()+"'"; + } + if(ptd.getNewLotInfo().getPropC9()!=null&&!ptd.getNewLotInfo().getPropC9().equals("")) { + hql1+=" and i.itemKey.lotInfo.propC9='"+ptd.getNewLotInfo().getPropC9()+"'"; + } + }else { + + } + StringBuffer sqlBuffer=new StringBuffer(); + sqlBuffer.append(" order by "); + if (invIds.size()>0) { + StringBuilder sb = new StringBuilder(); + for (int k = 0; k < invIds.size(); k++) { + sb.append(invIds.get(k)); + if (k < invIds.size() - 1) { + sb.append(","); + } + } + sqlBuffer.append(" CASE " + +" WHEN i.id IN (" + + sb.toString() + +") THEN 1 " + +" ELSE 0 " + +" END, "); + } + sqlBuffer.append(" i.itemKey.lotInfo.propD2,i.itemKey.lotInfo.propC3,i.itemKey.lotInfo.propC1,i.statuss desc,i.storageDate,i.quantity,i.id"); + String hql2=sqlBuffer.toString(); + //排序 + String lcs = new String(); + if(pt.getBillType()!=null&&pt.getBillType().getName().indexOf("工单")>=0 + &&ptd.getStrBill12()!=null&&(!ptd.getStrBill12().equals("881")&& + !ptd.getStrBill12().equals("981"))) { + String hqlmaveloc=" ";//优先入波的LOC + List hqllist1=commonDao.findByQuery("select pl.code from PlantLocation pl where pl.disabled=0 and pl.bePriorityWave=1"); + if(hqllist1.size()>0) { + hqlmaveloc=" CASE i.itemKey.lotInfo.propC2 "; + for(String sh:hqllist1) { + hqlmaveloc=hqlmaveloc+" WHEN '"+sh+"' THEN 1 "; + lcs=lcs+"'"+sh + "',"; + } + hqlmaveloc=hqlmaveloc+" ELSE 99 " + + " END ASC " ; + lcs=lcs.substring(0, lcs.length()-1); + + hql2=" order by i.itemKey.lotInfo.propD2,i.itemKey.lotInfo.propC3,i.itemKey.lotInfo.propC1,"+hqlmaveloc+",i.statuss desc,i.storageDate,i.quantity"; + } + } + + if(pt.getBillType()!=null&&pt.getBillType().getName().indexOf("其它")>=0) { + List cs=commonDao.findByQuery(" from Configuration c where c.configuration1='"+ + ptd.getNewLotInfo().getPropC2()+"' or c.configuration2='"+ptd.getNewLotInfo().getPropC2()+"' " ); + if(cs.size()>0) { + Configuration c=cs.get(0); + StringBuffer sb = new StringBuffer(); + if(c.getConfiguration1().length()>0) { + sb.append("'"+c.getConfiguration1() + "', "); + sb.append("'"+c.getConfiguration2() + "' "); + hql1+=" and i.itemKey.lotInfo.propC2 in("+sb.toString()+")"; + } + }else { + hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; + } + }else if(pt.getBillType()!=null&&pt.getBillType().getName().indexOf("工单")>=0) { + + if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC2()!=null + &&(!ptd.getNewLotInfo().getPropC2().equals("SL12")&&!ptd.getNewLotInfo().getPropC2().equals("")&& + !ptd.getNewLotInfo().getPropC2().equals("SL02") + &&!ptd.getNewLotInfo().getPropC2().equals("SL34"))) { + + hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; + + }else { + String bsql=" from BillTypeConfig b where b.billType.id="+pt.getBillType().getId(); + if(ptd.getNewLotInfo().getPropC9()!=null&&!ptd.getNewLotInfo().getPropC9().equals("")) { + bsql+=" and b.plantCode='"+ptd.getNewLotInfo().getPropC9()+"'"; + } + List bts=commonDao.findByQuery(bsql); + if(bts.size()>0) { + StringBuffer sb = new StringBuffer(); + for(int y1=0;y1<=bts.size()-1;y1++){ + BillTypeConfig bt=bts.get(y1); + if(y10) { + sb.append(","+lcs); + } + hql1+=" and i.itemKey.lotInfo.propC2 in("+sb.toString()+") "; + }else { + if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC2()!=null&&ptd.getNewLotInfo().getPropC2().length()>0) { + hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; + } + } + } + }else { + if(ptd.getNewLotInfo()!=null&&ptd.getNewLotInfo().getPropC2()!=null&&ptd.getNewLotInfo().getPropC2().length()>0) { + hql1+=" and i.itemKey.lotInfo.propC2='"+ptd.getNewLotInfo().getPropC2()+"'"; + } + } + //指定序列号 +// if(ptd.getApplyDoc()!=null&&!ptd.getApplyDoc().equals("")) { +// hql1+=" and i.barCode='"+ptd.getApplyDoc()+"'"; +// } + //有限期 + if(ptd.getItem().getIsBOM()) { + hql1+=" and CONVERT(varchar(100), i.itemKey.lotInfo.propD2, 23)>='"+DateUtil.formatDateYMDToStr(new Date())+"'"; + } + + List Inventorys = commonDao.findByQuery( + hql1+hql2,new String[] { "id" },new Object[] { ptd.getItem().getId() }); + if (Inventorys.size() > 0) { + double allocatedQuantity = 0; + double unQty = ptd.getOrderQuantity()- ptd.getAllocatedQuantity();//未分配数量 + double allocateQty=0; + for (Inventory inventory : Inventorys) { + int j = 0; + if (unQty == 0) { + break; + } + allocateQty = inventory.getQuantity()- inventory.getQueuedQuantity();//可分配数量 + if (allocateQty == 0) { + continue; + } + if (unQty < allocateQty) { + allocateQty = unQty; + } + j++; + inventory.setQueuedQuantity(inventory.getQueuedQuantity()+ allocateQty); + inventory.setVersion(inventory.getVersion()); + commonDao.store(inventory); + allocatedQuantity += allocateQty; + unQty -= allocateQty; + ptd.setAllocatedQuantity(ptd.getAllocatedQuantity()+ allocateQty); + commonDao.store(ptd); + + Task task = EntityFactory.getEntity(Task.class); + task.setPickTicketDetail(ptd); + Item item=commonDao.load(Item.class, ptd.getItem().getId()); + task.setBillCode(getSubWorkOrer(ptd.getPickTicket().getCode(),inventory.getLocation().getZone(),item)); + //单个子任务数量 + if(qty>0) { + List tas=commonDao.findByQuery("select t.hs from PickTicketTaskView t where t.pickTicket.id="+ptd.getPickTicket().getId() + +" and t.billcode='"+task.getBillCode()+"' "); + if(tas.size()>0) { + //单个子任务数量 + if(tas.get(0)>=qty) { + task.setBillCode(bussinessCodeManager.getCodeForYmd(ptd.getPickTicket().getCode()+"-", 2)); + } + } + } + if (inventory.getLocation().getStock()!=null) { + task.setStrBill7(inventory.getLocation().getStock().getLP()); + } + String tItemCode=item.getCode().substring(0, 9); + String ptCode = ptd.getPickTicket().getCode(); + char lastChar = ptCode.charAt(ptCode.length() - 1); + if (Character.isUpperCase(lastChar)) { + //System.out.println("最后一位是大写字母"); + task.setStrBill8(tItemCode+lastChar); + } + task.setCode(TimeNumberUtils.getTaskCode()); + task.setType(TaskType.MV_PICKTICKET); + task.setItemKey(inventory.getItemKey()); + task.setStorageDate(inventory.getStorageDate()); + task.setSrcLoc(inventory.getLocation()); + task.setSOI(inventory.getSOI()); + task.setPlanQuantity(allocateQty); + task.setPlanQuantityMU(allocateQty); + task.setInventoryStatus(inventory.getStatus()); + task.setCreateTime(new Date()); + task.setWarehouseArea(inventory.getWarehouseArea()); + task.setBarCode(inventory.getBarCode()); + task.setSrcLP(inventory.getLocation().getStock()); + if(UserHolder.getUser()!=null) { + task.setOperator(UserHolder.getUser().getName()); + task.setStrBill3(UserHolder.getUser().getName()); + } + commonDao.store(task); + tasks.add(task); + } + if(unQty>0) { + msg=msg+ptd.getItem().getCode()+",库存不足! "; + } + + //修改为下发的回传状态 +// List pdids=new ArrayList(); +// pdids.add(ptd.getId()); +// interfaceReqManager.wmsSapZhuantaihuichuang(pdids, 0,"",1);//状态回传 + }else { + msg=msg+ptd.getItem().getCode()+",无匹配库存! "; + } +// shuaxinPick(pt);//刷新订单 + + }else{ + throw new BusinessException("任务状态错误!"); + } + } + invIds =new ArrayList(); + return tasks; + } + public String getSubWorkOrer(String picktickCode,WarehouseArea warehouseArea,Item item){ + String code=""; + if(warehouseArea.getId()==1765) { + if(item.getGoodType()!=null&&item.getGoodType().equals("大件")) { + Long count= (Long) commonDao.findByQuery(" select max(t.id) from Task t where t.billCode like '"+picktickCode+"-%' and t.srcLoc.zone.id="+warehouseArea.getId()+ + " and t.planQuantity>t.movedQuantityMU and t.itemKey.item.goodType='大件' ").get(0); + if(count!=null&&count.longValue()>0){ + Task t=this.load(Task.class,count); + code=t.getBillCode(); + }else{ + code=bussinessCodeManager.getCodeForYmd(picktickCode+"-", 2); + } + }else { + Long count= (Long) commonDao.findByQuery(" select max(t.id) from Task t where t.billCode like '"+picktickCode+"-%' and t.srcLoc.zone.id="+warehouseArea.getId()+ + " and t.planQuantity>t.movedQuantityMU and t.itemKey.item.goodType<>'大件' ").get(0); + if(count!=null&&count.longValue()>0){ + Task t=this.load(Task.class,count); + code=t.getBillCode(); + }else{ + + code=bussinessCodeManager.getCodeForYmd(picktickCode+"-", 2); + } + } + }else { + Long count= (Long) commonDao.findByQuery(" select max(t.id) from Task t where t.billCode like '"+picktickCode+"-%' and t.srcLoc.zone.id="+warehouseArea.getId()+ + " and t.planQuantity>t.movedQuantityMU ").get(0); + if(count!=null&&count.longValue()>0){ + Task t=this.load(Task.class,count); + code=t.getBillCode(); + }else{ + + code=bussinessCodeManager.getCodeForYmd(picktickCode+"-", 2); + } + } + + return code; + } +} + + diff --git a/src/main/java/com/dev/swms/server/service/shipping/WaveDocManager1.java b/src/main/java/com/dev/swms/server/service/shipping/NewWaveDocManager.java similarity index 94% rename from src/main/java/com/dev/swms/server/service/shipping/WaveDocManager1.java rename to src/main/java/com/dev/swms/server/service/shipping/NewWaveDocManager.java index ff0f280..4869bd1 100644 --- a/src/main/java/com/dev/swms/server/service/shipping/WaveDocManager1.java +++ b/src/main/java/com/dev/swms/server/service/shipping/NewWaveDocManager.java @@ -14,7 +14,7 @@ import com.dev.swms.server.model.shipping.Prewave; import com.dev.swms.server.model.shipping.WaveDoc; import com.dev.energy.server.service.BaseManager; -public interface WaveDocManager1 extends BaseManager { +public interface NewWaveDocManager extends BaseManager { //自动创波,ddq1=3#不良品区,ddq2=3#焊接件区,ddq3=3#货架区,ddq4=3#料箱区,ddq5=7#3楼普通库, //ddq6=7#4楼普通库,ddq7=7#地堆区,ddq8=#堆垛库,ddq9=8#化学品区 @Transactional diff --git a/src/main/java/com/dev/swms/server/service/shipping/pojo/DefaultWaveDocManager1.java b/src/main/java/com/dev/swms/server/service/shipping/pojo/NewDefaultWaveDocManager.java similarity index 97% rename from src/main/java/com/dev/swms/server/service/shipping/pojo/DefaultWaveDocManager1.java rename to src/main/java/com/dev/swms/server/service/shipping/pojo/NewDefaultWaveDocManager.java index 2648eba..df1f2d6 100644 --- a/src/main/java/com/dev/swms/server/service/shipping/pojo/DefaultWaveDocManager1.java +++ b/src/main/java/com/dev/swms/server/service/shipping/pojo/NewDefaultWaveDocManager.java @@ -25,26 +25,26 @@ import com.dev.swms.server.service.base.ItemManager; import com.dev.swms.server.service.interfaceLog.JdbcManager; import com.dev.swms.server.service.inventory.InventoryManager; import com.dev.swms.server.service.picking.allocate.AutoAllocator; -import com.dev.swms.server.service.picking.allocate.AutoAllocator1; +import com.dev.swms.server.service.picking.allocate.NewAutoAllocator; import com.dev.swms.server.service.sequence.BussinessCodeManager; +import com.dev.swms.server.service.shipping.NewWaveDocManager; import com.dev.swms.server.service.shipping.PickTicketManager; -import com.dev.swms.server.service.shipping.WaveDocManager1; import com.dev.swms.server.utils.TimeNumberUtils; -public class DefaultWaveDocManager1 extends DefaultBaseManager implements - WaveDocManager1 { +public class NewDefaultWaveDocManager extends DefaultBaseManager implements + NewWaveDocManager { private static Logger logger = Logger.getLogger(DefaultWaveDocManager.class); private final PickTicketManager pickTicketManager; - protected final AutoAllocator1 autoAllocator; + protected final NewAutoAllocator autoAllocator; protected final InventoryManager inventoryManager; protected final ItemManager itemManager; protected final BussinessCodeManager bussinessCodeManager; protected final JdbcManager jdbcManager; protected static Date hotWaveDate=new Date();//波次创建,判断不能同时新建 protected static boolean hotWave=true;//波次创建,判断不能同时新建 - public DefaultWaveDocManager1(PickTicketManager pickTicketManager, AutoAllocator1 autoAllocator, + public NewDefaultWaveDocManager(PickTicketManager pickTicketManager, NewAutoAllocator autoAllocator, InventoryManager inventoryManager, ItemManager itemManager,BussinessCodeManager bussinessCodeManager,JdbcManager jdbcManager) { this.pickTicketManager = pickTicketManager; this.autoAllocator = autoAllocator; diff --git a/src/webapp/WEB-INF/classes/config/origen/menuConfig.xml b/src/webapp/WEB-INF/classes/config/origen/menuConfig.xml index ebd631f..82c5106 100644 --- a/src/webapp/WEB-INF/classes/config/origen/menuConfig.xml +++ b/src/webapp/WEB-INF/classes/config/origen/menuConfig.xml @@ -137,10 +137,10 @@ - - - - + + + diff --git a/src/webapp/WEB-INF/classes/config/origen/shipping/editbkcbPage1.xml b/src/webapp/WEB-INF/classes/config/origen/shipping/newEditbkcbPage.xml similarity index 96% rename from src/webapp/WEB-INF/classes/config/origen/shipping/editbkcbPage1.xml rename to src/webapp/WEB-INF/classes/config/origen/shipping/newEditbkcbPage.xml index d90953b..2c5f1fc 100644 --- a/src/webapp/WEB-INF/classes/config/origen/shipping/editbkcbPage1.xml +++ b/src/webapp/WEB-INF/classes/config/origen/shipping/newEditbkcbPage.xml @@ -1,7 +1,7 @@ - +