diff --git a/urbanLifelineServ/.bin/database/postgres/sql/createTableFile.sql b/urbanLifelineServ/.bin/database/postgres/sql/createTableFile.sql index 96443952..d308c57d 100644 --- a/urbanLifelineServ/.bin/database/postgres/sql/createTableFile.sql +++ b/urbanLifelineServ/.bin/database/postgres/sql/createTableFile.sql @@ -2,48 +2,77 @@ CREATE SCHEMA IF NOT EXISTS file; DROP TABLE IF EXISTS file.tb_sys_file CASCADE; CREATE TABLE file.tb_sys_file ( - optsn VARCHAR(50) NOT NULL, -- 流水号 - file_id VARCHAR(50) NOT NULL, -- 文件ID - name VARCHAR(255) NOT NULL, -- 文件名 - path VARCHAR(255) NOT NULL, -- 文件路径 - size BIGINT NOT NULL, -- 文件大小 - type VARCHAR(50) NOT NULL, -- 文件类型 - storage_type VARCHAR(50) NOT NULL, -- 存储类型 - mime_type VARCHAR(255) NOT NULL, -- 文件MIME类型 - url VARCHAR(255) NOT NULL, -- 文件URL - status VARCHAR(50) NOT NULL, -- 文件状态 - service_type VARCHAR(50), -- 服务类型(bidding/customer_service/internal等) - dept_path VARCHAR(255) NOT NULL, -- 当前部门路径 - creator VARCHAR(50) DEFAULT NULL, -- 创建者 - updater VARCHAR(50) DEFAULT NULL, -- 更新者 + -- BaseDTO 继承字段 + optsn VARCHAR(50) NOT NULL, -- 操作流水号 + creator VARCHAR(50) DEFAULT NULL, -- 创建人 + updater VARCHAR(50) DEFAULT NULL, -- 更新人 + dept_path VARCHAR(255) DEFAULT NULL, -- 部门路径 + remark TEXT DEFAULT NULL, -- 备注 create_time TIMESTAMPTZ NOT NULL DEFAULT now(), -- 创建时间 - update_time TIMESTAMPTZ DEFAULT NULL, -- 更新时间(由触发器维护) + update_time TIMESTAMPTZ DEFAULT NULL, -- 更新时间 delete_time TIMESTAMPTZ DEFAULT NULL, -- 删除时间 - deleted BOOLEAN NOT NULL DEFAULT false, -- 是否删除 + deleted INTEGER NOT NULL DEFAULT 0, -- 是否已删除(0-未删除,1-已删除) + + -- TbSysFileDTO 特有字段 + file_id VARCHAR(50) NOT NULL, -- 文件ID (主键) + name VARCHAR(255) NOT NULL, -- 文件名 + path VARCHAR(500) NOT NULL, -- 文件路径 + size BIGINT NOT NULL, -- 文件大小(字节) + type VARCHAR(50) DEFAULT NULL, -- 文件类型 + storage_type VARCHAR(50) DEFAULT NULL, -- 存储类型 + mime_type VARCHAR(255) DEFAULT NULL, -- MIME 类型 + url VARCHAR(500) DEFAULT NULL, -- 文件访问 URL + status VARCHAR(50) DEFAULT NULL, -- 文件状态 + module VARCHAR(100) DEFAULT NULL, -- 所属模块 + business_id VARCHAR(50) DEFAULT NULL, -- 业务ID + uploader VARCHAR(50) DEFAULT NULL, -- 上传者用户ID + object_name VARCHAR(500) DEFAULT NULL, -- MinIO对象名称 + bucket_name VARCHAR(100) DEFAULT NULL, -- MinIO存储桶名称 + md5_hash VARCHAR(32) DEFAULT NULL, -- 文件MD5值 + extension VARCHAR(20) DEFAULT NULL, -- 文件扩展名 + PRIMARY KEY (file_id), UNIQUE (optsn) ); -CREATE INDEX idx_file_service ON file.tb_sys_file(service_type) WHERE deleted = false; -COMMENT ON TABLE file.tb_sys_file IS '文件表'; -COMMENT ON COLUMN file.tb_sys_file.service_type IS '服务类型(用于服务间数据隔离)'; -COMMENT ON COLUMN file.tb_sys_file.optsn IS '流水号'; -COMMENT ON COLUMN file.tb_sys_file.file_id IS '文件ID'; -COMMENT ON COLUMN file.tb_sys_file.name IS '文件名'; -COMMENT ON COLUMN file.tb_sys_file.path IS '文件路径'; -COMMENT ON COLUMN file.tb_sys_file.size IS '文件大小'; -COMMENT ON COLUMN file.tb_sys_file.type IS '文件类型'; -COMMENT ON COLUMN file.tb_sys_file.storage_type IS '存储类型'; -COMMENT ON COLUMN file.tb_sys_file.mime_type IS '文件MIME类型'; -COMMENT ON COLUMN file.tb_sys_file.url IS '文件URL'; -COMMENT ON COLUMN file.tb_sys_file.status IS '文件状态'; -COMMENT ON COLUMN file.tb_sys_file.dept_path IS '当前部门路径'; -COMMENT ON COLUMN file.tb_sys_file.creator IS '创建者'; -COMMENT ON COLUMN file.tb_sys_file.updater IS '更新者'; +COMMENT ON TABLE file.tb_sys_file IS '系统文件表'; + +-- BaseDTO 继承字段注释 +COMMENT ON COLUMN file.tb_sys_file.optsn IS '操作流水号'; +COMMENT ON COLUMN file.tb_sys_file.creator IS '创建人'; +COMMENT ON COLUMN file.tb_sys_file.updater IS '更新人'; +COMMENT ON COLUMN file.tb_sys_file.dept_path IS '部门路径'; +COMMENT ON COLUMN file.tb_sys_file.remark IS '备注'; COMMENT ON COLUMN file.tb_sys_file.create_time IS '创建时间'; COMMENT ON COLUMN file.tb_sys_file.update_time IS '更新时间'; COMMENT ON COLUMN file.tb_sys_file.delete_time IS '删除时间'; -COMMENT ON COLUMN file.tb_sys_file.deleted IS '是否删除'; +COMMENT ON COLUMN file.tb_sys_file.deleted IS '是否已删除(0-未删除,1-已删除)'; + +-- TbSysFileDTO 特有字段注释 +COMMENT ON COLUMN file.tb_sys_file.file_id IS '文件ID (主键)'; +COMMENT ON COLUMN file.tb_sys_file.name IS '文件名'; +COMMENT ON COLUMN file.tb_sys_file.path IS '文件路径'; +COMMENT ON COLUMN file.tb_sys_file.size IS '文件大小(字节)'; +COMMENT ON COLUMN file.tb_sys_file.type IS '文件类型'; +COMMENT ON COLUMN file.tb_sys_file.storage_type IS '存储类型'; +COMMENT ON COLUMN file.tb_sys_file.mime_type IS 'MIME 类型'; +COMMENT ON COLUMN file.tb_sys_file.url IS '文件访问 URL'; +COMMENT ON COLUMN file.tb_sys_file.status IS '文件状态'; +COMMENT ON COLUMN file.tb_sys_file.module IS '所属模块'; +COMMENT ON COLUMN file.tb_sys_file.business_id IS '业务ID'; +COMMENT ON COLUMN file.tb_sys_file.uploader IS '上传者用户ID'; +COMMENT ON COLUMN file.tb_sys_file.object_name IS 'MinIO对象名称'; +COMMENT ON COLUMN file.tb_sys_file.bucket_name IS 'MinIO存储桶名称'; +COMMENT ON COLUMN file.tb_sys_file.md5_hash IS '文件MD5值'; +COMMENT ON COLUMN file.tb_sys_file.extension IS '文件扩展名'; + +-- 文件表索引 +CREATE INDEX idx_file_module_business ON file.tb_sys_file(module, business_id) WHERE deleted = 0; +CREATE INDEX idx_file_uploader ON file.tb_sys_file(uploader) WHERE deleted = 0; +CREATE INDEX idx_file_bucket ON file.tb_sys_file(bucket_name) WHERE deleted = 0; +CREATE INDEX idx_file_status ON file.tb_sys_file(status) WHERE deleted = 0; +CREATE INDEX idx_file_create_time ON file.tb_sys_file(create_time) WHERE deleted = 0; +CREATE INDEX idx_file_md5 ON file.tb_sys_file(md5_hash) WHERE deleted = 0; -- ============================= -- 文件关联表 @@ -85,6 +114,7 @@ COMMENT ON COLUMN file.tb_file_relation.update_time IS '更新时间'; COMMENT ON COLUMN file.tb_file_relation.delete_time IS '删除时间'; COMMENT ON COLUMN file.tb_file_relation.deleted IS '是否删除'; +-- 文件关联表索引 CREATE INDEX idx_file_relation_object ON file.tb_file_relation(object_type, object_id) WHERE deleted = false; CREATE INDEX idx_file_relation_file ON file.tb_file_relation(file_id) WHERE deleted = false; CREATE INDEX idx_file_relation_service ON file.tb_file_relation(service_type) WHERE deleted = false; \ No newline at end of file diff --git a/urbanLifelineServ/.bin/database/postgres/sql/initDataConfig.sql b/urbanLifelineServ/.bin/database/postgres/sql/initDataConfig.sql index 38f01506..48963205 100644 --- a/urbanLifelineServ/.bin/database/postgres/sql/initDataConfig.sql +++ b/urbanLifelineServ/.bin/database/postgres/sql/initDataConfig.sql @@ -24,9 +24,25 @@ INSERT INTO config.tb_sys_config ( -- 存储与上传 ('CFG-0301', 'cfg_upload_max', 'upload.maxSizeMB', '最大上传大小', '50', 'INTEGER', 'input', '单文件最大上传(MB)', NULL, NULL, 'storage', 'mod_file', 10, 0, '前后端需一致校验', 'system', NULL, NULL, now(), NULL, NULL, false), -('CFG-0302', 'cfg_storage_backend', 'storage.backend', '存储后端', 'local', 'String', 'select', '存储后端类型', NULL, '["local", "minio", "s3"]'::json, 'storage', 'mod_file', 20, 0, '本地/MinIO/S3等', 'system', NULL, NULL, now(), NULL, NULL, false), +('CFG-0302', 'cfg_storage_backend', 'storage.backend', '存储后端', 'minio', 'String', 'select', '存储后端类型', NULL, '["local", "minio", "s3"]'::json, 'storage', 'mod_file', 20, 0, '本地/MinIO/S3等,当前默认MinIO', 'system', NULL, NULL, now(), NULL, NULL, false), ('CFG-0303', 'cfg_storage_base', 'storage.basePath', '存储路径', '/data/urban-lifeline', 'String', 'input', '本地存储基路径', NULL, NULL, 'storage', 'mod_file', 30, 0, '当 backend=local', 'system', NULL, NULL, now(), NULL, NULL, false), +-- MinIO 对象存储配置 +('CFG-0310', 'cfg_minio_endpoint', 'minio.endpoint', 'MinIO服务端点', 'http://localhost:9000', 'String', 'input', 'MinIO服务器地址', NULL, NULL, 'storage', 'mod_file', 40, 0, 'MinIO API服务地址,如 http://localhost:9000', 'system', NULL, NULL, now(), NULL, NULL, false), +('CFG-0311', 'cfg_minio_accesskey', 'minio.accessKey', 'MinIO访问密钥', 'minioadmin', 'String', 'input', 'MinIO AccessKey', NULL, NULL, 'storage', 'mod_file', 50, 0, 'MinIO认证的AccessKey', 'system', NULL, NULL, now(), NULL, NULL, false), +('CFG-0312', 'cfg_minio_secretkey', 'minio.secretKey', 'MinIO私钥', 'minioadmin123', 'String', 'password', 'MinIO SecretKey', NULL, NULL, 'storage', 'mod_file', 60, 0, 'MinIO认证的SecretKey', 'system', NULL, NULL, now(), NULL, NULL, false), +('CFG-0313', 'cfg_minio_bucket', 'minio.bucketName', 'MinIO存储桶', 'urban-lifeline', 'String', 'input', 'MinIO默认存储桶名称', NULL, NULL, 'storage', 'mod_file', 70, 0, '用于存储文件的默认bucket', 'system', NULL, NULL, now(), NULL, NULL, false), +('CFG-0314', 'cfg_minio_publicurl', 'minio.publicUrl', 'MinIO公网地址', 'http://localhost:9000', 'String', 'input', 'MinIO公网访问地址', NULL, NULL, 'storage', 'mod_file', 80, 0, '用于生成文件访问URL,可与endpoint不同', 'system', NULL, NULL, now(), NULL, NULL, false), +('CFG-0315', 'cfg_minio_ssl', 'minio.ssl.enabled', '启用SSL', 'false', 'BOOLEAN', 'switch', '是否启用SSL连接', NULL, NULL, 'storage', 'mod_file', 90, 0, 'HTTPS连接MinIO服务', 'system', NULL, NULL, now(), NULL, NULL, false), +('CFG-0316', 'cfg_minio_region', 'minio.region', 'MinIO区域', 'us-east-1', 'String', 'input', 'MinIO存储区域', NULL, NULL, 'storage', 'mod_file', 100, 0, 'AWS S3兼容的区域配置', 'system', NULL, NULL, now(), NULL, NULL, false), + +-- 文件管理配置 +('CFG-0320', 'cfg_file_allowed_exts','file.allowedExtensions', '允许的文件扩展名', 'jpg,jpeg,png,gif,pdf,doc,docx,xls,xlsx,ppt,pptx,txt,zip,rar', 'String', 'textarea', '允许上传的文件扩展名', NULL, NULL, 'storage', 'mod_file', 110, 0, '逗号分隔,如 jpg,png,pdf', 'system', NULL, NULL, now(), NULL, NULL, false), +('CFG-0321', 'cfg_file_forbidden_exts','file.forbiddenExtensions','禁止的文件扩展名', 'exe,bat,sh,php,jsp,asp', 'String', 'textarea', '禁止上传的文件扩展名', NULL, NULL, 'storage', 'mod_file', 120, 0, '逗号分隔,安全考虑', 'system', NULL, NULL, now(), NULL, NULL, false), +('CFG-0322', 'cfg_file_cleanup_days', 'file.tempCleanupDays', '临时文件清理天数', '7', 'INTEGER', 'input', '临时文件自动清理天数', NULL, NULL, 'storage', 'mod_file', 130, 0, '超过天数的临时文件将被清理', 'system', NULL, NULL, now(), NULL, NULL, false), +('CFG-0323', 'cfg_file_duplicate_check','file.duplicateCheck.enabled','启用文件去重', 'true', 'BOOLEAN', 'switch', '是否启用MD5去重检查', NULL, NULL, 'storage', 'mod_file', 140, 0, '基于MD5值检查重复文件', 'system', NULL, NULL, now(), NULL, NULL, false), +('CFG-0324', 'cfg_file_virus_scan', 'file.virusScan.enabled', '启用病毒扫描', 'false', 'BOOLEAN', 'switch', '是否启用文件病毒扫描', NULL, NULL, 'storage', 'mod_file', 150, 0, '需要集成防病毒引擎', 'system', NULL, NULL, now(), NULL, NULL, false), + -- 通知(邮件/SMS) -- 邮件配置 ('CFG-0401', 'cfg_mail_host', 'email.host', 'SMTP服务器地址', 'smtp.qq.com', 'String', 'input', 'SMTP服务器地址', NULL, NULL, 'notify', 'mod_message', 10, 1, '邮件发送服务器地址', 'system', NULL, NULL, now(), NULL, NULL, false), diff --git a/urbanLifelineServ/.bin/docker/docker-compose.yml b/urbanLifelineServ/.bin/docker/docker-compose.yml index 2dd32bc4..7ab5447b 100644 --- a/urbanLifelineServ/.bin/docker/docker-compose.yml +++ b/urbanLifelineServ/.bin/docker/docker-compose.yml @@ -60,3 +60,38 @@ services: # Linux 需要添加 extra_hosts 来访问主机服务 extra_hosts: - "host.docker.internal:host-gateway" + + minio: + image: minio/minio:latest + container_name: urban-lifeline-minio + restart: unless-stopped + networks: + - urban-lifeline + ports: + - "9000:9000" # MinIO API 端口 + - "9001:9001" # MinIO Console (Web UI) 端口 + environment: + # 管理员账户配置 + MINIO_ROOT_USER: minioadmin + MINIO_ROOT_PASSWORD: minioadmin123 + + # Console 地址配置 + MINIO_CONSOLE_ADDRESS: ":9001" + MINIO_ADDRESS: ":9000" + + # 时区设置 + TZ: Asia/Shanghai + + volumes: + # 数据持久化到主机目录 + - ../../.data/docker/minio/data:/data + - ../../.data/docker/minio/config:/root/.minio + + command: server /data --console-address ":9001" + + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] + interval: 30s + timeout: 20s + retries: 3 + start_period: 30s diff --git a/urbanLifelineServ/.vscode/launch.json b/urbanLifelineServ/.vscode/launch.json index 731f71c3..756c8bcb 100644 --- a/urbanLifelineServ/.vscode/launch.json +++ b/urbanLifelineServ/.vscode/launch.json @@ -144,14 +144,14 @@ "Gateway (8180)", "Auth (8181)", "System (8182)", - "Log (8183)", + // "Log (8183)", "File (8184)", - "Message (8185)", - "Bidding (8186)", - "Platform (8187)", - "Workcase (8188)", - "Crontab (8189)", - "Agent (8190)" + // "Message (8185)", + // "Bidding (8186)", + // "Platform (8187)", + // "Workcase (8188)", + // "Crontab (8189)", + // "Agent (8190)" ], "stopAll": true, "presentation": { diff --git a/urbanLifelineServ/.windsurf/rules/urbanlife.md b/urbanLifelineServ/.windsurf/rules/urbanlife.md new file mode 100644 index 00000000..3c0148e1 --- /dev/null +++ b/urbanLifelineServ/.windsurf/rules/urbanlife.md @@ -0,0 +1,6 @@ +--- +trigger: manual +--- + +1. 有BaseDTO基类,DTO\VO在api模块下面 +2. 用Dubbo注册和,引用服务 \ No newline at end of file diff --git a/urbanLifelineServ/apis/api-file/src/main/java/org/xyzh/api/file/dto/TbSysFileDTO.java b/urbanLifelineServ/apis/api-file/src/main/java/org/xyzh/api/file/dto/TbSysFileDTO.java index 07d9746b..3b3c47ce 100644 --- a/urbanLifelineServ/apis/api-file/src/main/java/org/xyzh/api/file/dto/TbSysFileDTO.java +++ b/urbanLifelineServ/apis/api-file/src/main/java/org/xyzh/api/file/dto/TbSysFileDTO.java @@ -46,4 +46,25 @@ public class TbSysFileDTO extends BaseDTO { @Schema(description = "文件状态") private String status; + @Schema(description = "所属模块") + private String module; + + @Schema(description = "业务ID") + private String businessId; + + @Schema(description = "上传者用户ID") + private String uploader; + + @Schema(description = "MinIO对象名称") + private String objectName; + + @Schema(description = "MinIO存储桶名称") + private String bucketName; + + @Schema(description = "文件MD5值") + private String md5Hash; + + @Schema(description = "文件扩展名") + private String extension; + } diff --git a/urbanLifelineServ/common/common-utils/src/main/java/org/xyzh/common/utils/json/FastJson2TypeHandler.java b/urbanLifelineServ/common/common-utils/src/main/java/org/xyzh/common/utils/json/FastJson2TypeHandler.java new file mode 100644 index 00000000..70801d89 --- /dev/null +++ b/urbanLifelineServ/common/common-utils/src/main/java/org/xyzh/common/utils/json/FastJson2TypeHandler.java @@ -0,0 +1,58 @@ +package org.xyzh.common.utils.json; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedTypes; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * @description FastJSON2 JSONObject 类型处理器 + * @filename FastJson2TypeHandler.java + * @author yslg + * @copyright yslg + * @since 2025-12-09 + */ +@MappedTypes({JSONObject.class}) +public class FastJson2TypeHandler extends BaseTypeHandler { + + @Override + public void setNonNullParameter(PreparedStatement ps, int i, JSONObject parameter, JdbcType jdbcType) throws SQLException { + ps.setString(i, parameter.toJSONString()); + } + + @Override + public JSONObject getNullableResult(ResultSet rs, String columnName) throws SQLException { + String jsonString = rs.getString(columnName); + return parseToJSONObject(jsonString); + } + + @Override + public JSONObject getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + String jsonString = rs.getString(columnIndex); + return parseToJSONObject(jsonString); + } + + @Override + public JSONObject getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + String jsonString = cs.getString(columnIndex); + return parseToJSONObject(jsonString); + } + + private JSONObject parseToJSONObject(String jsonString) { + if (jsonString == null || jsonString.trim().isEmpty()) { + return null; + } + try { + return JSON.parseObject(jsonString); + } catch (Exception e) { + // 如果解析失败,返回一个空的JSONObject + return new JSONObject(); + } + } +} diff --git a/urbanLifelineServ/file/pom.xml b/urbanLifelineServ/file/pom.xml index 5a192a99..368c526a 100644 --- a/urbanLifelineServ/file/pom.xml +++ b/urbanLifelineServ/file/pom.xml @@ -29,6 +29,10 @@ org.xyzh.apis api-file + + org.xyzh.apis + api-system + diff --git a/urbanLifelineServ/file/src/main/java/org/xyzh/file/config/MinioConfig.java b/urbanLifelineServ/file/src/main/java/org/xyzh/file/config/MinioConfig.java new file mode 100644 index 00000000..5e9499aa --- /dev/null +++ b/urbanLifelineServ/file/src/main/java/org/xyzh/file/config/MinioConfig.java @@ -0,0 +1,145 @@ +package org.xyzh.file.config; + +import io.minio.MinioClient; +import lombok.Data; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.xyzh.api.system.service.SysConfigService; + +import org.apache.dubbo.config.annotation.DubboReference; +import jakarta.annotation.PostConstruct; + +/** + * @description MinIO 配置类,从数据库读取配置信息 + * @filename MinioConfig.java + * @author yslg + * @copyright yslg + * @since 2025-12-09 + */ +@Data +@Component +public class MinioConfig { + + private static final Logger logger = LoggerFactory.getLogger(MinioConfig.class); + + @DubboReference(version = "1.0.0", group = "system", timeout = 3000, retries = 0) + private SysConfigService sysConfigService; + + // MinIO 配置项的键名 + private static final String MINIO_ENDPOINT_KEY = "minio.endpoint"; + private static final String MINIO_ACCESS_KEY = "minio.accessKey"; + private static final String MINIO_SECRET_KEY = "minio.secretKey"; + private static final String MINIO_BUCKET_NAME_KEY = "minio.bucketName"; + private static final String MINIO_PUBLIC_URL_KEY = "minio.publicUrl"; + + // 默认值 + private static final String DEFAULT_ENDPOINT = "http://localhost:9000"; + private static final String DEFAULT_ACCESS_KEY = "minioadmin"; + private static final String DEFAULT_SECRET_KEY = "minioadmin123"; + private static final String DEFAULT_BUCKET_NAME = "urban-lifeline"; + private static final String DEFAULT_PUBLIC_URL = "http://localhost:9000"; + + // 配置属性 + private String endpoint; + private String accessKey; + private String secretKey; + private String bucketName; + private String publicUrl; + + private MinioClient minioClient; + + @PostConstruct + public void init() { + loadConfig(); + initClient(); + } + + /** + * 从数据库加载MinIO配置 + */ + private void loadConfig() { + try { + endpoint = sysConfigService.getStringConfig(MINIO_ENDPOINT_KEY); + accessKey = sysConfigService.getStringConfig(MINIO_ACCESS_KEY); + secretKey = sysConfigService.getStringConfig(MINIO_SECRET_KEY); + bucketName = sysConfigService.getStringConfig(MINIO_BUCKET_NAME_KEY); + publicUrl = sysConfigService.getStringConfig(MINIO_PUBLIC_URL_KEY); + + // 使用默认值如果配置不存在 + if (endpoint == null || endpoint.trim().isEmpty()) { + endpoint = DEFAULT_ENDPOINT; + logger.warn("未找到MinIO endpoint配置,使用默认值: {}", DEFAULT_ENDPOINT); + } + if (accessKey == null || accessKey.trim().isEmpty()) { + accessKey = DEFAULT_ACCESS_KEY; + logger.warn("未找到MinIO accessKey配置,使用默认值"); + } + if (secretKey == null || secretKey.trim().isEmpty()) { + secretKey = DEFAULT_SECRET_KEY; + logger.warn("未找到MinIO secretKey配置,使用默认值"); + } + if (bucketName == null || bucketName.trim().isEmpty()) { + bucketName = DEFAULT_BUCKET_NAME; + logger.warn("未找到MinIO bucketName配置,使用默认值: {}", DEFAULT_BUCKET_NAME); + } + if (publicUrl == null || publicUrl.trim().isEmpty()) { + publicUrl = endpoint; // 默认使用endpoint作为公网访问地址 + logger.warn("未找到MinIO publicUrl配置,使用endpoint作为默认值: {}", endpoint); + } + + logger.info("MinIO配置加载完成 - endpoint: {}, bucketName: {}", endpoint, bucketName); + + } catch (Exception e) { + logger.error("加载MinIO配置失败,使用默认配置", e); + endpoint = DEFAULT_ENDPOINT; + accessKey = DEFAULT_ACCESS_KEY; + secretKey = DEFAULT_SECRET_KEY; + bucketName = DEFAULT_BUCKET_NAME; + publicUrl = DEFAULT_PUBLIC_URL; + } + } + + /** + * 初始化MinIO客户端 + */ + private void initClient() { + try { + minioClient = MinioClient.builder() + .endpoint(endpoint) + .credentials(accessKey, secretKey) + .build(); + + logger.info("MinIO客户端初始化成功"); + } catch (Exception e) { + logger.error("MinIO客户端初始化失败", e); + throw new RuntimeException("MinIO客户端初始化失败", e); + } + } + + /** + * 重新加载配置 + */ + public void reloadConfig() { + logger.info("重新加载MinIO配置"); + loadConfig(); + initClient(); + } + + /** + * 获取MinIO客户端 + */ + public MinioClient getMinioClient() { + return minioClient; + } + + /** + * 构建文件的公网访问URL + * @param objectName 对象名称 + * @return 完整的文件访问URL + */ + public String buildFileUrl(String objectName) { + return publicUrl + "/" + bucketName + "/" + objectName; + } +} diff --git a/urbanLifelineServ/file/src/main/java/org/xyzh/file/mapper/FileMapper.java b/urbanLifelineServ/file/src/main/java/org/xyzh/file/mapper/FileMapper.java new file mode 100644 index 00000000..0ec52c83 --- /dev/null +++ b/urbanLifelineServ/file/src/main/java/org/xyzh/file/mapper/FileMapper.java @@ -0,0 +1,87 @@ +package org.xyzh.file.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +import java.util.List; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; +import org.xyzh.api.file.dto.TbSysFileDTO; + +/** + * @description 文件Mapper接口 + * @filename FileMapper.java + * @author yslg + * @copyright yslg + * @since 2025-12-09 + */ +@Mapper +public interface FileMapper extends BaseMapper { + + /** + * 根据文件ID查询文件信息(自定义方法替代selectById) + * @param fileId 文件ID + * @return 文件信息 + */ + @Select("SELECT * FROM file.tb_sys_file WHERE file_id = #{fileId} AND deleted = 0") + TbSysFileDTO selectByFileId(@Param("fileId") String fileId); + + /** + * 插入文件记录(自定义方法) + * @param fileDTO 文件DTO + * @return 影响行数 + */ + int insertFile(TbSysFileDTO fileDTO); + + /** + * 根据文件ID更新文件信息(自定义方法替代updateById) + * @param fileDTO 文件DTO + * @return 影响行数 + */ + int updateByFileId(TbSysFileDTO fileDTO); + + /** + * 根据文件ID逻辑删除文件(自定义方法) + * @param fileId 文件ID + * @param updater 更新者 + * @return 影响行数 + */ + @Update("UPDATE file.tb_sys_file SET deleted = 1, delete_time = CURRENT_TIMESTAMP, updater = #{updater} WHERE file_id = #{fileId}") + int deleteByFileId(@Param("fileId") String fileId, @Param("updater") String updater); + + /** + * 根据模块和业务ID查询文件列表 + * @param module 模块 + * @param businessId 业务ID + * @return 文件列表 + */ + @Select("SELECT * FROM file.tb_sys_file WHERE module = #{module} AND business_id = #{businessId} AND deleted = 0 ORDER BY create_time DESC") + List selectByModuleAndBusinessId(@Param("module") String module, @Param("businessId") String businessId); + + /** + * 根据上传者查询文件列表 + * @param uploader 上传者用户ID + * @return 文件列表 + */ + @Select("SELECT * FROM file.tb_sys_file WHERE uploader = #{uploader} AND deleted = 0 ORDER BY create_time DESC") + List selectByUploader(@Param("uploader") String uploader); + + /** + * 根据MD5查询文件(用于防重复上传) + * @param md5Hash MD5哈希值 + * @return 文件信息 + */ + @Select("SELECT * FROM file.tb_sys_file WHERE md5_hash = #{md5Hash} AND deleted = 0 LIMIT 1") + TbSysFileDTO selectByMd5Hash(@Param("md5Hash") String md5Hash); + + /** + * 根据MinIO对象名称查询文件 + * @param bucketName 存储桶名称 + * @param objectName 对象名称 + * @return 文件信息 + */ + @Select("SELECT * FROM file.tb_sys_file WHERE bucket_name = #{bucketName} AND object_name = #{objectName} AND deleted = 0") + TbSysFileDTO selectByMinioObject(@Param("bucketName") String bucketName, @Param("objectName") String objectName); +} diff --git a/urbanLifelineServ/file/src/main/java/org/xyzh/file/service/impl/FileServiceImpl.java b/urbanLifelineServ/file/src/main/java/org/xyzh/file/service/impl/FileServiceImpl.java new file mode 100644 index 00000000..d2f6f259 --- /dev/null +++ b/urbanLifelineServ/file/src/main/java/org/xyzh/file/service/impl/FileServiceImpl.java @@ -0,0 +1,307 @@ +package org.xyzh.file.service.impl; + +import org.apache.dubbo.config.annotation.DubboService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +// import org.springframework.beans.BeanUtils; // 不再需要BeanUtils +import org.springframework.util.DigestUtils; +import org.springframework.web.multipart.MultipartFile; +import org.xyzh.api.file.dto.TbSysFileDTO; +import org.xyzh.api.file.service.FileService; +import org.xyzh.common.core.domain.ResultDomain; +import org.xyzh.file.config.MinioConfig; +import org.xyzh.file.mapper.FileMapper; +import org.xyzh.file.util.MinioUtil; + +import java.io.InputStream; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * @description 文件服务实现类 + * @filename FileServiceImpl.java + * @author yslg + * @copyright yslg + * @since 2025-12-09 + */ +@DubboService( + version = "1.0.0", + group = "file", + timeout = 3000, + retries = 0 +) +public class FileServiceImpl implements FileService { + + private static final Logger logger = LoggerFactory.getLogger(FileServiceImpl.class); + + @Autowired + private MinioConfig minioConfig; + + @Autowired + private MinioUtil minioUtil; + + @Autowired + private FileMapper fileMapper; + + @Override + public ResultDomain uploadFile(MultipartFile file, String module, String businessId) { + try { + if (file == null || file.isEmpty()) { + return ResultDomain.failure("文件不能为空"); + } + + // 生成文件信息 + String originalFilename = file.getOriginalFilename(); + String extension = getFileExtension(originalFilename); + String contentType = file.getContentType(); + long size = file.getSize(); + + // 生成唯一的对象名称 + String objectName = generateObjectName(originalFilename, module); + + // 计算文件MD5 + String md5Hash = calculateMD5(file.getBytes()); + + // 上传到MinIO + String bucketName = minioConfig.getBucketName(); + boolean uploadSuccess = minioUtil.uploadFile( + bucketName, + objectName, + file.getInputStream(), + size, + contentType + ); + + if (!uploadSuccess) { + return ResultDomain.failure("文件上传到MinIO失败"); + } + + // 构建文件访问URL + String fileUrl = minioConfig.buildFileUrl(objectName); + + // 保存到数据库 + TbSysFileDTO fileDTO = new TbSysFileDTO(); + fileDTO.setOptsn(UUID.randomUUID().toString()); + fileDTO.setFileId(UUID.randomUUID().toString()); + fileDTO.setName(originalFilename); + fileDTO.setPath(objectName); + fileDTO.setSize(size); + fileDTO.setType(extension); + fileDTO.setStorageType("MINIO"); + fileDTO.setMimeType(contentType); + fileDTO.setUrl(fileUrl); + fileDTO.setStatus("NORMAL"); + fileDTO.setModule(module); + fileDTO.setBusinessId(businessId); + fileDTO.setObjectName(objectName); + fileDTO.setBucketName(bucketName); + fileDTO.setMd5Hash(md5Hash); + fileDTO.setExtension(extension); + fileDTO.setCreateTime(new java.util.Date()); + + int result = fileMapper.insertFile(fileDTO); + if (result <= 0) { + // 如果数据库保存失败,删除MinIO中的文件 + minioUtil.deleteFile(bucketName, objectName); + return ResultDomain.failure("文件信息保存失败"); + } + + logger.info("文件上传成功: {}, 大小: {} bytes", originalFilename, size); + return ResultDomain.success("文件上传成功", fileDTO); + + } catch (Exception e) { + logger.error("文件上传失败", e); + return ResultDomain.failure("文件上传失败: " + e.getMessage()); + } + } + + @Override + public ResultDomain batchUploadFiles(MultipartFile[] files, String module, String businessId, String uploader) { + try { + if (files == null || files.length == 0) { + return ResultDomain.failure("文件列表不能为空"); + } + + List uploadedFiles = new ArrayList<>(); + + for (MultipartFile file : files) { + ResultDomain result = uploadFile(file, module, businessId); + if (result.getSuccess()) { + TbSysFileDTO fileDTO = result.getData(); + fileDTO.setUploader(uploader); + uploadedFiles.add(fileDTO); + } else { + // 如果有文件上传失败,记录日志但继续处理其他文件 + logger.warn("文件上传失败: {}, 原因: {}", file.getOriginalFilename(), result.getMessage()); + } + } + + if (uploadedFiles.isEmpty()) { + return ResultDomain.failure("所有文件上传失败"); + } + + // 返回上传成功的文件列表(这里简化处理,实际可能需要返回详细结果) + TbSysFileDTO resultDTO = new TbSysFileDTO(); + // 可以在这里设置批量上传的汇总信息 + + logger.info("批量文件上传完成,成功: {}, 总数: {}", uploadedFiles.size(), files.length); + return ResultDomain.success("批量文件上传成功", resultDTO); + + } catch (Exception e) { + logger.error("批量文件上传失败", e); + return ResultDomain.failure("批量文件上传失败: " + e.getMessage()); + } + } + + @Override + public ResultDomain deleteFile(String fileId) { + try { + // 从数据库获取文件信息 + TbSysFileDTO sysFile = fileMapper.selectByFileId(fileId); + if (sysFile == null) { + return ResultDomain.failure("文件不存在"); + } + + // 删除MinIO中的文件 + minioUtil.deleteFile(sysFile.getBucketName(), sysFile.getObjectName()); + + // 逻辑删除数据库记录 + int result = fileMapper.deleteByFileId(fileId, "system"); + + if (result > 0) { + logger.info("文件删除成功: {}", fileId); + return ResultDomain.success("文件删除成功", true); + } else { + return ResultDomain.failure("文件删除失败"); + } + + } catch (Exception e) { + logger.error("文件删除失败: {}", fileId, e); + return ResultDomain.failure("文件删除失败: " + e.getMessage()); + } + } + + @Override + public ResultDomain batchDeleteFiles(String[] fileIds) { + try { + if (fileIds == null || fileIds.length == 0) { + return ResultDomain.failure("文件ID列表不能为空"); + } + + int successCount = 0; + for (String fileId : fileIds) { + ResultDomain result = deleteFile(fileId); + if (result.getSuccess()) { + successCount++; + } + } + + TbSysFileDTO resultDTO = new TbSysFileDTO(); + // 可以在这里设置批量删除的结果统计 + + logger.info("批量文件删除完成,成功: {}, 总数: {}", successCount, fileIds.length); + return ResultDomain.success("批量文件删除完成", resultDTO); + + } catch (Exception e) { + logger.error("批量文件删除失败", e); + return ResultDomain.failure("批量文件删除失败: " + e.getMessage()); + } + } + + @Override + public ResultDomain downloadFile(String fileId) { + try { + // 从数据库获取文件信息 + TbSysFileDTO sysFile = fileMapper.selectByFileId(fileId); + if (sysFile == null) { + return ResultDomain.failure("文件不存在"); + } + + // 从MinIO下载文件 + InputStream inputStream = minioUtil.downloadFile(sysFile.getBucketName(), sysFile.getObjectName()); + if (inputStream == null) { + return ResultDomain.failure("文件下载失败"); + } + + // 将输入流转换为字节数组 + byte[] data = inputStream.readAllBytes(); + inputStream.close(); + + logger.info("文件下载成功: {}", fileId); + return ResultDomain.success("文件下载成功", data); + + } catch (Exception e) { + logger.error("文件下载失败: {}", fileId, e); + return ResultDomain.failure("文件下载失败: " + e.getMessage()); + } + } + + @Override + public ResultDomain getFileById(String fileId) { + try { + TbSysFileDTO sysFile = fileMapper.selectByFileId(fileId); + if (sysFile == null) { + return ResultDomain.failure("文件不存在"); + } + + return ResultDomain.success("获取文件信息成功", sysFile); + + } catch (Exception e) { + logger.error("查询文件失败: {}", fileId, e); + return ResultDomain.failure("查询文件失败: " + e.getMessage()); + } + } + + @Override + public ResultDomain saveTempFile(MultipartFile file, String module, String businessId) { + try { + // 临时文件上传逻辑与普通上传相同,但可以添加特殊标识 + ResultDomain result = uploadFile(file, module, businessId); + if (result.getSuccess()) { + TbSysFileDTO fileDTO = result.getData(); + fileDTO.setStatus("TEMP"); // 标记为临时文件 + + // 更新数据库中的状态 + fileMapper.updateByFileId(fileDTO); + } + + return result; + + } catch (Exception e) { + logger.error("临时文件保存失败", e); + return ResultDomain.failure("临时文件保存失败: " + e.getMessage()); + } + } + + /** + * 生成唯一的对象名称 + */ + private String generateObjectName(String originalFilename, String module) { + String extension = getFileExtension(originalFilename); + String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd")); + String uuid = UUID.randomUUID().toString().replace("-", ""); + + return String.format("%s/%s/%s%s", module, date, uuid, extension); + } + + /** + * 获取文件扩展名 + */ + private String getFileExtension(String filename) { + if (filename == null || !filename.contains(".")) { + return ""; + } + return filename.substring(filename.lastIndexOf(".")); + } + + /** + * 计算文件MD5值 + */ + private String calculateMD5(byte[] data) { + return DigestUtils.md5DigestAsHex(data); + } +} diff --git a/urbanLifelineServ/file/src/main/java/org/xyzh/file/util/MinioUtil.java b/urbanLifelineServ/file/src/main/java/org/xyzh/file/util/MinioUtil.java new file mode 100644 index 00000000..2edb2bbe --- /dev/null +++ b/urbanLifelineServ/file/src/main/java/org/xyzh/file/util/MinioUtil.java @@ -0,0 +1,222 @@ +package org.xyzh.file.util; + +import io.minio.*; +import io.minio.http.Method; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.xyzh.file.config.MinioConfig; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.concurrent.TimeUnit; + +/** + * @description MinIO 工具类 + * @filename MinioUtil.java + * @author yslg + * @copyright yslg + * @since 2025-12-09 + */ +@Component +public class MinioUtil { + + private static final Logger logger = LoggerFactory.getLogger(MinioUtil.class); + + @Autowired + private MinioConfig minioConfig; + + /** + * 检查存储桶是否存在,如果不存在则创建 + * @param bucketName 存储桶名称 + * @return true 成功,false 失败 + */ + public boolean createBucketIfNotExists(String bucketName) { + try { + MinioClient minioClient = minioConfig.getMinioClient(); + + // 检查存储桶是否存在 + boolean exists = minioClient.bucketExists(BucketExistsArgs.builder() + .bucket(bucketName) + .build()); + + if (!exists) { + // 创建存储桶 + minioClient.makeBucket(MakeBucketArgs.builder() + .bucket(bucketName) + .build()); + logger.info("成功创建存储桶: {}", bucketName); + } + + return true; + } catch (Exception e) { + logger.error("创建存储桶失败: {}", bucketName, e); + return false; + } + } + + /** + * 上传文件到MinIO + * @param bucketName 存储桶名称 + * @param objectName 对象名称 + * @param inputStream 文件输入流 + * @param size 文件大小 + * @param contentType 文件类型 + * @return true 成功,false 失败 + */ + public boolean uploadFile(String bucketName, String objectName, InputStream inputStream, long size, String contentType) { + try { + MinioClient minioClient = minioConfig.getMinioClient(); + + // 确保存储桶存在 + if (!createBucketIfNotExists(bucketName)) { + return false; + } + + // 上传文件 + minioClient.putObject(PutObjectArgs.builder() + .bucket(bucketName) + .object(objectName) + .stream(inputStream, size, -1) + .contentType(contentType) + .build()); + + logger.info("文件上传成功: {}/{}", bucketName, objectName); + return true; + + } catch (Exception e) { + logger.error("文件上传失败: {}/{}", bucketName, objectName, e); + return false; + } + } + + /** + * 上传字节数组到MinIO + * @param bucketName 存储桶名称 + * @param objectName 对象名称 + * @param data 字节数组 + * @param contentType 文件类型 + * @return true 成功,false 失败 + */ + public boolean uploadFile(String bucketName, String objectName, byte[] data, String contentType) { + try (ByteArrayInputStream inputStream = new ByteArrayInputStream(data)) { + return uploadFile(bucketName, objectName, inputStream, data.length, contentType); + } catch (IOException e) { + logger.error("创建字节数组输入流失败", e); + return false; + } + } + + /** + * 下载文件 + * @param bucketName 存储桶名称 + * @param objectName 对象名称 + * @return 文件输入流,失败返回null + */ + public InputStream downloadFile(String bucketName, String objectName) { + try { + MinioClient minioClient = minioConfig.getMinioClient(); + + return minioClient.getObject(GetObjectArgs.builder() + .bucket(bucketName) + .object(objectName) + .build()); + + } catch (Exception e) { + logger.error("文件下载失败: {}/{}", bucketName, objectName, e); + return null; + } + } + + /** + * 删除文件 + * @param bucketName 存储桶名称 + * @param objectName 对象名称 + * @return true 成功,false 失败 + */ + public boolean deleteFile(String bucketName, String objectName) { + try { + MinioClient minioClient = minioConfig.getMinioClient(); + + minioClient.removeObject(RemoveObjectArgs.builder() + .bucket(bucketName) + .object(objectName) + .build()); + + logger.info("文件删除成功: {}/{}", bucketName, objectName); + return true; + + } catch (Exception e) { + logger.error("文件删除失败: {}/{}", bucketName, objectName, e); + return false; + } + } + + /** + * 获取文件的预签名URL(用于临时访问) + * @param bucketName 存储桶名称 + * @param objectName 对象名称 + * @param expiry 过期时间(秒) + * @return 预签名URL,失败返回null + */ + public String getPresignedUrl(String bucketName, String objectName, int expiry) { + try { + MinioClient minioClient = minioConfig.getMinioClient(); + + return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder() + .method(Method.GET) + .bucket(bucketName) + .object(objectName) + .expiry(expiry, TimeUnit.SECONDS) + .build()); + + } catch (Exception e) { + logger.error("生成预签名URL失败: {}/{}", bucketName, objectName, e); + return null; + } + } + + /** + * 检查文件是否存在 + * @param bucketName 存储桶名称 + * @param objectName 对象名称 + * @return true 存在,false 不存在 + */ + public boolean fileExists(String bucketName, String objectName) { + try { + MinioClient minioClient = minioConfig.getMinioClient(); + + minioClient.statObject(StatObjectArgs.builder() + .bucket(bucketName) + .object(objectName) + .build()); + + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 获取文件信息 + * @param bucketName 存储桶名称 + * @param objectName 对象名称 + * @return 文件信息,失败返回null + */ + public StatObjectResponse getFileInfo(String bucketName, String objectName) { + try { + MinioClient minioClient = minioConfig.getMinioClient(); + + return minioClient.statObject(StatObjectArgs.builder() + .bucket(bucketName) + .object(objectName) + .build()); + + } catch (Exception e) { + logger.error("获取文件信息失败: {}/{}", bucketName, objectName, e); + return null; + } + } +} diff --git a/urbanLifelineServ/file/src/main/resources/mapper/FileMapper.xml b/urbanLifelineServ/file/src/main/resources/mapper/FileMapper.xml new file mode 100644 index 00000000..166cfd8c --- /dev/null +++ b/urbanLifelineServ/file/src/main/resources/mapper/FileMapper.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO file.tb_sys_file ( + + optsn, file_id, name, path, size + + , creator + , updater + , dept_path + , remark + , create_time + , update_time + , delete_time + , deleted + , type + , storage_type + , mime_type + , url + , status + , module + , business_id + , uploader + , object_name + , bucket_name + , md5_hash + , extension + ) VALUES ( + + #{optsn}, #{fileId}, #{name}, #{path}, #{size} + + , #{creator} + , #{updater} + , #{deptPath} + , #{remark} + , #{createTime} + , #{updateTime} + , #{deleteTime} + , #{deleted} + , #{type} + , #{storageType} + , #{mimeType} + , #{url} + , #{status} + , #{module} + , #{businessId} + , #{uploader} + , #{objectName} + , #{bucketName} + , #{md5Hash} + , #{extension} + ) + + + + + UPDATE file.tb_sys_file + + updater = #{updater}, + dept_path = #{deptPath}, + remark = #{remark}, + update_time = CURRENT_TIMESTAMP, + name = #{name}, + path = #{path}, + size = #{size}, + type = #{type}, + storage_type = #{storageType}, + mime_type = #{mimeType}, + url = #{url}, + status = #{status}, + module = #{module}, + business_id = #{businessId}, + uploader = #{uploader}, + object_name = #{objectName}, + bucket_name = #{bucketName}, + md5_hash = #{md5Hash}, + extension = #{extension} + + WHERE file_id = #{fileId} AND ( deleted IS NULL OR deleted = false) + + + diff --git a/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/DeptRoleController.java b/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/DeptRoleController.java index 4a2b39a0..971d1496 100644 --- a/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/DeptRoleController.java +++ b/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/DeptRoleController.java @@ -1,5 +1,6 @@ package org.xyzh.system.controller; +import org.apache.dubbo.config.annotation.DubboReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -25,7 +26,7 @@ public class DeptRoleController { private static final Logger logger = LoggerFactory.getLogger(DeptRoleController.class); - @Autowired + @DubboReference(version = "1.0.0", group = "system", timeout = 3000, retries = 0) private DeptRoleService deptRoleService; // ================= 部门角色相关接口 ================= diff --git a/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/PermissionController.java b/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/PermissionController.java index 1e29e7e8..e030db65 100644 --- a/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/PermissionController.java +++ b/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/PermissionController.java @@ -1,5 +1,6 @@ package org.xyzh.system.controller; +import org.apache.dubbo.config.annotation.DubboReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -24,7 +25,7 @@ public class PermissionController { private static final Logger logger = LoggerFactory.getLogger(PermissionController.class); - @Autowired + @DubboReference(version = "1.0.0", group = "system", timeout = 3000, retries = 0) private ModulePermissionService modulePermissionService; // ================= 模块相关接口 ================= diff --git a/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/SysConfigController.java b/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/SysConfigController.java index 4fbed673..c5dc17ac 100644 --- a/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/SysConfigController.java +++ b/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/SysConfigController.java @@ -1,5 +1,6 @@ package org.xyzh.system.controller; +import org.apache.dubbo.config.annotation.DubboReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -23,7 +24,7 @@ public class SysConfigController { private static final Logger logger = LoggerFactory.getLogger(SysConfigController.class); - @Autowired + @DubboReference(version = "1.0.0", group = "system", timeout = 3000, retries = 0) private SysConfigService sysConfigService; // ================= 系统配置相关接口 ================= diff --git a/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/UserController.java b/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/UserController.java index 0d651836..cc796867 100644 --- a/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/UserController.java +++ b/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/UserController.java @@ -1,5 +1,6 @@ package org.xyzh.system.controller; +import org.apache.dubbo.config.annotation.DubboReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -25,7 +26,7 @@ public class UserController { private static final Logger logger = LoggerFactory.getLogger(UserController.class); - @Autowired + @DubboReference(version = "1.0.0", group = "system", timeout = 3000, retries = 0) private SysUserService sysUserService; // ================= 用户相关接口 ================= diff --git a/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/ViewController.java b/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/ViewController.java index 51554d4b..28e63940 100644 --- a/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/ViewController.java +++ b/urbanLifelineServ/system/src/main/java/org/xyzh/system/controller/ViewController.java @@ -1,5 +1,6 @@ package org.xyzh.system.controller; +import org.apache.dubbo.config.annotation.DubboReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -22,7 +23,7 @@ public class ViewController { private static final Logger logger = LoggerFactory.getLogger(ViewController.class); - @Autowired + @DubboReference(version = "1.0.0", group = "system", timeout = 3000, retries = 0) private ViewService viewService; // ================= 视图相关接口 ================= diff --git a/urbanLifelineServ/system/src/main/resources/application-dev.yml b/urbanLifelineServ/system/src/main/resources/application-dev.yml index 3d7566ce..756fe6a7 100644 --- a/urbanLifelineServ/system/src/main/resources/application-dev.yml +++ b/urbanLifelineServ/system/src/main/resources/application-dev.yml @@ -95,5 +95,5 @@ dubbo: # ================== MyBatis ================== mybatis-plus: - mapper-locations: classpath:mapper/*.xml + mapper-locations: classpath:mapper/**/*.xml type-aliases-package: org.xyzh.common.dto, org.xyzh.api diff --git a/urbanLifelineServ/system/src/main/resources/application.yml b/urbanLifelineServ/system/src/main/resources/application.yml index 5056609d..8d940ff7 100644 --- a/urbanLifelineServ/system/src/main/resources/application.yml +++ b/urbanLifelineServ/system/src/main/resources/application.yml @@ -110,7 +110,7 @@ dubbo: # ================== MyBatis ================== mybatis-plus: - mapper-locations: classpath:mapper/*.xml + mapper-locations: classpath:mapper/**/*.xml type-aliases-package: org.xyzh.common.dto, org.xyzh.api # ================== Logging ================== diff --git a/urbanLifelineServ/system/src/main/resources/mapper/acl/TbSysAclMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/acl/TbSysAclMapper.xml index 385e2a08..b3600144 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/acl/TbSysAclMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/acl/TbSysAclMapper.xml @@ -12,8 +12,8 @@ - - + + @@ -23,7 +23,7 @@ - + @@ -35,9 +35,9 @@ - - - + + + @@ -47,7 +47,7 @@ - + diff --git a/urbanLifelineServ/system/src/main/resources/mapper/acl/TbSysAclPolicyMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/acl/TbSysAclPolicyMapper.xml index cd691c63..2712e3c1 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/acl/TbSysAclPolicyMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/acl/TbSysAclPolicyMapper.xml @@ -10,9 +10,9 @@ - - - + + + @@ -22,7 +22,7 @@ - + @@ -33,9 +33,9 @@ - - - + + + @@ -45,7 +45,7 @@ - + diff --git a/urbanLifelineServ/system/src/main/resources/mapper/config/TbSysConfigMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/config/TbSysConfigMapper.xml index f4b2b89e..c4795284 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/config/TbSysConfigMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/config/TbSysConfigMapper.xml @@ -4,7 +4,6 @@ - @@ -12,13 +11,12 @@ - - + + - - - + + @@ -27,12 +25,11 @@ - + - @@ -40,16 +37,14 @@ - - + + - - - + + - @@ -58,7 +53,7 @@ - + @@ -69,11 +64,11 @@ - SELECT FROM config.tb_sys_config - WHERE config_key = #{configKey} - AND deleted = 0 + WHERE key = #{configKey} + AND (deleted IS NULL OR deleted = false) @@ -241,27 +236,26 @@ SELECT COUNT(1) FROM config.tb_sys_config - - AND config_id = #{filter.configId} + + AND config_id = #{configId} - - AND key LIKE CONCAT('%', #{filter.key}, '%') + + AND key LIKE CONCAT('%', #{key}, '%') - - AND config_type = #{filter.configType} + + AND config_type = #{configType} - - AND module_id = #{filter.moduleId} + + AND module_id = #{moduleId} - - AND status = #{filter.status} + + AND status = #{status} - - AND dept_path LIKE CONCAT(#{filter.deptPath}, '%') + + AND dept_path LIKE CONCAT(#{deptPath}, '%') AND (deleted IS NULL OR deleted = false) - diff --git a/urbanLifelineServ/system/src/main/resources/mapper/dept/TbSysDeptMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/dept/TbSysDeptMapper.xml index 8ae68ea8..a6877a6d 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/dept/TbSysDeptMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/dept/TbSysDeptMapper.xml @@ -18,7 +18,7 @@ - + @@ -37,7 +37,7 @@ - + diff --git a/urbanLifelineServ/system/src/main/resources/mapper/module/TbSysModuleMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/module/TbSysModuleMapper.xml index 089c743c..59a0e317 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/module/TbSysModuleMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/module/TbSysModuleMapper.xml @@ -17,7 +17,7 @@ - + @@ -35,7 +35,7 @@ - + diff --git a/urbanLifelineServ/system/src/main/resources/mapper/permission/TbSysPermissionMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/permission/TbSysPermissionMapper.xml index 45f79c9c..c19e75fa 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/permission/TbSysPermissionMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/permission/TbSysPermissionMapper.xml @@ -20,7 +20,7 @@ - + @@ -44,7 +44,7 @@ - + diff --git a/urbanLifelineServ/system/src/main/resources/mapper/role/TbSysRoleMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/role/TbSysRoleMapper.xml index 15b5147b..9483f398 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/role/TbSysRoleMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/role/TbSysRoleMapper.xml @@ -10,7 +10,7 @@ - + @@ -20,7 +20,7 @@ - + @@ -31,7 +31,7 @@ - + @@ -41,7 +41,7 @@ - + diff --git a/urbanLifelineServ/system/src/main/resources/mapper/role/TbSysRolePermissionMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/role/TbSysRolePermissionMapper.xml index e4ed8287..890a1c8c 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/role/TbSysRolePermissionMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/role/TbSysRolePermissionMapper.xml @@ -16,7 +16,7 @@ - + @@ -27,7 +27,7 @@ - + @@ -47,7 +47,7 @@ - + diff --git a/urbanLifelineServ/system/src/main/resources/mapper/user/TbSysUserInfoMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/user/TbSysUserInfoMapper.xml index ac102ac8..4e9864d7 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/user/TbSysUserInfoMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/user/TbSysUserInfoMapper.xml @@ -7,11 +7,11 @@ - + - + @@ -23,7 +23,7 @@ - + diff --git a/urbanLifelineServ/system/src/main/resources/mapper/user/TbSysUserMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/user/TbSysUserMapper.xml index 25d4edd3..2266c6a8 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/user/TbSysUserMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/user/TbSysUserMapper.xml @@ -10,14 +10,14 @@ - + - + @@ -28,14 +28,14 @@ - + - + - + @@ -43,7 +43,7 @@ - + diff --git a/urbanLifelineServ/system/src/main/resources/mapper/user/TbSysUserRoleMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/user/TbSysUserRoleMapper.xml index e34d513e..7873d3e8 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/user/TbSysUserRoleMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/user/TbSysUserRoleMapper.xml @@ -16,7 +16,7 @@ - + @@ -32,11 +32,11 @@ - + - + @@ -50,7 +50,7 @@ - + @@ -60,7 +60,7 @@ - + diff --git a/urbanLifelineServ/system/src/main/resources/mapper/view/TbSysViewMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/view/TbSysViewMapper.xml index 4a132ba7..90ca9ce5 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/view/TbSysViewMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/view/TbSysViewMapper.xml @@ -11,9 +11,9 @@ - + - + @@ -24,7 +24,7 @@ - + diff --git a/urbanLifelineServ/system/src/main/resources/mapper/view/TbSysViewPermissionMapper.xml b/urbanLifelineServ/system/src/main/resources/mapper/view/TbSysViewPermissionMapper.xml index 1897b89d..d9967bb8 100644 --- a/urbanLifelineServ/system/src/main/resources/mapper/view/TbSysViewPermissionMapper.xml +++ b/urbanLifelineServ/system/src/main/resources/mapper/view/TbSysViewPermissionMapper.xml @@ -16,7 +16,7 @@ - + @@ -28,9 +28,9 @@ - + - + @@ -51,7 +51,7 @@ - +