Commit 084e68b2 by ypenglv

增加接口服务

1 parent 876d025a
Showing 16 changed files with 345 additions and 23 deletions
......@@ -9,7 +9,6 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@MapperScan(basePackages ={"org.nafmii.admin/**/dao"})
@EnableFtpServer
public class NafmiiAdminApplication {
......
......@@ -51,11 +51,7 @@
<artifactId>nafmii-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.nafmii</groupId>
<artifactId>nafmii-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
......
......@@ -9,7 +9,6 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication(scanBasePackages={"org.nafmii"})
@EnableEurekaClient
@EnableFeignClients(basePackages = {"org.nafmii.feign"})
@MapperScan("org.nafmii.app/**/dao")
@EnableFtpServer
public class NafmiiAppApplication {
......
......@@ -46,7 +46,7 @@ public class UserController {
@ApiOperation( value = "app用户登陆接口",notes = "app用户登陆接口")
@PostMapping("/userLogin")
@ResponseBody
public ApiResponse<UserVO> login (@RequestBody @Validated LoginParam loginParam){
public ApiResponse<UserVO> userLogin (@RequestBody @Validated LoginParam loginParam){
ApiResponse<UserVO> login = userService.userLogin(loginParam);
return login;
}
......
......@@ -21,11 +21,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
@FeignClient("nafmii-app")
@RequestMapping("/app/nafmii/user")
public interface UserClient {
@PostMapping("/userLogin22")
@PostMapping("/userLogin")
@ResponseBody
ApiResponse<UserClientVO> userLogin(@RequestBody @Validated LoginClientParam loginClientParam);
@PostMapping("/phoneLogin22")
@PostMapping("/phoneLogin")
@ResponseBody
ApiResponse<UserClientVO> phoneLogin(@RequestBody @Validated LoginClientParam loginClientParam);
}
/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.nafmii</groupId>
<artifactId>nafmii-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.nafmii.outside</groupId>
<artifactId>nafmii-outside-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>nafmii-outside-server</name>
<description>外部接口服务</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties>
<!--区分环境打包-->
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<!--指定默认激活-->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.nafmii</groupId>
<artifactId>nafmii-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.nafmii</groupId>
<artifactId>nafmii-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-sleuth -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-sleuth-zipkin -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>application-dev.yml</exclude>
<exclude>application-test.yml</exclude>
<exclude>application-prod.yml</exclude>
</excludes>
</resource>
<!--需要动态添加的资源-->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<!--读取打包命令中指定的环境-->
<include>application-${env}.yml</include>
<include>application.yml</include>
</includes>
</resource>
</resources>
</build>
</project>
package org.nafmii.outside.server;
import org.nafmii.common.ftp.EnableFtpServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients(basePackages = {"org.nafmii.feign"})
@EnableFtpServer
public class NafmiiOutsideServerApplication {
public static void main(String[] args) {
SpringApplication.run(NafmiiOutsideServerApplication.class, args);
}
}
package org.nafmii.app.feign.controller;
package org.nafmii.outside.server.feign.controller;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nafmii.common.response.ApiResponse;
import org.nafmii.app.feign.service.UserFeignService;
import org.springframework.web.bind.annotation.*;
import org.nafmii.outside.server.feign.service.UserFeignService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
......@@ -26,10 +30,10 @@ public class UserFeignController {
private UserFeignService feignService;
@ApiOperation( value = "app用户登陆接口",notes = "app用户登陆接口")
@PostMapping("/userLogin")
@PostMapping("/outSideEntry")
@ResponseBody
public ApiResponse userLogin (@RequestBody JSONObject object){
ApiResponse userLogin = feignService.userLogin(object);
public ApiResponse outSideEntry (@RequestBody JSONObject object){
ApiResponse userLogin = feignService.outSideEntry(object);
return userLogin;
}
}
package org.nafmii.app.feign.param;
package org.nafmii.outside.server.feign.param;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
......
package org.nafmii.app.feign.service;
package org.nafmii.outside.server.feign.service;
import com.alibaba.fastjson.JSONObject;
import org.nafmii.common.response.ApiResponse;
......@@ -14,5 +14,5 @@ import org.nafmii.common.response.ApiResponse;
public interface UserFeignService {
//对外提供用户登陆接口
ApiResponse userLogin(JSONObject object);
ApiResponse outSideEntry(JSONObject object);
}
package org.nafmii.app.feign.service.impl;
package org.nafmii.outside.server.feign.service.impl;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nafmii.common.response.ApiResponse;
import org.nafmii.common.utils.BeanTransferUtils;
import org.nafmii.feign.UserClient;
import org.nafmii.app.feign.service.UserFeignService;
import org.nafmii.outside.server.feign.service.UserFeignService;
import org.nafmii.user.param.LoginClientParam;
import org.springframework.stereotype.Service;
......@@ -32,7 +32,7 @@ public class UserFeignServiceImpl implements UserFeignService {
* @return
*/
@Override
public ApiResponse userLogin(JSONObject object) {
public ApiResponse outSideEntry(JSONObject object) {
log.info("对外提供登陆接口相关json参数========》{}",object.toJSONString());
LoginClientParam loginClientParam = BeanTransferUtils.transfer(object, LoginClientParam.class);
log.info("对外提供登陆接口相关对象参数========》{}",loginClientParam);
......
package org.nafmii.app.feign.vo;
package org.nafmii.outside.server.feign.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
......
package org.nafmii.outside.server.swagger;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
/**
* 用于在swagger-ui.html上展示所有Api接口
* User: FrankBai
* Date: 2020/02/14
**/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket adminApi() {
ParameterBuilder ticketPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<Parameter>();
ticketPar.name("Authorization").description("Authorization")
.modelRef(new ModelRef("string")).parameterType("header")
.required(false).build(); //header中的ticket参数非必填,传空也可以
pars.add(ticketPar.build()); //根据每个方法名也知道当前方法在设置什么参数
return new Docket (DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build().globalOperationParameters(pars)
.useDefaultResponseMessages(false)
.enableUrlTemplating(false);
}
private static ApiInfo apiInfo() {
return new ApiInfoBuilder ()
.title ("NAFMII-APP应用层接口说明")
.description ("NAFMII-APP应用层接口说明")
.version ("1.0")
.build ();
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!