package com.ssm.manage.dao.impl;

import com.ssm.core.impl.BaseDaoImpl;
import com.ssm.manage.dao.SsmSysMenuPowerDao;
import com.ssm.manage.entity.SysMenuPower;
import com.ssm.manage.entity.SysPower;
import com.ssm.manage.mapper.SysMenuPowerMapper;
import com.ssm.manage.query.MenuPowerRequest;
import com.ssm.manage.query.PowerRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class SsmSysMenuPowerDaoImpl extends BaseDaoImpl<SysMenuPower> implements SsmSysMenuPowerDao {

    @Autowired
    private SysMenuPowerMapper mapper;

    @Override
    public SysMenuPowerMapper getMapper() {
        return mapper;
    }

//    @Transactional
//    @Override
//    public int saveMenuPower(MenuPowerRequest menuPowerRequest) {
//        SysMenuPower menuPower = new SysMenuPower();
//        menuPower.setMenuId(menuPowerRequest.getMenuId());
//        //前台传过来勾选的权限
//        List<PowerRequest> checkList = menuPowerRequest.getCheckList();
//
//        //处理后数据放的list
//        List<SysMenuPower> saveMenuPowerList = new ArrayList<>();
//        //遍历勾选权限  将数据放入list
//        for (PowerRequest sysPower : checkList) {
//            SysMenuPower sysMenuPower1 = new SysMenuPower();
//            sysMenuPower1.setMenuId(menuPowerRequest.getMenuId());
//            sysMenuPower1.setMenuName(menuPowerRequest.getMenuName());
//            sysMenuPower1.setPowerId(sysPower.getPowerId());
//            sysMenuPower1.setPowerName(sysPower.getPowerName());
//            saveMenuPowerList.add(sysMenuPower1);
//
//        }
//        //删除当前菜单权限
//        int i = 0;
//        try {
//             i = mapper.delete(menuPower);
//        }catch (Exception e){
//            log.error("SsmSysMenuPowerDaoImpl.saveMenuPower", e);
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//        }
//        //将前台重新勾选的权限插入表中
//        if (i > 0) {
//            try {
//                i = mapper.saveMenuPower(saveMenuPowerList);
//            }catch (Exception e){
//                log.error("SsmSysMenuPowerDaoImpl.saveMenuPower", e);
//                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//            }
//        }
//        return i;
//    }
}
