/**
* 文件：RoleAuthServiceImpl.java
* 版本：1.0.0
* 日期：
* Copyright &reg; 
* All right reserved.
*/

package com.mortals.xhx.base.system.role.service.impl;

import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.base.system.role.dao.RoleAuthDao;
import com.mortals.xhx.base.system.role.model.RoleAuthEntity;
import com.mortals.xhx.base.system.role.model.RoleAuthQuery;
import com.mortals.xhx.base.system.role.service.RoleAuthService;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>Title: 角色资源权限</p>
 * <p>Description: RoleAuthServiceImpl service接口 </p>
 * <p>Copyright: Copyright &reg;  </p>
 * <p>Company: </p>
 * @author 
 * @version 1.0.0
 */
@Service("roleAuthService")
public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao,RoleAuthEntity,Long> implements RoleAuthService {


    @Override
    public void doDistributionSource(RoleAuthQuery query) {
        // 删除角色资源老数据
        Long roleId = query.getRoleId();
        Map<String, Object> condition = new HashMap<>();
        condition.put("roleId", roleId);
        this.dao.delete(condition);

        List<RoleAuthEntity> list = new ArrayList<>();
        for (Long sourceId : query.getResourceIdList()) {
            RoleAuthEntity entity = new RoleAuthEntity();
            entity.setRoleId(roleId);
            entity.setResourceId(sourceId);
            list.add(entity);
        }
        this.dao.insertBatch(list);
    }
	
}