更新调整修复
This commit is contained in:
@@ -85,7 +85,7 @@ public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:50',
|
||||
'name' => 'required|string|max:100|unique:auth_permissions,name',
|
||||
'name' => 'required|string|max:100|unique:auth_permission,name',
|
||||
'type' => 'required|in:menu,api,button',
|
||||
'route' => 'nullable|string|max:200',
|
||||
'component' => 'nullable|string|max:200',
|
||||
@@ -127,7 +127,7 @@ public function update(Request $request, $id)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'nullable|string|max:50',
|
||||
'name' => 'nullable|string|max:100|unique:auth_permissions,name,' . $id,
|
||||
'name' => 'nullable|string|max:100|unique:auth_permission,name,' . $id,
|
||||
'type' => 'nullable|in:menu,api,button',
|
||||
'route' => 'nullable|string|max:200',
|
||||
'component' => 'nullable|string|max:200',
|
||||
|
||||
@@ -75,7 +75,7 @@ public function store(Request $request)
|
||||
'sort' => 'nullable|integer|min:0',
|
||||
'status' => 'nullable|integer|in:0,1',
|
||||
'permission_ids' => 'nullable|array',
|
||||
'permission_ids.*' => 'integer|exists:auth_permissions,id',
|
||||
'permission_ids.*' => 'integer|exists:auth_permission,id',
|
||||
]);
|
||||
|
||||
$result = $this->roleService->create($validated);
|
||||
@@ -99,7 +99,7 @@ public function update(Request $request, $id)
|
||||
'sort' => 'nullable|integer|min:0',
|
||||
'status' => 'nullable|integer|in:0,1',
|
||||
'permission_ids' => 'nullable|array',
|
||||
'permission_ids.*' => 'integer|exists:auth_permissions,id',
|
||||
'permission_ids.*' => 'integer|exists:auth_permission,id',
|
||||
]);
|
||||
|
||||
$result = $this->roleService->update($id, $validated);
|
||||
@@ -171,7 +171,7 @@ public function assignPermissions(Request $request, $id)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'permission_ids' => 'required|array',
|
||||
'permission_ids.*' => 'integer|exists:auth_permissions,id',
|
||||
'permission_ids.*' => 'integer|exists:auth_permission,id',
|
||||
]);
|
||||
|
||||
$this->roleService->assignPermissions($id, $validated['permission_ids']);
|
||||
|
||||
@@ -46,24 +46,24 @@ public function getList(array $params): array
|
||||
|
||||
public function getAll(): array
|
||||
{
|
||||
$cacheKey = 'system:dictionaries:all';
|
||||
$dictionaries = Cache::get($cacheKey);
|
||||
$cacheKey = 'system:dictionary:all';
|
||||
$dictionary = Cache::get($cacheKey);
|
||||
|
||||
if ($dictionaries === null) {
|
||||
$dictionaries = Dictionary::where('status', true)
|
||||
if ($dictionary === null) {
|
||||
$dictionary = Dictionary::where('status', true)
|
||||
->with(['activeItems'])
|
||||
->orderBy('sort')
|
||||
->get()
|
||||
->toArray();
|
||||
Cache::put($cacheKey, $dictionaries, 3600);
|
||||
Cache::put($cacheKey, $dictionary, 3600);
|
||||
}
|
||||
|
||||
return $dictionaries;
|
||||
return $dictionary;
|
||||
}
|
||||
|
||||
public function getById(int $id): ?array
|
||||
{
|
||||
$cacheKey = 'system:dictionaries:' . $id;
|
||||
$cacheKey = 'system:dictionary:' . $id;
|
||||
$dictionary = Cache::get($cacheKey);
|
||||
|
||||
if ($dictionary === null) {
|
||||
@@ -83,7 +83,7 @@ public function getById(int $id): ?array
|
||||
|
||||
public function getByCode(string $code): ?array
|
||||
{
|
||||
$cacheKey = 'system:dictionaries:code:' . $code;
|
||||
$cacheKey = 'system:dictionary:code:' . $code;
|
||||
$dictionary = Cache::get($cacheKey);
|
||||
|
||||
if ($dictionary === null) {
|
||||
@@ -131,7 +131,7 @@ public function create(array $data): Dictionary
|
||||
{
|
||||
Validator::make($data, [
|
||||
'name' => 'required|string|max:100',
|
||||
'code' => 'required|string|max:50|unique:system_dictionaries,code',
|
||||
'code' => 'required|string|max:50|unique:system_dictionary,code',
|
||||
])->validate();
|
||||
|
||||
$dictionary = Dictionary::create($data);
|
||||
@@ -146,7 +146,7 @@ public function update(int $id, array $data): Dictionary
|
||||
|
||||
Validator::make($data, [
|
||||
'name' => 'sometimes|required|string|max:100',
|
||||
'code' => 'sometimes|required|string|max:50|unique:system_dictionaries,code,' . $id,
|
||||
'code' => 'sometimes|required|string|max:50|unique:system_dictionary,code,' . $id,
|
||||
])->validate();
|
||||
|
||||
$dictionary->update($data);
|
||||
@@ -186,14 +186,14 @@ public function batchUpdateStatus(array $ids, bool $status): bool
|
||||
private function clearCache($dictionaryId = null): void
|
||||
{
|
||||
// 清理所有字典列表缓存
|
||||
Cache::forget('system:dictionaries:all');
|
||||
Cache::forget('system:dictionary:all');
|
||||
|
||||
if ($dictionaryId) {
|
||||
// 清理特定字典的缓存
|
||||
$dictionary = Dictionary::find($dictionaryId);
|
||||
if ($dictionary) {
|
||||
Cache::forget('system:dictionaries:' . $dictionaryId);
|
||||
Cache::forget('system:dictionaries:code:' . $dictionary->code);
|
||||
Cache::forget('system:dictionary:' . $dictionaryId);
|
||||
Cache::forget('system:dictionary:code:' . $dictionary->code);
|
||||
Cache::forget('system:dictionary:' . $dictionary->code);
|
||||
}
|
||||
} else {
|
||||
@@ -201,7 +201,7 @@ private function clearCache($dictionaryId = null): void
|
||||
$codes = Dictionary::pluck('code')->toArray();
|
||||
foreach ($codes as $code) {
|
||||
Cache::forget('system:dictionary:' . $code);
|
||||
Cache::forget('system:dictionaries:code:' . $code);
|
||||
Cache::forget('system:dictionary:code:' . $code);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +235,7 @@ public function getItemsList(array $params): array
|
||||
public function createItem(array $data): DictionaryItem
|
||||
{
|
||||
Validator::make($data, [
|
||||
'dictionary_id' => 'required|exists:system_dictionaries,id',
|
||||
'dictionary_id' => 'required|exists:system_dictionary,id',
|
||||
'label' => 'required|string|max:100',
|
||||
'value' => 'required|string|max:100',
|
||||
])->validate();
|
||||
@@ -251,7 +251,7 @@ public function updateItem(int $id, array $data): DictionaryItem
|
||||
$item = DictionaryItem::findOrFail($id);
|
||||
|
||||
Validator::make($data, [
|
||||
'dictionary_id' => 'sometimes|required|exists:system_dictionaries,id',
|
||||
'dictionary_id' => 'sometimes|required|exists:system_dictionary,id',
|
||||
'label' => 'sometimes|required|string|max:100',
|
||||
'value' => 'sometimes|required|string|max:100',
|
||||
])->validate();
|
||||
@@ -316,12 +316,12 @@ public function getAllItems(): array
|
||||
|
||||
if ($allItems === null) {
|
||||
// 获取所有启用的字典
|
||||
$dictionaries = Dictionary::where('status', true)
|
||||
$dictionary = Dictionary::where('status', true)
|
||||
->orderBy('sort')
|
||||
->get();
|
||||
|
||||
$result = [];
|
||||
foreach ($dictionaries as $dictionary) {
|
||||
foreach ($dictionary as $dictionary) {
|
||||
$items = $dictionary->activeItems->toArray();
|
||||
// 格式化字典项值
|
||||
$items = $this->formatItemsByType($items, $dictionary->value_type);
|
||||
|
||||
Reference in New Issue
Block a user