diff --git a/order/order-application/pom.xml b/order/order-application/pom.xml index 81dea751e..0d5e8e2df 100644 --- a/order/order-application/pom.xml +++ b/order/order-application/pom.xml @@ -11,28 +11,32 @@ order-application + 1.3.0.Final + + cn.iocoder.mall + order-service-impl + 1.0-SNAPSHOT + + + cn.iocoder.mall + admin-sdk + 1.0-SNAPSHOT + + + cn.iocoder.mall + common-framework + 1.0-SNAPSHOT + + org.springframework.boot spring-boot-starter-web - - mysql - mysql-connector-java - - - org.springframework.boot - spring-boot-starter-jdbc - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 2.0.0 - org.springframework.boot @@ -64,7 +68,6 @@ ${org.mapstruct.version} - io.springfox springfox-swagger2 @@ -75,6 +78,29 @@ springfox-swagger-ui 2.9.2 + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + org.springframework.boot + spring-boot-devtools + true + + + + de.codecentric + spring-boot-admin-starter-client + 2.1.3 + + + org.springframework.boot + spring-boot-starter-actuator + + @@ -96,6 +122,16 @@ + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/OrderApplication.java b/order/order-application/src/main/java/cn/iocoder/mall/order/OrderApplication.java new file mode 100644 index 000000000..4cb842769 --- /dev/null +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/OrderApplication.java @@ -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); + } + +} \ No newline at end of file diff --git a/order/order-application/src/main/resources/application.yaml b/order/order-application/src/main/resources/application.yaml index 1571ccb5a..54e9eb09b 100644 --- a/order/order-application/src/main/resources/application.yaml +++ b/order/order-application/src/main/resources/application.yaml @@ -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 \ No newline at end of file + port: 18084 + servlet: + context-path: /order-api/ diff --git a/order/order-service-api/pom.xml b/order/order-service-api/pom.xml index 23d69d81d..239cd3496 100644 --- a/order/order-service-api/pom.xml +++ b/order/order-service-api/pom.xml @@ -11,5 +11,10 @@ order-service-api - + + + javax.validation + validation-api + + \ No newline at end of file diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateDTO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateDTO.java index ffc105548..81cb3b819 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateDTO.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateDTO.java @@ -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 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 getOrderItems() { + return orderItems; + } + + public OrderCreateDTO setOrderItems(List orderItems) { + this.orderItems = orderItems; + return this; + } } diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateItemDTO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateItemDTO.java new file mode 100644 index 000000000..717523d44 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCreateItemDTO.java @@ -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; + } +} diff --git a/order/order-service-impl/pom.xml b/order/order-service-impl/pom.xml index 84772f74b..371573cb7 100644 --- a/order/order-service-impl/pom.xml +++ b/order/order-service-impl/pom.xml @@ -11,18 +11,28 @@ order-service-impl + + 1.3.0.Final + + cn.iocoder.mall order-service-api 1.0-SNAPSHOT - + + cn.iocoder.mall + admin-service-api + 1.0-SNAPSHOT + compile + com.alibaba dubbo compile + mysql mysql-connector-java @@ -37,11 +47,65 @@ mybatis-spring-boot-starter 2.0.0 + + org.mapstruct + mapstruct + ${org.mapstruct.version} + com.google.guava guava 27.0.1-jre + + + Pingplusplus + pingpp-java + 2.2.4 + jar + + + + com.xuxueli + xxl-job-core + 2.0.1 + + + + org.apache.rocketmq + rocketmq-spring-boot-starter + 2.0.1 + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + + + + \ No newline at end of file diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/config/DatabaseConfiguration.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/config/DatabaseConfiguration.java new file mode 100644 index 000000000..42cc4659d --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/config/DatabaseConfiguration.java @@ -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 + +} \ No newline at end of file diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/config/ServiceExceptionConfiguration.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/config/ServiceExceptionConfiguration.java new file mode 100644 index 000000000..14e361d08 --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/config/ServiceExceptionConfiguration.java @@ -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); +// } + } +} \ No newline at end of file diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderConvert.java new file mode 100644 index 000000000..e5209c17e --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/convert/OrderConvert.java @@ -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 convert(List orderCreateItemDTOList); +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderDO.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderDO.java index 7ea7d5519..f4fcb79d3 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderDO.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderDO.java @@ -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; } } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderItemDO.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderItemDO.java index 474d94b46..20fe8ff2a 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderItemDO.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/dataobject/OrderItemDO.java @@ -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; } } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/service/OrderServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/service/OrderServiceImpl.java new file mode 100644 index 000000000..6263d5d58 --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/service/OrderServiceImpl.java @@ -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 orderItemDTOList = orderCreateDTO.getOrderItems(); + OrderDO orderDO = OrderConvert.INSTANCE.convert(orderCreateDTO); + List 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() { + + } +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/service/ServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/service/ServiceImpl.java deleted file mode 100644 index 69c69fba2..000000000 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/service/ServiceImpl.java +++ /dev/null @@ -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 { - - -} diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/ProductApplication.java b/order/order-service-impl/src/test/java/cn/iocoder/mall/order/OrderApplicationTest.java similarity index 54% rename from order/order-application/src/main/java/cn/iocoder/mall/order/ProductApplication.java rename to order/order-service-impl/src/test/java/cn/iocoder/mall/order/OrderApplicationTest.java index 1df2b9d36..664a1bd44 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/ProductApplication.java +++ b/order/order-service-impl/src/test/java/cn/iocoder/mall/order/OrderApplicationTest.java @@ -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); } } \ No newline at end of file diff --git a/order/order-service-impl/src/test/java/cn/iocoder/mall/order/service/OrderServiceImplTest.java b/order/order-service-impl/src/test/java/cn/iocoder/mall/order/service/OrderServiceImplTest.java new file mode 100644 index 000000000..971e5441e --- /dev/null +++ b/order/order-service-impl/src/test/java/cn/iocoder/mall/order/service/OrderServiceImplTest.java @@ -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))); + } +}