package com.common.service.impl;


import com.common.entity.DmColumn;
import com.common.mapper.DmColumnMapper;
import com.common.mapper.DmNormalizeRuleMapper;
import com.common.service.DmColumnService;
import com.common.service.DmNormalizeRuleService;
import com.common.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class DmColumnServiceImpl implements DmColumnService {
    private static final Logger logger = LoggerFactory.getLogger(DmColumnServiceImpl.class);

    @Autowired
    private DmColumnMapper dmColumnMapper;

    @Override
    public List<DmColumn> findAll() {
        return dmColumnMapper.findAll();
    }

    @Override
    public DmColumn findById(Long id) {

        try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
            logger.info(" begin DmColumnServiceImpl->findById" );
            dmColumnMapper = sqlSession.getMapper(DmColumnMapper.class);
            return dmColumnMapper.findById(id);
        } catch (Exception e) {
            logger.error("DmColumnServiceImpl findById MyBatisUtil getSqlSession 异常", e);
        }
        logger.error("DmColumn  is null" );
        return null;


    }
    @Override
    public DmColumn findByDmColumnId(Long id) {
        return dmColumnMapper.findById(id);
    }
    @Override
    public DmColumn findByName(String name) {
        return dmColumnMapper.findByName(name);
    }

    @Override
    public List<DmColumn> findByDisplayName(String displayName) {
        return dmColumnMapper.findByDisplayName(displayName);
    }

    @Override
    public List<DmColumn> findByIsBuiltIn(Boolean isBuiltIn) {
        return dmColumnMapper.findByIsBuiltIn(isBuiltIn);
    }

    @Override
    //@Transactional
    public int insert(DmColumn dmColumn) {
        return dmColumnMapper.insert(dmColumn);
    }

    @Override
    //@Transactional
    public int batchInsert(List<DmColumn> dmColumns) {
        return dmColumnMapper.batchInsert(dmColumns);
    }

    @Override
    public List<DmColumn> findByCondition(DmColumn condition) {
        return dmColumnMapper.findByCondition(condition);
    }

    @Override
    public Long count() {
        return dmColumnMapper.count();
    }

    @Override
    public List<Map<String, Object>> selectAllNormal()
    {
        return dmColumnMapper.selectAllNormal();
    }

}