package com.dcsoft.system.consume.controller;

import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.web.page.TableDataInfo;
import com.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;
import com.dcsoft.system.consume.domain.ConsumeTimeInterval;
import com.dcsoft.system.consume.service.IConsumeTimeIntervalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 消费时段Controller
 *
 * @author nichun
 * @date 2023-09-14
 */
@RestController
@RequestMapping("/consumeInterval")
public class ConsumeTimeIntervalController extends BaseController
{
    @Autowired
    private IConsumeTimeIntervalService consumeTimeIntervalService;

    /**
     * 查询消费时段列表
     */
    @RequiresPermissions("system:consumeInterval:list")
    @GetMapping("/list")
    public TableDataInfo list(ConsumeTimeInterval consumeTimeInterval)
    {
        startPage();
        List<ConsumeTimeInterval> list = consumeTimeIntervalService.selectConsumeTimeIntervalList(consumeTimeInterval);
        return getDataTable(list);
    }

    /**
     * 导出消费时段列表
     */
    @RequiresPermissions("system:consumeInterval:export")
    @Log(title = "消费时段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConsumeTimeInterval consumeTimeInterval)
    {
        List<ConsumeTimeInterval> list = consumeTimeIntervalService.selectConsumeTimeIntervalList(consumeTimeInterval);
        ExcelUtil<ConsumeTimeInterval> util = new ExcelUtil<ConsumeTimeInterval>(ConsumeTimeInterval.class);
        util.exportExcel(response, list, "消费时段数据");
    }

    /**
     * 获取消费时段详细信息
     */
    @RequiresPermissions("system:consumeInterval:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(consumeTimeIntervalService.selectConsumeTimeIntervalById(id));
    }

    /**
     * 新增消费时段
     */
    @RequiresPermissions("system:consumeInterval:add")
    @Log(title = "消费时段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConsumeTimeInterval consumeTimeInterval)
    {
        return toAjax(consumeTimeIntervalService.insertConsumeTimeInterval(consumeTimeInterval));
    }

    /**
     * 修改消费时段
     */
    @RequiresPermissions("system:consumeInterval:edit")
    @Log(title = "消费时段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConsumeTimeInterval consumeTimeInterval)
    {
        return toAjax(consumeTimeIntervalService.updateConsumeTimeInterval(consumeTimeInterval));
    }

    /**
     * 删除消费时段
     */
    @RequiresPermissions("system:consumeInterval:remove")
    @Log(title = "消费时段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(consumeTimeIntervalService.deleteConsumeTimeIntervalByIds(ids));
    }
}
