作者 朱兆平

合并分支 'dev_security' 到 'master'

Dev security

合并security 权限部分到主分支

查看合并请求 !1
正在显示 89 个修改的文件 包含 4179 行增加89 行删除
@@ -3,7 +3,9 @@ @@ -3,7 +3,9 @@
3 /logs/ 3 /logs/
4 /out/ 4 /out/
5 .mvn 5 .mvn
6 - 6 +/xmlFromImf/
  7 +kakoRevice/
  8 +/errorLogs/
7 ### STS ### 9 ### STS ###
8 .apt_generated 10 .apt_generated
9 .classpath 11 .classpath
@@ -25,4 +27,4 @@ @@ -25,4 +27,4 @@
25 /nbbuild/ 27 /nbbuild/
26 /dist/ 28 /dist/
27 /nbdist/ 29 /nbdist/
28 -/.nb-gradle/  
  30 +/.nb-gradle/
1 #登录账号 1 #登录账号
2 -loginname = NMMS 2 +loginname = KAKO
3 #登录密码 3 #登录密码
4 -loginpass = NMMS 4 +loginpass = KAKO
5 #发送报文目录,相对程序目录 5 #发送报文目录,相对程序目录
6 -readDirectory = /Users/mrz/Downloads/1.woowo 6 +readDirectory = /Users/mrz/Documents/java项目/test
7 #接收存储报文目录 7 #接收存储报文目录
8 -bakDirectory = xmlFromImf 8 +bakDirectory = kakoRevice
9 #是否需要发送报文,默认N不发,Y将发送readDirectory下的XML扩展名的报文 9 #是否需要发送报文,默认N不发,Y将发送readDirectory下的XML扩展名的报文
10 -isNeedSend = N 10 +isNeedSend = Y
  11 +#本地要保存的styp类型,用英文逗号分隔,注意中英文字符
  12 +saveStyp = DFDL,ARRE,ONRE,STLS
11 13
12 #IMF MEAT报头配置 14 #IMF MEAT报头配置
13 15
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 <modelVersion>4.0.0</modelVersion> 4 <modelVersion>4.0.0</modelVersion>
  5 + <packaging>pom</packaging>
5 <parent> 6 <parent>
6 <groupId>org.springframework.boot</groupId> 7 <groupId>org.springframework.boot</groupId>
7 <artifactId>spring-boot-starter-parent</artifactId> 8 <artifactId>spring-boot-starter-parent</artifactId>
@@ -17,6 +18,9 @@ @@ -17,6 +18,9 @@
17 <properties> 18 <properties>
18 <java.version>1.8</java.version> 19 <java.version>1.8</java.version>
19 <spring-cloud.version>Greenwich.BUILD-SNAPSHOT</spring-cloud.version> 20 <spring-cloud.version>Greenwich.BUILD-SNAPSHOT</spring-cloud.version>
  21 + <fastjson_version>1.2.28</fastjson_version>
  22 + <lombok_sersion>1.18.6</lombok_sersion>
  23 + <swagger2_version>2.9.2</swagger2_version>
20 </properties> 24 </properties>
21 25
22 <dependencies> 26 <dependencies>
@@ -30,6 +34,11 @@ @@ -30,6 +34,11 @@
30 <artifactId>mybatis-spring-boot-starter</artifactId> 34 <artifactId>mybatis-spring-boot-starter</artifactId>
31 <version>1.3.2</version> 35 <version>1.3.2</version>
32 </dependency> 36 </dependency>
  37 + <!--<dependency>-->
  38 + <!--<groupId>org.springframework.boot</groupId>-->
  39 + <!--<artifactId>spring-boot-devtools</artifactId>-->
  40 + <!--<optional>true</optional>-->
  41 + <!--</dependency>-->
33 <!--有WEBSOCKET包 包含了spring-boot-starter-web 和spring-boot-starter包 有这个包不要引入这俩包--> 42 <!--有WEBSOCKET包 包含了spring-boot-starter-web 和spring-boot-starter包 有这个包不要引入这俩包-->
34 <dependency> 43 <dependency>
35 <groupId>org.springframework.boot</groupId> 44 <groupId>org.springframework.boot</groupId>
@@ -43,6 +52,11 @@ @@ -43,6 +52,11 @@
43 </dependency> 52 </dependency>
44 <dependency> 53 <dependency>
45 <groupId>org.springframework.boot</groupId> 54 <groupId>org.springframework.boot</groupId>
  55 + <artifactId>spring-boot-configuration-processor</artifactId>
  56 + <optional>true</optional>
  57 + </dependency>
  58 + <dependency>
  59 + <groupId>org.springframework.boot</groupId>
46 <artifactId>spring-boot-starter-thymeleaf</artifactId> 60 <artifactId>spring-boot-starter-thymeleaf</artifactId>
47 </dependency> 61 </dependency>
48 <dependency> 62 <dependency>
@@ -73,18 +87,95 @@ @@ -73,18 +87,95 @@
73 </exclusion> 87 </exclusion>
74 </exclusions> 88 </exclusions>
75 </dependency> 89 </dependency>
  90 +
76 <!--spring boot--> 91 <!--spring boot-->
  92 + <!-- tools-->
  93 + <!--集成swagger2,下面两个spring的配置解决springboot包 与swagger2的包冲突问题,生产部署的时候记得要去掉此swagger2的配置,开发环境开启-->
  94 + <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
  95 + <dependency>
  96 + <groupId>org.springframework.plugin</groupId>
  97 + <artifactId>spring-plugin-core</artifactId>
  98 + <version>1.2.0.RELEASE</version><!--$NO-MVN-MAN-VER$-->
  99 + </dependency>
  100 + <dependency>
  101 + <groupId>org.springframework.plugin</groupId>
  102 + <artifactId>spring-plugin-metadata</artifactId>
  103 + <version>1.2.0.RELEASE</version><!--$NO-MVN-MAN-VER$-->
  104 + </dependency>
  105 + <dependency>
  106 + <groupId>io.springfox</groupId>
  107 + <artifactId>springfox-swagger-ui</artifactId>
  108 + <version>${swagger2_version}</version>
  109 + <exclusions>
  110 + <exclusion>
  111 + <groupId>org.springframework.plugin</groupId>
  112 + <artifactId>spring-plugin-core</artifactId>
  113 + </exclusion>
  114 + <exclusion>
  115 + <groupId>org.springframework.plugin</groupId>
  116 + <artifactId>spring-plugin-metadata</artifactId>
  117 + </exclusion>
  118 + </exclusions>
  119 + </dependency>
  120 + <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
  121 + <dependency>
  122 + <groupId>io.springfox</groupId>
  123 + <artifactId>springfox-swagger2</artifactId>
  124 + <version>${swagger2_version}</version>
  125 + <!--2.9.2集成的是M1的这两个包,跟现在用的Greenwich.BUILD-SNAPSHOT的版本的SPRING boot2的版本包有冲突。去掉-->
  126 + <exclusions>
  127 + <exclusion>
  128 + <groupId>org.springframework.plugin</groupId>
  129 + <artifactId>spring-plugin-core</artifactId>
  130 + </exclusion>
  131 + <exclusion>
  132 + <groupId>org.springframework.plugin</groupId>
  133 + <artifactId>spring-plugin-metadata</artifactId>
  134 + </exclusion>
  135 + </exclusions>
  136 + </dependency>
  137 + <!--集成swagger2-->
  138 + <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
  139 + <dependency>
  140 + <groupId>org.projectlombok</groupId>
  141 + <artifactId>lombok</artifactId>
  142 + <version>${lombok_sersion}</version>
  143 + <scope>provided</scope>
  144 + </dependency>
  145 + <dependency>
  146 + <groupId>commons-codec</groupId>
  147 + <artifactId>commons-codec</artifactId>
  148 + <version>1.11</version>
  149 + </dependency>
  150 + <dependency>
  151 + <groupId>com.alibaba</groupId>
  152 + <artifactId>fastjson</artifactId>
  153 + <version>${fastjson_version}</version>
  154 + </dependency>
  155 + <!-- tools-->
77 <!-- alibaba的druid数据库连接池 --> 156 <!-- alibaba的druid数据库连接池 -->
78 <dependency> 157 <dependency>
79 <groupId>com.alibaba</groupId> 158 <groupId>com.alibaba</groupId>
80 <artifactId>druid-spring-boot-starter</artifactId> 159 <artifactId>druid-spring-boot-starter</artifactId>
81 <version>1.1.9</version> 160 <version>1.1.9</version>
82 </dependency> 161 </dependency>
  162 + <!-- mysql-->
  163 + <dependency>
  164 + <groupId>mysql</groupId>
  165 + <artifactId>mysql-connector-java</artifactId>
  166 + </dependency>
  167 + <!-- oracle-->
83 <dependency> 168 <dependency>
84 <groupId>com.oracle</groupId> 169 <groupId>com.oracle</groupId>
85 <artifactId>ojdbc6</artifactId> 170 <artifactId>ojdbc6</artifactId>
86 <version>11.2.0.4.0-atlassian-hosted</version> 171 <version>11.2.0.4.0-atlassian-hosted</version>
87 </dependency> 172 </dependency>
  173 + <!--分页插件-->
  174 + <dependency>
  175 + <groupId>com.github.pagehelper</groupId>
  176 + <artifactId>pagehelper-spring-boot-starter</artifactId>
  177 + <version>1.2.5</version>
  178 + </dependency>
88 <!-- https://mvnrepository.com/artifact/org.dom4j/dom4j --> 179 <!-- https://mvnrepository.com/artifact/org.dom4j/dom4j -->
89 <dependency> 180 <dependency>
90 <groupId>org.dom4j</groupId> 181 <groupId>org.dom4j</groupId>
  1 +**gitlab**: [http://118.31.66.166:zp260/imf_cloud_wearhouse.git](git@118.31.66.166:zp260/imf_cloud_wearhouse.git)
  2 +
  3 +# 项目描述
  4 +国际货运物流平台开发脚手架
  5 +#集成
  6 +* 已集成IMF,基于IMF的xml报文格式。在master的git主分支上
  7 + * POM文件包含本地包
  8 + * 接收IMF的消息
  9 + * 报文类型识别
  10 + * 报文分类本地存储
  11 + * 报文发送
  12 +* 已集成spring SECURITY
  13 + * 支持前后端分离
  14 + * 自定义权限角色管理
  15 + * url角色权限识别
  16 + * menu与权限关联
  17 + * 参数校验
  18 +* 已集成mybatis、mybatisGenerator、pageHelper
  19 +* 集成定时任务框架
  20 + * 目前在IMF框架中使用,打开IMF_Task里面的定时任务注释就可以启动IMF客户端功能
  21 +* 集成Spring Cloud
  22 +* 集成websocket
  23 +* 集成lombok,简化部分代码录入,比如实体类,方便实体及表结构修改,敏捷开发必用,使用方法见[lombok集成使用说明](https://jingyan.baidu.com/article/0a52e3f4e53ca1bf63ed725c.html)
  24 +)
  25 +* 集成了单文件、多文件上传接口
  26 +* 集成了swagger2,开发环境开启此POM配置,生产环境记得去掉。包冲突问题看POM配置文件注释。[接口访问测试地址](http://localhost:7003/swagger-ui.html)
  1 +package com.tianbo.warehouse;
  2 +
  3 +import org.springframework.context.annotation.Bean;
  4 +import org.springframework.context.annotation.Configuration;
  5 +import springfox.documentation.builders.ApiInfoBuilder;
  6 +import springfox.documentation.builders.PathSelectors;
  7 +import springfox.documentation.builders.RequestHandlerSelectors;
  8 +import springfox.documentation.service.ApiInfo;
  9 +import springfox.documentation.service.Contact;
  10 +import springfox.documentation.spi.DocumentationType;
  11 +import springfox.documentation.spring.web.plugins.Docket;
  12 +import springfox.documentation.swagger2.annotations.EnableSwagger2;
  13 +
  14 +@Configuration
  15 +@EnableSwagger2
  16 +public class Swagger2 {
  17 + //swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等
  18 + @Bean
  19 + public Docket createRestApi() {
  20 + return new Docket(DocumentationType.SWAGGER_2)
  21 + .apiInfo(apiInfo())
  22 + .select()
  23 + //为当前包路径
  24 + .apis(RequestHandlerSelectors.basePackage("com.tianbo.warehouse.controller"))
  25 + .paths(PathSelectors.any())
  26 + .build();
  27 + }
  28 + //构建 api文档的详细信息函数,注意这里的注解引用的是哪个
  29 + private ApiInfo apiInfo() {
  30 + return new ApiInfoBuilder()
  31 + //页面标题
  32 + .title("Spring Boot 测试使用 Swagger2 构建RESTful API")
  33 + //创建人
  34 + .contact(new Contact("MarryFeng", "http://www.baidu.com", ""))
  35 + //版本号
  36 + .version("1.0")
  37 + //描述
  38 + .description("API 描述")
  39 + .build();
  40 + }
  41 +
  42 +
  43 +}
@@ -6,13 +6,17 @@ package com.tianbo.warehouse; @@ -6,13 +6,17 @@ package com.tianbo.warehouse;
6 6
7 import org.mybatis.spring.annotation.MapperScan; 7 import org.mybatis.spring.annotation.MapperScan;
8 import org.springframework.boot.SpringApplication; 8 import org.springframework.boot.SpringApplication;
  9 +import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
9 import org.springframework.boot.autoconfigure.SpringBootApplication; 10 import org.springframework.boot.autoconfigure.SpringBootApplication;
  11 +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
10 import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 12 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
11 import org.springframework.scheduling.annotation.EnableScheduling; 13 import org.springframework.scheduling.annotation.EnableScheduling;
  14 +import org.springframework.transaction.annotation.EnableTransactionManagement;
12 15
13 @SpringBootApplication 16 @SpringBootApplication
14 @EnableScheduling 17 @EnableScheduling
15 -@EnableEurekaClient 18 +//@EnableEurekaClient
  19 +@EnableTransactionManagement
16 @MapperScan("com.tianbo.warehouse.dao") 20 @MapperScan("com.tianbo.warehouse.dao")
17 public class WarehouseApplication { 21 public class WarehouseApplication {
18 22
  1 +package com.tianbo.warehouse.annotation;
  2 +
  3 +
  4 +import java.lang.annotation.*;
  5 +
  6 +@Retention(RetentionPolicy.RUNTIME)
  7 +@Target({ElementType.METHOD})
  8 +@Documented
  9 +/**
  10 + * 自定义日志注解
  11 + */
  12 +public @interface LogAnnotation {
  13 +
  14 + /**模块名称*/
  15 + String moduleName() default "";
  16 +
  17 + /**操作内容*/
  18 + String operate() default "";
  19 +}
  1 +package com.tianbo.warehouse.annotation;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.tianbo.warehouse.model.LOGWithBLOBs;
  5 +import com.tianbo.warehouse.service.LogService;
  6 +import com.tianbo.warehouse.util.IO.StreamUtil;
  7 +import org.aspectj.lang.JoinPoint;
  8 +import org.aspectj.lang.ProceedingJoinPoint;
  9 +import org.aspectj.lang.annotation.*;
  10 +import org.aspectj.lang.reflect.MethodSignature;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.security.core.context.SecurityContextHolder;
  13 +import org.springframework.security.core.userdetails.UserDetails;
  14 +import org.springframework.stereotype.Component;
  15 +import org.springframework.validation.BindingResult;
  16 +import org.springframework.web.context.request.RequestContextHolder;
  17 +import org.springframework.web.context.request.ServletRequestAttributes;
  18 +
  19 +import javax.servlet.http.HttpServletRequest;
  20 +import javax.servlet.http.HttpServletResponse;
  21 +import java.lang.reflect.Method;
  22 +import java.util.List;
  23 +import java.util.stream.Collectors;
  24 +import java.util.stream.Stream;
  25 +
  26 +
  27 +@Aspect
  28 +@Component
  29 +public class LogAnnotationAOP {
  30 +
  31 + @Autowired
  32 + private LogService logService;
  33 +
  34 + private LOGWithBLOBs log;
  35 +
  36 + @Pointcut("@annotation(com.tianbo.warehouse.annotation.LogAnnotation)")
  37 + public void annotationPointCut(){
  38 +
  39 + }
  40 +
  41 + @Before("annotationPointCut()")
  42 + public void before(JoinPoint point){
  43 + //获取当前登录用户信息
  44 + try{
  45 + UserDetails userDetails =(UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  46 + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
  47 + HttpServletRequest request = attributes.getRequest();
  48 + String requestRemoteAddr = request.getRemoteAddr();
  49 +
  50 + log.setIp(requestRemoteAddr);
  51 + log.setUsername(userDetails.getUsername());
  52 + }catch (Exception e){
  53 + e.printStackTrace();
  54 + }
  55 +
  56 + try{
  57 + String targetName = point.getTarget().getClass().getName();
  58 + Class targetClass = Class.forName(targetName);
  59 +
  60 + MethodSignature signature = (MethodSignature) point.getSignature();
  61 + Method method= signature.getMethod();
  62 + LogAnnotation annotation = method.getAnnotation(LogAnnotation.class);
  63 + System.out.print("打印:"+annotation.moduleName()+" 开始前");
  64 + String methodName = point.getSignature().getName();
  65 +// Method[] methods = targetClass.getMethods();
  66 +
  67 +
  68 + if(annotation != null){
  69 + log.setModelnamecn(annotation.moduleName());
  70 + log.setOperatenamecn(annotation.operate());
  71 + }
  72 + log.setClassname(targetName);
  73 + log.setMethodname(methodName);
  74 +
  75 + // 获得参数列表
  76 + Object[] params = point.getArgs();
  77 + if(params.length>0){
  78 + //序列化时过滤掉request和response,参考资料为:https://blog.csdn.net/hbn1326317071/article/details/83818059
  79 + List<Object> logArgs = StreamUtil.streamOf(params)
  80 + .filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse) && !(arg instanceof BindingResult)))
  81 + .collect(Collectors.toList());
  82 +
  83 + //将参数列表转成JSON存储
  84 + log.setParameters(JSON.toJSONString(logArgs));
  85 + }
  86 +
  87 + }catch (ClassNotFoundException e){
  88 + e.printStackTrace();
  89 + log.setResult(JSON.toJSONString(e));
  90 + logService.insertSelective(log);
  91 + }
  92 +
  93 +
  94 +
  95 +
  96 + }
  97 +
  98 + @Around("annotationPointCut()")
  99 + public Object advice(ProceedingJoinPoint joinPoint){
  100 + System.out.println("通知之开始");
  101 + log = new LOGWithBLOBs();
  102 +
  103 + Object retmsg=null;
  104 + try {
  105 + retmsg=joinPoint.proceed();
  106 + System.err.println("++++++++"+retmsg);
  107 + } catch (Throwable e) {
  108 + e.printStackTrace();
  109 + }
  110 + System.out.println("通知之结束");
  111 + return retmsg;
  112 + }
  113 +
  114 + @After("annotationPointCut()")
  115 + public void after(){
  116 + System.out.println("after方法执行后");
  117 + }
  118 +
  119 + /**
  120 + * 方法正常完成后执行方法
  121 + * @param retmsg 这里的retmsg= advice中的Object retmsg
  122 + */
  123 + @AfterReturning(returning = "retmsg",pointcut="annotationPointCut()")
  124 + public void afterReturn(Object retmsg) throws Throwable{
  125 +
  126 + // 处理完请求,返回内容
  127 + log.setResult(JSON.toJSONString(retmsg));
  128 +
  129 + logService.insertSelective(log);
  130 + }
  131 +}
  1 +package com.tianbo.warehouse.annotation;
  2 +
  3 +
  4 +import com.tianbo.warehouse.model.USERS;
  5 +
  6 +import java.lang.annotation.*;
  7 +
  8 +/**
  9 + * 将前端注册、新增、编辑后提交的明文密码MD5加密
  10 + * 使用该注解不用再MD5转换了
  11 + *
  12 + * @author adonis
  13 + *
  14 + */
  15 +@Target({ElementType.PARAMETER,ElementType.METHOD})
  16 +@Retention(RetentionPolicy.RUNTIME)
  17 +@Documented
  18 +@Inherited
  19 +public @interface UserPasswordMd5 {
  20 + String value() default "password";
  21 +
  22 +}
  1 +package com.tianbo.warehouse.annotation;
  2 +
  3 +import com.tianbo.warehouse.model.USERS;
  4 +import org.apache.commons.codec.digest.DigestUtils;
  5 +import org.aspectj.lang.JoinPoint;
  6 +import org.aspectj.lang.ProceedingJoinPoint;
  7 +import org.aspectj.lang.annotation.*;
  8 +import org.aspectj.lang.reflect.MethodSignature;
  9 +import org.springframework.stereotype.Component;
  10 +
  11 +import java.lang.reflect.Method;
  12 +
  13 +@Aspect
  14 +@Component
  15 +public class UserPasswordMd5AOP {
  16 +
  17 + @Pointcut("@annotation(com.tianbo.warehouse.annotation.UserPasswordMd5)")
  18 + public void annotationPointCut(){
  19 +
  20 + }
  21 +
  22 + @Before("annotationPointCut()")
  23 + public void before(JoinPoint joinPoint){
  24 + MethodSignature signature = (MethodSignature) joinPoint.getSignature();
  25 + Method method= signature.getMethod();
  26 + UserPasswordMd5 annotation = method.getAnnotation(UserPasswordMd5.class);
  27 + System.out.print("打印:"+annotation.value()+" 开始前");
  28 + }
  29 +
  30 + @Around("annotationPointCut()")
  31 + public Object advice(ProceedingJoinPoint joinPoint){
  32 + System.out.println("通知之开始");
  33 + Object[] args = joinPoint.getArgs();
  34 + if (args != null && args.length > 0 && args[0].getClass() == USERS.class) {
  35 + USERS user = (USERS)args[0];
  36 + user.setPassword(DigestUtils.md5Hex(user.getPassword()));
  37 + args[0] = user;
  38 +
  39 + }
  40 + Object retmsg=null;
  41 + try {
  42 + retmsg=joinPoint.proceed(args);
  43 + System.err.println("++++++++"+retmsg);
  44 + } catch (Throwable e) {
  45 + e.printStackTrace();
  46 + }
  47 + System.out.println("通知之结束");
  48 + return retmsg;
  49 + }
  50 +
  51 + @After("annotationPointCut()")
  52 + public void after(){
  53 + System.out.println("after方法执行后");
  54 + }
  55 +
  56 +}
  1 +package com.tianbo.warehouse.bean;
  2 +
  3 +import org.springframework.security.core.Authentication;
  4 +
  5 +import java.io.Serializable;
  6 +import java.util.Map;
  7 +
  8 +public class AuthSuccessResponse implements Serializable{
  9 +
  10 + private static final long serialVersionUID = 1L;
  11 +
  12 + private Authentication authentication;
  13 +
  14 + private Map<String,Object> loginUserMenus;
  15 +
  16 + public AuthSuccessResponse (Authentication authentication,Map<String,Object> loginUserMenus){
  17 + this.authentication= authentication;
  18 + this.loginUserMenus = loginUserMenus;
  19 + }
  20 +
  21 + public Authentication getAuthentication() {
  22 + return authentication;
  23 + }
  24 +
  25 + public void setAuthentication(Authentication authentication) {
  26 + this.authentication = authentication;
  27 + }
  28 +
  29 + public Map<String, Object> getLoginUserMenus() {
  30 + return loginUserMenus;
  31 + }
  32 +
  33 + public void setLoginUserMenus(Map<String, Object> loginUserMenus) {
  34 + this.loginUserMenus = loginUserMenus;
  35 + }
  36 +}
  1 +package com.tianbo.warehouse.controller;
  2 +
  3 +import com.tianbo.warehouse.model.USERS;
  4 +import com.tianbo.warehouse.service.UserService;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.security.core.context.SecurityContextHolder;
  7 +import org.springframework.security.core.context.SecurityContextImpl;
  8 +import org.springframework.security.core.userdetails.UserDetails;
  9 +import org.springframework.web.bind.annotation.GetMapping;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +import java.util.List;
  13 +
  14 +@RestController
  15 +public class AdminController {
  16 +
  17 + @Autowired
  18 + UserService userService;
  19 +
  20 + @GetMapping("/admin")
  21 + public String admin(){
  22 + return "admin";
  23 + }
  24 +
  25 +
  26 +}
1 package com.tianbo.warehouse.controller; 1 package com.tianbo.warehouse.controller;
2 2
3 -import com.tianbo.warehouse.model.PERMISSION;  
4 import org.springframework.stereotype.Controller; 3 import org.springframework.stereotype.Controller;
5 -import org.springframework.ui.Model;  
6 import org.springframework.web.bind.annotation.RequestMapping; 4 import org.springframework.web.bind.annotation.RequestMapping;
7 import org.springframework.web.bind.annotation.ResponseBody; 5 import org.springframework.web.bind.annotation.ResponseBody;
8 6
9 @Controller 7 @Controller
10 -public class ImfLog { 8 +public class ImfLogController {
  9 +
11 10
12 @RequestMapping("/log/imf") 11 @RequestMapping("/log/imf")
13 public String IMFlog(){ 12 public String IMFlog(){
14 return "log/imf"; 13 return "log/imf";
15 } 14 }
16 15
17 - @RequestMapping("/home")  
18 - public String Home(Model model){  
19 - PERMISSION msg = new PERMISSION();  
20 - msg.setDescription("权限描述");  
21 - msg.setPermissionName("权限名称");  
22 - msg.setPermissionSign("权限路径");  
23 - model.addAttribute("msg", msg);  
24 - return "home";  
25 - }  
26 16
27 - @RequestMapping("/admin") 17 + @RequestMapping("/logs")
28 @ResponseBody 18 @ResponseBody
29 - public String Admin(){  
30 - return "hello admin";  
31 - }  
32 -  
33 - @RequestMapping("/login")  
34 - public String login(){  
35 - return "login"; 19 + public String logs(){
  20 + return "logs";
36 } 21 }
37 } 22 }
38 23
@@ -11,7 +11,8 @@ public class IndexController { @@ -11,7 +11,8 @@ public class IndexController {
11 11
12 @GetMapping("index") 12 @GetMapping("index")
13 public String index(){ 13 public String index(){
14 - return "数据仓库接收,落地报文给新舱单"; 14 + return "forward:/login";
  15 +// return "数据仓库接收,落地报文给新舱单";
15 } 16 }
16 17
17 18
  1 +package com.tianbo.warehouse.controller;
  2 +
  3 +
  4 +import com.github.pagehelper.PageInfo;
  5 +import com.tianbo.warehouse.model.LOGWithBLOBs;
  6 +import com.tianbo.warehouse.service.LogService;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.web.bind.annotation.GetMapping;
  9 +import org.springframework.web.bind.annotation.RequestParam;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +@RestController
  13 +public class LogController {
  14 +
  15 + @Autowired
  16 + private LogService logService;
  17 +
  18 + @GetMapping("/system/log/list")
  19 + public PageInfo<LOGWithBLOBs> systemLog(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
  20 + int pageNum,
  21 + @RequestParam(value = "pageSize",required = false,defaultValue = "5")
  22 + int pageSize){
  23 + return logService.selectAll(pageNum,pageSize);
  24 + }
  25 +}
@@ -15,7 +15,7 @@ import java.util.concurrent.CopyOnWriteArraySet; @@ -15,7 +15,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
15 15
16 @ServerEndpoint(value = "/log") 16 @ServerEndpoint(value = "/log")
17 @Component 17 @Component
18 -public class Log { 18 +public class LogWebsockController {
19 private Process process; 19 private Process process;
20 private InputStream inputStream; 20 private InputStream inputStream;
21 //与某个客户端的连接会话,需要通过它来给客户端发送数据 21 //与某个客户端的连接会话,需要通过它来给客户端发送数据
@@ -24,7 +24,7 @@ public class Log { @@ -24,7 +24,7 @@ public class Log {
24 //静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。 24 //静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
25 private static int onlineCount = 0; 25 private static int onlineCount = 0;
26 //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。 26 //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
27 - private static CopyOnWriteArraySet<Log> webSocketSet = new CopyOnWriteArraySet<Log>(); 27 + private static CopyOnWriteArraySet<LogWebsockController> webSocketSet = new CopyOnWriteArraySet<LogWebsockController>();
28 28
29 29
30 @OnOpen 30 @OnOpen
@@ -67,7 +67,7 @@ public class Log { @@ -67,7 +67,7 @@ public class Log {
67 } 67 }
68 68
69 public static synchronized void addOnlineCount() { 69 public static synchronized void addOnlineCount() {
70 - Log.onlineCount++; 70 + LogWebsockController.onlineCount++;
71 } 71 }
72 public static synchronized int getOnlineCount() { 72 public static synchronized int getOnlineCount() {
73 return onlineCount; 73 return onlineCount;
  1 +package com.tianbo.warehouse.controller;
  2 +
  3 +import org.springframework.stereotype.Controller;
  4 +import org.springframework.web.bind.annotation.RequestMapping;
  5 +
  6 +@Controller
  7 +public class LoginController {
  8 +
  9 + @RequestMapping("/login")
  10 + public String login(){
  11 + return "login";
  12 + }
  13 +}
  1 +package com.tianbo.warehouse.controller;
  2 +
  3 +import com.tianbo.warehouse.model.USERS;
  4 +import com.tianbo.warehouse.service.UserService;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.web.bind.annotation.GetMapping;
  7 +import org.springframework.web.bind.annotation.RestController;
  8 +
  9 +import java.util.List;
  10 +
  11 +@RestController
  12 +public class MainController {
  13 +
  14 + @Autowired
  15 + UserService userService;
  16 +
  17 + @GetMapping("/error")
  18 + public String error(){
  19 + return "error";
  20 + }
  21 +
  22 + @GetMapping("/main")
  23 + public String main(){
  24 + return "main";
  25 + }
  26 +}
  1 +package com.tianbo.warehouse.controller;
  2 +
  3 +import com.github.pagehelper.PageInfo;
  4 +import com.tianbo.warehouse.annotation.LogAnnotation;
  5 +import com.tianbo.warehouse.controller.response.ResultJson;
  6 +import com.tianbo.warehouse.dao.PERMISSIONMapper;
  7 +import com.tianbo.warehouse.model.PERMISSION;
  8 +import com.tianbo.warehouse.model.ROLE;
  9 +import com.tianbo.warehouse.service.PermissionService;
  10 +import org.apache.cxf.annotations.Logging;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.security.core.context.SecurityContextHolder;
  13 +import org.springframework.security.core.userdetails.UserDetails;
  14 +import org.springframework.web.bind.annotation.*;
  15 +
  16 +import java.util.List;
  17 +import java.util.Map;
  18 +
  19 +
  20 +@Logging
  21 +@RestController()
  22 +public class PermssionController {
  23 +
  24 + @Autowired
  25 + PermissionService permissionService;
  26 +
  27 + @GetMapping("/perm/list")
  28 + public PageInfo<PERMISSION> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
  29 + int pageNum,
  30 + @RequestParam(value = "pageSize",required = false,defaultValue = "5")
  31 + int pageSize){
  32 + return permissionService.findAll(pageNum,pageSize);
  33 +
  34 + }
  35 +
  36 + @LogAnnotation(moduleName = "权限管理",operate = "权限添加")
  37 + @PostMapping("/perm/add")
  38 + public ResultJson add(@RequestBody PERMISSION permission){
  39 + int i =permissionService.insertSelective(permission);
  40 +
  41 + ResultJson resultJson = new ResultJson();
  42 + if (1==i){
  43 + resultJson = new ResultJson("200","添加账户成功");
  44 + }else {
  45 + resultJson = new ResultJson("500","insert faild");
  46 + }
  47 + return resultJson;
  48 + }
  49 +}
  1 +package com.tianbo.warehouse.controller;
  2 +
  3 +import com.github.pagehelper.PageInfo;
  4 +import com.tianbo.warehouse.annotation.LogAnnotation;
  5 +import com.tianbo.warehouse.controller.response.ResultJson;
  6 +import com.tianbo.warehouse.model.ROLE;
  7 +import com.tianbo.warehouse.model.RolePermission;
  8 +import com.tianbo.warehouse.service.RoleService;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.web.bind.annotation.*;
  11 +
  12 +@RestController()
  13 +public class RoleController {
  14 +
  15 + @Autowired
  16 + RoleService roleService;
  17 +
  18 + @GetMapping("/role/list")
  19 + public PageInfo<ROLE> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
  20 + int pageNum,
  21 + @RequestParam(value = "pageSize",required = false,defaultValue = "5")
  22 + int pageSize){
  23 + return roleService.findAll(pageNum,pageSize);
  24 + }
  25 +
  26 + @LogAnnotation(moduleName = "角色管理",operate = "角色添加")
  27 + @PostMapping("/role/add")
  28 + public ResultJson add(@RequestBody ROLE role){
  29 + int i =roleService.insertSelective(role);
  30 + return i==1 ? new ResultJson("200","添加权限成功") :new ResultJson("500","insert faild");
  31 +
  32 + }
  33 +
  34 + /**
  35 + * 设置角色的权限
  36 + * @return
  37 + */
  38 + @LogAnnotation(moduleName = "角色管理",operate = "权限设置")
  39 + @PutMapping("/role/permSet")
  40 + public ResultJson permissionSet(@RequestBody RolePermission rolePermission){
  41 + int i = roleService.setRolePermissoin(rolePermission);
  42 + return i==1 ? new ResultJson("200","设置权限成功") :new ResultJson("500","设置权限失败");
  43 + }
  44 +}
  1 +package com.tianbo.warehouse.controller;
  2 +
  3 +import com.tianbo.warehouse.controller.response.ResultJson;
  4 +import com.tianbo.warehouse.model.Attachment;
  5 +import com.tianbo.warehouse.service.AttachmentService;
  6 +import com.tianbo.warehouse.util.Date.DateUtil;
  7 +import com.tianbo.warehouse.util.Helper;
  8 +import org.apache.commons.io.FileUtils;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.beans.factory.annotation.Value;
  11 +import org.springframework.web.bind.annotation.PostMapping;
  12 +import org.springframework.web.bind.annotation.RequestParam;
  13 +import org.springframework.web.bind.annotation.RestController;
  14 +import org.springframework.web.multipart.MultipartFile;
  15 +
  16 +import java.io.File;
  17 +import java.io.IOException;
  18 +
  19 +import static com.tianbo.warehouse.util.IO.FileTool.readProperties;
  20 +
  21 +@RestController
  22 +public class UploadController {
  23 +
  24 + @Autowired
  25 + private AttachmentService attachmentService;
  26 +
  27 + @Value("${web.upload-path}")
  28 + private String uploadPath; // =./upload/
  29 + /**
  30 + * 单个文件上传
  31 + * @param file
  32 + * @return
  33 + * @throws Exception
  34 + */
  35 + @PostMapping("/upload")
  36 + public ResultJson upload(@RequestParam MultipartFile file) throws Exception {
  37 + ResultJson resultJson = new ResultJson();
  38 + if (null!=file && !file.isEmpty() && file.getSize()>0){
  39 + byte[] filebyte = file.getBytes();
  40 + String fileLitleName = file.getName();
  41 + String fileName = file.getOriginalFilename();
  42 + String fileType = fileName.substring((fileName.lastIndexOf(".")));
  43 + StringBuffer stringBuffer = new StringBuffer();
  44 + String saveFileName = stringBuffer.append(uploadPath).append(DateUtil.getToday()).append("/").append(Helper.getUUID()).append(fileType).toString();
  45 + File saveFile = new File(saveFileName);
  46 + if(!saveFile.getParentFile().exists()){
  47 + saveFile.mkdirs();
  48 + }
  49 +
  50 + try{
  51 + FileUtils.writeByteArrayToFile(saveFile,filebyte);
  52 + Attachment attachment = new Attachment(saveFileName);
  53 + int i =attachmentService.insertSelective(attachment);
  54 + resultJson = (i==1 ? new ResultJson("200","附件入库成功",saveFileName) :new ResultJson("500","附件入库失败"));
  55 + }catch (IOException e){
  56 + resultJson = new ResultJson("400","附件存储失败",e);
  57 + e.printStackTrace();
  58 + }catch (IllegalStateException e){
  59 + resultJson = new ResultJson("400","附件存储失败",e);
  60 + e.printStackTrace();
  61 + }
  62 + }
  63 + return resultJson;
  64 + }
  65 +
  66 + /**
  67 + * 批量上传
  68 + * @param files
  69 + * @return
  70 + * @throws Exception
  71 + */
  72 + @PostMapping("/uploads")
  73 + public ResultJson upload(MultipartFile[] files) throws Exception {
  74 + if (files!=null && files.length>0){
  75 + // ... 处理文件储存逻辑
  76 + for (MultipartFile file : files) {
  77 + if (!file.isEmpty() && file.getSize()>0){
  78 + String fileName = file.getName();
  79 + String fileType = file.getContentType();
  80 + String saveDir = readProperties("uploadDirectory");
  81 + StringBuffer stringBuffer = new StringBuffer();
  82 + stringBuffer.append(saveDir).append("/").append(DateUtil.getToday()).append("/").append(fileType).append(Helper.getUUID()).append(fileName);
  83 + File saveFile = new File(stringBuffer.toString());
  84 + try{
  85 + file.transferTo(saveFile);
  86 + }catch (IOException e){
  87 + e.printStackTrace();
  88 + }catch (IllegalStateException e){
  89 + e.printStackTrace();
  90 + }
  91 +
  92 + }
  93 +
  94 + }
  95 + }
  96 + return new ResultJson();
  97 + }
  98 +}
  1 +package com.tianbo.warehouse.controller;
  2 +
  3 +import com.github.pagehelper.PageInfo;
  4 +import com.tianbo.warehouse.annotation.LogAnnotation;
  5 +import com.tianbo.warehouse.annotation.UserPasswordMd5;
  6 +import com.tianbo.warehouse.controller.response.ResultJson;
  7 +import com.tianbo.warehouse.model.USERS;
  8 +import com.tianbo.warehouse.model.UserRole;
  9 +import com.tianbo.warehouse.service.UserService;
  10 +import io.swagger.annotations.Api;
  11 +import io.swagger.annotations.ApiImplicitParam;
  12 +import io.swagger.annotations.ApiImplicitParams;
  13 +import io.swagger.annotations.ApiOperation;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.security.core.context.SecurityContextHolder;
  16 +import org.springframework.security.core.userdetails.UserDetails;
  17 +import org.springframework.validation.BindingResult;
  18 +import org.springframework.web.bind.annotation.*;
  19 +
  20 +import javax.servlet.http.HttpServletRequest;
  21 +import javax.servlet.http.HttpServletResponse;
  22 +import javax.validation.Valid;
  23 +
  24 +@RestController
  25 +@RequestMapping("/user")
  26 +@Api("swaggerDemoController相关的api")
  27 +public class UserController {
  28 +
  29 + @Autowired
  30 + UserService userService;
  31 +
  32 + @ApiOperation(value = "查询用户列表及信息", notes = "查询用户列表及单个用户信息")
  33 + @ApiImplicitParams({@ApiImplicitParam(name = "pageNum", value = "分页-当前页", required = false, dataType = "int",defaultValue = "1"),
  34 + @ApiImplicitParam(name = "pageSize", value = "分页-每页显示多少条", required = false, dataType = "int",defaultValue = "5")})
  35 + @GetMapping("/user/list")
  36 + public PageInfo<USERS> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
  37 + int pageNum,
  38 + @RequestParam(value = "pageSize",required = false,defaultValue = "5")
  39 + int pageSize){
  40 + return userService.selectAllUser(pageNum,pageSize);
  41 + }
  42 +
  43 + public String getusername(){
  44 +
  45 + //通过session获取当前登录的用户信息
  46 + UserDetails userDetails =(UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  47 + return "欢迎回来:"+userDetails.getUsername();
  48 + }
  49 +
  50 + @LogAnnotation(moduleName = "用户管理",operate = "用户编辑")
  51 + @UserPasswordMd5
  52 + @PutMapping("/user/edit")
  53 + public ResultJson updateUserById(@RequestBody @Valid USERS user){
  54 + int i = userService.updateByPrimaryKeySelective(user);
  55 + ResultJson resultJson = new ResultJson();
  56 + return i==1 ? new ResultJson("200","success") :new ResultJson("500","update faild");
  57 +
  58 + }
  59 +
  60 + @UserPasswordMd5
  61 + @LogAnnotation(moduleName = "用户管理",operate = "用户添加")
  62 + @PostMapping("/user/add")
  63 + public ResultJson addUser(@RequestBody @Valid USERS user, HttpServletRequest request, HttpServletResponse response, BindingResult bindingResult){
  64 +
  65 + if (bindingResult.hasErrors()){
  66 + String s = bindingResult.toString();
  67 + }
  68 +
  69 + int i = userService.insertSelective(user);
  70 + ResultJson resultJson = new ResultJson();
  71 + return i==1 ? new ResultJson("200","新建账户成功") :new ResultJson("500","insert faild");
  72 +
  73 + }
  74 +
  75 + @LogAnnotation(moduleName = "用户管理",operate = "用户删除")
  76 + @DeleteMapping("/user/del")
  77 + public ResultJson delUser(@RequestBody USERS user,HttpServletRequest request,HttpServletResponse response){
  78 + //String username = getusername();
  79 + int i = userService.deleteByPrimaryKey(user.getUserId());
  80 + ResultJson resultJson = new ResultJson();
  81 + return i==1 ? new ResultJson("200","删除账户成功") :new ResultJson("500","delete faild");
  82 +
  83 + }
  84 +
  85 + @PutMapping("/user/roleset")
  86 + public ResultJson roleSet(@RequestBody UserRole userRole){
  87 +
  88 + int i = userService.setUserRole(userRole);
  89 +
  90 + return i==1 ? new ResultJson("200","设置角色成功") :new ResultJson("500","设置角色失败");
  91 +
  92 + }
  93 +
  94 +}
  1 +package com.tianbo.warehouse.controller.response;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import org.springframework.core.MethodParameter;
  5 +import org.springframework.http.MediaType;
  6 +import org.springframework.http.converter.HttpMessageConverter;
  7 +import org.springframework.http.server.ServerHttpRequest;
  8 +import org.springframework.http.server.ServerHttpResponse;
  9 +import org.springframework.web.bind.annotation.ControllerAdvice;
  10 +import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
  11 +
  12 +/**
  13 + * 统一拦截response接口返回数据
  14 + */
  15 +//@ControllerAdvice
  16 +public class RestControllerResponseAdvice implements ResponseBodyAdvice<Object>{
  17 +
  18 + /**
  19 + * //判断支持的类型,因为我们定义的BaseResponseVo 里面的data可能是任何类型,这里就不判断统一放过
  20 + * 如果你想对执行的返回体进行操作,可将上方的Object换成你自己的类型
  21 + * @param returnType
  22 + * @param converterType
  23 + * @return
  24 + */
  25 + @Override
  26 + public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType){
  27 + return true;
  28 + }
  29 +
  30 + @Override
  31 + public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response){
  32 + // 对body进行封装处理
  33 + if (body instanceof String) {
  34 + String msg = (String) body;
  35 + ResultJson resultJson = new ResultJson("-1", msg);
  36 + // 因为在controller层中返回的是String类型,这边如果换成ResultJson的话,会导致StringMessageConverter方法类型转换异常,所以这边将对象转成字符串
  37 + return JSON.toJSONString(resultJson);
  38 + } else if (body instanceof Object) {
  39 + Object data = (Object) body;
  40 + ResultJson resultJson = new ResultJson(data);
  41 + return resultJson;
  42 + }
  43 +
  44 + return body;
  45 + }
  46 +}
  1 +package com.tianbo.warehouse.controller.response;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +public class ResultJson implements Serializable{
  6 + private static final long serialVersionUID = 1L;
  7 +
  8 + // 状态码 正确为0
  9 + private String code = "0";
  10 + // 错误描述
  11 + private String msg = "";
  12 + // 返回对象
  13 + private Object data = "";
  14 +
  15 + public ResultJson() {
  16 + }
  17 +
  18 + public ResultJson(String code) {
  19 + this.code = code;
  20 + }
  21 +
  22 + public ResultJson(String code, String msg) {
  23 + this.code = code;
  24 + this.msg = msg;
  25 + }
  26 +
  27 + public ResultJson(Object data) {
  28 + this.data = data;
  29 + }
  30 +
  31 + public ResultJson(String code, String msg, Object data) {
  32 + this.code = code;
  33 + this.msg = msg;
  34 + this.data = data;
  35 + }
  36 +
  37 + public String getCode() {
  38 + return code;
  39 + }
  40 +
  41 + public void setCode(String code) {
  42 + this.code = code;
  43 + }
  44 +
  45 + public String getMsg() {
  46 + return msg;
  47 + }
  48 +
  49 + public void setMsg(String msg) {
  50 + this.msg = msg;
  51 + }
  52 +
  53 + public Object getData() {
  54 + return data;
  55 + }
  56 +
  57 + public void setData(Object data) {
  58 + this.data = data;
  59 + }
  60 +}
  1 +package com.tianbo.warehouse.dao;
  2 +
  3 +import com.tianbo.warehouse.model.Attachment;
  4 +
  5 +public interface AttachmentMapper {
  6 + int deleteByPrimaryKey(Integer aid);
  7 +
  8 + int insert(Attachment record);
  9 +
  10 + int insertSelective(Attachment record);
  11 +
  12 + Attachment selectByPrimaryKey(Integer aid);
  13 +
  14 + int updateByPrimaryKeySelective(Attachment record);
  15 +
  16 + int updateByPrimaryKey(Attachment record);
  17 +}
  1 +package com.tianbo.warehouse.dao;
  2 +
  3 +import com.tianbo.warehouse.model.LOG;
  4 +import com.tianbo.warehouse.model.LOGWithBLOBs;
  5 +
  6 +import java.util.List;
  7 +
  8 +public interface LOGMapper {
  9 + int deleteByPrimaryKey(Integer logid);
  10 +
  11 + int insert(LOGWithBLOBs record);
  12 +
  13 + int insertSelective(LOGWithBLOBs record);
  14 +
  15 + LOGWithBLOBs selectByPrimaryKey(Integer logid);
  16 +
  17 + List<LOGWithBLOBs> selectAll();
  18 +
  19 + int updateByPrimaryKeySelective(LOGWithBLOBs record);
  20 +
  21 + int updateByPrimaryKeyWithBLOBs(LOGWithBLOBs record);
  22 +
  23 + int updateByPrimaryKey(LOG record);
  24 +}
  1 +package com.tianbo.warehouse.dao;
  2 +
  3 +import com.tianbo.warehouse.model.PERMISSION;
  4 +
  5 +import java.math.BigDecimal;
  6 +import java.util.List;
  7 +
  8 +public interface PERMISSIONMapper {
  9 + int deleteByPrimaryKey(Integer permissionId);
  10 +
  11 + int insert(PERMISSION record);
  12 +
  13 + int insertSelective(PERMISSION record);
  14 +
  15 + PERMISSION selectByPrimaryKey(Integer permissionId);
  16 +
  17 + int updateByPrimaryKeySelective(PERMISSION record);
  18 +
  19 + int updateByPrimaryKey(PERMISSION record);
  20 +
  21 + List<PERMISSION> findAll();
  22 +
  23 + List<PERMISSION> getAllMenus();
  24 +
  25 + List<PERMISSION> findByUserId(Integer userId);
  26 +
  27 + List<String> findRoleListByUrl(String permissionUrl);
  28 +
  29 + List<PERMISSION> getRolePermisson(Integer roleId);
  30 +}
  1 +package com.tianbo.warehouse.dao;
  2 +
  3 +import com.tianbo.warehouse.model.PERMISSION;
  4 +import com.tianbo.warehouse.model.ROLE;
  5 +
  6 +import java.math.BigDecimal;
  7 +import java.util.HashMap;
  8 +import java.util.List;
  9 +import java.util.Map;
  10 +
  11 +public interface ROLEMapper {
  12 + int deleteByPrimaryKey(Integer roleId);
  13 +
  14 + int insert(ROLE record);
  15 +
  16 + int insertSelective(ROLE record);
  17 +
  18 + ROLE selectByPrimaryKey(Integer roleId);
  19 +
  20 + int updateByPrimaryKeySelective(ROLE record);
  21 +
  22 + int updateByPrimaryKey(ROLE record);
  23 +
  24 + List<ROLE> findRolesByUserId(Integer userId);
  25 +
  26 + List<ROLE> findAll();
  27 +
  28 +
  29 +}
  1 +package com.tianbo.warehouse.dao;
  2 +
  3 +import com.tianbo.warehouse.model.RolePermission;
  4 +
  5 +import java.util.Map;
  6 +
  7 +public interface RolePermissionMapper {
  8 + int deleteByPrimaryKey(Integer id);
  9 +
  10 + int insert(RolePermission record);
  11 +
  12 + int insertSelective(RolePermission record);
  13 +
  14 + RolePermission selectByPrimaryKey(Integer id);
  15 +
  16 + int updateByPrimaryKeySelective(RolePermission record);
  17 +
  18 + int updateByPrimaryKey(RolePermission record);
  19 +
  20 + int insertRolePerm(RolePermission record);
  21 +
  22 + int delPermByRoleId(Integer roleId);
  23 +
  24 +}
  1 +package com.tianbo.warehouse.dao;
  2 +
  3 +import com.tianbo.warehouse.model.USERS;
  4 +
  5 +import java.util.List;
  6 +
  7 +public interface USERSMapper {
  8 + int deleteByPrimaryKey(Integer userId);
  9 +
  10 + int insert(USERS record);
  11 +
  12 + int insertSelective(USERS record);
  13 +
  14 + USERS selectByPrimaryKey(Integer userId);
  15 +
  16 + int updateByPrimaryKeySelective(USERS record);
  17 +
  18 + int updateByPrimaryKey(USERS record);
  19 +
  20 + List<USERS> selectByUsername(String userName);
  21 +
  22 + List<USERS> selectAllUser();
  23 +}
  1 +package com.tianbo.warehouse.dao;
  2 +
  3 +import com.tianbo.warehouse.model.UserRole;
  4 +
  5 +public interface UserRoleMapper {
  6 + int deleteByPrimaryKey(Integer id);
  7 +
  8 + int deleteByUserId(Integer userId);
  9 +
  10 + int insert(UserRole record);
  11 +
  12 + int insertSelective(UserRole record);
  13 +
  14 + UserRole selectByPrimaryKey(Integer id);
  15 +
  16 + int updateByPrimaryKeySelective(UserRole record);
  17 +
  18 + int updateByPrimaryKey(UserRole record);
  19 +}
1 package com.tianbo.warehouse.imf; 1 package com.tianbo.warehouse.imf;
2 2
3 import com.caac.imf.api.IMFClient; 3 import com.caac.imf.api.IMFClient;
4 -import com.tianbo.warehouse.handle.IMFSaveHandle;  
5 -import com.tianbo.warehouse.schedul.IMF_Task;  
6 -import com.tianbo.warehouse.util.IO.FileTool; 4 +import com.tianbo.warehouse.imf.handle.IMFSaveHandle;
  5 +import com.tianbo.warehouse.imf.schedul.IMF_Task;
7 import org.apache.log4j.Logger; 6 import org.apache.log4j.Logger;
8 7
9 public class IMF_Reader extends Thread{ 8 public class IMF_Reader extends Thread{
1 package com.tianbo.warehouse.imf; 1 package com.tianbo.warehouse.imf;
2 2
3 import com.caac.imf.api.IMFClient; 3 import com.caac.imf.api.IMFClient;
4 -import com.tianbo.warehouse.schedul.IMF_Task; 4 +import com.tianbo.warehouse.imf.schedul.IMF_Task;
5 import com.tianbo.warehouse.util.Date.DateUtil; 5 import com.tianbo.warehouse.util.Date.DateUtil;
6 import com.tianbo.warehouse.util.IO.FileTool; 6 import com.tianbo.warehouse.util.IO.FileTool;
7 import com.tianbo.warehouse.util.XML.MakeImfMeta; 7 import com.tianbo.warehouse.util.XML.MakeImfMeta;
8 import org.apache.commons.io.FileUtils; 8 import org.apache.commons.io.FileUtils;
9 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
10 -import org.xml.sax.SAXParseException;  
11 10
12 -import java.io.File;  
13 -import java.io.UnsupportedEncodingException; 11 +import java.io.*;
14 import java.util.Iterator; 12 import java.util.Iterator;
15 import java.util.List; 13 import java.util.List;
16 14
1 -package com.tianbo.warehouse.handle; 1 +package com.tianbo.warehouse.imf.handle;
2 2
3 import com.tianbo.warehouse.model.T_ETL_MESSAGE; 3 import com.tianbo.warehouse.model.T_ETL_MESSAGE;
4 import com.tianbo.warehouse.service.T_ETL_MESSAGEService; 4 import com.tianbo.warehouse.service.T_ETL_MESSAGEService;
@@ -55,19 +55,17 @@ public class IMFSaveHandle { @@ -55,19 +55,17 @@ public class IMFSaveHandle {
55 String sndrm = meta.get("SNDR").toString(); 55 String sndrm = meta.get("SNDR").toString();
56 String stypm = meta.get("STYP").toString(); 56 String stypm = meta.get("STYP").toString();
57 57
  58 +
  59 +
58 if ("TXD".equals(sndrm)){ 60 if ("TXD".equals(sndrm)){
59 - if("EDEP".equals(stypm)  
60 - || "EFOH".equals(stypm)  
61 - || "ERCF".equals(stypm)  
62 - || "PFFM".equals(stypm)  
63 - || "UDEP".equals(stypm)  
64 - || "UFOH".equals(stypm)  
65 - || "URCF".equals(stypm)  
66 - || "FFM".equals(stypm)  
67 - || "IFWB".equals(stypm)  
68 - || "IFHL".equals(stypm)){  
69 - //存储至备份目录  
70 - FileTool.writeFileToBak(xmlmessage); 61 + //读取配置文件的需要本地存储报文的节点
  62 + String saveStyp= FileTool.readProperties("saveStyp");
  63 + String[] styps = saveStyp.split(",");
  64 + for (String item: styps) {
  65 + if (item.equals(stypm)){
  66 + //存储至备份目录
  67 + FileTool.writeFileToBak(xmlmessage);
  68 + }
71 } 69 }
72 } 70 }
73 71
1 -package com.tianbo.warehouse.schedul; 1 +package com.tianbo.warehouse.imf.schedul;
2 2
3 import com.caac.imf.api.IMFClient; 3 import com.caac.imf.api.IMFClient;
4 import com.caac.imf.api.IMFClientFactory; 4 import com.caac.imf.api.IMFClientFactory;
@@ -7,7 +7,6 @@ import com.tianbo.warehouse.imf.IMF_Sender; @@ -7,7 +7,6 @@ import com.tianbo.warehouse.imf.IMF_Sender;
7 import com.tianbo.warehouse.util.IO.FileTool; 7 import com.tianbo.warehouse.util.IO.FileTool;
8 import org.apache.log4j.Logger; 8 import org.apache.log4j.Logger;
9 import org.apache.log4j.PropertyConfigurator; 9 import org.apache.log4j.PropertyConfigurator;
10 -import org.springframework.scheduling.annotation.Scheduled;  
11 import org.springframework.stereotype.Component; 10 import org.springframework.stereotype.Component;
12 11
13 import java.text.SimpleDateFormat; 12 import java.text.SimpleDateFormat;
@@ -24,7 +23,7 @@ public class IMF_Task { @@ -24,7 +23,7 @@ public class IMF_Task {
24 public static String isNeedSend = "N"; 23 public static String isNeedSend = "N";
25 24
26 25
27 - @Scheduled(fixedRate = 5000) 26 +// @Scheduled(fixedRate = 5000)
28 private static void start() throws Exception { 27 private static void start() throws Exception {
29 PropertyConfigurator.configure("config/log4j.properties"); 28 PropertyConfigurator.configure("config/log4j.properties");
30 client = IMFClientFactory.createInstance(); 29 client = IMFClientFactory.createInstance();
@@ -41,6 +40,7 @@ public class IMF_Task { @@ -41,6 +40,7 @@ public class IMF_Task {
41 //启动读取线程 40 //启动读取线程
42 if (client != null) { 41 if (client != null) {
43 IMF_Reader reader = new IMF_Reader(client); 42 IMF_Reader reader = new IMF_Reader(client);
  43 +
44 if (!IMF_Reader.isrunning) { 44 if (!IMF_Reader.isrunning) {
45 reader.start(); 45 reader.start();
46 logger.info("*********读取线程已开启***********"); 46 logger.info("*********读取线程已开启***********");
  1 +package com.tianbo.warehouse.model;
  2 +
  3 +import lombok.Data;
  4 +
  5 +@Data
  6 +public class Attachment {
  7 + private Integer aid;
  8 +
  9 + private String path;
  10 +
  11 + public Attachment(String path){
  12 + this.path = path;
  13 + }
  14 +}
  1 +package com.tianbo.warehouse.model;
  2 +
  3 +import java.util.Date;
  4 +
  5 +public class LOG {
  6 + private Integer logid;
  7 +
  8 + private String username;
  9 +
  10 + private String ip;
  11 +
  12 + private Date logcreattime;
  13 +
  14 + private String methodname;
  15 +
  16 + private String modelnamecn;
  17 +
  18 + private String operatenamecn;
  19 +
  20 + private String classname;
  21 +
  22 + public Integer getLogid() {
  23 + return logid;
  24 + }
  25 +
  26 + public void setLogid(Integer logid) {
  27 + this.logid = logid;
  28 + }
  29 +
  30 + public String getUsername() {
  31 + return username;
  32 + }
  33 +
  34 + public void setUsername(String username) {
  35 + this.username = username == null ? null : username.trim();
  36 + }
  37 +
  38 + public String getIp() {
  39 + return ip;
  40 + }
  41 +
  42 + public void setIp(String ip) {
  43 + this.ip = ip == null ? null : ip.trim();
  44 + }
  45 +
  46 + public Date getLogcreattime() {
  47 + return logcreattime;
  48 + }
  49 +
  50 + public void setLogcreattime(Date logcreattime) {
  51 + this.logcreattime = logcreattime;
  52 + }
  53 +
  54 + public String getMethodname() {
  55 + return methodname;
  56 + }
  57 +
  58 + public void setMethodname(String methodname) {
  59 + this.methodname = methodname == null ? null : methodname.trim();
  60 + }
  61 +
  62 + public String getModelnamecn() {
  63 + return modelnamecn;
  64 + }
  65 +
  66 + public void setModelnamecn(String modelnamecn) {
  67 + this.modelnamecn = modelnamecn == null ? null : modelnamecn.trim();
  68 + }
  69 +
  70 + public String getOperatenamecn() {
  71 + return operatenamecn;
  72 + }
  73 +
  74 + public void setOperatenamecn(String operatenamecn) {
  75 + this.operatenamecn = operatenamecn == null ? null : operatenamecn.trim();
  76 + }
  77 +
  78 + public String getClassname() {
  79 + return classname;
  80 + }
  81 +
  82 + public void setClassname(String classname) {
  83 + this.classname = classname == null ? null : classname.trim();
  84 + }
  85 +}
  1 +package com.tianbo.warehouse.model;
  2 +
  3 +public class LOGWithBLOBs extends LOG {
  4 + private String parameters;
  5 +
  6 + private String result;
  7 +
  8 + public String getParameters() {
  9 + return parameters;
  10 + }
  11 +
  12 + public void setParameters(String parameters) {
  13 + this.parameters = parameters == null ? null : parameters.trim();
  14 + }
  15 +
  16 + public String getResult() {
  17 + return result;
  18 + }
  19 +
  20 + public void setResult(String result) {
  21 + this.result = result == null ? null : result.trim();
  22 + }
  23 +}
  1 +package com.tianbo.warehouse.model;
  2 +
  3 +import java.util.List;
  4 +
  5 +public class PERMISSION {
  6 + private Integer permissionId;
  7 +
  8 + private String name;
  9 +
  10 + private String permissionOrder;
  11 +
  12 + private String description;
  13 +
  14 + private Boolean ismenu;
  15 +
  16 + private Boolean hidden;
  17 +
  18 + private Integer parentId;
  19 +
  20 + private String path;
  21 +
  22 + private String url;
  23 +
  24 + private String method;
  25 +
  26 + private String iconCls;
  27 +
  28 + private String component;
  29 +
  30 + private List<PERMISSION> children;
  31 +
  32 + public Integer getPermissionId() {
  33 + return permissionId;
  34 + }
  35 +
  36 + public String getName() {
  37 + return name;
  38 + }
  39 +
  40 + public void setName(String name) {
  41 + this.name = name;
  42 + }
  43 +
  44 + public String getPermissionOrder() {
  45 + return permissionOrder;
  46 + }
  47 +
  48 + public void setPermissionOrder(String permissionOrder) {
  49 + this.permissionOrder = permissionOrder;
  50 + }
  51 +
  52 + public String getDescription() {
  53 + return description;
  54 + }
  55 +
  56 + public void setDescription(String description) {
  57 + this.description = description == null ? null : description.trim();
  58 + }
  59 +
  60 + public Boolean getIsmenu() {
  61 + return ismenu;
  62 + }
  63 +
  64 + public void setIsmenu(Boolean ismenu) {
  65 + this.ismenu = ismenu;
  66 + }
  67 +
  68 + public Integer getParentId() {
  69 + return parentId;
  70 + }
  71 +
  72 + public void setParentId(Integer parentId) {
  73 + this.parentId = parentId;
  74 + }
  75 +
  76 + public String getPath() {
  77 + return path;
  78 + }
  79 +
  80 + public void setPath(String path) {
  81 + this.path = path == null ? null : path.trim();
  82 + }
  83 +
  84 + public String getUrl() {
  85 + return url;
  86 + }
  87 +
  88 + public void setUrl(String url) {
  89 + this.url = url == null ? null : url.trim();
  90 + }
  91 +
  92 + public String getMethod() {
  93 + return method;
  94 + }
  95 +
  96 + public void setMethod(String method) {
  97 + this.method = method;
  98 + }
  99 +
  100 + public String getIconCls() {
  101 + return iconCls;
  102 + }
  103 +
  104 + public void setIconCls(String iconCls) {
  105 + this.iconCls = iconCls;
  106 + }
  107 +
  108 + public String getComponent() {
  109 + return component;
  110 + }
  111 +
  112 + public void setComponent(String component) {
  113 + this.component = component;
  114 + }
  115 +
  116 + public List<PERMISSION> getChildren() {
  117 + return children;
  118 + }
  119 +
  120 + public void setChildren(List<PERMISSION> children) {
  121 + this.children = children;
  122 + }
  123 +}
  1 +package com.tianbo.warehouse.model;
  2 +
  3 +import org.springframework.security.core.GrantedAuthority;
  4 +
  5 +import java.util.List;
  6 +
  7 +public class ROLE implements GrantedAuthority {
  8 + private static final long serialVersionUID = 1L;
  9 +
  10 + private Integer roleId;
  11 +
  12 + private String roleName;
  13 +
  14 + private String roleSign;
  15 +
  16 + private String description;
  17 +
  18 + private List<PERMISSION> permissions;
  19 +
  20 + public Integer getRoleId() {
  21 + return roleId;
  22 + }
  23 +
  24 + public void setRoleId(Integer roleId) {
  25 + this.roleId = roleId;
  26 + }
  27 +
  28 + public String getRoleName() {
  29 + return roleName;
  30 + }
  31 +
  32 + public void setRoleName(String roleName) {
  33 + this.roleName = roleName == null ? null : roleName.trim();
  34 + }
  35 +
  36 + public String getRoleSign() {
  37 + return roleSign;
  38 + }
  39 +
  40 + public void setRoleSign(String roleSign) {
  41 + this.roleSign = roleSign == null ? null : roleSign.trim();
  42 + }
  43 +
  44 + public String getDescription() {
  45 + return description;
  46 + }
  47 +
  48 + public void setDescription(String description) {
  49 + this.description = description == null ? null : description.trim();
  50 + }
  51 +
  52 + public List<PERMISSION> getPermissions() {
  53 + return permissions;
  54 + }
  55 +
  56 + public void setPermissions(List<PERMISSION> permissions) {
  57 + this.permissions = permissions;
  58 + }
  59 +
  60 + @Override
  61 + public String getAuthority(){
  62 + return this.getRoleName();
  63 + }
  64 +}
  1 +package com.tianbo.warehouse.model;
  2 +
  3 +import java.util.List;
  4 +
  5 +public class RolePermission {
  6 + private Integer id;
  7 +
  8 + private Integer roleId;
  9 +
  10 + private Integer permissionId;
  11 +
  12 + //处理前端提交过来的权限ID列表
  13 + private List<Integer> permissionIds;
  14 +
  15 + public Integer getId() {
  16 + return id;
  17 + }
  18 +
  19 + public void setId(Integer id) {
  20 + this.id = id;
  21 + }
  22 +
  23 + public Integer getRoleId() {
  24 + return roleId;
  25 + }
  26 +
  27 + public void setRoleId(Integer roleId) {
  28 + this.roleId = roleId;
  29 + }
  30 +
  31 + public Integer getPermissionId() {
  32 + return permissionId;
  33 + }
  34 +
  35 + public void setPermissionId(Integer permissionId) {
  36 + this.permissionId = permissionId;
  37 + }
  38 +
  39 + public List<Integer> getPermissionIds() {
  40 + return permissionIds;
  41 + }
  42 +
  43 + public void setPermissionIds(List<Integer> permissionIds) {
  44 + this.permissionIds = permissionIds;
  45 + }
  46 +}
  1 +package com.tianbo.warehouse.model;
  2 +
  3 +import com.alibaba.fastjson.annotation.JSONField;
  4 +import com.alibaba.fastjson.serializer.SerializerFeature;
  5 +import com.tianbo.warehouse.validate.CheckUserExist;
  6 +import org.hibernate.validator.constraints.Length;
  7 +import org.springframework.security.core.GrantedAuthority;
  8 +import org.springframework.security.core.authority.SimpleGrantedAuthority;
  9 +import org.springframework.security.core.userdetails.UserDetails;
  10 +
  11 +import javax.validation.constraints.*;
  12 +import java.util.ArrayList;
  13 +import java.util.Collection;
  14 +import java.util.Date;
  15 +import java.util.List;
  16 +
  17 +public class USERS implements UserDetails {
  18 +
  19 + private static final long serialVersionUID = 1L;
  20 +
  21 + @DecimalMin("1")
  22 + private Integer userId;
  23 +
  24 + @NotBlank(message="用户名不能为空")
  25 + @Length(min = 5, max = 11, message = "username 长度必须在 {min} - {max} 之间")
  26 + @CheckUserExist(message = "用户已存在")
  27 + private String username;
  28 +
  29 + @NotNull
  30 + @NotBlank(message="密码不能为空")
  31 + @Length(min = 6, max = 22, message = "密码 长度必须在 {min} - {max} 之间")
  32 + private String password;
  33 +
  34 + private Date birthday;
  35 +
  36 + private String sex;
  37 +
  38 + private String address;
  39 +
  40 + private Boolean state;
  41 +
  42 + @Length(min = 11, max = 11, message = "mobilephone 长度必须为11位")
  43 + private String mobilephone;
  44 +
  45 + private Date creattime;
  46 +
  47 + private Date updatetime;
  48 +
  49 + private String userface;
  50 +
  51 + private String realname;
  52 + @Pattern(regexp="[a-za-z0-9._%+-]+@[a-za-z0-9.-]+\\.[a-za-z]{2,4}", message="邮件格式错误")
  53 + private String email;
  54 +
  55 + private Integer age;
  56 +
  57 + @JSONField(serialzeFeatures= {SerializerFeature.WriteMapNullValue,SerializerFeature.WriteNullStringAsEmpty})
  58 + private List<ROLE> roles;
  59 +
  60 + @JSONField(serialzeFeatures= {SerializerFeature.WriteMapNullValue,SerializerFeature.WriteNullStringAsEmpty})
  61 + private List<PERMISSION> permissions;
  62 +
  63 + public Integer getUserId() {
  64 + return userId;
  65 + }
  66 +
  67 + public void setUserId(Integer userId) {
  68 + this.userId = userId;
  69 + }
  70 +
  71 + @Override
  72 + public String getUsername() {
  73 + return username;
  74 + }
  75 +
  76 + public void setUsername(String username) {
  77 + this.username = username == null ? null : username.trim();
  78 + }
  79 +
  80 + @Override
  81 + public String getPassword() {
  82 + return password;
  83 + }
  84 +
  85 + public void setPassword(String password) {
  86 + this.password = password == null ? null : password.trim();
  87 + }
  88 +
  89 + public Date getBirthday() {
  90 + return birthday;
  91 + }
  92 +
  93 + public void setBirthday(Date birthday) {
  94 + this.birthday = birthday;
  95 + }
  96 +
  97 + public String getSex() {
  98 + return sex;
  99 + }
  100 +
  101 + public void setSex(String sex) {
  102 + this.sex = sex == null ? null : sex.trim();
  103 + }
  104 +
  105 + public String getAddress() {
  106 + return address;
  107 + }
  108 +
  109 + public void setAddress(String address) {
  110 + this.address = address == null ? null : address.trim();
  111 + }
  112 +
  113 + public Boolean getState() {
  114 + return state;
  115 + }
  116 +
  117 + public void setState(Boolean state) {
  118 + this.state = state;
  119 + }
  120 +
  121 + public String getMobilephone() {
  122 + return mobilephone;
  123 + }
  124 +
  125 + public void setMobilephone(String mobilephone) {
  126 + this.mobilephone = mobilephone == null ? null : mobilephone.trim();
  127 + }
  128 +
  129 + public Date getCreattime() {
  130 + return creattime;
  131 + }
  132 +
  133 + public void setCreattime(Date creattime) {
  134 + this.creattime = creattime;
  135 + }
  136 +
  137 + public Date getUpdatetime() {
  138 + return updatetime;
  139 + }
  140 +
  141 + public void setUpdatetime(Date updatetime) {
  142 + this.updatetime = updatetime;
  143 + }
  144 +
  145 + public String getUserface() {
  146 + return userface;
  147 + }
  148 +
  149 + public void setUserface(String userface) {
  150 + this.userface = userface == null ? null : userface.trim();
  151 + }
  152 +
  153 + public String getRealname() {
  154 + return realname;
  155 + }
  156 +
  157 + public void setRealname(String realname) {
  158 + this.realname = realname;
  159 + }
  160 +
  161 + public String getEmail() {
  162 + return email;
  163 + }
  164 +
  165 + public void setEmail(String email) {
  166 + this.email = email;
  167 + }
  168 +
  169 + public Integer getAge() {
  170 + return age;
  171 + }
  172 +
  173 + public void setAge(Integer age) {
  174 + this.age = age;
  175 + }
  176 +
  177 + public List<ROLE> getRoles() {
  178 + return roles;
  179 + }
  180 +
  181 + public void setRoles(List<ROLE> roles) {
  182 + this.roles = roles;
  183 + }
  184 +
  185 + public List<PERMISSION> getPermissions() {
  186 + return permissions;
  187 + }
  188 +
  189 + public void setPermissions(List<PERMISSION> permissions) {
  190 + this.permissions = permissions;
  191 + }
  192 +
  193 + /**
  194 + *
  195 + * @return 账户未过期
  196 + */
  197 + @Override
  198 + public boolean isAccountNonExpired(){
  199 + return true;
  200 + }
  201 +
  202 + /**
  203 + *
  204 + * @return 账户未锁定
  205 + */
  206 + @Override
  207 + public boolean isAccountNonLocked(){
  208 + return true;
  209 + }
  210 +
  211 + /**
  212 + *
  213 + * @return 密码未过期
  214 + */
  215 + @Override
  216 + public boolean isCredentialsNonExpired(){
  217 + return true;
  218 + }
  219 +
  220 + /**
  221 + *
  222 + * @return 账户可用
  223 + */
  224 + @Override
  225 + public boolean isEnabled(){
  226 + return true;
  227 + }
  228 +
  229 + /**
  230 + *
  231 + * @return user的权限列表
  232 + */
  233 + @Override
  234 + public Collection<? extends GrantedAuthority> getAuthorities(){
  235 + List<GrantedAuthority> auths = new ArrayList<>();
  236 + if(roles!=null && !roles.isEmpty()){
  237 + for (ROLE role : roles) {
  238 + if (null != role){
  239 + auths.add(new SimpleGrantedAuthority(role.getAuthority()));
  240 + }
  241 + }
  242 + }
  243 + return auths;
  244 + }
  245 +}
  1 +package com.tianbo.warehouse.model;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import javax.validation.constraints.DecimalMin;
  6 +import java.util.List;
  7 +
  8 +@Data
  9 +public class UserRole {
  10 +
  11 + @DecimalMin("1")
  12 + private Integer id;
  13 +
  14 + @DecimalMin("1")
  15 + private Integer userId;
  16 +
  17 + @DecimalMin("1")
  18 + private Integer roleId;
  19 +
  20 + private List<Integer> roleIds;
  21 +
  22 + public UserRole(){
  23 + }
  24 + public UserRole(Integer userId,Integer roleId){
  25 + this.roleId=roleId;
  26 + this.userId = userId;
  27 + }
  28 +}
  1 +package com.tianbo.warehouse.security;
  2 +
  3 +import com.tianbo.warehouse.model.USERS;
  4 +import com.tianbo.warehouse.service.UserService;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.security.authentication.BadCredentialsException;
  7 +import org.springframework.security.core.userdetails.UserDetails;
  8 +import org.springframework.security.core.userdetails.UserDetailsService;
  9 +import org.springframework.security.core.userdetails.UsernameNotFoundException;
  10 +import org.springframework.stereotype.Service;
  11 +
  12 +import java.util.ArrayList;
  13 +import java.util.List;
  14 +
  15 +@Service("customuserservice")
  16 +public class CustomUserDetailService implements UserDetailsService {
  17 +
  18 + @Autowired
  19 + UserService userService;
  20 +
  21 + @Override
  22 + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
  23 +
  24 +
  25 + USERS user = userService.loadByUsername(username);
  26 + if (user == null) {
  27 + throw new UsernameNotFoundException("用户名不存在");
  28 +// throw new BadCredentialsException("用户名不存在");
  29 + }
  30 + return user;
  31 +
  32 + }
  33 +}
  1 +package com.tianbo.warehouse.security;
  2 +
  3 +import org.springframework.security.access.AccessDecisionManager;
  4 +import org.springframework.security.access.AccessDeniedException;
  5 +import org.springframework.security.access.ConfigAttribute;
  6 +import org.springframework.security.authentication.InsufficientAuthenticationException;
  7 +import org.springframework.security.core.Authentication;
  8 +import org.springframework.security.core.GrantedAuthority;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +import java.util.Collection;
  12 +import java.util.Iterator;
  13 +
  14 +@Service
  15 +public class MyAccessDecisionManager implements AccessDecisionManager{
  16 + /**这里没用AccessDecisionVoter访问投票管理,自定义用户的role_name与URL需要的ROLE_NAME对碰决定,参考资料:https://blog.csdn.net/kaikai8552/article/details/3965841
  17 + * decide方法接收三个参数,decide 方法是判定是否拥有权限的决策方法
  18 + * 其中第一个参数中保存了当前登录用户的角色信息,authentication 是释CustomUserService中循环添加到 GrantedAuthority 对象中的权限信息集合.
  19 + * object 包含客户端发起的请求的requset信息,可转换为 HttpServletRequest request = ((FilterInvocation) object).getHttpRequest();
  20 + * 第三个参数则是MyInvocationSecurityMetadataSourceService中的getAttributes方法传来的,表示当前请求需要的角色(可能有多个),此方法是为了判定用户请求的url 是否在权限表中,如果在权限表中,则返回给 decide 方法,用来判定用户是否有此权限。如果不在权限表中则放行。
  21 + * @param authentication
  22 + * @param object
  23 + * @param configAttributes
  24 + * @throws AccessDeniedException
  25 + * @throws InsufficientAuthenticationException
  26 + */
  27 + @Override
  28 + public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException{
  29 +
  30 + if(null== configAttributes || configAttributes.size() <=0) {
  31 + return;
  32 + }
  33 + ConfigAttribute c;
  34 + String needRole;
  35 + for(Iterator<ConfigAttribute> iter = configAttributes.iterator(); iter.hasNext(); ) {
  36 + c = iter.next();
  37 + needRole = c.getAttribute();
  38 +
  39 +
  40 +
  41 + //authentication 为在注释1 中循环添加到 GrantedAuthority 对象中的权限信息集合
  42 + for(GrantedAuthority ga : authentication.getAuthorities()) {
  43 +
  44 + //如果URL需要的权限为匿名访问,返回
  45 + if(("ROLE_admin").equals(ga.getAuthority())){
  46 + return;
  47 + }
  48 +
  49 + if(needRole.trim().equals(ga.getAuthority())) {
  50 + return;
  51 + }
  52 + }
  53 + }
  54 + throw new AccessDeniedException("权限不足!");
  55 +
  56 + /**
  57 + * ExceptionTranslationFilter
  58 +
  59 + ExceptionTranslationFilter 是Spring Security的核心filter之一,用来处理AuthenticationException和AccessDeniedException两种异常。
  60 +
  61 + 在我们的例子中,AuthenticationException指的是未登录状态下访问受保护资源,AccessDeniedException指的是登陆了但是由于权限不足(比如普通用户访问管理员界面)。
  62 +
  63 + ExceptionTranslationFilter 持有两个处理类,分别是AuthenticationEntryPoint和AccessDeniedHandler。
  64 +
  65 + ExceptionTranslationFilter 对异常的处理是通过这两个处理类实现的,处理规则很简单:
  66 +
  67 + 规则1. 如果异常是 AuthenticationException,使用 AuthenticationEntryPoint 处理
  68 + 规则2. 如果异常是 AccessDeniedException 且用户是匿名用户,使用 AuthenticationEntryPoint 处理
  69 + 规则3. 如果异常是 AccessDeniedException 且用户不是匿名用户,如果否则交给 AccessDeniedHandler 处理。
  70 + */
  71 + }
  72 +
  73 + @Override
  74 + public boolean supports(ConfigAttribute var1){
  75 + return true;
  76 + }
  77 +
  78 + @Override
  79 + public boolean supports(Class<?> var1){
  80 + return true;
  81 + }
  82 +}
  1 +package com.tianbo.warehouse.security;
  2 +
  3 +import org.springframework.beans.factory.annotation.Autowired;
  4 +import org.springframework.security.access.SecurityMetadataSource;
  5 +import org.springframework.security.access.intercept.AbstractSecurityInterceptor;
  6 +import org.springframework.security.access.intercept.InterceptorStatusToken;
  7 +import org.springframework.security.web.FilterInvocation;
  8 +import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +import javax.servlet.*;
  12 +import java.io.IOException;
  13 +
  14 +@Service
  15 +public class MyFilterSecurityInterceptor extends AbstractSecurityInterceptor implements Filter {
  16 +
  17 + @Autowired
  18 + private MyInvocationSecurityMetadataSourceService securityMetadataSource;
  19 +
  20 +
  21 + @Autowired
  22 + public void setMyAccessDecisionManager(MyAccessDecisionManager myAccessDecisionManager) {
  23 + super.setAccessDecisionManager(myAccessDecisionManager);
  24 + }
  25 +
  26 +
  27 + @Override
  28 + public void init(FilterConfig filterConfig) throws ServletException {
  29 +
  30 + }
  31 +
  32 + @Override
  33 + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
  34 +
  35 + FilterInvocation fi = new FilterInvocation(request, response, chain);
  36 + invoke(fi);
  37 + }
  38 +
  39 +
  40 + public void invoke(FilterInvocation fi) throws IOException, ServletException {
  41 + /**
  42 + *fi里面有一个被拦截的url里面调用MyInvocationSecurityMetadataSource的getAttributes(Object object)这个方法获取fi对应的所有权限
  43 + 再调用MyAccessDecisionManager的decide方法来校验用户的权限是否足够
  44 + */
  45 + InterceptorStatusToken token = super.beforeInvocation(fi);
  46 + try {
  47 +//执行下一个拦截器
  48 + fi.getChain().doFilter(fi.getRequest(), fi.getResponse());
  49 + } finally {
  50 + super.afterInvocation(token, null);
  51 + }
  52 + }
  53 +
  54 + @Override
  55 + public void destroy() {
  56 +
  57 + }
  58 +
  59 + @Override
  60 + public Class<?> getSecureObjectClass() {
  61 + return FilterInvocation.class;
  62 + }
  63 +
  64 + @Override
  65 + public SecurityMetadataSource obtainSecurityMetadataSource() {
  66 + return this.securityMetadataSource;
  67 + }
  68 +
  69 +}
  1 +package com.tianbo.warehouse.security;
  2 +
  3 +import com.tianbo.warehouse.dao.PERMISSIONMapper;
  4 +import com.tianbo.warehouse.model.PERMISSION;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.security.access.ConfigAttribute;
  7 +import org.springframework.security.access.SecurityConfig;
  8 +import org.springframework.security.web.FilterInvocation;
  9 +import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
  10 +import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
  11 +import org.springframework.stereotype.Service;
  12 +import org.springframework.util.AntPathMatcher;
  13 +
  14 +import javax.servlet.http.HttpServletRequest;
  15 +import java.util.*;
  16 +
  17 +/**
  18 + * 本类的主要功能就是通过当前的请求地址,获取该地址需要的用户角色
  19 + * 如果getAttributes(Object o)方法返回null的话,意味着当前这个请求不需要任何角色就能访问,甚至不需要登录。
  20 + */
  21 +@Service
  22 +public class MyInvocationSecurityMetadataSourceService implements FilterInvocationSecurityMetadataSource{
  23 +
  24 + @Autowired
  25 + PERMISSIONMapper permissionMapper;
  26 + AntPathMatcher pathMatcher = new AntPathMatcher();
  27 +
  28 + private HashMap<String, Collection<ConfigAttribute>> map =null;
  29 +
  30 + /**
  31 + * 加载权限表中所有权限,还是加载URL所需要的权限
  32 + */
  33 + public void loadResourceDefine(String requestUrl){
  34 + map = new HashMap<>();
  35 + Collection<ConfigAttribute> array;
  36 + ConfigAttribute cfg;
  37 + List<PERMISSION> permissions = permissionMapper.findAll();
  38 + for(PERMISSION permission : permissions) {
  39 + array = new ArrayList<>();
  40 +
  41 + //此处只添加了用户的名字,其实还可以添加更多权限的信息,
  42 + // 例如请求方法到ConfigAttribute的集合中去。
  43 + // 此处添加的信息将会作为MyAccessDecisionManager类的decide的第三个参数。
  44 +
  45 + //CFG存储访问的URL需要的权限"ROLE_??"LIST
  46 + String pUrl = permission.getUrl();
  47 + List<String> urlOfRoles = permissionMapper.findRoleListByUrl(pUrl);
  48 +
  49 + //路径适配,这个很重要,是配上后会包含其他适配的所有权限,比如/**与/user/List是可以适配上的,
  50 + // 那么/**这个通用适配是要有/user/list这个路径所对应的角色信息的
  51 + if(pathMatcher.match(pUrl,requestUrl)){
  52 +
  53 + }
  54 +
  55 + for (String roleName:urlOfRoles) {
  56 +
  57 + if(null!=roleName) {
  58 + cfg = new SecurityConfig(roleName);
  59 + array.add(cfg);
  60 + }
  61 + }
  62 + //用权限的getUrl() 作为map的key,用ConfigAttribute的集合作为 value,
  63 + map.put(pUrl, array);
  64 +
  65 +
  66 + }
  67 +
  68 + }
  69 +
  70 + /**
  71 + * 所有的权限表中的url所对应的角色信息
  72 + * @return 有就返回集合 没有就返回null
  73 + */
  74 + public Collection<ConfigAttribute> loadResourceDefine(){
  75 + Collection<ConfigAttribute> array;
  76 + ConfigAttribute cfg;
  77 + List<PERMISSION> permissions = permissionMapper.findAll();
  78 + for(PERMISSION permission : permissions) {
  79 + array = new ArrayList<>();
  80 +
  81 + //此处只添加了用户的名字,其实还可以添加更多权限的信息,
  82 + // 例如请求方法到ConfigAttribute的集合中去。
  83 + // 此处添加的信息将会作为MyAccessDecisionManager类的decide的第三个参数。
  84 +
  85 + //CFG存储访问的URL需要的权限"ROLE_??"LIST
  86 + String pUrl = permission.getUrl();
  87 + List<String> urlOfRoles = permissionMapper.findRoleListByUrl(pUrl);
  88 +
  89 + for (String roleName:urlOfRoles) {
  90 + if(null!=roleName) {
  91 + cfg = new SecurityConfig(roleName);
  92 + array.add(cfg);
  93 + }
  94 + }
  95 + return array;
  96 +
  97 + }
  98 + return null;
  99 + }
  100 +
  101 + /**
  102 + * 此方法是为了判定用户请求的url权限 是否有对应的角色,
  103 + * 如果有对应角色信息,则返回给 decide 方法,
  104 + * 用来判定用户是否有此权限。如果不在权限表中则放行。
  105 + * 如果getAttributes(Object o)方法返回null的话,意味着当前这个请求不需要任何角色就能访问
  106 + * getAttributes(Object o)方法返回的集合最终会来到AccessDecisionManager类中
  107 + * @param object
  108 + * @return
  109 + * @throws IllegalArgumentException
  110 + */
  111 + @Override
  112 + public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
  113 + //清楚地址
  114 + String requestUrl = ((FilterInvocation)object).getRequest().getRequestURI();
  115 +
  116 + //每次判定的时候都加载权限对应URL表
  117 +// if(map ==null) {
  118 + loadResourceDefine(requestUrl);
  119 +// }
  120 + //object 中包含用户请求的request 信息
  121 + HttpServletRequest request = ((FilterInvocation) object).getHttpRequest();
  122 + String resUrl;
  123 + for(Iterator<String> iter = map.keySet().iterator(); iter.hasNext(); ) {
  124 + resUrl = iter.next();
  125 + AntPathRequestMatcher matcher = new AntPathRequestMatcher(resUrl);
  126 + if(matcher.matches(request)) {
  127 + return map.get(resUrl);
  128 + }
  129 + }
  130 + return null;
  131 + }
  132 +
  133 + /**
  134 + *
  135 + * @return 所有URL对应的所有权限
  136 + */
  137 + @Override
  138 + public Collection<ConfigAttribute> getAllConfigAttributes() {
  139 +// return loadResourceDefine();
  140 + return null;
  141 + }
  142 +
  143 + @Override
  144 + public boolean supports(Class<?> clazz) {
  145 + return true;
  146 + }
  147 +}
  1 +package com.tianbo.warehouse.security.config;
  2 +
  3 +import org.springframework.context.annotation.Configuration;
  4 +import org.springframework.web.servlet.config.annotation.CorsRegistry;
  5 +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  6 +/**
  7 + * 解决前后端分离跨域问题
  8 + */
  9 +@Configuration
  10 +public class CorsConfig implements WebMvcConfigurer{
  11 +
  12 + @Override
  13 + public void addCorsMappings(CorsRegistry registry) {
  14 + registry.addMapping("/**")//设置允许跨域的路径
  15 + .allowedOrigins("*")//设置允许跨域请求的域名
  16 + .allowCredentials(true)//是否允许证书 不再默认开启
  17 + .allowedMethods("GET", "POST", "PUT", "DELETE")//设置允许的方法
  18 + .maxAge(3600);//跨域允许时间
  19 + }
  20 +}
  1 +package com.tianbo.warehouse.security.config;
  2 +
  3 +import org.springframework.core.convert.converter.Converter;
  4 +
  5 +import java.text.ParseException;
  6 +import java.text.SimpleDateFormat;
  7 +import java.util.Date;
  8 +
  9 +public class DateConverter implements Converter<String,Date>{
  10 + private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  11 +
  12 + @Override
  13 + public Date convert(String s) {
  14 + if ("".equals(s) || s == null) {
  15 + return null;
  16 + }
  17 + try {
  18 + return simpleDateFormat.parse(s);
  19 + } catch (ParseException e) {
  20 + e.printStackTrace();
  21 + }
  22 + return null;
  23 + }
  24 +
  25 +}
  1 +package com.tianbo.warehouse.security.config;
  2 +
  3 +import org.springframework.context.annotation.Configuration;
  4 +import org.springframework.format.FormatterRegistry;
  5 +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  6 +
  7 +//@Configuration
  8 +public class MyWebMvcConfig {
  9 +
  10 +
  11 + public void addFormatters(FormatterRegistry registry) {
  12 + registry.addConverter(new DateConverter());
  13 + }
  14 +}
  1 +package com.tianbo.warehouse.security.config;
  2 +
  3 +import org.apache.commons.codec.digest.DigestUtils;
  4 +import org.springframework.security.crypto.password.PasswordEncoder;
  5 +import org.springframework.stereotype.Service;
  6 +
  7 +/**
  8 + * PasswordEncoder 是个接口,该接口下有两个方法,一个是encoder 一个是matches,前者用于加密,后者用于匹配校验.
  9 + */
  10 +@Service(value = "passwordEncodeService")
  11 +public class PasswordEncoderImp implements PasswordEncoder{
  12 +
  13 + @Override
  14 + public String encode(CharSequence charSequence) {
  15 + String enncodePassword = DigestUtils.md5Hex(charSequence.toString());
  16 + return enncodePassword;
  17 + }
  18 +
  19 + @Override
  20 + public boolean matches(CharSequence rawPassword, String encodedPassword) {
  21 + //用户输入的登录密码
  22 + String endcodeInputPass = DigestUtils.md5Hex(rawPassword.toString());
  23 + return encodedPassword.equals(endcodeInputPass);
  24 + }
  25 +}
  1 +package com.tianbo.warehouse.security.config;
  2 +
  3 +import com.tianbo.warehouse.security.model.BrowserProperties;
  4 +import org.springframework.boot.context.properties.ConfigurationProperties;
  5 +import org.springframework.stereotype.Component;
  6 +
  7 +@ConfigurationProperties(prefix = "tianbo.security")
  8 +@Component
  9 +public class SecurityProperties {
  10 +
  11 + /**
  12 + * 浏览器 属性类
  13 + */
  14 + private BrowserProperties browser = new BrowserProperties();
  15 +
  16 + public BrowserProperties getBrowser() {
  17 + return browser;
  18 + }
  19 +
  20 + public void setBrowser(BrowserProperties browser) {
  21 + this.browser = browser;
  22 + }
  23 +}
  1 +package com.tianbo.warehouse.security.config;
  2 +
  3 +import com.netflix.discovery.converters.Auto;
  4 +import com.tianbo.warehouse.security.CustomUserDetailService;
  5 +import com.tianbo.warehouse.security.handel.MyAuthenticationAccessDeniedHandler;
  6 +import com.tianbo.warehouse.security.handel.MyAuthenticationFailHandler;
  7 +import com.tianbo.warehouse.security.handel.MyAuthenticationSuccessHandler;
  8 +import com.tianbo.warehouse.security.MyFilterSecurityInterceptor;
  9 +import com.tianbo.warehouse.security.handel.MyLogoutSuccessHandler;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.beans.factory.annotation.Qualifier;
  12 +import org.springframework.context.annotation.Configuration;
  13 +import org.springframework.core.annotation.Order;
  14 +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  15 +import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication;
  16 +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
  17 +import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  18 +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  19 +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  20 +import org.springframework.security.core.userdetails.UserDetailsService;
  21 +import org.springframework.security.crypto.password.PasswordEncoder;
  22 +import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
  23 +import org.springframework.web.cors.CorsUtils;
  24 +
  25 +@Configuration
  26 +@EnableWebSecurity
  27 +@EnableGlobalMethodSecurity(prePostEnabled = true)
  28 +@Order(1)
  29 +public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  30 +
  31 + @Autowired
  32 + private MyFilterSecurityInterceptor myFilterSecurityInterceptor;
  33 +
  34 + @Autowired
  35 + private PasswordEncoder passwordEncoder;
  36 +
  37 + @Autowired
  38 + private MyAuthenticationSuccessHandler successHandler;
  39 +
  40 + @Autowired
  41 + private MyAuthenticationFailHandler failHandler;
  42 +
  43 + @Qualifier("customuserservice")
  44 + @Autowired
  45 + private CustomUserDetailService userDetailsService;
  46 +
  47 + @Autowired
  48 + private MyAuthenticationAccessDeniedHandler myAuthenticationAccessDeniedHandler;
  49 +
  50 + @Autowired
  51 + private MyLogoutSuccessHandler myLogoutSuccessHandler;
  52 +
  53 + @Override
  54 + protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  55 + //user Details Service验证
  56 + auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);
  57 + //不删除凭据,以便记住用户
  58 + auth.eraseCredentials(false);
  59 + }
  60 +
  61 + /**
  62 + * 在configure(HttpSecurity http)方法中,
  63 + * 通过withObjectPostProcessor将刚刚创建的UrlFilterInvocationSecurityMetadataSource和UrlAccessDecisionManager注入进来。
  64 + * 到时候,请求都会经过刚才的过滤器(除了configure(WebSecurity web)方法忽略的请求)。
  65 + * 通过myFilterSecurityInterceptor关联他俩
  66 + * @param http
  67 + * @throws Exception
  68 + */
  69 + @Override
  70 + protected void configure(HttpSecurity http) throws Exception {
  71 + http.authorizeRequests()
  72 + //跨域配置
  73 + .requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
  74 + //管理页面只允许管理员角色访问
  75 + .antMatchers("/admin/**","/role/**","/user/**").authenticated()
  76 + //任何请求,登录后可以访问
  77 + //其余的不需要验证
  78 + .anyRequest().permitAll()
  79 + .and()
  80 + .formLogin()
  81 + .passwordParameter("password")
  82 + .usernameParameter("username")
  83 + //登陆提交的处理url
  84 + //.loginProcessingUrl("/home")
  85 + .loginPage("/login")
  86 + .successHandler(successHandler)
  87 + .failureHandler(failHandler)
  88 +// .failureUrl("/error")
  89 + //登录页面用户任意访问
  90 + .permitAll()
  91 +// .successForwardUrl("/main")
  92 + .and()
  93 + .exceptionHandling().accessDeniedHandler(myAuthenticationAccessDeniedHandler)
  94 + .and()
  95 + .logout()
  96 + .logoutSuccessUrl("/?logout=true")
  97 + .logoutSuccessHandler(myLogoutSuccessHandler)
  98 + .permitAll()
  99 + .and()
  100 + .rememberMe()
  101 + .tokenValiditySeconds(604800)
  102 + //记住我功能,cookies有限期是一周
  103 + .rememberMeParameter("remeberme")
  104 + //登陆时是否激活记住我功能的参数名字,在登陆页面有展示
  105 + .rememberMeCookieName("workspace")
  106 + //cookies的名字,登陆后可以通过浏览器查看cookies名字
  107 + .and()
  108 + .cors()
  109 + .and()
  110 + .csrf().disable();
  111 +
  112 + http.addFilterBefore(myFilterSecurityInterceptor, FilterSecurityInterceptor.class);
  113 +
  114 + //session管理
  115 + //session失效后跳转
  116 +// http.sessionManagement().invalidSessionUrl("/login");
  117 +// //只允许一个用户登录,如果同一个账户两次登录,那么第一个账户将被踢下线,跳转到登录页面
  118 +// http.sessionManagement().maximumSessions(1).expiredUrl("/login");
  119 + }
  120 +}
  1 +package com.tianbo.warehouse.security.handel;
  2 +
  3 +import org.springframework.security.access.AccessDeniedException;
  4 +import org.springframework.security.web.access.AccessDeniedHandler;
  5 +import org.springframework.stereotype.Component;
  6 +
  7 +import javax.servlet.ServletException;
  8 +import javax.servlet.http.HttpServletRequest;
  9 +import javax.servlet.http.HttpServletResponse;
  10 +import java.io.IOException;
  11 +import java.io.PrintWriter;
  12 +
  13 +/**
  14 + * AuthenticationEntryPoint 用来解决匿名用户访问无权限资源时的异常
  15 + * AccessDeineHandler 用来解决认证过的用户访问无权限资源时的异常
  16 + */
  17 +@Component
  18 +public class MyAuthenticationAccessDeniedHandler implements AccessDeniedHandler{
  19 +
  20 + @Override
  21 + public void handle(HttpServletRequest httpServletRequest, HttpServletResponse resp, AccessDeniedException e) throws IOException, ServletException{
  22 +
  23 + resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
  24 + resp.setCharacterEncoding("UTF-8");
  25 + PrintWriter out = resp.getWriter();
  26 + out.write("{\"status\":\"error\",\"msg\":\"权限不足,请联系管理员!\"}");
  27 + out.flush();
  28 + out.close();
  29 + }
  30 +
  31 +}
  1 +package com.tianbo.warehouse.security.handel;
  2 +
  3 +import org.springframework.security.web.AuthenticationEntryPoint;
  4 +
  5 +/**实现AuthenticationEntryPoint接口
  6 + * AuthenticationEntryPoint 用来解决匿名用户访问无权限资源时的异常
  7 + * AccessDeineHandler 用来解决认证过的用户访问无权限资源时的异常
  8 + */
  9 +public class MyAuthenticationEntryPoint {
  10 +// response.setCharacterEncoding("utf-8");
  11 +// response.setContentType("text/javascript;charset=utf-8");
  12 +// response.getWriter().print(JSONObject.toJSONString(RestMsg.error("没有访问权限!")));
  13 +
  14 +}
  1 +package com.tianbo.warehouse.security.handel;
  2 +
  3 +import com.fasterxml.jackson.databind.ObjectMapper;
  4 +import com.tianbo.warehouse.security.config.SecurityProperties;
  5 +import com.tianbo.warehouse.security.model.LoginType;
  6 +import org.apache.commons.logging.Log;
  7 +import org.apache.commons.logging.LogFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.http.HttpStatus;
  10 +import org.springframework.security.authentication.BadCredentialsException;
  11 +import org.springframework.security.authentication.DisabledException;
  12 +import org.springframework.security.core.AuthenticationException;
  13 +import org.springframework.security.core.userdetails.UsernameNotFoundException;
  14 +import org.springframework.security.web.DefaultRedirectStrategy;
  15 +import org.springframework.security.web.RedirectStrategy;
  16 +import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
  17 +import org.springframework.stereotype.Component;
  18 +
  19 +import javax.servlet.ServletException;
  20 +import javax.servlet.http.HttpServletRequest;
  21 +import javax.servlet.http.HttpServletResponse;
  22 +import java.io.IOException;
  23 +import java.io.PrintWriter;
  24 +
  25 +/**
  26 + * 自定义登录失败处理器
  27 + * Created by mrz.
  28 + */
  29 +@Component
  30 +public class MyAuthenticationFailHandler extends SimpleUrlAuthenticationFailureHandler {
  31 + protected final Log logger = LogFactory.getLog(this.getClass());
  32 + /**
  33 + * json 转换工具类
  34 + */
  35 + @Autowired
  36 + private ObjectMapper objectMapper;
  37 +
  38 + private String defaultFailureUrl;
  39 + private boolean forwardToDestination = false;
  40 + private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
  41 +
  42 + @Autowired
  43 + private SecurityProperties securityProperties;
  44 +
  45 + @Override
  46 + public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
  47 +
  48 + //返回前端原因
  49 + PrintWriter out = response.getWriter();
  50 + StringBuffer sb = new StringBuffer();
  51 + sb.append("{\"status\":\"error\",\"msg\":\"");
  52 + if (exception instanceof UsernameNotFoundException || exception instanceof BadCredentialsException) {
  53 + sb.append("用户名或密码输入错误,登录失败!");
  54 + } else if (exception instanceof DisabledException) {
  55 + sb.append("账户被禁用,登录失败,请联系管理员!");
  56 + } else {
  57 + sb.append("登录失败!");
  58 + }
  59 + sb.append("\"}");
  60 +// out.write(sb.toString());
  61 +// out.flush();
  62 +// out.close();
  63 +
  64 + logger.info("登录失败");
  65 +
  66 + //不返回具体原因 只返回异常
  67 + //如果securityProperties中配置的是JSON就返回JSON
  68 + if (LoginType.JSON.equals(securityProperties.getBrowser().getLoginType())){
  69 + //设置状态码
  70 + response.setStatus(HttpStatus.UNAUTHORIZED.value());
  71 + //将 登录失败 信息打包成json格式返回
  72 + response.setContentType("application/json;charset=UTF-8");
  73 + response.getWriter().write(objectMapper.writeValueAsString(exception));
  74 + }
  75 +
  76 + if (this.defaultFailureUrl == null) {
  77 + this.logger.debug("No failure URL set, sending 401 Unauthorized error");
  78 + response.sendError(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase());
  79 + } else {
  80 + this.saveException(request, exception);
  81 + if (this.forwardToDestination) {
  82 + this.logger.debug("Forwarding to " + this.defaultFailureUrl);
  83 + request.getRequestDispatcher(this.defaultFailureUrl).forward(request, response);
  84 + } else {
  85 + this.logger.debug("Redirecting to " + this.defaultFailureUrl);
  86 + this.redirectStrategy.sendRedirect(request, response, this.defaultFailureUrl);
  87 + }
  88 + }
  89 +
  90 + }
  91 +}
  1 +package com.tianbo.warehouse.security.handel;
  2 +
  3 +import com.fasterxml.jackson.databind.ObjectMapper;
  4 +import com.tianbo.warehouse.bean.AuthSuccessResponse;
  5 +import com.tianbo.warehouse.controller.PermssionController;
  6 +import com.tianbo.warehouse.model.PERMISSION;
  7 +import com.tianbo.warehouse.model.USERS;
  8 +import com.tianbo.warehouse.security.model.LoginType;
  9 +import com.tianbo.warehouse.service.PermissionService;
  10 +import org.apache.commons.logging.Log;
  11 +import org.apache.commons.logging.LogFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import com.tianbo.warehouse.security.config.SecurityProperties;
  14 +import org.springframework.security.core.Authentication;
  15 +import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
  16 +import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
  17 +import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
  18 +import org.springframework.security.web.savedrequest.RequestCache;
  19 +import org.springframework.security.web.savedrequest.SavedRequest;
  20 +import org.springframework.stereotype.Component;
  21 +import org.springframework.util.StringUtils;
  22 +
  23 +import javax.servlet.ServletException;
  24 +import javax.servlet.http.HttpServletRequest;
  25 +import javax.servlet.http.HttpServletResponse;
  26 +import java.io.IOException;
  27 +import java.util.Map;
  28 +
  29 +/**
  30 + * 登录成功后的返回处理
  31 + */
  32 +@Component
  33 +public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler{
  34 + protected final Log logger = LogFactory.getLog(this.getClass());
  35 +
  36 + @Autowired
  37 + private ObjectMapper objectMapper;
  38 +
  39 + @Autowired
  40 + private PermissionService permissionService;
  41 + private RequestCache requestCache = new HttpSessionRequestCache();
  42 +
  43 + @Autowired
  44 + private SecurityProperties securityProperties;
  45 +
  46 + @Override
  47 + public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
  48 + logger.info("登录成功");
  49 + if (LoginType.JSON.equals(securityProperties.getBrowser().getLoginType())){
  50 + //将 authention 信息打包成json格式返回
  51 + response.setContentType("application/json;charset=UTF-8");
  52 + response.setHeader("Access-Control-Allow-Origin","*");
  53 + USERS loginedUser = (USERS) authentication.getPrincipal();
  54 + Map<String,Object> menuMap = permissionService.getUserMenus(loginedUser.getUserId());
  55 + response.getWriter().write(objectMapper.writeValueAsString(new AuthSuccessResponse(authentication,menuMap)));
  56 + }else {
  57 + //走原来的处理流程
  58 + SavedRequest savedRequest = this.requestCache.getRequest(request, response);
  59 + if (savedRequest == null) {
  60 + super.onAuthenticationSuccess(request, response, authentication);
  61 + } else {
  62 + String targetUrlParameter = this.getTargetUrlParameter();
  63 + if (!this.isAlwaysUseDefaultTargetUrl() && (targetUrlParameter == null || !StringUtils.hasText(request.getParameter(targetUrlParameter)))) {
  64 + this.clearAuthenticationAttributes(request);
  65 + String targetUrl = savedRequest.getRedirectUrl();
  66 + this.logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
  67 + this.getRedirectStrategy().sendRedirect(request, response, targetUrl);
  68 + } else {
  69 + this.requestCache.removeRequest(request, response);
  70 + super.onAuthenticationSuccess(request, response, authentication);
  71 + }
  72 + }
  73 + }
  74 +
  75 + }
  76 +
  77 +
  78 +}
  1 +package com.tianbo.warehouse.security.handel;
  2 +
  3 +import com.fasterxml.jackson.databind.ObjectMapper;
  4 +import org.springframework.security.core.Authentication;
  5 +import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
  6 +import org.springframework.stereotype.Component;
  7 +
  8 +import javax.servlet.ServletException;
  9 +import javax.servlet.http.HttpServletRequest;
  10 +import javax.servlet.http.HttpServletResponse;
  11 +import java.io.IOException;
  12 +import java.io.PrintWriter;
  13 +
  14 +@Component
  15 +public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
  16 +
  17 + @Override
  18 + public void onLogoutSuccess(HttpServletRequest req, HttpServletResponse resp, Authentication authentication) throws IOException, ServletException{
  19 + resp.setContentType("application/json;charset=utf-8");
  20 +// RespBean respBean = RespBean.ok("注销成功!");
  21 + ObjectMapper om = new ObjectMapper();
  22 + PrintWriter out = resp.getWriter();
  23 + out.write(om.writeValueAsString(authentication));
  24 + out.flush();
  25 + out.close();
  26 + }
  27 +
  28 +}
  1 +package com.tianbo.warehouse.security.model;
  2 +
  3 +/**
  4 + * browser(浏览器)配置文件里的: fantJ.security.browser.loginPage 属性类
  5 + *
  6 + */
  7 +public class BrowserProperties {
  8 + /**
  9 + * loginPage 默认值 是login.html
  10 + * 如果 application.properties 里有对 fantJ.security.browser.loginPage 的声明,则获取该值
  11 + */
  12 + private String loginPage = "/browser-login.html";
  13 +
  14 + /**
  15 + * 默认 返回 json 类型,声明登录返回格式
  16 + */
  17 + private LoginType loginType = LoginType.JSON;
  18 +
  19 + public String getLoginPage() {
  20 + return loginPage;
  21 + }
  22 +
  23 + public void setLoginPage(String loginPage) {
  24 + this.loginPage = loginPage;
  25 + }
  26 +
  27 + public LoginType getLoginType() {
  28 + return loginType;
  29 + }
  30 +
  31 + public void setLoginType(LoginType loginType) {
  32 + this.loginType = loginType;
  33 + }
  34 +}
  1 +package com.tianbo.warehouse.security.model;
  2 +
  3 +public enum LoginType {
  4 + REDIRECT,
  5 + JSON
  6 +}
  1 +package com.tianbo.warehouse.service;
  2 +
  3 +import com.tianbo.warehouse.model.Attachment;
  4 +
  5 +public interface AttachmentService {
  6 +
  7 + int insertSelective(Attachment record);
  8 +}
  1 +package com.tianbo.warehouse.service;
  2 +
  3 +import com.github.pagehelper.PageInfo;
  4 +import com.tianbo.warehouse.model.LOG;
  5 +import com.tianbo.warehouse.model.LOGWithBLOBs;
  6 +
  7 +public interface LogService {
  8 +
  9 + int insertSelective(LOGWithBLOBs record);
  10 +
  11 + PageInfo<LOGWithBLOBs> selectAll(int pageNum, int pageSize);
  12 +}
  1 +package com.tianbo.warehouse.service;
  2 +
  3 +import com.github.pagehelper.PageInfo;
  4 +import com.tianbo.warehouse.model.PERMISSION;
  5 +
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +
  9 +public interface PermissionService {
  10 +
  11 + PageInfo<PERMISSION> findAll(int pageNum, int pageSize);
  12 +
  13 + int insertSelective(PERMISSION record);
  14 +
  15 + /**
  16 + * 获取登录用户可访问的权限menus列表
  17 + * @param userId
  18 + * @return
  19 + */
  20 + Map<String,Object> getUserMenus(Integer userId);
  21 +}
  1 +package com.tianbo.warehouse.service;
  2 +
  3 +import com.github.pagehelper.PageInfo;
  4 +import com.tianbo.warehouse.model.ROLE;
  5 +import com.tianbo.warehouse.model.RolePermission;
  6 +
  7 +public interface RoleService {
  8 + PageInfo<ROLE> findAll(int pageNum, int pageSize);
  9 +
  10 + int insertSelective(ROLE record);
  11 +
  12 + int setRolePermissoin(RolePermission record);
  13 +}
  1 +package com.tianbo.warehouse.service;
  2 +
  3 +import com.github.pagehelper.PageInfo;
  4 +import com.tianbo.warehouse.model.USERS;
  5 +import com.tianbo.warehouse.model.UserRole;
  6 +
  7 +import java.util.List;
  8 +
  9 +public interface UserService {
  10 + USERS loadByUsername(String username);
  11 +
  12 + PageInfo<USERS> selectAllUser(int pageNum, int pageSize);
  13 +
  14 + int updateByPrimaryKeySelective(USERS record);
  15 +
  16 + int insertSelective(USERS record);
  17 +
  18 + int deleteByPrimaryKey(Integer userId);
  19 +
  20 + int setUserRole(UserRole userRole);
  21 +}
  1 +package com.tianbo.warehouse.service.imp;
  2 +
  3 +import com.tianbo.warehouse.dao.AttachmentMapper;
  4 +import com.tianbo.warehouse.model.Attachment;
  5 +import com.tianbo.warehouse.service.AttachmentService;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +@Service
  10 +public class AttachmentServiceImp implements AttachmentService {
  11 +
  12 + @Autowired
  13 + private AttachmentMapper attachmentMapper;
  14 +
  15 + @Override
  16 + public int insertSelective(Attachment record){
  17 + return attachmentMapper.insertSelective(record);
  18 + }
  19 +}
  1 +package com.tianbo.warehouse.service.imp;
  2 +
  3 +import com.github.pagehelper.Page;
  4 +import com.github.pagehelper.PageHelper;
  5 +import com.github.pagehelper.PageInfo;
  6 +import com.tianbo.warehouse.dao.LOGMapper;
  7 +import com.tianbo.warehouse.model.LOGWithBLOBs;
  8 +import com.tianbo.warehouse.service.LogService;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Service;
  11 +
  12 +import java.util.List;
  13 +
  14 +
  15 +@Service("webLog")
  16 +public class LogServiceImp implements LogService{
  17 +
  18 + @Autowired
  19 + private LOGMapper logMapper;
  20 +
  21 + @Override
  22 + public int insertSelective(LOGWithBLOBs record){
  23 + return logMapper.insertSelective(record);
  24 + }
  25 +
  26 + @Override
  27 + public PageInfo<LOGWithBLOBs> selectAll(int pageNum,int pageSize){
  28 + Page<LOGWithBLOBs> page = PageHelper.startPage(pageNum,pageSize);
  29 + List<LOGWithBLOBs> list = logMapper.selectAll();
  30 + PageInfo<LOGWithBLOBs> result = new PageInfo<LOGWithBLOBs>(list);
  31 + return result;
  32 + }
  33 +}
  1 +package com.tianbo.warehouse.service.imp;
  2 +
  3 +import com.github.pagehelper.Page;
  4 +import com.github.pagehelper.PageHelper;
  5 +import com.github.pagehelper.PageInfo;
  6 +import com.tianbo.warehouse.dao.PERMISSIONMapper;
  7 +import com.tianbo.warehouse.model.PERMISSION;
  8 +import com.tianbo.warehouse.model.ROLE;
  9 +import com.tianbo.warehouse.service.PermissionService;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.stereotype.Service;
  12 +
  13 +import java.util.*;
  14 +
  15 +@Service("PermissionService")
  16 +public class PermissionServiceImp implements PermissionService{
  17 +
  18 + @Autowired
  19 + PERMISSIONMapper permissionMapper;
  20 +
  21 + @Override
  22 + public PageInfo<PERMISSION> findAll(int pageNum, int pageSize){
  23 + Page<PERMISSION> page = PageHelper.startPage(pageNum,pageSize);
  24 + List<PERMISSION> list = permissionMapper.findAll();
  25 + PageInfo<PERMISSION> result = new PageInfo<>(list);
  26 + return result;
  27 + }
  28 +
  29 + @Override
  30 + public int insertSelective(PERMISSION record){
  31 + return permissionMapper.insertSelective(record);
  32 + }
  33 +
  34 + @Override
  35 + public Map<String,Object> getUserMenus(Integer userId){
  36 + Map<String,Object> data = new HashMap<String,Object>();
  37 + try {
  38 + //查询所有菜单
  39 + List<PERMISSION> allMenu = permissionMapper.findByUserId(userId);
  40 + //根节点
  41 + List<PERMISSION> rootMenu = new ArrayList<PERMISSION>();
  42 + for (PERMISSION nav : allMenu) {
  43 + if(nav.getParentId()==0){//父节点是0的,为根节点。
  44 + rootMenu.add(nav);
  45 + }
  46 + }
  47 +
  48 + /* 根据Menu类的order排序 */
  49 +// Collections.sort(rootMenu, order());
  50 + //为根菜单设置子菜单,getClild是递归调用的
  51 + for (PERMISSION nav : rootMenu) {
  52 + /* 获取根节点下的所有子节点 使用getChild方法*/
  53 + List<PERMISSION> childList = getChild(nav.getPermissionId(), allMenu);
  54 + nav.setChildren(childList);//给根节点设置子节点
  55 + }
  56 + /**
  57 + * 输出构建好的菜单数据。
  58 + *
  59 + */
  60 + data.put("success", "true");
  61 + data.put("list", rootMenu);
  62 + return data;
  63 + } catch (Exception e) {
  64 + data.put("success", "false");
  65 + data.put("list", new ArrayList());
  66 + return data;
  67 + }
  68 + }
  69 +
  70 + /**
  71 + * 获取子节点
  72 + * @param id 父节点id
  73 + * @param allMenu 所有菜单列表
  74 + * @return 每个根节点下,所有子菜单列表
  75 + */
  76 + public List<PERMISSION> getChild(Integer id,List<PERMISSION> allMenu){
  77 + //子菜单
  78 + List<PERMISSION> childList = new ArrayList<PERMISSION>();
  79 + for (PERMISSION nav : allMenu) {
  80 + // 遍历所有节点,将所有菜单的父id与传过来的根节点的id比较
  81 + //相等说明:为该根节点的子节点。
  82 + if(nav.getParentId().equals(id)){
  83 + childList.add(nav);
  84 + }
  85 + }
  86 + //递归
  87 + for (PERMISSION nav : childList) {
  88 + nav.setChildren(getChild(nav.getPermissionId(), allMenu));
  89 + }
  90 +// Collections.sort(childList,order());//排序
  91 + //如果节点下没有子节点,返回一个空List(递归退出)
  92 + if(childList.size() == 0){
  93 + return new ArrayList<PERMISSION>();
  94 + }
  95 + return childList;
  96 + }
  97 +}
  1 +package com.tianbo.warehouse.service.imp;
  2 +
  3 +import com.github.pagehelper.Page;
  4 +import com.github.pagehelper.PageHelper;
  5 +import com.github.pagehelper.PageInfo;
  6 +import com.tianbo.warehouse.dao.ROLEMapper;
  7 +import com.tianbo.warehouse.dao.RolePermissionMapper;
  8 +import com.tianbo.warehouse.model.ROLE;
  9 +import com.tianbo.warehouse.model.RolePermission;
  10 +import com.tianbo.warehouse.service.RoleService;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.stereotype.Service;
  13 +import org.springframework.transaction.annotation.Transactional;
  14 +
  15 +import java.util.List;
  16 +
  17 +@Service(value = "roleService")
  18 +public class RoleServiceImp implements RoleService{
  19 +
  20 + @Autowired
  21 + private ROLEMapper roleMapper;
  22 +
  23 + @Autowired
  24 + private RolePermissionMapper rolePermissionMapper;
  25 +
  26 + @Override
  27 + public PageInfo<ROLE> findAll(int pageNum, int pageSize){
  28 + Page<ROLE> page = PageHelper.startPage(pageNum,pageSize);
  29 + List<ROLE> list = roleMapper.findAll();
  30 + PageInfo<ROLE> result = new PageInfo<ROLE>(list);
  31 + return result;
  32 + }
  33 +
  34 + @Override
  35 + public int insertSelective(ROLE record){
  36 + return roleMapper.insertSelective(record);
  37 + }
  38 +
  39 + @Transactional(rollbackFor = Exception.class)
  40 + @Override
  41 + public int setRolePermissoin(RolePermission record){
  42 + try{
  43 + Integer roleId = record.getRoleId();
  44 + List<Integer> permissions = record.getPermissionIds();
  45 + //这里加个判定,如果前端提交的权限列表是空的,代表清空这个角色的所有权限,防止SQL出错
  46 + if (null!=permissions && !permissions.isEmpty()){
  47 + rolePermissionMapper.delPermByRoleId(roleId);
  48 + rolePermissionMapper.insertRolePerm(record);
  49 + }
  50 + return 1;
  51 + }catch (Exception e){
  52 + e.printStackTrace();
  53 + return 0;
  54 + }
  55 + }
  56 +}
  1 +package com.tianbo.warehouse.service.imp;
  2 +
  3 +import com.github.pagehelper.Page;
  4 +import com.github.pagehelper.PageHelper;
  5 +import com.github.pagehelper.PageInfo;
  6 +import com.tianbo.warehouse.dao.PERMISSIONMapper;
  7 +import com.tianbo.warehouse.dao.ROLEMapper;
  8 +import com.tianbo.warehouse.dao.USERSMapper;
  9 +import com.tianbo.warehouse.dao.UserRoleMapper;
  10 +import com.tianbo.warehouse.model.PERMISSION;
  11 +import com.tianbo.warehouse.model.ROLE;
  12 +import com.tianbo.warehouse.model.USERS;
  13 +import com.tianbo.warehouse.model.UserRole;
  14 +import com.tianbo.warehouse.service.UserService;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.stereotype.Service;
  17 +import org.springframework.transaction.annotation.Transactional;
  18 +
  19 +import java.util.List;
  20 +
  21 +@Service(value = "userService")
  22 +public class UserServiceImpl implements UserService{
  23 +
  24 + @Autowired
  25 + private USERSMapper usersMapper;
  26 +
  27 + @Autowired
  28 + private ROLEMapper roleMapper;
  29 +
  30 + @Autowired
  31 + private PERMISSIONMapper permissionMapper;
  32 +
  33 + @Autowired
  34 + private UserRoleMapper userRoleMapper;
  35 +
  36 + @Override
  37 + public USERS loadByUsername(String username){
  38 + List<USERS> userList = usersMapper.selectByUsername(username);
  39 +
  40 + if (userList != null && userList.size() > 0) {
  41 + USERS user = userList.get(0);
  42 +
  43 + List<PERMISSION> permissionList = permissionMapper.findByUserId(user.getUserId());
  44 + if (permissionList!=null && permissionList.size()>0){
  45 + user.setPermissions(permissionList);
  46 + }
  47 +
  48 + List<ROLE> roleList = roleMapper.findRolesByUserId(user.getUserId());
  49 + if (roleList!=null && roleList.size()>0){
  50 + user.setRoles(roleList);
  51 + }
  52 + return user;
  53 + }
  54 + return null;
  55 +
  56 + }
  57 +
  58 + @Override
  59 + public PageInfo<USERS> selectAllUser(int pageNum, int pageSize){
  60 + Page<USERS> page = PageHelper.startPage(pageNum,pageSize);
  61 + List<USERS> list = usersMapper.selectAllUser();
  62 + for (USERS user: list) {
  63 + List<PERMISSION> permissionList = permissionMapper.findByUserId(user.getUserId());
  64 + user.setPermissions(permissionList);
  65 + List<ROLE> roleList = roleMapper.findRolesByUserId(user.getUserId());
  66 + user.setRoles(roleList);
  67 + }
  68 + PageInfo<USERS> result = new PageInfo<USERS>(list);
  69 + return result;
  70 + }
  71 +
  72 + @Override
  73 + public int updateByPrimaryKeySelective(USERS record){
  74 + int i = 0;
  75 + if (record!=null){
  76 + i = usersMapper.updateByPrimaryKeySelective(record);
  77 + }
  78 + return i;
  79 +
  80 + }
  81 +
  82 + @Override
  83 + public int insertSelective(USERS record){
  84 + if (null!=record){
  85 + return usersMapper.insertSelective(record);
  86 + }else {
  87 + return 0;
  88 + }
  89 + }
  90 +
  91 + @Override
  92 + public int deleteByPrimaryKey(Integer userId){
  93 + if (null!=userId && userId>0){
  94 + return usersMapper.deleteByPrimaryKey(userId);
  95 + }else {
  96 + return 0;
  97 + }
  98 + }
  99 +
  100 + /**重置用户的权限,每次设置用户权限关系前,先删除用户所有权限,再重新分配用户权限
  101 + *这里需要开启事务,删除 或者插入不生效就回滚
  102 + * @param userRole
  103 + * @return
  104 + */
  105 + @Override
  106 + @Transactional(rollbackFor = Exception.class)
  107 + public int setUserRole(UserRole userRole){
  108 + try{
  109 + Integer userId = userRole.getUserId();
  110 + List<Integer> ids = userRole.getRoleIds();
  111 +
  112 + userRoleMapper.deleteByUserId(userId);
  113 + if (null!=ids && !ids.isEmpty()){
  114 + for (Integer id:ids) {
  115 + UserRole ur = new UserRole(userId,id);
  116 + userRoleMapper.insertSelective(ur);
  117 + }
  118 + }
  119 + return 1;
  120 + }catch (Exception e){
  121 + e.printStackTrace();
  122 + return 0;
  123 + }
  124 +
  125 + }
  126 +
  127 +}
  1 +package com.tianbo.warehouse.util.IO;
  2 +
  3 +import org.apache.commons.lang.ArrayUtils;
  4 +
  5 +import java.util.Arrays;
  6 +import java.util.stream.Stream;
  7 +
  8 +public abstract class StreamUtil implements Stream{
  9 +
  10 + public static <T> Stream<T> streamOf(T[] array) {
  11 + return ArrayUtils.isEmpty(array) ? Stream.empty() : Arrays.asList(array).stream();
  12 + }
  13 +}
@@ -25,6 +25,7 @@ public class MakeImfMeta { @@ -25,6 +25,7 @@ public class MakeImfMeta {
25 meta.addElement("STYP").addText(STYP); 25 meta.addElement("STYP").addText(STYP);
26 26
27 SAXReader saxReader = new SAXReader(); 27 SAXReader saxReader = new SAXReader();
  28 +// saxReader.setEncoding("gb2312");
28 Document doc = saxReader.read(Content); 29 Document doc = saxReader.read(Content);
29 Element contentRoot = doc.getRootElement(); 30 Element contentRoot = doc.getRootElement();
30 root.add(contentRoot); 31 root.add(contentRoot);
  1 +package com.tianbo.warehouse.validate;
  2 +
  3 +import javax.validation.Constraint;
  4 +import javax.validation.Payload;
  5 +import java.lang.annotation.*;
  6 +
  7 +@Target({ElementType.METHOD,ElementType.FIELD,ElementType.ANNOTATION_TYPE})
  8 +@Retention(RetentionPolicy.RUNTIME)
  9 +@Constraint(validatedBy = CheckUserExistValidator.class )
  10 +@Documented
  11 +/**
  12 + * 检查用户重复注解
  13 + * @author mrz
  14 + *
  15 + */
  16 +public @interface CheckUserExist {
  17 +
  18 + String message() default "";
  19 +
  20 + Class<?>[] groups() default {};
  21 +
  22 + Class<? extends Payload>[] payload() default {};
  23 +
  24 +
  25 +
  26 +}
  1 +package com.tianbo.warehouse.validate;
  2 +
  3 +import com.tianbo.warehouse.service.UserService;
  4 +import org.springframework.beans.factory.annotation.Autowired;
  5 +
  6 +import javax.validation.ConstraintValidator;
  7 +import javax.validation.ConstraintValidatorContext;
  8 +
  9 +public class CheckUserExistValidator implements ConstraintValidator<CheckUserExist,String> {
  10 +
  11 + private CheckUserExist checkUserExist;
  12 +
  13 + @Autowired
  14 + UserService userService;
  15 +
  16 + @Override
  17 + public void initialize(CheckUserExist checkUserExist) {
  18 + this.checkUserExist = checkUserExist;
  19 + }
  20 +
  21 + @Override
  22 + public boolean isValid(String username, ConstraintValidatorContext var2){
  23 + if (username == null){
  24 + return true;
  25 + }
  26 +
  27 + //根据用户名查询出来有数据,则返回失败存在用户
  28 + if (userService.loadByUsername(username)!=null){
  29 + return false;
  30 + }else {
  31 + return true;
  32 + }
  33 +
  34 +
  35 + }
  36 +}
@@ -2,29 +2,63 @@ @@ -2,29 +2,63 @@
2 #服务端口 2 #服务端口
3 server.port=7003 3 server.port=7003
4 server.servlet.context-path=${SERVER_CONTEXTPATH:} 4 server.servlet.context-path=${SERVER_CONTEXTPATH:}
5 -#eureka主机名,会在控制页面中显示  
6 -eureka.instance.hostname=${spring.cloud.client.ip-address}  
7 -#eureka服务器页面中status的请求路径  
8 -eureka.instance.status-page-url=http://${eureka.instance.hostname}:${server.port}/index  
9 -#eureka注册中心服务器地址  
10 -eureka.client.service-url.defaultZone=http://10.50.3.82:19527/eureka/ 5 +
  6 +#静态资源,设置上传文件的访问,上传文件的路径,要带斜杠
  7 +web.upload-path=upload/
  8 +#表示所有的访问经过静态资源路径
  9 +springboot.mvc.static-path-pattern=/**
  10 +spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/static,classpath:/resources/,file:${web.upload-path}
  11 +
  12 +
  13 +
11 #服务名 14 #服务名
12 -spring.application.name=imf-warehouse-reader  
13 -eureka.instance.prefer-ip-address=true  
14 -eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}  
15 -eureka.client.registry-fetch-interval-seconds=30  
16 -eureka.instance.lease-renewal-interval-in-seconds=15  
17 -eureka.instance.lease-expiration-duration-in-seconds=45 15 +spring.application.name=tianbo.base.dev.devkit
  16 +
  17 +spring.jackson.serialization.fail-on-empty-beans=false
  18 +
  19 +#springboot2.0之后会把Date类型字段自动给转成UTC字符串 如:1990-11-26T16:00:00.000+0000,如果想转成时间戳在application.properties配置文件增加以下配置
  20 +#jackson相关配置
  21 +spring.jackson.date-format = yyyy-MM-dd HH:mm:ss
  22 +spring.jackson.serialization.write-dates-as-timestamps=false
  23 +#时区必须要设置
  24 +spring.jackson.time-zone=GMT+8
  25 +#ALWAYS的意思是即时属性为null,仍然也会输出这个key
  26 +spring.jackson.default-property-inclusion=always
18 27
19 #springcloud 基本配置 28 #springcloud 基本配置
20 29
  30 +#eureka主机名,会在控制页面中显示
  31 +spring.cloud.features.enabled=false
  32 +spring.cloud.discovery.enabled=false
  33 +spring.cloud.service-registry.auto-registration.enabled=false
  34 +#eureka.instance.hostname=${spring.cloud.client.ip-address}
  35 +#eureka服务器页面中status的请求路径
  36 +#eureka.instance.status-page-url=http://${eureka.instance.hostname}:${server.port}/index
  37 +#eureka注册中心服务器地址
  38 +#eureka.client.service-url.defaultZone=http://10.50.3.82:19527/eureka/
  39 +#eureka.instance.prefer-ip-address=true
  40 +#eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
  41 +#eureka.client.registry-fetch-interval-seconds=30
  42 +#eureka.instance.lease-renewal-interval-in-seconds=15
  43 +#eureka.instance.lease-expiration-duration-in-seconds=45
21 44
22 -#spring.datasource.name=CGOETL 45 +#spring.datasource oracle
23 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource 46 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
24 -spring.datasource.driver-class-name=oracle.jdbc.OracleDriver  
25 -spring.datasource.url=jdbc:oracle:thin:@10.50.3.68:1521:CGODW  
26 -spring.datasource.username=CGOETL  
27 -spring.datasource.password=1q2w3e4r 47 +#spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
  48 +#spring.datasource.url=jdbc:oracle:thin:@10.50.3.68:1521:CGODW
  49 +#spring.datasource.username=CGOETL
  50 +#spring.datasource.password=1q2w3e4r
  51 +
  52 +#spring datasource mysql,注意编码配置,缺少数据库编码配置容易引起中文入库乱码
  53 +spring.datasource.url=jdbc:mysql://127.0.0.1:3307/statistics?useUnicode=true&characterEncoding=utf8
  54 +spring.datasource.username=root
  55 +spring.datasource.password=
  56 +spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  57 +spring.datasource.max-idle=10
  58 +spring.datasource.max-wait=10000
  59 +spring.datasource.min-idle=5
  60 +spring.datasource.initial-size=5
  61 +
28 #配置初始化大小/最小/最大 62 #配置初始化大小/最小/最大
29 spring.datasource.druid.initial-size=1 63 spring.datasource.druid.initial-size=1
30 spring.datasource.druid.min-idle=1 64 spring.datasource.druid.min-idle=1
@@ -35,21 +69,33 @@ spring.datasource.druid.max-wait=60000 @@ -35,21 +69,33 @@ spring.datasource.druid.max-wait=60000
35 spring.datasource.druid.min-evictable-idle-time-millis=300000 69 spring.datasource.druid.min-evictable-idle-time-millis=300000
36 #间隔多久进行一次检测,检测需要关闭的空闲连接 70 #间隔多久进行一次检测,检测需要关闭的空闲连接
37 spring.datasource.druid.time-between-eviction-runs-millis=60000 71 spring.datasource.druid.time-between-eviction-runs-millis=60000
38 -spring.datasource.druid.validation-query=SELECT 'x' FROM DUAL 72 +#oracle
  73 +#spring.datasource.druid.validation-query=SELECT 'x' FROM DUAL
  74 +#mysql
  75 +spring.datasource.druid.validation-query=SELECT 1 FROM DUAL
39 spring.datasource.druid.test-while-idle=true 76 spring.datasource.druid.test-while-idle=true
40 spring.datasource.druid.test-on-borrow=false 77 spring.datasource.druid.test-on-borrow=false
41 spring.datasource.druid.test-on-return=false 78 spring.datasource.druid.test-on-return=false
42 spring.datasource.druid.default-auto-commit=true 79 spring.datasource.druid.default-auto-commit=true
43 80
  81 +
  82 +
44 mybatis.mapper-locations=classpath:mapping/*.xml 83 mybatis.mapper-locations=classpath:mapping/*.xml
45 -mybatis.type-aliases-package=com.example.demo.model  
46 -logging.level.com.example.demo.mapper=DEBUG 84 +mybatis.type-aliases-package=com.tianbo.warehouse.model
  85 +
  86 +
47 87
48 -pagehelper.helper-dialect=oracle 88 +pagehelper.helper-dialect=mysql
49 #pagehelper.auto-dialect=true 89 #pagehelper.auto-dialect=true
50 #pagehelper.auto-runtime-dialect=true 90 #pagehelper.auto-runtime-dialect=true
51 pagehelper.reasonable=true 91 pagehelper.reasonable=true
52 pagehelper.support-methods-arguments=true 92 pagehelper.support-methods-arguments=true
53 pagehelper.params=count=countSql 93 pagehelper.params=count=countSql
54 94
  95 +#debug配置
  96 +trace=true
  97 +debug=true
  98 +logging.level.org.apache.tomcat=info
  99 +logging.level.com.tianbo.warehouse.dao=DEBUG
  100 +logging.level.org.springframework.security =trace
55 101
@@ -4,8 +4,8 @@ @@ -4,8 +4,8 @@
4 "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> 4 "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
5 <generatorConfiguration> 5 <generatorConfiguration>
6 <!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包--> 6 <!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包-->
7 - <!--<classPathEntry location="/Users/mrz/Downloads/mybatis-generator-core-1.3.2/lib/mysql-connector-java-5.1.25-bin.jar"/>-->  
8 - <classPathEntry location="/Users/mrz/Documents/maven/ojdbc6.jar"/> 7 + <classPathEntry location="/Users/mrz/Downloads/mybatis-generator-core-1.3.2/lib/mysql-connector-java-5.1.25-bin.jar"/>
  8 + <!--<classPathEntry location="/Users/mrz/Documents/maven/ojdbc6.jar"/>-->
9 <context id="DB2Tables" targetRuntime="MyBatis3"> 9 <context id="DB2Tables" targetRuntime="MyBatis3">
10 <commentGenerator> 10 <commentGenerator>
11 <property name="suppressDate" value="true"/> 11 <property name="suppressDate" value="true"/>
@@ -13,13 +13,16 @@ @@ -13,13 +13,16 @@
13 <property name="suppressAllComments" value="true"/> 13 <property name="suppressAllComments" value="true"/>
14 </commentGenerator> 14 </commentGenerator>
15 <!--数据库链接URL,用户名、密码 --> 15 <!--数据库链接URL,用户名、密码 -->
16 - <!--<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3307/statistics" userId="root" password="">-->  
17 - <!--</jdbcConnection>-->  
18 - <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"  
19 - connectionURL="jdbc:oracle:thin:@10.50.3.68:1521:CGODW"  
20 - userId="CGOETL"  
21 - password="1q2w3e4r"> 16 + <jdbcConnection driverClass="com.mysql.jdbc.Driver"
  17 + connectionURL="jdbc:mysql://127.0.0.1:3307/statistics"
  18 + userId="root"
  19 + password="">
22 </jdbcConnection> 20 </jdbcConnection>
  21 + <!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"-->
  22 + <!--connectionURL="jdbc:oracle:thin:@10.50.3.68:1521:CGODW"-->
  23 + <!--userId="CGOETL"-->
  24 + <!--password="1q2w3e4r">-->
  25 + <!--</jdbcConnection>-->
23 <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 26 <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
24 NUMERIC 类型解析为java.math.BigDecimal --> 27 NUMERIC 类型解析为java.math.BigDecimal -->
25 <!--<javaTypeResolver>--> 28 <!--<javaTypeResolver>-->
@@ -42,6 +45,6 @@ @@ -42,6 +45,6 @@
42 <property name="enableSubPackages" value="true"/> 45 <property name="enableSubPackages" value="true"/>
43 </javaClientGenerator> 46 </javaClientGenerator>
44 <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名--> 47 <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
45 - <table tableName="PERMISSION" domainObjectName="PERMISSION" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> 48 + <table tableName="attachment" domainObjectName="Attachment" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
46 </context> 49 </context>
47 </generatorConfiguration> 50 </generatorConfiguration>
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.tianbo.warehouse.dao.AttachmentMapper" >
  4 + <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.Attachment" >
  5 + <id column="aid" property="aid" jdbcType="INTEGER" />
  6 + <result column="path" property="path" jdbcType="VARCHAR" />
  7 + </resultMap>
  8 + <sql id="Base_Column_List" >
  9 + aid, path
  10 + </sql>
  11 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  12 + select
  13 + <include refid="Base_Column_List" />
  14 + from attachment
  15 + where aid = #{aid,jdbcType=INTEGER}
  16 + </select>
  17 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  18 + delete from attachment
  19 + where aid = #{aid,jdbcType=INTEGER}
  20 + </delete>
  21 + <insert id="insert" parameterType="com.tianbo.warehouse.model.Attachment" >
  22 + insert into attachment (aid, path)
  23 + values (#{aid,jdbcType=INTEGER}, #{path,jdbcType=VARCHAR})
  24 + </insert>
  25 + <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.Attachment" >
  26 + insert into attachment
  27 + <trim prefix="(" suffix=")" suffixOverrides="," >
  28 + <if test="aid != null" >
  29 + aid,
  30 + </if>
  31 + <if test="path != null" >
  32 + path,
  33 + </if>
  34 + </trim>
  35 + <trim prefix="values (" suffix=")" suffixOverrides="," >
  36 + <if test="aid != null" >
  37 + #{aid,jdbcType=INTEGER},
  38 + </if>
  39 + <if test="path != null" >
  40 + #{path,jdbcType=VARCHAR},
  41 + </if>
  42 + </trim>
  43 + </insert>
  44 + <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.Attachment" >
  45 + update attachment
  46 + <set >
  47 + <if test="path != null" >
  48 + path = #{path,jdbcType=VARCHAR},
  49 + </if>
  50 + </set>
  51 + where aid = #{aid,jdbcType=INTEGER}
  52 + </update>
  53 + <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.Attachment" >
  54 + update attachment
  55 + set path = #{path,jdbcType=VARCHAR}
  56 + where aid = #{aid,jdbcType=INTEGER}
  57 + </update>
  58 +</mapper>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.tianbo.warehouse.dao.LOGMapper">
  4 + <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.LOG">
  5 + <id column="logId" jdbcType="INTEGER" property="logid" />
  6 + <result column="userName" jdbcType="VARCHAR" property="username" />
  7 + <result column="ip" jdbcType="VARCHAR" property="ip" />
  8 + <result column="logCreatTime" jdbcType="TIMESTAMP" property="logcreattime" />
  9 + <result column="methodName" jdbcType="VARCHAR" property="methodname" />
  10 + <result column="modelNameCN" jdbcType="VARCHAR" property="modelnamecn" />
  11 + <result column="operateNameCN" jdbcType="VARCHAR" property="operatenamecn" />
  12 + <result column="className" jdbcType="VARCHAR" property="classname" />
  13 + </resultMap>
  14 + <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tianbo.warehouse.model.LOGWithBLOBs">
  15 + <result column="parameters" jdbcType="LONGVARCHAR" property="parameters" />
  16 + <result column="result" jdbcType="LONGVARCHAR" property="result" />
  17 + </resultMap>
  18 + <sql id="Base_Column_List">
  19 + logId, userName, ip, logCreatTime, methodName, modelNameCN, operateNameCN, className
  20 + </sql>
  21 + <sql id="Blob_Column_List">
  22 + parameters, result
  23 + </sql>
  24 + <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="ResultMapWithBLOBs">
  25 + select
  26 + <include refid="Base_Column_List" />
  27 + ,
  28 + <include refid="Blob_Column_List" />
  29 + from log
  30 + where logId = #{logid,jdbcType=INTEGER}
  31 + </select>
  32 + <select id="selectAll" resultMap="ResultMapWithBLOBs">
  33 + select
  34 + <include refid="Base_Column_List" />
  35 + ,
  36 + <include refid="Blob_Column_List" />
  37 + from log
  38 + </select>
  39 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  40 + delete from log
  41 + where logId = #{logid,jdbcType=INTEGER}
  42 + </delete>
  43 + <insert id="insert" parameterType="com.tianbo.warehouse.model.LOGWithBLOBs">
  44 + insert into log (logId, userName, ip,
  45 + logCreatTime, methodName, modelNameCN,
  46 + operateNameCN, className, parameters,
  47 + result)
  48 + values (#{logid,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{ip,jdbcType=VARCHAR},
  49 + #{logcreattime,jdbcType=TIMESTAMP}, #{methodname,jdbcType=VARCHAR}, #{modelnamecn,jdbcType=VARCHAR},
  50 + #{operatenamecn,jdbcType=VARCHAR}, #{classname,jdbcType=VARCHAR}, #{parameters,jdbcType=LONGVARCHAR},
  51 + #{result,jdbcType=LONGVARCHAR})
  52 + </insert>
  53 + <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.LOGWithBLOBs">
  54 + insert into log
  55 + <trim prefix="(" suffix=")" suffixOverrides=",">
  56 + <if test="logid != null">
  57 + logId,
  58 + </if>
  59 + <if test="username != null">
  60 + userName,
  61 + </if>
  62 + <if test="ip != null">
  63 + ip,
  64 + </if>
  65 + <if test="logcreattime != null">
  66 + logCreatTime,
  67 + </if>
  68 + <if test="methodname != null">
  69 + methodName,
  70 + </if>
  71 + <if test="modelnamecn != null">
  72 + modelNameCN,
  73 + </if>
  74 + <if test="operatenamecn != null">
  75 + operateNameCN,
  76 + </if>
  77 + <if test="classname != null">
  78 + className,
  79 + </if>
  80 + <if test="parameters != null">
  81 + parameters,
  82 + </if>
  83 + <if test="result != null">
  84 + result,
  85 + </if>
  86 + </trim>
  87 + <trim prefix="values (" suffix=")" suffixOverrides=",">
  88 + <if test="logid != null">
  89 + #{logid,jdbcType=INTEGER},
  90 + </if>
  91 + <if test="username != null">
  92 + #{username,jdbcType=VARCHAR},
  93 + </if>
  94 + <if test="ip != null">
  95 + #{ip,jdbcType=VARCHAR},
  96 + </if>
  97 + <if test="logcreattime != null">
  98 + #{logcreattime,jdbcType=TIMESTAMP},
  99 + </if>
  100 + <if test="methodname != null">
  101 + #{methodname,jdbcType=VARCHAR},
  102 + </if>
  103 + <if test="modelnamecn != null">
  104 + #{modelnamecn,jdbcType=VARCHAR},
  105 + </if>
  106 + <if test="operatenamecn != null">
  107 + #{operatenamecn,jdbcType=VARCHAR},
  108 + </if>
  109 + <if test="classname != null">
  110 + #{classname,jdbcType=VARCHAR},
  111 + </if>
  112 + <if test="parameters != null">
  113 + #{parameters,jdbcType=LONGVARCHAR},
  114 + </if>
  115 + <if test="result != null">
  116 + #{result,jdbcType=LONGVARCHAR},
  117 + </if>
  118 + </trim>
  119 + </insert>
  120 + <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.LOGWithBLOBs">
  121 + update log
  122 + <set>
  123 + <if test="username != null">
  124 + userName = #{username,jdbcType=VARCHAR},
  125 + </if>
  126 + <if test="ip != null">
  127 + ip = #{ip,jdbcType=VARCHAR},
  128 + </if>
  129 + <if test="logcreattime != null">
  130 + logCreatTime = #{logcreattime,jdbcType=TIMESTAMP},
  131 + </if>
  132 + <if test="methodname != null">
  133 + methodName = #{methodname,jdbcType=VARCHAR},
  134 + </if>
  135 + <if test="modelnamecn != null">
  136 + modelNameCN = #{modelnamecn,jdbcType=VARCHAR},
  137 + </if>
  138 + <if test="operatenamecn != null">
  139 + operateNameCN = #{operatenamecn,jdbcType=VARCHAR},
  140 + </if>
  141 + <if test="classname != null">
  142 + className = #{classname,jdbcType=VARCHAR},
  143 + </if>
  144 + <if test="parameters != null">
  145 + parameters = #{parameters,jdbcType=LONGVARCHAR},
  146 + </if>
  147 + <if test="result != null">
  148 + result = #{result,jdbcType=LONGVARCHAR},
  149 + </if>
  150 + </set>
  151 + where logId = #{logid,jdbcType=INTEGER}
  152 + </update>
  153 + <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.tianbo.warehouse.model.LOGWithBLOBs">
  154 + update log
  155 + set userName = #{username,jdbcType=VARCHAR},
  156 + ip = #{ip,jdbcType=VARCHAR},
  157 + logCreatTime = #{logcreattime,jdbcType=TIMESTAMP},
  158 + methodName = #{methodname,jdbcType=VARCHAR},
  159 + modelNameCN = #{modelnamecn,jdbcType=VARCHAR},
  160 + operateNameCN = #{operatenamecn,jdbcType=VARCHAR},
  161 + className = #{classname,jdbcType=VARCHAR},
  162 + parameters = #{parameters,jdbcType=LONGVARCHAR},
  163 + result = #{result,jdbcType=LONGVARCHAR}
  164 + where logId = #{logid,jdbcType=INTEGER}
  165 + </update>
  166 + <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.LOG">
  167 + update log
  168 + set userName = #{username,jdbcType=VARCHAR},
  169 + ip = #{ip,jdbcType=VARCHAR},
  170 + logCreatTime = #{logcreattime,jdbcType=TIMESTAMP},
  171 + methodName = #{methodname,jdbcType=VARCHAR},
  172 + modelNameCN = #{modelnamecn,jdbcType=VARCHAR},
  173 + operateNameCN = #{operatenamecn,jdbcType=VARCHAR},
  174 + className = #{classname,jdbcType=VARCHAR}
  175 + where logId = #{logid,jdbcType=INTEGER}
  176 + </update>
  177 +</mapper>
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.tianbo.warehouse.dao.PERMISSIONMapper" >
  4 + <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.PERMISSION" >
  5 + <id column="permission_id" property="permissionId" jdbcType="INTEGER" />
  6 + <result column="name" property="name" jdbcType="VARCHAR" />
  7 + <result column="permission_order" property="permissionOrder" jdbcType="VARCHAR" />
  8 + <result column="description" property="description" jdbcType="VARCHAR" />
  9 + <result column="ismenu" property="ismenu" jdbcType="BOOLEAN" />
  10 + <result column="hidden" property="hidden" jdbcType="BOOLEAN" />
  11 + <result column="parent_id" property="parentId" jdbcType="INTEGER" />
  12 + <result column="path" property="path" jdbcType="VARCHAR" />
  13 + <result column="url" property="url" jdbcType="VARCHAR" />
  14 + <result column="method" property="method" jdbcType="VARCHAR" />
  15 + <result column="iconCls" property="iconCls" jdbcType="VARCHAR" />
  16 + <result column="component" property="component" jdbcType="VARCHAR" />
  17 + </resultMap>
  18 + <sql id="Base_Column_List" >
  19 + permission_id, name, permission_order, description, ismenu,hidden,parent_id,
  20 + path, url, method, iconCls, component
  21 + </sql>
  22 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  23 + select
  24 + <include refid="Base_Column_List" />
  25 + from permission
  26 + where permission_id = #{permissionId,jdbcType=INTEGER} ORDER BY permission_order
  27 + </select>
  28 + <select id="findAll" resultMap="BaseResultMap" >
  29 + select
  30 + <include refid="Base_Column_List" />
  31 + from permission ORDER BY ismenu,parent_id,permission_order
  32 + </select>
  33 + <select id="getRolePermisson" resultMap="BaseResultMap" parameterType="java.lang.Integer">
  34 + SELECT P.*
  35 + FROM role R
  36 + LEFT JOIN role_permission RP ON R.role_id = RP.role_id
  37 + LEFT JOIN permission P ON RP.permission_id = P.permission_id
  38 + WHERE r.role_id=#{roleId,jdbcType=INTEGER}
  39 + ORDER BY P.ismenu,P.name,p.permission_order DESC
  40 + </select>
  41 + <select id="getAllMenus" resultMap="BaseResultMap" >
  42 + SELECT
  43 + P .*
  44 + FROM
  45 + permission P
  46 + WHERE
  47 + P .PERMISSION_ID IN (
  48 + SELECT
  49 + RP.permission_id
  50 + FROM
  51 + ROLE_PERMISSION RP
  52 + WHERE
  53 + RP.role_id IN (
  54 + SELECT
  55 + R.ROLE_ID
  56 + FROM
  57 + role R
  58 + WHERE
  59 + R.ROLE_ID IN (
  60 + SELECT
  61 + UR.ROLE_ID
  62 + FROM
  63 + USER_ROLE UR
  64 + WHERE
  65 + UR.USER_ID = #{userId,jdbcType=INTEGER} AND P.ismenu is TRUE
  66 + )
  67 + )
  68 + ) ORDER BY P.permission_order
  69 + <!--select-->
  70 + <!--<include refid="Base_Column_List" />-->
  71 + <!--from permission where ismenu is TRUE ORDER BY permission_order-->
  72 + </select>
  73 + <select id="findRoleListByUrl" resultType="java.lang.String" parameterType="java.lang.String">
  74 + SELECT
  75 + R.role_name
  76 +FROM
  77 + permission P
  78 + LEFT JOIN role_permission RP ON P.permission_id = RP.permission_id
  79 + LEFT JOIN ROLE R ON R.ROLE_ID= RP.ROLE_ID
  80 +where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order
  81 + </select>
  82 + <select id="findByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  83 + SELECT
  84 + P .*
  85 + FROM
  86 + permission P
  87 + WHERE
  88 + P .PERMISSION_ID IN (
  89 + SELECT
  90 + RP.permission_id
  91 + FROM
  92 + ROLE_PERMISSION RP
  93 + WHERE
  94 + RP.role_id IN (
  95 + SELECT
  96 + R.ROLE_ID
  97 + FROM
  98 + role R
  99 + WHERE
  100 + R.ROLE_ID IN (
  101 + SELECT
  102 + UR.ROLE_ID
  103 + FROM
  104 + USER_ROLE UR
  105 + WHERE
  106 + UR.USER_ID = #{userId,jdbcType=INTEGER}
  107 + )
  108 + )
  109 + ) ORDER BY permission_order
  110 + </select>
  111 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  112 + delete from permission
  113 + where permission_id = #{permissionId,jdbcType=INTEGER}
  114 + </delete>
  115 + <insert id="insert" parameterType="com.tianbo.warehouse.model.PERMISSION" >
  116 + insert into permission (permission_id, name, permission_order,
  117 + description, ismenu,hidden, parent_id,
  118 + path, url, method, iconCls,
  119 + component)
  120 + values (#{permissionId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{permissionOrder,jdbcType=VARCHAR},
  121 + #{description,jdbcType=VARCHAR}, #{ismenu,jdbcType=BOOLEAN},#{hidden,jdbcType=BOOLEAN},#{parentId,jdbcType=INTEGER},
  122 + #{path,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{method,jdbcType=VARCHAR}, #{iconCls,jdbcType=VARCHAR},
  123 + #{component,jdbcType=VARCHAR})
  124 + </insert>
  125 + <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.PERMISSION" >
  126 + insert into permission
  127 + <trim prefix="(" suffix=")" suffixOverrides="," >
  128 + <if test="permissionId != null" >
  129 + permission_id,
  130 + </if>
  131 + <if test="name != null" >
  132 + name,
  133 + </if>
  134 + <if test="permissionOrder != null" >
  135 + permission_order,
  136 + </if>
  137 + <if test="description != null" >
  138 + description,
  139 + </if>
  140 + <if test="ismenu != null" >
  141 + ismenu,
  142 + </if>
  143 + <if test="hidden != null" >
  144 + hidden,
  145 + </if>
  146 + <if test="parentId != null" >
  147 + parent_id,
  148 + </if>
  149 + <if test="path != null" >
  150 + path,
  151 + </if>
  152 + <if test="url != null" >
  153 + url,
  154 + </if>
  155 + <if test="method != null" >
  156 + method,
  157 + </if>
  158 + <if test="iconCls != null" >
  159 + iconCls,
  160 + </if>
  161 + <if test="component != null" >
  162 + component,
  163 + </if>
  164 + </trim>
  165 + <trim prefix="values (" suffix=")" suffixOverrides="," >
  166 + <if test="permissionId != null" >
  167 + #{permissionId,jdbcType=INTEGER},
  168 + </if>
  169 + <if test="name != null" >
  170 + #{name,jdbcType=VARCHAR},
  171 + </if>
  172 + <if test="permissionOrder != null" >
  173 + #{permissionOrder,jdbcType=VARCHAR},
  174 + </if>
  175 + <if test="description != null" >
  176 + #{description,jdbcType=VARCHAR},
  177 + </if>
  178 + <if test="ismenu != null" >
  179 + #{ismenu,jdbcType=BOOLEAN},
  180 + </if>
  181 + <if test="hidden != null" >
  182 + #{hidden,jdbcType=BOOLEAN},
  183 + </if>
  184 + <if test="parentId != null" >
  185 + #{parentId,jdbcType=INTEGER},
  186 + </if>
  187 + <if test="path != null" >
  188 + #{path,jdbcType=VARCHAR},
  189 + </if>
  190 + <if test="url != null" >
  191 + #{url,jdbcType=VARCHAR},
  192 + </if>
  193 + <if test="method != null" >
  194 + #{method,jdbcType=VARCHAR},
  195 + </if>
  196 + <if test="iconCls != null" >
  197 + #{iconCls,jdbcType=VARCHAR},
  198 + </if>
  199 + <if test="component != null" >
  200 + #{component,jdbcType=VARCHAR},
  201 + </if>
  202 + </trim>
  203 + </insert>
  204 + <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.PERMISSION" >
  205 + update permission
  206 + <set >
  207 + <if test="name != null" >
  208 + name = #{name,jdbcType=VARCHAR},
  209 + </if>
  210 + <if test="permissionOrder != null" >
  211 + permission_order = #{permissionOrder,jdbcType=VARCHAR},
  212 + </if>
  213 + <if test="description != null" >
  214 + description = #{description,jdbcType=VARCHAR},
  215 + </if>
  216 + <if test="ismenu != null" >
  217 + ismenu = #{ismenu,jdbcType=BOOLEAN},
  218 + </if>
  219 + <if test="hidden != null" >
  220 + hidden = #{hidden,jdbcType=BOOLEAN},
  221 + </if>
  222 + <if test="parentId != null" >
  223 + parent_id = #{parentId,jdbcType=INTEGER},
  224 + </if>
  225 + <if test="path != null" >
  226 + path = #{path,jdbcType=VARCHAR},
  227 + </if>
  228 + <if test="url != null" >
  229 + url = #{url,jdbcType=VARCHAR},
  230 + </if>
  231 + <if test="method != null" >
  232 + method = #{method,jdbcType=VARCHAR},
  233 + </if>
  234 + <if test="iconCls != null" >
  235 + iconCls = #{iconCls,jdbcType=VARCHAR},
  236 + </if>
  237 + <if test="component != null" >
  238 + component = #{component,jdbcType=VARCHAR},
  239 + </if>
  240 + </set>
  241 + where permission_id = #{permissionId,jdbcType=INTEGER}
  242 + </update>
  243 + <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.PERMISSION" >
  244 + update permission
  245 + set name = #{name,jdbcType=VARCHAR},
  246 + permission_order = #{permissionOrder,jdbcType=VARCHAR},
  247 + description = #{description,jdbcType=VARCHAR},
  248 + ismenu = #{ismenu,jdbcType=BOOLEAN},
  249 + hidden = #{hidden,jdbcType=BOOLEAN},
  250 + parent_id = #{parentId,jdbcType=INTEGER},
  251 + path = #{path,jdbcType=VARCHAR},
  252 + url = #{url,jdbcType=VARCHAR},
  253 + method = #{method,jdbcType=VARCHAR},
  254 + iconCls = #{iconCls,jdbcType=VARCHAR},
  255 + component = #{component,jdbcType=VARCHAR}
  256 + where permission_id = #{permissionId,jdbcType=INTEGER}
  257 + </update>
  258 +</mapper>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.tianbo.warehouse.dao.ROLEMapper">
  4 + <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.ROLE">
  5 + <id column="role_id" jdbcType="INTEGER" property="roleId" />
  6 + <result column="role_name" jdbcType="VARCHAR" property="roleName" />
  7 + <result column="role_sign" jdbcType="VARCHAR" property="roleSign" />
  8 + <result column="description" jdbcType="VARCHAR" property="description" />
  9 + <collection property="permissions" ofType="PERMISSION" javaType="java.util.ArrayList" select="com.tianbo.warehouse.dao.PERMISSIONMapper.getRolePermisson" column="role_id"></collection>
  10 + </resultMap>
  11 + <sql id="Base_Column_List">
  12 + role_id, role_name, role_sign, description
  13 + </sql>
  14 + <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  15 + select
  16 + <include refid="Base_Column_List" />
  17 + from role
  18 + where role_id = #{roleId,jdbcType=INTEGER}
  19 + </select>
  20 + <select id="findAll" resultMap="BaseResultMap" >
  21 + SELECT
  22 + <include refid="Base_Column_List" />
  23 + FROM role
  24 + </select>
  25 + <select id="findRolesByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  26 + SELECT
  27 + R.*
  28 + FROM
  29 + USERS U
  30 + LEFT JOIN USER_ROLE UR ON U .USER_ID = UR.USER_ID
  31 + LEFT JOIN ROLE R ON R.ROLE_ID= UR.ROLE_ID
  32 + where U.USER_ID = #{userId,jdbcType=INTEGER}
  33 + </select>
  34 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  35 + delete from role
  36 + where role_id = #{roleId,jdbcType=INTEGER}
  37 + </delete>
  38 + <insert id="insert" parameterType="com.tianbo.warehouse.model.ROLE">
  39 + insert into role (role_id, role_name, role_sign,
  40 + description)
  41 + values (#{roleId,jdbcType=INTEGER}, #{roleName,jdbcType=VARCHAR}, #{roleSign,jdbcType=VARCHAR},
  42 + #{description,jdbcType=VARCHAR})
  43 + </insert>
  44 +
  45 + <insert id="insertSelective" parameterType="Integer">
  46 + insert into role
  47 + <trim prefix="(" suffix=")" suffixOverrides=",">
  48 + <if test="roleId != null">
  49 + role_id,
  50 + </if>
  51 + <if test="roleName != null">
  52 + role_name,
  53 + </if>
  54 + <if test="roleSign != null">
  55 + role_sign,
  56 + </if>
  57 + <if test="description != null">
  58 + description,
  59 + </if>
  60 + </trim>
  61 + <trim prefix="values (" suffix=")" suffixOverrides=",">
  62 + <if test="roleId != null">
  63 + #{roleId,jdbcType=INTEGER},
  64 + </if>
  65 + <if test="roleName != null">
  66 + #{roleName,jdbcType=VARCHAR},
  67 + </if>
  68 + <if test="roleSign != null">
  69 + #{roleSign,jdbcType=VARCHAR},
  70 + </if>
  71 + <if test="description != null">
  72 + #{description,jdbcType=VARCHAR},
  73 + </if>
  74 + </trim>
  75 + </insert>
  76 + <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.ROLE">
  77 + update role
  78 + <set>
  79 + <if test="roleName != null">
  80 + role_name = #{roleName,jdbcType=VARCHAR},
  81 + </if>
  82 + <if test="roleSign != null">
  83 + role_sign = #{roleSign,jdbcType=VARCHAR},
  84 + </if>
  85 + <if test="description != null">
  86 + description = #{description,jdbcType=VARCHAR},
  87 + </if>
  88 + </set>
  89 + where role_id = #{roleId,jdbcType=INTEGER}
  90 + </update>
  91 + <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.ROLE">
  92 + update role
  93 + set role_name = #{roleName,jdbcType=VARCHAR},
  94 + role_sign = #{roleSign,jdbcType=VARCHAR},
  95 + description = #{description,jdbcType=VARCHAR}
  96 + where role_id = #{roleId,jdbcType=INTEGER}
  97 + </update>
  98 +</mapper>
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.tianbo.warehouse.dao.RolePermissionMapper" >
  4 + <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.RolePermission" >
  5 + <id column="id" property="id" jdbcType="INTEGER" />
  6 + <result column="role_id" property="roleId" jdbcType="INTEGER" />
  7 + <result column="permission_id" property="permissionId" jdbcType="INTEGER" />
  8 + </resultMap>
  9 + <sql id="Base_Column_List" >
  10 + id, role_id, permission_id
  11 + </sql>
  12 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  13 + select
  14 + <include refid="Base_Column_List" />
  15 + from role_permission
  16 + where id = #{id,jdbcType=INTEGER}
  17 + </select>
  18 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  19 + delete from role_permission
  20 + where id = #{id,jdbcType=INTEGER}
  21 + </delete>
  22 + <delete id="delPermByRoleId" parameterType="java.lang.Integer">
  23 + delete from role_permission
  24 + where role_id = #{roleId,jdbcType=INTEGER}
  25 + </delete>
  26 + <insert id="insert" parameterType="com.tianbo.warehouse.model.RolePermission" >
  27 + insert into role_permission (id, role_id, permission_id
  28 + )
  29 + values (#{id,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}, #{permissionId,jdbcType=INTEGER}
  30 + )
  31 + </insert>
  32 + <insert id="insertRolePerm" parameterType="RolePermission">
  33 + insert into role_permission(role_id, permission_id)
  34 + values
  35 + <foreach collection="permissionIds" item="rolePem" index="index" separator=",">
  36 + (#{roleId,jdbcType=INTEGER},#{rolePem,jdbcType=INTEGER})
  37 + </foreach>
  38 + </insert>
  39 + <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.RolePermission" >
  40 + insert into role_permission
  41 + <trim prefix="(" suffix=")" suffixOverrides="," >
  42 + <if test="id != null" >
  43 + id,
  44 + </if>
  45 + <if test="roleId != null" >
  46 + role_id,
  47 + </if>
  48 + <if test="permissionId != null" >
  49 + permission_id,
  50 + </if>
  51 + </trim>
  52 + <trim prefix="values (" suffix=")" suffixOverrides="," >
  53 + <if test="id != null" >
  54 + #{id,jdbcType=INTEGER},
  55 + </if>
  56 + <if test="roleId != null" >
  57 + #{roleId,jdbcType=INTEGER},
  58 + </if>
  59 + <if test="permissionId != null" >
  60 + #{permissionId,jdbcType=INTEGER},
  61 + </if>
  62 + </trim>
  63 + </insert>
  64 + <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.RolePermission" >
  65 + update role_permission
  66 + <set >
  67 + <if test="roleId != null" >
  68 + role_id = #{roleId,jdbcType=INTEGER},
  69 + </if>
  70 + <if test="permissionId != null" >
  71 + permission_id = #{permissionId,jdbcType=INTEGER},
  72 + </if>
  73 + </set>
  74 + where id = #{id,jdbcType=INTEGER}
  75 + </update>
  76 + <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.RolePermission" >
  77 + update role_permission
  78 + set role_id = #{roleId,jdbcType=INTEGER},
  79 + permission_id = #{permissionId,jdbcType=INTEGER}
  80 + where id = #{id,jdbcType=INTEGER}
  81 + </update>
  82 +</mapper>
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.tianbo.warehouse.dao.USERSMapper" >
  4 + <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.USERS" >
  5 + <id column="user_id" property="userId" jdbcType="INTEGER" />
  6 + <result column="username" property="username" jdbcType="VARCHAR" />
  7 + <result column="password" property="password" jdbcType="VARCHAR" />
  8 + <result column="birthday" property="birthday" jdbcType="TIMESTAMP" />
  9 + <result column="sex" property="sex" jdbcType="CHAR" />
  10 + <result column="address" property="address" jdbcType="VARCHAR" />
  11 + <result column="state" property="state" jdbcType="BIT" />
  12 + <result column="mobilePhone" property="mobilephone" jdbcType="VARCHAR" />
  13 + <result column="creatTime" property="creattime" jdbcType="TIMESTAMP" />
  14 + <result column="updateTime" property="updatetime" jdbcType="TIMESTAMP" />
  15 + <result column="userFace" property="userface" jdbcType="VARCHAR" />
  16 + <result column="realName" property="realname" jdbcType="VARCHAR" />
  17 + <result column="email" property="email" jdbcType="VARCHAR" />
  18 + <result column="age" property="age" jdbcType="INTEGER" />
  19 + </resultMap>
  20 + <sql id="Base_Column_List" >
  21 + user_id, username, password, birthday, sex, address, state, mobilePhone, creatTime,
  22 + updateTime, userFace, realName, email, age
  23 + </sql>
  24 + <sql id="user_List" >
  25 + user_id, username, birthday, sex, address, state, mobilePhone,userFace, realName, email, age
  26 + </sql>
  27 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  28 + select
  29 + <include refid="Base_Column_List" />
  30 + from users
  31 + where user_id = #{userId,jdbcType=INTEGER}
  32 + </select>
  33 + <select id="selectByUsername" resultMap="BaseResultMap" parameterType="java.lang.String" >
  34 + select
  35 + <include refid="Base_Column_List" />
  36 + from USERS
  37 + where USERNAME = #{username,jdbcType=VARCHAR}
  38 + </select>
  39 + <select id="selectAllUser" resultMap="BaseResultMap" >
  40 + select
  41 + <include refid="user_List" />
  42 + from USERS
  43 + </select>
  44 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  45 + delete from users
  46 + where user_id = #{userId,jdbcType=INTEGER}
  47 + </delete>
  48 + <insert id="insert" parameterType="com.tianbo.warehouse.model.USERS" >
  49 + insert into users (user_id, username, password,
  50 + birthday, sex, address,
  51 + state, mobilePhone, creatTime,
  52 + updateTime, userFace, realName,
  53 + email, age)
  54 + values (#{userId,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
  55 + #{birthday,jdbcType=TIMESTAMP}, #{sex,jdbcType=CHAR}, #{address,jdbcType=VARCHAR},
  56 + #{state,jdbcType=BIT}, #{mobilephone,jdbcType=VARCHAR}, #{creattime,jdbcType=TIMESTAMP},
  57 + #{updatetime,jdbcType=TIMESTAMP}, #{userface,jdbcType=VARCHAR}, #{realname,jdbcType=VARCHAR},
  58 + #{email,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER})
  59 + </insert>
  60 + <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.USERS" >
  61 + insert into users
  62 + <trim prefix="(" suffix=")" suffixOverrides="," >
  63 + <if test="userId != null" >
  64 + user_id,
  65 + </if>
  66 + <if test="username != null" >
  67 + username,
  68 + </if>
  69 + <if test="password != null" >
  70 + password,
  71 + </if>
  72 + <if test="birthday != null" >
  73 + birthday,
  74 + </if>
  75 + <if test="sex != null" >
  76 + sex,
  77 + </if>
  78 + <if test="address != null" >
  79 + address,
  80 + </if>
  81 + <if test="state != null" >
  82 + state,
  83 + </if>
  84 + <if test="mobilephone != null" >
  85 + mobilePhone,
  86 + </if>
  87 + <if test="creattime != null" >
  88 + creatTime,
  89 + </if>
  90 + <if test="updatetime != null" >
  91 + updateTime,
  92 + </if>
  93 + <if test="userface != null" >
  94 + userFace,
  95 + </if>
  96 + <if test="realname != null" >
  97 + realname,
  98 + </if>
  99 + <if test="email != null" >
  100 + email,
  101 + </if>
  102 + <if test="age != null" >
  103 + age,
  104 + </if>
  105 + </trim>
  106 + <trim prefix="values (" suffix=")" suffixOverrides="," >
  107 + <if test="userId != null" >
  108 + #{userId,jdbcType=INTEGER},
  109 + </if>
  110 + <if test="username != null" >
  111 + #{username,jdbcType=VARCHAR},
  112 + </if>
  113 + <if test="password != null" >
  114 + #{password,jdbcType=VARCHAR},
  115 + </if>
  116 + <if test="birthday != null" >
  117 + #{birthday,jdbcType=TIMESTAMP},
  118 + </if>
  119 + <if test="sex != null" >
  120 + #{sex,jdbcType=CHAR},
  121 + </if>
  122 + <if test="address != null" >
  123 + #{address,jdbcType=VARCHAR},
  124 + </if>
  125 + <if test="state != null" >
  126 + #{state,jdbcType=BIT},
  127 + </if>
  128 + <if test="mobilephone != null" >
  129 + #{mobilephone,jdbcType=VARCHAR},
  130 + </if>
  131 + <if test="creattime != null" >
  132 + #{creattime,jdbcType=TIMESTAMP},
  133 + </if>
  134 + <if test="updatetime != null" >
  135 + #{updatetime,jdbcType=TIMESTAMP},
  136 + </if>
  137 + <if test="userface != null" >
  138 + #{userface,jdbcType=VARCHAR},
  139 + </if>
  140 + <if test="realname != null" >
  141 + #{realname,jdbcType=VARCHAR},
  142 + </if>
  143 + <if test="email != null" >
  144 + #{email,jdbcType=VARCHAR},
  145 + </if>
  146 + <if test="age != null" >
  147 + #{age,jdbcType=INTEGER},
  148 + </if>
  149 + </trim>
  150 + </insert>
  151 + <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.USERS" >
  152 + update users
  153 + <set >
  154 + <if test="password != null" >
  155 + password = #{password,jdbcType=VARCHAR},
  156 + </if>
  157 + <if test="birthday != null" >
  158 + birthday = #{birthday,jdbcType=TIMESTAMP},
  159 + </if>
  160 + <if test="sex != null" >
  161 + sex = #{sex,jdbcType=CHAR},
  162 + </if>
  163 + <if test="address != null" >
  164 + address = #{address,jdbcType=VARCHAR},
  165 + </if>
  166 + <if test="state != null" >
  167 + state = #{state,jdbcType=BIT},
  168 + </if>
  169 + <if test="mobilephone != null" >
  170 + mobilePhone = #{mobilephone,jdbcType=VARCHAR},
  171 + </if>
  172 + <if test="creattime != null" >
  173 + creatTime = #{creattime,jdbcType=TIMESTAMP},
  174 + </if>
  175 + <if test="updatetime != null" >
  176 + updateTime = #{updatetime,jdbcType=TIMESTAMP},
  177 + </if>
  178 + <if test="userface != null" >
  179 + userFace = #{userface,jdbcType=VARCHAR},
  180 + </if>
  181 + <if test="realname != null" >
  182 + realname = #{realname,jdbcType=VARCHAR},
  183 + </if>
  184 + <if test="email != null" >
  185 + email = #{email,jdbcType=VARCHAR},
  186 + </if>
  187 + <if test="age != null" >
  188 + age = #{age,jdbcType=INTEGER},
  189 + </if>
  190 + </set>
  191 + where user_id = #{userId,jdbcType=INTEGER}
  192 + </update>
  193 + <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.USERS" >
  194 + update users
  195 + set password = #{password,jdbcType=VARCHAR},
  196 + birthday = #{birthday,jdbcType=TIMESTAMP},
  197 + sex = #{sex,jdbcType=CHAR},
  198 + address = #{address,jdbcType=VARCHAR},
  199 + state = #{state,jdbcType=BIT},
  200 + mobilePhone = #{mobilephone,jdbcType=VARCHAR},
  201 + creatTime = #{creattime,jdbcType=TIMESTAMP},
  202 + updateTime = #{updatetime,jdbcType=TIMESTAMP},
  203 + userFace = #{userface,jdbcType=VARCHAR},
  204 + realName = #{realname,jdbcType=VARCHAR},
  205 + email = #{email,jdbcType=VARCHAR},
  206 + age = #{age,jdbcType=INTEGER}
  207 + where user_id = #{userId,jdbcType=INTEGER}
  208 + </update>
  209 +</mapper>
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.tianbo.warehouse.dao.UserRoleMapper" >
  4 + <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.UserRole" >
  5 + <id column="id" property="id" jdbcType="INTEGER" />
  6 + <result column="user_id" property="userId" jdbcType="INTEGER" />
  7 + <result column="role_id" property="roleId" jdbcType="INTEGER" />
  8 + </resultMap>
  9 + <sql id="Base_Column_List" >
  10 + id, user_id, role_id
  11 + </sql>
  12 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  13 + select
  14 + <include refid="Base_Column_List" />
  15 + from user_role
  16 + where id = #{id,jdbcType=INTEGER}
  17 + </select>
  18 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  19 + delete from user_role
  20 + where id = #{id,jdbcType=INTEGER}
  21 + </delete>
  22 + <delete id="deleteByUserId" parameterType="java.lang.Integer" >
  23 + delete from user_role
  24 + where user_id = #{userId,jdbcType=INTEGER}
  25 + </delete>
  26 + <insert id="insert" parameterType="com.tianbo.warehouse.model.UserRole" >
  27 + insert into user_role (user_id, role_id
  28 + )
  29 + values (#{userId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}
  30 + )
  31 + </insert>
  32 + <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.UserRole" >
  33 + insert into user_role
  34 + <trim prefix="(" suffix=")" suffixOverrides="," >
  35 + <if test="userId != null" >
  36 + user_id,
  37 + </if>
  38 + <if test="roleId != null" >
  39 + role_id,
  40 + </if>
  41 + </trim>
  42 + <trim prefix="values (" suffix=")" suffixOverrides="," >
  43 + <if test="userId != null" >
  44 + #{userId,jdbcType=INTEGER},
  45 + </if>
  46 + <if test="roleId != null" >
  47 + #{roleId,jdbcType=INTEGER},
  48 + </if>
  49 + </trim>
  50 + </insert>
  51 + <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.UserRole" >
  52 + update user_role
  53 + <set >
  54 + <if test="userId != null" >
  55 + user_id = #{userId,jdbcType=INTEGER},
  56 + </if>
  57 + <if test="roleId != null" >
  58 + role_id = #{roleId,jdbcType=INTEGER},
  59 + </if>
  60 + </set>
  61 + where id = #{id,jdbcType=INTEGER}
  62 + </update>
  63 + <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.UserRole" >
  64 + update user_role
  65 + set user_id = #{userId,jdbcType=INTEGER},
  66 + role_id = #{roleId,jdbcType=INTEGER}
  67 + where id = #{id,jdbcType=INTEGER}
  68 + </update>
  69 +</mapper>
  1 +<!DOCTYPE html>
  2 +<html xmlns:th="http://www.thymeleaf.org">
  3 +<head>
  4 + <meta content="text/html;charset=UTF-8"/>
  5 + <title>登录页面</title>
  6 + <link rel="stylesheet" th:href="@{css/bootstrap.min.css}"/>
  7 + <style type="text/css">
  8 + body {
  9 + padding-top: 50px;
  10 + }
  11 + .starter-template {
  12 + padding: 40px 15px;
  13 + text-align: center;
  14 + }
  15 + </style>
  16 +</head>
  17 +<body>
  18 +
  19 +<nav class="navbar navbar-inverse navbar-fixed-top">
  20 + <div class="container">
  21 + <div class="navbar-header">
  22 + <a class="navbar-brand" href="#">Spring Security演示</a>
  23 + </div>
  24 + <div id="navbar" class="collapse navbar-collapse">
  25 + <ul class="nav navbar-nav">
  26 + <li><a th:href="@{/}"> 首页 </a></li>
  27 +
  28 + </ul>
  29 + </div><!--/.nav-collapse -->
  30 + </div>
  31 +</nav>
  32 +<div class="container">
  33 + welcom
  34 +</div>
  35 +</body>
  36 +</html>
  1 +<!DOCTYPE html>
  2 +<html xmlns:th="http://www.thymeleaf.org">
  3 +<head>
  4 + <meta content="text/html;charset=UTF-8"/>
  5 + <title>错误页面</title>
  6 + <link rel="stylesheet" th:href="@{css/bootstrap.min.css}"/>
  7 + <style type="text/css">
  8 + body {
  9 + padding-top: 50px;
  10 + }
  11 + .starter-template {
  12 + padding: 40px 15px;
  13 + text-align: center;
  14 + }
  15 + </style>
  16 +</head>
  17 +<body>
  18 +
  19 +<nav class="navbar navbar-inverse navbar-fixed-top">
  20 + <div class="container">
  21 + <div class="navbar-header">
  22 + <a class="navbar-brand" href="#">Spring Security演示</a>
  23 + </div>
  24 + <div id="navbar" class="collapse navbar-collapse">
  25 + <ul class="nav navbar-nav">
  26 + <li><a th:href="@{/}"> 首页 </a></li>
  27 +
  28 + </ul>
  29 + </div><!--/.nav-collapse -->
  30 + </div>
  31 +</nav>
  32 +<div class="container">
  33 +
  34 +</div>
  35 +</body>
  36 +</html>
@@ -36,10 +36,10 @@ @@ -36,10 +36,10 @@
36 <div class="starter-template"> 36 <div class="starter-template">
37 <h1 th:text="${msg.description}"></h1> 37 <h1 th:text="${msg.description}"></h1>
38 38
39 - <p class="bg-primary" th:text="${msg.content}"></p> 39 + <p class="bg-primary" th:text="${msg.description}"></p>
40 40
41 <div sec:authorize="hasRole('ROLE_HOME')"> <!-- 用户类型为ROLE_ADMIN 显示 --> 41 <div sec:authorize="hasRole('ROLE_HOME')"> <!-- 用户类型为ROLE_ADMIN 显示 -->
42 - <p class="bg-info" th:text="${msg.etraInfo}"></p> 42 + <p class="bg-info" th:text="${msg.description}"></p>
43 </div> 43 </div>
44 <div sec:authorize="hasRole('ROLE_ADMIN')"> <!-- 用户类型为ROLE_ADMIN 显示 --> 44 <div sec:authorize="hasRole('ROLE_ADMIN')"> <!-- 用户类型为ROLE_ADMIN 显示 -->
45 <p class="bg-info">恭喜您,您有 ROLE_ADMIN 权限 </p> 45 <p class="bg-info">恭喜您,您有 ROLE_ADMIN 权限 </p>
@@ -44,6 +44,10 @@ @@ -44,6 +44,10 @@
44 <label for="password">密码</label> 44 <label for="password">密码</label>
45 <input type="password" class="form-control" name="password" placeholder="密码" /> 45 <input type="password" class="form-control" name="password" placeholder="密码" />
46 </div> 46 </div>
  47 + <div class="form-group">
  48 + <label for="remeberme">记住我</label>
  49 + <input type="checkbox" name="remember-me" />
  50 + </div>
47 <input type="submit" id="login" value="Login" class="btn btn-primary" /> 51 <input type="submit" id="login" value="Login" class="btn btn-primary" />
48 </form> 52 </form>
49 </div> 53 </div>
@@ -4,9 +4,12 @@ import org.junit.Test; @@ -4,9 +4,12 @@ import org.junit.Test;
4 import org.junit.runner.RunWith; 4 import org.junit.runner.RunWith;
5 import org.springframework.boot.test.context.SpringBootTest; 5 import org.springframework.boot.test.context.SpringBootTest;
6 import org.springframework.test.context.junit4.SpringRunner; 6 import org.springframework.test.context.junit4.SpringRunner;
  7 +import org.springframework.test.context.web.WebAppConfiguration;
7 8
8 @RunWith(SpringRunner.class) 9 @RunWith(SpringRunner.class)
9 -@SpringBootTest 10 +@WebAppConfiguration
  11 +//解决mvn clean package打包项目websocketjavax.websocket.server.ServerContainer not available报错的问题
  12 +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
10 public class WarehouseApplicationTests { 13 public class WarehouseApplicationTests {
11 14
12 @Test 15 @Test
1 package com.tianbo.warehouse; 1 package com.tianbo.warehouse;
2 2
3 -import com.tianbo.warehouse.handle.IMFSaveHandle; 3 +import com.tianbo.warehouse.imf.handle.IMFSaveHandle;
4 4
5 public class handleTest { 5 public class handleTest {
6 private static String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Msg> <META> <SNDR>NDLR</SNDR> <RCVR></RCVR> <SEQN>172-33519102</SEQN> <DDTM>20181229124530224</DDTM> <TYPE>HYXX</TYPE> <STYP>NDLR</STYP> </META> <DECLAREPREPAREMASTERXMLBODY> <Head> <MessageID>CN_MT2201_1P0_460470678920X_20181229124530224</MessageID> <FunctionCode>9</FunctionCode> <MessageType>MT2201MASTER</MessageType> <SenderID>460470678920X_DXPENT0000460002_20181229124530224</SenderID> <ReceiverID>4604_20181229124530224</ReceiverID> <SendTime>20181229124530224</SendTime> <Version>1.0</Version> </Head> <Declaration> <Carrier> <ID>CV</ID> </Carrier> <ORG> <ID>CGO</ID> </ORG> <DES> <ID>CDG</ID> </DES> <BorderTransportMeans> <JourneyID>9732/2019-01-01</JourneyID> </BorderTransportMeans> <Consignment> <TransportContractDocument> <ID>172-33519102</ID> </TransportContractDocument> <LoadingLocation> <ID>CGO/4604</ID> <LoadingDate>2018-12-29 12:45</LoadingDate> </LoadingLocation> <UnloadingLocation> <ID>CGO/4604</ID> </UnloadingLocation> <TransportSplitIndicator>0</TransportSplitIndicator> <ConsignmentPackaging> <QuantityQuantity>337</QuantityQuantity> </ConsignmentPackaging> <TotalGrossMassMeasure>3192</TotalGrossMassMeasure> <PreQuantityQuantity>337</PreQuantityQuantity> <PreTotalGrossMassMeasure>3192</PreTotalGrossMassMeasure> <CustomsStatus>001</CustomsStatus> <FreightPayment> <MethodCode>PP</MethodCode> </FreightPayment> <ProductName>IMITATION JEWELRY</ProductName> <PrepareTime>2018-12-29 12:45</PrepareTime> <CustomsCode>4604</CustomsCode> <AgentName>ZRP</AgentName> <AgentCompany>郑州睿鹏物流有限公司</AgentCompany> <NameOfgoods>IMITATION JEWELRY</NameOfgoods> <DeliveryStation>001</DeliveryStation> <UNnumber></UNnumber> <Category></Category> <Consignee> <Name>QUALITAIR SEA INTERNATIONAL</Name> <Address> <Line>4 RUE DU MEUNIER BP 19622 95724 ROISSY CDG</Line> <CityName>CDG</CityName> <CountryCode>FR</CountryCode> <ZipCode></ZipCode> <PROVINCECODE></PROVINCECODE> <PROVINCENAME></PROVINCENAME> <Deltaname></Deltaname> <TelePhone>33 1 34 38 58 13</TelePhone> <Fax></Fax> <CNECUSID>EUROPEAN VAT NUMBER+FR93392293635</CNECUSID> <CNEAEO></CNEAEO> <Unlodingcode>CDG</Unlodingcode> </Address> </Consignee> <Consignor> <name>ON TIME EXPRESS LIMITED</name> <Address> <Line>ROOM 1102 FINANCIAL STREET HAI LUN CENTER NO 440 HAI LUN ROAD</Line> <CountryCode>CN</CountryCode> <ZipCode></ZipCode> <Deltaname></Deltaname> <TelePhone>862163642582</TelePhone> <Fax></Fax> <SHPAEO></SHPAEO> <SHPCUSID>USCI+91310000717852489D</SHPCUSID> </Address> </Consignor> </Consignment> </Declaration> </DECLAREPREPAREMASTERXMLBODY></Msg>"; 6 private static String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Msg> <META> <SNDR>NDLR</SNDR> <RCVR></RCVR> <SEQN>172-33519102</SEQN> <DDTM>20181229124530224</DDTM> <TYPE>HYXX</TYPE> <STYP>NDLR</STYP> </META> <DECLAREPREPAREMASTERXMLBODY> <Head> <MessageID>CN_MT2201_1P0_460470678920X_20181229124530224</MessageID> <FunctionCode>9</FunctionCode> <MessageType>MT2201MASTER</MessageType> <SenderID>460470678920X_DXPENT0000460002_20181229124530224</SenderID> <ReceiverID>4604_20181229124530224</ReceiverID> <SendTime>20181229124530224</SendTime> <Version>1.0</Version> </Head> <Declaration> <Carrier> <ID>CV</ID> </Carrier> <ORG> <ID>CGO</ID> </ORG> <DES> <ID>CDG</ID> </DES> <BorderTransportMeans> <JourneyID>9732/2019-01-01</JourneyID> </BorderTransportMeans> <Consignment> <TransportContractDocument> <ID>172-33519102</ID> </TransportContractDocument> <LoadingLocation> <ID>CGO/4604</ID> <LoadingDate>2018-12-29 12:45</LoadingDate> </LoadingLocation> <UnloadingLocation> <ID>CGO/4604</ID> </UnloadingLocation> <TransportSplitIndicator>0</TransportSplitIndicator> <ConsignmentPackaging> <QuantityQuantity>337</QuantityQuantity> </ConsignmentPackaging> <TotalGrossMassMeasure>3192</TotalGrossMassMeasure> <PreQuantityQuantity>337</PreQuantityQuantity> <PreTotalGrossMassMeasure>3192</PreTotalGrossMassMeasure> <CustomsStatus>001</CustomsStatus> <FreightPayment> <MethodCode>PP</MethodCode> </FreightPayment> <ProductName>IMITATION JEWELRY</ProductName> <PrepareTime>2018-12-29 12:45</PrepareTime> <CustomsCode>4604</CustomsCode> <AgentName>ZRP</AgentName> <AgentCompany>郑州睿鹏物流有限公司</AgentCompany> <NameOfgoods>IMITATION JEWELRY</NameOfgoods> <DeliveryStation>001</DeliveryStation> <UNnumber></UNnumber> <Category></Category> <Consignee> <Name>QUALITAIR SEA INTERNATIONAL</Name> <Address> <Line>4 RUE DU MEUNIER BP 19622 95724 ROISSY CDG</Line> <CityName>CDG</CityName> <CountryCode>FR</CountryCode> <ZipCode></ZipCode> <PROVINCECODE></PROVINCECODE> <PROVINCENAME></PROVINCENAME> <Deltaname></Deltaname> <TelePhone>33 1 34 38 58 13</TelePhone> <Fax></Fax> <CNECUSID>EUROPEAN VAT NUMBER+FR93392293635</CNECUSID> <CNEAEO></CNEAEO> <Unlodingcode>CDG</Unlodingcode> </Address> </Consignee> <Consignor> <name>ON TIME EXPRESS LIMITED</name> <Address> <Line>ROOM 1102 FINANCIAL STREET HAI LUN CENTER NO 440 HAI LUN ROAD</Line> <CountryCode>CN</CountryCode> <ZipCode></ZipCode> <Deltaname></Deltaname> <TelePhone>862163642582</TelePhone> <Fax></Fax> <SHPAEO></SHPAEO> <SHPCUSID>USCI+91310000717852489D</SHPCUSID> </Address> </Consignor> </Consignment> </Declaration> </DECLAREPREPAREMASTERXMLBODY></Msg>";