package cn.ezhizao.project.business.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;
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.project.business.domain.BizCertificateLot;
import cn.ezhizao.project.business.service.IBizCertificateLotService;

import static cn.ezhizao.common.utils.PageUtils.startPage;

/**
 * 合格证打印明细Controller
 *
 * @author ezhizao
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/business/certificateLot")
public class BizCertificateLotController extends BaseController
{
    @Resource
    private IBizCertificateLotService bizCertificateLotService;

    /**
     * 查询合格证打印明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:certificateLot:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCertificateLot bizCertificateLot) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCertificateLot);
        startPage();
        List<BizCertificateLot> list = bizCertificateLotService.getList(bizCertificateLot);
        return getDataTable(list);
    }

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

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

    /**
     * 新增合格证打印明细
     */
    @PreAuthorize("@ss.hasPermi('business:certificateLot:add')")
    @Log(title = "合格证打印明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCertificateLot bizCertificateLot) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCertificateLot);
        return toAjax(bizCertificateLotService.save(bizCertificateLot));
    }

    /**
     * 修改合格证打印明细
     */
    @PreAuthorize("@ss.hasPermi('business:certificateLot:edit')")
    @Log(title = "合格证打印明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCertificateLot bizCertificateLot) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCertificateLot);
        return toAjax(bizCertificateLotService.updateById(bizCertificateLot));
    }

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