package com.ytpm.middle.controller;

import com.github.pagehelper.PageInfo;
import com.ytpm.agent.view.AgentDictView;
import com.ytpm.general.Result;
import com.ytpm.general.ResultTable;
import com.ytpm.middle.dao.MiddleDictMapper;
import com.ytpm.middle.view.MiddleUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@Api(tags = "middle公用类")
@RestController
@RequestMapping("/middle")
public class MiddleController {

    @Resource
    private MiddleDictMapper dictMapper;

    @ApiOperation("获取当前登录的用户信息")
    @GetMapping("/curUser")
    public Result<MiddleUserInfo> getCurUser( @ApiIgnore @AuthenticationPrincipal MiddleUserInfo userInfo) {
        return Result.resultObjOk(userInfo);
    }

    /**
     * 查询字典数据列表
     */
    @ApiOperation(value = "查询字典数据列表")
    @GetMapping("/dictList")
    public ResultTable<AgentDictView> dictList(){
        return ResultTable.resultTableOk(new PageInfo<AgentDictView>(dictMapper.selectDictList()));
    }
}
