package com.happy.service.impl;

import com.happy.Model.Booking;
import com.happy.Model.BookingLog;
import com.happy.Until.DateUtil;
import com.happy.Until.Enum.OrderEnum;
import com.happy.Until.Enum.PayEnum;
import com.happy.Until.Func;
import com.happy.dao.BookingLogDao;
import com.happy.dto.BookTypeEto;
import com.happy.dto.IPage;
import com.happy.service.AdminManagerService;
import com.happy.service.BookinglogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service("BookinglogService")
public class BookinglogImplService implements BookinglogService {

    @Resource
    public BookingLogDao bookingLogDao;
    @Resource
    public AdminManagerService adminManagerService;

    @Override
    public int insertBookinglog(BookingLog book) {
        return bookingLogDao.insert(book);
    }

    @Override
    public BookingLog addBooklog(String operate, Booking booking) {
        // 生成订单时，写入数据操作
        BookingLog info = new BookingLog();
        info.setBookingId(Func.parseStr(booking.getId()));
        info.setBookingStatus(PayEnum.getValueBykey(Func.parseInt(booking.getOrderStatus())));
        info.setOperate(operate);
        info.setOperateId(booking.getCreateUserid());
        info.setOperateName(booking.getUserName());
        info.setOperateTime(DateUtil.parseDateToStr(new Date(), DateUtil.Time_Formatter_Second));
        insertBookinglog(info);
        return info;
    }

    @Override
    public int updateBookinglog(BookingLog book) {
        return bookingLogDao.update(book);
    }

    @Override
    public int insertBooking(BookingLog book) {
        return 0;
    }

    @Override
    public int delBookinglog(int id) {
        return bookingLogDao.del(id);
    }

    @Override
    public BookingLog getById(String id) {
        return bookingLogDao.queryById(id);
    }

    @Override
    public IPage<BookingLog> queryPage(String sqlx, int page, int rows) {
        return null;
    }

    @Override
    public List<BookingLog> queryList(String sqlx) {
        return bookingLogDao.queryByBookingId(sqlx);
    }


    @Override
    public String delBooking(String id) {
        if (Func.checkNull(id))
            return "未传入订单id";

        bookingLogDao.del(Func.parseInt(id));
        return null;
    }

}
