|  |  |  | 
|---|
|  |  |  | package com.vincent.rsf.server.manager.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.R; | 
|---|
|  |  |  | import com.vincent.rsf.framework.exception.CoolException; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.controller.params.InitContainerParams; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.WarehouseAreas; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.QRCodeType; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.mapper.BasContainerMapper; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.BasContainer; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.BasContainerService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.WarehouseAreasService; | 
|---|
|  |  |  | import org.apache.tika.utils.StringUtils; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service("basContainerService") | 
|---|
|  |  |  | public class BasContainerServiceImpl extends ServiceImpl<BasContainerMapper, BasContainer> implements BasContainerService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WarehouseAreasService warehouseAreasService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 容器初始化 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param params | 
|---|
|  |  |  | * @param loginUserId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public R init(InitContainerParams params, Long loginUserId) { | 
|---|
|  |  |  | if (Objects.isNull(params.getStartNo())) { | 
|---|
|  |  |  | throw new CoolException("容器起始值不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(params.getEndNo())) { | 
|---|
|  |  |  | throw new CoolException("容器结束值不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WarehouseAreas areas = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>().eq(WarehouseAreas::getId, 42L)); | 
|---|
|  |  |  | if (Objects.isNull(areas)) { | 
|---|
|  |  |  | throw new CoolException("库区不存在,请联系管理员!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (params.getFlagInit()) { | 
|---|
|  |  |  | this.remove(new LambdaQueryWrapper<>()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<BasContainer> containerList = new ArrayList<>(); | 
|---|
|  |  |  | for (int i = params.getStartNo(); i <= params.getEndNo() ; i++) { | 
|---|
|  |  |  | BasContainer container = new BasContainer(); | 
|---|
|  |  |  | String code = StringUtils.leftPad(i + "", params.getLength(), "0"); | 
|---|
|  |  |  | if (!params.getContainerType().equals(3L)) { | 
|---|
|  |  |  | params.setPrefix("81"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | container.setAreas(areas.getName()) | 
|---|
|  |  |  | .setCodeType(QRCodeType.QRCODE_TYPE_BARCODE.desc) | 
|---|
|  |  |  | .setCode(params.getPrefix() + code) | 
|---|
|  |  |  | .setCreateTime(new Date()) | 
|---|
|  |  |  | .setCreateBy(loginUserId) | 
|---|
|  |  |  | .setUpdateBy(loginUserId) | 
|---|
|  |  |  | .setUpdateTime(new Date()) | 
|---|
|  |  |  | .setContainerType(params.getContainerType()); | 
|---|
|  |  |  | containerList.add(container); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!this.saveBatch(containerList)) { | 
|---|
|  |  |  | throw new CoolException("容器保存失败,请检查编码是否有重复!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok("新增成功!!").add(containerList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|