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

import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.jeelowcode.core.framework.entity.ExcelFileDataEntity;
import com.jeelowcode.core.framework.entity.ExcelFileEntity;
import com.jeelowcode.core.framework.mapper.ExcelFileDataMapper;
import com.jeelowcode.core.framework.service.IExcelFileDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jeelowcode.core.framework.service.IExcelFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * ExcelData相关
 */
@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);

    }


}
