package com.miaxis.app.controller.user;

import java.util.List;

import com.miaxis.common.core.domain.entity.UserInfo;
import io.swagger.annotations.*;
import com.miaxis.common.core.domain.Response;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.ModelAttribute;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.user.service.IUserInfoService;
import com.miaxis.common.core.page.ResponsePageInfo;

/**
 * 【用户】Controller
 *
 * @author miaxis
 * @date 2021-08-18
 */
@RestController
@RequestMapping("/user/info")
@Api(tags={"【app-用户】"})
public class UserInfoController extends BaseController{
    @Autowired
    private IUserInfoService userInfoService;

    /**
     * 查询用户列表
     */

    @GetMapping("/list")
    @ApiOperation("查询用户列表")
        @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<UserInfo> list(@ModelAttribute UserInfo userInfo){
        startPage();
        List<UserInfo> list = userInfoService.selectUserInfoList(userInfo);
        return toResponsePageInfo(list);
    }


    /**
     * 获取用户详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取用户详细信息")
    public Response<UserInfo> getInfo(
            @ApiParam(name = "id", value = "用户参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(userInfoService.getById(id));
    }



    /**
     * 修改用户
     */
    @PreAuthorize("@ss.hasPermi('user:info:edit')")
    @Log(title = "用户", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改用户")
    public Response<Integer> edit(@RequestBody UserInfo userInfo){
        return toResponse(userInfoService.updateById(userInfo) ? 1 : 0);
    }


}
