package com.ktg.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.core.domain.entity.SysRole;
import com.ktg.system.domain.SysRoleWorkstation;
import com.ktg.system.mapper.SysRoleWorkstationMapper;
import com.ktg.system.service.ISysRoleWorkstationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 角色和岗位关联Service业务层处理
 *
 * @author cgj
 * @date 2024-12-31
 */
@Service
public class SysRoleWorkstationServiceImpl extends ServiceImpl<SysRoleWorkstationMapper, SysRoleWorkstation> implements ISysRoleWorkstationService {

    @Autowired
    private SysRoleWorkstationMapper sysRoleWorkstationMapper;

    @Override
    public Boolean insertRoleWorkstation(SysRole role) {
        if ("2".equals(role.getMarsDataScope()) && role.getWorkstationIds() != null && role.getWorkstationIds().length > 0) {
            List<SysRoleWorkstation> sysRoleWorkstations = new ArrayList<>();
            for (Long workstationId : role.getWorkstationIds()) {
                SysRoleWorkstation sysRoleWorkstation = new SysRoleWorkstation();
                sysRoleWorkstation.setRoleId(role.getRoleId());
                sysRoleWorkstation.setWorkstationId(workstationId);
                sysRoleWorkstations.add(sysRoleWorkstation);
            }
            sysRoleWorkstationMapper.insertBatch(sysRoleWorkstations);
        }
        return true;
    }
}
