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.ServerTimeSection;
import com.younike.system.service.IMerchantServerTimeSectionService;
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-13
 */
@Api("服务人员服务时间段接口")
@RestController
@RequestMapping("/system/section")
public class MerchantServerTimeSectionController  extends BaseController {
    @Autowired
    private IMerchantServerTimeSectionService serverTimeSectionService;

    /**
     * 查询服务人员服务时间段列表
     */
    @ApiOperation("查询服务人员服务时间段列表")
    @PreAuthorize("@ss.hasPermi('system:section:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServerTimeSection serverTimeSection) {
        startPage();
        List<ServerTimeSection> list = serverTimeSectionService.selectServerTimeSectionList(serverTimeSection);
        return getDataTable(list);
    }

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

    /**
     * 获取服务人员服务时间段详细信息
     */
    @ApiOperation("获取服务人员服务时间段详细信息")
    @PreAuthorize("@ss.hasPermi('system:section:query')")
    @GetMapping(value = "/{sectionId}")
    public AjaxResult getInfo(@PathVariable("sectionId") String sectionId) {
        return AjaxResult.success(serverTimeSectionService.selectServerTimeSectionBySectionId(sectionId));
    }

    /**
     * 新增服务人员服务时间段
     */
    @ApiOperation("新增服务人员服务时间段")
    @PreAuthorize("@ss.hasPermi('system:section:add')")
    @Log(title = "服务人员服务时间段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServerTimeSection serverTimeSection) {
        return toAjax(serverTimeSectionService.insertServerTimeSection(serverTimeSection));
    }

    /**
     * 修改服务人员服务时间段
     */
    @ApiOperation("修改服务人员服务时间段")
    @PreAuthorize("@ss.hasPermi('system:section:edit')")
    @Log(title = "服务人员服务时间段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServerTimeSection serverTimeSection) {
        return toAjax(serverTimeSectionService.updateServerTimeSection(serverTimeSection));
    }

    /**
     * 删除服务人员服务时间段
     */
    @ApiOperation("删除服务人员服务时间段")
    @PreAuthorize("@ss.hasPermi('system:section:remove')")
    @Log(title = "服务人员服务时间段", businessType = BusinessType.DELETE)
    @DeleteMapping("/{sectionIds}")
    public AjaxResult remove(@PathVariable String[] sectionIds) {
        return toAjax(serverTimeSectionService.deleteServerTimeSectionBySectionIds(sectionIds));
    }
}
