| @ -0,0 +1,47 @@ | |||||
| ###################################################################### | |||||
| # Build Tools | |||||
| .gradle | |||||
| /build/ | |||||
| !gradle/wrapper/gradle-wrapper.jar | |||||
| target/ | |||||
| !.mvn/wrapper/maven-wrapper.jar | |||||
| ###################################################################### | |||||
| # IDE | |||||
| ### STS ### | |||||
| .apt_generated | |||||
| .classpath | |||||
| .factorypath | |||||
| .project | |||||
| .settings | |||||
| .springBeans | |||||
| ### IntelliJ IDEA ### | |||||
| .idea | |||||
| *.iws | |||||
| *.iml | |||||
| *.ipr | |||||
| ### JRebel ### | |||||
| rebel.xml | |||||
| ### NetBeans ### | |||||
| nbproject/private/ | |||||
| build/* | |||||
| nbbuild/ | |||||
| dist/ | |||||
| nbdist/ | |||||
| .nb-gradle/ | |||||
| ###################################################################### | |||||
| # Others | |||||
| *.log | |||||
| *.xml.versionsBackup | |||||
| *.swp | |||||
| !*/build/*.java | |||||
| !*/build/*.html | |||||
| !*/build/*.xml | |||||
| @ -0,0 +1,13 @@ | |||||
| /*bug modify.*/ | |||||
| # Please enter the commit message for your changes. Lines starting | |||||
| # with '#' will be ignored, and an empty message aborts the commit. | |||||
| # | |||||
| # On branch master | |||||
| # Your branch is up to date with 'origin/master'. | |||||
| # | |||||
| # Changes to be committed: | |||||
| # modified: inspect-main/inspect-main-task/src/main/java/com/inspect/analysis/controller/ResultAnalysisController.java | |||||
| # modified: inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/controller/PatrolResultController.java | |||||
| # modified: inspect-main/inspect-main-video/src/main/java/com/inspect/patrol/controller/PatrolPresetPosController.java | |||||
| # modified: inspect-metadata/src/main/java/com/inspect/metadata/patrolpointmnt/controller/BasedataPatrolpointController.java | |||||
| # | |||||
| @ -0,0 +1,96 @@ | |||||
| <p align="center"> | |||||
| <img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png"> | |||||
| </p> | |||||
| <h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi v3.8.7</h1> | |||||
| <h4 align="center">基于SpringBoot+Vue前后端分离的Java快速开发框架</h4> | |||||
| <p align="center"> | |||||
| <a href="https://gitee.com/y_project/RuoYi-Vue/stargazers"><img src="https://gitee.com/y_project/RuoYi-Vue/badge/star.svg?theme=dark"></a> | |||||
| <a href="https://gitee.com/y_project/RuoYi-Vue"><img src="https://img.shields.io/badge/RuoYi-v3.8.7-brightgreen.svg"></a> | |||||
| <a href="https://gitee.com/y_project/RuoYi-Vue/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a> | |||||
| </p> | |||||
| ## 平台简介 | |||||
| 若依是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。 | |||||
| * 前端采用Vue、Element UI。 | |||||
| * 后端采用Spring Boot、Spring Security、Redis & Jwt。 | |||||
| * 权限认证使用Jwt,支持多终端认证系统。 | |||||
| * 支持加载动态权限菜单,多方式轻松权限控制。 | |||||
| * 高效率开发,使用代码生成器可以一键生成前后端代码。 | |||||
| * 提供了技术栈([Vue3](https://v3.cn.vuejs.org) [Element Plus](https://element-plus.org/zh-CN) [Vite](https://cn.vitejs.dev))版本[RuoYi-Vue3](https://github.com/yangzongzhuan/RuoYi-Vue3),保持同步更新。 | |||||
| * 提供了单应用版本[RuoYi-Vue-fast](https://github.com/yangzongzhuan/RuoYi-Vue-fast),Oracle版本[RuoYi-Vue-Oracle](https://github.com/yangzongzhuan/RuoYi-Vue-Oracle),保持同步更新。 | |||||
| * 不分离版本,请移步[RuoYi](https://gitee.com/y_project/RuoYi),微服务版本,请移步[RuoYi-Cloud](https://gitee.com/y_project/RuoYi-Cloud) | |||||
| * 阿里云折扣场:[点我进入](http://aly.ruoyi.vip),腾讯云秒杀场:[点我进入](http://txy.ruoyi.vip) | |||||
| * 阿里云优惠券:[点我领取](https://www.aliyun.com/minisite/goods?userCode=brki8iof&share_source=copy_link),腾讯云优惠券:[点我领取](https://cloud.tencent.com/redirect.php?redirect=1025&cps_key=198c8df2ed259157187173bc7f4f32fd&from=console) | |||||
| ## 内置功能 | |||||
| 1. 用户管理:用户是系统操作者,该功能主要完成系统用户配置。 | |||||
| 2. 部门管理:配置系统组织机构(公司、部门、小组),树结构展现支持数据权限。 | |||||
| 3. 岗位管理:配置系统用户所属担任职务。 | |||||
| 4. 菜单管理:配置系统菜单,操作权限,按钮权限标识等。 | |||||
| 5. 角色管理:角色菜单权限分配、设置角色按机构进行数据范围权限划分。 | |||||
| 6. 字典管理:对系统中经常使用的一些较为固定的数据进行维护。 | |||||
| 7. 参数管理:对系统动态配置常用参数。 | |||||
| 8. 通知公告:系统通知公告信息发布维护。 | |||||
| 9. 操作日志:系统正常操作日志记录和查询;系统异常信息日志记录和查询。 | |||||
| 10. 登录日志:系统登录日志记录查询包含登录异常。 | |||||
| 11. 在线用户:当前系统中活跃用户状态监控。 | |||||
| 12. 定时任务:在线(添加、修改、删除)任务调度包含执行结果日志。 | |||||
| 13. 代码生成:前后端代码的生成(java、html、xml、sql)支持CRUD下载 。 | |||||
| 14. 系统接口:根据业务代码自动生成相关的api接口文档。 | |||||
| 15. 服务监控:监视当前系统CPU、内存、磁盘、堆栈等相关信息。 | |||||
| 16. 缓存监控:对系统的缓存信息查询,命令统计等。 | |||||
| 17. 在线构建器:拖动表单元素生成相应的HTML代码。 | |||||
| 18. 连接池监视:监视当前系统数据库连接池状态,可进行分析SQL找出系统性能瓶颈。 | |||||
| ## 在线体验 | |||||
| - admin/admin123 | |||||
| - 陆陆续续收到一些打赏,为了更好的体验已用于演示服务器升级。谢谢各位小伙伴。 | |||||
| 演示地址:http://vue.ruoyi.vip | |||||
| 文档地址:http://doc.ruoyi.vip | |||||
| ## 演示图 | |||||
| <table> | |||||
| <tr> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/cd1f90be5f2684f4560c9519c0f2a232ee8.jpg"/></td> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/1cbcf0e6f257c7d3a063c0e3f2ff989e4b3.jpg"/></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/up-8074972883b5ba0622e13246738ebba237a.png"/></td> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/up-9f88719cdfca9af2e58b352a20e23d43b12.png"/></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/up-39bf2584ec3a529b0d5a3b70d15c9b37646.png"/></td> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/up-936ec82d1f4872e1bc980927654b6007307.png"/></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/up-b2d62ceb95d2dd9b3fbe157bb70d26001e9.png"/></td> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/up-d67451d308b7a79ad6819723396f7c3d77a.png"/></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/5e8c387724954459291aafd5eb52b456f53.jpg"/></td> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/644e78da53c2e92a95dfda4f76e6d117c4b.jpg"/></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/up-8370a0d02977eebf6dbf854c8450293c937.png"/></td> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/up-49003ed83f60f633e7153609a53a2b644f7.png"/></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/up-d4fe726319ece268d4746602c39cffc0621.png"/></td> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/up-c195234bbcd30be6927f037a6755e6ab69c.png"/></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/b6115bc8c31de52951982e509930b20684a.jpg"/></td> | |||||
| <td><img src="https://oscimg.oschina.net/oscnet/up-5e4daac0bb59612c5038448acbcef235e3a.png"/></td> | |||||
| </tr> | |||||
| </table> | |||||
| ## 若依前后端分离交流群 | |||||
| QQ群: [](https://jq.qq.com/?_wv=1027&k=5bVB1og) [](https://jq.qq.com/?_wv=1027&k=5eiA4DH) [](https://jq.qq.com/?_wv=1027&k=5AxMKlC) [](https://jq.qq.com/?_wv=1027&k=51G72yr) [](https://jq.qq.com/?_wv=1027&k=VvjN2nvu) [](https://jq.qq.com/?_wv=1027&k=5vYAqA05) [](https://jq.qq.com/?_wv=1027&k=kOIINEb5) [](https://jq.qq.com/?_wv=1027&k=UKtX5jhs) [](https://jq.qq.com/?_wv=1027&k=EI9an8lJ) [](https://jq.qq.com/?_wv=1027&k=SWCtLnMz) [](https://jq.qq.com/?_wv=1027&k=96Dkdq0k) [](https://jq.qq.com/?_wv=1027&k=0fsNiYZt) [](https://jq.qq.com/?_wv=1027&k=7xw4xUG1) [](https://jq.qq.com/?_wv=1027&k=eCx8eyoJ) [](https://jq.qq.com/?_wv=1027&k=SpyH2875) [](https://jq.qq.com/?_wv=1027&k=tKEt51dz) [](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=0vBbSb0ztbBgVtn3kJS-Q4HUNYwip89G&authKey=8irq5PhutrZmWIvsUsklBxhj57l%2F1nOZqjzigkXZVoZE451GG4JHPOqW7AW6cf0T&noverify=0&group_code=143961921) [](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=ZFAPAbp09S2ltvwrJzp7wGlbopsc0rwi&authKey=HB2cxpxP2yspk%2Bo3WKTBfktRCccVkU26cgi5B16u0KcAYrVu7sBaE7XSEqmMdFQp&noverify=0&group_code=174951577) [](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=Fn2aF5IHpwsy8j6VlalNJK6qbwFLFHat&authKey=uyIT%2B97x2AXj3odyXpsSpVaPMC%2Bidw0LxG5MAtEqlrcBcWJUA%2FeS43rsF1Tg7IRJ&noverify=0&group_code=161281055) [](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=XIzkm_mV2xTsUtFxo63bmicYoDBA6Ifm&authKey=dDW%2F4qsmw3x9govoZY9w%2FoWAoC4wbHqGal%2BbqLzoS6VBarU8EBptIgPKN%2FviyC8j&noverify=0&group_code=138988063) 点击按钮入群。 | |||||
| @ -0,0 +1,12 @@ | |||||
| @echo off | |||||
| echo. | |||||
| echo [信息] 清理工程target生成路径。 | |||||
| echo. | |||||
| %~d0 | |||||
| cd %~dp0 | |||||
| cd .. | |||||
| call mvn clean | |||||
| pause | |||||
| @ -0,0 +1,12 @@ | |||||
| @echo off | |||||
| echo. | |||||
| echo [信息] 打包Web工程,生成war/jar包文件。 | |||||
| echo. | |||||
| %~d0 | |||||
| cd %~dp0 | |||||
| cd .. | |||||
| call mvn clean package -Dmaven.test.skip=true | |||||
| pause | |||||
| @ -0,0 +1,14 @@ | |||||
| @echo off | |||||
| echo. | |||||
| echo [信息] 使用Jar命令运行Web工程。 | |||||
| echo. | |||||
| cd %~dp0 | |||||
| cd ../ruoyi-admin/target | |||||
| set JAVA_OPTS=-Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m | |||||
| java -jar %JAVA_OPTS% ruoyi-admin.jar | |||||
| cd bin | |||||
| pause | |||||
| @ -0,0 +1,95 @@ | |||||
| <?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"> | |||||
| <modelVersion>4.0.0</modelVersion> | |||||
| <parent> | |||||
| <groupId>com.inspect</groupId> | |||||
| <artifactId>inspect</artifactId> | |||||
| <version>3.4.0</version> | |||||
| <!-- <version>${revision}</version>--> | |||||
| <!-- <relativePath>../pom.xml</relativePath>--> | |||||
| </parent> | |||||
| <artifactId>inspect-admin</artifactId> | |||||
| <dependencies> | |||||
| <dependency> | |||||
| <groupId>com.alibaba.cloud</groupId> | |||||
| <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>com.alibaba.cloud</groupId> | |||||
| <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>com.alibaba.cloud</groupId> | |||||
| <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.springframework.boot</groupId> | |||||
| <artifactId>spring-boot-starter-web</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.springframework.boot</groupId> | |||||
| <artifactId>spring-boot-starter-actuator</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>com.inspect</groupId> | |||||
| <artifactId>inspect-common-security</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>com.inspect</groupId> | |||||
| <artifactId>inspect-base-core</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>com.twelvemonkeys.imageio</groupId> | |||||
| <artifactId>imageio-reference</artifactId> | |||||
| <version>3.9.3</version> | |||||
| </dependency> | |||||
| </dependencies> | |||||
| <build> | |||||
| <finalName>${project.artifactId}</finalName> | |||||
| <plugins> | |||||
| <!-- <plugin>--> | |||||
| <!-- <groupId>com.github.wvengen</groupId>--> | |||||
| <!-- <artifactId>proguard-maven-plugin</artifactId>--> | |||||
| <!-- <version>2.5.1</version>--> | |||||
| <!-- <executions>--> | |||||
| <!-- <execution>--> | |||||
| <!-- <phase>package</phase>--> | |||||
| <!-- <goals>--> | |||||
| <!-- <goal>proguard</goal>--> | |||||
| <!-- </goals>--> | |||||
| <!-- </execution>--> | |||||
| <!-- </executions>--> | |||||
| <!-- <configuration>--> | |||||
| <!-- <injar>${project.build.finalName}.jar</injar>--> | |||||
| <!-- <outjar>${project.build.finalName}.jar</outjar>--> | |||||
| <!-- <obfuscate>true</obfuscate>--> | |||||
| <!-- <proguardInclude>${project.basedir}/proguard.cfg</proguardInclude>--> | |||||
| <!-- <libs>--> | |||||
| <!-- <lib>${java.home}/lib/rt.jar</lib>--> | |||||
| <!-- <lib>${java.home}/lib/jce.jar</lib>--> | |||||
| <!-- <lib>${java.home}/lib/jsse.jar</lib>--> | |||||
| <!-- </libs>--> | |||||
| <!-- <outputDirectory>${project.basedir}/target</outputDirectory>--> | |||||
| <!-- <options>--> | |||||
| <!-- </options>--> | |||||
| <!-- </configuration>--> | |||||
| <!-- </plugin>--> | |||||
| <plugin> | |||||
| <groupId>org.springframework.boot</groupId> | |||||
| <artifactId>spring-boot-maven-plugin</artifactId> | |||||
| <version>${spring.boot.version}</version> | |||||
| <executions> | |||||
| <execution> | |||||
| <goals> | |||||
| <goal>repackage</goal> | |||||
| </goals> | |||||
| </execution> | |||||
| </executions> | |||||
| </plugin> | |||||
| </plugins> | |||||
| </build> | |||||
| </project> | |||||
| @ -0,0 +1,28 @@ | |||||
| -target 1.8 | |||||
| -dontshrink | |||||
| -dontoptimize | |||||
| -dontusemixedcaseclassnames | |||||
| -useuniqueclassmembernames | |||||
| -dontusemixedcaseclassnames | |||||
| -adaptclassstrings | |||||
| -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod | |||||
| -keepnames interface ** { *; } | |||||
| #-keep interface * extends * { *; } | |||||
| -keepparameternames | |||||
| -keepclassmembers enum * { *; } | |||||
| -keeppackagenames com.inspect.admin | |||||
| -keepclassmembers class * { | |||||
| @org.springframework.context.annotation.Bean *; | |||||
| @org.springframework.beans.factory.annotation.Autowired *; | |||||
| @org.springframework.beans.factory.annotation.Value *; | |||||
| @org.springframework.stereotype.Service *; | |||||
| @org.springframework.stereotype.Component *; | |||||
| } | |||||
| -ignorewarnings | |||||
| -dontnote | |||||
| -printconfiguration | |||||
| -keep public class com.inspect.admin.InspectAuthApplication { | |||||
| public static void main(java.lang.String[]); | |||||
| } | |||||
| @ -0,0 +1,34 @@ | |||||
| package com.inspect.admin; | |||||
| import com.inspect.common.security.annotation.EnableRyFeignClients; | |||||
| import org.springframework.beans.factory.config.BeanDefinition; | |||||
| import org.springframework.beans.factory.support.BeanDefinitionRegistry; | |||||
| import org.springframework.beans.factory.support.BeanNameGenerator; | |||||
| import org.springframework.boot.SpringApplication; | |||||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |||||
| import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | |||||
| import org.springframework.boot.builder.SpringApplicationBuilder; | |||||
| import org.springframework.context.annotation.ComponentScan; | |||||
| @EnableRyFeignClients | |||||
| @ComponentScan({"com.inspect.*"}) | |||||
| @SpringBootApplication( | |||||
| exclude = {DataSourceAutoConfiguration.class} | |||||
| ) | |||||
| public class InspectAuthApplication { | |||||
| public static void main(String[] args) { | |||||
| SpringApplication.run(InspectAuthApplication.class, args); | |||||
| // SpringApplicationBuilder builder = new SpringApplicationBuilder(InspectAuthApplication.class) | |||||
| // .beanNameGenerator(new CustomGenerator()); | |||||
| // builder.run(args); | |||||
| System.out.println("<=====☆ AUTH MODULE ☆ =====> \n .-------. ____ __ \n | _ _ \\ \\ \\ / / \n | ( ' ) | \\ _. / ' \n |(_ o _) / _( )_ .' \n | (_,_).' __ ___(_ o _)' \n | |\\ \\ | || |(_,_)' \n | | \\ `' /| `-' / \n | | \\ / \\ / \n ''-' `'-' `-..-' "); | |||||
| } | |||||
| public static class CustomGenerator implements BeanNameGenerator { | |||||
| @Override | |||||
| public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) { | |||||
| return definition.getBeanClassName(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,13 @@ | |||||
| package com.inspect.admin; | |||||
| import com.inspect.base.core.domain.SysWarning; | |||||
| import com.inspect.base.core.web.domain.AjaxResult; | |||||
| import org.springframework.cloud.openfeign.FeignClient; | |||||
| import org.springframework.web.bind.annotation.PostMapping; | |||||
| import org.springframework.web.bind.annotation.RequestBody; | |||||
| @FeignClient("inspect-management") | |||||
| public interface SystemClient { | |||||
| @PostMapping({"/warningLog/saveWarning"}) | |||||
| AjaxResult saveWarning(@RequestBody SysWarning var1); | |||||
| } | |||||
| @ -0,0 +1,79 @@ | |||||
| package com.inspect.admin.controller; | |||||
| import com.inspect.admin.form.LoginBody; | |||||
| import com.inspect.admin.form.RegisterBody; | |||||
| import com.inspect.admin.service.SysLoginService; | |||||
| import com.inspect.base.core.constant.TokenConst; | |||||
| import com.inspect.base.core.domain.Response; | |||||
| import com.inspect.base.core.utils.JwtUtils; | |||||
| import com.inspect.base.core.utils.StringUtils; | |||||
| import com.inspect.common.security.auth.AuthUtil; | |||||
| import com.inspect.common.security.service.TokenService; | |||||
| import com.inspect.common.security.utils.SecurityUtils; | |||||
| import com.inspect.system.base.model.LoginUser; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.PostMapping; | |||||
| import org.springframework.web.bind.annotation.RequestBody; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| @RestController | |||||
| public class TokenController { | |||||
| @Autowired | |||||
| private TokenService tokenService; | |||||
| @Autowired | |||||
| private SysLoginService sysLoginService; | |||||
| @PostMapping({"login"}) | |||||
| public Response<?> login(@RequestBody LoginBody form, HttpServletRequest request) { | |||||
| LoginUser userInfo = this.sysLoginService.login(form.getUsername(), form.getPassword(), request); | |||||
| return Response.ok(this.tokenService.createToken(userInfo)); | |||||
| } | |||||
| @PostMapping({"secondLogin"}) | |||||
| public Response<?> secondLogin(@RequestBody LoginBody form, HttpServletRequest request) { | |||||
| String ticket = this.sysLoginService.secondLogin(form.getUsername(), form.getPassword(), request); | |||||
| return Response.ok(ticket); | |||||
| } | |||||
| @PostMapping({"logout"}) | |||||
| public Response<?> logout(HttpServletRequest request) { | |||||
| String token = SecurityUtils.getToken(request); | |||||
| if(StringUtils.isNotEmpty(token)) { | |||||
| String username = JwtUtils.getUserName(token); | |||||
| AuthUtil.logoutByToken(token); | |||||
| this.sysLoginService.logout(username); | |||||
| } | |||||
| return Response.ok(); | |||||
| } | |||||
| @PostMapping({"refresh"}) | |||||
| public Response<?> refresh(HttpServletRequest request) { | |||||
| LoginUser loginUser = this.tokenService.getLoginUser(request); | |||||
| if(StringUtils.isNotNull(loginUser)) { | |||||
| this.tokenService.refreshToken(loginUser); | |||||
| return Response.ok(); | |||||
| } else { | |||||
| return Response.ok(); | |||||
| } | |||||
| } | |||||
| public Response<?> register(@RequestBody RegisterBody registerBody) { | |||||
| this.sysLoginService.register(registerBody.getUsername(), registerBody.getPassword()); | |||||
| return Response.ok(); | |||||
| } | |||||
| @PostMapping({"getToken"}) | |||||
| public Response<?> getToken(HttpServletRequest request) { | |||||
| LoginUser userInfo = this.sysLoginService.login("admin", "e6e061838856bf47e1de730719fb2609", request); | |||||
| Map<String, Object> map = this.tokenService.createToken(userInfo); | |||||
| Map<String, Object> mapApi = new HashMap(); | |||||
| mapApi.put("key", "Authorization"); | |||||
| mapApi.put("value", "Bearer " + map.get(TokenConst.ACCESS_TOKEN)); | |||||
| return Response.ok(mapApi, "操作成功"); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,31 @@ | |||||
| package com.inspect.admin.form; | |||||
| public class LoginBody { | |||||
| private String username; | |||||
| private String password; | |||||
| private String uuid; | |||||
| public String getUuid() { | |||||
| return this.uuid; | |||||
| } | |||||
| public void setUuid(String uuid) { | |||||
| this.uuid = uuid; | |||||
| } | |||||
| public String getUsername() { | |||||
| return this.username; | |||||
| } | |||||
| public void setUsername(String username) { | |||||
| this.username = username; | |||||
| } | |||||
| public String getPassword() { | |||||
| return this.password; | |||||
| } | |||||
| public void setPassword(String password) { | |||||
| this.password = password; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,4 @@ | |||||
| package com.inspect.admin.form; | |||||
| public class RegisterBody extends LoginBody { | |||||
| } | |||||
| @ -0,0 +1,247 @@ | |||||
| package com.inspect.admin.service; | |||||
| import com.inspect.admin.SystemClient; | |||||
| import com.inspect.base.core.domain.Response; | |||||
| import com.inspect.base.core.domain.SysWarning; | |||||
| import com.inspect.base.core.enums.UserStatus; | |||||
| import com.inspect.base.core.exception.ServiceException; | |||||
| import com.inspect.base.core.utils.JwtUtils; | |||||
| import com.inspect.base.core.utils.ServletUtils; | |||||
| import com.inspect.base.core.utils.StringUtils; | |||||
| import com.inspect.base.core.utils.ip.IpUtils; | |||||
| import com.inspect.base.redis.service.RedisService; | |||||
| import com.inspect.common.security.utils.SecurityUtils; | |||||
| import com.inspect.system.base.RemoteLogService; | |||||
| import com.inspect.system.base.RemoteUserService; | |||||
| import com.inspect.system.base.domain.SysLoginFor; | |||||
| import com.inspect.system.base.domain.SysUser; | |||||
| import com.inspect.system.base.model.LoginUser; | |||||
| import io.jsonwebtoken.Claims; | |||||
| import java.util.Set; | |||||
| import java.util.UUID; | |||||
| import java.util.concurrent.TimeUnit; | |||||
| import javax.annotation.Resource; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.data.redis.core.RedisTemplate; | |||||
| import org.springframework.data.redis.core.ValueOperations; | |||||
| import org.springframework.stereotype.Component; | |||||
| @Component | |||||
| public class SysLoginService { | |||||
| @Autowired | |||||
| private RemoteLogService remoteLogService; | |||||
| @Autowired | |||||
| private RemoteUserService remoteUserService; | |||||
| @Resource | |||||
| RedisService redisService; | |||||
| @Resource | |||||
| SystemClient systemClient; | |||||
| protected static final long MINUTE_SECOND = 60L; | |||||
| private static Logger logger = LoggerFactory.getLogger(SysLoginService.class); | |||||
| public LoginUser login(String username, String password, HttpServletRequest request) { | |||||
| this.verifyLoginFailTimes(username); | |||||
| LoginUser userInfo = this.commonLogin(username, password); | |||||
| this.verifyUserLoginIp(userInfo, request); | |||||
| this.recordLogininfor(username, "Success", "登录成功"); | |||||
| return userInfo; | |||||
| } | |||||
| public String secondLogin(String username, String password, HttpServletRequest request) { | |||||
| try { | |||||
| String token = this.getToken(request); | |||||
| Claims claims = JwtUtils.parseToken(token); | |||||
| String tokenUserName = JwtUtils.getUserName(claims); | |||||
| this.commonLogin(tokenUserName, password); | |||||
| return this.awardTicket(); | |||||
| } catch (Exception var7) { | |||||
| throw var7; | |||||
| } | |||||
| } | |||||
| private String getToken(HttpServletRequest request) { | |||||
| String token = request.getHeader("Authorization"); | |||||
| if(StringUtils.isNotEmpty(token) && token.startsWith("Bearer ")) { | |||||
| token = token.replaceFirst("Bearer ", ""); | |||||
| } | |||||
| return token; | |||||
| } | |||||
| public String awardTicket() { | |||||
| String ticket = UUID.randomUUID().toString().replaceAll("-", ""); | |||||
| this.redisService.redisTemplate.opsForValue().set(ticket, Integer.valueOf(1), 5L, TimeUnit.MINUTES); | |||||
| return ticket; | |||||
| } | |||||
| public LoginUser commonLogin(String username, String password) { | |||||
| if(StringUtils.isAnyBlank(new CharSequence[]{username, password})) { | |||||
| this.recordLogininfor(username, "Error", "用户/密码必须填写"); | |||||
| throw new ServiceException("用户/密码必须填写"); | |||||
| } else if(password.length() >= 5 && password.length() <= 40) { | |||||
| logger.info("[GABRIEL] username: {}, password: {}", username, password); | |||||
| if(username.length() >= 2 && username.length() <= 20) { | |||||
| Response<LoginUser> userResult = this.remoteUserService.getUserInfo(username, "inner"); | |||||
| if(Response.FAIL == userResult.getCode()) { | |||||
| throw new ServiceException(userResult.getMsg()); | |||||
| } else if(!StringUtils.isNull(userResult) && !StringUtils.isNull(userResult.getData())) { | |||||
| LoginUser userInfo = (LoginUser)userResult.getData(); | |||||
| SysUser user = ((LoginUser)userResult.getData()).getSysUser(); | |||||
| if(UserStatus.DELETED.getCode().equals(user.getDelFlag())) { | |||||
| this.recordLogininfor(username, "Error", "对不起,您的账号已被删除"); | |||||
| throw new ServiceException("对不起,您的账号:" + username + " 已被删除"); | |||||
| } else if(UserStatus.DISABLE.getCode().equals(user.getStatus())) { | |||||
| this.recordLogininfor(username, "Error", "用户已停用,请联系管理员"); | |||||
| throw new ServiceException("对不起,您的账号:" + username + " 已停用"); | |||||
| } else if(!SecurityUtils.matchesPassword(password, user.getPassword())) { | |||||
| int failNum = this.incrWrongNum(username); | |||||
| this.recordLogininfor(username, "Error", "用户密码错误"); | |||||
| int surplusNum = 5 - failNum + 1; | |||||
| throw new ServiceException("密码错误,再错误" + surplusNum + "次后将被锁定"); | |||||
| } else { | |||||
| this.resetWrongNum(username); | |||||
| return userInfo; | |||||
| } | |||||
| } else { | |||||
| this.recordLogininfor(username, "Error", "登录用户不存在"); | |||||
| throw new ServiceException("登录用户:" + username + " 不存在"); | |||||
| } | |||||
| } else { | |||||
| this.recordLogininfor(username, "Error", "用户名不在指定范围"); | |||||
| throw new ServiceException("用户名不在指定范围"); | |||||
| } | |||||
| } else { | |||||
| this.recordLogininfor(username, "Error", "用户密码不在指定范围"); | |||||
| throw new ServiceException("用户密码不在指定范围"); | |||||
| } | |||||
| } | |||||
| private void verifyUserLoginIp(LoginUser userInfo, HttpServletRequest request) { | |||||
| String requestIp = IpUtils.getIpAddr(request); | |||||
| Set<String> roles = userInfo.getRoles(); | |||||
| String username = userInfo.getUsername(); | |||||
| if(!roles.contains("admin")) { | |||||
| String aollowIp = userInfo.getSysUser().getAollowIp(); | |||||
| if(StringUtils.isBlank(aollowIp)) { | |||||
| throw new ServiceException("用户未绑定登录ip,不允许登录"); | |||||
| } else if(!StringUtils.equals(requestIp, aollowIp)) { | |||||
| try { | |||||
| SysWarning sysWarning = this.generateLoginErrorLogVo("用户登录ip与绑定ip不同,已禁止登录", Integer.valueOf(2), username); | |||||
| this.systemClient.saveWarning(sysWarning); | |||||
| } catch (Exception var8) { | |||||
| logger.error("记录登录错误次数超限日志时,捕获异常", var8); | |||||
| } | |||||
| throw new ServiceException("登录IP与用户绑定的IP不同,不允许登录"); | |||||
| } | |||||
| } | |||||
| } | |||||
| public void logout(String loginName) { | |||||
| this.recordLogininfor(loginName, "Logout", "退出成功"); | |||||
| } | |||||
| public int incrWrongNum(String username) { | |||||
| RedisTemplate redisTemplate = this.redisService.redisTemplate; | |||||
| ValueOperations valueOperations = redisTemplate.opsForValue(); | |||||
| String loginFailKey = this.getLoginFailKey(username); | |||||
| if(redisTemplate.hasKey(loginFailKey).booleanValue()) { | |||||
| valueOperations.increment(loginFailKey); | |||||
| Object o = valueOperations.get(loginFailKey); | |||||
| return ((Integer)o).intValue(); | |||||
| } else { | |||||
| valueOperations.set(loginFailKey, Integer.valueOf(1), 30L, TimeUnit.MINUTES); | |||||
| return 1; | |||||
| } | |||||
| } | |||||
| public void resetWrongNum(String username) { | |||||
| RedisTemplate redisTemplate = this.redisService.redisTemplate; | |||||
| ValueOperations valueOperations = redisTemplate.opsForValue(); | |||||
| String loginFailKey = this.getLoginFailKey(username); | |||||
| this.redisService.deleteObject(loginFailKey); | |||||
| } | |||||
| public void verifyLoginFailTimes(String username) { | |||||
| RedisTemplate redisTemplate = this.redisService.redisTemplate; | |||||
| ValueOperations<String, Integer> valueOperations = redisTemplate.opsForValue(); | |||||
| String loginFailKey = this.getLoginFailKey(username); | |||||
| if(redisTemplate.hasKey(loginFailKey).booleanValue()) { | |||||
| Integer failNum = (Integer)valueOperations.get(loginFailKey); | |||||
| if(failNum.intValue() >= 5) { | |||||
| Long expire = redisTemplate.getExpire(loginFailKey); | |||||
| long minute = 0L; | |||||
| if(expire.longValue() > 0L) { | |||||
| minute = expire.longValue() / 60L; | |||||
| if(minute < 1L) { | |||||
| minute = 1L; | |||||
| } | |||||
| } | |||||
| try { | |||||
| SysWarning sysWarning = this.generateLoginErrorLogVo("登录失败次数已达最大限制,限制登录" + minute + "分钟", Integer.valueOf(1), username); | |||||
| this.systemClient.saveWarning(sysWarning); | |||||
| } catch (Exception var10) { | |||||
| logger.error("记录登录错误次数超限日志时,捕获异常", var10); | |||||
| } | |||||
| throw new ServiceException("用户锁定,请等待" + minute + "分钟后重试"); | |||||
| } | |||||
| } | |||||
| } | |||||
| public SysWarning generateLoginErrorLogVo(String text, Integer level, String userName) { | |||||
| SysWarning warning = new SysWarning(); | |||||
| warning.setText(text); | |||||
| warning.setLevel(level); | |||||
| warning.setSourceName("系统"); | |||||
| warning.setUserName(userName); | |||||
| warning.setType(Integer.valueOf(0)); | |||||
| return warning; | |||||
| } | |||||
| public String getLoginFailKey(String username) { | |||||
| return "login_fail_times:" + username; | |||||
| } | |||||
| public void register(String username, String password) { | |||||
| if(StringUtils.isAnyBlank(new CharSequence[]{username, password})) { | |||||
| throw new ServiceException("用户/密码必须填写"); | |||||
| } else if(username.length() >= 2 && username.length() <= 20) { | |||||
| if(password.length() >= 5 && password.length() <= 40) { | |||||
| SysUser sysUser = new SysUser(); | |||||
| sysUser.setUserName(username); | |||||
| sysUser.setNickName(username); | |||||
| sysUser.setPassword(SecurityUtils.encryptPassword(password)); | |||||
| Response<?> registerResult = this.remoteUserService.registerUserInfo(sysUser, "inner"); | |||||
| if(Response.FAIL == registerResult.getCode()) { | |||||
| throw new ServiceException(registerResult.getMsg()); | |||||
| } else { | |||||
| this.recordLogininfor(username, "Register", "注册成功"); | |||||
| } | |||||
| } else { | |||||
| throw new ServiceException("密码长度必须在5到20个字符之间"); | |||||
| } | |||||
| } else { | |||||
| throw new ServiceException("账户长度必须在2到20个字符之间"); | |||||
| } | |||||
| } | |||||
| public void recordLogininfor(String username, String status, String message) { | |||||
| SysLoginFor logininfor = new SysLoginFor(); | |||||
| logininfor.setUserName(username); | |||||
| logininfor.setIpaddr(IpUtils.getIpAddr(ServletUtils.getRequest())); | |||||
| logininfor.setMsg(message); | |||||
| if(StringUtils.equalsAny(status, new CharSequence[]{"Success", "Logout", "Register"})) { | |||||
| logininfor.setStatus("0"); | |||||
| } else if("Error".equals(status)) { | |||||
| logininfor.setStatus("1"); | |||||
| } | |||||
| this.remoteLogService.saveLogininfor(logininfor, "inner"); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,10 @@ | |||||
| Spring Boot Version: ${spring-boot.version} | |||||
| Spring Application Name: ${spring.application.name} | |||||
| _ _ _ | |||||
| (_) | | | | | |||||
| _ __ _ _ ___ _ _ _ ______ __ _ _ _ | |_ | |__ | |||||
| | '__|| | | | / _ \ | | | || ||______| / _` || | | || __|| '_ \ | |||||
| | | | |_| || (_) || |_| || | | (_| || |_| || |_ | | | | | |||||
| |_| \__,_| \___/ \__, ||_| \__,_| \__,_| \__||_| |_| | |||||
| __/ | | |||||
| |___/ | |||||
| @ -0,0 +1,32 @@ | |||||
| # Tomcat | |||||
| server: | |||||
| port: 9200 | |||||
| # Spring | |||||
| spring: | |||||
| application: | |||||
| # 应用名称 | |||||
| name: dliip-auth | |||||
| profiles: | |||||
| # 环境配置 | |||||
| active: dev | |||||
| main: | |||||
| allow-circular-references: true | |||||
| cloud: | |||||
| nacos: | |||||
| discovery: | |||||
| # 服务注册地址 | |||||
| # server-addr: 177.177.177.3:8848 | |||||
| # namespace: 521f2683-cc74-4ae6-890c-d51311d9f60e | |||||
| server-addr: 127.0.0.1:8848 | |||||
| namespace: 69445dc4-9c24-4814-ac93-ff14f1438c36 | |||||
| config: | |||||
| # 配置中心地址 | |||||
| server-addr: ${spring.cloud.nacos.discovery.server-addr} | |||||
| # 配置文件格式 | |||||
| file-extension: yml | |||||
| # 共享配置 | |||||
| shared-configs: | |||||
| - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} | |||||
| #dev-1 | |||||
| namespace: ${spring.cloud.nacos.discovery.namespace} | |||||
| @ -0,0 +1,78 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <configuration scan="true" scanPeriod="60 seconds" debug="false"> | |||||
| <!-- 日志存放路径 --> | |||||
| <property name="log.path" value="logs/inspect-admin" /> | |||||
| <!-- 日志输出格式 --> | |||||
| <property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" /> | |||||
| <property name="log.maxHistory" value="60"/> | |||||
| <property name="log.maxFileSize" value="10MB"/> | |||||
| <!-- 控制台输出 --> | |||||
| <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> | |||||
| <encoder> | |||||
| <pattern>${log.pattern}</pattern> | |||||
| </encoder> | |||||
| </appender> | |||||
| <!-- 系统日志输出 --> | |||||
| <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||||
| <file>${log.path}/info.log</file> | |||||
| <!-- 循环政策:基于时间创建日志文件 --> | |||||
| <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> | |||||
| <!-- 日志文件名格式 --> | |||||
| <fileNamePattern>${log.path}/info/info.%d{yyyy-MM-dd}.%i.log</fileNamePattern> | |||||
| <maxFileSize>${log.maxFileSize}</maxFileSize> | |||||
| <!-- 日志最大的历史 60天 --> | |||||
| <maxHistory>${log.maxHistory}</maxHistory> | |||||
| </rollingPolicy> | |||||
| <encoder> | |||||
| <pattern>${log.pattern}</pattern> | |||||
| </encoder> | |||||
| <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |||||
| <!-- 过滤的级别 --> | |||||
| <level>INFO</level> | |||||
| <!-- 匹配时的操作:接收(记录) --> | |||||
| <onMatch>ACCEPT</onMatch> | |||||
| <!-- 不匹配时的操作:拒绝(不记录) --> | |||||
| <onMismatch>DENY</onMismatch> | |||||
| </filter> | |||||
| </appender> | |||||
| <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||||
| <file>${log.path}/error.log</file> | |||||
| <!-- 循环政策:基于时间创建日志文件 --> | |||||
| <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |||||
| <!-- 日志文件名格式 --> | |||||
| <fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern> | |||||
| <!-- 日志最大的历史 60天 --> | |||||
| <maxHistory>60</maxHistory> | |||||
| </rollingPolicy> | |||||
| <encoder> | |||||
| <pattern>${log.pattern}</pattern> | |||||
| </encoder> | |||||
| <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |||||
| <!-- 过滤的级别 --> | |||||
| <level>ERROR</level> | |||||
| <!-- 匹配时的操作:接收(记录) --> | |||||
| <onMatch>ACCEPT</onMatch> | |||||
| <!-- 不匹配时的操作:拒绝(不记录) --> | |||||
| <onMismatch>DENY</onMismatch> | |||||
| </filter> | |||||
| </appender> | |||||
| <!-- 系统模块日志级别控制 --> | |||||
| <logger name="com.inspect" level="info" /> | |||||
| <!-- Spring日志级别控制 --> | |||||
| <logger name="org.springframework" level="warn" /> | |||||
| <root level="info"> | |||||
| <appender-ref ref="console" /> | |||||
| </root> | |||||
| <!--系统操作日志--> | |||||
| <root level="info"> | |||||
| <appender-ref ref="file_info" /> | |||||
| <appender-ref ref="file_error" /> | |||||
| </root> | |||||
| </configuration> | |||||
| @ -0,0 +1,25 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||||
| xmlns="http://maven.apache.org/POM/4.0.0" | |||||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||||
| <modelVersion>4.0.0</modelVersion> | |||||
| <parent> | |||||
| <artifactId>inspect-base</artifactId> | |||||
| <groupId>com.inspect</groupId> | |||||
| <version>3.4.0</version> | |||||
| <!-- <version>${revision}</version>--> | |||||
| <!-- <relativePath>../pom.xml</relativePath>--> | |||||
| </parent> | |||||
| <artifactId>inspect-base-access</artifactId> | |||||
| <version>3.4.0</version> | |||||
| <dependencies> | |||||
| <dependency> | |||||
| <groupId>com.inspect</groupId> | |||||
| <artifactId>inspect-base-core</artifactId> | |||||
| <version>3.4.0</version> | |||||
| <!-- <scope>system</scope>--> | |||||
| <!-- <systemPath>${project.basedir}/../inspect-api-core/target/inspect-api-core-3.4.0.jar</systemPath>--> | |||||
| </dependency> | |||||
| </dependencies> | |||||
| </project> | |||||
| @ -0,0 +1,71 @@ | |||||
| package com.inspect.access.base.domain; | |||||
| import com.inspect.base.core.utils.DateUtils; | |||||
| import java.io.Serializable; | |||||
| import java.util.Date; | |||||
| public class InfraredFileNameGenerator implements Serializable { | |||||
| private static final long serialVersionUID = -7545318238298020694L; | |||||
| private String stationCode; | |||||
| private String taskCode; | |||||
| private String patrolpointCode; | |||||
| private String patroldeviceCode; | |||||
| private String FIR = "FIR"; | |||||
| private Date now = new Date(); | |||||
| private String suffix = ".jpg"; | |||||
| public InfraredFileNameGenerator() { | |||||
| } | |||||
| public InfraredFileNameGenerator(String stationCode, String taskCode, String patrolpointCode, String patroldeviceCode) { | |||||
| this.stationCode = stationCode; | |||||
| this.taskCode = taskCode; | |||||
| this.patrolpointCode = patrolpointCode; | |||||
| this.patroldeviceCode = patroldeviceCode; | |||||
| } | |||||
| public String getStationCode() { | |||||
| return this.stationCode; | |||||
| } | |||||
| public void setStationCode(String stationCode) { | |||||
| this.stationCode = stationCode; | |||||
| } | |||||
| public String getTaskCode() { | |||||
| return this.taskCode; | |||||
| } | |||||
| public void setTaskCode(String taskCode) { | |||||
| this.taskCode = taskCode; | |||||
| } | |||||
| public String getPatrolpointCode() { | |||||
| return this.patrolpointCode; | |||||
| } | |||||
| public void setPatrolpointCode(String patrolpointCode) { | |||||
| this.patrolpointCode = patrolpointCode; | |||||
| } | |||||
| public String getPatroldeviceCode() { | |||||
| return this.patroldeviceCode; | |||||
| } | |||||
| public void setPatroldeviceCode(String patroldeviceCode) { | |||||
| this.patroldeviceCode = patroldeviceCode; | |||||
| } | |||||
| public String toString() { | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| sb.append(this.toStringNoSuffix()).append(this.suffix); | |||||
| return sb.toString(); | |||||
| } | |||||
| public String toStringNoSuffix() { | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| sb.append(this.stationCode).append("/").append(DateUtils.parseDateToStr("YYYY", this.now)).append("/").append(DateUtils.parseDateToStr("MM", this.now)).append("/").append(DateUtils.parseDateToStr("dd", this.now)).append("/").append(this.taskCode).append("/").append(this.FIR).append("/").append(this.patrolpointCode).append("_").append(this.patroldeviceCode).append("_"); | |||||
| return sb.toString(); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,41 @@ | |||||
| package com.inspect.access.base.feign; | |||||
| import com.inspect.access.base.model.InfraredModel; | |||||
| import com.inspect.access.base.model.LoginModel; | |||||
| import com.inspect.access.base.model.RecordCompleteModel; | |||||
| import com.inspect.access.base.model.RuleCollectionModel; | |||||
| import com.inspect.access.base.model.TemperPortModel; | |||||
| import com.inspect.access.base.vo.DeviceStorageVo; | |||||
| import com.inspect.access.base.vo.OnlineStatsVo; | |||||
| import com.inspect.access.base.vo.RecordCompleteVo; | |||||
| import com.inspect.base.core.domain.Response; | |||||
| import java.util.List; | |||||
| import org.springframework.cloud.openfeign.FeignClient; | |||||
| import org.springframework.web.bind.annotation.PostMapping; | |||||
| import org.springframework.web.bind.annotation.RequestBody; | |||||
| @FeignClient("inspect-fastcall") | |||||
| public interface AccessFeign { | |||||
| @PostMapping({"/access/query_temper_point"}) | |||||
| Response<Float> queryTemperPoint(@RequestBody TemperPortModel temperPortModel); | |||||
| @PostMapping({"/access/remove_measure_param"}) | |||||
| Response removeMeasureParam(@RequestBody RuleCollectionModel ruleCollectionModel); | |||||
| @PostMapping({"/access/set_measure_param"}) | |||||
| Response setMeasureParam(@RequestBody RuleCollectionModel ruleCollectionModel); | |||||
| @PostMapping({"/access/record"}) | |||||
| Response<RecordCompleteVo> record(@RequestBody RecordCompleteModel recordCompleteModel); | |||||
| @PostMapping({"/access/online_stats"}) | |||||
| Response<List<OnlineStatsVo>> online(@RequestBody LoginModel loginModel); | |||||
| @PostMapping({"/access/storage"}) | |||||
| Response<DeviceStorageVo> storage(@RequestBody LoginModel loginModel); | |||||
| @PostMapping({"/access/infrared"}) | |||||
| Response<String> infrared(@RequestBody InfraredModel infraredModel); | |||||
| } | |||||
| @ -0,0 +1,33 @@ | |||||
| package com.inspect.access.base.model; | |||||
| import java.io.Serializable; | |||||
| public class AccessPointModel implements Serializable { | |||||
| private static final long serialVersionUID = 6235178610259501550L; | |||||
| public int nX; | |||||
| public int nY; | |||||
| public AccessPointModel() { | |||||
| } | |||||
| public AccessPointModel(int nX, int nY) { | |||||
| this.nX = nX; | |||||
| this.nY = nY; | |||||
| } | |||||
| public int getnX() { | |||||
| return this.nX; | |||||
| } | |||||
| public void setnX(int nX) { | |||||
| this.nX = nX; | |||||
| } | |||||
| public int getnY() { | |||||
| return this.nY; | |||||
| } | |||||
| public void setnY(int nY) { | |||||
| this.nY = nY; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,33 @@ | |||||
| package com.inspect.access.base.model; | |||||
| import com.inspect.access.base.domain.InfraredFileNameGenerator; | |||||
| public class InfraredModel extends LoginModel { | |||||
| private InfraredFileNameGenerator infraredFileNameGenerator; | |||||
| private int channelSerial; | |||||
| private int presetId; | |||||
| public InfraredFileNameGenerator getInfraredFileNameGenerator() { | |||||
| return this.infraredFileNameGenerator; | |||||
| } | |||||
| public void setInfraredFileNameGenerator(InfraredFileNameGenerator infraredFileNameGenerator) { | |||||
| this.infraredFileNameGenerator = infraredFileNameGenerator; | |||||
| } | |||||
| public int getChannelSerial() { | |||||
| return this.channelSerial; | |||||
| } | |||||
| public void setChannelSerial(String channelSerial) { | |||||
| this.channelSerial = 1; | |||||
| } | |||||
| public int getPresetId() { | |||||
| return this.presetId; | |||||
| } | |||||
| public void setPresetId(int presetId) { | |||||
| this.presetId = presetId; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,50 @@ | |||||
| package com.inspect.access.base.model; | |||||
| import java.io.Serializable; | |||||
| public class LoginModel implements Serializable { | |||||
| private static final long serialVersionUID = -6921425557814586580L; | |||||
| private String ip; | |||||
| private int port; | |||||
| private String username; | |||||
| private String password; | |||||
| public void init(String ip, int port, String username, String password) { | |||||
| this.ip = ip; | |||||
| this.port = port; | |||||
| this.username = username; | |||||
| this.password = password; | |||||
| } | |||||
| public String getIp() { | |||||
| return this.ip; | |||||
| } | |||||
| public void setIp(String ip) { | |||||
| this.ip = ip; | |||||
| } | |||||
| public int getPort() { | |||||
| return this.port; | |||||
| } | |||||
| public void setPort(int port) { | |||||
| this.port = port; | |||||
| } | |||||
| public String getUsername() { | |||||
| return this.username; | |||||
| } | |||||
| public void setUsername(String username) { | |||||
| this.username = username; | |||||
| } | |||||
| public String getPassword() { | |||||
| return this.password; | |||||
| } | |||||
| public void setPassword(String password) { | |||||
| this.password = password; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,19 @@ | |||||
| package com.inspect.access.base.model; | |||||
| import java.util.Date; | |||||
| public class RecordCompleteModel extends LoginModel { | |||||
| private Date date; | |||||
| public Date getDate() { | |||||
| return this.date; | |||||
| } | |||||
| public void setDate(Date date) { | |||||
| this.date = date; | |||||
| } | |||||
| public String toString() { | |||||
| return "RecordCompleteModel{ip=" + this.getIp() + ",port=" + this.getPort() + ",username=" + this.getUsername() + ",password=" + this.getPassword() + ",date=" + this.date + '}'; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,21 @@ | |||||
| package com.inspect.access.base.model; | |||||
| import java.util.ArrayList; | |||||
| import java.util.List; | |||||
| public class RuleCollectionModel extends LoginModel { | |||||
| private static final long serialVersionUID = -3518275025598117347L; | |||||
| private List<RuleModel> ruleModels = new ArrayList(); | |||||
| public List<RuleModel> getRuleModels() { | |||||
| return this.ruleModels; | |||||
| } | |||||
| public void addRuleModel(RuleModel ruleModel) { | |||||
| this.ruleModels.add(ruleModel); | |||||
| } | |||||
| public void setRuleModels(List<RuleModel> ruleModels) { | |||||
| this.ruleModels = ruleModels; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,109 @@ | |||||
| package com.inspect.access.base.model; | |||||
| import java.io.Serializable; | |||||
| import java.util.ArrayList; | |||||
| import java.util.List; | |||||
| public class RuleModel implements Serializable { | |||||
| private static final long serialVersionUID = -621853527262598913L; | |||||
| public int nChannel; | |||||
| public int nPresetId; | |||||
| public int nRuleId; | |||||
| public int nMeterType; | |||||
| public String szName; | |||||
| public int bEnable; | |||||
| public List<AccessPointModel> points; | |||||
| public float fObjectEmissivity; | |||||
| public int nObjectDistance; | |||||
| public int nRefalectedTemp; | |||||
| public int getnChannel() { | |||||
| return this.nChannel; | |||||
| } | |||||
| public void setnChannel(String nChannel) { | |||||
| this.nChannel = Integer.parseInt(nChannel.substring(nChannel.length() - 1)); | |||||
| } | |||||
| public int getnPresetId() { | |||||
| return this.nPresetId; | |||||
| } | |||||
| public void setnPresetId(int nPresetId) { | |||||
| this.nPresetId = nPresetId; | |||||
| } | |||||
| public int getnRuleId() { | |||||
| return this.nRuleId; | |||||
| } | |||||
| public void setnRuleId(int nRuleId) { | |||||
| this.nRuleId = nRuleId; | |||||
| } | |||||
| public int getnMeterType() { | |||||
| return this.nMeterType; | |||||
| } | |||||
| public void setnMeterType(int nMeterType) { | |||||
| this.nMeterType = nMeterType; | |||||
| } | |||||
| public String getSzName() { | |||||
| return this.szName; | |||||
| } | |||||
| public void setSzName(String szName) { | |||||
| this.szName = szName; | |||||
| } | |||||
| public int getbEnable() { | |||||
| return this.bEnable; | |||||
| } | |||||
| public void setbEnable(int bEnable) { | |||||
| this.bEnable = bEnable; | |||||
| } | |||||
| public List<AccessPointModel> getPoints() { | |||||
| return this.points; | |||||
| } | |||||
| public void setPoints(List<AccessPointModel> points) { | |||||
| this.points = points; | |||||
| } | |||||
| public void loadPoints(String coordinates) { | |||||
| String[] split = coordinates.split(","); | |||||
| this.points = new ArrayList(); | |||||
| for(int i = 0; i < split.length - 2; i += 2) { | |||||
| this.points.add(new AccessPointModel(Integer.parseInt(split[i]) * 8192 / Integer.parseInt(split[split.length - 2]), Integer.parseInt(split[i + 1]) * 8192 / Integer.parseInt(split[split.length - 1]))); | |||||
| } | |||||
| } | |||||
| public float getfObjectEmissivity() { | |||||
| return this.fObjectEmissivity; | |||||
| } | |||||
| public void setfObjectEmissivity(float fObjectEmissivity) { | |||||
| this.fObjectEmissivity = fObjectEmissivity; | |||||
| } | |||||
| public int getnObjectDistance() { | |||||
| return this.nObjectDistance; | |||||
| } | |||||
| public void setnObjectDistance(int nObjectDistance) { | |||||
| this.nObjectDistance = nObjectDistance; | |||||
| } | |||||
| public int getnRefalectedTemp() { | |||||
| return this.nRefalectedTemp; | |||||
| } | |||||
| public void setnRefalectedTemp(int nRefalectedTemp) { | |||||
| this.nRefalectedTemp = nRefalectedTemp; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,50 @@ | |||||
| package com.inspect.access.base.model; | |||||
| public class TemperPortModel extends LoginModel { | |||||
| private static final long serialVersionUID = -4937168171956268565L; | |||||
| private int nChannel; | |||||
| private short x; | |||||
| private short y; | |||||
| private int width; | |||||
| private int height; | |||||
| public int getWidth() { | |||||
| return this.width; | |||||
| } | |||||
| public void setWidth(int width) { | |||||
| this.width = width; | |||||
| } | |||||
| public int getHeight() { | |||||
| return this.height; | |||||
| } | |||||
| public void setHeight(int height) { | |||||
| this.height = height; | |||||
| } | |||||
| public int getnChannel() { | |||||
| return this.nChannel; | |||||
| } | |||||
| public void setnChannel(int nChannel) { | |||||
| this.nChannel = nChannel; | |||||
| } | |||||
| public short getX() { | |||||
| return this.x; | |||||
| } | |||||
| public void setX(short x) { | |||||
| this.x = x; | |||||
| } | |||||
| public short getY() { | |||||
| return this.y; | |||||
| } | |||||
| public void setY(short y) { | |||||
| this.y = y; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,43 @@ | |||||
| package com.inspect.access.base.vo; | |||||
| import java.io.Serializable; | |||||
| public class ChannelRecordCompleteVo implements Serializable { | |||||
| private static final long serialVersionUID = 7670374532519389252L; | |||||
| private int channelSerial; | |||||
| private String duration; | |||||
| private String complete; | |||||
| public ChannelRecordCompleteVo() { | |||||
| } | |||||
| public int getChannelSerial() { | |||||
| return this.channelSerial; | |||||
| } | |||||
| public void setChannelSerial(int channelSerial) { | |||||
| this.channelSerial = channelSerial; | |||||
| } | |||||
| public ChannelRecordCompleteVo(int channelSerial, String duration, String complete) { | |||||
| this.channelSerial = channelSerial; | |||||
| this.duration = duration; | |||||
| this.complete = complete; | |||||
| } | |||||
| public String getDuration() { | |||||
| return this.duration; | |||||
| } | |||||
| public void setDuration(String duration) { | |||||
| this.duration = duration; | |||||
| } | |||||
| public String getComplete() { | |||||
| return this.complete; | |||||
| } | |||||
| public void setComplete(String complete) { | |||||
| this.complete = complete; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,44 @@ | |||||
| package com.inspect.access.base.vo; | |||||
| import com.inspect.base.core.utils.BigDecimalUtil; | |||||
| import java.io.Serializable; | |||||
| public class DeviceStorageVo implements Serializable { | |||||
| private static final long serialVersionUID = -4207167945858333412L; | |||||
| private double nTotalSpace; | |||||
| private double nFreeSpace; | |||||
| private double nUsedSpace; | |||||
| public DeviceStorageVo() { | |||||
| } | |||||
| public DeviceStorageVo(long nTotalSpace, long nFreeSpace) { | |||||
| this.nTotalSpace = BigDecimalUtil.round((double)nTotalSpace / 1024.0D / 1024.0D / 1024.0D / 1024.0D, 2); | |||||
| this.nFreeSpace = BigDecimalUtil.round((double)nFreeSpace / 1024.0D / 1024.0D / 1024.0D / 1024.0D, 2); | |||||
| this.nUsedSpace = BigDecimalUtil.round(this.nTotalSpace - this.nFreeSpace, 2); | |||||
| } | |||||
| public double getnTotalSpace() { | |||||
| return this.nTotalSpace; | |||||
| } | |||||
| public void setnTotalSpace(double nTotalSpace) { | |||||
| this.nTotalSpace = nTotalSpace; | |||||
| } | |||||
| public double getnFreeSpace() { | |||||
| return this.nFreeSpace; | |||||
| } | |||||
| public void setnFreeSpace(double nFreeSpace) { | |||||
| this.nFreeSpace = nFreeSpace; | |||||
| } | |||||
| public double getnUsedSpace() { | |||||
| return this.nUsedSpace; | |||||
| } | |||||
| public void setnUsedSpace(double nUsedSpace) { | |||||
| this.nUsedSpace = nUsedSpace; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,33 @@ | |||||
| package com.inspect.access.base.vo; | |||||
| import java.io.Serializable; | |||||
| public class OnlineStatsVo implements Serializable { | |||||
| private static final long serialVersionUID = 1660612033884766447L; | |||||
| private int channelSerial; | |||||
| private int stats; | |||||
| public OnlineStatsVo() { | |||||
| } | |||||
| public OnlineStatsVo(int channelSerial, int stats) { | |||||
| this.channelSerial = channelSerial; | |||||
| this.stats = stats; | |||||
| } | |||||
| public int getChannelSerial() { | |||||
| return this.channelSerial; | |||||
| } | |||||
| public void setChannelSerial(int channelSerial) { | |||||
| this.channelSerial = channelSerial; | |||||
| } | |||||
| public int getStats() { | |||||
| return this.stats; | |||||
| } | |||||
| public void setStats(int stats) { | |||||
| this.stats = stats; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,43 @@ | |||||
| package com.inspect.access.base.vo; | |||||
| import java.io.Serializable; | |||||
| public class RecordCompleteVo implements Serializable { | |||||
| private static final long serialVersionUID = 3595689876039523280L; | |||||
| private int duration; | |||||
| private int complete; | |||||
| private int cycle; | |||||
| public RecordCompleteVo() { | |||||
| } | |||||
| public RecordCompleteVo(int duration, int complete, int cycle) { | |||||
| this.duration = duration; | |||||
| this.complete = complete; | |||||
| this.cycle = cycle; | |||||
| } | |||||
| public int getCycle() { | |||||
| return this.cycle; | |||||
| } | |||||
| public void setCycle(int cycle) { | |||||
| this.cycle = cycle; | |||||
| } | |||||
| public int getDuration() { | |||||
| return this.duration; | |||||
| } | |||||
| public void setDuration(int duration) { | |||||
| this.duration = duration; | |||||
| } | |||||
| public int getComplete() { | |||||
| return this.complete; | |||||
| } | |||||
| public void setComplete(int complete) { | |||||
| this.complete = complete; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,33 @@ | |||||
| package com.inspect.access.base.vo; | |||||
| import java.io.Serializable; | |||||
| public class RecordCycleVo implements Serializable { | |||||
| private static final long serialVersionUID = -7282338117472747415L; | |||||
| private int channelSerial; | |||||
| private int cycle; | |||||
| public RecordCycleVo() { | |||||
| } | |||||
| public RecordCycleVo(int channelSerial, int cycle) { | |||||
| this.channelSerial = channelSerial; | |||||
| this.cycle = cycle; | |||||
| } | |||||
| public int getChannelSerial() { | |||||
| return this.channelSerial; | |||||
| } | |||||
| public void setChannelSerial(int channelSerial) { | |||||
| this.channelSerial = channelSerial; | |||||
| } | |||||
| public int getCycle() { | |||||
| return this.cycle; | |||||
| } | |||||
| public void setCycle(int cycle) { | |||||
| this.cycle = cycle; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,129 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||||
| xmlns="http://maven.apache.org/POM/4.0.0" | |||||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||||
| <modelVersion>4.0.0</modelVersion> | |||||
| <parent> | |||||
| <groupId>com.inspect</groupId> | |||||
| <artifactId>inspect-base</artifactId> | |||||
| <version>3.4.0</version> | |||||
| <!-- <version>${revision}</version>--> | |||||
| <!-- <relativePath>../pom.xml</relativePath>--> | |||||
| </parent> | |||||
| <artifactId>inspect-base-core</artifactId> | |||||
| <version>3.4.0</version> | |||||
| <dependencies> | |||||
| <dependency> | |||||
| <groupId>org.springframework.cloud</groupId> | |||||
| <artifactId>spring-cloud-starter-openfeign</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.springframework.cloud</groupId> | |||||
| <artifactId>spring-cloud-starter-loadbalancer</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.springframework</groupId> | |||||
| <artifactId>spring-context-support</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>com.github.oshi</groupId> | |||||
| <artifactId>oshi-core</artifactId> | |||||
| <version>5.6.1</version> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>cn.hutool</groupId> | |||||
| <artifactId>hutool-all</artifactId> | |||||
| <version>5.7.19</version> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.bouncycastle</groupId> | |||||
| <artifactId>bcprov-jdk15to18</artifactId> | |||||
| <version>1.69</version> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.springframework</groupId> | |||||
| <artifactId>spring-web</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>com.alibaba</groupId> | |||||
| <artifactId>transmittable-thread-local</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>com.github.pagehelper</groupId> | |||||
| <artifactId>pagehelper-spring-boot-starter</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.springframework.boot</groupId> | |||||
| <artifactId>spring-boot-starter-validation</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>com.fasterxml.jackson.core</groupId> | |||||
| <artifactId>jackson-databind</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>com.alibaba</groupId> | |||||
| <artifactId>fastjson</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>io.jsonwebtoken</groupId> | |||||
| <artifactId>jjwt</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>javax.xml.bind</groupId> | |||||
| <artifactId>jaxb-api</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.apache.commons</groupId> | |||||
| <artifactId>commons-lang3</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>commons-io</groupId> | |||||
| <artifactId>commons-io</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>commons-fileupload</groupId> | |||||
| <artifactId>commons-fileupload</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.apache.poi</groupId> | |||||
| <artifactId>poi-ooxml</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>javax.servlet</groupId> | |||||
| <artifactId>javax.servlet-api</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>io.swagger</groupId> | |||||
| <artifactId>swagger-annotations</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>commons-fileupload</groupId> | |||||
| <artifactId>commons-fileupload</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>commons-net</groupId> | |||||
| <artifactId>commons-net</artifactId> | |||||
| <version>3.9.0</version> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>com.jcraft</groupId> | |||||
| <artifactId>jsch</artifactId> | |||||
| <version>0.1.54</version> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.dom4j</groupId> | |||||
| <artifactId>dom4j</artifactId> | |||||
| <version>2.1.3</version> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>io.netty</groupId> | |||||
| <artifactId>netty-all</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.projectlombok</groupId> | |||||
| <artifactId>lombok</artifactId> | |||||
| </dependency> | |||||
| </dependencies> | |||||
| </project> | |||||
| @ -0,0 +1,102 @@ | |||||
| package com.inspect.base.core.annotation; | |||||
| import com.inspect.base.core.utils.poi.ExcelHandlerAdapter; | |||||
| import java.lang.annotation.ElementType; | |||||
| import java.lang.annotation.Retention; | |||||
| import java.lang.annotation.RetentionPolicy; | |||||
| import java.lang.annotation.Target; | |||||
| @Retention(RetentionPolicy.RUNTIME) | |||||
| @Target({ElementType.FIELD}) | |||||
| public @interface Excel { | |||||
| int sort() default Integer.MAX_VALUE; | |||||
| String name() default ""; | |||||
| String dateFormat() default ""; | |||||
| String readConverterExp() default ""; | |||||
| String separator() default ","; | |||||
| int scale() default -1; | |||||
| int roundingMode() default 6; | |||||
| Excel.ColumnType cellType() default Excel.ColumnType.STRING; | |||||
| double height() default 14.0D; | |||||
| double width() default 16.0D; | |||||
| String suffix() default ""; | |||||
| String defaultValue() default ""; | |||||
| String prompt() default ""; | |||||
| String[] combo() default {}; | |||||
| boolean isExport() default true; | |||||
| String targetAttr() default ""; | |||||
| boolean isStatistics() default false; | |||||
| Excel.Align align() default Excel.Align.AUTO; | |||||
| Class<?> handler() default ExcelHandlerAdapter.class; | |||||
| String[] args() default {}; | |||||
| Excel.Type type() default Excel.Type.ALL; | |||||
| public static enum ColumnType { | |||||
| NUMERIC(0), | |||||
| STRING(1), | |||||
| IMAGE(2); | |||||
| private final int value; | |||||
| private ColumnType(int value) { | |||||
| this.value = value; | |||||
| } | |||||
| public int value() { | |||||
| return this.value; | |||||
| } | |||||
| } | |||||
| public static enum Type { | |||||
| ALL(0), | |||||
| EXPORT(1), | |||||
| IMPORT(2); | |||||
| private final int value; | |||||
| private Type(int value) { | |||||
| this.value = value; | |||||
| } | |||||
| public int value() { | |||||
| return this.value; | |||||
| } | |||||
| } | |||||
| public static enum Align { | |||||
| AUTO(0), | |||||
| LEFT(1), | |||||
| CENTER(2), | |||||
| RIGHT(3); | |||||
| private final int value; | |||||
| private Align(int value) { | |||||
| this.value = value; | |||||
| } | |||||
| public int value() { | |||||
| return this.value; | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,12 @@ | |||||
| package com.inspect.base.core.annotation; | |||||
| import java.lang.annotation.ElementType; | |||||
| import java.lang.annotation.Retention; | |||||
| import java.lang.annotation.RetentionPolicy; | |||||
| import java.lang.annotation.Target; | |||||
| @Target({ElementType.FIELD}) | |||||
| @Retention(RetentionPolicy.RUNTIME) | |||||
| public @interface Excels { | |||||
| Excel[] value(); | |||||
| } | |||||
| @ -0,0 +1,5 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class BasedataCacheConstants { | |||||
| public static final String BASEDATA_EQPBOOK_INFO = "basedata_eqpbook_info:"; | |||||
| } | |||||
| @ -0,0 +1,12 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class CacheConstants { | |||||
| public static final long EXPIRATION = 525600L; | |||||
| public static final long REFRESH_TIME = 525600L; | |||||
| public static final String LOGIN_TOKEN_KEY = "login_tokens:"; | |||||
| public static final String LOGIN_FAIL_KEY_PRE = "login_fail_times:"; | |||||
| public static final int LOGIN_PASSWORD_WRONG_TIMES = 5; | |||||
| public static final long LOGIN_FAIL_LIMIT_TIME = 30L; | |||||
| public static final String USER_UPDATE_PASS_INTERVAL_KEY = "sys_config:user_pass_update_interval_time"; | |||||
| public static final Long DAY_MILLIS_TIMES = Long.valueOf(86400000L); | |||||
| } | |||||
| @ -0,0 +1,11 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class Color { | |||||
| public static final String END = "\033[0m"; | |||||
| public static final String RED = "\033[31m"; | |||||
| public static final String GREEN = "\033[32m"; | |||||
| public static final String YELLOW = "\033[33m"; | |||||
| public static final String BLUE = "\033[34m"; | |||||
| public static final String MAGENTA = "\033[35m"; | |||||
| public static final String CYAN = "\033[36m"; | |||||
| } | |||||
| @ -0,0 +1,31 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class Constants { | |||||
| public static final String UTF8 = "UTF-8"; | |||||
| public static final String GBK = "GBK"; | |||||
| public static final String LOOKUP_RMI = "rmi:"; | |||||
| public static final String LOOKUP_LDAP = "ldap:"; | |||||
| public static final String LOOKUP_LDAPS = "ldaps:"; | |||||
| public static final String HTTP = "http://"; | |||||
| public static final String HTTPS = "https://"; | |||||
| public static final Integer SUCCESS = 200; | |||||
| public static final Integer FAIL = 500; | |||||
| public static final String LOGIN_SUCCESS_STATUS = "0"; | |||||
| public static final String LOGIN_FAIL_STATUS = "1"; | |||||
| public static final String LOGIN_SUCCESS = "Success"; | |||||
| public static final String LOGOUT = "Logout"; | |||||
| public static final String REGISTER = "Register"; | |||||
| public static final String LOGIN_FAIL = "Error"; | |||||
| public static final String PAGE_NUM = "pageNum"; | |||||
| public static final String PAGE_SIZE = "pageSize"; | |||||
| public static final String ORDER_BY_COLUMN = "orderByColumn"; | |||||
| public static final String IS_ASC = "isAsc"; | |||||
| public static final String CAPTCHA_CODE_KEY = "captcha_codes:"; | |||||
| public static final long CAPTCHA_EXPIRATION = 2L; | |||||
| public static final String SYS_CONFIG_KEY = "sys_config:"; | |||||
| public static final String SYS_DICT_KEY = "sys_dict:"; | |||||
| public static final String RESOURCE_PREFIX = "/profile"; | |||||
| public static final String[] JOB_WHITELIST_STR = new String[]{"com.inspect"}; | |||||
| public static final String[] JOB_ERROR_STR = new String[]{"java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml", "org.springframework", "org.apache", "com.inspect.common.core.utils.file"}; | |||||
| } | |||||
| @ -0,0 +1,39 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class GenConstants { | |||||
| public static final String TPL_CRUD = "crud"; | |||||
| public static final String TPL_TREE = "tree"; | |||||
| public static final String TPL_SUB = "sub"; | |||||
| public static final String TREE_CODE = "treeCode"; | |||||
| public static final String TREE_PARENT_CODE = "treeParentCode"; | |||||
| public static final String TREE_NAME = "treeName"; | |||||
| public static final String PARENT_MENU_ID = "parentMenuId"; | |||||
| public static final String PARENT_MENU_NAME = "parentMenuName"; | |||||
| public static final String[] COLUMNTYPE_STR = new String[]{"char", "varchar", "nvarchar", "varchar2"}; | |||||
| public static final String[] COLUMNTYPE_TEXT = new String[]{"tinytext", "text", "mediumtext", "longtext"}; | |||||
| public static final String[] COLUMNTYPE_TIME = new String[]{"datetime", "time", "date", "timestamp"}; | |||||
| public static final String[] COLUMNTYPE_NUMBER = new String[]{"tinyint", "smallint", "mediumint", "int", "number", "integer", "bigint", "float", "double", "decimal"}; | |||||
| public static final String[] COLUMNNAME_NOT_EDIT = new String[]{"id", "create_by", "create_time", "del_flag"}; | |||||
| public static final String[] COLUMNNAME_NOT_LIST = new String[]{"id", "create_by", "create_time", "del_flag", "update_by", "update_time"}; | |||||
| public static final String[] COLUMNNAME_NOT_QUERY = new String[]{"id", "create_by", "create_time", "del_flag", "update_by", "update_time", "remark"}; | |||||
| public static final String[] BASE_ENTITY = new String[]{"createBy", "createTime", "updateBy", "updateTime", "remark"}; | |||||
| public static final String[] TREE_ENTITY = new String[]{"parentName", "parentId", "orderNum", "ancestors"}; | |||||
| public static final String HTML_INPUT = "input"; | |||||
| public static final String HTML_TEXTAREA = "textarea"; | |||||
| public static final String HTML_SELECT = "select"; | |||||
| public static final String HTML_RADIO = "radio"; | |||||
| public static final String HTML_CHECKBOX = "checkbox"; | |||||
| public static final String HTML_DATETIME = "datetime"; | |||||
| public static final String HTML_IMAGE_UPLOAD = "imageUpload"; | |||||
| public static final String HTML_FILE_UPLOAD = "fileUpload"; | |||||
| public static final String HTML_EDITOR = "editor"; | |||||
| public static final String TYPE_STRING = "String"; | |||||
| public static final String TYPE_INTEGER = "Integer"; | |||||
| public static final String TYPE_LONG = "Long"; | |||||
| public static final String TYPE_DOUBLE = "Double"; | |||||
| public static final String TYPE_BIGDECIMAL = "BigDecimal"; | |||||
| public static final String TYPE_DATE = "Date"; | |||||
| public static final String QUERY_LIKE = "LIKE"; | |||||
| public static final String QUERY_EQ = "EQ"; | |||||
| public static final String REQUIRE = "1"; | |||||
| } | |||||
| @ -0,0 +1,20 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class HttpStatus { | |||||
| public static final int SUCCESS = 200; | |||||
| public static final int CREATED = 201; | |||||
| public static final int ACCEPTED = 202; | |||||
| public static final int NO_CONTENT = 204; | |||||
| public static final int MOVED_PERM = 301; | |||||
| public static final int SEE_OTHER = 303; | |||||
| public static final int NOT_MODIFIED = 304; | |||||
| public static final int BAD_REQUEST = 400; | |||||
| public static final int UNAUTHORIZED = 401; | |||||
| public static final int FORBIDDEN = 403; | |||||
| public static final int NOT_FOUND = 404; | |||||
| public static final int BAD_METHOD = 405; | |||||
| public static final int CONFLICT = 409; | |||||
| public static final int UNSUPPORTED_TYPE = 415; | |||||
| public static final int ERROR = 500; | |||||
| public static final int NOT_IMPLEMENTED = 501; | |||||
| } | |||||
| @ -0,0 +1,16 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class MontCacheConstants { | |||||
| public static final String MONT_EVN_INFO = "mont_evn_info:"; | |||||
| public static final String MONT_PATROL_DEVICE_ALMABN = "mont_patrol_device_almabn:"; | |||||
| public static final String MONT_PATROL_DEVICE_RUNDATA = "mont_patrol_device_rundata:"; | |||||
| public static final String MONT_PATROL_DEVICE_STADATA = "mont_patrol_device_stadata:"; | |||||
| public static final String MONT_NEST_RUNDATA = "mont_nest_rundata:"; | |||||
| public static final String MONT_NEST_STADATA = "mont_nest_stadata:"; | |||||
| public static final String MONT_PATROL_DEVICE_COORD = "mont_patrol_device_coord:"; | |||||
| public static final String MONT_PATDEV_PATROUTE = "mont_patdev_patroute:"; | |||||
| public static final String MONT_PATROL_DEVICE_ONLINE_STATUS = "mont_patrol_device_online_status:"; | |||||
| public static final String MONT_PATROL_DEVICE_OFFLINE_COUNT = "mont_patrol_device_offline_count:"; | |||||
| public static final String MONT_NVR_INFO = "mont_nvr_info:"; | |||||
| public static final String MONT_PATROL_DEVICE_CHANNEL_ONLINE_STATUS = "mont_patrol_device_channel_online_status:"; | |||||
| } | |||||
| @ -0,0 +1,7 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class RabbitmqConst { | |||||
| public static final String QUEUE_TOPIC_MONTDATA = "basedata.info.montdata"; | |||||
| public static final String RK_MONTDATA = "basedata.info.montdata"; | |||||
| public static final String RK_DATABASE_MONTDATA = "basedata.info.montdata.pk"; | |||||
| } | |||||
| @ -0,0 +1,15 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class RedisConst { | |||||
| public static final String TASK_PATROL_ID = "TASK_PATROL_ID"; | |||||
| public static final String TASK_PATROL_ID_EX = "TASK+PATROL+ID@"; | |||||
| public static final String TASK_PATROL_STATE = "TASK_PATROL_STATE"; | |||||
| public static final String TASK_PATROL_STOP = "PATROL_TASK_STOP"; | |||||
| public static final String TASK_CODE = "TASK_CODE@"; | |||||
| public static final String TASK_CODE_EX = "TASK_CODE@*"; | |||||
| public static final String TASK_RECORD_CNT = "TASK_RECORD_CNT"; | |||||
| public static final String TASK_CURRENT_CODE = "TASK_CURRENT_CODE@"; | |||||
| public static final String TASK_REPEAT_CODE = "TASK_REPEAT_CODE@"; | |||||
| public static final String TASK_TIMER_CLOCK = "TASK_TIMER_CLOCK"; | |||||
| public static final String IMMEDIATELY_EXEC_TASK_TIME = "IMMEDIATELY_EXEC_TASK_TIME"; | |||||
| } | |||||
| @ -0,0 +1,25 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class ScheduleConstants { | |||||
| public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME"; | |||||
| public static final String TASK_PROPERTIES = "TASK_PROPERTIES"; | |||||
| public static final String MISFIRE_DEFAULT = "0"; | |||||
| public static final String MISFIRE_IGNORE_MISFIRES = "1"; | |||||
| public static final String MISFIRE_FIRE_AND_PROCEED = "2"; | |||||
| public static final String MISFIRE_DO_NOTHING = "3"; | |||||
| public static enum Status { | |||||
| NORMAL("0"), | |||||
| PAUSE("1"); | |||||
| private String value; | |||||
| private Status(String value) { | |||||
| this.value = value; | |||||
| } | |||||
| public String getValue() { | |||||
| return this.value; | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,12 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class SecurityConstants { | |||||
| public static final String DETAILS_USER_ID = "user_id"; | |||||
| public static final String DETAILS_USERNAME = "username"; | |||||
| public static final String ADMIN_FLAG = "admin_flag"; | |||||
| public static final String AUTHORIZATION_HEADER = "authorization"; | |||||
| public static final String FROM_SOURCE = "from-source"; | |||||
| public static final String INNER = "inner"; | |||||
| public static final String USER_KEY = "user_key"; | |||||
| public static final String LOGIN_USER = "login_user"; | |||||
| } | |||||
| @ -0,0 +1,11 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class ServiceNameConstants { | |||||
| public static final String AUTH_SERVICE = "inspect-auth"; | |||||
| public static final String SYSTEM_SERVICE = "inspect-system"; | |||||
| public static final String FILE_SERVICE = "inspect-file"; | |||||
| public static final String DATABASE_SERVICE = "inspect-metadata"; | |||||
| public static final String PATROL_SERVICE = "inspect-main"; | |||||
| public static final String ACCESS_SERVICE = "inspect-access"; | |||||
| public static final String IVS_SERVICE = "inspect-ivs"; | |||||
| } | |||||
| @ -0,0 +1,6 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class Tags { | |||||
| public static final String DEFECT_TYPE = "defect_type"; | |||||
| } | |||||
| @ -0,0 +1,20 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class TokenConst { | |||||
| public static final String RESP_TOKEN_NULL = "Empty token!"; | |||||
| public static final String RESP_TOKEN_EXPIRE = "Expire token!"; | |||||
| public static final String RESP_REDIS_EXPIRE = "Account not login!"; | |||||
| public static final String RESP_TOKEN_FAIL = "Illegal token!"; | |||||
| public static final String AUTHENTICATION = "Authorization"; | |||||
| public static final String BEARER = "Bearer "; | |||||
| public static final String SECRET = "abcdefghijklmnopqrstuvwxyz"; | |||||
| public static final String USERNAME = "username"; | |||||
| public static final String USER_ID = "user_id"; | |||||
| public static final String USER_KEY = "user_key"; | |||||
| public static final String FROM_SOURCE = "from-source"; | |||||
| public static final String LOGIN_TOKENS = "login_tokens:"; | |||||
| public static final String DOWN_TOKEN = "downToken"; | |||||
| public static final String ACCESS_TOKEN = "access_token"; | |||||
| public static final String EXPIRES_IN = "expires_in"; | |||||
| public static final String ADMIN_FLAG = "admin_flag"; | |||||
| } | |||||
| @ -0,0 +1,27 @@ | |||||
| package com.inspect.base.core.constant; | |||||
| public class UserConstants { | |||||
| public static final String SYS_USER = "SYS_USER"; | |||||
| public static final String NORMAL = "0"; | |||||
| public static final String EXCEPTION = "1"; | |||||
| public static final String USER_DISABLE = "1"; | |||||
| public static final String ROLE_DISABLE = "1"; | |||||
| public static final String DEPT_NORMAL = "0"; | |||||
| public static final String DEPT_DISABLE = "1"; | |||||
| public static final String DICT_NORMAL = "0"; | |||||
| public static final String YES = "Y"; | |||||
| public static final String YES_FRAME = "0"; | |||||
| public static final String NO_FRAME = "1"; | |||||
| public static final String TYPE_DIR = "M"; | |||||
| public static final String TYPE_MENU = "C"; | |||||
| public static final String TYPE_BUTTON = "F"; | |||||
| public static final String LAYOUT = "Layout"; | |||||
| public static final String PARENT_VIEW = "ParentView"; | |||||
| public static final String INNER_LINK = "InnerLink"; | |||||
| public static final String UNIQUE = "0"; | |||||
| public static final String NOT_UNIQUE = "1"; | |||||
| public static final int USERNAME_MIN_LENGTH = 2; | |||||
| public static final int USERNAME_MAX_LENGTH = 20; | |||||
| public static final int PASSWORD_MIN_LENGTH = 5; | |||||
| public static final int PASSWORD_MAX_LENGTH = 40; | |||||
| } | |||||
| @ -0,0 +1,70 @@ | |||||
| package com.inspect.base.core.context; | |||||
| import com.alibaba.ttl.TransmittableThreadLocal; | |||||
| import com.inspect.base.core.constant.SecurityConstants; | |||||
| import com.inspect.base.core.text.Convert; | |||||
| import com.inspect.base.core.utils.StringUtils; | |||||
| import java.util.Map; | |||||
| import java.util.concurrent.ConcurrentHashMap; | |||||
| public class SecurityContextHolder { | |||||
| private static final TransmittableThreadLocal<Map<String, Object>> THREAD_LOCAL = new TransmittableThreadLocal<>(); | |||||
| public static void set(String key, Object value) { | |||||
| Map<String, Object> map = getLocalMap(); | |||||
| map.put(key, value == null ? "" : value); | |||||
| } | |||||
| public static String get(String key) { | |||||
| Map<String, Object> map = getLocalMap(); | |||||
| return Convert.toStr(map.getOrDefault(key, "")); | |||||
| } | |||||
| public static <T> T get(String key, Class<T> clazz) { | |||||
| Map<String, Object> map = getLocalMap(); | |||||
| return StringUtils.cast(map.getOrDefault(key, null)); | |||||
| } | |||||
| public static Map<String, Object> getLocalMap() { | |||||
| Map<String, Object> map = (Map) THREAD_LOCAL.get(); | |||||
| if (map == null) { | |||||
| map = new ConcurrentHashMap(); | |||||
| THREAD_LOCAL.set(map); | |||||
| } | |||||
| return (Map) map; | |||||
| } | |||||
| public static void setLocalMap(Map<String, Object> threadLocalMap) { | |||||
| THREAD_LOCAL.set(threadLocalMap); | |||||
| } | |||||
| public static Long getUserId() { | |||||
| return Convert.toLong(get("user_id"), 1L); | |||||
| } | |||||
| public static void setUserId(String account) { | |||||
| set("user_id", account); | |||||
| } | |||||
| public static String getUserName() { | |||||
| return get("username"); | |||||
| } | |||||
| public static void setUserName(String username) { | |||||
| set("username", username); | |||||
| } | |||||
| public static String getUserKey() { | |||||
| return get(SecurityConstants.USER_KEY); | |||||
| } | |||||
| public static void setUserKey(String userKey) { | |||||
| set(SecurityConstants.USER_KEY, userKey); | |||||
| } | |||||
| public static void remove() { | |||||
| THREAD_LOCAL.remove(); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,28 @@ | |||||
| package com.inspect.base.core.domain; | |||||
| import lombok.AllArgsConstructor; | |||||
| import lombok.Builder; | |||||
| import lombok.Data; | |||||
| import lombok.NoArgsConstructor; | |||||
| import java.io.InputStream; | |||||
| import java.util.List; | |||||
| @Data | |||||
| @Builder | |||||
| @NoArgsConstructor | |||||
| @AllArgsConstructor | |||||
| public class DataMsg { | |||||
| private String ip; | |||||
| private String port; | |||||
| private String username; | |||||
| private String password; | |||||
| private String isImplicit; | |||||
| private InputStream inputStream; | |||||
| private String fileName; | |||||
| private String filePath; | |||||
| private String type; | |||||
| private String uploadType; | |||||
| private List<String> filepathList; | |||||
| private String basePath; | |||||
| } | |||||
| @ -0,0 +1,15 @@ | |||||
| package com.inspect.base.core.domain; | |||||
| import lombok.AllArgsConstructor; | |||||
| import lombok.Builder; | |||||
| import lombok.Data; | |||||
| import lombok.NoArgsConstructor; | |||||
| @Data | |||||
| @Builder | |||||
| @AllArgsConstructor | |||||
| @NoArgsConstructor | |||||
| public class FtpResult { | |||||
| private boolean isOk; | |||||
| private String filepath; | |||||
| } | |||||
| @ -0,0 +1,83 @@ | |||||
| package com.inspect.base.core.domain; | |||||
| import com.inspect.base.core.constant.Constants; | |||||
| import java.io.Serializable; | |||||
| public class Response<T> implements Serializable { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public static final int SUCCESS; | |||||
| public static final int FAIL; | |||||
| private int code; | |||||
| private String msg; | |||||
| private T data; | |||||
| public static <T> Response<T> ok() { | |||||
| return restResult(null, SUCCESS, null); | |||||
| } | |||||
| public static <T> Response<T> ok(T data) { | |||||
| return restResult(data, SUCCESS, null); | |||||
| } | |||||
| public static <T> Response<T> ok(T data, String msg) { | |||||
| return restResult(data, SUCCESS, msg); | |||||
| } | |||||
| public static <T> Response<T> fail() { | |||||
| return restResult((T) null, FAIL, null); | |||||
| } | |||||
| public static <T> Response<T> fail(String msg) { | |||||
| return restResult(null, FAIL, msg); | |||||
| } | |||||
| public static <T> Response<T> fail(T data) { | |||||
| return restResult(data, FAIL, null); | |||||
| } | |||||
| public static <T> Response<T> fail(T data, String msg) { | |||||
| return restResult(data, FAIL, msg); | |||||
| } | |||||
| public static <T> Response<T> fail(int code, String msg) { | |||||
| return restResult(null, code, msg); | |||||
| } | |||||
| private static <T> Response<T> restResult(T data, int code, String msg) { | |||||
| Response<T> apiResult = new Response(); | |||||
| apiResult.setCode(code); | |||||
| apiResult.setData(data); | |||||
| apiResult.setMsg(msg); | |||||
| return apiResult; | |||||
| } | |||||
| public int getCode() { | |||||
| return this.code; | |||||
| } | |||||
| public void setCode(int code) { | |||||
| this.code = code; | |||||
| } | |||||
| public String getMsg() { | |||||
| return this.msg; | |||||
| } | |||||
| public void setMsg(String msg) { | |||||
| this.msg = msg; | |||||
| } | |||||
| public T getData() { | |||||
| return this.data; | |||||
| } | |||||
| public void setData(T data) { | |||||
| this.data = data; | |||||
| } | |||||
| static { | |||||
| SUCCESS = Constants.SUCCESS; | |||||
| FAIL = Constants.FAIL; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,51 @@ | |||||
| package com.inspect.base.core.domain; | |||||
| import com.inspect.base.core.annotation.Excel; | |||||
| import com.inspect.base.core.web.domain.BaseEntity; | |||||
| import lombok.Getter; | |||||
| import lombok.Setter; | |||||
| import java.util.Date; | |||||
| @Setter | |||||
| @Getter | |||||
| public class SysWarning extends BaseEntity { | |||||
| private Integer id; | |||||
| @Excel( | |||||
| name = "告警内容", | |||||
| sort = 2 | |||||
| ) | |||||
| private String text; | |||||
| @Excel( | |||||
| name = "相关人", | |||||
| sort = 1 | |||||
| ) | |||||
| private String userName; | |||||
| @Excel( | |||||
| name = "消息来源", | |||||
| sort = 3 | |||||
| ) | |||||
| private String sourceName; | |||||
| @Excel( | |||||
| name = "告警级别", | |||||
| sort = 4, | |||||
| readConverterExp = "1=一般,2=严重" | |||||
| ) | |||||
| private Integer level; | |||||
| @Excel( | |||||
| name = "告警类型", | |||||
| sort = 5, | |||||
| readConverterExp = "0=登录" | |||||
| ) | |||||
| private Integer type; | |||||
| @Excel( | |||||
| name = "告警时间", | |||||
| dateFormat = "yyyy-MM-dd HH:mm:ss" | |||||
| ) | |||||
| private Date time; | |||||
| private Date begin; | |||||
| private Date end; | |||||
| private Integer pageNum; | |||||
| private Integer pageSize; | |||||
| } | |||||
| @ -0,0 +1,89 @@ | |||||
| package com.inspect.base.core.domain.maintain; | |||||
| import com.fasterxml.jackson.annotation.JsonFormat; | |||||
| import com.inspect.base.core.annotation.Excel; | |||||
| import com.inspect.base.core.web.domain.BaseEntity; | |||||
| import lombok.AllArgsConstructor; | |||||
| import lombok.Builder; | |||||
| import lombok.Data; | |||||
| import lombok.NoArgsConstructor; | |||||
| import java.util.Date; | |||||
| @Data | |||||
| @Builder | |||||
| @NoArgsConstructor | |||||
| @AllArgsConstructor | |||||
| public class MaintainRegion extends BaseEntity { | |||||
| private static final long serialVersionUID = 1L; | |||||
| private Long lineId; | |||||
| @Excel( | |||||
| name = "变电站名称" | |||||
| ) | |||||
| private String stationName; | |||||
| @Excel( | |||||
| name = "变电站编码" | |||||
| ) | |||||
| private String stationCode; | |||||
| @Excel( | |||||
| name = "检修区域配置编码" | |||||
| ) | |||||
| private String configCode; | |||||
| @Excel( | |||||
| name = "是否有效 1:设置检修区域,0 取消检修 区域" | |||||
| ) | |||||
| private String enable; | |||||
| @JsonFormat( | |||||
| pattern = "yyyy-MM-dd" | |||||
| ) | |||||
| @Excel( | |||||
| name = "开始时间", | |||||
| width = 30.0D, | |||||
| dateFormat = "yyyy-MM-dd" | |||||
| ) | |||||
| private Date startTime; | |||||
| @JsonFormat( | |||||
| pattern = "yyyy-MM-dd" | |||||
| ) | |||||
| @Excel( | |||||
| name = "结束时间", | |||||
| width = 30.0D, | |||||
| dateFormat = "yyyy-MM-dd" | |||||
| ) | |||||
| private Date endTime; | |||||
| @Excel( | |||||
| name = "设备层级 : = 间隔 : = 主设备 : = 设备点位 : = 部件" | |||||
| ) | |||||
| private String deviceLevel; | |||||
| @Excel( | |||||
| name = "检修设备列表 格式:多个 ID,采用“,”分隔" | |||||
| ) | |||||
| private String deviceList; | |||||
| @Excel( | |||||
| name = "坐标框(像素点)格式:x1,y1,z1; x2,y2,z2; x3,y3,z3; x4,y4,z4" | |||||
| ) | |||||
| private String coordinatePixel; | |||||
| private String pointList; | |||||
| private String ids; | |||||
| private String pointName; | |||||
| @Override | |||||
| public String toString() { | |||||
| return "MaintainRegion{" + | |||||
| "lineId=" + lineId + | |||||
| ", stationName='" + stationName + '\'' + | |||||
| ", stationCode='" + stationCode + '\'' + | |||||
| ", configCode='" + configCode + '\'' + | |||||
| ", enable='" + enable + '\'' + | |||||
| ", startTime=" + startTime + | |||||
| ", endTime=" + endTime + | |||||
| ", deviceLevel='" + deviceLevel + '\'' + | |||||
| ", deviceList='" + deviceList + '\'' + | |||||
| ", coordinatePixel='" + coordinatePixel + '\'' + | |||||
| ", pointList='" + pointList + '\'' + | |||||
| ", ids='" + ids + '\'' + | |||||
| ", pointName='" + pointName + '\'' + | |||||
| '}'; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,17 @@ | |||||
| package com.inspect.base.core.enums; | |||||
| import lombok.AllArgsConstructor; | |||||
| import lombok.Getter; | |||||
| @Getter | |||||
| @AllArgsConstructor | |||||
| public enum ExecStatus { | |||||
| IMMEDIATE("0", "立即执行"), | |||||
| PERIODIC("1", "周期执行"), | |||||
| REGULAR("2", "定期执行"), | |||||
| ALREADY("3", "已经执行"), | |||||
| INTERVAL("4", "间隔执行"); | |||||
| private final String code; | |||||
| private final String info; | |||||
| } | |||||
| @ -0,0 +1,22 @@ | |||||
| package com.inspect.base.core.enums; | |||||
| public enum IntervalType { | |||||
| BY_HOUR("1", "按小时"), | |||||
| BY_DATE("2", "按天"); | |||||
| private final String code; | |||||
| private final String info; | |||||
| IntervalType(String code, String info) { | |||||
| this.code = code; | |||||
| this.info = info; | |||||
| } | |||||
| public String getCode() { | |||||
| return this.code; | |||||
| } | |||||
| public String getInfo() { | |||||
| return this.info; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,18 @@ | |||||
| package com.inspect.base.core.enums; | |||||
| import lombok.Getter; | |||||
| @Getter | |||||
| public enum PresetAction { | |||||
| PHOTO("1", "PHOTO"), | |||||
| VIDEO("2", "VIDEO"), | |||||
| ; | |||||
| private final String code; | |||||
| private final String info; | |||||
| PresetAction(String code, String info) { | |||||
| this.code = code; | |||||
| this.info = info; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,52 @@ | |||||
| package com.inspect.base.core.enums; | |||||
| import lombok.Getter; | |||||
| @Getter | |||||
| public enum StaEnum { | |||||
| BatPwr("1", "电池电量低"), | |||||
| BatPwr_0("1-0", "正常"), | |||||
| BatPwr_1("1-1", "低"), | |||||
| CommSta("2", "通信状态异常"), | |||||
| CommSta_0("2-0", "正常"), | |||||
| CommSta_1("2-1", "异常"), | |||||
| UlsonStopErr("3", "超声停障"), | |||||
| UlsonStopErr_0("3-0", "正常"), | |||||
| UlsonStopErr_1("3-1", "异常"), | |||||
| DriveErr("4", "驱动异常"), | |||||
| DriveErr_0("4-0", "正常"), | |||||
| DriveErr_1("4-1", "异常"), | |||||
| FaultAlm("21", "故障报警"), | |||||
| FaultAlm_0("21-0", "正常"), | |||||
| FaultAlm_1("21-1", "报警"), | |||||
| RunState("41", "运行状态"), | |||||
| RunState_1("41-1", "空闲状态"), | |||||
| RunState_2("41-2", "巡视状态"), | |||||
| RunState_3("41-3", "充电状态"), | |||||
| RunState_4("41-4", "检修状态"), | |||||
| CtlModel("61", "控制模式"), | |||||
| CtlModel_1("61-1", "任务模式"), | |||||
| CtlModel_2("61-2", "紧急定位模式"), | |||||
| CtlModel_3("61-3", "后台遥控模式"), | |||||
| CtlModel_4("61-4", "手持遥控模式"), | |||||
| CtlStat("81", "控制权状态"), | |||||
| CtlStat_0("81-0", "空闲"), | |||||
| CtlStat_1("81-1", "获得"), | |||||
| RotStat("101", "轮转状态"), | |||||
| RotStat_0("101-0", "空闲"), | |||||
| RotStat_1("101-1", "值班"), | |||||
| FliSta("201", "飞行状态"), | |||||
| FliSta_1("201-1", "待命"), | |||||
| FliSta_2("201-2", "准备起飞"), | |||||
| FliSta_3("201-3", "飞行中"), | |||||
| FliSta_4("201-4", "返航"), | |||||
| FliSta_5("201-5", "着陆"); | |||||
| private final String code; | |||||
| private final String value; | |||||
| StaEnum(String typeCode, String value) { | |||||
| this.code = typeCode; | |||||
| this.value = value; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,21 @@ | |||||
| package com.inspect.base.core.enums; | |||||
| import lombok.Getter; | |||||
| @Getter | |||||
| public enum TaskStatus { | |||||
| DONE("1", "已经执行"), | |||||
| RUNNING("2", "正在执行"), | |||||
| PAUSED("3", "暂停执行"), | |||||
| HALTED("4", "终止执行"), | |||||
| PENDING("5", "尚未执行"), | |||||
| EXPIRED("6", "超过期限"); | |||||
| private final String code; | |||||
| private final String info; | |||||
| TaskStatus(String code, String info) { | |||||
| this.code = code; | |||||
| this.info = info; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,23 @@ | |||||
| package com.inspect.base.core.enums; | |||||
| public enum UserStatus { | |||||
| OK("0", "正常"), | |||||
| DISABLE("1", "停用"), | |||||
| DELETED("2", "删除"); | |||||
| private final String code; | |||||
| private final String info; | |||||
| private UserStatus(String code, String info) { | |||||
| this.code = code; | |||||
| this.info = info; | |||||
| } | |||||
| public String getCode() { | |||||
| return this.code; | |||||
| } | |||||
| public String getInfo() { | |||||
| return this.info; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,9 @@ | |||||
| package com.inspect.base.core.exception; | |||||
| public class CaptchaException extends RuntimeException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public CaptchaException(String msg) { | |||||
| super(msg); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,21 @@ | |||||
| package com.inspect.base.core.exception; | |||||
| public class CheckedException extends RuntimeException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public CheckedException(String message) { | |||||
| super(message); | |||||
| } | |||||
| public CheckedException(Throwable cause) { | |||||
| super(cause); | |||||
| } | |||||
| public CheckedException(String message, Throwable cause) { | |||||
| super(message, cause); | |||||
| } | |||||
| public CheckedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | |||||
| super(message, cause, enableSuppression, writableStackTrace); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,5 @@ | |||||
| package com.inspect.base.core.exception; | |||||
| public class DemoModeException extends RuntimeException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| } | |||||
| @ -0,0 +1,32 @@ | |||||
| package com.inspect.base.core.exception; | |||||
| public class GlobalException extends RuntimeException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| private String message; | |||||
| private String detailMessage; | |||||
| public GlobalException() { | |||||
| } | |||||
| public GlobalException(String message) { | |||||
| this.message = message; | |||||
| } | |||||
| public String getDetailMessage() { | |||||
| return this.detailMessage; | |||||
| } | |||||
| public GlobalException setDetailMessage(String detailMessage) { | |||||
| this.detailMessage = detailMessage; | |||||
| return this; | |||||
| } | |||||
| public String getMessage() { | |||||
| return this.message; | |||||
| } | |||||
| public GlobalException setMessage(String message) { | |||||
| this.message = message; | |||||
| return this; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,9 @@ | |||||
| package com.inspect.base.core.exception; | |||||
| public class InnerAuthException extends RuntimeException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public InnerAuthException(String message) { | |||||
| super(message); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,5 @@ | |||||
| package com.inspect.base.core.exception; | |||||
| public class PreAuthorizeException extends RuntimeException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| } | |||||
| @ -0,0 +1,42 @@ | |||||
| package com.inspect.base.core.exception; | |||||
| public final class ServiceException extends RuntimeException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| private Integer code; | |||||
| private String message; | |||||
| private String detailMessage; | |||||
| public ServiceException() { | |||||
| } | |||||
| public ServiceException(String message) { | |||||
| this.message = message; | |||||
| } | |||||
| public ServiceException(String message, Integer code) { | |||||
| this.message = message; | |||||
| this.code = code; | |||||
| } | |||||
| public String getDetailMessage() { | |||||
| return this.detailMessage; | |||||
| } | |||||
| public String getMessage() { | |||||
| return this.message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return this.code; | |||||
| } | |||||
| public ServiceException setMessage(String message) { | |||||
| this.message = message; | |||||
| return this; | |||||
| } | |||||
| public ServiceException setDetailMessage(String detailMessage) { | |||||
| this.detailMessage = detailMessage; | |||||
| return this; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,17 @@ | |||||
| package com.inspect.base.core.exception; | |||||
| public class UtilException extends RuntimeException { | |||||
| private static final long serialVersionUID = 8247610319171014183L; | |||||
| public UtilException(Throwable e) { | |||||
| super(e.getMessage(), e); | |||||
| } | |||||
| public UtilException(String message) { | |||||
| super(message); | |||||
| } | |||||
| public UtilException(String message, Throwable throwable) { | |||||
| super(message, throwable); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,9 @@ | |||||
| package com.inspect.base.core.exception.auth; | |||||
| public class NotLoginException extends RuntimeException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public NotLoginException(String message) { | |||||
| super(message); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,16 @@ | |||||
| package com.inspect.base.core.exception.auth; | |||||
| import com.inspect.base.core.utils.StringUtils; | |||||
| public class NotPermissionException extends RuntimeException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public NotPermissionException(String permission) { | |||||
| super(permission); | |||||
| } | |||||
| public NotPermissionException(String[] permissions) { | |||||
| super(StringUtils.join(permissions, StringUtils.COMMA)); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,16 @@ | |||||
| package com.inspect.base.core.exception.auth; | |||||
| import com.inspect.base.core.utils.StringUtils; | |||||
| public class NotRoleException extends RuntimeException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public NotRoleException(String role) { | |||||
| super(role); | |||||
| } | |||||
| public NotRoleException(String[] roles) { | |||||
| super(StringUtils.join(roles, StringUtils.COMMA)); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,36 @@ | |||||
| package com.inspect.base.core.exception.base; | |||||
| import lombok.Getter; | |||||
| @Getter | |||||
| public class BaseException extends RuntimeException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| private String module; | |||||
| private String code; | |||||
| private Object[] args; | |||||
| private String defaultMessage; | |||||
| public BaseException(String module, String code, Object[] args, String defaultMessage) { | |||||
| this.module = module; | |||||
| this.code = code; | |||||
| this.args = args; | |||||
| this.defaultMessage = defaultMessage; | |||||
| } | |||||
| public BaseException(String module, String code, Object[] args) { | |||||
| this(module, code, args, null); | |||||
| } | |||||
| public BaseException(String module, String defaultMessage) { | |||||
| this(module, null, null, defaultMessage); | |||||
| } | |||||
| public BaseException(String code, Object[] args) { | |||||
| this(null, code, args, null); | |||||
| } | |||||
| public BaseException(String defaultMessage) { | |||||
| this(null, null, null, defaultMessage); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,11 @@ | |||||
| package com.inspect.base.core.exception.file; | |||||
| import com.inspect.base.core.exception.base.BaseException; | |||||
| public class FileException extends BaseException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public FileException(String code, Object[] args) { | |||||
| super("file", code, args, null); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,9 @@ | |||||
| package com.inspect.base.core.exception.file; | |||||
| public class FileNameLengthLimitExceededException extends FileException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public FileNameLengthLimitExceededException(int defaultFileNameLength) { | |||||
| super("upload.filename.exceed.length", new Object[]{defaultFileNameLength}); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,9 @@ | |||||
| package com.inspect.base.core.exception.file; | |||||
| public class FileSizeLimitExceededException extends FileException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public FileSizeLimitExceededException(long defaultMaxSize) { | |||||
| super("upload.exceed.maxSize", new Object[]{defaultMaxSize}); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,53 @@ | |||||
| package com.inspect.base.core.exception.file; | |||||
| import java.util.Arrays; | |||||
| import lombok.Getter; | |||||
| import org.apache.commons.fileupload.FileUploadException; | |||||
| @Getter | |||||
| public class InvalidExtensionException extends FileUploadException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| private String[] allowedExtension; | |||||
| private String extension; | |||||
| private String filename; | |||||
| public InvalidExtensionException(String[] allowedExtension, String extension, String filename) { | |||||
| super("filename : [" + filename + "], extension : [" + extension + "], allowed extension : [" + Arrays.toString(allowedExtension) + "]"); | |||||
| this.allowedExtension = allowedExtension; | |||||
| this.extension = extension; | |||||
| this.filename = filename; | |||||
| } | |||||
| public static class InvalidVideoExtensionException extends InvalidExtensionException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public InvalidVideoExtensionException(String[] allowedExtension, String extension, String filename) { | |||||
| super(allowedExtension, extension, filename); | |||||
| } | |||||
| } | |||||
| public static class InvalidMediaExtensionException extends InvalidExtensionException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public InvalidMediaExtensionException(String[] allowedExtension, String extension, String filename) { | |||||
| super(allowedExtension, extension, filename); | |||||
| } | |||||
| } | |||||
| public static class InvalidFlashExtensionException extends InvalidExtensionException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public InvalidFlashExtensionException(String[] allowedExtension, String extension, String filename) { | |||||
| super(allowedExtension, extension, filename); | |||||
| } | |||||
| } | |||||
| public static class InvalidImageExtensionException extends InvalidExtensionException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public InvalidImageExtensionException(String[] allowedExtension, String extension, String filename) { | |||||
| super(allowedExtension, extension, filename); | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,27 @@ | |||||
| package com.inspect.base.core.exception.job; | |||||
| import lombok.Getter; | |||||
| @Getter | |||||
| public class TaskException extends Exception { | |||||
| private static final long serialVersionUID = 1L; | |||||
| private TaskException.Code code; | |||||
| public TaskException(String msg, TaskException.Code code) { | |||||
| this(msg, code, null); | |||||
| } | |||||
| public TaskException(String msg, TaskException.Code code, Exception nestedEx) { | |||||
| super(msg, nestedEx); | |||||
| this.code = code; | |||||
| } | |||||
| public static enum Code { | |||||
| TASK_EXISTS, | |||||
| NO_TASK_EXISTS, | |||||
| TASK_ALREADY_STARTED, | |||||
| UNKNOWN, | |||||
| CONFIG_ERROR, | |||||
| TASK_NODE_NOT_AVAILABLE; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,9 @@ | |||||
| package com.inspect.base.core.exception.user; | |||||
| public class CaptchaExpireException extends UserException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public CaptchaExpireException() { | |||||
| super("user.jcaptcha.expire", null); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,11 @@ | |||||
| package com.inspect.base.core.exception.user; | |||||
| import com.inspect.base.core.exception.base.BaseException; | |||||
| public class UserException extends BaseException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public UserException(String code, Object[] args) { | |||||
| super("user", code, args, null); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,9 @@ | |||||
| package com.inspect.base.core.exception.user; | |||||
| public class UserPasswordNotMatchException extends UserException { | |||||
| private static final long serialVersionUID = 1L; | |||||
| public UserPasswordNotMatchException() { | |||||
| super("user.password.not.match", null); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,38 @@ | |||||
| package com.inspect.base.core.service; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.inspect.base.core.utils.HttpClientUtils; | |||||
| import com.inspect.base.core.web.domain.AjaxResult; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Value; | |||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |||||
| import org.springframework.cloud.context.config.annotation.RefreshScope; | |||||
| import org.springframework.stereotype.Service; | |||||
| @Service | |||||
| @RefreshScope | |||||
| @ConditionalOnProperty( | |||||
| name = {"tcp.client.enable"}, | |||||
| havingValue = "true" | |||||
| ) | |||||
| public class SendService { | |||||
| private Logger logger = LoggerFactory.getLogger(SendService.class); | |||||
| @Value("${tcp.client.send}") | |||||
| String sendUrl; | |||||
| public AjaxResult sendMsg(String msg) { | |||||
| return this.sendMsg(null, msg); | |||||
| } | |||||
| public AjaxResult sendMsg(String type, String msg) { | |||||
| try { | |||||
| String resultJson = HttpClientUtils.postJson(this.sendUrl, msg, null); | |||||
| AjaxResult ajaxResult = JSONObject.parseObject(resultJson, AjaxResult.class); | |||||
| return ajaxResult; | |||||
| } catch (Exception e) { | |||||
| this.logger.error("上报消息到上级系统捕获异常", e); | |||||
| return AjaxResult.fail(500, "上报消息失败"); | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,207 @@ | |||||
| package com.inspect.base.core.sftp; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import java.io.*; | |||||
| import com.inspect.base.core.constant.Color; | |||||
| import com.inspect.base.core.utils.StringUtils; | |||||
| import org.apache.commons.compress.utils.IOUtils; | |||||
| import org.apache.commons.net.ftp.FTPSClient; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.stereotype.Component; | |||||
| @Component | |||||
| public class SftpClient { | |||||
| protected final Logger log = LoggerFactory.getLogger(this.getClass()); | |||||
| private final SftpLoginConfig sftpLoginConfig; | |||||
| private final SftpFactory sftpFactory; | |||||
| public SftpClient(SftpLoginConfig sftpLoginConfig, SftpFactory sftpFactory) { | |||||
| this.sftpLoginConfig = sftpLoginConfig; | |||||
| this.sftpFactory = sftpFactory; | |||||
| } | |||||
| public String upload(SftpUploadEntity sftpUploadEntity) throws Exception { | |||||
| // final String tmp = sftpUploadEntity.getFileFullName(); | |||||
| // final String fileFullName = tmp.startsWith(sftpLoginConfig.getBasePath()) ? tmp : sftpLoginConfig.getBasePath() + tmp; | |||||
| final String tmp = sftpUploadEntity.getFileFullName(); | |||||
| final String fileFullName = tmp.startsWith(sftpLoginConfig.getBasePath()) ? tmp : sftpLoginConfig.getBasePath() + tmp; | |||||
| final String fileFullNameEx = StringUtils.isNotEmpty(sftpLoginConfig.getPrefix()) | |||||
| ? sftpLoginConfig.getPrefix() + fileFullName | |||||
| : fileFullName; | |||||
| log.info(Color.GREEN + "[FTP] fileFullName: {}, fileFullNameEx: {}" + Color.END, fileFullName, fileFullNameEx); | |||||
| connect((ftps) -> { | |||||
| log.info(Color.GREEN + "[FTP] UPLOAD Entity: {}" + Color.END, JSONObject.toJSONString(sftpUploadEntity)); | |||||
| String path = fileFullNameEx.substring(0, fileFullNameEx.lastIndexOf(StringUtils.SLASH)); | |||||
| mkdir(ftps, path); | |||||
| boolean bOk = ftps.storeFile(fileFullNameEx, sftpUploadEntity.getInputStream()); | |||||
| log.info(Color.GREEN + "[FTP] UPLOAD {}, PATH: {}, FULL PATH: {}, REPLY CODE: {}, INFO: {}" + Color.END, bOk ? "OK" : "FAIL", path, fileFullNameEx, ftps.getReplyCode(), ftps.getReplyString()); | |||||
| sftpUploadEntity.getInputStream().close(); | |||||
| }); | |||||
| return sftpUploadEntity.toResultPath(sftpLoginConfig.getBasePath()); | |||||
| } | |||||
| public String upload(SftpUploadEntity sftpUploadEntity, SftpClient.Upload upload) throws Exception { | |||||
| final String tmp = sftpUploadEntity.getFileFullName(); | |||||
| final String fileFullName = tmp.startsWith(sftpLoginConfig.getBasePath()) ? tmp : sftpLoginConfig.getBasePath() + tmp; | |||||
| final String fileFullNameEx = StringUtils.isNotEmpty(sftpLoginConfig.getPrefix()) | |||||
| ? sftpLoginConfig.getPrefix() + fileFullName | |||||
| : fileFullName; | |||||
| log.info("[FTP] fileFullName: {}, fileFullNameEx: {}", fileFullName, fileFullNameEx); | |||||
| connect((ftps) -> { | |||||
| String path = fileFullNameEx.substring(0, fileFullNameEx.lastIndexOf("/")); | |||||
| mkdir(ftps, path); | |||||
| log.info("[FTP] UPLOAD fileFullName: {}", fileFullNameEx); | |||||
| OutputStream outputStream = ftps.storeFileStream(fileFullNameEx); | |||||
| log.info("[FTP] UPLOAD outputStream: {}", outputStream); | |||||
| upload.run(outputStream); | |||||
| outputStream.close(); | |||||
| log.info("[FTP] UPLOAD OK: {}", fileFullNameEx); | |||||
| }); | |||||
| return sftpUploadEntity.toResultPath(sftpLoginConfig.getBasePath()); | |||||
| } | |||||
| public void mkdir(FTPSClient ftps, String path) throws IOException { | |||||
| ftps.changeWorkingDirectory(StringUtils.SLASH); | |||||
| String[] dirs = path.split(StringUtils.SLASH); | |||||
| for (String dir : dirs) { | |||||
| //log.info("[FTP] dir: {}", dir); | |||||
| if (StringUtils.isEmpty(dir)) { | |||||
| continue; | |||||
| } | |||||
| if (!ftps.changeWorkingDirectory(dir)) { | |||||
| ftps.makeDirectory(dir); | |||||
| ftps.changeWorkingDirectory(dir); | |||||
| } | |||||
| } | |||||
| } | |||||
| public void downLoad(String fileFullPath, SftpClient.Download download) throws Exception { | |||||
| final String fileFullPathTmp | |||||
| = fileFullPath.startsWith(sftpLoginConfig.getBasePath()) ? fileFullPath : sftpLoginConfig.getBasePath() + fileFullPath; | |||||
| final String fileFullNameTmpEx = StringUtils.isNotEmpty(sftpLoginConfig.getPrefix()) ? sftpLoginConfig.getPrefix() + fileFullPathTmp : fileFullPathTmp; | |||||
| log.info("[FTP] fileFullNameTmpEx: {}", fileFullPathTmp); | |||||
| connect((ftps) -> { | |||||
| InputStream inputStream = ftps.retrieveFileStream(fileFullNameTmpEx); | |||||
| if (inputStream == null) { | |||||
| log.error("[FTP] DOWNLOAD FAIL, EMPTY STREAM: {}", fileFullPath); | |||||
| } else { | |||||
| download.run(inputStream); | |||||
| inputStream.close(); | |||||
| } | |||||
| }); | |||||
| } | |||||
| private void connect(SftpClient.JoinPoint joinPoint) throws Exception { | |||||
| log.debug("[FTP} START <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"); | |||||
| long start = System.currentTimeMillis(); | |||||
| FTPSClient ftps = sftpFactory.connect(); | |||||
| try { | |||||
| ftps.setFileType(FTPSClient.BINARY_FILE_TYPE); | |||||
| } catch (IOException e) { | |||||
| log.error("[FTP] TIMEOUT, RETRY"); | |||||
| ftps = sftpFactory.connect(); | |||||
| ftps.setFileType(FTPSClient.BINARY_FILE_TYPE); | |||||
| sftpFactory.init(); | |||||
| } | |||||
| ftps.enterLocalPassiveMode(); | |||||
| ftps.enterLocalPassiveMode(); | |||||
| ftps.setFileTransferMode(FTPSClient.STREAM_TRANSFER_MODE); | |||||
| ftps.execPROT("P"); | |||||
| log.debug("[FTP] CONN COST: {}", System.currentTimeMillis() - start); | |||||
| start = System.currentTimeMillis(); | |||||
| joinPoint.run(ftps); | |||||
| //log.info("[FTP] TRANSPORT COST: {}", System.currentTimeMillis() - start); | |||||
| log.debug("[FTP] END >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |||||
| ftps.logout(); | |||||
| } | |||||
| public interface Upload { | |||||
| void run(OutputStream outputStream) throws Exception; | |||||
| } | |||||
| public interface Download { | |||||
| void run(InputStream inputStream) throws Exception; | |||||
| } | |||||
| interface JoinPoint { | |||||
| void run(FTPSClient ftpsClient) throws Exception; | |||||
| } | |||||
| public static void main(String[] args) throws Exception { | |||||
| // try { | |||||
| // FTPSClient ftps = new FTPSClient(true); | |||||
| // ftps.connect("192.168.1.198", 990); | |||||
| // boolean loginRes = ftps.login("ftpuser", "atia2018"); | |||||
| // System.out.println(loginRes); | |||||
| // ftps.setFileType(2); | |||||
| // //ftps.enterLocalPassiveMode(); | |||||
| // //ftps.enterLocalPassiveMode(); | |||||
| // ftps.setControlEncoding("UTF-8"); | |||||
| // ftps.setFileTransferMode(10); | |||||
| // ftps.execPROT("P"); | |||||
| // ftps.storeFile("11.jpg", new FileInputStream("E:/1.jpg")); | |||||
| // | |||||
| // String fileFullPathTmp = "1/2025/02/26/1339/CCD/1339_20250226095445_2023833_02160558340721910141.jpg"; | |||||
| // InputStream inputStream = ftps.retrieveFileStream(fileFullPathTmp); | |||||
| // if (inputStream == null) { | |||||
| // System.out.println("[FTP] DOWNLOAD FAIL, EMPTY STREAM:" + fileFullPathTmp); | |||||
| // } else { | |||||
| // File tempFile = File.createTempFile("E:\\test001234", ".jpg"); | |||||
| // tempFile.deleteOnExit(); | |||||
| // FileOutputStream out = new FileOutputStream(tempFile); | |||||
| // IOUtils.copy(inputStream, out); | |||||
| // inputStream.close(); | |||||
| // } | |||||
| // | |||||
| // | |||||
| // } catch (Exception e) { | |||||
| // e.printStackTrace(); | |||||
| // } | |||||
| try { | |||||
| FTPSClient ftps = new FTPSClient(true); | |||||
| // ftps.connect("192.168.1.198", 21); | |||||
| // boolean loginRes = ftps.login("hangtian", "123qweasd"); | |||||
| ftps.connect("192.168.1.12", 1991); | |||||
| boolean loginRes = ftps.login("ftpuser", "atia2018"); | |||||
| System.out.println(loginRes); | |||||
| ftps.setFileType(2); | |||||
| ftps.enterLocalPassiveMode(); | |||||
| ftps.enterLocalPassiveMode(); | |||||
| ftps.setControlEncoding("UTF-8"); | |||||
| ftps.setFileTransferMode(10); | |||||
| ftps.execPROT("P"); | |||||
| ftps.storeFile("11.jpg", new FileInputStream("E:/1.jpg")); | |||||
| String fileFullPathTmp = "1/2025/02/26/1339/CCD/1339_20250226095445_2023833_02160558340721910141.jpg"; | |||||
| //String fileFullPathTmp = "/home/hangtian/11.jpg"; | |||||
| InputStream inputStream = ftps.retrieveFileStream(fileFullPathTmp); | |||||
| if (inputStream == null) { | |||||
| System.out.println("[FTP] DOWNLOAD FAIL, EMPTY STREAM:" + fileFullPathTmp); | |||||
| } else { | |||||
| File tempFile = File.createTempFile("test0012345555", ".jpg"); | |||||
| tempFile.deleteOnExit(); | |||||
| FileOutputStream out = new FileOutputStream(tempFile); | |||||
| IOUtils.copy(inputStream, out); | |||||
| inputStream.close(); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| e.printStackTrace(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,6 @@ | |||||
| package com.inspect.base.core.sftp; | |||||
| public class SftpConstant { | |||||
| public static final String CHANNEL_SNAP_PATH = "snap/"; | |||||
| public static final String FILE_SUFFIX_JPG = ".jpg"; | |||||
| } | |||||
| @ -0,0 +1,124 @@ | |||||
| package com.inspect.base.core.sftp; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.inspect.base.core.constant.Color; | |||||
| import com.inspect.base.core.exception.ServiceException; | |||||
| import java.io.IOException; | |||||
| import java.util.ArrayDeque; | |||||
| import java.util.Queue; | |||||
| import javax.annotation.PostConstruct; | |||||
| import javax.net.ssl.SSLContext; | |||||
| import org.apache.commons.net.ftp.FTPClient; | |||||
| import org.apache.commons.net.ftp.FTPSClient; | |||||
| import org.apache.commons.net.util.TrustManagerUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Component; | |||||
| @Component | |||||
| public class SftpFactory { | |||||
| protected final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private SftpLoginConfig sftpLoginConfig; | |||||
| public volatile Queue<FTPSClient> queue = new ArrayDeque<>(); | |||||
| public int aliveNum = 20; | |||||
| public int initNum = 5; | |||||
| public synchronized FTPSClient getInstance() { | |||||
| return !this.queue.isEmpty() ? this.queue.remove() : null; | |||||
| } | |||||
| public void reset() { | |||||
| (new Thread(() -> { | |||||
| if (this.queue.size() < this.aliveNum) { | |||||
| try { | |||||
| this.queue.add(this.connect()); | |||||
| } catch (IOException var2) { | |||||
| ; | |||||
| } | |||||
| } | |||||
| })).start(); | |||||
| } | |||||
| @PostConstruct | |||||
| public void init() throws IOException { | |||||
| (new Thread(() -> { | |||||
| this.queue.clear(); | |||||
| for (int i = 0; i < this.initNum; ++i) { | |||||
| FTPSClient ftps = null; | |||||
| try { | |||||
| ftps = this.connect(); | |||||
| this.queue.add(ftps); | |||||
| } catch (IOException e) { | |||||
| ; | |||||
| } catch (ServiceException e) { | |||||
| if (!"Error".equals(e.getMessage())) { | |||||
| throw e; | |||||
| } | |||||
| } | |||||
| } | |||||
| })).start(); | |||||
| } | |||||
| public FTPSClient connect() throws IOException { | |||||
| boolean isImplicit = "true".equals(sftpLoginConfig.getIsImplicit()); | |||||
| //boolean isImplicit = Boolean.getBoolean(sftpLoginConfig.getIsImplicit()); | |||||
| logger.info(Color.MAGENTA + "[FTP] isImplicit: {}" + Color.END, isImplicit); | |||||
| FTPSClient ftps = new FTPSClient(isImplicit); | |||||
| try { | |||||
| ftps.setControlEncoding("UTF-8"); | |||||
| ftps.connect(sftpLoginConfig.getIp(), Integer.parseInt(sftpLoginConfig.getPort())); | |||||
| } catch (Exception e) { | |||||
| logger.error("[FTP] CONN FAIL: {}, CAUSE: {}", JSONObject.toJSONString(sftpLoginConfig), e.getMessage()); | |||||
| try { | |||||
| Thread.sleep(1000L); | |||||
| } catch (InterruptedException e2) { | |||||
| ; | |||||
| } | |||||
| return connect(); | |||||
| } | |||||
| boolean login = ftps.login(sftpLoginConfig.getUsername(), sftpLoginConfig.getPassword()); | |||||
| if (!login) { | |||||
| throw new ServiceException("LOGIN TO FTP FAIL!"); | |||||
| } else { | |||||
| return ftps; | |||||
| } | |||||
| } | |||||
| public static void main(String[] args) { | |||||
| for (int i = 0; i < 100; i++) { | |||||
| try { | |||||
| FTPSClient ftps = new FTPSClient(true); | |||||
| ftps.setControlEncoding("UTF-8"); | |||||
| ftps.connect("192.168.1.198", 990); | |||||
| //ftps.connect("192.168.1.116", 1990); | |||||
| boolean login = ftps.login("ftpuser", "atia2018"); | |||||
| System.out.println("ss:" + login); | |||||
| } catch (Exception var5) { | |||||
| var5.printStackTrace(); | |||||
| try { | |||||
| Thread.sleep(1000L); | |||||
| } catch (InterruptedException var4) { | |||||
| ; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,35 @@ | |||||
| package com.inspect.base.core.sftp; | |||||
| import lombok.Getter; | |||||
| import lombok.Setter; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| @Setter | |||||
| @Getter | |||||
| @Component | |||||
| @ConfigurationProperties( | |||||
| prefix = "sftp" | |||||
| ) | |||||
| public class SftpLoginConfig { | |||||
| private String ip; | |||||
| private String port; | |||||
| private String username; | |||||
| private String password; | |||||
| private String isImplicit; | |||||
| private String basePath; | |||||
| private String prefix; | |||||
| @Override | |||||
| public String toString() { | |||||
| return "SftpLoginConfig{" + | |||||
| "ip='" + ip + '\'' + | |||||
| ", port='" + port + '\'' + | |||||
| ", username='" + username + '\'' + | |||||
| ", password='" + password + '\'' + | |||||
| ", isImplicit='" + isImplicit + '\'' + | |||||
| ", basePath='" + basePath + '\'' + | |||||
| ", prefix='" + prefix + '\'' + | |||||
| '}'; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,60 @@ | |||||
| package com.inspect.base.core.sftp; | |||||
| import com.inspect.base.core.utils.StringUtils; | |||||
| import lombok.Getter; | |||||
| import lombok.Setter; | |||||
| import java.io.InputStream; | |||||
| import java.util.UUID; | |||||
| public class SftpUploadEntity { | |||||
| @Getter | |||||
| private String filePath = ""; | |||||
| @Getter | |||||
| private String fileName = UUID.randomUUID().toString(); | |||||
| @Setter | |||||
| @Getter | |||||
| private String suffix = ".jpg"; | |||||
| @Setter | |||||
| private String fileFullName; | |||||
| @Setter | |||||
| @Getter | |||||
| private InputStream inputStream; | |||||
| public SftpUploadEntity() { | |||||
| } | |||||
| public SftpUploadEntity(InputStream inputStream) { | |||||
| this.inputStream = inputStream; | |||||
| } | |||||
| public void setFilePath(String filePath) { | |||||
| this.filePath = filePath; | |||||
| if (filePath.contains(".")) { | |||||
| String[] split = filePath.split("\\."); | |||||
| this.filePath = split[0]; | |||||
| this.suffix = "." + split[split.length - 1]; | |||||
| } else if (!filePath.endsWith("/")) { | |||||
| this.filePath = this.filePath + "/"; | |||||
| } | |||||
| } | |||||
| public void setFileName(String fileName) { | |||||
| this.fileName = fileName; | |||||
| if (fileName.contains(".")) { | |||||
| String[] split = fileName.split("\\."); | |||||
| this.fileName = split[0]; | |||||
| this.suffix = "." + split[split.length - 1]; | |||||
| } | |||||
| } | |||||
| public String getFileFullName() { | |||||
| return !StringUtils.isEmpty(this.fileFullName) ? this.fileFullName : this.filePath + this.fileName + this.suffix; | |||||
| } | |||||
| public String toResultPath(String basePath) { | |||||
| this.fileFullName = this.getFileFullName(); | |||||
| return this.fileFullName.startsWith(basePath) ? this.fileFullName.replaceFirst(basePath, "") : this.fileFullName; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,119 @@ | |||||
| package com.inspect.base.core.sftp; | |||||
| import java.io.IOException; | |||||
| import java.io.InputStream; | |||||
| import com.inspect.base.core.utils.StringUtils; | |||||
| import org.apache.commons.net.ftp.FTPClient; | |||||
| import org.apache.commons.net.ftp.FTPFile; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Component; | |||||
| @Component | |||||
| public class ftpClient { | |||||
| protected final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private static SftpClient sftpClient; | |||||
| public static InputStream login(String host, int port, String username, String password, String fileName, String path) throws Exception { | |||||
| InputStream inputStream = null; | |||||
| FTPClient ftp = new FTPClient(); | |||||
| ftp.setControlEncoding("UTF-8"); | |||||
| ftp.connect(host, port); | |||||
| boolean success = ftp.login(username, password); | |||||
| if (success) { | |||||
| inputStream = downLoad(ftp, fileName, path); | |||||
| logout(ftp); | |||||
| } | |||||
| return inputStream; | |||||
| } | |||||
| public static void logout(FTPClient ftps) throws IOException { | |||||
| if (ftps != null && ftps.isConnected()) { | |||||
| ftps.disconnect(); | |||||
| } | |||||
| } | |||||
| public static boolean existFile(FTPClient ftp, String path, String fileName) throws IOException { | |||||
| boolean flag = false; | |||||
| String[] str = path.split(StringUtils.SLASH); | |||||
| for (String s : str) { | |||||
| ftp.changeWorkingDirectory(s); | |||||
| } | |||||
| FTPFile[] files = ftp.listFiles(); | |||||
| if (files != null) { | |||||
| for (FTPFile file : files) { | |||||
| if (file.getName().equals(fileName)) { | |||||
| System.out.println("File exists." + fileName); | |||||
| flag = true; | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| return flag; | |||||
| } | |||||
| public static void mkdir(FTPClient ftps, String path) throws IOException { | |||||
| String[] split = path.split(StringUtils.SLASH); | |||||
| ftps.changeWorkingDirectory(StringUtils.SLASH); | |||||
| for (String str : split) { | |||||
| if (ftps.changeWorkingDirectory(str)) { | |||||
| ftps.changeWorkingDirectory(str); | |||||
| } else { | |||||
| ftps.makeDirectory(str); | |||||
| ftps.changeWorkingDirectory(str); | |||||
| } | |||||
| } | |||||
| } | |||||
| public static InputStream downLoad(FTPClient ftp, String fileName, String path) { | |||||
| InputStream inputStream = null; | |||||
| Object object; | |||||
| try { | |||||
| ftp.enterLocalPassiveMode(); | |||||
| ftp.setFileType(2); | |||||
| boolean bl = existFile(ftp, path, fileName); | |||||
| if (bl) { | |||||
| inputStream = ftp.retrieveFileStream(path); | |||||
| ftp.logout(); | |||||
| return inputStream; | |||||
| } | |||||
| object = null; | |||||
| } catch (Exception e) { | |||||
| e.printStackTrace(); | |||||
| return inputStream; | |||||
| } finally { | |||||
| try { | |||||
| if (ftp.isConnected()) { | |||||
| ftp.disconnect(); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| e.printStackTrace(); | |||||
| } | |||||
| } | |||||
| return (InputStream) object; | |||||
| } | |||||
| public static void main(String[] args) throws Exception { | |||||
| String host = "10.10.18.92"; | |||||
| int port = 21; | |||||
| String username = "xg"; | |||||
| String password = "Xg@123456"; | |||||
| String fileName = "极1低,极1高,极2高,极2低巡检任务20240226150000.xls"; | |||||
| String path = "//极1低,极1高,极2高,极2低巡检任务20240226150000/"; | |||||
| InputStream str = login(host, port, username, password, fileName, path); | |||||
| System.out.println(str == null); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,39 @@ | |||||
| package com.inspect.base.core.text; | |||||
| import com.inspect.base.core.utils.StringUtils; | |||||
| import java.nio.charset.Charset; | |||||
| import java.nio.charset.StandardCharsets; | |||||
| public class CharsetKit { | |||||
| public static final String ISO_8859_1 = "ISO-8859-1"; | |||||
| public static final String UTF_8 = "UTF-8"; | |||||
| public static final String GBK = "GBK"; | |||||
| public static final Charset CHARSET_ISO_8859_1 = Charset.forName("ISO-8859-1"); | |||||
| public static final Charset CHARSET_UTF_8 = Charset.forName("UTF-8"); | |||||
| public static final Charset CHARSET_GBK = Charset.forName("GBK"); | |||||
| public static Charset charset(String charset) { | |||||
| return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset); | |||||
| } | |||||
| public static String convert(String source, String srcCharset, String destCharset) { | |||||
| return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset)); | |||||
| } | |||||
| public static String convert(String source, Charset srcCharset, Charset destCharset) { | |||||
| if (null == srcCharset) { | |||||
| srcCharset = StandardCharsets.ISO_8859_1; | |||||
| } | |||||
| if (null == destCharset) { | |||||
| destCharset = StandardCharsets.UTF_8; | |||||
| } | |||||
| return !StringUtils.isEmpty(source) && !srcCharset.equals(destCharset) ? new String(source.getBytes(srcCharset), destCharset) : source; | |||||
| } | |||||
| public static String systemCharset() { | |||||
| return Charset.defaultCharset().name(); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,491 @@ | |||||
| package com.inspect.base.core.text; | |||||
| import com.inspect.base.core.utils.StringUtils; | |||||
| import java.math.BigDecimal; | |||||
| import java.math.BigInteger; | |||||
| import java.nio.ByteBuffer; | |||||
| import java.nio.charset.Charset; | |||||
| import java.text.NumberFormat; | |||||
| import java.util.Set; | |||||
| public class Convert { | |||||
| public static String toStr(Object value, String defaultValue) { | |||||
| return null == value ? defaultValue : (value instanceof String ? (String) value : value.toString()); | |||||
| } | |||||
| public static String toStr(Object value) { | |||||
| return toStr(value, (String) null); | |||||
| } | |||||
| public static Character toChar(Object value, Character defaultValue) { | |||||
| if (null == value) { | |||||
| return defaultValue; | |||||
| } else if (value instanceof Character) { | |||||
| return (Character) value; | |||||
| } else { | |||||
| String valueStr = toStr(value, null); | |||||
| return StringUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0); | |||||
| } | |||||
| } | |||||
| public static Character toChar(Object value) { | |||||
| return toChar(value, null); | |||||
| } | |||||
| public static Byte toByte(Object value, Byte defaultValue) { | |||||
| if (value == null) { | |||||
| return defaultValue; | |||||
| } else if (value instanceof Byte) { | |||||
| return (Byte) value; | |||||
| } else if (value instanceof Number) { | |||||
| return ((Number) value).byteValue(); | |||||
| } else { | |||||
| String valueStr = toStr(value, null); | |||||
| if (StringUtils.isEmpty(valueStr)) { | |||||
| return defaultValue; | |||||
| } else { | |||||
| try { | |||||
| return Byte.parseByte(valueStr); | |||||
| } catch (Exception e) { | |||||
| return defaultValue; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| public static Byte toByte(Object value) { | |||||
| return toByte(value, null); | |||||
| } | |||||
| public static Short toShort(Object value, Short defaultValue) { | |||||
| if (value == null) { | |||||
| return defaultValue; | |||||
| } else if (value instanceof Short) { | |||||
| return (Short) value; | |||||
| } else if (value instanceof Number) { | |||||
| return ((Number) value).shortValue(); | |||||
| } else { | |||||
| String valueStr = toStr(value, null); | |||||
| if (StringUtils.isEmpty(valueStr)) { | |||||
| return defaultValue; | |||||
| } else { | |||||
| try { | |||||
| return Short.parseShort(valueStr.trim()); | |||||
| } catch (Exception e) { | |||||
| return defaultValue; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| public static Short toShort(Object value) { | |||||
| return toShort(value, null); | |||||
| } | |||||
| public static Number toNumber(Object value, Number defaultValue) { | |||||
| if (value == null) { | |||||
| return defaultValue; | |||||
| } else if (value instanceof Number) { | |||||
| return (Number) value; | |||||
| } else { | |||||
| String valueStr = toStr(value, null); | |||||
| if (StringUtils.isEmpty(valueStr)) { | |||||
| return defaultValue; | |||||
| } else { | |||||
| try { | |||||
| return NumberFormat.getInstance().parse(valueStr); | |||||
| } catch (Exception e) { | |||||
| return defaultValue; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| public static Number toNumber(Object value) { | |||||
| return toNumber(value, null); | |||||
| } | |||||
| public static Integer toInt(Object value, Integer defaultValue) { | |||||
| if (value == null) { | |||||
| return defaultValue; | |||||
| } else if (value instanceof Integer) { | |||||
| return (Integer) value; | |||||
| } else if (value instanceof Number) { | |||||
| return ((Number) value).intValue(); | |||||
| } else { | |||||
| String valueStr = toStr(value, null); | |||||
| if (StringUtils.isEmpty(valueStr)) { | |||||
| return defaultValue; | |||||
| } else { | |||||
| try { | |||||
| return Integer.parseInt(valueStr.trim()); | |||||
| } catch (Exception e) { | |||||
| return defaultValue; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| public static Integer toInt(Object value) { | |||||
| return toInt(value, null); | |||||
| } | |||||
| public static Integer[] toIntArray(String str) { | |||||
| return toIntArray(StringUtils.COMMA, str); | |||||
| } | |||||
| public static Long[] toLongArray(String str) { | |||||
| return toLongArray(StringUtils.COMMA, str); | |||||
| } | |||||
| public static Integer[] toIntArray(String split, String str) { | |||||
| if (StringUtils.isEmpty(str)) { | |||||
| return new Integer[0]; | |||||
| } else { | |||||
| String[] arr = str.split(split); | |||||
| Integer[] ints = new Integer[arr.length]; | |||||
| for (int i = 0; i < arr.length; ++i) { | |||||
| Integer v = toInt(arr[i], 0); | |||||
| ints[i] = v; | |||||
| } | |||||
| return ints; | |||||
| } | |||||
| } | |||||
| public static Long[] toLongArray(String split, String str) { | |||||
| if (StringUtils.isEmpty(str)) { | |||||
| return new Long[0]; | |||||
| } else { | |||||
| String[] arr = str.split(split); | |||||
| Long[] longs = new Long[arr.length]; | |||||
| for (int i = 0; i < arr.length; ++i) { | |||||
| Long v = toLong(arr[i], null); | |||||
| longs[i] = v; | |||||
| } | |||||
| return longs; | |||||
| } | |||||
| } | |||||
| public static String[] toStrArray(String str) { | |||||
| return toStrArray(StringUtils.COMMA, str); | |||||
| } | |||||
| public static String[] toStrArray(String split, String str) { | |||||
| return str.split(split); | |||||
| } | |||||
| public static Long toLong(Object value, Long defaultValue) { | |||||
| if (value == null) { | |||||
| return defaultValue; | |||||
| } else if (value instanceof Long) { | |||||
| return (Long) value; | |||||
| } else if (value instanceof Number) { | |||||
| return ((Number) value).longValue(); | |||||
| } else { | |||||
| String valueStr = toStr(value, null); | |||||
| if (StringUtils.isEmpty(valueStr)) { | |||||
| return defaultValue; | |||||
| } else { | |||||
| try { | |||||
| return (new BigDecimal(valueStr.trim())).longValue(); | |||||
| } catch (Exception e) { | |||||
| return defaultValue; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| public static Long toLong(Object value) { | |||||
| return toLong(value, null); | |||||
| } | |||||
| public static Double toDouble(Object value, Double defaultValue) { | |||||
| if (value == null) { | |||||
| return defaultValue; | |||||
| } else if (value instanceof Double) { | |||||
| return (Double) value; | |||||
| } else if (value instanceof Number) { | |||||
| return ((Number) value).doubleValue(); | |||||
| } else { | |||||
| String valueStr = toStr(value, null); | |||||
| if (StringUtils.isEmpty(valueStr)) { | |||||
| return defaultValue; | |||||
| } else { | |||||
| try { | |||||
| return (new BigDecimal(valueStr.trim())).doubleValue(); | |||||
| } catch (Exception e) { | |||||
| return defaultValue; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| public static Double toDouble(Object value) { | |||||
| return toDouble(value, null); | |||||
| } | |||||
| public static Float toFloat(Object value, Float defaultValue) { | |||||
| if (value == null) { | |||||
| return defaultValue; | |||||
| } else if (value instanceof Float) { | |||||
| return (Float) value; | |||||
| } else if (value instanceof Number) { | |||||
| return ((Number) value).floatValue(); | |||||
| } else { | |||||
| String valueStr = toStr(value, null); | |||||
| if (StringUtils.isEmpty(valueStr)) { | |||||
| return defaultValue; | |||||
| } else { | |||||
| try { | |||||
| return Float.parseFloat(valueStr.trim()); | |||||
| } catch (Exception e) { | |||||
| return defaultValue; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| public static Float toFloat(Object value) { | |||||
| return toFloat(value, null); | |||||
| } | |||||
| public static Boolean toBool(Object value, Boolean defaultValue) { | |||||
| if (value == null) { | |||||
| return defaultValue; | |||||
| } else if (value instanceof Boolean) { | |||||
| return (Boolean) value; | |||||
| } else { | |||||
| String valueStr = toStr(value, null); | |||||
| if (!StringUtils.isEmpty(valueStr)) { | |||||
| valueStr = valueStr.trim().toLowerCase(); | |||||
| switch (valueStr) { | |||||
| case "0": | |||||
| case "no": | |||||
| case "false": | |||||
| return Boolean.FALSE; | |||||
| case "1": | |||||
| case "ok": | |||||
| case "yes": | |||||
| case "true": | |||||
| return Boolean.TRUE; | |||||
| } | |||||
| } | |||||
| return defaultValue; | |||||
| } | |||||
| } | |||||
| public static Boolean toBool(Object value) { | |||||
| return toBool(value, (Boolean) null); | |||||
| } | |||||
| public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue) { | |||||
| if (value == null) { | |||||
| return defaultValue; | |||||
| } else if (clazz.isAssignableFrom(value.getClass())) { | |||||
| E myE = (E) value; | |||||
| return myE; | |||||
| } else { | |||||
| String valueStr = toStr(value, null); | |||||
| if (StringUtils.isEmpty(valueStr)) { | |||||
| return defaultValue; | |||||
| } else { | |||||
| try { | |||||
| return Enum.valueOf(clazz, valueStr); | |||||
| } catch (Exception exception) { | |||||
| return defaultValue; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value) { | |||||
| return toEnum(clazz, value, (E) null); | |||||
| } | |||||
| public static BigInteger toBigInteger(Object value, BigInteger defaultValue) { | |||||
| if (value == null) { | |||||
| return defaultValue; | |||||
| } else if (value instanceof BigInteger) { | |||||
| return (BigInteger) value; | |||||
| } else if (value instanceof Long) { | |||||
| return BigInteger.valueOf((Long) value); | |||||
| } else { | |||||
| String valueStr = toStr(value, null); | |||||
| if (StringUtils.isEmpty(valueStr)) { | |||||
| return defaultValue; | |||||
| } else { | |||||
| try { | |||||
| return new BigInteger(valueStr); | |||||
| } catch (Exception var4) { | |||||
| return defaultValue; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| public static BigInteger toBigInteger(Object value) { | |||||
| return toBigInteger(value, (BigInteger) null); | |||||
| } | |||||
| public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) { | |||||
| if (value == null) { | |||||
| return defaultValue; | |||||
| } else if (value instanceof BigDecimal) { | |||||
| return (BigDecimal) value; | |||||
| } else if (value instanceof Long) { | |||||
| return new BigDecimal((Long) value); | |||||
| } else if (value instanceof Double) { | |||||
| return new BigDecimal((Double) value); | |||||
| } else if (value instanceof Integer) { | |||||
| return new BigDecimal((Integer) value); | |||||
| } else { | |||||
| String valueStr = toStr(value, null); | |||||
| if (StringUtils.isEmpty(valueStr)) { | |||||
| return defaultValue; | |||||
| } else { | |||||
| try { | |||||
| return new BigDecimal(valueStr); | |||||
| } catch (Exception var4) { | |||||
| return defaultValue; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| public static BigDecimal toBigDecimal(Object value) { | |||||
| return toBigDecimal(value, null); | |||||
| } | |||||
| public static String utf8Str(Object obj) { | |||||
| return str(obj, CharsetKit.CHARSET_UTF_8); | |||||
| } | |||||
| public static String str(Object obj, String charsetName) { | |||||
| return str(obj, Charset.forName(charsetName)); | |||||
| } | |||||
| public static String str(Object obj, Charset charset) { | |||||
| if (null == obj) { | |||||
| return null; | |||||
| } else if (obj instanceof String) { | |||||
| return (String) obj; | |||||
| } else if (!(obj instanceof byte[]) && !(obj instanceof Byte[])) { | |||||
| return obj instanceof ByteBuffer ? str((ByteBuffer) obj, charset) : obj.toString(); | |||||
| } else if (obj instanceof byte[]) { | |||||
| String str = str((byte[]) obj, charset); | |||||
| return str; | |||||
| } else { | |||||
| Byte[] bytes = (Byte[]) obj; | |||||
| int length = bytes.length; | |||||
| byte[] dest = new byte[length]; | |||||
| for (int i = 0; i < length; ++i) { | |||||
| dest[i] = bytes[i]; | |||||
| } | |||||
| return str(dest, charset); | |||||
| } | |||||
| } | |||||
| public static String str(byte[] bytes, String charset) { | |||||
| return str(bytes, StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset)); | |||||
| } | |||||
| public static String str(byte[] data, Charset charset) { | |||||
| return data == null ? null : (null == charset ? new String(data) : new String(data, charset)); | |||||
| } | |||||
| public static String str(ByteBuffer data, String charset) { | |||||
| return data == null ? null : str(data, Charset.forName(charset)); | |||||
| } | |||||
| public static String str(ByteBuffer data, Charset charset) { | |||||
| if (null == charset) { | |||||
| charset = Charset.defaultCharset(); | |||||
| } | |||||
| return charset.decode(data).toString(); | |||||
| } | |||||
| public static String toSBC(String input) { | |||||
| return toSBC(input, null); | |||||
| } | |||||
| public static String toSBC(String input, Set<Character> notConvertSet) { | |||||
| char[] c = input.toCharArray(); | |||||
| for (int i = 0; i < c.length; ++i) { | |||||
| if (null == notConvertSet || !notConvertSet.contains(c[i])) { | |||||
| if (c[i] == 32) { | |||||
| c[i] = 12288; | |||||
| } else if (c[i] < 127) { | |||||
| c[i] += 'ﻠ'; | |||||
| } | |||||
| } | |||||
| } | |||||
| return new String(c); | |||||
| } | |||||
| public static String toDBC(String input) { | |||||
| return toDBC(input, null); | |||||
| } | |||||
| public static String toDBC(String text, Set<Character> notConvertSet) { | |||||
| char[] c = text.toCharArray(); | |||||
| for (int i = 0; i < c.length; ++i) { | |||||
| if (null == notConvertSet || !notConvertSet.contains(c[i])) { | |||||
| if (c[i] == 12288) { | |||||
| c[i] = 32; | |||||
| } else if (c[i] > '\uff00' && c[i] < '⦅') { | |||||
| c[i] -= 'ﻠ'; | |||||
| } | |||||
| } | |||||
| } | |||||
| String returnString = new String(c); | |||||
| return returnString; | |||||
| } | |||||
| public static String digitUppercase(double n) { | |||||
| String[] fraction = new String[]{"角", "分"}; | |||||
| String[] digit = new String[]{"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"}; | |||||
| String[][] unit = new String[][]{{"元", "万", "亿"}, {"", "拾", "佰", "仟"}}; | |||||
| String head = n < 0.0D ? "负" : ""; | |||||
| n = Math.abs(n); | |||||
| StringBuilder s = new StringBuilder(); | |||||
| int integerPart; | |||||
| for (integerPart = 0; integerPart < fraction.length; ++integerPart) { | |||||
| s.append((digit[(int) (Math.floor(n * 10.0D * Math.pow(10.0D, integerPart)) % 10.0D)] + fraction[integerPart]).replaceAll("(零.)+", "")); | |||||
| } | |||||
| if (s.length() == 0) { | |||||
| s = new StringBuilder("整"); | |||||
| } | |||||
| integerPart = (int) Math.floor(n); | |||||
| for (int i = 0; i < unit[0].length && integerPart > 0; ++i) { | |||||
| String p = ""; | |||||
| for (int j = 0; j < unit[1].length && n > 0.0D; ++j) { | |||||
| p = digit[integerPart % 10] + unit[1][j] + p; | |||||
| integerPart /= 10; | |||||
| } | |||||
| s.insert(0, p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i]); | |||||
| } | |||||
| return head + s.toString().replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "").replaceAll("(零.)+", "零").replaceAll("^整$", "零元整"); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,52 @@ | |||||
| package com.inspect.base.core.text; | |||||
| import com.inspect.base.core.utils.StringUtils; | |||||
| public class StrFormatter { | |||||
| public static final String EMPTY_JSON = "{}"; | |||||
| public static final char C_BACKSLASH = '\\'; | |||||
| public static final char C_DELIM_START = '{'; | |||||
| public static final char C_DELIM_END = '}'; | |||||
| public static String format(String strPattern, Object... argArray) { | |||||
| if (!StringUtils.isEmpty(strPattern) && !StringUtils.isEmpty(argArray)) { | |||||
| int strPatternLength = strPattern.length(); | |||||
| StringBuilder sbuf = new StringBuilder(strPatternLength + 50); | |||||
| int handledPosition = 0; | |||||
| for (int argIndex = 0; argIndex < argArray.length; ++argIndex) { | |||||
| int delimIndex = strPattern.indexOf("{}", handledPosition); | |||||
| if (delimIndex == -1) { | |||||
| if (handledPosition == 0) { | |||||
| return strPattern; | |||||
| } | |||||
| sbuf.append(strPattern, handledPosition, strPatternLength); | |||||
| return sbuf.toString(); | |||||
| } | |||||
| if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == 92) { | |||||
| if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == 92) { | |||||
| sbuf.append(strPattern, handledPosition, delimIndex - 1); | |||||
| sbuf.append(Convert.utf8Str(argArray[argIndex])); | |||||
| handledPosition = delimIndex + 2; | |||||
| } else { | |||||
| --argIndex; | |||||
| sbuf.append(strPattern, handledPosition, delimIndex - 1); | |||||
| sbuf.append('{'); | |||||
| handledPosition = delimIndex + 1; | |||||
| } | |||||
| } else { | |||||
| sbuf.append(strPattern, handledPosition, delimIndex); | |||||
| sbuf.append(Convert.utf8Str(argArray[argIndex])); | |||||
| handledPosition = delimIndex + 2; | |||||
| } | |||||
| } | |||||
| sbuf.append(strPattern, handledPosition, strPattern.length()); | |||||
| return sbuf.toString(); | |||||
| } else { | |||||
| return strPattern; | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,21 @@ | |||||
| package com.inspect.base.core.utils; | |||||
| import java.math.BigDecimal; | |||||
| public class BigDecimalUtil { | |||||
| public static double round(double f) { | |||||
| return round(f, 1); | |||||
| } | |||||
| public static double round(double f, int remain) { | |||||
| BigDecimal bigDecimal = new BigDecimal(f); | |||||
| bigDecimal.setScale(1, 4); | |||||
| float v = bigDecimal.floatValue(); | |||||
| String s = String.valueOf(v); | |||||
| if (s.contains(".") && s.substring(s.lastIndexOf(".") + 1).length() > remain) { | |||||
| s = s.substring(0, s.lastIndexOf(".") + remain + 1); | |||||
| } | |||||
| return Double.valueOf(s); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,78 @@ | |||||
| package com.inspect.base.core.utils; | |||||
| import java.nio.charset.Charset; | |||||
| public class ByteUtil { | |||||
| public static byte[] getBytes(short data) { | |||||
| byte[] bytes = new byte[]{(byte) (data & 255), (byte) ((data & '\uff00') >> 8)}; | |||||
| return bytes; | |||||
| } | |||||
| public static byte[] getBytes(char data) { | |||||
| byte[] bytes = new byte[]{(byte) data, (byte) (data >> 8)}; | |||||
| return bytes; | |||||
| } | |||||
| public static byte[] getBytes(int data) { | |||||
| byte[] bytes = new byte[]{(byte) (data & 255), (byte) ((data & '\uff00') >> 8), (byte) ((data & 16711680) >> 16), (byte) ((data & -16777216) >> 24)}; | |||||
| return bytes; | |||||
| } | |||||
| public static byte[] getBytes(long data) { | |||||
| byte[] bytes = new byte[]{(byte) ((int) (data & 255L)), (byte) ((int) (data >> 8 & 255L)), (byte) ((int) (data >> 16 & 255L)), (byte) ((int) (data >> 24 & 255L)), (byte) ((int) (data >> 32 & 255L)), (byte) ((int) (data >> 40 & 255L)), (byte) ((int) (data >> 48 & 255L)), (byte) ((int) (data >> 56 & 255L))}; | |||||
| return bytes; | |||||
| } | |||||
| public static byte[] getBytes(float data) { | |||||
| int intBits = Float.floatToIntBits(data); | |||||
| return getBytes(intBits); | |||||
| } | |||||
| public static byte[] getBytes(double data) { | |||||
| long intBits = Double.doubleToLongBits(data); | |||||
| return getBytes(intBits); | |||||
| } | |||||
| public static byte[] getBytes(String data, String charsetName) { | |||||
| Charset charset = Charset.forName(charsetName); | |||||
| return data.getBytes(charset); | |||||
| } | |||||
| public static byte[] getBytes(String data) { | |||||
| return getBytes(data, "GBK"); | |||||
| } | |||||
| public static short getShort(byte[] bytes) { | |||||
| return (short) (255 & bytes[0] | '\uff00' & bytes[1] << 8); | |||||
| } | |||||
| public static char getChar(byte[] bytes) { | |||||
| return (char) (255 & bytes[0] | '\uff00' & bytes[1] << 8); | |||||
| } | |||||
| public static int getInt(byte[] bytes) { | |||||
| return 255 & bytes[0] | '\uff00' & bytes[1] << 8 | 16711680 & bytes[2] << 16 | -16777216 & bytes[3] << 24; | |||||
| } | |||||
| public static long getLong(byte[] bytes) { | |||||
| return 255L & (long) bytes[0] | 65280L & (long) bytes[1] << 8 | 16711680L & (long) bytes[2] << 16 | 4278190080L & (long) bytes[3] << 24 | 1095216660480L & (long) bytes[4] << 32 | 280375465082880L & (long) bytes[5] << 40 | 71776119061217280L & (long) bytes[6] << 48 | -72057594037927936L & (long) bytes[7] << 56; | |||||
| } | |||||
| public static float getFloat(byte[] bytes) { | |||||
| return Float.intBitsToFloat(getInt(bytes)); | |||||
| } | |||||
| public static double getDouble(byte[] bytes) { | |||||
| long l = getLong(bytes); | |||||
| System.out.println(l); | |||||
| return Double.longBitsToDouble(l); | |||||
| } | |||||
| public static String getString(byte[] bytes, String charsetName) { | |||||
| return new String(bytes, Charset.forName(charsetName)); | |||||
| } | |||||
| public static String getString(byte[] bytes) { | |||||
| return getString(bytes, "GBK"); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,14 @@ | |||||
| package com.inspect.base.core.utils; | |||||
| import java.util.Calendar; | |||||
| import java.util.Date; | |||||
| public class CalendarUtil { | |||||
| public static boolean expire(Date date, int second) { | |||||
| Calendar now = Calendar.getInstance(); | |||||
| Calendar before = Calendar.getInstance(); | |||||
| before.setTime(date); | |||||
| before.add(Calendar.SECOND, second); | |||||
| return now.after(before); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,265 @@ | |||||
| package com.inspect.base.core.utils; | |||||
| import java.lang.management.ManagementFactory; | |||||
| import java.text.ParseException; | |||||
| import java.text.SimpleDateFormat; | |||||
| import java.time.LocalDate; | |||||
| import java.time.LocalDateTime; | |||||
| import java.time.LocalTime; | |||||
| import java.time.ZoneId; | |||||
| import java.time.ZonedDateTime; | |||||
| import java.util.Calendar; | |||||
| import java.util.Date; | |||||
| import org.apache.commons.lang3.time.DateFormatUtils; | |||||
| public class DateUtils extends org.apache.commons.lang3.time.DateUtils { | |||||
| public static String yyyy = "yyyy"; | |||||
| public static String yyyy_MM = "yyyy-MM"; | |||||
| public static String YYYY_MM_DD = "yyyy-MM-dd"; | |||||
| public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; | |||||
| public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; | |||||
| public static String HHmmss = "HHmmss"; | |||||
| public static final String yyyyMMdd = "yyyyMMdd"; | |||||
| public static final String yyyyMMdd2 = "yyyy-MM-dd"; | |||||
| public static final String yyyyMMddHHmmss = "yyyyMMddHHmmss"; | |||||
| public static final String yyyyMMddHHmmss2 = "yyyy-MM-dd HH:mm:ss"; | |||||
| private static String[] parsePatterns = new String[]{"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"}; | |||||
| public static Date getNowDate() { | |||||
| return new Date(); | |||||
| } | |||||
| public static String getDate() { | |||||
| return dateTimeNow(YYYY_MM_DD); | |||||
| } | |||||
| public static final String getTime() { | |||||
| return dateTimeNow(YYYY_MM_DD_HH_MM_SS); | |||||
| } | |||||
| public static final String dateTimeNow() { | |||||
| return dateTimeNow(YYYYMMDDHHMMSS); | |||||
| } | |||||
| public static final String dateTimeNow(String format) { | |||||
| return parseDateToStr(format, new Date()); | |||||
| } | |||||
| public static final String dateTime(Date date) { | |||||
| return parseDateToStr(YYYY_MM_DD, date); | |||||
| } | |||||
| public static final String parseDateToStr(String format, Date date) { | |||||
| return (new SimpleDateFormat(format)).format(date); | |||||
| } | |||||
| public static final Date dateTime(String format, String ts) { | |||||
| try { | |||||
| return (new SimpleDateFormat(format)).parse(ts); | |||||
| } catch (ParseException var3) { | |||||
| throw new RuntimeException(var3); | |||||
| } | |||||
| } | |||||
| public static final String datePath() { | |||||
| Date now = new Date(); | |||||
| return DateFormatUtils.format(now, "yyyy/MM/dd"); | |||||
| } | |||||
| public static final String dateTime() { | |||||
| Date now = new Date(); | |||||
| return DateFormatUtils.format(now, "yyyyMMdd"); | |||||
| } | |||||
| public static Date parseDate(Object str) { | |||||
| if (str == null) { | |||||
| return null; | |||||
| } else { | |||||
| try { | |||||
| return parseDate(str.toString(), parsePatterns); | |||||
| } catch (ParseException var2) { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| } | |||||
| public static Date getServerStartDate() { | |||||
| long time = ManagementFactory.getRuntimeMXBean().getStartTime(); | |||||
| return new Date(time); | |||||
| } | |||||
| public static String getDatePoor(Date endDate, Date nowDate) { | |||||
| long nd = 86400000L; | |||||
| long nh = 3600000L; | |||||
| long nm = 60000L; | |||||
| long diff = endDate.getTime() - nowDate.getTime(); | |||||
| long day = diff / nd; | |||||
| long hour = diff % nd / nh; | |||||
| long min = diff % nd % nh / nm; | |||||
| return day + "天" + hour + "小时" + min + "分钟"; | |||||
| } | |||||
| public static Date toDate(LocalDateTime temporalAccessor) { | |||||
| ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault()); | |||||
| return Date.from(zdt.toInstant()); | |||||
| } | |||||
| public static Date toDate(LocalDate temporalAccessor) { | |||||
| LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0)); | |||||
| ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault()); | |||||
| return Date.from(zdt.toInstant()); | |||||
| } | |||||
| public static Date theDayStartTime(Date date) { | |||||
| Calendar calendar = Calendar.getInstance(); | |||||
| calendar.setTime(date); | |||||
| calendar.set(11, 0); | |||||
| calendar.set(12, 0); | |||||
| calendar.set(13, 0); | |||||
| calendar.set(14, 0); | |||||
| Date date_start = calendar.getTime(); | |||||
| return date_start; | |||||
| } | |||||
| public static Date theDayBeforeStartTime(Date date) { | |||||
| Calendar calendar = Calendar.getInstance(); | |||||
| calendar.setTime(date); | |||||
| calendar.set(11, 0); | |||||
| calendar.set(12, 0); | |||||
| calendar.set(13, 0); | |||||
| calendar.set(14, 0); | |||||
| calendar.add(5, -1); | |||||
| Date date_start = calendar.getTime(); | |||||
| return date_start; | |||||
| } | |||||
| public static Date theDayBeforeEndTime(Date date) { | |||||
| Calendar calendar_end = Calendar.getInstance(); | |||||
| calendar_end.setTime(date); | |||||
| calendar_end.set(11, 23); | |||||
| calendar_end.set(12, 59); | |||||
| calendar_end.set(13, 59); | |||||
| calendar_end.set(14, 999); | |||||
| calendar_end.add(5, -1); | |||||
| Date date_end = calendar_end.getTime(); | |||||
| return date_end; | |||||
| } | |||||
| public static Date theDayTimeByAddHour(Date date, int hour) { | |||||
| Calendar calendar = Calendar.getInstance(); | |||||
| calendar.setTime(date); | |||||
| calendar.set(11, hour); | |||||
| calendar.set(12, 0); | |||||
| calendar.set(13, 0); | |||||
| calendar.set(14, 0); | |||||
| calendar.add(5, 0); | |||||
| Date date_time = calendar.getTime(); | |||||
| return date_time; | |||||
| } | |||||
| public static String format(final String pattern, final Date date) { | |||||
| try { | |||||
| return new SimpleDateFormat(pattern).format(date); | |||||
| } catch (Exception e) { | |||||
| return ""; | |||||
| } | |||||
| } | |||||
| public static int toInt(final String pattern, final Date date) { | |||||
| try { | |||||
| return Integer.parseInt(format(pattern, date)); | |||||
| } catch (Exception e) { | |||||
| return 0; | |||||
| } | |||||
| } | |||||
| public static Date parse(final String pattern, final String time) { | |||||
| try { | |||||
| return new SimpleDateFormat(pattern).parse(time); | |||||
| } catch (Exception e) { | |||||
| return new Date(0); | |||||
| } | |||||
| } | |||||
| public static int getYearInt() { | |||||
| return Calendar.getInstance().get(Calendar.YEAR); | |||||
| } | |||||
| public static int getMonthInt() { | |||||
| return Calendar.getInstance().get(Calendar.MONTH); | |||||
| } | |||||
| public static int getDayInt() { | |||||
| return Calendar.getInstance().get(Calendar.DATE); | |||||
| } | |||||
| public static int getHourInt() { | |||||
| return Calendar.getInstance().get(Calendar.HOUR_OF_DAY); | |||||
| } | |||||
| public static int getMinuteInt() { | |||||
| return Calendar.getInstance().get(Calendar.MINUTE); | |||||
| } | |||||
| public static String getDayEven() { | |||||
| int day = Calendar.getInstance().get(5); | |||||
| String dayStr = "" + day; | |||||
| if (day < 10) { | |||||
| dayStr = "0" + dayStr; | |||||
| } | |||||
| return dayStr; | |||||
| } | |||||
| public static String getMonthEven() { | |||||
| int month = Calendar.getInstance().get(2) + 1; | |||||
| String res = "" + month; | |||||
| if (month < 10) { | |||||
| res = "0" + res; | |||||
| } | |||||
| return res; | |||||
| } | |||||
| public static String getYearEven() { | |||||
| return "" + Calendar.getInstance().get(Calendar.YEAR); | |||||
| } | |||||
| public static String getDayOfWeek(Date date) { | |||||
| String[] weekDays = new String[]{"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; | |||||
| Calendar cal = Calendar.getInstance(); | |||||
| cal.setTime(date); | |||||
| int w = cal.get(Calendar.DAY_OF_WEEK) - 1; | |||||
| if (w < 0) { | |||||
| w = 0; | |||||
| } | |||||
| return weekDays[w]; | |||||
| } | |||||
| public static void main(String[] args) { | |||||
| theDayBeforeStartTime(new Date()); | |||||
| theDayBeforeEndTime(new Date()); | |||||
| theDayStartTime(new Date()); | |||||
| Date now = new Date(); | |||||
| System.out.println(now); | |||||
| theDayTimeByAddHour(getNowDate(), 24); | |||||
| int interval = 24; | |||||
| Date dayBeforeStartTime = theDayBeforeStartTime(new Date()); | |||||
| int hour; | |||||
| for (int i = 0; i < interval; ++i) { | |||||
| hour = i * 1 + 1; | |||||
| Date startTime = theDayTimeByAddHour(dayBeforeStartTime, i * 1); | |||||
| System.out.println("startTime::" + startTime); | |||||
| Date endTime = theDayTimeByAddHour(dayBeforeStartTime, hour); | |||||
| System.out.println(" endTime::" + endTime); | |||||
| } | |||||
| Calendar now1 = Calendar.getInstance(); | |||||
| hour = now1.get(11); | |||||
| Double a = Double.valueOf((double) (hour / 1)); | |||||
| int b = a.intValue(); | |||||
| System.out.println("时: " + now1.get(11)); | |||||
| System.out.println("时: " + b); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,23 @@ | |||||
| package com.inspect.base.core.utils; | |||||
| import com.inspect.base.core.enums.TaskStatus; | |||||
| public class DescUtil { | |||||
| public static String getTaskStatusDesc(String code) { | |||||
| String info = "UNKNOWN"; | |||||
| if (TaskStatus.DONE.getCode().equals(code)) { | |||||
| info = TaskStatus.DONE.getInfo(); | |||||
| } else if (TaskStatus.RUNNING.getCode().equals(code)) { | |||||
| info = TaskStatus.RUNNING.getInfo(); | |||||
| } else if (TaskStatus.PAUSED.getCode().equals(code)) { | |||||
| info = TaskStatus.PAUSED.getInfo(); | |||||
| } else if (TaskStatus.HALTED.getCode().equals(code)) { | |||||
| info = TaskStatus.HALTED.getInfo(); | |||||
| } else if (TaskStatus.PENDING.getCode().equals(code)) { | |||||
| info = TaskStatus.PENDING.getInfo(); | |||||
| } else if (TaskStatus.EXPIRED.getCode().equals(code)) { | |||||
| info = TaskStatus.EXPIRED.getInfo(); | |||||
| } | |||||
| return info; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,25 @@ | |||||
| package com.inspect.base.core.utils; | |||||
| import java.io.PrintWriter; | |||||
| import java.io.StringWriter; | |||||
| import org.apache.commons.lang3.exception.ExceptionUtils; | |||||
| public class ExceptionUtil { | |||||
| public static String getExceptionMessage(Throwable e) { | |||||
| StringWriter sw = new StringWriter(); | |||||
| e.printStackTrace(new PrintWriter(sw, true)); | |||||
| return sw.toString(); | |||||
| } | |||||
| public static String getRootErrorMessage(Exception e) { | |||||
| Throwable root = ExceptionUtils.getRootCause(e); | |||||
| root = root == null ? e : root; | |||||
| if (root == null) { | |||||
| return ""; | |||||
| } else { | |||||
| String msg = ((Throwable) root).getMessage(); | |||||
| return msg == null ? "null" : StringUtils.defaultString(msg); | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,130 @@ | |||||
| package com.inspect.base.core.utils; | |||||
| import java.math.BigInteger; | |||||
| import java.nio.charset.Charset; | |||||
| import org.apache.commons.codec.DecoderException; | |||||
| import org.apache.commons.codec.binary.Hex; | |||||
| public class HexUtils { | |||||
| public static byte[] hexToByteArray(String inHex) { | |||||
| int hexlen = inHex.length(); | |||||
| byte[] result; | |||||
| if (hexlen % 2 == 1) { | |||||
| ++hexlen; | |||||
| result = new byte[hexlen / 2]; | |||||
| inHex = "0" + inHex; | |||||
| } else { | |||||
| result = new byte[hexlen / 2]; | |||||
| } | |||||
| int j = 0; | |||||
| for (int i = 0; i < hexlen; i += 2) { | |||||
| result[j] = hexToByte(inHex.substring(i, i + 2)); | |||||
| ++j; | |||||
| } | |||||
| return result; | |||||
| } | |||||
| public static byte hexToByte(String inHex) { | |||||
| return (byte) Integer.parseInt(inHex, 16); | |||||
| } | |||||
| public static String convertStringToHex(String str) { | |||||
| return convertStringToHex(str, "UTF8"); | |||||
| } | |||||
| public static String convertStringToHex(String str, String charsetName) { | |||||
| char[] chars = Hex.encodeHex(str.getBytes(Charset.forName(charsetName))); | |||||
| return String.valueOf(chars); | |||||
| } | |||||
| public static String convertHexToString(String hex, String charsetName) { | |||||
| String result = ""; | |||||
| try { | |||||
| byte[] bytes = Hex.decodeHex(hex); | |||||
| result = new String(bytes, Charset.forName(charsetName)); | |||||
| return result; | |||||
| } catch (DecoderException var4) { | |||||
| throw new IllegalArgumentException("Invalid Hex format!"); | |||||
| } | |||||
| } | |||||
| public static String convertHexToString(String hex) { | |||||
| return convertHexToString(hex, "UTF8"); | |||||
| } | |||||
| public static byte[] int2bytes(int num) { | |||||
| return new byte[]{(byte) (num >> 24 & 255), (byte) (num >> 16 & 255), (byte) (num >> 8 & 255), (byte) (num & 255)}; | |||||
| } | |||||
| public static byte[] long2Bytes(long num) { | |||||
| byte[] byteNum = new byte[8]; | |||||
| for (int ix = 0; ix < 8; ++ix) { | |||||
| int offset = 64 - (ix + 1) * 8; | |||||
| byteNum[ix] = (byte) ((int) (num >> offset & 255L)); | |||||
| } | |||||
| return byteNum; | |||||
| } | |||||
| public static String binary(byte[] bytes, int radix) { | |||||
| String str = (new BigInteger(1, bytes)).toString(radix); | |||||
| return str; | |||||
| } | |||||
| public static byte[] toByteArrayLittle(String hexString) { | |||||
| System.out.println("=============toByteArrayLittle:" + hexString); | |||||
| if (StringUtils.isEmpty(hexString)) { | |||||
| throw new IllegalArgumentException("this hexString must not be empty"); | |||||
| } else { | |||||
| hexString = hexString.toLowerCase(); | |||||
| byte[] byteArray = new byte[hexString.length() / 2]; | |||||
| int k = 0; | |||||
| for (int i = 0; i < byteArray.length; ++i) { | |||||
| byte high = (byte) (Character.digit(hexString.charAt(k), 16) & 255); | |||||
| byte low = (byte) (Character.digit(hexString.charAt(k + 1), 16) & 255); | |||||
| byteArray[i] = (byte) (low >> 4 | high); | |||||
| k += 2; | |||||
| } | |||||
| return byteArray; | |||||
| } | |||||
| } | |||||
| public static byte[] toByteArray(String hexString) { | |||||
| if (StringUtils.isEmpty(hexString)) { | |||||
| throw new IllegalArgumentException("this hexString must not be empty"); | |||||
| } else { | |||||
| hexString = hexString.toLowerCase(); | |||||
| byte[] byteArray = new byte[hexString.length() / 2]; | |||||
| int k = 0; | |||||
| for (int i = 0; i < byteArray.length; ++i) { | |||||
| byte high = (byte) (Character.digit(hexString.charAt(k), 16) & 255); | |||||
| byte low = (byte) (Character.digit(hexString.charAt(k + 1), 16) & 255); | |||||
| byteArray[i] = (byte) (high >> 4 | low); | |||||
| k += 2; | |||||
| } | |||||
| return byteArray; | |||||
| } | |||||
| } | |||||
| public static String numToHex8(int b) { | |||||
| return String.format("%02x", new Object[]{Integer.valueOf(b)}); | |||||
| } | |||||
| public static String numToHex16(int b) { | |||||
| return String.format("%04x", new Object[]{Integer.valueOf(b)}); | |||||
| } | |||||
| public static String numToHex32(int b) { | |||||
| return String.format("%08x", new Object[]{Integer.valueOf(b)}); | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,241 @@ | |||||
| package com.inspect.base.core.utils; | |||||
| import java.io.BufferedReader; | |||||
| import java.io.IOException; | |||||
| import java.io.InputStream; | |||||
| import java.io.InputStreamReader; | |||||
| import java.io.OutputStreamWriter; | |||||
| import java.io.PrintWriter; | |||||
| import java.net.HttpURLConnection; | |||||
| import java.net.URL; | |||||
| import java.net.URLConnection; | |||||
| public class HttpClientUtils { | |||||
| public static String post(String requestUrl) { | |||||
| return post(requestUrl, "", ""); | |||||
| } | |||||
| public static String post(String requestUrl, String requestPram) { | |||||
| return post(requestUrl, requestPram, ""); | |||||
| } | |||||
| public static String post(String requestUrl, String requestPram, String accessToken) { | |||||
| OutputStreamWriter outputStreamWriter = null; | |||||
| BufferedReader bufferedReader = null; | |||||
| StringBuffer responseResult = new StringBuffer(); | |||||
| HttpURLConnection httpURLConnection = null; | |||||
| try { | |||||
| URL realUrl = new URL(requestUrl); | |||||
| httpURLConnection = (HttpURLConnection) realUrl.openConnection(); | |||||
| httpURLConnection.setRequestProperty("accept", "*/*"); | |||||
| httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); | |||||
| httpURLConnection.setRequestProperty("connection", "Keep-Alive"); | |||||
| if (!accessToken.equals("") || accessToken != null) { | |||||
| httpURLConnection.setRequestProperty("access-token", accessToken); | |||||
| } | |||||
| httpURLConnection.setRequestProperty("Content-Length", String.valueOf(requestPram.length())); | |||||
| httpURLConnection.setDoOutput(true); | |||||
| httpURLConnection.setDoInput(true); | |||||
| outputStreamWriter = new OutputStreamWriter(httpURLConnection.getOutputStream(), "utf-8"); | |||||
| outputStreamWriter.write(requestPram); | |||||
| outputStreamWriter.flush(); | |||||
| bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream(), "utf-8")); | |||||
| String line; | |||||
| while ((line = bufferedReader.readLine()) != null) { | |||||
| responseResult.append(line); | |||||
| } | |||||
| } catch (Exception var17) { | |||||
| var17.printStackTrace(); | |||||
| } finally { | |||||
| httpURLConnection.disconnect(); | |||||
| try { | |||||
| if (outputStreamWriter != null) { | |||||
| outputStreamWriter.close(); | |||||
| } | |||||
| if (bufferedReader != null) { | |||||
| bufferedReader.close(); | |||||
| } | |||||
| } catch (IOException var16) { | |||||
| var16.printStackTrace(); | |||||
| } | |||||
| } | |||||
| return responseResult.toString(); | |||||
| } | |||||
| public static InputStream getStream(String url, String param) throws Exception { | |||||
| param = param.replace("#", "%23"); | |||||
| URLConnection connection = getConnection(url, param); | |||||
| return connection.getInputStream(); | |||||
| } | |||||
| public static URLConnection getConnection(String url, String param) throws Exception { | |||||
| String urlNameString = url + "?" + param; | |||||
| URL realUrl = new URL(urlNameString); | |||||
| URLConnection connection = realUrl.openConnection(); | |||||
| connection.setRequestProperty("accept", "*/*"); | |||||
| connection.setRequestProperty("connection", "Keep-Alive"); | |||||
| connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); | |||||
| connection.connect(); | |||||
| return connection; | |||||
| } | |||||
| public static HttpURLConnection getConnection2(String url, String param) throws Exception { | |||||
| String urlNameString = url + "?" + param; | |||||
| URL realUrl = new URL(urlNameString); | |||||
| HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection(); | |||||
| connection.setRequestProperty("accept", "*/*"); | |||||
| connection.setRequestProperty("connection", "Keep-Alive"); | |||||
| connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); | |||||
| connection.connect(); | |||||
| return connection; | |||||
| } | |||||
| public static String get(String url, String param) throws Exception { | |||||
| StringBuilder result = new StringBuilder(); | |||||
| BufferedReader in = null; | |||||
| try { | |||||
| param = param.replace(" ", "%20"); | |||||
| param = param.replace("#", "%23"); | |||||
| URL realUrl = new URL(url + "?" + param); | |||||
| URLConnection connection = realUrl.openConnection(); | |||||
| connection.setRequestProperty("accept", "*/*"); | |||||
| connection.setRequestProperty("connection", "Keep-Alive"); | |||||
| connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); | |||||
| connection.connect(); | |||||
| in = new BufferedReader(new InputStreamReader(connection.getInputStream())); | |||||
| String line; | |||||
| while ((line = in.readLine()) != null) { | |||||
| result.append(line); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| e.printStackTrace(); | |||||
| } finally { | |||||
| if (null != in) { | |||||
| in.close(); | |||||
| } | |||||
| } | |||||
| return result.toString(); | |||||
| } | |||||
| public static String postJson(String requestUrl, String requestPram, String tokenKey, String accessToken) { | |||||
| OutputStreamWriter outputStreamWriter = null; | |||||
| BufferedReader bufferedReader = null; | |||||
| StringBuffer responseResult = new StringBuffer(); | |||||
| HttpURLConnection httpURLConnection = null; | |||||
| try { | |||||
| URL realUrl = new URL(requestUrl); | |||||
| httpURLConnection = (HttpURLConnection) realUrl.openConnection(); | |||||
| httpURLConnection.setRequestProperty("accept", "*/*"); | |||||
| httpURLConnection.setRequestProperty("Content-Type", "application/json"); | |||||
| httpURLConnection.setRequestProperty("connection", "Keep-Alive"); | |||||
| if (StringUtils.isNotBlank(accessToken)) { | |||||
| if (StringUtils.isNotBlank(tokenKey)) { | |||||
| httpURLConnection.setRequestProperty(tokenKey, accessToken); | |||||
| } else { | |||||
| httpURLConnection.setRequestProperty("access-token", accessToken); | |||||
| } | |||||
| } | |||||
| httpURLConnection.setRequestProperty("Content-Length", String.valueOf(requestPram.length())); | |||||
| httpURLConnection.setDoOutput(true); | |||||
| httpURLConnection.setDoInput(true); | |||||
| outputStreamWriter = new OutputStreamWriter(httpURLConnection.getOutputStream(), "utf-8"); | |||||
| outputStreamWriter.write(requestPram); | |||||
| outputStreamWriter.flush(); | |||||
| bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream(), "utf-8")); | |||||
| String line; | |||||
| while ((line = bufferedReader.readLine()) != null) { | |||||
| responseResult.append(line); | |||||
| } | |||||
| } catch (Exception var18) { | |||||
| var18.printStackTrace(); | |||||
| } finally { | |||||
| httpURLConnection.disconnect(); | |||||
| try { | |||||
| if (outputStreamWriter != null) { | |||||
| outputStreamWriter.close(); | |||||
| } | |||||
| if (bufferedReader != null) { | |||||
| bufferedReader.close(); | |||||
| } | |||||
| } catch (IOException var17) { | |||||
| var17.printStackTrace(); | |||||
| } | |||||
| } | |||||
| return responseResult.toString(); | |||||
| } | |||||
| public static String postJson(String requestUrl, String requestPram, String accessToken) { | |||||
| return postJson(requestUrl, requestPram, "", accessToken); | |||||
| } | |||||
| public static String sendPostAgain(String url, String param) { | |||||
| PrintWriter out = null; | |||||
| BufferedReader in = null; | |||||
| StringBuilder result = new StringBuilder(); | |||||
| URLConnection conn = null; | |||||
| try { | |||||
| URL realUrl = new URL(url); | |||||
| conn = realUrl.openConnection(); | |||||
| conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); | |||||
| conn.setConnectTimeout(30000); | |||||
| conn.setReadTimeout(120000); | |||||
| conn.setDoOutput(true); | |||||
| conn.setDoInput(true); | |||||
| out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8")); | |||||
| out.print(param); | |||||
| out.flush(); | |||||
| InputStream stream = conn.getInputStream(); | |||||
| in = new BufferedReader(new InputStreamReader(stream, "UTF-8")); | |||||
| String line; | |||||
| while ((line = in.readLine()) != null) { | |||||
| result.append(line); | |||||
| } | |||||
| } catch (Exception var19) { | |||||
| var19.printStackTrace(); | |||||
| try { | |||||
| in = new BufferedReader(new InputStreamReader(((HttpURLConnection) conn).getErrorStream(), "UTF-8")); | |||||
| String line; | |||||
| while ((line = in.readLine()) != null) { | |||||
| result.append(line); | |||||
| } | |||||
| } catch (IOException var18) { | |||||
| var18.printStackTrace(); | |||||
| } | |||||
| } finally { | |||||
| try { | |||||
| if (out != null) { | |||||
| out.close(); | |||||
| } | |||||
| if (in != null) { | |||||
| in.close(); | |||||
| } | |||||
| } catch (IOException var17) { | |||||
| var17.printStackTrace(); | |||||
| } | |||||
| } | |||||
| return result.toString(); | |||||
| } | |||||
| } | |||||