From 014bd716de3bc1c7a0fcc7d22a17eb336e6d432b Mon Sep 17 00:00:00 2001 From: chenbowen Date: Fri, 1 Aug 2025 08:47:13 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=AE=9E=E7=8E=B0=E9=9B=86=E4=B8=AD?= =?UTF-8?q?=E5=BC=8F=E7=9A=84=E9=99=84=E4=BB=B6=E7=BB=9F=E4=B8=80=E7=AE=A1?= =?UTF-8?q?=E7=90=86=EF=BC=8C=E7=BB=9F=E4=B8=80=E4=B8=8A=E4=BC=A0=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E9=A2=84=E8=A7=88=EF=BC=88=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=99=A8=EF=BC=8C=E5=85=AC=E5=85=B1=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=85=AC=E5=85=B1=E9=99=84=E4=BB=B6=E5=85=83=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=AE=9A=E4=B9=89=EF=BC=89=202.=20=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=9A=84=20DB=20=E5=AD=97=E6=AE=B5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E5=AE=9A=E4=B9=89=EF=BC=88=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=99=A8=EF=BC=8C=E5=85=B1=E7=94=A8=E8=A7=84?= =?UTF-8?q?=E8=8C=83=E6=A3=80=E6=9F=A5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit c2195ee3cf2079db8fd7949c2be873e870b40bdb) --- sql/dm/patch.sql | 32 +++- sql/dm/ruoyi-vue-pro-dm8.sql | 83 ++++++---- sql/mysql/ruoyi-vue-pro.sql | 34 +++- .../pom.xml | 12 ++ .../annotation/FileUploadController.java | 49 ++++++ .../YudaoBusinessAutoConfiguration.java | 13 ++ .../AbstractFileUploadController.java | 28 ++++ .../business/enums/FileUploadConstants.java | 19 +++ .../business/filter/FileUploadFilter.java | 149 +++++++++++++++++ .../YudaoBusinessRpcAutoConfiguration.java | 13 ++ .../FileUploadHeaderInterceptor.java | 69 ++++++++ .../business/vo/FileUploadInfoVO.java | 15 ++ ...ot.autoconfigure.AutoConfiguration.imports | 3 +- .../api/businessfile/BusinessFileApi.java | 27 ++++ .../dto/BusinessFileSaveReqDTO.java | 29 ++++ .../module/infra/api/stdnms/StdNmsApi.java | 59 +++++++ .../infra/api/stdnms/dto/StdNmsRespDTO.java | 26 +++ .../infra/enums/ErrorCodeConstants.java | 7 + .../api/businessfile/BusinessFileApiImpl.java | 33 ++++ .../infra/api/stdnms/StdNmsApiImpl.java | 59 +++++++ .../businessfile/BusinessFileController.java | 111 +++++++++++++ .../vo/BusinessFilePageReqVO.java | 35 ++++ .../businessfile/vo/BusinessFileRespVO.java | 43 +++++ .../vo/BusinessFileSaveReqVO.java | 25 +++ .../admin/codegen/CodegenController.java | 30 ++-- .../admin/file/vo/file/FileRespVO.java | 2 +- .../stdnms}/stdnms/StdNmsController.java | 14 +- .../stdnms}/stdnms/vo/StdNmsPageReqVO.java | 8 +- .../admin/stdnms}/stdnms/vo/StdNmsRespVO.java | 10 +- .../stdnms}/stdnms/vo/StdNmsSaveReqVO.java | 7 +- .../businessfile/BusinessFileDO.java | 53 +++++++ .../infra/dal/dataobject/file/FileDO.java | 18 ++- .../dataobject/stdnms}/stdnms/StdNmsDO.java | 6 +- .../businessfile/BusinessFileMapper.java | 31 ++++ .../infra}/dal/mysql/stdnms/StdNmsMapper.java | 6 +- .../businessfile/BusinessFileService.java | 64 ++++++++ .../businessfile/BusinessFileServiceImpl.java | 99 ++++++++++++ .../infra/service/codegen/CodegenService.java | 14 +- .../service/codegen/CodegenServiceImpl.java | 13 +- .../service/codegen/inner/CodegenEngine.java | 91 ++++++++++- .../infra/service/file/FileServiceImpl.java | 10 +- .../module/infra}/stdnms/StdNmsService.java | 26 ++- .../infra}/stdnms/StdNmsServiceImpl.java | 43 +++-- .../src/main/resources/application.yaml | 1 + .../codegen/java/controller/controller.vm | 30 +++- .../src/main/resources/codegen/java/dal/do.vm | 150 ++++++++---------- .../resources/codegen/java/service/service.vm | 2 +- .../codegen/java/service/serviceImpl.vm | 4 +- .../main/resources/codegen/vue3/api/api.ts.vm | 5 + .../resources/codegen/vue3/views/form.vue.vm | 11 ++ .../resources/codegen/vue3/views/index.vue.vm | 15 +- .../businessfile/BusinessFileMapper.xml | 12 ++ .../resources/mapper/stdnms/StdNmsMapper.xml | 6 +- .../codegen/CodegenServiceImplTest.java | 8 +- .../system/enums/ErrorCodeConstants.java | 2 - .../contract/DemoContractController.java | 65 ++++---- .../contract/vo/DemoContractPageReqVO.java | 23 +-- .../admin/contract/vo/DemoContractRespVO.java | 26 +-- .../contract/vo/DemoContractSaveReqVO.java | 41 +++-- .../dataobject/contract/DemoContractDO.java | 94 +++++++---- .../mysql/contract/DemoContractMapper.java | 5 - .../service/contract/DemoContractService.java | 2 +- .../contract/DemoContractServiceImpl.java | 5 +- 63 files changed, 1674 insertions(+), 351 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/annotation/FileUploadController.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/controller/AbstractFileUploadController.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/enums/FileUploadConstants.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/filter/FileUploadFilter.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/framework/rpc/YudaoBusinessRpcAutoConfiguration.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/interceptor/FileUploadHeaderInterceptor.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/vo/FileUploadInfoVO.java create mode 100644 yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/businessfile/BusinessFileApi.java create mode 100644 yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/businessfile/dto/BusinessFileSaveReqDTO.java create mode 100644 yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/stdnms/StdNmsApi.java create mode 100644 yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/stdnms/dto/StdNmsRespDTO.java create mode 100644 yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/api/businessfile/BusinessFileApiImpl.java create mode 100644 yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/api/stdnms/StdNmsApiImpl.java create mode 100644 yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/BusinessFileController.java create mode 100644 yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/vo/BusinessFilePageReqVO.java create mode 100644 yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/vo/BusinessFileRespVO.java create mode 100644 yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/vo/BusinessFileSaveReqVO.java rename {yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin => yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms}/stdnms/StdNmsController.java (90%) rename {yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin => yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms}/stdnms/vo/StdNmsPageReqVO.java (88%) rename {yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin => yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms}/stdnms/vo/StdNmsRespVO.java (82%) rename {yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin => yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms}/stdnms/vo/StdNmsSaveReqVO.java (84%) create mode 100644 yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/businessfile/BusinessFileDO.java rename {yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject => yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/stdnms}/stdnms/StdNmsDO.java (79%) create mode 100644 yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/businessfile/BusinessFileMapper.java rename {yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system => yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra}/dal/mysql/stdnms/StdNmsMapper.java (77%) create mode 100644 yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/businessfile/BusinessFileService.java create mode 100644 yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/businessfile/BusinessFileServiceImpl.java rename {yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service => yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra}/stdnms/StdNmsService.java (59%) rename {yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service => yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra}/stdnms/StdNmsServiceImpl.java (65%) create mode 100644 yudao-module-infra/yudao-module-infra-server/src/main/resources/mapper/businessfile/BusinessFileMapper.xml rename {yudao-module-system/yudao-module-system-server => yudao-module-infra/yudao-module-infra-server}/src/main/resources/mapper/stdnms/StdNmsMapper.xml (83%) diff --git a/sql/dm/patch.sql b/sql/dm/patch.sql index 5607679e..7a21b816 100644 --- a/sql/dm/patch.sql +++ b/sql/dm/patch.sql @@ -5,4 +5,34 @@ CREATE INDEX idx_infra_file_hash ON infra_file(hash); -- 2. 附件信息表新增 AES 加密时存储的随机 IV 字段 ALTER TABLE infra_file ADD aes_iv VARCHAR(128); -COMMENT ON COLUMN infra_file.aes_iv IS 'AES加密时的随机IV(Base64编码)'; \ No newline at end of file +COMMENT ON COLUMN infra_file.aes_iv IS 'AES加密时的随机IV(Base64编码)'; + +-- 3 业务附件统一管理 +DROP TABLE IF EXISTS infra_bsn_file; +CREATE TABLE infra_bsn_file ( + id bigint NOT NULL PRIMARY KEY, + bsn_id bigint NOT NULL, + bsn_cd varchar(100) DEFAULT '' NULL, + file_id bigint NOT NULL, + file_name varchar(500) DEFAULT '' NULL, + src varchar(100) DEFAULT '' NULL, + creator varchar(64) DEFAULT '' NULL, + create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, + updater varchar(64) DEFAULT '' NULL, + update_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, + deleted smallint DEFAULT 0 NOT NULL, + tenant_id bigint DEFAULT 0 NOT NULL +); +COMMENT ON TABLE infra_bsn_file IS '业务附件关联表'; +COMMENT ON COLUMN infra_bsn_file.id IS '主键ID'; +COMMENT ON COLUMN infra_bsn_file.bsn_id IS '业务Id'; +COMMENT ON COLUMN infra_bsn_file.bsn_cd IS '业务编码'; +COMMENT ON COLUMN infra_bsn_file.file_id IS '附件fileId'; +COMMENT ON COLUMN infra_bsn_file.file_name IS '附件名称'; +COMMENT ON COLUMN infra_bsn_file.src IS '附件来源'; +COMMENT ON COLUMN infra_bsn_file.creator IS '创建者'; +COMMENT ON COLUMN infra_bsn_file.create_time IS '创建时间'; +COMMENT ON COLUMN infra_bsn_file.updater IS '更新者'; +COMMENT ON COLUMN infra_bsn_file.update_time IS '最后更新时间'; +COMMENT ON COLUMN infra_bsn_file.deleted IS '是否删除'; +COMMENT ON COLUMN infra_bsn_file.tenant_id IS '租户编号'; \ No newline at end of file diff --git a/sql/dm/ruoyi-vue-pro-dm8.sql b/sql/dm/ruoyi-vue-pro-dm8.sql index b6f41a91..7a6d6cb9 100644 --- a/sql/dm/ruoyi-vue-pro-dm8.sql +++ b/sql/dm/ruoyi-vue-pro-dm8.sql @@ -5,7 +5,7 @@ Target Server Type : DM8 - Date: 2025-07-01 15:49:22 + Date: 2025-07-24 17:21:17 */ @@ -3968,7 +3968,7 @@ COMMENT ON TABLE system_sms_channel IS '短信渠道'; -- SET IDENTITY_INSERT system_sms_channel ON; INSERT INTO system_sms_channel (id, signature, code, status, remark, api_key, api_secret, callback_url, creator, create_time, updater, update_time, deleted) VALUES (2, 'Ballcat', 'ALIYUN', 0, '你要改哦,只有我可以用!!!!', 'LTAI5tCnKso2uG3kJ5gRav88', 'fGJ5SNXL7P1NHNRmJ7DJaMJGPyE55C', NULL, '', '2021-03-31 11:53:10', '1', '2024-08-04 08:53:26', '0'); INSERT INTO system_sms_channel (id, signature, code, status, remark, api_key, api_secret, callback_url, creator, create_time, updater, update_time, deleted) VALUES (4, '测试渠道', 'DEBUG_DING_TALK', 0, '123', '696b5d8ead48071237e4aa5861ff08dbadb2b4ded1c688a7b7c9afc615579859', 'SEC5c4e5ff888bc8a9923ae47f59e7ccd30af1f14d93c55b4e2c9cb094e35aeed67', NULL, '1', '2021-04-13 00:23:14', '1', '2022-03-27 20:29:49', '0'); -INSERT INTO system_sms_channel (id, signature, code, status, remark, api_key, api_secret, callback_url, creator, create_time, updater, update_time, deleted) VALUES (7, 'mock腾讯', 'TENCENT', 0, '', '1 2', '2 3', '', '1', '2024-09-30 08:53:45', '1', '2024-09-30 08:55:01', '0'); +INSERT INTO system_sms_channel (id, signature, code, status, remark, api_key, api_secret, callback_url, creator, create_time, updater, update_time, deleted) VALUES (7, 'mock腾讯云', 'TENCENT', 0, '', '1 2', '2 3', '', '1', '2024-09-30 08:53:45', '1', '2024-09-30 08:55:01', '0'); COMMIT; -- SET IDENTITY_INSERT system_sms_channel OFF; -- @formatter:on @@ -4791,33 +4791,62 @@ COMMENT ON COLUMN system_user_dept.deleted IS '是否删除'; COMMENT ON COLUMN system_user_dept.update_time IS '更新时间'; -- ---------------------------- --- Table structure for system_std_nms +-- Table structure for infra_std_nms -- ---------------------------- -DROP TABLE IF EXISTS system_std_nms; -CREATE TABLE system_std_nms -( - id BIGINT NOT NULL PRIMARY KEY, - word VARCHAR(128) NOT NULL UNIQUE, - abbr VARCHAR(32) NOT NULL UNIQUE, - info VARCHAR(128) NOT NULL UNIQUE, - creator VARCHAR(64) DEFAULT '', - create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, - updater VARCHAR(64) DEFAULT '', - update_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, - deleted bit DEFAULT '0' NOT NULL +DROP TABLE IF EXISTS infra_std_nms; +CREATE TABLE infra_std_nms ( + id bigint NOT NULL PRIMARY KEY, + word varchar(128) NOT NULL, + abbr varchar(32) NOT NULL, + info varchar(128) NOT NULL, + creator varchar(64) DEFAULT '' NULL, + create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, + updater varchar(64) DEFAULT '' NULL, + update_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, + deleted smallint DEFAULT 0 NOT NULL ); -COMMENT ON TABLE system_std_nms IS '数据命名与简写标准'; -COMMENT ON COLUMN system_std_nms.id IS '主键ID'; -COMMENT ON COLUMN system_std_nms.word IS '英文'; -COMMENT ON COLUMN system_std_nms.abbr IS '简写'; -COMMENT ON COLUMN system_std_nms.info IS '中文意思'; -COMMENT ON COLUMN system_std_nms.creator IS '创建者'; -COMMENT ON COLUMN system_std_nms.create_time IS '创建时间'; -COMMENT ON COLUMN system_std_nms.updater IS '更新者'; -COMMENT ON COLUMN system_std_nms.update_time IS '最后更新时间'; -COMMENT ON COLUMN system_std_nms.deleted IS '是否删除'; +COMMENT ON COLUMN infra_std_nms.id IS '主键ID'; +COMMENT ON COLUMN infra_std_nms.word IS '英文'; +COMMENT ON COLUMN infra_std_nms.abbr IS '简写'; +COMMENT ON COLUMN infra_std_nms.info IS '中文意思'; +COMMENT ON COLUMN infra_std_nms.creator IS '创建者'; +COMMENT ON COLUMN infra_std_nms.create_time IS '创建时间'; +COMMENT ON COLUMN infra_std_nms.updater IS '更新者'; +COMMENT ON COLUMN infra_std_nms.update_time IS '最后更新时间'; +COMMENT ON COLUMN infra_std_nms.deleted IS '是否删除'; -- ---------------------------- --- Records of system_std_nms --- +-- Table structure for infra_bsn_file +-- ---------------------------- +DROP TABLE IF EXISTS infra_bsn_file; +CREATE TABLE infra_bsn_file ( + id bigint NOT NULL PRIMARY KEY, + bsn_id bigint NOT NULL, + bsn_cd varchar(100) DEFAULT '' NULL, + file_id bigint NOT NULL, + file_name varchar(500) DEFAULT '' NULL, + src varchar(100) DEFAULT '' NULL, + creator varchar(64) DEFAULT '' NULL, + create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, + updater varchar(64) DEFAULT '' NULL, + update_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, + deleted smallint DEFAULT 0 NOT NULL, + tenant_id bigint DEFAULT 0 NOT NULL +); +COMMENT ON TABLE infra_bsn_file IS '业务附件关联表'; +COMMENT ON COLUMN infra_bsn_file.id IS '主键ID'; +COMMENT ON COLUMN infra_bsn_file.bsn_id IS '业务Id'; +COMMENT ON COLUMN infra_bsn_file.bsn_cd IS '业务编码'; +COMMENT ON COLUMN infra_bsn_file.file_id IS '附件fileId'; +COMMENT ON COLUMN infra_bsn_file.file_name IS '附件名称'; +COMMENT ON COLUMN infra_bsn_file.src IS '附件来源'; +COMMENT ON COLUMN infra_bsn_file.creator IS '创建者'; +COMMENT ON COLUMN infra_bsn_file.create_time IS '创建时间'; +COMMENT ON COLUMN infra_bsn_file.updater IS '更新者'; +COMMENT ON COLUMN infra_bsn_file.update_time IS '最后更新时间'; +COMMENT ON COLUMN infra_bsn_file.deleted IS '是否删除'; +COMMENT ON COLUMN infra_bsn_file.tenant_id IS '租户编号'; +-- ---------------------------- +-- Records of infra_bsn_file +-- ---------------------------- \ No newline at end of file diff --git a/sql/mysql/ruoyi-vue-pro.sql b/sql/mysql/ruoyi-vue-pro.sql index d1a0cce1..36b4215a 100644 --- a/sql/mysql/ruoyi-vue-pro.sql +++ b/sql/mysql/ruoyi-vue-pro.sql @@ -4114,11 +4114,12 @@ CREATE TABLE `system_user_dept` -- ---------------------------- -- Records of system_user_dept -- ---------------------------- + -- ---------------------------- --- Table structure for system_std_nms +-- Table structure for infra_std_nms -- ---------------------------- -DROP TABLE IF EXISTS `system_std_nms`; -CREATE TABLE `system_std_nms` +DROP TABLE IF EXISTS `infra_std_nms`; +CREATE TABLE `infra_std_nms` ( `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID', `word` VARCHAR(128) NOT NULL UNIQUE COMMENT '英文', @@ -4129,9 +4130,32 @@ CREATE TABLE `system_std_nms` `updater` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '更新者', `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', `deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否删除' -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='数据命名与简写标准' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='数据命名与简写标准'; -- ---------------------------- --- Records of system_std_nms +-- Records of infra_std_nms +-- ---------------------------- + +-- ---------------------------- +-- Table structure for infra_bsn_file +-- ---------------------------- +DROP TABLE IF EXISTS `infra_bsn_file`; +CREATE TABLE `infra_bsn_file` +( + `id` BIGINT NOT NULL PRIMARY KEY COMMENT '主键ID', + `bsn_id` BIGINT NOT NULL COMMENT '业务Id', + `bsn_code` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '业务编码', + `file_id` BIGINT NOT NULL COMMENT '附件fileId', + `file_id` VARCHAR(500) NOT NULL COMMENT '附件名称', + `source` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '附件来源', + `creator` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '创建者', + `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '更新者', + `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', + `deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否删除', + `tenant_id` BIGINT NOT NULL DEFAULT 0 COMMENT '租户编号' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='业务附件表'; +-- ---------------------------- +-- Records of infra_bsn_file -- ---------------------------- SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-business/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-business/pom.xml index e48b4d0b..52127212 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-business/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-biz-business/pom.xml @@ -37,6 +37,18 @@ yudao-spring-boot-starter-test test + + cn.iocoder.cloud + yudao-module-infra-api + ${revision} + + + + + cn.iocoder.cloud + yudao-spring-boot-starter-rpc + + \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/annotation/FileUploadController.java b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/annotation/FileUploadController.java new file mode 100644 index 00000000..641d5b42 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/annotation/FileUploadController.java @@ -0,0 +1,49 @@ +package cn.iocoder.yudao.framework.business.annotation; + +import java.lang.annotation.*; + +/** + * @author chenbowen + * + * 附件上传 Controller 注解, + * 1. 标记附件列表上传在 requestBody 中的 Key 值, + * 2. 标记当前 controller 中业务创建请求后返回的业务主键 Key 值, + * 2. 标记会开启业务提交时,前置校验操作用户唯一部门 + * 3. 标记当前 controller 所属的业务来源 + */ + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface FileUploadController { + /** + * 附件列表上传在 requestBody 中的 Key 值 + */ + String filesKey() default "files"; + + /** + * 附件名称在 requestBody 中的 Key 值 + */ + String fileNameKey() default "name"; + + /** + * 附件 ID 在 requestBody 中的 Key 值 + */ + String fileIdKey() default "id"; + + /** + * 业务来源 + * 例如:bpm、oa、hr 等 + */ + String source() default "default"; + + /** + * 业务创建请求后返回的业务主键 Key 值 + */ + String primaryKey() default "data.id"; + + /** + * 业务创建请求后返回的业务编码 Key 值 + */ + String codeKey() default "data.code"; +} \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/config/YudaoBusinessAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/config/YudaoBusinessAutoConfiguration.java index 05996ef1..f8b82af3 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/config/YudaoBusinessAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/config/YudaoBusinessAutoConfiguration.java @@ -1,8 +1,13 @@ package cn.iocoder.yudao.framework.business.config; +import cn.iocoder.yudao.framework.business.filter.FileUploadFilter; import cn.iocoder.yudao.framework.business.interceptor.BusinessHeaderInterceptor; +import cn.iocoder.yudao.framework.business.interceptor.FileUploadHeaderInterceptor; import cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -10,11 +15,19 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; * @author chenbowen */ @AutoConfiguration(after = YudaoWebAutoConfiguration.class) +@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) public class YudaoBusinessAutoConfiguration implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { // 只拦截增删改和 set 相关的 url registry.addInterceptor(new BusinessHeaderInterceptor()) .addPathPatterns("/**/add**", "/**/create**", "/**/update**", "/**/edit**", "/**/set**"); + registry.addInterceptor(new FileUploadHeaderInterceptor()) + .addPathPatterns("/**/add**", "/**/create**", "/**/update**", "/**/edit**", "/**/set**"); + } + + @Bean + public FilterRegistrationBean businessHeaderFilter() { + return new FilterRegistrationBean<>(new FileUploadFilter()); } } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/controller/AbstractFileUploadController.java b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/controller/AbstractFileUploadController.java new file mode 100644 index 00000000..142269cb --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/controller/AbstractFileUploadController.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.framework.business.controller; + +import cn.iocoder.yudao.framework.business.annotation.FileUploadController; +import cn.iocoder.yudao.framework.business.vo.FileUploadInfoVO; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import io.swagger.v3.oas.annotations.Operation; +import org.springframework.web.bind.annotation.GetMapping; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +/** + * @author chenbowen + */ + +public abstract class AbstractFileUploadController { + protected static String FILE_UPLOAD_SOURCE = ""; + @GetMapping("/upload-info") + @Operation(summary = "获取文件上传 source 配置值") + public CommonResult getFileUploadSource() { + FileUploadInfoVO vo = new FileUploadInfoVO(); + vo.setSource(FILE_UPLOAD_SOURCE); + return success(vo); + } + + protected static void setFileUploadInfo(FileUploadController annotation) { + FILE_UPLOAD_SOURCE = annotation.source(); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/enums/FileUploadConstants.java b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/enums/FileUploadConstants.java new file mode 100644 index 00000000..49d23422 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/enums/FileUploadConstants.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.framework.business.enums; +/** + * @author chenbowen + */ +public interface FileUploadConstants { + // 是否业务请求 + String IS_UPLOAD_REQUEST = "isUploadRequest"; + // request 中附件列表的 Key 值,支持多层级引用 如 data.files + String FILES_KEY = "fileKey"; + String FILE_NAME_KEY = "fileNameKey"; + String FILE_ID_KEY = "fileIdKey"; + + // request 中业务来源的 + String FILE_SOURCE = "fileSource"; + // request 中业务创建请求后返回的业务主键 Key 值,支持多层级引用 如 data.businessPrimaryKey + String FILE_REL_PRIMARY_KEY = "fileRelPrimaryKey"; + String FILE_REL_CODE_KEY = "fileRelCode"; +} + diff --git a/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/filter/FileUploadFilter.java b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/filter/FileUploadFilter.java new file mode 100644 index 00000000..e83ebfb2 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/filter/FileUploadFilter.java @@ -0,0 +1,149 @@ +package cn.iocoder.yudao.framework.business.filter; + +import cn.iocoder.yudao.framework.common.util.spring.SpringUtils; +import cn.iocoder.yudao.module.infra.api.businessfile.BusinessFileApi; +import cn.iocoder.yudao.module.infra.api.businessfile.dto.BusinessFileSaveReqDTO; +import com.esotericsoftware.minlog.Log; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.servlet.*; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.util.ContentCachingResponseWrapper; + +import java.io.BufferedReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static cn.iocoder.yudao.framework.business.enums.FileUploadConstants.*; + +/** + * @author chenbowen + */ +@Slf4j +public class FileUploadFilter implements Filter { + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + HttpServletRequest httpRequest = (HttpServletRequest) request; + ContentCachingResponseWrapper wrappedResponse = new ContentCachingResponseWrapper((HttpServletResponse) response); + chain.doFilter(request, wrappedResponse); + + // 仅当 request 包含 isUploadRequest 时,且只处理 200 响应 + if (!isUploadRequest(httpRequest) || wrappedResponse.getStatus() != HttpServletResponse.SC_OK) { + wrappedResponse.copyBodyToResponse(); + return; + } + try { + ObjectMapper objectMapper = new ObjectMapper(); + String requestBody = getRequestBody(httpRequest); + if (requestBody == null || requestBody.isEmpty()) { + wrappedResponse.copyBodyToResponse(); + return; + } + // 从 request 获取 fileKey、业务主键 key、系统来源 + String fileKey = httpRequest.getAttribute(FILES_KEY).toString(); + String businessPrimaryKey = httpRequest.getAttribute(FILE_REL_PRIMARY_KEY).toString(); + String businessCodeKey = httpRequest.getAttribute(FILE_REL_CODE_KEY).toString(); + String businessSource = httpRequest.getAttribute(FILE_SOURCE).toString(); + String fileNameKey = httpRequest.getAttribute(FILE_NAME_KEY).toString(); + String fileIdKey = httpRequest.getAttribute(FILE_ID_KEY).toString(); + + JsonNode filesNode = getJsonNodeByPath(objectMapper.readTree(requestBody), fileKey); + if (filesNode == null || !filesNode.isArray()) { + wrappedResponse.copyBodyToResponse(); + return; + } + String responseBody = new String(wrappedResponse.getContentAsByteArray(), wrappedResponse.getCharacterEncoding()); + // code 如果不等于 200,则不处理 + JsonNode responseJson = objectMapper.readTree(responseBody); + if (responseJson.path("code").asInt(-1) != 0) { + wrappedResponse.copyBodyToResponse(); + return; + } + // 业务主键支持多层级,如 data.businessPrimaryKey + String businessId = getJsonValueByPath(responseJson, businessPrimaryKey); + if (businessId == null) { + wrappedResponse.copyBodyToResponse(); + return; + } + // 业务编码支持多层级,如 data.businessCodeKey + String businessCode = getJsonValueByPath(responseJson, businessCodeKey); + + List fileNodeList = new ArrayList<>(); + filesNode.forEach(fileNodeList::add); + saveBusinessAttachmentBatch(fileNodeList, businessId, businessCode, businessSource, fileNameKey, fileIdKey); + } catch (Exception e) { + // 记录日志 + Log.error(e.getMessage(), e); + } + wrappedResponse.copyBodyToResponse(); + } + + /** + * 按路径获取 JsonNode 的值,支持多层级,如 data.businessPrimaryKey + */ + private String getJsonValueByPath(JsonNode node, String path) { + if (node == null || path == null || path.isEmpty()) return null; + JsonNode current = node; + for (String key : path.split("\\.")) { + current = current.path(key); + } + return current.isMissingNode() ? null : current.asText(null); + } + + /** + * 按路径获取 JsonNode 节点,支持多层级,如 data.files + */ + private JsonNode getJsonNodeByPath(JsonNode node, String path) { + if (node == null || path == null || path.isEmpty()) return null; + JsonNode current = node; + for (String key : path.split("\\.")) { + current = current.path(key); + } + return current; + } + + private boolean isUploadRequest(HttpServletRequest request) { + // 判断 request 是否包含 isUploadRequest 参数(可根据实际业务调整判断方式) + String isUpload = Optional.ofNullable(request.getAttribute(IS_UPLOAD_REQUEST)).orElse("").toString(); + return "true".equalsIgnoreCase(isUpload); + } + + private String getRequestBody(HttpServletRequest request) { + try { + BufferedReader reader = request.getReader(); + StringBuilder sb = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + sb.append(line); + } + return sb.toString(); + } catch (Exception e) { + return null; + } + } + + private void saveBusinessAttachmentBatch(List fileNodes, String businessId, String businessCode, String businessSource, String name, String id) { + BusinessFileApi businessFileApi = SpringUtils.getBean(BusinessFileApi.class); + List reqDTOList = new ArrayList<>(); + for (JsonNode fileNode : fileNodes) { + String fileId = fileNode.path(id).asText(null); + String fileName = fileNode.path(name).asText(null); + if (fileId != null) { + BusinessFileSaveReqDTO createReqDTO = new BusinessFileSaveReqDTO(); + createReqDTO.setBusinessId(Long.parseLong(businessId)); + createReqDTO.setBusinessCode(businessCode); + createReqDTO.setFileId(Long.parseLong(fileId)); + createReqDTO.setFileName(fileName); + createReqDTO.setSource(businessSource); + reqDTOList.add(createReqDTO); + } + } + if (!reqDTOList.isEmpty()) { + businessFileApi.batchCreateBusinessFile(reqDTOList); + } + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/framework/rpc/YudaoBusinessRpcAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/framework/rpc/YudaoBusinessRpcAutoConfiguration.java new file mode 100644 index 00000000..c221933e --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/framework/rpc/YudaoBusinessRpcAutoConfiguration.java @@ -0,0 +1,13 @@ +package cn.iocoder.yudao.framework.business.framework.rpc; + +import cn.iocoder.yudao.module.infra.api.businessfile.BusinessFileApi; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.cloud.openfeign.EnableFeignClients; + +/** + * @author chenbowen + */ +@AutoConfiguration +@EnableFeignClients(clients = BusinessFileApi.class) +public class YudaoBusinessRpcAutoConfiguration { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/interceptor/FileUploadHeaderInterceptor.java b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/interceptor/FileUploadHeaderInterceptor.java new file mode 100644 index 00000000..db81f068 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/interceptor/FileUploadHeaderInterceptor.java @@ -0,0 +1,69 @@ +package cn.iocoder.yudao.framework.business.interceptor; + +import cn.iocoder.yudao.framework.business.annotation.FileUploadController; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResultCodeEnum; +import cn.iocoder.yudao.framework.common.pojo.CompanyDeptInfo; +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.lang.NonNull; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.HandlerInterceptor; + +import java.util.Set; + +import static cn.iocoder.yudao.framework.business.core.util.BusinessDeptHandleUtil.getBelongCompanyAndDept; +import static cn.iocoder.yudao.framework.business.enums.FileUploadConstants.*; + +/** + * @author chenbowen + */ +@RequiredArgsConstructor +public class FileUploadHeaderInterceptor implements HandlerInterceptor { + + @Override + public boolean preHandle(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull Object handler) throws Exception { + if (!(handler instanceof HandlerMethod handlerMethod)) { + return true; + } + Object bean = handlerMethod.getBean(); + FileUploadController annotation = bean.getClass().getAnnotation(FileUploadController.class); + if (annotation == null) { + return true; + } + // 设置请求属性,标记当前请求为业务控制器 + request.setAttribute(IS_UPLOAD_REQUEST, true); + // 从注解中获取所有的 value 值,如果没有被 注解,获取注解默认值 + // 将这些值设置到 request + request.setAttribute(FILES_KEY, annotation.filesKey()); + request.setAttribute(FILE_NAME_KEY, annotation.fileNameKey()); + request.setAttribute(FILE_ID_KEY, annotation.fileIdKey()); + request.setAttribute(FILE_SOURCE, annotation.source()); + request.setAttribute(FILE_REL_PRIMARY_KEY, annotation.primaryKey()); + request.setAttribute(FILE_REL_CODE_KEY, annotation.codeKey()); + + ObjectMapper objectMapper = new ObjectMapper(); + Set companyDeptInfos = getBelongCompanyAndDept(request, response); + // 无法获取到有效的用户归属公司与部门信息,提示错误 + if (companyDeptInfos == null) { + return writeResponse(response, HttpStatus.BAD_REQUEST.value(), CommonResult.customize(null, CommonResultCodeEnum.ERROR.getCode(), "当前用户匹配部门不属于此公司"), objectMapper); + } + // 获取到了有效的一组或多组公司与部门信息,需要返回前端进行补充请求头后的二次请求 + if (!companyDeptInfos.isEmpty()) { + return writeResponse(response, HttpStatus.OK.value(), CommonResult.customize(companyDeptInfos, CommonResultCodeEnum.NEED_ADJUST), objectMapper); + } + else{ + return true; + } + } + + + private boolean writeResponse(HttpServletResponse response, int status, CommonResult result, ObjectMapper objectMapper) throws Exception { + response.setStatus(status); + response.getWriter().write(objectMapper.writeValueAsString(result)); + return false; + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/vo/FileUploadInfoVO.java b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/vo/FileUploadInfoVO.java new file mode 100644 index 00000000..c1aec26f --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/java/cn/iocoder/yudao/framework/business/vo/FileUploadInfoVO.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.framework.business.vo; + +import lombok.Data; + +/** + * 文件上传信息的值对象 + * 用于封装文件上传的相关信息 + * + * @author chenbowen + */ +@Data +public class FileUploadInfoVO { + // 文件来源标识 + private String source; +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index f9e25597..f59ce5d4 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/yudao-framework/yudao-spring-boot-starter-biz-business/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,2 +1,3 @@ cn.iocoder.yudao.framework.business.config.YudaoBusinessAutoConfiguration -cn.iocoder.yudao.framework.business.framework.BusinessDataPermissionConfiguration \ No newline at end of file +cn.iocoder.yudao.framework.business.framework.BusinessDataPermissionConfiguration +cn.iocoder.yudao.framework.business.framework.rpc.YudaoBusinessRpcAutoConfiguration \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/businessfile/BusinessFileApi.java b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/businessfile/BusinessFileApi.java new file mode 100644 index 00000000..a0e1843b --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/businessfile/BusinessFileApi.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.infra.api.businessfile; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.infra.api.businessfile.dto.BusinessFileSaveReqDTO; +import cn.iocoder.yudao.module.infra.enums.ApiConstants; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.List; + +/** + * @author chenbowen + */ +@FeignClient(name = ApiConstants.NAME) +@Tag(name = "RPC 服务 - 业务附件关联") +public interface BusinessFileApi { + + String PREFIX = ApiConstants.PREFIX + "/business-file"; + + @PostMapping(PREFIX + "/batch-create") + @Operation(summary = "批量新增业务附件关联") + CommonResult> batchCreateBusinessFile(@RequestBody List createReqDTOList); + +} diff --git a/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/businessfile/dto/BusinessFileSaveReqDTO.java b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/businessfile/dto/BusinessFileSaveReqDTO.java new file mode 100644 index 00000000..6fdcf60d --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/businessfile/dto/BusinessFileSaveReqDTO.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.infra.api.businessfile.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 业务附件关联保存请求 DTO + * @author chenbowen + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class BusinessFileSaveReqDTO implements Serializable { + /** 业务Id */ + private Long businessId; + /** 业务编码 */ + private String businessCode; + /** 文件名 */ + private String fileName; + private Long fileId; + /** 业务来源 */ + private String source; +} + diff --git a/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/stdnms/StdNmsApi.java b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/stdnms/StdNmsApi.java new file mode 100644 index 00000000..cd5f7cb2 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/stdnms/StdNmsApi.java @@ -0,0 +1,59 @@ + +package cn.iocoder.yudao.module.infra.api.stdnms; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.infra.api.stdnms.dto.StdNmsRespDTO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.Collection; +import java.util.List; + +@FeignClient(name = "stdnms-api") // 可根据实际服务名调整 +@Tag(name = "RPC 服务 - 数据命名与简写标准") +public interface StdNmsApi { + + String PREFIX = "/api/stdnms"; + + @DeleteMapping(PREFIX + "/delete") + @Operation(summary = "删除数据命名与简写标准") + @Parameters({ + @Parameter(name = "id", description = "主键ID", example = "1001", required = true) + }) + CommonResult deleteStdNms(@RequestParam("id") Long id); + + @DeleteMapping(PREFIX + "/delete-batch") + @Operation(summary = "批量删除数据命名与简写标准") + @Parameters({ + @Parameter(name = "ids", description = "主键ID集合", example = "[1001,1002]", required = true) + }) + CommonResult deleteStdNmsList(@RequestParam("ids") List ids); + + @GetMapping(PREFIX + "/get") + @Operation(summary = "根据主键获取数据命名与简写标准") + @Parameters({ + @Parameter(name = "id", description = "主键ID", example = "1001", required = true) + }) + CommonResult getStdNms(@RequestParam("id") Long id); + + @GetMapping(PREFIX + "/get-by-abbr") + @Operation(summary = "根据缩写获取数据命名与简写标准") + @Parameters({ + @Parameter(name = "abbr", description = "简写/缩写", example = "devNm", required = true) + }) + CommonResult getStdNmsByAbbr(@RequestParam("abbr") String abbr); + + @GetMapping(PREFIX + "/list-by-abbrs") + @Operation(summary = "根据缩写列表查询数据命名与简写标准") + @Parameters({ + @Parameter(name = "abbrs", description = "简写/缩写集合", example = "[devNm,devType]", required = true) + }) + CommonResult> getStdNmsListByAbbrs(@RequestParam("abbrs") Collection abbrs); + +} diff --git a/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/stdnms/dto/StdNmsRespDTO.java b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/stdnms/dto/StdNmsRespDTO.java new file mode 100644 index 00000000..3b3b8431 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/stdnms/dto/StdNmsRespDTO.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.infra.api.stdnms.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Schema(description = "数据命名与简写标准响应 DTO") +@Data +@NoArgsConstructor +@AllArgsConstructor +public class StdNmsRespDTO implements Serializable { + + @Schema(description = "主键ID", example = "1001") + private Long id; + + @Schema(description = "名称", example = "设备名称") + private String name; + + @Schema(description = "简写/缩写", example = "devNm") + private String abbr; + + // 可根据实际需求补充其他字段 +} diff --git a/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java index b30f5e86..6e5a9524 100644 --- a/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java +++ b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java @@ -79,4 +79,11 @@ public interface ErrorCodeConstants { ErrorCode DEMO03_GRADE_NOT_EXISTS = new ErrorCode(1_001_201_009, "学生班级不存在"); ErrorCode DEMO03_GRADE_EXISTS = new ErrorCode(1_001_201_010, "学生班级已存在"); + // ========== 业务附件关联 ========== + ErrorCode BUSINESS_FILE_NOT_EXISTS = new ErrorCode(1_002_201_010, "业务附件关联不存在"); + + // ========== 数据命名与简写标准 ========== + ErrorCode STD_NMS_NOT_EXISTS = new ErrorCode(1_002_030_000, "数据命名与简写标准不存在"); + + ErrorCode STD_ABBR_NOT_EXISTS = new ErrorCode(1_002_030_001, "字段名 {} 不存在命名规范定义,请核对字段定义"); } diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/api/businessfile/BusinessFileApiImpl.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/api/businessfile/BusinessFileApiImpl.java new file mode 100644 index 00000000..81f8bfc6 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/api/businessfile/BusinessFileApiImpl.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.infra.api.businessfile; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.infra.api.businessfile.dto.BusinessFileSaveReqDTO; +import cn.iocoder.yudao.module.infra.controller.admin.businessfile.vo.BusinessFileSaveReqVO; +import cn.iocoder.yudao.module.infra.service.businessfile.BusinessFileService; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +/** + * 业务附件关联 API 实现 + * @author chenbowen + */ +@RestController // 提供 RESTful API 接口,给 Feign 调用 +@Validated +public class BusinessFileApiImpl implements BusinessFileApi { + + @Resource + private BusinessFileService businessFileService; + + @Override + public CommonResult> batchCreateBusinessFile(List createReqDTOList) { + List createReqVOList = BeanUtils.toBean(createReqDTOList, BusinessFileSaveReqVO.class); + List ids = businessFileService.batchCreateBusinessFile(createReqVOList); + return success(ids); + } +} diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/api/stdnms/StdNmsApiImpl.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/api/stdnms/StdNmsApiImpl.java new file mode 100644 index 00000000..b73d887a --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/api/stdnms/StdNmsApiImpl.java @@ -0,0 +1,59 @@ +package cn.iocoder.yudao.module.infra.api.stdnms; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.infra.api.stdnms.dto.StdNmsRespDTO; +import cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO; +import cn.iocoder.yudao.module.infra.stdnms.StdNmsService; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +/** + * 数据命名与简写标准 API 实现 + * + * @author 后台管理 + */ +@RestController // 提供 RESTful API 接口,给 Feign 调用 +@Validated +public class StdNmsApiImpl implements StdNmsApi { + + @Resource + private StdNmsService stdNmsService; + + @Override + public CommonResult deleteStdNms(Long id) { + stdNmsService.deleteStdNms(id); + return success(true); + } + + @Override + public CommonResult deleteStdNmsList(List ids) { + stdNmsService.deleteStdNmsListByIds(ids); + return success(true); + } + + @Override + public CommonResult getStdNms(Long id) { + StdNmsDO stdNms = stdNmsService.getStdNms(id); + return success(BeanUtils.toBean(stdNms, StdNmsRespDTO.class)); + } + + @Override + public CommonResult getStdNmsByAbbr(String abbr) { + StdNmsDO stdNms = stdNmsService.getStdNmsByAbbr(abbr); + return success(BeanUtils.toBean(stdNms, StdNmsRespDTO.class)); + } + + @Override + public CommonResult> getStdNmsListByAbbrs(Collection abbrs) { + List stdNmsList = stdNmsService.getStdNmsListByAbbrs(abbrs); + return success(BeanUtils.toBean(stdNmsList, StdNmsRespDTO.class)); + } + +} diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/BusinessFileController.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/BusinessFileController.java new file mode 100644 index 00000000..86d9a6d0 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/BusinessFileController.java @@ -0,0 +1,111 @@ +package cn.iocoder.yudao.module.infra.controller.admin.businessfile; + +import org.springframework.web.bind.annotation.*; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import jakarta.validation.constraints.*; +import jakarta.validation.*; +import jakarta.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.infra.controller.admin.businessfile.vo.*; +import cn.iocoder.yudao.module.infra.dal.dataobject.businessfile.BusinessFileDO; +import cn.iocoder.yudao.module.infra.service.businessfile.BusinessFileService; + +@Tag(name = "管理后台 - 业务附件关联") +@RestController +@RequestMapping("/infra/business-file") +@Validated +public class BusinessFileController { + + @Resource + private BusinessFileService businessFileService; + + @PostMapping("/create") + @Operation(summary = "创建业务附件关联") + @PreAuthorize("@ss.hasPermission('infra:business-file:create')") + public CommonResult createBusinessFile(@Valid @RequestBody BusinessFileSaveReqVO createReqVO) { + return success(businessFileService.createBusinessFile(createReqVO)); + } + + @PostMapping("/batch-create") + @Operation(summary = "批量创建业务附件关联") + @PreAuthorize("@ss.hasPermission('infra:business-file:create')") + public CommonResult> batchCreateBusinessFile(@Valid @RequestBody List createReqVOList) { + return success(businessFileService.batchCreateBusinessFile(createReqVOList)); + } + + @PutMapping("/update") + @Operation(summary = "更新业务附件关联") + @PreAuthorize("@ss.hasPermission('infra:business-file:update')") + public CommonResult updateBusinessFile(@Valid @RequestBody BusinessFileSaveReqVO updateReqVO) { + businessFileService.updateBusinessFile(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除业务附件关联") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('infra:business-file:delete')") + public CommonResult deleteBusinessFile(@RequestParam("id") Long id) { + businessFileService.deleteBusinessFile(id); + return success(true); + } + + @DeleteMapping("/delete-list") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除业务附件关联") + @PreAuthorize("@ss.hasPermission('infra:business-file:delete')") + public CommonResult deleteBusinessFileList(@RequestParam("ids") List ids) { + businessFileService.deleteBusinessFileListByIds(ids); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得业务附件关联") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('infra:business-file:query')") + public CommonResult getBusinessFile(@RequestParam("id") Long id) { + BusinessFileDO businessFile = businessFileService.getBusinessFile(id); + return success(BeanUtils.toBean(businessFile, BusinessFileRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得业务附件关联分页") + @PreAuthorize("@ss.hasPermission('infra:business-file:query')") + public CommonResult> getBusinessFilePage(@Valid BusinessFilePageReqVO pageReqVO) { + PageResult pageResult = businessFileService.getBusinessFilePage(pageReqVO); + return success(BeanUtils.toBean(pageResult, BusinessFileRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出业务附件关联 Excel") + @PreAuthorize("@ss.hasPermission('infra:business-file:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportBusinessFileExcel(@Valid BusinessFilePageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = businessFileService.getBusinessFilePage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "业务附件关联.xls", "数据", BusinessFileRespVO.class, + BeanUtils.toBean(list, BusinessFileRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/vo/BusinessFilePageReqVO.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/vo/BusinessFilePageReqVO.java new file mode 100644 index 00000000..b9858ea2 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/vo/BusinessFilePageReqVO.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.module.infra.controller.admin.businessfile.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 业务附件关联分页 Request VO") +@Data +public class BusinessFilePageReqVO extends PageParam { + + @Schema(description = "业务Id", example = "24322") + private Long businessId; + + @Schema(description = "业务编码") + private String businessCode; + + @Schema(description = "附件fileId", example = "10125") + private Long fileId; + + @Schema(description = "附件名称", example = "李四") + private String fileName; + + @Schema(description = "附件来源") + private String source; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/vo/BusinessFileRespVO.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/vo/BusinessFileRespVO.java new file mode 100644 index 00000000..db7b5855 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/vo/BusinessFileRespVO.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.module.infra.controller.admin.businessfile.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 业务附件关联 Response VO") +@Data +@ExcelIgnoreUnannotated +public class BusinessFileRespVO { + + @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "29216") + @ExcelProperty("主键ID") + private Long id; + + @Schema(description = "业务Id", requiredMode = Schema.RequiredMode.REQUIRED, example = "24322") + @ExcelProperty("业务Id") + private Long businessId; + + @Schema(description = "业务编码") + @ExcelProperty("业务编码") + private String businessCode; + + @Schema(description = "附件fileId", requiredMode = Schema.RequiredMode.REQUIRED, example = "10125") + @ExcelProperty("附件fileId") + private Long fileId; + + @Schema(description = "附件名称", example = "李四") + @ExcelProperty("附件名称") + private String fileName; + + @Schema(description = "附件来源") + @ExcelProperty("附件来源") + private String source; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/vo/BusinessFileSaveReqVO.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/vo/BusinessFileSaveReqVO.java new file mode 100644 index 00000000..61a74598 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/businessfile/vo/BusinessFileSaveReqVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.infra.controller.admin.businessfile.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - 业务附件关联新增/修改 Request VO") +@Data +public class BusinessFileSaveReqVO { + + @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "29216") + private Long id; + + @Schema(description = "附件Id", example = "李四") + private Long fileId; + + @Schema(description = "业务Id", example = "李四") + private Long businessId; + + @Schema(description = "附件名称", example = "李四") + private String fileName; + + @Schema(description = "附件来源") + private String source; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/CodegenController.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/CodegenController.java index c577c8fa..12fdd2b8 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/CodegenController.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/CodegenController.java @@ -126,12 +126,17 @@ public class CodegenController { @GetMapping("/preview") @Parameters({ @Parameter(name = "tableId", description = "表编号", required = true, example = "1024"), - @Parameter(name = "isBusiness", description = "是否业务基类", example = "false") + @Parameter(name = "isBusiness", description = "是否业务基类", example = "false"), + @Parameter(name = "isStandardized", description = "是否标准化", example = "false"), + @Parameter(name = "isFileUpload", description = "是否包含附件上传能力", example = "false") }) @PreAuthorize("@ss.hasPermission('infra:codegen:preview')") - public CommonResult> previewCodegen(@RequestParam("tableId") Long tableId, - @RequestParam(value = "isBusiness", required = false, defaultValue = "false") Boolean isBusiness) { - Map codes = codegenService.generationCodes(tableId, isBusiness); + public CommonResult> previewCodegen( + @RequestParam("tableId") Long tableId, + @RequestParam(value = "isBusiness", required = false, defaultValue = "false") Boolean isBusiness, + @RequestParam(value = "isStandardized", required = false, defaultValue = "false") Boolean isStandardized, + @RequestParam(value = "isFileUpload", required = false, defaultValue = "false") Boolean isFileUpload) { + Map codes = codegenService.generationCodes(tableId, isBusiness, isStandardized, isFileUpload); return success(CodegenConvert.INSTANCE.convert(codes)); } @@ -139,14 +144,19 @@ public class CodegenController { @GetMapping("/download") @Parameters({ @Parameter(name = "tableId", description = "表编号", required = true, example = "1024"), - @Parameter(name = "isBusiness", description = "是否业务基类", example = "false") + @Parameter(name = "isBusiness", description = "是否业务基类", example = "false"), + @Parameter(name = "isStandardized", description = "是否标准化", example = "false"), + @Parameter(name = "isFileUpload", description = "是否包含附件上传能力", example = "false") }) @PreAuthorize("@ss.hasPermission('infra:codegen:download')") - public void downloadCodegen(@RequestParam("tableId") Long tableId, - @RequestParam(value = "isBusiness", required = false, defaultValue = "false") Boolean isBusiness, - HttpServletResponse response) throws IOException { - // 生成代码,传递 isBusiness - Map codes = codegenService.generationCodes(tableId, isBusiness); + public void downloadCodegen( + @RequestParam("tableId") Long tableId, + @RequestParam(value = "isBusiness", required = false, defaultValue = "false") Boolean isBusiness, + @RequestParam(value = "isStandardized", required = false, defaultValue = "false") Boolean isStandardized, + @RequestParam(value = "isFileUpload", required = false, defaultValue = "false") Boolean isFileUpload, + HttpServletResponse response) throws IOException { + // 生成代码,传递 isBusiness、isStandardized、isFileUpload + Map codes = codegenService.generationCodes(tableId, isBusiness, isStandardized, isFileUpload); // 构建 zip 包 String[] paths = codes.keySet().toArray(new String[0]); ByteArrayInputStream[] ins = codes.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new); diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FileRespVO.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FileRespVO.java index d4d4223e..3c7e4fff 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FileRespVO.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FileRespVO.java @@ -76,7 +76,7 @@ public class FileRespVO { if (presignedUrl == null || presignedUrl.isEmpty()) { return null; } - String base64PresignedUrl = Base64.getUrlEncoder().encodeToString(presignedUrl.getBytes(StandardCharsets.UTF_8)); + String base64PresignedUrl = Base64.getEncoder().encodeToString(presignedUrl.getBytes(StandardCharsets.UTF_8)); String timestamp = String.valueOf(System.currentTimeMillis()); String watermark = SpringUtils.getProperty("aj.captcha.water-mark", "中国铜业"); return onlinePreview + base64PresignedUrl + "&t=" + timestamp + "&watermarkTxt=" + watermark; diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/stdnms/StdNmsController.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms/stdnms/StdNmsController.java similarity index 90% rename from yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/stdnms/StdNmsController.java rename to yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms/stdnms/StdNmsController.java index 6f2e174d..fb11064a 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/stdnms/StdNmsController.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms/stdnms/StdNmsController.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.system.controller.admin.stdnms; +package cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms; import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; import cn.iocoder.yudao.framework.common.pojo.CommonResult; @@ -7,11 +7,11 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; -import cn.iocoder.yudao.module.system.controller.admin.stdnms.vo.StdNmsPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.stdnms.vo.StdNmsRespVO; -import cn.iocoder.yudao.module.system.controller.admin.stdnms.vo.StdNmsSaveReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.stdnms.StdNmsDO; -import cn.iocoder.yudao.module.system.service.stdnms.StdNmsService; +import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsRespVO; +import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsSaveReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO; +import cn.iocoder.yudao.module.infra.stdnms.StdNmsService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -32,7 +32,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Tag(name = "管理后台 - 数据命名与简写标准") @RestController -@RequestMapping("/system/std-nms") +@RequestMapping("/infra/std-nms") @Validated public class StdNmsController { diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/stdnms/vo/StdNmsPageReqVO.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms/stdnms/vo/StdNmsPageReqVO.java similarity index 88% rename from yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/stdnms/vo/StdNmsPageReqVO.java rename to yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms/stdnms/vo/StdNmsPageReqVO.java index e84c6235..ab50d46e 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/stdnms/vo/StdNmsPageReqVO.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms/stdnms/vo/StdNmsPageReqVO.java @@ -1,10 +1,10 @@ -package cn.iocoder.yudao.module.system.controller.admin.stdnms.vo; +package cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo; -import lombok.*; -import java.util.*; -import io.swagger.v3.oas.annotations.media.Schema; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; + import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/stdnms/vo/StdNmsRespVO.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms/stdnms/vo/StdNmsRespVO.java similarity index 82% rename from yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/stdnms/vo/StdNmsRespVO.java rename to yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms/stdnms/vo/StdNmsRespVO.java index 85f3bd7a..47be53e7 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/stdnms/vo/StdNmsRespVO.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms/stdnms/vo/StdNmsRespVO.java @@ -1,11 +1,11 @@ -package cn.iocoder.yudao.module.system.controller.admin.stdnms.vo; +package cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import java.util.*; -import org.springframework.format.annotation.DateTimeFormat; +import lombok.Data; + import java.time.LocalDateTime; -import com.alibaba.excel.annotation.*; @Schema(description = "管理后台 - 数据命名与简写标准 Response VO") @Data diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/stdnms/vo/StdNmsSaveReqVO.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms/stdnms/vo/StdNmsSaveReqVO.java similarity index 84% rename from yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/stdnms/vo/StdNmsSaveReqVO.java rename to yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms/stdnms/vo/StdNmsSaveReqVO.java index a03f1803..be96fa8f 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/stdnms/vo/StdNmsSaveReqVO.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/stdnms/stdnms/vo/StdNmsSaveReqVO.java @@ -1,9 +1,8 @@ -package cn.iocoder.yudao.module.system.controller.admin.stdnms.vo; +package cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import java.util.*; -import jakarta.validation.constraints.*; +import jakarta.validation.constraints.NotEmpty; +import lombok.Data; @Schema(description = "管理后台 - 数据命名与简写标准新增/修改 Request VO") @Data diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/businessfile/BusinessFileDO.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/businessfile/BusinessFileDO.java new file mode 100644 index 00000000..39de74b9 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/businessfile/BusinessFileDO.java @@ -0,0 +1,53 @@ +package cn.iocoder.yudao.module.infra.dal.dataobject.businessfile; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.*; +import lombok.*; +/** +* 业务附件关联 DO +* +* @author 后台管理 +*/ +@TableName("infra_bsn_file") +@KeySequence("infra_bsn_file_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class BusinessFileDO extends BaseDO { + + /** + * 主键ID + */ + @TableId(type = IdType.ASSIGN_ID) + private Long id; + /** + * 业务Id + */ + @TableField("BSN_ID") + private Long businessId; + /** + * 业务编码 + */ + @TableField("BSN_CD") + private String businessCode; + /** + * 附件fileId + */ + @TableField("FILE_ID") + private Long fileId; + /** + * 附件名称 + */ + @TableField("FILE_NAME") + private String fileName; + /** + * 附件来源 + */ + @TableField("SRC") + private String source; + + + } \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/file/FileDO.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/file/FileDO.java index f65e9b1f..44fc65c2 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/file/FileDO.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/file/FileDO.java @@ -2,11 +2,9 @@ package cn.iocoder.yudao.module.infra.dal.dataobject.file; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.*; import lombok.*; +import org.apache.commons.lang3.StringUtils; /** * 文件表 @@ -67,4 +65,16 @@ public class FileDO extends BaseDO { */ private String aesIv; + /** + * 是否加密 + *

+ * 例如,使用 AES 加密时,isEncrypted = true;未加密时,isEncrypted = false。 + */ + @TableField(exist = false) // 不在数据库中 + private Boolean isEncrypted; + + + public Boolean getIsEncrypted() { + return !StringUtils.isBlank(aesIv); + } } diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/stdnms/StdNmsDO.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/stdnms/stdnms/StdNmsDO.java similarity index 79% rename from yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/stdnms/StdNmsDO.java rename to yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/stdnms/stdnms/StdNmsDO.java index 71832e93..0b8299e9 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/stdnms/StdNmsDO.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/stdnms/stdnms/StdNmsDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.system.dal.dataobject.stdnms; +package cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.IdType; @@ -11,8 +11,8 @@ import lombok.*; * * @author 后台管理 */ -@TableName("system_std_nms") -@KeySequence("system_std_nms_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@TableName("infra_std_nms") +@KeySequence("infra_std_nms_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/businessfile/BusinessFileMapper.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/businessfile/BusinessFileMapper.java new file mode 100644 index 00000000..24eac268 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/businessfile/BusinessFileMapper.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.infra.dal.mysql.businessfile; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.infra.dal.dataobject.businessfile.BusinessFileDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.infra.controller.admin.businessfile.vo.*; + +/** + * 业务附件关联 Mapper + * + * @author 后台管理 + */ +@Mapper +public interface BusinessFileMapper extends BaseMapperX { + + default PageResult selectPage(BusinessFilePageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(BusinessFileDO::getBusinessId, reqVO.getBusinessId()) + .eqIfPresent(BusinessFileDO::getBusinessCode, reqVO.getBusinessCode()) + .eqIfPresent(BusinessFileDO::getFileId, reqVO.getFileId()) + .likeIfPresent(BusinessFileDO::getFileName, reqVO.getFileName()) + .eqIfPresent(BusinessFileDO::getSource, reqVO.getSource()) + .betweenIfPresent(BusinessFileDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(BusinessFileDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/stdnms/StdNmsMapper.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/stdnms/StdNmsMapper.java similarity index 77% rename from yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/stdnms/StdNmsMapper.java rename to yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/stdnms/StdNmsMapper.java index e21cb124..bc2d5e3c 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/stdnms/StdNmsMapper.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/stdnms/StdNmsMapper.java @@ -1,9 +1,9 @@ -package cn.iocoder.yudao.module.system.dal.mysql.stdnms; +package cn.iocoder.yudao.module.infra.dal.mysql.stdnms; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.module.system.controller.admin.stdnms.vo.StdNmsPageReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.stdnms.StdNmsDO; +import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsPageReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO; import org.apache.ibatis.annotations.Mapper; import java.util.List; diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/businessfile/BusinessFileService.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/businessfile/BusinessFileService.java new file mode 100644 index 00000000..272eb800 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/businessfile/BusinessFileService.java @@ -0,0 +1,64 @@ +package cn.iocoder.yudao.module.infra.service.businessfile; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.infra.controller.admin.businessfile.vo.BusinessFilePageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.businessfile.vo.BusinessFileSaveReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.businessfile.BusinessFileDO; +import jakarta.validation.Valid; + +import java.util.List; + +/** + * 业务附件关联 Service 接口 + * + * @author 后台管理 + */ +public interface BusinessFileService { + + /** + * 创建业务附件关联 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createBusinessFile(@Valid BusinessFileSaveReqVO createReqVO); + + /** + * 更新业务附件关联 + * + * @param updateReqVO 更新信息 + */ + void updateBusinessFile(@Valid BusinessFileSaveReqVO updateReqVO); + + /** + * 删除业务附件关联 + * + * @param id 编号 + */ + void deleteBusinessFile(Long id); + + /** + * 批量删除业务附件关联 + * + * @param ids 编号 + */ + void deleteBusinessFileListByIds(List ids); + + /** + * 获得业务附件关联 + * + * @param id 编号 + * @return 业务附件关联 + */ + BusinessFileDO getBusinessFile(Long id); + + /** + * 获得业务附件关联分页 + * + * @param pageReqVO 分页查询 + * @return 业务附件关联分页 + */ + PageResult getBusinessFilePage(BusinessFilePageReqVO pageReqVO); + + List batchCreateBusinessFile(List createReqVOList); +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/businessfile/BusinessFileServiceImpl.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/businessfile/BusinessFileServiceImpl.java new file mode 100644 index 00000000..ccedb864 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/businessfile/BusinessFileServiceImpl.java @@ -0,0 +1,99 @@ +package cn.iocoder.yudao.module.infra.service.businessfile; + +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.infra.controller.admin.businessfile.vo.BusinessFilePageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.businessfile.vo.BusinessFileSaveReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.businessfile.BusinessFileDO; +import cn.iocoder.yudao.module.infra.dal.mysql.businessfile.BusinessFileMapper; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.ArrayList; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.BUSINESS_FILE_NOT_EXISTS; + +/** + * 业务附件关联 Service 实现类 + * + * @author 后台管理 + */ +@Service +@Validated +public class BusinessFileServiceImpl implements BusinessFileService { + + @Resource + private BusinessFileMapper businessFileMapper; + + @Override + public Long createBusinessFile(BusinessFileSaveReqVO createReqVO) { + // 插入 + BusinessFileDO businessFile = BeanUtils.toBean(createReqVO, BusinessFileDO.class); + businessFileMapper.insert(businessFile); + // 返回 + return businessFile.getId(); + } + + @Override + public void updateBusinessFile(BusinessFileSaveReqVO updateReqVO) { + // 校验存在 + validateBusinessFileExists(updateReqVO.getId()); + // 更新 + BusinessFileDO updateObj = BeanUtils.toBean(updateReqVO, BusinessFileDO.class); + businessFileMapper.updateById(updateObj); + } + + @Override + public void deleteBusinessFile(Long id) { + // 校验存在 + validateBusinessFileExists(id); + // 删除 + businessFileMapper.deleteById(id); + } + + @Override + public void deleteBusinessFileListByIds(List ids) { + // 校验存在 + validateBusinessFileExists(ids); + // 删除 + businessFileMapper.deleteByIds(ids); + } + + private void validateBusinessFileExists(List ids) { + List list = businessFileMapper.selectByIds(ids); + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { + throw exception(BUSINESS_FILE_NOT_EXISTS); + } + } + + private void validateBusinessFileExists(Long id) { + if (businessFileMapper.selectById(id) == null) { + throw exception(BUSINESS_FILE_NOT_EXISTS); + } + } + + @Override + public BusinessFileDO getBusinessFile(Long id) { + return businessFileMapper.selectById(id); + } + + @Override + public PageResult getBusinessFilePage(BusinessFilePageReqVO pageReqVO) { + return businessFileMapper.selectPage(pageReqVO); + } + + @Override + public List batchCreateBusinessFile(List createReqVOList) { + List businessFileList = BeanUtils.toBean(createReqVOList, BusinessFileDO.class); + List ids = new ArrayList<>(); + for (BusinessFileDO businessFile : businessFileList) { + businessFileMapper.insert(businessFile); + ids.add(businessFile.getId()); + } + return ids; + } +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenService.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenService.java index 64835408..61e3879f 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenService.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenService.java @@ -81,18 +81,14 @@ public interface CodegenService { List getCodegenColumnListByTableId(Long tableId); /** - * 执行指定表的代码生成 - * - * @param tableId 表编号 - * @return 生成结果。key 为文件路径,value 为对应的代码内容 - */ - /** - * 执行指定表的代码生成,支持业务基类继承 + * 执行指定表的代码生成,支持业务基类继承、标准化和附件上传能力 * @param tableId 表编号 * @param isBusiness 是否业务基类 - * @return 生成结果 + * @param isStandardized 是否标准化 + * @param isFileUpload 是否包含附件上传能力 + * @return 生成结果。key 为文件路径,value 为对应的代码内容 */ - Map generationCodes(Long tableId, Boolean isBusiness); + Map generationCodes(Long tableId, Boolean isBusiness, Boolean isStandardized, Boolean isFileUpload); /** * 兼容原有接口,默认 isBusiness=false diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java index c50ebcc2..a1ae6f91 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java @@ -246,7 +246,7 @@ public class CodegenServiceImpl implements CodegenService { /** * 执行指定表的代码生成,支持业务基类继承 */ - public Map generationCodes(Long tableId, Boolean isBusiness) { + public Map generationCodes(Long tableId, Boolean isBusiness, Boolean isStandardized, Boolean isFileUpload) { // 校验是否已经存在 CodegenTableDO table = codegenTableMapper.selectById(tableId); if (table == null) { @@ -278,8 +278,13 @@ public class CodegenServiceImpl implements CodegenService { } } - // 执行生成,传递 isBusiness - return codegenEngine.execute(table, columns, subTables, subColumnsList, isBusiness != null && isBusiness); + // 执行生成,传递 extraParam + Map extraParam = new HashMap<>(); + extraParam.put("isBusiness", isBusiness != null && isBusiness); + extraParam.put("isStandardized", isStandardized != null && isStandardized); + extraParam.put("isFileUpload", isFileUpload != null && isFileUpload); + + return codegenEngine.execute(table, columns, subTables, subColumnsList, extraParam); } /** @@ -287,7 +292,7 @@ public class CodegenServiceImpl implements CodegenService { */ @Override public Map generationCodes(Long tableId) { - return generationCodes(tableId, false); + return generationCodes(tableId, false, false, false); } @Override diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java index 5880d47d..39459d47 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java @@ -29,11 +29,13 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO; import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenVOTypeEnum; import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; +import cn.iocoder.yudao.module.infra.stdnms.StdNmsService; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableTable; @@ -46,9 +48,14 @@ import org.springframework.stereotype.Component; import org.springframework.util.ClassUtils; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import static cn.hutool.core.map.MapUtil.getStr; import static cn.hutool.core.text.CharSequenceUtil.*; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.STD_ABBR_NOT_EXISTS; /** * 代码生成的引擎,用于具体生成代码 @@ -59,6 +66,8 @@ import static cn.hutool.core.text.CharSequenceUtil.*; */ @Component public class CodegenEngine { + @Resource + private StdNmsService stdNmsService; /** * 后端的模板配置 @@ -273,12 +282,22 @@ public class CodegenEngine { * 代码生成,支持业务基类继承 * @param isBusiness 是否业务基类 */ + /** + * 代码生成,支持传递额外参数 + * @param extraParam 额外参数,如 isBusiness + */ public Map execute(CodegenTableDO table, List columns, - List subTables, List> subColumnsList, boolean isBusiness) { + List subTables, List> subColumnsList, Map extraParam) { // 1.1 初始化 bindMap 上下文 Map bindingMap = initBindingMap(table, columns, subTables, subColumnsList); - // 传递 isBusiness 到模板 - bindingMap.put("isBusiness", isBusiness); + + // 标准化命名校验逻辑 + standardizedJavaField(columns, subColumnsList, extraParam); + + // 传递 extraParam 到模板 + if (extraParam != null) { + bindingMap.putAll(extraParam); + } // 1.2 获得模版 Map templates = getTemplates(table.getFrontType()); @@ -308,12 +327,76 @@ public class CodegenEngine { return result; } + /** + * 如果是标准化的字段名需要针对标准命名表映射 javaField 全名 + * @param columns 主表的字段集合 + * @param subColumnsList 子表的字段集合 + * @param extraParam 额外参数,包含 isStandardized 标志 + */ + private void standardizedJavaField(List columns, List> subColumnsList, Map extraParam) { + if (extraParam != null && Boolean.TRUE.equals(extraParam.get("isStandardized"))) { + List allColumns = new ArrayList<>(); + allColumns.addAll(columns); + allColumns.addAll(Optional.ofNullable(subColumnsList).orElse(new ArrayList<>()).stream().flatMap(Collection::stream).toList()); + // BusinessBaseDO 字段集合 + Set businessBaseFields = CodegenBuilder.BUSINESS_BASE_DO_FIELDS; + Map abbrToFullName = new HashMap<>(); + Set columnNameSet = allColumns.stream() + // 跳过 BusinessBaseDO 字段 + .filter(x -> !businessBaseFields.contains(x.getJavaField())) + .map(CodegenColumnDO::getColumnName).collect(Collectors.toSet()); + // 分词(如驼峰转词组) + Set phrases = columnNameSet.stream().map(String::toLowerCase) + // 分割,最终使用大写 + .flatMap(y -> Arrays.stream(y.split("_"))).map(String::toUpperCase) + .collect(Collectors.toSet()); + List checkedData = stdNmsService.getStdNmsListByAbbrs(phrases); + Set stdAbbrSet = checkedData.stream().map(StdNmsDO::getAbbr).collect(Collectors.toSet()); + phrases.removeAll(stdAbbrSet); + if (CollUtil.isNotEmpty(phrases)) { + throw exception(STD_ABBR_NOT_EXISTS, String.join(",", phrases)); + } + Map stdNmsAbbrMap = new ConcurrentHashMap<>(); + checkedData.forEach(x-> { + stdNmsAbbrMap.put(x.getAbbr(), x.getWord()); + }); + + // 构造列名和全名的映射(需要根据短语映射的关系进行拼接) + abbrToFullName = allColumns.stream() + // 跳过 BusinessBaseDO 字段 + .filter(x -> !businessBaseFields.contains(x.getJavaField())) + .collect(Collectors.toMap( + CodegenColumnDO::getJavaField, + column -> { + // 1.1.1 获取短语 + String columnName = column.getColumnName().toUpperCase(); + List words = new LinkedList<>(Arrays.asList(columnName.split("_"))); + List fullWords = words.stream().map(stdNmsAbbrMap::get).map(String::toLowerCase).toList(); + // 拼接 fullName 除第一个单词外,首字母需要大写 + return IntStream.range(0, fullWords.size()) + .mapToObj(i -> i == 0 ? fullWords.get(i) : Character.toUpperCase(fullWords.get(i).charAt(0)) + fullWords.get(i).substring(1)) + .collect(Collectors.joining()); + }, + (v1, v2) -> v1, + HashMap::new + )); + // 替换 所有列的 javaField + Map finalAbbrToFullName = abbrToFullName; + columns.stream().filter(x -> !businessBaseFields.contains(x.getJavaField())).forEach(column -> { + String fullName = finalAbbrToFullName.get(column.getJavaField()); + column.setJavaField(fullName); + }); + } + } + /** * 兼容原有接口,默认 isBusiness=false */ public Map execute(CodegenTableDO table, List columns, List subTables, List> subColumnsList) { - return execute(table, columns, subTables, subColumnsList, false); + Map extraParam = new HashMap<>(); + extraParam.put("isBusiness", false); + return execute(table, columns, subTables, subColumnsList, extraParam); } private void generateCode(Map result, String vmPath, diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java index 0b94078f..70069904 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java @@ -124,15 +124,7 @@ public class FileServiceImpl implements FileService { @Override public FileRespVO createFileWhitReturn(byte[] content, String name, String directory, String type, Boolean encrypt) { FileDO entity = uploadFile(content, name, directory, type, encrypt); - return new FileRespVO() - .setId(entity.getId()) - .setName(entity.getName()) - .setPath(entity.getPath()) - .setUrl(entity.getUrl()) - .setType(entity.getType()) - .setSize(entity.getSize()) - .setConfigId(entity.getConfigId()) - .setIsEncrypted(entity.getAesIv() != null && !entity.getAesIv().isEmpty()); + return BeanUtils.toBean(entity, FileRespVO.class); } private FileDO uploadFile(byte[] content, String name, String directory, String type, Boolean encrypt) throws Exception { diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/stdnms/StdNmsService.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/stdnms/StdNmsService.java similarity index 59% rename from yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/stdnms/StdNmsService.java rename to yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/stdnms/StdNmsService.java index 3699cd00..df15aaca 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/stdnms/StdNmsService.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/stdnms/StdNmsService.java @@ -1,11 +1,13 @@ -package cn.iocoder.yudao.module.system.service.stdnms; +package cn.iocoder.yudao.module.infra.stdnms; -import java.util.*; -import jakarta.validation.*; -import cn.iocoder.yudao.module.system.controller.admin.stdnms.vo.*; -import cn.iocoder.yudao.module.system.dal.dataobject.stdnms.StdNmsDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsSaveReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO; +import jakarta.validation.Valid; + +import java.util.Collection; +import java.util.List; /** * 数据命名与简写标准 Service 接口 @@ -58,5 +60,17 @@ public interface StdNmsService { * @return 数据命名与简写标准分页 */ PageResult getStdNmsPage(StdNmsPageReqVO pageReqVO); + /** + * 根据缩写查询数据命名与简写标准 + * @param abbr 缩写 + * @return 数据命名与简写标准 + */ + StdNmsDO getStdNmsByAbbr(String abbr); + /** + * 根据缩写列表查询数据命名与简写标准 + * @param abbrs 缩写列表 + * @return 数据命名与简写标准列表 + */ + List getStdNmsListByAbbrs(Collection abbrs); } \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/stdnms/StdNmsServiceImpl.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/stdnms/StdNmsServiceImpl.java similarity index 65% rename from yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/stdnms/StdNmsServiceImpl.java rename to yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/stdnms/StdNmsServiceImpl.java index 3bd104cb..68a165b2 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/stdnms/StdNmsServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/stdnms/StdNmsServiceImpl.java @@ -1,24 +1,23 @@ -package cn.iocoder.yudao.module.system.service.stdnms; +package cn.iocoder.yudao.module.infra.stdnms; import cn.hutool.core.collection.CollUtil; -import org.springframework.stereotype.Service; -import jakarta.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.transaction.annotation.Transactional; - -import java.util.*; -import cn.iocoder.yudao.module.system.controller.admin.stdnms.vo.*; -import cn.iocoder.yudao.module.system.dal.dataobject.stdnms.StdNmsDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; +import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsSaveReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO; +import cn.iocoder.yudao.module.infra.dal.mysql.stdnms.StdNmsMapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; -import cn.iocoder.yudao.module.system.dal.mysql.stdnms.StdNmsMapper; +import java.util.Collection; +import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.STD_NMS_NOT_EXISTS; /** * 数据命名与简写标准 Service 实现类 @@ -27,14 +26,28 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; */ @Service @Validated +@TenantIgnore public class StdNmsServiceImpl implements StdNmsService { @Resource private StdNmsMapper stdNmsMapper; + @Override + public StdNmsDO getStdNmsByAbbr(String abbr) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("abbr", abbr); + return stdNmsMapper.selectOne(queryWrapper); + } + + @Override + public List getStdNmsListByAbbrs(Collection abbrs) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in("abbr", abbrs); + return stdNmsMapper.selectList(queryWrapper); + } + @Override public Long createStdNms(StdNmsSaveReqVO createReqVO) { - // 插入 StdNmsDO stdNms = BeanUtils.toBean(createReqVO, StdNmsDO.class); stdNmsMapper.insert(stdNms); // 返回 diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/resources/application.yaml b/yudao-module-infra/yudao-module-infra-server/src/main/resources/application.yaml index 8abab8d4..d336b3bf 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/resources/application.yaml +++ b/yudao-module-infra/yudao-module-infra-server/src/main/resources/application.yaml @@ -173,5 +173,6 @@ yudao: enable: true ignore-urls: ignore-tables: + - infra_std_nms debug: false diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/controller/controller.vm b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/controller/controller.vm index ec9f3282..226b2329 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/controller/controller.vm +++ b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/controller/controller.vm @@ -3,10 +3,16 @@ package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePac import org.springframework.web.bind.annotation.*; import ${jakartaPackage}.annotation.Resource; import org.springframework.validation.annotation.Validated; -#if ($sceneEnum.scene == 1)import org.springframework.security.access.prepost.PreAuthorize;#end +#if ($sceneEnum.scene == 1) +import org.springframework.security.access.prepost.PreAuthorize; +#end #if($isBusiness && $isBusiness == true) import ${basePackage}.framework.business.interceptor.BusinessControllerMarker; #end +#if($isFileUpload && $isFileUpload == true) +import ${basePackage}.framework.business.annotation.FileUploadController; +import ${basePackage}.framework.business.controller.AbstractFileUploadController; +#end import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Parameter; @@ -42,11 +48,27 @@ import ${basePackage}.module.${table.moduleName}.service.${table.businessName}.$ ##二级的 businessName 暂时不算在 HTTP 路径上,可以根据需要写 @RequestMapping("/${table.moduleName}/${simpleClassName_strikeCase}") @Validated +#if($isFileUpload && $isFileUpload == true) +@FileUploadController(source = "${table.moduleName}.${table.businessName}") +#end ## 支持业务基类标记:isBusiness=true 时继承 BusinessControllerMarker -#if($isBusiness && $isBusiness == true) +#if($isBusiness && $isBusiness == true && (!$isFileUpload || !$isFileUpload == true)) public class ${sceneEnum.prefixClass}${table.className}Controller implements BusinessControllerMarker { -#else +#elseif((!$isBusiness || !$isBusiness == true) && (!$isFileUpload || !$isFileUpload == true)) public class ${sceneEnum.prefixClass}${table.className}Controller { +#elseif($isBusiness && $isBusiness == true && $isFileUpload && $isFileUpload == true) +public class ${sceneEnum.prefixClass}${table.className}Controller extends AbstractFileUploadController implements BusinessControllerMarker{ +#elseif((!$isBusiness || !$isBusiness == true) && $isFileUpload && $isFileUpload == true) +public class ${sceneEnum.prefixClass}${table.className}Controller extends AbstractFileUploadController { +#end + +#if($isFileUpload && $isFileUpload == true) + static { + FileUploadController annotation = DemoContractController.class.getAnnotation(FileUploadController.class); + if (annotation != null) { + setFileUploadInfo(annotation); + } + } #end @Resource @@ -57,7 +79,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')") #end - public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${saveReqVOClass} ${saveReqVOVar}) { + public CommonResult<${respVOClass}> create${simpleClassName}(@Valid @RequestBody ${saveReqVOClass} ${saveReqVOVar}) { return success(${classNameVar}Service.create${simpleClassName}(${saveReqVOVar})); } diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/dal/do.vm b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/dal/do.vm index 9c718296..ace9f98a 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/dal/do.vm +++ b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/dal/do.vm @@ -3,12 +3,12 @@ package ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.busines import lombok.*; import java.util.*; #foreach ($column in $columns) -#if (${column.javaType} == "BigDecimal") -import java.math.BigDecimal; -#end -#if (${column.javaType} == "LocalDateTime") -import java.time.LocalDateTime; -#end + #if (${column.javaType} == "BigDecimal") + import java.math.BigDecimal; + #end + #if (${column.javaType} == "LocalDateTime") + import java.time.LocalDateTime; + #end #end import com.baomidou.mybatisplus.annotation.*; ## 导入基类 @@ -21,19 +21,19 @@ import ${BaseDOClassName}; #if ($voType == 20) import io.swagger.v3.oas.annotations.media.Schema; import com.alibaba.excel.annotation.*; -#foreach ($column in $columns) - #if ("$!column.dictType" != "")## 有设置数据字典 + #foreach ($column in $columns) + #if ("$!column.dictType" != "")## 有设置数据字典 import ${DictFormatClassName}; import ${DictConvertClassName}; - #break + #break + #end #end #end -#end /** - * ${table.classComment} DO - * - * @author ${table.author} - */ +* ${table.classComment} DO +* +* @author ${table.author} +*/ @TableName("${table.tableName.toLowerCase()}") @KeySequence("${table.tableName.toLowerCase()}_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @@ -48,8 +48,8 @@ import com.alibaba.excel.annotation.*; @ExcelIgnoreUnannotated #end /** - * 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO - */ +* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO +*/ #if($isBusiness && $isBusiness == true) public class ${table.className}DO extends BusinessBaseDO { #else @@ -58,67 +58,53 @@ public class ${table.className}DO extends BaseDO { ## 特殊:树表专属逻辑 #if ( $table.templateType == 2 ) - public static final Long ${treeParentColumn_javaField_underlineCase.toUpperCase()}_ROOT = 0L; +public static final Long ${treeParentColumn_javaField_underlineCase.toUpperCase()}_ROOT = 0L; #end +## 字段定义宏,统一渲染字段 +#macro(renderField $column $isStandardized) + /** + * ${column.columnComment} + #if ("$!column.dictType" != "") + * + * 枚举 {@link TODO ${column.dictType} 对应的类} + #end + */ + #if (${column.primaryKey}) + @TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#else(type = IdType.ASSIGN_ID)#end + #end + #if ($voType == 20) + @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ( + "$!column.example" != ""), example = "${column.example}"#end) + #if ("$!column.dictType" != "") + @ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class) + @DictFormat("${column.dictType}") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 + #else + @ExcelProperty("${column.columnComment}") + #end + #end + #if($isStandardized == true) + #if(!${column.primaryKey}) + @TableField("${column.columnName}") + #end + #end + private ${column.javaType} ${column.javaField}; +#end + ## 字段定义,分支避免嵌套,保证 Velocity 兼容性 #if($isBusiness == true) -#foreach ($column in $columns) - #if (!${businessBaseDOFields.contains(${column.javaField})}) - /** - * ${column.columnComment} - #if ("$!column.dictType" != "")##处理枚举值 - * - * 枚举 {@link TODO ${column.dictType} 对应的类} + #foreach ($column in $columns) + #if (!${businessBaseDOFields.contains(${column.javaField})}) + #renderField($column $isStandardized) + #end #end - */ - #if (${column.primaryKey})##处理主键 - @TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#else(type = IdType.ASSIGN_ID)#end - #end -#if ($voType == 20) -## 1. 处理 Swagger 注解 - @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end) -## 2. 处理 Excel 导出 -#if ("$!column.dictType" != "")##处理枚举值 - @ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class) - @DictFormat("${column.dictType}") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 #else - @ExcelProperty("${column.columnComment}") -#end -#end -## 3. 处理字段定义 - private ${column.javaType} ${column.javaField}; - #end -#end -#else -#foreach ($column in $columns) - #if (!${baseDOFields.contains(${column.javaField})}) - /** - * ${column.columnComment} - #if ("$!column.dictType" != "")##处理枚举值 - * - * 枚举 {@link TODO ${column.dictType} 对应的类} + #foreach ($column in $columns) + #if (!${baseDOFields.contains(${column.javaField})}) + #renderField($column $isStandardized) + #end #end - */ - #if (${column.primaryKey})##处理主键 - @TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#else(type = IdType.ASSIGN_ID)#end - #end -#if ($voType == 20) -## 1. 处理 Swagger 注解 - @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end) -## 2. 处理 Excel 导出 -#if ("$!column.dictType" != "")##处理枚举值 - @ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class) - @DictFormat("${column.dictType}") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 -#else - @ExcelProperty("${column.columnComment}") -#end -#end -## 3. 处理字段定义 - private ${column.javaType} ${column.javaField}; - #end -#end #end ## 特殊:主子表专属逻辑(非 ERP 模式) @@ -126,21 +112,21 @@ public class ${table.className}DO extends BaseDO { #foreach ($subTable in $subTables) #set ($index = $foreach.count - 1) #if ( $subTable.subJoinMany) - /** - * ${subTable.classComment}列表 - */ - @Schema(description = "${subTable.classComment}列表") - @TableField(exist = false) - private List<${subTable.className}DO> ${subClassNameVars.get($index)}s; + /** + * ${subTable.classComment}列表 + */ + @Schema(description = "${subTable.classComment}列表") + @TableField(exist = false) + private List + <${subTable.className}DO> ${subClassNameVars.get($index)}s; #else - /** - * ${subTable.classComment} - */ - @Schema(description = "${subTable.classComment}") - @TableField(exist = false) - private ${subTable.className}DO ${subClassNameVars.get($index)}; + /** + * ${subTable.classComment} + */ + @Schema(description = "${subTable.classComment}") + @TableField(exist = false) + private ${subTable.className}DO ${subClassNameVars.get($index)}; #end #end #end - } \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/service/service.vm b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/service/service.vm index 1cc68bf3..5927ba9d 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/service/service.vm +++ b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/service/service.vm @@ -24,7 +24,7 @@ public interface ${table.className}Service { * @param ${saveReqVOVar} 创建信息 * @return 编号 */ - ${primaryColumn.javaType} create${simpleClassName}(@Valid ${saveReqVOClass} ${saveReqVOVar}); + ${respVOClass} create${simpleClassName}(@Valid ${saveReqVOClass} ${saveReqVOVar}); /** * 更新${table.classComment} diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/service/serviceImpl.vm b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/service/serviceImpl.vm index edea2e7a..93608a7b 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/service/serviceImpl.vm +++ b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/java/service/serviceImpl.vm @@ -52,7 +52,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 ) @Transactional(rollbackFor = Exception.class) #end - public ${primaryColumn.javaType} create${simpleClassName}(${saveReqVOClass} ${saveReqVOVar}) { + public ${respVOClass} create${simpleClassName}(${saveReqVOClass} ${saveReqVOVar}) { ## 特殊:树表专属逻辑 #if ( $table.templateType == 2 ) #set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写 @@ -86,7 +86,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service #end #end // 返回 - return ${classNameVar}.getId(); + return BeanUtils.toBean(${classNameVar}, ${respVOClass}.class); } @Override diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/vue3/api/api.ts.vm b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/vue3/api/api.ts.vm index a252884c..bf7a7960 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/vue3/api/api.ts.vm +++ b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/vue3/api/api.ts.vm @@ -64,6 +64,11 @@ export const ${simpleClassName}Api = { export${simpleClassName}: async (params) => { return await request.download({ url: `${baseURL}/export-excel`, params }) }, + + // 查询接口相关的文件上传元数据信息 + getFileUploadInfo: async () => { + return await request.get({url: `${baseURL}/upload-info`}) + } ## 特殊:主子表专属逻辑 #foreach ($subTable in $subTables) #set ($index = $foreach.count - 1) diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/vue3/views/form.vue.vm b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/vue3/views/form.vue.vm index e37474b8..c494c96c 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/vue3/views/form.vue.vm +++ b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/vue3/views/form.vue.vm @@ -115,6 +115,11 @@ #end #end #end + #if($isFileUpload && $isFileUpload == true) + + + + #end ## 特殊:主子表专属逻辑 #if ( $table.templateType == 10 || $table.templateType == 12 ) @@ -171,6 +176,9 @@ const formData = ref({ #end #end #end +#if($isFileUpload && $isFileUpload == true) + files: undefined +#end }) const formRules = reactive({ #foreach ($column in $columns) @@ -281,6 +289,9 @@ const resetForm = () => { $column.javaField: undefined, #end #end +#end +#if($isFileUpload && $isFileUpload == true) + files: undefined #end } formRef.value?.resetFields() diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/vue3/views/index.vue.vm b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/vue3/views/index.vue.vm index 399b58e3..985c37cb 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/vue3/views/index.vue.vm +++ b/yudao-module-infra/yudao-module-infra-server/src/main/resources/codegen/vue3/views/index.vue.vm @@ -181,7 +181,7 @@ #end #end #end - + @@ -248,6 +251,16 @@ import ${simpleClassName}Form from './${simpleClassName}Form.vue' import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue' #end #end +#if($isFileUpload && $isFileUpload == true) +import {useDialogStore} from '@/store/modules/dialog' +import {FileUploadInfoVO} from '@/api/infra/file' +const dialogStore = useDialogStore() +const openBusinessFile = async (id: string) => { + let fileUploadInfoVO : FileUploadInfoVO = await ${simpleClassName}Api.getFileUploadInfo(); + fileUploadInfoVO.businessId = id + dialogStore.openBusinessFileDialog(fileUploadInfoVO) +} +#end /** ${table.classComment} 列表 */ defineOptions({ name: '${table.className}' }) diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/resources/mapper/businessfile/BusinessFileMapper.xml b/yudao-module-infra/yudao-module-infra-server/src/main/resources/mapper/businessfile/BusinessFileMapper.xml new file mode 100644 index 00000000..2921a661 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-server/src/main/resources/mapper/businessfile/BusinessFileMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-server/src/main/resources/mapper/stdnms/StdNmsMapper.xml b/yudao-module-infra/yudao-module-infra-server/src/main/resources/mapper/stdnms/StdNmsMapper.xml similarity index 83% rename from yudao-module-system/yudao-module-system-server/src/main/resources/mapper/stdnms/StdNmsMapper.xml rename to yudao-module-infra/yudao-module-infra-server/src/main/resources/mapper/stdnms/StdNmsMapper.xml index cd8d25ab..9e42dcb1 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/resources/mapper/stdnms/StdNmsMapper.xml +++ b/yudao-module-infra/yudao-module-infra-server/src/main/resources/mapper/stdnms/StdNmsMapper.xml @@ -1,9 +1,9 @@ - + - + SELECT * FROM infra_std_nms AND LOWER(word) LIKE CONCAT('%', LOWER(#{word}), '%') diff --git a/yudao-module-infra/yudao-module-infra-server/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImplTest.java b/yudao-module-infra/yudao-module-infra-server/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImplTest.java index c0293306..dfef7866 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImplTest.java +++ b/yudao-module-infra/yudao-module-infra-server/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImplTest.java @@ -460,7 +460,9 @@ public class CodegenServiceImplTest extends BaseDbUnitTest { assertEquals(column01, columns.get(0)); assertEquals(column02, columns.get(1)); return true; - }), isNull(), isNull(), eq(false))).thenReturn(codes); + }), isNull(), isNull(), argThat(extraParam -> { + return extraParam != null && Boolean.FALSE.equals(extraParam.get("isBusiness")); + }))).thenReturn(codes); // 准备参数 Long tableId = table.getId(); @@ -509,7 +511,9 @@ public class CodegenServiceImplTest extends BaseDbUnitTest { assertEquals(1, columns.size()); assertPojoEquals(subColumn01, columns.size()); return true; - }), eq(false))).thenReturn(codes); + }), argThat(extraParam -> { + return extraParam != null && Boolean.FALSE.equals(extraParam.get("isBusiness")); + }))).thenReturn(codes); // 准备参数 Long tableId = table.getId(); diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index c7e3938f..2d66a7f8 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -176,6 +176,4 @@ public interface ErrorCodeConstants { // ========== 用户与部门关系 1-002-029-000 ========== ErrorCode USER_DEPT_NOT_EXISTS = new ErrorCode(1_002_029_000, "用户与部门关系不存在"); - // ========== 数据命名与简写标准 ========== - ErrorCode STD_NMS_NOT_EXISTS = new ErrorCode(1_002_030_000, "数据命名与简写标准不存在"); } diff --git a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/DemoContractController.java b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/DemoContractController.java index 7c9b9f4a..30e10021 100644 --- a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/DemoContractController.java +++ b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/DemoContractController.java @@ -1,41 +1,50 @@ package cn.iocoder.yudao.module.template.controller.admin.contract; -import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; -import cn.iocoder.yudao.framework.business.interceptor.BusinessControllerMarker; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import org.springframework.web.bind.annotation.*; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import cn.iocoder.yudao.framework.business.annotation.FileUploadController; +import cn.iocoder.yudao.framework.business.controller.AbstractFileUploadController; + +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import jakarta.validation.constraints.*; +import jakarta.validation.*; +import jakarta.servlet.http.*; +import java.util.*; +import java.io.IOException; + import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.module.template.controller.admin.contract.vo.DemoContractPageReqVO; -import cn.iocoder.yudao.module.template.controller.admin.contract.vo.DemoContractRespVO; -import cn.iocoder.yudao.module.template.controller.admin.contract.vo.DemoContractSaveReqVO; -import cn.iocoder.yudao.module.template.dal.dataobject.contract.DemoContractDO; -import cn.iocoder.yudao.module.template.service.contract.DemoContractService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.io.IOException; -import java.util.List; - -import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -/** - * @author chenbowen - */ +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.template.controller.admin.contract.vo.*; +import cn.iocoder.yudao.module.template.dal.dataobject.contract.DemoContractDO; +import cn.iocoder.yudao.module.template.service.contract.DemoContractService; + @Tag(name = "管理后台 - 合同") @RestController @RequestMapping("/template/demo-contract") @Validated -public class DemoContractController implements BusinessControllerMarker { +@FileUploadController(source = "template.contract") +public class DemoContractController extends AbstractFileUploadController { + + static { + FileUploadController annotation = DemoContractController.class.getAnnotation(FileUploadController.class); + if (annotation != null) { + setFileUploadInfo(annotation); + } + } @Resource private DemoContractService demoContractService; @@ -43,7 +52,7 @@ public class DemoContractController implements BusinessControllerMarker { @PostMapping("/create") @Operation(summary = "创建合同") @PreAuthorize("@ss.hasPermission('template:demo-contract:create')") - public CommonResult createDemoContract(@Valid @RequestBody DemoContractSaveReqVO createReqVO) { + public CommonResult createDemoContract(@Valid @RequestBody DemoContractSaveReqVO createReqVO) { return success(demoContractService.createDemoContract(createReqVO)); } diff --git a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/vo/DemoContractPageReqVO.java b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/vo/DemoContractPageReqVO.java index 6be5c5ca..2161efd5 100644 --- a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/vo/DemoContractPageReqVO.java +++ b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/vo/DemoContractPageReqVO.java @@ -17,13 +17,13 @@ public class DemoContractPageReqVO extends PageParam { @Schema(description = "合同编号") private String code; - @Schema(description = "合同名称", example = "李四") + @Schema(description = "合同名称", example = "赵六") private String name; - @Schema(description = "合同状态", example = "1") + @Schema(description = "合同状态", example = "2") private Short status; - @Schema(description = "流程实例ID", example = "24962") + @Schema(description = "流程实例ID", example = "10492") private Long processInstanceId; @Schema(description = "签订日期") @@ -41,26 +41,11 @@ public class DemoContractPageReqVO extends PageParam { @Schema(description = "合同金额") private BigDecimal amount; - @Schema(description = "备注", example = "随便") + @Schema(description = "备注", example = "你说的对") private String remark; @Schema(description = "创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] createTime; - @Schema(description = "公司ID", example = "4180") - private Long companyId; - - @Schema(description = "公司名称", example = "张三") - private String companyName; - - @Schema(description = "部门ID", example = "1707") - private Long deptId; - - @Schema(description = "部门名称", example = "张三") - private String deptName; - - @Schema(description = "岗位ID", example = "26779") - private Long postId; - } \ No newline at end of file diff --git a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/vo/DemoContractRespVO.java b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/vo/DemoContractRespVO.java index 8680fa21..2a87040d 100644 --- a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/vo/DemoContractRespVO.java +++ b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/vo/DemoContractRespVO.java @@ -13,7 +13,7 @@ import com.alibaba.excel.annotation.*; @ExcelIgnoreUnannotated public class DemoContractRespVO { - @Schema(description = "合同ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "9541") + @Schema(description = "合同ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "27417") @ExcelProperty("合同ID") private Long id; @@ -21,15 +21,15 @@ public class DemoContractRespVO { @ExcelProperty("合同编号") private String code; - @Schema(description = "合同名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") + @Schema(description = "合同名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") @ExcelProperty("合同名称") private String name; - @Schema(description = "合同状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @Schema(description = "合同状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @ExcelProperty("合同状态") private Short status; - @Schema(description = "流程实例ID", example = "24962") + @Schema(description = "流程实例ID", example = "10492") @ExcelProperty("流程实例ID") private Long processInstanceId; @@ -49,7 +49,7 @@ public class DemoContractRespVO { @ExcelProperty("合同金额") private BigDecimal amount; - @Schema(description = "备注", example = "随便") + @Schema(description = "备注", example = "你说的对") @ExcelProperty("备注") private String remark; @@ -57,24 +57,12 @@ public class DemoContractRespVO { @ExcelProperty("创建时间") private LocalDateTime createTime; - @Schema(description = "公司ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "4180") - @ExcelProperty("公司ID") - private Long companyId; - - @Schema(description = "公司名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") + @Schema(description = "公司名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") @ExcelProperty("公司名称") private String companyName; - @Schema(description = "部门ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1707") - @ExcelProperty("部门ID") - private Long deptId; - - @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") + @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") @ExcelProperty("部门名称") private String deptName; - @Schema(description = "岗位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26779") - @ExcelProperty("岗位ID") - private Long postId; - } \ No newline at end of file diff --git a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/vo/DemoContractSaveReqVO.java b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/vo/DemoContractSaveReqVO.java index ab520a95..fef50cb3 100644 --- a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/vo/DemoContractSaveReqVO.java +++ b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/controller/admin/contract/vo/DemoContractSaveReqVO.java @@ -1,24 +1,35 @@ package cn.iocoder.yudao.module.template.controller.admin.contract.vo; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - +import lombok.*; +import java.util.*; +import jakarta.validation.constraints.*; import java.math.BigDecimal; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; @Schema(description = "管理后台 - 合同新增/修改 Request VO") @Data public class DemoContractSaveReqVO { - @Schema(description = "合同ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "9541") + @Schema(description = "合同ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "27417") private Long id; - @Schema(description = "合同名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") + @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "合同编号不能为空") + private String code; + + @Schema(description = "合同名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") @NotEmpty(message = "合同名称不能为空") private String name; + @Schema(description = "合同状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @NotNull(message = "合同状态不能为空") + private Short status; + + @Schema(description = "流程实例ID", example = "10492") + private Long processInstanceId; + @Schema(description = "签订日期") private LocalDateTime signDate; @@ -32,23 +43,7 @@ public class DemoContractSaveReqVO { @NotNull(message = "合同金额不能为空") private BigDecimal amount; - @Schema(description = "备注", example = "随便") + @Schema(description = "备注", example = "你说的对") private String remark; - @Schema(description = "公司ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "4180") - private Long companyId; - - @Schema(description = "公司名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") - private String companyName; - - @Schema(description = "部门ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1707") - private Long deptId; - - @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") - private String deptName; - - @Schema(description = "岗位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26779") - @NotNull(message = "岗位ID不能为空") - private Long postId; - } \ No newline at end of file diff --git a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/dal/dataobject/contract/DemoContractDO.java b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/dal/dataobject/contract/DemoContractDO.java index 48253bbf..8003a5c2 100644 --- a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/dal/dataobject/contract/DemoContractDO.java +++ b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/dal/dataobject/contract/DemoContractDO.java @@ -1,20 +1,20 @@ package cn.iocoder.yudao.module.template.dal.dataobject.contract; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BusinessBaseDO; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; - -import java.math.BigDecimal; -import java.time.LocalDateTime; - +import java.util.*; + import java.time.LocalDateTime; + import java.time.LocalDateTime; + import java.time.LocalDateTime; + import java.math.BigDecimal; + import java.time.LocalDateTime; + import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; /** - * 合同 DO - * - * @author 后台管理 - */ +* 合同 DO +* +* @author 后台管理 +*/ @TableName("demo_contract") @KeySequence("demo_contract_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @@ -23,47 +23,73 @@ import java.time.LocalDateTime; @Builder @NoArgsConstructor @AllArgsConstructor -public class DemoContractDO extends BusinessBaseDO { +/** +* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO +*/ +public class DemoContractDO extends BaseDO { + + /** - * 合同ID - */ + * 合同ID + */ @TableId(type = IdType.ASSIGN_ID) private Long id; /** - * 合同编号 - */ + * 合同编号 + */ private String code; /** - * 合同名称 - */ + * 合同名称 + */ private String name; /** - * 合同状态 - */ + * 合同状态 + */ private Short status; /** - * 流程实例ID - */ + * 流程实例ID + */ private Long processInstanceId; /** - * 签订日期 - */ + * 签订日期 + */ private LocalDateTime signDate; /** - * 合同开始日期 - */ + * 合同开始日期 + */ private LocalDateTime startDate; /** - * 合同结束日期 - */ + * 合同结束日期 + */ private LocalDateTime endDate; /** - * 合同金额 - */ + * 合同金额 + */ private BigDecimal amount; /** - * 备注 - */ + * 备注 + */ private String remark; + /** + * 公司ID + */ + private Long companyId; + /** + * 公司名称 + */ + private String companyName; + /** + * 部门ID + */ + private Long deptId; + /** + * 部门名称 + */ + private String deptName; + /** + * 岗位ID + */ + private Long postId; + } \ No newline at end of file diff --git a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/dal/mysql/contract/DemoContractMapper.java b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/dal/mysql/contract/DemoContractMapper.java index 8e8f4ed0..8a1bd286 100644 --- a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/dal/mysql/contract/DemoContractMapper.java +++ b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/dal/mysql/contract/DemoContractMapper.java @@ -29,11 +29,6 @@ public interface DemoContractMapper extends BaseMapperX { .eqIfPresent(DemoContractDO::getAmount, reqVO.getAmount()) .eqIfPresent(DemoContractDO::getRemark, reqVO.getRemark()) .betweenIfPresent(DemoContractDO::getCreateTime, reqVO.getCreateTime()) - .eqIfPresent(DemoContractDO::getCompanyId, reqVO.getCompanyId()) - .likeIfPresent(DemoContractDO::getCompanyName, reqVO.getCompanyName()) - .eqIfPresent(DemoContractDO::getDeptId, reqVO.getDeptId()) - .likeIfPresent(DemoContractDO::getDeptName, reqVO.getDeptName()) - .eqIfPresent(DemoContractDO::getPostId, reqVO.getPostId()) .orderByDesc(DemoContractDO::getId)); } diff --git a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/service/contract/DemoContractService.java b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/service/contract/DemoContractService.java index 95c2f12c..3d90c2f8 100644 --- a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/service/contract/DemoContractService.java +++ b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/service/contract/DemoContractService.java @@ -20,7 +20,7 @@ public interface DemoContractService { * @param createReqVO 创建信息 * @return 编号 */ - Long createDemoContract(@Valid DemoContractSaveReqVO createReqVO); + DemoContractRespVO createDemoContract(@Valid DemoContractSaveReqVO createReqVO); /** * 更新合同 diff --git a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/service/contract/DemoContractServiceImpl.java b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/service/contract/DemoContractServiceImpl.java index 9cbf56ee..0e9d0cdf 100644 --- a/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/service/contract/DemoContractServiceImpl.java +++ b/yudao-module-template/yudao-module-template-server/src/main/java/cn/iocoder/yudao/module/template/service/contract/DemoContractServiceImpl.java @@ -33,13 +33,12 @@ public class DemoContractServiceImpl implements DemoContractService { private DemoContractMapper demoContractMapper; @Override - public Long createDemoContract(DemoContractSaveReqVO createReqVO) { + public DemoContractRespVO createDemoContract(DemoContractSaveReqVO createReqVO) { // 插入 DemoContractDO demoContract = BeanUtils.toBean(createReqVO, DemoContractDO.class); - demoContract.setCode("0"); demoContractMapper.insert(demoContract); // 返回 - return demoContract.getId(); + return BeanUtils.toBean(demoContract, DemoContractRespVO.class); } @Override