package com.yunzhupaas.base.service.impl;

import com.yunzhupaas.base.service.SuperServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.base.entity.AdvancedQueryEntity;
import com.yunzhupaas.base.entity.ModuleDataAuthorizeSchemeEntity;
import com.yunzhupaas.base.mapper.AdvancedQueryMapper;
import com.yunzhupaas.base.service.AdvancedQueryService;
import com.yunzhupaas.util.RandomUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 *
 *
 * @author 云筑产品开发平台组
 * @version V3.4.2
 * @copyright 深圳市乐程软件有限公司（http://www.szlecheng.cn）
 * @date  2022/5/30
 */
@Service
public class AdvancedQueryServiceImpl extends SuperServiceImpl<AdvancedQueryMapper, AdvancedQueryEntity> implements AdvancedQueryService {
	@Override
	public void create(AdvancedQueryEntity advancedQueryEntity) {
		String mainId = Optional.ofNullable(advancedQueryEntity.getId()).orElse(RandomUtil.uuId());
		advancedQueryEntity.setId(mainId);
		this.save(advancedQueryEntity);
	}

	@Override
	public AdvancedQueryEntity getInfo(String id,String userId) {
		QueryWrapper<AdvancedQueryEntity> queryWrapper = new QueryWrapper<>();
		queryWrapper.lambda().eq(AdvancedQueryEntity::getId, id).eq(AdvancedQueryEntity::getCreatorUserId, userId);
		return this.getOne(queryWrapper);
	}

	@Override
	public List<AdvancedQueryEntity> getList(String moduleId, UserInfo userInfo) {
		QueryWrapper<AdvancedQueryEntity> queryWrapper = new QueryWrapper<>();
		queryWrapper.lambda().eq(AdvancedQueryEntity::getModuleId, moduleId).eq(AdvancedQueryEntity::getCreatorUserId, userInfo.getUserId());
		List<AdvancedQueryEntity> list = this.list(queryWrapper);
		return list;
	}

}

