package com.ruoyi.web.controller.ss;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.timeBill.domain.TimeBill;
import com.ruoyi.ss.timeBill.domain.TimeBillVO;
import com.ruoyi.ss.timeBill.domain.TimeBillQuery;
import com.ruoyi.ss.timeBill.service.TimeBillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 时长订单Controller
 *
 * @author ruoyi
 * @date 2024-07-24
 */
@RestController
@RequestMapping("/ss/timeBill")
public class TimeBillController extends BaseController
{
    @Autowired
    private TimeBillService timeBillService;

    /**
     * 查询时长订单列表
     */
    @PreAuthorize("@ss.hasPermi('ss:timeBill:list')")
    @GetMapping("/list")
    public TableDataInfo list(TimeBillQuery query)
    {
        startPage();
        startOrderBy();
        List<TimeBillVO> list = timeBillService.selectTimeBillList(query);
        return getDataTable(list);
    }

    /**
     * 导出时长订单列表
     */
    @PreAuthorize("@ss.hasPermi('ss:timeBill:export')")
    @Log(title = "时长订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TimeBillQuery query)
    {
        List<TimeBillVO> list = timeBillService.selectTimeBillList(query);
        ExcelUtil<TimeBillVO> util = new ExcelUtil<TimeBillVO>(TimeBillVO.class);
        util.exportExcel(response, list, "时长订单数据");
    }

    /**
     * 获取时长订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:timeBill:query')")
    @GetMapping(value = "/{billId}")
    public AjaxResult getInfo(@PathVariable("billId") Long billId)
    {
        return success(timeBillService.selectTimeBillByBillId(billId));
    }

    /**
     * 新增时长订单
     */
    @PreAuthorize("@ss.hasPermi('ss:timeBill:add')")
    @Log(title = "时长订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TimeBill timeBill)
    {
        return toAjax(timeBillService.insertTimeBill(timeBill));
    }

    /**
     * 修改时长订单
     */
    @PreAuthorize("@ss.hasPermi('ss:timeBill:edit')")
    @Log(title = "时长订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TimeBill timeBill)
    {
        return toAjax(timeBillService.updateTimeBill(timeBill));
    }

    /**
     * 删除时长订单
     */
    @PreAuthorize("@ss.hasPermi('ss:timeBill:remove')")
    @Log(title = "时长订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{billIds}")
    public AjaxResult remove(@PathVariable List<Long> billIds)
    {
        return toAjax(timeBillService.logicDel(billIds));
    }
}
