init
						commit
						1b56968717
					
				| @ -0,0 +1,15 @@ | ||||
| package org.ils.order; | ||||
| 
 | ||||
| import org.springframework.boot.SpringApplication; | ||||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||
| 
 | ||||
| /** | ||||
|  * 主程序 | ||||
|  * @author chenjf | ||||
|  */ | ||||
| @SpringBootApplication | ||||
| public class IlsOrderServiceApplication { | ||||
|     public static void main(String[] args) { | ||||
|         SpringApplication.run(IlsOrderServiceApplication.class, args); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,15 @@ | ||||
| package org.ils.order.annotation; | ||||
| 
 | ||||
| import java.lang.annotation.*; | ||||
| 
 | ||||
| /** | ||||
|  * token 全局拦截注解 | ||||
|  * @author chenjf | ||||
|  */ | ||||
| 
 | ||||
| @Target({ElementType.PARAMETER, ElementType.METHOD}) | ||||
| @Retention(RetentionPolicy.RUNTIME) | ||||
| @Documented | ||||
| public @interface TokenAnnotation { | ||||
|     String description()  default ""; | ||||
| } | ||||
| @ -0,0 +1,57 @@ | ||||
| package org.ils.order.aspect; | ||||
| 
 | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.aspectj.lang.JoinPoint; | ||||
| import org.aspectj.lang.annotation.Aspect; | ||||
| import org.aspectj.lang.annotation.Before; | ||||
| import org.aspectj.lang.annotation.Pointcut; | ||||
| import org.ils.order.result.GlobalException; | ||||
| import org.ils.order.result.JwtVerifyResult; | ||||
| import org.ils.order.utils.CommonConstant; | ||||
| import org.ils.order.utils.JwtUtil; | ||||
| import org.ils.order.utils.SpringContextUtils; | ||||
| import org.springframework.stereotype.Component; | ||||
| 
 | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| 
 | ||||
| /** | ||||
|  * token 全局拦截处理 | ||||
|  */ | ||||
| @Slf4j | ||||
| @Aspect | ||||
| @Component | ||||
| public class TokenAspect { | ||||
|     //controller层切点
 | ||||
|     @Pointcut("@annotation(org.ils.order.annotation.TokenAnnotation)") | ||||
|     public  void TokenAspect() { | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 前置通知 用于拦截Controller层记录用户的操作 | ||||
|      * | ||||
|      * @param joinPoint 切点 | ||||
|      */ | ||||
|     @Before("TokenAspect()") | ||||
|     public  void doBeforeControl(JoinPoint joinPoint) throws GlobalException { | ||||
|         try { | ||||
|             log.info("Execute Controller: {}.{}()", joinPoint.getTarget().getClass().getName(), joinPoint.getSignature().getClass()); | ||||
|             //获取request
 | ||||
|             HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); | ||||
|             String token = request.getHeader(CommonConstant.ACCESS_TOKEN).toString(); | ||||
|             log.info("token: {}", token); | ||||
|             JwtVerifyResult jwtVerifyResult = JwtUtil.validateToken(token); | ||||
|             if(!jwtVerifyResult.getSuccess()){ | ||||
|                 log.error("验证失败:"+jwtVerifyResult.toString()); | ||||
|                 throw  new GlobalException(CommonConstant.ACCESS_TOKEN + "错误" ); | ||||
|             } | ||||
|         }  catch (Exception e) { | ||||
|             StringBuilder sb = new StringBuilder(); | ||||
|             sb.append(CommonConstant.ACCESS_TOKEN ); | ||||
|             sb.append("  error:  " ); | ||||
|             sb.append(e.getMessage() ); | ||||
|             log.error("{} ", sb.toString()); | ||||
|             throw  new GlobalException(sb.toString()); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,20 @@ | ||||
| package org.ils.order.config; | ||||
| 
 | ||||
| import lombok.Data; | ||||
| import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.stereotype.Component; | ||||
| 
 | ||||
| /** | ||||
|  * 系统获取yml基本参数 | ||||
|  * @author chenjf | ||||
|  * @datetime 2023/08/09 | ||||
|  */ | ||||
| @Component | ||||
| @Data | ||||
| public class BaseConfig { | ||||
|     @Value("${spring.rabbitmq.queue.orderQueue}") | ||||
|     private String ilsOrderQueue; | ||||
| 
 | ||||
|     @Value("${ils.other.host.baiduUrl}") | ||||
|     private String baiduUrl; | ||||
| } | ||||
| @ -0,0 +1,34 @@ | ||||
| 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; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,46 @@ | ||||
| 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; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,61 @@ | ||||
| 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(); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,70 @@ | ||||
| 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() | ||||
|         ); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,24 @@ | ||||
| package org.ils.order.config; | ||||
| 
 | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||||
| 
 | ||||
| /** | ||||
|  * @author chenjf | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| @Configuration | ||||
| public class WebMvcConfig  implements WebMvcConfigurer { | ||||
|     @Override | ||||
|     public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||||
|         registry.addResourceHandler("/**").addResourceLocations("classpath:/static/"); | ||||
|         registry.addResourceHandler("swagger-ui.html") | ||||
|                 .addResourceLocations("classpath:/META-INF/resources/"); | ||||
|         registry.addResourceHandler("/webjars/**") | ||||
|                 .addResourceLocations("classpath:/META-INF/resources/webjars/"); | ||||
|         registry.addResourceHandler("doc.html") | ||||
|                 .addResourceLocations("classpath:/META-INF/resources/"); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,27 @@ | ||||
| package org.ils.order.entity; | ||||
| 
 | ||||
| import com.baomidou.mybatisplus.annotation.FieldFill; | ||||
| import com.baomidou.mybatisplus.annotation.TableField; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | ||||
| 
 | ||||
| import java.io.Serializable; | ||||
| 
 | ||||
| @Data | ||||
| public class BaseEntity implements Serializable { | ||||
|     @TableField(fill = FieldFill.INSERT) | ||||
|     @ApiModelProperty(value = "创建时间") | ||||
|     private Long createTime; | ||||
| 
 | ||||
|     @TableField(fill = FieldFill.INSERT) | ||||
|     @ApiModelProperty(value = "创建人") | ||||
|     private String createBy; | ||||
| 
 | ||||
|     @TableField(fill = FieldFill.INSERT_UPDATE) | ||||
|     @ApiModelProperty(value = "更新时间") | ||||
|     private Long updateTime; | ||||
| 
 | ||||
|     @TableField(fill = FieldFill.INSERT_UPDATE) | ||||
|     @ApiModelProperty(value = "更新人") | ||||
|     private String updateBy; | ||||
| } | ||||
| @ -0,0 +1,33 @@ | ||||
| package org.ils.order.entity; | ||||
| 
 | ||||
| 
 | ||||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Builder; | ||||
| import lombok.Data; | ||||
| 
 | ||||
| import java.io.Serializable; | ||||
| 
 | ||||
| @Data | ||||
| @Builder | ||||
| public class IlsMainLine extends  BaseEntity implements Serializable  { | ||||
| 
 | ||||
|     @JsonFormat(shape = JsonFormat.Shape.STRING) | ||||
|     @ApiModelProperty(value = "主键id",  name = "id" ) | ||||
|     private Long id; | ||||
| 
 | ||||
|     @ApiModelProperty(value = "主线模型编码",  name = "mainLineCode" ) | ||||
|     private String mainLineCode; | ||||
| 
 | ||||
|     @ApiModelProperty(value = "主线模型名称",  name = "mainLineName" ) | ||||
|     private String mainLineName; | ||||
| 
 | ||||
|     @ApiModelProperty(value = "主线模型类型(0=海运1=空运2=首重续重)",  name = "mainLineType" ) | ||||
|     private Integer mainLineType; | ||||
| 
 | ||||
|     @ApiModelProperty(value = "备注",  name = "note" ) | ||||
|     private String note; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,27 @@ | ||||
| package org.ils.order.handler; | ||||
| 
 | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.ils.order.result.Result; | ||||
| import org.springframework.web.bind.annotation.ControllerAdvice; | ||||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||||
| import org.springframework.web.bind.annotation.ResponseBody; | ||||
| 
 | ||||
| /** | ||||
|  * 全局异常捕获 | ||||
|  * @author chenjf | ||||
|  */ | ||||
| @Slf4j | ||||
| @ControllerAdvice | ||||
| public class GlobalExceptionHandler { | ||||
|     /** | ||||
|      * 处理除0异常捕获 | ||||
|      * @param exception | ||||
|      * @return | ||||
|      */ | ||||
|     @ExceptionHandler(value = Exception.class) | ||||
|     @ResponseBody | ||||
|     public Result exceptionHandler(Exception exception){ | ||||
|         log.error("exceptionHandler: {}", exception.getMessage()); | ||||
|         return Result.error(exception.getMessage()); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,36 @@ | ||||
| package org.ils.order.handler; | ||||
| 
 | ||||
| import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.ibatis.reflection.MetaObject; | ||||
| import org.springframework.stereotype.Component; | ||||
| 
 | ||||
| @Slf4j | ||||
| @Component | ||||
| public class MysqlMetaObjectHandler implements MetaObjectHandler { | ||||
| 
 | ||||
|     @Override | ||||
|     public void insertFill(MetaObject metaObject) { | ||||
|         log.info("start insert fill ...."); | ||||
|         this.strictInsertFill(metaObject, "createTime", Long.class, System.currentTimeMillis()); | ||||
|         // 或者
 | ||||
|         this.strictInsertFill(metaObject, "createTime", () -> System.currentTimeMillis(), Long.class); | ||||
|         // 或者
 | ||||
|         this.fillStrategy(metaObject, "createTime",System.currentTimeMillis()); | ||||
| 
 | ||||
|         metaObject.setValue("createBy", "admin"); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void updateFill(MetaObject metaObject) { | ||||
|         log.info("start update fill ...."); | ||||
|         this.strictUpdateFill(metaObject, "updateTime", Long.class,System.currentTimeMillis()); | ||||
|         // 或者
 | ||||
|         this.strictUpdateFill(metaObject, "updateTime", () -> System.currentTimeMillis(), Long.class); | ||||
|         // 或者
 | ||||
|         this.fillStrategy(metaObject, "updateTime", System.currentTimeMillis()); | ||||
| 
 | ||||
|         metaObject.setValue("updateBy", "admin1"); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,11 @@ | ||||
| package org.ils.order.mapper; | ||||
| 
 | ||||
| 
 | ||||
| import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
| import org.ils.order.entity.IlsMainLine; | ||||
| 
 | ||||
| 
 | ||||
| @Mapper | ||||
| public interface IlsMainLineMapper extends BaseMapper<IlsMainLine> { | ||||
| } | ||||
| @ -0,0 +1,16 @@ | ||||
| package org.ils.order.model.DTO; | ||||
| 
 | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | ||||
| 
 | ||||
| import java.io.Serializable; | ||||
| 
 | ||||
| @Data | ||||
| public class BasePageDto implements Serializable { | ||||
| 
 | ||||
|     @ApiModelProperty(value = "当前页",  name = "pageNo" ,  required = true) | ||||
|     private Integer pageNo; | ||||
| 
 | ||||
|     @ApiModelProperty(value = "分页大小",  name = "pageSize" ,  required = true) | ||||
|     private Integer pageSize; | ||||
| } | ||||
| @ -0,0 +1,21 @@ | ||||
| package org.ils.order.model.DTO; | ||||
| 
 | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Builder; | ||||
| import lombok.Data; | ||||
| 
 | ||||
| import java.io.Serializable; | ||||
| 
 | ||||
| @Data | ||||
| @Builder | ||||
| public class MainLineDto implements Serializable { | ||||
| 
 | ||||
|     @ApiModelProperty(value = "主线模型名称",  name = "mainLineName" ,  required = true) | ||||
|     private String mainLineName; | ||||
| 
 | ||||
|     @ApiModelProperty(value = "主线模型类型(0=海运1=空运2=首重续重)",  name = "mainLineType" ,  required = true) | ||||
|     private Integer mainLineType; | ||||
| 
 | ||||
|     @ApiModelProperty(value = "备注",  name = "note" ,  required = true) | ||||
|     private String note; | ||||
| } | ||||
| @ -0,0 +1,15 @@ | ||||
| package org.ils.order.model.DTO; | ||||
| 
 | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | ||||
| 
 | ||||
| import java.io.Serializable; | ||||
| 
 | ||||
| @Data | ||||
| public class MainLinePageDto extends  BasePageDto implements Serializable { | ||||
| 
 | ||||
|     @ApiModelProperty(value = "主线线模型名称",  name = "mainLineName",  required = true) | ||||
|     private String mainLineName; | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,15 @@ | ||||
| package org.ils.order.model.DTO; | ||||
| 
 | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | ||||
| 
 | ||||
| import java.io.Serializable; | ||||
| 
 | ||||
| @Data | ||||
| public class OrderPageDto extends  BasePageDto implements Serializable { | ||||
| 
 | ||||
| 
 | ||||
|     @ApiModelProperty(value = "订单编号",  name = "orderId" ,  required = true) | ||||
|     private String orderId; | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,28 @@ | ||||
| package org.ils.order.rabbitmq; | ||||
| 
 | ||||
| import org.ils.order.config.BaseConfig; | ||||
| import org.springframework.amqp.core.Queue; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| 
 | ||||
| /** | ||||
|  * rabbitmq 绑定队列 | ||||
|  * @author chenjf | ||||
|  * @datetime 2023/08/09 | ||||
|  */ | ||||
| @Configuration | ||||
| public class RabbitQueue { | ||||
| 
 | ||||
|     @Autowired | ||||
|     private BaseConfig baseConfig; | ||||
| 
 | ||||
|     /** | ||||
|      * 订单队列 | ||||
|      */ | ||||
|     @Bean | ||||
|     public Queue IlsOrderQueue() { | ||||
|         return new Queue(baseConfig.getIlsOrderQueue()); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,22 @@ | ||||
| package org.ils.order.rabbitmq; | ||||
| 
 | ||||
| 
 | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.amqp.rabbit.annotation.RabbitHandler; | ||||
| import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||||
| import org.springframework.stereotype.Component; | ||||
| 
 | ||||
| /** | ||||
|  * 订单队列接收消息 | ||||
|  * @author chenjf | ||||
|  * @datetime 2023/08/09 | ||||
|  */ | ||||
| @Slf4j | ||||
| @Component | ||||
| @RabbitListener(queues = "${spring.rabbitmq.queue.orderQueue}") | ||||
| public class RabbitReceiver { | ||||
|     @RabbitHandler | ||||
|     public void process(String json) { | ||||
|         log.info("Receiver: {}", json); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,29 @@ | ||||
| package org.ils.order.rabbitmq; | ||||
| 
 | ||||
| import org.ils.order.config.BaseConfig; | ||||
| import org.springframework.amqp.core.AmqpTemplate; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Component; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * rabbitmq 发送消息 | ||||
|  * @author chenjf | ||||
|  * @datetime 2023/08/09 | ||||
|  */ | ||||
| @Component | ||||
| public class RabbitSender { | ||||
|     @Autowired | ||||
|     private AmqpTemplate rabbitTemplate; | ||||
|     @Autowired | ||||
|     private BaseConfig baseConfig ; | ||||
| 
 | ||||
|     /** | ||||
|      *  队列发送消息 | ||||
|      * @param queueName 队列名称 | ||||
|      * @param json json字符串 | ||||
|      */ | ||||
|     public void sendOrderQueue(String queueName,String json) { | ||||
|         this.rabbitTemplate.convertAndSend(queueName, json); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,50 @@ | ||||
| package org.ils.order.result; | ||||
| 
 | ||||
| /** | ||||
|  * | ||||
|  * @describe  全局异常处理类 | ||||
|  * @author chenjf | ||||
|  * @since 2023/8/8 | ||||
|  */ | ||||
| public class GlobalException extends  Exception{ | ||||
|     private String code; | ||||
|     private String message; | ||||
| 
 | ||||
|     public GlobalException() { | ||||
|         super(); | ||||
|     } | ||||
| 
 | ||||
|     public GlobalException(String message) { | ||||
|         super(message); | ||||
|         this.message = message; | ||||
|     } | ||||
| 
 | ||||
|     public GlobalException(String code, String message) { | ||||
|         super(code + ": " + message); | ||||
|         this.code = code; | ||||
|         this.message = message; | ||||
|     } | ||||
| 
 | ||||
|     public GlobalException(String message, Throwable throwable) { | ||||
|         super(message, throwable); | ||||
|         this.message = message; | ||||
|     } | ||||
| 
 | ||||
|     public GlobalException(Throwable throwable) { | ||||
|         super(throwable); | ||||
|     } | ||||
| 
 | ||||
|     public String getCode() { | ||||
|         return code; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getMessage() { | ||||
|         return message; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return code + ": " + message; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,54 @@ | ||||
| package org.ils.order.result; | ||||
| 
 | ||||
| import java.util.Map; | ||||
| 
 | ||||
| public class JwtVerifyResult { | ||||
|     /** 1 是否成功 **/ | ||||
|     private Boolean success; | ||||
|     /** 2 返回消息 **/ | ||||
|     private String msg; | ||||
|     /** 3 jwt负载 **/ | ||||
|     private Map<String,String> payload; | ||||
| 
 | ||||
|     public JwtVerifyResult() { | ||||
|     } | ||||
| 
 | ||||
|     public JwtVerifyResult(Boolean success, String msg) { | ||||
|         this.success = success; | ||||
|         this.msg = msg; | ||||
|     } | ||||
| 
 | ||||
|     public Boolean getSuccess() { | ||||
|         return success; | ||||
|     } | ||||
| 
 | ||||
|     public void setSuccess(Boolean success) { | ||||
|         this.success = success; | ||||
|     } | ||||
| 
 | ||||
|     public String getMsg() { | ||||
|         return msg; | ||||
|     } | ||||
| 
 | ||||
|     public void setMsg(String msg) { | ||||
|         this.msg = msg; | ||||
|     } | ||||
| 
 | ||||
|     public Map<String, String> getPayload() { | ||||
|         return payload; | ||||
|     } | ||||
| 
 | ||||
|     public void setPayload(Map<String, String> payload) { | ||||
|         this.payload = payload; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return "JwtResult{" + | ||||
|                 "success=" + success + | ||||
|                 ", msg='" + msg + '\'' + | ||||
|                 ", payload=" + payload + | ||||
|                 '}'; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,152 @@ | ||||
| package org.ils.order.result; | ||||
| 
 | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | ||||
| import org.ils.order.utils.CommonConstant; | ||||
| 
 | ||||
| import java.io.Serializable; | ||||
| 
 | ||||
| /** | ||||
|  * 接口返回数据格式 | ||||
|  * @author chenjf | ||||
|  * @date 2023/07/14 | ||||
|  * @param <T> | ||||
|  */ | ||||
| @Data | ||||
| public class Result<T> implements Serializable { | ||||
| 
 | ||||
|     private static final long serialVersionUID = 1L; | ||||
| 
 | ||||
| 
 | ||||
|     @ApiModelProperty(value = "成功标志") | ||||
|     private boolean success = true; | ||||
| 
 | ||||
| 
 | ||||
|     @ApiModelProperty(value = "返回处理消息") | ||||
|     private String message = ""; | ||||
| 
 | ||||
| 
 | ||||
|     @ApiModelProperty(value = "返回代码") | ||||
|     private Integer code = CommonConstant.HTTP_CODE_200; | ||||
| 
 | ||||
| 
 | ||||
|     @ApiModelProperty(value = "返回数据对象") | ||||
|     private T result; | ||||
| 
 | ||||
| 
 | ||||
|     @ApiModelProperty(value = "时间戳") | ||||
|     private long timestamp = System.currentTimeMillis(); | ||||
| 
 | ||||
|     public Result() { | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * | ||||
|      * @param code 响应code | ||||
|      * @param message 消息 | ||||
|      */ | ||||
|     public Result(Integer code, String message) { | ||||
|         this.code = code; | ||||
|         this.message = message; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * | ||||
|      * @param message 消息 | ||||
|      */ | ||||
|     public Result<T> success(String message) { | ||||
|         this.message = message; | ||||
|         this.code = CommonConstant.HTTP_CODE_200; | ||||
|         this.success = true; | ||||
|         return this; | ||||
|     } | ||||
| 
 | ||||
|     public static<T> Result<T> ok() { | ||||
|         Result<T> r = new Result<T>(); | ||||
|         r.setSuccess(true); | ||||
|         r.setCode(CommonConstant.HTTP_CODE_200); | ||||
|         return r; | ||||
|     } | ||||
| 
 | ||||
|     public static<T> Result<T> ok(String msg) { | ||||
|         Result<T> r = new Result<T>(); | ||||
|         r.setSuccess(true); | ||||
|         r.setCode(CommonConstant.HTTP_CODE_200); | ||||
|         //Result OK(String msg)方法会造成兼容性问题 issues/I4IP3D
 | ||||
|         r.setResult((T) msg); | ||||
|         r.setMessage(msg); | ||||
|         return r; | ||||
|     } | ||||
| 
 | ||||
|     public static<T> Result<T> ok(T data) { | ||||
|         Result<T> r = new Result<T>(); | ||||
|         r.setSuccess(true); | ||||
|         r.setCode(CommonConstant.HTTP_CODE_200); | ||||
|         r.setResult(data); | ||||
|         return r; | ||||
|     } | ||||
| 
 | ||||
|     public static<T> Result<T> OK() { | ||||
|         Result<T> r = new Result<T>(); | ||||
|         r.setSuccess(true); | ||||
|         r.setCode(CommonConstant.HTTP_CODE_200); | ||||
|         return r; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public static<T> Result<T> OK(String msg) { | ||||
|         Result<T> r = new Result<T>(); | ||||
|         r.setSuccess(true); | ||||
|         r.setCode(CommonConstant.HTTP_CODE_200); | ||||
|         r.setMessage(msg); | ||||
|         r.setResult((T) msg); | ||||
|         return r; | ||||
|     } | ||||
| 
 | ||||
|     public static<T> Result<T> OK(T data) { | ||||
|         Result<T> r = new Result<T>(); | ||||
|         r.setSuccess(true); | ||||
|         r.setCode(CommonConstant.HTTP_CODE_200); | ||||
|         r.setResult(data); | ||||
|         return r; | ||||
|     } | ||||
| 
 | ||||
|     public static<T> Result<T> OK(String msg, T data) { | ||||
|         Result<T> r = new Result<T>(); | ||||
|         r.setSuccess(true); | ||||
|         r.setCode(CommonConstant.HTTP_CODE_200); | ||||
|         r.setMessage(msg); | ||||
|         r.setResult(data); | ||||
|         return r; | ||||
|     } | ||||
| 
 | ||||
|     public static<T> Result<T> error(String msg, T data) { | ||||
|         Result<T> r = new Result<T>(); | ||||
|         r.setSuccess(false); | ||||
|         r.setCode(CommonConstant.HTTP_CODE_201); | ||||
|         r.setMessage(msg); | ||||
|         r.setResult(data); | ||||
|         return r; | ||||
|     } | ||||
| 
 | ||||
|     public static<T> Result<T> error(String msg) { | ||||
|         return error(CommonConstant.HTTP_CODE_201, msg); | ||||
|     } | ||||
| 
 | ||||
|     public static<T> Result<T> error(int code, String msg) { | ||||
|         Result<T> r = new Result<T>(); | ||||
|         r.setCode(code); | ||||
|         r.setMessage(msg); | ||||
|         r.setSuccess(false); | ||||
|         return r; | ||||
|     } | ||||
| 
 | ||||
|     public Result<T> error500(String message) { | ||||
|         this.message = message; | ||||
|         this.code = CommonConstant.HTTP_CODE_500; | ||||
|         this.success = false; | ||||
|         return this; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,42 @@ | ||||
| package org.ils.order.service.impl; | ||||
| 
 | ||||
| 
 | ||||
| import org.ils.order.model.DTO.MainLineDto; | ||||
| import org.ils.order.model.DTO.MainLinePageDto; | ||||
| 
 | ||||
| /** | ||||
|  * 计费引擎主线计费主线模型接口 | ||||
|  * @author chenjf | ||||
|  */ | ||||
| public interface MainLineService<T> { | ||||
| 
 | ||||
|     /** | ||||
|      *  新增 | ||||
|      * @param model | ||||
|      * @return 返回成功结果 | ||||
|      */ | ||||
|     public T add(T model); | ||||
| 
 | ||||
|     /** | ||||
|      * 删除 | ||||
|      * @param model | ||||
|      * @return | ||||
|      */ | ||||
|     public T del(T model); | ||||
| 
 | ||||
|     /** | ||||
|      * 修改 | ||||
|      * @param id | ||||
|      * @param model | ||||
|      * @return | ||||
|      */ | ||||
|     public T edit(String id, MainLineDto model); | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * 列表 | ||||
|      * @param model | ||||
|      * @return | ||||
|      */ | ||||
|     public T list(MainLinePageDto model); | ||||
| } | ||||
| @ -0,0 +1,17 @@ | ||||
| package org.ils.order.service.impl; | ||||
| 
 | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.stereotype.Service; | ||||
| 
 | ||||
| /** | ||||
|  * 基础 service | ||||
|  * @author chenjf | ||||
|  */ | ||||
| @Slf4j | ||||
| @Service | ||||
| public class BaseService { | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,58 @@ | ||||
| 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 lombok.extern.slf4j.Slf4j; | ||||
| 
 | ||||
| 
 | ||||
| import org.ils.order.entity.IlsMainLine; | ||||
| import org.ils.order.mapper.IlsMainLineMapper; | ||||
| import org.ils.order.model.DTO.MainLineDto; | ||||
| import org.ils.order.model.DTO.MainLinePageDto; | ||||
| import org.ils.order.result.Result; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * 计费引擎主线计费规则属性接口 | ||||
|  * @author chenjf | ||||
|  */ | ||||
| @Slf4j | ||||
| @Service | ||||
| public class MainLineServiceImpl implements org.ils.order.service.impl.MainLineService { | ||||
| 
 | ||||
|     @Autowired | ||||
|     private IlsMainLineMapper ilsMainLineMapper; | ||||
| 
 | ||||
| 
 | ||||
|     @Override | ||||
|     public Result add(Object model) { | ||||
| 
 | ||||
|         return Result.OK("success", null); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Result del(Object model) { | ||||
| 
 | ||||
|         return Result.OK("success", null); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Result edit(String id, MainLineDto model) { | ||||
|         return Result.OK("success", null); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Result list(MainLinePageDto model) { | ||||
|         QueryWrapper<IlsMainLine> queryWrapper = new  QueryWrapper<>(); | ||||
|         queryWrapper.like("main_line_name", model.getMainLineName()); | ||||
|         queryWrapper.orderByDesc("id"); | ||||
|         Page<IlsMainLine> page = new Page<>(model.getPageNo(), model.getPageSize()); | ||||
|         IPage<IlsMainLine> pageList = ilsMainLineMapper.selectPage(page, queryWrapper); | ||||
|         return Result.OK("success", pageList); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,37 @@ | ||||
| package org.ils.order.utils; | ||||
| 
 | ||||
| import cn.hutool.core.date.DatePattern; | ||||
| import cn.hutool.core.date.DateTime; | ||||
| import cn.hutool.core.lang.Snowflake; | ||||
| import cn.hutool.core.util.IdUtil; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.stereotype.Component; | ||||
| import java.util.concurrent.atomic.AtomicInteger; | ||||
| 
 | ||||
| @Slf4j | ||||
| @Component | ||||
| public class IdGeneratorUtil { | ||||
|     private static volatile AtomicInteger atomicInteger = new AtomicInteger(1001); | ||||
|     private static Snowflake snowflake = IdUtil.createSnowflake(2, 1); | ||||
| 
 | ||||
|     public static void main(String[] args) { | ||||
|         log.info("{}", IdGeneratorUtil.batchId("TAI")); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 生成递增批次号 prefix + 12位数字 | ||||
|      * @param prefix 前缀 | ||||
|      */ | ||||
|     public  static  synchronized String batchId(String prefix) { | ||||
|         String no = DateTime.now().toString(DatePattern.PURE_DATE_PATTERN); | ||||
|         return prefix + no + atomicInteger.getAndIncrement(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 获取唯一主键id 19位 | ||||
|      */ | ||||
|     public static synchronized long snowflakeId() { | ||||
|         return snowflake.nextId(); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,77 @@ | ||||
| package org.ils.order.utils; | ||||
| 
 | ||||
| import org.springframework.beans.BeansException; | ||||
| import org.springframework.context.ApplicationContext; | ||||
| import org.springframework.context.ApplicationContextAware; | ||||
| import org.springframework.stereotype.Component; | ||||
| import org.springframework.web.context.request.RequestContextHolder; | ||||
| import org.springframework.web.context.request.ServletRequestAttributes; | ||||
| 
 | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
| 
 | ||||
| /** | ||||
|  * @Description: spring上下文工具类 | ||||
|  * @author: jeecg-boot | ||||
|  */ | ||||
| @Component | ||||
| public class SpringContextUtils implements ApplicationContextAware { | ||||
| 
 | ||||
| 	/** | ||||
| 	 * 上下文对象实例 | ||||
| 	 */ | ||||
| 	private static ApplicationContext applicationContext; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||||
| 		SpringContextUtils.applicationContext = applicationContext; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * 获取applicationContext | ||||
| 	 */ | ||||
| 	public static ApplicationContext getApplicationContext() { | ||||
| 		return applicationContext; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	  * 获取HttpServletRequest | ||||
| 	 */ | ||||
| 	public static HttpServletRequest getHttpServletRequest() { | ||||
| 		return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | ||||
| 	} | ||||
| 	/** | ||||
| 	 * 获取HttpServletResponse | ||||
| 	 */ | ||||
| 	public static HttpServletResponse getHttpServletResponse() { | ||||
| 		return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse(); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 	public static String getOrigin(){ | ||||
| 		HttpServletRequest request = getHttpServletRequest(); | ||||
| 		return request.getHeader("Origin"); | ||||
| 	} | ||||
| 	 | ||||
| 	/** | ||||
| 	 * 通过name获取 Bean. | ||||
| 	 */ | ||||
| 	public static Object getBean(String name) { | ||||
| 		return getApplicationContext().getBean(name); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * 通过class获取Bean. | ||||
| 	 */ | ||||
| 	public static <T> T getBean(Class<T> clazz) { | ||||
| 		return getApplicationContext().getBean(clazz); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * 通过name,以及Clazz返回指定的Bean | ||||
| 	 */ | ||||
| 	public static <T> T getBean(String name, Class<T> clazz) { | ||||
| 		return getApplicationContext().getBean(name, clazz); | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,5 @@ | ||||
| spring: | ||||
|   application: | ||||
|     name: ils-order-service | ||||
|   profiles: | ||||
|     active: 'dev' | ||||
| @ -0,0 +1,31 @@ | ||||
| package org.ils.order; | ||||
| 
 | ||||
| import cn.hutool.json.JSONObject; | ||||
| import com.alibaba.fastjson.JSON; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.ils.order.config.BaseConfig; | ||||
| import org.ils.order.rabbitmq.RabbitSender; | ||||
| 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.test.context.junit4.SpringRunner; | ||||
| 
 | ||||
| @Slf4j | ||||
| @RunWith(SpringRunner.class) | ||||
| @SpringBootTest | ||||
| public  class RabbitMqHelloTest{ | ||||
|     @Autowired | ||||
|     private BaseConfig baseConfig; | ||||
| 
 | ||||
|     @Autowired | ||||
|     private RabbitSender rabbitSender; | ||||
|     @Test | ||||
|     public void test(){ | ||||
|         JSONObject json = new JSONObject(); | ||||
|         json.put("userName","test123"); | ||||
|         json.put("passWord","123456"); | ||||
|         rabbitSender.sendOrderQueue(baseConfig.getIlsOrderQueue(), JSON.toJSONString(json)); | ||||
|         log.info( "send: {}", true); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,45 @@ | ||||
| package org.ils.order; | ||||
| 
 | ||||
| import com.alibaba.fastjson.JSONObject; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.ils.order.config.BaseConfig; | ||||
| 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; | ||||
| 
 | ||||
| @Slf4j | ||||
| @RunWith(SpringRunner.class) | ||||
| @SpringBootTest | ||||
| public  class RestTemplateTest { | ||||
|     @Autowired | ||||
|     private RestTemplate restTemplate; | ||||
| 
 | ||||
|     @Autowired | ||||
|     private BaseConfig 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()); | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| } | ||||
					Loading…
					
					
				
		Reference in New Issue