|
|
@@ -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);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|