package com.lz.modules.third.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lz.common.utils.PageUtils;
import com.lz.common.utils.Query;
import com.lz.modules.third.dao.ThirdAppConfigMapper;
import com.lz.modules.third.entity.ThirdAppConfig;
import com.lz.modules.third.service.ThirdAppConfigService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
* <p>
* 第三方应用配置表 服务类
* </p>
*
* @author quyixiao
* @since 2020-08-17
*/

@Service
public class ThirdAppConfigServiceImpl extends ServiceImpl<ThirdAppConfigMapper, ThirdAppConfig> implements ThirdAppConfigService {


    @Autowired
	private ThirdAppConfigMapper thirdAppConfigMapper;



	@Override
	public ThirdAppConfig selectThirdAppConfigById(Long id){
		return thirdAppConfigMapper.selectThirdAppConfigById(id);
	}



	@Override
	public Long insertThirdAppConfig(ThirdAppConfig thirdAppConfig){
		return thirdAppConfigMapper.insertThirdAppConfig(thirdAppConfig);
	}



	@Override
	public int updateThirdAppConfigById(ThirdAppConfig thirdAppConfig){
		return thirdAppConfigMapper.updateThirdAppConfigById(thirdAppConfig);
	}



	@Override
	public int updateCoverThirdAppConfigById(ThirdAppConfig thirdAppConfig){
		return thirdAppConfigMapper.updateCoverThirdAppConfigById(thirdAppConfig);
	}



	@Override
	public int deleteThirdAppConfigById(Long id){
		return thirdAppConfigMapper.deleteThirdAppConfigById(id);
	}


	@Override
	public PageUtils queryPage(Map<String, Object> params){
		String roleName = (String)params.get("app_name");
		Long createUserId = (Long)params.get("app_key");

		IPage<ThirdAppConfig> page = this.page(
				new Query<ThirdAppConfig>().getPage(params),
				new QueryWrapper<ThirdAppConfig>()
						.like(StringUtils.isNotBlank(roleName),"app_name", roleName)
						.eq(createUserId != null,"app_key", createUserId)
		);

		return new PageUtils(page);
	}

	@Override
	public ThirdAppConfig getByAppId(String appid){
		return thirdAppConfigMapper.getByAppId(appid);
	}

}
