package cn.ezhizao.project.business.order.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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 cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.project.business.order.domain.BizArchiveInputDetail;
import cn.ezhizao.project.business.order.service.IBizArchiveInputDetailService;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.web.page.TableDataInfo;

/**
 * 合同明细Controller
 *
 * @author ruoyi
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/business/archiveInputDetail")
public class BizArchiveInputDetailController extends BaseController
{
    @Resource
    private IBizArchiveInputDetailService bizArchiveInputDetailService;

    /**
     * 查询合同明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizArchiveInputDetail bizArchiveInputDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizArchiveInputDetail);
        startPage();
        List<BizArchiveInputDetail> list = bizArchiveInputDetailService.getList(bizArchiveInputDetail);
        return getDataTable(list);
    }

    /**
     * 导出合同明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:detail:export')")
    @Log(title = "合同明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizArchiveInputDetail bizArchiveInputDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizArchiveInputDetail);
        List<BizArchiveInputDetail> list = bizArchiveInputDetailService.getList(bizArchiveInputDetail);
        ExcelUtil<BizArchiveInputDetail> util = new ExcelUtil<BizArchiveInputDetail>(BizArchiveInputDetail.class);
        util.exportExcel(response, list, "合同明细数据");
    }

    /**
     * 获取合同明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizArchiveInputDetailService.getById(id));
    }

    /**
     * 新增合同明细
     */
    @PreAuthorize("@ss.hasPermi('business:detail:add')")
    @Log(title = "合同明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizArchiveInputDetail bizArchiveInputDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizArchiveInputDetail);
        return toAjax(bizArchiveInputDetailService.save(bizArchiveInputDetail));
    }

    /**
     * 修改合同明细
     */
    @PreAuthorize("@ss.hasPermi('business:detail:edit')")
    @Log(title = "合同明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizArchiveInputDetail bizArchiveInputDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizArchiveInputDetail);
        return toAjax(bizArchiveInputDetailService.updateById(bizArchiveInputDetail));
    }

    /**
     * 删除合同明细
     */
    @PreAuthorize("@ss.hasPermi('business:detail:remove')")
    @Log(title = "合同明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizArchiveInputDetailService.removeBatchByIds(ids));
    }
}
