/**
* 文件：RoleUserServiceImpl.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.RoleUserDao;
import com.mortals.xhx.base.system.role.model.RoleUserEntity;
import com.mortals.xhx.base.system.role.model.RoleUserQuery;
import com.mortals.xhx.base.system.role.service.RoleUserService;

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: RoleUserServiceImpl service接口 </p>
 * <p>Copyright: Copyright &reg;  </p>
 * <p>Company: </p>
 * @author 
 * @version 1.0.0
 */
@Service("roleUserService")
public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao,RoleUserEntity,Long> implements RoleUserService {


    @Override
    public void doDistributionUser(RoleUserQuery query) {
        Long roleId = query.getRoleId();
        // 删除角色对应的用户信息
        Map<String, Object> condition = new HashMap<>(1);
        condition.put("roleId", roleId);
        dao.delete(condition);

        List<Long> userIdList = query.getUserIdList();
        List<RoleUserEntity> list = new ArrayList<>();
        for (Long userId : userIdList) {
            RoleUserEntity rolseUser = new RoleUserEntity();
            rolseUser.setRoleId(roleId);
            rolseUser.setUserId(userId);
            list.add(rolseUser);
        }
        this.dao.insertBatch(list);
    }

    @Override
    public void doDistributionRole(RoleUserQuery query) {
        // 删除角色对应的用户信息
        Long userId = query.getUserId();
        Map<String, Object> condition = new HashMap<>(1);
        condition.put("userId", userId);
        dao.delete(condition);
        List<Long> roleIdList = query.getRoleIdList();
        List<RoleUserEntity> list = new ArrayList<>();
        for (Long roleId : roleIdList) {
            RoleUserEntity rolseUser = new RoleUserEntity();
            rolseUser.setRoleId(roleId);
            rolseUser.setUserId(userId);
            list.add(rolseUser);
        }
        this.dao.insertBatch(list);
    }



}