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.OfflinePaymentsDao;
import com.pine.admin.modules.business.entity.OfflinePayments;
import com.pine.admin.modules.business.service.OfflinePaymentsService;


@Service("offlinePaymentsService")
@Slf4j
public class OfflinePaymentsServiceImpl implements OfflinePaymentsService {

    @Autowired
    private OfflinePaymentsDao offlinePaymentsDao;


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

        log.info("getOfflinePaymentsList");
        try {

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

        return null;
    }

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

        log.info("getOfflinePaymentsByPage");
        try {

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

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

        return null;
    }

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

        log.info("getOfflinePaymentsById");
        try {

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

        return null;
    }

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

        log.info("getOfflinePayments");
        try {

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

        return null;
    }

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

        log.info("createOfflinePayments");
        try {

            int updates = offlinePaymentsDao.insertSelective(record);

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

        return false;
    }

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

        log.info("deleteOfflinePayments");
        try {

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

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

        return false;
    }

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

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

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

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

        return false;
    }

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

        log.info("updateOfflinePayments");
        try {

            int updates = offlinePaymentsDao.updateByPrimaryKeySelective(record);

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

        return false;
    }

}
