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.UserCollection;
import com.izouma.awesomeadmin.service.UserCollectionService;
import com.izouma.awesomeadmin.dao.UserCollectionMapper;

/**
*  service接口实现类
*/
@Service
public class UserCollectionServiceImpl implements UserCollectionService{

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

    @Autowired
    private UserCollectionMapper userCollectionMapper;

    @Override
    public List<UserCollection> getUserCollectionList(UserCollection record) {

        logger.info("getUserCollectionList");
        try {

        return userCollectionMapper.queryAllUserCollection(record);
        } catch (Exception e) {
        logger.error("getUserCollectionList", e);
        }

        return null;
    }
    @Override
    public List<UserCollection> getUserCollectionByPage(Page page, UserCollection record) {

        logger.info("getUserCollectionByPage");
        try {

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

        return userCollectionMapper.queryUserCollectionByPage(parameter);
        } catch (Exception e) {
        logger.error("getUserCollectionByPage", e);
        }

        return null;
    }

    @Override
    public UserCollection getUserCollectionById(String id) {

        logger.info("getUserCollectionyId");
        try {

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

        return null;
    }

    @Override
    public UserCollection getUserCollection(UserCollection record) {

        logger.info("getUserCollection");
        try {

            return userCollectionMapper.queryUserCollection(record);
        } catch (Exception e) {
        logger.error("getUserCollection", e);
        }

        return null;
    }

    @Override
    public boolean createUserCollection(UserCollection record) {

        logger.info("createUserCollection");
        try {

            int updates = userCollectionMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteUserCollection(String id) {

        logger.info("deleteUserCollection");
        try {

             int updates = userCollectionMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateUserCollection(UserCollection record) {

        logger.info("updateUserCollection");
        try {

            int updates = userCollectionMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

