package com.ruoyi.web.controller.chuchai;

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

import com.ruoyi.system.domain.RecordLeave;
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.system.domain.BusinessTrip;
import com.ruoyi.system.service.IBusinessTripService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出差记录信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-23
 */
@RestController
@RequestMapping("/business/trip")
public class BusinessTripController extends BaseController
{
    @Autowired
    private IBusinessTripService businessTripService;

    /**
     * 查询出差记录信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:trip:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessTrip businessTrip)
    {
        startPage();
        List<BusinessTrip> list = businessTripService.selectBusinessTripList(businessTrip);
        return getDataTable(list);
    }

    /**
     * 导出出差记录信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:trip:export')")
    @Log(title = "出差记录信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessTrip businessTrip)
    {
        List<BusinessTrip> list = businessTripService.selectBusinessTripList(businessTrip);
        ExcelUtil<BusinessTrip> util = new ExcelUtil<BusinessTrip>(BusinessTrip.class);
        util.exportExcel(response, list, "出差记录信息数据");
    }

    /**
     * 获取出差记录信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:trip:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(businessTripService.selectBusinessTripById(id));
    }

    /**
     * 新增出差记录信息
     */
    @PreAuthorize("@ss.hasPermi('business:trip:add')")
    @Log(title = "出差记录信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessTrip businessTrip)
    {
        return toAjax(businessTripService.insertBusinessTrip(businessTrip));
    }

    /**
     * 修改出差记录信息
     */
    @PreAuthorize("@ss.hasPermi('business:trip:edit')")
    @Log(title = "出差记录信息", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody BusinessTrip businessTrip)
    {
        return toAjax(businessTripService.updateBusinessTrip(businessTrip));
    }

    /**
     * 删除出差记录信息
     */
    @PreAuthorize("@ss.hasPermi('business:trip:remove')")
    @Log(title = "出差记录信息", businessType = BusinessType.DELETE)
    @GetMapping(value = "/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(businessTripService.deleteBusinessTripByIds(ids));
    }

    /***
     * 出差审核
     * @param id id
     * @param isPass 是否通过 1：不通过，2：通过
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:trip:audit')")
    @GetMapping(value = "/audit")
    public AjaxResult audit(BusinessTrip businessTrip)
    {
        return toAjax(businessTripService.audit(businessTrip));
    }


    /**
     * 获取当前账号下的出差审核列表
     */
    @PreAuthorize("@ss.hasPermi('business:trippresentList')")
    @GetMapping("/presentList")
    public TableDataInfo presentList(BusinessTrip businessTrip)
    {
        startPage();
        List<BusinessTrip> list = businessTripService.presentList(businessTrip);
        return getDataTable(list);
    }
}
