zwl
2025-08-02 a9f4a820c583eb85cec381b6236063256f753652
zy-asrs-wms/src/main/java/com/zy/asrs/wms/controller/MobileController.java
@@ -1,6 +1,7 @@
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;
@@ -10,6 +11,8 @@
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.openapi.entity.param.WarehouseOutMergeBoardManyParam;
import com.zy.asrs.common.openapi.entity.param.WarehouseOutPickMergeParam;
import com.zy.asrs.common.sys.service.StaDescService;
import com.zy.asrs.common.web.BaseController;
import com.zy.asrs.common.wms.entity.*;
@@ -20,10 +23,7 @@
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;
@@ -64,21 +64,125 @@
    @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());
    public R WarehouseIn(@RequestParam String locNo, @RequestParam String barcode) {
        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());
    public R WarehouseOut(@RequestBody CombParam combParam) {
        return mobileService.WarehouseOut(combParam, getHostId(), getUserId());
    }
    @RequestMapping("/outBound/mat/list")
    @ManagerAuth
    public R WarehouseMat(@RequestParam String matnr, @RequestParam String orderNo) {
        if (Cools.isEmpty(matnr)) {
            R.error("品号不能为空");
        }
        ArrayList<PickMatParam> maps = new ArrayList<>();
        if (Cools.isEmpty(orderNo)) {
            List<OrderDetl> list = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>()
                    .eq(OrderDetl::getMatnr, matnr)
                    .orderByDesc(OrderDetl::getCreateTime));
            List<OrderDetl> orderDetls = new ArrayList<OrderDetl>();
            for (OrderDetl orderDetl : list
            ) {
                Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, orderDetl.getOrderNo()));
                if (!Cools.isEmpty(order)) {
                    DocType docType = docTypeService.getOne(new LambdaQueryWrapper<DocType>().eq(DocType::getDocId, order.getDocType()));
                    if (!Cools.isEmpty(docType) && docType.getPakout() == 1) {
                        double count = orderDetl.getAnfme() - orderDetl.getWorkQty();
                        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(count);
                        maps.add(matParam);
                    }
                }
            }
            return R.ok(maps);
        } else {
            List<OrderDetl> list = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>()
                    .eq(OrderDetl::getMatnr, matnr)
                    .like(OrderDetl::getOrderNo, orderNo)
                    .orderByDesc(OrderDetl::getCreateTime));
            for (OrderDetl orderDetl : list
            ) {
                double count = orderDetl.getAnfme() - orderDetl.getWorkQty();
                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(count);
                maps.add(matParam);
            }
            return R.ok(maps);
        }
    }
    /**
     * 并板途中拣料
     *
     * @param combParam
     * @return
     */
    @RequestMapping("/pda/WarehouseOut/v1")
    @ManagerAuth
    public R WarehouseOutV1(@RequestBody CombParam combParam) {
        return mobileService.WarehouseOutV1(combParam, getHostId(), getUserId());
    }
    /**
     * 拣料途中并板
     *
     * @param param
     * @return
     */
    @RequestMapping("/pda/WarehouseOutPickMerge/v1")
    @ManagerAuth
    public R WarehouseOutPickMergeV1(@RequestBody WarehouseOutPickMergeParam param) {
        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());
    }
    @RequestMapping("/menu/pda/auth")
    @ManagerAuth
    public R menuPda(){
    public R menuPda() {
        List<RolePermission> rolePermissions;
        Long roleId = getUser().getRoleId();
        rolePermissions = rolePermissionService.list(new LambdaQueryWrapper<RolePermission>().eq(RolePermission::getRoleId, getHostId()));
@@ -92,11 +196,50 @@
    }
    /**
     * 入库制令检测  -- 指令在库存里面借用批号字段batch
     * 1.可正常入库
     * 2.库存包含相同制令货物,是否进行补货
     * 3.工作档存在正在入库任务,拒绝入库
     */
    @RequestMapping("/pda/decrees/check")
    @ManagerAuth
    public R pdaDecreesCheck(@RequestParam String decrees) {
        if (Cools.isEmpty(decrees)) {
            return R.error("制令不能为空");
        }
        Long hostId = getHostId();
        //查询是否有库存
        List<LocDetl> list = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getBatch, decrees));
        //查询是否有正在工作的工作档
        List<WrkDetl> wrkDetls = wrkDetlService.list(new LambdaQueryWrapper<WrkDetl>().eq(WrkDetl::getBatch, decrees));
        HashMap<String, Object> map = new HashMap<>();
        if (list.isEmpty() && wrkDetls.isEmpty()) {
            map.put("status", 1);//可正常入库
        } else if (!wrkDetls.isEmpty()) {
            map.put("status", 3);//存在工作档,拒绝入库
        } else {
            //获取库存最少的一条记录
            Double anfme = 999999999D;
            LocDetl miniLocDetl = null;
            for (LocDetl locDetl : list) {
                if (locDetl.getAnfme() < anfme) {
                    anfme = locDetl.getAnfme();
                    miniLocDetl = locDetl;
                }
            }
            map.put("status", 2);//库存包含相同制令货物,是否进行补货
            map.put("data", miniLocDetl);//库存信息
        }
        return R.ok().add(map);
    }
    /**
     * 根据单号检索单据数据
     */
    @RequestMapping("/order/search/orderNo/auth")
    @ManagerAuth
    public R orderSearchByBarcode(@RequestParam String orderNo){
    public R orderSearchByBarcode(@RequestParam String orderNo) {
        Order order = orderService.selectByNo(orderNo, getHostId());
        if (order == null) {
            return R.ok();
@@ -117,7 +260,7 @@
    @RequestMapping("/comb/auth")
    @ManagerAuth(memo = "组托")
    public R comb(@RequestBody CombParam combParam){
    public R comb(@RequestBody CombParam combParam) {
        mobileService.comb(combParam, getUserId(), getHostId());
        return R.ok("组托成功");
    }
@@ -127,7 +270,7 @@
    @Deprecated
    public R pakoutQuery(@RequestParam(required = false) String barcode,
                         @RequestParam(required = false) Integer staNo,
                         @RequestParam(required = false) String matnr){
                         @RequestParam(required = false) String matnr) {
        if (Cools.isEmpty(barcode) && Cools.isEmpty(matnr)) {
            return R.ok();
        }
@@ -152,7 +295,7 @@
     */
    @RequestMapping("/pakout/confirm/barcode/auth")
    @ManagerAuth
    public R pakoutQueryByBarcode(@RequestParam(required = false) String barcode){
    public R pakoutQueryByBarcode(@RequestParam(required = false) String barcode) {
        if (Cools.isEmpty(barcode)) {
            return R.ok();
        }
@@ -173,7 +316,7 @@
    @RequestMapping("/pakout/confirm/pick/auth")
    @ManagerAuth
    public R pakoutQueryByBarcode(@RequestParam(required = false) Integer wrkNo
            , @RequestParam(required = false) String matnr){
            , @RequestParam(required = false) String matnr) {
        if (Cools.isEmpty(wrkNo)) {
            return R.ok();
        }
@@ -309,14 +452,14 @@
    @RequestMapping("/adjust/auth")
    @ManagerAuth(memo = "盘点")
    public R adjust(@RequestBody MobileAdjustParam combParam){
    public R adjust(@RequestBody MobileAdjustParam combParam) {
        mobileService.adjust(combParam, getUserId(), getHostId());
        return R.ok("盘点成功");
    }
    @RequestMapping("/loc/f/list")
    @ManagerAuth(memo = "获取在库库位")
    public R locNoF(@RequestParam(required = false) String locNo){
    public R locNoF(@RequestParam(required = false) String locNo) {
        LambdaQueryWrapper<LocMast> wrapper = new LambdaQueryWrapper<LocMast>()
                .eq(LocMast::getLocSts, "F")
                .eq(LocMast::getHostId, getHostId());
@@ -329,7 +472,7 @@
    @RequestMapping("/pick/sta/list")
    @ManagerAuth(memo = "获取并板站")
    public R pickSta(){
    public R pickSta() {
        List<StaDesc> list = staDescService.list(new LambdaQueryWrapper<StaDesc>()
                .eq(StaDesc::getTypeNo, 104)
                .eq(StaDesc::getHostId, getHostId()));
@@ -338,8 +481,75 @@
    @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, "入库"));
    public R pickMats(@RequestParam(required = false) String matnr, @RequestParam(required = false) String orderNo) {
        List<DocType> docTypes = docTypeService.list(new LambdaQueryWrapper<DocType>().like(DocType::getPakin, 1));
        ArrayList<Long> typeList = new ArrayList<>();
        for (DocType docType : docTypes) {
            typeList.add(docType.getDocId());
        }
        LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(Order::getStatus, 1,2);
        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) {
            Date currentDate = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(currentDate);
            calendar.add(Calendar.MONTH, -1);
            Date previousMonthDate = calendar.getTime();
            int result=previousMonthDate.compareTo(order.getCreateTime());
            if(result<0){
                orderIds.add(order.getId());
            }
        }
        //搜索明细
        LambdaQueryWrapper<OrderDetl> wrapper1 = new LambdaQueryWrapper<>();
        wrapper1.eq(OrderDetl::getStatus, 1);
        wrapper1.eq(OrderDetl::getHostId, getHostId());
        wrapper1.in(OrderDetl::getOrderId, orderIds);
        wrapper1.orderByDesc(OrderDetl::getCreateTime);
//        wrapper1.last("LIMIT 1000");
        if (!Cools.isEmpty(matnr)) {
            wrapper1.like(OrderDetl::getMatnr, matnr);
        }
        if (!Cools.isEmpty(orderNo)) {
            wrapper1.like(OrderDetl::getOrderNo, orderNo);
        }
        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.setMaktx(orderDetl.getMaktx());
            matParam.setBatch(orderDetl.getBatch());
            matParam.setOrderNo(orderDetl.getOrderNo());
            matParam.setOrderId(orderDetl.getOrderId());
            matParam.setCount(count);
            matParam.setUseCount(count);
            maps.add(matParam);
        }
        return R.ok().add(maps);
    }
    @RequestMapping("/outBound/order/list")
    @ManagerAuth(memo = "获取出库订单")
    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) {
            typeList.add(docType.getDocId());
@@ -381,7 +591,7 @@
            matParam.setOrderNo(orderDetl.getOrderNo());
            matParam.setOrderId(orderDetl.getOrderId());
            matParam.setCount(count);
            matParam.setUseCount(0D);
            matParam.setUseCount(count);
            maps.add(matParam);
        }
        return R.ok().add(maps);
@@ -390,7 +600,7 @@
    @RequestMapping("/pick/in")
    @ManagerAuth(memo = "并板入库")
    @Transactional
    public R pickConfirm(@RequestBody PickConfirmParam param){
    public R pickConfirm(@RequestBody PickConfirmParam param) {
        LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>()
                .eq(LocMast::getLocNo, param.getLocNo())
                .eq(LocMast::getHostId, getHostId()));
@@ -482,12 +692,21 @@
            wrkDetl.setModiUser(getUserId());
            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()));
@@ -505,4 +724,184 @@
        return R.ok();
    }
    @RequestMapping("/barcode/list/all")
    @ManagerAuth(memo = "并板入库途中拣料出库获取任务信息")
    @Transactional
    public R orderOutListOrder(@RequestBody String barcode) {
        ArrayList<WrkMast> wrkMastArrayList = new ArrayList<>();
        if (Cools.isEmpty(barcode) || barcode.isEmpty()) {
            List<WrkMast> wrkMasts = wrkMastService.list(new LambdaQueryWrapper<WrkMast>()
                    .eq(WrkMast::getHostId, getHostId())
                    .eq(WrkMast::getWrkSts, 199L)
                    .eq(WrkMast::getIoType, 104));
            wrkMastArrayList.addAll(wrkMasts);
            List<WrkMast> wrkMasts1 = wrkMastService.list(new LambdaQueryWrapper<WrkMast>()
                    .eq(WrkMast::getHostId, getHostId())
                    .eq(WrkMast::getWrkSts, 199L)
                    .eq(WrkMast::getIoType, 107));
            wrkMastArrayList.addAll(wrkMasts1);
        } else {
            List<WrkMast> wrkMasts = wrkMastService.list(new LambdaQueryWrapper<WrkMast>()
                    .like(WrkMast::getBarcode, barcode)
                    .eq(WrkMast::getHostId, getHostId())
                    .eq(WrkMast::getWrkSts, 199L)
                    .eq(WrkMast::getIoType, 104));
            wrkMastArrayList.addAll(wrkMasts);
            List<WrkMast> wrkMasts1 = wrkMastService.list(new LambdaQueryWrapper<WrkMast>()
                    .like(WrkMast::getBarcode, barcode)
                    .eq(WrkMast::getHostId, getHostId())
                    .eq(WrkMast::getWrkSts, 199L)
                    .eq(WrkMast::getIoType, 107));
            wrkMastArrayList.addAll(wrkMasts1);
        }
        return R.ok().add(wrkMastArrayList);
    }
    @RequestMapping("/barcode/list/pick")
    @ManagerAuth(memo = "拣料入库途中并板")
    @Transactional
    public R orderOutListOrderPick(@RequestBody(required = false) String barcode) {
        ArrayList<WrkMast> wrkMastArrayList = new ArrayList<>();
        if (Cools.isEmpty(barcode) || barcode.isEmpty()) {
            List<WrkMast> wrkMasts = wrkMastService.list(new LambdaQueryWrapper<WrkMast>()
                    .eq(WrkMast::getHostId, getHostId())
                    .eq(WrkMast::getWrkSts, 199L)
                    .eq(WrkMast::getIoType, 103));
            wrkMastArrayList.addAll(wrkMasts);
            List<WrkMast> wrkMasts1 = wrkMastService.list(new LambdaQueryWrapper<WrkMast>()
                    .eq(WrkMast::getHostId, getHostId())
                    .eq(WrkMast::getWrkSts, 199L)
                    .eq(WrkMast::getIoType, 107));
            wrkMastArrayList.addAll(wrkMasts1);
        } else {
            List<WrkMast> wrkMasts = wrkMastService.list(new LambdaQueryWrapper<WrkMast>()
                    .like(WrkMast::getBarcode, barcode)
                    .eq(WrkMast::getHostId, getHostId())
                    .eq(WrkMast::getWrkSts, 199L)
                    .eq(WrkMast::getIoType, 103)
            );
            wrkMastArrayList.addAll(wrkMasts);
            List<WrkMast> wrkMasts1 = wrkMastService.list(new LambdaQueryWrapper<WrkMast>()
                    .like(WrkMast::getBarcode, barcode)
                    .eq(WrkMast::getHostId, getHostId())
                    .eq(WrkMast::getWrkSts, 199L)
                    .eq(WrkMast::getIoType, 107));
            wrkMastArrayList.addAll(wrkMasts1);
        }
        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);
    }
}