package com.wok.supportbot.controller; import com.wok.supportbot.service.CustomerServiceRoleService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Map; import java.util.Objects; @RestController public class CustomerServiceRoleController { @Autowired private CustomerServiceRoleService customerServiceRoleService; @GetMapping("/role/list") public ResponseEntity> listRoles() { return ResponseEntity.ok(Map.of( "success", true, "data", customerServiceRoleService.listRoles() )); } @PutMapping("/role/{id}/categories") public ResponseEntity> updateRoleCategories( @PathVariable("id") Long roleId, @RequestBody Map body) { List categoryIds = parseCategoryIds(body.get("categoryIds")); customerServiceRoleService.updateRoleCategories(roleId, categoryIds); return ResponseEntity.ok(Map.of( "success", true, "message", "更新成功" )); } private List parseCategoryIds(Object rawCategoryIds) { if (!(rawCategoryIds instanceof List list)) { return List.of(); } return list.stream() .filter(Objects::nonNull) .map(item -> item instanceof Number number ? number.longValue() : Long.parseLong(item.toString())) .filter(id -> id > 0) .distinct() .toList(); } }