package com.fdkankan.manage.controller;

import com.alibaba.fastjson.JSON;
import com.dtflys.forest.annotation.Post;
import com.fdkankan.common.response.ResultData;
import com.fdkankan.manage.bean.MenuBean;
import com.fdkankan.manage.entity.Agent;
import com.fdkankan.manage.service.IAgentService;
import com.fdkankan.redis.constant.RedisKey;
import com.fdkankan.redis.util.RedisUtil;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author dengsixing
 * @since 2022/5/27
 **/
@RestController
@RequestMapping("/service/manage")
public class TestController {

    @Autowired
    RedisUtil redisUtil;

    @Autowired
    private IAgentService agentService;

    @GetMapping("/test")
    public ResultData test(String num){

        List<Agent> list = agentService.list();

        return ResultData.ok(list.toArray());
    }

    @PostMapping("/test3")
    public ResultData test3(String num, @RequestParam("file") MultipartFile file){

        List<Agent> list = agentService.list();

        return ResultData.ok(list.toArray());
    }

    @PostMapping("/test1")
    public ResultData test(@RequestBody Map<String, String> params){

        List<Agent> list = agentService.list();

        return ResultData.ok(list.toArray());
    }

    @GetMapping("/setMenu")
    public ResultData test(){
        MenuBean menuBean1 = new MenuBean();
        menuBean1.setId(1);
        menuBean1.setName("a");
        menuBean1.setUri("a");
        MenuBean menuBean2 = new MenuBean();
        menuBean2.setId(2);
        menuBean2.setName("b");
        menuBean2.setUri("b");
        menuBean2.setParent(menuBean1);
        MenuBean menuBean3 = new MenuBean();
        menuBean3.setId(3);
        menuBean3.setName("c");
        menuBean3.setUri("c");
        menuBean3.setParent(menuBean2);
        redisUtil.hset(RedisKey.MANAGE_MENU, "/service/manage/test", JSON.toJSONString(menuBean3));
        return ResultData.ok();
    }


}
