rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocServiceImpl.java
@@ -1,6 +1,5 @@
package com.vincent.rsf.server.manager.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.vincent.rsf.framework.common.R;
@@ -12,16 +11,14 @@
import com.vincent.rsf.server.manager.mapper.LocTypeRelaMapper;
import com.vincent.rsf.server.manager.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import springfox.documentation.annotations.ApiIgnore;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service("locService")
public class LocServiceImpl extends ServiceImpl<LocMapper, Loc> implements LocService {
@@ -52,13 +49,17 @@
            throw new CoolException("修改库位信息不能为空!!");
        }
        String join = loc.getType();
        if (!Objects.isNull(loc.getTypeIds()) && !loc.getTypeIds().isEmpty()) {
             join = StringUtils.join(loc.getTypeIds(), ",");
        }
        boolean update = this.update(new LambdaUpdateWrapper<Loc>()
                .in(Loc::getId, locs.getId())
                .eq(Loc::getStatus, 1)
                .set(!Objects.isNull(loc.getAreaId()), Loc::getAreaId, loc.getAreaId())
                .set(!Objects.isNull(loc.getWarehouseId()), Loc::getWarehouseId, loc.getWarehouseId())
                .set(!Objects.isNull(loc.getUseStatus()), Loc::getUseStatus, loc.getUseStatus())
                .set(!Objects.isNull(loc.getType()), Loc::getType, loc.getType())
                .set(!Objects.isNull(loc.getTypeIds()) && !loc.getTypeIds().isEmpty(), Loc::getType, join)
                .set(!Objects.isNull(loc.getLength()), Loc::getLength, loc.getLength())
                .set(!Objects.isNull(loc.getWidth()), Loc::getWidth, loc.getWidth())
                .set(!Objects.isNull(loc.getHeight()), Loc::getHeight, loc.getHeight())
@@ -74,16 +75,24 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R initLocs(LocMastInitParam param) {
    public R initLocs(LocMastInitParam param, Long loginUserId) {
        //清空表
        this.baseMapper.deleteAll();
//        this.baseMapper.deleteAll();
        //清空当前库区库位
        List<Loc> locs = this.list(new LambdaQueryWrapper<Loc>().eq(Loc::getWarehouseId, param.getWarehouseId()).eq(Loc::getAreaId, param.getAreaId()));
        if (!locs.isEmpty()) {
            if (!this.remove(new LambdaQueryWrapper<Loc>().eq(Loc::getWarehouseId, param.getWarehouseId()).eq(Loc::getAreaId, param.getAreaId()))) {
                throw new CoolException("初始化失败:数据删除失败!!");
            }
        }
        WarehouseAreas warehouseAreas = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>()
                .eq(WarehouseAreas::getWarehouseId, param.getWarehouseId())
                .eq(WarehouseAreas::getId, param.getAreaId()));
        if (Objects.isNull(warehouseAreas)) {
            throw new CoolException("库区不存在!!");
        }
        String join = StringUtils.join(param.getTypeIds(), ",");
        List<Loc> list = new ArrayList<>();
        for (int r = param.getStartRow(); r <= param.getEndRow(); r++) {
            for (int b = param.getStartBay(); b <= param.getEndBay(); b++) {
@@ -96,16 +105,30 @@
                            .setRow(r)
                            .setCol(b)
                            .setLev(l)
                            .setType(join)
                            .setAreaId(param.getAreaId())
                            .setWarehouseId(warehouseAreas.getWarehouseId())
                            .setType(param.getType());
                            .setUpdateBy(loginUserId)
                            .setCreateBy(loginUserId)
                            .setWarehouseId(warehouseAreas.getWarehouseId());
                    list.add(loc);
                }
            }
        }
        if (!this.saveBatch(list)) {
            throw new CoolException("库位初始化失败!!");
        }
        List<LocTypeRela> locTypeRelas = new ArrayList<>();
        for (Long typeId : param.getTypeIds()) {
            for (Loc loc : list) {
                LocTypeRela typeRela = new LocTypeRela();
                typeRela.setLocId(loc.getId()).setTypeId(typeId);
                locTypeRelas.add(typeRela);
            }
        }
        if (!locTypeRelaService.saveBatch(locTypeRelas)) {
            throw new CoolException("库位类型关联失败!!");
        }
        return R.ok("初始化成功!!");
    }