package com.dxhy.sign.service.elec.impl;

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

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.service.impl.MpBaseServiceImpl;
import com.dxhy.sign.dao.SignInvoiceDao;
import com.dxhy.sign.entity.TDxInvoice;
import com.dxhy.sign.model.QsInvoiceCount;
import com.dxhy.sign.service.elec.SignInvoiceScanService;

import lombok.extern.slf4j.Slf4j;

/**
 * @author peipei.li
 * @date 2019-05-09 发票扫描相关service
 */
@Service("signInvoiceScan")
@Slf4j

public class SignInvoiceScanImpl extends MpBaseServiceImpl<SignInvoiceDao, TDxInvoice>
    implements SignInvoiceScanService {

    /**
     * 根据uuid查询记录
     *
     * @param uuid
     *            uuid
     * @return 返回结果
     */
    @Override
    public TDxInvoice queryByUuid(String uuid, String dbName) {
        DynamicContextHolder.push(dbName + DbConstant.BUSINESS_READ);
        QueryWrapper<TDxInvoice> scannWrapper = new QueryWrapper<>();
        scannWrapper.lambda().eq(TDxInvoice::getUuid, uuid);
        return super.baseMapper.selectOne(scannWrapper);
    }

    /**
     * 发票扫描记录
     *
     * @param scannInvoice
     *            请求参数
     */
    @Override
    public void insertOrUpdate(TDxInvoice scannInvoice) {
        super.saveOrUpdate(scannInvoice);
    }

    /**
     * 根据uuid更新发票扫描表数据
     *
     * @param scannInvoice
     *            请求参数
     */
    @Override
    public void updateByUuid(TDxInvoice scannInvoice) {
        UpdateWrapper<TDxInvoice> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(TDxInvoice::getUuid, scannInvoice.getUuid());
        super.baseMapper.update(scannInvoice, updateWrapper);
    }

    /**
     * 电票查询 分页
     *
     * @param pramsMap
     *            请求参数
     * @return 返回结果
     */
    @Override
    public List<TDxInvoice> listElecInvoice(Map<String, Object> pramsMap) {
        return baseMapper.selectElecInvoice(pramsMap);
    }

    @Override
    public QsInvoiceCount selectListCount(Map<String, Object> pramsMap) {
        return baseMapper.selectElecInvoiceCount(pramsMap);
    }

    @Override
    public TDxInvoice queryByScanId(String ScanId, String dbName) {
        DynamicContextHolder.push(dbName + DbConstant.BUSINESS_READ);
        QueryWrapper<TDxInvoice> scannWrapper = new QueryWrapper<>();
        scannWrapper.eq("scan_id", ScanId);
        return super.baseMapper.selectOne(scannWrapper);
    }
}
