package com.pine.admin.modules.business.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import com.pine.common.dto.Page;
import org.springframework.transaction.annotation.Transactional;

import com.pine.admin.modules.business.dao.SysLogDao;
import com.pine.admin.modules.business.entity.SysLog;
import com.pine.admin.modules.business.service.SysLogService;


@Service("sysLogService")
@Slf4j
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogDao sysLogDao;


    @Override
    @Transactional
    public List<SysLog> getAllList(SysLog record) {

        log.info("getSysLogList");
        try {

            return sysLogDao.queryAll(record);
        } catch (Exception e) {
            log.error("getSysLogList", e);
        }

        return null;
    }

    @Override
    @Transactional
    public List<SysLog> getByPage(Page page, SysLog record) {

        log.info("getSysLogByPage");
        try {

            Map<String, Object> parameter = new HashMap<String, Object>();
            parameter.put("record", record);
            parameter.put("page", page);

            return sysLogDao.queryByPage(parameter);
        } catch (Exception e) {
            log.error("getSysLogByPage", e);
        }

        return null;
    }

    @Override
    @Transactional
    public SysLog getById(String id) {

        log.info("getSysLogById");
        try {

            return sysLogDao.selectByPrimaryKey(Integer.valueOf(id));
        } catch (Exception e) {
            log.error("getSysLogById", e);
        }

        return null;
    }

    @Override
    @Transactional
    public SysLog getOne(SysLog record) {

        log.info("getSysLog");
        try {

            return sysLogDao.queryOne(record);
        } catch (Exception e) {
            log.error("getSysLog", e);
        }

        return null;
    }

    @Override
    @Transactional
    public boolean create(SysLog record) {

        log.info("createSysLog");
        try {

            int updates = sysLogDao.insertSelective(record);

            if (updates > 0) {
                return true;
            }
        } catch (Exception e) {
            log.error("createSysLog", e);
        }

        return false;
    }

    @Override
    @Transactional
    public boolean delete(String id) {

        log.info("deleteSysLog");
        try {

            int updates = sysLogDao.delete(Integer.valueOf(id));

            if (updates > 0) {
                return true;
            }
        } catch (Exception e) {
            log.error("deleteSysLog", e);
        }

        return false;
    }

    @Override
    @Transactional
    public boolean deltetByIds(String ids) {

        log.info("deleteeSysLog byIDS");
        try {

            String[] id = ids.split(";");
            int updates = sysLogDao.deleteIds(id);

            if (id.length == updates) {
                return true;
            }
        } catch (Exception e) {
            log.error("deleteeSysLog byIDS", e);
        }

        return false;
    }

    @Override
    @Transactional
    public boolean update(SysLog record) {

        log.info("updateSysLog");
        try {

            int updates = sysLogDao.updateByPrimaryKeySelective(record);

            if (updates > 0) {
                return true;
            }
        } catch (Exception e) {
            log.error("updateSysLog", e);
        }

        return false;
    }

}
