package com.dxhy.jxpt.baseService.sign.service.singletable.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.service.impl.MpBaseServiceImpl;
import com.dxhy.jxpt.baseService.sign.dao.SignVehicleSaleInvoiceDao;
import com.dxhy.api.model.sign.TDxVehicleSaleInvoice;
import com.dxhy.jxpt.baseService.sign.service.singletable.SignJdcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * 机动车明细表业务操作实现
 *
 * @author ld
 */
@Service("signJdcService")
@Slf4j

public class SignJdcServiceImpl extends MpBaseServiceImpl<SignVehicleSaleInvoiceDao, TDxVehicleSaleInvoice>
    implements SignJdcService {

    @Override
    public boolean deleteVehicleSaleInvoice(String uuid, String dbName) {
        DynamicContextHolder.push(dbName + DbConstant.BUSINESS_WRITE);
        return this.removeVechicleSale(uuid);
    }

    @Transactional(rollbackFor = Exception.class)
    public boolean removeVechicleSale(String uuid) {
        // 删除已存在的数据，防止数据重复
        try {
            baseMapper.delete(new QueryWrapper<TDxVehicleSaleInvoice>().eq("uuid", uuid));
            return true;
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
            return false;
        }
    }

    @Override
    public void saveVehicleSaleInvoice(TDxVehicleSaleInvoice tDxVehicleSaleInvoice, String dbName) {
        DynamicContextHolder.push(dbName + DbConstant.BUSINESS_WRITE);
        this.insertInvoice(tDxVehicleSaleInvoice);

    }

    @Transactional(rollbackFor = Exception.class)
    public void insertInvoice(TDxVehicleSaleInvoice tDxVehicleSaleInvoice) {
        baseMapper.insert(tDxVehicleSaleInvoice);
    }
}
