| | |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasAreas; |
| | | import com.zy.asrs.entity.LocCache; |
| | |
| | | |
| | | @Autowired |
| | | private BasAreasService basAreasService; |
| | | |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | |
| | | /** |
| | | * @author Ryan |
| | |
| | | String locNo = areas.getAreaNo() + String.format("%02d", r) + String.format("%03d", b) + String.format("%02d", l); |
| | | Date now = new Date(); |
| | | LocCache locMast = new LocCache(); |
| | | // 手动生成ID |
| | | locMast.setId(snowflakeIdWorker.nextId()); |
| | | locMast.setLocNo(locNo); |
| | | locMast.setLocSts("O"); |
| | | locMast.setRow1(r); // 排 |
| | | locMast.setBay1(b); // 列 |
| | | locMast.setLev1(l); // 层 |
| | | locMast.setId(null); |
| | | locMast.setLocType1(!Cools.isEmpty(param.getLocType1()) ? param.getLocType1() : 1); |
| | | locMast.setLocType2(param.getLocType2()); |
| | | locMast.setLocType3(param.getLocType3()); |
| | |
| | | } |
| | | } |
| | | |
| | | if (!this.insertBatch(list)) { |
| | | throw new CoolException("添加失败!!"); |
| | | // SQL Server 批量插入获取生成键可能失败,改用循环单条插入确保所有记录都能成功插入 |
| | | int successCount = 0; |
| | | for (LocCache locCache : list) { |
| | | if (this.insert(locCache)) { |
| | | successCount++; |
| | | } else { |
| | | log.error("插入库位失败: {}", locCache.getLocNo()); |
| | | } |
| | | } |
| | | return R.ok("初始化成功"); |
| | | |
| | | if (successCount != list.size()) { |
| | | throw new CoolException(String.format("添加失败!成功插入 %d 条,应插入 %d 条", successCount, list.size())); |
| | | } |
| | | |
| | | return R.ok("初始化成功,共插入 " + successCount + " 条记录"); |
| | | } catch (Exception e) { |
| | | log.error("初始化库位失败", e); |
| | | return R.error("初始化失败===>" + e.getMessage()); |
| | | } |
| | | } |