package cn.ezhizao.project.business.workOrder.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.workOrder.domain.BizWorkOrderDetail;
import cn.ezhizao.project.business.workOrder.service.IBizWorkOrderDetailService;
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-11-08
 */
@RestController
@RequestMapping("/business/workOrderDetail")
public class BizWorkOrderDetailController extends BaseController
{
    @Resource
    private IBizWorkOrderDetailService bizWorkOrderDetailService;

    /**
     * 查询工单明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:workOrderDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizWorkOrderDetail bizWorkOrderDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizWorkOrderDetail);
        startPage();
        List<BizWorkOrderDetail> list = bizWorkOrderDetailService.getList(bizWorkOrderDetail);
        return getDataTable(list);
    }

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

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

    /**
     * 新增工单明细
     */
    @PreAuthorize("@ss.hasPermi('business:workOrderDetail:add')")
    @Log(title = "工单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizWorkOrderDetail bizWorkOrderDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizWorkOrderDetail);
        return toAjax(bizWorkOrderDetailService.save(bizWorkOrderDetail));
    }

    /**
     * 修改工单明细
     */
    @PreAuthorize("@ss.hasPermi('business:workOrderDetail:edit')")
    @Log(title = "工单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizWorkOrderDetail bizWorkOrderDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizWorkOrderDetail);
        return toAjax(bizWorkOrderDetailService.updateById(bizWorkOrderDetail));
    }

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