skyouc
2025-01-08 d1511d2d12b4223882fcfdabd3ba6b59c038edc4
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/MobileServiceImpl.java
@@ -1,12 +1,17 @@
package com.zy.asrs.wms.asrs.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wms.asrs.entity.*;
import com.zy.asrs.wms.asrs.entity.dto.PickSheetDetlDto;
import com.zy.asrs.wms.asrs.entity.enums.*;
import com.zy.asrs.wms.asrs.entity.enums.OrderType;
import com.zy.asrs.wms.asrs.entity.param.BatchMergeOrdersParam;
import com.zy.asrs.wms.asrs.entity.param.GeneratePakInParam;
import com.zy.asrs.wms.asrs.entity.param.PageRequest;
import com.zy.asrs.wms.asrs.entity.param.PakinOnShelvesParams;
import com.zy.asrs.wms.asrs.service.*;
import com.zy.asrs.wms.system.entity.Host;
@@ -16,10 +21,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@Service
@@ -45,7 +48,10 @@
    private LocAreaService locAreaService;
    @Autowired
    private LocAreaTypeService locAreaTypeService;
    @Autowired
    private PickSheetService pickSheetService;
    @Autowired
    private PickSheetDetlService pickSheetDetlService;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -133,11 +139,12 @@
            LocDetl locDetl = new LocDetl();
            locDetl.setAnfme(pakin.getAnfme());
            locDetl.setBatch(pakin.getBatch());
            locDetl.setMatnr(pakin.getMatnr());
            locDetl.setMatId(pakin.getMatnrId$());
            ;
            locDetl.setCreateTime(new Date());
            locDetl.setOrderNo(pakin.getOrderNo());
            locDetl.setLocNo(loc.getLocNo());
            locDetl.setLocId(loc.getLocStsId());
            locDetl.setLocId(loc.getId());
            locDetl.setMatnr(pakin.getMatnr());
            locDetl.setMemo(pakin.getMemo());
            locDetl.setUpdateTime(new Date());
@@ -149,7 +156,6 @@
        });
        //删除组拖档,加入历史组拖档
        List<WaitPakinLog> waitPakinLogs = new ArrayList<>();
        waitPakins.forEach(waitPakin -> {
            WaitPakinLog pakinLog = new WaitPakinLog();
            BeanUtils.copyProperties(waitPakin, pakinLog);
@@ -179,15 +185,84 @@
        return true;
    }
//    /**
//     * 获取当前库位是否存在
//     * @param shelvesParams
//     * @return
//     */
//    @Override
//    public Loc selectPakinLocs(PakinOnShelvesParams shelvesParams) {
//        return locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, shelvesParams.getLoc()));
//    }
    @Override
    public PickSheetDetlDto outFlatSheet(String code) {
        PickSheetDetlDto pickDetlDto = new PickSheetDetlDto();
        PickSheet pickSheet = pickSheetService.getOne(new LambdaQueryWrapper<PickSheet>()
                .eq(PickSheet::getPickNo, code)
                .eq(PickSheet::getDeleted, 0)
                .eq(PickSheet::getStatus, 1)
        );
        BeanUtils.copyProperties(pickSheet, pickDetlDto);
        if (Objects.isNull(pickDetlDto)) {
            throw new CoolException("对象复制失败!!");
        }
        List<PickSheetDetl> sheetDetls = pickSheetDetlService.list(new LambdaQueryWrapper<PickSheetDetl>()
                .eq(PickSheetDetl::getPickId, pickSheet.getId())
                .eq(PickSheetDetl::getStatus, 1)
                .eq(PickSheetDetl::getDeleted, 0));
        pickDetlDto.setPickSheetDetlList(sheetDetls);
        return pickDetlDto;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean confirmFlatSheet(String code) {
        PickSheet pickSheet = pickSheetService.getOne(new LambdaQueryWrapper<PickSheet>().eq(PickSheet::getPickNo, code));
        if (pickSheet.getStatus() == 1) {
            //状态修改为: 已转历史档
            pickSheet.setStatus(3);
            if (!pickSheetService.updateById(pickSheet)) {
                throw new CoolException("转历史档失败!!");
            } else{
                if (!pickSheetDetlService.update(new LambdaUpdateWrapper<PickSheetDetl>().eq(PickSheetDetl::getPickId, pickSheet.getId()).set(PickSheetDetl::getStatus, 3))) {
                    throw new CoolException("拣货单明细转历史档失败!!");
                }
            }
        } else {
            throw new CoolException("请勿操作历史档数据!!");
        }
        List<PickSheetDetl> sheetDetls = pickSheetDetlService.list(new LambdaQueryWrapper<PickSheetDetl>().eq(PickSheetDetl::getPickId, pickSheet.getId()));
        Map<Long, List<PickSheetDetl>> listMap = sheetDetls.stream().collect(Collectors.groupingBy(PickSheetDetl::getLocId));
        listMap.keySet().forEach(key -> {
            Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getId, key));
            listMap.get(key).forEach(pickDetl -> {
                LocDetl detl = locDetlService.getOne(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getId, pickDetl.getLocDetlId()));
                if (Objects.isNull(detl)) {
                    throw new CoolException("数据错误!!");
                }
                //更新锁定库存
                BigDecimal workQty = BigDecimal.valueOf(detl.getAnfme()).subtract(pickDetl.getAnfme());
                detl.setWorkQty(workQty.doubleValue());
                //计算结果小于等于零,移出库存明细
                BigDecimal qty = BigDecimal.valueOf(detl.getAnfme()).subtract(pickDetl.getAnfme());
                detl.setAnfme(qty.doubleValue());
                if (qty.compareTo(new BigDecimal("0.00")) <= 0) {
                    detl.setDeleted(1);
                    if (!locDetlService.removeById(detl)) {
                        throw new CoolException("库存明细删除失败!!");
                    }
                } else { //结果大于零,更新库存明细
                    if (!locDetlService.updateById(detl)) {
                        throw new CoolException("库存明细更新失败!!");
                    }
                }
            });
            /**明细更新完成后,判断是否为空,为空更新主单状态为空库,拖盘码清空,不为空不做更新**/
            List<LocDetl> list = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, loc.getId()).eq(LocDetl::getDeleted, 0));
            if (list.isEmpty()) {
                boolean update = locService.update(new LambdaUpdateWrapper<Loc>()
                        .eq(Loc::getId, loc.getId())
                        .set(Loc::getBarcode, null)
                        .set(Loc::getUpdateTime, new Date())
                        .set(Loc::getLocStsId, LocStsType.O.val()));
                if (update) {
                    throw new CoolException("库存更新失败!! ");
                }
            }
        });
        return true;
    }
}