package com.ruoyi.project.invoice.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.invoice.domain.TInvoiceContractor;
import com.ruoyi.project.invoice.service.ITInvoiceContractorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 承包商信息Controller
 *
 * @author ruoyi
 * @date 2022-08-24
 */
@RestController
@RequestMapping("/invoice/contractor")
public class TInvoiceContractorController extends BaseController
{
    @Autowired
    private ITInvoiceContractorService tInvoiceContractorService;

    /**
     * 查询承包商信息列表
     */
    @PreAuthorize("@ss.hasPermi('invoice:contractor:list')")
    @GetMapping("/list")
    public TableDataInfo list(TInvoiceContractor tInvoiceContractor)
    {
        startPage();
        List<TInvoiceContractor> list = tInvoiceContractorService.selectTInvoiceContractorList(tInvoiceContractor);
        return getDataTable(list);
    }


    /**
     *  查询承包商列表
     */
    @GetMapping("/select")
    public AjaxResult select()
    {

        List<String> list = tInvoiceContractorService.selectTInvoiceContractorAllList();

        return AjaxResult.success(list);
    }

    /**
     * 导出承包商信息列表
     */
    @PreAuthorize("@ss.hasPermi('invoice:contractor:export')")
    @Log(title = "承包商信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TInvoiceContractor tInvoiceContractor)
    {
        List<TInvoiceContractor> list = tInvoiceContractorService.selectTInvoiceContractorList(tInvoiceContractor);
        ExcelUtil<TInvoiceContractor> util = new ExcelUtil<TInvoiceContractor>(TInvoiceContractor.class);
        return util.exportExcel(list, "contractor");
    }

    /**
     * 获取承包商信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('invoice:contractor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tInvoiceContractorService.selectTInvoiceContractorById(id));
    }

    /**
     * 新增承包商信息
     */
    @PreAuthorize("@ss.hasPermi('invoice:contractor:add')")
    @Log(title = "承包商信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInvoiceContractor tInvoiceContractor)
    {
        //获取操作人员ID
        Long userId = getUserId();
        tInvoiceContractor.setCreaterCode(userId.toString());
        return toAjax(tInvoiceContractorService.insertTInvoiceContractor(tInvoiceContractor));
    }

    /**
     * 修改承包商信息
     */
    @PreAuthorize("@ss.hasPermi('invoice:contractor:edit')")
    @Log(title = "承包商信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TInvoiceContractor tInvoiceContractor)
    {
        //获取操作人员ID
        Long userId = getUserId();
        tInvoiceContractor.setUpdaterCode(userId);
        tInvoiceContractor.setUpdatedate(new Date());
        return toAjax(tInvoiceContractorService.updateTInvoiceContractor(tInvoiceContractor));
    }

    /**
     * 删除承包商信息
     */
    @PreAuthorize("@ss.hasPermi('invoice:contractor:remove')")
    @Log(title = "承包商信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tInvoiceContractorService.deleteTInvoiceContractorByIds(ids));
    }
}
