src/main/java/com/ruoyi/warehouse/controller/WarehouseController.java
@@ -9,6 +9,7 @@ import com.ruoyi.framework.web.domain.AjaxResult; import com.ruoyi.warehouse.pojo.Warehouse; import com.ruoyi.warehouse.service.WarehouseGoodsShelvesService; import com.ruoyi.warehouse.service.WarehouseService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -25,18 +26,18 @@ @Autowired private WarehouseService warehouseService; @GetMapping("/listPage") @ApiOperation("仓库-分页查询") @Log(title = "仓库-分页查询", businessType = BusinessType.OTHER) public AjaxResult listPage(Page page, Warehouse warehouse) { IPage<Warehouse> listPage = warehouseService.listPage(page, warehouse); return AjaxResult.success(listPage); @ApiOperation("仓库-查询") @Log(title = "仓库-查询", businessType = BusinessType.OTHER) public AjaxResult listPage( Warehouse warehouse) { return AjaxResult.success(warehouseService.listPage( warehouse)); } @PostMapping("/add") @ApiOperation("仓库-添加") @Log(title = "仓库-添加", businessType = BusinessType.INSERT) public AjaxResult add(@RequestBody Warehouse warehouse) { return AjaxResult.success(warehouseService.save(warehouse)); return warehouseService.save(warehouse) ? AjaxResult.success("添加成功") : AjaxResult.error("添加失败"); } @PostMapping("/update") @@ -51,6 +52,6 @@ @Log(title = "仓库-删除", businessType = BusinessType.DELETE) public AjaxResult delete(@RequestBody List<Long> ids) { if(CollectionUtils.isEmpty(ids)) return AjaxResult.error("请传入要删除的ID"); return AjaxResult.success(warehouseService.deleteByIds(ids)); return warehouseService.deleteByIds(ids) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败"); } } src/main/java/com/ruoyi/warehouse/controller/WarehouseGoodsShelvesController.java
@@ -1,5 +1,6 @@ package com.ruoyi.warehouse.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -29,6 +30,15 @@ IPage<WarehouseGoodsShelves> listPage = warehouseGoodsShelvesService.listPage(page, warehouseGoodsShelves); return AjaxResult.success(listPage); } @GetMapping("/listById") @ApiOperation("商品货架-查询") @Log(title = "商品货架-查询", businessType = BusinessType.OTHER) public AjaxResult listById(Long warehouseId) { List<WarehouseGoodsShelves> list = warehouseGoodsShelvesService.list(new QueryWrapper<WarehouseGoodsShelves>().lambda() .eq(WarehouseGoodsShelves::getWarehouseId, warehouseId)); return AjaxResult.success(list); } @PostMapping("/add") @ApiOperation("商品货架-添加") @Log(title = "商品货架-添加", businessType = BusinessType.INSERT) src/main/java/com/ruoyi/warehouse/mapper/WarehouseMapper.java
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import java.util.List; /** * @author 86151 * @description 针对表【warehouse(仓库表)】的数据库操作Mapper @@ -16,7 +18,7 @@ @Mapper public interface WarehouseMapper extends BaseMapper<Warehouse> { IPage<Warehouse> listPage(Page page,@Param("warehouse") Warehouse warehouse); List<Warehouse> listPage(@Param("warehouse") Warehouse warehouse); } src/main/java/com/ruoyi/warehouse/pojo/Warehouse.java
@@ -1,9 +1,7 @@ package com.ruoyi.warehouse.pojo; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.*; import java.io.Serializable; import java.time.LocalDateTime; import java.util.Date; @@ -33,28 +31,32 @@ /** * 创建时间 */ @TableField(fill = FieldFill.INSERT) private LocalDateTime createTime; /** * 创建用户 */ @TableField(fill = FieldFill.INSERT) private Long createUser; /** * 修改时间 */ @TableField(fill = FieldFill.INSERT_UPDATE) private LocalDateTime updateTime; /** * 修改用户 */ @TableField(fill = FieldFill.INSERT_UPDATE) private Long updateUser; /** * 租户ID */ @TableField(fill = FieldFill.INSERT) private Long tenantId; @TableField(exist = false) private static final long serialVersionUID = 1L; } src/main/java/com/ruoyi/warehouse/pojo/WarehouseGoodsShelves.java
@@ -1,9 +1,7 @@ package com.ruoyi.warehouse.pojo; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.*; import java.io.Serializable; import java.time.LocalDateTime; import java.util.Date; @@ -47,28 +45,33 @@ /** * 创建时间 */ @TableField(fill = FieldFill.INSERT) private LocalDateTime createTime; /** * 创建用户 */ @TableField(fill = FieldFill.INSERT) private Long createUser; /** * 修改时间 */ @TableField(fill = FieldFill.INSERT_UPDATE) private LocalDateTime updateTime; /** * 修改用户 */ @TableField(fill = FieldFill.INSERT_UPDATE) private Long updateUser; /** * 租户ID */ @TableField(fill = FieldFill.INSERT) private Long tenantId; @TableField(exist = false) private static final long serialVersionUID = 1L; } src/main/java/com/ruoyi/warehouse/pojo/WarehouseGoodsShelvesRowcol.java
@@ -1,9 +1,7 @@ package com.ruoyi.warehouse.pojo; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.*; import java.io.Serializable; import java.time.LocalDateTime; import java.util.Date; @@ -19,6 +17,7 @@ @Data @ApiModel(value = "仓库货架层,列表") public class WarehouseGoodsShelvesRowcol implements Serializable { private static final long serialVersionUID = 1L; /** * @@ -44,6 +43,7 @@ /** * 创建时间 */ private LocalDateTime createTime; /** @@ -54,16 +54,19 @@ /** * 修改时间 */ @TableField(fill = FieldFill.INSERT_UPDATE) private LocalDateTime updateTime; /** * 修改用户 */ @TableField(fill = FieldFill.INSERT) private Long updateUser; /** * 租户ID */ @TableField(fill = FieldFill.INSERT) private Long tenantId; /** * 备注 src/main/java/com/ruoyi/warehouse/service/WarehouseService.java
@@ -1,8 +1,6 @@ package com.ruoyi.warehouse.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.warehouse.pojo.Warehouse; @@ -15,7 +13,7 @@ */ public interface WarehouseService extends IService<Warehouse> { IPage<Warehouse> listPage(Page page, Warehouse warehouse); List<Warehouse> listPage( Warehouse warehouse); boolean deleteByIds(List<Long> ids); } src/main/java/com/ruoyi/warehouse/service/impl/WarehouseGoodsShelvesServiceImpl.java
@@ -19,6 +19,7 @@ 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.Arrays; @@ -46,6 +47,7 @@ } @Override @Transactional(rollbackFor = Exception.class) public boolean add(WarehouseGoodsShelves warehouseGoodsShelves) { int insert = warehouseGoodsShelvesMapper.insert(warehouseGoodsShelves); if (insert <= 0) { @@ -54,8 +56,6 @@ } Long shelvesId = warehouseGoodsShelves.getId(); Long warehouseId = warehouseGoodsShelves.getWarehouseId(); Long createUser = warehouseGoodsShelves.getCreateUser(); Long updateUser = warehouseGoodsShelves.getUpdateUser(); // 3. 批量创建行列记录 List<WarehouseGoodsShelvesRowcol> rowcolList = new ArrayList<>(); for (long i = 1; i <= warehouseGoodsShelves.getStorey(); i++) { @@ -64,9 +64,6 @@ rowcol.setStorey(i); rowcol.setArrange(j); rowcol.setWarehouseGoodsShelvesId(shelvesId); rowcol.setWarehouseId(warehouseId); rowcol.setCreateUser(createUser); rowcol.setUpdateUser(updateUser); rowcolList.add(rowcol); } } @@ -74,11 +71,7 @@ if (!rowcolList.isEmpty()) { try { // 使用批量插入方法替代循环单条插入 boolean saveBatch = warehouseGoodsShelvesRowcolService.saveBatch(rowcolList); if (!saveBatch) { log.warn("货架[{}]的行列记录部分添加失败", shelvesId); } warehouseGoodsShelvesRowcolService.saveBatch(rowcolList); } catch (Exception e) { log.error("货架[{}]的行列记录批量添加失败", shelvesId, e); // 抛出异常触发事务回滚 @@ -87,7 +80,7 @@ } log.info("货架[{}]添加成功,层数:{},排数:{}", shelvesId, warehouseGoodsShelves.getGoodsShelvesName(), warehouseGoodsShelves.getStorey(), warehouseGoodsShelves.getArrange()); return true; src/main/java/com/ruoyi/warehouse/service/impl/WarehouseServiceImpl.java
@@ -1,5 +1,6 @@ package com.ruoyi.warehouse.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -13,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.sql.Array; import java.util.List; /** @@ -30,22 +32,21 @@ private WarehouseGoodsShelvesService warehouseGoodsShelvesService; @Override public IPage<Warehouse> listPage(Page page, Warehouse warehouse) { return warehouseMapper.listPage(page, warehouse); public List<Warehouse> listPage(Warehouse warehouse) { return warehouseMapper.listPage( warehouse); } @Override public boolean deleteByIds(List<Long> ids) { for (Long id : ids) { WarehouseGoodsShelves shelves = new WarehouseGoodsShelves(); shelves.setWarehouseId(id); IPage<WarehouseGoodsShelves> page = warehouseGoodsShelvesService.listPage(new Page<>(), shelves); if(page.getRecords().size()>0){ log.error("仓库下有货架,不能删除"); List<WarehouseGoodsShelves> list = warehouseGoodsShelvesService.list(new QueryWrapper<WarehouseGoodsShelves>().lambda() .eq(WarehouseGoodsShelves::getWarehouseId, id)); if(list.size()>0){ log.error("仓库下有货架,不能删除 重新选择"); return false; } } return true; return removeByIds(ids); } }