package com.blueland.service.impl;


import java.util.List;
import java.util.Map;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blueland.model.TPfParameter;
import com.blueland.service.IParameterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blueland.bo.DictEntity;
import com.blueland.bo.ParameterEntity;
import com.blueland.bo.RoleEntity;
import com.blueland.dao.ParameterDao;

@Service
public class ParameterServiceImpl extends ServiceImpl<ParameterDao, TPfParameter> implements IParameterService {
    @Autowired
    //Parameter对应的DAO类,主要用于数据库的增删改查等操作
    private ParameterDao parameterDao;

    @Override
    public Page<ParameterEntity> findPageList(Map<String, Object> queryParams, int parseInt, int parseInt2) {
        // TODO Auto-generated method stub
        Page<ParameterEntity> page = new Page<>(parseInt, parseInt2);
        Page<ParameterEntity> result = parameterDao.findPageListNew(page, queryParams);
        return result;
    }

    @Override
    public Page<ParameterEntity> parameterListPage(Map<String, Object> queryParams, int curPageSize, int curPage) {
        Page<ParameterEntity> page = new Page<>(curPage, curPageSize);
        Page<ParameterEntity> result = parameterDao.parameterPage(page, queryParams);
        return result;
    }

    @Override
    public ParameterEntity getBykey(String key) {
        return parameterDao.getByKey(key);
    }

    @Override
    public String getValueByKey(String key) {
        return parameterDao.getValueByKey(key);
    }

    @Override
    public ParameterEntity getObj(ParameterEntity obj) {
        // TODO Auto-generated method stub
        return parameterDao.getObj(obj);
    }

    @Override
    public TPfParameter get(ParameterEntity bo) {
        return this.baseMapper.selectOne(buildQueryWrapper(bo));
    }

    @Override
    public Page<ParameterEntity> findPage(ParameterEntity bo) {
        Page<ParameterEntity> page = new Page(bo.getPageNum(), bo.getPageSize());
        return this.baseMapper.findPage(page, bo);
    }

    @Override
    public List<ParameterEntity> findList(ParameterEntity bo) {
        return this.baseMapper.findList(bo);
    }

    @Override
    public List<TPfParameter> selectConfigByKey(List<String> keys) {
        QueryWrapper<TPfParameter> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(TPfParameter::getPkey, keys);
        List<TPfParameter> list = this.baseMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public List<TPfParameter> selectConfigByValue(List<String> values) {
        QueryWrapper<TPfParameter> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(TPfParameter::getPvalue, values);
        List<TPfParameter> list = this.baseMapper.selectList(queryWrapper);
        return list;
    }


    private LambdaQueryWrapper<TPfParameter> buildQueryWrapper(ParameterEntity bo) {
        LambdaQueryWrapper<TPfParameter> lqw = Wrappers.lambdaQuery();
        lqw.eq(ObjectUtil.isNotEmpty(bo.getPid()), TPfParameter::getPid, bo.getPid());
        lqw.like(ObjectUtil.isNotEmpty(bo.getDescription()), TPfParameter::getDescription, bo.getDescription());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getPkey()), TPfParameter::getPkey, bo.getPkey());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getPvalue()), TPfParameter::getPvalue, bo.getPvalue());
        lqw.like(ObjectUtil.isNotEmpty(bo.getAppId()), TPfParameter::getAppId, bo.getAppId());
        return lqw;
    }

}
