美文网首页
买家订单DAO

买家订单DAO

作者: 谢谢水果 | 来源:发表于2018-11-19 08:15 被阅读0次

    买家订单主表 实体类

    main--dataobject--OrderMaster.java

    package com.tkft.sell.dataobject;
    
    import com.tkft.sell.enums.OrderStatusEnum;
    import com.tkft.sell.enums.PayStatusEnum;
    import lombok.Data;
    import org.hibernate.annotations.DynamicUpdate;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import java.math.BigDecimal;
    import java.util.Date;
    
    /**
     * @Auther xinyuan
     * @Date 11/18/18 3:41 PM
     **/
    @Entity
    @Data
    @DynamicUpdate
    public class OrderMaster {
        @Id
        private String orderId;
    
        private String buyerName;
    
        private String buyerPhone;
    
        private String buyerAddress;
    
        private String buyerOpenid;
    
        private BigDecimal orderAmount;
    
        //订单状态 默认为0 新订单
        private Integer orderStatus = OrderStatusEnum.NEW.getCode();
    
        //支付状态 默认为0 未支付
        private Integer payStatus = PayStatusEnum.WAIT.getCode();
    
        private Date createTime;
    
        private Date updateTime;
    
    }
    

    买家订单详情 实体类

    main--dataobject--OrderDetail.java

    package com.tkft.sell.dataobject;
    
    import lombok.Data;
    import org.hibernate.annotations.DynamicUpdate;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import java.math.BigDecimal;
    import java.util.Date;
    
    /**
     * @Auther xinyuan
     * @Date 11/18/18 4:03 PM
     **/
    @Entity
    @Data
    @DynamicUpdate
    public class OrderDetail {
        @Id
        private String detailId;
    
        private String orderId;
    
        private String productId;
    
        private String productName;
    
        private BigDecimal productPrice;
    
        private Integer productQuantity;
    
        private String productIcon;
    
    //    private Date createTime;
    //
    //    private Date updateTime;
    }
    

    买家订单主表 DAO

    main--repository--OrderMasterRepository.java

    package com.tkft.sell.repository;
    
    import com.tkft.sell.dataobject.OrderMaster;
    import org.springframework.data.domain.Page;
    import org.springframework.data.domain.Pageable;
    import org.springframework.data.jpa.repository.JpaRepository;
    
    /**
     * @Auther xinyuan
     * @Date 11/18/18 4:09 PM
     **/
    public interface OrderMasterRepository extends JpaRepository<OrderMaster, String> {
        Page<OrderMaster> findByBuyerOpenId(String buyerOpenId, Pageable pageable);
    }
    

    买家订单详情 DAO

    main--repository--OrderDetailRepository.java

    package com.tkft.sell.repository;
    
    import com.tkft.sell.dataobject.OrderDetail;
    import org.springframework.data.jpa.repository.JpaRepository;
    import java.util.List;
    
    /**
     * @Auther xinyuan
     * @Date 11/18/18 4:12 PM
     **/
    public interface OrderDetailRepository extends JpaRepository<OrderDetail, String> {
        List<OrderDetail> findByOrderId(String orderId);
    }
    

    买家订单主表测试

    package com.tkft.sell.repository;
    
    import com.tkft.sell.dataobject.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 = "000";
    
        @Test
        public void saveTest(){
            OrderMaster orderMaster = new OrderMaster();
            orderMaster.setBuyerAddress("Aurora Ct");
            orderMaster.setBuyerName("Xinyuan");
            orderMaster.setBuyerOpenid(OPENID);
            orderMaster.setBuyerPhone("150101");
            orderMaster.setOrderId("002");
            orderMaster.setOrderAmount(new BigDecimal(35));
            OrderMaster result = orderMasterRepository.save(orderMaster);
            Assert.assertNotNull(result);
        }
        @Test
        public void findByBuyerOpenId() {
            PageRequest request = new PageRequest(0,2);
            Page<OrderMaster> result = orderMasterRepository.findByBuyerOpenid(OPENID, request);
            Assert.assertNotEquals(0, result.getTotalElements());
        }
    }
    

    买家订单详情测试

    package com.tkft.sell.repository;
    
    import com.tkft.sell.dataobject.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 repository;
    
        @Test
        public void saveTest(){
            OrderDetail orderDetail = new OrderDetail();
            orderDetail.setDetailId("002");
            orderDetail.setOrderId("002");
            orderDetail.setProductIcon("www.apple.com");
            orderDetail.setProductId("123456");
            orderDetail.setProductName("apple");
            orderDetail.setProductPrice(new BigDecimal(3.5));
            orderDetail.setProductQuantity(10);
            OrderDetail result = repository.save(orderDetail);
            Assert.assertNotNull(result);
        }
        @Test
        public void findByOrderId() {
            List<OrderDetail> result = repository.findByOrderId("002");
            Assert.assertNotEquals(0, result.size());
        }
    }
    

    相关文章

      网友评论

          本文标题:买家订单DAO

          本文链接:https://www.haomeiwen.com/subject/lsanfqtx.html