package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.entity.IndexConfig;
import com.example.demo.service.IndexConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/index-config")
public class IndexConfigController {

    @Autowired
    private IndexConfigService indexConfigService;

    // 获取推荐列表
    @RequestMapping("/list")
    public String list(@RequestBody Map<String,Object> map){
        Integer indexType= (Integer) map.get("indexType");
        QueryWrapper<IndexConfig> indexConfigQueryWrapper=new QueryWrapper<>();
        indexConfigQueryWrapper.eq("config_type",indexType);
        List<IndexConfig> indexConfigList= indexConfigService.list(indexConfigQueryWrapper);
        if(null!=indexConfigList){
            return JSON.toJSONString(indexConfigList);
        }else {
            return "fail";
        }
    }
}
