本地主机消除502

This commit is contained in:
2025-09-21 14:25:01 +08:00
parent b7d9f16198
commit e5eb8d6174
38 changed files with 56 additions and 73 deletions

View File

@@ -53,8 +53,8 @@
- 增加健康检查与基础 CRUD 接口;在 `/doc/openapi.yaml` 按规范登记并标注实现状态(❌/✅)。
### 前端默认连接策略
- 默认后端地址:`http://192.168.31.193:8080`(可被环境变量/Storage 覆盖)
- 多地址重试:按顺序尝试(去重处理):`[ENV, Storage, 192.168.31.193:8080, 127.0.0.1:8080, localhost:8080]`
- 默认后端地址:`http://127.0.0.1:8080`(可被环境变量/Storage 覆盖)
- 多地址重试:按顺序尝试(去重处理):`[ENV, Storage, 127.0.0.1:8080, localhost:8080]`
- 默认用户:开启(可被环境变量/Storage 关闭),请求自动附带 `X-User-Id`(默认 `2`)。
- 如需关闭:在 Storage 或构建环境中设置 `ENABLE_DEFAULT_USER=false`

View File

@@ -10,12 +10,6 @@ public class Notice {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "shop_id", nullable = false)
private Long shopId;
@Column(name = "user_id", nullable = false)
private Long userId;
@Column(name = "title", nullable = false, length = 120)
private String title;
@@ -57,10 +51,6 @@ public class Notice {
}
public Long getId() { return id; }
public Long getShopId() { return shopId; }
public void setShopId(Long shopId) { this.shopId = shopId; }
public Long getUserId() { return userId; }
public void setUserId(Long userId) { this.userId = userId; }
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
public String getContent() { return content; }

View File

@@ -2,7 +2,6 @@ package com.example.demo.notice;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -18,13 +17,9 @@ public class NoticeController {
this.noticeService = noticeService;
}
/**
* 简化:通过请求头 X-Shop-Id 传递当前店铺ID。
*/
@GetMapping
public ResponseEntity<List<Notice>> list(@RequestHeader(name = "X-Shop-Id", required = false) Long shopId) {
Long sid = (shopId == null ? 1L : shopId);
return ResponseEntity.ok(noticeService.listActive(sid));
public ResponseEntity<List<Notice>> list() {
return ResponseEntity.ok(noticeService.listActive());
}
}

View File

@@ -8,10 +8,10 @@ import java.util.List;
public interface NoticeRepository extends JpaRepository<Notice, Long> {
@Query("SELECT n FROM Notice n WHERE n.shopId = :shopId AND n.status = :status " +
@Query("SELECT n FROM Notice n WHERE n.status = :status " +
"AND (n.startsAt IS NULL OR n.startsAt <= CURRENT_TIMESTAMP) AND (n.endsAt IS NULL OR n.endsAt >= CURRENT_TIMESTAMP) " +
"ORDER BY n.pinned DESC, n.createdAt DESC")
List<Notice> findActiveNotices(@Param("shopId") Long shopId, @Param("status") NoticeStatus status);
List<Notice> findActiveNotices(@Param("status") NoticeStatus status);
}

View File

@@ -12,8 +12,8 @@ public class NoticeService {
this.noticeRepository = noticeRepository;
}
public List<Notice> listActive(Long shopId) {
return noticeRepository.findActiveNotices(shopId, NoticeStatus.PUBLISHED);
public List<Notice> listActive() {
return noticeRepository.findActiveNotices(NoticeStatus.PUBLISHED);
}
}