package com.ruoyi.web.work.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.work.domain.Contract;
import com.ruoyi.web.work.service.IContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 合同模板
 *
 * @author lsw
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/work/contract")
public class ContractController extends BaseController {
    @Autowired
    private IContractService contractService;

    @PreAuthorize("@ss.hasPermi('work:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(Contract contract) {
        startPage();
        List<Contract> list = contractService.selectList(contract);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('work:contract:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id) {
        return AjaxResult.success(contractService.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('work:contract:edit')")
    @Log(title = "合同模板", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Contract contract) {
        return toAjax(contractService.updateById(contract));
    }

}
