|
|
@@ -0,0 +1,174 @@
|
|
|
+package com.etotem.cfc.controller.admin;
|
|
|
+
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.FoodDiseaseWeightGroup;
|
|
|
+import com.etotem.cfc.entity.FoodPairingMatrix;
|
|
|
+import com.etotem.cfc.entity.FoodProcessingEffect;
|
|
|
+import com.etotem.cfc.entity.FoodRecommendWeightRule;
|
|
|
+import com.etotem.cfc.service.FoodRuleManagementService;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 后台推荐规则管理端点(能力键 {@code food.ops.ruleManagement},S-cfc-502 / CR-06 §4.6)。
|
|
|
+ *
|
|
|
+ * <p>权重 / 配伍 / 加工 / 病症权重四 Tab 共 12 个端点,统一 {@code @PostMapping} +
|
|
|
+ * {@code Result<T>},放行前校验 {@code @RequestAttribute("role")} 为 admin。</p>
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/admin/food-rule")
|
|
|
+public class FoodRuleManagementController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private FoodRuleManagementService foodRuleManagementService;
|
|
|
+
|
|
|
+ // ==================== 权重规则 Tab ====================
|
|
|
+
|
|
|
+ @PostMapping("/weight/list")
|
|
|
+ public Result<List<FoodRecommendWeightRule>> listWeightRules(
|
|
|
+ @RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error(403, "无权限");
|
|
|
+ }
|
|
|
+ return Result.success(foodRuleManagementService.listWeightRules());
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/weight/save")
|
|
|
+ public Result<FoodRecommendWeightRule> saveWeightRule(
|
|
|
+ @RequestBody FoodRecommendWeightRule rule,
|
|
|
+ @RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error(403, "无权限");
|
|
|
+ }
|
|
|
+ return Result.success(foodRuleManagementService.saveWeightRule(rule));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/weight/toggle")
|
|
|
+ public Result<FoodRecommendWeightRule> toggleWeightRule(
|
|
|
+ @RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error(403, "无权限");
|
|
|
+ }
|
|
|
+ boolean enabled = isEnabled(body == null ? null : body.get("enabled"));
|
|
|
+ return Result.success(foodRuleManagementService.toggleWeightRule(idOf(body), enabled));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 配伍矩阵 Tab ====================
|
|
|
+
|
|
|
+ @PostMapping("/pairing/list")
|
|
|
+ public Result<List<FoodPairingMatrix>> listPairing(
|
|
|
+ @RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error(403, "无权限");
|
|
|
+ }
|
|
|
+ return Result.success(foodRuleManagementService.listPairing());
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/pairing/save")
|
|
|
+ public Result<FoodPairingMatrix> savePairing(
|
|
|
+ @RequestBody FoodPairingMatrix rule,
|
|
|
+ @RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error(403, "无权限");
|
|
|
+ }
|
|
|
+ return Result.success(foodRuleManagementService.savePairing(rule));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/pairing/delete")
|
|
|
+ public Result<Boolean> deletePairing(
|
|
|
+ @RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error(403, "无权限");
|
|
|
+ }
|
|
|
+ return Result.success(Boolean.valueOf(foodRuleManagementService.deletePairing(idOf(body))));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 加工效应 Tab ====================
|
|
|
+
|
|
|
+ @PostMapping("/processing/list")
|
|
|
+ public Result<List<FoodProcessingEffect>> listProcessing(
|
|
|
+ @RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error(403, "无权限");
|
|
|
+ }
|
|
|
+ return Result.success(foodRuleManagementService.listProcessing());
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/processing/save")
|
|
|
+ public Result<FoodProcessingEffect> saveProcessing(
|
|
|
+ @RequestBody FoodProcessingEffect rule,
|
|
|
+ @RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error(403, "无权限");
|
|
|
+ }
|
|
|
+ return Result.success(foodRuleManagementService.saveProcessing(rule));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/processing/delete")
|
|
|
+ public Result<Boolean> deleteProcessing(
|
|
|
+ @RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error(403, "无权限");
|
|
|
+ }
|
|
|
+ return Result.success(Boolean.valueOf(foodRuleManagementService.deleteProcessing(idOf(body))));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 病症权重 Tab ====================
|
|
|
+
|
|
|
+ @PostMapping("/disease-group/list")
|
|
|
+ public Result<List<FoodDiseaseWeightGroup>> listDiseaseGroup(
|
|
|
+ @RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error(403, "无权限");
|
|
|
+ }
|
|
|
+ return Result.success(foodRuleManagementService.listDiseaseGroup());
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/disease-group/save")
|
|
|
+ public Result<FoodDiseaseWeightGroup> saveDiseaseGroup(
|
|
|
+ @RequestBody FoodDiseaseWeightGroup rule,
|
|
|
+ @RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error(403, "无权限");
|
|
|
+ }
|
|
|
+ return Result.success(foodRuleManagementService.saveDiseaseGroup(rule));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/disease-group/delete")
|
|
|
+ public Result<Boolean> deleteDiseaseGroup(
|
|
|
+ @RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error(403, "无权限");
|
|
|
+ }
|
|
|
+ return Result.success(Boolean.valueOf(foodRuleManagementService.deleteDiseaseGroup(idOf(body))));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 辅助 ====================
|
|
|
+
|
|
|
+ private boolean isAdmin(String role) {
|
|
|
+ return "admin".equals(role);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long idOf(Map<String, Object> body) {
|
|
|
+ if (body == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Object raw = body.get("id");
|
|
|
+ return raw instanceof Number ? Long.valueOf(((Number) raw).longValue()) : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isEnabled(Object raw) {
|
|
|
+ return Boolean.TRUE.equals(raw) || "1".equals(String.valueOf(raw));
|
|
|
+ }
|
|
|
+}
|