You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.9 KiB
53 lines
1.9 KiB
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<Map<String, Object>> listRoles() {
|
|
return ResponseEntity.ok(Map.of(
|
|
"success", true,
|
|
"data", customerServiceRoleService.listRoles()
|
|
));
|
|
}
|
|
|
|
@PutMapping("/role/{id}/categories")
|
|
public ResponseEntity<Map<String, Object>> updateRoleCategories(
|
|
@PathVariable("id") Long roleId,
|
|
@RequestBody Map<String, Object> body) {
|
|
List<Long> categoryIds = parseCategoryIds(body.get("categoryIds"));
|
|
customerServiceRoleService.updateRoleCategories(roleId, categoryIds);
|
|
return ResponseEntity.ok(Map.of(
|
|
"success", true,
|
|
"message", "更新成功"
|
|
));
|
|
}
|
|
|
|
private List<Long> 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();
|
|
}
|
|
}
|