-- phpMyAdmin SQL Dump
-- version 5.2.3
-- https://www.phpmyadmin.net/
--
-- Máy chủ: localhost:3306
-- Thời gian đã tạo: Th1 20, 2026 lúc 12:29 PM
-- Phiên bản máy phục vụ: 10.6.23-MariaDB
-- Phiên bản PHP: 8.3.27

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Cơ sở dữ liệu: `kienthuc_luathinhsu`
--

-- --------------------------------------------------------

--
-- Cấu trúc bảng cho bảng `documents`
--

CREATE TABLE `documents` (
  `document_id` int(11) NOT NULL,
  `document_title` varchar(500) NOT NULL,
  `document_number` varchar(100) DEFAULT NULL,
  `document_code` varchar(100) DEFAULT NULL,
  `category_id` int(11) DEFAULT NULL,
  `document_type` enum('van_ban_phap_luat','thong_tu','nghi_dinh','quyet_dinh','chi_thi','huong_dan','tai_lieu_tham_khao','bieu_mau','khac') NOT NULL DEFAULT 'tai_lieu_tham_khao',
  `file_name` varchar(255) NOT NULL,
  `original_file_name` varchar(500) NOT NULL,
  `file_path` varchar(500) NOT NULL,
  `file_url` varchar(1000) NOT NULL,
  `file_size` bigint(20) DEFAULT NULL COMMENT 'Kích thước file (bytes)',
  `file_format` varchar(50) DEFAULT NULL COMMENT 'pdf, doc, docx, xls, xlsx, etc.',
  `mime_type` varchar(100) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `keywords` varchar(500) DEFAULT NULL COMMENT 'Từ khóa tìm kiếm, phân cách bằng dấu phẩy',
  `summary` text DEFAULT NULL COMMENT 'Tóm tắt nội dung',
  `issuing_agency` varchar(255) DEFAULT NULL COMMENT 'Cơ quan ban hành',
  `issuing_date` date DEFAULT NULL COMMENT 'Ngày ban hành',
  `effective_date` date DEFAULT NULL COMMENT 'Ngày có hiệu lực',
  `expiry_date` date DEFAULT NULL COMMENT 'Ngày hết hiệu lực',
  `status` enum('draft','published','archived','deleted') DEFAULT 'published',
  `is_public` tinyint(1) DEFAULT 1 COMMENT 'Công khai hay riêng tư',
  `is_featured` tinyint(1) DEFAULT 0 COMMENT 'Tài liệu nổi bật',
  `display_order` int(11) DEFAULT 0,
  `view_count` int(11) DEFAULT 0,
  `download_count` int(11) DEFAULT 0,
  `uploaded_by` int(11) NOT NULL,
  `approved_by` int(11) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `published_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Bảng chính lưu trữ thông tin tài liệu pháp luật';

--
-- Đang đổ dữ liệu cho bảng `documents`
--

INSERT INTO `documents` (`document_id`, `document_title`, `document_number`, `document_code`, `category_id`, `document_type`, `file_name`, `original_file_name`, `file_path`, `file_url`, `file_size`, `file_format`, `mime_type`, `description`, `keywords`, `summary`, `issuing_agency`, `issuing_date`, `effective_date`, `expiry_date`, `status`, `is_public`, `is_featured`, `display_order`, `view_count`, `download_count`, `uploaded_by`, `approved_by`, `created_at`, `updated_at`, `published_at`) VALUES
(7, 'Nghị định 142 về quản lý vật chứng', NULL, NULL, 7, 'tai_lieu_tham_khao', '20260114_083009_13d57c95_142-ngh_________nh_qu___n_l___v___t_ch___ng.pdf', '142-nghị định quản lý vật chứng.pdf', 'uploads/documents/2026/01/20260114_083009_13d57c95_142-ngh_________nh_qu___n_l___v___t_ch___ng.pdf', 'https://www.kienthucxahoi.click/server_backend/uploads/documents/2026/01/20260114_083009_13d57c95_142-ngh_________nh_qu___n_l___v___t_ch___ng.pdf', 715740, 'pdf', 'application/pdf', 'Nghị Định', '', '', NULL, NULL, NULL, NULL, 'published', 1, 0, 7, 0, 0, 1, NULL, '2026-01-14 01:30:09', '2026-01-20 04:33:13', '2026-01-14 01:30:09'),
(8, 'hướng dẫn tham ô tài sản', NULL, NULL, 7, 'tai_lieu_tham_khao', '20260114_113843_7e305fe4_h_____ng_d___n_tham____t__i_s___n.pdf', 'hướng dẫn về tội tham ô tài sản.pdf', 'uploads/documents/2026/01/20260114_113843_7e305fe4_h_____ng_d___n_tham____t__i_s___n.pdf', 'https://www.kienthucxahoi.click/server_backend/uploads/documents/2026/01/20260114_113843_7e305fe4_h_____ng_d___n_tham____t__i_s___n.pdf', 997359, 'pdf', 'application/pdf', '', '', '', NULL, '2026-01-14', NULL, NULL, 'published', 1, 0, 8, 0, 0, 1, NULL, '2026-01-14 04:38:43', '2026-01-20 04:33:13', '2026-01-14 04:38:43'),
(9, 'Danh sách 77 xã ủy quyền mới_CAT Bắc Ninh', NULL, NULL, 4, 'tai_lieu_tham_khao', '20260114_121736_685a38fa_Danh_s__ch_77_x______y_quy___n_m___i_0001.pdf', 'Danh sách 77 xã ủy quyền mới_0001.pdf', 'uploads/documents/2026/01/20260114_121736_685a38fa_Danh_s__ch_77_x______y_quy___n_m___i_0001.pdf', 'https://www.kienthucxahoi.click/server_backend/uploads/documents/2026/01/20260114_121736_685a38fa_Danh_s__ch_77_x______y_quy___n_m___i_0001.pdf', 1368267, 'pdf', 'application/pdf', 'Sếp Bình ký', '', '', NULL, '2026-01-01', NULL, NULL, 'published', 1, 0, 9, 0, 0, 1, NULL, '2026-01-14 05:17:36', '2026-01-20 04:33:13', '2026-01-14 05:17:36'),
(10, 'Thong tu 09 quy định về xử lý án tai nan giao thông.pdf', NULL, NULL, 7, 'tai_lieu_tham_khao', '20260114_161856_1eb00f94_Thong_tu_09_quy_dinh_ve_xu_ly_an_tai_nan_giao_thong.pdf', 'Thong tu 09 quy dinh ve xu ly an tai nan giao thong.pdf', 'uploads/documents/2026/01/20260114_161856_1eb00f94_Thong_tu_09_quy_dinh_ve_xu_ly_an_tai_nan_giao_thong.pdf', 'https://www.kienthucxahoi.click/server_backend/uploads/documents/2026/01/20260114_161856_1eb00f94_Thong_tu_09_quy_dinh_ve_xu_ly_an_tai_nan_giao_thong.pdf', 447024, 'pdf', 'application/pdf', '', '', '', NULL, '2026-01-20', NULL, NULL, 'published', 1, 0, 10, 0, 0, 1, NULL, '2026-01-14 09:18:56', '2026-01-20 04:33:13', '2026-01-14 09:18:56'),
(11, 'CV số 01-TANDTC ngày 05-1-2026.pdf.pdf', NULL, NULL, 7, 'tai_lieu_tham_khao', '20260116_102208_8ec5a39c_CV_s____01-TANDTC_ng__y_05-1-2026_pdf.pdf', 'Hướng dẫn xử lý hành vi dùng dao sát thương cao xâm phạm thân thể và tội phạm liên quan đến thuốc lá điếu nhập lậu.', 'uploads/documents/2026/01/20260116_102208_8ec5a39c_CV_s____01-TANDTC_ng__y_05-1-2026_pdf.pdf', 'https://www.kienthucxahoi.click/server_backend/uploads/documents/2026/01/20260116_102208_8ec5a39c_CV_s____01-TANDTC_ng__y_05-1-2026_pdf.pdf', 1208629, 'pdf', 'application/pdf', '', '', '', NULL, '2026-01-01', NULL, NULL, 'published', 1, 0, 11, 0, 0, 1, NULL, '2026-01-16 03:22:08', '2026-01-20 04:33:13', '2026-01-16 03:22:08'),
(12, 'Danh bạ CATBN tạm thời', NULL, NULL, 7, 'tai_lieu_tham_khao', '20260120_095959_bd2aa5a9_Danh_b____CATBN_t___m_th___i.docx', 'Danh bạ CATBN tạm thời.docx', 'uploads/documents/2026/01/20260120_095959_bd2aa5a9_Danh_b____CATBN_t___m_th___i.docx', 'https://www.kienthucxahoi.click/server_backend/uploads/documents/2026/01/20260120_095959_bd2aa5a9_Danh_b____CATBN_t___m_th___i.docx', 182574, 'docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'Danh bạ điện thoại công an tỉnh', '', '', NULL, '2026-01-20', NULL, NULL, 'published', 1, 0, 12, 0, 0, 1, NULL, '2026-01-20 02:59:59', '2026-01-20 04:33:13', '2026-01-20 02:59:59'),
(13, 'phân biệt tố giác-tin báo', NULL, NULL, 7, 'tai_lieu_tham_khao', '20260120_102221_cd77130d_ph__n_bi___t_t____gi__c-tin_b__o.docx', 'phân biệt tố giác-tin báo.docx', 'uploads/documents/2026/01/20260120_102221_cd77130d_ph__n_bi___t_t____gi__c-tin_b__o.docx', 'https://www.kienthucxahoi.click/server_backend/uploads/documents/2026/01/20260120_102221_cd77130d_ph__n_bi___t_t____gi__c-tin_b__o.docx', 16496, 'docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', '', '', '', NULL, '2026-01-20', NULL, NULL, 'published', 1, 0, 13, 0, 0, 1, NULL, '2026-01-20 03:22:21', '2026-01-20 04:33:13', '2026-01-20 03:22:21'),
(14, 'các lỗi sai phạm  của công an cấp xã điển hình', NULL, NULL, 7, 'tai_lieu_tham_khao', '20260120_104003_0debd30c_c__c_l___i_sai_ph___m__c___a_c__ng_an_c___p_x_____i___n_h__nh.docx', 'các lỗi sai phạm  của công an cấp xã điển hình.docx', 'uploads/documents/2026/01/20260120_104003_0debd30c_c__c_l___i_sai_ph___m__c___a_c__ng_an_c___p_x_____i___n_h__nh.docx', 'https://www.kienthucxahoi.click/server_backend/uploads/documents/2026/01/20260120_104003_0debd30c_c__c_l___i_sai_ph___m__c___a_c__ng_an_c___p_x_____i___n_h__nh.docx', 15665, 'docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', '', '', '', NULL, '2026-01-20', NULL, NULL, 'published', 1, 0, 15, 0, 0, 1, NULL, '2026-01-20 03:40:03', '2026-01-20 05:28:08', '2026-01-20 03:40:03'),
(15, 'Mẫu 9 C16- HD Giấy đi đường 2025', NULL, NULL, 7, 'tai_lieu_tham_khao', '20260120_105058_546ab688_M___u_9_C16-_HD_Gi___y___i________ng_2025.doc', 'Mẫu 9 C16- HD Giấy đi đường 2025.doc', 'uploads/documents/2026/01/20260120_105058_546ab688_M___u_9_C16-_HD_Gi___y___i________ng_2025.doc', 'https://www.kienthucxahoi.click/server_backend/uploads/documents/2026/01/20260120_105058_546ab688_M___u_9_C16-_HD_Gi___y___i________ng_2025.doc', 54272, 'doc', 'application/msword', 'mẫu giấy đi đường', '', '', NULL, '2026-01-20', NULL, NULL, 'published', 1, 0, 14, 0, 0, 1, NULL, '2026-01-20 03:50:58', '2026-01-20 05:28:08', '2026-01-20 03:50:58'),
(16, 'giải đáp khó khăn trong vụ việc vụ án vũ khí vật liệu nổ và công cụ hỗ trợ.pdf_1.pdf', NULL, NULL, 7, 'tai_lieu_tham_khao', '20260120_110649_16e2585e_4442_C01_gi___i_____p_kh___kh__n_trong_v____vi___c_v______n_v___kh___v___t_li___u_n____v___c__ng_c____h____tr____pdf_1.pdf', 'Giải đáp khó khăn trong vụ việc vụ án vũ khí vật liệu nổ và công cụ hỗ trợ.pdf_1.pdf', 'uploads/documents/2026/01/20260120_110649_16e2585e_4442_C01_gi___i_____p_kh___kh__n_trong_v____vi___c_v______n_v___kh___v___t_li___u_n____v___c__ng_c____h____tr____pdf_1.pdf', 'https://www.kienthucxahoi.click/server_backend/uploads/documents/2026/01/20260120_110649_16e2585e_4442_C01_gi___i_____p_kh___kh__n_trong_v____vi___c_v______n_v___kh___v___t_li___u_n____v___c__ng_c____h____tr____pdf_1.pdf', 382787, 'pdf', 'application/pdf', '', '', '', NULL, '2026-01-20', NULL, NULL, 'published', 1, 0, 16, 0, 0, 1, NULL, '2026-01-20 04:06:49', '2026-01-20 05:27:02', '2026-01-20 04:06:49');

--
-- Chỉ mục cho các bảng đã đổ
--

--
-- Chỉ mục cho bảng `documents`
--
ALTER TABLE `documents`
  ADD PRIMARY KEY (`document_id`),
  ADD UNIQUE KEY `document_code` (`document_code`),
  ADD KEY `approved_by` (`approved_by`),
  ADD KEY `idx_document_code` (`document_code`),
  ADD KEY `idx_document_number` (`document_number`),
  ADD KEY `idx_category` (`category_id`),
  ADD KEY `idx_document_type` (`document_type`),
  ADD KEY `idx_status` (`status`),
  ADD KEY `idx_uploaded_by` (`uploaded_by`),
  ADD KEY `idx_created_at` (`created_at`),
  ADD KEY `idx_issuing_date` (`issuing_date`),
  ADD KEY `idx_status_public_created` (`status`,`is_public`,`created_at`),
  ADD KEY `idx_category_status` (`category_id`,`status`),
  ADD KEY `idx_display_order` (`display_order`);
ALTER TABLE `documents` ADD FULLTEXT KEY `idx_fulltext_search` (`document_title`,`description`,`keywords`,`summary`);

--
-- AUTO_INCREMENT cho các bảng đã đổ
--

--
-- AUTO_INCREMENT cho bảng `documents`
--
ALTER TABLE `documents`
  MODIFY `document_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;

--
-- Ràng buộc đối với các bảng kết xuất
--

--
-- Ràng buộc cho bảng `documents`
--
ALTER TABLE `documents`
  ADD CONSTRAINT `documents_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `document_categories` (`category_id`) ON DELETE SET NULL,
  ADD CONSTRAINT `documents_ibfk_2` FOREIGN KEY (`uploaded_by`) REFERENCES `users` (`user_id`) ON DELETE CASCADE,
  ADD CONSTRAINT `documents_ibfk_3` FOREIGN KEY (`approved_by`) REFERENCES `users` (`user_id`) ON DELETE SET NULL;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
