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.CreditRating;
import com.izouma.awesomeadmin.service.CreditRatingService;
import com.izouma.awesomeadmin.dao.CreditRatingMapper;

/**
*  service接口实现类
*/
@Service
public class CreditRatingServiceImpl implements CreditRatingService{

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

    @Autowired
    private CreditRatingMapper creditRatingMapper;

    @Override
    public List<CreditRating> getCreditRatingList(CreditRating record) {

        logger.info("getCreditRatingList");
        try {

        return creditRatingMapper.queryAllCreditRating(record);
        } catch (Exception e) {
        logger.error("getCreditRatingList", e);
        }

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

        logger.info("getCreditRatingByPage");
        try {

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

        return creditRatingMapper.queryCreditRatingByPage(parameter);
        } catch (Exception e) {
        logger.error("getCreditRatingByPage", e);
        }

        return null;
    }

    @Override
    public CreditRating getCreditRatingById(String id) {

        logger.info("getCreditRatingyId");
        try {

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

        return null;
    }

    @Override
    public CreditRating getCreditRating(CreditRating record) {

        logger.info("getCreditRating");
        try {

            return creditRatingMapper.queryCreditRating(record);
        } catch (Exception e) {
        logger.error("getCreditRating", e);
        }

        return null;
    }

    @Override
    public boolean createCreditRating(CreditRating record) {

        logger.info("createCreditRating");
        try {

            int updates = creditRatingMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteCreditRating(CreditRating record) {

        logger.info("deleteCreditRating");
        try {

             int updates = creditRatingMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateCreditRating(CreditRating record) {

        logger.info("updateCreditRating");
        try {

            int updates = creditRatingMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

