优先设置后台模块,然后是用户模块、教练模块、
- User
优先设置后台模块,然后是用户模块、教练模块、
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
优先设置后台模块,然后是用户模块、教练模块、
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
好的!根据你的优先级,我会先提供 总管理后台模块 的核心功能实现,然后是 用户模块 和 教练模块。以下是分阶段的详细实现方案:
@RestController
@RequestMapping("/admin/stores")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class AdminStoreController {
@Autowired
private StoreService storeService;
@PostMapping
public ResponseEntity<StoreDTO> createStore(@RequestBody StoreDTO storeDTO) {
Store store = storeService.createStore(storeDTO);
return ResponseEntity.ok(StoreMapper.toDTO(store));
}
@PutMapping("/{id}")
public ResponseEntity<StoreDTO> updateStore(@PathVariable Long id, @RequestBody StoreDTO storeDTO) {
Store updatedStore = storeService.updateStore(id, storeDTO);
return ResponseEntity.ok(StoreMapper.toDTO(updatedStore));
}
@DeleteMapping("/{id}")
public ResponseEntity<?> deleteStore(@PathVariable Long id) {
storeService.deleteStore(id);
return ResponseEntity.ok().build();
}
@GetMapping
public ResponseEntity<List<StoreDTO>> getAllStores() {
List<Store> stores = storeService.getAllStores();
return ResponseEntity.ok(StoreMapper.toDTOList(stores));
}
}
@RestController
@RequestMapping("/admin/course-templates")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class CourseTemplateController {
@Autowired
private ConfigService configService;
@PostMapping
public ResponseEntity<?> createTemplate(@RequestBody CourseTemplateDTO template) {
configService.saveConfig("course_template", template.getName(), JsonUtils.toJson(template));
return ResponseEntity.ok().build();
}
@GetMapping
public ResponseEntity<List<CourseTemplateDTO>> getAllTemplates() {
List<Config> configs = configService.getConfigsByType("course_template");
return ResponseEntity.ok(configs.stream()
.map(c -> JsonUtils.fromJson(c.getValueJson(), CourseTemplateDTO.class))
.collect(Collectors.toList()));
}
}
@Service
public class ConfigService {
@Autowired
private ConfigMapper configMapper;
public void saveConfig(String moduleType, String key, String valueJson) {
Config config = new Config();
config.setModuleType(moduleType);
config.setKeyName(key);
config.setValueJson(valueJson);
configMapper.insert(config);
}
public List<Config> getConfigsByType(String moduleType) {
return configMapper.selectByModuleType(moduleType);
}
}
@Service
public class WeChatService {
private static final String APPID = "your_appid";
private static final String SECRET = "your_secret";
public String getOpenId(String code) {
String url = String.format("https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code",
APPID, SECRET, code);
ResponseEntity<WeChatLoginResponse> response = restTemplate.getForEntity(url, WeChatLoginResponse.class);
return response.getBody().getOpenid();
}
}
@Data
class WeChatLoginResponse {
private String openid;
private String session_key;
}
@RestController
@RequestMapping("/user/courses")
@PreAuthorize("hasRole('ROLE_USER')")
public class UserCourseController {
@Autowired
private CourseBookingService bookingService;
@PostMapping("/book/{courseId}")
public ResponseEntity<?> bookCourse(@PathVariable Long courseId, @AuthenticationPrincipal User user) {
bookingService.bookCourse(courseId, user.getId());
return ResponseEntity.ok().build();
}
}
@RestController
@RequestMapping("/coach/courses")
@PreAuthorize("hasRole('ROLE_COACH')")
public class CoachCourseController {
@Autowired
private CourseService courseService;
@PostMapping
public ResponseEntity<CourseDTO> createCourse(@RequestBody CourseDTO courseDTO, @AuthenticationPrincipal User coach) {
courseDTO.setCoachId(coach.getId());
Course course = courseService.createCourse(courseDTO);
return ResponseEntity.ok(CourseMapper.toDTO(course));
}
@PutMapping("/{id}")
public ResponseEntity<CourseDTO> updateCourse(@PathVariable Long id, @RequestBody CourseDTO courseDTO) {
Course updatedCourse = courseService.updateCourse(id, courseDTO);
return ResponseEntity.ok(CourseMapper.toDTO(updatedCourse));
}
}
@GetMapping("/{courseId}/bookings")
public ResponseEntity<List<UserDTO>> getBookedUsers(@PathVariable Long courseId, @AuthenticationPrincipal User coach) {
List<User> users = bookingService.getBookedUsers(courseId);
return ResponseEntity.ok(UserMapper.toDTOList(users));
}
使用 Flyway 或 Liquibase 管理数据库版本:
-- V1__initial_schema.sql
CREATE TABLE user (
id BIGINT PRIMARY KEY,
open_id VARCHAR(64),
role INT DEFAULT 1
);
CREATE TABLE course (
id BIGINT PRIMARY KEY,
coach_id BIGINT,
approved_by_manager BOOLEAN DEFAULT FALSE
);
如果需要任何模块的完整代码(如教练课程发布、用户预约逻辑、总后台配置模块),请直接告诉我!我可以提供更详细的实现。