diff --git a/db-file/opsli-boot.sql b/db-file/opsli-boot.sql index cbc6152a..840d4d4d 100644 --- a/db-file/opsli-boot.sql +++ b/db-file/opsli-boot.sql @@ -11,7 +11,7 @@ Target Server Version : 50722 File Encoding : 65001 - Date: 29/04/2021 19:43:28 + Date: 30/04/2021 22:25:45 */ SET NAMES utf8mb4; @@ -5871,6 +5871,8 @@ INSERT INTO `sys_logs` VALUES (1387730595282341890, '1', '系统配置-系统设 INSERT INTO `sys_logs` VALUES (1387730667277570049, '1', '系统配置-系统设置-更新', '127.0.0.1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36', '/opsli-boot/api/v1/sys/options/updateOptions', 'POST', 66, '[{\"email_smtp\":\"smtp.qq.com\",\"email_addresser\":\"测试\",\"email_password\":\"ygxbqwgcfhtgbaii\",\"email_port\":\"465\",\"email_account\":\"meet.parker@foxmail.com\",\"email_ssl_enable\":\"0\"}]', NULL, 0, 1, '2021-04-29 19:29:09', 1, '2021-04-29 19:29:09', '2021-04-29 19:29:08'); INSERT INTO `sys_logs` VALUES (1387730845975891970, '1', '系统配置-系统设置-更新', '127.0.0.1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36', '/opsli-boot/api/v1/sys/options/updateOptions', 'POST', 50, '[{\"email_smtp\":\"smtp.qq.com\",\"email_addresser\":\"测试\",\"email_password\":\"ygxbqwgcfhtgbaii\",\"email_port\":\"465\",\"email_account\":\"meet.parker@foxmail.com\",\"email_ssl_enable\":\"1\"}]', NULL, 0, 1, '2021-04-29 19:29:51', 1, '2021-04-29 19:29:51', '2021-04-29 19:29:51'); INSERT INTO `sys_logs` VALUES (1387734139762769921, '1', '系统配置-角色管理-设置权限', '127.0.0.1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36', '/opsli-boot/api/v1/sys/role/perms/setPerms', 'POST', 92, '[{\"permsIds\":[\"1314066547072872450\",\"1314066863436640258\",\"1313806847370620930\",\"1313789204920131585\",\"1313789308506857474\",\"1313789400169177089\",\"1313789529840279554\",\"1313864645827678210\",\"1313864777918894082\",\"1335619974709936130\",\"1370051609388388353\",\"1370404146704654337\",\"4\",\"1313867061172195330\",\"1313867122731995137\",\"1313867360502894594\",\"1313867409949544450\",\"1313885644824522754\",\"1332662450423635969\",\"1332662689314414594\",\"1332662758860169217\",\"1332662809711910913\",\"1332662858294534146\",\"1315201380721446914\",\"1315201734892670977\",\"1315201809668722690\",\"1315201864219840513\",\"1315201925477650433\",\"1380173787882696705\",\"1312756531833356289\",\"1313867556498526209\",\"1314884045724717057\",\"1313867617949274113\",\"1313867682814185474\",\"1313867732508299265\",\"1387633500164599809\",\"1387633799226863618\",\"1387633960401383426\",\"1387634089447534594\",\"1387634157474951169\",\"1335439751687208961\",\"1335440004809261058\",\"1335439904372457474\",\"1335440081128816642\",\"1335440153140822017\",\"1360233188433977345\",\"1360233383397810177\",\"1327085543511293954\",\"1327085856930660353\",\"1327086205548625921\",\"1327086298750255105\",\"1327086378794352642\",\"1327086433609711617\",\"1337796232345407489\",\"1337796311940714498\",\"1330365141900591105\",\"1330365525440331778\",\"1330365570587820033\",\"1330365615181660162\",\"1330365717015166977\",\"1337719928086458369\",\"1337720128930705409\",\"1340626549594677250\",\"1340626612895113217\",\"1340626666078887937\",\"1340626895356321793\",\"1340626939119689729\",\"1340626988251766786\",\"1340627032942075906\",\"1314610817013919745\",\"1351012936860155906\",\"1351013587816136705\",\"1314616518671085570\",\"1314782679522099201\",\"1314782733087555586\",\"1314799744349913090\",\"1314068325453574145\",\"1327893773049262082\",\"1327894701135491073\",\"1327894767283859457\",\"1327894837093855234\",\"1327894965179510785\",\"1327895061598171137\",\"1327903778221699074\",\"1329374800267452417\",\"1314786106243301378\",\"1314071137365307394\",\"1314074765178187777\",\"1314075128635600897\",\"1314075267769053186\",\"1314075542684708865\",\"1314075764852797442\",\"1314075970382082050\",\"1314076169481498625\",\"1314076280542474242\",\"1314076678317682689\",\"1314077008057085954\",\"1314077108560998402\",\"1314077229235318786\",\"1314077399507283970\",\"1314077518340304897\",\"1314077631905280001\",\"1314077729003417602\",\"1314120834868060162\",\"1314121004749955073\",\"1314121200103858178\",\"1314121675192672257\",\"1314121808793837570\",\"1314121928784486402\",\"1314122020136427521\",\"1314122353273217025\",\"1314122123047870466\",\"1314122457908518914\",\"1314122556776652802\",\"1314122628184678401\",\"1314122717041008641\",\"1314123071354839041\",\"1314123272790482945\",\"1314123690283114498\",\"1314123894637993985\",\"1314123990633029633\",\"1314124102365093890\",\"1\",\"3\"],\"roleId\":\"2\"}]', NULL, 0, 1, '2021-04-29 19:42:56', 1, '2021-04-29 19:42:56', '2021-04-29 19:42:56'); +INSERT INTO `sys_logs` VALUES (1387763431574056962, '1', '系统配置-系统设置-更新', '127.0.0.1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36', '/opsli-boot/api/v1/sys/options/updateOptions', 'POST', 124, '[{\"email_smtp\":\"smtp.qq.com\",\"email_addresser\":\"测试\",\"email_password\":\"ygxbqwgcfhtgbaii\",\"email_port\":\"465\",\"email_account\":\"meet.parker@foxmail.com\",\"email_ssl_enable\":\"1\"}]', NULL, 0, 1, '2021-04-29 21:39:20', 1, '2021-04-29 21:39:20', '2021-04-29 21:39:20'); +INSERT INTO `sys_logs` VALUES (1388129689855234049, '1', '系统配置-系统设置-更新', '127.0.0.1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36', '/opsli-boot/api/v1/sys/options/updateOptions', 'POST', 83, '[{\"storage_local_domain\":\"http://127.0.0.1:8080/opsli-boot\",\"storage_local_path_prefix\":\"\"}]', NULL, 0, 1313694379541635074, '2021-04-30 21:54:43', 1313694379541635074, '2021-04-30 21:54:43', '2021-04-30 21:54:42'); -- ---------------------------- -- Table structure for sys_menu @@ -5887,8 +5889,8 @@ CREATE TABLE `sys_menu` ( `component` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '组件', `redirect` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '重定向', `sort_no` int(11) NOT NULL COMMENT '排序', - `always_show` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '是否总是显示 0否 1是', - `hidden` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '是否隐藏 0否 1是', + `always_show` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '是否总是显示 0是 1否', + `hidden` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '是否隐藏 0是 1否', `deleted` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '删除状态', `version` int(11) NOT NULL COMMENT '版本(乐观锁)', `create_by` bigint(19) NOT NULL COMMENT '创建用户', @@ -6057,7 +6059,7 @@ CREATE TABLE `sys_options` ( `id` bigint(19) NOT NULL COMMENT '唯一主键', `option_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '参数编号', `option_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '参数名称', - `option_value` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '参数值', + `option_value` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '参数值', `iz_lock` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '是否内置 0否 1是', `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注', `version` int(11) NOT NULL DEFAULT 0 COMMENT '版本(乐观锁)', @@ -6078,12 +6080,14 @@ INSERT INTO `sys_options` VALUES (2, 'crypto_asymmetric_public_key', '非对称 INSERT INTO `sys_options` VALUES (3, 'crypto_asymmetric_private_key', '非对称加解密-私钥', 'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJBLvllNhQvogkkGDKWAUO2SxZnHg6xUrkIEkZeLef0s43UmDsqzGSCKd0IPbyBBEgSHpk/Ui6GUyz039C15FszdvWgMpbsJuvuUWT4RhSak7mfAPX4gejCI1zQAr5d8gI5UXnbzvATgsUuoEOdaFXRY1AWNhikBzvznZl8TBOFJAgMBAAECgYAJvtCmFi7RK6ysIxhBj6JnmTN24ltJpuJ2zpL8Sc0J+B+LyIk6z9CROqjS5L+PM+kN0BEmCedwTBNTf1VV3BXzbPcX/prE004LXcbv5mjgaHf/PybzJQumYM5MuD9dJYBLc1PUNu2b9eGekEU+vzn0HCnmAkfwU7FCdU7Nh8/ZnQJBAMkY/nzYxue0rdfD4ZybM8chBksp9EA8mwmCW/PosJGJ6YVJ913PbfovYuSG4rwm0Ew6i/1zcXvAFjt5dW+L5EsCQQC3sMq5EF4Bfils0dTdn8Pwtv2t3H6wwaAc9QAExHYtZ5pipFH9NXiWn6KUJYq28mRxxKtfoara/8Ahb5yHY0w7AkEArGnmfyno123cgppqC7gxW3AgEj+FL7IGhs+igOumvxFMCsBQ+rhGpXMNSbuwF/r7KfAkaAgbaytUpGdNXXbGIwJAas7uoXsl3iJYvgCokJFkYmRUzzJlrCt6CTxgXWVK/g2+1FqNnfjofFSoORI3PTdmNkzQBRRA/4Q0WHzIfGS9nwJBAMLXrVKH6uhn67dwXKRCy2Xt54dLEtL43jL+xzWeHJibSkSyImLiAn1n2imSpB6ubJnBuvH19Y0nOXKBP0+VDGA=', '1', NULL, 0, 1, '2021-02-10 23:19:35', 1313694379541635074, '2021-04-04 11:19:26', '2021-04-29 11:11:41'); INSERT INTO `sys_options` VALUES (4, 'def_pass', '系统默认密码', 'Aa123456', '1', NULL, 0, 1, '2021-02-10 23:19:35', 1, '2021-04-09 21:09:36', '2021-04-29 11:11:42'); INSERT INTO `sys_options` VALUES (5, 'def_role', '系统默认角色编号', '007', '1', NULL, 0, 1, '2021-02-10 23:19:35', 1, '2021-04-09 21:09:36', '2021-04-29 11:11:44'); -INSERT INTO `sys_options` VALUES (1387687830355902465, 'email_account', '邮箱账号', 'meet.parker@foxmail.com', '1', NULL, 37, 1, '2021-04-29 16:38:55', 1, '2021-04-29 19:29:51', '2021-04-29 19:29:51'); -INSERT INTO `sys_options` VALUES (1387687830523674626, 'email_password', '邮箱密码', 'ygxbqwgcfhtgbaii', '1', NULL, 37, 1, '2021-04-29 16:38:55', 1, '2021-04-29 19:29:51', '2021-04-29 19:29:51'); -INSERT INTO `sys_options` VALUES (1387687830586589186, 'email_addresser', '发件人', '测试', '1', NULL, 37, 1, '2021-04-29 16:38:55', 1, '2021-04-29 19:29:51', '2021-04-29 19:29:51'); -INSERT INTO `sys_options` VALUES (1387692123406348289, 'email_smtp', 'SMTP地址', 'smtp.qq.com', '1', NULL, 28, 1, '2021-04-29 16:55:59', 1, '2021-04-29 19:29:51', '2021-04-29 19:29:51'); -INSERT INTO `sys_options` VALUES (1387695264482865154, 'email_port', 'SMTP端口', '465', '1', NULL, 20, 1, '2021-04-29 17:08:28', 1, '2021-04-29 19:29:51', '2021-04-29 19:29:51'); -INSERT INTO `sys_options` VALUES (1387700400634605569, 'email_ssl_enable', '开启SSL认证', '1', '1', NULL, 16, 1313694379541635074, '2021-04-29 17:28:52', 1, '2021-04-29 19:29:51', '2021-04-29 19:29:51'); +INSERT INTO `sys_options` VALUES (1387687830355902465, 'email_account', '邮箱账号', 'meet.parker@foxmail.com', '1', NULL, 38, 1, '2021-04-29 16:38:55', 1, '2021-04-29 21:39:20', '2021-04-29 21:39:19'); +INSERT INTO `sys_options` VALUES (1387687830523674626, 'email_password', '邮箱密码', 'xxxxxxxxxxx', '1', NULL, 38, 1, '2021-04-29 16:38:55', 1, '2021-04-29 21:39:20', '2021-04-29 21:39:20'); +INSERT INTO `sys_options` VALUES (1387687830586589186, 'email_addresser', '发件人', '测试', '1', NULL, 38, 1, '2021-04-29 16:38:55', 1, '2021-04-29 21:39:20', '2021-04-29 21:39:20'); +INSERT INTO `sys_options` VALUES (1387692123406348289, 'email_smtp', 'SMTP地址', 'smtp.qq.com', '1', NULL, 29, 1, '2021-04-29 16:55:59', 1, '2021-04-29 21:39:20', '2021-04-29 21:39:19'); +INSERT INTO `sys_options` VALUES (1387695264482865154, 'email_port', 'SMTP端口', '465', '1', NULL, 21, 1, '2021-04-29 17:08:28', 1, '2021-04-29 21:39:20', '2021-04-29 21:39:19'); +INSERT INTO `sys_options` VALUES (1387700400634605569, 'email_ssl_enable', '开启SSL认证', '1', '1', NULL, 17, 1313694379541635074, '2021-04-29 17:28:52', 1, '2021-04-29 21:39:20', '2021-04-29 21:39:19'); +INSERT INTO `sys_options` VALUES (1388129689385472001, 'storage_local_domain', 'storage_local_domain', 'http://127.0.0.1:8080/opsli-boot', '1', NULL, 0, 1313694379541635074, '2021-04-30 21:54:43', 1313694379541635074, '2021-04-30 21:54:43', '2021-04-30 21:54:42'); +INSERT INTO `sys_options` VALUES (1388129689523884033, 'storage_local_path_prefix', 'storage_local_path_prefix', '', '1', NULL, 0, 1313694379541635074, '2021-04-30 21:54:43', 1313694379541635074, '2021-04-30 21:54:43', '2021-04-30 21:54:42'); -- ---------------------------- -- Table structure for sys_org @@ -6370,8 +6374,8 @@ CREATE TABLE `sys_user` ( -- ---------------------------- -- Records of sys_user -- ---------------------------- -INSERT INTO `sys_user` VALUES (1, 'system', 'bffc4c8d318437f37f7203a5d0a16436', 'z25fk1otoj45ref83shq', '1', '超级管理员', '15321010110', '112', '/static/file/20201008/20201008235457-2fcb9a59a3334a2d966e41c341bc9756.jpg', '127.0.0.1', 'meet.parker@foxmail.com', '没有自学能力的人没有未来', '', 1315203865179602945, '0', 80, 1, '2020-09-25 15:03:22', 1, '2021-04-09 21:04:40', '2021-04-09 21:04:39'); -INSERT INTO `sys_user` VALUES (1313694379541635074, 'demo', '011eae89281e764ce9774b7f9b18b12a', '08oa2ktg9gi6vlv98f63', '1', '演示用户', '15321010110', 'test_001', '/static/file/20210218/20210218193757-745547dee93f403a823e813badb8e9a1.jpg', '127.0.0.1', 'meet.parker@foxmail.com', '没有自学能力的人没有未来', NULL, 1, '0', 2, 1, '2020-10-06 23:15:22', 1, '2020-10-11 16:53:58', '2021-04-29 19:05:53'); +INSERT INTO `sys_user` VALUES (1, 'system', 'bffc4c8d318437f37f7203a5d0a16436', 'z25fk1otoj45ref83shq', '1', '超级管理员', '15321010110', '112', 'http://127.0.0.1:8080/opsli-boot/static/files/20210430/162056101700285193J6IAU.jpg', '127.0.0.1', 'meet.parker@foxmail.com', '没有自学能力的人没有未来', '', 1315203865179602945, '0', 80, 1, '2020-09-25 15:03:22', 1, '2021-04-09 21:04:40', '2021-04-30 22:25:19'); +INSERT INTO `sys_user` VALUES (1313694379541635074, 'demo', '011eae89281e764ce9774b7f9b18b12a', '08oa2ktg9gi6vlv98f63', '1', '演示用户', '15321010110', 'test_001', 'http://127.0.0.1:8080/opsli-boot/static/files/20210430/1620442318684142618O725.jpg', '127.0.0.1', 'meet.parker@foxmail.com', '没有自学能力的人没有未来', NULL, 1, '0', 2, 1, '2020-10-06 23:15:22', 1, '2020-10-11 16:53:58', '2021-04-30 22:24:24'); INSERT INTO `sys_user` VALUES (1315218541317750785, 'zhangsan', '386a1212b388a49d6cca827173824914', 'g6880o4q5k98w6a6hplu', '1', '张三', NULL, '123123', NULL, '127.0.0.1', NULL, NULL, NULL, NULL, '0', 0, 1, '2020-10-11 17:11:50', 1, '2020-10-11 17:11:50', '2021-04-09 21:04:07'); INSERT INTO `sys_user` VALUES (1315224529580072961, 'test', '248b77e86f3137b0381e78a0050c8eab', 'x93jqlq94e7bmludjzxm', '0', '123', NULL, '123123123', NULL, NULL, NULL, NULL, NULL, NULL, '1', 0, 1, '2020-10-11 17:35:38', 1, '2020-10-11 17:35:38', '2021-04-08 23:51:32'); INSERT INTO `sys_user` VALUES (1315224823500120066, 'lyf', 'e7f977aac0007f3ae2b36c46d5fdc5c9', '0ep05v5hl5q86lv0uprg', '1', '刘亦菲', NULL, '0101001', NULL, '127.0.0.1', NULL, NULL, NULL, 1, '0', 0, 1313694379541635074, '2020-10-11 17:36:48', 1313694379541635074, '2020-10-11 17:36:48', '2021-04-09 21:04:05'); diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/options/OptionsModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/options/OptionsModel.java index 5b0b9d5f..6e6384f0 100644 --- a/opsli-api/src/main/java/org/opsli/api/wrapper/system/options/OptionsModel.java +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/options/OptionsModel.java @@ -61,8 +61,6 @@ public class OptionsModel extends ApiWrapper { @ApiModelProperty(value = "参数值") @ExcelProperty(value = "参数值", order = 3) @ExcelInfo - @ValidationArgs({ValiArgsType.IS_NOT_NULL}) - @ValidationArgsLenMax(10000) private String optionValue; diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserInfo.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserInfo.java index cc17c7c5..6cba1271 100644 --- a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserInfo.java +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserInfo.java @@ -59,13 +59,11 @@ public class UserInfo extends ApiWrapper { /** 邮箱 */ @ApiModelProperty(value = "邮箱") - @ExcelProperty(value = "邮箱", order = 3) @ValidationArgs({ValiArgsType.IS_EMAIL}) private String email; /** 工号 */ @ApiModelProperty(value = "工号") - @ExcelProperty(value = "工号", order = 4) @ValidationArgs({ValiArgsType.IS_GENERAL}) @ValidationArgsLenMax(32) private String no; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/autoconfigure/conf/ShiroConfig.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/autoconfigure/conf/ShiroConfig.java index 0c6abf7e..995a8b13 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/autoconfigure/conf/ShiroConfig.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/autoconfigure/conf/ShiroConfig.java @@ -105,7 +105,6 @@ public class ShiroConfig { filterMap.put("/doc.html", "anon"); filterMap.put("/swagger-ui.html", "anon"); filterMap.put("/swagger-resources/**", "anon"); - filterMap.put("/static/file/**", "anon"); filterMap.put("/**", "last_filter"); shiroFilter.setFilterChainDefinitionMap(filterMap); diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/options/entity/SysOptions.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/options/entity/SysOptions.java index 4c864fa7..81300d18 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/options/entity/SysOptions.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/options/entity/SysOptions.java @@ -43,6 +43,7 @@ public class SysOptions extends BaseEntity { private String optionName; /** 参数值 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) private String optionValue; /** 是否内置数据 0否 1是*/ diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java index 1ed838b8..14c8181b 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java @@ -62,6 +62,10 @@ import org.opsli.modulars.system.org.web.SysOrgRestController; import org.opsli.modulars.system.user.entity.SysUser; import org.opsli.modulars.system.user.entity.SysUserAndOrg; import org.opsli.modulars.system.user.service.IUserService; +import org.opsli.modulars.tools.oss.enums.OssStorageType; +import org.opsli.modulars.tools.oss.factory.OssStorageFactory; +import org.opsli.modulars.tools.oss.service.BaseOssStorageService; +import org.opsli.modulars.tools.oss.service.OssStorageService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; @@ -203,23 +207,16 @@ public class UserRestController extends BaseRestController + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.tools.oss; + + +import org.opsli.common.base.msg.BaseMsg; + +/** + * @Author: 周鹏程 + * @CreateTime: 2020-11-04 17:34 + * @Description: OSS服务异常 - 消息 + */ +public enum OssMsg implements BaseMsg { + + /** + * OSS + */ + + + + ; + + private final int code; + private final String message; + + OssMsg(int code, String message){ + this.code = code; + this.message = message; + } + + @Override + public Integer getCode() { + return this.code; + } + + @Override + public String getMessage() { + return this.message; + } +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/conf/LocalConfig.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/conf/LocalConfig.java new file mode 100644 index 00000000..8fc73585 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/conf/LocalConfig.java @@ -0,0 +1,44 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.tools.oss.conf; + +import lombok.Data; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; + +import java.io.Serializable; + +/** + * 本地存储配置 + * + * @author Parker + */ +@Data +public class LocalConfig implements Serializable { + + private static final long serialVersionUID = 1L; + + /** 域名 */ + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(100) + private String domain; + + /** 前缀 */ + @ValidationArgsLenMax(100) + private String pathPrefix; + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/enums/LocalStorageType.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/enums/LocalStorageType.java new file mode 100644 index 00000000..9333114b --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/enums/LocalStorageType.java @@ -0,0 +1,58 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.tools.oss.enums; + +/** + * 本地存储 参数类型 + * + * @author Parker + */ +public enum LocalStorageType { + + /** 本地存储服务 */ + DOMAIN("storage_local_domain", "域名"), + PATH_PREFIX("storage_local_path_prefix", "路径前缀"), + + ; + + private final String code; + private final String desc; + + public static LocalStorageType getType(String cacheType) { + LocalStorageType[] var1 = values(); + for (LocalStorageType type : var1) { + if (type.code.equalsIgnoreCase(cacheType)) { + return type; + } + } + return null; + } + + public String getCode() { + return this.code; + } + + public String getDesc() { + return this.desc; + } + + // ================= + + LocalStorageType(final String code, final String desc) { + this.code = code; + this.desc = desc; + } +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/enums/OssConfType.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/enums/OssConfType.java new file mode 100644 index 00000000..89d46293 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/enums/OssConfType.java @@ -0,0 +1,57 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.tools.oss.enums; + +/** + * 存储服务类型 + * + * @author Parker + */ +public enum OssConfType { + + /** 存储服务类型 */ + STORAGE_TYPE("storage_type", "存储服务类型"), + + ; + + private final String code; + private final String desc; + + public static OssConfType getType(String cacheType) { + OssConfType[] var1 = values(); + for (OssConfType type : var1) { + if (type.code.equalsIgnoreCase(cacheType)) { + return type; + } + } + return null; + } + + public String getCode() { + return this.code; + } + + public String getDesc() { + return this.desc; + } + + // ================= + + OssConfType(final String code, final String desc) { + this.code = code; + this.desc = desc; + } +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/enums/OssStorageType.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/enums/OssStorageType.java new file mode 100644 index 00000000..2fe91caa --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/enums/OssStorageType.java @@ -0,0 +1,57 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.tools.oss.enums; + +/** + * 存储服务类型 + * + * @author Parker + */ +public enum OssStorageType { + + /** 存储服务类型 */ + LOCAL("local", "本地"), + + ; + + private final String code; + private final String desc; + + public static OssStorageType getType(String cacheType) { + OssStorageType[] var1 = values(); + for (OssStorageType type : var1) { + if (type.code.equalsIgnoreCase(cacheType)) { + return type; + } + } + return null; + } + + public String getCode() { + return this.code; + } + + public String getDesc() { + return this.desc; + } + + // ================= + + OssStorageType(final String code, final String desc) { + this.code = code; + this.desc = desc; + } +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/factory/OssStorageFactory.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/factory/OssStorageFactory.java new file mode 100644 index 00000000..02396ea8 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/factory/OssStorageFactory.java @@ -0,0 +1,138 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.tools.oss.factory; + +import cn.hutool.core.util.ClassUtil; +import com.google.common.collect.Maps; +import lombok.extern.slf4j.Slf4j; +import org.opsli.api.wrapper.system.options.OptionsModel; +import org.opsli.core.utils.OptionsUtil; +import org.opsli.modulars.tools.oss.enums.OssConfType; +import org.opsli.modulars.tools.oss.enums.OssStorageType; +import org.opsli.modulars.tools.oss.service.OssStorageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Modifier; +import java.util.Map; +import java.util.Set; + +/** + * OSS服务 工厂 + * + * @author Parker + * @date 2021年3月16日10:16:29 + * + */ +@Slf4j +@Component +public class OssStorageFactory { + + /** Spring Bean 前缀 */ + public static final String SPRING_PREFIX = "ossStorage_"; + + /** OSS 服务容器 */ + private static final Map OSS_HANDLE_MAP = Maps.newHashMap(); + + /** + * 获得OSS 执行类 + * @return OssStorageService + */ + public static OssStorageService getHandle(){ + OssStorageType storageType = null; + + OptionsModel storageTypeOption = OptionsUtil.getOptionByCode(OssConfType.STORAGE_TYPE.getCode()); + if(storageTypeOption != null){ + storageType = OssStorageType.getType(storageTypeOption.getOptionValue()); + } + + return OssStorageFactory.getHandle(storageType); + } + + /** + * 获得OSS 执行类 + * @return OssStorageService + */ + public static OssStorageService getHandle(OssStorageType storageType){ + OssStorageService ossStorageService = OSS_HANDLE_MAP.get(storageType); + if(ossStorageService == null){ + return OSS_HANDLE_MAP.get(OssStorageType.LOCAL); + } + return OSS_HANDLE_MAP.get(storageType); + } + + + // ============================ + + + /** + * 初始化 + */ + @Autowired + public void init(AutowireCapableBeanFactory beanFactory, + DefaultListableBeanFactory defaultListableBeanFactory){ + + // 清空执行器集合 + OSS_HANDLE_MAP.clear(); + + // 拿到实现了 OssStorageService 接口的,所有子类 + Set> clazzSet = ClassUtil.scanPackageBySuper(OssStorageService.class.getPackage().getName()+".impl" + , OssStorageService.class + ); + + + // 入参处理类 + this.handleInit(beanFactory, defaultListableBeanFactory, clazzSet); + } + + /** + * 处理类 + * @param beanFactory Bean工程 + * @param defaultListableBeanFactory 默认BeanList工厂 + * @param clazzSet 扫描处理类 + */ + private void handleInit(AutowireCapableBeanFactory beanFactory, + DefaultListableBeanFactory defaultListableBeanFactory, + Set> clazzSet){ + for (Class aClass : clazzSet) { + // 位运算 去除抽象类 + if((aClass.getModifiers() & Modifier.ABSTRACT) != 0){ + continue; + } + + try { + Object obj = aClass.newInstance(); + + OssStorageService handler = (OssStorageService) obj; + + // 加入集合 + OssStorageFactory.OSS_HANDLE_MAP.put(handler.getType(), handler); + + // 将new出的对象放入Spring容器中 + defaultListableBeanFactory.registerSingleton(SPRING_PREFIX + aClass.getSimpleName(), obj); + + // 自动注入依赖 + beanFactory.autowireBean(obj); + + } catch (Exception e){ + log.error("Oss 服务注入失败"); + } + } + } + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/service/BaseOssStorageService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/service/BaseOssStorageService.java new file mode 100644 index 00000000..d02e3009 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/service/BaseOssStorageService.java @@ -0,0 +1,170 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.tools.oss.service; + +import cn.hutool.core.convert.Convert; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.RandomUtil; +import lombok.Data; +import org.apache.commons.lang3.StringUtils; + +import java.io.File; +import java.io.InputStream; + +/** + * 云存储 (支持本地、七牛、阿里云、腾讯云、又拍云) + * + * @author Parker + * @date 2021年4月30日16:12:45 + */ +public abstract class BaseOssStorageService implements OssStorageService { + + /** 文件夹前缀 */ + private static final String FOLDER_PREFIX = "/"; + private static final String FOLDER_WINDOWS_PREFIX = "\\"; + + /** + * 获得文件信息 + * @param file 文件 + * @return FileAttr + */ + protected FileAttr getFileAttr(File file){ + FileAttr fileAttr = new FileAttr(); + fileAttr.setName(FileUtil.getName(file)); + fileAttr.setSize(FileUtil.size(file)); + fileAttr.setPrefix(FileUtil.getPrefix(file)); + fileAttr.setSuffix(FileUtil.getSuffix(file)); + fileAttr.setNameAndSuffix(fileAttr.getName()+"."+fileAttr.getSuffix()); + // 生成随机 文件名称 + // 当前时间戳 + 文件名 hash + 文件大小 + 5位随机码 + + // 当前时间戳 + long currentTimeMillis = System.currentTimeMillis(); + // 文件名 HashCode + int fileNameHashCode = fileAttr.getName().hashCode(); + // 随机字符串 + String randomString = RandomUtil.randomStringUpper(5); + // 随机文件名 + String randomFileName = currentTimeMillis + fileNameHashCode + fileAttr.getSize() + randomString; + + fileAttr.setRandomFileName(randomFileName); + fileAttr.setRandomFileNameAndSuffix(randomFileName+"."+fileAttr.getSuffix()); + + return fileAttr; + } + + + /** + * 获得文件信息 + * @param inputStream 文件 + * @param suffix 后缀 + * @return FileAttr + */ + protected FileAttr getFileAttr(InputStream inputStream, String suffix){ + FileAttr fileAttr = new FileAttr(); + fileAttr.setSuffix(suffix); + + // 生成随机 文件名称 + // 当前时间戳 + 文件名 hash + 5位随机数字码 + 5位随机码 + + // 当前时间戳 + long currentTimeMillis = System.currentTimeMillis(); + // 文件名 HashCode + int fileNameHashCode = inputStream.hashCode(); + // 随机字符串 + String randomString = RandomUtil.randomStringUpper(5); + // 随机数 + String randomNumbers = RandomUtil.randomNumbers(5); + // 随机文件名 + String randomFileName = currentTimeMillis + fileNameHashCode + randomNumbers + randomString; + + fileAttr.setRandomFileName(randomFileName); + fileAttr.setRandomFileNameAndSuffix(randomFileName+"."+fileAttr.getSuffix()); + + return fileAttr; + } + + /** + * 处理 Path 路径 + * @param path 路径 + * @return String + */ + protected String handlePath(String path){ + return this.handlePath(path, true); + } + + /** + * 处理 Path 路径 + * @param path 路径 + * @return String + */ + protected String handlePath(String path, boolean isHandleFirst){ + if(StringUtils.isEmpty(path)){ + return path; + } + + if(isHandleFirst){ + // 如果 第一位不是 / 则加 / + char firstChar = path.charAt(0); + if(!StringUtils.equals(FOLDER_PREFIX, Convert.toStr(firstChar))){ + path = FOLDER_PREFIX + path; + } + } + + // 如果最后一位 是 / 则减 / + char lastChar = path.charAt(path.length()-1); + if(path.length() > 1 && + StringUtils.equals(FOLDER_PREFIX, Convert.toStr(lastChar))){ + path = StringUtils.substring(path, 0, path.length()-1); + } + + // 针对 windows 特殊路径 进行统一翻转 + return StringUtils.replace(path, FOLDER_WINDOWS_PREFIX, FOLDER_PREFIX); + } + + + // ============================= + + @Data + public static class FileAttr{ + + /** 大小 */ + private long size; + + /** 文件名 */ + private String name; + + /** 文件名 包含后缀 */ + private String nameAndSuffix; + + /** 前缀 */ + private String prefix; + + /** 后缀 */ + private String suffix; + + /** 随机唯一文件名 */ + private String randomFileName; + + /** 随机唯一文件名 包含后缀 */ + private String randomFileNameAndSuffix; + + /** 文件存储 */ + private String fileStoragePath; + + } + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/service/OssStorageService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/service/OssStorageService.java new file mode 100644 index 00000000..1ee581f5 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/service/OssStorageService.java @@ -0,0 +1,59 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.tools.oss.service; + + +import org.opsli.modulars.tools.oss.enums.OssStorageType; + +import java.io.File; +import java.io.InputStream; + +/** + * 云存储 (支持本地、七牛、阿里云、腾讯云、又拍云) + * + * @author Parker + * @date 2021年4月30日16:12:45 + */ +public interface OssStorageService { + + /** + * 获得存储服务类型 + * @return type + */ + OssStorageType getType(); + + /** + * 获得域名 + * @return String + */ + String getDomain(); + + /** + * 文件上传 + * @param file 文件 + * @return 返回文件信息 + */ + BaseOssStorageService.FileAttr upload(File file); + + /** + * 文件上传 + * @param inputStream 输入流 + * @param suffix 后缀 + * @return 返回文件信息 + */ + BaseOssStorageService.FileAttr upload(InputStream inputStream, String suffix); + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/service/impl/LocalStorageServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/service/impl/LocalStorageServiceImpl.java new file mode 100644 index 00000000..5efcaaab --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/tools/oss/service/impl/LocalStorageServiceImpl.java @@ -0,0 +1,205 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.tools.oss.service.impl; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.opsli.api.wrapper.system.options.OptionsModel; +import org.opsli.core.autoconfigure.properties.GlobalProperties; +import org.opsli.core.utils.OptionsUtil; +import org.opsli.core.utils.ValidationUtil; +import org.opsli.modulars.tools.oss.conf.LocalConfig; +import org.opsli.modulars.tools.oss.enums.LocalStorageType; +import org.opsli.modulars.tools.oss.enums.OssStorageType; +import org.opsli.modulars.tools.oss.service.BaseOssStorageService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Date; + +/** + * 本地文件上传 + * + * @author Parker + * @date 2021年4月30日14:09:08 + */ +@Slf4j +public class LocalStorageServiceImpl extends BaseOssStorageService { + + /** 固定路径 */ + private static final String FIXED_PATH = "/static/files"; + + @Autowired + private GlobalProperties globalProperties; + + @Override + public OssStorageType getType() { + return OssStorageType.LOCAL; + } + + @Override + public String getDomain() { + return this.getConfig().getDomain(); + } + + @Override + public FileAttr upload(File file) { + // 非空判断 + if(FileUtil.isEmpty(file)){ + return new FileAttr(); + } + + // 获得配置信息 + LocalConfig config = this.getConfig(); + // 验证对象 + ValidationUtil.verify(config); + + // 当前时间戳 + long currentTimeMillis = System.currentTimeMillis(); + + // 当前时间 + Date currDate = DateUtil.date(currentTimeMillis); + + // 静态路径 + String genPath = globalProperties != null && globalProperties.getWeb() != null && + StringUtils.isNotEmpty(globalProperties.getWeb().getUploadPath()) + ? globalProperties.getWeb().getUploadPath() + : FileUtil.getUserHomePath(); + + // 静态路径前缀 默认为空 + String pathPrefix = StringUtils.isNotEmpty(config.getPathPrefix())?config.getPathPrefix():""; + + // 文件夹名称 + String folderName = DateUtil.format(currDate, "yyyyMMdd"); + + // 包 全名称 + String packageName = super.handlePath(genPath, false) + + super.handlePath(FIXED_PATH) + super.handlePath(pathPrefix) + + super.handlePath(folderName); + // 包 半名称 + String packageNameByHalf = super.handlePath(FIXED_PATH) + super.handlePath(pathPrefix) + + super.handlePath(folderName); + + // 文件属性 + FileAttr fileAttr = super.getFileAttr(file); + // 设置文件路径 + fileAttr.setFileStoragePath( + config.getDomain() + packageNameByHalf + fileAttr.getName() + fileAttr.getSuffix()); + + + // 创建文件夹 + FileUtil.mkdir(packageName); + + // 创建文件 + File tmpFile = new File( + packageName + super.handlePath(fileAttr.getRandomFileNameAndSuffix())); + try { + FileUtils.copyFile(file, tmpFile); + }catch (IOException e){ + log.error(e.getMessage(), e); + } + FileUtil.touch(tmpFile); + + return fileAttr; + } + + @Override + public FileAttr upload(InputStream inputStream, String suffix) { + // 获得配置信息 + LocalConfig config = this.getConfig(); + // 验证对象 + ValidationUtil.verify(config); + + // 当前时间戳 + long currentTimeMillis = System.currentTimeMillis(); + + // 当前时间 + Date currDate = DateUtil.date(currentTimeMillis); + + // 静态路径 + String genPath = globalProperties != null && globalProperties.getWeb() != null && + StringUtils.isNotEmpty(globalProperties.getWeb().getUploadPath()) + ? globalProperties.getWeb().getUploadPath() + : FileUtil.getUserHomePath(); + + // 静态路径前缀 默认为空 + String pathPrefix = StringUtils.isNotEmpty(config.getPathPrefix())?config.getPathPrefix():""; + + // 文件夹名称 + String folderName = DateUtil.format(currDate, "yyyyMMdd"); + + // 包 全名称 + String packageName = super.handlePath(genPath, false) + + super.handlePath(FIXED_PATH) + super.handlePath(pathPrefix) + + super.handlePath(folderName); + // 包 半名称 + String packageNameByHalf = super.handlePath(FIXED_PATH) + super.handlePath(pathPrefix) + + super.handlePath(folderName); + + // 文件属性 + FileAttr fileAttr = super.getFileAttr(inputStream, suffix); + + // 设置文件路径 + fileAttr.setFileStoragePath( + config.getDomain() + packageNameByHalf + + super.handlePath(fileAttr.getRandomFileNameAndSuffix())); + + // 创建文件夹 + FileUtil.mkdir(packageName); + + // 创建文件 + File tmpFile = new File( + packageName + super.handlePath(fileAttr.getRandomFileNameAndSuffix())); + try { + FileUtils.copyInputStreamToFile(inputStream, tmpFile); + }catch (IOException e){ + log.error(e.getMessage(), e); + } + FileUtil.touch(tmpFile); + + return fileAttr; + } + + // =================== + + /** + * 获得配置信息 + * @return 配置 + */ + private LocalConfig getConfig(){ + LocalConfig localConfig = new LocalConfig(); + + // 获得配置数据 + OptionsModel domain = OptionsUtil.getOptionByCode(LocalStorageType.DOMAIN.getCode()); + OptionsModel pathPrefix = OptionsUtil.getOptionByCode(LocalStorageType.PATH_PREFIX.getCode()); + + if(domain != null){ + localConfig.setDomain(domain.getOptionValue()); + } + + if(pathPrefix != null){ + localConfig.setPathPrefix(pathPrefix.getOptionValue()); + } + + return localConfig; + } + +} diff --git a/opsli-starter/src/main/resources/application.yaml b/opsli-starter/src/main/resources/application.yaml index 49b5ee0f..9a0b3e94 100644 --- a/opsli-starter/src/main/resources/application.yaml +++ b/opsli-starter/src/main/resources/application.yaml @@ -160,8 +160,8 @@ opsli: url-patterns: "/*" # 排除过滤URL url-exclusion: + - "/static/files/" - "/doc.html" - - "/static/file" # 认证 auth: @@ -178,6 +178,7 @@ opsli: effective-time: 120 # 排除过滤URL url-exclusion: + - "/static/files/**" - "/test.html" # 登录设置