package com.vincent.rsf.server.manager.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.vincent.rsf.framework.common.R;
|
import com.vincent.rsf.framework.exception.CoolException;
|
import com.vincent.rsf.server.manager.controller.params.LocMastInitParam;
|
import com.vincent.rsf.server.manager.controller.params.LocModifyParams;
|
import com.vincent.rsf.server.manager.entity.WarehouseAreas;
|
import com.vincent.rsf.server.manager.mapper.LocMapper;
|
import com.vincent.rsf.server.manager.entity.Loc;
|
import com.vincent.rsf.server.manager.service.LocService;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.vincent.rsf.server.manager.service.WarehouseAreasService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
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.util.stream.Collectors;
|
|
@Service("locService")
|
public class LocServiceImpl extends ServiceImpl<LocMapper, Loc> implements LocService {
|
|
@Autowired
|
private WarehouseAreasService warehouseAreasService;
|
|
@Override
|
public R modifyLocs(LocModifyParams locs) {
|
if (locs.getId().isEmpty()) {
|
throw new CoolException("库位ID不能为空!!");
|
}
|
Loc loc = locs.getLoc();
|
|
if (Objects.isNull(loc)) {
|
throw new CoolException("修改库位信息不能为空!!");
|
}
|
|
boolean update = this.update(new LambdaUpdateWrapper<Loc>()
|
.in(Loc::getId, locs.getId())
|
.eq(Loc::getStatus, 1)
|
.set(!Objects.isNull(loc.getUseStatus()), Loc::getUseStatus, loc.getUseStatus())
|
.set(!Objects.isNull(loc.getType()), Loc::getType, loc.getType())
|
.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())
|
.set(!Objects.isNull(loc.getChannel()), Loc::getChannel, loc.getChannel())
|
.set(!Objects.isNull(loc.getFlagLabelMange()), Loc::getFlagLabelMange, loc.getFlagLabelMange())
|
.set(!Objects.isNull(loc.getStatus()), Loc::getStatus, loc.getStatus()));
|
if (!update) {
|
throw new CoolException("库位信息修改失败!!");
|
}
|
return R.ok("操作成功!!");
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public R initLocs(LocMastInitParam param) {
|
//清空表
|
if (this.baseMapper.delete(new LambdaUpdateWrapper<>()) < 0) {
|
throw new CoolException("数据库初始化失败:老数据删除失败!!");
|
}
|
WarehouseAreas warehouseAreas = warehouseAreasService.getById(param.getAreaId());
|
if (Objects.isNull(warehouseAreas)) {
|
throw new CoolException("库区不存在!!");
|
}
|
|
List<Loc> list = new ArrayList<>();
|
for (int r = param.getStartRow(); r <= param.getEndRow(); r++) {
|
for (int b = param.getStartBay(); b <= param.getEndBay(); b++) {
|
for (int l = param.getStartLev(); l <= param.getEndLev(); l++) {
|
// 获取库位号
|
String locNo = String.format("%02d", r) + String.format("%03d", b) + String.format("%02d", l);
|
Loc loc = new Loc();
|
loc.setCode(locNo)
|
.setUseStatus("O")
|
.setRow(r)
|
.setCol(b)
|
.setLev(l)
|
.setAreaId(param.getAreaId())
|
.setWarehouseId(warehouseAreas.getWareId())
|
.setType(param.getType());
|
|
list.add(loc);
|
}
|
}
|
}
|
if (!this.saveBatch(list)) {
|
throw new CoolException("库位初始化失败!!");
|
}
|
return R.ok("初始化成功!!");
|
}
|
}
|