package com.younike.admin;

import com.younike.common.annotation.Log;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.core.page.TableDataInfo;
import com.younike.common.enums.BusinessType;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.framework.config.AnonymousAccess;
import com.younike.system.domain.ServerUser;
import com.younike.system.domain.vo.ServerUserListVo;
import com.younike.system.param.ServerUserQueryParam;
import com.younike.system.service.IServerUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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


    /**
     * 查询服务人员列表
     */
    @ApiOperation("查询服务人员列表")
    @PreAuthorize("@ss.hasPermi('admin:user:list')")
    @GetMapping("/pageList")
    public TableDataInfo pageList(ServerUserQueryParam param) {
        startPage();
        List<ServerUserListVo> list = serverUserService.pageList(param);
        return getDataTable(list);
    }
    /**
     * 查询服务人员列表
     */
    @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));
    }
}
