- order 临时提交 发现 db 链接的不对

This commit is contained in:
sin 2019-03-17 17:05:01 +08:00
parent 8a652c24eb
commit ba7669f3a2
16 changed files with 509 additions and 80 deletions

View File

@ -11,28 +11,32 @@
<artifactId>order-application</artifactId>
<properties>
<org.mapstruct.version>1.3.0.Final</org.mapstruct.version>
</properties>
<dependencies>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>order-service-impl</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>admin-sdk</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>common-framework</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -64,7 +68,6 @@
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
@ -75,6 +78,29 @@
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId> <!-- use mapstruct-jdk8 for Java 8 or higher -->
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
@ -96,6 +122,16 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<!-- 打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -0,0 +1,14 @@
package cn.iocoder.mall.order;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.order"})
public class OrderApplication {
public static void main(String[] args) {
SpringApplication.run(OrderApplication.class, args);
}
}

View File

@ -1,32 +1,9 @@
spring:
application:
name: order-application
# datasource
datasource:
url: jdbc:mysql://127.0.0.1:33061/mall_order?useSSL=false
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
# server
server:
port: 8080
# mybatis
mybatis:
config-location: classpath:mybatis-config.xml
mapper-locations: classpath:mapper/*.xml
type-aliases-package: cn.iocoder.mall.order.dataobject
# dubbo
dubbo:
registry:
address: zookeeper://127.0.0.1:2181
protocol:
port: -1
name: dubbo
scan:
base-packages: cn.iocoder.mall.order.service
demo:
service:
version: 1.0.0
port: 18084
servlet:
context-path: /order-api/

View File

@ -11,5 +11,10 @@
<artifactId>order-service-api</artifactId>
<dependencies>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,6 +1,9 @@
package cn.iocoder.mall.order.api.dto;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;
/**
* 订单创建
@ -9,4 +12,87 @@ import java.io.Serializable;
* @time 2019-03-16 14:42
*/
public class OrderCreateDTO implements Serializable {
/**
* 收件区域编号
*/
@NotNull
private String receiverAreaNo;
/**
* 收件手机号
*/
@NotNull
private String receiverMobile;
/**
* 收件详细地址
*/
@NotNull
private String receiverAddress;
/**
* 备注
*/
private String remark;
///
/// order item
@NotNull
@Size(max = 1000, min = 1)
private List<OrderCreateItemDTO> orderItems;
@Override
public String toString() {
return "OrderCreateDTO{" +
"receiverAreaNo='" + receiverAreaNo + '\'' +
", receiverMobile='" + receiverMobile + '\'' +
", receiverAddress='" + receiverAddress + '\'' +
", remark='" + remark + '\'' +
", orderItems=" + orderItems +
'}';
}
public String getReceiverAreaNo() {
return receiverAreaNo;
}
public OrderCreateDTO setReceiverAreaNo(String receiverAreaNo) {
this.receiverAreaNo = receiverAreaNo;
return this;
}
public String getReceiverMobile() {
return receiverMobile;
}
public OrderCreateDTO setReceiverMobile(String receiverMobile) {
this.receiverMobile = receiverMobile;
return this;
}
public String getReceiverAddress() {
return receiverAddress;
}
public OrderCreateDTO setReceiverAddress(String receiverAddress) {
this.receiverAddress = receiverAddress;
return this;
}
public String getRemark() {
return remark;
}
public OrderCreateDTO setRemark(String remark) {
this.remark = remark;
return this;
}
public List<OrderCreateItemDTO> getOrderItems() {
return orderItems;
}
public OrderCreateDTO setOrderItems(List<OrderCreateItemDTO> orderItems) {
this.orderItems = orderItems;
return this;
}
}

View File

@ -0,0 +1,49 @@
package cn.iocoder.mall.order.api.dto;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;
/**
* @author Sin
* @time 2019-03-17 09:37
*/
public class OrderCreateItemDTO {
/**
* 商品编号
*/
@NotNull
private String commodityId;
/**
* 数量
*/
@NotNull
@Max(value = 1000)
private Integer quantity;
@Override
public String toString() {
return "OrderCreateItemDTO{" +
"commodityId='" + commodityId + '\'' +
", quantity=" + quantity +
'}';
}
public String getCommodityId() {
return commodityId;
}
public OrderCreateItemDTO setCommodityId(String commodityId) {
this.commodityId = commodityId;
return this;
}
public Integer getQuantity() {
return quantity;
}
public OrderCreateItemDTO setQuantity(Integer quantity) {
this.quantity = quantity;
return this;
}
}

View File

@ -11,18 +11,28 @@
<artifactId>order-service-impl</artifactId>
<properties>
<org.mapstruct.version>1.3.0.Final</org.mapstruct.version>
</properties>
<dependencies>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>order-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>admin-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
@ -37,11 +47,65 @@
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0.1-jre</version>
</dependency>
<dependency>
<groupId>Pingplusplus</groupId>
<artifactId>pingpp-java</artifactId>
<version>2.2.4</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 提供给 mapstruct 使用 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source> <!-- or higher, depending on your project -->
<target>1.8</target> <!-- or higher, depending on your project -->
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,14 @@
package cn.iocoder.mall.order.config;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@MapperScan("cn.iocoder.mall.order.dao") // 扫描对应的 Mapper 接口
@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理为什么使用 proxyTargetClass 参数参见 https://blog.csdn.net/huang_550/article/details/76492600
public class DatabaseConfiguration {
// 数据源使用 HikariCP
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.mall.order.config;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
@Configuration
public class ServiceExceptionConfiguration {
@EventListener(ApplicationReadyEvent.class) // 可参考 https://www.cnblogs.com/ssslinppp/p/7607509.html
public void initMessages() {
// service_exception_message.properties 加载错误码的方案
// Properties properties;
// try {
// properties = PropertiesLoaderUtils.loadAllProperties("classpath:service_exception_message.properties");
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
}
}

View File

@ -0,0 +1,41 @@
package cn.iocoder.mall.order.convert;
import cn.iocoder.mall.order.api.dto.OrderCreateDTO;
import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO;
import cn.iocoder.mall.order.dataobject.OrderDO;
import cn.iocoder.mall.order.dataobject.OrderItemDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 订单 convert
*
* @author Sin
* @time 2019-03-17 10:14
*/
@Mapper
public interface OrderConvert {
OrderConvert INSTANCE = Mappers.getMapper(OrderConvert.class);
/**
* 转换 OrderDO
*
* @param orderCreateDTO
* @return
*/
@Mappings({})
OrderDO convert(OrderCreateDTO orderCreateDTO);
/**
* 转换 OrderItemDO
*
* @param orderCreateItemDTOList
* @return
*/
@Mappings({})
List<OrderItemDO> convert(List<OrderCreateItemDTO> orderCreateItemDTOList);
}

View File

@ -99,103 +99,116 @@ public class OrderDO implements Serializable {
return id;
}
public void setId(String id) {
public OrderDO setId(String id) {
this.id = id;
return this;
}
public String getOrderNo() {
return orderNo;
}
public void setOrderNo(String orderNo) {
public OrderDO setOrderNo(String orderNo) {
this.orderNo = orderNo;
return this;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
public OrderDO setPrice(Integer price) {
this.price = price;
return this;
}
public String getReceiverAreaNo() {
return receiverAreaNo;
}
public void setReceiverAreaNo(String receiverAreaNo) {
public OrderDO setReceiverAreaNo(String receiverAreaNo) {
this.receiverAreaNo = receiverAreaNo;
return this;
}
public String getReceiverMobile() {
return receiverMobile;
}
public void setReceiverMobile(String receiverMobile) {
public OrderDO setReceiverMobile(String receiverMobile) {
this.receiverMobile = receiverMobile;
return this;
}
public String getReceiverAddress() {
return receiverAddress;
}
public void setReceiverAddress(String receiverAddress) {
public OrderDO setReceiverAddress(String receiverAddress) {
this.receiverAddress = receiverAddress;
return this;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
public OrderDO setStatus(Integer status) {
this.status = status;
return this;
}
public Integer getPayStatus() {
return payStatus;
}
public void setPayStatus(Integer payStatus) {
public OrderDO setPayStatus(Integer payStatus) {
this.payStatus = payStatus;
return this;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
public OrderDO setCreateTime(Date createTime) {
this.createTime = createTime;
return this;
}
public Date getPaymentTime() {
return paymentTime;
}
public void setPaymentTime(Date paymentTime) {
public OrderDO setPaymentTime(Date paymentTime) {
this.paymentTime = paymentTime;
return this;
}
public Date getDeliveryTime() {
return deliveryTime;
}
public void setDeliveryTime(Date deliveryTime) {
public OrderDO setDeliveryTime(Date deliveryTime) {
this.deliveryTime = deliveryTime;
return this;
}
public Date getClosingTime() {
return closingTime;
}
public void setClosingTime(Date closingTime) {
public OrderDO setClosingTime(Date closingTime) {
this.closingTime = closingTime;
return this;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
public OrderDO setRemark(String remark) {
this.remark = remark;
return this;
}
}

View File

@ -59,47 +59,53 @@ public class OrderItemDO implements Serializable {
return id;
}
public void setId(String id) {
public OrderItemDO setId(String id) {
this.id = id;
return this;
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
public OrderItemDO setOrderId(String orderId) {
this.orderId = orderId;
return this;
}
public String getCommodityId() {
return commodityId;
}
public void setCommodityId(String commodityId) {
public OrderItemDO setCommodityId(String commodityId) {
this.commodityId = commodityId;
return this;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
public OrderItemDO setQuantity(Integer quantity) {
this.quantity = quantity;
return this;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
public OrderItemDO setPrice(Integer price) {
this.price = price;
return this;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
public OrderItemDO setStatus(Integer status) {
this.status = status;
return this;
}
}

View File

@ -0,0 +1,75 @@
package cn.iocoder.mall.order.service;
import cn.iocoder.mall.order.api.OrderService;
import cn.iocoder.mall.order.api.bo.OrderBO;
import cn.iocoder.mall.order.api.dto.OrderCreateDTO;
import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO;
import cn.iocoder.mall.order.api.dto.OrderUpdateDTO;
import cn.iocoder.mall.order.dataobject.OrderDO;
import cn.iocoder.mall.order.dataobject.OrderItemDO;
import cn.iocoder.mall.order.convert.OrderConvert;
import cn.iocoder.mall.order.dao.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 订单 service impl
*
* @author Sin
* @time 2019-03-16 15:08
*/
@Service
@com.alibaba.dubbo.config.annotation.Service(validation = "true")
public class OrderServiceImpl implements OrderService {
@Autowired
private OrderMapper orderMapper;
@Override
public OrderBO createOrder(OrderCreateDTO orderCreateDTO) {
List<OrderCreateItemDTO> orderItemDTOList = orderCreateDTO.getOrderItems();
OrderDO orderDO = OrderConvert.INSTANCE.convert(orderCreateDTO);
List<OrderItemDO> orderItemDOList = OrderConvert.INSTANCE.convert(orderItemDTOList);
orderMapper.insert(orderDO);
String a = "";
// orderConvert.con
// for (OrderCreateItemDTO orderCreateItemDTO : orderItemDTOList) {
// OrderItemDO orderItemDO = new OrderItemDO();
// orderItemDO.setId();
// orderItemDO.setCommodityId();
// orderItemDO.setOrderId();
// orderItemDO.setPrice();
// orderItemDO.setQuantity();
// orderItemDO.setStatus();
// }
// orderMapper.insert();
return null;
}
@Override
public void updateOrder(OrderUpdateDTO orderUpdateDTO) {
}
@Override
public void deleteOrder(String orderId) {
}
@Override
public void listenerPayment() {
}
@Override
public void listenerConfirmGoods() {
}
@Override
public void listenerExchangeGoods() {
}
}

View File

@ -1,16 +0,0 @@
package cn.iocoder.mall.order.service;
import org.springframework.stereotype.Service;
/**
* 订单 service impl
*
* @author Sin
* @time 2019-03-16 15:08
*/
@Service
@com.alibaba.dubbo.config.annotation.Service(validation = "true")
public class ServiceImpl {
}

View File

@ -3,11 +3,11 @@ package cn.iocoder.mall.order;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ProductApplication {
@SpringBootApplication(scanBasePackages = "cn.iocoder.mall.order")
public class OrderApplicationTest {
public static void main(String[] args) {
SpringApplication.run(ProductApplication.class, args);
SpringApplication.run(OrderApplicationTest.class, args);
}
}

View File

@ -0,0 +1,45 @@
package cn.iocoder.mall.order.service;
import cn.iocoder.mall.order.OrderApplicationTest;
import cn.iocoder.mall.order.api.OrderService;
import cn.iocoder.mall.order.api.dto.OrderCreateDTO;
import cn.iocoder.mall.order.api.dto.OrderCreateItemDTO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
/**
* 订单 service test
*
* @author Sin
* @time 2019-03-17 10:34
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = OrderApplicationTest.class)
//@Transactional
public class OrderServiceImplTest {
@Autowired
private OrderService orderService;
@Test
public void createOrderTest() {
OrderCreateItemDTO orderCreateItemDTO
= new OrderCreateItemDTO()
.setCommodityId("CID_001")
.setQuantity(1);
orderService.createOrder(new OrderCreateDTO()
.setRemark("")
.setReceiverMobile("13301926050")
.setReceiverAddress("深圳市福田区")
.setReceiverAreaNo("1000100")
.setOrderItems(Arrays.asList(orderCreateItemDTO)));
}
}