package com.younike.merchant;

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.system.domain.ServerUser;
import com.younike.system.service.IServerUserService;
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 jubs
 * @date 2022-01-05
 */
@RestController
@RequestMapping("/system/ServiceUser")
public class MerchantServerUserController extends BaseController{
    @Autowired
    private IServerUserService serverUserService;

    /**
     * 查询服务人员列表
     */

    @GetMapping("/list")
    @PreAuthorize("@ss.hasRole('merchant')")
    public TableDataInfo list( ServerUser serverUser)
    {
        startPage();
        List<ServerUser> list = serverUserService.selectServerUserList(serverUser);
        return getDataTable(list);
    }

    /**
     * 导出服务人员列表
     */

    @Log(title = "服务人员", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasRole('merchant')")
    @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, "服务人员数据");
    }

    /**
     * 获取服务人员详细信息
     */

    @GetMapping(value = "/{serverId}")
    @PreAuthorize("@ss.hasRole('merchant')")
    public AjaxResult getInfo(@PathVariable("serverId") Long serverId)
    {
        return AjaxResult.success(serverUserService.selectServerUserByServerId(serverId));
    }

    /**
     * 新增服务人员
     */

    @Log(title = "服务人员", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasRole('merchant')")
    @PostMapping
    public AjaxResult add(@RequestBody ServerUser serverUser)
    {
        return toAjax(serverUserService.insertServerUser(serverUser));
    }

    /**
     * 修改服务人员
     */

    @Log(title = "服务人员", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasRole('merchant')")
    @PutMapping
    public AjaxResult edit(@RequestBody ServerUser serverUser)
    {
        return toAjax(serverUserService.updateServerUser(serverUser));
    }

    /**
     * 删除服务人员
     */

    @Log(title = "服务人员", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasRole('merchant')")
    @DeleteMapping("/{serverIds}")
    public AjaxResult remove(@PathVariable Long[] serverIds)
    {
        return toAjax(serverUserService.deleteServerUserByServerIds(serverIds));
    }
}
