package com.izouma.awesomeadmin.service.impl;

#foreach($import in $imports)
$import
#end
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.${model.className};
import com.izouma.awesomeadmin.service.${model.className}Service;
import com.izouma.awesomeadmin.dao.${model.className}Mapper;

/**
*  service接口实现类
*/
@Service
public class ${model.className}ServiceImpl implements ${model.className}Service{

    private static Logger logger = Logger.getLogger(${model.className}ServiceImpl.class);

    @Autowired
    private ${model.className}Mapper ${display.uncapitalize(${model.className})}Mapper;

    @Override
    public List<${model.className}> get${model.className}List(${model.className} record) {

        logger.info("get${model.className}List");
        try {

        return ${display.uncapitalize(${model.className})}Mapper.queryAll${model.className}(record);
        } catch (Exception e) {
        logger.error("get${model.className}List", e);
        }

        return null;
    }
    @Override
    public List<${model.className}> get${model.className}ByPage(Page page, ${model.className} record) {

        logger.info("get${model.className}ByPage");
        try {

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

        return ${display.uncapitalize(${model.className})}Mapper.query${model.className}ByPage(parameter);
        } catch (Exception e) {
        logger.error("get${model.className}ByPage", e);
        }

        return null;
    }

    @Override
    public ${model.className} get${model.className}ById(String id) {

        logger.info("get${model.className}yId");
        try {

            return ${display.uncapitalize(${model.className})}Mapper.selectByPrimaryKey(Integer.valueOf(id));
        } catch (Exception e) {
        logger.error("get${model.className}ById", e);
        }

        return null;
    }

    @Override
    public ${model.className} get${model.className}(${model.className} record) {

        logger.info("get${model.className}");
        try {

            return ${display.uncapitalize(${model.className})}Mapper.query${model.className}(record);
        } catch (Exception e) {
        logger.error("get${model.className}", e);
        }

        return null;
    }

    @Override
    public boolean create${model.className}(${model.className} record) {

        logger.info("create${model.className}");
        try {

            int updates = ${display.uncapitalize(${model.className})}Mapper.insertSelective(record);

            if (updates > 0) {
                 return true;
            }
        } catch (Exception e) {
            logger.error("create${model.className}", e);
        }

        return false;
    }

    @Override
    public boolean delete${model.className}(${model.className} record) {

        logger.info("delete${model.className}");
        try {

             int updates = ${display.uncapitalize(${model.className})}Mapper.delete(record);

            if (updates > 0) {
                 return true;
            }
        } catch (Exception e) {
             logger.error("delete${model.className}", e);
        }

        return false;
    }

    @Override
    public boolean update${model.className}(${model.className} record) {

        logger.info("update${model.className}");
        try {

            int updates = ${display.uncapitalize(${model.className})}Mapper.updateByPrimaryKeySelective(record);

            if (updates > 0) {
                 return true;
            }
        } catch (Exception e) {
             logger.error("update${model.className}", e);
        }

        return false;
    }
}

