|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.wms.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | 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.common.domain.entity.StaDesc; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.enums.WorkNoType; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.param.MobileAdjustParam; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.param.PickConfirmParam; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.param.PickMatParam; | 
|---|
|  |  |  | import com.zy.asrs.common.openapi.entity.param.CombParam; | 
|---|
|  |  |  | import com.zy.asrs.common.sys.service.StaDescService; | 
|---|
|  |  |  | import com.zy.asrs.common.web.BaseController; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.service.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | private RolePermissionService rolePermissionService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PermissionService permissionService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocMastService locMastService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private StaDescService staDescService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OrderDetlService orderDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CommonService commonService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MatService matService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/pda/WarehouseIn") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R WarehouseIn(@RequestParam String locNo,@RequestParam String barcode){ | 
|---|
|  |  |  | return mobileService.WarehouseIn(locNo,barcode,getHostId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/pda/WarehouseOut") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R WarehouseOut(@RequestBody CombParam combParam){ | 
|---|
|  |  |  | return mobileService.WarehouseOut(combParam,getHostId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/menu/pda/auth") | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok("盘点成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/loc/f/list") | 
|---|
|  |  |  | @ManagerAuth(memo = "获取在库库位") | 
|---|
|  |  |  | public R locNoF(@RequestParam(required = false) String locNo){ | 
|---|
|  |  |  | LambdaQueryWrapper<LocMast> wrapper = new LambdaQueryWrapper<LocMast>() | 
|---|
|  |  |  | .eq(LocMast::getLocSts, "F") | 
|---|
|  |  |  | .eq(LocMast::getHostId, getHostId()); | 
|---|
|  |  |  | if (!Cools.isEmpty(locNo)) { | 
|---|
|  |  |  | wrapper.like(LocMast::getLocNo, locNo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<LocMast> list = locMastService.list(wrapper); | 
|---|
|  |  |  | return R.ok().add(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/pick/sta/list") | 
|---|
|  |  |  | @ManagerAuth(memo = "获取并板站") | 
|---|
|  |  |  | public R pickSta(){ | 
|---|
|  |  |  | List<StaDesc> list = staDescService.list(new LambdaQueryWrapper<StaDesc>() | 
|---|
|  |  |  | .eq(StaDesc::getTypeNo, 104) | 
|---|
|  |  |  | .eq(StaDesc::getHostId, getHostId())); | 
|---|
|  |  |  | return R.ok().add(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/pick/mat/list") | 
|---|
|  |  |  | @ManagerAuth(memo = "获取并板物料") | 
|---|
|  |  |  | public R pickMats(@RequestParam(required = false) String matnr){ | 
|---|
|  |  |  | List<DocType> docTypes = docTypeService.list(new LambdaQueryWrapper<DocType>().like(DocType::getDocName, "入库")); | 
|---|
|  |  |  | ArrayList<Long> typeList = new ArrayList<>(); | 
|---|
|  |  |  | for (DocType docType : docTypes) { | 
|---|
|  |  |  | typeList.add(docType.getDocId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq(Order::getStatus, 1); | 
|---|
|  |  |  | wrapper.eq(Order::getHostId, getHostId()); | 
|---|
|  |  |  | wrapper.in(Order::getDocType, typeList); | 
|---|
|  |  |  | List<Order> orders = orderService.list(wrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ArrayList<Long> orderIds = new ArrayList<>(); | 
|---|
|  |  |  | for (Order order : orders) { | 
|---|
|  |  |  | orderIds.add(order.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //搜索明细 | 
|---|
|  |  |  | LambdaQueryWrapper<OrderDetl> wrapper1 = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | wrapper1.eq(OrderDetl::getStatus, 1); | 
|---|
|  |  |  | wrapper1.eq(OrderDetl::getHostId, getHostId()); | 
|---|
|  |  |  | wrapper1.in(OrderDetl::getOrderId, orderIds); | 
|---|
|  |  |  | if (!Cools.isEmpty(matnr)) { | 
|---|
|  |  |  | wrapper1.like(OrderDetl::getMatnr, matnr); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<OrderDetl> list = orderDetlService.list(wrapper1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ArrayList<PickMatParam> maps = new ArrayList<>(); | 
|---|
|  |  |  | for (OrderDetl orderDetl : list) { | 
|---|
|  |  |  | //剩余可用数量 | 
|---|
|  |  |  | double count = orderDetl.getAnfme() - orderDetl.getWorkQty(); | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PickMatParam matParam = new PickMatParam(); | 
|---|
|  |  |  | matParam.setMatnr(orderDetl.getMatnr()); | 
|---|
|  |  |  | matParam.setBatch(orderDetl.getBatch()); | 
|---|
|  |  |  | matParam.setOrderNo(orderDetl.getOrderNo()); | 
|---|
|  |  |  | matParam.setOrderId(orderDetl.getOrderId()); | 
|---|
|  |  |  | matParam.setCount(count); | 
|---|
|  |  |  | matParam.setUseCount(0D); | 
|---|
|  |  |  | maps.add(matParam); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(maps); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/pick/in") | 
|---|
|  |  |  | @ManagerAuth(memo = "并板入库") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R pickConfirm(@RequestBody PickConfirmParam param){ | 
|---|
|  |  |  | LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>() | 
|---|
|  |  |  | .eq(LocMast::getLocNo, param.getLocNo()) | 
|---|
|  |  |  | .eq(LocMast::getHostId, getHostId())); | 
|---|
|  |  |  | if (!locMast.getLocSts().equals("F")) { | 
|---|
|  |  |  | return R.error("库位状态不是在库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | StaDesc staDesc = staDescService.getOne(new LambdaQueryWrapper<StaDesc>() | 
|---|
|  |  |  | .eq(StaDesc::getTypeNo, 104) | 
|---|
|  |  |  | .eq(StaDesc::getStnNo, param.getStaNo()) | 
|---|
|  |  |  | .eq(StaDesc::getHostId, getHostId())); | 
|---|
|  |  |  | if (staDesc == null) { | 
|---|
|  |  |  | return R.error("站点不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //检验传参是否和订单明细匹配 | 
|---|
|  |  |  | for (PickMatParam matParam : param.getList()) { | 
|---|
|  |  |  | LambdaQueryWrapper<OrderDetl> wrapper = new LambdaQueryWrapper<OrderDetl>() | 
|---|
|  |  |  | .eq(OrderDetl::getOrderNo, matParam.getOrderNo()) | 
|---|
|  |  |  | .eq(OrderDetl::getHostId, getHostId()) | 
|---|
|  |  |  | .eq(OrderDetl::getStatus, 1) | 
|---|
|  |  |  | .eq(OrderDetl::getMatnr, matParam.getMatnr()); | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getBatch())) { | 
|---|
|  |  |  | wrapper.eq(OrderDetl::getBatch, matParam.getBatch()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.getOne(wrapper); | 
|---|
|  |  |  | if (orderDetl == null) { | 
|---|
|  |  |  | return R.error("物料数据不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //剩余可用数量 | 
|---|
|  |  |  | double count = orderDetl.getAnfme() - orderDetl.getWorkQty(); | 
|---|
|  |  |  | if (matParam.getCount() != count) { | 
|---|
|  |  |  | return R.error("物料数据已过期"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (matParam.getUseCount() > count) { | 
|---|
|  |  |  | return R.error("可用数量不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | // 生成工作号 | 
|---|
|  |  |  | int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(104)); | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | WrkMast wrkMast = new WrkMast(); | 
|---|
|  |  |  | wrkMast.setWrkNo(workNo); | 
|---|
|  |  |  | wrkMast.setIoTime(now); | 
|---|
|  |  |  | wrkMast.setWrkSts(101L); // 工作状态:101.生成出库 | 
|---|
|  |  |  | wrkMast.setIoType(104); // 入出库状态 | 
|---|
|  |  |  | wrkMast.setIoPri(13D); // 优先级:13 | 
|---|
|  |  |  | wrkMast.setSourceStaNo(staDesc.getDeviceStn()); // 源站 | 
|---|
|  |  |  | wrkMast.setStaNo(staDesc.getStnNo()); // 目标站 | 
|---|
|  |  |  | wrkMast.setSourceLocNo(param.getLocNo()); // 源库位 | 
|---|
|  |  |  | wrkMast.setFullPlt("Y"); // 满板:Y | 
|---|
|  |  |  | wrkMast.setPicking("Y"); // 拣料 | 
|---|
|  |  |  | wrkMast.setExitMk("N"); // 退出 | 
|---|
|  |  |  | wrkMast.setEmptyMk("N"); // 空板 | 
|---|
|  |  |  | wrkMast.setBarcode(locMast.getBarcode()); | 
|---|
|  |  |  | wrkMast.setAppeUser(String.valueOf(getUserId())); // 操作人员数据 | 
|---|
|  |  |  | wrkMast.setAppeTime(now); | 
|---|
|  |  |  | wrkMast.setModiUser(String.valueOf(getUserId())); | 
|---|
|  |  |  | wrkMast.setModiTime(now); | 
|---|
|  |  |  | wrkMast.setHostId(getHostId()); | 
|---|
|  |  |  | wrkMast.setCrnNo(staDesc.getDeviceNo()); | 
|---|
|  |  |  | if (!wrkMastService.save(wrkMast)) { | 
|---|
|  |  |  | throw new CoolException("保存工作档失败,出库库位号:" + param.getLocNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 生成工作档明细 | 
|---|
|  |  |  | for (PickMatParam matParam : param.getList()) { | 
|---|
|  |  |  | LambdaQueryWrapper<Mat> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq(Mat::getHostId, getHostId()); | 
|---|
|  |  |  | wrapper.eq(Mat::getStatus, 1); | 
|---|
|  |  |  | wrapper.eq(Mat::getMatnr, matParam.getMatnr()); | 
|---|
|  |  |  | Mat mat = matService.getOne(wrapper); | 
|---|
|  |  |  | if (mat == null) { | 
|---|
|  |  |  | throw new CoolException("保存工作档失败,物料信息不存在:" + matParam.getMatnr()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WrkDetl wrkDetl = new WrkDetl(); | 
|---|
|  |  |  | wrkDetl.sync(mat); | 
|---|
|  |  |  | wrkDetl.setOrderNo(matParam.getOrderNo()); | 
|---|
|  |  |  | wrkDetl.setWrkNo(workNo); | 
|---|
|  |  |  | wrkDetl.setIoTime(now); | 
|---|
|  |  |  | wrkDetl.setAnfme(matParam.getUseCount()); // 数量 | 
|---|
|  |  |  | wrkDetl.setAppeTime(now); | 
|---|
|  |  |  | wrkDetl.setAppeUser(getUserId()); | 
|---|
|  |  |  | wrkDetl.setModiTime(now); | 
|---|
|  |  |  | wrkDetl.setModiUser(getUserId()); | 
|---|
|  |  |  | wrkDetl.setHostId(getHostId()); | 
|---|
|  |  |  | wrkDetl.setWrkMastId(wrkMast.getId()); | 
|---|
|  |  |  | if (!wrkDetlService.save(wrkDetl)) { | 
|---|
|  |  |  | throw new CoolException("保存工作档明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新订单工作数量 | 
|---|
|  |  |  | orderDetlService.increaseWorkQtyByOrderNo(matParam.getOrderNo(), matParam.getMatnr(), matParam.getBatch(), matParam.getUseCount(), getHostId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中 | 
|---|
|  |  |  | locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, param.getLocNo()).eq(LocMast::getHostId, getHostId())); | 
|---|
|  |  |  | if (locMast.getLocSts().equals("F")) { | 
|---|
|  |  |  | locMast.setLocSts("P"); | 
|---|
|  |  |  | locMast.setModiUser(getUserId()); | 
|---|
|  |  |  | locMast.setModiTime(now); | 
|---|
|  |  |  | if (!locMastService.updateById(locMast)) { | 
|---|
|  |  |  | throw new CoolException("预约库位状态失败,库位号:" + param.getLocNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException(param.getLocNo() + "库位不是在库状态"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|