package cn.ezhizao.project.system.service.impl;

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

import cn.ezhizao.project.system.domain.SysVersionMenu;
import cn.ezhizao.project.system.mapper.SysVersionMenuMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import cn.ezhizao.project.system.mapper.SysVersionMapper;
import cn.ezhizao.project.system.domain.SysVersion;
import cn.ezhizao.project.system.service.ISysVersionService;

/**
 * 版本管理Service业务层处理
 *
 * @author ruoyi
 * @date 2023-10-24
 */
@Service
public class SysVersionServiceImpl  extends ServiceImpl<SysVersionMapper, SysVersion> implements ISysVersionService
{
    @Resource
    private SysVersionMapper sysVersionMapper;
    @Resource
    private SysVersionMenuMapper sysVersionMenuMapper;

    /**
     * 查询版本管理列表
     *
     * @param sysVersion 版本管理
     * @return 版本管理
     */
    @Override
    public List<SysVersion> getList(SysVersion sysVersion)
    {
        return sysVersionMapper.getList(sysVersion);
    }

    /**
     * 物理删除
     * @param sysVersion
     * @return 删除结果
     */
    @Override
    public int physicalDelete(SysVersion sysVersion){ return sysVersionMapper.physicalDelete(sysVersion); }

    @Override
    public boolean save(SysVersion sysVersion) {
        boolean saveStatus = super.save(sysVersion);
        List<SysVersionMenu> menus = sysVersion.getModules();
        SysVersionMenu delCondition = new SysVersionMenu();
        delCondition.setVersionId(sysVersion.getId());
        sysVersionMenuMapper.physicalDelete(delCondition);
        menus.forEach(l -> {
            l.setVersionId(sysVersion.getId());
            sysVersionMenuMapper.insert(l);
        });
        return saveStatus;
    }

    @Override
    public boolean updateById(SysVersion sysVersion) {
        boolean saveStatus = super.updateById(sysVersion);
        List<SysVersionMenu> menus = sysVersion.getModules();
        SysVersionMenu delCondition = new SysVersionMenu();
        delCondition.setVersionId(sysVersion.getId());
        sysVersionMenuMapper.physicalDelete(delCondition);
        menus.forEach(l -> {
            l.setVersionId(sysVersion.getId());
            sysVersionMenuMapper.insert(l);
        });
        return saveStatus;
    }

//    @Override
//    public SysVersion getById(Long id) {
//        return sysVersionMenuMapper.getById(id);
//    }



}
