#
luxiaotao1123
2021-03-24 df142079833e357624e64bd327e40e1f5f2e8fa9
src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
/**
@@ -50,6 +51,8 @@
    private AsrsService asrsService;
    @Autowired
    private ErpService erpService;
    @Autowired
    private CheckService checkService;
    @Override
    @Transactional
@@ -414,7 +417,117 @@
    @Override
    public R stockCheck(StoCheckParam param, Long userId) {
        if (Cools.isEmpty(param.getLocNo())) {
            return R.error("请选择货位");
        }
        Node node = nodeService.selectByUuid(param.getLocNo());
        if (Cools.isEmpty(node)) {
            return R.error("货位异常,请联系管理员");
        }
        // 准备数据
        Date now = new Date();
        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("node_id", node.getId()));
        List<String> locDetlMatnrs = new ArrayList<>();
        locDetls.forEach(locDetl -> {
            locDetlMatnrs.add(locDetl.getMatnr());
        });
        Iterator<LocDetl> detlIterator = locDetls.iterator();
        List<PakinMatDto> dtos = param.getDtos();
        // 1.盈亏 修改数量
        while (detlIterator.hasNext()){
            LocDetl locDetl = detlIterator.next();
            for (PakinMatDto dto : dtos) {
                if (locDetl.getMatnr().equals(dto.getMatnr())) {
                    if (!locDetl.getAnfme().equals(dto.getCount())) {
                        Check check = new Check(
                                String.valueOf(snowflakeIdWorker.nextId()),    // 盘点编号
                                node.getId(),    // 盘点货位
                                node.getUuid(),    // 货位编号
                                node.getName(),    // 货位名称
                                locDetl.getMatnr(),    // 商品编号
                                locDetl.getMaktx(),    // 商品名称
                                locDetl.getUnit(),    // 单位
                                null,    // 单据类型
                                null,    // 单据编号
                                locDetl.getAnfme(),    // 账面数量
                                dto.getCount(),    // 实盘数量
                                locDetl.getAnfme() < dto.getCount() ? 1 : 2,    // 盈亏
                                1,    // 状态
                                userId,    // 添加人员
                                now,    // 添加时间
                                userId,    // 修改人员
                                now,    // 修改时间
                                null    // 备注
                        );
                        if (!checkService.insert(check)) {
                            throw new CoolException("保存盘点记录失败");
                        }
                    }
                    detlIterator.remove();
                    break;
                }
            }
        }
        // 2.盘亏 删除库存
        for (LocDetl locDetl : locDetls) {
            Check check = new Check(
                    String.valueOf(snowflakeIdWorker.nextId()),    // 盘点编号
                    node.getId(),    // 盘点货位
                    node.getUuid(),    // 货位编号
                    node.getName(),    // 货位名称
                    locDetl.getMatnr(),    // 商品编号
                    locDetl.getMaktx(),    // 商品名称
                    locDetl.getUnit(),    // 单位
                    null,    // 单据类型
                    null,    // 单据编号
                    locDetl.getAnfme(),    // 账面数量
                    0D,    // 实盘数量
                    2,    // 盈亏
                    1,    // 状态
                    userId,    // 添加人员
                    now,    // 添加时间
                    userId,    // 修改人员
                    now,    // 修改时间
                    null    // 备注
            );
            if (!checkService.insert(check)) {
                throw new CoolException("保存盘点记录失败");
            }
        }
        // 3.盘盈 新增库存
        for (PakinMatDto dto : dtos) {
            if (!locDetlMatnrs.contains(dto.getMatnr())) {
                Mat mat = matService.selectByMatnr(dto.getMatnr());
                Check check = new Check(
                        String.valueOf(snowflakeIdWorker.nextId()),    // 盘点编号
                        node.getId(),    // 盘点货位
                        node.getUuid(),    // 货位编号
                        node.getName(),    // 货位名称
                        mat.getMatnr(),    // 商品编号
                        mat.getMaktx(),    // 商品名称
                        mat.getUnit(),    // 单位
                        null,    // 单据类型
                        null,    // 单据编号
                        0D,    // 账面数量
                        dto.getCount(),    // 实盘数量
                        1,    // 盈亏
                        1,    // 状态
                        userId,    // 添加人员
                        now,    // 添加时间
                        userId,    // 修改人员
                        now,    // 修改时间
                        null    // 备注
                );
                if (!checkService.insert(check)) {
                    throw new CoolException("保存盘点记录失败");
                }
            }
        }
        return R.ok();
    }