authorization
parent
db353c319f
commit
29bfa023ec
|
@ -0,0 +1,110 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="Spring" name="Spring">
|
||||
<configuration />
|
||||
</facet>
|
||||
<facet type="web" name="Web">
|
||||
<configuration>
|
||||
<webroots />
|
||||
<sourceRoots>
|
||||
<root url="file://$MODULE_DIR$/src/main/java" />
|
||||
<root url="file://$MODULE_DIR$/src/main/resources" />
|
||||
</sourceRoots>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.11.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.11.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.26" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.23" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.21" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:9.0.21" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.21" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.0.17.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.validation:validation-api:2.0.1.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.2.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.4.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-devtools:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.15" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: com.jayway.jsonpath:json-path:2.4.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:json-smart:2.3" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:accessors-smart:1.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.ow2.asm:asm:5.0.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.26" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:3.11.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:2.23.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.9.13" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.9.13" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.6" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.5.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.6.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-jpa:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.9.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.transaction:javax.transaction-api:1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hibernate:hibernate-core:5.3.10.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.persistence:javax.persistence-api:2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.javassist:javassist:3.23.2-GA" level="project" />
|
||||
<orderEntry type="library" name="Maven: antlr:antlr:2.7.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jboss:jandex:2.0.5.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.dom4j:dom4j:2.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:5.0.4.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-jpa:2.1.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:2.1.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-orm:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aspects:5.1.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.5" level="project" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,89 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>SpringBoot2</artifactId>
|
||||
<groupId>zz</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>SpringBootOrder</artifactId>
|
||||
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.6</version><!--$NO-MVN-MAN-VER$-->
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.15</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>alimaven</id>
|
||||
<name>aliyun maven</name>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<build>
|
||||
<finalName>core</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,23 @@
|
|||
package com.zz;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2019-05-6 18:30
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@ServletComponentScan //如果使用过滤器,必须添加这个注解
|
||||
@EnableJpaAuditing //用户 插入数据的时候,插入默认系统时间
|
||||
public class Application {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.zz.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
@Configuration
|
||||
public class CORSConfiguration extends WebMvcConfigurerAdapter {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedMethods("*")
|
||||
.allowedOrigins("*")
|
||||
.allowedHeaders("*");
|
||||
super.addCorsMappings(registry);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package com.zz.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.zz.order.entity.ShopRecord;
|
||||
import com.zz.util.Date2LongSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-06-11 18:30
|
||||
*/
|
||||
@Data
|
||||
//@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
|
||||
//@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class OrderDTO {
|
||||
|
||||
private Long shopOrderId;
|
||||
|
||||
private String shopOrderUser;
|
||||
|
||||
private String shopOrderCreateman;
|
||||
|
||||
private Date shopOrderCreatetime;
|
||||
|
||||
private String shopOrderCode;
|
||||
|
||||
private String shopOrderRemarks;
|
||||
|
||||
private Byte shopOrderStatus;
|
||||
|
||||
private String shopOrderCompanyid;
|
||||
|
||||
private String shopOrderName;
|
||||
|
||||
private String shopOrderCarnumber;
|
||||
|
||||
private String shopOrderPhone;
|
||||
|
||||
private String shopOrderCartype;
|
||||
|
||||
private String shopOrderCarbrand;
|
||||
|
||||
private BigDecimal shopOrderTotalprice;
|
||||
|
||||
private String shopOrderUserCard;
|
||||
|
||||
private Byte shopOrderPaytype;
|
||||
|
||||
private String shopOrderUpdateman;
|
||||
@JsonSerialize(using = Date2LongSerializer.class)
|
||||
private Date shopOrderUpdatetime;
|
||||
|
||||
List<ShopRecord> orderDetailList;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.zz.enums;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-07-16 18:16
|
||||
*/
|
||||
public interface CodeEnum {
|
||||
Integer getCode();
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.zz.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-06-11 17:12
|
||||
*/
|
||||
@Getter
|
||||
public enum OrderStatusEnum implements CodeEnum {
|
||||
NEW(0, "新订单"),
|
||||
FINISHED(1, "完结"),
|
||||
CANCEL(2, "已取消"),
|
||||
;
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String message;
|
||||
|
||||
OrderStatusEnum(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.zz.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-06-11 17:16
|
||||
*/
|
||||
@Getter
|
||||
public enum PayStatusEnum implements CodeEnum {
|
||||
|
||||
WAIT(0, "等待支付"),
|
||||
SUCCESS(1, "支付成功"),
|
||||
|
||||
;
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String message;
|
||||
|
||||
PayStatusEnum(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.zz.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 商品状态
|
||||
* Created by Bsea
|
||||
* 2017-05-09 17:33
|
||||
*/
|
||||
@Getter
|
||||
public enum ProductStatusEnum implements CodeEnum {
|
||||
UP(0, "在架"),
|
||||
DOWN(1, "下架")
|
||||
;
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String message;
|
||||
|
||||
ProductStatusEnum(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.zz.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-06-11 18:56
|
||||
*/
|
||||
@Getter
|
||||
public enum ResultEnum {
|
||||
|
||||
SUCCESS(0, "成功"),
|
||||
|
||||
PARAM_ERROR(1, "参数不正确"),
|
||||
|
||||
PRODUCT_NOT_EXIST(10, "商品不存在"),
|
||||
|
||||
PRODUCT_STOCK_ERROR(11, "商品库存不正确"),
|
||||
|
||||
ORDER_NOT_EXIST(12, "订单不存在"),
|
||||
|
||||
ORDERDETAIL_NOT_EXIST(13, "订单详情不存在"),
|
||||
|
||||
ORDER_STATUS_ERROR(14, "订单状态不正确"),
|
||||
|
||||
ORDER_UPDATE_FAIL(15, "订单更新失败"),
|
||||
|
||||
ORDER_DETAIL_EMPTY(16, "订单详情为空"),
|
||||
|
||||
ORDER_PAY_STATUS_ERROR(17, "订单支付状态不正确"),
|
||||
|
||||
CART_EMPTY(18, "购物车为空"),
|
||||
|
||||
ORDER_OWNER_ERROR(19, "该订单不属于当前用户"),
|
||||
|
||||
WECHAT_MP_ERROR(20, "微信公众账号方面错误"),
|
||||
|
||||
WXPAY_NOTIFY_MONEY_VERIFY_ERROR(21, "微信支付异步通知金额校验不通过"),
|
||||
|
||||
ORDER_CANCEL_SUCCESS(22, "订单取消成功"),
|
||||
|
||||
ORDER_FINISH_SUCCESS(23, "订单完结成功"),
|
||||
|
||||
PRODUCT_STATUS_ERROR(24, "商品状态不正确"),
|
||||
|
||||
LOGIN_FAIL(25, "登录失败, 登录信息不正确"),
|
||||
|
||||
LOGOUT_SUCCESS(26, "登出成功"),
|
||||
;
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String message;
|
||||
|
||||
ResultEnum(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.zz.exception;
|
||||
|
||||
public class DataValidationException extends RuntimeException {
|
||||
|
||||
public DataValidationException(String msg){
|
||||
super(msg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.zz.exception;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
public class GlobExceptionHandler {
|
||||
//没有匹配的错误处理方法的时候,就被这个处理
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Map<String, Object> handle2(Exception e) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("message", e.getMessage());
|
||||
log.error(e.getMessage());
|
||||
return map;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.zz.form;
|
||||
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-06-18 23:31
|
||||
*/
|
||||
@Data
|
||||
public class OrderForm {
|
||||
|
||||
/**
|
||||
* 买家手机号码
|
||||
*/
|
||||
@NotEmpty(message = "手机号码必填")
|
||||
private String shopOrderCode;
|
||||
|
||||
/**
|
||||
* 桌号
|
||||
*/
|
||||
@NotEmpty(message = "桌号必填")
|
||||
private String shopOrderRemarks;
|
||||
|
||||
/**
|
||||
* 买家姓名
|
||||
*/
|
||||
@NotEmpty(message = "姓名必填")
|
||||
private String shopOrderUser;
|
||||
|
||||
/**
|
||||
* 总价
|
||||
*/
|
||||
|
||||
private String shopOrderTotalprice;
|
||||
|
||||
/**
|
||||
* 订单状态
|
||||
*/
|
||||
|
||||
private Byte shopOrderStatus;
|
||||
/**
|
||||
* 订单内容
|
||||
*/
|
||||
private String shopOrderName;
|
||||
/**
|
||||
* 商户id
|
||||
*/
|
||||
@NotEmpty(message = "商户号码必填")
|
||||
private String shopOrderCompanyid;
|
||||
/**
|
||||
* 购物车
|
||||
*/
|
||||
@NotEmpty(message = "购物车不能为空")
|
||||
private String shopRecordList;
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.zz.order.controller;
|
||||
|
||||
import com.zz.dto.OrderDTO;
|
||||
import com.zz.exception.DataValidationException;
|
||||
import com.zz.form.OrderForm;
|
||||
import com.zz.order.service.OrderService;
|
||||
import com.zz.util.OrderForm2OrderDTOConverter;
|
||||
import com.zz.util.ResultVOUtil;
|
||||
import com.zz.vo.ResultVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2019-05-6 18:30
|
||||
*/
|
||||
@RequestMapping("/order")
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class OrderController {
|
||||
|
||||
@Resource
|
||||
OrderService orderService;
|
||||
//创建订单
|
||||
@PostMapping("/create")
|
||||
public ResultVO<Map<String, String>> create(@Valid OrderForm orderForm,
|
||||
BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
log.error("【创建订单】参数不正确, orderForm={}", orderForm);
|
||||
throw new DataValidationException(bindingResult.getFieldError().getDefaultMessage());
|
||||
}
|
||||
|
||||
OrderDTO orderDTO = OrderForm2OrderDTOConverter.convert(orderForm);
|
||||
if (CollectionUtils.isEmpty(orderDTO.getOrderDetailList())) {
|
||||
log.error("【创建订单】购物车不能为空");
|
||||
throw new DataValidationException("购物车不能为空");
|
||||
}
|
||||
|
||||
OrderDTO createResult = orderService.create(orderDTO);
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("shopOrderId", createResult.getShopOrderId()+"");
|
||||
|
||||
return ResultVOUtil.success(map);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.zz.order.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class ShopOrder {
|
||||
@Id
|
||||
private Long shopOrderId;
|
||||
|
||||
private String shopOrderUser;
|
||||
|
||||
private String shopOrderCreateman;
|
||||
|
||||
private Date shopOrderCreatetime;
|
||||
|
||||
private String shopOrderCode;
|
||||
|
||||
private String shopOrderRemarks;
|
||||
|
||||
private Byte shopOrderStatus;
|
||||
|
||||
private String shopOrderCompanyid;
|
||||
|
||||
private String shopOrderName;
|
||||
|
||||
private String shopOrderCarnumber;
|
||||
|
||||
private String shopOrderPhone;
|
||||
|
||||
private String shopOrderCartype;
|
||||
|
||||
private String shopOrderCarbrand;
|
||||
|
||||
private BigDecimal shopOrderTotalprice;
|
||||
|
||||
private String shopOrderUserCard;
|
||||
|
||||
private Byte shopOrderPaytype;
|
||||
|
||||
private String shopOrderUpdateman;
|
||||
|
||||
private Date shopOrderUpdatetime;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.zz.order.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
@Entity
|
||||
@Data
|
||||
public class ShopRecord {
|
||||
@Id
|
||||
private Long shopRecordId;
|
||||
|
||||
private Long shopRecordSparesId;
|
||||
|
||||
private BigDecimal shopRecordPrice;
|
||||
|
||||
private Integer shopRecordNumber;
|
||||
|
||||
private String shopRecordUnit;
|
||||
|
||||
private Float shopRecordDiscount;
|
||||
|
||||
private BigDecimal shopRecordActualprice;
|
||||
|
||||
private String shopRecordOperater;
|
||||
|
||||
private String shopRecordSalesman;
|
||||
|
||||
private Long shopOrderId;
|
||||
|
||||
private Long mealId;
|
||||
|
||||
private String shopRecordStatus;
|
||||
|
||||
private Date shopRecordUpdatetime;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.zz.order.repository;
|
||||
|
||||
import com.zz.order.entity.ShopOrder;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface ShopOrderRepository extends JpaRepository<ShopOrder, Long> {
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.zz.order.repository;
|
||||
|
||||
import com.zz.order.entity.ShopRecord;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface ShopRecordRepository extends JpaRepository<ShopRecord,Long> {
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.zz.order.service;
|
||||
|
||||
import com.zz.dto.OrderDTO;
|
||||
|
||||
public interface OrderService {
|
||||
public OrderDTO create(OrderDTO orderDTO);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.zz.order.service.impl;
|
||||
|
||||
import com.zz.dto.OrderDTO;
|
||||
import com.zz.order.entity.ShopOrder;
|
||||
import com.zz.order.entity.ShopRecord;
|
||||
import com.zz.order.repository.ShopOrderRepository;
|
||||
import com.zz.order.repository.ShopRecordRepository;
|
||||
import com.zz.order.service.OrderService;
|
||||
import com.zz.util.KeyUtil;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
@Resource
|
||||
ShopRecordRepository shopRecordRepository;
|
||||
@Resource
|
||||
ShopOrderRepository shopOrderRepository;
|
||||
@Override
|
||||
public OrderDTO create(OrderDTO orderDTO) {
|
||||
Long orderId = KeyUtil.genUniqueLongKey();
|
||||
//1. 查询商品(数量, 价格)
|
||||
for (ShopRecord orderDetail: orderDTO.getOrderDetailList()) {
|
||||
//订单详情入库
|
||||
orderDetail.setShopRecordId(KeyUtil.genUniqueLongKey());
|
||||
orderDetail.setShopOrderId(orderId);
|
||||
// BeanUtils.copyProperties(productInfo, orderDetail);
|
||||
shopRecordRepository.save(orderDetail);
|
||||
}
|
||||
ShopOrder shopOrder=new ShopOrder();
|
||||
|
||||
BeanUtils.copyProperties(orderDTO, shopOrder);
|
||||
shopOrder.setShopOrderId(orderId);
|
||||
shopOrderRepository.save(shopOrder);
|
||||
orderDTO.setShopOrderId(orderId);
|
||||
return orderDTO;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.zz.util;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* cookie工具类
|
||||
* Created by Bsea
|
||||
* 2017-07-30 16:31
|
||||
*/
|
||||
public class CookieUtil {
|
||||
|
||||
/**
|
||||
* 设置
|
||||
* @param response
|
||||
* @param name
|
||||
* @param value
|
||||
* @param maxAge
|
||||
*/
|
||||
public static void set(HttpServletResponse response,
|
||||
String name,
|
||||
String value,
|
||||
int maxAge) {
|
||||
Cookie cookie = new Cookie(name, value);
|
||||
cookie.setPath("/");
|
||||
cookie.setMaxAge(maxAge);
|
||||
response.addCookie(cookie);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取cookie
|
||||
* @param request
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static Cookie get(HttpServletRequest request,
|
||||
String name) {
|
||||
Map<String, Cookie> cookieMap = readCookieMap(request);
|
||||
if (cookieMap.containsKey(name)) {
|
||||
return cookieMap.get(name);
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将cookie封装成Map
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private static Map<String, Cookie> readCookieMap(HttpServletRequest request) {
|
||||
Map<String, Cookie> cookieMap = new HashMap<>();
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (cookies != null) {
|
||||
for (Cookie cookie: cookies) {
|
||||
cookieMap.put(cookie.getName(), cookie);
|
||||
}
|
||||
}
|
||||
return cookieMap;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.zz.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-06-19 00:29
|
||||
*/
|
||||
public class Date2LongSerializer extends JsonSerializer<Date> {
|
||||
|
||||
@Override
|
||||
public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
|
||||
jsonGenerator.writeNumber(date.getTime() / 1000);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.zz.util;
|
||||
|
||||
|
||||
import com.zz.enums.CodeEnum;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-07-16 18:36
|
||||
*/
|
||||
public class EnumUtil {
|
||||
|
||||
public static <T extends CodeEnum> T getByCode(Integer code, Class<T> enumClass) {
|
||||
for (T each: enumClass.getEnumConstants()) {
|
||||
if (code.equals(each.getCode())) {
|
||||
return each;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.zz.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-07-04 01:30
|
||||
*/
|
||||
public class JsonUtil {
|
||||
|
||||
public static String toJson(Object object) {
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.setPrettyPrinting();
|
||||
Gson gson = gsonBuilder.create();
|
||||
return gson.toJson(object);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.zz.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-06-11 19:12
|
||||
*/
|
||||
public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 生成唯一的主键
|
||||
* 格式: 时间+随机数
|
||||
* @return
|
||||
*/
|
||||
public static synchronized String genUniqueKey() {
|
||||
Random random = new Random();
|
||||
Integer number = random.nextInt(900000) + 100000;
|
||||
|
||||
return System.currentTimeMillis() + String.valueOf(number);
|
||||
}
|
||||
|
||||
|
||||
public static synchronized Long genUniqueLongKey() {
|
||||
Random random = new Random();
|
||||
Integer number = random.nextInt(900000) + 100000;
|
||||
|
||||
return Long.parseLong(System.currentTimeMillis() + String.valueOf(number));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.zz.util;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-07-09 16:56
|
||||
*/
|
||||
public class MathUtil {
|
||||
|
||||
private static final Double MONEY_RANGE = 0.01;
|
||||
|
||||
/**
|
||||
* 比较2个金额是否相等
|
||||
* @param d1
|
||||
* @param d2
|
||||
* @return
|
||||
*/
|
||||
public static Boolean equals(Double d1, Double d2) {
|
||||
Double result = Math.abs(d1 - d2);
|
||||
if (result < MONEY_RANGE) {
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.zz.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.zz.dto.OrderDTO;
|
||||
import com.zz.exception.DataValidationException;
|
||||
import com.zz.form.OrderForm;
|
||||
import com.zz.order.entity.ShopRecord;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.DataFormatException;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-06-18 23:41
|
||||
*/
|
||||
@Slf4j
|
||||
public class OrderForm2OrderDTOConverter {
|
||||
|
||||
public static OrderDTO convert(OrderForm orderForm) {
|
||||
Gson gson = new Gson();
|
||||
OrderDTO orderDTO = new OrderDTO();
|
||||
orderDTO.setShopOrderCode(orderForm.getShopOrderCode());
|
||||
orderDTO.setShopOrderName(orderForm.getShopOrderName());
|
||||
orderDTO.setShopOrderRemarks(orderForm.getShopOrderRemarks());
|
||||
orderDTO.setShopOrderCompanyid(orderForm.getShopOrderCompanyid());
|
||||
orderDTO.setShopOrderUser(orderForm.getShopOrderUser());
|
||||
orderDTO.setShopOrderStatus(orderForm.getShopOrderStatus());
|
||||
|
||||
List<ShopRecord> orderDetailList = new ArrayList<>();
|
||||
try {
|
||||
orderDetailList = gson.fromJson(orderForm.getShopRecordList(),
|
||||
new TypeToken<List<ShopRecord>>() {
|
||||
}.getType());
|
||||
} catch (Exception e) {
|
||||
log.error("【对象转换】错误, string={}", orderForm.getShopRecordList());
|
||||
throw new DataValidationException("对象转换");
|
||||
}
|
||||
orderDTO.setOrderDetailList(orderDetailList);
|
||||
|
||||
return orderDTO;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.zz.util;
|
||||
|
||||
import com.zz.vo.ResultVO;
|
||||
|
||||
/**
|
||||
* Created by Bsea
|
||||
* 2017-05-15 00:22
|
||||
*/
|
||||
public class ResultVOUtil {
|
||||
|
||||
public static ResultVO success(Object object) {
|
||||
ResultVO resultVO = new ResultVO();
|
||||
resultVO.setBody(object);
|
||||
resultVO.setErrorCode(-1);
|
||||
resultVO.setMsg("成功");
|
||||
return resultVO;
|
||||
}
|
||||
|
||||
public static ResultVO success() {
|
||||
return success(null);
|
||||
}
|
||||
|
||||
public static ResultVO error(Integer code, String msg) {
|
||||
ResultVO resultVO = new ResultVO();
|
||||
resultVO.setErrorCode(code);
|
||||
resultVO.setMsg(msg);
|
||||
return resultVO;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.zz.util;
|
||||
|
||||
|
||||
public class Test {
|
||||
|
||||
static final int PRICE_TABLE_MAX = 16;
|
||||
public static void main(String[] args) {
|
||||
String a="2343";
|
||||
if("ss".equals(a)){
|
||||
a=null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int[] priceTable = new int [PRICE_TABLE_MAX];
|
||||
|
||||
System.out.println("hello");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.zz.util;
|
||||
|
||||
/**
|
||||
* @Description: java类作用描述
|
||||
* @Author: Bsea
|
||||
* @CreateDate: 2019/9/22$ 21:20$
|
||||
*/
|
||||
public class Test2 {
|
||||
final static String PARAM1="DDD";
|
||||
static String s1="sss";
|
||||
String s2;
|
||||
String s3="aaa";
|
||||
int a=18;
|
||||
Test2(String a){
|
||||
this.s2=a;
|
||||
System.out.println(s1);
|
||||
System.out.println(s3);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
Test2 test2=new Test2("CCC");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.zz.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 商品详情
|
||||
* Created by Bsea
|
||||
* 2017-05-12 14:25
|
||||
*/
|
||||
@Data
|
||||
public class ProductInfoVO {
|
||||
|
||||
@JsonProperty("id")
|
||||
private String productId;
|
||||
|
||||
@JsonProperty("name")
|
||||
private String productName;
|
||||
|
||||
@JsonProperty("price")
|
||||
private BigDecimal productPrice;
|
||||
|
||||
@JsonProperty("description")
|
||||
private String productDescription;
|
||||
|
||||
@JsonProperty("icon")
|
||||
private String productIcon;
|
||||
|
||||
@JsonProperty("num")
|
||||
private Integer productNum;
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.zz.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品(包含类目)
|
||||
* Created by Bsea
|
||||
* 2017-05-12 14:20
|
||||
*/
|
||||
@Data
|
||||
public class ProductVO {
|
||||
|
||||
@JsonProperty("name")
|
||||
private String categoryName;
|
||||
|
||||
@JsonProperty("type")
|
||||
private Integer categoryType;
|
||||
|
||||
@JsonProperty("foods")
|
||||
private List<ProductInfoVO> productInfoVOList;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.zz.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* http请求返回的最外层对象
|
||||
* Created by Bsea
|
||||
* 2017-05-12 14:13
|
||||
*/
|
||||
@Data
|
||||
public class ResultVO<T> {
|
||||
|
||||
/** 结果. */
|
||||
private boolean success;
|
||||
|
||||
/** 错误码. */
|
||||
private Integer errorCode;
|
||||
|
||||
/** 提示信息. */
|
||||
private String msg;
|
||||
|
||||
/** 具体内容. */
|
||||
private T body;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
# 设置项目的端口号
|
||||
server.port=9088
|
||||
#设置工程名字
|
||||
server.servlet.context-path=/xsz
|
||||
|
||||
# 数据库的信息
|
||||
spring.datasource.url = jdbc:mysql://localhost:3306/java10?useSSL=false&serverTimezone=Asia/Shanghai
|
||||
spring.datasource.username = root
|
||||
spring.datasource.password = Java20190713*yy
|
||||
spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
|
||||
spring.jpa.database = MYSQL
|
||||
# spring.jpa.show-sql = true 表示会在控制台打印执行的sql语句
|
||||
spring.jpa.show-sql = true
|
||||
spring.jpa.hibernate.ddl-auto = update
|
Loading…
Reference in New Issue