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.ExecuteFailLogDAO;
import com.jpsoft.shinestar.modules.base.entity.ExecuteFailLog;
import com.jpsoft.shinestar.modules.base.service.ExecuteFailLogService;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * @author 墨鱼_mo
 * @date 2020-5-15 17:28
 */
@Transactional
@Component(value="executeFailLogService")
public class ExecuteFailLogServiceImpl implements ExecuteFailLogService {
    @Autowired
    private ExecuteFailLogDAO executeFailLogDAO;

    @Override
    public ExecuteFailLog get(String id) {
        // TODO Auto-generated method stub
        return executeFailLogDAO.get(id);
    }

    @Override
    public int insert(ExecuteFailLog model) {
        // TODO Auto-generated method stub
        //model.set${PkFieldName}(UUID.randomUUID().toString());
        ExecuteFailLog efl = executeFailLogDAO.findByPersonIdAndDeviceIdAndType(model.getPersonId(),model.getDeviceId(),model.getType());

        if(efl==null){
            return executeFailLogDAO.insert(model);
        }
        else{
            return 0;
        }
    }

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

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

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

        return count > 0 ? true : false;
    }

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

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

        return page;
    }

    @Override
    public List<ExecuteFailLog> findByDeviceNo(String deviceNo, int limit) {
        return executeFailLogDAO.findByDeviceNo(deviceNo,limit);
    }
}
