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.vo.ServerTimesVO;
import com.younike.system.service.IMerchantServerTimeService;
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 jubs
 * @date 2022-01-07
 */
@Api("服务人员服务时间接口")
@RestController
@RequestMapping("/system/time")
public class MerchantServerTimeController extends BaseController {
    @Autowired
    private IMerchantServerTimeService serverTimeService;

    /**
     * 查询服务人员服务时间列表
     */
    @ApiOperation("查询服务人员服务时间列表")
    @PreAuthorize("@ss.hasPermi('system:time:list')")
    @PostMapping("/list")
    public TableDataInfo list( @RequestBody ServerTimesVO serverTime) {
        startPage();
        List<ServerTimesVO> list = serverTimeService.selectServerTimeList(serverTime);
        return getDataTable(list);
    }

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

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

    /**
     * 新增服务人员服务时间
     */
    @ApiOperation("新增服务人员服务时间")
    @PreAuthorize("@ss.hasPermi('system:time:add')")
    @Log(title = "服务人员服务时间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServerTimesVO serverTime) {
        return toAjax(serverTimeService.insertServerTime(serverTime));
    }

    /**
     * 修改服务人员服务时间
     */
    @ApiOperation("修改服务人员服务时间")
    @PreAuthorize("@ss.hasPermi('system:time:edit')")
    @Log(title = "服务人员服务时间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServerTimesVO serverTime) {
        return toAjax(serverTimeService.updateServerTime(serverTime));
    }

    /**
     * 删除服务人员服务时间
     */
    @ApiOperation("删除服务人员服务时间")
    @PreAuthorize("@ss.hasPermi('system:time:remove')")
    @Log(title = "服务人员服务时间", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serverIds}")
    public AjaxResult remove(@PathVariable Long[] serverIds) {
        return toAjax(serverTimeService.deleteServerTimeByServerIds(serverIds));
    }
}
