package com.jpsoft.shinestar.modules.base.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jpsoft.shinestar.modules.base.dao.OrderLogDAO;
import com.jpsoft.shinestar.modules.base.entity.OrderLog;
import com.jpsoft.shinestar.modules.base.service.OrderLogService;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * @author 墨鱼_mo
 * @date 2020-7-27 9:13
 */
@Transactional
@Component(value="orderLogService")
public class OrderLogServiceImpl implements OrderLogService {


    @Resource
    private OrderLogDAO orderLogDAO;

    @Override
    public OrderLog get(String id) {
        return orderLogDAO.get(id);
    }

    @Override
    public int insert(OrderLog model) {
        // TODO Auto-generated method stub
        //model.setId(UUID.randomUUID().toString());

        return orderLogDAO.insert(model);
    }

    @Override
    public int insert2(OrderLog model) {
        model.setId(UUID.randomUUID().toString());
        model.setCreateTime(new Date());
        model.setDelFlag(false);
        return orderLogDAO.insert(model);
    }

    @Override
    public int update(OrderLog model) {
        // TODO Auto-generated method stub
        return orderLogDAO.update(model);
    }

    @Override
    public int delete(String id) {
        // TODO Auto-generated method stub
        return orderLogDAO.delete(id);
    }

    @Override
    public boolean exist(String id) {
        // TODO Auto-generated method stub
        int count = orderLogDAO.exist(id);

        return count > 0 ? true : false;
    }

    @Override
    public List<OrderLog> list() {
        // TODO Auto-generated method stub
        return orderLogDAO.list();
    }

    @Override
    public List<OrderLog> findByOrderId(String orderId){
        return orderLogDAO.findByOrderId(orderId);
    }


    @Override
    public Page<OrderLog> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize, boolean count, List<Sort> sortList) {
        Page<OrderLog> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            orderLogDAO.search(searchParams,sortList);
        });

        return page;
    }
}
