package co.dc.aptiv.service;

import co.dc.aptiv.pojo.ConfigPojo;
import co.dc.commons.basedao.CommonBaseDao;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * @describe: 配置类业务层
 * @author: 刘兴龙
 * @version: 2019/1/3 10:04
 */
@Service("configService")
public class ConfigService {
    private static final Log log = LogFactory.getLog (ConfigService.class);

    @Resource(name = "commonBaseDao")
    private CommonBaseDao baseDao;

    @Resource
    private QueryRunner queryRunner;

    /**
     * 更新基础信息
     *
     * @param pojo
     */
    public void updateConfig (ConfigPojo pojo) {
        ConfigPojo configPojo = baseDao.findById (ConfigPojo.class, 1);
        if (!StringUtils.isEmpty (pojo.getLastName ())) {
            configPojo.setLastName (pojo.getLastName ());
        }
        if (pojo.getOnLine () != null && !configPojo.getOnLine ().equals (pojo.getOnLine ())) {
            configPojo.setOnLine (pojo.getOnLine ());
        }
        baseDao.update (configPojo);
        log.info ("更新配置类信息" + pojo.toString ());
    }

    /**
     * 根据id取配置信息
     *
     * @param id
     * @return
     */
    public ConfigPojo get (Long id) {
        return baseDao.findById (ConfigPojo.class, id);
    }
}
