feat(shop): 添加仓库管理功能

- 创建ShopWarehouse实体类,包含仓库基本信息字段
- 实现ShopWarehouseController控制器,提供CRUD和批量操作接口
- 开发ShopWarehouseService业务接口及其实现类
- 配置ShopWarehouseMapper数据访问层和XML映射文件
- 添加ShopWarehouseParam查询参数类
- 集成权限控制、分页查询和关联查询功能
- 实现仓库类型的增删改查和批量处理逻辑
This commit is contained in:
2026-01-30 19:08:58 +08:00
parent 0cd1cb26f1
commit 5753163c0e
7 changed files with 489 additions and 0 deletions

View File

@@ -0,0 +1,127 @@
package com.gxwebsoft.shop.controller;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.shop.service.ShopWarehouseService;
import com.gxwebsoft.shop.entity.ShopWarehouse;
import com.gxwebsoft.shop.param.ShopWarehouseParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 仓库控制器
*
* @author 科技小王子
* @since 2026-01-30 17:46:48
*/
@Tag(name = "仓库管理")
@RestController
@RequestMapping("/api/shop/shop-warehouse")
public class ShopWarehouseController extends BaseController {
@Resource
private ShopWarehouseService shopWarehouseService;
@Operation(summary = "分页查询仓库")
@GetMapping("/page")
public ApiResult<PageResult<ShopWarehouse>> page(ShopWarehouseParam param) {
// 使用关联查询
return success(shopWarehouseService.pageRel(param));
}
@PreAuthorize("hasAuthority('shop:shopWarehouse:list')")
@Operation(summary = "查询全部仓库")
@GetMapping()
public ApiResult<List<ShopWarehouse>> list(ShopWarehouseParam param) {
// 使用关联查询
return success(shopWarehouseService.listRel(param));
}
@PreAuthorize("hasAuthority('shop:shopWarehouse:list')")
@Operation(summary = "根据id查询仓库")
@GetMapping("/{id}")
public ApiResult<ShopWarehouse> get(@PathVariable("id") Integer id) {
// 使用关联查询
return success(shopWarehouseService.getByIdRel(id));
}
@PreAuthorize("hasAuthority('shop:shopWarehouse:save')")
@OperationLog
@Operation(summary = "添加仓库")
@PostMapping()
public ApiResult<?> save(@RequestBody ShopWarehouse shopWarehouse) {
// 记录当前登录用户id
// User loginUser = getLoginUser();
// if (loginUser != null) {
// shopWarehouse.setUserId(loginUser.getUserId());
// }
if (shopWarehouseService.save(shopWarehouse)) {
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('shop:shopWarehouse:update')")
@OperationLog
@Operation(summary = "修改仓库")
@PutMapping()
public ApiResult<?> update(@RequestBody ShopWarehouse shopWarehouse) {
if (shopWarehouseService.updateById(shopWarehouse)) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('shop:shopWarehouse:remove')")
@OperationLog
@Operation(summary = "删除仓库")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
if (shopWarehouseService.removeById(id)) {
return success("删除成功");
}
return fail("删除失败");
}
@PreAuthorize("hasAuthority('shop:shopWarehouse:save')")
@OperationLog
@Operation(summary = "批量添加仓库")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<ShopWarehouse> list) {
if (shopWarehouseService.saveBatch(list)) {
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('shop:shopWarehouse:update')")
@OperationLog
@Operation(summary = "批量修改仓库")
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<ShopWarehouse> batchParam) {
if (batchParam.update(shopWarehouseService, "id")) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('shop:shopWarehouse:remove')")
@OperationLog
@Operation(summary = "批量删除仓库")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
if (shopWarehouseService.removeByIds(ids)) {
return success("删除成功");
}
return fail("删除失败");
}
}

View File

@@ -0,0 +1,81 @@
package com.gxwebsoft.shop.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.fasterxml.jackson.annotation.JsonFormat;
/**
* 仓库
*
* @author 科技小王子
* @since 2026-01-30 17:46:47
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Schema(name = "ShopWarehouse对象", description = "仓库")
public class ShopWarehouse implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "自增ID")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@Schema(description = "仓库名称")
private String name;
@Schema(description = "唯一标识")
private String code;
@Schema(description = "类型 中心仓,区域仓,门店仓")
private String type;
@Schema(description = "仓库地址")
private String address;
@Schema(description = "真实姓名")
private String realName;
@Schema(description = "联系电话")
private String phone;
@Schema(description = "所在省份")
private String province;
@Schema(description = "所在城市")
private String city;
@Schema(description = "所在辖区")
private String region;
@Schema(description = "经纬度")
private String lngAndLat;
@Schema(description = "用户ID")
private Integer userId;
@Schema(description = "备注")
private String comments;
@Schema(description = "排序号")
private Integer sortNumber;
@Schema(description = "是否删除")
private Integer isDelete;
@Schema(description = "租户id")
private Integer tenantId;
@Schema(description = "创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
@Schema(description = "修改时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,37 @@
package com.gxwebsoft.shop.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxwebsoft.shop.entity.ShopWarehouse;
import com.gxwebsoft.shop.param.ShopWarehouseParam;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 仓库Mapper
*
* @author 科技小王子
* @since 2026-01-30 17:46:47
*/
public interface ShopWarehouseMapper extends BaseMapper<ShopWarehouse> {
/**
* 分页查询
*
* @param page 分页对象
* @param param 查询参数
* @return List<ShopWarehouse>
*/
List<ShopWarehouse> selectPageRel(@Param("page") IPage<ShopWarehouse> page,
@Param("param") ShopWarehouseParam param);
/**
* 查询全部
*
* @param param 查询参数
* @return List<User>
*/
List<ShopWarehouse> selectListRel(@Param("param") ShopWarehouseParam param);
}

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gxwebsoft.shop.mapper.ShopWarehouseMapper">
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
FROM shop_warehouse a
<where>
<if test="param.id != null">
AND a.id = #{param.id}
</if>
<if test="param.name != null">
AND a.name LIKE CONCAT('%', #{param.name}, '%')
</if>
<if test="param.code != null">
AND a.code LIKE CONCAT('%', #{param.code}, '%')
</if>
<if test="param.type != null">
AND a.type LIKE CONCAT('%', #{param.type}, '%')
</if>
<if test="param.address != null">
AND a.address LIKE CONCAT('%', #{param.address}, '%')
</if>
<if test="param.realName != null">
AND a.real_name LIKE CONCAT('%', #{param.realName}, '%')
</if>
<if test="param.phone != null">
AND a.phone LIKE CONCAT('%', #{param.phone}, '%')
</if>
<if test="param.province != null">
AND a.province LIKE CONCAT('%', #{param.province}, '%')
</if>
<if test="param.city != null">
AND a.city LIKE CONCAT('%', #{param.city}, '%')
</if>
<if test="param.region != null">
AND a.region LIKE CONCAT('%', #{param.region}, '%')
</if>
<if test="param.lngAndLat != null">
AND a.lng_and_lat LIKE CONCAT('%', #{param.lngAndLat}, '%')
</if>
<if test="param.userId != null">
AND a.user_id = #{param.userId}
</if>
<if test="param.comments != null">
AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
</if>
<if test="param.sortNumber != null">
AND a.sort_number = #{param.sortNumber}
</if>
<if test="param.isDelete != null">
AND a.is_delete = #{param.isDelete}
</if>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.keywords != null">
AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
)
</if>
</where>
</sql>
<!-- 分页查询 -->
<select id="selectPageRel" resultType="com.gxwebsoft.shop.entity.ShopWarehouse">
<include refid="selectSql"></include>
</select>
<!-- 查询全部 -->
<select id="selectListRel" resultType="com.gxwebsoft.shop.entity.ShopWarehouse">
<include refid="selectSql"></include>
</select>
</mapper>

View File

@@ -0,0 +1,77 @@
package com.gxwebsoft.shop.param;
import java.math.BigDecimal;
import com.gxwebsoft.common.core.annotation.QueryField;
import com.gxwebsoft.common.core.annotation.QueryType;
import com.gxwebsoft.common.core.web.BaseParam;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 仓库查询参数
*
* @author 科技小王子
* @since 2026-01-30 17:46:47
*/
@Data
@EqualsAndHashCode(callSuper = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(name = "ShopWarehouseParam对象", description = "仓库查询参数")
public class ShopWarehouseParam extends BaseParam {
private static final long serialVersionUID = 1L;
@Schema(description = "自增ID")
@QueryField(type = QueryType.EQ)
private Integer id;
@Schema(description = "仓库名称")
private String name;
@Schema(description = "唯一标识")
private String code;
@Schema(description = "类型 中心仓,区域仓,门店仓")
private String type;
@Schema(description = "仓库地址")
private String address;
@Schema(description = "真实姓名")
private String realName;
@Schema(description = "联系电话")
private String phone;
@Schema(description = "所在省份")
@QueryField(type = QueryType.EQ)
private String province;
@Schema(description = "所在城市")
@QueryField(type = QueryType.EQ)
private String city;
@Schema(description = "所在辖区")
@QueryField(type = QueryType.EQ)
private String region;
@Schema(description = "经纬度")
private String lngAndLat;
@Schema(description = "用户ID")
@QueryField(type = QueryType.EQ)
private Integer userId;
@Schema(description = "备注")
private String comments;
@Schema(description = "排序号")
@QueryField(type = QueryType.EQ)
private Integer sortNumber;
@Schema(description = "是否删除")
@QueryField(type = QueryType.EQ)
private Integer isDelete;
}

View File

@@ -0,0 +1,42 @@
package com.gxwebsoft.shop.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.shop.entity.ShopWarehouse;
import com.gxwebsoft.shop.param.ShopWarehouseParam;
import java.util.List;
/**
* 仓库Service
*
* @author 科技小王子
* @since 2026-01-30 17:46:48
*/
public interface ShopWarehouseService extends IService<ShopWarehouse> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<ShopWarehouse>
*/
PageResult<ShopWarehouse> pageRel(ShopWarehouseParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<ShopWarehouse>
*/
List<ShopWarehouse> listRel(ShopWarehouseParam param);
/**
* 根据id查询
*
* @param id 自增ID
* @return ShopWarehouse
*/
ShopWarehouse getByIdRel(Integer id);
}

View File

@@ -0,0 +1,47 @@
package com.gxwebsoft.shop.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopWarehouseMapper;
import com.gxwebsoft.shop.service.ShopWarehouseService;
import com.gxwebsoft.shop.entity.ShopWarehouse;
import com.gxwebsoft.shop.param.ShopWarehouseParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 仓库Service实现
*
* @author 科技小王子
* @since 2026-01-30 17:46:48
*/
@Service
public class ShopWarehouseServiceImpl extends ServiceImpl<ShopWarehouseMapper, ShopWarehouse> implements ShopWarehouseService {
@Override
public PageResult<ShopWarehouse> pageRel(ShopWarehouseParam param) {
PageParam<ShopWarehouse, ShopWarehouseParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, create_time desc");
List<ShopWarehouse> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<ShopWarehouse> listRel(ShopWarehouseParam param) {
List<ShopWarehouse> list = baseMapper.selectListRel(param);
// 排序
PageParam<ShopWarehouse, ShopWarehouseParam> page = new PageParam<>();
page.setDefaultOrder("sort_number asc, create_time desc");
return page.sortRecords(list);
}
@Override
public ShopWarehouse getByIdRel(Integer id) {
ShopWarehouseParam param = new ShopWarehouseParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}