package com.steerinfo.ems.usagedataconfig.service.impl;

import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.ems.usagedataconfig.model.UsageDataConfig;

import java.util.Date;
import java.util.List;

import com.steerinfo.ems.usagedataconfig.mapper.UsageDataConfigMapper;
import com.steerinfo.ems.usagedataconfig.service.IUsageDataConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * UsageDataConfig服务实现：
 * @author generator
 * @version 1.0-SNAPSHORT 2019-11-06 11:10
 * 类描述
 * 修订历史：
 * 日期：2019-11-06
 * 作者：generator
 * 参考：
 * 描述：UsageDataConfig服务实现
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@Service(value = "usageDataConfigService")
public class UsageDataConfigServiceImpl extends BaseServiceImpl<UsageDataConfig, Short> implements IUsageDataConfigService {
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	
    @Autowired
    private UsageDataConfigMapper usageDataConfigMapper;

    @Override
    protected IBaseMapper<UsageDataConfig, Short> getMapper() {
        return usageDataConfigMapper;
    }
    
    @Override
    public UsageDataConfig add(UsageDataConfig model) {
    	Short maxId = jdbcTemplate.queryForObject(String.format("SELECT MAX(ID) FROM USAGE_DATA_CONFIG"), Short.class);
    	Short newId = (short) (maxId + 1);
    	model.setId(newId);
    	
    	if(model.getCt() == null) {
        	model.setCt(new Date());
        }
    	
    	usageDataConfigMapper.insert(model);
    	
    	return model;
    }

    public List<UsageDataConfig> getIdAndNote() {
        return usageDataConfigMapper.getIdAndNote();
    }

    public List<UsageDataConfig> getAutoData() {
        return usageDataConfigMapper.getAutoData();
    }
}
