package com.hotent.uc.manager.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hotent.base.manager.impl.BaseManagerImpl;
import com.hotent.uc.dao.UcGroupDao;
import com.hotent.uc.manager.UcGroupManager;
import com.hotent.uc.manager.UcGroupUserManager;
import com.hotent.uc.model.UcGroup;
import com.hotent.uc.util.ContextUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 群组管理 服务实现类
 *
 * @company 广州宏天软件股份有限公司
 * @author 超级管理员
 * @email test
 * @since 2021-01-15
 */
@Service
public class UcGroupManagerImpl extends BaseManagerImpl<UcGroupDao, UcGroup> implements UcGroupManager {
	@Resource
	UcGroupUserManager ucGroupUserManager;

	@Override
	@Transactional
	public void deleteByIds(List<String> list) {
		baseMapper.deleteBatchIds(list);
		QueryWrapper wrapper = new QueryWrapper();
		wrapper.in("GROUP_ID_",list);
		ucGroupUserManager.remove(wrapper);
	}

	@Override
	public UcGroup getByAlias(String code) {
		QueryWrapper<UcGroup> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("CODE_", code);
		queryWrapper.eq("CREATE_BY_", ContextUtil.getCurrentUserId());
		return getOne(queryWrapper);
	}
}
