feat(dict): data dictionary module — two-level flat model, CRUD/default/cache/permission/seed (ADR-0015)
- 4 tables (dict_group/dict_item/dict_group_default/dict_ref_count), delete_key soft-delete reuse
- DictGroup/DictItem full CRUD + force-delete + status toggle + enabled-list
- DictReferenceService: increment/decrement/batchApply/isReferenced, same-tx ref_count, no cache
- DictQueryService: Caffeine 10s cache + 2s negative cache for empty results, group.status join
- Default item: INSERT ON DUPLICATE KEY UPDATE, hibernate on group disable, auto-restore
- Permission seeds: 10 perm codes → sys_menu tree, bound to ROLE_ADMIN, no crm-auth import
- Built-in dict initializer: idempotent upsert, builtin=false never touched (US-41), value not overwritten
- 48 tests pass; full project compiles
1 month ago
|
|
|
package com.crm.dict.controller;
|
|
|
|
|
|
|
|
|
|
import com.crm.base.domain.result.PageResult;
|
|
|
|
|
import com.crm.base.domain.result.Result;
|
|
|
|
|
import com.crm.dict.constant.DictConstants;
|
|
|
|
|
import com.crm.dict.domain.dto.DictItemDTO;
|
feat(dict): data dictionary module — two-level flat model, CRUD/default/cache/permission/seed (ADR-0015)
- 4 tables (dict_group/dict_item/dict_group_default/dict_ref_count), delete_key soft-delete reuse
- DictGroup/DictItem full CRUD + force-delete + status toggle + enabled-list
- DictReferenceService: increment/decrement/batchApply/isReferenced, same-tx ref_count, no cache
- DictQueryService: Caffeine 10s cache + 2s negative cache for empty results, group.status join
- Default item: INSERT ON DUPLICATE KEY UPDATE, hibernate on group disable, auto-restore
- Permission seeds: 10 perm codes → sys_menu tree, bound to ROLE_ADMIN, no crm-auth import
- Built-in dict initializer: idempotent upsert, builtin=false never touched (US-41), value not overwritten
- 48 tests pass; full project compiles
1 month ago
|
|
|
import com.crm.dict.domain.param.ItemPageParam;
|
|
|
|
|
import com.crm.dict.service.DictQueryService;
|
|
|
|
|
import com.crm.dict.service.IDictItemService;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 字典项管理接口(薄适配层,只调 {@link IDictItemService} / {@link DictQueryService},不含业务逻辑)
|
|
|
|
|
*/
|
|
|
|
|
@Tag(name = "数据字典-字典项")
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/dict/item")
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class DictItemController {
|
|
|
|
|
|
|
|
|
|
private final IDictItemService dictItemService;
|
|
|
|
|
private final DictQueryService dictQueryService;
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "字典项分页(groupId/keyword/status 筛选,附带默认/引用/有效可选标记)")
|
|
|
|
|
@PreAuthorize("hasAuthority('" + DictConstants.PERM_ITEM_LIST + "')")
|
|
|
|
|
@PostMapping("/page")
|
|
|
|
|
public Result<PageResult<DictItemDTO>> page(ItemPageParam param) {
|
feat(dict): data dictionary module — two-level flat model, CRUD/default/cache/permission/seed (ADR-0015)
- 4 tables (dict_group/dict_item/dict_group_default/dict_ref_count), delete_key soft-delete reuse
- DictGroup/DictItem full CRUD + force-delete + status toggle + enabled-list
- DictReferenceService: increment/decrement/batchApply/isReferenced, same-tx ref_count, no cache
- DictQueryService: Caffeine 10s cache + 2s negative cache for empty results, group.status join
- Default item: INSERT ON DUPLICATE KEY UPDATE, hibernate on group disable, auto-restore
- Permission seeds: 10 perm codes → sys_menu tree, bound to ROLE_ADMIN, no crm-auth import
- Built-in dict initializer: idempotent upsert, builtin=false never touched (US-41), value not overwritten
- 48 tests pass; full project compiles
1 month ago
|
|
|
return Result.success(dictItemService.pageItems(param));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "新建/编辑字典项(新建编码空自动生成;分组/编码创建后只读;值被引用后只读)")
|
|
|
|
|
@PreAuthorize("hasAuthority('" + DictConstants.PERM_ITEM_SAVE + "')")
|
|
|
|
|
@PostMapping("/saveOrUpdate")
|
|
|
|
|
public Result<Void> saveOrUpdate(DictItemDTO dto) {
|
|
|
|
|
dictItemService.saveItem(dto);
|
feat(dict): data dictionary module — two-level flat model, CRUD/default/cache/permission/seed (ADR-0015)
- 4 tables (dict_group/dict_item/dict_group_default/dict_ref_count), delete_key soft-delete reuse
- DictGroup/DictItem full CRUD + force-delete + status toggle + enabled-list
- DictReferenceService: increment/decrement/batchApply/isReferenced, same-tx ref_count, no cache
- DictQueryService: Caffeine 10s cache + 2s negative cache for empty results, group.status join
- Default item: INSERT ON DUPLICATE KEY UPDATE, hibernate on group disable, auto-restore
- Permission seeds: 10 perm codes → sys_menu tree, bound to ROLE_ADMIN, no crm-auth import
- Built-in dict initializer: idempotent upsert, builtin=false never touched (US-41), value not overwritten
- 48 tests pass; full project compiles
1 month ago
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "删除字典项(内置或被引用则阻断)")
|
|
|
|
|
@PreAuthorize("hasAuthority('" + DictConstants.PERM_ITEM_DELETE + "')")
|
|
|
|
|
@PostMapping("/delete")
|
|
|
|
|
public Result<Void> delete(@RequestParam("id") Long id) {
|
|
|
|
|
dictItemService.deleteItem(id);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "强制删除字典项(绕过引用计数校验,计数飘高兜底入口)")
|
|
|
|
|
@PreAuthorize("hasAuthority('" + DictConstants.PERM_ITEM_FORCE_DELETE + "')")
|
|
|
|
|
@PostMapping("/force-delete")
|
|
|
|
|
public Result<Void> forceDelete(@RequestParam("id") Long id) {
|
|
|
|
|
dictItemService.forceDeleteItem(id);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "字典项启停(停用若为默认项则自动取消默认)")
|
|
|
|
|
@PreAuthorize("hasAuthority('" + DictConstants.PERM_ITEM_STATUS + "')")
|
|
|
|
|
@PostMapping("/status")
|
|
|
|
|
public Result<Void> status(@RequestParam("id") Long id, @RequestParam("status") Integer status) {
|
|
|
|
|
dictItemService.updateItemStatus(id, status);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "设为分组默认项(同事务自动取消同组原默认)")
|
|
|
|
|
@PreAuthorize("hasAuthority('" + DictConstants.PERM_ITEM_DEFAULT + "')")
|
|
|
|
|
@PostMapping("/set-default")
|
|
|
|
|
public Result<Void> setDefault(@RequestParam("groupId") Long groupId,
|
|
|
|
|
@RequestParam("itemId") Long itemId) {
|
|
|
|
|
dictItemService.setDefault(groupId, itemId);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "某分组启用项列表(业务选择器渲染用,走 10s 本地缓存)")
|
|
|
|
|
@PreAuthorize("hasAuthority('" + DictConstants.PERM_ITEM_LIST + "')")
|
|
|
|
|
@GetMapping("/enabled-list")
|
|
|
|
|
public Result<List<DictItemDTO>> enabledList(@RequestParam("groupCode") String groupCode) {
|
feat(dict): data dictionary module — two-level flat model, CRUD/default/cache/permission/seed (ADR-0015)
- 4 tables (dict_group/dict_item/dict_group_default/dict_ref_count), delete_key soft-delete reuse
- DictGroup/DictItem full CRUD + force-delete + status toggle + enabled-list
- DictReferenceService: increment/decrement/batchApply/isReferenced, same-tx ref_count, no cache
- DictQueryService: Caffeine 10s cache + 2s negative cache for empty results, group.status join
- Default item: INSERT ON DUPLICATE KEY UPDATE, hibernate on group disable, auto-restore
- Permission seeds: 10 perm codes → sys_menu tree, bound to ROLE_ADMIN, no crm-auth import
- Built-in dict initializer: idempotent upsert, builtin=false never touched (US-41), value not overwritten
- 48 tests pass; full project compiles
1 month ago
|
|
|
return Result.success(dictQueryService.listEnabledItems(groupCode));
|
|
|
|
|
}
|
|
|
|
|
}
|