package com.iformall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.WxCarCmdLog;
import com.iformall.mapper.WxCarCmdLogMapper;
import com.iformall.service.WxCarCmdLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iformall.common.IdWorker;

import java.util.HashMap;
import java.util.List;

@Service
public class WxCarCmdLogServiceImpl implements WxCarCmdLogService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
    WxCarCmdLogMapper wxCarCmdLogMapper;


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

    @Override
    public WxCarCmdLog getById(Long id) {
        return wxCarCmdLogMapper.selectById(id);
    }

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

    @Override
    public void deleteById(Long id) {
        wxCarCmdLogMapper.deleteById(id);
    }
    
    
    @Override
    public String getTenantIdBySynId(HashMap<String,String> params) {
        // 同一辆车，一天内可能多次入场
        List<String> list = wxCarCmdLogMapper.queryTenantIdBySynId(params);
        if(list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public WxCarCmdLog getByOrderId(HashMap<String, String> params) {
        return wxCarCmdLogMapper.queryByOrderId(params);
    }

    @Override
    public WxCarCmdLog getBySynId(HashMap<String, Object> params) {
        return wxCarCmdLogMapper.queryBySynId(params);
    }

    
    
    
    
    
}
