From 1d6e7763f4a30272cc0818ea12f83697b7375c45 Mon Sep 17 00:00:00 2001 From: shikeying <shikeying@163.com> Date: 星期五, 23 二月 2024 15:17:19 +0800 Subject: [PATCH] 测试了aws oss,另外 mybatis模块还未完成 --- iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java | 62 + iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/WebsocketDemo.java | 22 iplatform-test-mybatis/src/main/java/com/iplatform/test/controller/EbUserController.java | 107 +++ iplatform-file-server/src/main/java/com/iplatform/file/support/AbstractOssFileEngine.java | 14 deploy-jar-template/src/main/resources/application-dev.yml | 23 iplatform-base/src/main/java/com/iplatform/base/config/FileProperties.java | 73 ++ iplatform-test-mybatis/src/main/java/com/iplatform/test/mapper/EbUserMapper.java | 14 iplatform-test-mybatis/src/main/java/com/iplatform/test/service/impl/EbUserServiceImpl.java | 100 +++ deploy-jar-template/src/main/resources/application.yml | 4 iplatform-base-security/src/main/java/com/iplatform/security/DefaultAuthenticationFailureHandler.java | 2 iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/vo/EbUserVo.java | 25 pom.xml | 8 iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/DemoWebsocketClient.java | 81 ++ iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/DemoLoginResponse.java | 51 + iplatform-base/src/main/java/com/iplatform/base/ArgumentsConstants.java | 10 iplatform-file-server/src/main/java/com/iplatform/file/config/FileConfig.java | 30 iplatform-test-mybatis/src/main/java/com/iplatform/test/Test1.java | 4 iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/bo/EbUserQueryBo.java | 36 + iplatform-support-mybatis/pom.xml | 6 iplatform-test-mybatis/src/test/java/com/iplatform/AppTest.java | 20 iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/WebsocketClientTest.java | 100 +++ iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/service/MetaDataServiceImpl.java | 179 +++++ iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/util/DataTypeUtils.java | 90 ++ iplatform-test-mybatis/src/main/java/com/iplatform/test/service/IEbUserService.java | 53 + iplatform-base-admin/src/main/java/com/iplatform/base/controller/UserController.java | 18 iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/util/SqlUtils.java | 29 deploy-jar-template/src/main/resources/application-test.yml | 14 iplatform-test-mybatis/pom.xml | 33 + iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/bo/EbUserBo.java | 20 iplatform-file-server/pom.xml | 7 iplatform-base-security/src/main/java/com/iplatform/security/JwtAuthenticationTokenFilter.java | 2 iplatform-base-tcp-client/src/test/java/com/iplatform/AppTest.java | 16 iplatform-base-security/src/main/java/com/iplatform/security/FailedAuthenticationEntryPoint.java | 2 deploy-jar-template/pom.xml | 25 iplatform-file-server/src/main/java/com/iplatform/file/FileEngineFactory.java | 22 deploy-jar-template/src/main/resources/application-prod.yml | 13 iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/EbUser.java | 158 ++++ iplatform-base/src/main/java/com/iplatform/base/AbstractFileOperateSpiController.java | 34 iplatform-file-server/src/main/java/com/iplatform/file/support/AwsOssFileEngine.java | 359 +++++++++++ 39 files changed, 1,830 insertions(+), 36 deletions(-) diff --git a/deploy-jar-template/pom.xml b/deploy-jar-template/pom.xml index 8e3c8b6..1a2533b 100644 --- a/deploy-jar-template/pom.xml +++ b/deploy-jar-template/pom.xml @@ -83,10 +83,10 @@ </dependency> <!-- tcp閫氫俊妯″潡寮曞叆锛屽彲閰嶇疆鏄惁寮�鍚細鍖呮嫭鑱婂ぉ鍔熻兘鍩虹绛夈��2023-04-17 --> - <dependency> - <groupId>com.iplatform</groupId> - <artifactId>iplatform-base-tcp</artifactId> - </dependency> +<!-- <dependency>--> +<!-- <groupId>com.iplatform</groupId>--> +<!-- <artifactId>iplatform-base-tcp</artifactId>--> +<!-- </dependency>--> <!-- 鍚敤Rocket闃熷垪娑堟伅妯″潡锛岃亰澶╅泦缇や娇鐢�,2023-09-26 --> <dependency> <groupId>com.walkersoft</groupId> @@ -161,16 +161,15 @@ </dependency> <!-- 娴嬭瘯鍟嗘埛鍔熻兘妯″潡锛�2023-06-01 --> - <dependency> - <groupId>com.iplatform</groupId> - <artifactId>ishop-merchant</artifactId> - </dependency> - +<!-- <dependency>--> +<!-- <groupId>com.iplatform</groupId>--> +<!-- <artifactId>ishop-merchant</artifactId>--> +<!-- </dependency>--> <!-- 娴嬭瘯绉诲姩绔紝2023-06-23 --> - <dependency> - <groupId>com.iplatform</groupId> - <artifactId>ishop-mobile</artifactId> - </dependency> +<!-- <dependency>--> +<!-- <groupId>com.iplatform</groupId>--> +<!-- <artifactId>ishop-mobile</artifactId>--> +<!-- </dependency>--> <!-- 娴嬭瘯mongo鑱婂ぉ鍐欏叆锛�2023-07-07 --> <!-- <dependency>--> diff --git a/deploy-jar-template/src/main/resources/application-dev.yml b/deploy-jar-template/src/main/resources/application-dev.yml index 09b2b89..e4c35a8 100644 --- a/deploy-jar-template/src/main/resources/application-dev.yml +++ b/deploy-jar-template/src/main/resources/application-dev.yml @@ -87,7 +87,7 @@ host: 116.198.40.76 port: 6379 password: Jmy2019. - database: 2 + database: 15 mvc: pathmatch: @@ -161,7 +161,7 @@ # 骞冲彴缂撳瓨锛屾槸鍚﹀惎鐢╮edis缂撳瓨锛岄粯璁や娇鐢ㄥ熀浜庡唴瀛樼紦瀛�. # 娉ㄦ剰锛氬鏋滃紑鍚痳edis缂撳瓨锛屼笟鍔″伐绋嬪繀椤讳緷璧�(walker-support-redis) cache: - redis-enabled: false + redis-enabled: true # redis 缂撳瓨鏄惁瑕侀噸寤猴紝濡傛灉璁剧疆 true锛屽垯绯荤粺鍚姩鍚庝細鍒犻櫎缂撳瓨锛屽苟鎵ц榛樿閲嶆柊鍔犺浇鏂规硶銆�2023-08-26 # 娉ㄦ剰锛氳鍙傛暟涓�鑸湪娴嬭瘯闃舵浣跨敤锛屾寮忕幆澧冧笉瑕佷娇鐢紒 redis-rebuild: true @@ -303,7 +303,21 @@ file-root: d:/tmp/ # 璋冪敤杩滅▼涓婁紶鏂囦欢锛屾槸鍚︽寜鐓ф湰鍦版枃浠跺鐞嗭紝2023-07-03 # 鍦ㄦ祴璇曡繃绋嬩腑濡傛灉娌℃湁FTP绛夋湇鍔★紝鍙互璁剧疆涓簍rue涓存椂瀛樺偍鏈湴 - remote-as-local: true + remote-as-local: false + + # oss瀹炵幇绫诲瀷锛歛ws_s3锛堜簹椹�婏級 | tx锛堣吘璁級 | ali锛堥樋閲岋級 | qn锛堜竷鐗涳級锛�2023-12-13 + # | ftp锛�2024-02-23澧炲姞 + oss-type: aws_s3 + # oss璁块棶鍓嶇紑锛屽锛歨ttp://localhost:8082/admin/oss/锛�2023-12-13 + oss-prefix: http://localhost:8082/admin/oss/ + oss-access-key: HDKSYC2Y4FELF5CL5FIB + oss-secret-key: ktf8Px9uTvLFFpQNGsO41ehRsgJ0hWnLtxZnDBCX + # oss鏈嶅姟鍦板潃 + oss-endpoint: http://eos-beijing-1.cmecloud.cn + # oss榛樿鐨勬《鍚嶇О + oss-bucket-name: ctoms-file + protocol: http + ftp: ip: 116.198.40.76 port: 22 @@ -343,7 +357,8 @@ # websocket杩炴帴绔彛 port-ws: 60000 # websocket杩炴帴uri - websocket-uri: ws://localhost:60000/websocket +# websocket-uri: ws://localhost:60000/websocket + websocket-uri: ws://localhost:60000 # 閫氫俊绾跨▼鏁伴噺 boss-thread-num: 2 # 涓氬姟澶勭悊绾跨▼鏁伴噺 diff --git a/deploy-jar-template/src/main/resources/application-prod.yml b/deploy-jar-template/src/main/resources/application-prod.yml index 17edbd4..ed218c7 100644 --- a/deploy-jar-template/src/main/resources/application-prod.yml +++ b/deploy-jar-template/src/main/resources/application-prod.yml @@ -285,6 +285,19 @@ # 璋冪敤杩滅▼涓婁紶鏂囦欢锛屾槸鍚︽寜鐓ф湰鍦版枃浠跺鐞嗭紝2023-07-03 # 鍦ㄦ祴璇曡繃绋嬩腑濡傛灉娌℃湁FTP绛夋湇鍔★紝鍙互璁剧疆涓簍rue涓存椂瀛樺偍鏈湴 remote-as-local: true + + # oss瀹炵幇绫诲瀷锛歛ws_s3锛堜簹椹�婏級 | tx锛堣吘璁級 | ali锛堥樋閲岋級 | qn锛堜竷鐗涳級锛�2023-12-13 + oss-type: aws_s3 + # oss璁块棶鍓嶇紑锛屽锛歨ttp://localhost:8082/admin/oss/锛�2023-12-13 + oss-prefix: http://localhost:8082/admin/oss/ + oss-access-key: HDKSYC2Y4FELF5CL5FIB + oss-secret-key: 111 + # oss鏈嶅姟鍦板潃 + oss-endpoint: http://eos-beijing-1.cmecloud.cn + # oss榛樿鐨勬《鍚嶇О + oss-bucket-name: ctoms-file + protocol: http + ftp: ip: 116.198.40.76 port: 22 diff --git a/deploy-jar-template/src/main/resources/application-test.yml b/deploy-jar-template/src/main/resources/application-test.yml index 8ab1628..e9f0790 100644 --- a/deploy-jar-template/src/main/resources/application-test.yml +++ b/deploy-jar-template/src/main/resources/application-test.yml @@ -281,6 +281,20 @@ # 璋冪敤杩滅▼涓婁紶鏂囦欢锛屾槸鍚︽寜鐓ф湰鍦版枃浠跺鐞嗭紝2023-07-03 # 鍦ㄦ祴璇曡繃绋嬩腑濡傛灉娌℃湁FTP绛夋湇鍔★紝鍙互璁剧疆涓簍rue涓存椂瀛樺偍鏈湴 remote-as-local: true + + # oss瀹炵幇绫诲瀷锛歛ws_s3锛堜簹椹�婏級 | tx锛堣吘璁級 | ali锛堥樋閲岋級 | qn锛堜竷鐗涳級锛�2023-12-13 + # | ftp锛�2024-02-23澧炲姞 + oss-type: aws_s3 + # oss璁块棶鍓嶇紑锛屽锛歨ttp://localhost:8082/admin/oss/锛�2023-12-13 + oss-prefix: http://localhost:8082/admin/oss/ + oss-access-key: HDKSYC2Y4FELF5CL5FIB + oss-secret-key: ktf8Px9uTvLFFpQNGsO41ehRsgJ0hWnLtxZnDBCX + # oss鏈嶅姟鍦板潃 + oss-endpoint: http://eos-beijing-1.cmecloud.cn + # oss榛樿鐨勬《鍚嶇О + oss-bucket-name: ctoms-file + protocol: http + # ftp: # ip: 116.198.40.76 # port: 22 diff --git a/deploy-jar-template/src/main/resources/application.yml b/deploy-jar-template/src/main/resources/application.yml index 8bc0bdc..55db90a 100644 --- a/deploy-jar-template/src/main/resources/application.yml +++ b/deploy-jar-template/src/main/resources/application.yml @@ -1,7 +1,7 @@ spring: profiles: # active: oracle -# active: dev - active: master + active: dev +# active: master # active: test diff --git a/iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java b/iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java index 1c557bc..425c2d2 100644 --- a/iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java +++ b/iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java @@ -1,14 +1,22 @@ package com.iplatform.base.controller; import com.iplatform.base.SystemController; +import com.iplatform.core.util.CharsetKit; import com.iplatform.core.util.Convert; import com.iplatform.mybatis.domain.GenTable; import com.iplatform.mybatis.domain.GenTableColumn; import com.iplatform.mybatis.domain.TableDataInfo; import com.iplatform.mybatis.service.IGenTableColumnService; import com.iplatform.mybatis.service.IGenTableService; +import com.iplatform.mybatis.service.MetaDataServiceImpl; +import com.iplatform.mybatis.util.VelocityInitializer; +import com.iplatform.mybatis.util.VelocityUtils; +import com.walker.infrastructure.utils.StringUtils; import com.walker.web.ResponseValue; import org.apache.commons.io.IOUtils; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.validation.annotation.Validated; @@ -22,10 +30,14 @@ import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.StringWriter; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; /** * 浠g爜鐢熸垚 鎿嶄綔澶勭悊銆� @@ -48,6 +60,9 @@ @Autowired private IGenTableColumnService genTableColumnService; + + @Autowired + private MetaDataServiceImpl metaDataService; /** * 鏌ヨ浠g爜鐢熸垚鍒楄〃 @@ -233,4 +248,51 @@ rspData.setTotal(0); return rspData; } + + /** + * 鐢熸垚鎸囧畾琛ㄧ粨鏋勪唬鐮侊紝鏀寔澶氭暟鎹簱銆� + * @param response + * @param tableName 琛ㄥ悕锛屽彲浠ユ槸绮剧‘鐨勮〃鍚嶏紝濡傦細s_ment锛屼篃鍙互鏄墠缂�锛屽锛歴_ + * @param isPrecision 鏄惁绮剧‘鏌ヨ锛堝崟琛級 + * @param packageName + * @throws IOException + * @date 2024-02-20 + */ + @GetMapping("/batchDownloadGenCode") + public void batchDownloadGenCode(HttpServletResponse response, String tableName, boolean isPrecision, String packageName) throws IOException{ + List<GenTable> list = this.metaDataService.queryDatabaseTableInfo(tableName, isPrecision, packageName, null, null, null); + if(StringUtils.isEmptyList(list)){ + logger.error("鏈煡鎵惧埌浠讳綍琛ㄤ俊鎭紝鏃犳硶鐢熷瓨浠g爜锛宼ableName={}", tableName); + return; + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ZipOutputStream zip = new ZipOutputStream(outputStream); + for(GenTable table : list){ + VelocityInitializer.initVelocity(); + VelocityContext context = VelocityUtils.prepareContext(table); + + // 鑾峰彇妯℃澘鍒楄〃 + List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); + for (String template : templates) { + // 娓叉煋妯℃澘 + StringWriter sw = new StringWriter(); + Template tpl = Velocity.getTemplate(template, CharsetKit.UTF_8); + tpl.merge(context, sw); + try { + // 娣诲姞鍒皕ip + zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); + IOUtils.write(sw.toString(), zip, CharsetKit.UTF_8); + IOUtils.closeQuietly(sw); + zip.flush(); + zip.closeEntry(); + } + catch (IOException e) { + logger.error("娓叉煋妯℃澘澶辫触锛岃〃鍚嶏細" + table.getTableName(), e); + } + } + } + IOUtils.closeQuietly(zip); + byte[] data = outputStream.toByteArray(); + genCode(response, data); + } } diff --git a/iplatform-base-admin/src/main/java/com/iplatform/base/controller/UserController.java b/iplatform-base-admin/src/main/java/com/iplatform/base/controller/UserController.java index 937dba2..133af49 100644 --- a/iplatform-base-admin/src/main/java/com/iplatform/base/controller/UserController.java +++ b/iplatform-base-admin/src/main/java/com/iplatform/base/controller/UserController.java @@ -19,6 +19,7 @@ import com.walker.di.DataImportException; import com.walker.file.FileInfo; import com.walker.infrastructure.utils.DateUtils; +import com.walker.infrastructure.utils.FileCopyUtils; import com.walker.infrastructure.utils.NumberGenerator; import com.walker.infrastructure.utils.StringUtils; import com.walker.web.ResponseValue; @@ -35,6 +36,8 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import java.io.File; +import java.io.FileOutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -68,6 +71,18 @@ @PostMapping("/import") public ResponseValue importExcel(MultipartFile file, boolean updateSupport){ try { + // ~~~~~~~~~~~~~~~~~~~~~ 娴嬭瘯 +// String filePath = "d:/tmp/test_user_001.csv"; +// FileOutputStream fileOutputStream = new FileOutputStream(new File(filePath)); +// FileCopyUtils.copy(file.getInputStream(), fileOutputStream); +// logger.info("鏂囦欢鍐欏叆鎴愬姛:{}", filePath); +// FileInfo testFileInfo = this.uploadFileToRemote(filePath, null, String.valueOf(this.getOwner())); + + // 2024-02-23 浠ヤ笅浠g爜鎴愬姛鎵ц锛屾殏鏃舵敞閲� +// FileInfo testFileInfo = this.uploadFileToRemote(file.getInputStream(), "avatar.jpg", null, file.getSize(), null, String.valueOf(Constants.OWNER_PLATFORM)); +// logger.info("testFileInfo = {}", testFileInfo); + // ~~~~~~~~~~~~~~~~~~~~~ 娴嬭瘯 end + UserDataImportor dataImportor = new UserDataImportor(file.getInputStream()); dataImportor.setId("user_import"); this.getDataImportEngine().executeImport(dataImportor, this.getCurrentUserPrincipal().getUserName()); @@ -75,6 +90,9 @@ logger.info("閿欒缁撴灉鏂囦欢:{}", dataImportor.getErrorFile()); // FileInfo errorFileInfo = this.uploadFileToRemote(dataImportor.getErrorFile()); +// this.uploadFileToRemote(file.getInputStream(), null, null, String.valueOf(this.getOwner()),) + // 杩欓噷浼氭姤閿欙紝鍥犱负涓婁紶 s3 oss鏃跺姩鎬佺敓鎴愮殑鏂囦欢锛屾�绘槸璇磋鍙栭暱搴﹀拰鏈熸湜闀垮害涓嶄竴鑷达細 + // 淇濆瓨鏂囦欢鍒般�恛ss銆戦敊璇�:Data read has a different length than the expected: dataLength=2764; expectedLength=107374178304; FileInfo errorFileInfo = this.uploadFileToRemote(dataImportor.getErrorFile(), null, String.valueOf(this.getOwner())); if(errorFileInfo != null){ logger.debug("鐢ㄦ埛瀵煎叆瀛樺湪'涓嶇鍚堟暟鎹�': 锛�", errorFileInfo.toString()); diff --git a/iplatform-base-security/src/main/java/com/iplatform/security/DefaultAuthenticationFailureHandler.java b/iplatform-base-security/src/main/java/com/iplatform/security/DefaultAuthenticationFailureHandler.java index f3dd5c3..8f0ba15 100644 --- a/iplatform-base-security/src/main/java/com/iplatform/security/DefaultAuthenticationFailureHandler.java +++ b/iplatform-base-security/src/main/java/com/iplatform/security/DefaultAuthenticationFailureHandler.java @@ -51,7 +51,7 @@ } try { - ServletUtils.renderString(response, JsonUtils.objectToJsonString(ResponseValue.error(code, message))); + ServletUtils.renderString(response, JsonUtils.objectToJsonString(ResponseValue.error(message))); } catch (Exception e) { logger.error("璁よ瘉澶辫触:" + request.getRequestURI(), e); } diff --git a/iplatform-base-security/src/main/java/com/iplatform/security/FailedAuthenticationEntryPoint.java b/iplatform-base-security/src/main/java/com/iplatform/security/FailedAuthenticationEntryPoint.java index 5a88332..3b627df 100644 --- a/iplatform-base-security/src/main/java/com/iplatform/security/FailedAuthenticationEntryPoint.java +++ b/iplatform-base-security/src/main/java/com/iplatform/security/FailedAuthenticationEntryPoint.java @@ -28,7 +28,7 @@ String msg = "璁よ瘉澶辫触锛屾棤鏉冮檺璁块棶绯荤粺璧勬簮" + request.getRequestURI(); try { - ServletUtils.renderString(response, JsonUtils.objectToJsonString(ResponseValue.error(ResponseCode.NO_PERMISSION.getCode(), msg))); + ServletUtils.renderString(response, JsonUtils.objectToJsonString(ResponseValue.error(ResponseCode.EXCEPTION.getCode(), msg))); } catch (Exception e) { logger.error("鏃犳潈闄愯闂郴缁熻祫婧�" + request.getRequestURI()); } diff --git a/iplatform-base-security/src/main/java/com/iplatform/security/JwtAuthenticationTokenFilter.java b/iplatform-base-security/src/main/java/com/iplatform/security/JwtAuthenticationTokenFilter.java index a9ea030..241bb83 100644 --- a/iplatform-base-security/src/main/java/com/iplatform/security/JwtAuthenticationTokenFilter.java +++ b/iplatform-base-security/src/main/java/com/iplatform/security/JwtAuthenticationTokenFilter.java @@ -143,7 +143,7 @@ , userPrincipal.getUserName(), uuid, this.tokenGenerator, securityProperties.getTokenExpireWeb()); // 閲嶆柊璁剧疆鐢ㄦ埛鍒涘缓token鏃堕棿 userPrincipal.setLastLoginTime(System.currentTimeMillis()); - this.userOnlineProvider.cacheUserPrincipal(uuid, userPrincipal); + this.userOnlineProvider.cacheUserPrincipal(uuid, userPrincipal, securityProperties.getTokenExpireWeb()); response.addHeader(Constants.TOKEN_HEADER_REFRESH, token); if(this.logger.isDebugEnabled()){ logger.debug("鍒锋柊token, uuid = " + uuid + ", " + token); diff --git a/iplatform-base-tcp-client/src/test/java/com/iplatform/AppTest.java b/iplatform-base-tcp-client/src/test/java/com/iplatform/AppTest.java new file mode 100644 index 0000000..7c41876 --- /dev/null +++ b/iplatform-base-tcp-client/src/test/java/com/iplatform/AppTest.java @@ -0,0 +1,16 @@ +package com.iplatform; + +import com.iplatform.tcp.WebsocketClientTest; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + WebsocketClientTest test = new WebsocketClientTest(); + test.createBatch(); + } +} diff --git a/iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/DemoLoginResponse.java b/iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/DemoLoginResponse.java new file mode 100644 index 0000000..657b68e --- /dev/null +++ b/iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/DemoLoginResponse.java @@ -0,0 +1,51 @@ +package com.iplatform.tcp; + +public class DemoLoginResponse { + + /** + * + */ + private static final long serialVersionUID = 1167352207355638142L; + +// @Override +// protected void translateProperties(JSONObject result) { +// result.put("status", status); +// } + + @Override + public String toString(){ + return new StringBuilder("[protocol=").append(this.getProtocol()) + .append(", name=").append(this.getUid()) + .append(", status=").append(this.status) + .append("]").toString(); + } + + public String getUid() { + return uid; + } + + public void setUid(String uid) { + this.uid = uid; + } + + private String protocol; + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + private int status = 0; + private String uid; +} diff --git a/iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/DemoWebsocketClient.java b/iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/DemoWebsocketClient.java new file mode 100644 index 0000000..1383826 --- /dev/null +++ b/iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/DemoWebsocketClient.java @@ -0,0 +1,81 @@ +package com.iplatform.tcp; + +import com.walker.infrastructure.utils.JsonUtils; +import org.java_websocket.client.WebSocketClient; +import org.java_websocket.handshake.ServerHandshake; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +public class DemoWebsocketClient extends WebSocketClient { + + protected final transient Logger logger = LoggerFactory.getLogger(this.getClass()); + + public DemoWebsocketClient(URI serverUri) { + super(serverUri); + } + + @Override + public void onOpen(ServerHandshake serverHandshake) { +// logger.info("ws 杩炴帴鎴愬姛"); + String data = null; + Map<String, String> map = new HashMap<>(4); + map.put("protocol", "login"); + map.put("uid", this.uid); + try { + data = JsonUtils.objectToJsonString(map); + } catch (Exception e) { + throw new RuntimeException(e); + } + this.send(data); + logger.info("瀹㈡埛绔彂閫佺櫥褰曡姹傦紝name = {}", this.uid); + } + + @Override + public void onMessage(String s) { + if(s.indexOf("heartbeat") >= 0){ + return; + } + logger.info("ws 鏀跺埌娑堟伅:{}", s); + try { + DemoLoginResponse response = JsonUtils.jsonStringToObject(s, DemoLoginResponse.class); + if(response.getProtocol().equals("login")){ + logger.info("websocket 鐧诲綍鎴愬姛锛歿}", response.getUid()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public void onClose(int i, String s, boolean b) { + logger.warn("杩炴帴琚叧闂細code={}, reason={}, remote={}", i, s, b); + } + + @Override + public void onError(Exception e) { + logger.error("杩炴帴閿欒锛�" + e.getMessage(), e); + } + + public String getUid() { + return uid; + } + + public void setUid(String uid) { + this.uid = uid; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + private String uid; + private String userName; +} diff --git a/iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/WebsocketClientTest.java b/iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/WebsocketClientTest.java new file mode 100644 index 0000000..a77611a --- /dev/null +++ b/iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/WebsocketClientTest.java @@ -0,0 +1,100 @@ +package com.iplatform.tcp; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.URI; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +public class WebsocketClientTest { + + protected final transient Logger logger = LoggerFactory.getLogger(this.getClass()); + +// private static final URI wsUri = URI.create("ws://127.0.0.1:60000/websocket"); +// private static final URI wsUri = URI.create("ws://116.198.40.76:60000/websocket"); +// private static final URI wsUri = URI.create("ws://10.8.4.35:60035/websocket"); +// private static final URI wsUri = URI.create("ws://www.shikeying.com:60001/websocket"); +// private static final URI wsUri = URI.create("ws://ctoms.chinapost.com.cn/ws/websocket"); + private static final URI wsUri = URI.create("ws://localhost:60000"); +// private static final URI wsUri = URI.create("ws://10.8.4.98:60011/websocket"); + + private static Map<String, DemoWebsocketClient> cacheClient = new ConcurrentHashMap<>(32770); + + private ExecutorService executorService = Executors.newFixedThreadPool(4); +// private static int currentSize = 20000; + private static int currentSize = 1; + private static final int TOTAL_LINES = 2; +// private static final int TOTAL_LINES = 16; +// private static final int BATCH_SIZE = 8; + private static final int BATCH_SIZE = 2; + + public void createBatch(){ + logger.info(".........寮�濮嬫祴璇曢�氫俊杩炴帴.......... TOTAL_LINES = {}, url = {}", TOTAL_LINES, wsUri); + while(currentSize < TOTAL_LINES){ + try { + this.executorService.execute(new Runnable() { + @Override + public void run() { + int count = BATCH_SIZE; + for(int i=0; i<count; i++){ + String uri = "mike" + (currentSize); + DemoWebsocketClient client = createOneClient(wsUri, uri); + logger.info("鍒涘缓浜嗕竴涓鎴风锛� " + uri); + cacheClient.put(uri, client); + currentSize ++; + } + } + }); + } catch (Exception ex){ + ex.printStackTrace(); + } finally { + try { + logger.info("currentSize = {}", currentSize); + TimeUnit.SECONDS.sleep(3); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + + logger.info("宸茬疮璁″垱寤鸿繛鎺ワ細{} 涓�", currentSize); + try { + TimeUnit.SECONDS.sleep(10); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + +// logger.info("鍑嗗鍏抽棴鎵�鏈夐摼鎺ュ璞�..."); +// for(DemoWebsocketClient client : cacheClient.values()){ +// client.close(); +// } +// logger.info("鎵ц浜嗗叧闂搷浣滐紝鎵�鏈夎繛鎺ョ◢鍚庝細瀹屽叏鍏抽棴"); + } + + private DemoWebsocketClient createOneClient(URI uri, String uid){ + DemoWebsocketClient client = new DemoWebsocketClient(uri); + client.setUid(uid); + client.setConnectionLostTimeout(0); + try { + client.connectBlocking(); + } catch (InterruptedException e) { + throw new RuntimeException("鍒涘缓client閿欒, uid=" + uid + ", " + e.getMessage(), e); + } + return client; + } + +// public void createOneClient(){ +// DemoWebsocketClient client = new DemoWebsocketClient(wsUri); +// client.setUid("mike"); +// try { +// client.connectBlocking(); +// } catch (InterruptedException e) { +// throw new RuntimeException(e); +// } +// WaitConsoleInput.waitInput(); +// } +} diff --git a/iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/WebsocketDemo.java b/iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/WebsocketDemo.java new file mode 100644 index 0000000..822842e --- /dev/null +++ b/iplatform-base-tcp-client/src/test/java/com/iplatform/tcp/WebsocketDemo.java @@ -0,0 +1,22 @@ +package com.iplatform.tcp; + +import com.iplatform.tcp.util.ws.WebDataResponse; +import com.walker.infrastructure.utils.JsonUtils; +import com.walker.infrastructure.utils.NumberGenerator; +import org.junit.Test; + +public class WebsocketDemo { + + @Test + public void sendDataFormat(){ + WebDataResponse msg = new WebDataResponse(); + msg.setMessageId(NumberGenerator.getLongSequenceId()); + msg.setName("shikeying"); // 鎸囧畾鐢ㄦ埛鍙戦�侊紝璇d涓庢祻瑙堝櫒绔敞鍐岀殑id淇濇寔涓�鑷淬�� + msg.setData("浣犲ソ锛岃繖鏄帹閫佺粰娴忚鍣ㄧ殑鍐呭锛屼竴鑸槸JSON鏍煎紡銆�"); + try { + System.out.println(JsonUtils.objectToJsonString(msg)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/iplatform-base/src/main/java/com/iplatform/base/AbstractFileOperateSpiController.java b/iplatform-base/src/main/java/com/iplatform/base/AbstractFileOperateSpiController.java index c9cb3b6..d4ea391 100644 --- a/iplatform-base/src/main/java/com/iplatform/base/AbstractFileOperateSpiController.java +++ b/iplatform-base/src/main/java/com/iplatform/base/AbstractFileOperateSpiController.java @@ -1,5 +1,6 @@ package com.iplatform.base; +import com.iplatform.base.config.FileProperties; import com.iplatform.core.BeanContextAware; import com.walker.file.FileInfo; import com.walker.file.FileStoreType; @@ -144,34 +145,47 @@ protected FileInfo uploadFileToRemote(InputStream inputStream , String fileName, String groupId, long fileSize, Integer businessType, String owner) throws Exception{ - String remoteFileStoreType = this.getArgumentVariable(ArgumentsConstants.CONFIG_UPLOAD_TYPE).getStringValue(); - if(StringUtils.isEmpty(remoteFileStoreType)){ - throw new PlatformRuntimeException("骞冲彴鏈厤缃换浣曡繙绋嬪瓨鍌ㄧ被鍒細" + ArgumentsConstants.CONFIG_UPLOAD_TYPE); - } // 2023-07-03锛屽鏋滈厤缃繙绋嬩笂浼犱负鏈湴 if(this.acquireFileOperateSpi().isRemoteAsLocal()){ return this.acquireFileOperateSpi().uploadFileToLocal(inputStream, fileName, groupId, fileSize, businessType, owner); } - FileStoreType fileStoreType = FileStoreType.getType(remoteFileStoreType); +// String remoteFileStoreType = this.getArgumentVariable(ArgumentsConstants.CONFIG_UPLOAD_TYPE).getStringValue(); +// if(StringUtils.isEmpty(remoteFileStoreType)){ +// throw new PlatformRuntimeException("骞冲彴鏈厤缃换浣曡繙绋嬪瓨鍌ㄧ被鍒細" + ArgumentsConstants.CONFIG_UPLOAD_TYPE); +// } +// FileStoreType fileStoreType = FileStoreType.getType(remoteFileStoreType); + String ossType = BeanContextAware.getBeanByType(FileProperties.class).getOssType(); + if(StringUtils.isEmpty(ossType)){ + throw new PlatformRuntimeException("骞冲彴鏈厤缃换浣昽ssType"); + } + + FileStoreType fileStoreType = FileStoreType.getType(ossType); if(fileStoreType == FileStoreType.Ftp){ return this.acquireFileOperateSpi().uploadFileToFtp(inputStream, fileName, groupId, fileSize, businessType, owner); } else { return this.acquireFileOperateSpi().uploadFileToOss(inputStream, fileName, groupId, fileSize, businessType, owner, fileStoreType); } } + protected FileInfo[] uploadFileToRemote(InputStream[] inputStream , String[] fileName, String groupId, long[] fileSize, Integer businessType, String owner) throws Exception{ - String remoteFileStoreType = this.getArgumentVariable(ArgumentsConstants.CONFIG_UPLOAD_TYPE).getStringValue(); - if(StringUtils.isEmpty(remoteFileStoreType)){ - throw new PlatformRuntimeException("骞冲彴鏈厤缃换浣曡繙绋嬪瓨鍌ㄧ被鍒細" + ArgumentsConstants.CONFIG_UPLOAD_TYPE); - } +// String remoteFileStoreType = this.getArgumentVariable(ArgumentsConstants.CONFIG_UPLOAD_TYPE).getStringValue(); +// if(StringUtils.isEmpty(remoteFileStoreType)){ +// throw new PlatformRuntimeException("骞冲彴鏈厤缃换浣曡繙绋嬪瓨鍌ㄧ被鍒細" + ArgumentsConstants.CONFIG_UPLOAD_TYPE); +// } +// FileStoreType fileStoreType = FileStoreType.getType(remoteFileStoreType); // 2023-07-03锛屽鏋滈厤缃繙绋嬩笂浼犱负鏈湴 if(this.acquireFileOperateSpi().isRemoteAsLocal()){ return this.acquireFileOperateSpi().uploadFileToLocal(inputStream, fileName, groupId, fileSize, businessType, owner); } - FileStoreType fileStoreType = FileStoreType.getType(remoteFileStoreType); + String ossType = BeanContextAware.getBeanByType(FileProperties.class).getOssType(); + if(StringUtils.isEmpty(ossType)){ + throw new PlatformRuntimeException("骞冲彴鏈厤缃换浣昽ssType"); + } + + FileStoreType fileStoreType = FileStoreType.getType(ossType); if(fileStoreType == FileStoreType.Ftp){ return this.acquireFileOperateSpi().uploadFileToFtp(inputStream, fileName, groupId, fileSize, businessType, owner); } else { diff --git a/iplatform-base/src/main/java/com/iplatform/base/ArgumentsConstants.java b/iplatform-base/src/main/java/com/iplatform/base/ArgumentsConstants.java index 0ca77e7..7676824 100644 --- a/iplatform-base/src/main/java/com/iplatform/base/ArgumentsConstants.java +++ b/iplatform-base/src/main/java/com/iplatform/base/ArgumentsConstants.java @@ -28,9 +28,15 @@ /** 绉诲姩绔煙鍚� */ public static final String CONFIG_KEY_SITE_URL = "site_url"; - /** 鍥剧墖涓婁紶绫诲瀷 1鏈湴 2涓冪墰浜� 3OSS 4COS, 榛樿鏈湴 + /** 鍥剧墖涓婁紶绫诲瀷 1-鏈湴 2-涓冪墰浜� 3-闃块噷浜慜SS 4-鑵捐OSS 5-浜氶┈閫妔3, 榛樿鏈湴 * <p>鏀寔绯荤粺鑷繁鐨勫畾涔夊父閲忥紝鍙傝�冿細{@linkplain com.walker.file.FileStoreType}</p> + * <pre> + * 1) 涓婁紶鍒版湰鍦帮紝杩樻槸杩滅▼锛屼笟鍔¢�夋嫨锛岀郴缁熶細閰嶇疆杩滅▼ossType鏍囪瘑鍝釜骞冲彴銆� + * 2) 瀵逛簬鏂囦欢鏄瓨鍌ㄦ湰鍦拌繕鏄繙绋嬶紝閫氳繃锛歩sRemoteAsLocal()鏂规硶鍒ゆ柇锛屽彲浠ョ敤鍦ㄦ祴璇曢樁娈点�� + * </pre> + * * */ + @Deprecated public static final String CONFIG_UPLOAD_TYPE = "uploadType"; /** 鍏ㄥ眬鏈湴鍥剧墖鍩熷悕 */ @@ -41,6 +47,8 @@ public static final String CONFIG_AL_UPLOAD_URL = "alUploadUrl"; /** 鑵捐浜戜笂浼燯RL */ public static final String CONFIG_TX_UPLOAD_URL = "txUploadUrl"; + /** 浜氶┈閫奡3涓婁紶URL */ + public static final String CONFIG_S3_UPLOAD_URL = "s3UploadUrl"; /** FTP涓婁紶URL */ public static final String CONFIG_FTP_UPLOAD_URL = "ftpUploadUrl"; diff --git a/iplatform-base/src/main/java/com/iplatform/base/config/FileProperties.java b/iplatform-base/src/main/java/com/iplatform/base/config/FileProperties.java index c0ce3cc..aa008a6 100644 --- a/iplatform-base/src/main/java/com/iplatform/base/config/FileProperties.java +++ b/iplatform-base/src/main/java/com/iplatform/base/config/FileProperties.java @@ -30,6 +30,79 @@ this.remoteAsLocal = remoteAsLocal; } + /** + * oss瀹炵幇绫诲瀷锛歛ws_s3锛堜簹椹�婏級 | tx锛堣吘璁級 | ali锛堥樋閲岋級 | qn锛堜竷鐗涳級 + * @return + * @date 2023-12-13 + */ + public String getOssType() { + return ossType; + } + + public void setOssType(String ossType) { + this.ossType = ossType; + } + + /** + * oss璁块棶鍓嶇紑锛屽锛歨ttp://localhost:8082/admin/oss/ + * @return + * @date 2023-12-13 + */ + public String getOssPrefix() { + return ossPrefix; + } + + public void setOssPrefix(String ossPrefix) { + this.ossPrefix = ossPrefix; + } + + public String getOssAccessKey() { + return ossAccessKey; + } + + public void setOssAccessKey(String ossAccessKey) { + this.ossAccessKey = ossAccessKey; + } + + public String getOssSecretKey() { + return ossSecretKey; + } + + public void setOssSecretKey(String ossSecretKey) { + this.ossSecretKey = ossSecretKey; + } + + public String getOssEndpoint() { + return ossEndpoint; + } + + public void setOssEndpoint(String ossEndpoint) { + this.ossEndpoint = ossEndpoint; + } + + public String getOssBucketName() { + return ossBucketName; + } + + public void setOssBucketName(String ossBucketName) { + this.ossBucketName = ossBucketName; + } + + public String getProtocolStr() { + return protocolStr; + } + + public void setProtocolStr(String protocolStr) { + this.protocolStr = protocolStr; + } + + private String ossAccessKey; + private String ossSecretKey; + private String ossEndpoint; + private String ossBucketName; + private String ossType; + private String ossPrefix; + private String protocolStr = "http"; private boolean remoteAsLocal = true; private String fileRoot = null; diff --git a/iplatform-file-server/pom.xml b/iplatform-file-server/pom.xml index 9c0a2e9..b451956 100644 --- a/iplatform-file-server/pom.xml +++ b/iplatform-file-server/pom.xml @@ -39,6 +39,13 @@ <scope>provided</scope> </dependency> + <!-- 浜氶┈閫奡3 OSS 鏈嶅姟閰嶇疆锛�2023-12-12 --> + <dependency> + <groupId>com.amazonaws</groupId> + <artifactId>aws-java-sdk-s3</artifactId> + <version>1.11.126</version> + </dependency> + <!-- |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |~ 浠ヤ笅閰嶇疆涓�"鐙珛閮ㄧ讲鏂瑰紡"锛�2023-02-12 diff --git a/iplatform-file-server/src/main/java/com/iplatform/file/FileEngineFactory.java b/iplatform-file-server/src/main/java/com/iplatform/file/FileEngineFactory.java index 90e0b86..d4e2d0a 100644 --- a/iplatform-file-server/src/main/java/com/iplatform/file/FileEngineFactory.java +++ b/iplatform-file-server/src/main/java/com/iplatform/file/FileEngineFactory.java @@ -1,5 +1,6 @@ package com.iplatform.file; +import com.iplatform.base.PlatformRuntimeException; import com.iplatform.file.util.FileStoreUtils; import com.walker.file.FileInfo; import com.walker.file.FileOperateEngine; @@ -25,6 +26,21 @@ public class FileEngineFactory implements ApplicationBeanInitialized { protected final transient Logger logger = LoggerFactory.getLogger(this.getClass()); + + /** + * 涓嬭浇oss鏂囦欢 + * @param fileStoreType + * @param id 鏂囦欢鍞竴缂栧彿 + * @return + * @date 2023-12-13 + */ + public byte[] downloadOssFile(FileStoreType fileStoreType, String id){ + try { + return this.fileOperateEngineMap.get(fileStoreType).downloadFile(id); + } catch (FileOperateException e) { + throw new PlatformRuntimeException("涓嬭浇oss鏂囦欢閿欒锛�" + e.getMessage() + ", id=" + id, e); + } + } /** * 鏍规嵁鏂囦欢ID锛岃繑鍥炴枃浠跺璞°�� @@ -142,7 +158,8 @@ public FileInfo uploadFileToOss(InputStream inputStream, String fileName, String groupId , long fileSize, Integer businessType, String owner, FileStoreType fileStoreType) throws FileOperateException{ if(fileStoreType != FileStoreType.OssQiNiu - && fileStoreType != FileStoreType.OssTx && fileStoreType != FileStoreType.OssAli){ + && fileStoreType != FileStoreType.OssTx && fileStoreType != FileStoreType.OssAli + && fileStoreType != FileStoreType.OssAws){ throw new UnsupportedOperationException("涓嶆敮鎸佺殑OSS绫诲瀷锛�" + fileStoreType); } if(this.remoteAsLocal){ @@ -155,7 +172,8 @@ public FileInfo[] uploadFileToOss(InputStream[] inputStream, String[] fileName, String groupId , long[] fileSize, Integer businessType, String owner, FileStoreType fileStoreType) throws FileOperateException{ if(fileStoreType != FileStoreType.OssQiNiu - && fileStoreType != FileStoreType.OssTx && fileStoreType != FileStoreType.OssAli){ + && fileStoreType != FileStoreType.OssTx && fileStoreType != FileStoreType.OssAli + && fileStoreType != FileStoreType.OssAws){ throw new UnsupportedOperationException("涓嶆敮鎸佺殑OSS绫诲瀷锛�" + fileStoreType); } if(this.remoteAsLocal){ diff --git a/iplatform-file-server/src/main/java/com/iplatform/file/config/FileConfig.java b/iplatform-file-server/src/main/java/com/iplatform/file/config/FileConfig.java index 3f1ded1..5d5444a 100644 --- a/iplatform-file-server/src/main/java/com/iplatform/file/config/FileConfig.java +++ b/iplatform-file-server/src/main/java/com/iplatform/file/config/FileConfig.java @@ -1,11 +1,13 @@ package com.iplatform.file.config; import com.iplatform.base.config.FileProperties; +import com.iplatform.core.PlatformConfiguration; import com.iplatform.file.FileEngineFactory; import com.iplatform.file.FileStoreCallback; import com.iplatform.file.service.FileServiceImpl; import com.iplatform.file.support.AliOssFileEngine; import com.iplatform.file.support.AttachmentJdbcCallback; +import com.iplatform.file.support.AwsOssFileEngine; import com.iplatform.file.support.DefaultFileSystemEngine; import com.iplatform.file.support.DefaultFtpFileEngine; import com.iplatform.file.support.QnOssFileEngine; @@ -17,7 +19,7 @@ import org.springframework.context.annotation.Configuration; @Configuration -public class FileConfig { +public class FileConfig extends PlatformConfiguration { /** * 閰嶇疆涓�涓枃浠跺紩鎿庡伐鍘傚璞°�� @@ -30,6 +32,7 @@ @Bean public FileEngineFactory fileEngineFactory(DefaultFtpFileEngine ftpFileEngine, DefaultFileSystemEngine fileSystemEngine , QnOssFileEngine qnOssFileEngine, TxOssFileEngine txOssFileEngine, AliOssFileEngine aliOssFileEngine + , AwsOssFileEngine awsOssFileEngine , ArgumentsManager argumentsManager, FileProperties fileProperties){ FileEngineFactory fileEngineFactory = new FileEngineFactory(); fileEngineFactory.register(FileStoreType.Ftp, ftpFileEngine); @@ -37,6 +40,9 @@ fileEngineFactory.register(FileStoreType.OssQiNiu, qnOssFileEngine); fileEngineFactory.register(FileStoreType.OssTx, txOssFileEngine); fileEngineFactory.register(FileStoreType.OssAli, aliOssFileEngine); + // 2023-12-13 + fileEngineFactory.register(FileStoreType.OssAws, awsOssFileEngine); + fileEngineFactory.setArgumentsManager(argumentsManager); fileEngineFactory.setRemoteAsLocal(fileProperties.isRemoteAsLocal()); fileEngineFactory.startup(); @@ -44,6 +50,28 @@ } /** + * 鍒涘缓锛歄SS鏈嶅姟寮曟搸銆� + * + * @param fileProperties + * @param fileStoreCallback + * @return + * @date 2023-12-13 + */ + @Bean + public AwsOssFileEngine awsOssFileEngine(FileProperties fileProperties, FileStoreCallback fileStoreCallback) throws Exception { + AwsOssFileEngine engine = new AwsOssFileEngine(); + engine.setPrefix(fileProperties.getOssPrefix()); + engine.setFileStoreCallback(fileStoreCallback); + engine.setAccessKey(fileProperties.getOssAccessKey()); + engine.setSecretKey(fileProperties.getOssSecretKey()); + engine.setEndpoint(fileProperties.getOssEndpoint()); + engine.setBucketName(fileProperties.getOssBucketName()); + engine.initS3Client(); + logger.info(".............. OSS 鍒濆鍖栵細 浜氶┈閫奡3!"); + return engine; + } + + /** * 闃块噷浜� OSS 鏂囦欢寮曟搸瀹氫箟銆� * @param fileProperties * @param fileStoreCallback diff --git a/iplatform-file-server/src/main/java/com/iplatform/file/support/AbstractOssFileEngine.java b/iplatform-file-server/src/main/java/com/iplatform/file/support/AbstractOssFileEngine.java index 75f0339..ca6f2b8 100644 --- a/iplatform-file-server/src/main/java/com/iplatform/file/support/AbstractOssFileEngine.java +++ b/iplatform-file-server/src/main/java/com/iplatform/file/support/AbstractOssFileEngine.java @@ -38,5 +38,19 @@ this.fileStoreCallback = fileStoreCallback; } + /** + * 杩斿洖OSS璁块棶鍓嶇紑锛岄�氬父鍦ㄩ厤缃畒aml鏂囦欢涓厤缃�� + * @return + * @date 2023-12-13 + */ + public String getPrefix() { + return prefix; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + private String prefix; // oss鍓嶇紑锛�2023-12-13 private FileStoreCallback fileStoreCallback = null; } diff --git a/iplatform-file-server/src/main/java/com/iplatform/file/support/AwsOssFileEngine.java b/iplatform-file-server/src/main/java/com/iplatform/file/support/AwsOssFileEngine.java new file mode 100644 index 0000000..2e25b98 --- /dev/null +++ b/iplatform-file-server/src/main/java/com/iplatform/file/support/AwsOssFileEngine.java @@ -0,0 +1,359 @@ +package com.iplatform.file.support; + +import com.amazonaws.ClientConfiguration; +import com.amazonaws.Protocol; +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.auth.policy.Policy; +import com.amazonaws.auth.policy.Principal; +import com.amazonaws.auth.policy.Resource; +import com.amazonaws.auth.policy.Statement; +import com.amazonaws.auth.policy.actions.S3Actions; +import com.amazonaws.client.builder.AwsClientBuilder; +import com.amazonaws.regions.Regions; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import com.amazonaws.services.s3.model.BucketCrossOriginConfiguration; +import com.amazonaws.services.s3.model.CORSRule; +import com.amazonaws.services.s3.model.ObjectMetadata; +import com.amazonaws.services.s3.model.PutObjectRequest; +import com.amazonaws.services.s3.model.PutObjectResult; +import com.amazonaws.services.s3.model.S3Object; +import com.amazonaws.services.s3.model.S3ObjectInputStream; +import com.amazonaws.services.s3.model.SetBucketPolicyRequest; +import com.walker.file.DefaultFileInfo; +import com.walker.file.FileInfo; +import com.walker.file.FileOperateException; +import com.walker.file.FileStoreType; +import com.walker.infrastructure.utils.Base64; +import com.walker.infrastructure.utils.JsonUtils; +import com.walker.infrastructure.utils.StringUtils; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Calendar; + +/** + * 浜氶┈閫奡3 OSS 瀹炵幇銆� + * + * @author 鏃跺厠鑻� + * @date 2023-12-12 + */ +public class AwsOssFileEngine extends AbstractOssFileEngine { + + public AwsOssFileEngine() { + } + + @Override + protected void executeUpload(InputStream inputStream, FileInfo fileInfo) throws FileOperateException { + //鍒濆鍖栧璞″厓鏁版嵁 + ObjectMetadata metadata = new ObjectMetadata(); + // metadata.setContentType("plain/text"); + AmazonS3 client = this.acquireOneClient(); + + try { + String fileNameBase64 = new String(Base64.encode(fileInfo.getFileName().getBytes(StringUtils.DEFAULT_CHARSET_UTF8))); + metadata.addUserMetadata("x-amz-meta-title", fileNameBase64); + metadata.setContentLength(fileInfo.getFileSize()); + //璁剧疆瀵硅薄鍏冩暟鎹� + String objectKey = fileInfo.getId(); + logger.debug("鍑嗗涓婁紶鏂囦欢 objectKey = {}", objectKey); +// String objectKey = createFileOssPath(fileInfo.getId(), fileInfo.getFileExt()); + PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectKey, inputStream, metadata); +// PutObjectResult result = amazonS3Client.putObject(putObjectRequest); + PutObjectResult result = client.putObject(putObjectRequest); + + System.out.println(JsonUtils.objectToJsonString(result)); + StringBuilder url = new StringBuilder(); + url.append(objectKey); + +// ((DefaultFileInfo) fileInfo).setFileSize(result.getMetadata().getContentLength()); + ((DefaultFileInfo) fileInfo).setUrl(url.toString()); + + } catch (Exception var11) { + throw new FileOperateException("淇濆瓨鏂囦欢鍒般�恛ss銆戦敊璇�:" + var11.getMessage() + ", id=" + fileInfo.getId(), var11); + } finally { + if(client != null){ + client.shutdown(); + } + } + } + + @Override + protected byte[] executeDownload(FileInfo fileInfo) throws FileOperateException { +// throw new IllegalAccessError("涓嶈兘璋冪敤OSS涓嬭浇鏂规硶锛岃璁块棶绗笁鏂归摼鎺�"); + + AmazonS3 client = this.acquireOneClient(); + S3ObjectInputStream objectContent = null; + ByteArrayOutputStream fileOutputStream = null; + try { + //涓嬭浇瀵硅薄 + S3Object object = client.getObject(bucketName, fileInfo.getId()); + //鑾峰彇瀵硅薄娴� + objectContent = object.getObjectContent(); + //鍒濆鍖栨枃浠惰緭鍑烘祦 +// FileOutputStream fileOutputStream = new FileOutputStream(new File(file_path)); + fileOutputStream = new ByteArrayOutputStream(); + + byte[] readbuf = new byte[1024 * 20]; + int read_len = 0; + while ((read_len = objectContent.read(readbuf)) > 0) { + //瀵硅薄涓嬭浇瀛楄妭鍐欏叆鏂囦欢杈撳嚭娴� + fileOutputStream.write(readbuf, 0, read_len); + } + return fileOutputStream.toByteArray(); + + } catch (Exception ex) { + throw new FileOperateException("涓嬭浇鏂囦欢閿欒锛�" + ex.getMessage() + ", fileId=" + fileInfo.getId(), ex); + } finally { + //鍏抽棴娴� + try { + if(objectContent != null){ + objectContent.close(); + } +// if(fileOutputStream != null){ +// fileOutputStream.close(); +// } + if(client != null){ + client.shutdown(); + } + } catch (IOException e) { +// throw new RuntimeException(e); + logger.error("杩欓噷涓嶉渶瑕佹姏鍑哄紓甯革紝浠呯敤浜庤皟璇曠煡閬撴祦娌℃湁琚叧闂嵆鍙��", e); + } + } + } + + @Override + public FileStoreType getFileStoreType() { + return FileStoreType.OssAws; + } + + @Override + public void close() { + super.close(); + this.closeAmazonS3Client(); + } + + private AmazonS3 acquireOneClient(){ + AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); + ClientConfiguration clientConfiguration = new ClientConfiguration(); + + if (endpoint.contains("https")) { + clientConfiguration.setProtocol(Protocol.HTTPS); + logger.error("===================> HTTPS "); + } else { + clientConfiguration.setProtocol(Protocol.HTTP); + logger.error("===================> HTTP "); + } + return AmazonS3ClientBuilder.standard() + .withClientConfiguration(clientConfiguration) + .withEndpointConfiguration( + new AwsClientBuilder.EndpointConfiguration(this.endpoint, Regions.DEFAULT_REGION.getName())) + .withCredentials(new AWSStaticCredentialsProvider(credentials)) + .build(); + +// AmazonS3 amazonS3Client = new AmazonS3Client(credentials, clientConfiguration); +// amazonS3Client.setEndpoint(endpoint); +// amazonS3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).disableChunkedEncoding().build()); +// return amazonS3Client; + } + + /** + * 鍒濆鍖朼mazonS3Client + * @author 鏃跺厠鑻� + * @date 2024-02-02 浣跨敤澶氫緥锛屾棤闇�鍒濆鍖栵紝搴熷純鏂规硶銆� + */ + @Deprecated + public void initS3Client() { + logger.warn("涓嶅啀浣跨敤鍗曚緥锛屾棤闇�鍒濆鍖栵紝姣忔涓婁紶涓嬭浇浼氬垱寤烘柊瀹㈡埛绔繛鎺�!"); +// AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); //鍒涘缓AWS鍑瘉 +// ClientConfiguration connconfig = new ClientConfiguration(); //鍒濆鍖栧鎴风config +// connconfig.setProtocol(Protocol.HTTP); //璁剧疆mos 璇锋眰鍗忚涓篽ttp +// +// //浣跨敤AWS鍑瘉鍜宑lientConfiguration鍒濆鍖朅mazonS3Client瀹㈡埛绔� +// amazonS3Client = new AmazonS3Client(credentials, connconfig); +// amazonS3Client.setEndpoint(endpoint); ////璁剧疆mos瀵硅薄鏈嶅姟鎺ュ彛鍦板潃 +// amazonS3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).disableChunkedEncoding().build()); + + +// AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); +// ClientConfiguration clientConfiguration = new ClientConfiguration(); +// +// if (endpoint.contains("https")) { +// clientConfiguration.setProtocol(Protocol.HTTPS); +// logger.error("===================> HTTPS "); +// } else { +// clientConfiguration.setProtocol(Protocol.HTTP); +// logger.error("===================> HTTP "); +// } +// +// AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(endpoint, "beijing1"); +// AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); +// +// +// amazonS3Client = AmazonS3ClientBuilder.standard() +// .withEndpointConfiguration(endpointConfiguration) +// .withCredentials(credentialsProvider).build(); +//// amazonS3Client = new AmazonS3Client(credentials, clientConfiguration); +//// amazonS3Client.setEndpoint(endpoint); +//// amazonS3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).disableChunkedEncoding().build()); + + + AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); + ClientConfiguration clientConfiguration = new ClientConfiguration(); + + if (endpoint.contains("https")) { + clientConfiguration.setProtocol(Protocol.HTTPS); + logger.error("===================> HTTPS "); + } else { + clientConfiguration.setProtocol(Protocol.HTTP); + logger.error("===================> HTTP "); + } + // 璁剧疆鍏佽鎵撳紑鐨勬渶澶� HTTP 杩炴帴鏁帮紝榛樿涓� 50 涓紝姝ょず渚嬩唬鐮佽缃负 100 涓�� +// clientConfiguration.setMaxConnections(100 * 2); +// // 璁剧疆 Socket 灞備紶杈撴暟鎹殑瓒呮椂鏃堕棿锛堝崟浣嶏細姣锛夛紝榛樿涓� 50000 姣锛屾绀轰緥浠g爜璁剧疆涓� 60000 姣銆� +// clientConfiguration.setSocketTimeout(60000 * 2); +// // 璁剧疆寤虹珛杩炴帴鐨勮秴鏃舵椂闂达紙鍗曚綅锛氭绉掞級锛岄粯璁や负 10000 姣锛屾绀轰緥浠g爜璁剧疆涓� 5000 姣銆� +// clientConfiguration.setConnectionTimeout(5000 * 2); +// // 璁剧疆绛夊緟璇锋眰瀹屾垚鐨勮秴鏃舵椂闂达紙鍗曚綅锛氭绉掞級銆傞粯璁や笉瓒呮椂锛�0锛夛紝姝ょず渚嬩唬鐮佽缃负 60000 姣銆� +// clientConfiguration.setRequestTimeout(60000 * 2); +// // 璁剧疆瀹㈡埛绔姹傛墽琛岃秴鏃舵椂闂达紙鍗曚綅锛氭绉掞級銆傞粯璁や笉瓒呮椂锛�0锛夛紝姝ょず渚嬩唬鐮佽缃负 60000 姣銆� +// clientConfiguration.setClientExecutionTimeout(60000 * 2); +// // 璁剧疆杩炴帴绌洪棽瓒呮椂鏃堕棿銆傝秴鏃跺垯鍏抽棴杩炴帴锛岄粯璁や负 60000 姣锛屾绀轰緥浠g爜璁剧疆涓� 90000 姣銆� +//// clientConfiguration.setConnectionMaxIdleMillis(90000 * 2); +// // 璁剧疆璇锋眰澶辫触鍚庢渶澶х殑閲嶈瘯娆℃暟锛岄粯璁� 3 娆★紝姝ょず渚嬩唬鐮佽缃负 5 娆°�� +// clientConfiguration.setMaxErrorRetry(5); + // 璁剧疆杩炴帴 EOS 鎵�浣跨敤鐨勫崗璁紙HTTP 鎴� HTTPS锛夛紝榛樿涓� HTTPS锛屾绀轰緥浠g爜璁剧疆涓� HTTP銆� +// clientConfiguration.setProtocol(Protocol.HTTP); + // 璁剧疆鐢ㄦ埛浠g悊鍓嶇紑锛屽嵆 HTTP 鐨� User-Agent 澶寸殑鍓嶇紑锛屾绀轰緥浠g爜璁剧疆涓� "EOS S3 Java SDK"銆� +// clientConfiguration.setUserAgentPrefix("EOS S3 Java SDK"); + // 璁剧疆鐢ㄦ埛浠g悊鍚庣紑锛屽嵆 HTTP 鐨� User-Agent 澶寸殑鍚庣紑锛屾绀轰緥浠g爜璁剧疆涓� "1.12.378"銆� +// clientConfiguration.setUserAgentSuffix("1.12.378"); + // 璁剧疆绛惧悕绠楁硶锛岄粯璁や负 v4 绛惧悕銆傛绀轰緥浠g爜璁剧疆涓� S3SignerType锛屽嵆閲囩敤 v2 绛惧悕銆� +// clientConfiguration.setSignerOverride("S3SignerType"); + + // 2024-02-02锛屼笉鐢ㄥ崟渚嬶紝浣跨敤澶氫緥鍗筹細姣忔璋冪敤鍒涘缓瀹㈡埛绔柟寮忥紒 +// amazonS3Client = new AmazonS3Client(credentials, clientConfiguration); +// amazonS3Client.setEndpoint(endpoint); +// amazonS3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).disableChunkedEncoding().build()); + } + + /** + * 瀵瑰簲MOS JAVA SDK鏂囨。4.3.6绔犺妭 璁剧疆瀛樺偍妗剁瓥鐣� + */ + @Deprecated + public void setBucketPolicy() throws IOException { +// List<String> readLines = Files.readLines(new File("policy.txt"), Charset.forName("utf8")); +// StringBuilder sb = new StringBuilder(); +// for(String str : readLines) +// { +// sb.append(str); +// } +// System.out.println(sb.toString()); +// +// //policy 淇℃伅鏌ョ湅椤圭洰鏍圭洰褰� policy.txt鏂囦欢 +// String policy = sb.toString(); +// amazonS3Client.setBucketPolicy(bucket_name, policy); + + //閫氳繃Policy绫绘瀯寤烘《绛栫暐 + Policy bucket_policy = new Policy().withStatements(new Statement( + Statement.Effect.Allow) + .withPrincipals(Principal.AllUsers) + .withActions(S3Actions.GetObject) + .withResources( + new Resource("arn:aws:s3:::" + bucketName + "/*"))); + + SetBucketPolicyRequest setBucketPolicyRequest = new SetBucketPolicyRequest(bucketName, bucket_policy.toJson()); + + //璁剧疆妗剁瓥鐣� +// amazonS3Client.setBucketPolicy(setBucketPolicyRequest); + } + + @Deprecated + public void configBucketCors() { + // 閰嶇疆璺ㄥ煙璁块棶绛栫暐 + BucketCrossOriginConfiguration conf = new BucketCrossOriginConfiguration() + .withRules( + new CORSRule() + .withId("1")// 閰嶇疆瑙勫垯 ID + .withAllowedHeaders(Arrays.asList("*")) // 璺ㄥ煙璇锋眰鍙互浣跨敤鐨� HTTP 璇锋眰澶撮儴锛屾敮鎸侀�氶厤绗� * + .withAllowedMethods(Arrays.asList(CORSRule.AllowedMethods.GET, CORSRule.AllowedMethods.PUT))// 璺ㄥ煙璇锋眰鍏佽鐨� HTTP 鎿嶄綔锛屼緥濡傦細GET锛孭UT锛孒EAD锛孭OST锛孌ELETE +// .withAllowedOrigins(Arrays.asList("http://www.example1.com"))// 鍏佽鐨勮闂潵婧愶紝鏀寔閫氶厤绗� *锛屾牸寮忎负锛氬崗璁�://鍩熷悕[:绔彛] +// .withMaxAgeSeconds(30)// 璺ㄥ煙璇锋眰寰楀埌缁撴灉鐨勬湁鏁堟湡 + ); +// SetBucketCrossOriginConfigurationRequest req = new SetBucketCrossOriginConfigurationRequest("bkt", conf); +// amazonS3Client.setBucketCrossOriginConfiguration(req); + + // 鍒犻櫎璺ㄥ煙璁块棶绛栫暐 +// amazonS3Client.deleteBucketCrossOriginConfiguration("1"); + } + + /** + * 鍏抽棴amazonS3Client + */ + private void closeAmazonS3Client() { +// if (this.amazonS3Client != null) { +// amazonS3Client.shutdown(); //鍏抽棴瀹㈡埛绔� +// } + } + + public byte[] testDownload(String fileId){ + DefaultFileInfo fileInfo = new DefaultFileInfo(); + fileInfo.setId(fileId); + try { + return this.executeDownload(fileInfo); + } catch (FileOperateException e) { + throw new RuntimeException("涓嬭浇oss鏂囦欢鎶ラ敊锛�" + e.getMessage() + ", fileId=" + fileId, e); + } + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public void setEndpoint(String endpoint) { + this.endpoint = endpoint; + } + + public void setBucketName(String bucketName) { + this.bucketName = bucketName; + } + + public void setProtocol(Protocol protocol) { + this.protocol = protocol; + } + + private String bucketName = "ctoms-file"; + public String endpoint = "http://10.2.36.9:8080"; + private String accessKey = "4XJOR8RXEWWRVV8N4HOC"; + private String secretKey = "1Dp2ua3lcCocEQJMf1VtHBABPfpkUxF4gGE3xacW"; + private Protocol protocol = Protocol.HTTP; + +// private AmazonS3 amazonS3Client; + + public String createFileOssPath(String fileId, String ext) { + Calendar ca = Calendar.getInstance(); + String year = ca.get(Calendar.YEAR) + ""; + String mon = ca.get(Calendar.MONTH) + 1 + ""; + String day = ca.get(Calendar.DAY_OF_MONTH) + ""; + String directory = year + "/" + mon + "/" + day + "/"; +// mkdirFolder(directory); + return fileId + StringUtils.SYMBOL_DOT + ext; + } + + // 涓婁紶鍓嶄笂璁剧疆鏂囦欢澶� + public boolean mkdirFolder(String directory) { + AmazonS3 client = this.acquireOneClient(); + PutObjectResult putObjectResult = client.putObject(bucketName, directory, new ByteArrayInputStream(new byte[0]), null); + return putObjectResult != null; + } +} diff --git a/iplatform-support-mybatis/pom.xml b/iplatform-support-mybatis/pom.xml index c16d53b..1a8584a 100644 --- a/iplatform-support-mybatis/pom.xml +++ b/iplatform-support-mybatis/pom.xml @@ -48,6 +48,12 @@ <artifactId>iplatform-core</artifactId> </dependency> + <!-- 鎻愪緵鏁版嵁搴搄dbc鏀寔锛屾煡璇㈣〃鍏冩暟鎹�, 2024/02/20 --> + <dependency> + <groupId>com.walkersoft</groupId> + <artifactId>walker-jdbc</artifactId> + </dependency> + <!--velocity浠g爜鐢熸垚浣跨敤妯℃澘 --> <!-- <dependency>--> <!-- <groupId>org.apache.velocity</groupId>--> diff --git a/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/service/MetaDataServiceImpl.java b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/service/MetaDataServiceImpl.java new file mode 100644 index 0000000..94d5a4f --- /dev/null +++ b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/service/MetaDataServiceImpl.java @@ -0,0 +1,179 @@ +package com.iplatform.mybatis.service; + +import com.iplatform.mybatis.domain.GenTable; +import com.iplatform.mybatis.domain.GenTableColumn; +import com.iplatform.mybatis.util.DataTypeUtils; +import com.iplatform.mybatis.util.SqlUtils; +import com.walker.db.DatabaseType; +import com.walker.infrastructure.utils.DateUtils; +import com.walker.infrastructure.utils.StringUtils; +import com.walker.jdbc.JdbcInspector; +import com.walker.jdbc.service.BaseServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class MetaDataServiceImpl extends BaseServiceImpl { + + /** + * 杩斿洖浠庡厓鏁版嵁涓煡璇㈢殑琛ㄧ粨鏋勪俊鎭� + * @param tableName 琛ㄥ悕绉帮紝鍙互鏄〃鍓嶇紑 + * @param isPrecision 鏄惁绮剧‘鏌ユ壘锛屽鏋滄槸鍒欎粎杩斿洖鍜岃〃鍚嶄竴鏍风殑琛ㄧ粨鏋勩�� + * @param packageName 鍖呭悕绉帮紝蹇呭~ + * @param moduleName 妯″潡鍚嶇О锛岄�夊~ + * @param businessName 涓氬姟鍚嶇О锛岄�夊~ + * @param functionName 鍔熻兘鍚嶇О锛岄�夊~ + * @return + * @date 2024-02-20 + */ + public List<GenTable> queryDatabaseTableInfo(String tableName, boolean isPrecision + , String packageName, String moduleName, String businessName, String functionName){ + List<GenTable> genTableList = new ArrayList<>(8); + DatabaseType databaseType = JdbcInspector.getInstance().getPrimaryDatabaseType(); + log.debug("databaseType = " + databaseType.toString()); + if(DataTypeUtils.isOracle(databaseType)){ + // oracle鍏冩暟鎹腑琛ㄥ悕閮芥槸澶у啓 + tableName = tableName.toUpperCase(); + } else { + tableName = tableName.toLowerCase(); + } + + Map<String, Object> sqlMap = new HashMap<>(); + if(isPrecision){ + sqlMap.put("tablename", "%" + tableName); + } else { + sqlMap.put("tablename", tableName + "%"); + } + + String sql_table = ""; +// String sql_pk = ""; + String sql_column = ""; + + if (DataTypeUtils.isOracle(databaseType)) { + sql_table = "select table_name from user_tables where table_name like :tablename order by table_name desc"; +// sql_pk = "select col.table_name,col.column_name from user_constraints con,user_cons_columns col where con.constraint_name=col.constraint_name and con.constraint_type='P' and col.table_name like :tablename "; + sql_column = SqlUtils.ORACLE_QUERY_COLUMNS; + } else if(DataTypeUtils.isMysql(databaseType)) { + sql_table = "select table_name from information_schema.tables where table_schema=(SELECT DATABASE()) and table_name like :tablename order by table_name desc"; +// sql_pk = "select table_name,column_name from INFORMATION_SCHEMA.Columns where column_key='PRI' AND table_schema=(SELECT DATABASE()) and table_name like :tablename"; + sql_column = "select table_name,column_name,data_type,NUMERIC_PRECISION data_precision,NUMERIC_SCALE data_scale, column_key from INFORMATION_SCHEMA.Columns where table_schema=(SELECT DATABASE()) and table_name like :tablename order by table_name,ordinal_position\n"; + + } else if(databaseType == DatabaseType.POSTGRES){ + sql_table = "SELECT c.relname table_name from pg_class c, pg_namespace n where c.relkind = 'r' and n.nspname = 'public' and c.relnamespace = n.oid and c.relname like :tablename"; + sql_column = SqlUtils.SQL_PG_FIELDS; + log.debug("POSTGRES......"); + + } else { + throw new UnsupportedOperationException("锛坧o鐢熸垚锛変笉鏀寔鐨勬暟鎹簱绫诲瀷锛�" + databaseType); + } + List<Map<String, Object>> table_list = this.dao.select(sql_table, sqlMap); + List<Map<String, Object>> column_list = this.dao.select(sql_column, sqlMap); + + log.debug("鐢熸垚琛ㄧ粨鏋勶紙PO锛� = {}", table_list); + + for (Map<String, Object> table : table_list) { + String table_name = table.get("table_name").toString(); + String pk_name = "id"; + String pk_type = "NUMBER"; + List<Map<String, Object>> column_temp = new ArrayList<>(); + + String columnKey = null; + for (Map<String, Object> column : column_list) { + if(!column.get("table_name").toString().equalsIgnoreCase(table.get("table_name").toString())){ + // 鍙湁褰撳墠琛ㄥ瓧娈垫墠澶勭悊锛岃�佷唬鐮侀亶鍘嗘墍鏈夎〃瀛楁鏈夐棶棰樸��2022-09-20 + continue; + } + // 2022-09-07 淇敼锛堝悗缁湁oracle闇�姹傝繕闇�瑕佹敼锛� + if(column.get("column_key") != null){ + columnKey = column.get("column_key").toString(); + if(DataTypeUtils.isPrimaryColumn(columnKey)){ + // mysql涓婚敭瀛楁鏄細PRI锛宱racle鏄細P锛�2023-03-03 淇敼 + pk_name = column.get("column_name").toString().toLowerCase(); + pk_type = column.get("data_type").toString().toLowerCase(); + log.info(table_name + " 鎵惧埌涓婚敭:" + pk_name + ", " + pk_type); + continue; + } + } + + if ((table_name.equalsIgnoreCase(column.get("table_name").toString())) && (!column.get("column_name").toString().equalsIgnoreCase(pk_name))) { + String type = column.get("data_type").toString().toLowerCase(); + column.put("name", column.get("column_name").toString().toLowerCase()); + if ((type.equalsIgnoreCase("number")) || (type.equalsIgnoreCase("decimal"))) { + int precision = Integer.valueOf(column.get("data_precision") == null ? "0" : column.get("data_precision").toString()).intValue(); + int scale = Integer.valueOf(column.get("data_scale") == null ? "0" : column.get("data_scale").toString()).intValue(); + type = DataTypeUtils.getType(type, precision, scale); + } + column.put("type", type); + column_temp.add(column); + } + } + table.put("table_name", table_name.toLowerCase()); + table.put("pk_name", pk_name); +// table.put("pk_type", pk_type); + table.put("pk_type", DataTypeUtils.getType(pk_type, 0, 0)); + table.put("columns", column_temp); + + GenTable genTable = this.acquireGenTable(table, packageName, moduleName, businessName, functionName, pk_name); + genTableList.add(genTable); + } + return genTableList; + } + + private GenTable acquireGenTable(Map<String, Object> table + , String packageName, String moduleName, String businessName, String functionName, String pkName){ + GenTable genTable = new GenTable(); + genTable.setCreateTime(DateUtils.getDateTimeNumber()); + genTable.setTableName(table.get("table_name").toString()); + genTable.setTableComment(StringUtils.EMPTY_STRING); + genTable.setClassName(StringUtils.transferUnderlineName2Camel(genTable.getTableName(), true)); + genTable.setTplCategory("crud"); + genTable.setGenType("0"); + genTable.setFunctionAuthor("shikeying"); + genTable.setPackageName(packageName); +// genTable.setGenPath("/"); + if(StringUtils.isNotEmpty(moduleName)){ + genTable.setModuleName(moduleName); + } + if(StringUtils.isNotEmpty(businessName)){ + genTable.setBusinessName(businessName); + } + if(StringUtils.isNotEmpty(functionName)){ + genTable.setFunctionName(functionName); + } + + List<GenTableColumn> genTableColumnList = new ArrayList<>(); + List<Map<String, Object>> columns = (List<Map<String, Object>>)table.get("columns"); + GenTableColumn genTableColumn = null; + boolean isPrimaryKey = false; + + for(Map<String, Object> map : columns){ + if(StringUtils.isNotEmpty(pkName) && map.get("column_name").toString().equals(pkName)){ + isPrimaryKey = true; + } + genTableColumn = this.acquireGenColumn(map, isPrimaryKey); + if(isPrimaryKey){ + genTable.setPkColumn(genTableColumn); + } + genTableColumnList.add(genTableColumn); + } + genTable.setColumns(genTableColumnList); + return genTable; + } + + private GenTableColumn acquireGenColumn(Map<String, Object> map, boolean isPrimaryKey){ + GenTableColumn genTableColumn = new GenTableColumn(); + genTableColumn.setCreateTime(DateUtils.getDateTimeNumber()); + genTableColumn.setColumnName(map.get("column_name").toString()); + genTableColumn.setColumnType(map.get("type").toString()); + genTableColumn.setColumnComment(StringUtils.EMPTY_STRING); + if(isPrimaryKey){ + genTableColumn.setIsPk("1"); + } + genTableColumn.setJavaField(StringUtils.transferUnderlineName2Camel(genTableColumn.getColumnName(), true)); + return genTableColumn; + } +} diff --git a/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/util/DataTypeUtils.java b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/util/DataTypeUtils.java new file mode 100644 index 0000000..4f7b9e0 --- /dev/null +++ b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/util/DataTypeUtils.java @@ -0,0 +1,90 @@ +package com.iplatform.mybatis.util; + +import com.walker.db.DatabaseType; + +public class DataTypeUtils { + + public static final String PRIMARY_KEY_MYSQL = "PRI"; + public static final String PRIMARY_KEY_ORACLE = "P"; + + public static boolean isMysql(DatabaseType databaseType){ +// if (databaseType == DatabaseType.ORACLE || databaseType == DatabaseType.DAMENG) { +// return false; +// } else { +// return true; +// } + return databaseType == DatabaseType.MYSQL || databaseType == DatabaseType.SQLITE; + } + + public static boolean isOracle(DatabaseType databaseType){ + if (databaseType == DatabaseType.ORACLE || databaseType == DatabaseType.DAMENG) { + return true; + } + return false; + } + + public static boolean isPrimaryColumn(String columnKey){ + if(columnKey.equalsIgnoreCase(PRIMARY_KEY_MYSQL) || columnKey.equalsIgnoreCase(PRIMARY_KEY_ORACLE)){ + return true; + } + return false; + } + + public static String getType(String type_name, int column_size, int decimal_digits) { + if (type_name.contains("CHAR") + || type_name.toLowerCase().indexOf("varchar") >= 0 + || type_name.equalsIgnoreCase("nvarchar2") + // PG鏁版嵁搴撳瓧绗︿覆瀛楁绫诲瀷锛�2023-10-10 + || type_name.indexOf("character") >= 0) + return "string"; + if (("NUMBER".equalsIgnoreCase(type_name)) || ("DECIMAL".equalsIgnoreCase(type_name))) { + if (decimal_digits == 0) { + if (column_size > 0 && column_size <= 8) { + return "int"; + } + return "long"; + } + + if (column_size < 14) { + return "double"; + } + return "big_decimal"; + } + + // 2023-10-10 postgresql + if(type_name.equalsIgnoreCase("integer")){ + if(column_size > 4){ + // 8 浣嶈〃绀洪暱鏁村舰 + return "long"; + } else { + return "int"; + } + } + if(type_name.indexOf("numeric") >= 0){ + return "double"; + } + + if (("DATE".equalsIgnoreCase(type_name)) || ("DATETIME".equalsIgnoreCase(type_name)) || (type_name.startsWith("TIMESTAMP"))) + return "date"; + if ("INT".equalsIgnoreCase(type_name)) + return "int"; + if (("Long".equalsIgnoreCase(type_name)) || ("BIGINT".equalsIgnoreCase(type_name))) + return "long"; + if ("FLOAT".equalsIgnoreCase(type_name)) + return "float"; + if ("SMALLINT".equalsIgnoreCase(type_name)) + return "int"; + if ("TINYINT".equalsIgnoreCase(type_name)) + return "byte"; + if ("DOUBLE".equalsIgnoreCase(type_name) || type_name.indexOf("double") >= 0) + return "double"; + if (("CLOB".equalsIgnoreCase(type_name)) || ("TEXT".equalsIgnoreCase(type_name)) || ("MEDIUMTEXT".equalsIgnoreCase(type_name)) || ("LONGTEXT".equalsIgnoreCase(type_name))) +// return "materialized_clob"; + return "string"; + if (type_name.contains("BLOB")) { + return "materialized_blob"; + } + throw new RuntimeException("绫诲瀷 " + type_name + " 涓嶆敮鎸�! "); + } + +} diff --git a/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/util/SqlUtils.java b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/util/SqlUtils.java new file mode 100644 index 0000000..26fde91 --- /dev/null +++ b/iplatform-support-mybatis/src/main/java/com/iplatform/mybatis/util/SqlUtils.java @@ -0,0 +1,29 @@ +package com.iplatform.mybatis.util; + +public class SqlUtils { + + public static final String SQL_PG_FIELDS = "SELECT\n" + + "\tC.relname table_name,\n" + + "\tA.attname AS column_name, A.attlen data_precision,\n" + + "\tformat_type ( A.atttypid, A.atttypmod ) AS data_type,\n" + + "\tcol_description ( A.attrelid, A.attnum ) AS COMMENT, 0 AS data_scale,\n" + + "(CASE WHEN ( SELECT COUNT(*) FROM pg_constraint WHERE conrelid = a.attrelid AND conkey[1]= attnum AND contype = 'p' ) > 0 THEN\n" + + " 'PRI' ELSE '' \n" + + " END ) AS column_key\n" + + "FROM\n" + + "\tpg_class AS C,\n" + + "\tpg_attribute AS A,\n" + + "\tpg_tables AS B\n" + + "WHERE A.attrelid = C.oid\n" + + " and C.relname=B.tablename\n" + + " AND A.attnum > 0\n" + + " AND B.schemaname = 'public' and c.relname like :tablename"; + + public static final String ORACLE_QUERY_COLUMNS = new StringBuilder("select t1.*, ucc.constraint_name, uc.constraint_type column_key from (") + .append("select c.table_name, c.column_name, c.data_type, c.data_length, c.data_precision, c.data_scale, c.nullable, c.column_id, s.comments ") + .append("from user_tab_columns c, user_col_comments s ") + .append("where c.table_name like :tablename and c.table_name = s.table_name and c.column_name = s.column_name order by c.column_id") + .append(") t1 ") + .append("left join user_cons_columns ucc on ucc.table_name=t1.table_name and ucc.column_name=t1.column_name ") + .append("left join user_constraints uc on uc.constraint_name=ucc.constraint_name").toString(); +} diff --git a/iplatform-test-mybatis/pom.xml b/iplatform-test-mybatis/pom.xml new file mode 100644 index 0000000..a4b91dd --- /dev/null +++ b/iplatform-test-mybatis/pom.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>iplatform</artifactId> + <groupId>com.iplatform</groupId> + <version>2.7.18</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>iplatform-test-mybatis</artifactId> + <name>iplatform-test-mybatis</name> + <packaging>jar</packaging> + + <properties> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>com.iplatform</groupId> + <artifactId>iplatform-support-mybatis</artifactId> + </dependency> + + </dependencies> + +</project> diff --git a/iplatform-test-mybatis/src/main/java/com/iplatform/test/Test1.java b/iplatform-test-mybatis/src/main/java/com/iplatform/test/Test1.java new file mode 100644 index 0000000..58e3f24 --- /dev/null +++ b/iplatform-test-mybatis/src/main/java/com/iplatform/test/Test1.java @@ -0,0 +1,4 @@ +package com.iplatform.test; + +public class Test1 { +} diff --git a/iplatform-test-mybatis/src/main/java/com/iplatform/test/controller/EbUserController.java b/iplatform-test-mybatis/src/main/java/com/iplatform/test/controller/EbUserController.java new file mode 100644 index 0000000..31e1423 --- /dev/null +++ b/iplatform-test-mybatis/src/main/java/com/iplatform/test/controller/EbUserController.java @@ -0,0 +1,107 @@ +package com.iplatform.test.controller; + +import java.util.List; +import java.util.Arrays; + +import com.insurance.common.annotation.RepeatSubmit; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.insurance.common.annotation.Log; +import com.insurance.common.core.controller.BaseController; +import com.insurance.common.core.domain.AjaxResult; +import com.insurance.common.enums.BusinessType; +import com.iplatform.test.domain.vo.EbUserVo; +import com.iplatform.test.domain.bo.EbUserBo; +import com.iplatform.test.domain.bo.EbUserQueryBo; +import com.iplatform.test.service.IEbUserService; +import com.insurance.common.utils.poi.ExcelUtil; +import com.insurance.common.core.page.TableDataInfo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; + +/** + * 銆愯濉啓鍔熻兘鍚嶇О銆慍ontroller + * + * @author shikeying + * @date 2024-02-20 + */ +@Api(value = "銆愯濉啓鍔熻兘鍚嶇О銆戞帶鍒跺櫒", tags = {"銆愯濉啓鍔熻兘鍚嶇О銆戠鐞�"}) +@RequiredArgsConstructor(onConstructor_ = @Autowired) +@RestController +@RequestMapping("/${moduleName}/${businessName}") +public class EbUserController extends BaseController { + + private final IEbUserService iEbUserService; + + + @ApiOperation("鏌ヨ銆愯濉啓鍔熻兘鍚嶇О銆戝垪琛�") + @GetMapping("/list") + public TableDataInfo list(EbUserQueryBo bo) + { + startPage(); + List<EbUserVo> list = iEbUserService.queryList(bo); + return getDataTable(list); + } + + + + @ApiOperation("瀵煎嚭銆愯濉啓鍔熻兘鍚嶇О銆戝垪琛�") + //@PreAuthorize("@ss.hasPermi('null:null:export')") + @Log(title = "銆愯濉啓鍔熻兘鍚嶇О銆�", businessType = BusinessType.EXPORT) + @GetMapping("/export") + @RepeatSubmit + public AjaxResult export(EbUserQueryBo bo) + { + List<EbUserVo> list = iEbUserService.queryList(bo); + ExcelUtil<EbUserVo> util = new ExcelUtil<EbUserVo>(EbUserVo.class); + return util.exportExcel(list, "銆愯濉啓鍔熻兘鍚嶇О銆�"); + } + + + @ApiOperation("鑾峰彇銆愯濉啓鍔熻兘鍚嶇О銆戣缁嗕俊鎭�") + @GetMapping("/{${pkColumn.javaField}}") + public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}" ) ${pkColumn.javaType} ${pkColumn.javaField}) + { + return AjaxResult.success(iEbUserService.queryById(${pkColumn.javaField})); + } + + + @ApiOperation("鏂板銆愯濉啓鍔熻兘鍚嶇О銆�") + //@PreAuthorize("@ss.hasPermi('null:null:add')") + @Log(title = "銆愯濉啓鍔熻兘鍚嶇О銆�", businessType = BusinessType.INSERT) + @PostMapping("/add") + @RepeatSubmit + public AjaxResult add(@RequestBody EbUserBo bo) + { + return toAjax(iEbUserService.insertByBo(bo) ? 1 : 0); + } + + + @ApiOperation("淇敼銆愯濉啓鍔熻兘鍚嶇О銆�") + //@PreAuthorize("@ss.hasPermi('null:null:edit')") + @Log(title = "銆愯濉啓鍔熻兘鍚嶇О銆�", businessType = BusinessType.UPDATE) + @PostMapping("/upd") + @RepeatSubmit + public AjaxResult upd(@RequestBody EbUserBo bo) + { + return toAjax(iEbUserService.updateByBo(bo) ? 1 : 0); + } + + + @ApiOperation("鍒犻櫎銆愯濉啓鍔熻兘鍚嶇О銆�") + //@PreAuthorize("@ss.hasPermi('null:null:remove')") + @Log(title = "銆愯濉啓鍔熻兘鍚嶇О銆�" , businessType = BusinessType.DELETE) + @DeleteMapping("/{${pkColumn.javaField}s}") + @RepeatSubmit + public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) + { + return toAjax(iEbUserService.deleteByIds(Arrays.asList(${pkColumn.javaField}s)) ? 1 : 0); + } +} diff --git a/iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/EbUser.java b/iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/EbUser.java new file mode 100644 index 0000000..8a7cb63 --- /dev/null +++ b/iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/EbUser.java @@ -0,0 +1,158 @@ +package com.iplatform.test.domain; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; +//import io.swagger.annotations.ApiModel; +//import io.swagger.annotations.ApiModelProperty; +/** + * 銆愯濉啓鍔熻兘鍚嶇О銆戝璞� eb_user + * + * @author shikeying + * @date 2024-02-20 + */ +@Data +@NoArgsConstructor +@Accessors(chain = true) +@TableName("eb_user") +//@ApiModel("銆愯濉啓鍔熻兘鍚嶇О銆戝疄浣撳璞�") +public class EbUser implements Serializable { + + private static final long serialVersionUID=1L; + + + @ApiModelProperty("") + private $column.javaType Account; + + @ApiModelProperty("") + private $column.javaType Pwd; + + @ApiModelProperty("") + private $column.javaType RealName; + + @ApiModelProperty("") + private $column.javaType Birthday; + + @ApiModelProperty("") + private $column.javaType IdentityCardNo; + + @ApiModelProperty("") + private $column.javaType TagId; + + @ApiModelProperty("") + private $column.javaType Nickname; + + @ApiModelProperty("") + private $column.javaType Avatar; + + @ApiModelProperty("") + private $column.javaType Phone; + + @ApiModelProperty("") + private $column.javaType Country; + + @ApiModelProperty("") + private $column.javaType Province; + + @ApiModelProperty("") + private $column.javaType City; + + @ApiModelProperty("") + private $column.javaType District; + + @ApiModelProperty("") + private $column.javaType Address; + + @ApiModelProperty("") + private $column.javaType Sex; + + @ApiModelProperty("") + private $column.javaType Integral; + + @ApiModelProperty("") + private $column.javaType Experience; + + @ApiModelProperty("") + private $column.javaType NowMoney; + + @ApiModelProperty("") + private $column.javaType BrokeragePrice; + + @ApiModelProperty("") + private $column.javaType Level; + + @ApiModelProperty("") + private $column.javaType SignNum; + + @ApiModelProperty("") + private $column.javaType IsWechatPublic; + + @ApiModelProperty("") + private $column.javaType IsWechatRoutine; + + @ApiModelProperty("") + private $column.javaType PayCount; + + @ApiModelProperty("") + private $column.javaType IsPromoter; + + @ApiModelProperty("") + private $column.javaType PromoterTime; + + @ApiModelProperty("") + private $column.javaType SpreadUid; + + @ApiModelProperty("") + private $column.javaType SpreadTime; + + @ApiModelProperty("") + private $column.javaType SpreadCount; + + @ApiModelProperty("") + private $column.javaType RegisterType; + + @ApiModelProperty("") + private $column.javaType AddIp; + + @ApiModelProperty("") + private $column.javaType LastIp; + + @ApiModelProperty("") + private $column.javaType LastLoginTime; + + @ApiModelProperty("") + private $column.javaType Status; + + @ApiModelProperty("") + private $column.javaType Mark; + + @ApiModelProperty("") + private $column.javaType CreateTime; + + @ApiModelProperty("") + private $column.javaType UpdateTime; + + @ApiModelProperty("") + private $column.javaType IsLogoff; + + @ApiModelProperty("") + private $column.javaType LogoffTime; + + @ApiModelProperty("") + private $column.javaType IsWechatIos; + + @ApiModelProperty("") + private $column.javaType IsWechatAndroid; + + @ApiModelProperty("") + private $column.javaType IsBindingIos; + + @ApiModelProperty("") + private $column.javaType MoneySign; + +} diff --git a/iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/bo/EbUserBo.java b/iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/bo/EbUserBo.java new file mode 100644 index 0000000..61bb987 --- /dev/null +++ b/iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/bo/EbUserBo.java @@ -0,0 +1,20 @@ +package com.iplatform.test.domain.bo; + +//import io.swagger.annotations.ApiModel; +//import io.swagger.annotations.ApiModelProperty; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import java.util.Date; + + +/** + * 銆愯濉啓鍔熻兘鍚嶇О銆戠紪杈戝璞� eb_user + * + * @author shikeying + * @date 2024-02-20 + */ +@Data +//@ApiModel("銆愯濉啓鍔熻兘鍚嶇О銆戞搷浣滃璞�") +public class EbUserBo { + +} diff --git a/iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/bo/EbUserQueryBo.java b/iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/bo/EbUserQueryBo.java new file mode 100644 index 0000000..3f10f18 --- /dev/null +++ b/iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/bo/EbUserQueryBo.java @@ -0,0 +1,36 @@ +package com.iplatform.test.domain.bo; + +import com.insurance.common.core.domain.BaseQuery; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +/** + * 銆愯濉啓鍔熻兘鍚嶇О銆戝垎椤垫煡璇㈠璞� eb_user + * + * @author shikeying + * @date 2024-02-20 + */ +@EqualsAndHashCode(callSuper = true) +@Data +//@ApiModel("銆愯濉啓鍔熻兘鍚嶇О銆戝垎椤垫煡璇㈠璞�") +public class EbUserQueryBo extends BaseQuery{ + + /** 鍒嗛〉澶у皬 */ + @ApiModelProperty("鍒嗛〉澶у皬") + private Integer pageSize; + /** 褰撳墠椤垫暟 */ + @ApiModelProperty("褰撳墠椤垫暟") + private Integer pageNum; + /** 鎺掑簭鍒� */ + @ApiModelProperty("鎺掑簭鍒�") + private String orderByColumn; + /** 鎺掑簭鐨勬柟鍚慸esc鎴栬�卆sc */ + @ApiModelProperty(value = "鎺掑簭鐨勬柟鍚�", example = "asc,desc") + private String isAsc; + + + +} diff --git a/iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/vo/EbUserVo.java b/iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/vo/EbUserVo.java new file mode 100644 index 0000000..1169558 --- /dev/null +++ b/iplatform-test-mybatis/src/main/java/com/iplatform/test/domain/vo/EbUserVo.java @@ -0,0 +1,25 @@ +package com.iplatform.test.domain.vo; + +import com.iplatform.mybatis.Excel; +import com.fasterxml.jackson.annotation.JsonFormat; +//import io.swagger.annotations.ApiModel; +//import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 銆愯濉啓鍔熻兘鍚嶇О銆戣鍥惧璞� mall_package + * + * @author shikeying + * @date 2024-02-20 + */ +@Data +//@ApiModel("銆愯濉啓鍔熻兘鍚嶇О銆戣鍥惧璞�") +public class EbUserVo { + private static final long serialVersionUID = 1L; + + /** $pkColumn.columnComment */ + //@ApiModelProperty("$pkColumn.columnComment") + private ${pkColumn.javaType} ${pkColumn.javaField}; + + +} diff --git a/iplatform-test-mybatis/src/main/java/com/iplatform/test/mapper/EbUserMapper.java b/iplatform-test-mybatis/src/main/java/com/iplatform/test/mapper/EbUserMapper.java new file mode 100644 index 0000000..7c2adcf --- /dev/null +++ b/iplatform-test-mybatis/src/main/java/com/iplatform/test/mapper/EbUserMapper.java @@ -0,0 +1,14 @@ +package com.iplatform.test.mapper; + +import com.iplatform.test.domain.EbUser; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + * 銆愯濉啓鍔熻兘鍚嶇О銆慚apper鎺ュ彛 + * + * @author shikeying + * @date 2024-02-20 + */ +public interface EbUserMapper extends BaseMapper<EbUser> { + +} diff --git a/iplatform-test-mybatis/src/main/java/com/iplatform/test/service/IEbUserService.java b/iplatform-test-mybatis/src/main/java/com/iplatform/test/service/IEbUserService.java new file mode 100644 index 0000000..e41ec98 --- /dev/null +++ b/iplatform-test-mybatis/src/main/java/com/iplatform/test/service/IEbUserService.java @@ -0,0 +1,53 @@ +package com.iplatform.test.service; + +import com.iplatform.test.domain.EbUser; +import com.iplatform.test.domain.vo.EbUserVo; +import com.iplatform.test.domain.bo.EbUserBo; +import com.iplatform.test.domain.bo.EbUserQueryBo; +import com.baomidou.mybatisplus.extension.service.IService; +import com.iplatform.mybatis.IBaseService; + +import java.util.Collection; +import java.util.List; + +/** + * 銆愯濉啓鍔熻兘鍚嶇О銆慡ervice鎺ュ彛 + * + * @author shikeying + * @date 2024-02-20 + */ +public interface IEbUserService extends IBaseService<EbUser> { + + /** + * 鏌ヨ鍒楄〃 + */ + List<EbUserVo> queryList(EbUserQueryBo bo); + + /** + * 鏌ヨ鍗曚釜 + * @return EbUserVo + */ + EbUserVo queryById(${pkColumn.javaType} ${pkColumn.javaField}); + + + /** + * 鏍规嵁鏂板涓氬姟瀵硅薄鎻掑叆銆愯濉啓鍔熻兘鍚嶇О銆� + * @param bo 銆愯濉啓鍔熻兘鍚嶇О銆戞柊澧炰笟鍔″璞� + * @return true鎴愬姛 false澶辫触 + */ + Boolean insertByBo(EbUserBo bo); + + /** + * 鏍规嵁缂栬緫涓氬姟瀵硅薄淇敼銆愯濉啓鍔熻兘鍚嶇О銆� + * @param bo 銆愯濉啓鍔熻兘鍚嶇О銆戠紪杈戜笟鍔″璞� + * @return true鎴愬姛 false澶辫触 + */ + Boolean updateByBo(EbUserBo bo); + + /** + * 鏍¢獙骞跺垹闄ゆ暟鎹� + * @param ids 涓婚敭闆嗗悎 + * @return true鎴愬姛 false澶辫触 + */ + Boolean deleteByIds(Collection<Long> ids); +} diff --git a/iplatform-test-mybatis/src/main/java/com/iplatform/test/service/impl/EbUserServiceImpl.java b/iplatform-test-mybatis/src/main/java/com/iplatform/test/service/impl/EbUserServiceImpl.java new file mode 100644 index 0000000..5725430 --- /dev/null +++ b/iplatform-test-mybatis/src/main/java/com/iplatform/test/service/impl/EbUserServiceImpl.java @@ -0,0 +1,100 @@ +package com.iplatform.test.service.impl; + +import lombok.RequiredArgsConstructor; +import cn.hutool.core.convert.Convert; +import com.iplatform.core.util.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.iplatform.test.domain.vo.EbUserVo; +import com.iplatform.test.domain.bo.EbUserBo; +import com.iplatform.test.domain.bo.EbUserQueryBo; +import com.iplatform.test.domain.EbUser; +import com.iplatform.test.mapper.EbUserMapper; +import com.iplatform.test.service.IEbUserService; + +import java.util.Collection; +import java.util.List; + +/** + * 銆愯濉啓鍔熻兘鍚嶇О銆慡ervice涓氬姟灞傚鐞� + * + * @author shikeying + * @date 2024-02-20 + */ +@Service +@RequiredArgsConstructor(onConstructor_ = @Autowired) +public class EbUserServiceImpl extends ServiceImpl<EbUserMapper, EbUser> implements IEbUserService { + + @Override//鍒楄〃鏌ヨ + public List<EbUserVo> queryList(EbUserQueryBo bo) + { + QueryWrapper<EbUser> qw = getQw(bo); + List<EbUser> list = this.list(qw); + return Convert.toList(EbUserVo.class , list); + } + + @Override//id鏌ヨ + public EbUserVo queryById(${pkColumn.javaType} ${pkColumn.javaField}) + { + EbUser db = this.baseMapper.selectById(${pkColumn.javaField}); + return Convert.convert(EbUserVo.class , db); + } + + + @Override//娣诲姞 + @Transactional + public Boolean insertByBo(EbUserBo bo) + { + EbUser add = Convert.convert(EbUser.class, bo); + validEntityBeforeSave(add); + return this.save(add); + } + + @Override//淇敼 + @Transactional + public Boolean updateByBo(EbUserBo bo) + { + EbUser update = Convert.convert(EbUser.class, bo); + validEntityBeforeSave(update); + return this.updateById(update); + } + + @Override//鍒犻櫎 + @Transactional + public Boolean deleteByIds(Collection<Long> ids) + { + + //鍋氫竴浜涗笟鍔′笂鐨勬牎楠�,鍒ゆ柇鏄惁闇�瑕佹牎楠� + + return this.removeByIds(ids); + } + + +//------------------------------------------------------------------------------------- + + //淇濆瓨鍓嶆牎楠� + private void validEntityBeforeSave(EbUser entity) + { + //鍋氫竴浜涙暟鎹牎楠�,濡傚敮涓�绾︽潫 + } + + //鑾峰彇鏌ヨ鍙傛暟 + private QueryWrapper<EbUser> getQw(EbUserQueryBo bo) + { + QueryWrapper<EbUser> qw = Wrappers.query(); + + if (StringUtils.isNotEmpty(bo.getIsAsc()) && StringUtils.isNotEmpty(bo.getOrderByColumn())){ + if ("acs".equals(bo.getIsAsc())) { + qw.orderByAsc(bo.getOrderByColumn()); + } else if ("desc".equals(bo.getIsAsc())) { + qw.orderByDesc(bo.getOrderByColumn()); + } + } + return qw; + } +} diff --git a/iplatform-test-mybatis/src/test/java/com/iplatform/AppTest.java b/iplatform-test-mybatis/src/test/java/com/iplatform/AppTest.java new file mode 100644 index 0000000..76e83ab --- /dev/null +++ b/iplatform-test-mybatis/src/test/java/com/iplatform/AppTest.java @@ -0,0 +1,20 @@ +package com.iplatform; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/pom.xml b/pom.xml index 5110464..1b7b369 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,7 @@ <module>ishop-mobile</module> <module>iplatform-base-tcp-client</module> <module>iplatform-support-mybatis</module> + <module>iplatform-test-mybatis</module> </modules> <parent> @@ -221,6 +222,13 @@ <version>${iplatform.version}</version> </dependency> + <!-- mybatis绀轰緥妯″潡锛�2024-02-19 --> + <dependency> + <groupId>com.iplatform</groupId> + <artifactId>iplatform-test-mybatis</artifactId> + <version>${iplatform.version}</version> + </dependency> + <!-- 鎺ㄩ�佸疄鐜版ā鍧楋紝2023-04-24 --> <dependency> <groupId>com.walkersoft</groupId> -- Gitblit v1.9.1