package com.younike.server.controller;

import java.util.List;

import com.younike.framework.config.AnonymousAccess;
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.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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 com.younike.common.annotation.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.enums.BusinessType;
import com.younike.system.domain.ServerUser;
import com.younike.system.service.IServerUserService;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.common.core.page.TableDataInfo;

/**
 * 服务人员Controller
 * 
 * @author elev
 * @date 2022-01-06
 */
@Api("服务人员接口")
@RestController
@RequestMapping("/server/user")
public class ServerUserController extends BaseController {
    @Autowired
    private IServerUserService serverUserService;

    /**
     * 查询服务人员列表
     */
    @ApiOperation("查询服务人员列表")
    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServerUser serverUser) {
        startPage();
        List<ServerUser> list = serverUserService.selectServerUserList(serverUser);
        return getDataTable(list);
    }

    /**
     * 导出服务人员列表
     */
    @ApiOperation("导出服务人员列表")
    @PreAuthorize("@ss.hasPermi('system:user:export')")
    @Log(title = "服务人员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ServerUser serverUser) {
        List<ServerUser> list = serverUserService.selectServerUserList(serverUser);
        ExcelUtil<ServerUser> util = new ExcelUtil<ServerUser>(ServerUser.class);
        return util.exportExcel(list, "服务人员数据");
    }

    /**
     * 获取服务人员详细信息
     */
    @ApiOperation("获取服务人员详细信息")
    @PreAuthorize("@ss.hasPermi('system:user:query')")
    @GetMapping(value = "/{serverId}")
    public AjaxResult getInfo(@PathVariable("serverId") Long serverId) {
        return AjaxResult.success(serverUserService.selectServerUserByServerId(serverId));
    }

    /**
     * 新增服务人员
     */
    @ApiOperation("新增服务人员")
    @PreAuthorize("@ss.hasPermi('system:user:add')")
    @Log(title = "服务人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServerUser serverUser) {
        return toAjax(serverUserService.insertServerUser(serverUser));
    }

    /**
     * 修改服务人员
     */
    @ApiOperation("修改服务人员")
    @PreAuthorize("@ss.hasPermi('system:user:edit')")
    @Log(title = "服务人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServerUser serverUser) {
        return toAjax(serverUserService.updateServerUser(serverUser));
    }

    /**
     * 删除服务人员
     */
    @ApiOperation("删除服务人员")
    @PreAuthorize("@ss.hasPermi('system:user:remove')")
    @Log(title = "服务人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{serverIds}")
    public AjaxResult remove(@PathVariable Long[] serverIds) {
        return toAjax(serverUserService.deleteServerUserByServerIds(serverIds));
    }
    /**
     * 获取用户信息
     */
    @ApiOperation("获取用户信息")
	@PostMapping("/getUserInfo")
    @AnonymousAccess
    public AjaxResult getUserInfo(@RequestBody ServerUser serverUser) {
        return AjaxResult.success(serverUserService.selectUserInfo(serverUser));
    }

    /**
     * 修改服务人员
     */
    @ApiOperation("修改服务人员")
    @PostMapping("/updateUserInfo")
    @AnonymousAccess
    public AjaxResult updateUserInfo(@RequestBody ServerUser serverUser) {
        return toAjax(serverUserService.updateServerUser(serverUser));
    }
}
