测试逻辑
This commit is contained in:
parent
0c3157639a
commit
0197af4fbe
40
pom.xml
40
pom.xml
@ -9,14 +9,19 @@
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>ink.wgink</groupId>
|
||||
<artifactId>gateway</artifactId>
|
||||
<artifactId>wg-gateway</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>wg-gateway</name>
|
||||
<description>网关</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<jodatime.version>2.9.4</jodatime.version>
|
||||
<lombok.version>1.18.16</lombok.version>
|
||||
<fastjson.version>1.2.73</fastjson.version>
|
||||
<spring-cloud.version>2020.0.2</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
@ -26,12 +31,35 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@ -50,6 +78,14 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
@ -6,6 +6,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.cloud.gateway.route.RouteLocator;
|
||||
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.yaml.snakeyaml.util.UriEncoder;
|
||||
|
||||
@EnableConfigurationProperties
|
||||
@SpringBootApplication
|
||||
@ -19,9 +20,9 @@ public class WgGatewayApplication {
|
||||
public RouteLocator routes(RouteLocatorBuilder builder) {
|
||||
RouteLocator routeLocator = builder.routes()
|
||||
.route(r -> r
|
||||
.path("/study")
|
||||
.filters(f -> f.addRequestHeader("name", "张三").addRequestParameter("test", "gogo"))
|
||||
.uri("http://127.0.0.1:7008/study"))
|
||||
.path("/study/**")
|
||||
.filters(f -> f.rewritePath("/study/", "/twoduty/").addRequestHeader("name", UriEncoder.encode("zhangsan")).addRequestParameter("test", "gogo"))
|
||||
.uri("http://192.168.0.120:8080"))
|
||||
.build();
|
||||
routeLocator.getRoutes().toStream().forEach(System.out::println);
|
||||
return routeLocator;
|
||||
|
44
src/main/java/ink/wgink/gateway/config/BeanConfig.java
Normal file
44
src/main/java/ink/wgink/gateway/config/BeanConfig.java
Normal file
@ -0,0 +1,44 @@
|
||||
package ink.wgink.gateway.config;
|
||||
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: BeanConfig
|
||||
* @Description: bean配置
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/2/5 6:44 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class BeanConfig {
|
||||
|
||||
/**
|
||||
* 解决 disable SerializationFeature.FAIL_ON_EMPTY_BEANS 问题,由于没有属性导致
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
|
||||
}
|
||||
|
||||
}
|
19
src/main/java/ink/wgink/gateway/consts/ISystemConst.java
Normal file
19
src/main/java/ink/wgink/gateway/consts/ISystemConst.java
Normal file
@ -0,0 +1,19 @@
|
||||
package ink.wgink.gateway.consts;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: ISystemConst
|
||||
* @Description: 常量
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/14 10:16 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface ISystemConst {
|
||||
|
||||
String UUID = "uuid";
|
||||
|
||||
String COUNT = "count";
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package ink.wgink.gateway.controller.api.route;
|
||||
|
||||
import ink.wgink.gateway.dao.route.IRouteDao;
|
||||
import ink.wgink.gateway.pojo.ListPage;
|
||||
import ink.wgink.gateway.pojo.dtos.route.RouteDTO;
|
||||
import ink.wgink.gateway.pojo.result.SuccessResult;
|
||||
import ink.wgink.gateway.pojo.result.SuccessResultList;
|
||||
import ink.wgink.gateway.pojo.vos.route.RouteVO;
|
||||
import ink.wgink.gateway.service.route.IRouteService;
|
||||
import ink.wgink.gateway.util.ReflectUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: RouteController
|
||||
* @Description: 路由
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 6:41 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@RestController("sys/route")
|
||||
public class RouteController {
|
||||
|
||||
@Autowired
|
||||
private IRouteService routeService;
|
||||
|
||||
@PostMapping("save")
|
||||
public SuccessResult save(@RequestBody RouteVO routeVO) throws ReflectUtil.ReflectException {
|
||||
routeService.save(routeVO);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
public SuccessResultList<List<RouteDTO>> listPage(ListPage page) {
|
||||
return routeService.listPage(page);
|
||||
}
|
||||
|
||||
}
|
47
src/main/java/ink/wgink/gateway/dao/BaseDao.java
Normal file
47
src/main/java/ink/wgink/gateway/dao/BaseDao.java
Normal file
@ -0,0 +1,47 @@
|
||||
package ink.wgink.gateway.dao;
|
||||
|
||||
import ink.wgink.gateway.pojo.BasePOJO;
|
||||
import ink.wgink.gateway.util.DateUtil;
|
||||
import ink.wgink.gateway.util.UUIDUtil;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: BaseDao
|
||||
* @Description: dao接口
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 5:56 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class BaseDao {
|
||||
|
||||
public static final String CREATOR = "creator";
|
||||
public static final String MODIFIER = "modifier";
|
||||
public static final String GMT_CREATE = "gmtCreate";
|
||||
public static final String GMT_MODIFIED = "gmtModified";
|
||||
|
||||
protected void setSave(BasePOJO base) {
|
||||
String datetime = DateUtil.getTime();
|
||||
base.setUuid(UUIDUtil.getUUID());
|
||||
base.setCreator("1");
|
||||
base.setGmtCreate(datetime);
|
||||
base.setModifier("1");
|
||||
base.setGmtModified(datetime);
|
||||
}
|
||||
|
||||
protected void setUpdate(Update update) {
|
||||
update.set(GMT_MODIFIED, DateUtil.getTime());
|
||||
update.set(MODIFIER, "1");
|
||||
}
|
||||
|
||||
protected int getLimit(int size) {
|
||||
return size;
|
||||
}
|
||||
|
||||
protected long getSkip(int page, int size) {
|
||||
return (page - 1) * size;
|
||||
}
|
||||
|
||||
}
|
65
src/main/java/ink/wgink/gateway/dao/IBaseDao.java
Normal file
65
src/main/java/ink/wgink/gateway/dao/IBaseDao.java
Normal file
@ -0,0 +1,65 @@
|
||||
package ink.wgink.gateway.dao;
|
||||
|
||||
import ink.wgink.gateway.pojo.BasePOJO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: IBaseDao
|
||||
* @Description:
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 6:29 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IBaseDao<PO extends BasePOJO, DTO extends BasePOJO> {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param po
|
||||
*/
|
||||
void save(PO po);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
void remote(List<String> ids);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*
|
||||
* @param id
|
||||
* @param po
|
||||
*/
|
||||
void update(String id, PO po);
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
<DTO> DTO get(String id);
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param page
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
<DTO> List<DTO> list(int page, int size);
|
||||
|
||||
/**
|
||||
* 统计
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Long count();
|
||||
|
||||
}
|
21
src/main/java/ink/wgink/gateway/dao/route/IRouteDao.java
Normal file
21
src/main/java/ink/wgink/gateway/dao/route/IRouteDao.java
Normal file
@ -0,0 +1,21 @@
|
||||
package ink.wgink.gateway.dao.route;
|
||||
|
||||
import ink.wgink.gateway.dao.IBaseDao;
|
||||
import ink.wgink.gateway.pojo.dtos.route.RouteDTO;
|
||||
import ink.wgink.gateway.pojo.pos.route.RoutePO;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: IRouteDao
|
||||
* @Description: 路由
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 5:28 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IRouteDao extends IBaseDao<RoutePO, RouteDTO> {
|
||||
|
||||
String COLLECTION_NAME = "sys_route";
|
||||
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package ink.wgink.gateway.dao.route.impl;
|
||||
|
||||
import ink.wgink.gateway.consts.ISystemConst;
|
||||
import ink.wgink.gateway.dao.BaseDao;
|
||||
import ink.wgink.gateway.dao.route.IRouteDao;
|
||||
import ink.wgink.gateway.pojo.dtos.route.RouteDTO;
|
||||
import ink.wgink.gateway.pojo.pos.route.RoutePO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
||||
import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
|
||||
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: RouteDaoImpl
|
||||
* @Description: 路由
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 5:32 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Repository
|
||||
public class RouteDaoImpl extends BaseDao implements IRouteDao {
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
@Override
|
||||
public void save(RoutePO routePO) {
|
||||
setSave(routePO);
|
||||
mongoTemplate.save(routePO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remote(List<String> ids) {
|
||||
if (ids.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Criteria queryCriteria = Criteria.where(ISystemConst.UUID);
|
||||
for (int i = 0; i < ids.size(); i++) {
|
||||
if (i > 0) {
|
||||
queryCriteria.and(ISystemConst.UUID);
|
||||
}
|
||||
queryCriteria.is(ids.get(i));
|
||||
}
|
||||
|
||||
mongoTemplate.remove(new Query(queryCriteria), RoutePO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(String uuid, RoutePO routePO) {
|
||||
Update update = new Update();
|
||||
update.set("system", routePO.getSystem());
|
||||
update.set("summary", routePO.getSummary());
|
||||
update.set("inUrl", routePO.getInUrl());
|
||||
update.set("outUrl", routePO.getOutUrl());
|
||||
setUpdate(update);
|
||||
mongoTemplate.updateMulti(new Query(Criteria.where(ISystemConst.UUID).is(uuid)), update, RoutePO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouteDTO get(String uuid) {
|
||||
return mongoTemplate.findOne(new Query(Criteria.where(ISystemConst.UUID).is(uuid)), RouteDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RouteDTO> list(int page, int size) {
|
||||
Query query = new Query();
|
||||
query.limit(getLimit(size));
|
||||
query.skip(getSkip(page, size));
|
||||
return mongoTemplate.find(query, RouteDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long count() {
|
||||
List<AggregationOperation> operations = new ArrayList<>();
|
||||
operations.add(Aggregation.group(ISystemConst.UUID).count().as(ISystemConst.COUNT));
|
||||
Aggregation aggregation = Aggregation.newAggregation(operations);
|
||||
AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, COLLECTION_NAME, Map.class);
|
||||
return Long.parseLong(results.getMappedResults().get(0).get(ISystemConst.COUNT).toString());
|
||||
}
|
||||
}
|
@ -1,12 +1,19 @@
|
||||
package ink.wgink.gateway.filter.global;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
@ -17,12 +24,19 @@ import reactor.core.publisher.Mono;
|
||||
* @Date: 2021/4/13 12:10
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CountGlobalFilter implements GlobalFilter, Ordered {
|
||||
|
||||
private AtomicInteger count = new AtomicInteger(0);
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
System.out.println("count filter");
|
||||
URI uri = exchange.getRequest().getURI();
|
||||
System.out.println();
|
||||
System.out.println("uri: " + uri);
|
||||
System.out.println("count: "+ count.getAndAdd(1));
|
||||
System.out.println();
|
||||
return chain.filter(exchange);
|
||||
// return exchange.getResponse().setComplete();
|
||||
}
|
||||
|
26
src/main/java/ink/wgink/gateway/pojo/BasePOJO.java
Normal file
26
src/main/java/ink/wgink/gateway/pojo/BasePOJO.java
Normal file
@ -0,0 +1,26 @@
|
||||
package ink.wgink.gateway.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: BasePO
|
||||
* @Description:
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 5:56 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
public class BasePOJO {
|
||||
|
||||
@Indexed
|
||||
private String uuid;
|
||||
private String gmtCreate;
|
||||
private String creator;
|
||||
private String gmtModified;
|
||||
private String modifier;
|
||||
|
||||
}
|
33
src/main/java/ink/wgink/gateway/pojo/ListPage.java
Normal file
33
src/main/java/ink/wgink/gateway/pojo/ListPage.java
Normal file
@ -0,0 +1,33 @@
|
||||
package ink.wgink.gateway.pojo;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: ListPage
|
||||
* @Description:
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 6:19 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class ListPage {
|
||||
|
||||
private Integer page;
|
||||
private Integer size;
|
||||
|
||||
public Integer getPage() {
|
||||
return page == null ? 1 : page;
|
||||
}
|
||||
|
||||
public void setPage(Integer page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public Integer getSize() {
|
||||
return size == null ? 20 : size;
|
||||
}
|
||||
|
||||
public void setSize(Integer size) {
|
||||
this.size = size;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package ink.wgink.gateway.pojo.dtos.route;
|
||||
|
||||
import ink.wgink.gateway.pojo.BasePOJO;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: RouteDTO
|
||||
* @Description: 路由
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 7:15 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Document(collection = "sys_route")
|
||||
public class RouteDTO extends BasePOJO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4892456861969101733L;
|
||||
private String system;
|
||||
private String summary;
|
||||
private String outUrl;
|
||||
private String inUrl;
|
||||
|
||||
}
|
35
src/main/java/ink/wgink/gateway/pojo/pos/route/RoutePO.java
Normal file
35
src/main/java/ink/wgink/gateway/pojo/pos/route/RoutePO.java
Normal file
@ -0,0 +1,35 @@
|
||||
package ink.wgink.gateway.pojo.pos.route;
|
||||
|
||||
import ink.wgink.gateway.pojo.BasePOJO;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: RoutePO
|
||||
* @Description: 路由
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 5:20 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Document(collection = "sys_route")
|
||||
public class RoutePO extends BasePOJO implements Serializable {
|
||||
private static final long serialVersionUID = 3471850588453134724L;
|
||||
@Indexed
|
||||
private String system;
|
||||
private String summary;
|
||||
@Indexed
|
||||
private String outUrl;
|
||||
@Indexed
|
||||
private String inUrl;
|
||||
|
||||
}
|
99
src/main/java/ink/wgink/gateway/pojo/result/ErrorResult.java
Normal file
99
src/main/java/ink/wgink/gateway/pojo/result/ErrorResult.java
Normal file
@ -0,0 +1,99 @@
|
||||
package ink.wgink.gateway.pojo.result;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName: ErrorResult
|
||||
* @Description: 错误结果
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/3/2 3:37 PM
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class ErrorResult implements Serializable {
|
||||
|
||||
private Integer code;
|
||||
private String msg;
|
||||
private String detail;
|
||||
|
||||
public ErrorResult() {
|
||||
}
|
||||
|
||||
public ErrorResult(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public String getDetail() {
|
||||
return detail == null ? "" : detail.trim();
|
||||
}
|
||||
|
||||
public void setDetail(String detail) {
|
||||
this.detail = detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"code\":")
|
||||
.append(code);
|
||||
sb.append(",\"msg\":\"")
|
||||
.append(msg).append('\"');
|
||||
sb.append(",\"detail\":\"")
|
||||
.append(detail).append('\"');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public enum ErrorResultCodeEnum {
|
||||
|
||||
/**
|
||||
* 错误类型
|
||||
*/
|
||||
SYSTEM_ERROR(40001),
|
||||
ENCODE_ERROR(40002),
|
||||
DECODE_ERROR(40003),
|
||||
APP_DEPENDENCY_ERROR(40004),
|
||||
PROPERTIES_ERROR(40005),
|
||||
TEXT_ILLEGAL(40101),
|
||||
PARAMS_ERROR(40102),
|
||||
QUERY_ERROR(40101),
|
||||
SAVE_ERROR(40102),
|
||||
UPDATE_ERROR(40103),
|
||||
REMOVE_ERROR(40104),
|
||||
FILE_ERROR(40401),
|
||||
TEST_ERROR(40201),
|
||||
LOGIN_OUT(40301),
|
||||
TOKEN_ERROR(40302),
|
||||
USERNAME_PASSWORD_ERROR(40303),
|
||||
USER_EXIST(40304),
|
||||
PERMISSION_ERROR(40401),
|
||||
DEVICE_ERROR(40501),
|
||||
DEVICE_VERSION_ERROR(40502);
|
||||
|
||||
private int value;
|
||||
|
||||
ErrorResultCodeEnum(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package ink.wgink.gateway.pojo.result;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName: SuccessResult
|
||||
* @Description: 成功结果
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/3/2 11:52 PM
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class SuccessResult implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2794583329290530150L;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package ink.wgink.gateway.pojo.result;
|
||||
|
||||
/**
|
||||
* @ClassName: SuccessResultData
|
||||
* @Description: 返回结果带对象
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/3/11 9:31 AM
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class SuccessResultData<T> extends SuccessResult {
|
||||
|
||||
private static final long serialVersionUID = 2292105832378967169L;
|
||||
private T data;
|
||||
|
||||
public SuccessResultData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"data\":")
|
||||
.append(data);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package ink.wgink.gateway.pojo.result;
|
||||
|
||||
/**
|
||||
* @ClassName: SuccessResultList
|
||||
* @Description: 成功列表结果
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/3/3 12:21 AM
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class SuccessResultList<List> extends SuccessResult {
|
||||
|
||||
private List rows;
|
||||
private Integer page;
|
||||
private Long total;
|
||||
|
||||
public SuccessResultList() {
|
||||
}
|
||||
|
||||
public SuccessResultList(List rows, Integer page, Long total) {
|
||||
this.rows = rows;
|
||||
this.page = page;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(List rows) {
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
public Integer getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(Integer page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public Long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Long total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"rows\":")
|
||||
.append(rows);
|
||||
sb.append(",\"page\":")
|
||||
.append(page);
|
||||
sb.append(",\"total\":")
|
||||
.append(total);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package ink.wgink.gateway.pojo.result;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: UploadExcelResultDTO
|
||||
* @Description: 上传Excel结果
|
||||
* @Author: WangGeng
|
||||
* @Date: 2020/1/6 10:41 下午
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class UploadExcelResultDTO {
|
||||
|
||||
private Integer failedCount;
|
||||
private Long usedTime;
|
||||
private String errorExcel;
|
||||
|
||||
public UploadExcelResultDTO(Integer failedCount, Long usedTime, String errorExcel) {
|
||||
this.failedCount = failedCount;
|
||||
this.usedTime = usedTime;
|
||||
this.errorExcel = errorExcel;
|
||||
}
|
||||
|
||||
public Integer getFailedCount() {
|
||||
return failedCount;
|
||||
}
|
||||
|
||||
public void setFailedCount(Integer failedCount) {
|
||||
this.failedCount = failedCount;
|
||||
}
|
||||
|
||||
public Long getUsedTime() {
|
||||
return usedTime;
|
||||
}
|
||||
|
||||
public void setUsedTime(Long usedTime) {
|
||||
this.usedTime = usedTime;
|
||||
}
|
||||
|
||||
public String getErrorExcel() {
|
||||
return errorExcel == null ? "" : errorExcel.trim();
|
||||
}
|
||||
|
||||
public void setErrorExcel(String errorExcel) {
|
||||
this.errorExcel = errorExcel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"failedCount\":")
|
||||
.append(failedCount);
|
||||
sb.append(",\"usedTime\":")
|
||||
.append(usedTime);
|
||||
sb.append(",\"errorExcel\":")
|
||||
.append("\"").append(errorExcel).append("\"");
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
57
src/main/java/ink/wgink/gateway/pojo/vos/route/RouteVO.java
Normal file
57
src/main/java/ink/wgink/gateway/pojo/vos/route/RouteVO.java
Normal file
@ -0,0 +1,57 @@
|
||||
package ink.wgink.gateway.pojo.vos.route;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: RouteVO
|
||||
* @Description: 路由
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 6:45 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
public class RouteVO {
|
||||
|
||||
private String system;
|
||||
private String summary;
|
||||
private String outUrl;
|
||||
private String inUrl;
|
||||
|
||||
public String getSystem() {
|
||||
return system == null ? "" : system;
|
||||
}
|
||||
|
||||
public void setSystem(String system) {
|
||||
this.system = system;
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
return summary == null ? "" : summary;
|
||||
}
|
||||
|
||||
public void setSummary(String summary) {
|
||||
this.summary = summary;
|
||||
}
|
||||
|
||||
public String getOutUrl() {
|
||||
return outUrl == null ? "" : outUrl;
|
||||
}
|
||||
|
||||
public void setOutUrl(String outUrl) {
|
||||
this.outUrl = outUrl;
|
||||
}
|
||||
|
||||
public String getInUrl() {
|
||||
return inUrl == null ? "" : inUrl;
|
||||
}
|
||||
|
||||
public void setInUrl(String inUrl) {
|
||||
this.inUrl = inUrl;
|
||||
}
|
||||
}
|
14
src/main/java/ink/wgink/gateway/service/BaseService.java
Normal file
14
src/main/java/ink/wgink/gateway/service/BaseService.java
Normal file
@ -0,0 +1,14 @@
|
||||
package ink.wgink.gateway.service;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: BaseService
|
||||
* @Description:
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 6:42 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class BaseService {
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package ink.wgink.gateway.service.route;
|
||||
|
||||
import ink.wgink.gateway.pojo.ListPage;
|
||||
import ink.wgink.gateway.pojo.dtos.route.RouteDTO;
|
||||
import ink.wgink.gateway.pojo.result.SuccessResultList;
|
||||
import ink.wgink.gateway.pojo.vos.route.RouteVO;
|
||||
import ink.wgink.gateway.util.ReflectUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: IRouteService
|
||||
* @Description: 路由
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 6:42 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IRouteService {
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
* @param routeVO
|
||||
* @throws ReflectUtil.ReflectException
|
||||
*/
|
||||
void save(RouteVO routeVO) throws ReflectUtil.ReflectException;
|
||||
|
||||
/**
|
||||
* 分页列表
|
||||
*
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
SuccessResultList<List<RouteDTO>> listPage(ListPage page);
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package ink.wgink.gateway.service.route.impl;
|
||||
|
||||
import ink.wgink.gateway.dao.route.IRouteDao;
|
||||
import ink.wgink.gateway.pojo.ListPage;
|
||||
import ink.wgink.gateway.pojo.dtos.route.RouteDTO;
|
||||
import ink.wgink.gateway.pojo.pos.route.RoutePO;
|
||||
import ink.wgink.gateway.pojo.result.SuccessResultList;
|
||||
import ink.wgink.gateway.pojo.vos.route.RouteVO;
|
||||
import ink.wgink.gateway.service.BaseService;
|
||||
import ink.wgink.gateway.service.route.IRouteService;
|
||||
import ink.wgink.gateway.util.ReflectUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: RouteServiceImpl
|
||||
* @Description: 路由
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/4/13 6:42 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class RouteServiceImpl extends BaseService implements IRouteService {
|
||||
|
||||
@Autowired
|
||||
private IRouteDao routeDao;
|
||||
|
||||
@Override
|
||||
public void save(RouteVO routeVO) throws ReflectUtil.ReflectException {
|
||||
routeDao.save(ReflectUtil.beanToBean(routeVO, RoutePO.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResultList<List<RouteDTO>> listPage(ListPage page) {
|
||||
List<RouteDTO> routeDTOs = routeDao.list(page.getPage(), page.getSize());
|
||||
Long count = routeDao.count();
|
||||
return new SuccessResultList<>(routeDTOs, page.getPage(), count);
|
||||
}
|
||||
}
|
457
src/main/java/ink/wgink/gateway/util/DateUtil.java
Normal file
457
src/main/java/ink/wgink/gateway/util/DateUtil.java
Normal file
@ -0,0 +1,457 @@
|
||||
package ink.wgink.gateway.util;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 说明:日期处理 创建人:CM 修改时间:2015年11月24日
|
||||
*/
|
||||
public class DateUtil {
|
||||
|
||||
public final static String AM = "AM";
|
||||
public final static String PM = "PM";
|
||||
public final static SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
|
||||
public final static SimpleDateFormat sdfMonth = new SimpleDateFormat("MM");
|
||||
public final static SimpleDateFormat sdfd = new SimpleDateFormat("dd");
|
||||
public final static SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
|
||||
public final static SimpleDateFormat sdfDayZh = new SimpleDateFormat("yyyy年MM月dd日");
|
||||
public final static SimpleDateFormat sdfDays = new SimpleDateFormat("yyyyMMdd");
|
||||
public final static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
public final static SimpleDateFormat sdfTimes = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
public final static SimpleDateFormat sdfYearMonth = new SimpleDateFormat("yyyyMM");
|
||||
|
||||
public static String getZhDate(String date) {
|
||||
try {
|
||||
return sdfDayZh.format(sdfDay.parse(date));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验日期格式
|
||||
*
|
||||
* @param date
|
||||
* @param simpleDateFormat
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkFormat(String date, SimpleDateFormat simpleDateFormat) {
|
||||
if (StringUtils.isEmpty(date) || simpleDateFormat == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
simpleDateFormat.parse(date);
|
||||
return true;
|
||||
} catch (ParseException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取YYYYMM格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getSdfYearMonth() {
|
||||
return sdfYearMonth.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取YYYYMMDDHHMMSS格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getSdfTimes() {
|
||||
return sdfTimes.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取YYYY格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getYear() {
|
||||
return sdfYear.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取MM格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getMonth() {
|
||||
return sdfMonth.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取dd格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getToday() {
|
||||
return sdfd.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取YYYY-MM-DD格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getDay() {
|
||||
return sdfDay.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取YYYYMMDD格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getDays() {
|
||||
return sdfDays.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取YYYY-MM-DD HH:mm:ss格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getTime() {
|
||||
return sdfTime.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取日期
|
||||
*
|
||||
* @param datetime
|
||||
* @return
|
||||
*/
|
||||
public static String getDate(String datetime) {
|
||||
return datetime.substring(0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param s
|
||||
* @param e
|
||||
* @return boolean
|
||||
* @throws @author fh
|
||||
* @Title: compareDate
|
||||
* @Description: TODO(日期比较 , 如果s > = e 返回true 否则返回false)
|
||||
*/
|
||||
public static boolean compareDate(String s, String e) {
|
||||
if (fomatDate(s) == null || fomatDate(e) == null) {
|
||||
return false;
|
||||
}
|
||||
return fomatDate(s).getTime() >= fomatDate(e).getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static Date fomatDate(String date) {
|
||||
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
return fmt.parse(date);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验日期是否合法
|
||||
*
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidDate(String s) {
|
||||
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
fmt.parse(s);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
// 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
public static int getDiffYear(String startTime, String endTime) {
|
||||
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
// long aa=0;
|
||||
int years = (int) (((fmt.parse(endTime).getTime() - fmt.parse(startTime).getTime()) / (1000 * 60 * 60 * 24))
|
||||
/ 365);
|
||||
return years;
|
||||
} catch (Exception e) {
|
||||
// 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <li>功能描述:时间相减得到天数
|
||||
*
|
||||
* @param beginDateStr
|
||||
* @param endDateStr
|
||||
* @return long
|
||||
* @author Administrator
|
||||
*/
|
||||
public static long getDaySub(String beginDateStr, String endDateStr) {
|
||||
long day = 0;
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date beginDate = null;
|
||||
Date endDate = null;
|
||||
|
||||
try {
|
||||
beginDate = format.parse(beginDateStr);
|
||||
endDate = format.parse(endDateStr);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
day = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000);
|
||||
// System.out.println("相隔的天数="+day);
|
||||
|
||||
return day;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到n天之后的日期
|
||||
*
|
||||
* @param days
|
||||
* @return
|
||||
*/
|
||||
public static String getAfterDayDate(String days) {
|
||||
int daysInt = Integer.parseInt(days);
|
||||
// java.util包
|
||||
Calendar canlendar = Calendar.getInstance();
|
||||
// 日期减 如果不够减会将月变动
|
||||
canlendar.add(Calendar.DATE, daysInt);
|
||||
Date date = canlendar.getTime();
|
||||
|
||||
SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String dateStr = sdfd.format(date);
|
||||
|
||||
return dateStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到n天之后是周几
|
||||
*
|
||||
* @param days
|
||||
* @return
|
||||
*/
|
||||
public static String getAfterDayWeek(String days) {
|
||||
int daysInt = Integer.parseInt(days);
|
||||
// java.util包
|
||||
Calendar canlendar = Calendar.getInstance();
|
||||
// 日期减 如果不够减会将月变动
|
||||
canlendar.add(Calendar.DATE, daysInt);
|
||||
Date date = canlendar.getTime();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("E");
|
||||
String dateStr = sdf.format(date);
|
||||
return dateStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算年龄生日格式yyyy-MM-dd
|
||||
*
|
||||
* @param birth
|
||||
* @return
|
||||
*/
|
||||
public static String getAge(String birth) {
|
||||
int cYear = Integer.parseInt(getYear());
|
||||
String[] births = birth.split("-");
|
||||
int year = Integer.parseInt(births[0]);
|
||||
if (cYear <= year) {
|
||||
return "0";
|
||||
}
|
||||
int cMonth = Integer.parseInt(getMonth());
|
||||
int cDay = Integer.parseInt(getToday());
|
||||
int month = Integer.parseInt(births[1]);
|
||||
int day = Integer.parseInt(births[2]);
|
||||
int age = cYear - year;
|
||||
if (cMonth - month > 0) {
|
||||
return String.valueOf(age);
|
||||
}
|
||||
if (cDay - day > 0) {
|
||||
return String.valueOf(age);
|
||||
}
|
||||
return String.valueOf(age - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本周周一的日期
|
||||
*/
|
||||
public static String weekStartDate(String pattern) {
|
||||
return new DateTime().dayOfWeek().withMinimumValue().toString(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本周周一的日期
|
||||
*/
|
||||
public static Date weekStartDate() {
|
||||
return new DateTime().dayOfWeek().withMinimumValue().toDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本周最后一天
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String weekEndDate(String pattern) {
|
||||
return new DateTime().dayOfWeek().withMaximumValue().toString(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本周最后一天
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Date weekEndDate() {
|
||||
return new DateTime().dayOfWeek().withMaximumValue().toDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本月开始日期
|
||||
*
|
||||
* @param pattern
|
||||
* @return
|
||||
*/
|
||||
public static String monthStartDate(String pattern) {
|
||||
return new DateTime().dayOfMonth().withMinimumValue().toString(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本月开始日期
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Date monthStartDate() {
|
||||
return new DateTime().dayOfMonth().withMinimumValue().toDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本月结束日期
|
||||
*
|
||||
* @param pattern
|
||||
* @return
|
||||
*/
|
||||
public static String monthEndDate(String pattern) {
|
||||
return new DateTime().dayOfMonth().withMaximumValue().toString(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本月结束日期
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Date monthEndDate() {
|
||||
return new DateTime().dayOfMonth().withMaximumValue().toDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期
|
||||
*
|
||||
* @param parseLong
|
||||
* @param format
|
||||
* @return
|
||||
*/
|
||||
public static String formatDate(long parseLong, String format) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
|
||||
String date;
|
||||
try {
|
||||
date = simpleDateFormat.format(new Date(parseLong));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取前几天的日期,带格式
|
||||
*
|
||||
* @param day
|
||||
* @param format
|
||||
* @return
|
||||
*/
|
||||
public static String getBeforeDate(int day, String format) {
|
||||
DateTime time = new DateTime().plusDays(-day);
|
||||
return sdfDay.format(time.toDate());
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算时间差
|
||||
*
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @param format
|
||||
* @return
|
||||
*/
|
||||
public static long getTimeConsuming(String startTime, String endTime, String format) throws ParseException {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
|
||||
long start = simpleDateFormat.parse(startTime).getTime();
|
||||
long end = simpleDateFormat.parse(endTime).getTime();
|
||||
long useTime = end - start;
|
||||
return useTime < 0 ? 0 : useTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算年龄
|
||||
*
|
||||
* @param birthday yyyy-MM-dd
|
||||
* @return
|
||||
*/
|
||||
public static int getAgeByBirthday(String birthday) {
|
||||
int age = 0;
|
||||
String[] days = getDay().split("-");
|
||||
String[] births = birthday.split("-");
|
||||
int year = Integer.parseInt(days[0]);
|
||||
int birthYear = Integer.parseInt(births[0]);
|
||||
int month = Integer.parseInt(days[1]);
|
||||
int birthMonth = Integer.parseInt(births[1]);
|
||||
int day = Integer.parseInt(days[2]);
|
||||
int birthDay = Integer.parseInt(births[2]);
|
||||
// 判断年龄是否相等
|
||||
if (year - birthYear > 0) {
|
||||
if (month - birthMonth > 0) {
|
||||
return year - birthYear;
|
||||
} else if (month - birthMonth == 0) {
|
||||
if (day - birthDay > 0) {
|
||||
return year - birthYear;
|
||||
}
|
||||
return year - birthYear - 1;
|
||||
}
|
||||
return year - birthYear - 1;
|
||||
}
|
||||
return age;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得上下午标识
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getAmPm() {
|
||||
DateTime dateTime = new DateTime();
|
||||
int hour = dateTime.getHourOfDay();
|
||||
if (hour < 13) {
|
||||
return AM;
|
||||
}
|
||||
return PM;
|
||||
}
|
||||
}
|
124
src/main/java/ink/wgink/gateway/util/ReflectUtil.java
Normal file
124
src/main/java/ink/wgink/gateway/util/ReflectUtil.java
Normal file
@ -0,0 +1,124 @@
|
||||
package ink.wgink.gateway.util;
|
||||
|
||||
import ink.wgink.gateway.pojo.pos.route.RoutePO;
|
||||
import ink.wgink.gateway.pojo.vos.route.RouteVO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: ReflectUtil
|
||||
* @Description: 反射工具
|
||||
* @Author: WangGeng
|
||||
* @Date: 2021/2/25 20:10
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class ReflectUtil {
|
||||
|
||||
/**
|
||||
* 获取单例对象
|
||||
*
|
||||
* @param className 完整类路径
|
||||
* @param superClass 父级类或接口,没有就是当前类
|
||||
* @param <T>
|
||||
* @return
|
||||
* @throws ReflectException
|
||||
*/
|
||||
public static <T> T getSingleInstance(String className, Class<T> superClass) throws ReflectException {
|
||||
return getSingleInstance(className, superClass, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单例对象
|
||||
*
|
||||
* @param className 完整类路径
|
||||
* @param superClass 父级类或接口,没有就是当前类
|
||||
* @param getInstanceMethodName 单例方法名,默认 getInstance
|
||||
* @param <T>
|
||||
* @return
|
||||
* @throws ReflectException
|
||||
*/
|
||||
public static <T> T getSingleInstance(String className, Class<T> superClass, String getInstanceMethodName) throws ReflectException {
|
||||
if (className == null) {
|
||||
throw new ReflectException("className 不能为空");
|
||||
}
|
||||
if (superClass == null) {
|
||||
throw new ReflectException("superClass 不能为空");
|
||||
}
|
||||
Object singleInstanceObject = null;
|
||||
try {
|
||||
Class clazz = Class.forName(className);
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
if (StringUtils.equals(method.getName(), StringUtils.isBlank(getInstanceMethodName) ? "getInstance" : getInstanceMethodName)) {
|
||||
singleInstanceObject = method.invoke(null);
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException e) {
|
||||
throw new ReflectException(e.getMessage(), e);
|
||||
}
|
||||
if (singleInstanceObject == null) {
|
||||
throw new ReflectException("非单例对象");
|
||||
}
|
||||
return (T) singleInstanceObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* bean转bean,相同属性的值可以相互复制
|
||||
*
|
||||
* @param srcBean 源bean
|
||||
* @param destBeanClass 转换后的bean类
|
||||
* @param <T>
|
||||
* @return
|
||||
* @throws ReflectException
|
||||
*/
|
||||
public static <T> T beanToBean(Object srcBean, Class<T> destBeanClass) throws ReflectException {
|
||||
try {
|
||||
Field[] srcFieldArray = srcBean.getClass().getDeclaredFields();
|
||||
Field[] destFieldArray = destBeanClass.getDeclaredFields();
|
||||
T t = destBeanClass.newInstance();
|
||||
for (Field field : srcFieldArray) {
|
||||
for (Field destField : destFieldArray) {
|
||||
String destFieldName = destField.getName();
|
||||
if (!StringUtils.equals(field.getName(), destFieldName)) {
|
||||
continue;
|
||||
}
|
||||
String firstLetter = destFieldName.substring(0, 1).toUpperCase();
|
||||
String firstUpperMethodName = firstLetter + destFieldName.substring(1, destFieldName.length());
|
||||
Method getMethod = srcBean.getClass().getMethod("get" + firstUpperMethodName);
|
||||
Object value = getMethod.invoke(srcBean);
|
||||
Method setMethod = destBeanClass.getMethod("set" + firstUpperMethodName, value.getClass());
|
||||
setMethod.invoke(t, value);
|
||||
}
|
||||
}
|
||||
return t;
|
||||
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||
throw new ReflectException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ReflectException extends ReflectiveOperationException {
|
||||
|
||||
public ReflectException() {
|
||||
}
|
||||
|
||||
public ReflectException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ReflectException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ReflectException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
20
src/main/java/ink/wgink/gateway/util/UUIDUtil.java
Normal file
20
src/main/java/ink/wgink/gateway/util/UUIDUtil.java
Normal file
@ -0,0 +1,20 @@
|
||||
package ink.wgink.gateway.util;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* UuidUtil
|
||||
*
|
||||
* @author WangGeng
|
||||
*/
|
||||
public class UUIDUtil {
|
||||
|
||||
public static String getUUID() {
|
||||
return UUID.randomUUID().toString().trim();
|
||||
}
|
||||
|
||||
public static String get32UUID() {
|
||||
return getUUID().replaceAll("-", "");
|
||||
}
|
||||
|
||||
}
|
@ -4,3 +4,11 @@ spring:
|
||||
cloud:
|
||||
gateway:
|
||||
enabled: true
|
||||
data:
|
||||
mongodb:
|
||||
uri: mongodb://127.0.0.1:27017/gateway
|
||||
|
||||
logging:
|
||||
level:
|
||||
org: debug
|
||||
ink.wgink: debug
|
10
src/main/resources/static/route/list.html
Normal file
10
src/main/resources/static/route/list.html
Normal file
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello Gateway</h1>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user