|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.wms.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.sun.org.apache.xpath.internal.operations.Or; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.dto.LocDetlDto; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.dto.WrkDto; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.entity.MobileAdjustResult; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.framework.exception.CoolException; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestParam; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MatService matService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 平庫上架 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param locNo | 
|---|
|  |  |  | * @param barcode | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RequestMapping("/pda/WarehouseIn") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R WarehouseIn(@RequestParam String locNo, @RequestParam String barcode) { | 
|---|
|  |  |  | return mobileService.WarehouseIn(locNo, barcode, getHostId()); | 
|---|
|  |  |  | return mobileService.WarehouseIn(locNo, barcode, getHostId(), getUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 平庫下架 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param combParam | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RequestMapping("/pda/WarehouseOut") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R WarehouseOut(@RequestBody CombParam combParam) { | 
|---|
|  |  |  | return mobileService.WarehouseOut(combParam, getHostId()); | 
|---|
|  |  |  | return mobileService.WarehouseOut(combParam, getHostId(), getUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/outBound/mat/list") | 
|---|
|  |  |  | 
|---|
|  |  |  | .eq(OrderDetl::getMatnr, matnr) | 
|---|
|  |  |  | .like(OrderDetl::getOrderNo, orderNo) | 
|---|
|  |  |  | .orderByDesc(OrderDetl::getCreateTime)); | 
|---|
|  |  |  | for (OrderDetl orderDetl:list | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | for (OrderDetl orderDetl : list | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | double count = orderDetl.getAnfme() - orderDetl.getWorkQty(); | 
|---|
|  |  |  | PickMatParam matParam = new PickMatParam(); | 
|---|
|  |  |  | matParam.setMatnr(orderDetl.getMatnr()); | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping("/pda/WarehouseOutPickMerge/v1") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R WarehouseOutPickMergeV1(@RequestBody WarehouseOutPickMergeParam param) { | 
|---|
|  |  |  | return mobileService.WarehouseOutPickMergeV1(param, getHostId(),getUserId()); | 
|---|
|  |  |  | return mobileService.WarehouseOutPickMergeV1(param, getHostId(), getUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 多次并板 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RequestMapping("/pda/WarehouseOutMergeBoardMany/v1") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R WarehouseOutMergeBoardManyV1(@RequestBody WarehouseOutMergeBoardManyParam param) { | 
|---|
|  |  |  | return mobileService.WarehouseOutMergeBoardMany(param, getHostId(),getUserId()); | 
|---|
|  |  |  | return mobileService.WarehouseOutMergeBoardMany(param, getHostId(), getUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/menu/pda/auth") | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PickMatParam matParam = new PickMatParam(); | 
|---|
|  |  |  | matParam.setMatnr(orderDetl.getMatnr()); | 
|---|
|  |  |  | matParam.setMaktx(orderDetl.getMaktx()); | 
|---|
|  |  |  | matParam.setBatch(orderDetl.getBatch()); | 
|---|
|  |  |  | matParam.setOrderNo(orderDetl.getOrderNo()); | 
|---|
|  |  |  | matParam.setOrderId(orderDetl.getOrderId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok().add(maps); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/outBound/mat/list") | 
|---|
|  |  |  | @RequestMapping("/outBound/order/list") | 
|---|
|  |  |  | @ManagerAuth(memo = "获取出库订单") | 
|---|
|  |  |  | public R outBound(@RequestParam(required = false) String matnr,@RequestParam(required = false) String orderNo){ | 
|---|
|  |  |  | public R outBound(@RequestParam(required = false) String matnr, @RequestParam(required = false) String orderNo) { | 
|---|
|  |  |  | List<DocType> docTypes = docTypeService.list(new LambdaQueryWrapper<DocType>().like(DocType::getPakout, 1)); | 
|---|
|  |  |  | ArrayList<Long> typeList = new ArrayList<>(); | 
|---|
|  |  |  | for (DocType docType : docTypes) { | 
|---|
|  |  |  | 
|---|
|  |  |  | wrkDetl.setHostId(getHostId()); | 
|---|
|  |  |  | wrkDetl.setWrkMastId(wrkMast.getId()); | 
|---|
|  |  |  | wrkDetl.setZpallet(wrkMast.getBarcode()); | 
|---|
|  |  |  | if(Cools.isEmpty(matParam.getBatch())){ | 
|---|
|  |  |  | wrkDetl.setBatch(""); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!wrkDetlService.save(wrkDetl)) { | 
|---|
|  |  |  | throw new CoolException("保存工作档明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Order order = orderService.selectByNo(matParam.getOrderNo(), getHostId()); | 
|---|
|  |  |  | if (order == null) { | 
|---|
|  |  |  | throw new CoolException("Order is not exits"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //更新订单工作数量 | 
|---|
|  |  |  | orderDetlService.increaseWorkQtyByOrderNo(matParam.getOrderNo(), matParam.getMatnr(), matParam.getBatch(), matParam.getUseCount(), getHostId()); | 
|---|
|  |  |  | orderService.updateSettle(order.getId(), 2L, getUserId(), getHostId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中 | 
|---|
|  |  |  | locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, param.getLocNo()).eq(LocMast::getHostId, getHostId())); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok().add(wrkMastArrayList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/pda/OutLocNo") | 
|---|
|  |  |  | @ManagerAuth(memo = "获得平库出库的对应库位号") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R OutLocNo(@RequestParam Long orderId) { | 
|---|
|  |  |  | List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>() | 
|---|
|  |  |  | .eq(OrderDetl::getOrderId, orderId) | 
|---|
|  |  |  | .eq(OrderDetl::getHostId, getHostId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (Cools.isEmpty(orderDetls)) { | 
|---|
|  |  |  | return R.error("订单明细不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<String> list = new ArrayList<>(); | 
|---|
|  |  |  | for (OrderDetl o : orderDetls | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | if (o.getAnfme() <= o.getWorkQty()) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //查看库位明细中有的物料 | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>() | 
|---|
|  |  |  | .eq(LocDetl::getMatnr, o.getMatnr()).eq(LocDetl::getHostId, getHostId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (Cools.isEmpty(locDetls)) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | for (LocDetl l : locDetls | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | String s = l.getLocNo().substring(1, 2); | 
|---|
|  |  |  | if (Integer.valueOf(s) > 4) { | 
|---|
|  |  |  | list.add(l.getLocNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<String> myList = list.stream().distinct().collect(Collectors.toList()); | 
|---|
|  |  |  | return R.ok(myList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/pda/OrderDetlContrastLocDetl") | 
|---|
|  |  |  | @ManagerAuth(memo = "获得订单明细对应的库存明细") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R OrderDetlContrastLocDetl(@RequestParam Long orderId, @RequestParam String locNo) { | 
|---|
|  |  |  | List<LocDetl> locDetlList = new ArrayList<LocDetl>(); | 
|---|
|  |  |  | List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>() | 
|---|
|  |  |  | .eq(OrderDetl::getOrderId, orderId) | 
|---|
|  |  |  | .eq(OrderDetl::getHostId, getHostId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (Cools.isEmpty(orderDetls)) { | 
|---|
|  |  |  | return R.error("订单明细不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>() | 
|---|
|  |  |  | .eq(LocDetl::getLocNo, locNo)); | 
|---|
|  |  |  | if (Cools.isEmpty(locDetls)) { | 
|---|
|  |  |  | return R.error("库位为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (OrderDetl o : orderDetls | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | if(o.getAnfme().equals(o.getQty())){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (LocDetl l : locDetls | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | if (o.getMatnr().equals(l.getMatnr())) { | 
|---|
|  |  |  | if (o.getAnfme() - o.getWorkQty() >= l.getAnfme()) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | l.setAnfme(o.getAnfme() - o.getWorkQty()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locDetlList.add(l); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(locDetlList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/pda/OutOrder") | 
|---|
|  |  |  | @ManagerAuth(memo = "获得出库单") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R OutOrder(@RequestParam String orderNo) { | 
|---|
|  |  |  | List<Order> orders=new ArrayList<Order>(); | 
|---|
|  |  |  | List<Order> OrderList=new ArrayList<Order>(); | 
|---|
|  |  |  | if(Cools.isEmpty(orderNo)){ | 
|---|
|  |  |  | orders= orderService.list(new LambdaQueryWrapper<Order>() | 
|---|
|  |  |  | .between(Order::getSettle,1,2) | 
|---|
|  |  |  | .eq(Order::getHostId, getHostId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | orders= orderService.list(new LambdaQueryWrapper<Order>() | 
|---|
|  |  |  | .like(Order::getOrderNo, orderNo) | 
|---|
|  |  |  | .between(Order::getSettle,1,2) | 
|---|
|  |  |  | .eq(Order::getHostId, getHostId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Cools.isEmpty(orders)){ | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Order o:orders | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | DocType docType=docTypeService.getOne(new LambdaQueryWrapper<DocType>() | 
|---|
|  |  |  | .eq(DocType::getDocId,o.getDocType())); | 
|---|
|  |  |  | if(docType.getPakout()==1){ | 
|---|
|  |  |  | OrderList.add(o); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(OrderList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|