package com.pannk.sys.user.controller;

import com.pannk.sys.user.entity.SysUserEntity;
import com.pannk.sys.user.service.SysUserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wolf on 20-11-30.
 */
@Api(tags = "用户操作", description = "用户控制器")
@RestController
public class UserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 查询用户列表
     *
     * @param filter 条件
     * @return
     */
    @ApiOperation(value = "查询用户列表", notes = "过滤条件:用户名称/编号", nickname = "list")
    @ApiParam(name = "filter", value = "用户名/编号", required = true)
    @ApiImplicitParams(@ApiImplicitParam(value = "过滤条件", name = "filter", required = true, paramType = "query"))
    @ApiResponses(value = {@ApiResponse(code = 200, message = "查询成功", response = SysUserEntity.class,
            responseContainer = "List")})
    @GetMapping("/list")
    public Map<String, Object> list(String filter) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("message", "查询成功");
        result.put("data", sysUserService.list(filter));
        return result;
    }

    /**
     * 查询详情
     *
     * @param id id
     * @return
     */
    @GetMapping("/detail/{id}")
    public SysUserEntity detail(@PathVariable Long id) {
        return sysUserService.detail(id);
    }

    /**
     * 新则用户信息
     *
     * @param sysUserEntity sysUserEntity
     * @return
     */
    @PostMapping("/save")
    public SysUserEntity save(@RequestBody SysUserEntity sysUserEntity) {
        return sysUserService.save(sysUserEntity);
    }

    /**
     * 更新用户信息
     *
     * @param sysUserEntity sysUserEntity
     * @return
     */
    @PostMapping("/update")
    public SysUserEntity update(@RequestBody SysUserEntity sysUserEntity) {
        return sysUserService.save(sysUserEntity);
    }

    /**
     * 新则用户信息
     *
     * @param id id
     * @return
     */
    @PostMapping("/delete")
    public String delete(Long id) {
        sysUserService.delete(id);
        return "OK";
    }

    /**
     * 新则用户信息
     *
     * @param ids ids
     * @return
     */
    @PostMapping("/batchDelete")
    public String batchDelete(Long[] ids) {
        sysUserService.batchDelete(ids);
        return "OK";
    }
}
