石油部门档案管理系统:从零搭建高可用数字档案库的实操指南

一、系统架构设计与技术选型

本系统采用前后端分离架构,后端使用Java Spring Boot,前端使用Vue.js,数据库选用PostgreSQL,文件存储使用MinIO。

1.1 环境要求清单

  • 操作系统:CentOS 7.9 或 Ubuntu 20.04 LTS
  • Java:JDK 11
  • Node.js:16.x
  • PostgreSQL:13.x
  • MinIO:RELEASE.2023-08-29T23-07-35Z

1.2 硬件配置建议

生产环境建议配置:

  • CPU:4核8线程以上
  • 内存:16GB以上
  • 存储:SSD 500GB + HDD 2TB(用于档案文件存储)
  • 带宽:100Mbps专线

二、环境搭建与配置

2.1 基础环境安装

执行以下命令安装必要组件:

 更新系统
sudo yum update -y   CentOS
sudo apt update && sudo apt upgrade -y   Ubuntu
安装JDK 11
sudo yum install java-11-openjdk-devel -y
sudo apt install openjdk-11-jdk -y
安装Node.js
curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -
sudo yum install nodejs -y
安装PostgreSQL
sudo yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y
sudo yum install postgresql13-server postgresql13-contrib -y
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13

2.2 MinIO对象存储安装

 下载并安装MinIO
wget https://dl.min.io/server/minio/release/linux-amd64/minio
chmod +x minio
sudo mv minio /usr/local/bin/
创建数据目录
sudo mkdir -p /data/minio
sudo chmod -R 775 /data/minio
创建MinIO服务文件
sudo vi /etc/systemd/system/minio.service

minio.service文件内容:

[Unit]
Description=MinIO
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/minio server /data/minio --console-address ":9001"
Restart=on-failure
[Install]
WantedBy=multi-user.target

启动服务:

石油部门档案管理系统:从零搭建高可用数字档案库的实操指南

sudo systemctl daemon-reload
sudo systemctl enable minio
sudo systemctl start minio

三、数据库设计与初始化

3.1 创建数据库和用户

 切换到postgres用户
sudo -i -u postgres
psql
创建数据库和用户
CREATE DATABASE oil_archive;
CREATE USER archive_user WITH PASSWORD 'Archive@2023';
GRANT ALL PRIVILEGES ON DATABASE oil_archive TO archive_user;

3.2 核心表结构设计

-- 档案分类表
CREATE TABLE archive_category (
id SERIAL PRIMARY KEY,
category_code VARCHAR(50) NOT NULL UNIQUE,
category_name VARCHAR(100) NOT NULL,
parent_id INTEGER REFERENCES archive_category(id),
security_level INTEGER DEFAULT 1,
retention_years INTEGER NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 档案文件表
CREATE TABLE archive_file (
id SERIAL PRIMARY KEY,
file_code VARCHAR(100) NOT NULL UNIQUE,
file_name VARCHAR(255) NOT NULL,
original_name VARCHAR(255) NOT NULL,
category_id INTEGER REFERENCES archive_category(id),
file_size BIGINT NOT NULL,
file_type VARCHAR(50),
storage_path VARCHAR(500) NOT NULL,
security_level INTEGER DEFAULT 1,
upload_user_id INTEGER NOT NULL,
upload_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
expire_date DATE,
metadata JSONB
);
-- 档案借阅记录表
CREATE TABLE archive_borrow (
id SERIAL PRIMARY KEY,
file_id INTEGER REFERENCES archive_file(id),
borrower_id INTEGER NOT NULL,
borrow_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
expected_return DATE NOT NULL,
actual_return TIMESTAMP,
borrow_purpose TEXT,
status VARCHAR(20) DEFAULT 'BORROWED'
);
-- 创建索引
CREATE INDEX idx_file_category ON archive_file(category_id);
CREATE INDEX idx_file_security ON archive_file(security_level);
CREATE INDEX idx_borrow_status ON archive_borrow(status);
CREATE INDEX idx_file_expire ON archive_file(expire_date);

四、后端系统开发

4.1 Spring Boot项目初始化

 使用Spring Initializr创建项目
curl https://start.spring.io/starter.zip \
-d type=maven-project \
-d language=java \
-d bootVersion=2.7.14 \
-d baseDir=oil-archive-backend \
-d groupId=com.oil.archive \
-d artifactId=backend \
-d name=OilArchiveBackend \
-d dependencies=web,data-jpa,postgresql,validation,security \
-o oil-archive-backend.zip
解压并进入项目目录
unzip oil-archive-backend.zip
cd oil-archive-backend

4.2 关键配置文件

application.yml配置:

server:
port: 8080
servlet:
context-path: /api
spring:
datasource:
url: jdbc:postgresql://localhost:5432/oil_archive
username: archive_user
password: Archive@2023
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: true
servlet:
multipart:
max-file-size: 2GB
max-request-size: 2GB
minio:
endpoint: http://localhost:9000
accessKey: minioadmin
secretKey: minioadmin
bucket: oil-archive

4.3 核心业务代码实现

文件上传服务类:

@Service
public class FileStorageService {
@Value("${minio.endpoint}")
private String endpoint;
@Value("${minio.accessKey}")
private String accessKey;
@Value("${minio.secretKey}")
private String secretKey;
@Value("${minio.bucket}")
private String bucket;
private MinioClient minioClient;
@PostConstruct
public void init() throws Exception {
minioClient = MinioClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey)
.build();
boolean found = minioClient.bucketExists(
BucketExistsArgs.builder().bucket(bucket).build());
if (!found) {
minioClient.makeBucket(
MakeBucketArgs.builder().bucket(bucket).build());
}
}
public String uploadFile(MultipartFile file, String category)
throws Exception {
String fileName = generateFileName(file.getOriginalFilename());
String objectName = category + "/" + fileName;
minioClient.putObject(
PutObjectArgs.builder()
.bucket(bucket)
.object(objectName)
.stream(file.getInputStream(), file.getSize(), -1)
.contentType(file.getContentType())
.build());
return objectName;
}
private String generateFileName(String originalFileName) {
String extension = originalFileName.substring(
originalFileName.lastIndexOf("."));
return UUID.randomUUID().toString() + extension;
}
}

五、前端系统开发

5.1 Vue项目初始化

 创建Vue项目
npm init vue@latest oil-archive-frontend
cd oil-archive-frontend
npm install
安装必要依赖
npm install axios element-plus vue-router@4 vuex@4
npm install @element-plus/icons-vue

5.2 文件上传组件实现


六、系统部署与运维

6.1 Nginx反向代理配置

 /etc/nginx/conf.d/archive.conf
upstream backend {
server 127.0.0.1:8080;
}
upstream minio_console {
server 127.0.0.1:9001;
}
server {
listen 80;
server_name archive.oil-company.com;
前端静态文件
location / {
root /var/www/oil-archive-frontend/dist;
index index.html;
try_files $uri $uri/ /index.html;
}
后端API代理
location /api/ {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
MinIO控制台
location /minio/ {
proxy_pass http://minio_console;
proxy_set_header Host $host;
}
}

6.2 系统启动脚本

创建启动脚本 start.sh:

!/bin/bash
启动PostgreSQL
sudo systemctl start postgresql-13
启动MinIO
sudo systemctl start minio
启动后端服务
cd /opt/oil-archive-backend
nohup java -jar target/backend-0.0.1-SNAPSHOT.jar \
--spring.profiles.active=prod > backend.log 2>&1 &
启动Nginx
sudo systemctl start nginx
echo "系统启动完成"
echo "前端访问:http://archive.oil-company.com"
echo "MinIO控制台:http://archive.oil-company.com/minio"

6.3 数据备份策略

创建备份脚本 backup.sh:

!/bin/bash
BACKUP_DIR="/backup/archive"
DATE=$(date +%Y%m%d_%H%M%S)
备份数据库
pg_dump -U archive_user -d oil_archive \
-f $BACKUP_DIR/db_backup_$DATE.sql
备份MinIO数据
mc mirror --overwrite /data/minio \
$BACKUP_DIR/minio_backup_$DATE/
保留最近7天的备份
find $BACKUP_DIR -type f -mtime +7 -delete
find $BACKUP_DIR -type d -mtime +7 -exec rm -rf {} \;

添加到crontab每日自动备份:

0 2    /opt/scripts/backup.sh

七、安全配置与权限管理

7.1 Spring Security配置

@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/api/auth/").permitAll()
.antMatchers("/api/files/download/").permitAll()
.antMatchers("/api/admin/").hasRole("ADMIN")
.antMatchers("/api/files/upload").hasAnyRole("USER", "ADMIN")
.anyRequest().authenticated()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.addFilterBefore(jwtFilter(),
UsernamePasswordAuthenticationFilter.class);
return http.build();
}
@Bean
public JwtAuthenticationFilter jwtFilter() {
return new JwtAuthenticationFilter();
}
}

7.2 文件访问权限控制

@Service
public class FileAccessService {
@Autowired
private ArchiveFileRepository fileRepository;
public boolean checkFileAccess(Integer userId, Integer fileId) {
ArchiveFile file = fileRepository.findById(fileId).orElse(null);
if (file == null) return false;
// 获取用户权限级别
User user = userRepository.findById(userId).orElse(null);
if (user == null) return false;
// 检查权限级别
return user.getSecurityLevel() >= file.getSecurityLevel();
}
public String generateSecureDownloadUrl(Integer fileId, Integer userId) {
if (!checkFileAccess(userId, fileId)) {
throw new AccessDeniedException("无权访问该文件");
}
ArchiveFile file = fileRepository.findById(fileId).get();
// 生成带签名的MinIO下载链接(7天有效)
return minioClient.getPresignedObjectUrl(
GetPresignedObjectUrlArgs.builder()
.method(Method.GET)
.bucket(bucket)
.object(file.getStoragePath())
.expiry(7  24  60  60)  // 7天
.build());
}
}

八、系统监控与维护

8.1 健康检查接口

@RestController
@RequestMapping("/api/health")
public class HealthController {
@Autowired
private DataSource dataSource;
@GetMapping
public ResponseEntity> healthCheck() {
Map health = new HashMap<>();
// 检查数据库连接
try (Connection conn = dataSource.getConnection()) {
health.put("database", "UP");
} catch (Exception e) {
health.put("database", "DOWN");
}
// 检查MinIO连接
try {
minioClient.listBuckets();
health.put("minio", "UP");
} catch (Exception e) {
health.put("minio", "DOWN");
}
// 系统信息
health.put("timestamp", System.currentTimeMillis());
health.put("version", "1.0.0");
return ResponseEntity.ok(health);
}
}

            
            


            
            
        
AI咨询
热线电话

028-85154420

15388110056

全国售前咨询电话

扫码咨询
安答联动微信公众号二维码

微信扫码关注安答联动

申请试用
热线电话
申请试用

安答联动档案管理系统