package com.thinkgem.jeesite.modules.pay.service;


import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.DateUtils;
import com.thinkgem.jeesite.modules.pay.bean.OrderRequest;
import com.thinkgem.jeesite.modules.pay.dao.OrderApiDao;

import com.thinkgem.jeesite.modules.pay.entity.OrderEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author niehh
 * @Description: 订单
 * @date 2018年03月18日 10:51
 */
@Service
@Transactional(readOnly = true)
public class OrderService {

    @Autowired
    private OrderApiDao orderApiDao;

    /**
     * 订单列表
     * @param request
     * @return
     */
    public List<OrderEntity> getOrderList(OrderRequest request){
        if(request.getStartDate()!= null && request.getStartDate() != 0){
            request.setStartTime(DateUtils.formatDate(new Date(request.getStartDate()*1000),"yyyy-MM-dd") + " 00:00:00");
        }
        if(request.getEndDate() != null && request.getEndDate() != 0){
            request.setEndTime(DateUtils.formatDate(new Date(request.getEndDate()*1000),"yyyy-MM-dd") + " 23:59:59");
        }

        return orderApiDao.getOrderList(request);

    }



    /**
     * 订单列表
     * @param request
     * @return
     */
    public Page<OrderEntity> getOrderPage(OrderRequest<OrderEntity> request){

        Page<OrderEntity> page = new Page<>();
        page.setPageNo(request.getPageNum());
        page.setPageSize(request.getPageSize());
        request.setPage(page);
        if(request.getStartDate()!= null && request.getStartDate() != 0){
            request.setStartTime(DateUtils.formatDate(new Date(request.getStartDate()*1000),"yyyy-MM-dd") + " 00:00:00");
        }
        if(request.getEndDate() != null && request.getEndDate() != 0){
            request.setEndTime(DateUtils.formatDate(new Date(request.getEndDate()*1000),"yyyy-MM-dd") + " 23:59:59");
        }
        List<OrderEntity> list = orderApiDao.getOrderList(request);
        page.setList(list);
        page.setTotalPage(page.getLast());
        return page;
    }

}
