Przeglądaj źródła

基础设施服务(图片上传和区域设施列表)1.0

panzhilin 3 miesięcy temu
rodzic
commit
02e969e57f

+ 1 - 2
alien-entity/src/main/java/shop/alien/entity/store/SportsFacilityArea.java

@@ -68,9 +68,8 @@ public class SportsFacilityArea implements Serializable {
     @TableField("area_logo_img")
     private String areaLogoImg;
 
-    @ApiModelProperty(value = "头图")
+    @ApiModelProperty(value = "区域头图URL")
     @TableField("area_head_url")
     private String areaHeadUrl;
-
 }
 

+ 33 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/UpdateAreaRequestVo.java

@@ -0,0 +1,33 @@
+package shop.alien.entity.store.vo;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 更新区域请求VO
+ *
+ * @author assistant
+ * @since 2025-01-XX
+ */
+@Data
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@ApiModel(value = "UpdateAreaRequestVo对象", description = "更新区域请求视图对象")
+public class UpdateAreaRequestVo implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "区域ID", required = true, example = "1")
+    private Integer areaId;
+
+    @ApiModelProperty(value = "区域名称(可选,限10字)", required = false, example = "新洗浴区")
+    private String areaName;
+
+    @ApiModelProperty(value = "排序号(可选,数字越小越靠前)", required = false, example = "1")
+    private Integer sortOrder;
+}
+
+

+ 46 - 5
alien-store/src/main/java/shop/alien/store/controller/SportsFacilityAreaController.java

@@ -10,6 +10,7 @@ import shop.alien.entity.store.SportsFacilityArea;
 import shop.alien.entity.store.vo.BatchDeleteAreaRequestVo;
 import shop.alien.entity.store.vo.CreateAreaRequestVo;
 import shop.alien.entity.store.vo.DeleteAreaRequestVo;
+import shop.alien.entity.store.vo.UpdateAreaHeadUrlRequestVo;
 import shop.alien.store.service.SportsFacilityAreaService;
 
 import java.util.List;
@@ -22,7 +23,7 @@ import java.util.List;
  */
 @Slf4j
 @Api(tags = {"商户端-运动设施区域管理"})
-@ApiSort(2)
+@ApiSort(1)
 @CrossOrigin
 @RestController
 @RequestMapping("/sports/facility/area")
@@ -41,7 +42,7 @@ public class SportsFacilityAreaController {
      */
     private static final String INVALID_STORE_ID_MSG = "门店ID不能为空且必须大于0";
 
-    @ApiOperation("新建区域(创建新的设施区域)")
+    @ApiOperation("新建区域")
     @ApiOperationSupport(order = 1)
     @ApiImplicitParams({
             @ApiImplicitParam(name = "request", value = "新建区域请求参数", dataType = "CreateAreaRequestVo", paramType = "body", required = true)
@@ -142,9 +143,49 @@ public class SportsFacilityAreaController {
         }
     }
 
-    @ApiOperation("删除区域(逻辑删除,同时删除该区域下的所有设施)")
+    @ApiOperation("更新区域头图")
     @ApiOperationSupport(order = 4)
     @ApiImplicitParams({
+            @ApiImplicitParam(name = "request", value = "更新区域头图请求参数", dataType = "UpdateAreaHeadUrlRequestVo", paramType = "body", required = true)
+    })
+    @PostMapping("/updateHeadUrl")
+    public R<Boolean> updateAreaHeadUrl(@RequestBody UpdateAreaHeadUrlRequestVo request) {
+        log.info("更新区域头图,request={}", request);
+        try {
+            // 参数验证
+            if (request == null) {
+                log.warn("更新区域头图失败,请求参数为空");
+                return R.fail("请求参数不能为空");
+            }
+
+            if (request.getAreaId() == null || request.getAreaId() < MIN_VALID_VALUE) {
+                log.warn("更新区域头图失败,区域ID无效:{}", request.getAreaId());
+                return R.fail("区域ID不能为空且必须大于0");
+            }
+
+            if (request.getAreaHeadUrl() == null) {
+                log.warn("更新区域头图失败,区域头图URL为空");
+                return R.fail("区域头图URL不能为空");
+            }
+
+            boolean result = areaService.updateAreaHeadUrl(request.getAreaId(), request.getAreaHeadUrl());
+            if (result) {
+                log.info("更新区域头图成功,areaId={}", request.getAreaId());
+                return R.success("更新区域头图成功");
+            }
+            return R.fail("更新区域头图失败");
+        } catch (IllegalArgumentException e) {
+            log.warn("更新区域头图失败,参数验证失败:{}", e.getMessage());
+            return R.fail(e.getMessage());
+        } catch (Exception e) {
+            log.error("更新区域头图异常,request={},异常信息:{}", request, e.getMessage(), e);
+            return R.fail("更新区域头图失败:" + e.getMessage());
+        }
+    }
+
+    @ApiOperation("删除区域")
+    @ApiOperationSupport(order = 5)
+    @ApiImplicitParams({
             @ApiImplicitParam(name = "request", value = "删除区域请求参数", dataType = "DeleteAreaRequestVo", paramType = "body", required = true)
     })
     @PostMapping("/delete")
@@ -177,8 +218,8 @@ public class SportsFacilityAreaController {
         }
     }
 
-    @ApiOperation("批量删除区域(逻辑删除,同时删除这些区域下的所有设施)")
-    @ApiOperationSupport(order = 5)
+    @ApiOperation("批量删除区域")
+    @ApiOperationSupport(order = 6)
     @ApiImplicitParams({
             @ApiImplicitParam(name = "request", value = "批量删除区域请求参数", dataType = "BatchDeleteAreaRequestVo", paramType = "body", required = true)
     })

+ 10 - 0
alien-store/src/main/java/shop/alien/store/service/SportsFacilityAreaService.java

@@ -42,6 +42,16 @@ public interface SportsFacilityAreaService extends IService<SportsFacilityArea>
     boolean updateArea(Integer areaId, String areaName, Integer sortOrder);
 
     /**
+     * 更新区域头图
+     * 将传入的长字符串URL覆盖原有的area_head_url字段中的数据
+     *
+     * @param areaId 区域ID,不能为空且必须大于0
+     * @param areaHeadUrl 区域头图URL(长字符串),必填
+     * @return 更新是否成功
+     */
+    boolean updateAreaHeadUrl(Integer areaId, String areaHeadUrl);
+
+    /**
      * 删除区域(逻辑删除)
      * 删除区域时,会同时逻辑删除该区域下的所有设施
      *

+ 47 - 0
alien-store/src/main/java/shop/alien/store/service/impl/SportsFacilityAreaServiceImpl.java

@@ -107,6 +107,8 @@ public class SportsFacilityAreaServiceImpl extends ServiceImpl<SportsFacilityAre
         }
 
         // 查询该门店下的所有未删除区域,按排序号升序,相同排序号按创建时间降序
+        // 查询结果包含所有字段:id、storeId、areaName、sortOrder、deleteFlag、createdTime、updatedTime、
+        // createdUserId、updatedUserId、areaLogoImg、areaHeadUrl
         LambdaQueryWrapper<SportsFacilityArea> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(SportsFacilityArea::getStoreId, storeId)
                 .eq(SportsFacilityArea::getDeleteFlag, DELETE_FLAG_NOT_DELETED)
@@ -114,6 +116,18 @@ public class SportsFacilityAreaServiceImpl extends ServiceImpl<SportsFacilityAre
                 .orderByDesc(SportsFacilityArea::getCreatedTime);
 
         List<SportsFacilityArea> areaList = this.list(queryWrapper);
+        
+        // 记录查询结果详情(包括区域头图URL长度信息,用于调试)
+        if (log.isDebugEnabled()) {
+            areaList.forEach(area -> {
+                log.debug("查询区域详情,areaId={},areaName={},areaHeadUrl长度={},areaLogoImg={}", 
+                        area.getId(), 
+                        area.getAreaName(),
+                        area.getAreaHeadUrl() != null ? area.getAreaHeadUrl().length() : 0,
+                        area.getAreaLogoImg());
+            });
+        }
+        
         log.info("查询区域列表成功,storeId={},区域数量:{}", storeId, areaList.size());
         return areaList;
     }
@@ -163,6 +177,39 @@ public class SportsFacilityAreaServiceImpl extends ServiceImpl<SportsFacilityAre
     }
 
     @Override
+    public boolean updateAreaHeadUrl(Integer areaId, String areaHeadUrl) {
+        log.info("更新区域头图,areaId={},areaHeadUrl长度={}", areaId, areaHeadUrl != null ? areaHeadUrl.length() : 0);
+
+        // 参数验证
+        if (areaId == null || areaId <= 0) {
+            log.warn("更新区域头图失败,区域ID无效:{}", areaId);
+            throw new IllegalArgumentException("区域ID不能为空且必须大于0");
+        }
+
+        if (areaHeadUrl == null) {
+            log.warn("更新区域头图失败,区域头图URL为空");
+            throw new IllegalArgumentException("区域头图URL不能为空");
+        }
+
+        // 查询区域是否存在
+        SportsFacilityArea existingArea = this.getById(areaId);
+        if (existingArea == null || existingArea.getDeleteFlag() == DELETE_FLAG_DELETED) {
+            log.warn("更新区域头图失败,区域不存在或已删除:areaId={}", areaId);
+            throw new IllegalArgumentException("区域不存在或已删除");
+        }
+
+        // 构建更新条件,直接覆盖原有的area_head_url字段
+        LambdaUpdateWrapper<SportsFacilityArea> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.eq(SportsFacilityArea::getId, areaId)
+                .set(SportsFacilityArea::getAreaHeadUrl, areaHeadUrl);
+
+        // 执行更新
+        boolean updateResult = this.update(updateWrapper);
+        log.info("更新区域头图{},areaId={}", updateResult ? "成功" : "失败", areaId);
+        return updateResult;
+    }
+
+    @Override
     public boolean deleteArea(Integer areaId) {
         log.info("删除区域,areaId={}", areaId);