package com.iformall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.common.IdWorker;
import com.iformall.domain.po.ThDevInfo;
import com.iformall.mapper.ThDevInfoMapper;
import com.iformall.service.ThDevInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ThDevInfoServiceImpl implements ThDevInfoService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
    ThDevInfoMapper thDevInfoMapper;


    @Override
    public PageInfo<ThDevInfo> listAsPage(ThDevInfo record, Integer pageIndex, Integer pageSize) {
        return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> thDevInfoMapper.findList(record));
    }

    @Override
    public ThDevInfo getById(Long id) {
        return thDevInfoMapper.selectById(id);
    }

    @Override
    public ThDevInfo getByDevId(String devId) {
        ThDevInfo q = new ThDevInfo();
        q.setDevId(devId);
        try {
            return thDevInfoMapper.selectOne(new QueryWrapper(q));
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return null;
    }

    @Override
    public void saveOrUpdate(ThDevInfo record) {
        if (record.getId() == null) {
            //record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            final IdWorker idWorker = IdWorker.get();
        	record.setId(idWorker.nextId());
            thDevInfoMapper.insert(record);
        } else {
            thDevInfoMapper.updateById(record);
        }
    }

    @Override
    public void deleteById(Long id) {
        thDevInfoMapper.deleteById(id);
    }
    
    
    
    
    
    
    
    
}
