|
@@ -3,6 +3,7 @@ package shop.alien.store.controller;
|
|
|
import io.swagger.annotations.*;
|
|
import io.swagger.annotations.*;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import shop.alien.entity.result.R;
|
|
import shop.alien.entity.result.R;
|
|
@@ -53,49 +54,48 @@ public class StoreBookingCategoryController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@ApiOperationSupport(order = 2)
|
|
@ApiOperationSupport(order = 2)
|
|
|
|
|
+ @ApiOperation("查询预订服务分类详情")
|
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
|
+ @ApiImplicitParam(name = "id", value = "分类ID", dataType = "Integer", paramType = "query", required = true)
|
|
|
|
|
+ })
|
|
|
|
|
+ @GetMapping("/detail")
|
|
|
|
|
+ public R<StoreBookingCategory> getCategoryDetail(@RequestParam Integer id) {
|
|
|
|
|
+ log.info("StoreBookingCategoryController.getCategoryDetail?id={}", id);
|
|
|
|
|
+
|
|
|
|
|
+ if (id == null) {
|
|
|
|
|
+ return R.fail("分类ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ StoreBookingCategory category = storeBookingCategoryService.getById(id);
|
|
|
|
|
+ if (category == null) {
|
|
|
|
|
+ return R.fail("分类不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.data(category);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("查询预订服务分类详情失败", e);
|
|
|
|
|
+ return R.fail("查询失败:" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
@ApiOperation("新增预订服务分类")
|
|
@ApiOperation("新增预订服务分类")
|
|
|
@PostMapping("/add")
|
|
@PostMapping("/add")
|
|
|
public R<StoreBookingCategory> addCategory(@RequestBody StoreBookingCategoryDTO dto) {
|
|
public R<StoreBookingCategory> addCategory(@RequestBody StoreBookingCategoryDTO dto) {
|
|
|
log.info("StoreBookingCategoryController.addCategory?dto={}", dto);
|
|
log.info("StoreBookingCategoryController.addCategory?dto={}", dto);
|
|
|
-
|
|
|
|
|
- // 参数验证
|
|
|
|
|
- if (dto.getStoreId() == null) {
|
|
|
|
|
- return R.fail("门店ID不能为空");
|
|
|
|
|
- }
|
|
|
|
|
- if (!StringUtils.hasText(dto.getCategoryName())) {
|
|
|
|
|
- return R.fail("分类名称不能为空");
|
|
|
|
|
- }
|
|
|
|
|
- if (!StringUtils.hasText(dto.getFloorPlanImages())) {
|
|
|
|
|
- return R.fail("平面图不能为空");
|
|
|
|
|
- }
|
|
|
|
|
- if (dto.getMaxBookingTime() == null || dto.getMaxBookingTime() <= 0) {
|
|
|
|
|
- return R.fail("最长预订时间必须大于0");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
try {
|
|
try {
|
|
|
StoreBookingCategory category = new StoreBookingCategory();
|
|
StoreBookingCategory category = new StoreBookingCategory();
|
|
|
- category.setStoreId(dto.getStoreId());
|
|
|
|
|
- category.setCategoryName(dto.getCategoryName());
|
|
|
|
|
- category.setFloorPlanImages(dto.getFloorPlanImages());
|
|
|
|
|
- category.setIsDisplay(dto.getIsDisplay() != null ? dto.getIsDisplay() : 1); // 默认显示
|
|
|
|
|
- category.setMaxBookingTime(dto.getMaxBookingTime());
|
|
|
|
|
- category.setSort(dto.getSort());
|
|
|
|
|
-
|
|
|
|
|
- boolean result = storeBookingCategoryService.addCategory(category);
|
|
|
|
|
- if (result) {
|
|
|
|
|
- // 返回保存后的完整对象
|
|
|
|
|
- StoreBookingCategory savedCategory = storeBookingCategoryService.getById(category.getId());
|
|
|
|
|
- return R.data(savedCategory, "新增成功");
|
|
|
|
|
- } else {
|
|
|
|
|
- return R.fail("新增失败");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ BeanUtils.copyProperties(dto, category);
|
|
|
|
|
+ storeBookingCategoryService.addCategory(category);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("新增预订服务分类失败", e);
|
|
log.error("新增预订服务分类失败", e);
|
|
|
|
|
+ // 如果是名称已存在的错误,直接返回友好提示
|
|
|
return R.fail("新增失败:" + e.getMessage());
|
|
return R.fail("新增失败:" + e.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
+ return R.success("新增成功");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperationSupport(order = 3)
|
|
|
|
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
@ApiOperation("编辑预订服务分类")
|
|
@ApiOperation("编辑预订服务分类")
|
|
|
@PostMapping("/update")
|
|
@PostMapping("/update")
|
|
|
public R<String> updateCategory(@RequestBody StoreBookingCategoryDTO dto) {
|
|
public R<String> updateCategory(@RequestBody StoreBookingCategoryDTO dto) {
|
|
@@ -132,11 +132,15 @@ public class StoreBookingCategoryController {
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("更新预订服务分类失败", e);
|
|
log.error("更新预订服务分类失败", e);
|
|
|
|
|
+ // 如果是名称已存在的错误,直接返回友好提示
|
|
|
|
|
+ if (e.getMessage() != null && e.getMessage().contains("此名称已存在")) {
|
|
|
|
|
+ return R.fail("此名称已存在");
|
|
|
|
|
+ }
|
|
|
return R.fail("更新失败:" + e.getMessage());
|
|
return R.fail("更新失败:" + e.getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperationSupport(order = 4)
|
|
|
|
|
|
|
+ @ApiOperationSupport(order = 5)
|
|
|
@ApiOperation("删除预订服务分类")
|
|
@ApiOperation("删除预订服务分类")
|
|
|
@ApiImplicitParams({
|
|
@ApiImplicitParams({
|
|
|
@ApiImplicitParam(name = "id", value = "分类ID", dataType = "Integer", paramType = "query", required = true)
|
|
@ApiImplicitParam(name = "id", value = "分类ID", dataType = "Integer", paramType = "query", required = true)
|
|
@@ -162,7 +166,7 @@ public class StoreBookingCategoryController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperationSupport(order = 5)
|
|
|
|
|
|
|
+ @ApiOperationSupport(order = 6)
|
|
|
@ApiOperation("更新预订服务分类排序")
|
|
@ApiOperation("更新预订服务分类排序")
|
|
|
@PostMapping("/updateSort")
|
|
@PostMapping("/updateSort")
|
|
|
public R<String> updateCategorySort(@RequestBody StoreBookingCategorySortDTO dto) {
|
|
public R<String> updateCategorySort(@RequestBody StoreBookingCategorySortDTO dto) {
|