#
Junjie
2025-02-14 ac4341ea6b66ae02427d39d35f41d42d78b2eb2e
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/controller/WorkController.java
@@ -58,65 +58,12 @@
    @PostMapping("/loc/adjust")
    @Transactional
    public R locAdjust(@RequestBody LocAdjustParam param) {
        if (param == null) {
            return R.error("参数不能为空");
        try {
            workService.locAdjust(param);
            return R.ok();
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
        if (Cools.isEmpty(param.getLocNo())) {
            return R.error("库位号不能为空");
        }
        if (param.getDetls() == null) {
            return R.error("库存明细不能为空");
        }
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, param.getLocNo()));
        if (loc == null) {
            return R.error("库位不存在");
        }
        //删除源库存
        locDetlService.removeLocDetl(loc.getId());
        List<MatField> matFields = matFieldService.list(new LambdaQueryWrapper<MatField>().eq(MatField::getUnique, 1));
        for (Map<String, Object> map : param.getDetls()) {
            LocDetl locDetl = JSON.parseObject(JSON.toJSONString(map), LocDetl.class);
            HashMap<String, Object> uniqueFields = new HashMap<>();
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                for (MatField field : matFields) {
                    if (entry.getKey().equals(field.getName())) {
                        uniqueFields.put(entry.getKey(), entry.getValue());
                    }
                }
            }
            locDetl.setAnfme(Double.parseDouble(map.get("qty").toString()));
            locDetl.syncFieldMap(uniqueFields);
            if (locDetl.getAnfme() <= 0D) {
                throw new CoolException("数量不能小于0");
            }
            locDetl.setId(null);
            locDetl.setLocId(loc.getId());
            locDetl.setLocNo(loc.getLocNo());
            boolean save = locDetlService.save(locDetl);
            if (!save) {
                throw new CoolException("库存调整失败");
            }
            //插入库存明细字段
            for (MatField matField : matFields) {
                LocDetlField locDetlField = new LocDetlField();
                locDetlField.setDetlId(locDetl.getId());
                locDetlField.setFieldId(matField.getId());
                locDetlField.setName(matField.getName());
                locDetlField.setValue(Optional.ofNullable(uniqueFields.get(matField.getName()).toString()).orElse(""));
                locDetlFieldService.save(locDetlField);
            }
        }
        return R.ok();
    }
    @OperationLog("库存移转")