package com.fs.project.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.project.domain.ProjectContract;
import com.fs.project.service.IProjectContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目合同信息Controller
 * 
 * @author fs
 * @date 2025-12-30
 */
@RestController
@RequestMapping("/project/contract")
public class ProjectContractController extends BaseController
{
    @Autowired
    private IProjectContractService projectContractService;

    /**
     * 查询项目合同信息列表
     */
    @PreAuthorize("@ss.hasPermi('project:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectContract projectContract)
    {
        startPage();
        List<ProjectContract> list = projectContractService.selectProjectContractList(projectContract);
        return getDataTable(list);
    }

    /**
     * 导出项目合同信息列表
     */
    @PreAuthorize("@ss.hasPermi('project:contract:export')")
    @Log(title = "项目合同信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProjectContract projectContract)
    {
        List<ProjectContract> list = projectContractService.selectProjectContractList(projectContract);
        ExcelUtil<ProjectContract> util = new ExcelUtil<ProjectContract>(ProjectContract.class);
        return util.exportExcel(list, "项目合同信息数据");
    }

    /**
     * 获取项目合同信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(projectContractService.selectProjectContractById(id));
    }

    /**
     * 新增项目合同信息
     */
    @PreAuthorize("@ss.hasPermi('project:contract:add')")
    @Log(title = "项目合同信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectContract projectContract)
    {
        return toAjax(projectContractService.insertProjectContract(projectContract));
    }

    /**
     * 修改项目合同信息
     */
    @PreAuthorize("@ss.hasPermi('project:contract:edit')")
    @Log(title = "项目合同信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectContract projectContract)
    {
        return toAjax(projectContractService.updateProjectContract(projectContract));
    }

    /**
     * 删除项目合同信息
     */
    @PreAuthorize("@ss.hasPermi('project:contract:remove')")
    @Log(title = "项目合同信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectContractService.deleteProjectContractByIds(ids));
    }
}
