|
@@ -0,0 +1,185 @@
|
|
|
|
|
+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.StoreProductBar;
|
|
|
|
|
+import shop.alien.store.service.StoreProductBarService;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 酒吧商品表 Controller
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author system
|
|
|
|
|
+ * @since 2025-01-XX
|
|
|
|
|
+ */
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Api(tags = {"酒吧商品管理"})
|
|
|
|
|
+@CrossOrigin
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/store/product/bar")
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+public class StoreProductBarController {
|
|
|
|
|
+
|
|
|
|
|
+ private final StoreProductBarService storeProductBarService;
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("新增酒吧商品")
|
|
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
|
|
+ @PostMapping
|
|
|
|
|
+ public R<String> saveBar(@RequestBody StoreProductBar bar) {
|
|
|
|
|
+ log.info("StoreProductBarController.saveBar?bar={}", bar);
|
|
|
|
|
+ // 参数校验
|
|
|
|
|
+ if (bar.getName() == null || bar.getName().trim().isEmpty()) {
|
|
|
|
|
+ return R.fail("名称不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (bar.getPrice() == null) {
|
|
|
|
|
+ return R.fail("价格不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (bar.getCostPrice() == null) {
|
|
|
|
|
+ return R.fail("成本价不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (bar.getCategory() == null || bar.getCategory().trim().isEmpty()) {
|
|
|
|
|
+ return R.fail("品类不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ R<StoreProductBar> result = storeProductBarService.addStoreProductBar(bar);
|
|
|
|
|
+ if (result.getCode() == 200) {
|
|
|
|
|
+ return R.success("新增成功");
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.fail(result.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("修改酒吧商品")
|
|
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
|
|
+ @PutMapping
|
|
|
|
|
+ public R<String> updateBar(@RequestBody StoreProductBar bar) {
|
|
|
|
|
+ log.info("StoreProductBarController.updateBar?bar={}", bar);
|
|
|
|
|
+ if (bar.getId() == null) {
|
|
|
|
|
+ return R.fail("ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ R<StoreProductBar> result = storeProductBarService.editStoreProductBar(bar);
|
|
|
|
|
+ if (result.getCode() == 200) {
|
|
|
|
|
+ return R.success("修改成功");
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.fail(result.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("删除酒吧商品")
|
|
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
|
+ @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", paramType = "path", required = true)
|
|
|
|
|
+ })
|
|
|
|
|
+ @DeleteMapping("/{id}")
|
|
|
|
|
+ public R<String> deleteBar(@PathVariable("id") Long id) {
|
|
|
|
|
+ log.info("StoreProductBarController.deleteBar?id={}", id);
|
|
|
|
|
+ R<Boolean> result = storeProductBarService.deleteStoreProductBar(id);
|
|
|
|
|
+ if (result.getCode() == 200) {
|
|
|
|
|
+ return R.success("删除成功");
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.fail(result.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("根据ID查询酒吧商品详情")
|
|
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
|
+ @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", paramType = "path", required = true)
|
|
|
|
|
+ })
|
|
|
|
|
+ @GetMapping("/{id}")
|
|
|
|
|
+ public R<StoreProductBar> getById(@PathVariable("id") Long id) {
|
|
|
|
|
+ log.info("StoreProductBarController.getById?id={}", id);
|
|
|
|
|
+ R<StoreProductBar> result = storeProductBarService.getStoreProductBarById(id);
|
|
|
|
|
+ if (result.getCode() == 200 && result.getData() != null) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.fail("未找到该酒吧商品信息");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("分页查询酒吧商品列表")
|
|
|
|
|
+ @ApiOperationSupport(order = 5)
|
|
|
|
|
+ @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 = "status", value = "状态(0:禁用,1:启用)", dataType = "Integer", paramType = "query"),
|
|
|
|
|
+ @ApiImplicitParam(name = "extId", value = "商品表主键", dataType = "Long", paramType = "query")
|
|
|
|
|
+ })
|
|
|
|
|
+ @GetMapping("/page")
|
|
|
|
|
+ public R<IPage<StoreProductBar>> getPage(
|
|
|
|
|
+ @RequestParam(defaultValue = "1") int pageNum,
|
|
|
|
|
+ @RequestParam(defaultValue = "10") int pageSize,
|
|
|
|
|
+ @RequestParam(required = false) String name,
|
|
|
|
|
+ @RequestParam(required = false) String category,
|
|
|
|
|
+ @RequestParam(required = false) Integer status,
|
|
|
|
|
+ @RequestParam(required = false) Long extId) {
|
|
|
|
|
+ log.info("StoreProductBarController.getPage?pageNum={}, pageSize={}, name={}, category={}, status={}, extId={}",
|
|
|
|
|
+ pageNum, pageSize, name, category, status, extId);
|
|
|
|
|
+ IPage<StoreProductBar> page = storeProductBarService.getPage(pageNum, pageSize, name, category, status, extId);
|
|
|
|
|
+ return R.data(page);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("批量删除酒吧商品")
|
|
|
|
|
+ @ApiOperationSupport(order = 6)
|
|
|
|
|
+ @PostMapping("/batchDelete")
|
|
|
|
|
+ public R<String> deleteBatch(@RequestBody List<Long> ids) {
|
|
|
|
|
+ log.info("StoreProductBarController.deleteBatch?ids={}", ids);
|
|
|
|
|
+ if (ids == null || ids.isEmpty()) {
|
|
|
|
|
+ return R.fail("ID列表不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ boolean result = storeProductBarService.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("StoreProductBarController.updateStatus?id={}, status={}", id, status);
|
|
|
|
|
+ if (status == null || (status != 0 && status != 1)) {
|
|
|
|
|
+ return R.fail("状态值无效,只能为0或1");
|
|
|
|
|
+ }
|
|
|
|
|
+ boolean result = storeProductBarService.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<StoreProductBar>> getListByExtId(@RequestParam("extId") Long extId) {
|
|
|
|
|
+ log.info("StoreProductBarController.getListByExtId?extId={}", extId);
|
|
|
|
|
+ List<StoreProductBar> list = storeProductBarService.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<StoreProductBar>> getListByCategory(@RequestParam("category") String category) {
|
|
|
|
|
+ log.info("StoreProductBarController.getListByCategory?category={}", category);
|
|
|
|
|
+ List<StoreProductBar> list = storeProductBarService.getListByCategory(category);
|
|
|
|
|
+ return R.data(list);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|