正在显示
21 个修改的文件
包含
467 行增加
和
185 行删除
| 1 | -package com.ruoyi.framework.config; | 1 | +package com.zhonglai.luhui.datasource.config; |
| 2 | 2 | ||
| 3 | //import org.mybatis.spring.annotation.MapperScan; | 3 | //import org.mybatis.spring.annotation.MapperScan; |
| 4 | import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; | 4 | import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; |
| @@ -21,13 +21,5 @@ import java.util.TimeZone; | @@ -21,13 +21,5 @@ import java.util.TimeZone; | ||
| 21 | //@tk.mybatis.spring.annotation.MapperScan(basePackages={"com.ruoyi.system.tk"}) | 21 | //@tk.mybatis.spring.annotation.MapperScan(basePackages={"com.ruoyi.system.tk"}) |
| 22 | public class ApplicationConfig | 22 | public class ApplicationConfig |
| 23 | { | 23 | { |
| 24 | - /** | ||
| 25 | - * 时区配置 | ||
| 26 | - */ | ||
| 27 | - @Bean | ||
| 28 | - public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() | ||
| 29 | - { | ||
| 30 | - return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault()); | ||
| 31 | - } | ||
| 32 | 24 | ||
| 33 | } | 25 | } |
| @@ -2,6 +2,7 @@ package com.ruoyi.framework.config; | @@ -2,6 +2,7 @@ package com.ruoyi.framework.config; | ||
| 2 | 2 | ||
| 3 | import com.ruoyi.common.config.RuoYiConfig; | 3 | import com.ruoyi.common.config.RuoYiConfig; |
| 4 | import com.ruoyi.common.constant.Constants; | 4 | import com.ruoyi.common.constant.Constants; |
| 5 | +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; | ||
| 5 | import org.springframework.context.annotation.Bean; | 6 | import org.springframework.context.annotation.Bean; |
| 6 | import org.springframework.context.annotation.Configuration; | 7 | import org.springframework.context.annotation.Configuration; |
| 7 | import org.springframework.web.cors.CorsConfiguration; | 8 | import org.springframework.web.cors.CorsConfiguration; |
| @@ -10,6 +11,8 @@ import org.springframework.web.filter.CorsFilter; | @@ -10,6 +11,8 @@ import org.springframework.web.filter.CorsFilter; | ||
| 10 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | 11 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
| 11 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | 12 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| 12 | 13 | ||
| 14 | +import java.util.TimeZone; | ||
| 15 | + | ||
| 13 | /** | 16 | /** |
| 14 | * 通用配置 | 17 | * 通用配置 |
| 15 | * | 18 | * |
| @@ -70,4 +73,13 @@ public class ResourcesConfig implements WebMvcConfigurer | @@ -70,4 +73,13 @@ public class ResourcesConfig implements WebMvcConfigurer | ||
| 70 | source.registerCorsConfiguration("/**", buildConfig()); // 4 | 73 | source.registerCorsConfiguration("/**", buildConfig()); // 4 |
| 71 | return new CorsFilter(source); | 74 | return new CorsFilter(source); |
| 72 | } | 75 | } |
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * 时区配置 | ||
| 79 | + */ | ||
| 80 | + @Bean | ||
| 81 | + public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() | ||
| 82 | + { | ||
| 83 | + return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault()); | ||
| 84 | + } | ||
| 73 | } | 85 | } |
| @@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
| 9 | <version>1.0-SNAPSHOT</version> | 9 | <version>1.0-SNAPSHOT</version> |
| 10 | </parent> | 10 | </parent> |
| 11 | 11 | ||
| 12 | - <artifactId>lh-smart-feeder-pureness</artifactId> | 12 | + <artifactId>lh-data-file-service</artifactId> |
| 13 | 13 | ||
| 14 | <properties> | 14 | <properties> |
| 15 | <maven.compiler.source>8</maven.compiler.source> | 15 | <maven.compiler.source>8</maven.compiler.source> |
| @@ -18,24 +18,26 @@ | @@ -18,24 +18,26 @@ | ||
| 18 | </properties> | 18 | </properties> |
| 19 | 19 | ||
| 20 | <dependencies> | 20 | <dependencies> |
| 21 | - <!-- mqtt --> | ||
| 22 | - <dependency> | ||
| 23 | - <groupId>org.eclipse.paho</groupId> | ||
| 24 | - <artifactId>org.eclipse.paho.client.mqttv3</artifactId> | ||
| 25 | - </dependency> | ||
| 26 | <dependency> | 21 | <dependency> |
| 27 | <groupId>cn.hutool</groupId> | 22 | <groupId>cn.hutool</groupId> |
| 28 | <artifactId>hutool-all</artifactId> | 23 | <artifactId>hutool-all</artifactId> |
| 29 | </dependency> | 24 | </dependency> |
| 30 | 25 | ||
| 26 | + <!-- Mysql驱动包 --> | ||
| 27 | + <dependency> | ||
| 28 | + <groupId>mysql</groupId> | ||
| 29 | + <artifactId>mysql-connector-java</artifactId> | ||
| 30 | + </dependency> | ||
| 31 | + | ||
| 32 | + <!-- 核心模块--> | ||
| 31 | <dependency> | 33 | <dependency> |
| 32 | - <groupId>org.slf4j</groupId> | ||
| 33 | - <artifactId>slf4j-simple</artifactId> | 34 | + <groupId>com.zhonglai.luhui</groupId> |
| 35 | + <artifactId>ruoyi-framework</artifactId> | ||
| 34 | </dependency> | 36 | </dependency> |
| 35 | 37 | ||
| 36 | <dependency> | 38 | <dependency> |
| 37 | <groupId>com.zhonglai.luhui</groupId> | 39 | <groupId>com.zhonglai.luhui</groupId> |
| 38 | - <artifactId>ruoyi-common</artifactId> | 40 | + <artifactId>lh-common-swagger</artifactId> |
| 39 | </dependency> | 41 | </dependency> |
| 40 | </dependencies> | 42 | </dependencies> |
| 41 | </project> | 43 | </project> |
lh-modules/lh-data-file-service/src/main/java/com/zhonglai/luhui/data/file/service/Main.java
0 → 100644
| 1 | +package com.zhonglai.luhui.data.file.service; | ||
| 2 | + | ||
| 3 | +import org.springframework.boot.SpringApplication; | ||
| 4 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| 5 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
| 6 | +import org.springframework.context.annotation.ComponentScan; | ||
| 7 | + | ||
| 8 | +@ComponentScan(basePackages = { | ||
| 9 | + "com.ruoyi.common", | ||
| 10 | + "com.ruoyi.framework", | ||
| 11 | + "com.zhonglai.luhui.data.file.service", | ||
| 12 | +} | ||
| 13 | +) | ||
| 14 | +@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) | ||
| 15 | +public class Main { | ||
| 16 | + public static void main(String[] args) { | ||
| 17 | + SpringApplication.run(Main.class,args); | ||
| 18 | + System.out.println("启动成功"); | ||
| 19 | + } | ||
| 20 | +} |
| 1 | +package com.zhonglai.luhui.data.file.service.baidu; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +@Data | ||
| 6 | +public class BaiDuWangPanResponse { | ||
| 7 | + /** | ||
| 8 | + * Access Token的有效期,单位为秒。 | ||
| 9 | + */ | ||
| 10 | + private Integer expires_in; //: 2592000, | ||
| 11 | + /** | ||
| 12 | + * 用于刷新Access Token, 有效期为10年。 | ||
| 13 | + */ | ||
| 14 | + private String refresh_token; //: "122.51265f007055bc895cb02c639410a90d.YDLFcE2nee3Cyu-Bsn7SAFVCAfdCkvSm4EnCdkO.Zs_FiQ", | ||
| 15 | + /** | ||
| 16 | + * 获取到的Access Token,Access Token是调用网盘开放API访问用户授权资源的凭证。 | ||
| 17 | + */ | ||
| 18 | + private String access_token; //: "121.60bf4c9911cb554aac39a1c701a4dae8.YDjwYds0zFgbM1rifQhjMLwsfb6xYus5tUhNEoA.XNNoOQ", | ||
| 19 | + private String session_secret; //: "", | ||
| 20 | + private String session_key; //: "", | ||
| 21 | + /** | ||
| 22 | + * Access Token 最终的访问权限,即用户的实际授权列表。 | ||
| 23 | + */ | ||
| 24 | + private String scope; //: "basic netdisk" | ||
| 25 | +} |
| 1 | +package com.zhonglai.luhui.data.file.service.baidu; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.data.file.service.config.SysConfig; | ||
| 4 | + | ||
| 5 | +import java.io.BufferedReader; | ||
| 6 | +import java.io.InputStreamReader; | ||
| 7 | +import java.net.HttpURLConnection; | ||
| 8 | +import java.net.URL; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 百度网盘服务 | ||
| 12 | + */ | ||
| 13 | +public class BaiDuWangPanService { | ||
| 14 | + /** | ||
| 15 | + * 获取授权地址 | ||
| 16 | + * @param redirect_uri | ||
| 17 | + * @return | ||
| 18 | + */ | ||
| 19 | + public static String getOauth2Url(String redirect_uri) | ||
| 20 | + { | ||
| 21 | + return "http://openapi.baidu.com/oauth/2.0/authorize?response_type=code&client_id="+ SysConfig.BaiDuWangPanAppConfig.AppKey+"&redirect_uri="+redirect_uri+"&scope=basic,netdisk&device_id="+SysConfig.BaiDuWangPanAppConfig.AppID; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 授权 | ||
| 26 | + * @param code | ||
| 27 | + * @param redirect_uri | ||
| 28 | + * @return | ||
| 29 | + */ | ||
| 30 | + public static String oauth2(String code,String redirect_uri) | ||
| 31 | + { | ||
| 32 | + try { | ||
| 33 | + URL url = new URL("https://openapi.baidu.com/oauth/2.0/token?grant_type=authorization_code&code="+code+"&client_id="+SysConfig.BaiDuWangPanAppConfig.AppKey+"&client_secret="+SysConfig.BaiDuWangPanAppConfig.Secretkey+"&redirect_uri="+redirect_uri); | ||
| 34 | + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | ||
| 35 | + conn.setRequestMethod("GET"); | ||
| 36 | + BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); | ||
| 37 | + String inputLine; | ||
| 38 | + StringBuffer response = new StringBuffer(); | ||
| 39 | + while ((inputLine = in.readLine()) != null) { | ||
| 40 | + response.append(inputLine); | ||
| 41 | + } | ||
| 42 | + in.close(); | ||
| 43 | + String str = response.toString(); | ||
| 44 | + System.out.println(str); | ||
| 45 | + return str; | ||
| 46 | + } catch (Exception e) { | ||
| 47 | + System.out.println(e); | ||
| 48 | + } | ||
| 49 | + return null; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 刷新token | ||
| 54 | + * @param refresh_token | ||
| 55 | + * @return | ||
| 56 | + */ | ||
| 57 | + public static String refreshToken(String refresh_token) | ||
| 58 | + { | ||
| 59 | + try { | ||
| 60 | + URL url = new URL("https://openapi.baidu.com/oauth/2.0/token?grant_type=refresh_token&refresh_token="+refresh_token+"&client_id="+SysConfig.BaiDuWangPanAppConfig.AppKey+"&client_secret="+SysConfig.BaiDuWangPanAppConfig.Secretkey); | ||
| 61 | + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | ||
| 62 | + conn.setRequestMethod("GET"); | ||
| 63 | + BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); | ||
| 64 | + String inputLine; | ||
| 65 | + StringBuffer response = new StringBuffer(); | ||
| 66 | + while ((inputLine = in.readLine()) != null) { | ||
| 67 | + response.append(inputLine); | ||
| 68 | + } | ||
| 69 | + in.close(); | ||
| 70 | + String str = response.toString(); | ||
| 71 | + System.out.println(str); | ||
| 72 | + return str; | ||
| 73 | + } catch (Exception e) { | ||
| 74 | + System.out.println(e); | ||
| 75 | + } | ||
| 76 | + return null; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + | ||
| 80 | + | ||
| 81 | +} |
| 1 | +package com.zhonglai.luhui.data.file.service.config; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.config.RuoYiConfig; | ||
| 4 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 5 | +import org.springframework.context.annotation.Bean; | ||
| 6 | +import org.springframework.context.annotation.Configuration; | ||
| 7 | +import springfox.documentation.builders.ApiInfoBuilder; | ||
| 8 | +import springfox.documentation.builders.PathSelectors; | ||
| 9 | +import springfox.documentation.builders.RequestHandlerSelectors; | ||
| 10 | +import springfox.documentation.service.Contact; | ||
| 11 | +import springfox.documentation.spi.DocumentationType; | ||
| 12 | +import springfox.documentation.spring.web.plugins.Docket; | ||
| 13 | +import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +@Configuration | ||
| 17 | +@EnableSwagger2 | ||
| 18 | +public class SwaggerConfig { | ||
| 19 | + /** 系统基础配置 */ | ||
| 20 | + @Autowired | ||
| 21 | + private RuoYiConfig ruoyiConfig; | ||
| 22 | + @Bean | ||
| 23 | + public Docket createRestApi() { | ||
| 24 | + return new Docket(DocumentationType.SWAGGER_2) | ||
| 25 | + .groupName("数据文件管理服务") | ||
| 26 | + .apiInfo( | ||
| 27 | + new ApiInfoBuilder().title("标题:数据文件管理服务api") | ||
| 28 | + .description("数据文件管理服务") | ||
| 29 | + .contact(new Contact(ruoyiConfig.getName(), null, null)) | ||
| 30 | + .version("版本号:" + ruoyiConfig.getVersion()) | ||
| 31 | + .build() | ||
| 32 | + ) | ||
| 33 | + .select() | ||
| 34 | + .apis(RequestHandlerSelectors.basePackage("com.zhonglai.luhui.data.file.service.controller")) | ||
| 35 | + .paths(PathSelectors.any()) | ||
| 36 | + .build(); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | +} |
| 1 | +package com.zhonglai.luhui.data.file.service.config; | ||
| 2 | + | ||
| 3 | +public class SysConfig { | ||
| 4 | + public static String DATA_FILE_DOMAIN = "/禄辉/ly_sensor_data"; | ||
| 5 | + | ||
| 6 | + public static class BaiDuWangPanAppConfig | ||
| 7 | + { | ||
| 8 | + public static String AppID = "42678014"; | ||
| 9 | + public static String AppKey = "Euj78joa7qLVAXKEgGyv0jGgeyUuyfrA"; | ||
| 10 | + public static String Secretkey = "bCPrMDpbRVG3K2x7HLuRuXQwGuQt6wGG"; | ||
| 11 | + public static String Signkey = "~7YysF+j@hgg=XWAGGkEEOScaWwY^btE"; | ||
| 12 | + } | ||
| 13 | +} |
| 1 | +package com.zhonglai.luhui.data.file.service.controller; | ||
| 2 | + | ||
| 3 | +import cn.hutool.db.Db; | ||
| 4 | +import cn.hutool.db.Entity; | ||
| 5 | +import com.ruoyi.common.core.domain.Message; | ||
| 6 | +import com.ruoyi.common.core.domain.MessageCode; | ||
| 7 | +import com.ruoyi.common.utils.DateUtils; | ||
| 8 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 9 | +import com.ruoyi.common.utils.StringUtils; | ||
| 10 | +import com.zhonglai.luhui.data.file.service.baidu.BaiDuWangPanResponse; | ||
| 11 | +import com.zhonglai.luhui.data.file.service.baidu.BaiDuWangPanService; | ||
| 12 | +import com.zhonglai.luhui.data.file.service.dto.SysTripartitePlatformToken; | ||
| 13 | +import io.swagger.annotations.Api; | ||
| 14 | +import io.swagger.annotations.ApiOperation; | ||
| 15 | +import org.slf4j.Logger; | ||
| 16 | +import org.slf4j.LoggerFactory; | ||
| 17 | +import org.springframework.stereotype.Controller; | ||
| 18 | +import org.springframework.web.bind.annotation.GetMapping; | ||
| 19 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 20 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
| 21 | + | ||
| 22 | +import javax.servlet.http.HttpServletRequest; | ||
| 23 | +import javax.servlet.http.HttpServletResponse; | ||
| 24 | +import java.io.IOException; | ||
| 25 | +import java.sql.SQLException; | ||
| 26 | + | ||
| 27 | +@Api(tags = "百度网盘管理") | ||
| 28 | +@Controller | ||
| 29 | +@RequestMapping("/baiDuWangPan") | ||
| 30 | +public class BaiDuWangPanController { | ||
| 31 | + private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 32 | + private static String typestr = "BaiDuWangPanToken_ZL"; | ||
| 33 | + | ||
| 34 | + @ApiOperation("获取授权连接") | ||
| 35 | + @GetMapping("/getOauth2Url") | ||
| 36 | + public void getOauth2Url(HttpServletResponse httpServletResponse,HttpServletRequest httpServletRequest) | ||
| 37 | + { | ||
| 38 | + try { | ||
| 39 | + httpServletResponse.sendRedirect(BaiDuWangPanService.getOauth2Url(getRedirectUri(httpServletRequest))); | ||
| 40 | + } catch (IOException e) { | ||
| 41 | + logger.error("获取授权连接失败", e); | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @ApiOperation("授权回调") | ||
| 46 | + @GetMapping("/oauth2") | ||
| 47 | + @ResponseBody | ||
| 48 | + public String oauth2(String code,HttpServletRequest httpServletRequest) | ||
| 49 | + { | ||
| 50 | + String str = BaiDuWangPanService.oauth2(code,getRedirectUri(httpServletRequest)); | ||
| 51 | + logger.info("收到授权返回的数据{}", str); | ||
| 52 | + if(StringUtils.isEmpty(str)) | ||
| 53 | + { | ||
| 54 | + return "获取授权码错误"; | ||
| 55 | + } | ||
| 56 | + saveOauth2(str); | ||
| 57 | + | ||
| 58 | + return str; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public static void main(String[] args) { | ||
| 62 | + BaiDuWangPanController baiDuWangPanController = new BaiDuWangPanController(); | ||
| 63 | + baiDuWangPanController.saveOauth2("{\"expires_in\":2592000,\"refresh_token\":\"122.0053b4548d54856cceccae388c878853.Y3HekPPrUdJIXRDKIxMD7CpGAuPOWcVU61SGsQQ.1BN3ew\",\"access_token\":\"121.1cd4766c1e1cd5d58a461b3c2a09f213.YHdmmMQr0l3iHKQUJVJHNfp2f_fk3y6RFWHNSLY.GvxSuA\",\"session_secret\":\"\",\"session_key\":\"\",\"scope\":\"basic netdisk\"}\n"); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + private void saveOauth2(String str) | ||
| 67 | + { | ||
| 68 | + BaiDuWangPanResponse baiDuWangPanResponse = GsonConstructor.get().fromJson(str,BaiDuWangPanResponse.class); | ||
| 69 | + | ||
| 70 | + try { | ||
| 71 | + SysTripartitePlatformToken sysTripartitePlatformToken = new SysTripartitePlatformToken(); | ||
| 72 | + sysTripartitePlatformToken.setTripartite_platform_type(typestr); | ||
| 73 | + sysTripartitePlatformToken.setTripartite_platform_name("百度网络的授权token(钟来的)"); | ||
| 74 | + sysTripartitePlatformToken.setCreate_time(DateUtils.getNowTimeMilly()); | ||
| 75 | + sysTripartitePlatformToken.setUpdate_time(DateUtils.getNowTimeMilly()); | ||
| 76 | + | ||
| 77 | + sysTripartitePlatformToken.setAccess_token(baiDuWangPanResponse.getAccess_token()); | ||
| 78 | + sysTripartitePlatformToken.setAccess_token_end_time(sysTripartitePlatformToken.getUpdate_time()+baiDuWangPanResponse.getExpires_in()); | ||
| 79 | + sysTripartitePlatformToken.setRefresh_token(baiDuWangPanResponse.getRefresh_token()); | ||
| 80 | + sysTripartitePlatformToken.setRefresh_token_end_time(sysTripartitePlatformToken.getUpdate_time()+(10*365*24*60*60)); | ||
| 81 | + | ||
| 82 | + Db.use().insert(Entity.create().parse(sysTripartitePlatformToken).setTableName("sys_tripartite_platform_token")); | ||
| 83 | + } catch (SQLException e) { | ||
| 84 | + throw new RuntimeException(e); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @ApiOperation("获取token") | ||
| 89 | + @GetMapping("/getToekn") | ||
| 90 | + @ResponseBody | ||
| 91 | + public Message getToekn() | ||
| 92 | + { | ||
| 93 | + try { | ||
| 94 | + Entity entity = Db.use().get("sys_tripartite_platform_token","tripartite_platform_type",typestr); | ||
| 95 | + if(null == entity) | ||
| 96 | + { | ||
| 97 | + return new Message(MessageCode.DEFAULT_FAIL_CODE,"未授权"); | ||
| 98 | + } | ||
| 99 | + SysTripartitePlatformToken sysTripartitePlatformToken = entity.toBean(SysTripartitePlatformToken.class); | ||
| 100 | + int time = DateUtils.getNowTimeMilly(); | ||
| 101 | + if((sysTripartitePlatformToken.getAccess_token_end_time()-time)<=3600) | ||
| 102 | + { | ||
| 103 | + if((sysTripartitePlatformToken.getRefresh_token_end_time()-time)<=(24*60*60)) | ||
| 104 | + { | ||
| 105 | + String str = BaiDuWangPanService.refreshToken(sysTripartitePlatformToken.getRefresh_token()); | ||
| 106 | + BaiDuWangPanResponse baiDuWangPanResponse = GsonConstructor.get().fromJson(str,BaiDuWangPanResponse.class); | ||
| 107 | + sysTripartitePlatformToken.setAccess_token(baiDuWangPanResponse.getAccess_token()); | ||
| 108 | + sysTripartitePlatformToken.setAccess_token_end_time(sysTripartitePlatformToken.getUpdate_time()+baiDuWangPanResponse.getExpires_in()); | ||
| 109 | + sysTripartitePlatformToken.setRefresh_token(baiDuWangPanResponse.getRefresh_token()); | ||
| 110 | + sysTripartitePlatformToken.setRefresh_token_end_time(sysTripartitePlatformToken.getUpdate_time()+(10*365*24*60*60)); | ||
| 111 | + sysTripartitePlatformToken.setUpdate_time(DateUtils.getNowTimeMilly()); | ||
| 112 | + Db.use().update(Entity.create().parse(sysTripartitePlatformToken).setTableName("sys_tripartite_platform_token"),Entity.create().addFieldNames("id")); | ||
| 113 | + } | ||
| 114 | + return new Message(MessageCode.DEFAULT_FAIL_CODE,"授权到期,请重新授权"); | ||
| 115 | + } | ||
| 116 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,sysTripartitePlatformToken.getAccess_token()); | ||
| 117 | + } catch (SQLException e) { | ||
| 118 | + throw new RuntimeException(e); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + private String getRedirectUri(HttpServletRequest httpServletRequest) | ||
| 124 | + { | ||
| 125 | + String requestUrl = httpServletRequest.getRequestURL().toString(); | ||
| 126 | + String rootUrl = requestUrl.substring(0, requestUrl.lastIndexOf("/")); | ||
| 127 | +// return rootUrl+"/baiDuWangPan/oauth2"; | ||
| 128 | + return "oob"; | ||
| 129 | + } | ||
| 130 | +} |
| 1 | +package com.zhonglai.luhui.data.file.service.db; | ||
| 2 | + | ||
| 3 | +import cn.hutool.db.Db; | ||
| 4 | +import cn.hutool.db.Entity; | ||
| 5 | +import com.ruoyi.common.utils.DateUtils; | ||
| 6 | +import com.zhonglai.luhui.data.file.service.config.SysConfig; | ||
| 7 | +import com.zhonglai.luhui.data.file.service.dto.DataFile; | ||
| 8 | + | ||
| 9 | +import java.sql.SQLException; | ||
| 10 | + | ||
| 11 | +public class DataFileDb { | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 从数据库获取数据文件对象 | ||
| 16 | + * @param id | ||
| 17 | + * @return | ||
| 18 | + */ | ||
| 19 | + public DataFile getDataFile(String id) | ||
| 20 | + { | ||
| 21 | + //查询 | ||
| 22 | + try { | ||
| 23 | + DataFile dataFile = Db.use().get("data_file","id",id).toBean(DataFile.class); | ||
| 24 | + return dataFile; | ||
| 25 | + } catch (SQLException e) { | ||
| 26 | + throw new RuntimeException(e); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 保存数据文件对象 | ||
| 32 | + * @param id | ||
| 33 | + * @return | ||
| 34 | + */ | ||
| 35 | + public DataFile insert(String id) | ||
| 36 | + { | ||
| 37 | + DataFile dataFile = new DataFile(); | ||
| 38 | + dataFile.setId(id); | ||
| 39 | + String time = DateUtils.getTime(); | ||
| 40 | + String[] ts = time.split("-"); | ||
| 41 | + dataFile.setFile_path("/"+ts[0]+"/"+ts[1]); | ||
| 42 | + dataFile.setCreate_time(time); | ||
| 43 | + try { | ||
| 44 | + Db.use().insert(Entity.parse(dataFile)); | ||
| 45 | + } catch (SQLException e) { | ||
| 46 | + throw new RuntimeException(e); | ||
| 47 | + } | ||
| 48 | + return dataFile; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * 获取文件路径 | ||
| 53 | + * @param id | ||
| 54 | + * @return | ||
| 55 | + */ | ||
| 56 | + public String getDataFilePath(String id) | ||
| 57 | + { | ||
| 58 | + DataFile dataFile =getDataFile(id); | ||
| 59 | + if(null == dataFile) | ||
| 60 | + { | ||
| 61 | + dataFile = insert(id); | ||
| 62 | + } | ||
| 63 | + return SysConfig.DATA_FILE_DOMAIN+dataFile.getFile_path(); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | +} |
lh-modules/lh-data-file-service/src/main/java/com/zhonglai/luhui/data/file/service/dto/DataFile.java
0 → 100644
| 1 | +package com.zhonglai.luhui.data.file.service.dto; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | +import lombok.experimental.Accessors; | ||
| 5 | + | ||
| 6 | +@Data | ||
| 7 | +@Accessors(chain = true) //链式写法 | ||
| 8 | +public class DataFile { | ||
| 9 | + private String id; //主键 | ||
| 10 | + private String file_path; //路径 | ||
| 11 | + private String create_time; //创建时间 | ||
| 12 | +} |
| 1 | +package com.zhonglai.luhui.data.file.service.dto; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +@Data | ||
| 7 | +@ApiModel(value = "SysTripartitePlatformToken", description = "第三方平台的token管理") | ||
| 8 | +public class SysTripartitePlatformToken { | ||
| 9 | + private Integer id; // int NOT NULL AUTO_INCREMENT COMMENT '主键', | ||
| 10 | + private String access_token; // varchar(200) DEFAULT NULL COMMENT '第三方平台的api请求token', | ||
| 11 | + private Integer access_token_end_time; // int DEFAULT NULL COMMENT 'api请求token到期时间', | ||
| 12 | + private String refresh_token; // varchar(200) DEFAULT NULL COMMENT '第三方平台的刷新token', | ||
| 13 | + private Integer refresh_token_end_time; // int DEFAULT NULL COMMENT '刷新token的到期时间', | ||
| 14 | + private String tripartite_platform_type; // varchar(50) DEFAULT NULL COMMENT '第三方平台类型', | ||
| 15 | + private String tripartite_platform_name; // varchar(150) DEFAULT NULL COMMENT '第三方平台名称', | ||
| 16 | + private Integer create_time; // int DEFAULT NULL COMMENT '创建时间', | ||
| 17 | + private Integer update_time; // int DEFAULT NULL COMMENT '更新时间', | ||
| 18 | +} |
| 1 | +# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2023 # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8067 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api |
| 1 | +url=jdbc:mysql://rm-wz9740un21f09iokuao.mysql.rds.aliyuncs.com:3306/mqtt_broker?useUnicode=true&characterEncoding=utf8&autoReconnect=true | ||
| 2 | +user = luhui | ||
| 3 | +pass = Luhui586 | ||
| 4 | + | ||
| 5 | +## 可选配置 | ||
| 6 | +# 是否在日志中显示执行的SQL | ||
| 7 | +showSql = true | ||
| 8 | +# 是否格式化显示的SQL | ||
| 9 | +formatSql = false | ||
| 10 | +# 是否显示SQL参数 | ||
| 11 | +showParams = true | ||
| 12 | +# 打印SQL的日志等级,默认debug,可以是info、warn、error | ||
| 13 | +sqlLevel = debug | ||
| 14 | + | ||
| 15 | +## 连接池配置项 | ||
| 16 | +# 自动提交 | ||
| 17 | +autoCommit = true | ||
| 18 | +# 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 缺省:30秒 | ||
| 19 | +connectionTimeout = 30000 | ||
| 20 | +# 一个连接idle状态的最大时长(毫秒),超时则被释放(retired),缺省:10分钟 | ||
| 21 | +idleTimeout = 600000 | ||
| 22 | +# 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';) | ||
| 23 | +maxLifetime = 1800000 | ||
| 24 | +# 获取连接前的测试SQL | ||
| 25 | +connectionTestQuery = SELECT 1 | ||
| 26 | +# 最小闲置连接数 | ||
| 27 | +minimumIdle = 2 | ||
| 28 | +# 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count) | ||
| 29 | +maximumPoolSize = 10 | ||
| 30 | +# 连接只读数据库时配置为true, 保证安全 | ||
| 31 | +readOnly = false |
| 1 | -package com.zhonglai.luhui.smart.feeder.pureness.config; | ||
| 2 | - | ||
| 3 | -import org.slf4j.Logger; | ||
| 4 | -import org.slf4j.LoggerFactory; | ||
| 5 | - | ||
| 6 | -import java.io.FileInputStream; | ||
| 7 | -import java.io.IOException; | ||
| 8 | -import java.util.HashMap; | ||
| 9 | -import java.util.Map; | ||
| 10 | -import java.util.Properties; | ||
| 11 | - | ||
| 12 | -public class SysConfig { | ||
| 13 | - private static final Logger log = LoggerFactory.getLogger(SysConfig.class); | ||
| 14 | - private static Map<String,String> map = new HashMap<>(); | ||
| 15 | - | ||
| 16 | - private void loadconfig(String configpath) throws IOException { | ||
| 17 | - log.info("加载系统配置文件:{}",configpath); | ||
| 18 | - Properties p = new Properties(); | ||
| 19 | - //创建一个字节输入流对象读取文件默认在当前项目下查找 | ||
| 20 | - FileInputStream in = new FileInputStream(configpath); | ||
| 21 | - //Properties类的load()方法进行配置文件的加载 | ||
| 22 | - p.load(in); | ||
| 23 | - | ||
| 24 | - for(String key:p.stringPropertyNames()) | ||
| 25 | - { | ||
| 26 | - | ||
| 27 | - p.getProperty(key); | ||
| 28 | - | ||
| 29 | - } | ||
| 30 | - } | ||
| 31 | - | ||
| 32 | - public static String sys_srs_push_address; | ||
| 33 | - public static String sys_mp4_file_path; | ||
| 34 | - | ||
| 35 | - public static String mqtt_broke; | ||
| 36 | - public static String mqtt_clientId; | ||
| 37 | - public static String mqtt_topics; | ||
| 38 | - public static String mqtt_username; | ||
| 39 | - public static String mqtt_password; | ||
| 40 | - public static String mqtt_client_operationTime; | ||
| 41 | - | ||
| 42 | - | ||
| 43 | -} |
| 1 | -package com.zhonglai.luhui.smart.feeder.pureness.service; | ||
| 2 | - | ||
| 3 | -import com.alibaba.fastjson.JSONObject; | ||
| 4 | -import com.ruoyi.common.utils.ip.IpUtils; | ||
| 5 | -import org.eclipse.paho.client.mqttv3.*; | ||
| 6 | -import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; | ||
| 7 | - | ||
| 8 | -import org.slf4j.Logger; | ||
| 9 | -import org.slf4j.LoggerFactory; | ||
| 10 | - | ||
| 11 | -import java.io.FileInputStream; | ||
| 12 | -import java.util.HashMap; | ||
| 13 | -import java.util.List; | ||
| 14 | -import java.util.Map; | ||
| 15 | -import java.util.Properties; | ||
| 16 | - | ||
| 17 | -public class TerminalService { | ||
| 18 | - private static final Logger log = LoggerFactory.getLogger(TerminalService.class); | ||
| 19 | - | ||
| 20 | - private MqttClient mqttclient; | ||
| 21 | - private MqttConnectOptions options; | ||
| 22 | - private MqttCallback mqttCallback; | ||
| 23 | - private String broker; | ||
| 24 | - private String clientId; | ||
| 25 | - private List<String> topics; | ||
| 26 | - | ||
| 27 | - private List<String> mqtt_usernames; | ||
| 28 | - | ||
| 29 | - private String username; | ||
| 30 | - private String password; | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - public void startMqttListenerService() throws MqttException { | ||
| 35 | - log.info("-----------开始启动mqtt监听服务--------------------"); | ||
| 36 | - init(); | ||
| 37 | - connect(); | ||
| 38 | - subscribe(); | ||
| 39 | - | ||
| 40 | - Map<String,Object> dmap = new HashMap<>(); | ||
| 41 | - Map<String,Object> map = new HashMap<>(); | ||
| 42 | - dmap.put("summary",map); | ||
| 43 | - map.put("localhostIp", IpUtils.getLocalHost()); | ||
| 44 | - JSONObject jsonObject = new JSONObject(); | ||
| 45 | - jsonObject.put("0",dmap); | ||
| 46 | - String topic = "ADD_POST"; | ||
| 47 | - publish(topic,jsonObject.toJSONString()); | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - public void init() throws MqttException { | ||
| 52 | - if(null == mqttclient) | ||
| 53 | - { | ||
| 54 | - mqttclient = new MqttClient(broker, clientId, new MemoryPersistence()); | ||
| 55 | - } | ||
| 56 | - options = new MqttConnectOptions(); | ||
| 57 | - options.setCleanSession(true); | ||
| 58 | - options.setConnectionTimeout(15); | ||
| 59 | - //设置断开后重新连接 | ||
| 60 | - options.setAutomaticReconnect(true); | ||
| 61 | - mqttclient.setCallback(mqttCallback); | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - private void connect() throws MqttException { | ||
| 65 | - options.setUserName(username); | ||
| 66 | - options.setPassword(password.toCharArray()); | ||
| 67 | - mqttclient.connect(options); | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | - public void subscribe() throws MqttException { | ||
| 71 | - mqttclient.subscribe(topics.toArray(new String[topics.size()])); | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - public void publish(String topic, MqttMessage message) throws MqttException { | ||
| 75 | - mqttclient.publish(topic,message); | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - public void publish(String topic, String messageStr) throws MqttException { | ||
| 79 | - MqttMessage message = new MqttMessage(); | ||
| 80 | - message.setPayload(messageStr.getBytes()); | ||
| 81 | - mqttclient.publish(topic,message); | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - public void scheduledSubmissionData(String messageStr) throws MqttException { | ||
| 85 | - String topic = "ALL_POST"; | ||
| 86 | - publish(topic,messageStr); | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | - public void close() | ||
| 90 | - { | ||
| 91 | - try { | ||
| 92 | - options.setAutomaticReconnect(false); | ||
| 93 | - if(null != mqttclient && mqttclient.isConnected()) | ||
| 94 | - { | ||
| 95 | - mqttclient.disconnect(); | ||
| 96 | - mqttclient.close(); | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - } catch (MqttException e) { | ||
| 100 | - log.error("关闭失败",e); | ||
| 101 | - } | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | -} |
| 1 | -sys.srs_push_address=rtmp://119.23.218.181:21935/live/${mqtt.clientId} | ||
| 2 | -sys.mp4_file_path=D:/lh-smart-feeder/2.mp4 | ||
| 3 | - | ||
| 4 | - | ||
| 5 | -mqtt.broker=tcp://175.24.61.68:1883 | ||
| 6 | -mqtt.clientId=70094a59d1d991d | ||
| 7 | -mqtt.topics=PUT/+,GET_REQ/+, READ/+,POST_REQ/+ | ||
| 8 | -mqtt.username=12_ZNZY | ||
| 9 | -mqtt.password=Luhui586 | ||
| 10 | -mqtt.client.operationTime=10 |
| @@ -29,11 +29,16 @@ public class SysConfig implements OperatingDataType{ | @@ -29,11 +29,16 @@ public class SysConfig implements OperatingDataType{ | ||
| 29 | 29 | ||
| 30 | private Boolean ifRegisterConfig = false; | 30 | private Boolean ifRegisterConfig = false; |
| 31 | 31 | ||
| 32 | + /** | ||
| 33 | + * 摄像头密码,默认是验证码 | ||
| 34 | + */ | ||
| 35 | + private String password; | ||
| 32 | public SysConfig creteDefault() | 36 | public SysConfig creteDefault() |
| 33 | { | 37 | { |
| 34 | ifUpLoadData = false; | 38 | ifUpLoadData = false; |
| 35 | ifVeiw = false; | 39 | ifVeiw = false; |
| 36 | nettyConfig = new NettyConfig(); | 40 | nettyConfig = new NettyConfig(); |
| 41 | + password = "Luhui586"; | ||
| 37 | return this; | 42 | return this; |
| 38 | } | 43 | } |
| 39 | 44 |
| @@ -118,7 +118,7 @@ public class CameraRtspHandle implements CameraHandle { | @@ -118,7 +118,7 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 118 | return false; | 118 | return false; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | - String rtspUrl = "rtsp://admin:Luhui586@"+ip+":554/h264/ch1/main/av_stream"; | 121 | + String rtspUrl = "rtsp://admin:"+OperatingData.sysConfig.getPassword()+"@"+ip+":554/h264/ch1/main/av_stream"; |
| 122 | grabber = new FFmpegFrameGrabber(rtspUrl); | 122 | grabber = new FFmpegFrameGrabber(rtspUrl); |
| 123 | // grabber.setOption("framerate", "30"); // 设置帧率为30帧/秒 | 123 | // grabber.setOption("framerate", "30"); // 设置帧率为30帧/秒 |
| 124 | // grabber.setOption("skip_frame", "nokey"); // 只抓取关键帧 | 124 | // grabber.setOption("skip_frame", "nokey"); // 只抓取关键帧 |
| @@ -26,7 +26,7 @@ | @@ -26,7 +26,7 @@ | ||
| 26 | <module>lh-smart-feeder</module> | 26 | <module>lh-smart-feeder</module> |
| 27 | <module>lh-server-ops</module> | 27 | <module>lh-server-ops</module> |
| 28 | <module>lh-http-service</module> | 28 | <module>lh-http-service</module> |
| 29 | - <module>lh-smart-feeder-pureness</module> | 29 | + <module>lh-data-file-service</module> |
| 30 | </modules> | 30 | </modules> |
| 31 | 31 | ||
| 32 | <properties> | 32 | <properties> |
-
请 注册 或 登录 后发表评论