作者 朱兆平

init

HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
### VS Code ###
.vscode/
... ...
# 项目描述-海关新舱单、运输工具报文生成服务
* 生成XML格式的新舱单报文 和 运输工具报文
* 前端采用vue element开发框架集成 ,前端git:[git@118.31.66.166:zp260/vue_cli.git](git@118.31.66.166:zp260/vue_cli.git)
* 后端采用spring boot 2
## 配置
* 配置文件为项目根目录下的config文件夹内,方便部署后的配置修改
* logback-dev.xml 为logback的配置文件
* application.yml 为spring boot的配置文件
##集成
* 集成Spring Cloud
* 集成lombok,简化部分代码录入,比如实体类,方便实体及表结构修改,敏捷开发必用,使用方法见[lombok集成使用说明](https://jingyan.baidu.com/article/0a52e3f4e53ca1bf63ed725c.html)
)
* 集成了swagger2,开发环境开启此POM配置,生产环境记得去掉。包冲突问题看POM配置文件注释。[接口访问测试地址](http://localhost:7003/swagger-ui.html)
... ...
#上传文件的路径,要带斜杠
web:
upload-path: upload/
server:
port: 7003
servlet:
context-path: ${SERVER_CONTEXTPATH:}
spring:
profiles:
active: dev
mvc:
#静态资源,设置上传文件的访问,
static-path-pattern: /**
resources:
static-locations: classpath:/META-INF/resources/,classpath:/static,classpath:/resources/,file:${web.upload-path}
application:
name: WLPT-MessageBuilder
jackson:
serialization:
FAIL_ON_EMPTY_BEANS: false
#springboot2.0之后会把Date类型字段自动给转成UTC字符串 如:1990-11-26T16:00:00.000+0000,如果想转成时间戳在application.properties配置文件增加以下配置
date-format: yyyy-MM-dd HH:mm:ss
#时区必须要设置
time-zone: GMT+8
#ALWAYS的意思是即时属性为null,仍然也会输出这个key
default-property-inclusion: always
cloud:
#eureka主机名,会在控制页面中显示
#DEV环境关闭注册。
features:
enabled: true
discovery:
enabled: true
service-registry:
auto-registration:
enabled: true
datasource:
type: com.alibaba.druid.pool.DruidDataSource
#oracle
#driver-class-name=oracle.jdbc.OracleDriver
#url=jdbc:oracle:thin:@10.50.3.68:1521:CGODW
#username=CGOETL
#password=1q2w3e4r
#spring datasource mysql,注意编码配置,缺少数据库编码配置容易引起中文入库乱码
url: jdbc:mysql://127.0.0.1:3307/statistics?useUnicode=true&characterEncoding=utf8
username: root
password:
driver-class-name: com.mysql.jdbc.Driver
max-idle: 10
max-wait: 10000
min-idle: 5
initial-size: 5
#配置初始化大小/最小/最大
druid:
initial-size: 1
min-idle: 1
max-active: 20
#获取连接等待超时时间
max-wait: 60000
#一个连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
#间隔多久进行一次检测,检测需要关闭的空闲连接
time-between-eviction-runs-millis: 60000
#mysql
validation-query: SELECT 1 FROM DUAL
#oracle
#druid.validation-query:SELECT 'x' FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
default-auto-commit: true
freemarker:
template-loader-path: classpath:/templates
#关闭缓存,及时刷新,上线生产环境需要修改为true
cache: false
charset: utf-8
check-template-location: true
content-type: text/xml
suffix: .ftlx
eureka:
instance:
#eureka服务器页面中status的请求路径
status-page-url: http://${eureka.instance.hostname}:${server.port}/index
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
hostname: ${spring.cloud.client.ip-address}
client:
#eureka注册中心服务器地址
service-url:
defaultZone: http://10.50.3.82:19527/eureka/
registry-fetch-interval-seconds: 30
lease-renewal-interval-in-seconds: 15
lease-expiration-duration-in-seconds: 45
mybatis:
mapper-locations: classpath:mapping/*.xml
type-aliases-package: com.tianbo.warehouse.model
pagehelper:
#auto-dialect: true
#auto-runtime-dialect: true
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
params: count=countSql
#debug配置,debug或者为true的时候,logback才会记录和写入日志文件
trace: false
debug: true
logging:
file:
path: ./logs/
name: system.log
config: config/logback-dev.xml
#转移到logback配置文件中
#level:
#org.apache.tomcat: info
#com.tianbo.warehouse.dao: DEBUG
#org.springframework.security: trace
#日志配置,输出到文本,
#Java Web Token 时效时间,单位秒
jwt:
max-alive: 300
custom:
send-path: ./send/
tcs:
mq-number: DXPENT0000460002
... ...
<?xml version="1.0" encoding="UTF-8"?>
<!--参考文档链接:https://blog.csdn.net/qq_34912478/article/details/80877132-->
<!-- 日志级别从低到高分为TRACE < DEBUG < INFO < WARN < ERROR < FATAL,如果设置为WARN,则低于WARN的信息都不会输出 -->
<!-- scan:当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true -->
<!-- scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 -->
<!-- debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
<configuration scan="true" scanPeriod="10 seconds">
<!--<include resource="org/springframework/boot/logging/logback/base.xml" />-->
<contextName>logback</contextName>
<!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 -->
<property name="log.path" value="./logs" />
<!-- 彩色日志 -->
<!-- 彩色日志依赖的渲染类 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<!-- 彩色日志格式 -->
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<!--输出到控制台-->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<encoder>
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
<!-- 设置字符集 -->
<charset>UTF-8</charset>
</encoder>
</appender>
<!--输出到文件-->
<!-- 时间滚动输出 level为 DEBUG 日志 -->
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_debug.log</file>
<!--日志文件输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志归档 -->
<fileNamePattern>${log.path}/debug/log-debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录debug级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>debug</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 时间滚动输出 level为 INFO 日志 -->
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_info.log</file>
<!--日志文件输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 每天日志归档路径以及格式 -->
<fileNamePattern>${log.path}/info/log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录info级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>info</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 时间滚动输出 level为 WARN 日志 -->
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_warn.log</file>
<!--日志文件输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录warn级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>warn</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 时间滚动输出 level为 ERROR 日志 -->
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_error.log</file>
<!--日志文件输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/error/log-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录ERROR级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!--
<logger>用来设置某一个包或者具体的某一个类的日志打印级别、
以及指定<appender>。<logger>仅有一个name属性,
一个可选的level和一个可选的addtivity属性。
name:用来指定受此logger约束的某一个包或者具体的某一个类。
level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,
还有一个特俗值INHERITED或者同义词NULL,代表强制执行上级的级别。
如果未设置此属性,那么当前logger将会继承上级的级别。
addtivity:是否向上级logger传递打印信息。默认是true。
-->
<!--<logger name="org.springframework.web" level="info"/>-->
<!--<logger name="org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor" level="INFO"/>-->
<!--
使用mybatis的时候,sql语句是debug下才会打印,而这里我们只配置了info,所以想要查看sql语句的话,有以下两种操作:
第一种把<root level="info">改成<root level="DEBUG">这样就会打印sql,不过这样日志那边会出现很多其他消息
第二种就是单独给dao下目录配置debug模式,代码如下,这样配置sql语句会打印,其他还是正常info级别:
-->
<!--
root节点是必选节点,用来指定最基础的日志输出级别,只有一个level属性
level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,
不能设置为INHERITED或者同义词NULL。默认是DEBUG
可以包含零个或多个元素,标识这个appender将会添加到这个logger。
-->
<!--开发环境:打印控制台-->
<springProfile name="dev">
<logger name="org.springframework.security" level="trace"/>
<logger name="org.apache.tomcat" level="info" />
<logger name="com.tianbo.warehouse.dao" level="DEBUG" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
<!--<appender-ref ref="DEBUG_FILE" />-->
<!--<appender-ref ref="INFO_FILE" />-->
<!--<appender-ref ref="WARN_FILE" />-->
<appender-ref ref="ERROR_FILE" />
</root>
</springProfile>
<!--生产环境:输出到文件-->
<springProfile name="pro">
<root level="info">
<appender-ref ref="CONSOLE" />
<appender-ref ref="DEBUG_FILE" />
<appender-ref ref="INFO_FILE" />
<appender-ref ref="ERROR_FILE" />
<appender-ref ref="WARN_FILE" />
</root>
</springProfile>
</configuration>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.M6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sunyo.wlpt.message</groupId>
<artifactId>builder</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>builder</name>
<description>海关报文生成</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.M2</spring-cloud.version>
<swagger2_version>2.9.2</swagger2_version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!--集成swagger2,下面两个spring的配置解决springboot包 与swagger2的包冲突问题,生产部署的时候记得要去掉此swagger2的配置,开发环境开启-->
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>1.2.0.RELEASE</version><!--$NO-MVN-MAN-VER$-->
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-metadata</artifactId>
<version>1.2.0.RELEASE</version><!--$NO-MVN-MAN-VER$-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger2_version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-metadata</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2_version}</version>
<!--2.9.2集成的是M1的这两个包,跟现在用的Greenwich.BUILD-SNAPSHOT的版本的SPRING boot2的版本包有冲突。去掉-->
<exclusions>
<exclusion>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-metadata</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.tianbo</groupId>
<artifactId>util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sunyo.wlpt</groupId>
<artifactId>base</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
<!-- mybatis generator 自动生成代码插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>
... ...
package com.sunyo.wlpt.message.builder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class BuilderApplication {
public static void main(String[] args) {
SpringApplication.run(BuilderApplication.class, args);
}
}
... ...
package com.sunyo.wlpt.message.builder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class Swagger2 {
//swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//为当前包路径
.apis(RequestHandlerSelectors.basePackage("com.sunyo.wlpt.message.builder.controller"))
.paths(PathSelectors.any())
.build();
}
//构建 api文档的详细信息函数,注意这里的注解引用的是哪个
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//页面标题
.title("海关报文生成服务")
//创建人
.contact(new Contact("mrz", "http://www.baidu.com", "17966059@qq.com"))
//版本号
.version("1.0")
//描述
.description("API 描述")
.build();
}
}
... ...
package com.sunyo.wlpt.message.builder.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/")
public class IndexController {
@GetMapping("index")
public String index(){
return "11";
// return "数据仓库接收,落地报文给新舱单";
}
}
... ...
package com.sunyo.wlpt.message.builder.controller;
import com.sunyo.wlpt.message.builder.util.CustomXmlMaker;
import freemarker.template.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@RequestMapping("/mt1201")
public class MT1201Controller extends CustomXmlMaker {
private static String businessType = "MT1201";
@Autowired
private Configuration freemakerTemplate;
@RequestMapping("/send")
public Boolean mt1201New(@RequestBody Map awb_manifest) throws Exception{
}
}
... ...
package com.sunyo.wlpt.message.builder.controller;
import com.sunyo.wlpt.message.builder.model.CUSTOM_RESPONSE;
import com.sunyo.wlpt.message.builder.util.CustomXmlMaker;
import freemarker.template.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.Map;
@RestController
@RequestMapping("/mt2201")
public class MT2201Controller extends CustomXmlMaker {
@Autowired
private Configuration freemakerTemplate;
private static String businessType = "MT2201";
/**
* MAP包含运单实体与舱单实体
* @param awb_manifest {awb:AWB_AWBINFO,man:}
* @return
* @throws Exception
*/
@RequestMapping("/send")
public Boolean mt1201New(@RequestBody Map awb_manifest) throws Exception{
try {
CUSTOM_RESPONSE response = new CUSTOM_RESPONSE();
response.setAwbano("17212345678");
response.setCusfunctioncode("2");
response.setCusreciverid("4604");
response.setCusversion("1.2");
response.setBusdate(new Date());
response.setBustype(businessType);
String msgId = makeMsgID(businessType,"460470678920X","17212345678");
response.setCusmsgid(msgId);
response.setCussenderid(makeSenderID("4604","460470678920X"));
String filename = response.getCusmsgid()+".xml";
makeXmlToFile("/manifest/MT2201.ftlx",filename,awb_manifest);
}catch (Exception e){
e.printStackTrace();
return false;
}
return true;
}
}
... ...
package com.sunyo.wlpt.message.builder.model;
import java.util.Date;
public class CUSTOM_RESPONSE {
private String id;
private Date flightdate;
private String flightno;
private String carrier;
private String awbano;
private String awbhno;
private String bustype;
private Date busdate;
private Long busweight;
private Integer buspiece;
private String opertype;
private String cusmsgid;
private String cussenderid;
private String cusreciverid;
private String cusversion;
private String cusfunctioncode;
private Date cusresrcvtime;
private Date cusressendtime;
private String cusrescode;
private String cusresstatus;
private String operusername;
private String opersystemname;
private String cusrestext;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public Date getFlightdate() {
return flightdate;
}
public void setFlightdate(Date flightdate) {
this.flightdate = flightdate;
}
public String getFlightno() {
return flightno;
}
public void setFlightno(String flightno) {
this.flightno = flightno == null ? null : flightno.trim();
}
public String getCarrier() {
return carrier;
}
public void setCarrier(String carrier) {
this.carrier = carrier == null ? null : carrier.trim();
}
public String getAwbano() {
return awbano;
}
public void setAwbano(String awbano) {
this.awbano = awbano == null ? null : awbano.trim();
}
public String getAwbhno() {
return awbhno;
}
public void setAwbhno(String awbhno) {
this.awbhno = awbhno == null ? null : awbhno.trim();
}
public String getBustype() {
return bustype;
}
public void setBustype(String bustype) {
this.bustype = bustype == null ? null : bustype.trim();
}
public Date getBusdate() {
return busdate;
}
public void setBusdate(Date busdate) {
this.busdate = busdate;
}
public Long getBusweight() {
return busweight;
}
public void setBusweight(Long busweight) {
this.busweight = busweight;
}
public Integer getBuspiece() {
return buspiece;
}
public void setBuspiece(Integer buspiece) {
this.buspiece = buspiece;
}
public String getOpertype() {
return opertype;
}
public void setOpertype(String opertype) {
this.opertype = opertype == null ? null : opertype.trim();
}
public String getCusmsgid() {
return cusmsgid;
}
public void setCusmsgid(String cusmsgid) {
this.cusmsgid = cusmsgid == null ? null : cusmsgid.trim();
}
public String getCussenderid() {
return cussenderid;
}
public void setCussenderid(String cussenderid) {
this.cussenderid = cussenderid == null ? null : cussenderid.trim();
}
public String getCusreciverid() {
return cusreciverid;
}
public void setCusreciverid(String cusreciverid) {
this.cusreciverid = cusreciverid == null ? null : cusreciverid.trim();
}
public String getCusversion() {
return cusversion;
}
public void setCusversion(String cusversion) {
this.cusversion = cusversion == null ? null : cusversion.trim();
}
public String getCusfunctioncode() {
return cusfunctioncode;
}
public void setCusfunctioncode(String cusfunctioncode) {
this.cusfunctioncode = cusfunctioncode == null ? null : cusfunctioncode.trim();
}
public Date getCusresrcvtime() {
return cusresrcvtime;
}
public void setCusresrcvtime(Date cusresrcvtime) {
this.cusresrcvtime = cusresrcvtime;
}
public Date getCusressendtime() {
return cusressendtime;
}
public void setCusressendtime(Date cusressendtime) {
this.cusressendtime = cusressendtime;
}
public String getCusrescode() {
return cusrescode;
}
public void setCusrescode(String cusrescode) {
this.cusrescode = cusrescode == null ? null : cusrescode.trim();
}
public String getCusresstatus() {
return cusresstatus;
}
public void setCusresstatus(String cusresstatus) {
this.cusresstatus = cusresstatus == null ? null : cusresstatus.trim();
}
public String getOperusername() {
return operusername;
}
public void setOperusername(String operusername) {
this.operusername = operusername == null ? null : operusername.trim();
}
public String getOpersystemname() {
return opersystemname;
}
public void setOpersystemname(String opersystemname) {
this.opersystemname = opersystemname == null ? null : opersystemname.trim();
}
public String getCusrestext() {
return cusrestext;
}
public void setCusrestext(String cusrestext) {
this.cusrestext = cusrestext == null ? null : cusrestext.trim();
}
}
\ No newline at end of file
... ...
package com.sunyo.wlpt.message.builder.service;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Map;
public interface MakeXml1201Service {
boolean makeXml1201_new(@RequestBody Map awb_manifest) throws Exception;
}
... ...
package com.sunyo.wlpt.message.builder.service.imp;
import com.sunyo.wlpt.base.model.AWB_AWBINFO;
import com.sunyo.wlpt.base.model.NMMS_CUSTOM_MT1201;
import com.sunyo.wlpt.base.model.NMMS_CUSTOM_RESPONSE;
import com.sunyo.wlpt.message.builder.model.CUSTOM_RESPONSE;
import com.sunyo.wlpt.message.builder.service.MakeXml1201Service;
import com.sunyo.wlpt.message.builder.util.CustomXmlMaker;
import freemarker.template.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class MakeXml1201ServiceImp extends CustomXmlMaker implements MakeXml1201Service {
private static String businessType = "MT1201";
@Autowired
private Configuration freemakerTemplate;
/**
* MAP包含运单实体与舱单实体
* @param awb_manifest {awb:AWB_AWBINFO,man:NMMS_CUSTOM_MT1201}
* @return
* @throws Exception
*/
@Override
public boolean makeXml1201_new(@RequestBody Map awb_manifest) throws Exception{
try {
NMMS_CUSTOM_MT1201 mt1201 = new NMMS_CUSTOM_MT1201();
AWB_AWBINFO awb = new AWB_AWBINFO();
NMMS_CUSTOM_RESPONSE customResponse = new NMMS_CUSTOM_RESPONSE();
Map<String,Object> xmlmap = new HashMap<>();
xmlmap.put("awb",awb);
xmlmap.put("man",mt1201);
xmlmap.put("res",customResponse);
mt1201.setAwba("17212345678");
mt1201.setCarrier("CV");
mt1201.setCustomcode("4604");
mt1201.setFlightno("9733");
mt1201.setFlightdate(new Date());
mt1201.setDestinationstation("CGO");
String msgId = makeMsgID(businessType,"460470678920X","17212345678");
makeXmlToFile("/manifest/MT2201.ftlx",filename,awb_manifest);
}catch (Exception e){
e.printStackTrace();
return false;
}
return true;
}
}
... ...
package com.sunyo.wlpt.message.builder.util;
import com.tianbo.util.Date.DateUtil;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import java.io.File;
import java.io.IOException;
import java.util.Map;
@Component
public class CustomXmlMaker {
@Autowired
private Configuration freemakerTemplate;
@Value("${custom.send-path}")
private static String sendPath;
@Value("${tcs.mq-number}")
private static String TCSMQNumber;
/**
* 所有填制项中不得出现“<”、“&”符号,如有实际需要,请填写对应的转义符“&lt;”、“&amp;”。
十、报文中不允许出现空节点,如<Consignee></Consignee>或<Consignee/>。
* @param tplName 模板名称
* @param fileName 生成的报文名称
* @param manifestMap 数据实体
* @return 0失败,1成功
* @throws IOException
*/
public int makeXmlToFile(String tplName,String fileName,Map manifestMap) throws IOException{
try {
Template template = freemakerTemplate.getTemplate(tplName);
String content = FreeMarkerTemplateUtils.processTemplateIntoString(template,manifestMap);
String filename = sendPath+fileName;
File sendfile = new File(filename);
FileUtils.writeStringToFile(sendfile,content,"UTF-8");
}catch (IOException e){
e.printStackTrace();
return 0;
}catch (TemplateException ee){
ee.printStackTrace();
return 0;
}
return 1;
}
/**
* 生成MessageId
* MessageID:报文编号,由企业自定义,
* 要求与其它企业同类型报文不得重复,
* 最大长度为64位,由字母、数字、特定符号组成,并不得出现除“-”、“_”“/”等以外的特殊符号,
* 且符号不得作为报文编号的开头与结尾;
* @param mtType 舱单业务申报类型 如:MT1201
* @param ORGSN 使用企业在海关备案的代码,备案规则为:4位关区代码+9位企业组织机构代码+50位自定义扩展字符。:460470678920X
* @param waylbillNo 运单号
* @return CN_MT1201_1P0_460470678920X_17218902832_yyyyMMddHHmmssSSS
*/
public String makeMsgID(String mtType,String ORGSN,String waylbillNo){
StringBuilder sb = new StringBuilder();
sb.append("CN_")
.append(mtType)
.append("_1P0_")
.append(ORGSN).append("_")
.append(waylbillNo)
.append("_").append(DateUtil.getCurrentTime17());
return sb.toString();
}
/**
* 生成新舱单报文报头的SenderID。
* 发送方代码,使用企业在海关备案的代码,备案规则为:4位关区代码+9位企业组织机构代码+50位自定义扩展字符,
* 由字母和数字组成,并不得出现除“-”、“_”“/”、“@”、“.”、“*”等以外的特殊字符,且符号不得作为结尾。
* 我们这里的备案规则设置为:关区代码+9位企业组织机构代码+_TCS通道号。
* @param customCode 关区代码
* @param ORGSN 海关企业备案编码
* @param TCSSN TCS分配的通道编号
* @return 460470678920X_DXPENT0000460002
*/
public String makeSenderID(String customCode,String ORGSN,String TCSSN){
StringBuilder sb = new StringBuilder();
sb.append(customCode)
.append(ORGSN)
.append("_")
.append(TCSSN);
return sb.toString();
}
public String makeSenderID(String customCode,String ORGSN){
return makeSenderID(customCode,ORGSN,TCSMQNumber);
}
}
... ...
${AnsiColor.YELLOW}
##################*CETC-TIANBO*#########################
.::::.
.::::::::.
:::::::::::
..:::::::::::'
'::::::::::::'
.::::::::::
'::::::::::::::..
..::::::::::::.
``::::::::::::::::
::::``:::::::::' .:::.
::::' ':::::' .::::::::.
.::::' :::: .:::::::'::::.
.:::' ::::: .:::::::::' ':::::.
.::' :::::.:::::::::' ':::::.
.::' ::::::::::::::' ``::::.
...::: ::::::::::::' ``::.
```` ':. ':::::::::' ::::..
'.:::::' ':'````..
#########################################################
==================================================
Application Info:${application.title}
ver:${application.version}
Powered by:Spring Boot ${spring-boot.version}
\ No newline at end of file
... ...
<Manifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:Declaration:datamodel:standard:CN:MT1201:1">
<Head>
<MessageID>CN_MT1201_1P0_460470678920X_20190918220458427</MessageID>
<FunctionCode>9</FunctionCode>
<MessageType>MT1201</MessageType>
<SenderID>460470678920X_DXPENT0000460002</SenderID>
<ReceiverID>4604</ReceiverID>
<SendTime>20190918220458427</SendTime>
<Version>1.0</Version>
</Head>
<Declaration>
<RepresentativePerson>
<Name>9141010070678920XJ</Name>
</RepresentativePerson>
<ExitCustomsOffice>
<ID>KUL</ID>
</ExitCustomsOffice>
<Carrier>
<ID>CV</ID>
</Carrier>
<BorderTransportMeans>
<JourneyID>CV7303/20190919</JourneyID>
<TypeCode>4</TypeCode>
<FirstArrivalLocationID>CGO</FirstArrivalLocationID>
<ArrivalDateTime>20190919010458086</ArrivalDateTime>
<DepartureDateTime>20190918230458086</DepartureDateTime>
</BorderTransportMeans>
<Consignment>
<TransportContractDocument>
<ID>17236633273</ID>
<ConditionCode>10</ConditionCode>
</TransportContractDocument>
<LoadingLocation>
<ID>KUL</ID>
</LoadingLocation>
<UnloadingLocation>
<ID>CGO/4604</ID>
<ArrivalDate>20190919</ArrivalDate>
</UnloadingLocation>
<TransitDestination>
<ID>CGN</ID>
</TransitDestination>
<CustomsStatusCode>002</CustomsStatusCode>
<TransportSplitIndicator>0</TransportSplitIndicator>
<FreightPayment>
<MethodCode>PP</MethodCode>
</FreightPayment>
<ConsignmentPackaging>
<QuantityQuantity>3</QuantityQuantity>
</ConsignmentPackaging>
<TotalGrossMassMeasure>24.0</TotalGrossMassMeasure>
<Consignee>
<ID>8888+NONE</ID>
<Name>SCHENKER DEUTSCHLAND AG</Name>
<Address>
<Line>NEUER WEYERSTRASSERWEG 120 122</Line>
<CountryCode>CN</CountryCode>
</Address>
<Communication>
<ID>00000000</ID>
<TypeID>TE</TypeID>
</Communication>
<Contact>
<Name>NONE</Name>
<Communication>
<ID>00000000</ID>
<TypeID>TE</TypeID>
</Communication>
</Contact>
</Consignee>
<Consignor>
<ID>9999+NONE</ID>
<Name>SCHENKER LOGISTICS MALAYSIA SDN BHD</Name>
<Address>
<Line>B 10 MAS FREIGHT FOWARDERS COMPLEX</Line>
<CountryCode>MY</CountryCode>
</Address>
<Communication>
<ID>60387757888</ID>
<TypeID>TE</TypeID>
</Communication>
</Consignor>
<ConsignmentItem>
<SequenceNumeric>1</SequenceNumeric>
<ConsignmentItemPackaging>
<QuantityQuantity>3</QuantityQuantity>
</ConsignmentItemPackaging>
<Commodity>
<CargoDescription>CONSOL</CargoDescription>
</Commodity>
<GoodsMeasure>
<GrossMassMeasure>24</GrossMassMeasure>
</GoodsMeasure>
</ConsignmentItem>
</Consignment>
</Declaration>
</Manifest>
\ No newline at end of file
... ...
<Manifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:Declaration:datamodel:standard:CN:MT1201:1">
<Head>
<MessageID>${cusmsgid}</MessageID>
<FunctionCode>${cusfunctioncode}</FunctionCode>
<MessageType>${bustype}</MessageType>
<SenderID>${cussenderid}</SenderID>
<ReceiverID>${cusreciverid}</ReceiverID>
<SendTime>${busdate?string('ddMMyyyyHHmmssSSS')}</SendTime>
<Version>${cusversion}</Version>
</Head>
</Manifest>
... ...
package com.sunyo.wlpt.message.builder;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class BuilderApplicationTests {
@Test
void contextLoads() {
}
}
... ...