ソースを参照

创建store_product_delicacies 美食商品表

ldz 11 時間 前
コミット
b39ee00c67

+ 91 - 0
alien-entity/src/main/java/shop/alien/entity/store/StoreProductDelicacies.java

@@ -0,0 +1,91 @@
+package shop.alien.entity.store;
+
+import com.baomidou.mybatisplus.annotation.*;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 美食商品表
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Data
+@JsonInclude
+@TableName("store_product_delicacies")
+@ApiModel(value = "StoreProductDelicacies对象", description = "美食商品表")
+public class StoreProductDelicacies implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "主键")
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    @ApiModelProperty(value = "商品表主键")
+    @TableField("ext_id")
+    private Long extId;
+
+    @ApiModelProperty(value = "名称")
+    @TableField("name")
+    private String name;
+
+    @ApiModelProperty(value = "价格(¥)")
+    @TableField("price")
+    private BigDecimal price;
+
+    @ApiModelProperty(value = "成本价(¥)")
+    @TableField("cost_price")
+    private BigDecimal costPrice;
+
+    @ApiModelProperty(value = "单位,如份/瓶/杯")
+    @TableField("unit")
+    private String unit;
+
+    @ApiModelProperty(value = "数量")
+    @TableField("quantity")
+    private Integer quantity;
+
+    @ApiModelProperty(value = "类别")
+    @TableField("category")
+    private String category;
+
+    @ApiModelProperty(value = "菜品分组")
+    @TableField("ext_group")
+    private String extGroup;
+
+    @ApiModelProperty(value = "状态:0禁用,1启用")
+    @TableField("status")
+    private Integer status;
+
+    @ApiModelProperty(value = "删除标记, 0:未删除, 1:已删除")
+    @TableField("delete_flag")
+    @TableLogic
+    private Integer deleteFlag;
+
+    @ApiModelProperty(value = "创建人")
+    @TableField("created_user_id")
+    private Long createdUserId;
+
+    @ApiModelProperty(value = "更新人")
+    @TableField("updated_user_id")
+    private Long updatedUserId;
+
+    @ApiModelProperty(value = "创建时间")
+    @TableField(value = "created_time", fill = FieldFill.INSERT)
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date createdTime;
+
+    @ApiModelProperty(value = "更新时间")
+    @TableField(value = "updated_time", fill = FieldFill.INSERT_UPDATE)
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date updatedTime;
+}
+

+ 17 - 0
alien-entity/src/main/java/shop/alien/mapper/StoreProductDelicaciesMapper.java

@@ -0,0 +1,17 @@
+package shop.alien.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import shop.alien.entity.store.StoreProductDelicacies;
+
+/**
+ * 美食商品表 Mapper 接口
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Mapper
+public interface StoreProductDelicaciesMapper extends BaseMapper<StoreProductDelicacies> {
+
+}
+

+ 204 - 0
alien-store/src/main/java/shop/alien/store/controller/StoreProductDelicaciesController.java

@@ -0,0 +1,204 @@
+package shop.alien.store.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import io.swagger.annotations.*;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+import shop.alien.entity.result.R;
+import shop.alien.entity.store.StoreProductDelicacies;
+import shop.alien.store.service.StoreProductDelicaciesService;
+
+import java.util.List;
+
+/**
+ * 美食商品表 Controller
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Slf4j
+@Api(tags = {"美食商品管理"})
+@ApiSort(1)
+@CrossOrigin
+@RestController
+@RequestMapping("/store/product/delicacies")
+@RequiredArgsConstructor
+public class StoreProductDelicaciesController {
+
+    private final StoreProductDelicaciesService storeProductDelicaciesService;
+
+    @ApiOperation("分页查询美食商品列表")
+    @ApiOperationSupport(order = 1)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "int", paramType = "query", required = true),
+            @ApiImplicitParam(name = "pageSize", value = "页容", dataType = "int", paramType = "query", required = true),
+            @ApiImplicitParam(name = "name", value = "名称(模糊查询)", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "category", value = "类别", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "extGroup", value = "菜品分组", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "status", value = "状态(0:禁用,1:启用)", dataType = "Integer", paramType = "query"),
+            @ApiImplicitParam(name = "extId", value = "商品表主键", dataType = "Long", paramType = "query")
+    })
+    @GetMapping("/page")
+    public R<IPage<StoreProductDelicacies>> getPage(
+            @RequestParam(defaultValue = "1") int pageNum,
+            @RequestParam(defaultValue = "10") int pageSize,
+            @RequestParam(required = false) String name,
+            @RequestParam(required = false) String category,
+            @RequestParam(required = false) String extGroup,
+            @RequestParam(required = false) Integer status,
+            @RequestParam(required = false) Long extId) {
+        log.info("StoreProductDelicaciesController.getPage?pageNum={}, pageSize={}, name={}, category={}, extGroup={}, status={}, extId={}",
+                pageNum, pageSize, name, category, extGroup, status, extId);
+        IPage<StoreProductDelicacies> page = storeProductDelicaciesService.getPage(pageNum, pageSize, name, category, extGroup, status, extId);
+        return R.data(page);
+    }
+
+    @ApiOperation("根据ID查询美食商品详情")
+    @ApiOperationSupport(order = 2)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", paramType = "path", required = true)
+    })
+    @GetMapping("/{id}")
+    public R<StoreProductDelicacies> getById(@PathVariable("id") Long id) {
+        log.info("StoreProductDelicaciesController.getById?id={}", id);
+        StoreProductDelicacies delicacies = storeProductDelicaciesService.getById(id);
+        if (delicacies == null) {
+            return R.fail("未找到该美食商品信息");
+        }
+        return R.data(delicacies);
+    }
+
+    @ApiOperation("新增美食商品")
+    @ApiOperationSupport(order = 3)
+    @PostMapping
+    public R<String> saveDelicacies(@RequestBody StoreProductDelicacies delicacies) {
+        log.info("StoreProductDelicaciesController.saveDelicacies?delicacies={}", delicacies);
+        // 参数校验
+        if (delicacies.getName() == null || delicacies.getName().trim().isEmpty()) {
+            return R.fail("名称不能为空");
+        }
+        if (delicacies.getPrice() == null) {
+            return R.fail("价格不能为空");
+        }
+        if (delicacies.getCostPrice() == null) {
+            return R.fail("成本价不能为空");
+        }
+        if (delicacies.getCategory() == null || delicacies.getCategory().trim().isEmpty()) {
+            return R.fail("类别不能为空");
+        }
+        if (delicacies.getExtGroup() == null || delicacies.getExtGroup().trim().isEmpty()) {
+            return R.fail("菜品分组不能为空");
+        }
+
+        boolean result = storeProductDelicaciesService.saveDelicacies(delicacies);
+        if (result) {
+            return R.success("新增成功");
+        }
+        return R.fail("新增失败");
+    }
+
+    @ApiOperation("修改美食商品")
+    @ApiOperationSupport(order = 4)
+    @PutMapping
+    public R<String> updateDelicacies(@RequestBody StoreProductDelicacies delicacies) {
+        log.info("StoreProductDelicaciesController.updateDelicacies?delicacies={}", delicacies);
+        if (delicacies.getId() == null) {
+            return R.fail("ID不能为空");
+        }
+
+        boolean result = storeProductDelicaciesService.updateDelicacies(delicacies);
+        if (result) {
+            return R.success("修改成功");
+        }
+        return R.fail("修改失败");
+    }
+
+    @ApiOperation("删除美食商品")
+    @ApiOperationSupport(order = 5)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", paramType = "path", required = true)
+    })
+    @DeleteMapping("/{id}")
+    public R<String> deleteDelicacies(@PathVariable("id") Long id) {
+        log.info("StoreProductDelicaciesController.deleteDelicacies?id={}", id);
+        boolean result = storeProductDelicaciesService.deleteDelicacies(id);
+        if (result) {
+            return R.success("删除成功");
+        }
+        return R.fail("删除失败");
+    }
+
+    @ApiOperation("批量删除美食商品")
+    @ApiOperationSupport(order = 6)
+    @PostMapping("/batchDelete")
+    public R<String> deleteBatch(@RequestBody List<Long> ids) {
+        log.info("StoreProductDelicaciesController.deleteBatch?ids={}", ids);
+        if (ids == null || ids.isEmpty()) {
+            return R.fail("ID列表不能为空");
+        }
+        boolean result = storeProductDelicaciesService.deleteBatch(ids);
+        if (result) {
+            return R.success("批量删除成功");
+        }
+        return R.fail("批量删除失败");
+    }
+
+    @ApiOperation("更新美食商品状态")
+    @ApiOperationSupport(order = 7)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", paramType = "path", required = true),
+            @ApiImplicitParam(name = "status", value = "状态(0:禁用,1:启用)", dataType = "Integer", paramType = "query", required = true)
+    })
+    @PutMapping("/{id}/status")
+    public R<String> updateStatus(
+            @PathVariable("id") Long id,
+            @RequestParam("status") Integer status) {
+        log.info("StoreProductDelicaciesController.updateStatus?id={}, status={}", id, status);
+        if (status == null || (status != 0 && status != 1)) {
+            return R.fail("状态值无效,只能为0或1");
+        }
+        boolean result = storeProductDelicaciesService.updateStatus(id, status);
+        if (result) {
+            return R.success("状态更新成功");
+        }
+        return R.fail("状态更新失败");
+    }
+
+    @ApiOperation("根据商品表主键查询美食商品列表")
+    @ApiOperationSupport(order = 8)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "extId", value = "商品表主键", dataType = "Long", paramType = "query", required = true)
+    })
+    @GetMapping("/listByExtId")
+    public R<List<StoreProductDelicacies>> getListByExtId(@RequestParam("extId") Long extId) {
+        log.info("StoreProductDelicaciesController.getListByExtId?extId={}", extId);
+        List<StoreProductDelicacies> list = storeProductDelicaciesService.getListByExtId(extId);
+        return R.data(list);
+    }
+
+    @ApiOperation("根据类别查询美食商品列表")
+    @ApiOperationSupport(order = 9)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "category", value = "类别", dataType = "String", paramType = "query", required = true)
+    })
+    @GetMapping("/listByCategory")
+    public R<List<StoreProductDelicacies>> getListByCategory(@RequestParam("category") String category) {
+        log.info("StoreProductDelicaciesController.getListByCategory?category={}", category);
+        List<StoreProductDelicacies> list = storeProductDelicaciesService.getListByCategory(category);
+        return R.data(list);
+    }
+
+    @ApiOperation("根据菜品分组查询美食商品列表")
+    @ApiOperationSupport(order = 10)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "extGroup", value = "菜品分组", dataType = "String", paramType = "query", required = true)
+    })
+    @GetMapping("/listByExtGroup")
+    public R<List<StoreProductDelicacies>> getListByExtGroup(@RequestParam("extGroup") String extGroup) {
+        log.info("StoreProductDelicaciesController.getListByExtGroup?extGroup={}", extGroup);
+        List<StoreProductDelicacies> list = storeProductDelicaciesService.getListByExtGroup(extGroup);
+        return R.data(list);
+    }
+}
+

+ 103 - 0
alien-store/src/main/java/shop/alien/store/service/StoreProductDelicaciesService.java

@@ -0,0 +1,103 @@
+package shop.alien.store.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import shop.alien.entity.store.StoreProductDelicacies;
+
+import java.util.List;
+
+/**
+ * 美食商品表 服务类
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+public interface StoreProductDelicaciesService {
+
+    /**
+     * 分页查询美食商品列表
+     *
+     * @param pageNum  页码
+     * @param pageSize 页容
+     * @param name     名称(模糊查询)
+     * @param category 类别
+     * @param extGroup 菜品分组
+     * @param status   状态(0:禁用,1:启用)
+     * @param extId    商品表主键
+     * @return IPage<StoreProductDelicacies>
+     */
+    IPage<StoreProductDelicacies> getPage(int pageNum, int pageSize, String name, String category, String extGroup, Integer status, Long extId);
+
+    /**
+     * 根据ID查询美食商品详情
+     *
+     * @param id 主键ID
+     * @return StoreProductDelicacies
+     */
+    StoreProductDelicacies getById(Long id);
+
+    /**
+     * 新增美食商品
+     *
+     * @param delicacies 美食商品信息
+     * @return boolean
+     */
+    boolean saveDelicacies(StoreProductDelicacies delicacies);
+
+    /**
+     * 修改美食商品
+     *
+     * @param delicacies 美食商品信息
+     * @return boolean
+     */
+    boolean updateDelicacies(StoreProductDelicacies delicacies);
+
+    /**
+     * 删除美食商品(逻辑删除)
+     *
+     * @param id 主键ID
+     * @return boolean
+     */
+    boolean deleteDelicacies(Long id);
+
+    /**
+     * 批量删除美食商品(逻辑删除)
+     *
+     * @param ids 主键ID列表
+     * @return boolean
+     */
+    boolean deleteBatch(List<Long> ids);
+
+    /**
+     * 更新美食商品状态
+     *
+     * @param id     主键ID
+     * @param status 状态(0:禁用,1:启用)
+     * @return boolean
+     */
+    boolean updateStatus(Long id, Integer status);
+
+    /**
+     * 根据商品表主键查询美食商品列表
+     *
+     * @param extId 商品表主键
+     * @return List<StoreProductDelicacies>
+     */
+    List<StoreProductDelicacies> getListByExtId(Long extId);
+
+    /**
+     * 根据类别查询美食商品列表
+     *
+     * @param category 类别
+     * @return List<StoreProductDelicacies>
+     */
+    List<StoreProductDelicacies> getListByCategory(String category);
+
+    /**
+     * 根据菜品分组查询美食商品列表
+     *
+     * @param extGroup 菜品分组
+     * @return List<StoreProductDelicacies>
+     */
+    List<StoreProductDelicacies> getListByExtGroup(String extGroup);
+}
+

+ 176 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StoreProductDelicaciesServiceImpl.java

@@ -0,0 +1,176 @@
+package shop.alien.store.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
+import shop.alien.entity.store.StoreProductDelicacies;
+import shop.alien.mapper.StoreProductDelicaciesMapper;
+import shop.alien.store.service.StoreProductDelicaciesService;
+
+import java.util.List;
+
+/**
+ * 美食商品表 服务实现类
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Slf4j
+@Service
+@RequiredArgsConstructor
+@Transactional
+public class StoreProductDelicaciesServiceImpl implements StoreProductDelicaciesService {
+
+    private final StoreProductDelicaciesMapper storeProductDelicaciesMapper;
+
+    @Override
+    public IPage<StoreProductDelicacies> getPage(int pageNum, int pageSize, String name, String category, String extGroup, Integer status, Long extId) {
+        LambdaQueryWrapper<StoreProductDelicacies> queryWrapper = new LambdaQueryWrapper<>();
+
+        // 名称模糊查询
+        if (StringUtils.hasText(name)) {
+            queryWrapper.like(StoreProductDelicacies::getName, name);
+        }
+
+        // 类别查询
+        if (StringUtils.hasText(category)) {
+            queryWrapper.eq(StoreProductDelicacies::getCategory, category);
+        }
+
+        // 菜品分组查询
+        if (StringUtils.hasText(extGroup)) {
+            queryWrapper.eq(StoreProductDelicacies::getExtGroup, extGroup);
+        }
+
+        // 状态查询
+        if (status != null) {
+            queryWrapper.eq(StoreProductDelicacies::getStatus, status);
+        }
+
+        // 商品表主键查询
+        if (extId != null) {
+            queryWrapper.eq(StoreProductDelicacies::getExtId, extId);
+        }
+
+        // 按创建时间倒序
+        queryWrapper.orderByDesc(StoreProductDelicacies::getCreatedTime);
+
+        return storeProductDelicaciesMapper.selectPage(new Page<>(pageNum, pageSize), queryWrapper);
+    }
+
+    @Override
+    public StoreProductDelicacies getById(Long id) {
+        return storeProductDelicaciesMapper.selectById(id);
+    }
+
+    @Override
+    public boolean saveDelicacies(StoreProductDelicacies delicacies) {
+        // 设置默认值
+        if (delicacies.getUnit() == null || delicacies.getUnit().isEmpty()) {
+            delicacies.setUnit("份");
+        }
+        if (delicacies.getQuantity() == null) {
+            delicacies.setQuantity(0);
+        }
+        if (delicacies.getStatus() == null) {
+            delicacies.setStatus(1);
+        }
+        if (delicacies.getCreatedUserId() == null) {
+            delicacies.setCreatedUserId(0L);
+        }
+        if (delicacies.getUpdatedUserId() == null) {
+            delicacies.setUpdatedUserId(0L);
+        }
+
+        return storeProductDelicaciesMapper.insert(delicacies) > 0;
+    }
+
+    @Override
+    public boolean updateDelicacies(StoreProductDelicacies delicacies) {
+        if (delicacies.getId() == null) {
+            log.error("更新美食商品失败:ID不能为空");
+            return false;
+        }
+
+        // 设置更新人
+        if (delicacies.getUpdatedUserId() == null) {
+            delicacies.setUpdatedUserId(0L);
+        }
+
+        return storeProductDelicaciesMapper.updateById(delicacies) > 0;
+    }
+
+    @Override
+    public boolean deleteDelicacies(Long id) {
+        // 逻辑删除,MyBatis-Plus会自动处理
+        return storeProductDelicaciesMapper.deleteById(id) > 0;
+    }
+
+    @Override
+    public boolean deleteBatch(List<Long> ids) {
+        if (ids == null || ids.isEmpty()) {
+            log.error("批量删除美食商品失败:ID列表不能为空");
+            return false;
+        }
+        // 逻辑删除,MyBatis-Plus会自动处理
+        return storeProductDelicaciesMapper.deleteBatchIds(ids) > 0;
+    }
+
+    @Override
+    public boolean updateStatus(Long id, Integer status) {
+        if (id == null) {
+            log.error("更新美食商品状态失败:ID不能为空");
+            return false;
+        }
+        if (status == null || (status != 0 && status != 1)) {
+            log.error("更新美食商品状态失败:状态值无效,只能为0或1");
+            return false;
+        }
+
+        LambdaUpdateWrapper<StoreProductDelicacies> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.eq(StoreProductDelicacies::getId, id)
+                .set(StoreProductDelicacies::getStatus, status);
+
+        return storeProductDelicaciesMapper.update(null, updateWrapper) > 0;
+    }
+
+    @Override
+    public List<StoreProductDelicacies> getListByExtId(Long extId) {
+        if (extId == null) {
+            return null;
+        }
+        LambdaQueryWrapper<StoreProductDelicacies> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(StoreProductDelicacies::getExtId, extId)
+                .orderByDesc(StoreProductDelicacies::getCreatedTime);
+        return storeProductDelicaciesMapper.selectList(queryWrapper);
+    }
+
+    @Override
+    public List<StoreProductDelicacies> getListByCategory(String category) {
+        if (!StringUtils.hasText(category)) {
+            return null;
+        }
+        LambdaQueryWrapper<StoreProductDelicacies> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(StoreProductDelicacies::getCategory, category)
+                .orderByDesc(StoreProductDelicacies::getCreatedTime);
+        return storeProductDelicaciesMapper.selectList(queryWrapper);
+    }
+
+    @Override
+    public List<StoreProductDelicacies> getListByExtGroup(String extGroup) {
+        if (!StringUtils.hasText(extGroup)) {
+            return null;
+        }
+        LambdaQueryWrapper<StoreProductDelicacies> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(StoreProductDelicacies::getExtGroup, extGroup)
+                .orderByDesc(StoreProductDelicacies::getCreatedTime);
+        return storeProductDelicaciesMapper.selectList(queryWrapper);
+    }
+}
+