package cn.ezhizao.project.business.recycleBin.service.impl;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;

import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.project.business.company.domain.BizCompany;
import cn.ezhizao.project.business.company.mapper.BizCompanyMapper;
import cn.ezhizao.project.business.recycleBin.controller.BizRecycleBinController;
import cn.ezhizao.project.business.recycleBin.domain.BizRecycleBin;
import cn.ezhizao.project.business.recycleBin.mapper.BizRecycleBinMapper;
import cn.ezhizao.project.business.recycleBin.service.IBizRecycleBinService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.Getter;
import org.springframework.stereotype.Service;


/**
 * 回收站Service业务层处理
 *
 * @author ruoyi
 * @date 2023-11-02
 */
@Service
public class BizRecycleBinServiceImpl  extends ServiceImpl<BizRecycleBinMapper, BizRecycleBin> implements IBizRecycleBinService
{
    @Resource
    private BizRecycleBinMapper bizRecycleBinMapper;

    @Resource
    private BizCompanyMapper bizCompanyMapper;

    private BizRecycleBinController bizController=new BizRecycleBinController();



    BaseController bcl=new BaseController();
    /**
     * 查询回收站列表
     *
     * @param bizRecycleBin 回收站
     * @return 回收站
     */
    @Override
    public List<BizRecycleBin> getList(BizRecycleBin bizRecycleBin)
    {
        return bizRecycleBinMapper.getList(bizRecycleBin);
    }

    /**
     * 物理删除
     * @param bizRecycleBin
     * @return 删除结果
     */
    @Override
    public int physicalDelete(BizRecycleBin bizRecycleBin){ return bizRecycleBinMapper.physicalDelete(bizRecycleBin); };

    /**
     * 还原
     * @return
     */
    @Override
    public int restore(List<Long> ids){
        String [] tabs= bizController.getTabs();
        for (Long id:ids) {
            //回收站数据还原
            bizRecycleBinMapper.restore(id);
            //获取要还原的数据
            BizRecycleBin bin=bizRecycleBinMapper.getById(id);
            //还原用户表数据
            bizRecycleBinMapper.restoreCompany(bin.getSourceId());
            //还原子表数据
            bizRecycleBinMapper.restoreData(bin.getSourceId(),tabs);

//            for (String tab:tabs) {
//            }

        }
        return 1;
    }

    /**
     * 删除
     * @return
     */
    @Override
    public int remove(List<Long> ids){
        for (Long id: ids) {
            bizRecycleBinMapper.remove(id);
        }
        return 1;
    }

    /**
     * 删除客户关联的子表数据
     * @return
     */
    @Override
    public void deleteData(Long id, String[] tabs){
        bizRecycleBinMapper.deleteData(id,tabs);
    }

    @Override
    public Long getChildById (Long id, String tab){
        return bizRecycleBinMapper.getChildById(id,tab);
    }

    @Override
    public List<BizRecycleBin> getChildIdsByParentId(List<Map<String, Object>> tabs) {
        return bizRecycleBinMapper.getChildIdsByParentId(tabs);
    }

}
