272 lines
10 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<List<DemandType>> getAllDemandTypes() {
return Result.success(configService.getAllDemandTypes());
}
@Operation(summary = "获取所有启用的需求类型(用于下拉选择)")
@GetMapping("/demand-types/enabled")
public Result<List<DemandType>> getEnabledDemandTypes() {
return Result.success(configService.getEnabledDemandTypes());
}
@Operation(summary = "根据ID获取需求类型")
@GetMapping("/demand-types/{id:\\d+}")
public Result<DemandType> getDemandTypeById(@PathVariable Long id) {
return Result.success(configService.getDemandTypeById(id));
}
@Operation(summary = "创建需求类型")
@PostMapping("/demand-types")
public Result<DemandType> createDemandType(@RequestBody DemandType demandType) {
return Result.success(configService.createDemandType(demandType));
}
@Operation(summary = "更新需求类型")
@PutMapping("/demand-types/{id:\\d+}")
public Result<Boolean> 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<Boolean> deleteDemandType(@PathVariable Long id) {
return Result.success(configService.deleteDemandType(id));
}
@Operation(summary = "设置需求类型的可接单部门")
@PutMapping("/demand-types/{id:\\d+}/departments")
public Result<Boolean> setDemandTypeDepartments(
@PathVariable Long id,
@RequestBody List<Long> departmentIds) {
return Result.success(demandTypeDepartmentService.setDemandTypeDepartments(id, departmentIds));
}
@Operation(summary = "获取需求类型的可接单部门列表")
@GetMapping("/demand-types/{id:\\d+}/departments")
public Result<List<Long>> getDemandTypeDepartments(@PathVariable Long id) {
return Result.success(demandTypeDepartmentService.getDepartmentIdsByDemandType(id));
}
// ============ 品牌管理 ============
@Operation(summary = "获取所有品牌(包括禁用的,用于管理页面)")
@GetMapping("/brands")
public Result<List<Brand>> getAllBrands() {
return Result.success(configService.getAllBrands());
}
@Operation(summary = "获取所有启用的品牌(用于下拉选择)")
@GetMapping("/brands/enabled")
public Result<List<Brand>> getEnabledBrands() {
return Result.success(configService.getEnabledBrands());
}
@Operation(summary = "根据ID获取品牌")
@GetMapping("/brands/{id:\\d+}")
public Result<Brand> getBrandById(@PathVariable Long id) {
return Result.success(configService.getBrandById(id));
}
@Operation(summary = "创建品牌")
@PostMapping("/brands")
public Result<Brand> createBrand(@RequestBody Brand brand) {
return Result.success(configService.createBrand(brand));
}
@Operation(summary = "更新品牌")
@PutMapping("/brands/{id:\\d+}")
public Result<Boolean> updateBrand(@PathVariable Long id, @RequestBody Brand brand) {
brand.setId(id);
return Result.success(configService.updateBrand(brand));
}
@Operation(summary = "删除品牌")
@DeleteMapping("/brands/{id:\\d+}")
public Result<Boolean> deleteBrand(@PathVariable Long id) {
return Result.success(configService.deleteBrand(id));
}
// ============ 平台管理 ============
@Operation(summary = "获取所有平台(包括禁用的,用于管理页面)")
@GetMapping("/platforms")
public Result<List<Platform>> getAllPlatforms() {
return Result.success(configService.getAllPlatforms());
}
@Operation(summary = "获取所有启用的平台(用于下拉选择)")
@GetMapping("/platforms/enabled")
public Result<List<Platform>> getEnabledPlatforms() {
return Result.success(configService.getEnabledPlatforms());
}
@Operation(summary = "根据ID获取平台")
@GetMapping("/platforms/{id:\\d+}")
public Result<Platform> getPlatformById(@PathVariable Long id) {
return Result.success(configService.getPlatformById(id));
}
@Operation(summary = "创建平台")
@PostMapping("/platforms")
public Result<Platform> createPlatform(@RequestBody Platform platform) {
return Result.success(configService.createPlatform(platform));
}
@Operation(summary = "更新平台")
@PutMapping("/platforms/{id:\\d+}")
public Result<Boolean> updatePlatform(@PathVariable Long id, @RequestBody Platform platform) {
platform.setId(id);
return Result.success(configService.updatePlatform(platform));
}
@Operation(summary = "删除平台")
@DeleteMapping("/platforms/{id:\\d+}")
public Result<Boolean> deletePlatform(@PathVariable Long id) {
return Result.success(configService.deletePlatform(id));
}
// ============ 类目管理 ============
@Operation(summary = "获取所有叶子类目(包括禁用的,用于管理页面)")
@GetMapping("/categories/leaf")
public Result<List<Category>> getAllLeafCategories() {
return Result.success(configService.getAllLeafCategories());
}
@Operation(summary = "获取所有启用的叶子类目(用于下拉选择)")
@GetMapping("/categories/leaf/enabled")
public Result<List<Category>> getEnabledLeafCategories() {
return Result.success(configService.getEnabledLeafCategories());
}
@Operation(summary = "获取所有类目")
@GetMapping("/categories")
public Result<List<Category>> getAllCategories() {
return Result.success(configService.getAllCategories());
}
@Operation(summary = "根据父ID获取子类目")
@GetMapping("/categories/parent/{parentId}")
public Result<List<Category>> getCategoriesByParentId(@PathVariable Long parentId) {
return Result.success(configService.getCategoriesByParentId(parentId));
}
@Operation(summary = "根据ID获取类目")
@GetMapping("/categories/{id:\\d+}")
public Result<Category> getCategoryById(@PathVariable Long id) {
return Result.success(configService.getCategoryById(id));
}
@Operation(summary = "创建类目")
@PostMapping("/categories")
public Result<Category> createCategory(@RequestBody Category category) {
return Result.success(configService.createCategory(category));
}
@Operation(summary = "更新类目")
@PutMapping("/categories/{id:\\d+}")
public Result<Boolean> updateCategory(@PathVariable Long id, @RequestBody Category category) {
category.setId(id);
return Result.success(configService.updateCategory(category));
}
@Operation(summary = "删除类目")
@DeleteMapping("/categories/{id:\\d+}")
public Result<Boolean> deleteCategory(@PathVariable Long id) {
return Result.success(configService.deleteCategory(id));
}
// ============ 团队积分池管理 ============
@Operation(summary = "根据部门ID获取积分池")
@GetMapping("/score-pool/dept/{deptId}")
public Result<TeamScorePool> 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<Boolean> checkBalance(@RequestParam Long deptId, @RequestParam Integer score) {
return Result.success(teamScorePoolService.checkBalance(deptId, score));
}
@Operation(summary = "检查是否超过周期限制")
@GetMapping("/score-pool/check-limit")
public Result<Boolean> checkPeriodLimit(@RequestParam Long deptId, @RequestParam Integer score) {
return Result.success(teamScorePoolService.checkPeriodLimit(deptId, score));
}
@Operation(summary = "充值积分")
@PostMapping("/score-pool/recharge")
public Result<Void> rechargeScore(@RequestParam Long deptId, @RequestParam Integer score) {
teamScorePoolService.rechargeScore(deptId, score);
return Result.success();
}
@Operation(summary = "创建积分池")
@PostMapping("/score-pool")
public Result<TeamScorePool> createScorePool(@RequestBody TeamScorePool pool) {
return Result.success(teamScorePoolService.createPool(pool));
}
@Operation(summary = "更新积分池配置")
@PutMapping("/score-pool/{id}")
public Result<Boolean> 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<Boolean> isAlert(@PathVariable Long deptId) {
return Result.success(teamScorePoolService.isAlert(deptId));
}
}