赞
踩
- package com.fjz.vxsell.bean;
-
- import com.fjz.vxsell.enums.OrderStatusEnums;
- import com.fjz.vxsell.enums.PayStatusEnums;
- import lombok.Data;
- import org.hibernate.annotations.DynamicUpdate;
-
- import javax.persistence.Entity;
- import javax.persistence.Id;
- import java.math.BigDecimal;
- import java.util.Date;
-
- /**
- * 订单主表
- * @author 冯师兄
- * @date 2020-05-08 14:18
- */
- @Entity
- @Data
- @DynamicUpdate
- public class OrderMaster {
-
- /*订单id*/
- @Id
- private String orderId;
-
- /*买家名字*/
- private String buyerName;
-
- /*买家电话*/
- private String buyerPhone;
-
- /*买家地址*/
- private String buyerAddress;
-
- /*买家微信id*/
- private String buyerOpenid;
-
- /*订单总金额*/
- private BigDecimal orderAmount;
-
- /*订单状态,默认是新订单为0,实体类中最好不要出现=0,这里用一个枚举*/
- private Integer orderStatus = OrderStatusEnums.NEW.getCode();
-
- /*支付状态,默认为0 未支付*/
- private Integer payerStatus = PayStatusEnums.WAIT.getCode();
-
- /*创建时间*/
- private Date createTime;
-
- /*修改时间*/
- private Date updateTime;
- }
- package com.fjz.vxsell.enums;
-
- import lombok.Getter;
-
- /**
- * @author 冯师兄
- * @date 2020-05-08 14:29
- */
- @Getter
- public enum OrderStatusEnums {
-
- NEW(0,"新订单"),
- FINISH(1,"订单已完结"),
- CANCLE(2,"订单已取消"),
- ;
-
-
- private Integer code;
- private String message;
-
- OrderStatusEnums(Integer code, String message) {
- this.code = code;
- this.message = message;
- }
- }
- package com.fjz.vxsell.enums;
-
- import lombok.Getter;
-
- /**
- * @author 冯师兄
- * @date 2020-05-08 14:36
- */
- @Getter
- public enum PayStatusEnums {
- WAIT(0,"等待支付"),
- SUCCESS(1,"支付成功"),
- ;
-
- private Integer code;
- private String message;
-
- PayStatusEnums(Integer code, String message) {
- this.code = code;
- this.message = message;
- }
- }
- package com.fjz.vxsell.bean;
-
- import lombok.Data;
- import org.hibernate.annotations.DynamicUpdate;
-
- import javax.persistence.Entity;
- import javax.persistence.Id;
- import java.math.BigDecimal;
- import java.security.PrivateKey;
- import java.util.Date;
-
- /**
- * 订单详情表
- * @author 冯师兄
- * @date 2020-05-08 14:44
- */
- @Entity
- @Data
- @DynamicUpdate
- public class OrderDetail {
-
- /*订单详情id*/
- @Id
- private String detailId;
-
- /*订单id*/
- private String orderId;
-
- /*商品id*/
- private String productId;
-
- /*商品名称*/
- private String productName;
-
- /*商品价格*/
- private BigDecimal productPrice;
-
- /*商品数量*/
- private Integer productQuantity;
-
- /*商品图片*/
- private String productIcon;
-
-
-
- }
- package com.fjz.vxsell.repository;
-
- import com.fjz.vxsell.bean.OrderMaster;
- import org.springframework.data.domain.Page;
- import org.springframework.data.domain.Pageable;
- import org.springframework.data.jpa.repository.JpaRepository;
-
- /**
- * @author 冯师兄
- * @date 2020-05-08 14:59
- */
- public interface OrderMasterRepository extends JpaRepository<OrderMaster,String> {
-
- /**
- * 分页查询
- * 根据买家的openid查询
- * @param buyerOpenid
- * @param pageable
- * @return
- */
- Page<OrderMaster> findByBuyerOpenid(String buyerOpenid, Pageable pageable);
- }
- package com.fjz.vxsell.repository;
-
- import com.fjz.vxsell.bean.OrderMaster;
- import org.junit.Assert;
- 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.data.domain.Page;
- import org.springframework.data.domain.PageRequest;
- import org.springframework.test.context.junit4.SpringRunner;
-
- import java.math.BigDecimal;
-
- import static org.junit.Assert.*;
-
- @RunWith(SpringRunner.class)
- @SpringBootTest
- public class OrderMasterRepositoryTest {
-
- @Autowired
- private OrderMasterRepository orderMasterRepository;
-
- private final String Openid = "123456";
-
- /**
- * 测试保存
- */
- @Test
- public void saveTest() {
- OrderMaster orderMaster = new OrderMaster();
- orderMaster.setOrderId("004");
- orderMaster.setBuyerName("十三师兄");
- orderMaster.setBuyerPhone("15916574437");
- orderMaster.setBuyerAddress("北京房山");
- orderMaster.setBuyerOpenid(Openid);
- orderMaster.setOrderAmount(new BigDecimal(255.63));
-
- OrderMaster result = orderMasterRepository.save(orderMaster);
- Assert.assertNotNull(result);
-
- }
-
- /**
- * 分页查询
- */
- @Test
- public void findByBuyerOpenid() {
- PageRequest request = new PageRequest(0,2);
- Page<OrderMaster> page = orderMasterRepository.findByBuyerOpenid(Openid, request);
- System.out.println(page.getTotalElements());
- Assert.assertNotEquals(0, page.getTotalPages());
- }
- }
- package com.fjz.vxsell.repository;
-
- import com.fjz.vxsell.bean.OrderDetail;
- import org.springframework.data.jpa.repository.JpaRepository;
-
- import java.util.List;
-
- /**
- * @author 冯师兄
- * @date 2020-05-08 15:02
- */
- public interface OrderDetailRepository extends JpaRepository<OrderDetail, String> {
-
- /**
- * 根据orderID查询出所有的订单详情
- * @param orderId
- * @return
- */
- List<OrderDetail> findByOrderId(String orderId);
- }
- package com.fjz.vxsell.repository;
-
- import com.fjz.vxsell.bean.OrderDetail;
- import org.junit.Assert;
- 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 java.math.BigDecimal;
- import java.util.List;
-
- import static org.junit.Assert.*;
-
- @RunWith(SpringRunner.class)
- @SpringBootTest
- public class OrderDetailRepositoryTest {
-
- @Autowired
- private OrderDetailRepository orderDetailRepository;
-
- @Test
- public void saveTest(){
- OrderDetail orderDetail = new OrderDetail();
- orderDetail.setDetailId("000002");
- orderDetail.setOrderId("111111");
- orderDetail.setProductId("010101");
- orderDetail.setProductIcon("http://xxxx.jpg");
- orderDetail.setProductName("华为");
- orderDetail.setProductPrice(new BigDecimal(35.3));
- orderDetail.setProductQuantity(50);
-
- OrderDetail result = orderDetailRepository.save(orderDetail);
- Assert.assertNotNull(result);
- }
-
- @Test
- public void findByOrderId() {
- List<OrderDetail> list = orderDetailRepository.findByOrderId("111111");
- Assert.assertNotEquals(0, list.size());
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。