package com.ruoyi.web.work.controller;

import java.util.Arrays;
import java.util.List;
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.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.web.work.domain.ContractDetail;
import com.ruoyi.web.work.service.IContractDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同签约管理
 * @author lsw
 * @date 2024-04-24
 */
@RestController
@RequestMapping("/work/detail")
public class ContractDetailController extends BaseController {
    @Autowired
    private IContractDetailService contractDetailService;

    @PreAuthorize("@ss.hasPermi('work:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractDetail contractDetail){
        startPage();
        List<ContractDetail> list = contractDetailService.selectList(contractDetail);
        return getDataTable(list);
    }

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

    @PreAuthorize("@ss.hasPermi('work:detail:add')")
    @Log(title = "合同签约管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ContractDetail contractDetail){
        return toAjax(contractDetailService.save(contractDetail));
    }

    @PreAuthorize("@ss.hasPermi('work:detail:edit')")
    @Log(title = "合同签约管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ContractDetail contractDetail){
        return toAjax(contractDetailService.updateById(contractDetail));
    }

    @PreAuthorize("@ss.hasPermi('work:detail:remove')")
    @Log(title = "合同签约管理", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(contractDetailService.removeByIds(Arrays.asList(ids)));
    }
}
