package com.hotent.portal.persistence.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hotent.portal.model.PortalUserLayoutConfig;
import com.hotent.base.manager.impl.BaseManagerImpl;
import com.hotent.portal.persistence.dao.PortalUserLayoutConfigDao;
import com.hotent.portal.persistence.manager.PortalUserLayoutConfigManager;
import com.hotent.uc.api.impl.util.ContextUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * 用户布局配置 服务实现类
 *
 * @author zengst
 * @company 广州宏天软件股份有限公司
 * @since 2021-09-30
 */
@Service
public class PortalUserLayoutConfigManagerImpl extends BaseManagerImpl<PortalUserLayoutConfigDao, PortalUserLayoutConfig> implements PortalUserLayoutConfigManager {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createOrUpdate(PortalUserLayoutConfig portalUserLayoutConfig) {
        String userId = ContextUtil.getCurrentUserId();
        QueryWrapper<PortalUserLayoutConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("LAYOUT_ID_", portalUserLayoutConfig.getLayoutId())
                .eq("CREATOR_", userId);
        this.remove(queryWrapper);
        portalUserLayoutConfig.setCreator(userId);
        //新建或更新
        this.saveOrUpdate(portalUserLayoutConfig);
    }

	@Override
	public PortalUserLayoutConfig getByLayoutIdUserId(String layoutId, String userId) {
		QueryWrapper<PortalUserLayoutConfig> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("LAYOUT_ID_", layoutId)
				.eq("CREATOR_", userId);
		return getOne(queryWrapper);
	}
}
