package com.ruoyi.tuya.controller;

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

import com.ruoyi.tuya.domain.BusTravelExperience;
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.tuya.domain.BusTravel;
import com.ruoyi.tuya.service.IBusTravelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 平台游记Controller
 *
 * @author zf
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/tuya/tuyatravel")
public class BusTravelController extends BaseController
{
    @Autowired
    private IBusTravelService busTravelService;

    /**
     * 获取模块下拉列表
     */
    @GetMapping("/selectlist")
    public AjaxResult selectlist(BusTravel busTravel)
    {
        return AjaxResult.success(busTravelService.selectBusTravelList(busTravel));
    }

    /**
     * 查询平台游记列表
     */
    @PreAuthorize("@ss.hasPermi('tuya:travel:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusTravel busTravel)
    {
        startPage();
        List<BusTravel> list = busTravelService.selectBusTravelList(busTravel);
        return getDataTable(list);
    }

    /**
     * 导出平台游记列表
     */
    @PreAuthorize("@ss.hasPermi('tuya:travel:export')")
    @Log(title = "平台游记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusTravel busTravel)
    {
        List<BusTravel> list = busTravelService.selectBusTravelList(busTravel);
        ExcelUtil<BusTravel> util = new ExcelUtil<BusTravel>(BusTravel.class);
        util.exportExcel(response, list, "平台游记数据");
    }

    /**
     * 获取平台游记详细信息
     */
    @PreAuthorize("@ss.hasPermi('tuya:travel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(busTravelService.selectBusTravelById(id));
    }

    /**
     * 新增平台游记
     */
    @PreAuthorize("@ss.hasPermi('tuya:travel:add')")
    @Log(title = "平台游记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusTravel busTravel)
    {
        return toAjax(busTravelService.insertBusTravel(busTravel));
    }


    /**
     * 修改平台游记
     */
    @PreAuthorize("@ss.hasPermi('tuya:travel:edit')")
    @Log(title = "平台游记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusTravel busTravel)
    {
        return toAjax(busTravelService.updateBusTravel(busTravel));
    }

    /**
     * 删除平台游记
     */
    @PreAuthorize("@ss.hasPermi('tuya:travel:remove')")
    @Log(title = "平台游记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        busTravelService.insertBusTravelDiscard(ids);
        return toAjax(busTravelService.deleteBusTravelByIds(ids));
    }
}
