package org.jeecg.modules.apiService.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.apiBean.PageBean;
import org.jeecg.modules.apiService.ConfigService;
import org.jeecg.modules.teambuyConfig.entity.TeambuyConfig;
import org.jeecg.modules.teambuyConfig.service.ITeambuyConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ConfigServiceImpl implements ConfigService {
    /******************************************************************************************************************/
    //系统配置信息
    @Resource
    private ITeambuyConfigService teambuyConfigService;
    /******************************************************************************************************************/
    //查询系统配置列表
    @Override
    public Result<?> queryConfigList(PageBean pageBean) {
        //返回信息
        String massege = "";
        //分页信息
        Page<TeambuyConfig> page = null;
        //查询信息
        LambdaQueryChainWrapper<TeambuyConfig> query = null;
        //返回信息
        Page<TeambuyConfig> pageList = null;

        try{
            //分页
            page = new Page<TeambuyConfig>(pageBean.getPageNo(), pageBean.getPageSize());
            query = teambuyConfigService
                    .lambdaQuery();

            //组装查询条件
            //按照创建时间降序排列
            query.orderByDesc(TeambuyConfig::getCreateTime);

            //获取分类列表信息
            pageList = query.page(page);

            return Result.OK("分类列表", pageList);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error("分类列表查询失败");
        }
    }

    //查询系统配置详情
    @Override
    public Result<?> queryConfigByParamCode(String paramCode) {
        //返回信息
        String massege = "";

        try{
            TeambuyConfig config = teambuyConfigService
                    .lambdaQuery()
                    .eq(TeambuyConfig::getParamCode, paramCode)
                    .one();

            return Result.OK("配置详情", config);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error("配置详情查询失败");
        }
    }
}
