master
chenjf 2 years ago
parent f38513a7d1
commit b67ea7362f

@ -12,6 +12,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<z.common.version>1.0.0-SNAPSHOT</z.common.version>
</properties>
<parent>
@ -21,118 +22,29 @@
<relativePath/>
</parent>
<dependencies>
<!-- Z common redis依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<groupId>com.z.common</groupId>
<artifactId>z-common-redis</artifactId>
<version>${z.common.version}</version>
</dependency>
<!-- Z common rabbitmq 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<groupId>com.z.common</groupId>
<artifactId>z-common-rabbitmq</artifactId>
<version>${z.common.version}</version>
</dependency>
<!--hutool-->
<!-- Z common swagger 依赖 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.0</version>
<groupId>com.z.common</groupId>
<artifactId>z-common-swagger</artifactId>
<version>${z.common.version}</version>
</dependency>
<!-- Lombok -->
<!-- Z common core 依赖 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!--swagger2-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
<!--fastjson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
<!--redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.6.6</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>
<!--mybatisplus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!--druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.22</version>
</dependency>
<!--aop-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.6.6</version>
</dependency>
<!--文件操作-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.17</version>
</dependency>
<!--rabbitmq-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>2.6.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.6.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!--httpclient-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.9</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.1.4</version>
<groupId>com.z.common</groupId>
<artifactId>z-common-core</artifactId>
<version>${z.common.version}</version>
</dependency>
</dependencies>
<build>

@ -7,43 +7,6 @@ ils 订单服务
- ## 接口文档地址
- http://127.0.0.1:9097/doc.html
## 开发说明和约定
- ## mybatis-plus 插件使用方法
- 实现下面方法即可
- @Mapper
public interface XXXMapper extends BaseMapper<XXXEntity> {
}
- 如果需要自定义需要同时新增接口和xml方法
- ## JwtUtil
- token工具类
- ## TokenAnnotation 接口注解拦截
- 在需要拦截的controller 加上注解@TokenAnnotation(description = "备注")即可
- ## IdGeneratorUtil 插件说明
- String batchId(String prefix) -- 生成递增批次号 prefix + 12位数字
- long snowflakeId() -- 雪花算法唯一id
- ## RedisUtil
- redis工具类
- ## hutool 工具类
- 一个Java基础工具类对文件、流、加密解密、转码、正则、线程、XML等JDK方法进行封装组成各种Util工具类同时提供以下组件
- 模块 介绍
- hutool-aop JDK动态代理封装提供非IOC下的切面支持
- hutool-bloomFilter 布隆过滤提供一些Hash算法的布隆过滤
- hutool-cache 简单缓存实现
- hutool-core 核心包括Bean操作、日期、各种Util等
- hutool-cron 定时任务模块提供类Crontab表达式的定时任务
- hutool-crypto 加密解密模块,提供对称、非对称和摘要算法封装
- hutool-db JDBC封装后的数据操作基于ActiveRecord思想
- hutool-dfa 基于DFA模型的多关键字查找
- hutool-extra 扩展模块对第三方封装模板引擎、邮件、Servlet、二维码、Emoji、FTP、分词等
- hutool-http 基于HttpUrlConnection的Http客户端封装
- hutool-log 自动识别日志实现的日志门面
- hutool-script 脚本执行封装例如Javascript
- hutool-setting 功能更强大的Setting配置文件和Properties封装
- hutool-system 系统参数调用封装JVM信息等
- hutool-json JSON实现
- hutool-captcha 图片验证码实现
- hutool-poi 针对POI中Excel和Word的封装
- hutool-socket 基于Java的NIO和AIO的Socket封装
- hutool-jwt JSON Web Token (JWT)封装实现
可以根据需求对每个模块单独引入也可以通过引入hutool-all方式引入所有模块。
- ## 开发使用规范
-

@ -1,13 +1,25 @@
package org.ils.order;
import com.z.common.configuration.exception.ZGlobalExceptionHandler;
import com.z.common.configuration.rabbit.ZRabbitAutoConfiguration;
import com.z.common.configuration.redis.ZRedisAutoConfiguration;
import com.z.common.swagger.ZSwagger2Configuration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
/**
*
* @author chenjf
*/
@SpringBootApplication
@Import(value = {
ZSwagger2Configuration.class,
ZRedisAutoConfiguration.class,
ZRabbitAutoConfiguration.class,
ZGlobalExceptionHandler.class
})
public class IlsOrderServiceApplication {
public static void main(String[] args) {
SpringApplication.run(IlsOrderServiceApplication.class, args);

@ -1,34 +0,0 @@
package org.ils.order.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import java.util.Collections;
@EnableTransactionManagement
@Configuration
@MapperScan("org.ils.order.mapper")
public class MyBatisPlusConfig {
@Bean
public PaginationInnerInterceptor paginationInnerInterceptor() {
PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
// 设置最大单页限制数量,默认 500 条,-1 不受限制
paginationInterceptor.setMaxLimit(-1L);
paginationInterceptor.setDbType(DbType.MYSQL);
// 开启 count 的 join 优化,只针对部分 left join
paginationInterceptor.setOptimizeJoin(true);
return paginationInterceptor;
}
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
mybatisPlusInterceptor.setInterceptors(Collections.singletonList(paginationInnerInterceptor()));
return mybatisPlusInterceptor;
}
}

@ -1,46 +0,0 @@
package org.ils.order.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.net.UnknownHostException;
/**
* @author chenjf
*/
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory)
throws UnknownHostException {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
//Json序列化配置
//注意:SpringBoot默认的redis序列化方式是jdk序列化有兴趣可以看默认RedisTemplate源码
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance,ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
jackson2JsonRedisSerializer.setObjectMapper(om);
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
//key采用string的序列化方式
template.setKeySerializer(stringRedisSerializer);
//hash的key也采用string的序列化方式
template.setHashKeySerializer(stringRedisSerializer);
//value序列化方式采用jackson
template.setValueSerializer(stringRedisSerializer);
//hash的value序列化方式采用jackson
template.setHashValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
}

@ -1,61 +0,0 @@
package org.ils.order.config;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
/**
* restTemplate
* @author chenjf
*/
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate(httpRequestFactory());
}
@Bean
public ClientHttpRequestFactory httpRequestFactory() {
return new HttpComponentsClientHttpRequestFactory(httpClient());
}
@Bean
public HttpClient httpClient() {
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", SSLConnectionSocketFactory.getSocketFactory())
.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
//设置整个连接池最大连接数
connectionManager.setMaxTotal(400);
//路由是对maxTotal的细分
connectionManager.setDefaultMaxPerRoute(100);
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(3000) //返回数据的超时时间
.setConnectTimeout(2000) //连接上服务器的超时时间
.setConnectionRequestTimeout(1000) //从连接池中获取连接的超时时间
.build();
return HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setConnectionManager(connectionManager)
.build();
}
}

@ -1,70 +0,0 @@
package org.ils.order.config;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
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;
/**
*
* @author chenjf
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
//配置了 Swagger 的Docket的bean实例
@Bean
public Docket docket(){
ParameterBuilder ticketPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<>();
ticketPar.name("Authorization").description("token")
.modelRef(new ModelRef("string")).parameterType("header")
.required(false).build();
pars.add(ticketPar.build());
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//RequestHandlerSelectors, 配置要扫描接口的方式
//basePackage:指定要扫描的包
//any():扫描全部
//withClassAnnotation: 扫描类上的注解
//withMethodAnnotation: 扫描方法上的注解
.apis(RequestHandlerSelectors.basePackage("org.ils.order"))
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build()
.globalOperationParameters(pars);
}
//配置Swagger 信息=apiInfo
private ApiInfo apiInfo(){
return new ApiInfo(
"ils engine Api",
"ils 订单服务接口文档",
"v1.0",
"127.0.0.1:9097/",
null,//contact
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList()
);
}
}

@ -10,7 +10,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");

@ -0,0 +1,26 @@
package org.ils.order.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.ils.order.dto.dto.MainLinePageDto;
import org.ils.order.result.Result;
import org.ils.order.service.impl.MainLineServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/v1/main/line/")
@Slf4j
@Api(value = "ils 测试接口", tags = {"测试接口"})
public class MainLineController {
@Autowired
private MainLineServiceImpl mainLineService;
@ApiOperation("查询列表")
@RequestMapping(value = "list", method = RequestMethod.POST)
public Result list(@RequestBody MainLinePageDto record){
return (Result) mainLineService.list(record);
}
}

@ -1,7 +1,7 @@
package org.ils.order.listener.rabbitmq;
import org.ils.order.properties.BaseConfigProperties;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -12,17 +12,30 @@ import org.springframework.context.annotation.Configuration;
* @datetime 2023/08/09
*/
@Configuration
public class RabbitQueue {
public class RabbitQueueConfig {
@Autowired
private BaseConfigProperties baseConfig;
private final static String EVENT = "events.";
@Bean
public FanoutExchange OrderExchange() {
return new FanoutExchange ( EVENT + baseConfig.getOrderQueue(), true, false);
}
/**
*
*/
@Bean
public Queue IlsOrderQueue() {
return new Queue(baseConfig.getIlsOrderQueue());
return new Queue(baseConfig.getOrderQueue());
}
@Bean
public Binding OrderBinding() {
return BindingBuilder.bind(IlsOrderQueue()).to(OrderExchange());
}
}

@ -1,6 +1,7 @@
package org.ils.order.listener.rabbitmq;
import com.z.common.mq.EventMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
@ -13,10 +14,10 @@ import org.springframework.stereotype.Component;
*/
@Slf4j
@Component
@RabbitListener(queues = "${spring.rabbitmq.queue.orderQueue}")
@RabbitListener(queues = "${spring.rabbitmq.queues.orderQueue}")
public class RabbitReceiver {
@RabbitHandler
public void process(String json) {
log.info("Receiver: {}", json);
public void process(EventMessage message) {
log.info("Receiver: {}", message.getPayload());
}
}

@ -1,5 +1,6 @@
package org.ils.order.listener.rabbitmq;
import com.z.common.mq.EventPublisher;
import org.ils.order.properties.BaseConfigProperties;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
@ -14,16 +15,15 @@ import org.springframework.stereotype.Component;
@Component
public class RabbitSender {
@Autowired
private AmqpTemplate rabbitTemplate;
private EventPublisher eventPublisher;
@Autowired
private BaseConfigProperties baseConfig ;
/**
*
* @param queueName
* @param exChangeName
* @param json json
*/
public void sendOrderQueue(String queueName,String json) {
this.rabbitTemplate.convertAndSend(queueName, json);
public void sendOrderQueue(String exChangeName,String json) {
this.eventPublisher.publish( exChangeName, json);
}
}

@ -12,8 +12,9 @@ import org.springframework.stereotype.Component;
@Component
@Data
public class BaseConfigProperties {
@Value("${spring.rabbitmq.queue.orderQueue}")
private String ilsOrderQueue;
@Value("${spring.rabbitmq.queues.orderQueue}")
private String orderQueue;
@Value("${ils.other.host.baiduUrl}")
private String baiduUrl;

@ -39,4 +39,6 @@ public interface MainLineService<T> {
* @return
*/
public T list(MainLinePageDto model);
void test();
}

@ -3,6 +3,7 @@ package org.ils.order.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.z.common.util.RedisUtils;
import lombok.extern.slf4j.Slf4j;
@ -27,7 +28,8 @@ public class MainLineServiceImpl implements org.ils.order.service.impl.MainLineS
@Autowired
private IlsMainLineMapper ilsMainLineMapper;
@Autowired
private RedisUtils redisUtils;
@Override
public Result add(Object model) {
@ -55,4 +57,9 @@ public class MainLineServiceImpl implements org.ils.order.service.impl.MainLineS
IPage<IlsMainLine> pageList = ilsMainLineMapper.selectPage(page, queryWrapper);
return Result.OK("success", pageList);
}
@Override
public void test(){
log.info("redis: {}", redisUtils.get("CUS_MODEL_CUS202308031001_CHA202308031001"));
}
}

@ -1,431 +0,0 @@
package org.ils.order.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* @author chenjf
* @datetime 2023/07/27
*/
@Component
public class RedisUtil {
@Autowired
private RedisTemplate<String, Object> redisTemplate;
/**
* @param key @param time () @return
*/
public boolean expire(String key, long time) {
try {
if (time > 0) {
redisTemplate.expire(key, time, TimeUnit.SECONDS);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* key @param key null @return () 0
*/
public long getExpire(String key) {
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
}
/**
* key @param key @return true false
*/
public boolean hasKey(String key) {
try {
return redisTemplate.hasKey(key);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* @param key
*/
@SuppressWarnings("unchecked")
public void del(String... key) {
if (key != null && key.length > 0) {
if (key.length ==0) {
redisTemplate.delete(key[0]);
} else {
redisTemplate.delete((Collection<String>) CollectionUtils.arrayToList(key));
}
}
}
/**
* @param key @return
*/
public Object get(String key) {
return key == null ? null : redisTemplate.opsForValue().get(key);
}
/**
* @param key @param value @return true false
*/
public boolean set(String key, Object value) {
try {
redisTemplate.opsForValue().set(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* @param key @param value @param time () time0 time0 @return true false
*/
public boolean set(String key, Object value, long time) {
try {
if (time > 0) {
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
} else {
set(key, value);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* @param key @param delta (0) @return
*/
public long incr(String key, long delta) {
if (delta < 0) {
throw new RuntimeException("递增因子必须大于0");
}
return redisTemplate.opsForValue().increment(key, delta);
}
/**
* @param key @param delta (0) @return
*/
public long decr(String key, long delta) {
if (delta < 0) {
throw new RuntimeException("递减因子必须大于0");
}
return redisTemplate.opsForValue().increment(key, -delta);
}
/* ================================Map=================================*/
/**
* HashGet @param key null @param item null @return
*/
public Object hget(String key, String item) {
return redisTemplate.opsForHash().get(key, item);
}
/**
* hashKey @param key @return
*/
public Map<Object, Object> hmget(String key) {
return redisTemplate.opsForHash().entries(key);
}
/**
* HashSet @param key @param map @return true false
*/
public boolean hmset(String key, Map<String, Object> map) {
try {
redisTemplate.opsForHash().putAll(key, map);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* HashSet @param key @param map @param time () @return true false
*/
public boolean hmset(String key, Map<String, Object> map, long time) {
try {
redisTemplate.opsForHash().putAll(key, map);
if (time > 0) {
expire(key, time);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* hash, @param key @param item @param value @return true false
*/
public boolean hset(String key, String item, Object value) {
try {
redisTemplate.opsForHash().put(key, item, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* hash, @param key @param item @param value @param time () :hash, @return true false
*/
public boolean hset(String key, String item, Object value, long time) {
try {
redisTemplate.opsForHash().put(key, item, value);
if (time > 0) {
expire(key, time);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* hash @param key null @param item 使 null
*/
public void hdel(String key, Object... item) {
redisTemplate.opsForHash().delete(key, item);
}
/**
* hash @param key null @param item null @return true false
*/
public boolean hHasKey(String key, String item) {
return redisTemplate.opsForHash().hasKey(key, item);
}
/**
* hash , @param key @param item @param by (0) @return
*/
public double hincr(String key, String item, double by) {
return redisTemplate.opsForHash().increment(key, item, by);
}
/**
* hash @param key @param item @param by (0) @return
*/
public double hdecr(String key, String item, double by) {
return redisTemplate.opsForHash().increment(key, item, -by);
}
/**
* keySet @param key @return
*/
public Set<Object> sGet(String key) {
try {
return redisTemplate.opsForSet().members(key);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* valueset, @param key @param value @return true false
*/
public boolean sHasKey(String key, Object value) {
try {
return redisTemplate.opsForSet().isMember(key, value);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* set @param key @param values @return
*/
public long sSet(String key, Object... values) {
try {
return redisTemplate.opsForSet().add(key, values);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
/**
* set @param key @param time () @param values @return
*/
public long sSetAndTime(String key, long time, Object... values) {
try {
Long count = redisTemplate.opsForSet().add(key, values);
if (time > 0) {
expire(key, time);
}
return count;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
/**
* set @param key @return
*/
public long sGetSetSize(String key) {
try {
return redisTemplate.opsForSet().size(key);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
/**
* value @param key @param values @return
*/
public long setRemove(String key, Object... values) {
try {
return redisTemplate.opsForSet().remove(key, values);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
/* ===============================list=================================*/
/**
* list @param key @param start @param end 0 - @return
*/
public List<Object> lGet(String key, long start, long end) {
try {
return redisTemplate.opsForList().range(key, start, end);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* list @param key @return
*/
public long lGetListSize(String key) {
try {
return redisTemplate.opsForList().size(key);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
/**
* list @param key @param index index>=0 0 index<0-- @return
*/
public Object lGetIndex(String key, long index) {
try {
return redisTemplate.opsForList().index(key, index);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* list @param key @param value @param time () @return
*/
public boolean lSet(String key, Object value) {
try {
redisTemplate.opsForList().rightPush(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* list @param key @param value @param time () @return
*/
public boolean lSet(String key, Object value, long time) {
try {
redisTemplate.opsForList().rightPush(key, value);
if (time > 0) {
expire(key, time);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* list @param key @param value @param time () @return
*/
public boolean lSet(String key, List<Object> value) {
try {
redisTemplate.opsForList().rightPushAll(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* list @param key @param value @param time () @return
*/
public boolean lSet(String key, List<Object> value, long time) {
try {
redisTemplate.opsForList().rightPushAll(key, value);
if (time > 0) {
expire(key, time);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* list @param key @param index @param value @return
*/
public boolean lUpdateIndex(String key, long index, Object value) {
try {
redisTemplate.opsForList().set(key, index, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* Nvalue @param key @param count @param value @return
*/
public long lRemove(String key, long count, Object value) {
try {
Long remove = redisTemplate.opsForList().remove(key, count, value);
return remove;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
}

@ -3,13 +3,13 @@ server:
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
matching-strategy: ANT_PATH_MATCHER
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
datasource:
url: jdbc:mysql://127.0.0.1:3306/ils_order?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&AllowPublicKeyRetrieval=True&useSSL=false
url: jdbc:mysql://127.0.0.1:3306/ils_engine?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&AllowPublicKeyRetrieval=True&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
@ -49,7 +49,6 @@ spring:
max-wait: 10000 #最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。
min-idle: 0 #最小等待连接中的数量,设 0 为没有限制
shutdown-timeout: 100ms
password: ''
port: 6379
# rabbitmq 配置
rabbitmq:
@ -73,7 +72,7 @@ spring:
simple:
acknowledge-mode: auto
# 配置rabbitmq队列
queue:
queues:
orderQueue: ilsOrderQueue #订单队列
# mybatis-plus 配置
mybatis-plus:
@ -94,6 +93,16 @@ ils:
other:
host:
baiduUrl: https://www.baidu.com
# swagger 配置
swagger:
enabled: true
title: ils 订单接口api
description: ils订单接口文档
name: ils订单接口文档
url: 127.0.0.1:9097/
version: v1.0
pkg: org.ils
email: 123qq.com

@ -25,7 +25,7 @@ public class RabbitMqHelloTest{
JSONObject json = new JSONObject();
json.put("userName","test123");
json.put("passWord","123456");
rabbitSender.sendOrderQueue(baseConfig.getIlsOrderQueue(), JSON.toJSONString(json));
rabbitSender.sendOrderQueue( baseConfig.getOrderQueue(), JSON.toJSONString(json));
log.info( "send: {}", true);
}
}

@ -1,45 +1,42 @@
package org.ils.order;
import com.alibaba.fastjson.JSONObject;
import com.z.common.util.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.ils.order.dto.dto.MainLinePageDto;
import org.ils.order.properties.BaseConfigProperties;
import org.ils.order.result.Result;
import org.ils.order.service.impl.MainLineServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class RestTemplateTest {
@Autowired
private RestTemplate restTemplate;
@Autowired
private BaseConfigProperties baseConfig;
@Test
public void test(){
log.info("url :{}", baseConfig.getBaiduUrl());
String content = restTemplate.getForObject( baseConfig.getBaiduUrl(), String.class);
log.info("get content :{}", content);
JSONObject param = new JSONObject();
param.put("alarmType", 2);
param.put("optType", 2);
param.put("optDesc", "自动处理");
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type","application/json;charset=UTF-8");
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
HttpEntity<String> formEntity = new HttpEntity<String>(param.toString(),headers);
ResponseEntity<JSONObject> response2 = restTemplate.postForEntity( baseConfig.getBaiduUrl(), formEntity, JSONObject.class);
log.info("response2--->{}",response2.getBody());
@Autowired
private MainLineServiceImpl mainLineServiceImpl;
public void test(){
mainLineServiceImpl.test();
}
@Test
public void test2(){
MainLinePageDto mainLinePageDto = new MainLinePageDto();
mainLinePageDto.setPageNo(1);
mainLinePageDto.setPageSize(10);
mainLinePageDto.setMainLineName("MAI202308021001");
Result list = mainLineServiceImpl.list(mainLinePageDto);
log.info(list.toString());
}
}
Loading…
Cancel
Save