package com.izouma.awesomeadmin.service.impl;

import java.util.*;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.izouma.awesomeadmin.constant.AppConstant;
import com.izouma.awesomeadmin.dto.Page;
import com.izouma.awesomeadmin.model.StoreInfo;
import com.izouma.awesomeadmin.service.StoreInfoService;
import com.izouma.awesomeadmin.dao.StoreInfoMapper;

/**
 * service接口实现类
 */
@Service
public class StoreInfoServiceImpl implements StoreInfoService {

    private static Logger logger = Logger.getLogger(StoreInfoServiceImpl.class);

    @Autowired
    private StoreInfoMapper storeInfoMapper;

    @Override
    public List<StoreInfo> getStoreInfoList(StoreInfo record) {

        logger.info("getStoreInfoList");
        try {

            return storeInfoMapper.queryAllStoreInfo(record);
        } catch (Exception e) {
            logger.error("getStoreInfoList", e);
        }

        return null;
    }

    @Override
    public List<StoreInfo> getStoreInfoListForHome(StoreInfo record) {

        logger.info("getStoreInfoListForHome");
        try {

            return storeInfoMapper.queryAllStoreInfoForHome(record);
        } catch (Exception e) {
            logger.error("getStoreInfoListForHome", e);
        }

        return null;
    }

    @Override
    public List<StoreInfo> getStoreInfoByPage(Page page, StoreInfo record) {

        logger.info("getStoreInfoByPage");
        try {

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

            return storeInfoMapper.queryStoreInfoByPage(parameter);
        } catch (Exception e) {
            logger.error("getStoreInfoByPage", e);
        }

        return null;
    }

    @Override
    public StoreInfo getStoreInfoById(String id) {

        logger.info("getStoreInfoyId");
        try {

            return storeInfoMapper.selectByPrimaryKey(Integer.valueOf(id));
        } catch (Exception e) {
            logger.error("getStoreInfoById", e);
        }

        return null;
    }

    @Override
    public StoreInfo getStoreInfo(StoreInfo record) {

        logger.info("getStoreInfo");
        try {

            return storeInfoMapper.queryStoreInfo(record);
        } catch (Exception e) {
            logger.error("getStoreInfo", e);
        }

        return null;
    }

    @Override
    public boolean createStoreInfo(StoreInfo record) {

        logger.info("createStoreInfo");
        try {

            int updates = storeInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteStoreInfo(String id) {

        logger.info("deleteStoreInfo");
        try {

            int updates = storeInfoMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateStoreInfo(StoreInfo record) {

        logger.info("updateStoreInfo");
        try {

            int updates = storeInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

