package com.designhub.controller; import com.designhub.common.Result; import com.designhub.entity.*; import com.designhub.service.ConfigService; import com.designhub.service.DemandTypeDepartmentService; import com.designhub.service.DepartmentService; import com.designhub.service.TeamScorePoolService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; import java.util.List; /** * 配置管理Controller */ @Tag(name = "配置管理", description = "系统配置相关API") @RestController @RequestMapping("/api/config") @RequiredArgsConstructor public class ConfigController { private final ConfigService configService; private final DemandTypeDepartmentService demandTypeDepartmentService; private final TeamScorePoolService teamScorePoolService; private final DepartmentService departmentService; // ============ 需求类型管理 ============ @Operation(summary = "获取所有需求类型(包括禁用的,用于管理页面)") @GetMapping("/demand-types") public Result> getAllDemandTypes() { return Result.success(configService.getAllDemandTypes()); } @Operation(summary = "获取所有启用的需求类型(用于下拉选择)") @GetMapping("/demand-types/enabled") public Result> getEnabledDemandTypes() { return Result.success(configService.getEnabledDemandTypes()); } @Operation(summary = "根据ID获取需求类型") @GetMapping("/demand-types/{id:\\d+}") public Result getDemandTypeById(@PathVariable Long id) { return Result.success(configService.getDemandTypeById(id)); } @Operation(summary = "创建需求类型") @PostMapping("/demand-types") public Result createDemandType(@RequestBody DemandType demandType) { return Result.success(configService.createDemandType(demandType)); } @Operation(summary = "更新需求类型") @PutMapping("/demand-types/{id:\\d+}") public Result updateDemandType(@PathVariable Long id, @RequestBody DemandType demandType) { demandType.setId(id); return Result.success(configService.updateDemandType(demandType)); } @Operation(summary = "删除需求类型") @DeleteMapping("/demand-types/{id:\\d+}") public Result deleteDemandType(@PathVariable Long id) { return Result.success(configService.deleteDemandType(id)); } @Operation(summary = "设置需求类型的可接单部门") @PutMapping("/demand-types/{id:\\d+}/departments") public Result setDemandTypeDepartments( @PathVariable Long id, @RequestBody List departmentIds) { return Result.success(demandTypeDepartmentService.setDemandTypeDepartments(id, departmentIds)); } @Operation(summary = "获取需求类型的可接单部门列表") @GetMapping("/demand-types/{id:\\d+}/departments") public Result> getDemandTypeDepartments(@PathVariable Long id) { return Result.success(demandTypeDepartmentService.getDepartmentIdsByDemandType(id)); } // ============ 品牌管理 ============ @Operation(summary = "获取所有品牌(包括禁用的,用于管理页面)") @GetMapping("/brands") public Result> getAllBrands() { return Result.success(configService.getAllBrands()); } @Operation(summary = "获取所有启用的品牌(用于下拉选择)") @GetMapping("/brands/enabled") public Result> getEnabledBrands() { return Result.success(configService.getEnabledBrands()); } @Operation(summary = "根据ID获取品牌") @GetMapping("/brands/{id:\\d+}") public Result getBrandById(@PathVariable Long id) { return Result.success(configService.getBrandById(id)); } @Operation(summary = "创建品牌") @PostMapping("/brands") public Result createBrand(@RequestBody Brand brand) { return Result.success(configService.createBrand(brand)); } @Operation(summary = "更新品牌") @PutMapping("/brands/{id:\\d+}") public Result updateBrand(@PathVariable Long id, @RequestBody Brand brand) { brand.setId(id); return Result.success(configService.updateBrand(brand)); } @Operation(summary = "删除品牌") @DeleteMapping("/brands/{id:\\d+}") public Result deleteBrand(@PathVariable Long id) { return Result.success(configService.deleteBrand(id)); } // ============ 平台管理 ============ @Operation(summary = "获取所有平台(包括禁用的,用于管理页面)") @GetMapping("/platforms") public Result> getAllPlatforms() { return Result.success(configService.getAllPlatforms()); } @Operation(summary = "获取所有启用的平台(用于下拉选择)") @GetMapping("/platforms/enabled") public Result> getEnabledPlatforms() { return Result.success(configService.getEnabledPlatforms()); } @Operation(summary = "根据ID获取平台") @GetMapping("/platforms/{id:\\d+}") public Result getPlatformById(@PathVariable Long id) { return Result.success(configService.getPlatformById(id)); } @Operation(summary = "创建平台") @PostMapping("/platforms") public Result createPlatform(@RequestBody Platform platform) { return Result.success(configService.createPlatform(platform)); } @Operation(summary = "更新平台") @PutMapping("/platforms/{id:\\d+}") public Result updatePlatform(@PathVariable Long id, @RequestBody Platform platform) { platform.setId(id); return Result.success(configService.updatePlatform(platform)); } @Operation(summary = "删除平台") @DeleteMapping("/platforms/{id:\\d+}") public Result deletePlatform(@PathVariable Long id) { return Result.success(configService.deletePlatform(id)); } // ============ 类目管理 ============ @Operation(summary = "获取所有叶子类目(包括禁用的,用于管理页面)") @GetMapping("/categories/leaf") public Result> getAllLeafCategories() { return Result.success(configService.getAllLeafCategories()); } @Operation(summary = "获取所有启用的叶子类目(用于下拉选择)") @GetMapping("/categories/leaf/enabled") public Result> getEnabledLeafCategories() { return Result.success(configService.getEnabledLeafCategories()); } @Operation(summary = "获取所有类目") @GetMapping("/categories") public Result> getAllCategories() { return Result.success(configService.getAllCategories()); } @Operation(summary = "根据父ID获取子类目") @GetMapping("/categories/parent/{parentId}") public Result> getCategoriesByParentId(@PathVariable Long parentId) { return Result.success(configService.getCategoriesByParentId(parentId)); } @Operation(summary = "根据ID获取类目") @GetMapping("/categories/{id:\\d+}") public Result getCategoryById(@PathVariable Long id) { return Result.success(configService.getCategoryById(id)); } @Operation(summary = "创建类目") @PostMapping("/categories") public Result createCategory(@RequestBody Category category) { return Result.success(configService.createCategory(category)); } @Operation(summary = "更新类目") @PutMapping("/categories/{id:\\d+}") public Result updateCategory(@PathVariable Long id, @RequestBody Category category) { category.setId(id); return Result.success(configService.updateCategory(category)); } @Operation(summary = "删除类目") @DeleteMapping("/categories/{id:\\d+}") public Result deleteCategory(@PathVariable Long id) { return Result.success(configService.deleteCategory(id)); } // ============ 团队积分池管理 ============ @Operation(summary = "根据部门ID获取积分池") @GetMapping("/score-pool/dept/{deptId}") public Result getScorePoolByDeptId(@PathVariable Long deptId) { TeamScorePool pool = teamScorePoolService.getByDeptId(deptId); // 如果积分池不存在,自动创建 if (pool == null) { var department = departmentService.getDepartmentById(deptId); if (department != null) { pool = teamScorePoolService.upsertPool(deptId, department.getDeptName()); } else { // 部门不存在,返回一个默认的积分池对象(余额为0) pool = new TeamScorePool(); pool.setDeptId(deptId); pool.setBalance(0); } } return Result.success(pool); } @Operation(summary = "检查积分余额是否足够") @GetMapping("/score-pool/check-balance") public Result checkBalance(@RequestParam Long deptId, @RequestParam Integer score) { return Result.success(teamScorePoolService.checkBalance(deptId, score)); } @Operation(summary = "检查是否超过周期限制") @GetMapping("/score-pool/check-limit") public Result checkPeriodLimit(@RequestParam Long deptId, @RequestParam Integer score) { return Result.success(teamScorePoolService.checkPeriodLimit(deptId, score)); } @Operation(summary = "充值积分") @PostMapping("/score-pool/recharge") public Result rechargeScore(@RequestParam Long deptId, @RequestParam Integer score) { teamScorePoolService.rechargeScore(deptId, score); return Result.success(); } @Operation(summary = "创建积分池") @PostMapping("/score-pool") public Result createScorePool(@RequestBody TeamScorePool pool) { return Result.success(teamScorePoolService.createPool(pool)); } @Operation(summary = "更新积分池配置") @PutMapping("/score-pool/{id}") public Result updateScorePool(@PathVariable Long id, @RequestBody TeamScorePool pool) { pool.setId(id); return Result.success(teamScorePoolService.updatePool(pool)); } @Operation(summary = "检查是否需要预警") @GetMapping("/score-pool/alert/{deptId}") public Result isAlert(@PathVariable Long deptId) { return Result.success(teamScorePoolService.isAlert(deptId)); } }