
package com.lideeyunji.core.framework.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.lideeyunji.core.framework.entity.ExcelFileDataEntity;
import com.lideeyunji.core.framework.entity.ExcelFileEntity;
import com.lideeyunji.core.framework.mapper.ExcelFileDataMapper;
import com.lideeyunji.core.framework.service.IExcelFileDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lideeyunji.core.framework.service.IExcelFileService;
import com.lideeyunji.tool.framework.common.constant.lideeYunJiBaseConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * ExcelData相关
 */
@DS(lideeYunJiBaseConstant.DS_lideeyunji)
@Service
public class ExcelFileDataServiceImpl extends ServiceImpl<ExcelFileDataMapper, ExcelFileDataEntity> implements IExcelFileDataService {

    @Autowired
    private IExcelFileService fileService;

    //删除
    @DSTransactional(rollbackFor = Exception.class)
    @Override
    public void delById(Long fileDataId){
        ExcelFileDataEntity fileDataEntity = baseMapper.selectById(fileDataId);
        ExcelFileEntity excelFileEntity = fileService.getById(fileDataEntity.getExcelFileId());

        //总数-1
        Integer totalNum = excelFileEntity.getTotalNum();
        ExcelFileEntity updateTotal=new ExcelFileEntity();
        updateTotal.setTotalNum(--totalNum);
        updateTotal.setId(excelFileEntity.getId());
        fileService.updateById(updateTotal);


        //删除本条记录
        baseMapper.deleteById(fileDataId);

    }


}
