半成品出库分配-人工分配
							parent
							
								
									2c39c59201
								
							
						
					
					
						commit
						79f7b07fcc
					
				| 
						 | 
				
			
			@ -43,4 +43,6 @@ public interface BoxRepository extends JpaRepository<Box, Long>, JpaSpecificatio
 | 
			
		|||
 | 
			
		||||
    @Query(value = "SELECT * FROM base_box", nativeQuery = true)
 | 
			
		||||
    List<Box> getBoxAllData();
 | 
			
		||||
    @Query(value = "SELECT b FROM Box b where b.code=?1 and b.enabled=true ")
 | 
			
		||||
    List<Box> findByCodeAndItem(String code);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -114,47 +114,7 @@ public class BoxServiceImpl implements BoxService {
 | 
			
		|||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public void update(Box resources) {
 | 
			
		||||
        redisUtils.del("ButtonBoxCode");
 | 
			
		||||
        //判断那个按钮盒
 | 
			
		||||
        if (resources.getLampCode() != null && resources.getLampCode().length() > 0) {
 | 
			
		||||
            switch (resources.getLampCode()) {
 | 
			
		||||
                case "0001":
 | 
			
		||||
                    this.executeLampStatus(resources.getLampStatus(), resources.getIP(), NettyUtils.light_1);
 | 
			
		||||
                    break;
 | 
			
		||||
                case "0002":
 | 
			
		||||
                    this.executeLampStatus(resources.getLampStatus(), resources.getIP(), NettyUtils.light_2);
 | 
			
		||||
                    break;
 | 
			
		||||
                case "0003":
 | 
			
		||||
                    this.executeLampStatus(resources.getLampStatus(), resources.getIP(), NettyUtils.light_3);
 | 
			
		||||
                    break;
 | 
			
		||||
                case "0004":
 | 
			
		||||
                    this.executeLampStatus(resources.getLampStatus(), resources.getIP(), NettyUtils.light_4);
 | 
			
		||||
                    break;
 | 
			
		||||
                default:
 | 
			
		||||
                    log.error("{}:按钮盒编码【{}】出错", resources.getCode(), resources.getLampCode());
 | 
			
		||||
                    return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //根据IP和按钮盒编号查询是否存在了,存在提示,不存在绑定
 | 
			
		||||
        if ((resources.getIP() != null && resources.getIP().length() > 0) && (resources.getLampCode() != null && resources.getLampCode().length() > 0)) {
 | 
			
		||||
            String hql = " from Box box where box.iP='" + resources.getIP() + "' and box.lampCode='" + resources.getLampCode() + "' and box.id!=" + resources.getId() + " ";
 | 
			
		||||
            Query query = entityManager.createQuery(hql);
 | 
			
		||||
            List<Box> boxList = query.getResultList();
 | 
			
		||||
            if (boxList.size() > 0) {
 | 
			
		||||
                StringBuffer sbf = new StringBuffer();
 | 
			
		||||
                for (Box box : boxList) {
 | 
			
		||||
                    sbf.append(box.getLampCode()).append(",").toString();
 | 
			
		||||
                }
 | 
			
		||||
                throw new RuntimeException("按钮盒编号" + sbf.deleteCharAt(sbf.length() - 1) + "已绑定!");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        Box box = boxRepository.findById(resources.getId()).orElseGet(Box::new);
 | 
			
		||||
        ValidationUtil.isNull(box.getId(), "Box", "id", resources.getId());
 | 
			
		||||
        box.copy(resources);
 | 
			
		||||
        boxRepository.save(box);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        boxRepository.save(resources);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -128,10 +128,6 @@ public class PickDetailController {
 | 
			
		|||
    public synchronized ResponseEntity<Object> allocate(@RequestBody Long[] ids) throws Exception {
 | 
			
		||||
        List<Long> pickDetailIds = Arrays.asList(ids);
 | 
			
		||||
        ApiResult apiResult=pickDetailService.allocate(ids);
 | 
			
		||||
        /*for (Long id : pickDetailIds) {
 | 
			
		||||
            PickDetailDto pickDetailDto = pickDetailService.findById(id);
 | 
			
		||||
            pickDetailService.allocate(id, pickDetailDto.getOrderQty());
 | 
			
		||||
        }*/
 | 
			
		||||
        return new ResponseEntity<>(apiResult, HttpStatus.valueOf(apiResult.getStatus()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -166,8 +162,11 @@ public class PickDetailController {
 | 
			
		|||
    @Log("拣货")
 | 
			
		||||
    @ApiOperation("拣货确认")
 | 
			
		||||
    @AnonymousAccess
 | 
			
		||||
    public synchronized ResponseEntity<Object> picking(@RequestBody Long pickDetailId) throws Exception {
 | 
			
		||||
        return  pick_in(pickDetailId);
 | 
			
		||||
    public ResponseEntity<Object> picking(@RequestBody String datas){
 | 
			
		||||
        System.out.println("datas:"+datas);
 | 
			
		||||
//        pick_in(pickDetailId);
 | 
			
		||||
        ApiResult apiResult=ApiResult.fail(200, "操作成功", "");
 | 
			
		||||
        return new ResponseEntity<>(apiResult, HttpStatus.valueOf(apiResult.getStatus()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ResponseEntity<Object> pick_in(Long pickDetailId){
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -145,66 +145,92 @@ public class PickDetailServiceImpl implements PickDetailService {
 | 
			
		|||
            Item item = pickDetail.getItem();
 | 
			
		||||
            Dept dept = item.getDept();//仓库
 | 
			
		||||
            Double quantity=pickDetail.getOrderQty()-pickDetail.getAllocatedQty();//未分配数量
 | 
			
		||||
            Point endPoint;//目标点位
 | 
			
		||||
            ApiResult apiResult =null;
 | 
			
		||||
            if (pickDetail.getPropC4()==null){
 | 
			
		||||
                /** 默认出库配置*/
 | 
			
		||||
                List<Box> boxList=boxRepository.findByCodeAndItem(BizStatus.BCP_PT);
 | 
			
		||||
                if (boxList.size()>0){
 | 
			
		||||
                    Box box=boxList.get(0);
 | 
			
		||||
                    pickDetail.setPropC4(box.getLampCode());
 | 
			
		||||
                    pickDetail.setPropC5(box.getPoint().getCode());
 | 
			
		||||
                    pickDetailRepository.save(pickDetail);
 | 
			
		||||
                }else {
 | 
			
		||||
                    return ApiResult.fail(500, "请设置业务类型", "");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (pickDetail.getPropC4().equals(BizStatus.RG_PT)){
 | 
			
		||||
                /** 人工出库*/
 | 
			
		||||
                apiResult = getAllocate(pickDetail, item, dept, quantity,0);
 | 
			
		||||
            }
 | 
			
		||||
            if (pickDetail.getPropC4().equals(BizStatus.AGV_PT)){
 | 
			
		||||
                /**AGV出库分配*/
 | 
			
		||||
                //获取目标点位
 | 
			
		||||
                endPoint = pointRepository.findByCode(pickDetail.getPropC5());
 | 
			
		||||
                if (pickDetail.getOrderQty() > pickDetail.getAllocatedQty()) {
 | 
			
		||||
                    List<Inventory> inventoryList = inventoryRepository.queryInventory(item.getId());
 | 
			
		||||
                    if (inventoryList.size() > 0) {
 | 
			
		||||
                        double allocateQty = 0;//分配数量
 | 
			
		||||
                        double unQty = quantity;//订单数量
 | 
			
		||||
                        for (Inventory inv : inventoryList) {
 | 
			
		||||
                            Point startPoint = inv.getPoint();//原库位
 | 
			
		||||
                            if (unQty == 0) {
 | 
			
		||||
                                break;
 | 
			
		||||
                            }
 | 
			
		||||
                            //整托分配
 | 
			
		||||
                            allocateQty = inv.getQuantity();
 | 
			
		||||
                            if (unQty < allocateQty) {
 | 
			
		||||
                                return ApiResult.fail(201,"剩余订单数量不足一托","");
 | 
			
		||||
                            }
 | 
			
		||||
                            //更新库存
 | 
			
		||||
                            inv.setQueuedQty(allocateQty);
 | 
			
		||||
                            inventoryRepository.save(inv);
 | 
			
		||||
                            unQty = unQty-allocateQty;
 | 
			
		||||
                            //更新出库单
 | 
			
		||||
                            pickDetail.setAllocatedQty(pickDetail.getAllocatedQty() + allocateQty);
 | 
			
		||||
                            pickDetail.setStatus(BizStatus.ALLOCATE);
 | 
			
		||||
                            pickDetailRepository.save(pickDetail);
 | 
			
		||||
                            //生成Task任务
 | 
			
		||||
                            Task task = new Task();
 | 
			
		||||
                            task.setItem(inv.getItemKey().getItem());
 | 
			
		||||
                            task.setItemKey(inv.getItemKey());
 | 
			
		||||
                            task.setPickDetail(pickDetail);
 | 
			
		||||
                            task.setBillCode(pickDetail.getPick().getRelatedBill1());
 | 
			
		||||
                            task.setSrcPoint(startPoint);
 | 
			
		||||
                            task.setDstPoint(endPoint);
 | 
			
		||||
                            task.setTaskType(BizStatus.PICK);
 | 
			
		||||
                            task.setTaskStatus(BizStatus.ALLOCATE);
 | 
			
		||||
                            task.setBeSkip(1);//是否AGV出库
 | 
			
		||||
                            task.setPlanQty(allocateQty);
 | 
			
		||||
                            task.setDept(dept);
 | 
			
		||||
                            task.setInventory(inv);
 | 
			
		||||
                            taskRepository.save(task);
 | 
			
		||||
                            //生成AGV任务
 | 
			
		||||
                            AgvTask agvTask = agvTaskService.addAgvTask(BizStatus.AGV, startPoint.getStorageType(), startPoint.getCode(),endPoint.getCode() , BizStatus.OPEN, BizStatus.PICK);
 | 
			
		||||
                            //更新Task任务 写入关联AGV
 | 
			
		||||
                            task.setAgvTask(agvTask);
 | 
			
		||||
                            taskRepository.save(task);
 | 
			
		||||
                        }
 | 
			
		||||
                    }else {
 | 
			
		||||
                        return ApiResult.fail(500, item.getCode()+"料号,无库存", "");
 | 
			
		||||
                    }
 | 
			
		||||
                }else {
 | 
			
		||||
                    return ApiResult.fail(500, "已分配", "");
 | 
			
		||||
                }
 | 
			
		||||
                apiResult = getAllocate(pickDetail, item, dept, quantity,1);
 | 
			
		||||
            }
 | 
			
		||||
            if (apiResult != null) return apiResult;
 | 
			
		||||
        }
 | 
			
		||||
        return ApiResult.fail(200,"操作成功",null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private ApiResult getAllocate(PickDetail pickDetail, Item item, Dept dept, Double quantity,Integer agvFlag) {
 | 
			
		||||
        Point endPoint;
 | 
			
		||||
        endPoint = pointRepository.findByCode(pickDetail.getPropC5());
 | 
			
		||||
        if (pickDetail.getOrderQty() > pickDetail.getAllocatedQty()) {
 | 
			
		||||
            List<Inventory> inventoryList = inventoryRepository.queryInventory(item.getId());
 | 
			
		||||
            if (inventoryList.size() > 0) {
 | 
			
		||||
                double allocateQty = 0;//分配数量
 | 
			
		||||
                double unQty = quantity;//订单数量
 | 
			
		||||
                for (Inventory inv : inventoryList) {
 | 
			
		||||
                    Point startPoint = inv.getPoint();//原库位
 | 
			
		||||
                    if (unQty == 0) {
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                    //整托分配
 | 
			
		||||
                    allocateQty = inv.getQuantity();
 | 
			
		||||
                    if (unQty < allocateQty) {
 | 
			
		||||
                        return ApiResult.fail(201, "剩余订单数量不足一托", "");
 | 
			
		||||
                    }
 | 
			
		||||
                    //更新库存
 | 
			
		||||
                    inv.setQueuedQty(allocateQty);
 | 
			
		||||
                    inventoryRepository.save(inv);
 | 
			
		||||
                    unQty = unQty-allocateQty;
 | 
			
		||||
                    //更新出库单
 | 
			
		||||
                    pickDetail.setAllocatedQty(pickDetail.getAllocatedQty() + allocateQty);
 | 
			
		||||
                    pickDetail.setStatus(BizStatus.ALLOCATE);
 | 
			
		||||
                    pickDetailRepository.save(pickDetail);
 | 
			
		||||
                    //生成Task任务
 | 
			
		||||
                    Task task = new Task();
 | 
			
		||||
                    task.setItem(inv.getItemKey().getItem());
 | 
			
		||||
                    task.setItemKey(inv.getItemKey());
 | 
			
		||||
                    task.setPickDetail(pickDetail);
 | 
			
		||||
                    task.setBillCode(pickDetail.getPick().getRelatedBill1());
 | 
			
		||||
                    task.setSrcPoint(startPoint);
 | 
			
		||||
                    task.setDstPoint(endPoint);
 | 
			
		||||
                    task.setTaskType(BizStatus.PICK);
 | 
			
		||||
                    task.setTaskStatus(BizStatus.ALLOCATE);
 | 
			
		||||
                    task.setBeSkip(agvFlag);//是否AGV出库
 | 
			
		||||
                    task.setPlanQty(allocateQty);
 | 
			
		||||
                    task.setDept(dept);
 | 
			
		||||
                    task.setInventory(inv);
 | 
			
		||||
                    taskRepository.save(task);
 | 
			
		||||
                    if (agvFlag==1) {
 | 
			
		||||
                        /** 是否AGV任务*/
 | 
			
		||||
                        //生成AGV任务
 | 
			
		||||
                        AgvTask agvTask = agvTaskService.addAgvTask(BizStatus.AGV, startPoint.getStorageType(), startPoint.getCode(), endPoint.getCode(), BizStatus.OPEN, BizStatus.PICK);
 | 
			
		||||
                        //更新Task任务 写入关联AGV
 | 
			
		||||
                        task.setAgvTask(agvTask);
 | 
			
		||||
                        taskRepository.save(task);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }else {
 | 
			
		||||
                return ApiResult.fail(500, item.getCode() + "料号,无库存", "");
 | 
			
		||||
            }
 | 
			
		||||
        }else {
 | 
			
		||||
            return ApiResult.fail(500, "已分配", "");
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public synchronized void allocateAll(long id, Point endPoint) throws Exception {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -359,7 +359,7 @@ public class TaskServiceImpl implements TaskService {
 | 
			
		|||
            return apiResult;
 | 
			
		||||
        }
 | 
			
		||||
        // 分配Task库位
 | 
			
		||||
        List<Task> taskList=taskRepository.findByItemType(BizStatus.RECEIVING,0,BizStatus.SMGS);
 | 
			
		||||
        List<Task> taskList=taskRepository.findByItemType(BizStatus.RECEIVING,0,BizStatus.BCP);
 | 
			
		||||
        for (int i = 0; i < taskList.size(); i++) {
 | 
			
		||||
            Task task=taskList.get(i);
 | 
			
		||||
            getAsnTask(point, task);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -214,11 +214,18 @@ public  interface  BizStatus {
 | 
			
		|||
    String AGV_R="AGV_R";
 | 
			
		||||
    /** AGV_容器出场*/
 | 
			
		||||
    String AGV_C="AGV_C";
 | 
			
		||||
    /** 半成品入库*/
 | 
			
		||||
    String SMGS="SMGS";
 | 
			
		||||
    /** 半成品*/
 | 
			
		||||
    String BCP="BCP";
 | 
			
		||||
    /** 成品*/
 | 
			
		||||
    String CP="CP";
 | 
			
		||||
    /** 料箱*/
 | 
			
		||||
    String LX="LX";
 | 
			
		||||
    String BCP_PT="BCP_PT";
 | 
			
		||||
    String CP_PT="CP_PT";
 | 
			
		||||
    String LX_PT="LX_PT";
 | 
			
		||||
 | 
			
		||||
    /** AGV出库*/
 | 
			
		||||
    String AGV_PT="AGV_PT";
 | 
			
		||||
    String AGV_PT=" AGV_PT";
 | 
			
		||||
    /** 人工出库*/
 | 
			
		||||
    String RG_PT="RG_PT";
 | 
			
		||||
    /** AGV入库*/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue